700-nios2-6.6.patch 254 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978
  1. diff --git a/bfd/Makefile.am b/bfd/Makefile.am
  2. index 435b30b..488c4ab 100644
  3. --- a/bfd/Makefile.am
  4. +++ b/bfd/Makefile.am
  5. @@ -92,6 +92,7 @@ ALL_MACHINES = \
  6. cpu-maxq.lo \
  7. cpu-mcore.lo \
  8. cpu-mips.lo \
  9. + cpu-nios2.lo \
  10. cpu-mmix.lo \
  11. cpu-mt.lo \
  12. cpu-msp430.lo \
  13. @@ -156,6 +157,7 @@ ALL_MACHINES_CFILES = \
  14. cpu-maxq.c \
  15. cpu-mcore.c \
  16. cpu-mips.c \
  17. + cpu-nios2.c \
  18. cpu-mmix.c \
  19. cpu-mt.c \
  20. cpu-msp430.c \
  21. @@ -270,6 +272,7 @@ BFD32_BACKENDS = \
  22. elf32-mips.lo \
  23. elf32-mt.lo \
  24. elf32-msp430.lo \
  25. + elf32-nios2.lo \
  26. elf32-openrisc.lo \
  27. elf32-or32.lo \
  28. elf32-pj.lo \
  29. @@ -446,6 +449,7 @@ BFD32_BACKENDS_CFILES = \
  30. elf32-mips.c \
  31. elf32-mt.c \
  32. elf32-msp430.c \
  33. + elf32-nios2.c \
  34. elf32-openrisc.c \
  35. elf32-or32.c \
  36. elf32-pj.c \
  37. @@ -1065,6 +1069,7 @@ cpu-m10300.lo: cpu-m10300.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h
  38. cpu-maxq.lo: cpu-maxq.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h
  39. cpu-mcore.lo: cpu-mcore.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h
  40. cpu-mips.lo: cpu-mips.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h
  41. +cpu-nios2.lo: cpu-nios2.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h
  42. cpu-mmix.lo: cpu-mmix.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h
  43. cpu-mt.lo: cpu-mt.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h
  44. cpu-msp430.lo: cpu-msp430.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h
  45. @@ -1428,6 +1433,10 @@ elf32-msp430.lo: elf32-msp430.c $(INCDIR)/filenames.h \
  46. $(INCDIR)/elf/common.h $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h \
  47. $(INCDIR)/bfdlink.h $(INCDIR)/elf/msp430.h $(INCDIR)/elf/reloc-macros.h \
  48. elf32-target.h
  49. +elf32-nios2.lo: elf32-nios2.c $(INCDIR)/filenames.h $(INCDIR)/bfdlink.h \
  50. + genlink.h elf-bfd.h $(INCDIR)/elf/common.h $(INCDIR)/elf/internal.h \
  51. + $(INCDIR)/elf/external.h $(INCDIR)/elf/nios2.h \
  52. + $(INCDIR)/elf/reloc-macros.h elf32-target.h
  53. elf32-openrisc.lo: elf32-openrisc.c $(INCDIR)/filenames.h \
  54. $(INCDIR)/hashtab.h elf-bfd.h $(INCDIR)/elf/common.h \
  55. $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h $(INCDIR)/bfdlink.h \
  56. diff --git a/bfd/Makefile.in b/bfd/Makefile.in
  57. index 5bde689..5e57321 100644
  58. --- a/bfd/Makefile.in
  59. +++ b/bfd/Makefile.in
  60. @@ -327,6 +327,7 @@ ALL_MACHINES = \
  61. cpu-mt.lo \
  62. cpu-msp430.lo \
  63. cpu-or32.lo \
  64. + cpu-nios2.lo \
  65. cpu-ns32k.lo \
  66. cpu-openrisc.lo \
  67. cpu-pdp11.lo \
  68. @@ -391,6 +392,7 @@ ALL_MACHINES_CFILES = \
  69. cpu-mt.c \
  70. cpu-msp430.c \
  71. cpu-or32.c \
  72. + cpu-nios2.c \
  73. cpu-ns32k.c \
  74. cpu-openrisc.c \
  75. cpu-pdp11.c \
  76. @@ -502,6 +504,7 @@ BFD32_BACKENDS = \
  77. elf32-mips.lo \
  78. elf32-mt.lo \
  79. elf32-msp430.lo \
  80. + elf32-nios2.lo \
  81. elf32-openrisc.lo \
  82. elf32-or32.lo \
  83. elf32-pj.lo \
  84. @@ -678,6 +681,7 @@ BFD32_BACKENDS_CFILES = \
  85. elf32-mips.c \
  86. elf32-mt.c \
  87. elf32-msp430.c \
  88. + elf32-nios2.c \
  89. elf32-openrisc.c \
  90. elf32-or32.c \
  91. elf32-pj.c \
  92. @@ -1626,6 +1630,7 @@ cpu-m10300.lo: cpu-m10300.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h
  93. cpu-maxq.lo: cpu-maxq.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h
  94. cpu-mcore.lo: cpu-mcore.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h
  95. cpu-mips.lo: cpu-mips.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h
  96. +cpu-nios2.lo: cpu-nios2.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h
  97. cpu-mmix.lo: cpu-mmix.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h
  98. cpu-mt.lo: cpu-mt.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h
  99. cpu-msp430.lo: cpu-msp430.c $(INCDIR)/filenames.h $(INCDIR)/hashtab.h
  100. @@ -1989,6 +1994,10 @@ elf32-msp430.lo: elf32-msp430.c $(INCDIR)/filenames.h \
  101. $(INCDIR)/elf/common.h $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h \
  102. $(INCDIR)/bfdlink.h $(INCDIR)/elf/msp430.h $(INCDIR)/elf/reloc-macros.h \
  103. elf32-target.h
  104. +elf32-nios2.lo: elf32-nios2.c $(INCDIR)/filenames.h $(INCDIR)/bfdlink.h \
  105. + genlink.h elf-bfd.h $(INCDIR)/elf/common.h $(INCDIR)/elf/internal.h \
  106. + $(INCDIR)/elf/external.h $(INCDIR)/elf/nios2.h \
  107. + $(INCDIR)/elf/reloc-macros.h elf32-target.h
  108. elf32-openrisc.lo: elf32-openrisc.c $(INCDIR)/filenames.h \
  109. $(INCDIR)/hashtab.h elf-bfd.h $(INCDIR)/elf/common.h \
  110. $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h $(INCDIR)/bfdlink.h \
  111. diff --git a/bfd/archures.c b/bfd/archures.c
  112. index 5029cb0..ece60b4 100644
  113. --- a/bfd/archures.c
  114. +++ b/bfd/archures.c
  115. @@ -381,6 +381,8 @@ DESCRIPTION
  116. . bfd_arch_maxq, {* Dallas MAXQ 10/20 *}
  117. .#define bfd_mach_maxq10 10
  118. .#define bfd_mach_maxq20 20
  119. +. bfd_arch_nios2,
  120. +.#define bfd_mach_nios2 1
  121. . bfd_arch_z80,
  122. .#define bfd_mach_z80strict 1 {* No undocumented opcodes. *}
  123. .#define bfd_mach_z80 3 {* With ixl, ixh, iyl, and iyh. *}
  124. @@ -462,6 +464,7 @@ extern const bfd_arch_info_type bfd_mn10300_arch;
  125. extern const bfd_arch_info_type bfd_msp430_arch;
  126. extern const bfd_arch_info_type bfd_mt_arch;
  127. extern const bfd_arch_info_type bfd_ns32k_arch;
  128. +extern const bfd_arch_info_type bfd_nios2_arch;
  129. extern const bfd_arch_info_type bfd_openrisc_arch;
  130. extern const bfd_arch_info_type bfd_or32_arch;
  131. extern const bfd_arch_info_type bfd_pdp11_arch;
  132. @@ -530,6 +533,7 @@ static const bfd_arch_info_type * const bfd_archures_list[] =
  133. &bfd_mn10300_arch,
  134. &bfd_mt_arch,
  135. &bfd_msp430_arch,
  136. + &bfd_nios2_arch,
  137. &bfd_ns32k_arch,
  138. &bfd_openrisc_arch,
  139. &bfd_or32_arch,
  140. diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h
  141. index 8f2af8b..f5c51d6 100644
  142. --- a/bfd/bfd-in2.h
  143. +++ b/bfd/bfd-in2.h
  144. @@ -2010,6 +2010,8 @@ enum bfd_architecture
  145. bfd_arch_maxq, /* Dallas MAXQ 10/20 */
  146. #define bfd_mach_maxq10 10
  147. #define bfd_mach_maxq20 20
  148. + bfd_arch_nios2,
  149. +#define bfd_mach_nios2 1
  150. bfd_arch_z80,
  151. #define bfd_mach_z80strict 1 /* No undocumented opcodes. */
  152. #define bfd_mach_z80 3 /* With ixl, ixh, iyl, and iyh. */
  153. @@ -4271,6 +4273,23 @@ internally by the linker after analysis of a
  154. BFD_RELOC_XTENSA_ASM_EXPAND. */
  155. BFD_RELOC_XTENSA_ASM_SIMPLIFY,
  156. +/* Relocations used by the Altera New Jersey core */
  157. + BFD_RELOC_NIOS2_S16,
  158. + BFD_RELOC_NIOS2_U16,
  159. + BFD_RELOC_NIOS2_CALL26,
  160. + BFD_RELOC_NIOS2_IMM5,
  161. + BFD_RELOC_NIOS2_CACHE_OPX,
  162. + BFD_RELOC_NIOS2_IMM6,
  163. + BFD_RELOC_NIOS2_IMM8,
  164. + BFD_RELOC_NIOS2_HI16,
  165. + BFD_RELOC_NIOS2_LO16,
  166. + BFD_RELOC_NIOS2_HIADJ16,
  167. + BFD_RELOC_NIOS2_GPREL,
  168. + BFD_RELOC_NIOS2_UJMP,
  169. + BFD_RELOC_NIOS2_CJMP,
  170. + BFD_RELOC_NIOS2_CALLR,
  171. + BFD_RELOC_NIOS2_ALIGN,
  172. +
  173. /* 8 bit signed offset in (ix+d) or (iy+d). */
  174. BFD_RELOC_Z80_DISP8,
  175. diff --git a/bfd/config.bfd b/bfd/config.bfd
  176. old mode 100755
  177. new mode 100644
  178. index 9b81db7..fa86103
  179. --- a/bfd/config.bfd
  180. +++ b/bfd/config.bfd
  181. @@ -88,6 +88,7 @@ m68*) targ_archs=bfd_m68k_arch ;;
  182. m88*) targ_archs=bfd_m88k_arch ;;
  183. maxq*) targ_archs=bfd_maxq_arch ;;
  184. mips*) targ_archs=bfd_mips_arch ;;
  185. +nios2*) targ_archs=bfd_nios2_arch ;;
  186. or32*) targ_archs=bfd_or32_arch ;;
  187. pdp11*) targ_archs=bfd_pdp11_arch ;;
  188. pj*) targ_archs="bfd_pj_arch bfd_i386_arch";;
  189. @@ -985,6 +986,21 @@ case "${targ}" in
  190. targ_underscore=yes
  191. ;;
  192. + nios2eb-*-*)
  193. + targ_defvec=bfd_elf32_bignios2_vec
  194. + targ_selvecs=bfd_elf32_littlenios2_vec
  195. + ;;
  196. +
  197. + nios2el-*-*)
  198. + targ_defvec=bfd_elf32_littlenios2_vec
  199. + targ_selvecs=bfd_elf32_bignios2_vec
  200. + ;;
  201. +
  202. + nios2-*-*)
  203. + targ_defvec=bfd_elf32_littlenios2_vec
  204. + targ_selvecs=bfd_elf32_bignios2_vec
  205. + ;;
  206. +
  207. openrisc-*-elf)
  208. targ_defvec=bfd_elf32_openrisc_vec
  209. ;;
  210. diff --git a/bfd/configure b/bfd/configure
  211. index bc138ff..a64fef5 100755
  212. --- a/bfd/configure
  213. +++ b/bfd/configure
  214. @@ -10846,6 +10846,8 @@ do
  215. bfd_elf32_littlemips_vec) tb="$tb elf32-mips.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo" ;;
  216. bfd_elf32_littlemips_vxworks_vec)
  217. tb="$tb elf32-mips.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo" ;;
  218. + bfd_elf32_littlenios2_vec) tb="$tb elf32-nios2.lo elf32.lo $elf" ;;
  219. + bfd_elf32_bignios2_vec) tb="$tb elf32-nios2.lo elf32.lo $elf" ;;
  220. bfd_elf32_m32c_vec) tb="$tb elf32-m32c.lo elf32.lo $elf" ;;
  221. bfd_elf32_m32r_vec) tb="$tb elf32-m32r.lo elf32.lo $elf" ;;
  222. bfd_elf32_m32rle_vec) tb="$tb elf32-m32r.lo elf32.lo $elf" ;;
  223. diff --git a/bfd/configure.in b/bfd/configure.in
  224. index fa0d50f..eb1e5f6 100644
  225. --- a/bfd/configure.in
  226. +++ b/bfd/configure.in
  227. @@ -655,6 +655,8 @@ do
  228. bfd_elf32_nlittlemips_vec) tb="$tb elfn32-mips.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo"; target_size=64 ;;
  229. bfd_elf32_ntradbigmips_vec) tb="$tb elfn32-mips.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo"; target_size=64 ;;
  230. bfd_elf32_ntradlittlemips_vec) tb="$tb elfn32-mips.lo elfxx-mips.lo elf-vxworks.lo elf32.lo $elf ecofflink.lo"; target_size=64 ;;
  231. + bfd_elf32_littlenios2_vec) tb="$tb elf32-nios2.lo elf32.lo $elf" ;;
  232. + bfd_elf32_bignios2_vec) tb="$tb elf32-nios2.lo elf32.lo $elf" ;;
  233. bfd_elf32_openrisc_vec) tb="$tb elf32-openrisc.lo elf32.lo $elf" ;;
  234. bfd_elf32_or32_big_vec) tb="$tb elf32-or32.lo elf32.lo $elf" ;;
  235. bfd_elf32_pj_vec) tb="$tb elf32-pj.lo elf32.lo $elf";;
  236. diff --git a/bfd/cpu-nios2.c b/bfd/cpu-nios2.c
  237. new file mode 100644
  238. index 0000000..c8f39c9
  239. --- /dev/null
  240. +++ b/bfd/cpu-nios2.c
  241. @@ -0,0 +1,70 @@
  242. +/* bfd back-end for Altera Nios II support
  243. +
  244. + Copyright (C) 2003
  245. + by Nigel Gray (ngray@altera.com).
  246. +
  247. +This file is part of BFD, the Binary File Descriptor library.
  248. +
  249. +This program is free software; you can redistribute it and/or modify
  250. +it under the terms of the GNU General Public License as published by
  251. +the Free Software Foundation; either version 2 of the License, or
  252. +(at your option) any later version.
  253. +
  254. +This program is distributed in the hope that it will be useful,
  255. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  256. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  257. +GNU General Public License for more details.
  258. +
  259. +You should have received a copy of the GNU General Public License
  260. +along with this program; if not, write to the Free Software
  261. +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  262. +
  263. +#include "bfd.h"
  264. +#include "sysdep.h"
  265. +#include "libbfd.h"
  266. +
  267. +static const bfd_arch_info_type *nios2_compatible
  268. + (const bfd_arch_info_type *, const bfd_arch_info_type *);
  269. +
  270. +/* The default routine tests bits_per_word, which is wrong on mips as
  271. + mips word size doesn't correlate with reloc size. */
  272. +
  273. +static const bfd_arch_info_type *
  274. +nios2_compatible (const bfd_arch_info_type *a, const bfd_arch_info_type *b)
  275. +{
  276. + if (a->arch != b->arch)
  277. + return NULL;
  278. +
  279. + /* Machine compatibility is checked in
  280. + _bfd_mips_elf_merge_private_bfd_data. */
  281. +
  282. + return a;
  283. +}
  284. +
  285. +#define N(BITS_WORD, BITS_ADDR, NUMBER, PRINT, DEFAULT, NEXT) \
  286. + { \
  287. + BITS_WORD, /* bits in a word */ \
  288. + BITS_ADDR, /* bits in an address */ \
  289. + 8, /* 8 bits in a byte */ \
  290. + bfd_arch_nios2, \
  291. + NUMBER, \
  292. + "nios2", \
  293. + PRINT, \
  294. + 3, \
  295. + DEFAULT, \
  296. + nios2_compatible, \
  297. + bfd_default_scan, \
  298. + NEXT, \
  299. + }
  300. +
  301. +#define NN(index) (&arch_info_struct[(index) + 1])
  302. +
  303. +static const bfd_arch_info_type arch_info_struct[] =
  304. +{
  305. + N (32, 32, bfd_mach_nios2, "nios2", FALSE, 0),
  306. +};
  307. +
  308. +/* There is only one architecture - but we give the default a machine number of 0
  309. + so the linker can distinguish it */
  310. +const bfd_arch_info_type bfd_nios2_arch =
  311. +N (32, 32, 0, "nios2", TRUE, &arch_info_struct[0]);
  312. diff --git a/bfd/elf32-nios2.c b/bfd/elf32-nios2.c
  313. new file mode 100644
  314. index 0000000..f9ba1a0
  315. --- /dev/null
  316. +++ b/bfd/elf32-nios2.c
  317. @@ -0,0 +1,2193 @@
  318. +/* New Jersey-specific support for 32-bit ELF
  319. +
  320. + Copyright (C) 2003
  321. + by Nigel Gray (ngray@altera.com).
  322. +
  323. +
  324. +This file is part of BFD, the Binary File Descriptor library.
  325. +
  326. +This program is free software; you can redistribute it and/or modify
  327. +it under the terms of the GNU General Public License as published by
  328. +the Free Software Foundation; either version 2 of the License, or
  329. +(at your option) any later version.
  330. +
  331. +This program is distributed in the hope that it will be useful,
  332. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  333. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  334. +GNU General Public License for more details.
  335. +
  336. +You should have received a copy of the GNU General Public License
  337. +along with this program; if not, write to the Free Software
  338. +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  339. +
  340. +/* This file handles Altera New Jersey ELF targets */
  341. +
  342. +#include "bfd.h"
  343. +#include "sysdep.h"
  344. +#include "libbfd.h"
  345. +#include "bfdlink.h"
  346. +#include "genlink.h"
  347. +#include "elf-bfd.h"
  348. +#include "elf/nios2.h"
  349. +#include "opcode/nios2.h"
  350. +
  351. +/* use RELA relocations*/
  352. +#ifndef USE_RELA
  353. +#define USE_RELA
  354. +#endif
  355. +
  356. +#ifdef USE_REL
  357. +#undef USE_REL
  358. +#endif
  359. +
  360. +/* Function prototypes */
  361. +
  362. +static reloc_howto_type *nios2_elf32_bfd_reloc_type_lookup
  363. + (bfd *, bfd_reloc_code_real_type);
  364. +
  365. +static bfd_boolean nios2_elf32_relax_section
  366. + (bfd *, asection *, struct bfd_link_info *, bfd_boolean *);
  367. +
  368. +static bfd_boolean nios2_elf32_relax_delete_bytes
  369. + (bfd *, asection *, bfd_vma, int);
  370. +
  371. +static reloc_howto_type *nios2_elf32_rtype_to_howto
  372. + (unsigned int r_type, bfd_boolean rela_p);
  373. +
  374. +static void nios2_elf32_info_to_howto
  375. + (bfd * abfd, arelent * cache_ptr, Elf_Internal_Rela * dst);
  376. +
  377. +static bfd_boolean nios2_elf32_relocate_section
  378. + (bfd * output_bfd, struct bfd_link_info * info, bfd * input_bfd,
  379. + asection * input_section, bfd_byte * contents,
  380. + Elf_Internal_Rela * relocs, Elf_Internal_Sym * local_syms,
  381. + asection ** local_sections);
  382. +
  383. +static reloc_howto_type *lookup_howto (unsigned int rtype);
  384. +
  385. +static bfd_reloc_status_type nios2_elf_final_gp
  386. + (bfd *, asymbol *, bfd_boolean, char **, bfd_vma *,
  387. + struct bfd_link_info *);
  388. +
  389. +static bfd_boolean nios2_elf_assign_gp
  390. + (bfd *, bfd_vma *, struct bfd_link_info *);
  391. +
  392. +static bfd_reloc_status_type nios2_elf32_ignore_reloc
  393. + (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  394. +
  395. +static bfd_reloc_status_type nios2_elf32_hi16_relocate
  396. + (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  397. +
  398. +static bfd_reloc_status_type nios2_elf32_lo16_relocate
  399. + (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  400. +
  401. +static bfd_reloc_status_type nios2_elf32_hiadj16_relocate
  402. + (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  403. +
  404. +static bfd_reloc_status_type nios2_elf32_pcrel16_relocate
  405. + (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  406. +
  407. +static bfd_reloc_status_type nios2_elf32_call26_relocate
  408. + (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  409. +
  410. +static bfd_reloc_status_type nios2_elf32_gprel_relocate
  411. + (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  412. +
  413. +static bfd_reloc_status_type nios2_elf32_ujmp_relocate
  414. + (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  415. +
  416. +static bfd_reloc_status_type nios2_elf32_cjmp_relocate
  417. + (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  418. +
  419. +static bfd_reloc_status_type nios2_elf32_callr_relocate
  420. + (bfd *, arelent *, asymbol *, void *, asection *, bfd *, char **);
  421. +
  422. +static bfd_reloc_status_type nios2_elf32_do_hi16_relocate
  423. + (bfd *, reloc_howto_type *, asection *,
  424. + bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
  425. +
  426. +static bfd_reloc_status_type nios2_elf32_do_lo16_relocate
  427. + (bfd *, reloc_howto_type *, asection *,
  428. + bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
  429. +
  430. +static bfd_reloc_status_type nios2_elf32_do_hiadj16_relocate
  431. + (bfd *, reloc_howto_type *, asection *,
  432. + bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
  433. +
  434. +static bfd_reloc_status_type nios2_elf32_do_pcrel16_relocate
  435. + (bfd *, reloc_howto_type *, asection *,
  436. + bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
  437. +
  438. +static bfd_reloc_status_type nios2_elf32_do_call26_relocate
  439. + (bfd *, reloc_howto_type *, asection *,
  440. + bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
  441. +
  442. +static bfd_reloc_status_type nios2_elf32_do_gprel_relocate
  443. + (bfd *, reloc_howto_type *, asection *,
  444. + bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
  445. +
  446. +static bfd_reloc_status_type nios2_elf32_do_ujmp_relocate
  447. + (bfd *, reloc_howto_type *, asection *,
  448. + bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
  449. +
  450. +static bfd_reloc_status_type nios2_elf32_do_cjmp_relocate
  451. + (bfd *, reloc_howto_type *, asection *,
  452. + bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
  453. +
  454. +static bfd_reloc_status_type nios2_elf32_do_callr_relocate
  455. + (bfd *, reloc_howto_type *, asection *,
  456. + bfd_byte *, bfd_vma, bfd_vma, bfd_vma);
  457. +
  458. +
  459. +static void nios2_elf32_post_process_headers
  460. + (bfd *, struct bfd_link_info *);
  461. +
  462. +static bfd_boolean nios2_elf32_section_from_shdr
  463. + (bfd *, Elf_Internal_Shdr *, const char *name, int shindex);
  464. +
  465. +static bfd_boolean nios2_elf32_section_flags
  466. + (flagword *, const Elf_Internal_Shdr *);
  467. +
  468. +static bfd_boolean nios2_elf32_fake_sections
  469. + (bfd *, Elf_Internal_Shdr *, asection *);
  470. +
  471. +
  472. +
  473. +static bfd_boolean nios2_elf32_check_relocs
  474. + (bfd *, struct bfd_link_info *, asection *,
  475. + const Elf_Internal_Rela *);
  476. +
  477. +static asection *nios2_elf32_gc_mark_hook (asection * sec,
  478. + struct bfd_link_info *
  479. + info,
  480. + Elf_Internal_Rela * rel,
  481. + struct elf_link_hash_entry
  482. + * h,
  483. + Elf_Internal_Sym * sym);
  484. +
  485. +
  486. +/* target vector */
  487. +extern const bfd_target bfd_elf32_littlenios2_vec;
  488. +extern const bfd_target bfd_elf32_bignios2_vec;
  489. +
  490. +/* The relocation table used for SHT_REL sections. */
  491. +
  492. +static reloc_howto_type elf_nios2_howto_table_rel[] = {
  493. + /* No relocation. */
  494. + HOWTO (R_NIOS2_NONE, /* type */
  495. + 0, /* rightshift */
  496. + 0, /* size (0 = byte, 1 = short, 2 = long) */
  497. + 0, /* bitsize */
  498. + FALSE, /* pc_relative */
  499. + 0, /* bitpos */
  500. + complain_overflow_dont, /* complain_on_overflow */
  501. + bfd_elf_generic_reloc, /* special_function */
  502. + "R_NIOS2_NONE", /* name */
  503. + FALSE, /* partial_inplace */
  504. + 0, /* src_mask */
  505. + 0, /* dst_mask */
  506. + FALSE), /* pcrel_offset */
  507. +
  508. + /* 16-bit signed immediate relocation */
  509. + HOWTO (R_NIOS2_S16, /* type */
  510. + 0, /* rightshift */
  511. + 2, /* size (0 = byte, 1 = short, 2 = long) */
  512. + 16, /* bitsize */
  513. + FALSE, /* pc_relative */
  514. + 6, /* bitpos */
  515. + complain_overflow_signed, /* complain on overflow */
  516. + bfd_elf_generic_reloc, /* special function */
  517. + "R_NIOS2_S16", /* name */
  518. + FALSE, /* partial_inplace */
  519. + 0x003fffc0, /* src_mask */
  520. + 0x003fffc0, /* dest_mask */
  521. + FALSE), /* pcrel_offset */
  522. +
  523. + /* 16-bit unsigned immediate relocation */
  524. + HOWTO (R_NIOS2_U16, /* type */
  525. + 0, /* rightshift */
  526. + 2, /* size (0 = byte, 1 = short, 2 = long) */
  527. + 16, /* bitsize */
  528. + FALSE, /* pc_relative */
  529. + 6, /* bitpos */
  530. + complain_overflow_unsigned, /* complain on overflow */
  531. + bfd_elf_generic_reloc, /* special function */
  532. + "R_NIOS2_U16", /* name */
  533. + FALSE, /* partial_inplace */
  534. + 0x003fffc0, /* src_mask */
  535. + 0x003fffc0, /* dest_mask */
  536. + FALSE), /* pcrel_offset */
  537. +
  538. + HOWTO (R_NIOS2_PCREL16, /* type */
  539. + 0, /* rightshift */
  540. + 2, /* size (0 = byte, 1 = short, 2 = long) */
  541. + 16, /* bitsize */
  542. + TRUE, /* pc_relative */
  543. + 6, /* bitpos */
  544. + complain_overflow_signed, /* complain on overflow */
  545. + nios2_elf32_pcrel16_relocate, /* special function */
  546. + "R_NIOS2_PCREL16", /* name */
  547. + FALSE, /* partial_inplace */
  548. + 0x003fffc0, /* src_mask */
  549. + 0x003fffc0, /* dest_mask */
  550. + TRUE), /* pcrel_offset */
  551. +
  552. + HOWTO (R_NIOS2_CALL26, /* type */
  553. + 2, /* rightshift */
  554. + 2, /* size (0 = byte, 1 = short, 2 = long) */
  555. + 26, /* bitsize */
  556. + FALSE, /* pc_relative */
  557. + 6, /* bitpos */
  558. + complain_overflow_dont, /* complain on overflow */
  559. + nios2_elf32_call26_relocate, /* special function */
  560. + "R_NIOS2_CALL26", /* name */
  561. + FALSE, /* partial_inplace */
  562. + 0xffffffc0, /* src_mask */
  563. + 0xffffffc0, /* dst_mask */
  564. + FALSE), /* pcrel_offset */
  565. +
  566. + HOWTO (R_NIOS2_IMM5,
  567. + 0,
  568. + 2,
  569. + 5,
  570. + FALSE,
  571. + 6,
  572. + complain_overflow_bitfield,
  573. + bfd_elf_generic_reloc,
  574. + "R_NIOS2_IMM5",
  575. + FALSE,
  576. + 0x000007c0,
  577. + 0x000007c0,
  578. + FALSE),
  579. +
  580. + HOWTO (R_NIOS2_CACHE_OPX,
  581. + 0,
  582. + 2,
  583. + 5,
  584. + FALSE,
  585. + 22,
  586. + complain_overflow_bitfield,
  587. + bfd_elf_generic_reloc,
  588. + "R_NIOS2_CACHE_OPX",
  589. + FALSE,
  590. + 0x07c00000,
  591. + 0x07c00000,
  592. + FALSE),
  593. +
  594. + HOWTO (R_NIOS2_IMM6,
  595. + 0,
  596. + 2,
  597. + 6,
  598. + FALSE,
  599. + 6,
  600. + complain_overflow_bitfield,
  601. + bfd_elf_generic_reloc,
  602. + "R_NIOS2_IMM6",
  603. + FALSE,
  604. + 0x00000fc0,
  605. + 0x00000fc0,
  606. + FALSE),
  607. +
  608. + HOWTO (R_NIOS2_IMM8,
  609. + 0,
  610. + 2,
  611. + 8,
  612. + FALSE,
  613. + 6,
  614. + complain_overflow_bitfield,
  615. + bfd_elf_generic_reloc,
  616. + "R_NIOS2_IMM8",
  617. + FALSE,
  618. + 0x00003fc0,
  619. + 0x00003fc0,
  620. + FALSE),
  621. +
  622. + HOWTO (R_NIOS2_HI16,
  623. + 0,
  624. + 2,
  625. + 32,
  626. + FALSE,
  627. + 6,
  628. + complain_overflow_dont,
  629. + nios2_elf32_hi16_relocate,
  630. + "R_NIOS2_HI16",
  631. + FALSE,
  632. + 0x003fffc0,
  633. + 0x003fffc0,
  634. + FALSE),
  635. +
  636. + HOWTO (R_NIOS2_LO16,
  637. + 0,
  638. + 2,
  639. + 32,
  640. + FALSE,
  641. + 6,
  642. + complain_overflow_dont,
  643. + nios2_elf32_lo16_relocate,
  644. + "R_NIOS2_LO16",
  645. + FALSE,
  646. + 0x003fffc0,
  647. + 0x003fffc0,
  648. + FALSE),
  649. +
  650. + HOWTO (R_NIOS2_HIADJ16,
  651. + 0,
  652. + 2,
  653. + 32,
  654. + FALSE,
  655. + 6,
  656. + complain_overflow_dont,
  657. + nios2_elf32_hiadj16_relocate,
  658. + "R_NIOS2_HIADJ16",
  659. + FALSE,
  660. + 0x003fffc0,
  661. + 0x003fffc0,
  662. + FALSE),
  663. +
  664. + HOWTO (R_NIOS2_BFD_RELOC_32,
  665. + 0,
  666. + 2, /* long */
  667. + 32,
  668. + FALSE,
  669. + 0,
  670. + complain_overflow_dont,
  671. + bfd_elf_generic_reloc,
  672. + "R_NIOS2_BFD_RELOC32",
  673. + FALSE,
  674. + 0xffffffff,
  675. + 0xffffffff,
  676. + FALSE),
  677. +
  678. + HOWTO (R_NIOS2_BFD_RELOC_16,
  679. + 0,
  680. + 1, /* short */
  681. + 16,
  682. + FALSE,
  683. + 0,
  684. + complain_overflow_bitfield,
  685. + bfd_elf_generic_reloc,
  686. + "R_NIOS2_BFD_RELOC16",
  687. + FALSE,
  688. + 0x0000ffff,
  689. + 0x0000ffff,
  690. + FALSE),
  691. +
  692. + HOWTO (R_NIOS2_BFD_RELOC_8,
  693. + 0,
  694. + 0, /* byte */
  695. + 8,
  696. + FALSE,
  697. + 0,
  698. + complain_overflow_bitfield,
  699. + bfd_elf_generic_reloc,
  700. + "R_NIOS2_BFD_RELOC8",
  701. + FALSE,
  702. + 0x000000ff,
  703. + 0x000000ff,
  704. + FALSE),
  705. +
  706. + HOWTO (R_NIOS2_GPREL,
  707. + 0,
  708. + 2,
  709. + 32,
  710. + FALSE,
  711. + 6,
  712. + complain_overflow_dont,
  713. + nios2_elf32_gprel_relocate,
  714. + "R_NIOS2_GPREL",
  715. + FALSE,
  716. + 0x003fffc0,
  717. + 0x003fffc0,
  718. + FALSE),
  719. +
  720. + HOWTO (R_NIOS2_GNU_VTINHERIT,
  721. + 0,
  722. + 2, /* short */
  723. + 0,
  724. + FALSE,
  725. + 0,
  726. + complain_overflow_dont,
  727. + NULL,
  728. + "R_NIOS2_GNU_VTINHERIT",
  729. + FALSE,
  730. + 0,
  731. + 0,
  732. + FALSE),
  733. +
  734. + HOWTO (R_NIOS2_GNU_VTENTRY,
  735. + 0,
  736. + 2, /* byte */
  737. + 0,
  738. + FALSE,
  739. + 0,
  740. + complain_overflow_dont,
  741. + _bfd_elf_rel_vtable_reloc_fn,
  742. + "R_NIOS2_GNU_VTENTRY",
  743. + FALSE,
  744. + 0,
  745. + 0,
  746. + FALSE),
  747. +
  748. + HOWTO (R_NIOS2_UJMP,
  749. + 0,
  750. + 2,
  751. + 32,
  752. + FALSE,
  753. + 6,
  754. + complain_overflow_dont,
  755. + nios2_elf32_ujmp_relocate,
  756. + "R_NIOS2_UJMP",
  757. + FALSE,
  758. + 0x003fffc0,
  759. + 0x003fffc0,
  760. + FALSE),
  761. +
  762. + HOWTO (R_NIOS2_CJMP,
  763. + 0,
  764. + 2,
  765. + 32,
  766. + FALSE,
  767. + 6,
  768. + complain_overflow_dont,
  769. + nios2_elf32_cjmp_relocate,
  770. + "R_NIOS2_CJMP",
  771. + FALSE,
  772. + 0x003fffc0,
  773. + 0x003fffc0,
  774. + FALSE),
  775. +
  776. + HOWTO (R_NIOS2_CALLR,
  777. + 0,
  778. + 2,
  779. + 32,
  780. + FALSE,
  781. + 6,
  782. + complain_overflow_dont,
  783. + nios2_elf32_callr_relocate,
  784. + "R_NIOS2_CALLR",
  785. + FALSE,
  786. + 0x003fffc0,
  787. + 0x003fffc0,
  788. + FALSE),
  789. +
  790. + HOWTO (R_NIOS2_ALIGN,
  791. + 0,
  792. + 2,
  793. + 0,
  794. + FALSE,
  795. + 0,
  796. + complain_overflow_dont,
  797. + nios2_elf32_ignore_reloc,
  798. + "R_NIOS2_ALIGN",
  799. + FALSE,
  800. + 0,
  801. + 0,
  802. + TRUE),
  803. +
  804. +/* add other relocations here */
  805. +};
  806. +
  807. +static unsigned char elf_code_to_howto_index[R_NIOS2_ILLEGAL + 1];
  808. +
  809. +static reloc_howto_type *
  810. +lookup_howto (unsigned int rtype)
  811. +{
  812. + static int initialized = 0;
  813. + int i;
  814. + int howto_tbl_size = (int) (sizeof (elf_nios2_howto_table_rel)
  815. + / sizeof (elf_nios2_howto_table_rel[0]));
  816. +
  817. + if (!initialized)
  818. + {
  819. + initialized = 1;
  820. + memset (elf_code_to_howto_index, 0xff,
  821. + sizeof (elf_code_to_howto_index));
  822. + for (i = 0; i < howto_tbl_size; i++)
  823. + elf_code_to_howto_index[elf_nios2_howto_table_rel[i].type] = i;
  824. + }
  825. +
  826. + BFD_ASSERT (rtype <= R_NIOS2_ILLEGAL);
  827. + i = elf_code_to_howto_index[rtype];
  828. + if (i >= howto_tbl_size)
  829. + return 0;
  830. + return elf_nios2_howto_table_rel + i;
  831. +}
  832. +
  833. +/*
  834. + map for converting BFD reloc types to New Jersey
  835. + reloc types
  836. + */
  837. +struct elf_reloc_map
  838. +{
  839. + bfd_reloc_code_real_type bfd_val;
  840. + enum elf_nios2_reloc_type elf_val;
  841. +};
  842. +
  843. +static const struct elf_reloc_map nios2_reloc_map[] = {
  844. + {BFD_RELOC_NIOS2_S16, R_NIOS2_S16},
  845. + {BFD_RELOC_NIOS2_U16, R_NIOS2_U16},
  846. + {BFD_RELOC_16_PCREL, R_NIOS2_PCREL16},
  847. + {BFD_RELOC_NIOS2_CALL26, R_NIOS2_CALL26},
  848. + {BFD_RELOC_NIOS2_IMM5, R_NIOS2_IMM5},
  849. + {BFD_RELOC_NIOS2_CACHE_OPX, R_NIOS2_CACHE_OPX},
  850. + {BFD_RELOC_NIOS2_IMM6, R_NIOS2_IMM6},
  851. + {BFD_RELOC_NIOS2_IMM8, R_NIOS2_IMM8},
  852. + {BFD_RELOC_NIOS2_HI16, R_NIOS2_HI16},
  853. + {BFD_RELOC_NIOS2_LO16, R_NIOS2_LO16},
  854. + {BFD_RELOC_NIOS2_HIADJ16, R_NIOS2_HIADJ16},
  855. + {BFD_RELOC_32, R_NIOS2_BFD_RELOC_32},
  856. + {BFD_RELOC_16, R_NIOS2_BFD_RELOC_16},
  857. + {BFD_RELOC_8, R_NIOS2_BFD_RELOC_8},
  858. + {BFD_RELOC_NIOS2_GPREL, R_NIOS2_GPREL},
  859. + {BFD_RELOC_VTABLE_INHERIT, R_NIOS2_GNU_VTINHERIT},
  860. + {BFD_RELOC_VTABLE_ENTRY, R_NIOS2_GNU_VTENTRY},
  861. + {BFD_RELOC_NIOS2_UJMP, R_NIOS2_UJMP},
  862. + {BFD_RELOC_NIOS2_CJMP, R_NIOS2_CJMP},
  863. + {BFD_RELOC_NIOS2_CALLR, R_NIOS2_CALLR},
  864. + {BFD_RELOC_NIOS2_ALIGN, R_NIOS2_ALIGN},
  865. +};
  866. +
  867. +/* Given a BFD reloc type, return a howto structure. */
  868. +
  869. +static reloc_howto_type *
  870. +nios2_elf32_bfd_reloc_type_lookup (bfd * abfd ATTRIBUTE_UNUSED,
  871. + bfd_reloc_code_real_type code)
  872. +{
  873. + int i;
  874. + for (i = 0;
  875. + i < (int) (sizeof (nios2_reloc_map) / sizeof (struct elf_reloc_map));
  876. + ++i)
  877. + {
  878. + if (nios2_reloc_map[i].bfd_val == code)
  879. + return &elf_nios2_howto_table_rel[(int) nios2_reloc_map[i].elf_val];
  880. + }
  881. +
  882. + return NULL;
  883. +}
  884. +
  885. +/* Helper function for nios2_elf32_info_to_howto */
  886. +
  887. +static reloc_howto_type *
  888. +nios2_elf32_rtype_to_howto (unsigned int r_type,
  889. + bfd_boolean rela_p ATTRIBUTE_UNUSED)
  890. +{
  891. + BFD_ASSERT (r_type < R_NIOS2_ILLEGAL);
  892. + return &elf_nios2_howto_table_rel[r_type];
  893. +}
  894. +
  895. +/* Given a ELF32 relocation, fill in a arelent structure */
  896. +
  897. +static void
  898. +nios2_elf32_info_to_howto (bfd * abfd ATTRIBUTE_UNUSED, arelent * cache_ptr,
  899. + Elf_Internal_Rela * dst)
  900. +{
  901. + unsigned int r_type;
  902. +
  903. + r_type = ELF32_R_TYPE (dst->r_info);
  904. + cache_ptr->howto = nios2_elf32_rtype_to_howto (r_type, FALSE);
  905. +
  906. + // FIXME - do we need to do anything else here???
  907. +}
  908. +
  909. +/* The assembler has output long jmp/call sequences for all calls
  910. + * and pc-relative branches that it cannot guarantee are within
  911. + * range, so the linker must attempt to "relax" these sequences to
  912. + * short branches and calls if it can. Since we only relax in one
  913. + * direction - long to short - we don't need to see whether each
  914. + * relaxation invalidates any others
  915. + *
  916. + *
  917. + **/
  918. +static bfd_boolean
  919. +nios2_elf32_relax_section (bfd * abfd,
  920. + asection * sec,
  921. + struct bfd_link_info *link_info, bfd_boolean * again)
  922. +{
  923. + Elf_Internal_Shdr *symtab_hdr;
  924. + Elf_Internal_Rela *internal_relocs;
  925. + Elf_Internal_Rela *irel, *irelend;
  926. + bfd_byte *contents = NULL;
  927. + Elf_Internal_Sym *isymbuf = NULL;
  928. +
  929. + /* Assume nothing changes. */
  930. + *again = FALSE;
  931. +
  932. + /* We don't have to do anything for a relocatable link, if
  933. + this section does not have relocs, or if this is not a
  934. + code section. */
  935. + if (link_info->relocatable
  936. + || (sec->flags & SEC_RELOC) == 0
  937. + || sec->reloc_count == 0 || (sec->flags & SEC_CODE) == 0)
  938. + return TRUE;
  939. +
  940. + /* If this is the first time we have been called for this section,
  941. + initialize the cooked size. */
  942. + if (sec->size == 0)
  943. + sec->size = sec->rawsize;
  944. +
  945. + symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  946. +
  947. + /* Get a copy of the native relocations. */
  948. + internal_relocs = (_bfd_elf_link_read_relocs
  949. + (abfd, sec, (void *) NULL, (Elf_Internal_Rela *) NULL,
  950. + link_info->keep_memory));
  951. + if (internal_relocs == NULL)
  952. + goto error_return;
  953. +
  954. + /* Walk through them looking for relaxing opportunities. */
  955. + irelend = internal_relocs + sec->reloc_count;
  956. + for (irel = internal_relocs; irel < irelend; irel++)
  957. + {
  958. + bfd_vma symval;
  959. +
  960. + /* If this isn't something that can be relaxed, then ignore
  961. + this reloc. */
  962. + if (ELF32_R_TYPE (irel->r_info) != (int) R_NIOS2_UJMP
  963. + && ELF32_R_TYPE (irel->r_info) != (int) R_NIOS2_CJMP
  964. + && ELF32_R_TYPE (irel->r_info) != (int) R_NIOS2_CALLR)
  965. + {
  966. + continue;
  967. + }
  968. +
  969. + /* Get the section contents if we haven't done so already. */
  970. + if (contents == NULL)
  971. + {
  972. + /* Get cached copy if it exists. */
  973. + if (elf_section_data (sec)->this_hdr.contents != NULL)
  974. + contents = elf_section_data (sec)->this_hdr.contents;
  975. + else
  976. + {
  977. + /* Go get them off disk. */
  978. + contents = (bfd_byte *) bfd_malloc (sec->rawsize);
  979. + if (contents == NULL)
  980. + goto error_return;
  981. +
  982. + if (!bfd_get_section_contents (abfd, sec, contents,
  983. + (file_ptr) 0, sec->rawsize))
  984. + goto error_return;
  985. + }
  986. + }
  987. +
  988. + /* Read this BFD's local symbols if we haven't done so already. */
  989. + if (isymbuf == NULL && symtab_hdr->sh_info != 0)
  990. + {
  991. + isymbuf = (Elf_Internal_Sym *) symtab_hdr->contents;
  992. + if (isymbuf == NULL)
  993. + isymbuf = bfd_elf_get_elf_syms (abfd, symtab_hdr,
  994. + symtab_hdr->sh_info, 0,
  995. + NULL, NULL, NULL);
  996. + if (isymbuf == NULL)
  997. + goto error_return;
  998. + }
  999. +
  1000. + /* Get the value of the symbol referred to by the reloc. */
  1001. + if (ELF32_R_SYM (irel->r_info) < symtab_hdr->sh_info)
  1002. + {
  1003. + /* A local symbol. */
  1004. + Elf_Internal_Sym *isym;
  1005. + asection *sym_sec;
  1006. +
  1007. + isym = isymbuf + ELF32_R_SYM (irel->r_info);
  1008. + if (isym->st_shndx == SHN_UNDEF)
  1009. + sym_sec = bfd_und_section_ptr;
  1010. + else if (isym->st_shndx == SHN_ABS)
  1011. + sym_sec = bfd_abs_section_ptr;
  1012. + else if (isym->st_shndx == SHN_COMMON)
  1013. + sym_sec = bfd_com_section_ptr;
  1014. + else
  1015. + sym_sec = bfd_section_from_elf_index (abfd, isym->st_shndx);
  1016. + symval = (isym->st_value
  1017. + + sym_sec->output_section->vma + sym_sec->output_offset);
  1018. + }
  1019. + else
  1020. + {
  1021. + unsigned long indx;
  1022. + struct elf_link_hash_entry *h;
  1023. +
  1024. + /* An external symbol. */
  1025. + indx = ELF32_R_SYM (irel->r_info) - symtab_hdr->sh_info;
  1026. + h = elf_sym_hashes (abfd)[indx];
  1027. + BFD_ASSERT (h != NULL);
  1028. + if (h->root.type != bfd_link_hash_defined
  1029. + && h->root.type != bfd_link_hash_defweak)
  1030. + {
  1031. + /* This appears to be a reference to an undefined
  1032. + symbol. Just ignore it--it will be caught by the
  1033. + regular reloc processing. */
  1034. + continue;
  1035. + }
  1036. +
  1037. + symval = (h->root.u.def.value
  1038. + + h->root.u.def.section->output_section->vma
  1039. + + h->root.u.def.section->output_offset);
  1040. + }
  1041. +
  1042. + /* For simplicity of coding, we are going to modify the section
  1043. + contents, the section relocs, and the BFD symbol table. We
  1044. + must tell the rest of the code not to free up this
  1045. + information. It would be possible to instead create a table
  1046. + of changes which have to be made, as is done in coff-mips.c;
  1047. + that would be more work, but would require less memory when
  1048. + the linker is run. */
  1049. +
  1050. + /* try to turn :
  1051. + * movhi at, %hi(symbol)
  1052. + * movui at, %lo(symbol)
  1053. + * callr at
  1054. + * into:
  1055. + * call symbol
  1056. + */
  1057. + if (ELF32_R_TYPE (irel->r_info) == (int) R_NIOS2_CALLR)
  1058. + {
  1059. + bfd_vma targ_addr = symval + irel->r_addend;
  1060. + bfd_vma curr_addr = (sec->output_section->vma + sec->output_offset);
  1061. + bfd_vma targ_page, curr_page;
  1062. + targ_page = targ_addr & 0xf0000000;
  1063. + curr_page = curr_addr & 0xf0000000;
  1064. +
  1065. + if (targ_page == curr_page)
  1066. + {
  1067. + /* change the opcode to a call */
  1068. + bfd_put_32 (abfd, OP_MATCH_CALL, contents + irel->r_offset);
  1069. + /* Note that we've changed the relocs, section contents, etc. */
  1070. + elf_section_data (sec)->relocs = internal_relocs;
  1071. + elf_section_data (sec)->this_hdr.contents = contents;
  1072. + symtab_hdr->contents = (unsigned char *) isymbuf;
  1073. +
  1074. + /* Fix the relocation's type. */
  1075. + irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
  1076. + R_NIOS2_CALL26);
  1077. +
  1078. + /* delete the next two instructions */
  1079. + if (!nios2_elf32_relax_delete_bytes (abfd, sec,
  1080. + irel->r_offset + 4, 8))
  1081. + goto error_return;
  1082. +
  1083. + /* NG FIXME - I'm putting this in for now, but I don't think we need it */
  1084. + *again = TRUE;
  1085. + }
  1086. + }
  1087. +
  1088. + /* try to turn :
  1089. + * movhi at, %hi(symbol)
  1090. + * movui at, %lo(symbol)
  1091. + * jmp at
  1092. + * into:
  1093. + * br symbol
  1094. + */
  1095. + if (ELF32_R_TYPE (irel->r_info) == (int) R_NIOS2_UJMP)
  1096. + {
  1097. + bfd_vma pcrel_offset;
  1098. + Elf_Internal_Rela *irelalign = NULL;
  1099. + Elf_Internal_Rela *irela = elf_section_data (sec)->relocs;
  1100. + Elf_Internal_Rela *irelend = irel + sec->reloc_count;
  1101. +
  1102. + for (; irela < irelend; irela++)
  1103. + {
  1104. + if (ELF32_R_TYPE (irela->r_info) == (int) R_NIOS2_ALIGN
  1105. + && irela->r_offset > irel->r_offset + 4
  1106. + && 8 < (1 << irela->r_addend))
  1107. + {
  1108. + irelalign = irela;
  1109. + break;
  1110. + }
  1111. + }
  1112. +
  1113. + /* calculate the pcrelative offset from current location */
  1114. + pcrel_offset = symval;
  1115. + pcrel_offset -= (sec->output_section->vma + sec->output_offset);
  1116. + pcrel_offset += irel->r_addend;
  1117. +
  1118. + /* we need to compute the pcrel_offset from the next instruction */
  1119. + pcrel_offset -= (irel->r_offset + 4);
  1120. +
  1121. + /* does this value fit in 16 bits */
  1122. + if ((irelalign == NULL && (long) pcrel_offset <= 0x8004
  1123. + && (long) pcrel_offset >= -0x8000) || (irelalign != NULL
  1124. + && (long) pcrel_offset
  1125. + <= 0x7ffc
  1126. + && (long) pcrel_offset
  1127. + >= -0x8000))
  1128. + {
  1129. + /* change the opcode to an unconditional branch */
  1130. + bfd_put_32 (abfd, OP_MATCH_BR, contents + irel->r_offset);
  1131. + /* Note that we've changed the relocs, section contents, etc. */
  1132. + elf_section_data (sec)->relocs = internal_relocs;
  1133. + elf_section_data (sec)->this_hdr.contents = contents;
  1134. + symtab_hdr->contents = (unsigned char *) isymbuf;
  1135. +
  1136. + /* Fix the relocation's type. */
  1137. + irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
  1138. + R_NIOS2_PCREL16);
  1139. +
  1140. + /* delete the next two instructions */
  1141. + if (!nios2_elf32_relax_delete_bytes (abfd, sec,
  1142. + irel->r_offset + 4, 8))
  1143. + goto error_return;
  1144. +
  1145. + /* NG FIXME - I'm putting this in for now, but I don't think we need it */
  1146. + *again = TRUE;
  1147. + }
  1148. + }
  1149. +
  1150. + /* try to turn :
  1151. + * b{cond} a, b skip
  1152. + * movhi at, %hi(symbol)
  1153. + * movui at, %lo(symbol)
  1154. + * jmp at
  1155. + * skip:
  1156. + * ...
  1157. + * into:
  1158. + * br{opp_cond} a, b, symbol
  1159. + */
  1160. + if (ELF32_R_TYPE (irel->r_info) == (int) R_NIOS2_CJMP)
  1161. + {
  1162. + bfd_vma pcrel_offset;
  1163. + Elf_Internal_Rela *irelalign = NULL;
  1164. + Elf_Internal_Rela *irela = elf_section_data (sec)->relocs;
  1165. + Elf_Internal_Rela *irelend = irel + sec->reloc_count;
  1166. +
  1167. + for (; irela < irelend; irela++)
  1168. + {
  1169. + if (ELF32_R_TYPE (irela->r_info) == (int) R_NIOS2_ALIGN
  1170. + && irela->r_offset > irel->r_offset + 4
  1171. + && 8 < (1 << irela->r_addend))
  1172. + {
  1173. + irelalign = irela;
  1174. + break;
  1175. + }
  1176. + }
  1177. +
  1178. + /* calculate the pcrelative offset from current location */
  1179. + pcrel_offset = symval;
  1180. + pcrel_offset -= (sec->output_section->vma + sec->output_offset);
  1181. + pcrel_offset += irel->r_addend;
  1182. +
  1183. + /* we need to compute the pcrel_offset from this instruction
  1184. + * ie the movhi */
  1185. + pcrel_offset -= (irel->r_offset);
  1186. +
  1187. + /* does this value fit in 16 bits */
  1188. + if ((irelalign == NULL && (long) pcrel_offset <= 0x8008
  1189. + && (long) pcrel_offset >= -0x8000) || (irelalign != NULL
  1190. + && (long) pcrel_offset
  1191. + <= 0x7ffc
  1192. + && (long) pcrel_offset
  1193. + >= -0x8000))
  1194. + {
  1195. + unsigned long opcode, op_a, op_b;
  1196. + /* get the conditional branch opcode */
  1197. + opcode = bfd_get_32 (abfd, contents + irel->r_offset - 4);
  1198. + /* reverse the condition */
  1199. + switch (opcode & OP_MASK_OP)
  1200. + {
  1201. + case OP_MATCH_BEQ:
  1202. + opcode = (opcode & ~OP_MASK_OP) | OP_MATCH_BNE;
  1203. + break;
  1204. + case OP_MATCH_BNE:
  1205. + opcode = (opcode & ~OP_MASK_OP) | OP_MATCH_BEQ;
  1206. + break;
  1207. + case OP_MATCH_BGE:
  1208. + case OP_MATCH_BGEU:
  1209. + case OP_MATCH_BLT:
  1210. + case OP_MATCH_BLTU:
  1211. + /* swap the operands */
  1212. + op_a = (opcode & OP_MASK_RRT) << 5;
  1213. + op_b = (opcode & OP_MASK_RRS) >> 5;
  1214. + opcode =
  1215. + (opcode & ~(OP_MASK_RRS | OP_MASK_RRT)) | op_a | op_b;
  1216. + break;
  1217. + default:
  1218. + fprintf (stderr,
  1219. + "relaxation error - expecting conditional branch, aborting\n");
  1220. + abort ();
  1221. + break;
  1222. + }
  1223. +
  1224. + /* we must set the branch target to zero so that the skip over the jmp doesn't get
  1225. + * added to the jmp */
  1226. + opcode = opcode & (~OP_MASK_IMM16);
  1227. +
  1228. + /* change the opcode to the reversed conditional branch */
  1229. + bfd_put_32 (abfd, opcode, contents + irel->r_offset - 4);
  1230. + /* Note that we've changed the relocs, section contents, etc. */
  1231. + elf_section_data (sec)->relocs = internal_relocs;
  1232. + elf_section_data (sec)->this_hdr.contents = contents;
  1233. + symtab_hdr->contents = (unsigned char *) isymbuf;
  1234. +
  1235. + /* Fix the relocation's type. */
  1236. + irel->r_info = ELF32_R_INFO (ELF32_R_SYM (irel->r_info),
  1237. + R_NIOS2_PCREL16);
  1238. +
  1239. + /* this relocation's offset has also been reduced by 4 bytes */
  1240. + irel->r_offset -= 4;
  1241. +
  1242. + /* delete the next three instructions */
  1243. + if (!nios2_elf32_relax_delete_bytes (abfd, sec,
  1244. + irel->r_offset + 4, 12))
  1245. + goto error_return;
  1246. +
  1247. + /* NG FIXME - I'm putting this in for now, but I don't think we need it */
  1248. + *again = TRUE;
  1249. + }
  1250. + }
  1251. +
  1252. + /* otherwise, leave alone */
  1253. + }
  1254. +
  1255. + if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
  1256. + {
  1257. + if (!link_info->keep_memory)
  1258. + free (isymbuf);
  1259. + else
  1260. + {
  1261. + /* Cache the symbols for elf_link_input_bfd. */
  1262. + symtab_hdr->contents = (unsigned char *) isymbuf;
  1263. + }
  1264. + }
  1265. +
  1266. + if (contents != NULL
  1267. + && elf_section_data (sec)->this_hdr.contents != contents)
  1268. + {
  1269. + if (!link_info->keep_memory)
  1270. + free (contents);
  1271. + else
  1272. + {
  1273. + /* Cache the section contents for elf_link_input_bfd. */
  1274. + elf_section_data (sec)->this_hdr.contents = contents;
  1275. + }
  1276. + }
  1277. +
  1278. + if (internal_relocs != NULL
  1279. + && elf_section_data (sec)->relocs != internal_relocs)
  1280. + free (internal_relocs);
  1281. +
  1282. +
  1283. + return TRUE;
  1284. +
  1285. +error_return:
  1286. + if (isymbuf != NULL && symtab_hdr->contents != (unsigned char *) isymbuf)
  1287. + free (isymbuf);
  1288. + if (contents != NULL
  1289. + && elf_section_data (sec)->this_hdr.contents != contents)
  1290. + free (contents);
  1291. + if (internal_relocs != NULL
  1292. + && elf_section_data (sec)->relocs != internal_relocs)
  1293. + free (internal_relocs);
  1294. +
  1295. + return FALSE;
  1296. +}
  1297. +
  1298. +/* Delete some bytes from a section while relaxing.
  1299. + * Copied from mn10200 port */
  1300. +
  1301. +static bfd_boolean
  1302. +nios2_elf32_relax_delete_bytes (bfd * abfd,
  1303. + asection * sec, bfd_vma addr, int count)
  1304. +{
  1305. + Elf_Internal_Shdr *symtab_hdr;
  1306. + unsigned int sec_shndx;
  1307. + bfd_byte *contents;
  1308. + Elf_Internal_Rela *irel, *irelend;
  1309. + Elf_Internal_Rela *irelalign;
  1310. + bfd_vma toaddr;
  1311. + Elf_Internal_Sym *isym;
  1312. + Elf_Internal_Sym *isymend;
  1313. + struct elf_link_hash_entry **sym_hashes;
  1314. + struct elf_link_hash_entry **end_hashes;
  1315. + unsigned int symcount;
  1316. + asection *asec;
  1317. +
  1318. + sec_shndx = _bfd_elf_section_from_bfd_section (abfd, sec);
  1319. +
  1320. + contents = elf_section_data (sec)->this_hdr.contents;
  1321. +
  1322. + /* The deletion must stop at the next ALIGN reloc for an aligment
  1323. + power larger than the number of bytes we are deleting. */
  1324. +
  1325. + irelalign = NULL;
  1326. + /* +1 because we need to readjust symbols at end of section */
  1327. + toaddr = sec->size + 1;
  1328. +
  1329. + irel = elf_section_data (sec)->relocs;
  1330. + irelend = irel + sec->reloc_count;
  1331. +
  1332. + for (; irel < irelend; irel++)
  1333. + {
  1334. + if (ELF32_R_TYPE (irel->r_info) == (int) R_NIOS2_ALIGN
  1335. + && irel->r_offset > addr && count < (1 << irel->r_addend))
  1336. + {
  1337. + irelalign = irel;
  1338. + /* +1 because we need to readjust symbols at end of section */
  1339. + toaddr = irel->r_offset + 1;
  1340. + break;
  1341. + }
  1342. + }
  1343. +
  1344. +
  1345. + /* Actually delete the bytes. */
  1346. + memmove (contents + addr, contents + addr + count,
  1347. + (size_t) ((toaddr - 1) - addr - count));
  1348. +
  1349. + if (irelalign == NULL)
  1350. + sec->size -= count;
  1351. + else
  1352. + {
  1353. + int i;
  1354. +
  1355. +#define NOP_OPCODE (0x0001883a)
  1356. +
  1357. + BFD_ASSERT ((count & 3) == 0);
  1358. + for (i = 0; i < count; i += 4)
  1359. + bfd_put_32 (abfd, (bfd_vma) NOP_OPCODE,
  1360. + contents + (toaddr - 1) - count + i);
  1361. + }
  1362. +
  1363. + /* get the symbol table */
  1364. + symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  1365. + isym = (Elf_Internal_Sym *) symtab_hdr->contents;
  1366. +
  1367. + /* Adjust all the reloc offsets in this section. */
  1368. + for (irel = elf_section_data (sec)->relocs; irel < irelend; irel++)
  1369. + {
  1370. + /* Get the new reloc address. */
  1371. + if ((irel->r_offset > addr && irel->r_offset < toaddr))
  1372. + irel->r_offset -= count;
  1373. + }
  1374. +
  1375. + /* Adjust relocations against targets in this section whose positions
  1376. + * have moved as a result of the relaxation */
  1377. +
  1378. + for (asec = abfd->sections; asec; asec = asec->next)
  1379. + {
  1380. + irelend = elf_section_data (asec)->relocs + asec->reloc_count;
  1381. + for (irel = elf_section_data (asec)->relocs; irel < irelend; irel++)
  1382. + {
  1383. + Elf_Internal_Sym *sym;
  1384. + /* if the symbol which this reloc is against doesn't change
  1385. + * we need to change the reloc addend */
  1386. +
  1387. + sym = isym + ELF32_R_SYM (irel->r_info);
  1388. + if (sym->st_shndx == sec_shndx
  1389. + && !(sym->st_value > addr && sym->st_value < toaddr)
  1390. + && sym->st_value + irel->r_addend > addr
  1391. + && sym->st_value + irel->r_addend < toaddr)
  1392. + {
  1393. + irel->r_addend -= count;
  1394. + }
  1395. +
  1396. + }
  1397. + }
  1398. +
  1399. + /* Adjust the local symbols defined in this section. */
  1400. + for (isymend = isym + symtab_hdr->sh_info; isym < isymend; isym++)
  1401. + {
  1402. + if (isym->st_shndx == sec_shndx
  1403. + && isym->st_value > addr && isym->st_value < toaddr)
  1404. + isym->st_value -= count;
  1405. +
  1406. +
  1407. + }
  1408. +
  1409. + /* Now adjust the global symbols defined in this section. */
  1410. + symcount = (symtab_hdr->sh_size / sizeof (Elf32_External_Sym)
  1411. + - symtab_hdr->sh_info);
  1412. + sym_hashes = elf_sym_hashes (abfd);
  1413. + end_hashes = sym_hashes + symcount;
  1414. + for (; sym_hashes < end_hashes; sym_hashes++)
  1415. + {
  1416. + struct elf_link_hash_entry *sym_hash = *sym_hashes;
  1417. + if ((sym_hash->root.type == bfd_link_hash_defined
  1418. + || sym_hash->root.type == bfd_link_hash_defweak)
  1419. + && sym_hash->root.u.def.section == sec
  1420. + && sym_hash->root.u.def.value > addr
  1421. + && sym_hash->root.u.def.value < toaddr)
  1422. + {
  1423. + sym_hash->root.u.def.value -= count;
  1424. + }
  1425. + }
  1426. +
  1427. + return TRUE;
  1428. +}
  1429. +
  1430. +struct bfd_link_info *nios2_link_info = NULL;
  1431. +
  1432. +/*
  1433. +void
  1434. +_bfd_set_link_info (info)
  1435. + struct bfd_link_info *info;
  1436. +{
  1437. + nios2_link_info = info;
  1438. +}
  1439. +*/
  1440. +
  1441. +bfd_boolean linker_force_make_executable = FALSE;
  1442. +
  1443. +/*
  1444. +void
  1445. +_bfd_set_force_make_executable (force)
  1446. + bfd_boolean force;
  1447. +{
  1448. + linker_force_make_executable = force;
  1449. +}
  1450. +*/
  1451. +
  1452. +/* Set the GP value for OUTPUT_BFD. Returns FALSE if this is a
  1453. + dangerous relocation. */
  1454. +
  1455. +static bfd_boolean
  1456. +nios2_elf_assign_gp (bfd *output_bfd, bfd_vma *pgp, struct bfd_link_info *info)
  1457. +{
  1458. +
  1459. + bfd_boolean gp_found;
  1460. + struct bfd_hash_entry *h;
  1461. + struct bfd_link_hash_entry *lh;
  1462. +
  1463. + /* If we've already figured out what GP will be, just return it. */
  1464. + *pgp = _bfd_get_gp_value (output_bfd);
  1465. + if (*pgp)
  1466. + return TRUE;
  1467. +
  1468. + h = bfd_hash_lookup (&info->hash->table, "_gp", FALSE, FALSE);
  1469. + lh = (struct bfd_link_hash_entry *) h;
  1470. +lookup:
  1471. + if (lh)
  1472. + {
  1473. + switch (lh->type)
  1474. + {
  1475. + case bfd_link_hash_undefined:
  1476. + case bfd_link_hash_undefweak:
  1477. + case bfd_link_hash_common:
  1478. + gp_found = FALSE;
  1479. + break;
  1480. + case bfd_link_hash_defined:
  1481. + case bfd_link_hash_defweak:
  1482. + gp_found = TRUE;
  1483. + *pgp = lh->u.def.value;
  1484. + break;
  1485. + case bfd_link_hash_indirect:
  1486. + case bfd_link_hash_warning:
  1487. + lh = lh->u.i.link;
  1488. + /* @@FIXME ignoring warning for now */
  1489. + goto lookup;
  1490. + case bfd_link_hash_new:
  1491. + default:
  1492. + abort ();
  1493. + }
  1494. + }
  1495. + else
  1496. + gp_found = FALSE;
  1497. +
  1498. + if (!gp_found)
  1499. + {
  1500. + /* Only get the error once. */
  1501. + *pgp = 4;
  1502. + _bfd_set_gp_value (output_bfd, *pgp);
  1503. + return FALSE;
  1504. + }
  1505. +
  1506. + _bfd_set_gp_value (output_bfd, *pgp);
  1507. +
  1508. + return TRUE;
  1509. +}
  1510. +
  1511. +/* We have to figure out the gp value, so that we can adjust the
  1512. + symbol value correctly. We look up the symbol _gp in the output
  1513. + BFD. If we can't find it, we're stuck. We cache it in the ELF
  1514. + target data. We don't need to adjust the symbol value for an
  1515. + external symbol if we are producing relocatable output. */
  1516. +
  1517. +static bfd_reloc_status_type
  1518. +nios2_elf_final_gp (bfd *output_bfd, asymbol *symbol, bfd_boolean relocatable,
  1519. + char **error_message, bfd_vma *pgp, struct bfd_link_info *info)
  1520. +{
  1521. + if (bfd_is_und_section (symbol->section) && !relocatable)
  1522. + {
  1523. + *pgp = 0;
  1524. + return bfd_reloc_undefined;
  1525. + }
  1526. +
  1527. + *pgp = _bfd_get_gp_value (output_bfd);
  1528. + if (*pgp == 0 && (!relocatable || (symbol->flags & BSF_SECTION_SYM) != 0))
  1529. + {
  1530. + /* if this is called without link_info, then
  1531. + we cannot be doing a final link */
  1532. + if (info == NULL)
  1533. + relocatable = TRUE;
  1534. +
  1535. + if (relocatable)
  1536. + {
  1537. + /* Make up a value. */
  1538. + *pgp = symbol->section->output_section->vma + 0x4000;
  1539. + _bfd_set_gp_value (output_bfd, *pgp);
  1540. + }
  1541. + else if (!nios2_elf_assign_gp (output_bfd, pgp, info))
  1542. + {
  1543. + *error_message =
  1544. + (char *)
  1545. + _("global pointer relative relocation when _gp not defined");
  1546. + return bfd_reloc_dangerous;
  1547. + }
  1548. + }
  1549. +
  1550. + return bfd_reloc_ok;
  1551. +}
  1552. +
  1553. +
  1554. +/* Relocations that require special handling */
  1555. +
  1556. +/* This is for relocations used only when relaxing to ensure
  1557. + * changes in size of section don't screw up .align */
  1558. +static bfd_reloc_status_type
  1559. +nios2_elf32_ignore_reloc (bfd *abfd ATTRIBUTE_UNUSED, arelent *reloc_entry,
  1560. + asymbol *symbol ATTRIBUTE_UNUSED, void *data ATTRIBUTE_UNUSED,
  1561. + asection *input_section, bfd *output_bfd, char **error_message ATTRIBUTE_UNUSED)
  1562. +{
  1563. + if (output_bfd != NULL)
  1564. + reloc_entry->address += input_section->output_offset;
  1565. + return bfd_reloc_ok;
  1566. +}
  1567. +
  1568. +static bfd_reloc_status_type
  1569. +nios2_elf32_hi16_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol, void *data,
  1570. + asection *input_section, bfd *output_bfd, char **error_message ATTRIBUTE_UNUSED)
  1571. +{
  1572. + /* This part is from bfd_elf_generic_reloc. */
  1573. + if (output_bfd != (bfd *) NULL
  1574. + && (symbol->flags & BSF_SECTION_SYM) == 0
  1575. + && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0))
  1576. + {
  1577. + reloc_entry->address += input_section->output_offset;
  1578. + return bfd_reloc_ok;
  1579. + }
  1580. +
  1581. + if (output_bfd != NULL)
  1582. + /* FIXME: See bfd_perform_relocation. Is this right? */
  1583. + return bfd_reloc_ok;
  1584. +
  1585. + return nios2_elf32_do_hi16_relocate (abfd, reloc_entry->howto,
  1586. + input_section,
  1587. + data, reloc_entry->address,
  1588. + (symbol->value
  1589. + + symbol->section->output_section->vma
  1590. + + symbol->section->output_offset),
  1591. + reloc_entry->addend);
  1592. +}
  1593. +
  1594. +static bfd_reloc_status_type
  1595. +nios2_elf32_lo16_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  1596. + void *data, asection *input_section, bfd *output_bfd, char **error_message ATTRIBUTE_UNUSED)
  1597. +{
  1598. +/* This part is from bfd_elf_generic_reloc. */
  1599. + if (output_bfd != (bfd *) NULL
  1600. + && (symbol->flags & BSF_SECTION_SYM) == 0
  1601. + && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0))
  1602. + {
  1603. + reloc_entry->address += input_section->output_offset;
  1604. + return bfd_reloc_ok;
  1605. + }
  1606. +
  1607. + if (output_bfd != NULL)
  1608. + /* FIXME: See bfd_perform_relocation. Is this right? */
  1609. + return bfd_reloc_ok;
  1610. +
  1611. + return nios2_elf32_do_lo16_relocate (abfd, reloc_entry->howto,
  1612. + input_section,
  1613. + data, reloc_entry->address,
  1614. + (symbol->value
  1615. + + symbol->section->output_section->vma
  1616. + + symbol->section->output_offset),
  1617. + reloc_entry->addend);
  1618. +}
  1619. +
  1620. +static bfd_reloc_status_type
  1621. +nios2_elf32_hiadj16_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  1622. + void *data, asection *input_section, bfd *output_bfd,
  1623. + char **error_message ATTRIBUTE_UNUSED)
  1624. +{
  1625. +/* This part is from bfd_elf_generic_reloc. */
  1626. + if (output_bfd != (bfd *) NULL
  1627. + && (symbol->flags & BSF_SECTION_SYM) == 0
  1628. + && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0))
  1629. + {
  1630. + reloc_entry->address += input_section->output_offset;
  1631. + return bfd_reloc_ok;
  1632. + }
  1633. +
  1634. + if (output_bfd != NULL)
  1635. + /* FIXME: See bfd_perform_relocation. Is this right? */
  1636. + return bfd_reloc_ok;
  1637. +
  1638. + return nios2_elf32_do_hiadj16_relocate (abfd, reloc_entry->howto,
  1639. + input_section,
  1640. + data, reloc_entry->address,
  1641. + (symbol->value
  1642. + +
  1643. + symbol->section->output_section->
  1644. + vma +
  1645. + symbol->section->output_offset),
  1646. + reloc_entry->addend);
  1647. +}
  1648. +
  1649. +static bfd_reloc_status_type
  1650. +nios2_elf32_pcrel16_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  1651. + void *data, asection *input_section, bfd *output_bfd,
  1652. + char **error_message ATTRIBUTE_UNUSED)
  1653. +{
  1654. +/* This part is from bfd_elf_generic_reloc. */
  1655. + if (output_bfd != (bfd *) NULL
  1656. + && (symbol->flags & BSF_SECTION_SYM) == 0
  1657. + && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0))
  1658. + {
  1659. + reloc_entry->address += input_section->output_offset;
  1660. + return bfd_reloc_ok;
  1661. + }
  1662. +
  1663. + if (output_bfd != NULL)
  1664. + /* FIXME: See bfd_perform_relocation. Is this right? */
  1665. + return bfd_reloc_ok;
  1666. +
  1667. + return nios2_elf32_do_pcrel16_relocate (abfd, reloc_entry->howto,
  1668. + input_section,
  1669. + data, reloc_entry->address,
  1670. + (symbol->value
  1671. + +
  1672. + symbol->section->output_section->
  1673. + vma +
  1674. + symbol->section->output_offset),
  1675. + reloc_entry->addend);
  1676. +}
  1677. +
  1678. +static bfd_reloc_status_type
  1679. +nios2_elf32_call26_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  1680. + void *data, asection *input_section, bfd *output_bfd, char **error_message ATTRIBUTE_UNUSED)
  1681. +{
  1682. +/* This part is from bfd_elf_generic_reloc. */
  1683. + if (output_bfd != (bfd *) NULL
  1684. + && (symbol->flags & BSF_SECTION_SYM) == 0
  1685. + && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0))
  1686. + {
  1687. + reloc_entry->address += input_section->output_offset;
  1688. + return bfd_reloc_ok;
  1689. + }
  1690. +
  1691. + if (output_bfd != NULL)
  1692. + /* FIXME: See bfd_perform_relocation. Is this right? */
  1693. + return bfd_reloc_ok;
  1694. +
  1695. + return nios2_elf32_do_call26_relocate (abfd, reloc_entry->howto,
  1696. + input_section,
  1697. + data, reloc_entry->address,
  1698. + (symbol->value
  1699. + +
  1700. + symbol->section->output_section->
  1701. + vma +
  1702. + symbol->section->output_offset),
  1703. + reloc_entry->addend);
  1704. +}
  1705. +
  1706. +static bfd_reloc_status_type
  1707. +nios2_elf32_gprel_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  1708. + void *data, asection *input_section, bfd *output_bfd, char **msg)
  1709. +{
  1710. + bfd_vma relocation;
  1711. + bfd_vma gp;
  1712. + bfd_reloc_status_type r;
  1713. +
  1714. +
  1715. +/* This part is from bfd_elf_generic_reloc. */
  1716. + if (output_bfd != (bfd *) NULL
  1717. + && (symbol->flags & BSF_SECTION_SYM) == 0
  1718. + && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0))
  1719. + {
  1720. + reloc_entry->address += input_section->output_offset;
  1721. + return bfd_reloc_ok;
  1722. + }
  1723. +
  1724. + if (output_bfd != NULL)
  1725. + /* FIXME: See bfd_perform_relocation. Is this right? */
  1726. + return bfd_reloc_ok;
  1727. +
  1728. + relocation = symbol->value
  1729. + + symbol->section->output_section->vma + symbol->section->output_offset;
  1730. +
  1731. + if ((r =
  1732. + nios2_elf_final_gp (abfd, symbol, FALSE, msg, &gp,
  1733. + nios2_link_info)) == bfd_reloc_ok)
  1734. + {
  1735. + relocation = relocation + reloc_entry->addend - gp;
  1736. + reloc_entry->addend = 0;
  1737. + if ((signed) relocation < -32768 || (signed) relocation > 32767)
  1738. + {
  1739. + *msg = _("global pointer relative address out of range");
  1740. + r = bfd_reloc_outofrange;
  1741. + }
  1742. + else
  1743. + {
  1744. + r = nios2_elf32_do_gprel_relocate (abfd, reloc_entry->howto,
  1745. + input_section,
  1746. + data, reloc_entry->address,
  1747. + relocation, reloc_entry->addend);
  1748. + }
  1749. + }
  1750. +
  1751. + return r;
  1752. +}
  1753. +
  1754. +static bfd_reloc_status_type
  1755. +nios2_elf32_ujmp_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  1756. + void *data, asection *input_section, bfd *output_bfd, char **msg ATTRIBUTE_UNUSED)
  1757. +{
  1758. + /* This part is from bfd_elf_generic_reloc. */
  1759. + if (output_bfd != (bfd *) NULL
  1760. + && (symbol->flags & BSF_SECTION_SYM) == 0
  1761. + && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0))
  1762. + {
  1763. + reloc_entry->address += input_section->output_offset;
  1764. + return bfd_reloc_ok;
  1765. + }
  1766. +
  1767. + if (output_bfd != NULL)
  1768. + /* FIXME: See bfd_perform_relocation. Is this right? */
  1769. + return bfd_reloc_ok;
  1770. +
  1771. + return nios2_elf32_do_ujmp_relocate (abfd, reloc_entry->howto,
  1772. + input_section,
  1773. + data, reloc_entry->address,
  1774. + (symbol->value
  1775. + + symbol->section->output_section->vma
  1776. + + symbol->section->output_offset),
  1777. + reloc_entry->addend);
  1778. +}
  1779. +
  1780. +static bfd_reloc_status_type
  1781. +nios2_elf32_cjmp_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  1782. + void *data, asection *input_section, bfd *output_bfd, char **msg ATTRIBUTE_UNUSED)
  1783. +{
  1784. + /* This part is from bfd_elf_generic_reloc. */
  1785. + if (output_bfd != (bfd *) NULL
  1786. + && (symbol->flags & BSF_SECTION_SYM) == 0
  1787. + && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0))
  1788. + {
  1789. + reloc_entry->address += input_section->output_offset;
  1790. + return bfd_reloc_ok;
  1791. + }
  1792. +
  1793. + if (output_bfd != NULL)
  1794. + /* FIXME: See bfd_perform_relocation. Is this right? */
  1795. + return bfd_reloc_ok;
  1796. +
  1797. + return nios2_elf32_do_cjmp_relocate (abfd, reloc_entry->howto,
  1798. + input_section,
  1799. + data, reloc_entry->address,
  1800. + (symbol->value
  1801. + + symbol->section->output_section->vma
  1802. + + symbol->section->output_offset),
  1803. + reloc_entry->addend);
  1804. +}
  1805. +
  1806. +static bfd_reloc_status_type
  1807. +nios2_elf32_callr_relocate (bfd *abfd, arelent *reloc_entry, asymbol *symbol,
  1808. + void *data, asection *input_section, bfd *output_bfd, char **msg ATTRIBUTE_UNUSED)
  1809. +{
  1810. + /* This part is from bfd_elf_generic_reloc. */
  1811. + if (output_bfd != (bfd *) NULL
  1812. + && (symbol->flags & BSF_SECTION_SYM) == 0
  1813. + && (!reloc_entry->howto->partial_inplace || reloc_entry->addend == 0))
  1814. + {
  1815. + reloc_entry->address += input_section->output_offset;
  1816. + return bfd_reloc_ok;
  1817. + }
  1818. +
  1819. + if (output_bfd != NULL)
  1820. + /* FIXME: See bfd_perform_relocation. Is this right? */
  1821. + return bfd_reloc_ok;
  1822. +
  1823. +
  1824. + return nios2_elf32_do_callr_relocate (abfd, reloc_entry->howto,
  1825. + input_section,
  1826. + data, reloc_entry->address,
  1827. + (symbol->value
  1828. + +
  1829. + symbol->section->output_section->
  1830. + vma +
  1831. + symbol->section->output_offset),
  1832. + reloc_entry->addend);
  1833. +}
  1834. +
  1835. +/* Do the relocations which require special handling */
  1836. +
  1837. +static bfd_reloc_status_type
  1838. +nios2_elf32_do_hi16_relocate (bfd *abfd, reloc_howto_type *howto,
  1839. + asection *input_section ATTRIBUTE_UNUSED, bfd_byte *data,
  1840. + bfd_vma offset, bfd_vma symbol_value, bfd_vma addend)
  1841. +{
  1842. + symbol_value = symbol_value + addend;
  1843. + addend = 0;
  1844. + symbol_value = (symbol_value >> 16) & 0xffff;
  1845. + return _bfd_final_link_relocate (howto, abfd, input_section,
  1846. + data, offset, symbol_value, addend);
  1847. +}
  1848. +
  1849. +
  1850. +static bfd_reloc_status_type
  1851. +nios2_elf32_do_lo16_relocate (bfd *abfd, reloc_howto_type *howto,
  1852. + asection *input_section ATTRIBUTE_UNUSED, bfd_byte *data,
  1853. + bfd_vma offset, bfd_vma symbol_value, bfd_vma addend)
  1854. +{
  1855. + symbol_value = symbol_value + addend;
  1856. + addend = 0;
  1857. + symbol_value = symbol_value & 0xffff;
  1858. + return _bfd_final_link_relocate (howto, abfd, input_section,
  1859. + data, offset, symbol_value, addend);
  1860. +}
  1861. +
  1862. +static bfd_reloc_status_type
  1863. +nios2_elf32_do_hiadj16_relocate (bfd *abfd, reloc_howto_type *howto,
  1864. + asection *input_section ATTRIBUTE_UNUSED, bfd_byte *data, bfd_vma offset,
  1865. + bfd_vma symbol_value, bfd_vma addend)
  1866. +{
  1867. + symbol_value = symbol_value + addend;
  1868. + addend = 0;
  1869. + symbol_value =
  1870. + ((symbol_value >> 16) & 0xffff) + ((symbol_value >> 15) & 0x01);
  1871. + return _bfd_final_link_relocate (howto, abfd, input_section, data, offset,
  1872. + symbol_value, addend);
  1873. +}
  1874. +
  1875. +static bfd_reloc_status_type
  1876. +nios2_elf32_do_pcrel16_relocate (bfd *abfd, reloc_howto_type *howto,
  1877. + asection *input_section ATTRIBUTE_UNUSED, bfd_byte *data,
  1878. + bfd_vma offset, bfd_vma symbol_value, bfd_vma addend)
  1879. +{
  1880. + // NIOS2 pc relative relocations are relative to the next 32-bit instruction so we need
  1881. + // to subtract 4 before doing a final_link_relocate
  1882. + symbol_value = symbol_value + addend - 4;
  1883. + addend = 0;
  1884. + return _bfd_final_link_relocate (howto, abfd, input_section,
  1885. + data, offset, symbol_value, addend);
  1886. +}
  1887. +
  1888. +static bfd_reloc_status_type
  1889. +nios2_elf32_do_call26_relocate (bfd *abfd, reloc_howto_type *howto,
  1890. + asection *input_section ATTRIBUTE_UNUSED, bfd_byte *data,
  1891. + bfd_vma offset, bfd_vma symbol_value, bfd_vma addend)
  1892. +{
  1893. + /* check that the relocation is in the same page as the current address */
  1894. + if (((symbol_value + addend) & 0xf0000000)
  1895. + != ((input_section->output_section->vma + offset) & 0xf0000000))
  1896. + return bfd_reloc_overflow;
  1897. +
  1898. + return _bfd_final_link_relocate (howto, abfd, input_section,
  1899. + data, offset, symbol_value, addend);
  1900. +}
  1901. +
  1902. +
  1903. +static bfd_reloc_status_type
  1904. +nios2_elf32_do_gprel_relocate (bfd *abfd, reloc_howto_type *howto,
  1905. + asection *input_section ATTRIBUTE_UNUSED, bfd_byte *data,
  1906. + bfd_vma offset, bfd_vma symbol_value, bfd_vma addend)
  1907. +{
  1908. + // because we need the output_bfd, the special handling is done
  1909. + // in nios2_elf32_relocate_section or in nios2_elf32_gprel_relocate
  1910. + return _bfd_final_link_relocate (howto, abfd, input_section,
  1911. + data, offset, symbol_value, addend);
  1912. +}
  1913. +
  1914. +static bfd_reloc_status_type
  1915. +nios2_elf32_do_ujmp_relocate (bfd *abfd, reloc_howto_type *howto,
  1916. + asection *input_section ATTRIBUTE_UNUSED, bfd_byte *data,
  1917. + bfd_vma offset, bfd_vma symbol_value, bfd_vma addend)
  1918. +{
  1919. + bfd_vma symbol_lo16, symbol_hi16;
  1920. + bfd_reloc_status_type r;
  1921. + symbol_value = symbol_value + addend;
  1922. + addend = 0;
  1923. + symbol_hi16 = (symbol_value >> 16) & 0xffff;
  1924. + symbol_lo16 = symbol_value & 0xffff;
  1925. +
  1926. + r = _bfd_final_link_relocate (howto, abfd, input_section,
  1927. + data, offset, symbol_hi16, addend);
  1928. +
  1929. + if (r == bfd_reloc_ok)
  1930. + return _bfd_final_link_relocate (howto, abfd, input_section,
  1931. + data, offset + 4, symbol_lo16, addend);
  1932. +
  1933. + return r;
  1934. +}
  1935. +
  1936. +static bfd_reloc_status_type
  1937. +nios2_elf32_do_cjmp_relocate (bfd *abfd, reloc_howto_type *howto,
  1938. + asection *input_section ATTRIBUTE_UNUSED, bfd_byte *data,
  1939. + bfd_vma offset, bfd_vma symbol_value, bfd_vma addend)
  1940. +{
  1941. + bfd_vma symbol_lo16, symbol_hi16;
  1942. + bfd_reloc_status_type r;
  1943. + symbol_value = symbol_value + addend;
  1944. + addend = 0;
  1945. + symbol_hi16 = (symbol_value >> 16) & 0xffff;
  1946. + symbol_lo16 = symbol_value & 0xffff;
  1947. +
  1948. + r = _bfd_final_link_relocate (howto, abfd, input_section,
  1949. + data, offset, symbol_hi16, addend);
  1950. +
  1951. + if (r == bfd_reloc_ok)
  1952. + return _bfd_final_link_relocate (howto, abfd, input_section,
  1953. + data, offset + 4, symbol_lo16, addend);
  1954. +
  1955. + return r;
  1956. +}
  1957. +
  1958. +static bfd_reloc_status_type
  1959. +nios2_elf32_do_callr_relocate (bfd *abfd, reloc_howto_type *howto,
  1960. + asection *input_section ATTRIBUTE_UNUSED, bfd_byte *data,
  1961. + bfd_vma offset, bfd_vma symbol_value, bfd_vma addend)
  1962. +{
  1963. + bfd_vma symbol_lo16, symbol_hi16;
  1964. + bfd_reloc_status_type r;
  1965. + symbol_value = symbol_value + addend;
  1966. + addend = 0;
  1967. + symbol_hi16 = (symbol_value >> 16) & 0xffff;
  1968. + symbol_lo16 = symbol_value & 0xffff;
  1969. +
  1970. + r = _bfd_final_link_relocate (howto, abfd, input_section,
  1971. + data, offset, symbol_hi16, addend);
  1972. +
  1973. + if (r == bfd_reloc_ok)
  1974. + return _bfd_final_link_relocate (howto, abfd, input_section,
  1975. + data, offset + 4, symbol_lo16, addend);
  1976. +
  1977. + return r;
  1978. +}
  1979. +
  1980. +/*
  1981. + The function nios2_elf32_relocate_section is used by the linker
  1982. + to perform relocations
  1983. +*/
  1984. +static bfd_boolean
  1985. +nios2_elf32_relocate_section (bfd * output_bfd,
  1986. + struct bfd_link_info *info,
  1987. + bfd * input_bfd,
  1988. + asection * input_section,
  1989. + bfd_byte * contents,
  1990. + Elf_Internal_Rela * relocs,
  1991. + Elf_Internal_Sym * local_syms,
  1992. + asection ** local_sections)
  1993. +{
  1994. + Elf_Internal_Shdr *symtab_hdr;
  1995. + struct elf_link_hash_entry **sym_hashes;
  1996. + Elf_Internal_Rela *rel;
  1997. + Elf_Internal_Rela *relend;
  1998. +
  1999. + symtab_hdr = &elf_tdata (input_bfd)->symtab_hdr;
  2000. + sym_hashes = elf_sym_hashes (input_bfd);
  2001. + relend = relocs + input_section->reloc_count;
  2002. +
  2003. +// size_t psymalloc = 0;
  2004. +// _bfd_generic_link_output_symbols(output_bfd, input_bfd, info, &psymalloc);
  2005. + for (rel = relocs; rel < relend; rel++)
  2006. + {
  2007. + reloc_howto_type *howto;
  2008. + unsigned long r_symndx;
  2009. + Elf_Internal_Sym *sym;
  2010. + asection *sec;
  2011. + struct elf_link_hash_entry *h;
  2012. + bfd_vma relocation;
  2013. + bfd_vma gp;
  2014. + bfd_reloc_status_type r = bfd_reloc_ok;
  2015. + const char *name = NULL;
  2016. + int r_type;
  2017. + const char *msg;
  2018. +
  2019. + msg = (const char *) NULL;
  2020. +
  2021. + r_type = ELF32_R_TYPE (rel->r_info);
  2022. +
  2023. + r_symndx = ELF32_R_SYM (rel->r_info);
  2024. +
  2025. + if (info->relocatable)
  2026. + {
  2027. + /* This is a relocatable link. We don't have to change
  2028. + anything, unless the reloc is against a section symbol,
  2029. + in which case we have to adjust according to where the
  2030. + section symbol winds up in the output section. */
  2031. + if (r_symndx < symtab_hdr->sh_info)
  2032. + {
  2033. + sym = local_syms + r_symndx;
  2034. +
  2035. + if (ELF_ST_TYPE (sym->st_info) == STT_SECTION)
  2036. + {
  2037. + sec = local_sections[r_symndx];
  2038. + rel->r_addend += sec->output_offset + sym->st_value;
  2039. + }
  2040. + }
  2041. + continue;
  2042. + }
  2043. +
  2044. + /* This is a final link. */
  2045. + howto = lookup_howto ((unsigned) ELF32_R_TYPE (rel->r_info));
  2046. + h = NULL;
  2047. + sym = NULL;
  2048. + sec = NULL;
  2049. +
  2050. + if (r_symndx < symtab_hdr->sh_info)
  2051. + {
  2052. + sym = local_syms + r_symndx;
  2053. + sec = local_sections[r_symndx];
  2054. +
  2055. + relocation = (sec->output_section->vma
  2056. + + sec->output_offset + sym->st_value);
  2057. +
  2058. + // this ensures that relocations against duplicated symbols
  2059. + // in merged sections that have been removed are fixed up against
  2060. + // the remaining symbol and not the one that has been removed
  2061. + if ((sec->flags & SEC_MERGE)
  2062. + && ELF_ST_TYPE (sym->st_info) == STT_SECTION)
  2063. + {
  2064. + rel->r_addend =
  2065. + _bfd_elf_rel_local_sym (output_bfd, sym, &sec, rel->r_addend);
  2066. + rel->r_addend -= relocation;
  2067. + rel->r_addend += sec->output_section->vma + sec->output_offset;
  2068. + }
  2069. +
  2070. + name = bfd_elf_string_from_elf_section
  2071. + (input_bfd, symtab_hdr->sh_link, sym->st_name);
  2072. +
  2073. + name = (name == NULL) ? bfd_section_name (input_bfd, sec) : name;
  2074. + }
  2075. + else
  2076. + {
  2077. + h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  2078. +
  2079. + while (h->root.type == bfd_link_hash_indirect
  2080. + || h->root.type == bfd_link_hash_warning)
  2081. + h = (struct elf_link_hash_entry *) h->root.u.i.link;
  2082. +
  2083. + name = h->root.root.string;
  2084. +
  2085. + if (h->root.type == bfd_link_hash_defined
  2086. + || h->root.type == bfd_link_hash_defweak)
  2087. + {
  2088. + sec = h->root.u.def.section;
  2089. +
  2090. + relocation = (h->root.u.def.value
  2091. + + sec->output_section->vma + sec->output_offset);
  2092. + }
  2093. + else if (h->root.type == bfd_link_hash_undefweak)
  2094. + {
  2095. + relocation = 0;
  2096. + }
  2097. + else
  2098. + {
  2099. + if (!((*info->callbacks->undefined_symbol)
  2100. + (info, h->root.root.string, input_bfd,
  2101. + input_section, rel->r_offset, TRUE)))
  2102. + return FALSE;
  2103. + relocation = 0;
  2104. + }
  2105. + }
  2106. +
  2107. + if (howto != NULL)
  2108. + {
  2109. + switch (howto->type)
  2110. + {
  2111. + case R_NIOS2_HI16:
  2112. + r =
  2113. + nios2_elf32_do_hi16_relocate (input_bfd, howto, input_section,
  2114. + contents, rel->r_offset,
  2115. + relocation, rel->r_addend);
  2116. + break;
  2117. + case R_NIOS2_LO16:
  2118. + r =
  2119. + nios2_elf32_do_lo16_relocate (input_bfd, howto, input_section,
  2120. + contents, rel->r_offset,
  2121. + relocation, rel->r_addend);
  2122. + break;
  2123. + case R_NIOS2_HIADJ16:
  2124. + r =
  2125. + nios2_elf32_do_hiadj16_relocate (input_bfd, howto,
  2126. + input_section, contents,
  2127. + rel->r_offset, relocation,
  2128. + rel->r_addend);
  2129. + break;
  2130. + case R_NIOS2_PCREL16:
  2131. + r =
  2132. + nios2_elf32_do_pcrel16_relocate (input_bfd, howto,
  2133. + input_section, contents,
  2134. + rel->r_offset, relocation,
  2135. + rel->r_addend);
  2136. + break;
  2137. + case R_NIOS2_GPREL:
  2138. + // turns an absolute address into a gp-relative address
  2139. + if (!nios2_elf_assign_gp (output_bfd, &gp, info))
  2140. + {
  2141. + msg =
  2142. + _
  2143. + ("global pointer relative relocation when _gp not defined");
  2144. + r = bfd_reloc_dangerous;
  2145. + }
  2146. + else
  2147. + {
  2148. + relocation = relocation + rel->r_addend - gp;
  2149. + rel->r_addend = 0;
  2150. + if ((signed) relocation < -32768
  2151. + || (signed) relocation > 32767)
  2152. + {
  2153. + msg = _("global pointer relative address out of range");
  2154. + r = bfd_reloc_outofrange;
  2155. + }
  2156. + else
  2157. + {
  2158. + r =
  2159. + _bfd_final_link_relocate (howto, input_bfd,
  2160. + input_section, contents,
  2161. + rel->r_offset, relocation,
  2162. + rel->r_addend);
  2163. + }
  2164. + }
  2165. +
  2166. + break;
  2167. + case R_NIOS2_UJMP:
  2168. + r =
  2169. + nios2_elf32_do_ujmp_relocate (input_bfd, howto, input_section,
  2170. + contents, rel->r_offset,
  2171. + relocation, rel->r_addend);
  2172. + break;
  2173. + case R_NIOS2_CJMP:
  2174. + r =
  2175. + nios2_elf32_do_cjmp_relocate (input_bfd, howto, input_section,
  2176. + contents, rel->r_offset,
  2177. + relocation, rel->r_addend);
  2178. + break;
  2179. + case R_NIOS2_CALLR:
  2180. + r =
  2181. + nios2_elf32_do_callr_relocate (input_bfd, howto,
  2182. + input_section, contents,
  2183. + rel->r_offset, relocation,
  2184. + rel->r_addend);
  2185. + break;
  2186. + case R_NIOS2_CALL26:
  2187. + r =
  2188. + nios2_elf32_do_call26_relocate (input_bfd, howto,
  2189. + input_section, contents,
  2190. + rel->r_offset, relocation,
  2191. + rel->r_addend);
  2192. + break;
  2193. + case R_NIOS2_ALIGN:
  2194. + r = bfd_reloc_ok;
  2195. + /* comment - for symmetry this would be
  2196. + r = nios2_elf32_do_ignore_reloc (input_bfd, howto, input_section,
  2197. + contents, rel->r_offset,
  2198. + relocation, rel->r_addend);
  2199. + but do_ignore_reloc would do no more than return bfd_reloc_ok */
  2200. + break;
  2201. + default:
  2202. + r = _bfd_final_link_relocate (howto, input_bfd, input_section,
  2203. + contents, rel->r_offset,
  2204. + relocation, rel->r_addend);
  2205. + break;
  2206. + }
  2207. + }
  2208. + else
  2209. + {
  2210. + r = bfd_reloc_notsupported;
  2211. + }
  2212. +
  2213. + if (r != bfd_reloc_ok)
  2214. + {
  2215. + if (h != NULL)
  2216. + name = h->root.root.string;
  2217. + else
  2218. + {
  2219. + name = (bfd_elf_string_from_elf_section
  2220. + (input_bfd, symtab_hdr->sh_link, sym->st_name));
  2221. + if (name == NULL || *name == '\0')
  2222. + name = bfd_section_name (input_bfd, sec);
  2223. + }
  2224. +
  2225. + switch (r)
  2226. + {
  2227. + case bfd_reloc_overflow:
  2228. + r = info->callbacks->reloc_overflow
  2229. + (info, (h ? &h->root : NULL), name, howto->name, (bfd_vma) 0,
  2230. + input_bfd, input_section, rel->r_offset);
  2231. + break;
  2232. +
  2233. + case bfd_reloc_undefined:
  2234. + r = info->callbacks->undefined_symbol
  2235. + (info, name, input_bfd, input_section, rel->r_offset, TRUE);
  2236. + break;
  2237. +
  2238. + case bfd_reloc_outofrange:
  2239. + if (msg == NULL)
  2240. + msg = _("relocation out of range");
  2241. + break;
  2242. +
  2243. + case bfd_reloc_notsupported:
  2244. + if (msg == NULL)
  2245. + msg = _("unsupported relocation");
  2246. + break;
  2247. +
  2248. + case bfd_reloc_dangerous:
  2249. + if (msg == NULL)
  2250. + msg = _("dangerous relocation");
  2251. + break;
  2252. +
  2253. + default:
  2254. + if (msg == NULL)
  2255. + msg = _("unknown error");
  2256. + break;
  2257. + }
  2258. +
  2259. + if (msg)
  2260. + {
  2261. + r = info->callbacks->warning
  2262. + (info, msg, name, input_bfd, input_section, rel->r_offset);
  2263. + return linker_force_make_executable;
  2264. + }
  2265. + }
  2266. + }
  2267. + return TRUE;
  2268. +}
  2269. +
  2270. +
  2271. +
  2272. +/* Handle an NIOS2 specific section when reading an object file. This
  2273. + is called when elfcode.h finds a section with an unknown type.
  2274. + FIXME: We need to handle the SHF_NIOS2_GPREL flag */
  2275. +
  2276. +static bfd_boolean
  2277. +nios2_elf32_section_from_shdr (bfd *abfd,
  2278. + Elf_Internal_Shdr *hdr, const char *name, int shindex)
  2279. +{
  2280. + asection *newsect;
  2281. +
  2282. + /* NG - I'm keeping this code commented out at the moment
  2283. + in case we add a .mdebug section */
  2284. +
  2285. + /*
  2286. + switch (hdr->sh_type)
  2287. + {
  2288. + case SHT_NIOS2_DEBUG:
  2289. + if (strcmp (name, ".mdebug") != 0)
  2290. + return FALSE;
  2291. + break;
  2292. + default:
  2293. + return FALSE;
  2294. + }
  2295. + */
  2296. +
  2297. + if (!_bfd_elf_make_section_from_shdr (abfd, hdr, name, shindex))
  2298. + return FALSE;
  2299. +
  2300. + newsect = hdr->bfd_section;
  2301. +
  2302. + /* ditto */
  2303. + /*
  2304. + if (hdr->sh_type == SHT_NIOS2_DEBUG)
  2305. + {
  2306. + if (! bfd_set_section_flags (abfd, newsect,
  2307. + (bfd_get_section_flags (abfd, newsect)
  2308. + | SEC_DEBUGGING)))
  2309. + return FALSE;
  2310. + }
  2311. + */
  2312. + return TRUE;
  2313. +}
  2314. +
  2315. +/* Convert NIOS2 specific section flags to bfd internal section flags. */
  2316. +
  2317. +static bfd_boolean
  2318. +nios2_elf32_section_flags (flagword *flags, const Elf_Internal_Shdr *hdr)
  2319. +{
  2320. + if (hdr->sh_flags & SHF_NIOS2_GPREL)
  2321. + *flags |= SEC_SMALL_DATA;
  2322. +
  2323. + return TRUE;
  2324. +}
  2325. +
  2326. +/* Set the correct type for an NIOS2 ELF section. We do this by the
  2327. + section name, which is a hack, but ought to work. */
  2328. +
  2329. +static bfd_boolean
  2330. +nios2_elf32_fake_sections (bfd *abfd ATTRIBUTE_UNUSED,
  2331. + Elf_Internal_Shdr *hdr, asection *sec)
  2332. +{
  2333. + register const char *name;
  2334. +
  2335. + name = bfd_get_section_name (abfd, sec);
  2336. +
  2337. + if (strcmp (name, ".mdebug") == 0)
  2338. + {
  2339. + /* we don't yet have an .mdebug section, but I'm leaving this here
  2340. + in case we ever do
  2341. + hdr->sh_type = SHT_NIOS2_DEBUG;
  2342. +
  2343. + if ((abfd->flags & DYNAMIC) != 0 )
  2344. + hdr->sh_entsize = 0;
  2345. + else
  2346. + hdr->sh_entsize = 1;
  2347. + */
  2348. + }
  2349. + else if ((sec->flags & SEC_SMALL_DATA)
  2350. + || strcmp (name, ".sdata") == 0
  2351. + || strcmp (name, ".sbss") == 0
  2352. + || strcmp (name, ".lit4") == 0 || strcmp (name, ".lit8") == 0)
  2353. + hdr->sh_flags |= SHF_NIOS2_GPREL;
  2354. +
  2355. + return TRUE;
  2356. +}
  2357. +
  2358. +/* Look through the relocs for a section during the first phase.
  2359. + Since we don't do .gots or .plts, we just need to consider the
  2360. + virtual table relocs for gc. */
  2361. +
  2362. +static bfd_boolean
  2363. +nios2_elf32_check_relocs (bfd *abfd, struct bfd_link_info *info,
  2364. + asection *sec, const Elf_Internal_Rela *relocs)
  2365. +{
  2366. + Elf_Internal_Shdr *symtab_hdr;
  2367. + struct elf_link_hash_entry **sym_hashes, **sym_hashes_end;
  2368. + const Elf_Internal_Rela *rel;
  2369. + const Elf_Internal_Rela *rel_end;
  2370. +
  2371. + if (info->relocatable)
  2372. + return TRUE;
  2373. +
  2374. + symtab_hdr = &elf_tdata (abfd)->symtab_hdr;
  2375. + sym_hashes = elf_sym_hashes (abfd);
  2376. + sym_hashes_end =
  2377. + sym_hashes + symtab_hdr->sh_size / sizeof (Elf32_External_Sym);
  2378. + if (!elf_bad_symtab (abfd))
  2379. + sym_hashes_end -= symtab_hdr->sh_info;
  2380. +
  2381. + rel_end = relocs + sec->reloc_count;
  2382. + for (rel = relocs; rel < rel_end; rel++)
  2383. + {
  2384. + struct elf_link_hash_entry *h;
  2385. + unsigned long r_symndx;
  2386. +
  2387. + r_symndx = ELF32_R_SYM (rel->r_info);
  2388. + if (r_symndx < symtab_hdr->sh_info)
  2389. + h = NULL;
  2390. + else
  2391. + h = sym_hashes[r_symndx - symtab_hdr->sh_info];
  2392. +
  2393. + switch (ELF32_R_TYPE (rel->r_info))
  2394. + {
  2395. + /* This relocation describes the C++ object vtable hierarchy.
  2396. + Reconstruct it for later use during GC. */
  2397. + case R_NIOS2_GNU_VTINHERIT:
  2398. + if (!bfd_elf_gc_record_vtinherit (abfd, sec, h, rel->r_offset))
  2399. + return FALSE;
  2400. + break;
  2401. +
  2402. + /* This relocation describes which C++ vtable entries are actually
  2403. + used. Record for later use during GC. */
  2404. + case R_NIOS2_GNU_VTENTRY:
  2405. + if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend))
  2406. + return FALSE;
  2407. + break;
  2408. + }
  2409. + }
  2410. +
  2411. + return TRUE;
  2412. +}
  2413. +
  2414. +
  2415. +/* Return the section that should be marked against GC for a given
  2416. + relocation. */
  2417. +
  2418. +asection *
  2419. +nios2_elf32_gc_mark_hook (asection *sec,
  2420. + struct bfd_link_info *info ATTRIBUTE_UNUSED,
  2421. + Elf_Internal_Rela *rel, struct elf_link_hash_entry *h,
  2422. + Elf_Internal_Sym *sym)
  2423. +{
  2424. + if (h != NULL)
  2425. + {
  2426. + switch (ELF32_R_TYPE (rel->r_info))
  2427. + {
  2428. + case R_NIOS2_GNU_VTINHERIT:
  2429. + case R_NIOS2_GNU_VTENTRY:
  2430. + break;
  2431. +
  2432. + default:
  2433. + switch (h->root.type)
  2434. + {
  2435. + case bfd_link_hash_defined:
  2436. + case bfd_link_hash_defweak:
  2437. + return h->root.u.def.section;
  2438. +
  2439. + case bfd_link_hash_common:
  2440. + return h->root.u.c.p->section;
  2441. +
  2442. + default:
  2443. + break;
  2444. + }
  2445. + }
  2446. + }
  2447. + else
  2448. + return bfd_section_from_elf_index (sec->owner, sym->st_shndx);
  2449. +
  2450. + return NULL;
  2451. +}
  2452. +
  2453. +/*
  2454. + NG ??? I'm marking the sections as standalone ie. I'm linking for
  2455. + standalone embedded applications, not for UNIX System V or any other
  2456. + OS/ABI - this may need to change when we deal with embedded PIC or
  2457. + dynamic linking
  2458. +*/
  2459. +
  2460. +static void
  2461. +nios2_elf32_post_process_headers (bfd *abfd,
  2462. + struct bfd_link_info *link_info ATTRIBUTE_UNUSED)
  2463. +{
  2464. + Elf_Internal_Ehdr *i_ehdrp; /* Elf file header, internal form */
  2465. +
  2466. + i_ehdrp = elf_elfheader (abfd);
  2467. + i_ehdrp->e_ident[EI_OSABI] = ELFOSABI_STANDALONE;
  2468. +}
  2469. +
  2470. +#define ELF_ARCH bfd_arch_nios2
  2471. +#define ELF_MACHINE_CODE EM_ALTERA_NIOS2
  2472. +
  2473. +/* for now we just make this 1, as we have no MMU in New Jersey */
  2474. +
  2475. +#define ELF_MAXPAGESIZE 1
  2476. +
  2477. +/* relocation table lookup macros */
  2478. +
  2479. +#define bfd_elf32_bfd_reloc_type_lookup nios2_elf32_bfd_reloc_type_lookup
  2480. +
  2481. +/* JUMP_TABLE_LINK macros */
  2482. +
  2483. +#define bfd_elf32_bfd_relax_section nios2_elf32_relax_section
  2484. +
  2485. +/* elf_info_to_howto (using RELA relocations) */
  2486. +
  2487. +#define elf_info_to_howto nios2_elf32_info_to_howto
  2488. +
  2489. +/* elf backend functions */
  2490. +
  2491. +#define elf_backend_can_gc_sections 1
  2492. +
  2493. +#define elf_backend_relocate_section nios2_elf32_relocate_section
  2494. +#define elf_backend_section_from_shdr nios2_elf32_section_from_shdr
  2495. +#define elf_backend_section_flags nios2_elf32_section_flags
  2496. +#define elf_backend_fake_sections nios2_elf32_fake_sections
  2497. +#define elf_backend_post_process_headers nios2_elf32_post_process_headers
  2498. +#define elf_backend_check_relocs nios2_elf32_check_relocs
  2499. +
  2500. +#define elf_backend_gc_mark_hook nios2_elf32_gc_mark_hook
  2501. +
  2502. +
  2503. +
  2504. +/* Support for SGI-ish mips targets. */
  2505. +#define TARGET_LITTLE_SYM bfd_elf32_littlenios2_vec
  2506. +#define TARGET_LITTLE_NAME "elf32-littlenios2"
  2507. +#define TARGET_BIG_SYM bfd_elf32_bignios2_vec
  2508. +#define TARGET_BIG_NAME "elf32-bignios2"
  2509. +
  2510. +#include "elf32-target.h"
  2511. diff --git a/bfd/reloc.c b/bfd/reloc.c
  2512. index 1b8c8d7..c66a23d 100644
  2513. --- a/bfd/reloc.c
  2514. +++ b/bfd/reloc.c
  2515. @@ -4733,6 +4733,39 @@ ENUMDOC
  2516. msp430 specific relocation codes
  2517. ENUM
  2518. + BFD_RELOC_NIOS2_S16
  2519. +ENUMX
  2520. + BFD_RELOC_NIOS2_U16
  2521. +ENUMX
  2522. + BFD_RELOC_NIOS2_CALL26
  2523. +ENUMX
  2524. + BFD_RELOC_NIOS2_IMM5
  2525. +ENUMX
  2526. + BFD_RELOC_NIOS2_CACHE_OPX
  2527. +ENUMX
  2528. + BFD_RELOC_NIOS2_IMM6
  2529. +ENUMX
  2530. + BFD_RELOC_NIOS2_IMM8
  2531. +ENUMX
  2532. + BFD_RELOC_NIOS2_HI16
  2533. +ENUMX
  2534. + BFD_RELOC_NIOS2_LO16
  2535. +ENUMX
  2536. + BFD_RELOC_NIOS2_HIADJ16
  2537. +ENUMX
  2538. + BFD_RELOC_NIOS2_GPREL
  2539. +ENUMX
  2540. + BFD_RELOC_NIOS2_UJMP
  2541. +ENUMX
  2542. + BFD_RELOC_NIOS2_CJMP
  2543. +ENUMX
  2544. + BFD_RELOC_NIOS2_CALLR
  2545. +ENUMX
  2546. + BFD_RELOC_NIOS2_ALIGN
  2547. +ENUMDOC
  2548. + Relocations used by the Altera Nios II core
  2549. +
  2550. +ENUM
  2551. BFD_RELOC_IQ2000_OFFSET_16
  2552. ENUMX
  2553. BFD_RELOC_IQ2000_OFFSET_21
  2554. diff --git a/bfd/targets.c b/bfd/targets.c
  2555. index 71e3337..d5f6d60 100644
  2556. --- a/bfd/targets.c
  2557. +++ b/bfd/targets.c
  2558. @@ -619,6 +619,8 @@ extern const bfd_target bfd_elf32_ntradbigmips_vec;
  2559. extern const bfd_target bfd_elf32_ntradlittlemips_vec;
  2560. extern const bfd_target bfd_elf32_openrisc_vec;
  2561. extern const bfd_target bfd_elf32_or32_big_vec;
  2562. +extern const bfd_target bfd_elf32_littlenios2_vec;
  2563. +extern const bfd_target bfd_elf32_bignios2_vec;
  2564. extern const bfd_target bfd_elf32_pj_vec;
  2565. extern const bfd_target bfd_elf32_pjl_vec;
  2566. extern const bfd_target bfd_elf32_powerpc_vec;
  2567. @@ -819,6 +821,8 @@ extern const bfd_target sco5_core_vec;
  2568. extern const bfd_target trad_core_vec;
  2569. extern const bfd_target bfd_elf32_am33lin_vec;
  2570. +extern const bfd_target bfd_elf32_littlenios2_vec;
  2571. +extern const bfd_target bfd_elf32_bignios2_vec;
  2572. static const bfd_target * const _bfd_target_vector[] =
  2573. {
  2574. #ifdef SELECT_VECS
  2575. @@ -923,6 +927,8 @@ static const bfd_target * const _bfd_target_vector[] =
  2576. &bfd_elf32_littlearm_vxworks_vec,
  2577. &bfd_elf32_littlemips_vec,
  2578. &bfd_elf32_littlemips_vxworks_vec,
  2579. + &bfd_elf32_littlenios2_vec,
  2580. + &bfd_elf32_bignios2_vec,
  2581. &bfd_elf32_m32c_vec,
  2582. &bfd_elf32_m32r_vec,
  2583. &bfd_elf32_m32rle_vec,
  2584. diff --git a/config.sub b/config.sub
  2585. index fab0aa3..462e7c6 100755
  2586. --- a/config.sub
  2587. +++ b/config.sub
  2588. @@ -270,7 +270,7 @@ case $basic_machine in
  2589. | mn10200 | mn10300 \
  2590. | mt \
  2591. | msp430 \
  2592. - | nios | nios2 \
  2593. + | nios2 | nios2eb | nios2el \
  2594. | ns16k | ns32k \
  2595. | or32 \
  2596. | pdp10 | pdp11 | pj | pjl \
  2597. diff --git a/configure.in b/configure.in
  2598. index a4befda..f2e34c7 100644
  2599. --- a/configure.in
  2600. +++ b/configure.in
  2601. @@ -740,6 +740,9 @@ case "${target}" in
  2602. mips*-*-*)
  2603. noconfigdirs="$noconfigdirs gprof ${libgcj}"
  2604. ;;
  2605. + nios2*-*-*)
  2606. + noconfigdirs="$noconfigdirs ld"
  2607. + ;;
  2608. romp-*-*)
  2609. noconfigdirs="$noconfigdirs bfd binutils ld gas opcodes target-libgloss ${libgcj}"
  2610. ;;
  2611. diff --git a/gdb/Makefile.in b/gdb/Makefile.in
  2612. index 14fd58b..eac9489 100644
  2613. --- a/gdb/Makefile.in
  2614. +++ b/gdb/Makefile.in
  2615. @@ -593,6 +593,7 @@ libiberty_h = $(INCLUDE_DIR)/libiberty.h
  2616. libbfd_h = $(BFD_SRC)/libbfd.h
  2617. remote_sim_h = $(INCLUDE_DIR)/gdb/remote-sim.h
  2618. demangle_h = $(INCLUDE_DIR)/demangle.h
  2619. +nios2_h = $(INCLUDE_DIR)/opcode/nios2.h
  2620. obstack_h = $(INCLUDE_DIR)/obstack.h
  2621. opcode_m68hc11_h = $(INCLUDE_DIR)/opcode/m68hc11.h
  2622. readline_h = $(READLINE_SRC)/readline.h
  2623. @@ -2399,6 +2400,7 @@ ms1-tdep.o: ms1-tdep.c $(defs_h) $(frame_h) $(frame_unwind_h) $(frame_base_h) \
  2624. $(trad_frame_h) $(inferior_h) $(dwarf2_frame_h) $(infcall_h) \
  2625. $(gdb_assert_h)
  2626. nbsd-tdep.o: nbsd-tdep.c $(defs_h) $(gdb_string_h) $(solib_svr4_h)
  2627. +nios2-tdep.o: nios2-tdep.c $(defs_h) $(symtab_h) $(frame_h) $(nios2_h)
  2628. nlmread.o: nlmread.c $(defs_h) $(bfd_h) $(symtab_h) $(symfile_h) \
  2629. $(objfiles_h) $(buildsym_h) $(stabsread_h) $(block_h)
  2630. nto-procfs.o: nto-procfs.c $(defs_h) $(gdb_dirent_h) $(exceptions_h) \
  2631. diff --git a/gdb/config/nios2/nios2.mt b/gdb/config/nios2/nios2.mt
  2632. new file mode 100644
  2633. index 0000000..63413b4
  2634. --- /dev/null
  2635. +++ b/gdb/config/nios2/nios2.mt
  2636. @@ -0,0 +1,4 @@
  2637. +# Target: Altera New Jersey Processor machine (NIOS2)
  2638. +TDEPFILES= nios2-tdep.o
  2639. +
  2640. +
  2641. diff --git a/gdb/config/nios2/tm-nios2.h b/gdb/config/nios2/tm-nios2.h
  2642. new file mode 100644
  2643. index 0000000..2962b6b
  2644. --- /dev/null
  2645. +++ b/gdb/config/nios2/tm-nios2.h
  2646. @@ -0,0 +1,28 @@
  2647. +/* Definitions to target GDB to New Jersey targets.
  2648. + Copyright 1986, 1987, 1988, 1989, 1991, 1993, 1994,
  2649. + 1995, 1996, 1997, 1998, 1999, 2000, 2003
  2650. + by Peter Brookes (pbrookes@altera.com)
  2651. +
  2652. + This file is part of GDB.
  2653. +
  2654. + This program is free software; you can redistribute it and/or modify
  2655. + it under the terms of the GNU General Public License as published by
  2656. + the Free Software Foundation; either version 2 of the License, or
  2657. + (at your option) any later version.
  2658. +
  2659. + This program is distributed in the hope that it will be useful,
  2660. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2661. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2662. + GNU General Public License for more details.
  2663. +
  2664. + You should have received a copy of the GNU General Public License
  2665. + along with this program; if not, write to the Free Software
  2666. + Foundation, Inc., 59 Temple Place - Suite 330,
  2667. + Boston, MA 02111-1307, USA. */
  2668. +
  2669. +#ifndef TM_NIOS2_H
  2670. +#define TM_NIOS2_H
  2671. +
  2672. +#define GDB_MULTI_ARCH 1
  2673. +
  2674. +#endif /* TM_NIOS2_H */
  2675. diff --git a/gdb/configure.tgt b/gdb/configure.tgt
  2676. index dd2e719..7222f59 100644
  2677. --- a/gdb/configure.tgt
  2678. +++ b/gdb/configure.tgt
  2679. @@ -20,6 +20,7 @@ m68hc11*|m6811*) gdb_target_cpu=m68hc11 ;;
  2680. m68*) gdb_target_cpu=m68k ;;
  2681. m88*) gdb_target_cpu=m88k ;;
  2682. mips*) gdb_target_cpu=mips ;;
  2683. +nios2*) gdb_target_cpu=nios2 ;;
  2684. powerpc*) gdb_target_cpu=powerpc ;;
  2685. sparc*) gdb_target_cpu=sparc ;;
  2686. thumb*) gdb_target_cpu=arm ;;
  2687. @@ -155,6 +156,8 @@ mn10300-*-*) gdb_target=mn10300 ;;
  2688. mt-*-*) gdb_target=mt ;;
  2689. +nios2*-*-*) gdb_target=nios2 ;;
  2690. +
  2691. powerpc-*-netbsd* | powerpc-*-knetbsd*-gnu)
  2692. gdb_target=nbsd ;;
  2693. powerpc-*-openbsd*) gdb_target=obsd ;;
  2694. diff --git a/gdb/gdbserver/Makefile.in b/gdb/gdbserver/Makefile.in
  2695. index 9748c95..b3fb5f8 100644
  2696. --- a/gdb/gdbserver/Makefile.in
  2697. +++ b/gdb/gdbserver/Makefile.in
  2698. @@ -280,6 +280,7 @@ linux-ia64-low.o: linux-ia64-low.c $(linux_low_h) $(server_h)
  2699. linux-m32r-low.o: linux-m32r-low.c $(linux_low_h) $(server_h)
  2700. linux-mips-low.o: linux-mips-low.c $(linux_low_h) $(server_h) \
  2701. $(gdb_proc_service_h)
  2702. +linux-nios2-low.o: linux-nios2-low.c $(linux_low_h) $(server_h)
  2703. linux-ppc-low.o: linux-ppc-low.c $(linux_low_h) $(server_h)
  2704. linux-ppc64-low.o: linux-ppc64-low.c $(linux_low_h) $(server_h)
  2705. linux-s390-low.o: linux-s390-low.c $(linux_low_h) $(server_h)
  2706. @@ -318,6 +319,9 @@ reg-m68k.c : $(srcdir)/../regformats/reg-m68k.dat $(regdat_sh)
  2707. reg-mips.o : reg-mips.c $(regdef_h)
  2708. reg-mips.c : $(srcdir)/../regformats/reg-mips.dat $(regdat_sh)
  2709. sh $(regdat_sh) $(srcdir)/../regformats/reg-mips.dat reg-mips.c
  2710. +reg-nios2.o : reg-nios2.c $(regdef_h)
  2711. +reg-nios2.c : $(srcdir)/../regformats/reg-nios2.dat $(regdat_sh)
  2712. + sh $(regdat_sh) $(srcdir)/../regformats/reg-nios2.dat reg-nios2.c
  2713. reg-ppc.o : reg-ppc.c $(regdef_h)
  2714. reg-ppc.c : $(srcdir)/../regformats/reg-ppc.dat $(regdat_sh)
  2715. sh $(regdat_sh) $(srcdir)/../regformats/reg-ppc.dat reg-ppc.c
  2716. diff --git a/gdb/gdbserver/configure.srv b/gdb/gdbserver/configure.srv
  2717. index 5a4792c..fdc847c 100644
  2718. --- a/gdb/gdbserver/configure.srv
  2719. +++ b/gdb/gdbserver/configure.srv
  2720. @@ -72,6 +72,10 @@ case "${target}" in
  2721. srv_linux_usrregs=yes
  2722. srv_linux_thread_db=yes
  2723. ;;
  2724. + nios2-*-linux*) srv_regobj=reg-nios2.o
  2725. + srv_tgtobj="linux-low.o linux-nios2-low.o"
  2726. + srv_linux_usrregs=yes
  2727. + ;;
  2728. powerpc64-*-linux*) srv_regobj=reg-ppc64.o
  2729. srv_tgtobj="linux-low.o linux-ppc64-low.o"
  2730. srv_linux_usrregs=yes
  2731. diff --git a/gdb/gdbserver/linux-nios2-low.c b/gdb/gdbserver/linux-nios2-low.c
  2732. new file mode 100644
  2733. index 0000000..1fab749
  2734. --- /dev/null
  2735. +++ b/gdb/gdbserver/linux-nios2-low.c
  2736. @@ -0,0 +1,89 @@
  2737. +/* GNU/Linux/Nios2 specific low level interface for the remote server for GDB */
  2738. +
  2739. +#include "server.h"
  2740. +#include "linux-low.h"
  2741. +
  2742. +#ifdef HAVE_SYS_REG_H
  2743. +#include <sys/reg.h>
  2744. +#endif
  2745. +
  2746. +#include <asm/ptrace.h>
  2747. +
  2748. +static int nios2_regmap[] =
  2749. +{
  2750. + -1, PTR_R1 * 4, PTR_R2 * 4, PTR_R3 * 4,
  2751. + PTR_R4 * 4, PTR_R5 * 4, PTR_R6 * 4, PTR_R7 * 4,
  2752. + PTR_R8 * 4, PTR_R9 * 4, PTR_R10 * 4, PTR_R11 * 4,
  2753. + PTR_R12 * 4, PTR_R13 * 4, PTR_R14 * 4, PTR_R15 * 4, /* reg 15 */
  2754. + PTR_R16 * 4, PTR_R17 * 4, PTR_R18 * 4, PTR_R19 * 4,
  2755. + PTR_R20 * 4, PTR_R21 * 4, PTR_R22 * 4, PTR_R23 * 4,
  2756. + -1, -1, PTR_GP * 4, PTR_SP * 4,
  2757. + PTR_FP * 4, -1, -1, PTR_RA * 4, /* reg 31 */
  2758. + PTR_PC * 4, -1, -1, -1,
  2759. + -1, -1, -1, -1,
  2760. + -1, -1, -1, -1
  2761. +};
  2762. +
  2763. +#define nios2_num_regs (sizeof(nios2_regmap) / sizeof(nios2_regmap[0]))
  2764. +
  2765. +static int
  2766. +nios2_cannot_store_register (int regno)
  2767. +{
  2768. + return (regno >= 33);
  2769. +}
  2770. +
  2771. +static int
  2772. +nios2_cannot_fetch_register (int regno)
  2773. +{
  2774. + return (regno >= 33);
  2775. +}
  2776. +
  2777. +static CORE_ADDR
  2778. +nios2_get_pc ()
  2779. +{
  2780. + unsigned long pc;
  2781. + collect_register_by_name ("pc", &pc);
  2782. + return pc;
  2783. +}
  2784. +
  2785. +static void
  2786. +nios2_set_pc (CORE_ADDR pc)
  2787. +{
  2788. + unsigned long newpc = pc;
  2789. + supply_register_by_name ("pc", &newpc);
  2790. +}
  2791. +
  2792. +#if 0
  2793. +static const unsigned long nios2_breakpoint = 0x003da03a;
  2794. +#else
  2795. +static const unsigned long nios2_breakpoint = 0x003b687a; /* Trap instr. w/imm=0x01 */
  2796. +#endif
  2797. +#define nios2_breakpoint_len 4
  2798. +
  2799. +static int
  2800. +nios2_breakpoint_at (CORE_ADDR where)
  2801. +{
  2802. + unsigned long insn;
  2803. +
  2804. + (*the_target->read_memory) (where, (char *) &insn, nios2_breakpoint_len);
  2805. + if (insn == nios2_breakpoint)
  2806. + return 1;
  2807. +
  2808. + /* If necessary, recognize more trap instructions here. GDB only uses the
  2809. + one. */
  2810. + return 0;
  2811. +}
  2812. +
  2813. +struct linux_target_ops the_low_target = {
  2814. + nios2_num_regs,
  2815. + nios2_regmap,
  2816. + nios2_cannot_fetch_register,
  2817. + nios2_cannot_store_register,
  2818. + nios2_get_pc,
  2819. + nios2_set_pc,
  2820. + (const char *) &nios2_breakpoint,
  2821. + nios2_breakpoint_len,
  2822. + NULL,
  2823. + 0,
  2824. + nios2_breakpoint_at,
  2825. +};
  2826. diff --git a/gdb/nios2-tdep.c b/gdb/nios2-tdep.c
  2827. new file mode 100644
  2828. index 0000000..e0712dd
  2829. --- /dev/null
  2830. +++ b/gdb/nios2-tdep.c
  2831. @@ -0,0 +1,1610 @@
  2832. +/* Target-machine dependent code for Nios2, for GDB.
  2833. + Copyright (C) 2003-2005
  2834. + by Peter Brookes (pbrookes@altera.com)
  2835. + and Andrew Draper (adraper@altera.com)
  2836. +
  2837. + This file is part of GDB.
  2838. +
  2839. + This program is free software; you can redistribute it and/or modify
  2840. + it under the terms of the GNU General Public License as published by
  2841. + the Free Software Foundation; either version 2 of the License, or
  2842. + (at your option) any later version.
  2843. +
  2844. + This program is distributed in the hope that it will be useful,
  2845. + but WITHOUT ANY WARRANTY; without even the implied warranty of
  2846. + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2847. + GNU General Public License for more details.
  2848. +
  2849. + You should have received a copy of the GNU General Public License
  2850. + along with this program; if not, write to the Free Software
  2851. + Foundation, Inc., 59 Temple Place - Suite 330,
  2852. + Boston, MA 02111-1307, USA. */
  2853. +
  2854. +#include "defs.h"
  2855. +#include "frame.h"
  2856. +#include "frame-unwind.h"
  2857. +#include "frame-base.h"
  2858. +#include "trad-frame.h"
  2859. +#include "dwarf2-frame.h"
  2860. +#include "symtab.h"
  2861. +#include "inferior.h"
  2862. +#include "gdbtypes.h"
  2863. +#include "gdbcore.h"
  2864. +#include "gdbcmd.h"
  2865. +#include "target.h"
  2866. +#include "dis-asm.h"
  2867. +#include "regcache.h"
  2868. +#include "value.h"
  2869. +#include "symfile.h"
  2870. +#include "arch-utils.h"
  2871. +#include "floatformat.h"
  2872. +#include "gdb_assert.h"
  2873. +
  2874. +/* To get entry_point_address. */
  2875. +#include "objfiles.h"
  2876. +
  2877. +/* Nios II ISA specific encodings and macros */
  2878. +#include "opcode/nios2.h"
  2879. +
  2880. +/* Macros */
  2881. +
  2882. +#define Z_REGNUM 0 /* Zero */
  2883. +#define R2_REGNUM 2 /* used for return value */
  2884. +#define R3_REGNUM 3 /* used for return value */
  2885. +/* used for hidden zero argument to store ptr to struct return value */
  2886. +#define R4_REGNUM 4
  2887. +#define R7_REGNUM 7
  2888. +#define GP_REGNUM 26 /* Global Pointer */
  2889. +#undef SP_REGNUM
  2890. +#define SP_REGNUM 27 /* Stack Pointer */
  2891. +#undef FP_REGNUM
  2892. +#define FP_REGNUM 28 /* Frame Pointer */
  2893. +#define EA_REGNUM 29 /* Exception address */
  2894. +#define BA_REGNUM 30 /* Breakpoint return address */
  2895. +#define RA_REGNUM 31 /* Return address */
  2896. +#undef PC_REGNUM
  2897. +#define PC_REGNUM 32
  2898. +#define STATUS_REGNUM 33 /* Ctrl registers */
  2899. +#define ESTATUS_REGNUM 34
  2900. +#define BSTATUS_REGNUM 35
  2901. +#define IENABLE_REGNUM 36
  2902. +#define IPENDING_REGNUM 37
  2903. +#define CPUID_REGNUM 38
  2904. +#define PTEADDR_REGNUM 41
  2905. +#define TLBACC_REGNUM 42
  2906. +#define TLBMISC_REGNUM 43
  2907. +#define FIRST_ARGREG R4_REGNUM
  2908. +#define LAST_ARGREG R7_REGNUM
  2909. +/* Number of all registers */
  2910. +#define NIOS2_NUM_REGS (44)
  2911. +/* The maximum register number displayed to the user, */
  2912. +/* as a result of typing "info reg" at the gdb prompt */
  2913. +#define NIOS2_MAX_REG_DISPLAYED_REGNUM (38)
  2914. +
  2915. +#define NIOS2_OPCODE_SIZE 4
  2916. +
  2917. +/* Structures */
  2918. +struct register_info
  2919. +{
  2920. + int size;
  2921. + char *name;
  2922. + struct type **type;
  2923. +};
  2924. +
  2925. +/* The current value in the register is the value in r[base] at the start of
  2926. + * the function + offset ; unless base < 0 in which case it's unknown.
  2927. + */
  2928. +typedef struct
  2929. +{
  2930. + int reg;
  2931. + unsigned int offset;
  2932. +
  2933. +} REG_VALUE;
  2934. +
  2935. +
  2936. +typedef struct
  2937. +{
  2938. + int basereg;
  2939. + CORE_ADDR addr;
  2940. +
  2941. +} REG_SAVED;
  2942. +
  2943. +struct nios2_unwind_cache
  2944. +{
  2945. + /* The frame's base, optionally used by the high-level debug info. */
  2946. + CORE_ADDR base;
  2947. +
  2948. + /* The previous frame's inner most stack address. Used as this
  2949. + frame ID's stack_addr. */
  2950. + CORE_ADDR cfa;
  2951. +
  2952. + /* The address of the first instruction in this function */
  2953. + CORE_ADDR pc;
  2954. +
  2955. + /* Which register holds the return address for the frame. */
  2956. + int return_regnum;
  2957. +
  2958. + /* Table indicating what changes have been made to each register */
  2959. + REG_VALUE reg_value[NIOS2_NUM_REGS];
  2960. +
  2961. + /* Table indicating where each register has been saved. */
  2962. + REG_SAVED reg_saved[NIOS2_NUM_REGS];
  2963. +};
  2964. +
  2965. +
  2966. +/* Function prototypes */
  2967. +CORE_ADDR nios2_saved_pc_after_call (struct frame_info *fi);
  2968. +
  2969. +/* nios2_register_info_table[i] is the number of bytes of storage in
  2970. + GDB's register array occupied by register i. */
  2971. +static struct register_info nios2_register_info_table[] = {
  2972. + /* 0 */ {4, "zero", &builtin_type_uint32},
  2973. + /* 1 */ {4, "at", &builtin_type_uint32},
  2974. + /* 2 */ {4, "r2", &builtin_type_uint32},
  2975. + /* 3 */ {4, "r3", &builtin_type_uint32},
  2976. + /* 4 */ {4, "r4", &builtin_type_uint32},
  2977. + /* 5 */ {4, "r5", &builtin_type_uint32},
  2978. + /* 6 */ {4, "r6", &builtin_type_uint32},
  2979. + /* 7 */ {4, "r7", &builtin_type_uint32},
  2980. + /* 8 */ {4, "r8", &builtin_type_uint32},
  2981. + /* 9 */ {4, "r9", &builtin_type_uint32},
  2982. + /* 10 */ {4, "r10", &builtin_type_uint32},
  2983. + /* 11 */ {4, "r11", &builtin_type_uint32},
  2984. + /* 12 */ {4, "r12", &builtin_type_uint32},
  2985. + /* 13 */ {4, "r13", &builtin_type_uint32},
  2986. + /* 14 */ {4, "r14", &builtin_type_uint32},
  2987. + /* 15 */ {4, "r15", &builtin_type_uint32},
  2988. + /* 16 */ {4, "r16", &builtin_type_uint32},
  2989. + /* 17 */ {4, "r17", &builtin_type_uint32},
  2990. + /* 18 */ {4, "r18", &builtin_type_uint32},
  2991. + /* 19 */ {4, "r19", &builtin_type_uint32},
  2992. + /* 20 */ {4, "r20", &builtin_type_uint32},
  2993. + /* 21 */ {4, "r21", &builtin_type_uint32},
  2994. + /* 22 */ {4, "r22", &builtin_type_uint32},
  2995. + /* 23 */ {4, "r23", &builtin_type_uint32},
  2996. + /* 24 */ {4, "et", &builtin_type_uint32},
  2997. + /* 25 */ {4, "bt", &builtin_type_uint32},
  2998. + /* 26 */ {4, "gp", &builtin_type_uint32},
  2999. + /* 27 */ {4, "sp", &builtin_type_uint32},
  3000. + /* 28 */ {4, "fp", &builtin_type_uint32},
  3001. + /* 29 */ {4, "ea", &builtin_type_uint32},
  3002. + /* 30 */ {4, "ba", &builtin_type_uint32},
  3003. + /* 31 */ {4, "ra", &builtin_type_uint32},
  3004. + /* 32 */ {4, "pc", &builtin_type_uint32},
  3005. + /* 33 */ {4, "status", &builtin_type_uint32},
  3006. + /* 34 */ {4, "estatus", &builtin_type_uint32},
  3007. + /* 35 */ {4, "bstatus", &builtin_type_uint32},
  3008. + /* 36 */ {4, "ienable", &builtin_type_uint32},
  3009. + /* 37 */ {4, "ipending", &builtin_type_uint32},
  3010. + /* 38 */ {4, "cpuid", &builtin_type_uint32},
  3011. + /* 39 */ {4, "ctl6", &builtin_type_uint32},
  3012. + /* 40 */ {4, "ctl7", &builtin_type_uint32},
  3013. + /* 41 */ {4, "pteaddr", &builtin_type_uint32},
  3014. + /* 42 */ {4, "tlbacc", &builtin_type_uint32},
  3015. + /* 43 */ {4, "tlbmisc", &builtin_type_uint32}
  3016. +};
  3017. +
  3018. +/* This array is a mapping from Dwarf-2 register
  3019. + numbering to GDB's */
  3020. +static int nios2_dwarf2gdb_regno_map[] = {
  3021. + 0, 1, 2, 3,
  3022. + 4, 5, 6, 7,
  3023. + 8, 9, 10, 11,
  3024. + 12, 13, 14, 15,
  3025. + 16, 17, 18, 19,
  3026. + 20, 21, 22, 23,
  3027. + 24, 25,
  3028. + GP_REGNUM, /* 26 */
  3029. + SP_REGNUM, /* 27 */
  3030. + FP_REGNUM, /* 28 */
  3031. + EA_REGNUM, /* 29 */
  3032. + BA_REGNUM, /* 30 */
  3033. + RA_REGNUM, /* 31 */
  3034. + PC_REGNUM, /* 32 */
  3035. + STATUS_REGNUM, /* 33 */
  3036. + ESTATUS_REGNUM, /* 34 */
  3037. + BSTATUS_REGNUM, /* 35 */
  3038. + IENABLE_REGNUM, /* 36 */
  3039. + IPENDING_REGNUM, /* 37 */
  3040. + 38, 39, 40, 41, 42, 43
  3041. +};
  3042. +
  3043. +/* Dwarf-2 <-> GDB register numbers mapping. */
  3044. +int
  3045. +nios2_dwarf_reg_to_regnum (int dw_reg)
  3046. +{
  3047. + if (dw_reg < 0 || dw_reg > NIOS2_NUM_REGS)
  3048. + {
  3049. + warning ("Dwarf-2 uses unmapped register #%d\n", dw_reg);
  3050. + return dw_reg;
  3051. + }
  3052. +
  3053. + return nios2_dwarf2gdb_regno_map[dw_reg];
  3054. +}
  3055. +
  3056. +/* Same as read_memory_u6signed_integer, but don't report an error if
  3057. + can't read. */
  3058. +int
  3059. +nios2_read_memory_unsigned_integer (CORE_ADDR memaddr, int len, ULONGEST *ret)
  3060. +{
  3061. + char buf[sizeof (ULONGEST)];
  3062. + int error;
  3063. +
  3064. + error = target_read_memory (memaddr, buf, len);
  3065. + if (error != 0)
  3066. + return 0;
  3067. + else
  3068. + {
  3069. + *ret = extract_unsigned_integer (buf, len);
  3070. + return 1;
  3071. + }
  3072. +}
  3073. +
  3074. +/* Find the name for the specified NIOS2 regno */
  3075. +static const char *
  3076. +nios2_register_name (int regno)
  3077. +{
  3078. + /* Don't display any registers after NIOS2_MAX_REG_DISPLAYED_REGNUM */
  3079. + if (regno < 0)
  3080. + return NULL;
  3081. + else if (regno > NIOS2_MAX_REG_DISPLAYED_REGNUM)
  3082. + return NULL;
  3083. + return nios2_register_info_table[regno].name;
  3084. +}
  3085. +
  3086. +/* Returns the default type for register N. */
  3087. +static struct type *
  3088. +nios2_register_type (struct gdbarch *gdbarch, int regno)
  3089. +{
  3090. +/* FIXME Do we need some checks on regno ? */
  3091. + return *nios2_register_info_table[regno].type;
  3092. +}
  3093. +
  3094. +/* nios2_register_byte_table[i] is the offset into the register file of the
  3095. + start of register number i. We initialize this from
  3096. + nios2_register_info_table. */
  3097. +int nios2_register_byte_table[NIOS2_NUM_REGS];
  3098. +
  3099. +/* Index within `registers' of the first byte of the space for register REGNO. */
  3100. +int
  3101. +nios2_register_byte (int regno)
  3102. +{
  3103. + return nios2_register_byte_table[regno];
  3104. +}
  3105. +
  3106. +/* Number of bytes of storage in the actual machine representation for
  3107. + register 'regno'. */
  3108. +static int
  3109. +nios2_register_raw_size (int regno)
  3110. +{
  3111. + return nios2_register_info_table[regno].size;
  3112. +}
  3113. +
  3114. +/* Number of bytes of storage in the program's representation for
  3115. + register 'regno'. */
  3116. +static int
  3117. +nios2_register_virtual_size (int regno)
  3118. +{
  3119. + return nios2_register_info_table[regno].size;
  3120. +}
  3121. +
  3122. +/* Return the GDB type object for the "standard" data type
  3123. + of data in register 'regno'. */
  3124. +static struct type *
  3125. +nios2_register_virtual_type (int regno)
  3126. +{
  3127. + return *nios2_register_info_table[regno].type;
  3128. +}
  3129. +
  3130. +/* Does this register need conversion betwen raw and virtual formats */
  3131. +int
  3132. +nios2_register_convertible (int regno)
  3133. +{
  3134. + if (nios2_register_raw_size (regno) == nios2_register_virtual_size (regno))
  3135. + return 0;
  3136. + else
  3137. + return 1;
  3138. +}
  3139. +
  3140. +
  3141. +
  3142. +/* Given a return value in `regcache' with a type `valtype',
  3143. + extract and copy its value into `valbuf'. */
  3144. +/* FIXME: check this function*/
  3145. +void
  3146. +nios2_extract_return_value (struct type *valtype, struct regcache *regcache, void *valbuf)
  3147. +{
  3148. +#ifdef PORTINGTO61
  3149. + int len = TYPE_LENGTH (valtype);
  3150. +
  3151. + /* pointer types are returned in register r2,
  3152. + up to 16-bit types in r2
  3153. + up to 32-bit types in r2,r3 */
  3154. + if (len <= nios2_register_raw_size (R2_REGNUM))
  3155. + memcpy (valbuf, regbuf + REGISTER_BYTE (R2_REGNUM), len);
  3156. + else if (len <= (nios2_register_raw_size (R2_REGNUM)
  3157. + + nios2_register_raw_size (R3_REGNUM)))
  3158. + memcpy (valbuf, regbuf + REGISTER_BYTE (R2_REGNUM), len);
  3159. + else
  3160. + {
  3161. + /* Can I get the returned value here ? */
  3162. + memset(valbuf, 0, len);
  3163. + }
  3164. +#endif
  3165. +}
  3166. +
  3167. +/* Write into appropriate registers a function return value
  3168. + of type TYPE, given in virtual format. */
  3169. +/* FIXME: check if required */
  3170. +void
  3171. +nios2_store_return_value (struct type *valtype, void *valbuf)
  3172. +{
  3173. +#ifdef PORTINGTO61
  3174. + int len = TYPE_LENGTH (valtype);
  3175. +
  3176. + /* return values of up to 8 bytes are returned in $r2 $r3 */
  3177. +
  3178. + if (len <= nios2_register_raw_size (R2_REGNUM))
  3179. + write_register_bytes (REGISTER_BYTE (R2_REGNUM),
  3180. + valbuf,
  3181. + len);
  3182. + else if (len <= (nios2_register_raw_size (R2_REGNUM)
  3183. + + nios2_register_raw_size (R3_REGNUM)))
  3184. + write_register_bytes (REGISTER_BYTE (R2_REGNUM),
  3185. + valbuf,
  3186. + len);
  3187. +#endif
  3188. +}
  3189. +
  3190. +#ifdef PORTINGTO61
  3191. +
  3192. +/* Setup the function arguments for calling a function in the inferior. */
  3193. +static CORE_ADDR
  3194. +nios2_push_arguments (int nargs, struct value **args, CORE_ADDR sp,
  3195. + int struct_return, CORE_ADDR struct_addr)
  3196. +{
  3197. + int argreg;
  3198. + int argnum;
  3199. + struct stack_arg
  3200. + {
  3201. + int len;
  3202. + char *val;
  3203. + } *stack_args;
  3204. + int nstack_args = 0;
  3205. +
  3206. + stack_args = (struct stack_arg *) alloca (nargs * sizeof (struct stack_arg));
  3207. +
  3208. + /* The lowest register number containing arguments */
  3209. + argreg = FIRST_ARGREG;
  3210. +
  3211. + /* Align the stack. It will be needed
  3212. + if we call a function which has argument overflow. */
  3213. + sp &= ~3;
  3214. +
  3215. + /* If this function returns a struct which does not fit in the
  3216. + return registers, we must pass a buffer to the function
  3217. + which it can use to save the return value. */
  3218. + if (struct_return)
  3219. + write_register (R2_REGNUM, struct_addr);
  3220. +
  3221. + /* FIXME: what about unions? */
  3222. + for (argnum = 0; argnum < nargs; argnum++)
  3223. + {
  3224. + char *val = (char *) VALUE_CONTENTS (args[argnum]);
  3225. + int len = TYPE_LENGTH (VALUE_TYPE (args[argnum]));
  3226. + struct type *type = VALUE_TYPE (args[argnum]);
  3227. + int olen;
  3228. +
  3229. + if ((argreg <= LAST_ARGREG && len <= (LAST_ARGREG - argreg + 1) * DEPRECATED_REGISTER_SIZE)
  3230. + || (TYPE_CODE (type) == TYPE_CODE_STRUCT))
  3231. + {
  3232. + /* Something that will fit entirely into registers or go on the stack. */
  3233. + while (len > 0 && argreg <= LAST_ARGREG)
  3234. + { write_register (argreg, extract_unsigned_integer (val, DEPRECATED_REGISTER_SIZE));
  3235. +
  3236. + argreg++;
  3237. + val += DEPRECATED_REGISTER_SIZE;
  3238. + len -= DEPRECATED_REGISTER_SIZE;
  3239. + }
  3240. +
  3241. + /* Any remainder for the stack is noted below... */
  3242. + }
  3243. + else if (TYPE_CODE (VALUE_TYPE (args[argnum])) != TYPE_CODE_STRUCT
  3244. + && len > DEPRECATED_REGISTER_SIZE)
  3245. + {
  3246. + /* All subsequent args go onto the stack. */
  3247. + argnum = LAST_ARGREG + 1;
  3248. + }
  3249. +
  3250. + if (len > 0)
  3251. + {
  3252. + /* Note that this must be saved onto the stack */
  3253. + stack_args[nstack_args].val = val;
  3254. + stack_args[nstack_args].len = len;
  3255. + nstack_args++;
  3256. + }
  3257. + }
  3258. +
  3259. + /* We're done with registers and stack allocation. Now do the actual
  3260. + stack pushes. */
  3261. + while (nstack_args--)
  3262. + {
  3263. + sp -= stack_args[nstack_args].len;
  3264. + write_memory (sp, stack_args[nstack_args].val, stack_args[nstack_args].len);
  3265. + }
  3266. +
  3267. + /* Return adjusted stack pointer. */
  3268. + return sp;
  3269. +}
  3270. +
  3271. +/* Function: push_return_address (pc)
  3272. + Set up the return address for the inferior function call.*/
  3273. +/* FIXME: Check if required */
  3274. +static CORE_ADDR
  3275. +nios2_push_return_address (CORE_ADDR pc, CORE_ADDR sp)
  3276. +{
  3277. + write_register (RA_REGNUM, CALL_DUMMY_ADDRESS ());
  3278. + return sp;
  3279. +}
  3280. +
  3281. +/* Extract from an array regcache containing the (raw) register state
  3282. + the address in which a function should return its structure value,
  3283. + as a CORE_ADDR (or an expression that can be used as one). */
  3284. +/* FIXME: Check if required */
  3285. +
  3286. +static CORE_ADDR
  3287. +nios2_extract_struct_value_address (char *regbuf)
  3288. +{
  3289. + return (extract_address ((regbuf) + REGISTER_BYTE (R4_REGNUM),
  3290. + REGISTER_RAW_SIZE (R4_REGNUM)));
  3291. +}
  3292. +
  3293. +/* Store the address of the place in which to copy the structure the
  3294. + subroutine will return. This is called from call_function. */
  3295. +
  3296. +/* FIXME: Check if required */
  3297. +static void
  3298. +nios2_store_struct_return (CORE_ADDR addr, CORE_ADDR sp)
  3299. +{
  3300. + write_register (R4_REGNUM, (addr));
  3301. +}
  3302. +#endif
  3303. +
  3304. +
  3305. +/* This function analyzes the function prologue and tries to work
  3306. + out where registers are saved and how long the prologue is.
  3307. + The prologue will consist of the following parts:
  3308. + 1) Optional profiling instrumentation. The old version uses six
  3309. + instructions. We step over this if there is an exact match.
  3310. + nextpc r8
  3311. + mov r9, ra
  3312. + movhi r10, %hiadj(.LP2)
  3313. + addi r10, r10, %lo(.LP2)
  3314. + call mcount
  3315. + mov ra, r9
  3316. + The new version uses two or three instructions (the last of
  3317. + these might get merged in with the STW which saves RA to the
  3318. + stack). We interpret these.
  3319. + mov r8, ra
  3320. + call mcount
  3321. + mov ra, r8
  3322. +
  3323. + 2) Optional interrupt entry decision. Again, we step over
  3324. + this if there is an exact match.
  3325. + rdctl et,estatus
  3326. + andi et,et,1
  3327. + beq et,zero, <software_exception>
  3328. + rdctl et,ipending
  3329. + beq et,zero, <software_exception>
  3330. +
  3331. + 3) A stack adjustment or stack which, which will be one of:
  3332. + addi sp, sp, -constant
  3333. + or:
  3334. + movi r8, constant
  3335. + sub sp, sp, r8
  3336. + or
  3337. + movhi r8, constant
  3338. + addi r8, r8, constant
  3339. + sub sp, sp, r8
  3340. + or
  3341. + movhi rx, %hiadj(newstack)
  3342. + addhi rx, rx, %lo(newstack)
  3343. + stw sp, constant(rx)
  3344. + mov sp, rx
  3345. +
  3346. + 4) An optional stack check, which can take either of these forms:
  3347. + bgeu sp, rx, +8
  3348. + break 3
  3349. + or
  3350. + bltu sp, rx, .Lstack_overflow
  3351. + ...
  3352. + .Lstack_overflow:
  3353. + break 3
  3354. +
  3355. + 5) Saving any registers which need to be saved. These will
  3356. + normally just be stored onto the stack:
  3357. + stw rx, constant(sp)
  3358. + but in the large frame case will use r8 as an offset back
  3359. + to the cfa:
  3360. + add r8, r8, sp
  3361. + stw rx, -constant(r8)
  3362. +
  3363. + Saving control registers looks slightly different:
  3364. + rdctl rx, ctlN
  3365. + stw rx, constant(sp)
  3366. +
  3367. + 6) An optional FP setup, either if the user has requested a
  3368. + frame pointer or if the function calls alloca.
  3369. + This is always:
  3370. + mov fp, sp
  3371. +
  3372. + The prologue instructions may be interleaved, and the register
  3373. + saves and FP setup can occur in either order.
  3374. +
  3375. + To cope with all this variability we decode all the instructions
  3376. + from the start of the prologue until we hit a branch, call or
  3377. + return. For each of the instructions mentioned in 3, 4 and 5 we
  3378. + handle the limited cases of stores to the stack and operations
  3379. + on constant values.
  3380. + */
  3381. +
  3382. +typedef struct
  3383. +{
  3384. + unsigned int insn;
  3385. + unsigned int mask;
  3386. +} wild_insn;
  3387. +
  3388. +static const wild_insn profiler_insn[] =
  3389. +{
  3390. + { 0x0010e03a, 0x00000000 }, // nextpc r8
  3391. + { 0xf813883a, 0x00000000 }, // mov r9,ra
  3392. + { 0x02800034, 0x003FFFC0 }, // movhi r10,257
  3393. + { 0x52800004, 0x003FFFC0 }, // addi r10,r10,-31992
  3394. + { 0x00000000, 0xFFFFFFC0 }, // call <mcount>
  3395. + { 0x483f883a, 0x00000000 } // mov ra,r9
  3396. +};
  3397. +
  3398. +static const wild_insn irqentry_insn[] =
  3399. +{
  3400. + { 0x0031307a, 0x00000000 }, // rdctl et,estatus
  3401. + { 0xc600004c, 0x00000000 }, // andi et,et,1
  3402. + { 0xc0000026, 0x003FFFC0 }, // beq et,zero, <software_exception>
  3403. + { 0x0031313a, 0x00000000 }, // rdctl et,ipending
  3404. + { 0xc0000026, 0x003FFFC0 } // beq et,zero, <software_exception>
  3405. +};
  3406. +
  3407. +static void
  3408. +nios2_setup_default(struct nios2_unwind_cache *cache)
  3409. +{
  3410. + int i;
  3411. +
  3412. + for (i = 0; i < NIOS2_NUM_REGS; i++)
  3413. + {
  3414. + /* All registers start off holding their previous values */
  3415. + cache->reg_value[i].reg = i;
  3416. + cache->reg_value[i].offset = 0;
  3417. +
  3418. + /* All registers start off not saved */
  3419. + cache->reg_saved[i].basereg = -1;
  3420. + cache->reg_saved[i].addr = 0;
  3421. + }
  3422. +}
  3423. +
  3424. +static int
  3425. +nios2_match_sequence(CORE_ADDR start_pc, const wild_insn * sequence, int count)
  3426. +{
  3427. + CORE_ADDR pc = start_pc;
  3428. + int i;
  3429. + unsigned int insn;
  3430. +
  3431. + for (i = 0 ; i < count ; i++)
  3432. + {
  3433. + insn = read_memory_unsigned_integer (pc, NIOS2_OPCODE_SIZE);
  3434. + if ((insn & ~sequence[i].mask) != sequence[i].insn)
  3435. + return 0;
  3436. +
  3437. + pc += NIOS2_OPCODE_SIZE;
  3438. + }
  3439. +
  3440. + return 1;
  3441. +}
  3442. +
  3443. +
  3444. +CORE_ADDR
  3445. +nios2_analyze_prologue (const CORE_ADDR start_pc, const CORE_ADDR current_pc,
  3446. + struct nios2_unwind_cache *cache, struct frame_info *next_frame)
  3447. +{
  3448. + /* Maximum lines of prologue to check */
  3449. + /* Note that this number should not be too large, else we can potentially */
  3450. + /* end up iterating through unmapped memory */
  3451. + CORE_ADDR limit_pc = start_pc + 200;
  3452. + int regno;
  3453. +
  3454. + /* Does the frame set up the FP register? */
  3455. + int base_reg = 0;
  3456. +
  3457. + REG_VALUE * value = cache->reg_value;
  3458. + REG_VALUE temp_value[NIOS2_NUM_REGS];
  3459. +
  3460. + int i;
  3461. +
  3462. + /* Save the starting PC so we can correct the pc after running */
  3463. + /* through the prolog, using symbol info */
  3464. + CORE_ADDR pc = start_pc;
  3465. +
  3466. + /* Is this an exception handler? */
  3467. + int exception_handler = 0;
  3468. +
  3469. + /* What was the original value of SP (or fake original value for
  3470. + * functions which switch stacks?
  3471. + */
  3472. + CORE_ADDR frame_high;
  3473. +
  3474. + /* Is this the end of the prologue? */
  3475. + int within_prologue = 1;
  3476. +
  3477. + CORE_ADDR prologue_end;
  3478. +
  3479. + /* Is this the innermost function? */
  3480. + int innermost = (frame_relative_level(next_frame) < 0);
  3481. +
  3482. +#ifdef DEBUG_PRINT
  3483. + fprintf_unfiltered (gdb_stdlog,
  3484. + "{ nios2_analyze_prologue start=0x%s, current=0x%s ",
  3485. + paddr_nz (start_pc), paddr_nz (current_pc));
  3486. +#endif
  3487. +
  3488. + /* Set up the default values of the registers. */
  3489. + nios2_setup_default(cache);
  3490. +
  3491. + /* If the first few instructions are the profile entry then skip over them. */
  3492. + /* Newer versions of the compiler use more efficient profiling code. */
  3493. + if (nios2_match_sequence(pc, profiler_insn, sizeof(profiler_insn)/sizeof(profiler_insn[0])))
  3494. + pc += sizeof(profiler_insn)/sizeof(profiler_insn[0]) * NIOS2_OPCODE_SIZE;
  3495. +
  3496. + /* If the first few are an interrupt entry then skip over them too */
  3497. + if (nios2_match_sequence(pc, irqentry_insn, sizeof(irqentry_insn)/sizeof(irqentry_insn[0])))
  3498. + {
  3499. + pc += sizeof(irqentry_insn)/sizeof(irqentry_insn[0]) * NIOS2_OPCODE_SIZE;
  3500. + exception_handler = 1;
  3501. + }
  3502. +
  3503. + prologue_end = start_pc;
  3504. +
  3505. + /* Find the prologue instructions. */
  3506. + /* Fortunately we're in 32bit paradise */
  3507. + while (pc < limit_pc && within_prologue)
  3508. + {
  3509. + /* Present instruction. */
  3510. + unsigned int insn;
  3511. +
  3512. + int prologue_insn = 0;
  3513. +
  3514. + if (pc == current_pc)
  3515. + {
  3516. + /*
  3517. + * When we reach the current PC we must save the current register
  3518. + * state (for the backtrace) but keep analysing because there might
  3519. + * be more to find out (eg. is this an exception handler).
  3520. + */
  3521. + memcpy(temp_value, value, sizeof(temp_value));
  3522. + value = temp_value;
  3523. +#ifdef DEBUG_PRINT
  3524. + fprintf_unfiltered (gdb_stdlog, "*");
  3525. +#endif
  3526. + }
  3527. +
  3528. + insn = read_memory_unsigned_integer (pc, NIOS2_OPCODE_SIZE);
  3529. + pc += NIOS2_OPCODE_SIZE;
  3530. +
  3531. +#ifdef DEBUG_PRINT
  3532. + fprintf_unfiltered (gdb_stdlog, "[%08X]", insn);
  3533. +#endif
  3534. +
  3535. + /* The following instructions can appear in the prologue */
  3536. +
  3537. + if ((insn & 0x0001FFFF) == 0x0001883A)
  3538. + {
  3539. + /* ADD rc, ra, rb (also used for MOV) */
  3540. +
  3541. + int ra = GET_IW_A(insn);
  3542. + int rb = GET_IW_B(insn);
  3543. + int rc = GET_IW_C(insn);
  3544. +
  3545. + if (rc == SP_REGNUM && rb == 0 && value[ra].reg == cache->reg_saved[SP_REGNUM].basereg)
  3546. + {
  3547. + /* If the previous value of SP is available somewhere near the new
  3548. + * stack pointer value then this is a stack switch.
  3549. + */
  3550. +
  3551. + /* If any registers were saved on the stack before then we can't backtrace
  3552. + * into them now.
  3553. + */
  3554. + for (i = 0 ; i < NIOS2_NUM_REGS ; i++)
  3555. + {
  3556. + if (cache->reg_saved[i].basereg == SP_REGNUM)
  3557. + cache->reg_saved[i].basereg = -1;
  3558. + if (value[i].reg == SP_REGNUM)
  3559. + value[i].reg = -1;
  3560. + }
  3561. +
  3562. + /* Create a fake "high water mark" 4 bytes above where SP was stored
  3563. + * and fake up the registers to be consistent with that.
  3564. + */
  3565. + value[SP_REGNUM].reg = SP_REGNUM;
  3566. + value[SP_REGNUM].offset = value[ra].offset - cache->reg_saved[SP_REGNUM].addr - 4;
  3567. +
  3568. + cache->reg_saved[SP_REGNUM].basereg = SP_REGNUM;
  3569. + cache->reg_saved[SP_REGNUM].addr = -4;
  3570. + }
  3571. +
  3572. + else if (rc != 0)
  3573. + {
  3574. + if (value[rb].reg == 0)
  3575. + value[rc].reg = value[ra].reg;
  3576. + else if (value[ra].reg == 0)
  3577. + value[rc].reg = value[rb].reg;
  3578. + else
  3579. + value[rc].reg = -1;
  3580. +
  3581. + value[rc].offset = value[ra].offset + value[rb].offset;
  3582. + }
  3583. + prologue_insn = 1;
  3584. + }
  3585. +
  3586. + else if ((insn & 0x0001FFFF) == 0x0001983A)
  3587. + {
  3588. + /* SUB rc, ra, rb */
  3589. +
  3590. + int ra = GET_IW_A(insn);
  3591. + int rb = GET_IW_B(insn);
  3592. + int rc = GET_IW_C(insn);
  3593. +
  3594. + if (rc != 0)
  3595. + {
  3596. + if (value[rb].reg == 0)
  3597. + value[rc].reg = value[ra].reg;
  3598. + else
  3599. + value[rc].reg = -1;
  3600. +
  3601. + value[rc].offset = value[ra].offset - value[rb].offset;
  3602. + }
  3603. + }
  3604. +
  3605. + else if ((insn & 0x0000003F) == 0x00000004)
  3606. + {
  3607. + /* ADDI rb, ra, immed (also used for MOVI) */
  3608. + short immed = GET_IW_IMM16(insn);
  3609. + int ra = GET_IW_A(insn);
  3610. + int rb = GET_IW_B(insn);
  3611. +
  3612. + if (rb == SP_REGNUM)
  3613. + {
  3614. + /* The first stack adjustment is part of the prologue. Any subsequent
  3615. + stack adjustments are either down to alloca or the epilogue so stop
  3616. + analysing when we hit them. */
  3617. + if (value[rb].offset != 0 || value[ra].reg != SP_REGNUM)
  3618. + break;
  3619. + }
  3620. +
  3621. + if (rb != 0)
  3622. + {
  3623. + value[rb].reg = value[ra].reg;
  3624. + value[rb].offset = value[ra].offset + immed;
  3625. + }
  3626. +
  3627. + prologue_insn = 1;
  3628. + }
  3629. +
  3630. + else if ((insn & 0x0000003F) == 0x00000034)
  3631. + {
  3632. + /* ORHI rb, ra, immed (also used for MOVHI) */
  3633. + unsigned int immed = GET_IW_IMM16(insn);
  3634. + int ra = GET_IW_A(insn);
  3635. + int rb = GET_IW_B(insn);
  3636. +
  3637. + if (rb != 0)
  3638. + {
  3639. + value[rb].reg = (value[ra].reg == 0) ? 0 : -1;
  3640. + value[rb].offset = value[ra].offset | (immed << 16);
  3641. + }
  3642. + }
  3643. +
  3644. + else if (((insn & IW_OP_MASK) == OP_STW || (insn & IW_OP_MASK) == OP_STWIO))
  3645. + {
  3646. + /* STW rb, immediate(ra) */
  3647. +
  3648. + short immed16 = GET_IW_IMM16(insn);
  3649. + int ra = GET_IW_A(insn);
  3650. + int rb = GET_IW_B(insn);
  3651. +
  3652. + /* Are we storing the original value of a register? For exception handlers
  3653. + * the value of EA-4 (return address from interrupts etc) is sometimes stored.
  3654. + */
  3655. + int orig = value[rb].reg;
  3656. + if (orig > 0 && (value[rb].offset == 0 || (orig == EA_REGNUM && value[rb].offset == -4)))
  3657. + {
  3658. + /* We are most interested in stores to the stack, but will also take note
  3659. + * of stores to other places as they might be useful later.
  3660. + */
  3661. + if ((value[ra].reg == SP_REGNUM && cache->reg_saved[orig].basereg != SP_REGNUM) ||
  3662. + cache->reg_saved[orig].basereg == -1)
  3663. + {
  3664. + if (pc < current_pc)
  3665. + {
  3666. + /* Save off callee saved registers */
  3667. + cache->reg_saved[orig].basereg = value[ra].reg;
  3668. + cache->reg_saved[orig].addr = value[ra].offset + GET_IW_IMM16(insn);
  3669. + }
  3670. +
  3671. + prologue_insn = 1;
  3672. +
  3673. + if (orig == EA_REGNUM || orig == ESTATUS_REGNUM)
  3674. + exception_handler = 1;
  3675. + }
  3676. + }
  3677. + }
  3678. +
  3679. + else if ((insn & 0xFFC1F83F) == 0x0001303A)
  3680. + {
  3681. + /* RDCTL rC, ctlN */
  3682. + int rc = GET_IW_C(insn);
  3683. + int n = GET_IW_CONTROL_REGNUM(insn);
  3684. +
  3685. + if (rc != 0)
  3686. + {
  3687. + value[rc].reg = STATUS_REGNUM + n;
  3688. + value[rc].offset = 0;
  3689. + }
  3690. +
  3691. + prologue_insn = 1;
  3692. + }
  3693. +
  3694. + else if ((insn & 0x0000003F) == 0 &&
  3695. + value[8].reg == RA_REGNUM && value[8].offset == 0 &&
  3696. + value[SP_REGNUM].reg == SP_REGNUM && value[SP_REGNUM].offset == 0)
  3697. + {
  3698. + /* A CALL instruction. This is treated as a call to mcount if ra
  3699. + * has been stored into r8 beforehand and if it's before the stack adjust.
  3700. + * mcount corrupts r2-r3, r9-r15 & ra
  3701. + */
  3702. + for (i = 2 ; i <= 3 ; i++)
  3703. + value[i].reg = -1;
  3704. + for (i = 9 ; i <= 15 ; i++)
  3705. + value[i].reg = -1;
  3706. + value[RA_REGNUM].reg = -1;
  3707. +
  3708. + prologue_insn = 1;
  3709. + }
  3710. +
  3711. + else if ((insn & 0xF83FFFFF) == 0xD800012E)
  3712. + {
  3713. + /* BGEU sp, rx, +8
  3714. + * BREAK 3
  3715. + * This instruction sequence is used in stack checking - we can ignore it
  3716. + */
  3717. + unsigned int next_insn = read_memory_unsigned_integer(pc, NIOS2_OPCODE_SIZE);
  3718. +
  3719. + if (next_insn != 0x003DA0FA)
  3720. + within_prologue = 0;
  3721. + else
  3722. + pc += NIOS2_OPCODE_SIZE;
  3723. + }
  3724. +
  3725. + else if ((insn & 0xF800003F) == 0xD8000036)
  3726. + {
  3727. + /* BLTU sp, rx, .Lstackoverflow
  3728. + * If the location branched to holds a BREAK 3 instruction then this is
  3729. + * also stack overflow detection. We can ignore it.
  3730. + */
  3731. + CORE_ADDR target_pc = pc + ((insn & 0x3FFFC0) >> 6);
  3732. + unsigned int target_insn = read_memory_unsigned_integer(target_pc, NIOS2_OPCODE_SIZE);
  3733. +
  3734. + if (target_insn != 0x003DA0FA)
  3735. + within_prologue = 0;
  3736. + }
  3737. +
  3738. + /* Any other instructions are allowed to be moved up into the prologue. If we
  3739. + reach a branch, call or return then the prologue is considered over */
  3740. + /* We also consider a second stack adjustment as terminating the prologue (see
  3741. + above) */
  3742. +
  3743. + else
  3744. + {
  3745. + switch (GET_IW_OP(insn))
  3746. + {
  3747. + case OP_BEQ:
  3748. + case OP_BGE:
  3749. + case OP_BGEU:
  3750. + case OP_BLT:
  3751. + case OP_BLTU:
  3752. + case OP_BNE:
  3753. + case OP_BR:
  3754. + case OP_CALL:
  3755. + within_prologue = 0;
  3756. + break;
  3757. + case OP_OPX:
  3758. + if (GET_IW_OPX(insn) == OPX_RET ||
  3759. + GET_IW_OPX(insn) == OPX_ERET ||
  3760. + GET_IW_OPX(insn) == OPX_BRET ||
  3761. + GET_IW_OPX(insn) == OPX_CALLR ||
  3762. + GET_IW_OPX(insn) == OPX_JMP)
  3763. + {
  3764. + within_prologue = 0;
  3765. + }
  3766. + default:
  3767. + break;
  3768. + }
  3769. + }
  3770. +
  3771. + if (prologue_insn)
  3772. + prologue_end = pc;
  3773. + }
  3774. +
  3775. + /* Are we within the function epilogue? If so then we should go back to the
  3776. + original register values */
  3777. + if (innermost && current_pc > start_pc)
  3778. + {
  3779. + /* First check whether the previous instruction was a stack
  3780. + adjustment. */
  3781. + unsigned int insn = read_memory_unsigned_integer (current_pc - NIOS2_OPCODE_SIZE, NIOS2_OPCODE_SIZE);
  3782. +
  3783. + if ((insn & 0xFFC0003C) == 0xDEC00004 || /* ADDI sp, sp, */
  3784. + (insn & 0xFFC1FFFF) == 0xDEC1883A || /* ADD sp, sp, */
  3785. + (insn & 0xFFC0003F) == 0xDEC00017) /* LDW sp, constant(sp) */
  3786. + {
  3787. + /* Then check if it's followed by a return or a tail call */
  3788. + insn = read_memory_unsigned_integer (current_pc, NIOS2_OPCODE_SIZE);
  3789. +
  3790. + if (insn == 0xF800283A || /* RET */
  3791. + insn == 0xE800083A || /* ERET */
  3792. + (insn & 0x07FFFFFF) == 0x0000683A || /* JMP */
  3793. + (insn & 0xFFC0003F) == 6) /* BR */
  3794. + {
  3795. + /* Go back to default value of the registers */
  3796. + nios2_setup_default(cache);
  3797. + }
  3798. + }
  3799. + }
  3800. +
  3801. + /* Exception handlers use a different return address register. */
  3802. + if (exception_handler)
  3803. + cache->return_regnum = EA_REGNUM;
  3804. +
  3805. +#ifdef DEBUG_PRINT
  3806. + fprintf_unfiltered (gdb_stdlog, "\n-> retreg=%d, ", cache->return_regnum);
  3807. +#endif
  3808. +
  3809. + if (cache->reg_value[FP_REGNUM].reg == SP_REGNUM)
  3810. + {
  3811. + /* If the FP now holds an offset from the CFA then this is a normal
  3812. + frame which uses the frame pointer. */
  3813. + base_reg = FP_REGNUM;
  3814. + }
  3815. + else if (cache->reg_value[SP_REGNUM].reg == SP_REGNUM)
  3816. + {
  3817. + /* FP doesn't hold an offset from the CFA. If SP still holds an
  3818. + offset from the CFA then we might be in a function which omits
  3819. + the frame pointer, or we might be partway through the prologue.
  3820. + In both cases we can find the CFA using SP. */
  3821. + base_reg = SP_REGNUM;
  3822. + }
  3823. + else
  3824. + {
  3825. + /* Somehow the stack pointer has been corrupted. We can't return. */
  3826. +#ifdef DEBUG_PRINT
  3827. + fprintf_unfiltered (gdb_stdlog, "<can't reach cfa> }\n");
  3828. +#endif
  3829. + return 0;
  3830. + }
  3831. +
  3832. + if (cache->reg_value[base_reg].offset == 0 ||
  3833. + cache->reg_saved[RA_REGNUM].basereg != SP_REGNUM ||
  3834. + cache->reg_saved[cache->return_regnum].basereg != SP_REGNUM)
  3835. + {
  3836. + /*
  3837. + * If the frame didn't adjust the stack, didn't save RA or didn't save
  3838. + * EA in an exception handler then it must either be a leaf function
  3839. + * (doesn't call any other functions) or it can't return. If it has
  3840. + * called another function then it can't be a leaf, so set base == 0
  3841. + * to indicate that we can't backtrace past it.
  3842. + */
  3843. +
  3844. + if (!innermost)
  3845. + {
  3846. + /* If it isn't the innermost function then it can't be a leaf, unless
  3847. + * it was interrupted. Check whether RA for this frame is the same
  3848. + * as PC. If so then it probably wan't interrupted.
  3849. + */
  3850. + char buf[8];
  3851. + CORE_ADDR ra;
  3852. +
  3853. + frame_unwind_register (next_frame, RA_REGNUM, buf);
  3854. + ra = extract_typed_address (buf, builtin_type_void_func_ptr);
  3855. +
  3856. + if (ra == current_pc)
  3857. + {
  3858. +#ifdef DEBUG_PRINT
  3859. + fprintf_unfiltered (gdb_stdlog, "<noreturn ADJUST 0x%s, r31@r%d+?>, r%d@r%d+?> }\n",
  3860. + paddr_nz(cache->reg_value[base_reg].offset),
  3861. + cache->reg_saved[RA_REGNUM].basereg,
  3862. + cache->return_regnum, cache->reg_saved[cache->return_regnum].basereg);
  3863. +#endif
  3864. + return 0;
  3865. + }
  3866. + }
  3867. + }
  3868. +
  3869. + /* Get the value of whichever register we are using for the base. */
  3870. + cache->base = frame_unwind_register_unsigned (next_frame, base_reg);
  3871. +
  3872. + /* What was the value of SP at the start of this function (or just
  3873. + * after the stack switch).
  3874. + */
  3875. + frame_high = cache->base - cache->reg_value[base_reg].offset;
  3876. +
  3877. + /* Adjust all the saved registers such that they contain addresses
  3878. + instead of offsets. */
  3879. + for (i = 0; i < NIOS2_NUM_REGS; i++)
  3880. + if (cache->reg_saved[i].basereg == SP_REGNUM)
  3881. + {
  3882. + cache->reg_saved[i].basereg = Z_REGNUM;
  3883. + cache->reg_saved[i].addr += frame_high;
  3884. + }
  3885. +
  3886. + for (i = 0; i < NIOS2_NUM_REGS; i++)
  3887. + if (cache->reg_saved[i].basereg == GP_REGNUM)
  3888. + {
  3889. + CORE_ADDR gp = frame_unwind_register_unsigned (next_frame, GP_REGNUM);
  3890. +
  3891. + for ( ; i < NIOS2_NUM_REGS; i++)
  3892. + if (cache->reg_saved[i].basereg == GP_REGNUM)
  3893. + {
  3894. + cache->reg_saved[i].basereg = Z_REGNUM;
  3895. + cache->reg_saved[i].addr += gp;
  3896. + }
  3897. + }
  3898. +
  3899. + /* Work out what the value of SP was on the first instruction of this
  3900. + * function. If we didn't switch stacks then this can be trivially
  3901. + * computed from the base address.
  3902. + */
  3903. + if (cache->reg_saved[SP_REGNUM].basereg == Z_REGNUM)
  3904. + {
  3905. + cache->cfa = read_memory_unsigned_integer(cache->reg_saved[SP_REGNUM].addr, 4);
  3906. + }
  3907. + else
  3908. + cache->cfa = frame_high;
  3909. +
  3910. + /* Exception handlers restore ESTATUS into STATUS. */
  3911. + if (exception_handler)
  3912. + {
  3913. + cache->reg_saved[STATUS_REGNUM] = cache->reg_saved[ESTATUS_REGNUM];
  3914. + cache->reg_saved[ESTATUS_REGNUM].basereg = -1;
  3915. + }
  3916. +
  3917. +#ifdef DEBUG_PRINT
  3918. + fprintf_unfiltered (gdb_stdlog, "cfa=0x%s }\n", paddr_nz(cache->cfa));
  3919. +#endif
  3920. +
  3921. + return prologue_end;
  3922. +}
  3923. +
  3924. +struct frame_info *
  3925. +setup_arbitrary_frame (int argc, CORE_ADDR *argv)
  3926. +{
  3927. + if (argc != 2)
  3928. + error ("Nios II frame specifications require two arguments: sp and pc");
  3929. +
  3930. + return create_new_frame (argv[0], argv[1]);
  3931. +}
  3932. +
  3933. +#ifdef PORTINGTO61
  3934. +/* Should be handled by unwind informations. */
  3935. +/* However, doing this manually until we can find */
  3936. +/* use the CFA information to examine the stack */
  3937. +void
  3938. +nios2_frame_init_saved_regs (struct frame_info *fi)
  3939. +{
  3940. + CORE_ADDR ip;
  3941. +
  3942. + /* Examine the entire prologue. */
  3943. + register int frameless_p = 0;
  3944. +
  3945. + /* Has this frame's registers already been initialized? */
  3946. + if (fi->saved_regs)
  3947. + return;
  3948. +
  3949. + frame_saved_regs_zalloc (fi);
  3950. +
  3951. + ip = get_pc_function_start (fi->pc);
  3952. + nios2_examine (ip, fi, frameless_p);
  3953. +}
  3954. +#endif
  3955. +
  3956. +
  3957. +/* Given a PC value corresponding to the start of a function, return the PC
  3958. + of the first instruction after the function prologue. */
  3959. +
  3960. +CORE_ADDR
  3961. +nios2_skip_prologue (CORE_ADDR start_pc)
  3962. +{
  3963. + CORE_ADDR func_addr, func_end;
  3964. + struct symtab_and_line sal;
  3965. + CORE_ADDR pc_after_prologue;
  3966. +
  3967. + /* If we have line debugging information, then the end of the prologue
  3968. + should the first assembly instruction of the first source line. */
  3969. + if (find_pc_partial_function (start_pc, NULL, &func_addr, &func_end))
  3970. + {
  3971. + sal = find_pc_line (func_addr, 0);
  3972. + if (sal.end > 0 && sal.end < func_end)
  3973. + return sal.end;
  3974. + }
  3975. +
  3976. + return start_pc;
  3977. +}
  3978. +
  3979. +/* nios2_software_single_step() is called just before we want to resume
  3980. + the inferior, if we want to single-step it but there is no hardware
  3981. + or kernel single-step support (NIOS2 on GNU/Linux for example). We find
  3982. + the target of the coming instruction and breakpoint it.
  3983. +
  3984. + single_step is also called just after the inferior stops. If we had
  3985. + set up a simulated single-step, we undo our damage. */
  3986. +
  3987. +void
  3988. +nios2_software_single_step (enum target_signal sig, int insert_breakpoints_p)
  3989. +{
  3990. + int ii;
  3991. + unsigned int insn;
  3992. + CORE_ADDR pc;
  3993. + CORE_ADDR breaks[2];
  3994. + int imme;
  3995. +
  3996. + if (insert_breakpoints_p)
  3997. + {
  3998. + pc = read_pc ();
  3999. + breaks[0] = pc + 4;
  4000. + breaks[1] = -1;
  4001. + insn = read_memory_unsigned_integer (pc, 4);
  4002. +
  4003. + /* Calculate the destination of a branch/jump */
  4004. + switch (GET_IW_OP(insn))
  4005. + {
  4006. + /* I-type branch */
  4007. + case OP_BEQ:
  4008. + case OP_BGE:
  4009. + case OP_BGEU:
  4010. + case OP_BLT:
  4011. + case OP_BLTU:
  4012. + case OP_BNE:
  4013. + imme = (short) GET_IW_IMM16(insn);
  4014. + breaks[1] = pc + 4 + imme;
  4015. + break;
  4016. + case OP_BR:
  4017. + imme = (short) GET_IW_IMM16(insn);
  4018. + breaks[0] = pc + 4 + imme;
  4019. + break;
  4020. + /* J-type branch */
  4021. + case OP_CALL:
  4022. + case OP_JMPI:
  4023. + imme = GET_IW_IMM26(insn);
  4024. + breaks[0] = (pc & 0xf0000000) | (imme * 4);
  4025. + break;
  4026. + /* R-type branch */
  4027. + case OP_OPX:
  4028. + switch (GET_IW_OPX(insn))
  4029. + {
  4030. + case OPX_CALLR:
  4031. + case OPX_JMP:
  4032. + case OPX_RET:
  4033. + imme = read_register (GET_IW_A(insn));
  4034. + breaks[0] = imme;
  4035. + break;
  4036. + }
  4037. + break;
  4038. + }
  4039. +
  4040. + /* Don't put two breakpoints on the same address. */
  4041. + if (breaks[1] == breaks[0])
  4042. + breaks[1] = -1;
  4043. +
  4044. + for (ii = 0; ii < 2; ++ii)
  4045. + {
  4046. + /* ignore invalid breakpoint. */
  4047. + if (breaks[ii] == -1)
  4048. + continue;
  4049. + insert_single_step_breakpoint (breaks[ii]);
  4050. + }
  4051. + }
  4052. + else
  4053. + remove_single_step_breakpoints ();
  4054. +
  4055. +}
  4056. +
  4057. +const unsigned char*
  4058. +nios2_breakpoint_from_pc (CORE_ADDR *bp_addr, int *bp_size)
  4059. +{
  4060. + /* break encoding: 31->27 26->22 21->17 16->11 10->6 5->0 */
  4061. + /* 00000 00000 0x1e 0x34 00000 0x3a */
  4062. + /* 00000 00000 11110 110100 00000 111010 */
  4063. + /* In bytes: 00000000 00111101 10100000 00111010 */
  4064. + /* 0x0 0x3d 0xa0 0x3a */
  4065. +#if 0
  4066. + static unsigned char breakpoint[] = {0x3a, 0xa0, 0x3d, 0x0};
  4067. +#else
  4068. + static unsigned char breakpoint[] = {0x7a, 0x68, 0x3b, 0x0}; /* Trap instr. w/imm=0x01 */
  4069. +#endif
  4070. + *bp_size = 4;
  4071. + return breakpoint;
  4072. +}
  4073. +
  4074. +
  4075. +int
  4076. +gdb_print_insn_nios2 (bfd_vma memaddr, disassemble_info *info)
  4077. +{
  4078. + if (info->endian == BFD_ENDIAN_BIG)
  4079. + {
  4080. + return print_insn_big_nios2 (memaddr, info);
  4081. + }
  4082. + else
  4083. + {
  4084. + return print_insn_little_nios2 (memaddr, info);
  4085. + }
  4086. +}
  4087. +
  4088. +
  4089. +
  4090. +/* Adjust the address downward (direction of stack growth) so that it
  4091. + is correctly aligned for a new stack frame. */
  4092. +
  4093. +/* ??? Big endian issues here? */
  4094. +
  4095. +static CORE_ADDR
  4096. +nios2_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
  4097. +{
  4098. + return align_down (addr, 4);
  4099. +}
  4100. +
  4101. +
  4102. +
  4103. +/* We don't convert anything at the moment */
  4104. +static int
  4105. +nios2_convert_register_p (int regnum, struct type *type)
  4106. +{
  4107. + return 0;
  4108. +}
  4109. +
  4110. +static void
  4111. +nios2_register_to_value (struct frame_info *frame, int regnum,
  4112. + struct type *type, void *to)
  4113. +{
  4114. + get_frame_register (frame, regnum + 0, (char *) to + 0);
  4115. + get_frame_register (frame, regnum + 0, (char *) to + 0);
  4116. +}
  4117. +
  4118. +static void
  4119. +nios2_value_to_register (struct frame_info *frame, int regnum,
  4120. + struct type *type, const void *from)
  4121. +{
  4122. + put_frame_register (frame, regnum + 0, (const char *) from + 0);
  4123. + put_frame_register (frame, regnum + 0, (const char *) from + 0);
  4124. +}
  4125. +
  4126. +/* Determine, for architecture GDBARCH, how a return value of TYPE
  4127. + should be returned. If it is supposed to be returned in registers,
  4128. + and READBUF is non-zero, read the appropriate value from REGCACHE,
  4129. + and copy it into READBUF. If WRITEBUF is non-zero, write the value
  4130. + from WRITEBUF into REGCACHE. */
  4131. +
  4132. +static enum return_value_convention
  4133. +nios2_return_value (struct gdbarch *gdbarch, struct type *type,
  4134. + struct regcache *regcache, void *readbuf,
  4135. + const void *writebuf)
  4136. +{
  4137. + enum type_code code = TYPE_CODE (type);
  4138. +
  4139. + /* FIXME PBrookes add struct return function */
  4140. + if ((code == TYPE_CODE_STRUCT || code == TYPE_CODE_UNION)
  4141. + /*&& !nios2_reg_struct_return_p (gdbarch, type)*/)
  4142. + return RETURN_VALUE_STRUCT_CONVENTION;
  4143. +
  4144. +
  4145. + if (readbuf)
  4146. + nios2_extract_return_value (type, regcache, readbuf);
  4147. + if (writebuf)
  4148. + nios2_store_return_value (type, regcache);
  4149. +
  4150. + return RETURN_VALUE_REGISTER_CONVENTION;
  4151. +}
  4152. +
  4153. +/* Assuming NEXT_FRAME->prev is a dummy, return the frame ID of that
  4154. + dummy frame. The frame ID's base needs to match the TOS value
  4155. + saved by save_dummy_frame_tos() and returned from
  4156. + nios2_push_dummy_call, and the PC needs to match the dummy frame's
  4157. + breakpoint. */
  4158. +
  4159. +static struct frame_id
  4160. +nios2_unwind_dummy_id (struct gdbarch *gdbarch, struct frame_info *next_frame)
  4161. +{
  4162. + return frame_id_build (frame_unwind_register_unsigned (next_frame, SP_REGNUM),
  4163. + frame_pc_unwind (next_frame));
  4164. +}
  4165. +
  4166. +static CORE_ADDR
  4167. +nios2_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
  4168. +{
  4169. + char buf[8];
  4170. +
  4171. + frame_unwind_register (next_frame, PC_REGNUM, buf);
  4172. + return extract_typed_address (buf, builtin_type_void_func_ptr);
  4173. +}
  4174. +
  4175. +
  4176. +/* Frame base handling. */
  4177. +
  4178. +struct nios2_unwind_cache *
  4179. +nios2_frame_unwind_cache (struct frame_info *next_frame,
  4180. + void **this_prologue_cache)
  4181. +{
  4182. + CORE_ADDR current_pc;
  4183. + struct nios2_unwind_cache *cache;
  4184. + int i;
  4185. +
  4186. + if (*this_prologue_cache)
  4187. + return *this_prologue_cache;
  4188. +
  4189. + cache = FRAME_OBSTACK_ZALLOC (struct nios2_unwind_cache);
  4190. + (*this_prologue_cache) = cache;
  4191. +
  4192. + /* Zero all fields. */
  4193. + cache->base = 0;
  4194. + cache->cfa = 0;
  4195. + cache->pc = 0;
  4196. +
  4197. + cache->return_regnum = RA_REGNUM;
  4198. +
  4199. + nios2_setup_default(cache);
  4200. +
  4201. + cache->pc = frame_func_unwind (next_frame);
  4202. + current_pc = frame_pc_unwind (next_frame);
  4203. +
  4204. + /* Prologue analysis does the rest... */
  4205. + if (cache->pc != 0)
  4206. + nios2_analyze_prologue (cache->pc, current_pc, cache, next_frame);
  4207. +
  4208. + return cache;
  4209. +}
  4210. +
  4211. +static void
  4212. +nios2_frame_this_id (struct frame_info *next_frame, void **this_cache,
  4213. + struct frame_id *this_id)
  4214. +{
  4215. + struct nios2_unwind_cache *cache =
  4216. + nios2_frame_unwind_cache (next_frame, this_cache);
  4217. +
  4218. + /* This marks the outermost frame. */
  4219. + if (cache->base == 0)
  4220. + return;
  4221. +
  4222. + (*this_id) = frame_id_build (cache->cfa, cache->pc);
  4223. +}
  4224. +
  4225. +static void
  4226. +nios2_frame_prev_register (struct frame_info *next_frame, void **this_cache,
  4227. + int regnum, int *optimizedp,
  4228. + enum lval_type *lvalp, CORE_ADDR *addrp,
  4229. + int *realnump, void *valuep)
  4230. +{
  4231. + struct nios2_unwind_cache *cache =
  4232. + nios2_frame_unwind_cache (next_frame, this_cache);
  4233. +
  4234. + gdb_assert (regnum >= 0);
  4235. +
  4236. + /* The PC of the previous frame is stored in the RA register of
  4237. + the current frame. Frob regnum so that we pull the value from
  4238. + the correct place. */
  4239. + if (regnum == PC_REGNUM)
  4240. + regnum = cache->return_regnum;
  4241. +
  4242. + /* If we've worked out where a register is stored then load it from there.
  4243. + */
  4244. + if (regnum < NIOS2_NUM_REGS && cache->reg_saved[regnum].basereg == Z_REGNUM)
  4245. + {
  4246. + *optimizedp = 0;
  4247. + *lvalp = lval_memory;
  4248. + *addrp = cache->reg_saved[regnum].addr;
  4249. + *realnump = -1;
  4250. + if (valuep)
  4251. + {
  4252. + /* Read the value in from memory. */
  4253. + read_memory (*addrp, valuep,
  4254. + register_size (current_gdbarch, regnum));
  4255. + }
  4256. + return;
  4257. + }
  4258. +
  4259. + if (regnum == SP_REGNUM && cache->cfa)
  4260. + {
  4261. + *optimizedp = 0;
  4262. + *lvalp = not_lval;
  4263. + *addrp = 0;
  4264. + *realnump = -1;
  4265. + if (valuep)
  4266. + {
  4267. + /* Store the value. */
  4268. + store_unsigned_integer (valuep, 8, cache->cfa);
  4269. + }
  4270. + return;
  4271. + }
  4272. +
  4273. + frame_register_unwind (next_frame, regnum,
  4274. + optimizedp, lvalp, addrp, realnump, valuep);
  4275. +}
  4276. +
  4277. +
  4278. +
  4279. +static const struct frame_unwind nios2_frame_unwind =
  4280. +{
  4281. + NORMAL_FRAME,
  4282. + nios2_frame_this_id,
  4283. + nios2_frame_prev_register
  4284. +};
  4285. +
  4286. +static CORE_ADDR
  4287. +nios2_frame_base_address (struct frame_info *next_frame, void **this_cache)
  4288. +{
  4289. + struct nios2_unwind_cache *info
  4290. + = nios2_frame_unwind_cache (next_frame, this_cache);
  4291. + return info->base;
  4292. +}
  4293. +
  4294. +static const struct frame_base nios2_frame_base =
  4295. +{
  4296. + &nios2_frame_unwind,
  4297. + nios2_frame_base_address,
  4298. + nios2_frame_base_address,
  4299. + nios2_frame_base_address
  4300. +};
  4301. +
  4302. +static const struct frame_unwind *
  4303. +nios2_frame_sniffer (struct frame_info *next_frame)
  4304. +{
  4305. + return &nios2_frame_unwind;
  4306. +}
  4307. +
  4308. +
  4309. +static struct gdbarch *
  4310. +nios2_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
  4311. +{
  4312. + struct gdbarch *gdbarch;
  4313. + int register_bytes, i;
  4314. +
  4315. + /* Change the register names based on the current machine type. */
  4316. + if (info.bfd_arch_info->arch != bfd_arch_nios2)
  4317. + return NULL;
  4318. +
  4319. + /* None found, create a new architecture from the information
  4320. + provided. We don't have any architecture specific state, so just
  4321. + pass in 0 for the struct gdbarch_tdep parameter. */
  4322. + gdbarch = gdbarch_alloc (&info, NULL);
  4323. +
  4324. + /* Data type sizes. */
  4325. + set_gdbarch_ptr_bit (gdbarch, 32);
  4326. + set_gdbarch_addr_bit (gdbarch, 32);
  4327. + set_gdbarch_short_bit (gdbarch, 16);
  4328. + set_gdbarch_int_bit (gdbarch, 32);
  4329. + set_gdbarch_long_bit (gdbarch, 32);
  4330. + set_gdbarch_long_long_bit (gdbarch, 64);
  4331. + set_gdbarch_float_bit (gdbarch, 32);
  4332. + set_gdbarch_double_bit (gdbarch, 64);
  4333. +
  4334. + switch (info.byte_order)
  4335. + {
  4336. + case BFD_ENDIAN_BIG:
  4337. + set_gdbarch_float_format (gdbarch, &floatformat_ieee_single_big);
  4338. + set_gdbarch_double_format (gdbarch, &floatformat_ieee_double_big);
  4339. + break;
  4340. +
  4341. + case BFD_ENDIAN_LITTLE:
  4342. + set_gdbarch_float_format (gdbarch, &floatformat_ieee_single_little);
  4343. + set_gdbarch_double_format (gdbarch, &floatformat_ieee_double_little);
  4344. + break;
  4345. +
  4346. + default:
  4347. + internal_error (__FILE__, __LINE__,
  4348. + "nios2_gdbarch_init: bad byte ordering");
  4349. + break;
  4350. + }
  4351. +
  4352. + /* The register set. */
  4353. + set_gdbarch_num_regs (gdbarch, NIOS2_NUM_REGS);
  4354. + set_gdbarch_sp_regnum (gdbarch, SP_REGNUM);
  4355. + set_gdbarch_pc_regnum (gdbarch, PC_REGNUM); /* Pseudo register PC */
  4356. +
  4357. + set_gdbarch_register_name (gdbarch, nios2_register_name);
  4358. + /* Length of ordinary registers used in push_word and a few other
  4359. + places. DEPRECATED_REGISTER_RAW_SIZE is the real way to know how
  4360. + big a register is. */
  4361. +/* FIXME
  4362. + set_gdbarch_deprecated_register_size (gdbarch, 4);
  4363. + set_gdbarch_deprecated_register_virtual_type (gdbarch,
  4364. + nios2_register_virtual_type);
  4365. +*/
  4366. +
  4367. + set_gdbarch_register_type (gdbarch, nios2_register_type);
  4368. +
  4369. + /* The "default" register numbering scheme for AMD64 is referred to
  4370. + as the "DWARF Register Number Mapping" in the System V psABI.
  4371. + The preferred debugging format for all known Nios II targets is
  4372. + actually DWARF2, and GCC doesn't seem to support DWARF (that is
  4373. + DWARF-1), but we provide the same mapping just in case. This
  4374. + mapping is also used for stabs, which GCC does support. */
  4375. + set_gdbarch_stab_reg_to_regnum (gdbarch, nios2_dwarf_reg_to_regnum);
  4376. + set_gdbarch_dwarf_reg_to_regnum (gdbarch, nios2_dwarf_reg_to_regnum);
  4377. + set_gdbarch_dwarf2_reg_to_regnum (gdbarch, nios2_dwarf_reg_to_regnum);
  4378. +
  4379. + set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
  4380. +
  4381. + /* Call dummy code. */
  4382. + set_gdbarch_frame_align (gdbarch, nios2_frame_align);
  4383. +
  4384. + /* Some registers require conversion from raw format to virtual format. */
  4385. +/* FIXME
  4386. + set_gdbarch_deprecated_register_convertible (gdbarch, nios2_register_convertible);
  4387. +*/
  4388. +
  4389. + set_gdbarch_convert_register_p (gdbarch, nios2_convert_register_p);
  4390. + set_gdbarch_register_to_value (gdbarch, nios2_register_to_value);
  4391. + set_gdbarch_value_to_register (gdbarch, nios2_value_to_register);
  4392. +
  4393. + set_gdbarch_return_value (gdbarch, nios2_return_value);
  4394. +
  4395. + set_gdbarch_skip_prologue (gdbarch, nios2_skip_prologue);
  4396. + set_gdbarch_breakpoint_from_pc (gdbarch, nios2_breakpoint_from_pc);
  4397. + set_gdbarch_software_single_step (gdbarch, nios2_software_single_step);
  4398. +
  4399. + set_gdbarch_unwind_dummy_id (gdbarch, nios2_unwind_dummy_id);
  4400. + set_gdbarch_unwind_pc (gdbarch, nios2_unwind_pc);
  4401. +
  4402. + /* The dwarf2 unwinder will normally produce the best results if the
  4403. + debug information is available, so register it first. */
  4404. + frame_unwind_append_sniffer (gdbarch, dwarf2_frame_sniffer);
  4405. +
  4406. + /* FIXME: PBrookes - copied from AMD64-TDEP.c (kettenis/20021026):
  4407. + This is ELF-specific. Fine for now, since all supported NIOS II
  4408. + targets are ELF, but that might change in the future. */
  4409. +/* FIXME again.. Does not exist anymore...
  4410. + set_gdbarch_in_solib_call_trampoline (gdbarch, in_plt_section);
  4411. +*/
  4412. +
  4413. + frame_unwind_append_sniffer (gdbarch, nios2_frame_sniffer);
  4414. +
  4415. + frame_base_set_default (gdbarch, &nios2_frame_base);
  4416. +
  4417. + set_gdbarch_print_insn (gdbarch, gdb_print_insn_nios2);
  4418. +
  4419. + return gdbarch;
  4420. +}
  4421. +
  4422. +void
  4423. +_initialize_nios2_tdep (void)
  4424. +{
  4425. + register_gdbarch_init (bfd_arch_nios2, nios2_gdbarch_init);
  4426. +
  4427. + int i, offset = 0;
  4428. +
  4429. + /* Do not display anything after NIOS2_MAX_REG_DISPLAYED_REGNUM */
  4430. + for (i = 0; i <= NIOS2_MAX_REG_DISPLAYED_REGNUM; i++)
  4431. + {
  4432. + nios2_register_byte_table[i] = offset;
  4433. + offset += nios2_register_info_table[i].size;
  4434. + }
  4435. +
  4436. + for (i = NIOS2_MAX_REG_DISPLAYED_REGNUM + 1; i <= NIOS2_NUM_REGS; i++)
  4437. + {
  4438. + nios2_register_byte_table[i] = -1;
  4439. + }
  4440. +
  4441. +}
  4442. diff --git a/gdb/regformats/reg-nios2.dat b/gdb/regformats/reg-nios2.dat
  4443. new file mode 100644
  4444. index 0000000..77b39a9
  4445. --- /dev/null
  4446. +++ b/gdb/regformats/reg-nios2.dat
  4447. @@ -0,0 +1,46 @@
  4448. +name:nios2
  4449. +expedite:sp,fp,pc
  4450. +32:zero
  4451. +32:at
  4452. +32:r2
  4453. +32:r3
  4454. +32:r4
  4455. +32:r5
  4456. +32:r6
  4457. +32:r7
  4458. +32:r8
  4459. +32:r9
  4460. +32:r10
  4461. +32:r11
  4462. +32:r12
  4463. +32:r13
  4464. +32:r14
  4465. +32:r15
  4466. +32:r16
  4467. +32:r17
  4468. +32:r18
  4469. +32:r19
  4470. +32:r20
  4471. +32:r21
  4472. +32:r22
  4473. +32:r23
  4474. +32:et
  4475. +32:bt
  4476. +32:gp
  4477. +32:sp
  4478. +32:fp
  4479. +32:ea
  4480. +32:ba
  4481. +32:ra
  4482. +32:pc
  4483. +32:status
  4484. +32:estatus
  4485. +32:bstatus
  4486. +32:ienable
  4487. +32:ipending
  4488. +32:cpuid
  4489. +32:ctl6
  4490. +32:ctl7
  4491. +32:pteaddr
  4492. +32:tlbacc
  4493. +32:tlbmisc
  4494. diff --git a/gdb/testsuite/config/nios2-iss.exp b/gdb/testsuite/config/nios2-iss.exp
  4495. new file mode 100644
  4496. index 0000000..624f831
  4497. --- /dev/null
  4498. +++ b/gdb/testsuite/config/nios2-iss.exp
  4499. @@ -0,0 +1,233 @@
  4500. +# Test framework for GDB (remote protocol) using a "gdbserver",
  4501. +# ie. a debug agent running as a native process on the same or
  4502. +# a different host.
  4503. +
  4504. +# Copyright 2000, 2002 Free Software Foundation, Inc.
  4505. +
  4506. +# This program is free software; you can redistribute it and/or modify
  4507. +# it under the terms of the GNU General Public License as published by
  4508. +# the Free Software Foundation; either version 2 of the License, or
  4509. +# (at your option) any later version.
  4510. +#
  4511. +# This program is distributed in the hope that it will be useful,
  4512. +# but WITHOUT ANY WARRANTY; without even the implied warranty of
  4513. +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4514. +# GNU General Public License for more details.
  4515. +#
  4516. +# You should have received a copy of the GNU General Public License
  4517. +# along with this program; if not, write to the Free Software
  4518. +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  4519. +
  4520. +# Please email any bugs, comments, and/or additions to this file to:
  4521. +# bug-gdb@prep.ai.mit.edu
  4522. +
  4523. +# This file was written by Michael Snyder. (msnyder@redhat.com)
  4524. +
  4525. +#
  4526. +# This module to be used for testing gdb with a "gdbserver"
  4527. +# built either from libremote or from gdb/gdbserver.
  4528. +#
  4529. +
  4530. +# Load the basic testing library, and the remote stuff.
  4531. +load_lib ../config/monitor.exp
  4532. +
  4533. +#
  4534. +# To be addressed or set in your baseboard config file:
  4535. +#
  4536. +# set_board_info gdb_protocol "remote"
  4537. +# Unles you have a gdbserver that uses a different protocol...
  4538. +#
  4539. +# set_board_info use_gdb_stub 1
  4540. +# This tells the rest of the test suite not to do things
  4541. +# like "run" which don't work well on remote targets.
  4542. +#
  4543. +# set_board_info gdb,do_reload_on_run 1
  4544. +# Unles you have a gdbserver that can handle multiple sessions.
  4545. +#
  4546. +# set_board_info noargs 1
  4547. +# At present there is no provision in the remote protocol
  4548. +# for passing arguments. This test framework does not
  4549. +# address the issue, so it's best to set this variable
  4550. +# in your baseboard configuration file.
  4551. +# FIXME: there's no reason why the test harness couldn't
  4552. +# pass commandline args when it spawns gdbserver.
  4553. +#
  4554. +# set_board_info gdb,noinferiorio 1
  4555. +# Neither the traditional gdbserver nor the one in libremote
  4556. +# can presently capture stdout and relay it to GDB via the
  4557. +# 'O' packet. This means that tests involving printf will
  4558. +# fail unles you set this varibale in your baseboard
  4559. +# configuration file.
  4560. +#
  4561. +# set_board_info gdb,no_hardware_watchpoints 1
  4562. +# Unles you have a gdbserver that supports hardware watchpoints.
  4563. +# FIXME: gdb should detect if the target doesn't support them,
  4564. +# and fall back to using software watchpoints.
  4565. +#
  4566. +# set_board_info gdb_server_prog
  4567. +# This will be the path to the gdbserver program you want to test.
  4568. +# Defaults to "gdbserver".
  4569. +#
  4570. +# set_board_info sockethost
  4571. +# The name of the host computer whose socket is being used.
  4572. +# Defaults to "localhost". Note: old gdbserver requires
  4573. +# that you define this, but libremote/gdbserver does not.
  4574. +#
  4575. +# set_board_info socketport
  4576. +# Port id to use for socket connection. If not set explicitly,
  4577. +# it will start at "9996" and increment for each use.
  4578. +#
  4579. +
  4580. +
  4581. +
  4582. +#
  4583. +# gdb_load -- load a file into the debugger.
  4584. +# return a -1 if anything goes wrong.
  4585. +#
  4586. +
  4587. +global server_exec;
  4588. +global portnum;
  4589. +set portnum "9996";
  4590. +
  4591. +proc gdb_load { arg } {
  4592. + global host_exec;
  4593. + global server_exec;
  4594. + global portnum;
  4595. + global verbose;
  4596. + global gdb_prompt;
  4597. +
  4598. + regsub "/cygdrive/c" $arg "c:" arg
  4599. + regsub "/cygdrive/d" $arg "d:" arg
  4600. + regsub "/cygdrive/e" $arg "e:" arg
  4601. + regsub "/cygdrive/q" $arg "q:" arg
  4602. + regsub "/cygdrive/r" $arg "r:" arg
  4603. +
  4604. + # Always kill and restart quest (or try to before loading)
  4605. + slay quest
  4606. + slay gdb
  4607. +
  4608. + # Port id -- either specified in baseboard file, or managed here.
  4609. + if [target_info exists gdb,socketport] {
  4610. + set portnum [target_info gdb,socketport];
  4611. + } else {
  4612. + # Bump the port number to avoid conflicts with hung ports.
  4613. + incr portnum;
  4614. + }
  4615. +
  4616. + verbose "gdb_load : portnum = $portnum arg = $arg"
  4617. + # Extract the local and remote host ids from the target board struct.
  4618. +
  4619. + if [target_info exists sockethost] {
  4620. + set debughost [target_info sockethost];
  4621. + } else {
  4622. + set debughost "localhost:";
  4623. + }
  4624. + # Extract the protocol
  4625. + if [target_info exists gdb_protocol] {
  4626. + set protocol [target_info gdb_protocol];
  4627. + } else {
  4628. + set protocol "remote";
  4629. + }
  4630. +
  4631. + # Extract the name of the gdbserver, if known (default 'gdbserver').
  4632. + if [target_info exists gdb_server_prog] {
  4633. + set gdbserver [target_info gdb_server_prog];
  4634. + } else {
  4635. + set gdbserver "gdbserver";
  4636. + }
  4637. +
  4638. + verbose "gdbserver is set to $gdbserver"
  4639. + # Extract the socket hostname
  4640. + if [target_info exists sockethost] {
  4641. + set sockethost [target_info sockethost];
  4642. + } else {
  4643. + set sockethost ""
  4644. + }
  4645. +
  4646. + # Export the host:port pair.
  4647. + set gdbport $debughost$portnum;
  4648. + verbose "gdbport is now $gdbport"
  4649. + # Remember new exec file.
  4650. + if { $arg == "" } {
  4651. + if { ! [info exists host_exec] } {
  4652. + send_gdb "info files\n";
  4653. + gdb_expect 30 {
  4654. + -re "Symbols from \"(\[^\"\]+)\"" {
  4655. + set host_exec $expect_out(1,string);
  4656. + exp_continue;
  4657. + }
  4658. + -re "Local exec file:\[\r\n\]+\[ \t\]*`(\[^'\]+)'," {
  4659. + set host_exec $expect_out(1,string);
  4660. + exp_continue;
  4661. + }
  4662. + -re "$gdb_prompt $" { }
  4663. + }
  4664. + }
  4665. + } else {
  4666. + set host_exec $arg
  4667. + if [info exists server_exec] { unset server_exec }
  4668. + }
  4669. +
  4670. + # Fire off the debug agent
  4671. + if [target_info exists gdb_server_args] {
  4672. + # This flavour of gdbserver takes as arguments those specified
  4673. + # in the board configuration file
  4674. + set custom_args [target_info gdb_server_args];
  4675. + set launch_return [eval remote_spawn host \{ $gdbserver $custom_args \} $arg ]
  4676. + verbose "spawned $gdbserver $custom_args $arg with return code $launch_return"
  4677. + } else {
  4678. + # This flavour of gdbserver takes as arguments the port information
  4679. + # and the name of the executable file to be debugged.
  4680. + set server_spawn_id [remote_spawn target\
  4681. + "$gdbserver $sockethost$portnum "]
  4682. + verbose "remote_spawn $gdbserver $sockethost$portnum"
  4683. + }
  4684. +
  4685. + # We can't call close, because if gdbserver is local then that means
  4686. + # that it will get a SIGHUP.
  4687. + ## close -i $server_spawn_id
  4688. + #wait -nowait -i $server_spawn_id
  4689. +
  4690. + # Give it a little time to establish
  4691. + sleep 1
  4692. +
  4693. + # tell gdb what file we are debugging
  4694. + if { $arg != "" } {
  4695. + if [gdb_file_cmd $arg] {
  4696. + return -1;
  4697. + }
  4698. + }
  4699. + verbose "gdb_file_cmd has been called with $arg"
  4700. +
  4701. + # attach to the "serial port"
  4702. + gdb_target_cmd $protocol $gdbport;
  4703. +
  4704. + # do the real load if needed
  4705. + if [target_info exists gdb_server_do_load] {
  4706. + send_gdb "load\n"
  4707. + set timeout 2400
  4708. + verbose "Timeout is now $timeout seconds" 2
  4709. + gdb_expect {
  4710. + -re ".*$gdb_prompt $" {
  4711. + if $verbose>1 then {
  4712. + send_user "Loaded $arg into $GDB\n"
  4713. + }
  4714. + set timeout 30
  4715. + verbose "Timeout is now $timeout seconds" 2
  4716. + return 1
  4717. + }
  4718. + -re "$gdb_prompt $" {
  4719. + if $verbose>1 then {
  4720. + perror "GDB couldn't load."
  4721. + }
  4722. + }
  4723. + timeout {
  4724. + if $verbose>1 then {
  4725. + perror "Timed out trying to load $arg."
  4726. + }
  4727. + }
  4728. + }
  4729. + }
  4730. +
  4731. + return 0;
  4732. +}
  4733. diff --git a/include/dis-asm.h b/include/dis-asm.h
  4734. index af48e85..e3d84ab 100644
  4735. --- a/include/dis-asm.h
  4736. +++ b/include/dis-asm.h
  4737. @@ -280,6 +280,8 @@ extern int print_insn_xtensa (bfd_vma, disassemble_info *);
  4738. extern int print_insn_z80 (bfd_vma, disassemble_info *);
  4739. extern int print_insn_z8001 (bfd_vma, disassemble_info *);
  4740. extern int print_insn_z8002 (bfd_vma, disassemble_info *);
  4741. +extern int print_insn_little_nios2 (bfd_vma, disassemble_info *);
  4742. +extern int print_insn_big_nios2 (bfd_vma, disassemble_info *);
  4743. extern disassembler_ftype arc_get_disassembler (void *);
  4744. extern disassembler_ftype cris_get_disassembler (bfd *);
  4745. diff --git a/include/elf/nios2.h b/include/elf/nios2.h
  4746. new file mode 100644
  4747. index 0000000..ef810c5
  4748. --- /dev/null
  4749. +++ b/include/elf/nios2.h
  4750. @@ -0,0 +1,65 @@
  4751. +/* Altera New Jersey ELF support for BFD
  4752. +
  4753. + Copyright (C) 2003
  4754. + by Nigel Gray (ngray@altera.com).
  4755. +
  4756. +This file is part of BFD, the Binary File Descriptor library.
  4757. +
  4758. +This program is free software; you can redistribute it and/or modify
  4759. +it under the terms of the GNU General Public License as published by
  4760. +the Free Software Foundation; either version 2 of the License, or
  4761. +(at your option) any later version.
  4762. +
  4763. +This program is distributed in the hope that it will be useful,
  4764. +but WITHOUT ANY WARRANTY; without even the implied warranty of
  4765. +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  4766. +GNU General Public License for more details.
  4767. +
  4768. +You should have received a copy of the GNU General Public License
  4769. +along with this program; if not, write to the Free Software
  4770. +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  4771. +
  4772. +/* This file holds definitions specific to the Altera New Jersey ELF ABI. Note
  4773. + that most of this is not actually implemented by BFD. */
  4774. +
  4775. +#ifndef _ELF_NIOS2_H
  4776. +#define _ELF_NIOS2_H
  4777. +
  4778. +#include "elf/reloc-macros.h"
  4779. +
  4780. +/* the order of these numbers must match the order in
  4781. + the elf_nios2_howto_table_rel table for the lookup
  4782. + function to work properly */
  4783. +
  4784. +START_RELOC_NUMBERS (elf_nios2_reloc_type)
  4785. + RELOC_NUMBER (R_NIOS2_NONE, 0)
  4786. + RELOC_NUMBER (R_NIOS2_S16, 1)
  4787. + RELOC_NUMBER (R_NIOS2_U16, 2)
  4788. + RELOC_NUMBER (R_NIOS2_PCREL16, 3)
  4789. + RELOC_NUMBER (R_NIOS2_CALL26, 4)
  4790. + RELOC_NUMBER (R_NIOS2_IMM5, 5)
  4791. + RELOC_NUMBER (R_NIOS2_CACHE_OPX, 6)
  4792. + RELOC_NUMBER (R_NIOS2_IMM6, 7)
  4793. + RELOC_NUMBER (R_NIOS2_IMM8, 8)
  4794. + RELOC_NUMBER (R_NIOS2_HI16, 9)
  4795. + RELOC_NUMBER (R_NIOS2_LO16, 10)
  4796. + RELOC_NUMBER (R_NIOS2_HIADJ16, 11)
  4797. + RELOC_NUMBER (R_NIOS2_BFD_RELOC_32, 12)
  4798. + RELOC_NUMBER (R_NIOS2_BFD_RELOC_16, 13)
  4799. + RELOC_NUMBER (R_NIOS2_BFD_RELOC_8, 14)
  4800. + RELOC_NUMBER (R_NIOS2_GPREL, 15)
  4801. + RELOC_NUMBER (R_NIOS2_GNU_VTINHERIT, 16)
  4802. + RELOC_NUMBER (R_NIOS2_GNU_VTENTRY, 17)
  4803. + RELOC_NUMBER (R_NIOS2_UJMP, 18)
  4804. + RELOC_NUMBER (R_NIOS2_CJMP, 19)
  4805. + RELOC_NUMBER (R_NIOS2_CALLR, 20)
  4806. + RELOC_NUMBER (R_NIOS2_ALIGN, 21)
  4807. + RELOC_NUMBER (R_NIOS2_ILLEGAL, 22)
  4808. +END_RELOC_NUMBERS (R_NIOS2_maxext)
  4809. +
  4810. +/* Processor specific section flags */
  4811. +
  4812. +/* This is used to mark gp-relative sections */
  4813. +#define SHF_NIOS2_GPREL 0x10000000
  4814. +
  4815. +#endif //_ELF_NIOS2_H
  4816. diff --git a/include/opcode/nios2-isa.h b/include/opcode/nios2-isa.h
  4817. new file mode 100644
  4818. index 0000000..0023880
  4819. --- /dev/null
  4820. +++ b/include/opcode/nios2-isa.h
  4821. @@ -0,0 +1,1860 @@
  4822. +/*
  4823. + * This file defines Nios II instruction set constants.
  4824. + * To include it in assembly code (.S file), define ALT_ASM_SRC
  4825. + * before including this file.
  4826. + *
  4827. + * This file is automatically generated by gen_isa.pl - do not edit
  4828. + */
  4829. +
  4830. +#ifndef _NIOS2_ISA_H_
  4831. +#define _NIOS2_ISA_H_
  4832. +
  4833. +/* OP instruction opcode values (index is OP field) */
  4834. +#define NUM_OP_INSTS 64
  4835. +
  4836. +#ifndef ALT_ASM_SRC
  4837. +extern const char* op_names[NUM_OP_INSTS];
  4838. +#endif /* ALT_ASM_SRC */
  4839. +
  4840. +/* OPX instruction opcode values (index is OPX field) */
  4841. +#define NUM_OPX_INSTS 64
  4842. +
  4843. +#ifndef ALT_ASM_SRC
  4844. +extern const char* opx_names[NUM_OPX_INSTS];
  4845. +#endif /* ALT_ASM_SRC */
  4846. +
  4847. +/* Constants for instruction fields and ISA */
  4848. +#define CPU_RESET_EXC_ID 1
  4849. +#define DIV_ERROR_EXC_ID 9
  4850. +#define DTLB_MISS_EXC_ID 15
  4851. +#define DTLB_PERM_EXC_ID 16
  4852. +#define FAST_INTR_EXC_ID 3
  4853. +#define HBREAK_EXC_ID 0
  4854. +#define ITLB_MISS_EXC_ID 13
  4855. +#define ITLB_PERM_EXC_ID 14
  4856. +#define MISALIGNED_DATA_ADDR_EXC_ID 7
  4857. +#define MISALIGNED_TARGET_PC_EXC_ID 8
  4858. +#define NMI_EXC_ID 2
  4859. +#define NORM_INTR_EXC_ID 4
  4860. +#define SBREAK_EXC_ID 6
  4861. +#define SLAVE_DATA_ACCESS_ERROR_EXC_ID 18
  4862. +#define SLAVE_INST_ACCESS_ERROR_EXC_ID 17
  4863. +#define SUPERVISOR_DATA_ADDR_EXC_ID 12
  4864. +#define SUPERVISOR_INST_ADDR_EXC_ID 10
  4865. +#define SUPERVISOR_INST_EXC_ID 11
  4866. +#define TRAP_EXC_ID 5
  4867. +#define AT_REGNUM 1
  4868. +#define BRETADDR_REGNUM 30
  4869. +#define BSTATUS_REG_LSB 2
  4870. +#define BSTATUS_REG_MMU_LSB 0
  4871. +#define BSTATUS_REG_MMU_MSB 2
  4872. +#define BSTATUS_REG_MMU_SZ 3
  4873. +#define BSTATUS_REG_MMU_MASK 0x7
  4874. +#define BSTATUS_REG_NO_MMU_LSB 0
  4875. +#define BSTATUS_REG_NO_MMU_MSB 0
  4876. +#define BSTATUS_REG_NO_MMU_SZ 1
  4877. +#define BSTATUS_REG_NO_MMU_MASK 0x1
  4878. +#define BSTATUS_REG_REGNUM 2
  4879. +#define BSTATUS_REG_SZ 3
  4880. +#define BSTATUS_REG_MASK 0x7
  4881. +#define BT_REGNUM 25
  4882. +#define CACHE_MAX_BYTES 65536
  4883. +#define CACHE_MAX_LINE_BYTES 32
  4884. +#define CACHE_MIN_LINE_BYTES 4
  4885. +#define COMPARE_OP_EQ 0x0
  4886. +#define COMPARE_OP_GE 0x1
  4887. +#define COMPARE_OP_LSB 3
  4888. +#define COMPARE_OP_LT 0x2
  4889. +#define COMPARE_OP_MSB 4
  4890. +#define COMPARE_OP_NE 0x3
  4891. +#define COMPARE_OP_SZ 2
  4892. +#define COMPARE_OP_MASK 0x3
  4893. +#define CPUID_REG_LSB 0
  4894. +#define CPUID_REG_MSB 31
  4895. +#define CPUID_REG_REGNUM 5
  4896. +#define CPUID_REG_SZ 32
  4897. +#define CPUID_REG_MASK 0xffffffff
  4898. +#define DATAPATH_LOG2_SZ 5
  4899. +#define DATAPATH_LOG2_MASK 0x1f
  4900. +#define DATAPATH_LSB 0
  4901. +#define DATAPATH_MSB 31
  4902. +#define DATAPATH_SZ 32
  4903. +#define DATAPATH_MASK 0xffffffff
  4904. +#define EMPTY_CRST_IW 127034
  4905. +#define EMPTY_HBREAK_IW 4040762
  4906. +#define EMPTY_INTR_IW 3926074
  4907. +#define EMPTY_NOP_IW 100410
  4908. +#define EMPTY_RET_IW 4160759866
  4909. +#define ERETADDR_REGNUM 29
  4910. +#define ESTATUS_REG_LSB 0
  4911. +#define ESTATUS_REG_MMU_LSB 0
  4912. +#define ESTATUS_REG_MMU_MSB 2
  4913. +#define ESTATUS_REG_MMU_SZ 3
  4914. +#define ESTATUS_REG_MMU_MASK 0x7
  4915. +#define ESTATUS_REG_MSB 2
  4916. +#define ESTATUS_REG_NO_MMU_LSB 0
  4917. +#define ESTATUS_REG_NO_MMU_MSB 0
  4918. +#define ESTATUS_REG_NO_MMU_SZ 1
  4919. +#define ESTATUS_REG_NO_MMU_MASK 0x1
  4920. +#define ESTATUS_REG_REGNUM 1
  4921. +#define ESTATUS_REG_SZ 3
  4922. +#define ESTATUS_REG_MASK 0x7
  4923. +#define ET_REGNUM 24
  4924. +#define EXCEPTION_REG_LSB 0
  4925. +#define EXCEPTION_REG_MEA_LSB 0
  4926. +#define EXCEPTION_REG_MEA_MSB 0
  4927. +#define EXCEPTION_REG_MEA_SZ 1
  4928. +#define EXCEPTION_REG_MEA_MASK 0x1
  4929. +#define EXCEPTION_REG_MEE_LSB 1
  4930. +#define EXCEPTION_REG_MEE_MSB 1
  4931. +#define EXCEPTION_REG_MEE_SZ 1
  4932. +#define EXCEPTION_REG_MEE_MASK 0x1
  4933. +#define EXCEPTION_REG_MSB 1
  4934. +#define EXCEPTION_REG_REGNUM 7
  4935. +#define EXCEPTION_REG_SZ 2
  4936. +#define EXCEPTION_REG_MASK 0x3
  4937. +#define FP_REGNUM 28
  4938. +#define FSTATUS_REG_REGNUM 11
  4939. +#define GP_REGNUM 26
  4940. +#define IENABLE_REG_LSB 0
  4941. +#define IENABLE_REG_MSB 31
  4942. +#define IENABLE_REG_REGNUM 3
  4943. +#define IENABLE_REG_SZ 32
  4944. +#define IENABLE_REG_MASK 0xffffffff
  4945. +#define IPENDING_REG_LSB 0
  4946. +#define IPENDING_REG_MSB 31
  4947. +#define IPENDING_REG_REGNUM 4
  4948. +#define IPENDING_REG_SZ 32
  4949. +#define IPENDING_REG_MASK 0xffffffff
  4950. +#define IW_A_LSB 27
  4951. +#define IW_A_MSB 31
  4952. +#define IW_A_SZ 5
  4953. +#define IW_A_MASK 0x1f
  4954. +#define IW_B_LSB 22
  4955. +#define IW_B_MSB 26
  4956. +#define IW_B_SZ 5
  4957. +#define IW_B_MASK 0x1f
  4958. +#define IW_C_LSB 17
  4959. +#define IW_C_MSB 21
  4960. +#define IW_C_SZ 5
  4961. +#define IW_C_MASK 0x1f
  4962. +#define IW_CONTROL_REGNUM_BASE 0
  4963. +#define IW_CONTROL_REGNUM_LSB 6
  4964. +#define IW_CONTROL_REGNUM_MSB 9
  4965. +#define IW_CONTROL_REGNUM_SZ 4
  4966. +#define IW_CONTROL_REGNUM_MASK 0xf
  4967. +#define IW_CUSTOM_N_LSB 6
  4968. +#define IW_CUSTOM_N_MSB 13
  4969. +#define IW_CUSTOM_N_SZ 8
  4970. +#define IW_CUSTOM_N_MASK 0xff
  4971. +#define IW_CUSTOM_READRA_LSB 16
  4972. +#define IW_CUSTOM_READRA_MSB 16
  4973. +#define IW_CUSTOM_READRA_SZ 1
  4974. +#define IW_CUSTOM_READRA_MASK 0x1
  4975. +#define IW_CUSTOM_READRB_LSB 15
  4976. +#define IW_CUSTOM_READRB_MSB 15
  4977. +#define IW_CUSTOM_READRB_SZ 1
  4978. +#define IW_CUSTOM_READRB_MASK 0x1
  4979. +#define IW_CUSTOM_WRITERC_LSB 14
  4980. +#define IW_CUSTOM_WRITERC_MSB 14
  4981. +#define IW_CUSTOM_WRITERC_SZ 1
  4982. +#define IW_CUSTOM_WRITERC_MASK 0x1
  4983. +#define IW_IMM16_LSB 6
  4984. +#define IW_IMM16_MSB 21
  4985. +#define IW_IMM16_SZ 16
  4986. +#define IW_IMM16_MASK 0xffff
  4987. +#define IW_IMM26_LSB 6
  4988. +#define IW_IMM26_MSB 31
  4989. +#define IW_IMM26_SZ 26
  4990. +#define IW_IMM26_MASK 0x3ffffff
  4991. +#define IW_MEMSZ_BYTE 0x0
  4992. +#define IW_MEMSZ_HWORD 0x1
  4993. +#define IW_MEMSZ_LSB 3
  4994. +#define IW_MEMSZ_MSB 4
  4995. +#define IW_MEMSZ_SZ 2
  4996. +#define IW_MEMSZ_MASK 0x3
  4997. +#define IW_MEMSZ_WORD 0x2
  4998. +#define IW_MEMSZ_WORD_MSB 0x1
  4999. +#define IW_OP_LSB 0
  5000. +#define IW_OP_MSB 5
  5001. +#define IW_OP_SZ 6
  5002. +#define IW_OP_MASK 0x3f
  5003. +#define IW_OPX_LSB 11
  5004. +#define IW_OPX_MSB 16
  5005. +#define IW_OPX_SZ 6
  5006. +#define IW_OPX_MASK 0x3f
  5007. +#define IW_SHIFT_IMM5_LSB 6
  5008. +#define IW_SHIFT_IMM5_MSB 10
  5009. +#define IW_SHIFT_IMM5_SZ 5
  5010. +#define IW_SHIFT_IMM5_MASK 0x1f
  5011. +#define IW_SZ 32
  5012. +#define IW_MASK 0xffffffff
  5013. +#define IW_TRAP_BREAK_IMM5_LSB 6
  5014. +#define IW_TRAP_BREAK_IMM5_MSB 10
  5015. +#define IW_TRAP_BREAK_IMM5_SZ 5
  5016. +#define IW_TRAP_BREAK_IMM5_MASK 0x1f
  5017. +#define JMP_CALLR_VS_RET_IS_RET 0
  5018. +#define JMP_CALLR_VS_RET_OPX_BIT 3
  5019. +#define LOGIC_OP_AND 0x1
  5020. +#define LOGIC_OP_LSB 3
  5021. +#define LOGIC_OP_MSB 4
  5022. +#define LOGIC_OP_NOR 0x0
  5023. +#define LOGIC_OP_OR 0x2
  5024. +#define LOGIC_OP_SZ 2
  5025. +#define LOGIC_OP_MASK 0x3
  5026. +#define LOGIC_OP_XOR 0x3
  5027. +#define MMU_ADDR_BYPASS_TLB 0x3
  5028. +#define MMU_ADDR_BYPASS_TLB_CACHEABLE 0x0
  5029. +#define MMU_ADDR_BYPASS_TLB_CACHEABLE_LSB 29
  5030. +#define MMU_ADDR_BYPASS_TLB_CACHEABLE_MSB 29
  5031. +#define MMU_ADDR_BYPASS_TLB_CACHEABLE_SZ 1
  5032. +#define MMU_ADDR_BYPASS_TLB_CACHEABLE_MASK 0x1
  5033. +#define MMU_ADDR_BYPASS_TLB_LSB 30
  5034. +#define MMU_ADDR_BYPASS_TLB_MSB 31
  5035. +#define MMU_ADDR_BYPASS_TLB_PADDR_LSB 0
  5036. +#define MMU_ADDR_BYPASS_TLB_PADDR_MSB 28
  5037. +#define MMU_ADDR_BYPASS_TLB_PADDR_SZ 29
  5038. +#define MMU_ADDR_BYPASS_TLB_PADDR_MASK 0x1fffffff
  5039. +#define MMU_ADDR_BYPASS_TLB_SZ 2
  5040. +#define MMU_ADDR_BYPASS_TLB_MASK 0x3
  5041. +#define MMU_ADDR_IO_REGION 0x7
  5042. +#define MMU_ADDR_IO_REGION_LSB 29
  5043. +#define MMU_ADDR_IO_REGION_MSB 31
  5044. +#define MMU_ADDR_IO_REGION_SZ 3
  5045. +#define MMU_ADDR_IO_REGION_MASK 0x7
  5046. +#define MMU_ADDR_IO_REGION_VPN 0xe0000
  5047. +#define MMU_ADDR_KERNEL_MMU_REGION 0x2
  5048. +#define MMU_ADDR_KERNEL_MMU_REGION_LSB 30
  5049. +#define MMU_ADDR_KERNEL_MMU_REGION_MSB 31
  5050. +#define MMU_ADDR_KERNEL_MMU_REGION_SZ 2
  5051. +#define MMU_ADDR_KERNEL_MMU_REGION_MASK 0x3
  5052. +#define MMU_ADDR_KERNEL_REGION 0x6
  5053. +#define MMU_ADDR_KERNEL_REGION_INT 6
  5054. +#define MMU_ADDR_KERNEL_REGION_LSB 29
  5055. +#define MMU_ADDR_KERNEL_REGION_MSB 31
  5056. +#define MMU_ADDR_KERNEL_REGION_SZ 3
  5057. +#define MMU_ADDR_KERNEL_REGION_MASK 0x7
  5058. +#define MMU_ADDR_PAGE_OFFSET_LSB 0
  5059. +#define MMU_ADDR_PAGE_OFFSET_MSB 11
  5060. +#define MMU_ADDR_PAGE_OFFSET_SZ 12
  5061. +#define MMU_ADDR_PAGE_OFFSET_MASK 0xfff
  5062. +#define MMU_ADDR_PFN_LSB 12
  5063. +#define MMU_ADDR_PFN_MSB 31
  5064. +#define MMU_ADDR_PFN_SZ 20
  5065. +#define MMU_ADDR_PFN_MASK 0xfffff
  5066. +#define MMU_ADDR_USER_REGION 0x0
  5067. +#define MMU_ADDR_USER_REGION_LSB 31
  5068. +#define MMU_ADDR_USER_REGION_MSB 31
  5069. +#define MMU_ADDR_USER_REGION_SZ 1
  5070. +#define MMU_ADDR_USER_REGION_MASK 0x1
  5071. +#define MMU_ADDR_VPN_LSB 12
  5072. +#define MMU_ADDR_VPN_MSB 31
  5073. +#define MMU_ADDR_VPN_SZ 20
  5074. +#define MMU_ADDR_VPN_MASK 0xfffff
  5075. +#define PTEADDR_REG_LSB 0
  5076. +#define PTEADDR_REG_MSB 31
  5077. +#define PTEADDR_REG_PTBASE_LSB 22
  5078. +#define PTEADDR_REG_PTBASE_MSB 31
  5079. +#define PTEADDR_REG_PTBASE_SZ 10
  5080. +#define PTEADDR_REG_PTBASE_MASK 0x3ff
  5081. +#define PTEADDR_REG_REGNUM 8
  5082. +#define PTEADDR_REG_RSV_LSB 0
  5083. +#define PTEADDR_REG_RSV_MSB 1
  5084. +#define PTEADDR_REG_RSV_SZ 2
  5085. +#define PTEADDR_REG_RSV_MASK 0x3
  5086. +#define PTEADDR_REG_SZ 32
  5087. +#define PTEADDR_REG_MASK 0xffffffff
  5088. +#define PTEADDR_REG_VPN_LSB 2
  5089. +#define PTEADDR_REG_VPN_MSB 21
  5090. +#define PTEADDR_REG_VPN_SZ 20
  5091. +#define PTEADDR_REG_VPN_MASK 0xfffff
  5092. +#define REGNUM_SZ 5
  5093. +#define REGNUM_MASK 0x1f
  5094. +#define RETADDR_REGNUM 31
  5095. +#define RF_ADDR_SZ 5
  5096. +#define RF_ADDR_MASK 0x1f
  5097. +#define RF_NUM_REG 32
  5098. +#define SIM_REG_LSB 0
  5099. +#define SIM_REG_MSB 3
  5100. +#define SIM_REG_PERF_CNT_CLR_LSB 2
  5101. +#define SIM_REG_PERF_CNT_CLR_MSB 2
  5102. +#define SIM_REG_PERF_CNT_CLR_SZ 1
  5103. +#define SIM_REG_PERF_CNT_CLR_MASK 0x1
  5104. +#define SIM_REG_PERF_CNT_EN_LSB 1
  5105. +#define SIM_REG_PERF_CNT_EN_MSB 1
  5106. +#define SIM_REG_PERF_CNT_EN_SZ 1
  5107. +#define SIM_REG_PERF_CNT_EN_MASK 0x1
  5108. +#define SIM_REG_REGNUM 6
  5109. +#define SIM_REG_SHOW_DTLB_LSB 4
  5110. +#define SIM_REG_SHOW_DTLB_MSB 4
  5111. +#define SIM_REG_SHOW_DTLB_SZ 1
  5112. +#define SIM_REG_SHOW_DTLB_MASK 0x1
  5113. +#define SIM_REG_SHOW_ITLB_LSB 3
  5114. +#define SIM_REG_SHOW_ITLB_MSB 3
  5115. +#define SIM_REG_SHOW_ITLB_SZ 1
  5116. +#define SIM_REG_SHOW_ITLB_MASK 0x1
  5117. +#define SIM_REG_SHOW_MMU_REGS_LSB 5
  5118. +#define SIM_REG_SHOW_MMU_REGS_MSB 5
  5119. +#define SIM_REG_SHOW_MMU_REGS_SZ 1
  5120. +#define SIM_REG_SHOW_MMU_REGS_MASK 0x1
  5121. +#define SIM_REG_STOP_LSB 0
  5122. +#define SIM_REG_STOP_MSB 0
  5123. +#define SIM_REG_STOP_SZ 1
  5124. +#define SIM_REG_STOP_MASK 0x1
  5125. +#define SIM_REG_SZ 4
  5126. +#define SIM_REG_MASK 0xf
  5127. +#define SP_REGNUM 27
  5128. +#define STATUS_REG_EH_LSB 2
  5129. +#define STATUS_REG_EH_MSB 2
  5130. +#define STATUS_REG_EH_SZ 1
  5131. +#define STATUS_REG_EH_MASK 0x1
  5132. +#define STATUS_REG_LSB 0
  5133. +#define STATUS_REG_MMU_LSB 0
  5134. +#define STATUS_REG_MMU_MSB 2
  5135. +#define STATUS_REG_MMU_RSV_LSB 3
  5136. +#define STATUS_REG_MMU_RSV_MSB 31
  5137. +#define STATUS_REG_MMU_RSV_SZ 29
  5138. +#define STATUS_REG_MMU_RSV_MASK 0x1fffffff
  5139. +#define STATUS_REG_MMU_SZ 3
  5140. +#define STATUS_REG_MMU_MASK 0x7
  5141. +#define STATUS_REG_MSB 2
  5142. +#define STATUS_REG_NO_MMU_LSB 0
  5143. +#define STATUS_REG_NO_MMU_MSB 0
  5144. +#define STATUS_REG_NO_MMU_RSV_LSB 1
  5145. +#define STATUS_REG_NO_MMU_RSV_MSB 31
  5146. +#define STATUS_REG_NO_MMU_RSV_SZ 31
  5147. +#define STATUS_REG_NO_MMU_RSV_MASK 0x7fffffff
  5148. +#define STATUS_REG_NO_MMU_SZ 1
  5149. +#define STATUS_REG_NO_MMU_MASK 0x1
  5150. +#define STATUS_REG_PIE_LSB 0
  5151. +#define STATUS_REG_PIE_MSB 0
  5152. +#define STATUS_REG_PIE_SZ 1
  5153. +#define STATUS_REG_PIE_MASK 0x1
  5154. +#define STATUS_REG_REGNUM 0
  5155. +#define STATUS_REG_SZ 3
  5156. +#define STATUS_REG_MASK 0x7
  5157. +#define STATUS_REG_U_LSB 1
  5158. +#define STATUS_REG_U_MSB 1
  5159. +#define STATUS_REG_U_SZ 1
  5160. +#define STATUS_REG_U_MASK 0x1
  5161. +#define TLB_MAX_ENTRIES 1024
  5162. +#define TLB_MAX_LINES 512
  5163. +#define TLB_MAX_PID_SZ 14
  5164. +#define TLB_MAX_PID_MASK 0x3fff
  5165. +#define TLB_MAX_PTR_SZ 10
  5166. +#define TLB_MAX_PTR_MASK 0x3ff
  5167. +#define TLB_MAX_WAYS 8
  5168. +#define TLB_MIN_PID_SZ 1
  5169. +#define TLB_MIN_PID_MASK 0x1
  5170. +#define TLB_MIN_PTR_SZ 7
  5171. +#define TLB_MIN_PTR_MASK 0x7f
  5172. +#define TLB_MIN_WAYS 2
  5173. +#define TLBACC_REG_C_LSB 24
  5174. +#define TLBACC_REG_C_MSB 24
  5175. +#define TLBACC_REG_C_SZ 1
  5176. +#define TLBACC_REG_C_MASK 0x1
  5177. +#define TLBACC_REG_G_LSB 20
  5178. +#define TLBACC_REG_G_MSB 20
  5179. +#define TLBACC_REG_G_SZ 1
  5180. +#define TLBACC_REG_G_MASK 0x1
  5181. +#define TLBACC_REG_IG_LSB 25
  5182. +#define TLBACC_REG_IG_MSB 31
  5183. +#define TLBACC_REG_IG_SZ 7
  5184. +#define TLBACC_REG_IG_MASK 0x7f
  5185. +#define TLBACC_REG_LSB 0
  5186. +#define TLBACC_REG_MSB 24
  5187. +#define TLBACC_REG_PFN_LSB 0
  5188. +#define TLBACC_REG_PFN_MSB 19
  5189. +#define TLBACC_REG_PFN_SZ 20
  5190. +#define TLBACC_REG_PFN_MASK 0xfffff
  5191. +#define TLBACC_REG_R_LSB 23
  5192. +#define TLBACC_REG_R_MSB 23
  5193. +#define TLBACC_REG_R_SZ 1
  5194. +#define TLBACC_REG_R_MASK 0x1
  5195. +#define TLBACC_REG_REGNUM 9
  5196. +#define TLBACC_REG_SZ 25
  5197. +#define TLBACC_REG_MASK 0x1ffffff
  5198. +#define TLBACC_REG_W_LSB 22
  5199. +#define TLBACC_REG_W_MSB 22
  5200. +#define TLBACC_REG_W_SZ 1
  5201. +#define TLBACC_REG_W_MASK 0x1
  5202. +#define TLBACC_REG_X_LSB 21
  5203. +#define TLBACC_REG_X_MSB 21
  5204. +#define TLBACC_REG_X_SZ 1
  5205. +#define TLBACC_REG_X_MASK 0x1
  5206. +#define TLBMISC_REG_BAD_LSB 2
  5207. +#define TLBMISC_REG_BAD_MSB 2
  5208. +#define TLBMISC_REG_BAD_SZ 1
  5209. +#define TLBMISC_REG_BAD_MASK 0x1
  5210. +#define TLBMISC_REG_D_LSB 0
  5211. +#define TLBMISC_REG_D_MSB 0
  5212. +#define TLBMISC_REG_D_SZ 1
  5213. +#define TLBMISC_REG_D_MASK 0x1
  5214. +#define TLBMISC_REG_DBL_LSB 3
  5215. +#define TLBMISC_REG_DBL_MSB 3
  5216. +#define TLBMISC_REG_DBL_SZ 1
  5217. +#define TLBMISC_REG_DBL_MASK 0x1
  5218. +#define TLBMISC_REG_LSB 0
  5219. +#define TLBMISC_REG_MSB 23
  5220. +#define TLBMISC_REG_PERM_LSB 1
  5221. +#define TLBMISC_REG_PERM_MSB 1
  5222. +#define TLBMISC_REG_PERM_SZ 1
  5223. +#define TLBMISC_REG_PERM_MASK 0x1
  5224. +#define TLBMISC_REG_PID_LSB 4
  5225. +#define TLBMISC_REG_PID_MSB 17
  5226. +#define TLBMISC_REG_PID_SZ 14
  5227. +#define TLBMISC_REG_PID_MASK 0x3fff
  5228. +#define TLBMISC_REG_RD_LSB 24
  5229. +#define TLBMISC_REG_RD_MSB 24
  5230. +#define TLBMISC_REG_RD_SZ 1
  5231. +#define TLBMISC_REG_RD_MASK 0x1
  5232. +#define TLBMISC_REG_REGNUM 10
  5233. +#define TLBMISC_REG_RSV0_LSB 18
  5234. +#define TLBMISC_REG_RSV0_MSB 19
  5235. +#define TLBMISC_REG_RSV0_SZ 2
  5236. +#define TLBMISC_REG_RSV0_MASK 0x3
  5237. +#define TLBMISC_REG_RSV1_LSB 25
  5238. +#define TLBMISC_REG_RSV1_MSB 31
  5239. +#define TLBMISC_REG_RSV1_SZ 7
  5240. +#define TLBMISC_REG_RSV1_MASK 0x7f
  5241. +#define TLBMISC_REG_SZ 24
  5242. +#define TLBMISC_REG_MASK 0xffffff
  5243. +#define TLBMISC_REG_WAY_LSB 20
  5244. +#define TLBMISC_REG_WAY_MSB 22
  5245. +#define TLBMISC_REG_WAY_SZ 3
  5246. +#define TLBMISC_REG_WAY_MASK 0x7
  5247. +#define TLBMISC_REG_WE_LSB 23
  5248. +#define TLBMISC_REG_WE_MSB 23
  5249. +#define TLBMISC_REG_WE_SZ 1
  5250. +#define TLBMISC_REG_WE_MASK 0x1
  5251. +
  5252. +/* Macros to extract instruction fields */
  5253. +#define GET_IW_A(Iw) \
  5254. + (((Iw) >> IW_A_LSB) & IW_A_MASK)
  5255. +#define SET_IW_A(Iw, Val) \
  5256. + Iw = (((Iw) & (~(IW_A_MASK << IW_A_LSB))) | \
  5257. + (((Val) & IW_A_MASK) << IW_A_LSB))
  5258. +#define GET_IW_B(Iw) \
  5259. + (((Iw) >> IW_B_LSB) & IW_B_MASK)
  5260. +#define SET_IW_B(Iw, Val) \
  5261. + Iw = (((Iw) & (~(IW_B_MASK << IW_B_LSB))) | \
  5262. + (((Val) & IW_B_MASK) << IW_B_LSB))
  5263. +#define GET_IW_C(Iw) \
  5264. + (((Iw) >> IW_C_LSB) & IW_C_MASK)
  5265. +#define SET_IW_C(Iw, Val) \
  5266. + Iw = (((Iw) & (~(IW_C_MASK << IW_C_LSB))) | \
  5267. + (((Val) & IW_C_MASK) << IW_C_LSB))
  5268. +#define GET_IW_CONTROL_REGNUM(Iw) \
  5269. + (((Iw) >> IW_CONTROL_REGNUM_LSB) & IW_CONTROL_REGNUM_MASK)
  5270. +#define SET_IW_CONTROL_REGNUM(Iw, Val) \
  5271. + Iw = (((Iw) & (~(IW_CONTROL_REGNUM_MASK << IW_CONTROL_REGNUM_LSB))) | \
  5272. + (((Val) & IW_CONTROL_REGNUM_MASK) << IW_CONTROL_REGNUM_LSB))
  5273. +#define GET_IW_CUSTOM_N(Iw) \
  5274. + (((Iw) >> IW_CUSTOM_N_LSB) & IW_CUSTOM_N_MASK)
  5275. +#define SET_IW_CUSTOM_N(Iw, Val) \
  5276. + Iw = (((Iw) & (~(IW_CUSTOM_N_MASK << IW_CUSTOM_N_LSB))) | \
  5277. + (((Val) & IW_CUSTOM_N_MASK) << IW_CUSTOM_N_LSB))
  5278. +#define GET_IW_CUSTOM_READRA(Iw) \
  5279. + (((Iw) >> IW_CUSTOM_READRA_LSB) & IW_CUSTOM_READRA_MASK)
  5280. +#define SET_IW_CUSTOM_READRA(Iw, Val) \
  5281. + Iw = (((Iw) & (~(IW_CUSTOM_READRA_MASK << IW_CUSTOM_READRA_LSB))) | \
  5282. + (((Val) & IW_CUSTOM_READRA_MASK) << IW_CUSTOM_READRA_LSB))
  5283. +#define GET_IW_CUSTOM_READRB(Iw) \
  5284. + (((Iw) >> IW_CUSTOM_READRB_LSB) & IW_CUSTOM_READRB_MASK)
  5285. +#define SET_IW_CUSTOM_READRB(Iw, Val) \
  5286. + Iw = (((Iw) & (~(IW_CUSTOM_READRB_MASK << IW_CUSTOM_READRB_LSB))) | \
  5287. + (((Val) & IW_CUSTOM_READRB_MASK) << IW_CUSTOM_READRB_LSB))
  5288. +#define GET_IW_CUSTOM_WRITERC(Iw) \
  5289. + (((Iw) >> IW_CUSTOM_WRITERC_LSB) & IW_CUSTOM_WRITERC_MASK)
  5290. +#define SET_IW_CUSTOM_WRITERC(Iw, Val) \
  5291. + Iw = (((Iw) & (~(IW_CUSTOM_WRITERC_MASK << IW_CUSTOM_WRITERC_LSB))) | \
  5292. + (((Val) & IW_CUSTOM_WRITERC_MASK) << IW_CUSTOM_WRITERC_LSB))
  5293. +#define GET_IW_IMM16(Iw) \
  5294. + (((Iw) >> IW_IMM16_LSB) & IW_IMM16_MASK)
  5295. +#define SET_IW_IMM16(Iw, Val) \
  5296. + Iw = (((Iw) & (~(IW_IMM16_MASK << IW_IMM16_LSB))) | \
  5297. + (((Val) & IW_IMM16_MASK) << IW_IMM16_LSB))
  5298. +#define GET_IW_IMM26(Iw) \
  5299. + (((Iw) >> IW_IMM26_LSB) & IW_IMM26_MASK)
  5300. +#define SET_IW_IMM26(Iw, Val) \
  5301. + Iw = (((Iw) & (~(IW_IMM26_MASK << IW_IMM26_LSB))) | \
  5302. + (((Val) & IW_IMM26_MASK) << IW_IMM26_LSB))
  5303. +#define GET_IW_MEMSZ(Iw) \
  5304. + (((Iw) >> IW_MEMSZ_LSB) & IW_MEMSZ_MASK)
  5305. +#define SET_IW_MEMSZ(Iw, Val) \
  5306. + Iw = (((Iw) & (~(IW_MEMSZ_MASK << IW_MEMSZ_LSB))) | \
  5307. + (((Val) & IW_MEMSZ_MASK) << IW_MEMSZ_LSB))
  5308. +#define GET_IW_OP(Iw) \
  5309. + (((Iw) >> IW_OP_LSB) & IW_OP_MASK)
  5310. +#define SET_IW_OP(Iw, Val) \
  5311. + Iw = (((Iw) & (~(IW_OP_MASK << IW_OP_LSB))) | \
  5312. + (((Val) & IW_OP_MASK) << IW_OP_LSB))
  5313. +#define GET_IW_OPX(Iw) \
  5314. + (((Iw) >> IW_OPX_LSB) & IW_OPX_MASK)
  5315. +#define SET_IW_OPX(Iw, Val) \
  5316. + Iw = (((Iw) & (~(IW_OPX_MASK << IW_OPX_LSB))) | \
  5317. + (((Val) & IW_OPX_MASK) << IW_OPX_LSB))
  5318. +#define GET_IW_SHIFT_IMM5(Iw) \
  5319. + (((Iw) >> IW_SHIFT_IMM5_LSB) & IW_SHIFT_IMM5_MASK)
  5320. +#define SET_IW_SHIFT_IMM5(Iw, Val) \
  5321. + Iw = (((Iw) & (~(IW_SHIFT_IMM5_MASK << IW_SHIFT_IMM5_LSB))) | \
  5322. + (((Val) & IW_SHIFT_IMM5_MASK) << IW_SHIFT_IMM5_LSB))
  5323. +#define GET_IW_TRAP_BREAK_IMM5(Iw) \
  5324. + (((Iw) >> IW_TRAP_BREAK_IMM5_LSB) & IW_TRAP_BREAK_IMM5_MASK)
  5325. +#define SET_IW_TRAP_BREAK_IMM5(Iw, Val) \
  5326. + Iw = (((Iw) & (~(IW_TRAP_BREAK_IMM5_MASK << IW_TRAP_BREAK_IMM5_LSB))) | \
  5327. + (((Val) & IW_TRAP_BREAK_IMM5_MASK) << IW_TRAP_BREAK_IMM5_LSB))
  5328. +
  5329. +/* Macros to extract control register fields */
  5330. +#define GET_BSTATUS_REG_MMU(Reg) \
  5331. + (((Reg) >> BSTATUS_REG_MMU_LSB) & BSTATUS_REG_MMU_MASK)
  5332. +#define SET_BSTATUS_REG_MMU(Reg, Val) \
  5333. + Reg = (((Reg) & (~(BSTATUS_REG_MMU_MASK << BSTATUS_REG_MMU_LSB))) | \
  5334. + (((Val) & BSTATUS_REG_MMU_MASK) << BSTATUS_REG_MMU_LSB))
  5335. +#define GET_BSTATUS_REG_NO_MMU(Reg) \
  5336. + (((Reg) >> BSTATUS_REG_NO_MMU_LSB) & BSTATUS_REG_NO_MMU_MASK)
  5337. +#define SET_BSTATUS_REG_NO_MMU(Reg, Val) \
  5338. + Reg = (((Reg) & (~(BSTATUS_REG_NO_MMU_MASK << BSTATUS_REG_NO_MMU_LSB))) | \
  5339. + (((Val) & BSTATUS_REG_NO_MMU_MASK) << BSTATUS_REG_NO_MMU_LSB))
  5340. +#define GET_ESTATUS_REG_MMU(Reg) \
  5341. + (((Reg) >> ESTATUS_REG_MMU_LSB) & ESTATUS_REG_MMU_MASK)
  5342. +#define SET_ESTATUS_REG_MMU(Reg, Val) \
  5343. + Reg = (((Reg) & (~(ESTATUS_REG_MMU_MASK << ESTATUS_REG_MMU_LSB))) | \
  5344. + (((Val) & ESTATUS_REG_MMU_MASK) << ESTATUS_REG_MMU_LSB))
  5345. +#define GET_ESTATUS_REG_NO_MMU(Reg) \
  5346. + (((Reg) >> ESTATUS_REG_NO_MMU_LSB) & ESTATUS_REG_NO_MMU_MASK)
  5347. +#define SET_ESTATUS_REG_NO_MMU(Reg, Val) \
  5348. + Reg = (((Reg) & (~(ESTATUS_REG_NO_MMU_MASK << ESTATUS_REG_NO_MMU_LSB))) | \
  5349. + (((Val) & ESTATUS_REG_NO_MMU_MASK) << ESTATUS_REG_NO_MMU_LSB))
  5350. +#define GET_EXCEPTION_REG_MEA(Reg) \
  5351. + (((Reg) >> EXCEPTION_REG_MEA_LSB) & EXCEPTION_REG_MEA_MASK)
  5352. +#define SET_EXCEPTION_REG_MEA(Reg, Val) \
  5353. + Reg = (((Reg) & (~(EXCEPTION_REG_MEA_MASK << EXCEPTION_REG_MEA_LSB))) | \
  5354. + (((Val) & EXCEPTION_REG_MEA_MASK) << EXCEPTION_REG_MEA_LSB))
  5355. +#define GET_EXCEPTION_REG_MEE(Reg) \
  5356. + (((Reg) >> EXCEPTION_REG_MEE_LSB) & EXCEPTION_REG_MEE_MASK)
  5357. +#define SET_EXCEPTION_REG_MEE(Reg, Val) \
  5358. + Reg = (((Reg) & (~(EXCEPTION_REG_MEE_MASK << EXCEPTION_REG_MEE_LSB))) | \
  5359. + (((Val) & EXCEPTION_REG_MEE_MASK) << EXCEPTION_REG_MEE_LSB))
  5360. +#define GET_PTEADDR_REG_PTBASE(Reg) \
  5361. + (((Reg) >> PTEADDR_REG_PTBASE_LSB) & PTEADDR_REG_PTBASE_MASK)
  5362. +#define SET_PTEADDR_REG_PTBASE(Reg, Val) \
  5363. + Reg = (((Reg) & (~(PTEADDR_REG_PTBASE_MASK << PTEADDR_REG_PTBASE_LSB))) | \
  5364. + (((Val) & PTEADDR_REG_PTBASE_MASK) << PTEADDR_REG_PTBASE_LSB))
  5365. +#define GET_PTEADDR_REG_RSV(Reg) \
  5366. + (((Reg) >> PTEADDR_REG_RSV_LSB) & PTEADDR_REG_RSV_MASK)
  5367. +#define SET_PTEADDR_REG_RSV(Reg, Val) \
  5368. + Reg = (((Reg) & (~(PTEADDR_REG_RSV_MASK << PTEADDR_REG_RSV_LSB))) | \
  5369. + (((Val) & PTEADDR_REG_RSV_MASK) << PTEADDR_REG_RSV_LSB))
  5370. +#define GET_PTEADDR_REG_VPN(Reg) \
  5371. + (((Reg) >> PTEADDR_REG_VPN_LSB) & PTEADDR_REG_VPN_MASK)
  5372. +#define SET_PTEADDR_REG_VPN(Reg, Val) \
  5373. + Reg = (((Reg) & (~(PTEADDR_REG_VPN_MASK << PTEADDR_REG_VPN_LSB))) | \
  5374. + (((Val) & PTEADDR_REG_VPN_MASK) << PTEADDR_REG_VPN_LSB))
  5375. +#define GET_SIM_REG_PERF_CNT_CLR(Reg) \
  5376. + (((Reg) >> SIM_REG_PERF_CNT_CLR_LSB) & SIM_REG_PERF_CNT_CLR_MASK)
  5377. +#define SET_SIM_REG_PERF_CNT_CLR(Reg, Val) \
  5378. + Reg = (((Reg) & (~(SIM_REG_PERF_CNT_CLR_MASK << SIM_REG_PERF_CNT_CLR_LSB))) | \
  5379. + (((Val) & SIM_REG_PERF_CNT_CLR_MASK) << SIM_REG_PERF_CNT_CLR_LSB))
  5380. +#define GET_SIM_REG_PERF_CNT_EN(Reg) \
  5381. + (((Reg) >> SIM_REG_PERF_CNT_EN_LSB) & SIM_REG_PERF_CNT_EN_MASK)
  5382. +#define SET_SIM_REG_PERF_CNT_EN(Reg, Val) \
  5383. + Reg = (((Reg) & (~(SIM_REG_PERF_CNT_EN_MASK << SIM_REG_PERF_CNT_EN_LSB))) | \
  5384. + (((Val) & SIM_REG_PERF_CNT_EN_MASK) << SIM_REG_PERF_CNT_EN_LSB))
  5385. +#define GET_SIM_REG_SHOW_DTLB(Reg) \
  5386. + (((Reg) >> SIM_REG_SHOW_DTLB_LSB) & SIM_REG_SHOW_DTLB_MASK)
  5387. +#define SET_SIM_REG_SHOW_DTLB(Reg, Val) \
  5388. + Reg = (((Reg) & (~(SIM_REG_SHOW_DTLB_MASK << SIM_REG_SHOW_DTLB_LSB))) | \
  5389. + (((Val) & SIM_REG_SHOW_DTLB_MASK) << SIM_REG_SHOW_DTLB_LSB))
  5390. +#define GET_SIM_REG_SHOW_ITLB(Reg) \
  5391. + (((Reg) >> SIM_REG_SHOW_ITLB_LSB) & SIM_REG_SHOW_ITLB_MASK)
  5392. +#define SET_SIM_REG_SHOW_ITLB(Reg, Val) \
  5393. + Reg = (((Reg) & (~(SIM_REG_SHOW_ITLB_MASK << SIM_REG_SHOW_ITLB_LSB))) | \
  5394. + (((Val) & SIM_REG_SHOW_ITLB_MASK) << SIM_REG_SHOW_ITLB_LSB))
  5395. +#define GET_SIM_REG_SHOW_MMU_REGS(Reg) \
  5396. + (((Reg) >> SIM_REG_SHOW_MMU_REGS_LSB) & SIM_REG_SHOW_MMU_REGS_MASK)
  5397. +#define SET_SIM_REG_SHOW_MMU_REGS(Reg, Val) \
  5398. + Reg = (((Reg) & (~(SIM_REG_SHOW_MMU_REGS_MASK << SIM_REG_SHOW_MMU_REGS_LSB))) | \
  5399. + (((Val) & SIM_REG_SHOW_MMU_REGS_MASK) << SIM_REG_SHOW_MMU_REGS_LSB))
  5400. +#define GET_SIM_REG_STOP(Reg) \
  5401. + (((Reg) >> SIM_REG_STOP_LSB) & SIM_REG_STOP_MASK)
  5402. +#define SET_SIM_REG_STOP(Reg, Val) \
  5403. + Reg = (((Reg) & (~(SIM_REG_STOP_MASK << SIM_REG_STOP_LSB))) | \
  5404. + (((Val) & SIM_REG_STOP_MASK) << SIM_REG_STOP_LSB))
  5405. +#define GET_STATUS_REG_EH(Reg) \
  5406. + (((Reg) >> STATUS_REG_EH_LSB) & STATUS_REG_EH_MASK)
  5407. +#define SET_STATUS_REG_EH(Reg, Val) \
  5408. + Reg = (((Reg) & (~(STATUS_REG_EH_MASK << STATUS_REG_EH_LSB))) | \
  5409. + (((Val) & STATUS_REG_EH_MASK) << STATUS_REG_EH_LSB))
  5410. +#define GET_STATUS_REG_MMU(Reg) \
  5411. + (((Reg) >> STATUS_REG_MMU_LSB) & STATUS_REG_MMU_MASK)
  5412. +#define SET_STATUS_REG_MMU(Reg, Val) \
  5413. + Reg = (((Reg) & (~(STATUS_REG_MMU_MASK << STATUS_REG_MMU_LSB))) | \
  5414. + (((Val) & STATUS_REG_MMU_MASK) << STATUS_REG_MMU_LSB))
  5415. +#define GET_STATUS_REG_MMU_RSV(Reg) \
  5416. + (((Reg) >> STATUS_REG_MMU_RSV_LSB) & STATUS_REG_MMU_RSV_MASK)
  5417. +#define SET_STATUS_REG_MMU_RSV(Reg, Val) \
  5418. + Reg = (((Reg) & (~(STATUS_REG_MMU_RSV_MASK << STATUS_REG_MMU_RSV_LSB))) | \
  5419. + (((Val) & STATUS_REG_MMU_RSV_MASK) << STATUS_REG_MMU_RSV_LSB))
  5420. +#define GET_STATUS_REG_NO_MMU(Reg) \
  5421. + (((Reg) >> STATUS_REG_NO_MMU_LSB) & STATUS_REG_NO_MMU_MASK)
  5422. +#define SET_STATUS_REG_NO_MMU(Reg, Val) \
  5423. + Reg = (((Reg) & (~(STATUS_REG_NO_MMU_MASK << STATUS_REG_NO_MMU_LSB))) | \
  5424. + (((Val) & STATUS_REG_NO_MMU_MASK) << STATUS_REG_NO_MMU_LSB))
  5425. +#define GET_STATUS_REG_NO_MMU_RSV(Reg) \
  5426. + (((Reg) >> STATUS_REG_NO_MMU_RSV_LSB) & STATUS_REG_NO_MMU_RSV_MASK)
  5427. +#define SET_STATUS_REG_NO_MMU_RSV(Reg, Val) \
  5428. + Reg = (((Reg) & (~(STATUS_REG_NO_MMU_RSV_MASK << STATUS_REG_NO_MMU_RSV_LSB))) | \
  5429. + (((Val) & STATUS_REG_NO_MMU_RSV_MASK) << STATUS_REG_NO_MMU_RSV_LSB))
  5430. +#define GET_STATUS_REG_PIE(Reg) \
  5431. + (((Reg) >> STATUS_REG_PIE_LSB) & STATUS_REG_PIE_MASK)
  5432. +#define SET_STATUS_REG_PIE(Reg, Val) \
  5433. + Reg = (((Reg) & (~(STATUS_REG_PIE_MASK << STATUS_REG_PIE_LSB))) | \
  5434. + (((Val) & STATUS_REG_PIE_MASK) << STATUS_REG_PIE_LSB))
  5435. +#define GET_STATUS_REG_U(Reg) \
  5436. + (((Reg) >> STATUS_REG_U_LSB) & STATUS_REG_U_MASK)
  5437. +#define SET_STATUS_REG_U(Reg, Val) \
  5438. + Reg = (((Reg) & (~(STATUS_REG_U_MASK << STATUS_REG_U_LSB))) | \
  5439. + (((Val) & STATUS_REG_U_MASK) << STATUS_REG_U_LSB))
  5440. +#define GET_TLBACC_REG_C(Reg) \
  5441. + (((Reg) >> TLBACC_REG_C_LSB) & TLBACC_REG_C_MASK)
  5442. +#define SET_TLBACC_REG_C(Reg, Val) \
  5443. + Reg = (((Reg) & (~(TLBACC_REG_C_MASK << TLBACC_REG_C_LSB))) | \
  5444. + (((Val) & TLBACC_REG_C_MASK) << TLBACC_REG_C_LSB))
  5445. +#define GET_TLBACC_REG_G(Reg) \
  5446. + (((Reg) >> TLBACC_REG_G_LSB) & TLBACC_REG_G_MASK)
  5447. +#define SET_TLBACC_REG_G(Reg, Val) \
  5448. + Reg = (((Reg) & (~(TLBACC_REG_G_MASK << TLBACC_REG_G_LSB))) | \
  5449. + (((Val) & TLBACC_REG_G_MASK) << TLBACC_REG_G_LSB))
  5450. +#define GET_TLBACC_REG_IG(Reg) \
  5451. + (((Reg) >> TLBACC_REG_IG_LSB) & TLBACC_REG_IG_MASK)
  5452. +#define SET_TLBACC_REG_IG(Reg, Val) \
  5453. + Reg = (((Reg) & (~(TLBACC_REG_IG_MASK << TLBACC_REG_IG_LSB))) | \
  5454. + (((Val) & TLBACC_REG_IG_MASK) << TLBACC_REG_IG_LSB))
  5455. +#define GET_TLBACC_REG_PFN(Reg) \
  5456. + (((Reg) >> TLBACC_REG_PFN_LSB) & TLBACC_REG_PFN_MASK)
  5457. +#define SET_TLBACC_REG_PFN(Reg, Val) \
  5458. + Reg = (((Reg) & (~(TLBACC_REG_PFN_MASK << TLBACC_REG_PFN_LSB))) | \
  5459. + (((Val) & TLBACC_REG_PFN_MASK) << TLBACC_REG_PFN_LSB))
  5460. +#define GET_TLBACC_REG_R(Reg) \
  5461. + (((Reg) >> TLBACC_REG_R_LSB) & TLBACC_REG_R_MASK)
  5462. +#define SET_TLBACC_REG_R(Reg, Val) \
  5463. + Reg = (((Reg) & (~(TLBACC_REG_R_MASK << TLBACC_REG_R_LSB))) | \
  5464. + (((Val) & TLBACC_REG_R_MASK) << TLBACC_REG_R_LSB))
  5465. +#define GET_TLBACC_REG_W(Reg) \
  5466. + (((Reg) >> TLBACC_REG_W_LSB) & TLBACC_REG_W_MASK)
  5467. +#define SET_TLBACC_REG_W(Reg, Val) \
  5468. + Reg = (((Reg) & (~(TLBACC_REG_W_MASK << TLBACC_REG_W_LSB))) | \
  5469. + (((Val) & TLBACC_REG_W_MASK) << TLBACC_REG_W_LSB))
  5470. +#define GET_TLBACC_REG_X(Reg) \
  5471. + (((Reg) >> TLBACC_REG_X_LSB) & TLBACC_REG_X_MASK)
  5472. +#define SET_TLBACC_REG_X(Reg, Val) \
  5473. + Reg = (((Reg) & (~(TLBACC_REG_X_MASK << TLBACC_REG_X_LSB))) | \
  5474. + (((Val) & TLBACC_REG_X_MASK) << TLBACC_REG_X_LSB))
  5475. +#define GET_TLBMISC_REG_BAD(Reg) \
  5476. + (((Reg) >> TLBMISC_REG_BAD_LSB) & TLBMISC_REG_BAD_MASK)
  5477. +#define SET_TLBMISC_REG_BAD(Reg, Val) \
  5478. + Reg = (((Reg) & (~(TLBMISC_REG_BAD_MASK << TLBMISC_REG_BAD_LSB))) | \
  5479. + (((Val) & TLBMISC_REG_BAD_MASK) << TLBMISC_REG_BAD_LSB))
  5480. +#define GET_TLBMISC_REG_D(Reg) \
  5481. + (((Reg) >> TLBMISC_REG_D_LSB) & TLBMISC_REG_D_MASK)
  5482. +#define SET_TLBMISC_REG_D(Reg, Val) \
  5483. + Reg = (((Reg) & (~(TLBMISC_REG_D_MASK << TLBMISC_REG_D_LSB))) | \
  5484. + (((Val) & TLBMISC_REG_D_MASK) << TLBMISC_REG_D_LSB))
  5485. +#define GET_TLBMISC_REG_DBL(Reg) \
  5486. + (((Reg) >> TLBMISC_REG_DBL_LSB) & TLBMISC_REG_DBL_MASK)
  5487. +#define SET_TLBMISC_REG_DBL(Reg, Val) \
  5488. + Reg = (((Reg) & (~(TLBMISC_REG_DBL_MASK << TLBMISC_REG_DBL_LSB))) | \
  5489. + (((Val) & TLBMISC_REG_DBL_MASK) << TLBMISC_REG_DBL_LSB))
  5490. +#define GET_TLBMISC_REG_PERM(Reg) \
  5491. + (((Reg) >> TLBMISC_REG_PERM_LSB) & TLBMISC_REG_PERM_MASK)
  5492. +#define SET_TLBMISC_REG_PERM(Reg, Val) \
  5493. + Reg = (((Reg) & (~(TLBMISC_REG_PERM_MASK << TLBMISC_REG_PERM_LSB))) | \
  5494. + (((Val) & TLBMISC_REG_PERM_MASK) << TLBMISC_REG_PERM_LSB))
  5495. +#define GET_TLBMISC_REG_PID(Reg) \
  5496. + (((Reg) >> TLBMISC_REG_PID_LSB) & TLBMISC_REG_PID_MASK)
  5497. +#define SET_TLBMISC_REG_PID(Reg, Val) \
  5498. + Reg = (((Reg) & (~(TLBMISC_REG_PID_MASK << TLBMISC_REG_PID_LSB))) | \
  5499. + (((Val) & TLBMISC_REG_PID_MASK) << TLBMISC_REG_PID_LSB))
  5500. +#define GET_TLBMISC_REG_RD(Reg) \
  5501. + (((Reg) >> TLBMISC_REG_RD_LSB) & TLBMISC_REG_RD_MASK)
  5502. +#define SET_TLBMISC_REG_RD(Reg, Val) \
  5503. + Reg = (((Reg) & (~(TLBMISC_REG_RD_MASK << TLBMISC_REG_RD_LSB))) | \
  5504. + (((Val) & TLBMISC_REG_RD_MASK) << TLBMISC_REG_RD_LSB))
  5505. +#define GET_TLBMISC_REG_RSV0(Reg) \
  5506. + (((Reg) >> TLBMISC_REG_RSV0_LSB) & TLBMISC_REG_RSV0_MASK)
  5507. +#define SET_TLBMISC_REG_RSV0(Reg, Val) \
  5508. + Reg = (((Reg) & (~(TLBMISC_REG_RSV0_MASK << TLBMISC_REG_RSV0_LSB))) | \
  5509. + (((Val) & TLBMISC_REG_RSV0_MASK) << TLBMISC_REG_RSV0_LSB))
  5510. +#define GET_TLBMISC_REG_RSV1(Reg) \
  5511. + (((Reg) >> TLBMISC_REG_RSV1_LSB) & TLBMISC_REG_RSV1_MASK)
  5512. +#define SET_TLBMISC_REG_RSV1(Reg, Val) \
  5513. + Reg = (((Reg) & (~(TLBMISC_REG_RSV1_MASK << TLBMISC_REG_RSV1_LSB))) | \
  5514. + (((Val) & TLBMISC_REG_RSV1_MASK) << TLBMISC_REG_RSV1_LSB))
  5515. +#define GET_TLBMISC_REG_WAY(Reg) \
  5516. + (((Reg) >> TLBMISC_REG_WAY_LSB) & TLBMISC_REG_WAY_MASK)
  5517. +#define SET_TLBMISC_REG_WAY(Reg, Val) \
  5518. + Reg = (((Reg) & (~(TLBMISC_REG_WAY_MASK << TLBMISC_REG_WAY_LSB))) | \
  5519. + (((Val) & TLBMISC_REG_WAY_MASK) << TLBMISC_REG_WAY_LSB))
  5520. +#define GET_TLBMISC_REG_WE(Reg) \
  5521. + (((Reg) >> TLBMISC_REG_WE_LSB) & TLBMISC_REG_WE_MASK)
  5522. +#define SET_TLBMISC_REG_WE(Reg, Val) \
  5523. + Reg = (((Reg) & (~(TLBMISC_REG_WE_MASK << TLBMISC_REG_WE_LSB))) | \
  5524. + (((Val) & TLBMISC_REG_WE_MASK) << TLBMISC_REG_WE_LSB))
  5525. +
  5526. +/* Macros to extract MMU fields */
  5527. +#define GET_MMU_ADDR_BYPASS_TLB_CACHEABLE(Addr) \
  5528. + (((Addr) >> MMU_ADDR_BYPASS_TLB_CACHEABLE_LSB) & MMU_ADDR_BYPASS_TLB_CACHEABLE_MASK)
  5529. +#define SET_MMU_ADDR_BYPASS_TLB_CACHEABLE(Addr, Val) \
  5530. + Addr = (((Addr) & (~(MMU_ADDR_BYPASS_TLB_CACHEABLE_MASK << MMU_ADDR_BYPASS_TLB_CACHEABLE_LSB))) | \
  5531. + (((Val) & MMU_ADDR_BYPASS_TLB_CACHEABLE_MASK) << MMU_ADDR_BYPASS_TLB_CACHEABLE_LSB))
  5532. +#define GET_MMU_ADDR_BYPASS_TLB(Addr) \
  5533. + (((Addr) >> MMU_ADDR_BYPASS_TLB_LSB) & MMU_ADDR_BYPASS_TLB_MASK)
  5534. +#define SET_MMU_ADDR_BYPASS_TLB(Addr, Val) \
  5535. + Addr = (((Addr) & (~(MMU_ADDR_BYPASS_TLB_MASK << MMU_ADDR_BYPASS_TLB_LSB))) | \
  5536. + (((Val) & MMU_ADDR_BYPASS_TLB_MASK) << MMU_ADDR_BYPASS_TLB_LSB))
  5537. +#define GET_MMU_ADDR_BYPASS_TLB_PADDR(Addr) \
  5538. + (((Addr) >> MMU_ADDR_BYPASS_TLB_PADDR_LSB) & MMU_ADDR_BYPASS_TLB_PADDR_MASK)
  5539. +#define SET_MMU_ADDR_BYPASS_TLB_PADDR(Addr, Val) \
  5540. + Addr = (((Addr) & (~(MMU_ADDR_BYPASS_TLB_PADDR_MASK << MMU_ADDR_BYPASS_TLB_PADDR_LSB))) | \
  5541. + (((Val) & MMU_ADDR_BYPASS_TLB_PADDR_MASK) << MMU_ADDR_BYPASS_TLB_PADDR_LSB))
  5542. +#define GET_MMU_ADDR_IO_REGION(Addr) \
  5543. + (((Addr) >> MMU_ADDR_IO_REGION_LSB) & MMU_ADDR_IO_REGION_MASK)
  5544. +#define SET_MMU_ADDR_IO_REGION(Addr, Val) \
  5545. + Addr = (((Addr) & (~(MMU_ADDR_IO_REGION_MASK << MMU_ADDR_IO_REGION_LSB))) | \
  5546. + (((Val) & MMU_ADDR_IO_REGION_MASK) << MMU_ADDR_IO_REGION_LSB))
  5547. +#define GET_MMU_ADDR_KERNEL_MMU_REGION(Addr) \
  5548. + (((Addr) >> MMU_ADDR_KERNEL_MMU_REGION_LSB) & MMU_ADDR_KERNEL_MMU_REGION_MASK)
  5549. +#define SET_MMU_ADDR_KERNEL_MMU_REGION(Addr, Val) \
  5550. + Addr = (((Addr) & (~(MMU_ADDR_KERNEL_MMU_REGION_MASK << MMU_ADDR_KERNEL_MMU_REGION_LSB))) | \
  5551. + (((Val) & MMU_ADDR_KERNEL_MMU_REGION_MASK) << MMU_ADDR_KERNEL_MMU_REGION_LSB))
  5552. +#define GET_MMU_ADDR_KERNEL_REGION(Addr) \
  5553. + (((Addr) >> MMU_ADDR_KERNEL_REGION_LSB) & MMU_ADDR_KERNEL_REGION_MASK)
  5554. +#define SET_MMU_ADDR_KERNEL_REGION(Addr, Val) \
  5555. + Addr = (((Addr) & (~(MMU_ADDR_KERNEL_REGION_MASK << MMU_ADDR_KERNEL_REGION_LSB))) | \
  5556. + (((Val) & MMU_ADDR_KERNEL_REGION_MASK) << MMU_ADDR_KERNEL_REGION_LSB))
  5557. +#define GET_MMU_ADDR_PAGE_OFFSET(Addr) \
  5558. + (((Addr) >> MMU_ADDR_PAGE_OFFSET_LSB) & MMU_ADDR_PAGE_OFFSET_MASK)
  5559. +#define SET_MMU_ADDR_PAGE_OFFSET(Addr, Val) \
  5560. + Addr = (((Addr) & (~(MMU_ADDR_PAGE_OFFSET_MASK << MMU_ADDR_PAGE_OFFSET_LSB))) | \
  5561. + (((Val) & MMU_ADDR_PAGE_OFFSET_MASK) << MMU_ADDR_PAGE_OFFSET_LSB))
  5562. +#define GET_MMU_ADDR_PFN(Addr) \
  5563. + (((Addr) >> MMU_ADDR_PFN_LSB) & MMU_ADDR_PFN_MASK)
  5564. +#define SET_MMU_ADDR_PFN(Addr, Val) \
  5565. + Addr = (((Addr) & (~(MMU_ADDR_PFN_MASK << MMU_ADDR_PFN_LSB))) | \
  5566. + (((Val) & MMU_ADDR_PFN_MASK) << MMU_ADDR_PFN_LSB))
  5567. +#define GET_MMU_ADDR_USER_REGION(Addr) \
  5568. + (((Addr) >> MMU_ADDR_USER_REGION_LSB) & MMU_ADDR_USER_REGION_MASK)
  5569. +#define SET_MMU_ADDR_USER_REGION(Addr, Val) \
  5570. + Addr = (((Addr) & (~(MMU_ADDR_USER_REGION_MASK << MMU_ADDR_USER_REGION_LSB))) | \
  5571. + (((Val) & MMU_ADDR_USER_REGION_MASK) << MMU_ADDR_USER_REGION_LSB))
  5572. +#define GET_MMU_ADDR_VPN(Addr) \
  5573. + (((Addr) >> MMU_ADDR_VPN_LSB) & MMU_ADDR_VPN_MASK)
  5574. +#define SET_MMU_ADDR_VPN(Addr, Val) \
  5575. + Addr = (((Addr) & (~(MMU_ADDR_VPN_MASK << MMU_ADDR_VPN_LSB))) | \
  5576. + (((Val) & MMU_ADDR_VPN_MASK) << MMU_ADDR_VPN_LSB))
  5577. +
  5578. +/* OP instruction values */
  5579. +#define OP_ADDI 4
  5580. +#define OP_ANDHI 44
  5581. +#define OP_ANDI 12
  5582. +#define OP_BEQ 38
  5583. +#define OP_BGE 14
  5584. +#define OP_BGEU 46
  5585. +#define OP_BLT 22
  5586. +#define OP_BLTU 54
  5587. +#define OP_BNE 30
  5588. +#define OP_BR 6
  5589. +#define OP_CALL 0
  5590. +#define OP_CMPEQI 32
  5591. +#define OP_CMPGEI 8
  5592. +#define OP_CMPGEUI 40
  5593. +#define OP_CMPLTI 16
  5594. +#define OP_CMPLTUI 48
  5595. +#define OP_CMPNEI 24
  5596. +#define OP_CUSTOM 50
  5597. +#define OP_FLUSHD 59
  5598. +#define OP_FLUSHDA 27
  5599. +#define OP_INITD 51
  5600. +#define OP_JMPI 1
  5601. +#define OP_LDB 7
  5602. +#define OP_LDBIO 39
  5603. +#define OP_LDBU 3
  5604. +#define OP_LDBUIO 35
  5605. +#define OP_LDH 15
  5606. +#define OP_LDHIO 47
  5607. +#define OP_LDHU 11
  5608. +#define OP_LDHUIO 43
  5609. +#define OP_LDW 23
  5610. +#define OP_LDWIO 55
  5611. +#define OP_MULI 36
  5612. +#define OP_OPX 58
  5613. +#define OP_ORHI 52
  5614. +#define OP_ORI 20
  5615. +#define OP_STB 5
  5616. +#define OP_STBIO 37
  5617. +#define OP_STH 13
  5618. +#define OP_STHIO 45
  5619. +#define OP_STW 21
  5620. +#define OP_STWIO 53
  5621. +#define OP_XORHI 60
  5622. +#define OP_XORI 28
  5623. +
  5624. +/* OPX instruction values */
  5625. +#define OPX_ADD 49
  5626. +#define OPX_AND 14
  5627. +#define OPX_BREAK 52
  5628. +#define OPX_BRET 9
  5629. +#define OPX_CALLR 29
  5630. +#define OPX_CMPEQ 32
  5631. +#define OPX_CMPGE 8
  5632. +#define OPX_CMPGEU 40
  5633. +#define OPX_CMPLT 16
  5634. +#define OPX_CMPLTU 48
  5635. +#define OPX_CMPNE 24
  5636. +#define OPX_CRST 62
  5637. +#define OPX_DIV 37
  5638. +#define OPX_DIVU 36
  5639. +#define OPX_ERET 1
  5640. +#define OPX_FLUSHI 12
  5641. +#define OPX_FLUSHP 4
  5642. +#define OPX_HBREAK 53
  5643. +#define OPX_INITI 41
  5644. +#define OPX_INTR 61
  5645. +#define OPX_JMP 13
  5646. +#define OPX_MUL 39
  5647. +#define OPX_MULXSS 31
  5648. +#define OPX_MULXSU 23
  5649. +#define OPX_MULXUU 7
  5650. +#define OPX_NEXTPC 28
  5651. +#define OPX_NOR 6
  5652. +#define OPX_OR 22
  5653. +#define OPX_RDCTL 38
  5654. +#define OPX_RET 5
  5655. +#define OPX_ROL 3
  5656. +#define OPX_ROLI 2
  5657. +#define OPX_ROR 11
  5658. +#define OPX_SLL 19
  5659. +#define OPX_SLLI 18
  5660. +#define OPX_SRA 59
  5661. +#define OPX_SRAI 58
  5662. +#define OPX_SRL 27
  5663. +#define OPX_SRLI 26
  5664. +#define OPX_SUB 57
  5665. +#define OPX_SYNC 54
  5666. +#define OPX_TRAP 45
  5667. +#define OPX_WRCTL 46
  5668. +#define OPX_XOR 30
  5669. +
  5670. +/* Macros to detect sub-opcode instructions */
  5671. +#define IS_OPX_INST(Iw) (GET_IW_OP(Iw) == OP_OPX)
  5672. +#define IS_CUSTOM_INST(Iw) (GET_IW_OP(Iw) == OP_CUSTOM)
  5673. +
  5674. +/* Instruction property macros */
  5675. +#define IW_PROP_RESERVED_OP(Iw) (0)
  5676. +
  5677. +#define IW_PROP_RESERVED_OPX(Iw) (0)
  5678. +
  5679. +#define IW_PROP_RESERVED(Iw) (0)
  5680. +
  5681. +#define IW_PROP_SUPERVISOR_ONLY(Iw) ( \
  5682. + (op_prop_supervisor_only[GET_IW_OP(Iw)] || \
  5683. + (IS_OPX_INST(Iw) && opx_prop_supervisor_only[GET_IW_OPX(Iw)])))
  5684. +
  5685. +#ifndef ALT_ASM_SRC
  5686. +extern unsigned char op_prop_supervisor_only[64];
  5687. +#endif /* ALT_ASM_SRC */
  5688. +
  5689. +#ifndef ALT_ASM_SRC
  5690. +extern unsigned char opx_prop_supervisor_only[64];
  5691. +#endif /* ALT_ASM_SRC */
  5692. +
  5693. +#define IW_PROP_INITI_FLUSHI(Iw) ( \
  5694. + ( \
  5695. + ((GET_IW_OPX((Iw)) == OPX_INITI) && IS_OPX_INST(Iw)) || \
  5696. + ((GET_IW_OPX((Iw)) == OPX_FLUSHI) && IS_OPX_INST(Iw)) \
  5697. + ) \
  5698. + \
  5699. +)
  5700. +
  5701. +#define IW_PROP_FLUSH_PIPE(Iw) ( \
  5702. + (IS_OPX_INST(Iw) && opx_prop_flush_pipe[GET_IW_OPX(Iw)]))
  5703. +
  5704. +#ifndef ALT_ASM_SRC
  5705. +extern unsigned char opx_prop_flush_pipe[64];
  5706. +#endif /* ALT_ASM_SRC */
  5707. +
  5708. +#define IW_PROP_JMP_INDIRECT_NON_TRAP(Iw) ( \
  5709. + (IS_OPX_INST(Iw) && opx_prop_jmp_indirect_non_trap[GET_IW_OPX(Iw)]))
  5710. +
  5711. +#ifndef ALT_ASM_SRC
  5712. +extern unsigned char opx_prop_jmp_indirect_non_trap[64];
  5713. +#endif /* ALT_ASM_SRC */
  5714. +
  5715. +#define IW_PROP_JMP_INDIRECT(Iw) ( \
  5716. + (IS_OPX_INST(Iw) && opx_prop_jmp_indirect[GET_IW_OPX(Iw)]))
  5717. +
  5718. +#ifndef ALT_ASM_SRC
  5719. +extern unsigned char opx_prop_jmp_indirect[64];
  5720. +#endif /* ALT_ASM_SRC */
  5721. +
  5722. +#define IW_PROP_JMP_DIRECT(Iw) ( \
  5723. + ( \
  5724. + ((GET_IW_OP((Iw)) == OP_CALL)) || \
  5725. + ((GET_IW_OP((Iw)) == OP_JMPI)) \
  5726. + ) \
  5727. + \
  5728. +)
  5729. +
  5730. +#define IW_PROP_MUL_LSW(Iw) ( \
  5731. + ( \
  5732. + ((GET_IW_OP((Iw)) == OP_MULI)) || \
  5733. + ((GET_IW_OPX((Iw)) == OPX_MUL) && IS_OPX_INST(Iw)) \
  5734. + ) \
  5735. + \
  5736. +)
  5737. +
  5738. +#define IW_PROP_MULX(Iw) ( \
  5739. + (IS_OPX_INST(Iw) && opx_prop_mulx[GET_IW_OPX(Iw)]))
  5740. +
  5741. +#ifndef ALT_ASM_SRC
  5742. +extern unsigned char opx_prop_mulx[64];
  5743. +#endif /* ALT_ASM_SRC */
  5744. +
  5745. +#define IW_PROP_MUL(Iw) ( \
  5746. + (op_prop_mul[GET_IW_OP(Iw)] || \
  5747. + (IS_OPX_INST(Iw) && opx_prop_mul[GET_IW_OPX(Iw)])))
  5748. +
  5749. +#ifndef ALT_ASM_SRC
  5750. +extern unsigned char op_prop_mul[64];
  5751. +#endif /* ALT_ASM_SRC */
  5752. +
  5753. +#ifndef ALT_ASM_SRC
  5754. +extern unsigned char opx_prop_mul[64];
  5755. +#endif /* ALT_ASM_SRC */
  5756. +
  5757. +#define IW_PROP_DIV_UNSIGNED(Iw) ( \
  5758. + ( \
  5759. + ((GET_IW_OPX((Iw)) == OPX_DIVU) && IS_OPX_INST(Iw)) \
  5760. + ) \
  5761. + \
  5762. +)
  5763. +
  5764. +#define IW_PROP_DIV_SIGNED(Iw) ( \
  5765. + ( \
  5766. + ((GET_IW_OPX((Iw)) == OPX_DIV) && IS_OPX_INST(Iw)) \
  5767. + ) \
  5768. + \
  5769. +)
  5770. +
  5771. +#define IW_PROP_DIV(Iw) ( \
  5772. + ( \
  5773. + ((GET_IW_OPX((Iw)) == OPX_DIVU) && IS_OPX_INST(Iw)) || \
  5774. + ((GET_IW_OPX((Iw)) == OPX_DIV) && IS_OPX_INST(Iw)) \
  5775. + ) \
  5776. + \
  5777. +)
  5778. +
  5779. +#define IW_PROP_UNIMPLEMENTED(Iw) (0)
  5780. +
  5781. +#define IW_PROP_IMPLICIT_DST_RETADDR(Iw) ( \
  5782. + ( \
  5783. + ((GET_IW_OP((Iw)) == OP_CALL)) \
  5784. + ) \
  5785. + \
  5786. +)
  5787. +
  5788. +#define IW_PROP_IMPLICIT_DST_ERETADDR(Iw) (0)
  5789. +
  5790. +#define IW_PROP_EXCEPTION(Iw) ( \
  5791. + ( \
  5792. + ((GET_IW_OPX((Iw)) == OPX_TRAP) && IS_OPX_INST(Iw)) || \
  5793. + ((GET_IW_OPX((Iw)) == OPX_INTR) && IS_OPX_INST(Iw)) \
  5794. + ) \
  5795. + \
  5796. +)
  5797. +
  5798. +#define IW_PROP_BREAK(Iw) ( \
  5799. + ( \
  5800. + ((GET_IW_OPX((Iw)) == OPX_BREAK) && IS_OPX_INST(Iw)) || \
  5801. + ((GET_IW_OPX((Iw)) == OPX_HBREAK) && IS_OPX_INST(Iw)) \
  5802. + ) \
  5803. + \
  5804. +)
  5805. +
  5806. +#define IW_PROP_CRST(Iw) ( \
  5807. + ( \
  5808. + ((GET_IW_OPX((Iw)) == OPX_CRST) && IS_OPX_INST(Iw)) \
  5809. + ) \
  5810. + \
  5811. +)
  5812. +
  5813. +#define IW_PROP_WR_CTL_REG(Iw) ( \
  5814. + (IS_OPX_INST(Iw) && opx_prop_wr_ctl_reg[GET_IW_OPX(Iw)]))
  5815. +
  5816. +#ifndef ALT_ASM_SRC
  5817. +extern unsigned char opx_prop_wr_ctl_reg[64];
  5818. +#endif /* ALT_ASM_SRC */
  5819. +
  5820. +#define IW_PROP_UNCOND_CTI_NON_BR(Iw) ( \
  5821. + (op_prop_uncond_cti_non_br[GET_IW_OP(Iw)] || \
  5822. + (IS_OPX_INST(Iw) && opx_prop_uncond_cti_non_br[GET_IW_OPX(Iw)])))
  5823. +
  5824. +#ifndef ALT_ASM_SRC
  5825. +extern unsigned char op_prop_uncond_cti_non_br[64];
  5826. +#endif /* ALT_ASM_SRC */
  5827. +
  5828. +#ifndef ALT_ASM_SRC
  5829. +extern unsigned char opx_prop_uncond_cti_non_br[64];
  5830. +#endif /* ALT_ASM_SRC */
  5831. +
  5832. +#define IW_PROP_RETADDR(Iw) ( \
  5833. + (op_prop_retaddr[GET_IW_OP(Iw)] || \
  5834. + (IS_OPX_INST(Iw) && opx_prop_retaddr[GET_IW_OPX(Iw)])))
  5835. +
  5836. +#ifndef ALT_ASM_SRC
  5837. +extern unsigned char op_prop_retaddr[64];
  5838. +#endif /* ALT_ASM_SRC */
  5839. +
  5840. +#ifndef ALT_ASM_SRC
  5841. +extern unsigned char opx_prop_retaddr[64];
  5842. +#endif /* ALT_ASM_SRC */
  5843. +
  5844. +#define IW_PROP_SHIFT_LEFT(Iw) ( \
  5845. + ( \
  5846. + ((GET_IW_OPX((Iw)) == OPX_SLLI) && IS_OPX_INST(Iw)) || \
  5847. + ((GET_IW_OPX((Iw)) == OPX_SLL) && IS_OPX_INST(Iw)) \
  5848. + ) \
  5849. + \
  5850. +)
  5851. +
  5852. +#define IW_PROP_SHIFT_LOGICAL(Iw) ( \
  5853. + (IS_OPX_INST(Iw) && opx_prop_shift_logical[GET_IW_OPX(Iw)]))
  5854. +
  5855. +#ifndef ALT_ASM_SRC
  5856. +extern unsigned char opx_prop_shift_logical[64];
  5857. +#endif /* ALT_ASM_SRC */
  5858. +
  5859. +#define IW_PROP_ROT_LEFT(Iw) ( \
  5860. + ( \
  5861. + ((GET_IW_OPX((Iw)) == OPX_ROLI) && IS_OPX_INST(Iw)) || \
  5862. + ((GET_IW_OPX((Iw)) == OPX_ROL) && IS_OPX_INST(Iw)) \
  5863. + ) \
  5864. + \
  5865. +)
  5866. +
  5867. +#define IW_PROP_SHIFT_ROT_LEFT(Iw) ( \
  5868. + (IS_OPX_INST(Iw) && opx_prop_shift_rot_left[GET_IW_OPX(Iw)]))
  5869. +
  5870. +#ifndef ALT_ASM_SRC
  5871. +extern unsigned char opx_prop_shift_rot_left[64];
  5872. +#endif /* ALT_ASM_SRC */
  5873. +
  5874. +#define IW_PROP_SHIFT_RIGHT_LOGICAL(Iw) ( \
  5875. + ( \
  5876. + ((GET_IW_OPX((Iw)) == OPX_SRLI) && IS_OPX_INST(Iw)) || \
  5877. + ((GET_IW_OPX((Iw)) == OPX_SRL) && IS_OPX_INST(Iw)) \
  5878. + ) \
  5879. + \
  5880. +)
  5881. +
  5882. +#define IW_PROP_SHIFT_RIGHT_ARITH(Iw) ( \
  5883. + ( \
  5884. + ((GET_IW_OPX((Iw)) == OPX_SRAI) && IS_OPX_INST(Iw)) || \
  5885. + ((GET_IW_OPX((Iw)) == OPX_SRA) && IS_OPX_INST(Iw)) \
  5886. + ) \
  5887. + \
  5888. +)
  5889. +
  5890. +#define IW_PROP_SHIFT_RIGHT(Iw) ( \
  5891. + (IS_OPX_INST(Iw) && opx_prop_shift_right[GET_IW_OPX(Iw)]))
  5892. +
  5893. +#ifndef ALT_ASM_SRC
  5894. +extern unsigned char opx_prop_shift_right[64];
  5895. +#endif /* ALT_ASM_SRC */
  5896. +
  5897. +#define IW_PROP_ROT_RIGHT(Iw) ( \
  5898. + ( \
  5899. + ((GET_IW_OPX((Iw)) == OPX_ROR) && IS_OPX_INST(Iw)) \
  5900. + ) \
  5901. + \
  5902. +)
  5903. +
  5904. +#define IW_PROP_SHIFT_ROT_RIGHT(Iw) ( \
  5905. + (IS_OPX_INST(Iw) && opx_prop_shift_rot_right[GET_IW_OPX(Iw)]))
  5906. +
  5907. +#ifndef ALT_ASM_SRC
  5908. +extern unsigned char opx_prop_shift_rot_right[64];
  5909. +#endif /* ALT_ASM_SRC */
  5910. +
  5911. +#define IW_PROP_SHIFT_ROT(Iw) ( \
  5912. + (IS_OPX_INST(Iw) && opx_prop_shift_rot[GET_IW_OPX(Iw)]))
  5913. +
  5914. +#ifndef ALT_ASM_SRC
  5915. +extern unsigned char opx_prop_shift_rot[64];
  5916. +#endif /* ALT_ASM_SRC */
  5917. +
  5918. +#define IW_PROP_SHIFT_ROT_IMM(Iw) ( \
  5919. + (IS_OPX_INST(Iw) && opx_prop_shift_rot_imm[GET_IW_OPX(Iw)]))
  5920. +
  5921. +#ifndef ALT_ASM_SRC
  5922. +extern unsigned char opx_prop_shift_rot_imm[64];
  5923. +#endif /* ALT_ASM_SRC */
  5924. +
  5925. +#define IW_PROP_ROTATE(Iw) ( \
  5926. + (IS_OPX_INST(Iw) && opx_prop_rotate[GET_IW_OPX(Iw)]))
  5927. +
  5928. +#ifndef ALT_ASM_SRC
  5929. +extern unsigned char opx_prop_rotate[64];
  5930. +#endif /* ALT_ASM_SRC */
  5931. +
  5932. +#define IW_PROP_LOGIC_REG(Iw) ( \
  5933. + (IS_OPX_INST(Iw) && opx_prop_logic_reg[GET_IW_OPX(Iw)]))
  5934. +
  5935. +#ifndef ALT_ASM_SRC
  5936. +extern unsigned char opx_prop_logic_reg[64];
  5937. +#endif /* ALT_ASM_SRC */
  5938. +
  5939. +#define IW_PROP_LOGIC_HI_IMM16(Iw) ( \
  5940. + (op_prop_logic_hi_imm16[GET_IW_OP(Iw)]))
  5941. +
  5942. +#ifndef ALT_ASM_SRC
  5943. +extern unsigned char op_prop_logic_hi_imm16[64];
  5944. +#endif /* ALT_ASM_SRC */
  5945. +
  5946. +#define IW_PROP_LOGIC_LO_IMM16(Iw) ( \
  5947. + (op_prop_logic_lo_imm16[GET_IW_OP(Iw)]))
  5948. +
  5949. +#ifndef ALT_ASM_SRC
  5950. +extern unsigned char op_prop_logic_lo_imm16[64];
  5951. +#endif /* ALT_ASM_SRC */
  5952. +
  5953. +#define IW_PROP_LOGIC_IMM16(Iw) ( \
  5954. + (op_prop_logic_imm16[GET_IW_OP(Iw)]))
  5955. +
  5956. +#ifndef ALT_ASM_SRC
  5957. +extern unsigned char op_prop_logic_imm16[64];
  5958. +#endif /* ALT_ASM_SRC */
  5959. +
  5960. +#define IW_PROP_LOGIC(Iw) ( \
  5961. + (op_prop_logic[GET_IW_OP(Iw)] || \
  5962. + (IS_OPX_INST(Iw) && opx_prop_logic[GET_IW_OPX(Iw)])))
  5963. +
  5964. +#ifndef ALT_ASM_SRC
  5965. +extern unsigned char op_prop_logic[64];
  5966. +#endif /* ALT_ASM_SRC */
  5967. +
  5968. +#ifndef ALT_ASM_SRC
  5969. +extern unsigned char opx_prop_logic[64];
  5970. +#endif /* ALT_ASM_SRC */
  5971. +
  5972. +#define IW_PROP_UNSIGNED_LO_IMM16(Iw) ( \
  5973. + (op_prop_unsigned_lo_imm16[GET_IW_OP(Iw)] || \
  5974. + (IS_OPX_INST(Iw) && opx_prop_unsigned_lo_imm16[GET_IW_OPX(Iw)])))
  5975. +
  5976. +#ifndef ALT_ASM_SRC
  5977. +extern unsigned char op_prop_unsigned_lo_imm16[64];
  5978. +#endif /* ALT_ASM_SRC */
  5979. +
  5980. +#ifndef ALT_ASM_SRC
  5981. +extern unsigned char opx_prop_unsigned_lo_imm16[64];
  5982. +#endif /* ALT_ASM_SRC */
  5983. +
  5984. +#define IW_PROP_ARITH_IMM16(Iw) ( \
  5985. + ( \
  5986. + ((GET_IW_OP((Iw)) == OP_ADDI)) || \
  5987. + ((GET_IW_OP((Iw)) == OP_MULI)) \
  5988. + ) \
  5989. + \
  5990. +)
  5991. +
  5992. +#define IW_PROP_CMP_IMM16(Iw) ( \
  5993. + (op_prop_cmp_imm16[GET_IW_OP(Iw)]))
  5994. +
  5995. +#ifndef ALT_ASM_SRC
  5996. +extern unsigned char op_prop_cmp_imm16[64];
  5997. +#endif /* ALT_ASM_SRC */
  5998. +
  5999. +#define IW_PROP_JMPI(Iw) ( \
  6000. + ( \
  6001. + ((GET_IW_OP((Iw)) == OP_JMPI)) \
  6002. + ) \
  6003. + \
  6004. +)
  6005. +
  6006. +#define IW_PROP_CMP_IMM16_WITH_CALL_JMPI(Iw) ( \
  6007. + (op_prop_cmp_imm16_with_call_jmpi[GET_IW_OP(Iw)]))
  6008. +
  6009. +#ifndef ALT_ASM_SRC
  6010. +extern unsigned char op_prop_cmp_imm16_with_call_jmpi[64];
  6011. +#endif /* ALT_ASM_SRC */
  6012. +
  6013. +#define IW_PROP_CMP_REG(Iw) ( \
  6014. + (IS_OPX_INST(Iw) && opx_prop_cmp_reg[GET_IW_OPX(Iw)]))
  6015. +
  6016. +#ifndef ALT_ASM_SRC
  6017. +extern unsigned char opx_prop_cmp_reg[64];
  6018. +#endif /* ALT_ASM_SRC */
  6019. +
  6020. +#define IW_PROP_SRC_IMM5(Iw) ( \
  6021. + (IS_OPX_INST(Iw) && opx_prop_src_imm5[GET_IW_OPX(Iw)]))
  6022. +
  6023. +#ifndef ALT_ASM_SRC
  6024. +extern unsigned char opx_prop_src_imm5[64];
  6025. +#endif /* ALT_ASM_SRC */
  6026. +
  6027. +#define IW_PROP_CMP_WITH_LT(Iw) ( \
  6028. + (op_prop_cmp_with_lt[GET_IW_OP(Iw)] || \
  6029. + (IS_OPX_INST(Iw) && opx_prop_cmp_with_lt[GET_IW_OPX(Iw)])))
  6030. +
  6031. +#ifndef ALT_ASM_SRC
  6032. +extern unsigned char op_prop_cmp_with_lt[64];
  6033. +#endif /* ALT_ASM_SRC */
  6034. +
  6035. +#ifndef ALT_ASM_SRC
  6036. +extern unsigned char opx_prop_cmp_with_lt[64];
  6037. +#endif /* ALT_ASM_SRC */
  6038. +
  6039. +#define IW_PROP_CMP_WITH_EQ(Iw) ( \
  6040. + (op_prop_cmp_with_eq[GET_IW_OP(Iw)] || \
  6041. + (IS_OPX_INST(Iw) && opx_prop_cmp_with_eq[GET_IW_OPX(Iw)])))
  6042. +
  6043. +#ifndef ALT_ASM_SRC
  6044. +extern unsigned char op_prop_cmp_with_eq[64];
  6045. +#endif /* ALT_ASM_SRC */
  6046. +
  6047. +#ifndef ALT_ASM_SRC
  6048. +extern unsigned char opx_prop_cmp_with_eq[64];
  6049. +#endif /* ALT_ASM_SRC */
  6050. +
  6051. +#define IW_PROP_CMP_WITH_GE(Iw) ( \
  6052. + (op_prop_cmp_with_ge[GET_IW_OP(Iw)] || \
  6053. + (IS_OPX_INST(Iw) && opx_prop_cmp_with_ge[GET_IW_OPX(Iw)])))
  6054. +
  6055. +#ifndef ALT_ASM_SRC
  6056. +extern unsigned char op_prop_cmp_with_ge[64];
  6057. +#endif /* ALT_ASM_SRC */
  6058. +
  6059. +#ifndef ALT_ASM_SRC
  6060. +extern unsigned char opx_prop_cmp_with_ge[64];
  6061. +#endif /* ALT_ASM_SRC */
  6062. +
  6063. +#define IW_PROP_CMP_WITH_NE(Iw) ( \
  6064. + ( \
  6065. + ((GET_IW_OP((Iw)) == OP_CMPNEI)) || \
  6066. + ((GET_IW_OPX((Iw)) == OPX_CMPNE) && IS_OPX_INST(Iw)) \
  6067. + ) \
  6068. + \
  6069. +)
  6070. +
  6071. +#define IW_PROP_CMP_ALU_SIGNED(Iw) ( \
  6072. + (op_prop_cmp_alu_signed[GET_IW_OP(Iw)] || \
  6073. + (IS_OPX_INST(Iw) && opx_prop_cmp_alu_signed[GET_IW_OPX(Iw)])))
  6074. +
  6075. +#ifndef ALT_ASM_SRC
  6076. +extern unsigned char op_prop_cmp_alu_signed[64];
  6077. +#endif /* ALT_ASM_SRC */
  6078. +
  6079. +#ifndef ALT_ASM_SRC
  6080. +extern unsigned char opx_prop_cmp_alu_signed[64];
  6081. +#endif /* ALT_ASM_SRC */
  6082. +
  6083. +#define IW_PROP_CMP(Iw) ( \
  6084. + (op_prop_cmp[GET_IW_OP(Iw)] || \
  6085. + (IS_OPX_INST(Iw) && opx_prop_cmp[GET_IW_OPX(Iw)])))
  6086. +
  6087. +#ifndef ALT_ASM_SRC
  6088. +extern unsigned char op_prop_cmp[64];
  6089. +#endif /* ALT_ASM_SRC */
  6090. +
  6091. +#ifndef ALT_ASM_SRC
  6092. +extern unsigned char opx_prop_cmp[64];
  6093. +#endif /* ALT_ASM_SRC */
  6094. +
  6095. +#define IW_PROP_BR_WITH_LT(Iw) ( \
  6096. + ( \
  6097. + ((GET_IW_OP((Iw)) == OP_BLT)) || \
  6098. + ((GET_IW_OP((Iw)) == OP_BLTU)) \
  6099. + ) \
  6100. + \
  6101. +)
  6102. +
  6103. +#define IW_PROP_BR_WITH_GE(Iw) ( \
  6104. + ( \
  6105. + ((GET_IW_OP((Iw)) == OP_BGE)) || \
  6106. + ((GET_IW_OP((Iw)) == OP_BGEU)) \
  6107. + ) \
  6108. + \
  6109. +)
  6110. +
  6111. +#define IW_PROP_BR_WITH_EQ(Iw) ( \
  6112. + (op_prop_br_with_eq[GET_IW_OP(Iw)]))
  6113. +
  6114. +#ifndef ALT_ASM_SRC
  6115. +extern unsigned char op_prop_br_with_eq[64];
  6116. +#endif /* ALT_ASM_SRC */
  6117. +
  6118. +#define IW_PROP_BR_WITH_NE(Iw) ( \
  6119. + ( \
  6120. + ((GET_IW_OP((Iw)) == OP_BNE)) \
  6121. + ) \
  6122. + \
  6123. +)
  6124. +
  6125. +#define IW_PROP_BR_ALU_SIGNED(Iw) ( \
  6126. + ( \
  6127. + ((GET_IW_OP((Iw)) == OP_BGE)) || \
  6128. + ((GET_IW_OP((Iw)) == OP_BLT)) \
  6129. + ) \
  6130. + \
  6131. +)
  6132. +
  6133. +#define IW_PROP_BR_COND(Iw) ( \
  6134. + (op_prop_br_cond[GET_IW_OP(Iw)]))
  6135. +
  6136. +#ifndef ALT_ASM_SRC
  6137. +extern unsigned char op_prop_br_cond[64];
  6138. +#endif /* ALT_ASM_SRC */
  6139. +
  6140. +#define IW_PROP_BR_UNCOND(Iw) ( \
  6141. + ( \
  6142. + ((GET_IW_OP((Iw)) == OP_BR)) \
  6143. + ) \
  6144. + \
  6145. +)
  6146. +
  6147. +#define IW_PROP_BR(Iw) ( \
  6148. + (op_prop_br[GET_IW_OP(Iw)]))
  6149. +
  6150. +#ifndef ALT_ASM_SRC
  6151. +extern unsigned char op_prop_br[64];
  6152. +#endif /* ALT_ASM_SRC */
  6153. +
  6154. +#define IW_PROP_ALU_SUB(Iw) ( \
  6155. + (op_prop_alu_sub[GET_IW_OP(Iw)] || \
  6156. + (IS_OPX_INST(Iw) && opx_prop_alu_sub[GET_IW_OPX(Iw)])))
  6157. +
  6158. +#ifndef ALT_ASM_SRC
  6159. +extern unsigned char op_prop_alu_sub[64];
  6160. +#endif /* ALT_ASM_SRC */
  6161. +
  6162. +#ifndef ALT_ASM_SRC
  6163. +extern unsigned char opx_prop_alu_sub[64];
  6164. +#endif /* ALT_ASM_SRC */
  6165. +
  6166. +#define IW_PROP_FORCE_XOR(Iw) ( \
  6167. + (op_prop_force_xor[GET_IW_OP(Iw)] || \
  6168. + (IS_OPX_INST(Iw) && opx_prop_force_xor[GET_IW_OPX(Iw)])))
  6169. +
  6170. +#ifndef ALT_ASM_SRC
  6171. +extern unsigned char op_prop_force_xor[64];
  6172. +#endif /* ALT_ASM_SRC */
  6173. +
  6174. +#ifndef ALT_ASM_SRC
  6175. +extern unsigned char opx_prop_force_xor[64];
  6176. +#endif /* ALT_ASM_SRC */
  6177. +
  6178. +#define IW_PROP_LOAD8(Iw) ( \
  6179. + (op_prop_load8[GET_IW_OP(Iw)]))
  6180. +
  6181. +#ifndef ALT_ASM_SRC
  6182. +extern unsigned char op_prop_load8[64];
  6183. +#endif /* ALT_ASM_SRC */
  6184. +
  6185. +#define IW_PROP_LOAD16(Iw) ( \
  6186. + (op_prop_load16[GET_IW_OP(Iw)]))
  6187. +
  6188. +#ifndef ALT_ASM_SRC
  6189. +extern unsigned char op_prop_load16[64];
  6190. +#endif /* ALT_ASM_SRC */
  6191. +
  6192. +#define IW_PROP_LOAD32(Iw) ( \
  6193. + ( \
  6194. + ((GET_IW_OP((Iw)) == OP_LDW)) || \
  6195. + ((GET_IW_OP((Iw)) == OP_LDWIO)) \
  6196. + ) \
  6197. + \
  6198. +)
  6199. +
  6200. +#define IW_PROP_LOAD_SIGNED(Iw) ( \
  6201. + (op_prop_load_signed[GET_IW_OP(Iw)]))
  6202. +
  6203. +#ifndef ALT_ASM_SRC
  6204. +extern unsigned char op_prop_load_signed[64];
  6205. +#endif /* ALT_ASM_SRC */
  6206. +
  6207. +#define IW_PROP_LOAD_UNSIGNED(Iw) ( \
  6208. + (op_prop_load_unsigned[GET_IW_OP(Iw)]))
  6209. +
  6210. +#ifndef ALT_ASM_SRC
  6211. +extern unsigned char op_prop_load_unsigned[64];
  6212. +#endif /* ALT_ASM_SRC */
  6213. +
  6214. +#define IW_PROP_LOAD(Iw) ( \
  6215. + (op_prop_load[GET_IW_OP(Iw)]))
  6216. +
  6217. +#ifndef ALT_ASM_SRC
  6218. +extern unsigned char op_prop_load[64];
  6219. +#endif /* ALT_ASM_SRC */
  6220. +
  6221. +#define IW_PROP_LOAD_INITD_FLUSHD_FLUSHDA(Iw) ( \
  6222. + (op_prop_load_initd_flushd_flushda[GET_IW_OP(Iw)]))
  6223. +
  6224. +#ifndef ALT_ASM_SRC
  6225. +extern unsigned char op_prop_load_initd_flushd_flushda[64];
  6226. +#endif /* ALT_ASM_SRC */
  6227. +
  6228. +#define IW_PROP_LOAD_NON_IO(Iw) ( \
  6229. + (op_prop_load_non_io[GET_IW_OP(Iw)]))
  6230. +
  6231. +#ifndef ALT_ASM_SRC
  6232. +extern unsigned char op_prop_load_non_io[64];
  6233. +#endif /* ALT_ASM_SRC */
  6234. +
  6235. +#define IW_PROP_STORE8(Iw) ( \
  6236. + ( \
  6237. + ((GET_IW_OP((Iw)) == OP_STB)) || \
  6238. + ((GET_IW_OP((Iw)) == OP_STBIO)) \
  6239. + ) \
  6240. + \
  6241. +)
  6242. +
  6243. +#define IW_PROP_STORE16(Iw) ( \
  6244. + ( \
  6245. + ((GET_IW_OP((Iw)) == OP_STH)) || \
  6246. + ((GET_IW_OP((Iw)) == OP_STHIO)) \
  6247. + ) \
  6248. + \
  6249. +)
  6250. +
  6251. +#define IW_PROP_STORE32(Iw) ( \
  6252. + ( \
  6253. + ((GET_IW_OP((Iw)) == OP_STW)) || \
  6254. + ((GET_IW_OP((Iw)) == OP_STWIO)) \
  6255. + ) \
  6256. + \
  6257. +)
  6258. +
  6259. +#define IW_PROP_STORE(Iw) ( \
  6260. + (op_prop_store[GET_IW_OP(Iw)]))
  6261. +
  6262. +#ifndef ALT_ASM_SRC
  6263. +extern unsigned char op_prop_store[64];
  6264. +#endif /* ALT_ASM_SRC */
  6265. +
  6266. +#define IW_PROP_STORE_NON_IO(Iw) ( \
  6267. + (op_prop_store_non_io[GET_IW_OP(Iw)]))
  6268. +
  6269. +#ifndef ALT_ASM_SRC
  6270. +extern unsigned char op_prop_store_non_io[64];
  6271. +#endif /* ALT_ASM_SRC */
  6272. +
  6273. +#define IW_PROP_MEM(Iw) ( \
  6274. + (op_prop_mem[GET_IW_OP(Iw)]))
  6275. +
  6276. +#ifndef ALT_ASM_SRC
  6277. +extern unsigned char op_prop_mem[64];
  6278. +#endif /* ALT_ASM_SRC */
  6279. +
  6280. +#define IW_PROP_INITD(Iw) ( \
  6281. + ( \
  6282. + ((GET_IW_OP((Iw)) == OP_INITD)) \
  6283. + ) \
  6284. + \
  6285. +)
  6286. +
  6287. +#define IW_PROP_FLUSHD(Iw) ( \
  6288. + ( \
  6289. + ((GET_IW_OP((Iw)) == OP_FLUSHD)) \
  6290. + ) \
  6291. + \
  6292. +)
  6293. +
  6294. +#define IW_PROP_INITD_FLUSHD(Iw) ( \
  6295. + ( \
  6296. + ((GET_IW_OP((Iw)) == OP_INITD)) || \
  6297. + ((GET_IW_OP((Iw)) == OP_FLUSHD)) \
  6298. + ) \
  6299. + \
  6300. +)
  6301. +
  6302. +#define IW_PROP_FLUSHDA(Iw) ( \
  6303. + ( \
  6304. + ((GET_IW_OP((Iw)) == OP_FLUSHDA)) \
  6305. + ) \
  6306. + \
  6307. +)
  6308. +
  6309. +#define IW_PROP_FLUSHD_FLUSHDA(Iw) ( \
  6310. + ( \
  6311. + ((GET_IW_OP((Iw)) == OP_FLUSHD)) || \
  6312. + ((GET_IW_OP((Iw)) == OP_FLUSHDA)) \
  6313. + ) \
  6314. + \
  6315. +)
  6316. +
  6317. +#define IW_PROP_INITD_FLUSHD_FLUSHDA(Iw) ( \
  6318. + (op_prop_initd_flushd_flushda[GET_IW_OP(Iw)]))
  6319. +
  6320. +#ifndef ALT_ASM_SRC
  6321. +extern unsigned char op_prop_initd_flushd_flushda[64];
  6322. +#endif /* ALT_ASM_SRC */
  6323. +
  6324. +#define IW_PROP_LOAD_IO(Iw) ( \
  6325. + (op_prop_load_io[GET_IW_OP(Iw)]))
  6326. +
  6327. +#ifndef ALT_ASM_SRC
  6328. +extern unsigned char op_prop_load_io[64];
  6329. +#endif /* ALT_ASM_SRC */
  6330. +
  6331. +#define IW_PROP_STORE_IO(Iw) ( \
  6332. + (op_prop_store_io[GET_IW_OP(Iw)]))
  6333. +
  6334. +#ifndef ALT_ASM_SRC
  6335. +extern unsigned char op_prop_store_io[64];
  6336. +#endif /* ALT_ASM_SRC */
  6337. +
  6338. +#define IW_PROP_MEM_IO(Iw) ( \
  6339. + (op_prop_mem_io[GET_IW_OP(Iw)]))
  6340. +
  6341. +#ifndef ALT_ASM_SRC
  6342. +extern unsigned char op_prop_mem_io[64];
  6343. +#endif /* ALT_ASM_SRC */
  6344. +
  6345. +#define IW_PROP_ARITH(Iw) ( \
  6346. + (op_prop_arith[GET_IW_OP(Iw)] || \
  6347. + (IS_OPX_INST(Iw) && opx_prop_arith[GET_IW_OPX(Iw)])))
  6348. +
  6349. +#ifndef ALT_ASM_SRC
  6350. +extern unsigned char op_prop_arith[64];
  6351. +#endif /* ALT_ASM_SRC */
  6352. +
  6353. +#ifndef ALT_ASM_SRC
  6354. +extern unsigned char opx_prop_arith[64];
  6355. +#endif /* ALT_ASM_SRC */
  6356. +
  6357. +#define IW_PROP_A_NOT_SRC(Iw) ( \
  6358. + ( \
  6359. + ((GET_IW_OP((Iw)) == OP_CALL)) || \
  6360. + ((GET_IW_OP((Iw)) == OP_JMPI)) \
  6361. + ) \
  6362. + || (IS_CUSTOM_INST(Iw) && !GET_IW_CUSTOM_READRA(Iw)) \
  6363. +)
  6364. +
  6365. +#define IW_PROP_B_NOT_SRC(Iw) ( \
  6366. + (op_prop_b_not_src[GET_IW_OP(Iw)]) \
  6367. + || (IS_CUSTOM_INST(Iw) && !GET_IW_CUSTOM_READRB(Iw)))
  6368. +
  6369. +#ifndef ALT_ASM_SRC
  6370. +extern unsigned char op_prop_b_not_src[64];
  6371. +#endif /* ALT_ASM_SRC */
  6372. +
  6373. +#define IW_PROP_IGNORE_DST(Iw) ( \
  6374. + (op_prop_ignore_dst[GET_IW_OP(Iw)]) \
  6375. + || (IS_CUSTOM_INST(Iw) && !GET_IW_CUSTOM_WRITERC(Iw)))
  6376. +
  6377. +#ifndef ALT_ASM_SRC
  6378. +extern unsigned char op_prop_ignore_dst[64];
  6379. +#endif /* ALT_ASM_SRC */
  6380. +
  6381. +#define IW_PROP_SRC2_CHOOSE_IMM(Iw) ( \
  6382. + (op_prop_src2_choose_imm[GET_IW_OP(Iw)] || \
  6383. + (IS_OPX_INST(Iw) && opx_prop_src2_choose_imm[GET_IW_OPX(Iw)])))
  6384. +
  6385. +#ifndef ALT_ASM_SRC
  6386. +extern unsigned char op_prop_src2_choose_imm[64];
  6387. +#endif /* ALT_ASM_SRC */
  6388. +
  6389. +#ifndef ALT_ASM_SRC
  6390. +extern unsigned char opx_prop_src2_choose_imm[64];
  6391. +#endif /* ALT_ASM_SRC */
  6392. +
  6393. +#define IW_PROP_WRCTL_INST(Iw) ( \
  6394. + ( \
  6395. + ((GET_IW_OPX((Iw)) == OPX_WRCTL) && IS_OPX_INST(Iw)) \
  6396. + ) \
  6397. + \
  6398. +)
  6399. +
  6400. +#define IW_PROP_RDCTL_INST(Iw) ( \
  6401. + ( \
  6402. + ((GET_IW_OPX((Iw)) == OPX_RDCTL) && IS_OPX_INST(Iw)) \
  6403. + ) \
  6404. + \
  6405. +)
  6406. +
  6407. +#define IW_PROP_MUL_SRC1_SIGNED(Iw) ( \
  6408. + ( \
  6409. + ((GET_IW_OPX((Iw)) == OPX_MULXSS) && IS_OPX_INST(Iw)) || \
  6410. + ((GET_IW_OPX((Iw)) == OPX_MULXSU) && IS_OPX_INST(Iw)) \
  6411. + ) \
  6412. + \
  6413. +)
  6414. +
  6415. +#define IW_PROP_MUL_SRC2_SIGNED(Iw) ( \
  6416. + ( \
  6417. + ((GET_IW_OPX((Iw)) == OPX_MULXSS) && IS_OPX_INST(Iw)) \
  6418. + ) \
  6419. + \
  6420. +)
  6421. +
  6422. +#define IW_PROP_MUL_SHIFT_SRC1_SIGNED(Iw) ( \
  6423. + (IS_OPX_INST(Iw) && opx_prop_mul_shift_src1_signed[GET_IW_OPX(Iw)]))
  6424. +
  6425. +#ifndef ALT_ASM_SRC
  6426. +extern unsigned char opx_prop_mul_shift_src1_signed[64];
  6427. +#endif /* ALT_ASM_SRC */
  6428. +
  6429. +#define IW_PROP_MUL_SHIFT_SRC2_SIGNED(Iw) ( \
  6430. + ( \
  6431. + ((GET_IW_OPX((Iw)) == OPX_MULXSS) && IS_OPX_INST(Iw)) \
  6432. + ) \
  6433. + \
  6434. +)
  6435. +
  6436. +#define IW_PROP_DONT_DISPLAY_DST_REG(Iw) ( \
  6437. + (op_prop_dont_display_dst_reg[GET_IW_OP(Iw)] || \
  6438. + (IS_OPX_INST(Iw) && opx_prop_dont_display_dst_reg[GET_IW_OPX(Iw)])))
  6439. +
  6440. +#ifndef ALT_ASM_SRC
  6441. +extern unsigned char op_prop_dont_display_dst_reg[64];
  6442. +#endif /* ALT_ASM_SRC */
  6443. +
  6444. +#ifndef ALT_ASM_SRC
  6445. +extern unsigned char opx_prop_dont_display_dst_reg[64];
  6446. +#endif /* ALT_ASM_SRC */
  6447. +
  6448. +#define IW_PROP_DONT_DISPLAY_SRC1_REG(Iw) ( \
  6449. + (op_prop_dont_display_src1_reg[GET_IW_OP(Iw)] || \
  6450. + (IS_OPX_INST(Iw) && opx_prop_dont_display_src1_reg[GET_IW_OPX(Iw)])))
  6451. +
  6452. +#ifndef ALT_ASM_SRC
  6453. +extern unsigned char op_prop_dont_display_src1_reg[64];
  6454. +#endif /* ALT_ASM_SRC */
  6455. +
  6456. +#ifndef ALT_ASM_SRC
  6457. +extern unsigned char opx_prop_dont_display_src1_reg[64];
  6458. +#endif /* ALT_ASM_SRC */
  6459. +
  6460. +#define IW_PROP_DONT_DISPLAY_SRC2_REG(Iw) ( \
  6461. + (op_prop_dont_display_src2_reg[GET_IW_OP(Iw)] || \
  6462. + (IS_OPX_INST(Iw) && opx_prop_dont_display_src2_reg[GET_IW_OPX(Iw)])))
  6463. +
  6464. +#ifndef ALT_ASM_SRC
  6465. +extern unsigned char op_prop_dont_display_src2_reg[64];
  6466. +#endif /* ALT_ASM_SRC */
  6467. +
  6468. +#ifndef ALT_ASM_SRC
  6469. +extern unsigned char opx_prop_dont_display_src2_reg[64];
  6470. +#endif /* ALT_ASM_SRC */
  6471. +
  6472. +#define IW_PROP_SRC1_NO_X(Iw) ( \
  6473. + (op_prop_src1_no_x[GET_IW_OP(Iw)] || \
  6474. + (IS_OPX_INST(Iw) && opx_prop_src1_no_x[GET_IW_OPX(Iw)])))
  6475. +
  6476. +#ifndef ALT_ASM_SRC
  6477. +extern unsigned char op_prop_src1_no_x[64];
  6478. +#endif /* ALT_ASM_SRC */
  6479. +
  6480. +#ifndef ALT_ASM_SRC
  6481. +extern unsigned char opx_prop_src1_no_x[64];
  6482. +#endif /* ALT_ASM_SRC */
  6483. +
  6484. +#define IW_PROP_SRC2_NO_X(Iw) ( \
  6485. + (op_prop_src2_no_x[GET_IW_OP(Iw)] || \
  6486. + (IS_OPX_INST(Iw) && opx_prop_src2_no_x[GET_IW_OPX(Iw)])))
  6487. +
  6488. +#ifndef ALT_ASM_SRC
  6489. +extern unsigned char op_prop_src2_no_x[64];
  6490. +#endif /* ALT_ASM_SRC */
  6491. +
  6492. +#ifndef ALT_ASM_SRC
  6493. +extern unsigned char opx_prop_src2_no_x[64];
  6494. +#endif /* ALT_ASM_SRC */
  6495. +
  6496. +/* Instruction types */
  6497. +#define INST_TYPE_OP 0
  6498. +#define INST_TYPE_OPX 1
  6499. +
  6500. +/* Canonical instruction codes independent of encoding */
  6501. +#define CALL_INST_CODE 0
  6502. +#define JMPI_INST_CODE 1
  6503. +#define LDBU_INST_CODE 2
  6504. +#define ADDI_INST_CODE 3
  6505. +#define STB_INST_CODE 4
  6506. +#define BR_INST_CODE 5
  6507. +#define LDB_INST_CODE 6
  6508. +#define CMPGEI_INST_CODE 7
  6509. +#define LDHU_INST_CODE 8
  6510. +#define ANDI_INST_CODE 9
  6511. +#define STH_INST_CODE 10
  6512. +#define BGE_INST_CODE 11
  6513. +#define LDH_INST_CODE 12
  6514. +#define CMPLTI_INST_CODE 13
  6515. +#define ORI_INST_CODE 14
  6516. +#define STW_INST_CODE 15
  6517. +#define BLT_INST_CODE 16
  6518. +#define LDW_INST_CODE 17
  6519. +#define CMPNEI_INST_CODE 18
  6520. +#define FLUSHDA_INST_CODE 19
  6521. +#define XORI_INST_CODE 20
  6522. +#define BNE_INST_CODE 21
  6523. +#define CMPEQI_INST_CODE 22
  6524. +#define LDBUIO_INST_CODE 23
  6525. +#define MULI_INST_CODE 24
  6526. +#define STBIO_INST_CODE 25
  6527. +#define BEQ_INST_CODE 26
  6528. +#define LDBIO_INST_CODE 27
  6529. +#define CMPGEUI_INST_CODE 28
  6530. +#define LDHUIO_INST_CODE 29
  6531. +#define ANDHI_INST_CODE 30
  6532. +#define STHIO_INST_CODE 31
  6533. +#define BGEU_INST_CODE 32
  6534. +#define LDHIO_INST_CODE 33
  6535. +#define CMPLTUI_INST_CODE 34
  6536. +#define CUSTOM_INST_CODE 35
  6537. +#define INITD_INST_CODE 36
  6538. +#define ORHI_INST_CODE 37
  6539. +#define STWIO_INST_CODE 38
  6540. +#define BLTU_INST_CODE 39
  6541. +#define LDWIO_INST_CODE 40
  6542. +#define FLUSHD_INST_CODE 41
  6543. +#define XORHI_INST_CODE 42
  6544. +#define ERET_INST_CODE 43
  6545. +#define ROLI_INST_CODE 44
  6546. +#define ROL_INST_CODE 45
  6547. +#define FLUSHP_INST_CODE 46
  6548. +#define RET_INST_CODE 47
  6549. +#define NOR_INST_CODE 48
  6550. +#define MULXUU_INST_CODE 49
  6551. +#define CMPGE_INST_CODE 50
  6552. +#define BRET_INST_CODE 51
  6553. +#define ROR_INST_CODE 52
  6554. +#define FLUSHI_INST_CODE 53
  6555. +#define JMP_INST_CODE 54
  6556. +#define AND_INST_CODE 55
  6557. +#define CMPLT_INST_CODE 56
  6558. +#define SLLI_INST_CODE 57
  6559. +#define SLL_INST_CODE 58
  6560. +#define OR_INST_CODE 59
  6561. +#define MULXSU_INST_CODE 60
  6562. +#define CMPNE_INST_CODE 61
  6563. +#define SRLI_INST_CODE 62
  6564. +#define SRL_INST_CODE 63
  6565. +#define NEXTPC_INST_CODE 64
  6566. +#define CALLR_INST_CODE 65
  6567. +#define XOR_INST_CODE 66
  6568. +#define MULXSS_INST_CODE 67
  6569. +#define CMPEQ_INST_CODE 68
  6570. +#define DIVU_INST_CODE 69
  6571. +#define DIV_INST_CODE 70
  6572. +#define RDCTL_INST_CODE 71
  6573. +#define MUL_INST_CODE 72
  6574. +#define CMPGEU_INST_CODE 73
  6575. +#define INITI_INST_CODE 74
  6576. +#define TRAP_INST_CODE 75
  6577. +#define WRCTL_INST_CODE 76
  6578. +#define CMPLTU_INST_CODE 77
  6579. +#define ADD_INST_CODE 78
  6580. +#define BREAK_INST_CODE 79
  6581. +#define HBREAK_INST_CODE 80
  6582. +#define SYNC_INST_CODE 81
  6583. +#define SUB_INST_CODE 82
  6584. +#define SRAI_INST_CODE 83
  6585. +#define SRA_INST_CODE 84
  6586. +#define INTR_INST_CODE 85
  6587. +#define CRST_INST_CODE 86
  6588. +#define RSV_INST_CODE 87
  6589. +#define NUM_NIOS2_INST_CODES 88
  6590. +
  6591. +#ifndef ALT_ASM_SRC
  6592. +/* Instruction information entry */
  6593. +typedef struct {
  6594. + const char* name; /* Assembly-language instruction name */
  6595. + int instType; /* INST_TYPE_OP or INST_TYPE_OPX */
  6596. + unsigned opcode; /* Value of instruction word OP/OPX field */
  6597. +} Nios2InstInfo;
  6598. +
  6599. +extern Nios2InstInfo nios2InstInfo[NUM_NIOS2_INST_CODES];
  6600. +#endif /* ALT_ASM_SRC */
  6601. +
  6602. +/* Returns the instruction code given the 32-bit instruction word */
  6603. +#define GET_INST_CODE(Iw) \
  6604. + (IS_OPX_INST(Iw) ? opxToInstCode[GET_IW_OPX(Iw)] : opToInstCode[GET_IW_OP(Iw)])
  6605. +
  6606. +#ifndef ALT_ASM_SRC
  6607. +extern int opToInstCode[64];
  6608. +extern int opxToInstCode[64];
  6609. +#endif /* ALT_ASM_SRC */
  6610. +
  6611. +/*
  6612. + * MMU Memory Region Macros
  6613. + */
  6614. +#define USER_REGION_MIN_VADDR 0x00000000
  6615. +#define USER_REGION_MAX_VADDR 0x7fffffff
  6616. +#define KERNEL_MMU_REGION_MIN_VADDR 0x80000000
  6617. +#define KERNEL_MMU_REGION_MAX_VADDR 0xbfffffff
  6618. +#define KERNEL_REGION_MIN_VADDR 0xc0000000
  6619. +#define KERNEL_REGION_MAX_VADDR 0xdfffffff
  6620. +#define IO_REGION_MIN_VADDR 0xe0000000
  6621. +#define IO_REGION_MAX_VADDR 0xffffffff
  6622. +
  6623. +#define MMU_PAGE_SIZE (0x1 << (MMU_ADDR_PAGE_OFFSET_SZ))
  6624. +
  6625. +#define isMmuUserRegion(Vaddr) \
  6626. + (GET_MMU_ADDR_USER_REGION(Vaddr) == MMU_ADDR_USER_REGION)
  6627. +#define isMmuKernelMmuRegion(Vaddr) \
  6628. + (GET_MMU_ADDR_KERNEL_MMU_REGION(Vaddr) == MMU_ADDR_KERNEL_MMU_REGION)
  6629. +#define isMmuKernelRegion(Vaddr) \
  6630. + (GET_MMU_ADDR_KERNEL_REGION(Vaddr) == MMU_ADDR_KERNEL_REGION)
  6631. +#define isMmuIORegion(Vaddr) \
  6632. + (GET_MMU_ADDR_IO_REGION(Vaddr) == MMU_ADDR_IO_REGION)
  6633. +
  6634. +/* Does this virtual address bypass the TLB? */
  6635. +#define vaddrBypassTlb(Vaddr) \
  6636. + (GET_MMU_ADDR_BYPASS_TLB(Vaddr) == MMU_ADDR_BYPASS_TLB)
  6637. +
  6638. +/* If TLB is bypassed, is the address cacheable or uncachable. */
  6639. +#define vaddrBypassTlbCacheable(Vaddr) \
  6640. + (GET_MMU_ADDR_BYPASS_TLB_CACHEABLE(Vaddr) == MMU_ADDR_BYPASS_TLB_CACHEABLE)
  6641. +
  6642. +/*
  6643. + * Compute physical address for regions that bypass the TLB.
  6644. + * Just need to clear some top bits.
  6645. + */
  6646. +#define bypassTlbVaddrToPaddr(Vaddr) \
  6647. + ((Vaddr) & (MMU_ADDR_BYPASS_TLB_PADDR_MASK << MMU_ADDR_BYPASS_TLB_PADDR_LSB))
  6648. +
  6649. +/*
  6650. + * Will the physical address fit in the Kernel/IO region virtual address space?
  6651. + */
  6652. +#define fitsInKernelRegion(Paddr) \
  6653. + (GET_MMU_ADDR_KERNEL_REGION(Paddr) == 0)
  6654. +#define fitsInIORegion(Paddr) \
  6655. + (GET_MMU_ADDR_IO_REGION(Paddr) == 0)
  6656. +
  6657. +/* Convert a physical address to a Kernel/IO region virtual address. */
  6658. +#define paddrToKernelRegionVaddr(Paddr) \
  6659. + ((Paddr) | (MMU_ADDR_KERNEL_REGION << MMU_ADDR_KERNEL_REGION_LSB))
  6660. +#define paddrToIORegionVaddr(Paddr) \
  6661. + ((Paddr) | (MMU_ADDR_IO_REGION << MMU_ADDR_IO_REGION_LSB))
  6662. +
  6663. +/*
  6664. + * Convert a virtual address to a Kernel/IO region virtual address.
  6665. + * Uses bypassTlbVaddrToPaddr to clear top bits.
  6666. + */
  6667. +#define vaddrToKernelRegionVaddr(Vaddr) \
  6668. + paddrToKernelRegionVaddr(bypassTlbVaddrToPaddr(Vaddr))
  6669. +#define vaddrToIORegionVaddr(Vaddr) \
  6670. + paddrToIORegionVaddr(bypassTlbVaddrToPaddr(Vaddr))
  6671. +
  6672. +/* Convert between VPN/PFN and virtual/physical addresses. */
  6673. +#define vpnToVaddr(Vpn) ((Vpn) << MMU_ADDR_VPN_LSB)
  6674. +#define pfnToPaddr(Pfn) ((Pfn) << MMU_ADDR_PFN_LSB)
  6675. +#define vaddrToVpn(Vaddr) GET_MMU_ADDR_VPN(Vaddr)
  6676. +#define paddrToPfn(Paddr) GET_MMU_ADDR_PFN(Paddr)
  6677. +
  6678. +/* Bitwise OR with a KERNEL region address to make it an IO region address */
  6679. +#define KERNEL_TO_IO_REGION 0x20000000
  6680. +
  6681. +#endif /* _NIOS2_ISA_H_ */
  6682. diff --git a/include/opcode/nios2.h b/include/opcode/nios2.h
  6683. new file mode 100644
  6684. index 0000000..992bb80
  6685. --- /dev/null
  6686. +++ b/include/opcode/nios2.h
  6687. @@ -0,0 +1,361 @@
  6688. +/* nios2.h. Altera New Jersey opcode list for GAS, the GNU assembler.
  6689. +
  6690. + Copyright (C) 2003
  6691. + by Nigel Gray (ngray@altera.com).
  6692. +
  6693. +This file is part of GDB, GAS, and the GNU binutils.
  6694. +
  6695. +GDB, GAS, and the GNU binutils are free software; you can redistribute
  6696. +them and/or modify them under the terms of the GNU General Public
  6697. +License as published by the Free Software Foundation; either version
  6698. +1, or (at your option) any later version.
  6699. +
  6700. +GDB, GAS, and the GNU binutils are distributed in the hope that they
  6701. +will be useful, but WITHOUT ANY WARRANTY; without even the implied
  6702. +warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  6703. +the GNU General Public License for more details.
  6704. +
  6705. +You should have received a copy of the GNU General Public License
  6706. +along with this file; see the file COPYING. If not, write to the Free
  6707. +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  6708. +
  6709. +#ifndef _NIOS2_H_
  6710. +#define _NIOS2_H_
  6711. +
  6712. +
  6713. +/****************************************************************************
  6714. + * This file contains structures, bit masks and shift counts used
  6715. + * by the GNU toolchain to define the New Jersey instruction set and
  6716. + * access various opcode fields.
  6717. + ****************************************************************************/
  6718. +
  6719. +enum overflow_type
  6720. +{
  6721. + call_target_overflow = 0,
  6722. + branch_target_overflow,
  6723. + address_offset_overflow,
  6724. + signed_immed16_overflow,
  6725. + unsigned_immed16_overflow,
  6726. + unsigned_immed5_overflow,
  6727. + custom_opcode_overflow,
  6728. + no_overflow
  6729. +};
  6730. +
  6731. +/*---------------------------------------------------------------------------
  6732. + This structure holds information for a particular instruction
  6733. + ---------------------------------------------------------------------------*/
  6734. +
  6735. +/* match When assembling, this
  6736. + opcode is modified by the arguments to produce the actual opcode
  6737. + that is used. If pinfo is INSN_MACRO, then this is 0. */
  6738. +
  6739. +/* mask If pinfo is not INSN_MACRO, then this is a bit mask for the
  6740. + relevant portions of the opcode when disassembling. If the
  6741. + actual opcode anded with the match field equals the opcode field,
  6742. + then we have found the correct instruction. If pinfo is
  6743. + INSN_MACRO, then this field is the macro identifier. */
  6744. +
  6745. +/* For a macro, this is INSN_MACRO. Otherwise, it is a collection
  6746. + of bits describing the instruction, notably any relevant hazard
  6747. + information. */
  6748. +
  6749. +struct nios2_opcode
  6750. +{
  6751. + const char *name; /* The name of the instruction. */
  6752. + const char *args; /* A string describing the arguments for this instruction. */
  6753. + const char *args_test; /* Like args, but with an extra argument for the expected opcode */
  6754. + unsigned long num_args; /* the number of arguments the instruction takes */
  6755. + unsigned long match; /* The basic opcode for the instruction. */
  6756. + unsigned long mask; /* mask for the opcode field of the instruction */
  6757. + unsigned long pinfo; /* is this a real instruction or instruction macro */
  6758. + enum overflow_type overflow_msg; /* msg template used to generate informative message when fixup overflows */
  6759. +};
  6760. +
  6761. +/* This value is used in the nios2_opcode.pinfo field to indicate that the instruction
  6762. + is a macro or pseudo-op. This requires special treatment by the assembler, and is
  6763. + used by the disassembler to determine whether to check for a nop */
  6764. +#define NIOS2_INSN_MACRO 0x80000000
  6765. +#define NIOS2_INSN_MACRO_MOV 0x80000001
  6766. +#define NIOS2_INSN_MACRO_MOVI 0x80000002
  6767. +#define NIOS2_INSN_MACRO_MOVIA 0x80000004
  6768. +
  6769. +#define NIOS2_INSN_RELAXABLE 0x40000000
  6770. +#define NIOS2_INSN_UBRANCH 0x00000010
  6771. +#define NIOS2_INSN_CBRANCH 0x00000020
  6772. +#define NIOS2_INSN_CALL 0x00000040
  6773. +
  6774. +#define NIOS2_INSN_ADDI 0x00000080
  6775. +#define NIOS2_INSN_ANDI 0x00000100
  6776. +#define NIOS2_INSN_ORI 0x00000200
  6777. +#define NIOS2_INSN_XORI 0x00000400
  6778. +
  6779. +
  6780. +
  6781. +/* Associates a register name ($6) with a 5-bit index (eg 6) */
  6782. +struct nios2_reg
  6783. +{
  6784. + const char *name;
  6785. + const int index;
  6786. +};
  6787. +
  6788. +
  6789. +/* -------------------------------------------------------------------------
  6790. + Bitfield masks for New Jersey instructions
  6791. + -------------------------------------------------------------------------*/
  6792. +
  6793. +/* These are bit masks and shift counts to use to access the various
  6794. + fields of an instruction. */
  6795. +
  6796. +/* Macros for getting and setting an instruction field */
  6797. +#define GET_INSN_FIELD(X, i) ((i) & OP_MASK_##X) >> OP_SH_##X
  6798. +#define SET_INSN_FIELD(X, i, j) (i) = ((i) &~ (OP_MASK_##X)) | ((j) << OP_SH_##X)
  6799. +
  6800. +
  6801. +/*
  6802. + We include the auto-generated file nios2-isa.h and define the mask
  6803. + and shifts below in terms of those in nios2-isa.h. This ensures
  6804. + that the binutils and hardware are always in sync
  6805. +*/
  6806. +
  6807. +#include "nios2-isa.h"
  6808. +
  6809. +#define OP_MASK_OP (IW_OP_MASK << IW_OP_LSB)
  6810. +#define OP_SH_OP IW_OP_LSB
  6811. +
  6812. +
  6813. +/* Masks and shifts for I-type instructions */
  6814. +
  6815. +#define OP_MASK_IOP (IW_OP_MASK << IW_OP_LSB)
  6816. +#define OP_SH_IOP IW_OP_LSB
  6817. +
  6818. +#define OP_MASK_IMM16 (IW_IMM16_MASK << IW_IMM16_LSB)
  6819. +#define OP_SH_IMM16 IW_IMM16_LSB
  6820. +
  6821. +#define OP_MASK_IRD (IW_B_MASK << IW_B_LSB) // the same as T for I-type
  6822. +#define OP_SH_IRD IW_B_LSB
  6823. +
  6824. +#define OP_MASK_IRT (IW_B_MASK << IW_B_LSB)
  6825. +#define OP_SH_IRT IW_B_LSB
  6826. +
  6827. +#define OP_MASK_IRS (IW_A_MASK << IW_A_LSB)
  6828. +#define OP_SH_IRS IW_A_LSB
  6829. +
  6830. +/* Masks and shifts for R-type instructions */
  6831. +
  6832. +#define OP_MASK_ROP (IW_OP_MASK << IW_OP_LSB)
  6833. +#define OP_SH_ROP IW_OP_LSB
  6834. +
  6835. +#define OP_MASK_ROPX (IW_OPX_MASK << IW_OPX_LSB)
  6836. +#define OP_SH_ROPX IW_OPX_LSB
  6837. +
  6838. +#define OP_MASK_RRD (IW_C_MASK << IW_C_LSB)
  6839. +#define OP_SH_RRD IW_C_LSB
  6840. +
  6841. +#define OP_MASK_RRT (IW_B_MASK << IW_B_LSB)
  6842. +#define OP_SH_RRT IW_B_LSB
  6843. +
  6844. +#define OP_MASK_RRS (IW_A_MASK << IW_A_LSB)
  6845. +#define OP_SH_RRS IW_A_LSB
  6846. +
  6847. +/* Masks and shifts for J-type instructions */
  6848. +
  6849. +#define OP_MASK_JOP (IW_OP_MASK << IW_OP_LSB)
  6850. +#define OP_SH_JOP IW_OP_LSB
  6851. +
  6852. +#define OP_MASK_IMM26 (IW_IMM26_MASK << IW_IMM26_LSB)
  6853. +#define OP_SH_IMM26 IW_IMM26_LSB
  6854. +
  6855. +/* Masks and shifts for CTL instructions */
  6856. +
  6857. +#define OP_MASK_RCTL 0x000007c0
  6858. +#define OP_SH_RCTL 6
  6859. +
  6860. +/* break instruction imm5 field */
  6861. +#define OP_MASK_TRAP_IMM5 0x000007c0
  6862. +#define OP_SH_TRAP_IMM5 6
  6863. +
  6864. +/* instruction imm5 field */
  6865. +#define OP_MASK_IMM5 (IW_SHIFT_IMM5_MASK << IW_SHIFT_IMM5_LSB)
  6866. +#define OP_SH_IMM5 IW_SHIFT_IMM5_LSB
  6867. +
  6868. +/* cache operation fields (type j,i(s)) */
  6869. +#define OP_MASK_CACHE_OPX (IW_B_MASK << IW_B_LSB)
  6870. +#define OP_SH_CACHE_OPX IW_B_LSB
  6871. +#define OP_MASK_CACHE_RRS (IW_A_MASK << IW_A_LSB)
  6872. +#define OP_SH_CACHE_RRS IW_A_LSB
  6873. +
  6874. +/* custom instruction masks */
  6875. +#define OP_MASK_CUSTOM_A 0x00010000
  6876. +#define OP_SH_CUSTOM_A 16
  6877. +
  6878. +#define OP_MASK_CUSTOM_B 0x00008000
  6879. +#define OP_SH_CUSTOM_B 15
  6880. +
  6881. +#define OP_MASK_CUSTOM_C 0x00004000
  6882. +#define OP_SH_CUSTOM_C 14
  6883. +
  6884. +#define OP_MASK_CUSTOM_N 0x00003fc0
  6885. +#define OP_SH_CUSTOM_N 6
  6886. +#define OP_MAX_CUSTOM_N 255
  6887. +
  6888. +/*
  6889. + The following macros define the opcode matches for each
  6890. + instruction
  6891. + code & OP_MASK_INST == OP_MATCH_INST
  6892. + */
  6893. +
  6894. +/* OP instruction matches */
  6895. +#define OP_MATCH_ADDI OP_ADDI
  6896. +#define OP_MATCH_ANDHI OP_ANDHI
  6897. +#define OP_MATCH_ANDI OP_ANDI
  6898. +#define OP_MATCH_BEQ OP_BEQ
  6899. +#define OP_MATCH_BGE OP_BGE
  6900. +#define OP_MATCH_BGEU OP_BGEU
  6901. +#define OP_MATCH_BLT OP_BLT
  6902. +#define OP_MATCH_BLTU OP_BLTU
  6903. +#define OP_MATCH_BNE OP_BNE
  6904. +#define OP_MATCH_BR OP_BR
  6905. +#define OP_MATCH_FLUSHD OP_FLUSHD
  6906. +#define OP_MATCH_FLUSHDA OP_FLUSHDA
  6907. +#define OP_MATCH_INITD OP_INITD
  6908. +#define OP_MATCH_CALL OP_CALL
  6909. +#define OP_MATCH_CMPEQI OP_CMPEQI
  6910. +#define OP_MATCH_CMPGEI OP_CMPGEI
  6911. +#define OP_MATCH_CMPGEUI OP_CMPGEUI
  6912. +#define OP_MATCH_CMPLTI OP_CMPLTI
  6913. +#define OP_MATCH_CMPLTUI OP_CMPLTUI
  6914. +#define OP_MATCH_CMPNEI OP_CMPNEI
  6915. +#define OP_MATCH_JMPI OP_JMPI
  6916. +#define OP_MATCH_LDB OP_LDB
  6917. +#define OP_MATCH_LDBIO OP_LDBIO
  6918. +#define OP_MATCH_LDBU OP_LDBU
  6919. +#define OP_MATCH_LDBUIO OP_LDBUIO
  6920. +#define OP_MATCH_LDH OP_LDH
  6921. +#define OP_MATCH_LDHIO OP_LDHIO
  6922. +#define OP_MATCH_LDHU OP_LDHU
  6923. +#define OP_MATCH_LDHUIO OP_LDHUIO
  6924. +#define OP_MATCH_LDW OP_LDW
  6925. +#define OP_MATCH_LDWIO OP_LDWIO
  6926. +#define OP_MATCH_MULI OP_MULI
  6927. +#define OP_MATCH_OPX OP_OPX
  6928. +#define OP_MATCH_ORHI OP_ORHI
  6929. +#define OP_MATCH_ORI OP_ORI
  6930. +#define OP_MATCH_STB OP_STB
  6931. +#define OP_MATCH_STBIO OP_STBIO
  6932. +#define OP_MATCH_STH OP_STH
  6933. +#define OP_MATCH_STHIO OP_STHIO
  6934. +#define OP_MATCH_STW OP_STW
  6935. +#define OP_MATCH_STWIO OP_STWIO
  6936. +#define OP_MATCH_CUSTOM OP_CUSTOM
  6937. +#define OP_MATCH_XORHI OP_XORHI
  6938. +#define OP_MATCH_XORI OP_XORI
  6939. +#define OP_MATCH_OPX OP_OPX
  6940. +
  6941. +
  6942. +
  6943. +/* OPX instruction values */
  6944. +#define OP_MATCH_ADD ((OPX_ADD << IW_OPX_LSB) | (OP_OPX))
  6945. +#define OP_MATCH_AND ((OPX_AND << IW_OPX_LSB) | (OP_OPX))
  6946. +#define OP_MATCH_BREAK ((0x1e << 17) | (OPX_BREAK << IW_OPX_LSB) | (OP_OPX))
  6947. +#define OP_MATCH_BRET ((0xf0000000) | (OPX_BRET << IW_OPX_LSB) | (OP_OPX))
  6948. +#define OP_MATCH_CALLR ((0x1f << 17) | (OPX_CALLR << IW_OPX_LSB) | (OP_OPX))
  6949. +#define OP_MATCH_CMPEQ ((OPX_CMPEQ << IW_OPX_LSB) | (OP_OPX))
  6950. +#define OP_MATCH_CMPGE ((OPX_CMPGE << IW_OPX_LSB) | (OP_OPX))
  6951. +#define OP_MATCH_CMPGEU ((OPX_CMPGEU << IW_OPX_LSB) | (OP_OPX))
  6952. +#define OP_MATCH_CMPLT ((OPX_CMPLT << IW_OPX_LSB) | (OP_OPX))
  6953. +#define OP_MATCH_CMPLTU ((OPX_CMPLTU << IW_OPX_LSB) | (OP_OPX))
  6954. +#define OP_MATCH_CMPNE ((OPX_CMPNE << IW_OPX_LSB) | (OP_OPX))
  6955. +#define OP_MATCH_DIV ((OPX_DIV << IW_OPX_LSB) | (OP_OPX))
  6956. +#define OP_MATCH_DIVU ((OPX_DIVU << IW_OPX_LSB) | (OP_OPX))
  6957. +#define OP_MATCH_JMP ((OPX_JMP << IW_OPX_LSB) | (OP_OPX))
  6958. +#define OP_MATCH_MUL ((OPX_MUL << IW_OPX_LSB) | (OP_OPX))
  6959. +#define OP_MATCH_MULXSS ((OPX_MULXSS << IW_OPX_LSB) | (OP_OPX))
  6960. +#define OP_MATCH_MULXSU ((OPX_MULXSU << IW_OPX_LSB) | (OP_OPX))
  6961. +#define OP_MATCH_MULXUU ((OPX_MULXUU << IW_OPX_LSB) | (OP_OPX))
  6962. +#define OP_MATCH_NEXTPC ((OPX_NEXTPC << IW_OPX_LSB) | (OP_OPX))
  6963. +#define OP_MATCH_NOR ((OPX_NOR << IW_OPX_LSB) | (OP_OPX))
  6964. +#define OP_MATCH_OR ((OPX_OR << IW_OPX_LSB) | (OP_OPX))
  6965. +#define OP_MATCH_RDCTL ((OPX_RDCTL << IW_OPX_LSB) | (OP_OPX))
  6966. +#define OP_MATCH_RET ((0xf8000000) | (OPX_RET << IW_OPX_LSB) | (OP_OPX))
  6967. +#define OP_MATCH_ROL ((OPX_ROL << IW_OPX_LSB) | (OP_OPX))
  6968. +#define OP_MATCH_ROLI ((OPX_ROLI << IW_OPX_LSB) | (OP_OPX))
  6969. +#define OP_MATCH_ROR ((OPX_ROR << IW_OPX_LSB) | (OP_OPX))
  6970. +#define OP_MATCH_SLL ((OPX_SLL << IW_OPX_LSB) | (OP_OPX))
  6971. +#define OP_MATCH_SLLI ((OPX_SLLI << IW_OPX_LSB) | (OP_OPX))
  6972. +#define OP_MATCH_SRA ((OPX_SRA << IW_OPX_LSB) | (OP_OPX))
  6973. +#define OP_MATCH_SRAI ((OPX_SRAI << IW_OPX_LSB) | (OP_OPX))
  6974. +#define OP_MATCH_SRL ((OPX_SRL << IW_OPX_LSB) | (OP_OPX))
  6975. +#define OP_MATCH_SRLI ((OPX_SRLI << IW_OPX_LSB) | (OP_OPX))
  6976. +#define OP_MATCH_SUB ((OPX_SUB << IW_OPX_LSB) | (OP_OPX))
  6977. +#define OP_MATCH_SYNC ((OPX_SYNC << IW_OPX_LSB) | (OP_OPX))
  6978. +#define OP_MATCH_TRAP ((0x1d << 17) | (OPX_TRAP << IW_OPX_LSB) | (OP_OPX))
  6979. +#define OP_MATCH_ERET ((0xe8000000) | (OPX_ERET << IW_OPX_LSB) | (OP_OPX))
  6980. +#define OP_MATCH_WRCTL ((OPX_WRCTL << IW_OPX_LSB) | (OP_OPX))
  6981. +#define OP_MATCH_XOR ((OPX_XOR << IW_OPX_LSB) | (OP_OPX))
  6982. +#define OP_MATCH_FLUSHI ((OPX_FLUSHI << IW_OPX_LSB) | (OP_OPX))
  6983. +#define OP_MATCH_FLUSHP ((OPX_FLUSHP << IW_OPX_LSB) | (OP_OPX))
  6984. +#define OP_MATCH_INITI ((OPX_INITI << IW_OPX_LSB) | (OP_OPX))
  6985. +
  6986. +/*
  6987. + Some unusual op masks
  6988. +*/
  6989. +#define OP_MASK_BREAK ((OP_MASK_RRS | OP_MASK_RRT | OP_MASK_RRD | OP_MASK_ROPX | OP_MASK_OP) & 0xfffff03f)
  6990. +#define OP_MASK_CALLR ((OP_MASK_RRT | OP_MASK_RRD | OP_MASK_ROPX | OP_MASK_OP))
  6991. +#define OP_MASK_JMP ((OP_MASK_RRT | OP_MASK_RRD | OP_MASK_ROPX | OP_MASK_OP))
  6992. +#define OP_MASK_SYNC ((OP_MASK_RRT | OP_MASK_RRD | OP_MASK_ROPX | OP_MASK_OP))
  6993. +#define OP_MASK_TRAP ((OP_MASK_RRS | OP_MASK_RRT | OP_MASK_RRD | OP_MASK_ROPX | OP_MASK_OP) & 0xfffff83f)
  6994. +#define OP_MASK_WRCTL ((OP_MASK_RRT | OP_MASK_RRD | OP_MASK_ROPX | OP_MASK_OP)) /*& 0xfffff83f */
  6995. +#define OP_MASK_NEXTPC ((OP_MASK_RRS | OP_MASK_RRT | OP_MASK_ROPX | OP_MASK_OP))
  6996. +#define OP_MASK_FLUSHI ((OP_MASK_RRT | OP_MASK_RRD | OP_MASK_ROPX | OP_MASK_OP))
  6997. +#define OP_MASK_INITI ((OP_MASK_RRT | OP_MASK_RRD | OP_MASK_ROPX | OP_MASK_OP))
  6998. +
  6999. +#define OP_MASK_ROLI ((OP_MASK_RRT | OP_MASK_ROPX | OP_MASK_OP))
  7000. +#define OP_MASK_SLLI ((OP_MASK_RRT | OP_MASK_ROPX | OP_MASK_OP))
  7001. +#define OP_MASK_SRAI ((OP_MASK_RRT | OP_MASK_ROPX | OP_MASK_OP))
  7002. +#define OP_MASK_SRLI ((OP_MASK_RRT | OP_MASK_ROPX | OP_MASK_OP))
  7003. +#define OP_MASK_RDCTL ((OP_MASK_RRS | OP_MASK_RRT | OP_MASK_ROPX | OP_MASK_OP)) /*& 0xfffff83f */
  7004. +
  7005. +#ifndef OP_MASK
  7006. +#define OP_MASK 0xffffffff
  7007. +#endif
  7008. +
  7009. +/* These are the data structures we use to hold the instruction information */
  7010. +
  7011. +extern const struct nios2_opcode nios2_builtin_opcodes[];
  7012. +extern const int bfd_nios2_num_builtin_opcodes;
  7013. +extern struct nios2_opcode *nios2_opcodes;
  7014. +extern int bfd_nios2_num_opcodes;
  7015. +
  7016. +/* These are the data structures used to hold the operand parsing information */
  7017. +//extern const struct nios2_arg_parser nios2_arg_parsers[];
  7018. +//extern struct nios2_arg_parser* nios2_arg_parsers;
  7019. +//extern const int nios2_num_builtin_arg_parsers;
  7020. +//extern int nios2_num_arg_parsers;
  7021. +
  7022. +/* These are the data structures used to hold the register information */
  7023. +extern const struct nios2_reg nios2_builtin_regs[];
  7024. +extern struct nios2_reg *nios2_regs;
  7025. +extern const int nios2_num_builtin_regs;
  7026. +extern int nios2_num_regs;
  7027. +
  7028. +/* Machine-independent macro for number of opcodes */
  7029. +
  7030. +#define NUMOPCODES bfd_nios2_num_opcodes
  7031. +#define NUMREGISTERS nios2_num_regs;
  7032. +
  7033. +/* these are used in disassembly to get the correct register names */
  7034. +#define NUMREGNAMES 32
  7035. +#define NUMCTLREGNAMES 32
  7036. +#define CTLREGBASE 42
  7037. +#define COPROCREGBASE 83
  7038. +#define NUMCOPROCREGNAMES 32
  7039. +
  7040. +
  7041. +/* this is made extern so that the assembler can use it to find out
  7042. + what instruction caused an error */
  7043. +extern const struct nios2_opcode *nios2_find_opcode_hash (unsigned long);
  7044. +
  7045. +/* overflow message strings used in the assembler */
  7046. +extern char *overflow_msgs[];
  7047. +
  7048. +#endif // _NIOS2_H
  7049. diff --git a/opcodes/Makefile.am b/opcodes/Makefile.am
  7050. index ebd252f..a7ca06b 100644
  7051. --- a/opcodes/Makefile.am
  7052. +++ b/opcodes/Makefile.am
  7053. @@ -146,6 +146,13 @@ CFILES = \
  7054. mt-dis.c \
  7055. mt-ibld.c \
  7056. mt-opc.c \
  7057. + nios2-opc.c \
  7058. + nios2-dis.c \
  7059. + ms1-asm.c \
  7060. + ms1-desc.c \
  7061. + ms1-dis.c \
  7062. + ms1-ibld.c \
  7063. + ms1-opc.c \
  7064. ns32k-dis.c \
  7065. openrisc-asm.c \
  7066. openrisc-desc.c \
  7067. @@ -281,6 +288,8 @@ ALL_MACHINES = \
  7068. mt-dis.lo \
  7069. mt-ibld.lo \
  7070. mt-opc.lo \
  7071. + nios2-opc.lo \
  7072. + nios2-dis.lo \
  7073. ns32k-dis.lo \
  7074. openrisc-asm.lo \
  7075. openrisc-desc.lo \
  7076. @@ -980,6 +989,13 @@ mt-opc.lo: mt-opc.c sysdep.h config.h $(INCDIR)/ansidecl.h \
  7077. mt-desc.h $(INCDIR)/opcode/cgen-bitset.h $(INCDIR)/opcode/cgen.h \
  7078. $(INCDIR)/symcat.h $(INCDIR)/opcode/cgen-bitset.h mt-opc.h \
  7079. $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h
  7080. +nios2-opc.lo: nios2-opc.c sysdep.h config.h $(INCDIR)/ansidecl.h \
  7081. + $(INCDIR)/opcode/nios2.h
  7082. +nios2-dis.lo: nios2-dis.c sysdep.h config.h $(INCDIR)/ansidecl.h \
  7083. + $(INCDIR)/dis-asm.h $(BFD_H) $(INCDIR)/symcat.h $(INCDIR)/opcode/nios2.h \
  7084. + opintl.h $(BFDDIR)/elf-bfd.h $(INCDIR)/elf/common.h \
  7085. + $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h $(INCDIR)/bfdlink.h \
  7086. + $(INCDIR)/elf/nios2.h $(INCDIR)/elf/reloc-macros.h
  7087. ns32k-dis.lo: ns32k-dis.c $(BFD_H) $(INCDIR)/ansidecl.h \
  7088. $(INCDIR)/symcat.h sysdep.h config.h $(INCDIR)/ansidecl.h \
  7089. $(INCDIR)/dis-asm.h $(BFD_H) $(INCDIR)/opcode/ns32k.h \
  7090. diff --git a/opcodes/Makefile.in b/opcodes/Makefile.in
  7091. index 85003e6..9e3baae 100644
  7092. --- a/opcodes/Makefile.in
  7093. +++ b/opcodes/Makefile.in
  7094. @@ -360,6 +360,8 @@ CFILES = \
  7095. mt-dis.c \
  7096. mt-ibld.c \
  7097. mt-opc.c \
  7098. + nios2-opc.c \
  7099. + nios2-dis.c \
  7100. ns32k-dis.c \
  7101. openrisc-asm.c \
  7102. openrisc-desc.c \
  7103. @@ -495,6 +497,8 @@ ALL_MACHINES = \
  7104. mt-dis.lo \
  7105. mt-ibld.lo \
  7106. mt-opc.lo \
  7107. + nios2-opc.lo \
  7108. + nios2-dis.lo \
  7109. ns32k-dis.lo \
  7110. openrisc-asm.lo \
  7111. openrisc-desc.lo \
  7112. @@ -1517,6 +1521,13 @@ mt-opc.lo: mt-opc.c sysdep.h config.h $(INCDIR)/ansidecl.h \
  7113. mt-desc.h $(INCDIR)/opcode/cgen-bitset.h $(INCDIR)/opcode/cgen.h \
  7114. $(INCDIR)/symcat.h $(INCDIR)/opcode/cgen-bitset.h mt-opc.h \
  7115. $(INCDIR)/libiberty.h $(INCDIR)/ansidecl.h $(INCDIR)/safe-ctype.h
  7116. +nios2-opc.lo: nios2-opc.c sysdep.h config.h $(INCDIR)/ansidecl.h \
  7117. + $(INCDIR)/opcode/nios2.h
  7118. +nios2-dis.lo: nios2-dis.c sysdep.h config.h $(INCDIR)/ansidecl.h \
  7119. + $(INCDIR)/dis-asm.h $(BFD_H) $(INCDIR)/symcat.h $(INCDIR)/opcode/nios2.h \
  7120. + opintl.h $(BFDDIR)/elf-bfd.h $(INCDIR)/elf/common.h \
  7121. + $(INCDIR)/elf/internal.h $(INCDIR)/elf/external.h $(INCDIR)/bfdlink.h \
  7122. + $(INCDIR)/elf/nios2.h $(INCDIR)/elf/reloc-macros.h
  7123. ns32k-dis.lo: ns32k-dis.c $(BFD_H) $(INCDIR)/ansidecl.h \
  7124. $(INCDIR)/symcat.h sysdep.h config.h $(INCDIR)/ansidecl.h \
  7125. $(INCDIR)/dis-asm.h $(BFD_H) $(INCDIR)/opcode/ns32k.h \
  7126. diff --git a/opcodes/configure b/opcodes/configure
  7127. index 8e3e27e..a28cc46 100755
  7128. --- a/opcodes/configure
  7129. +++ b/opcodes/configure
  7130. @@ -6561,6 +6561,7 @@ if test x${all_targets} = xfalse ; then
  7131. bfd_mn10300_arch) ta="$ta m10300-dis.lo m10300-opc.lo" ;;
  7132. bfd_mt_arch) ta="$ta mt-asm.lo mt-desc.lo mt-dis.lo mt-ibld.lo mt-opc.lo" using_cgen=yes ;;
  7133. bfd_msp430_arch) ta="$ta msp430-dis.lo" ;;
  7134. + bfd_nios2_arch) ta="$ta nios2-opc.lo nios2-dis.lo" ;;
  7135. bfd_ns32k_arch) ta="$ta ns32k-dis.lo" ;;
  7136. bfd_openrisc_arch) ta="$ta openrisc-asm.lo openrisc-desc.lo openrisc-dis.lo openrisc-ibld.lo openrisc-opc.lo" using_cgen=yes ;;
  7137. bfd_or32_arch) ta="$ta or32-dis.lo or32-opc.lo" using_cgen=yes ;;
  7138. diff --git a/opcodes/configure.in b/opcodes/configure.in
  7139. index d937784..c9df814 100644
  7140. --- a/opcodes/configure.in
  7141. +++ b/opcodes/configure.in
  7142. @@ -190,6 +190,7 @@ if test x${all_targets} = xfalse ; then
  7143. bfd_mn10300_arch) ta="$ta m10300-dis.lo m10300-opc.lo" ;;
  7144. bfd_mt_arch) ta="$ta mt-asm.lo mt-desc.lo mt-dis.lo mt-ibld.lo mt-opc.lo" using_cgen=yes ;;
  7145. bfd_msp430_arch) ta="$ta msp430-dis.lo" ;;
  7146. + bfd_nios2_arch) ta="$ta nios2-opc.lo nios2-dis.lo" ;;
  7147. bfd_ns32k_arch) ta="$ta ns32k-dis.lo" ;;
  7148. bfd_openrisc_arch) ta="$ta openrisc-asm.lo openrisc-desc.lo openrisc-dis.lo openrisc-ibld.lo openrisc-opc.lo" using_cgen=yes ;;
  7149. bfd_or32_arch) ta="$ta or32-dis.lo or32-opc.lo" using_cgen=yes ;;
  7150. diff --git a/opcodes/disassemble.c b/opcodes/disassemble.c
  7151. index ca28f56..dfacbb9 100644
  7152. --- a/opcodes/disassemble.c
  7153. +++ b/opcodes/disassemble.c
  7154. @@ -80,6 +80,7 @@
  7155. #define ARCH_xtensa
  7156. #define ARCH_z80
  7157. #define ARCH_z8k
  7158. +#define ARCH_nios2
  7159. #define INCLUDE_SHMEDIA
  7160. #endif
  7161. @@ -424,6 +425,14 @@ disassembler (abfd)
  7162. disassemble = print_insn_iq2000;
  7163. break;
  7164. #endif
  7165. +#ifdef ARCH_nios2
  7166. + case bfd_arch_nios2:
  7167. + if (bfd_big_endian (abfd))
  7168. + disassemble = print_insn_big_nios2;
  7169. + else
  7170. + disassemble = print_insn_little_nios2;
  7171. + break;
  7172. +#endif
  7173. #ifdef ARCH_m32c
  7174. case bfd_arch_m32c:
  7175. disassemble = print_insn_m32c;
  7176. diff --git a/opcodes/nios2-dis.c b/opcodes/nios2-dis.c
  7177. new file mode 100644
  7178. index 0000000..ac9eb0d
  7179. --- /dev/null
  7180. +++ b/opcodes/nios2-dis.c
  7181. @@ -0,0 +1,462 @@
  7182. +/* nios2-dis.c -- Altera New Jersey disassemble routines.
  7183. +
  7184. + Copyright (C) 2003
  7185. + by Nigel Gray (ngray@altera.com).
  7186. +
  7187. +This file is part of GDB, GAS, and the GNU binutils.
  7188. +
  7189. +GDB, GAS, and the GNU binutils are free software; you can redistribute
  7190. +them and/or modify them under the terms of the GNU General Public
  7191. +License as published by the Free Software Foundation; either version
  7192. +1, or (at your option) any later version.
  7193. +
  7194. +GDB, GAS, and the GNU binutils are distributed in the hope that they
  7195. +will be useful, but WITHOUT ANY WARRANTY; without even the implied
  7196. +warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  7197. +the GNU General Public License for more details.
  7198. +
  7199. +You should have received a copy of the GNU General Public License
  7200. +along with this file; see the file COPYING. If not, write to the Free
  7201. +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  7202. +
  7203. +#include <stdlib.h>
  7204. +#include <assert.h>
  7205. +#include <string.h>
  7206. +#include "dis-asm.h"
  7207. +#include "opcode/nios2.h"
  7208. +
  7209. +/* No symbol table is available when this code runs out in an embedded
  7210. + system as when it is used for disassembler support in a monitor. */
  7211. +
  7212. +#if !defined(EMBEDDED_ENV)
  7213. +#define SYMTAB_AVAILABLE 1
  7214. +#include "elf-bfd.h"
  7215. +#include "elf/nios2.h"
  7216. +#endif
  7217. +
  7218. +/* length of New Jersey instruction in bytes */
  7219. +#define INSNLEN 4
  7220. +
  7221. +/* helper function prototypes */
  7222. +static int nios2_disassemble (bfd_vma, unsigned long, disassemble_info *);
  7223. +static void nios2_init_opcode_hash (void);
  7224. +
  7225. +
  7226. +static int nios2_print_insn_arg (const char *argptr, unsigned long opcode,
  7227. + bfd_vma address, disassemble_info * info);
  7228. +
  7229. +
  7230. +/* print_insn_nios2 is the main disassemble function for New Jersey.
  7231. + The function diassembler(abfd) (source in disassemble.c) returns a
  7232. + pointer to this either print_insn_big_nios2 or
  7233. + print_insn_little_nios2, which in turn call this function, when the
  7234. + bfd machine type is New Jersey. print_insn_nios2 reads the
  7235. + instruction word at the address given, and prints the disassembled
  7236. + instruction on the stream info->stream using info->fprintf_func. */
  7237. +
  7238. +static int
  7239. +print_insn_nios2 (bfd_vma address, disassemble_info * info,
  7240. + enum bfd_endian endianness)
  7241. +{
  7242. + /* buffer into which the instruction bytes are written */
  7243. + bfd_byte buffer[INSNLEN];
  7244. + /* used to indicate return status from function calls */
  7245. + int status;
  7246. +
  7247. + assert (info != NULL);
  7248. +
  7249. + status = (*info->read_memory_func) (address, buffer, INSNLEN, info);
  7250. + if (status == 0)
  7251. + {
  7252. + unsigned long insn;
  7253. + if (endianness == BFD_ENDIAN_BIG)
  7254. + insn = (unsigned long) bfd_getb32 (buffer);
  7255. + else
  7256. + insn = (unsigned long) bfd_getl32 (buffer);
  7257. + status = nios2_disassemble (address, insn, info);
  7258. + }
  7259. + else
  7260. + {
  7261. + (*info->memory_error_func) (status, address, info);
  7262. + status = -1;
  7263. + }
  7264. + return status;
  7265. +}
  7266. +
  7267. +int
  7268. +print_insn_big_nios2 (bfd_vma address, disassemble_info * info)
  7269. +{
  7270. + return print_insn_nios2 (address, info, BFD_ENDIAN_BIG);
  7271. +}
  7272. +
  7273. +int
  7274. +print_insn_little_nios2 (bfd_vma address, disassemble_info * info)
  7275. +{
  7276. + return print_insn_nios2 (address, info, BFD_ENDIAN_LITTLE);
  7277. +}
  7278. +
  7279. +/* Data structures used by the opcode hash table */
  7280. +
  7281. +typedef struct _nios2_opcode_hash
  7282. +{
  7283. + const struct nios2_opcode *opcode;
  7284. + struct _nios2_opcode_hash *next;
  7285. +} nios2_opcode_hash;
  7286. +
  7287. +static bfd_boolean nios2_hash_init = 0;
  7288. +static nios2_opcode_hash *nios2_hash[(OP_MASK_OP) + 1];
  7289. +
  7290. +/* separate hash table for pseudo-ops */
  7291. +static nios2_opcode_hash *nios2_ps_hash[(OP_MASK_OP) + 1];
  7292. +
  7293. +/* Function to initialize the opcode hash table */
  7294. +
  7295. +void
  7296. +nios2_init_opcode_hash ()
  7297. +{
  7298. + unsigned int i;
  7299. + register const struct nios2_opcode *op;
  7300. + nios2_opcode_hash *tmp_hash;
  7301. +
  7302. + for (i = 0; i <= OP_MASK_OP; ++i)
  7303. + {
  7304. + nios2_hash[0] = NULL;
  7305. + }
  7306. + for (i = 0; i <= OP_MASK_OP; i++)
  7307. + {
  7308. + for (op = nios2_opcodes; op < &nios2_opcodes[NUMOPCODES]; op++)
  7309. + {
  7310. + if ((op->pinfo & NIOS2_INSN_MACRO) == NIOS2_INSN_MACRO)
  7311. + {
  7312. + if (i == ((op->match >> OP_SH_OP) & OP_MASK_OP) &&
  7313. + (op->
  7314. + pinfo & (NIOS2_INSN_MACRO_MOV | NIOS2_INSN_MACRO_MOVI) &
  7315. + 0x7fffffff) != 0)
  7316. + {
  7317. + tmp_hash = nios2_ps_hash[i];
  7318. + if (tmp_hash == NULL)
  7319. + {
  7320. + tmp_hash =
  7321. + (nios2_opcode_hash *)
  7322. + malloc (sizeof (nios2_opcode_hash));
  7323. + nios2_ps_hash[i] = tmp_hash;
  7324. + }
  7325. + else
  7326. + {
  7327. + while (tmp_hash->next != NULL)
  7328. + tmp_hash = tmp_hash->next;
  7329. + tmp_hash->next =
  7330. + (nios2_opcode_hash *)
  7331. + malloc (sizeof (nios2_opcode_hash));
  7332. + tmp_hash = tmp_hash->next;
  7333. + }
  7334. + if (tmp_hash == NULL)
  7335. + {
  7336. + fprintf (stderr,
  7337. + "error allocating memory...broken disassembler\n");
  7338. + abort ();
  7339. + }
  7340. + tmp_hash->opcode = op;
  7341. + tmp_hash->next = NULL;
  7342. + }
  7343. + }
  7344. + else if (i == ((op->match >> OP_SH_OP) & OP_MASK_OP))
  7345. + {
  7346. + tmp_hash = nios2_hash[i];
  7347. + if (tmp_hash == NULL)
  7348. + {
  7349. + tmp_hash =
  7350. + (nios2_opcode_hash *) malloc (sizeof (nios2_opcode_hash));
  7351. + nios2_hash[i] = tmp_hash;
  7352. + }
  7353. + else
  7354. + {
  7355. + while (tmp_hash->next != NULL)
  7356. + tmp_hash = tmp_hash->next;
  7357. + tmp_hash->next =
  7358. + (nios2_opcode_hash *) malloc (sizeof (nios2_opcode_hash));
  7359. + tmp_hash = tmp_hash->next;
  7360. + }
  7361. + if (tmp_hash == NULL)
  7362. + {
  7363. + fprintf (stderr,
  7364. + "error allocating memory...broken disassembler\n");
  7365. + abort ();
  7366. + }
  7367. + tmp_hash->opcode = op;
  7368. + tmp_hash->next = NULL;
  7369. + }
  7370. + }
  7371. + }
  7372. + nios2_hash_init = 1;
  7373. +#ifdef DEBUG_HASHTABLE
  7374. + for (i = 0; i <= OP_MASK_OP; ++i)
  7375. + {
  7376. + printf ("index: 0x%02X ops: ", i);
  7377. + tmp_hash = nios2_hash[i];
  7378. + if (tmp_hash != NULL)
  7379. + {
  7380. + while (tmp_hash != NULL)
  7381. + {
  7382. + printf ("%s ", tmp_hash->opcode->name);
  7383. + tmp_hash = tmp_hash->next;
  7384. + }
  7385. + }
  7386. + printf ("\n");
  7387. + }
  7388. +
  7389. + for (i = 0; i <= OP_MASK_OP; ++i)
  7390. + {
  7391. + printf ("index: 0x%02X ops: ", i);
  7392. + tmp_hash = nios2_ps_hash[i];
  7393. + if (tmp_hash != NULL)
  7394. + {
  7395. + while (tmp_hash != NULL)
  7396. + {
  7397. + printf ("%s ", tmp_hash->opcode->name);
  7398. + tmp_hash = tmp_hash->next;
  7399. + }
  7400. + }
  7401. + printf ("\n");
  7402. + }
  7403. +#endif
  7404. +}
  7405. +
  7406. +/* Function which returns a pointer to an nios2_opcode struct for
  7407. + a given instruction opcode, or NULL if there is an error */
  7408. +
  7409. +const struct nios2_opcode *
  7410. +nios2_find_opcode_hash (unsigned long opcode)
  7411. +{
  7412. + nios2_opcode_hash *entry;
  7413. +
  7414. + /* Build a hash table to shorten the search time. */
  7415. + if (!nios2_hash_init)
  7416. + {
  7417. + nios2_init_opcode_hash ();
  7418. + }
  7419. +
  7420. + /* first look in the pseudo-op hashtable */
  7421. + entry = nios2_ps_hash[(opcode >> OP_SH_OP) & OP_MASK_OP];
  7422. +
  7423. + /* look for a match and if we get one, this is the instruction we decode */
  7424. + while (entry != NULL)
  7425. + {
  7426. + if ((entry->opcode->match) == (opcode & entry->opcode->mask))
  7427. + return entry->opcode;
  7428. + else
  7429. + entry = entry->next;
  7430. + }
  7431. +
  7432. + /* if we haven't yet returned, then we need to look in the main
  7433. + hashtable */
  7434. + entry = nios2_hash[(opcode >> OP_SH_OP) & OP_MASK_OP];
  7435. +
  7436. + if (entry == NULL)
  7437. + return NULL;
  7438. +
  7439. +
  7440. + while (entry != NULL)
  7441. + {
  7442. + if ((entry->opcode->match) == (opcode & entry->opcode->mask))
  7443. + return entry->opcode;
  7444. + else
  7445. + entry = entry->next;
  7446. + }
  7447. +
  7448. + return NULL;
  7449. +}
  7450. +
  7451. +/* nios2_disassemble does all the work of disassembling a New Jersey
  7452. + instruction opcode */
  7453. +
  7454. +int
  7455. +nios2_disassemble (bfd_vma address, unsigned long opcode,
  7456. + disassemble_info * info)
  7457. +{
  7458. + const struct nios2_opcode *op;
  7459. + const char *argstr;
  7460. +
  7461. + info->bytes_per_line = INSNLEN;
  7462. + info->bytes_per_chunk = INSNLEN;
  7463. + info->display_endian = info->endian;
  7464. + info->insn_info_valid = 1;
  7465. + info->branch_delay_insns = 0;
  7466. + info->data_size = 0;
  7467. + info->insn_type = dis_nonbranch;
  7468. + info->target = 0;
  7469. + info->target2 = 0;
  7470. +
  7471. + /* Find the major opcode and use this to disassemble
  7472. + the instruction and its arguments */
  7473. + op = nios2_find_opcode_hash (opcode);
  7474. +
  7475. + if (op != NULL)
  7476. + {
  7477. + bfd_boolean is_nop = FALSE;
  7478. + if (op->pinfo == NIOS2_INSN_MACRO_MOV)
  7479. + {
  7480. + /* check for mov r0, r0 and if it is
  7481. + change to nop */
  7482. + int dst, src;
  7483. + dst = GET_INSN_FIELD (RRD, opcode);
  7484. + src = GET_INSN_FIELD (RRS, opcode);
  7485. + if (dst == 0 && src == 0)
  7486. + {
  7487. + (*info->fprintf_func) (info->stream, "nop");
  7488. + is_nop = TRUE;
  7489. + }
  7490. + else
  7491. + {
  7492. + (*info->fprintf_func) (info->stream, "%s", op->name);
  7493. + }
  7494. + }
  7495. + else
  7496. + {
  7497. + (*info->fprintf_func) (info->stream, "%s", op->name);
  7498. + }
  7499. +
  7500. + if (!is_nop)
  7501. + {
  7502. + argstr = op->args;
  7503. + if (argstr != NULL && *argstr != '\0')
  7504. + {
  7505. + (*info->fprintf_func) (info->stream, "\t");
  7506. + while (*argstr != '\0')
  7507. + {
  7508. + nios2_print_insn_arg (argstr, opcode, address, info);
  7509. + ++argstr;
  7510. + }
  7511. + }
  7512. + }
  7513. + }
  7514. + else
  7515. + {
  7516. + /* Handle undefined instructions. */
  7517. + info->insn_type = dis_noninsn;
  7518. + (*info->fprintf_func) (info->stream, "0x%x", (unsigned int) opcode);
  7519. + }
  7520. + // this tells the caller how far to advance the program counter
  7521. + return INSNLEN;
  7522. +}
  7523. +
  7524. +/* The function nios2_print_insn_arg uses the character pointed
  7525. + to by argptr to determine how it print the next token or separator
  7526. + character in the arguments to an instruction */
  7527. +int
  7528. +nios2_print_insn_arg (const char *argptr,
  7529. + unsigned long opcode, bfd_vma address,
  7530. + disassemble_info * info)
  7531. +{
  7532. + unsigned long i = 0;
  7533. + unsigned long reg_base;
  7534. +
  7535. + assert (argptr != NULL);
  7536. + assert (info != NULL);
  7537. +
  7538. + switch (*argptr)
  7539. + {
  7540. + case ',':
  7541. + case '(':
  7542. + case ')':
  7543. + (*info->fprintf_func) (info->stream, "%c", *argptr);
  7544. + break;
  7545. + case 'd':
  7546. + i = GET_INSN_FIELD (RRD, opcode);
  7547. +
  7548. + if (GET_INSN_FIELD (OP, opcode) == OP_MATCH_CUSTOM
  7549. + && GET_INSN_FIELD (CUSTOM_C, opcode) == 0)
  7550. + reg_base = COPROCREGBASE;
  7551. + else
  7552. + reg_base = 0;
  7553. +
  7554. + if (i < NUMREGNAMES)
  7555. + (*info->fprintf_func) (info->stream, "%s",
  7556. + nios2_regs[i + reg_base].name);
  7557. + else
  7558. + (*info->fprintf_func) (info->stream, "unknown");
  7559. + break;
  7560. + case 's':
  7561. + i = GET_INSN_FIELD (RRS, opcode);
  7562. +
  7563. + if (GET_INSN_FIELD (OP, opcode) == OP_MATCH_CUSTOM
  7564. + && GET_INSN_FIELD (CUSTOM_A, opcode) == 0)
  7565. + reg_base = COPROCREGBASE;
  7566. + else
  7567. + reg_base = 0;
  7568. +
  7569. + if (i < NUMREGNAMES)
  7570. + (*info->fprintf_func) (info->stream, "%s",
  7571. + nios2_regs[i + reg_base].name);
  7572. + else
  7573. + (*info->fprintf_func) (info->stream, "unknown");
  7574. + break;
  7575. + case 't':
  7576. + i = GET_INSN_FIELD (RRT, opcode);
  7577. +
  7578. + if (GET_INSN_FIELD (OP, opcode) == OP_MATCH_CUSTOM
  7579. + && GET_INSN_FIELD (CUSTOM_B, opcode) == 0)
  7580. + reg_base = COPROCREGBASE;
  7581. + else
  7582. + reg_base = 0;
  7583. +
  7584. + if (i < NUMREGNAMES)
  7585. + (*info->fprintf_func) (info->stream, "%s",
  7586. + nios2_regs[i + reg_base].name);
  7587. + else
  7588. + (*info->fprintf_func) (info->stream, "unknown");
  7589. + break;
  7590. + case 'i':
  7591. + /* 16-bit signed immediate */
  7592. + i = (signed) (GET_INSN_FIELD (IMM16, opcode) << 16) >> 16;
  7593. + (*info->fprintf_func) (info->stream, "%d", (int) i);
  7594. + break;
  7595. + case 'u':
  7596. + /* 16-bit unsigned immediate */
  7597. + i = GET_INSN_FIELD (IMM16, opcode);
  7598. + (*info->fprintf_func) (info->stream, "%d", (int) i);
  7599. + break;
  7600. + case 'o':
  7601. + /* 16-bit signed immediate address offset */
  7602. + i = (signed) (GET_INSN_FIELD (IMM16, opcode) << 16) >> 16;
  7603. + address = address + 4 + i; /* NG changed to byte offset 1/9/03 */
  7604. + (*info->print_address_func) (address, info);
  7605. + break;
  7606. + case 'p':
  7607. + /* 5-bit unsigned immediate */
  7608. + i = GET_INSN_FIELD (CACHE_OPX, opcode);
  7609. + (*info->fprintf_func) (info->stream, "%d", (int) i);
  7610. + break;
  7611. + case 'j':
  7612. + /* 5-bit unsigned immediate */
  7613. + i = GET_INSN_FIELD (IMM5, opcode);
  7614. + (*info->fprintf_func) (info->stream, "%d", (int) i);
  7615. + break;
  7616. + case 'l':
  7617. + /* 8-bit unsigned immediate */
  7618. + /* FIXME - not yet implemented */
  7619. + i = GET_INSN_FIELD (CUSTOM_N, opcode);
  7620. + (*info->fprintf_func) (info->stream, "%u", (int) i);
  7621. + break;
  7622. + case 'm':
  7623. + /* 26-bit unsigned immediate */
  7624. + i = GET_INSN_FIELD (IMM26, opcode);
  7625. + /* this translates to an address because its only used in call instructions */
  7626. + address = (address & 0xf0000000) | (i << 2);
  7627. + (*info->print_address_func) (address, info);
  7628. + break;
  7629. + case 'c':
  7630. + i = GET_INSN_FIELD (IMM5, opcode); /* ctrl register index */
  7631. + (*info->fprintf_func) (info->stream, "%s",
  7632. + nios2_regs[CTLREGBASE + i].name);
  7633. + break;
  7634. + case 'b':
  7635. + i = GET_INSN_FIELD (IMM5, opcode);
  7636. + (*info->fprintf_func) (info->stream, "%d", (int) i);
  7637. + break;
  7638. + default:
  7639. + (*info->fprintf_func) (info->stream, "unknown");
  7640. + break;
  7641. + }
  7642. + return 0;
  7643. +}
  7644. diff --git a/opcodes/nios2-opc.c b/opcodes/nios2-opc.c
  7645. new file mode 100644
  7646. index 0000000..c860207
  7647. --- /dev/null
  7648. +++ b/opcodes/nios2-opc.c
  7649. @@ -0,0 +1,320 @@
  7650. +/* nios2-opc.c -- Altera New Jersey opcode list.
  7651. +
  7652. + Copyright (C) 2003
  7653. + by Nigel Gray (ngray@altera.com).
  7654. +
  7655. +This file is part of GDB, GAS, and the GNU binutils.
  7656. +
  7657. +GDB, GAS, and the GNU binutils are free software; you can redistribute
  7658. +them and/or modify them under the terms of the GNU General Public
  7659. +License as published by the Free Software Foundation; either version
  7660. +1, or (at your option) any later version.
  7661. +
  7662. +GDB, GAS, and the GNU binutils are distributed in the hope that they
  7663. +will be useful, but WITHOUT ANY WARRANTY; without even the implied
  7664. +warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
  7665. +the GNU General Public License for more details.
  7666. +
  7667. +You should have received a copy of the GNU General Public License
  7668. +along with this file; see the file COPYING. If not, write to the Free
  7669. +Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  7670. +
  7671. +#include <stdio.h>
  7672. +#include "opcode/nios2.h"
  7673. +
  7674. +/* Register string table */
  7675. +
  7676. +const struct nios2_reg nios2_builtin_regs[] = {
  7677. + {"zero", 0},
  7678. + {"at", 1}, // assembler temporary
  7679. + {"r2", 2},
  7680. + {"r3", 3},
  7681. + {"r4", 4},
  7682. + {"r5", 5},
  7683. + {"r6", 6},
  7684. + {"r7", 7},
  7685. + {"r8", 8},
  7686. + {"r9", 9},
  7687. + {"r10", 10},
  7688. + {"r11", 11},
  7689. + {"r12", 12},
  7690. + {"r13", 13},
  7691. + {"r14", 14},
  7692. + {"r15", 15},
  7693. + {"r16", 16},
  7694. + {"r17", 17},
  7695. + {"r18", 18},
  7696. + {"r19", 19},
  7697. + {"r20", 20},
  7698. + {"r21", 21},
  7699. + {"r22", 22},
  7700. + {"r23", 23},
  7701. + {"et", 24},
  7702. + {"bt", 25},
  7703. + {"gp", 26}, /* global pointer */
  7704. + {"sp", 27}, /* stack pointer */
  7705. + {"fp", 28}, /* frame pointer */
  7706. + {"ea", 29}, /* exception return address */
  7707. + {"ba", 30}, /* breakpoint return address */
  7708. + {"ra", 31}, /* return address */
  7709. +
  7710. + /* alternative names for special registers */
  7711. + {"r0", 0},
  7712. + {"r1", 1},
  7713. + {"r24", 24},
  7714. + {"r25", 25},
  7715. + {"r26", 26},
  7716. + {"r27", 27},
  7717. + {"r28", 28},
  7718. + {"r29", 29},
  7719. + {"r30", 30},
  7720. + {"r31", 31},
  7721. +
  7722. + /* control register names */
  7723. + {"status", 0},
  7724. + {"estatus", 1},
  7725. + {"bstatus", 2},
  7726. + {"ienable", 3},
  7727. + {"ipending", 4},
  7728. + {"cpuid", 5},
  7729. + {"ctl6", 6},
  7730. + {"ctl7", 7},
  7731. + {"pteaddr", 8},
  7732. + {"tlbacc", 9},
  7733. + {"tlbmisc", 10},
  7734. + {"fstatus", 11},
  7735. + {"ctl12", 12},
  7736. + {"ctl13", 13},
  7737. + {"ctl14", 14},
  7738. + {"ctl15", 15},
  7739. + {"ctl16", 16},
  7740. + {"ctl17", 17},
  7741. + {"ctl18", 18},
  7742. + {"ctl19", 19},
  7743. + {"ctl20", 20},
  7744. + {"ctl21", 21},
  7745. + {"ctl22", 22},
  7746. + {"ctl23", 23},
  7747. + {"ctl24", 24},
  7748. + {"ctl25", 25},
  7749. + {"ctl26", 26},
  7750. + {"ctl27", 27},
  7751. + {"ctl28", 28},
  7752. + {"ctl29", 29},
  7753. + {"ctl30", 30},
  7754. + {"ctl31", 31},
  7755. +
  7756. + /* alternative names for special control registers */
  7757. + {"ctl0", 0},
  7758. + {"ctl1", 1},
  7759. + {"ctl2", 2},
  7760. + {"ctl3", 3},
  7761. + {"ctl4", 4},
  7762. + {"ctl5", 5},
  7763. + {"ctl8", 8},
  7764. + {"ctl9", 9},
  7765. + {"ctl10", 10},
  7766. + {"ctl11", 11},
  7767. +
  7768. + /* coprocessor register names */
  7769. + {"c0", 0},
  7770. + {"c1", 1},
  7771. + {"c2", 2},
  7772. + {"c3", 3},
  7773. + {"c4", 4},
  7774. + {"c5", 5},
  7775. + {"c6", 6},
  7776. + {"c7", 7},
  7777. + {"c8", 8},
  7778. + {"c9", 9},
  7779. + {"c10", 10},
  7780. + {"c11", 11},
  7781. + {"c12", 12},
  7782. + {"c13", 13},
  7783. + {"c14", 14},
  7784. + {"c15", 15},
  7785. + {"c16", 16},
  7786. + {"c17", 17},
  7787. + {"c18", 18},
  7788. + {"c19", 19},
  7789. + {"c20", 20},
  7790. + {"c21", 21},
  7791. + {"c22", 22},
  7792. + {"c23", 23},
  7793. + {"c24", 24},
  7794. + {"c25", 25},
  7795. + {"c26", 26},
  7796. + {"c27", 27},
  7797. + {"c28", 28},
  7798. + {"c29", 29},
  7799. + {"c30", 30},
  7800. + {"c31", 31},
  7801. +};
  7802. +
  7803. +#define NIOS2_NUM_REGS \
  7804. + ((sizeof nios2_builtin_regs) / (sizeof (nios2_builtin_regs[0])))
  7805. +const int nios2_num_builtin_regs = NIOS2_NUM_REGS;
  7806. +
  7807. +/* const removed from the following to allow for dynamic extensions to the
  7808. + * built-in instruction set. */
  7809. +struct nios2_reg *nios2_regs = (struct nios2_reg *) nios2_builtin_regs;
  7810. +int nios2_num_regs = NIOS2_NUM_REGS;
  7811. +#undef NIOS2_NUM_REGS
  7812. +
  7813. +/* overflow message string templates */
  7814. +
  7815. +char *overflow_msgs[] = {
  7816. + "call target address 0x%08x out of range 0x%08x to 0x%08x",
  7817. + "branch offset %d out of range %d to %d",
  7818. + "%s offset %d out of range %d to %d",
  7819. + "immediate value %d out of range %d to %d",
  7820. + "immediate value %u out of range %u to %u",
  7821. + "immediate value %u out of range %u to %u",
  7822. + "custom instruction opcode %u out of range %u to %u",
  7823. +};
  7824. +
  7825. +
  7826. +
  7827. +/*--------------------------------------------------------------------------------
  7828. + This is the opcode table used by the New Jersey GNU as, disassembler and GDB
  7829. + --------------------------------------------------------------------------------*/
  7830. +
  7831. +/*
  7832. + The following letters can appear in the args field of the nios2_opcode
  7833. + structure:
  7834. +
  7835. + c - a 5-bit control register index or break opcode
  7836. + d - a 5-bit destination register index
  7837. + s - a 5-bit left source register index
  7838. + t - a 5-bit right source register index
  7839. + i - a 16-bit signed immediate
  7840. + u - a 16-bit unsigned immediate
  7841. +
  7842. + j - a 5-bit unsigned immediate
  7843. + k - a 6-bit unsigned immediate
  7844. + l - an 8-bit unsigned immediate
  7845. + m - a 26-bit unsigned immediate
  7846. +*/
  7847. +
  7848. +/* *INDENT-OFF* */
  7849. +/* FIXME: Re-format for GNU standards */
  7850. +const struct nios2_opcode nios2_builtin_opcodes[] =
  7851. +{
  7852. + /* name, args, args_test num_args, match, mask, pinfo */
  7853. + {"add", "d,s,t", "d,s,t,E", 3, OP_MATCH_ADD, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7854. + {"addi", "t,s,i", "t,s,i,E", 3, OP_MATCH_ADDI, OP_MASK_IOP, NIOS2_INSN_ADDI, signed_immed16_overflow },
  7855. + {"subi", "t,s,i", "t,s,i,E", 3, OP_MATCH_ADDI, OP_MASK_IOP, NIOS2_INSN_MACRO, signed_immed16_overflow },
  7856. + {"and", "d,s,t", "d,s,t,E", 3, OP_MATCH_AND, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7857. + {"andhi", "t,s,u", "t,s,u,E", 3, OP_MATCH_ANDHI, OP_MASK_IOP, 0, unsigned_immed16_overflow },
  7858. + {"andi", "t,s,u", "t,s,u,E", 3, OP_MATCH_ANDI, OP_MASK_IOP, NIOS2_INSN_ANDI, unsigned_immed16_overflow },
  7859. + {"beq", "s,t,o", "s,t,o,E", 3, OP_MATCH_BEQ, OP_MASK_IOP, NIOS2_INSN_CBRANCH, branch_target_overflow },
  7860. + {"bge", "s,t,o", "s,t,o,E", 3, OP_MATCH_BGE, OP_MASK_IOP, NIOS2_INSN_CBRANCH, branch_target_overflow },
  7861. + {"bgeu", "s,t,o", "s,t,o,E", 3, OP_MATCH_BGEU, OP_MASK_IOP, NIOS2_INSN_CBRANCH, branch_target_overflow },
  7862. + {"bgt", "s,t,o", "s,t,o,E", 3, OP_MATCH_BLT, OP_MASK_IOP, NIOS2_INSN_MACRO|NIOS2_INSN_CBRANCH, branch_target_overflow },
  7863. + {"bgtu", "s,t,o", "s,t,o,E", 3, OP_MATCH_BLTU, OP_MASK_IOP, NIOS2_INSN_MACRO|NIOS2_INSN_CBRANCH, branch_target_overflow },
  7864. + {"ble", "s,t,o", "s,t,o,E", 3, OP_MATCH_BGE, OP_MASK_IOP, NIOS2_INSN_MACRO|NIOS2_INSN_CBRANCH, branch_target_overflow },
  7865. + {"bleu", "s,t,o", "s,t,o,E", 3, OP_MATCH_BGEU, OP_MASK_IOP, NIOS2_INSN_MACRO|NIOS2_INSN_CBRANCH, branch_target_overflow },
  7866. + {"blt", "s,t,o", "s,t,o,E", 3, OP_MATCH_BLT, OP_MASK_IOP, NIOS2_INSN_CBRANCH, branch_target_overflow },
  7867. + {"bltu", "s,t,o", "s,t,o,E", 3, OP_MATCH_BLTU, OP_MASK_IOP, NIOS2_INSN_CBRANCH, branch_target_overflow },
  7868. + {"bne", "s,t,o", "s,t,o,E", 3, OP_MATCH_BNE, OP_MASK_IOP, NIOS2_INSN_CBRANCH, branch_target_overflow },
  7869. + {"br", "o", "o,E", 1, OP_MATCH_BR, OP_MASK_IOP, NIOS2_INSN_UBRANCH, branch_target_overflow },
  7870. + {"break", "b", "b,E", 1, OP_MATCH_BREAK, OP_MASK_BREAK, 0, no_overflow },
  7871. + {"bret", "", "E", 0, OP_MATCH_BRET, OP_MASK, 0, no_overflow },
  7872. + {"flushd", "i(s)", "i(s)E", 2, OP_MATCH_FLUSHD, OP_MASK_IOP, 0, signed_immed16_overflow },
  7873. + {"flushda", "i(s)", "i(s)E", 2, OP_MATCH_FLUSHDA, OP_MASK_IOP, 0, signed_immed16_overflow },
  7874. + {"flushi", "s", "s,E", 1, OP_MATCH_FLUSHI, OP_MASK_FLUSHI, 0, no_overflow },
  7875. + {"flushp", "", "E", 0, OP_MATCH_FLUSHP, OP_MASK, 0, no_overflow },
  7876. + {"initd", "i(s)", "i(s)E", 2, OP_MATCH_INITD, OP_MASK_IOP, 0, signed_immed16_overflow },
  7877. + {"initi", "s", "s,E", 1, OP_MATCH_INITI, OP_MASK_INITI, 0, no_overflow },
  7878. + {"call", "m", "m,E", 1, OP_MATCH_CALL, OP_MASK_IOP, NIOS2_INSN_CALL, call_target_overflow },
  7879. + {"callr", "s", "s,E", 1, OP_MATCH_CALLR, OP_MASK_CALLR, 0, no_overflow },
  7880. + {"cmpeq", "d,s,t", "d,s,t,E", 3, OP_MATCH_CMPEQ, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7881. + {"cmpeqi", "t,s,i", "t,s,i,E", 3, OP_MATCH_CMPEQI, OP_MASK_IOP, 0, signed_immed16_overflow },
  7882. + {"cmpge", "d,s,t", "d,s,t,E", 3, OP_MATCH_CMPGE, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7883. + {"cmpgei", "t,s,i", "t,s,i,E", 3, OP_MATCH_CMPGEI, OP_MASK_IOP, 0, signed_immed16_overflow },
  7884. + {"cmpgeu", "d,s,t", "d,s,t,E", 3, OP_MATCH_CMPGEU, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7885. + {"cmpgeui", "t,s,u", "t,s,u,E", 3, OP_MATCH_CMPGEUI, OP_MASK_IOP, 0, unsigned_immed16_overflow },
  7886. + {"cmpgt", "d,s,t", "d,s,t,E", 3, OP_MATCH_CMPLT, OP_MASK_ROPX | OP_MASK_ROP, NIOS2_INSN_MACRO, no_overflow },
  7887. + {"cmpgti", "t,s,i", "t,s,i,E", 3, OP_MATCH_CMPGEI, OP_MASK_IOP, NIOS2_INSN_MACRO, signed_immed16_overflow },
  7888. + {"cmpgtu", "d,s,t", "d,s,t,E", 3, OP_MATCH_CMPLTU, OP_MASK_ROPX | OP_MASK_ROP, NIOS2_INSN_MACRO, no_overflow },
  7889. + {"cmpgtui", "t,s,u", "t,s,u,E", 3, OP_MATCH_CMPGEUI, OP_MASK_IOP, NIOS2_INSN_MACRO, unsigned_immed16_overflow },
  7890. + {"cmple", "d,s,t", "d,s,t,E", 3, OP_MATCH_CMPGE, OP_MASK_ROPX | OP_MASK_ROP, NIOS2_INSN_MACRO, no_overflow },
  7891. + {"cmplei", "t,s,i", "t,s,i,E", 3, OP_MATCH_CMPLTI, OP_MASK_IOP, NIOS2_INSN_MACRO, signed_immed16_overflow },
  7892. + {"cmpleu", "d,s,t", "d,s,t,E", 3, OP_MATCH_CMPGEU, OP_MASK_ROPX | OP_MASK_ROP, NIOS2_INSN_MACRO, no_overflow },
  7893. + {"cmpleui", "t,s,u", "t,s,u,E", 3, OP_MATCH_CMPLTUI, OP_MASK_IOP, NIOS2_INSN_MACRO, unsigned_immed16_overflow },
  7894. + {"cmplt", "d,s,t", "d,s,t,E", 3, OP_MATCH_CMPLT, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7895. + {"cmplti", "t,s,i", "t,s,i,E", 3, OP_MATCH_CMPLTI, OP_MASK_IOP, 0, signed_immed16_overflow },
  7896. + {"cmpltu", "d,s,t", "d,s,t,E", 3, OP_MATCH_CMPLTU, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7897. + {"cmpltui", "t,s,u", "t,s,u,E", 3, OP_MATCH_CMPLTUI, OP_MASK_IOP, 0, unsigned_immed16_overflow },
  7898. + {"cmpne", "d,s,t", "d,s,t,E", 3, OP_MATCH_CMPNE, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7899. + {"cmpnei", "t,s,i", "t,s,i,E", 3, OP_MATCH_CMPNEI, OP_MASK_IOP, 0, signed_immed16_overflow },
  7900. + {"div", "d,s,t", "d,s,t,E", 3, OP_MATCH_DIV, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7901. + {"divu", "d,s,t", "d,s,t,E", 3, OP_MATCH_DIVU, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7902. + {"jmp", "s", "s,E", 1, OP_MATCH_JMP, OP_MASK_JMP, 0, no_overflow },
  7903. + {"jmpi", "m", "m,E", 1, OP_MATCH_JMPI, OP_MASK_IOP, 0, no_overflow },
  7904. + {"ldb", "t,i(s)", "t,i(s)E", 3, OP_MATCH_LDB, OP_MASK_IOP, 0, address_offset_overflow },
  7905. + {"ldbio", "t,i(s)", "t,i(s)E", 3, OP_MATCH_LDBIO, OP_MASK_IOP, 0, address_offset_overflow },
  7906. + {"ldbu", "t,i(s)", "t,i(s)E", 3, OP_MATCH_LDBU, OP_MASK_IOP, 0, address_offset_overflow },
  7907. + {"ldbuio", "t,i(s)", "t,i(s)E", 3, OP_MATCH_LDBUIO, OP_MASK_IOP, 0, address_offset_overflow },
  7908. + {"ldh", "t,i(s)", "t,i(s)E", 3, OP_MATCH_LDH, OP_MASK_IOP, 0, address_offset_overflow },
  7909. + {"ldhio", "t,i(s)", "t,i(s)E", 3, OP_MATCH_LDHIO, OP_MASK_IOP, 0, address_offset_overflow },
  7910. + {"ldhu", "t,i(s)", "t,i(s)E", 3, OP_MATCH_LDHU, OP_MASK_IOP, 0, address_offset_overflow },
  7911. + {"ldhuio", "t,i(s)", "t,i(s)E", 3, OP_MATCH_LDHUIO, OP_MASK_IOP, 0, address_offset_overflow },
  7912. + {"ldw", "t,i(s)", "t,i(s)E", 3, OP_MATCH_LDW, OP_MASK_IOP, 0, address_offset_overflow },
  7913. + {"ldwio", "t,i(s)", "t,i(s)E", 3, OP_MATCH_LDWIO, OP_MASK_IOP, 0, address_offset_overflow },
  7914. + {"mov", "d,s", "d,s,E", 2, OP_MATCH_ADD, OP_MASK_RRT|OP_MASK_ROPX|OP_MASK_ROP, NIOS2_INSN_MACRO_MOV, no_overflow },
  7915. + {"movhi", "t,u", "t,u,E", 2, OP_MATCH_ORHI, OP_MASK_IRS|OP_MASK_IOP, NIOS2_INSN_MACRO_MOVI, unsigned_immed16_overflow },
  7916. + {"movui", "t,u", "t,u,E", 2, OP_MATCH_ORI, OP_MASK_IRS|OP_MASK_IOP, NIOS2_INSN_MACRO_MOVI, unsigned_immed16_overflow },
  7917. + {"movi", "t,i", "t,i,E", 2, OP_MATCH_ADDI, OP_MASK_IRS|OP_MASK_IOP, NIOS2_INSN_MACRO_MOVI, signed_immed16_overflow },
  7918. + /* movia expands to two instructions so there is no mask or match */
  7919. + {"movia", "t,o", "t,o,E", 2, OP_MATCH_ORHI, OP_MASK_IOP, NIOS2_INSN_MACRO_MOVIA, no_overflow },
  7920. + {"mul", "d,s,t", "d,s,t,E", 3, OP_MATCH_MUL, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7921. + {"muli", "t,s,i", "t,s,i,E", 3, OP_MATCH_MULI, OP_MASK_IOP, 0, signed_immed16_overflow },
  7922. + {"mulxss", "d,s,t", "d,s,t,E", 3, OP_MATCH_MULXSS, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7923. + {"mulxsu", "d,s,t", "d,s,t,E", 3, OP_MATCH_MULXSU, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7924. + {"mulxuu", "d,s,t", "d,s,t,E", 3, OP_MATCH_MULXUU, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7925. + {"nextpc", "d", "d,E", 1, OP_MATCH_NEXTPC, OP_MASK_NEXTPC, 0, no_overflow },
  7926. + {"nop", "", "E", 0, OP_MATCH_ADD, OP_MASK, NIOS2_INSN_MACRO_MOV, no_overflow },
  7927. + {"nor", "d,s,t", "d,s,t,E", 3, OP_MATCH_NOR, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7928. + {"or", "d,s,t", "d,s,t,E", 3, OP_MATCH_OR, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7929. + {"orhi", "t,s,u", "t,s,u,E", 3, OP_MATCH_ORHI, OP_MASK_IOP, 0, unsigned_immed16_overflow },
  7930. + {"ori", "t,s,u", "t,s,u,E", 3, OP_MATCH_ORI, OP_MASK_IOP, NIOS2_INSN_ORI, unsigned_immed16_overflow },
  7931. + {"rdctl", "d,c", "d,c,E", 2, OP_MATCH_RDCTL, OP_MASK_RDCTL, 0, no_overflow },
  7932. + {"ret", "", "E", 0, OP_MATCH_RET, OP_MASK, 0, no_overflow },
  7933. + {"rol", "d,s,t", "d,s,t,E", 3, OP_MATCH_ROL, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7934. + {"roli", "d,s,j", "d,s,j,E", 3, OP_MATCH_ROLI, OP_MASK_ROLI, 0, unsigned_immed5_overflow },
  7935. + {"ror", "d,s,t", "d,s,t,E", 3, OP_MATCH_ROR, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7936. + {"sll", "d,s,t", "d,s,t,E", 3, OP_MATCH_SLL, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7937. + {"slli", "d,s,j", "d,s,j,E", 3, OP_MATCH_SLLI, OP_MASK_SLLI, 0, unsigned_immed5_overflow },
  7938. + {"sra", "d,s,t", "d,s,t,E", 3, OP_MATCH_SRA, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7939. + {"srai", "d,s,j", "d,s,j,E", 3, OP_MATCH_SRAI, OP_MASK_SRAI, 0, unsigned_immed5_overflow },
  7940. + {"srl", "d,s,t", "d,s,t,E", 3, OP_MATCH_SRL, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7941. + {"srli", "d,s,j", "d,s,j,E", 3, OP_MATCH_SRLI, OP_MASK_SRLI, 0, unsigned_immed5_overflow },
  7942. + {"stb", "t,i(s)", "t,i(s)E", 3, OP_MATCH_STB, OP_MASK_IOP, 0, address_offset_overflow },
  7943. + {"stbio", "t,i(s)", "t,i(s)E", 3, OP_MATCH_STBIO, OP_MASK_IOP, 0, address_offset_overflow },
  7944. + {"sth", "t,i(s)", "t,i(s)E", 3, OP_MATCH_STH, OP_MASK_IOP, 0, address_offset_overflow },
  7945. + {"sthio", "t,i(s)", "t,i(s)E", 3, OP_MATCH_STHIO, OP_MASK_IOP, 0, address_offset_overflow },
  7946. + {"stw", "t,i(s)", "t,i(s)E", 3, OP_MATCH_STW, OP_MASK_IOP, 0, address_offset_overflow },
  7947. + {"stwio", "t,i(s)", "t,i(s)E", 3, OP_MATCH_STWIO, OP_MASK_IOP, 0, address_offset_overflow },
  7948. + {"sub", "d,s,t", "d,s,t,E", 3, OP_MATCH_SUB, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7949. + {"sync", "", "E", 0, OP_MATCH_SYNC, OP_MASK_SYNC, 0, no_overflow },
  7950. + {"trap", "", "E", 0, OP_MATCH_TRAP, OP_MASK_TRAP, 0, no_overflow },
  7951. + {"eret", "", "E", 0, OP_MATCH_ERET, OP_MASK, 0, no_overflow },
  7952. + {"custom", "l,d,s,t", "l,d,s,t,E", 4, OP_MATCH_CUSTOM, OP_MASK_ROP, 0, custom_opcode_overflow },
  7953. + {"wrctl", "c,s", "c,s,E", 2, OP_MATCH_WRCTL, OP_MASK_WRCTL, 0, no_overflow },
  7954. + {"xor", "d,s,t", "d,s,t,E", 3, OP_MATCH_XOR, OP_MASK_ROPX | OP_MASK_ROP, 0, no_overflow },
  7955. + {"xorhi", "t,s,u", "t,s,u,E", 3, OP_MATCH_XORHI, OP_MASK_IOP, 0, unsigned_immed16_overflow },
  7956. + {"xori", "t,s,u", "t,s,u,E", 3, OP_MATCH_XORI, OP_MASK_IOP, NIOS2_INSN_XORI, unsigned_immed16_overflow }
  7957. +};
  7958. +/* *INDENT-ON* */
  7959. +
  7960. +#define NIOS2_NUM_OPCODES \
  7961. + ((sizeof nios2_builtin_opcodes) / (sizeof (nios2_builtin_opcodes[0])))
  7962. +const int bfd_nios2_num_builtin_opcodes = NIOS2_NUM_OPCODES;
  7963. +
  7964. +/* const removed from the following to allow for dynamic extensions to the
  7965. + * built-in instruction set. */
  7966. +struct nios2_opcode *nios2_opcodes =
  7967. + (struct nios2_opcode *) nios2_builtin_opcodes;
  7968. +int bfd_nios2_num_opcodes = NIOS2_NUM_OPCODES;
  7969. +#undef NIOS2_NUM_OPCODES