mips-tdep.c 286 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121
  1. /* Target-dependent code for the MIPS architecture, for GDB, the GNU Debugger.
  2. Copyright (C) 1988-2022 Free Software Foundation, Inc.
  3. Contributed by Alessandro Forin(af@cs.cmu.edu) at CMU
  4. and by Per Bothner(bothner@cs.wisc.edu) at U.Wisconsin.
  5. This file is part of GDB.
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 3 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  16. #include "defs.h"
  17. #include "frame.h"
  18. #include "inferior.h"
  19. #include "symtab.h"
  20. #include "value.h"
  21. #include "gdbcmd.h"
  22. #include "language.h"
  23. #include "gdbcore.h"
  24. #include "symfile.h"
  25. #include "objfiles.h"
  26. #include "gdbtypes.h"
  27. #include "target.h"
  28. #include "arch-utils.h"
  29. #include "regcache.h"
  30. #include "osabi.h"
  31. #include "mips-tdep.h"
  32. #include "block.h"
  33. #include "reggroups.h"
  34. #include "opcode/mips.h"
  35. #include "elf/mips.h"
  36. #include "elf-bfd.h"
  37. #include "symcat.h"
  38. #include "sim-regno.h"
  39. #include "dis-asm.h"
  40. #include "disasm.h"
  41. #include "frame-unwind.h"
  42. #include "frame-base.h"
  43. #include "trad-frame.h"
  44. #include "infcall.h"
  45. #include "remote.h"
  46. #include "target-descriptions.h"
  47. #include "dwarf2/frame.h"
  48. #include "user-regs.h"
  49. #include "valprint.h"
  50. #include "ax.h"
  51. #include "target-float.h"
  52. #include <algorithm>
  53. static struct type *mips_register_type (struct gdbarch *gdbarch, int regnum);
  54. static int mips32_instruction_has_delay_slot (struct gdbarch *gdbarch,
  55. ULONGEST inst);
  56. static int micromips_instruction_has_delay_slot (ULONGEST insn, int mustbe32);
  57. static int mips16_instruction_has_delay_slot (unsigned short inst,
  58. int mustbe32);
  59. static int mips32_insn_at_pc_has_delay_slot (struct gdbarch *gdbarch,
  60. CORE_ADDR addr);
  61. static int micromips_insn_at_pc_has_delay_slot (struct gdbarch *gdbarch,
  62. CORE_ADDR addr, int mustbe32);
  63. static int mips16_insn_at_pc_has_delay_slot (struct gdbarch *gdbarch,
  64. CORE_ADDR addr, int mustbe32);
  65. static void mips_print_float_info (struct gdbarch *, struct ui_file *,
  66. struct frame_info *, const char *);
  67. /* A useful bit in the CP0 status register (MIPS_PS_REGNUM). */
  68. /* This bit is set if we are emulating 32-bit FPRs on a 64-bit chip. */
  69. #define ST0_FR (1 << 26)
  70. /* The sizes of floating point registers. */
  71. enum
  72. {
  73. MIPS_FPU_SINGLE_REGSIZE = 4,
  74. MIPS_FPU_DOUBLE_REGSIZE = 8
  75. };
  76. enum
  77. {
  78. MIPS32_REGSIZE = 4,
  79. MIPS64_REGSIZE = 8
  80. };
  81. static const char *mips_abi_string;
  82. static const char *const mips_abi_strings[] = {
  83. "auto",
  84. "n32",
  85. "o32",
  86. "n64",
  87. "o64",
  88. "eabi32",
  89. "eabi64",
  90. NULL
  91. };
  92. /* Enum describing the different kinds of breakpoints. */
  93. enum mips_breakpoint_kind
  94. {
  95. /* 16-bit MIPS16 mode breakpoint. */
  96. MIPS_BP_KIND_MIPS16 = 2,
  97. /* 16-bit microMIPS mode breakpoint. */
  98. MIPS_BP_KIND_MICROMIPS16 = 3,
  99. /* 32-bit standard MIPS mode breakpoint. */
  100. MIPS_BP_KIND_MIPS32 = 4,
  101. /* 32-bit microMIPS mode breakpoint. */
  102. MIPS_BP_KIND_MICROMIPS32 = 5,
  103. };
  104. /* For backwards compatibility we default to MIPS16. This flag is
  105. overridden as soon as unambiguous ELF file flags tell us the
  106. compressed ISA encoding used. */
  107. static const char mips_compression_mips16[] = "mips16";
  108. static const char mips_compression_micromips[] = "micromips";
  109. static const char *const mips_compression_strings[] =
  110. {
  111. mips_compression_mips16,
  112. mips_compression_micromips,
  113. NULL
  114. };
  115. static const char *mips_compression_string = mips_compression_mips16;
  116. /* The standard register names, and all the valid aliases for them. */
  117. struct register_alias
  118. {
  119. const char *name;
  120. int regnum;
  121. };
  122. /* Aliases for o32 and most other ABIs. */
  123. const struct register_alias mips_o32_aliases[] = {
  124. { "ta0", 12 },
  125. { "ta1", 13 },
  126. { "ta2", 14 },
  127. { "ta3", 15 }
  128. };
  129. /* Aliases for n32 and n64. */
  130. const struct register_alias mips_n32_n64_aliases[] = {
  131. { "ta0", 8 },
  132. { "ta1", 9 },
  133. { "ta2", 10 },
  134. { "ta3", 11 }
  135. };
  136. /* Aliases for ABI-independent registers. */
  137. const struct register_alias mips_register_aliases[] = {
  138. /* The architecture manuals specify these ABI-independent names for
  139. the GPRs. */
  140. #define R(n) { "r" #n, n }
  141. R(0), R(1), R(2), R(3), R(4), R(5), R(6), R(7),
  142. R(8), R(9), R(10), R(11), R(12), R(13), R(14), R(15),
  143. R(16), R(17), R(18), R(19), R(20), R(21), R(22), R(23),
  144. R(24), R(25), R(26), R(27), R(28), R(29), R(30), R(31),
  145. #undef R
  146. /* k0 and k1 are sometimes called these instead (for "kernel
  147. temp"). */
  148. { "kt0", 26 },
  149. { "kt1", 27 },
  150. /* This is the traditional GDB name for the CP0 status register. */
  151. { "sr", MIPS_PS_REGNUM },
  152. /* This is the traditional GDB name for the CP0 BadVAddr register. */
  153. { "bad", MIPS_EMBED_BADVADDR_REGNUM },
  154. /* This is the traditional GDB name for the FCSR. */
  155. { "fsr", MIPS_EMBED_FP0_REGNUM + 32 }
  156. };
  157. const struct register_alias mips_numeric_register_aliases[] = {
  158. #define R(n) { #n, n }
  159. R(0), R(1), R(2), R(3), R(4), R(5), R(6), R(7),
  160. R(8), R(9), R(10), R(11), R(12), R(13), R(14), R(15),
  161. R(16), R(17), R(18), R(19), R(20), R(21), R(22), R(23),
  162. R(24), R(25), R(26), R(27), R(28), R(29), R(30), R(31),
  163. #undef R
  164. };
  165. #ifndef MIPS_DEFAULT_FPU_TYPE
  166. #define MIPS_DEFAULT_FPU_TYPE MIPS_FPU_DOUBLE
  167. #endif
  168. static int mips_fpu_type_auto = 1;
  169. static enum mips_fpu_type mips_fpu_type = MIPS_DEFAULT_FPU_TYPE;
  170. static unsigned int mips_debug = 0;
  171. /* Properties (for struct target_desc) describing the g/G packet
  172. layout. */
  173. #define PROPERTY_GP32 "internal: transfers-32bit-registers"
  174. #define PROPERTY_GP64 "internal: transfers-64bit-registers"
  175. struct target_desc *mips_tdesc_gp32;
  176. struct target_desc *mips_tdesc_gp64;
  177. /* The current set of options to be passed to the disassembler. */
  178. static char *mips_disassembler_options;
  179. /* Implicit disassembler options for individual ABIs. These tell
  180. libopcodes to use general-purpose register names corresponding
  181. to the ABI we have selected, perhaps via a `set mips abi ...'
  182. override, rather than ones inferred from the ABI set in the ELF
  183. headers of the binary file selected for debugging. */
  184. static const char mips_disassembler_options_o32[] = "gpr-names=32";
  185. static const char mips_disassembler_options_n32[] = "gpr-names=n32";
  186. static const char mips_disassembler_options_n64[] = "gpr-names=64";
  187. const struct mips_regnum *
  188. mips_regnum (struct gdbarch *gdbarch)
  189. {
  190. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  191. return tdep->regnum;
  192. }
  193. static int
  194. mips_fpa0_regnum (struct gdbarch *gdbarch)
  195. {
  196. return mips_regnum (gdbarch)->fp0 + 12;
  197. }
  198. /* Return 1 if REGNUM refers to a floating-point general register, raw
  199. or cooked. Otherwise return 0. */
  200. static int
  201. mips_float_register_p (struct gdbarch *gdbarch, int regnum)
  202. {
  203. int rawnum = regnum % gdbarch_num_regs (gdbarch);
  204. return (rawnum >= mips_regnum (gdbarch)->fp0
  205. && rawnum < mips_regnum (gdbarch)->fp0 + 32);
  206. }
  207. static bool
  208. mips_eabi (gdbarch *arch)
  209. {
  210. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
  211. return (tdep->mips_abi == MIPS_ABI_EABI32 \
  212. || tdep->mips_abi == MIPS_ABI_EABI64);
  213. }
  214. static int
  215. mips_last_fp_arg_regnum (gdbarch *arch)
  216. {
  217. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
  218. return tdep->mips_last_fp_arg_regnum;
  219. }
  220. static int
  221. mips_last_arg_regnum (gdbarch *arch)
  222. {
  223. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
  224. return tdep->mips_last_arg_regnum;
  225. }
  226. static enum mips_fpu_type
  227. mips_get_fpu_type (gdbarch *arch)
  228. {
  229. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (arch);
  230. return tdep->mips_fpu_type;
  231. }
  232. /* Return the MIPS ABI associated with GDBARCH. */
  233. enum mips_abi
  234. mips_abi (struct gdbarch *gdbarch)
  235. {
  236. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  237. return tdep->mips_abi;
  238. }
  239. int
  240. mips_isa_regsize (struct gdbarch *gdbarch)
  241. {
  242. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  243. /* If we know how big the registers are, use that size. */
  244. if (tdep->register_size_valid_p)
  245. return tdep->register_size;
  246. /* Fall back to the previous behavior. */
  247. return (gdbarch_bfd_arch_info (gdbarch)->bits_per_word
  248. / gdbarch_bfd_arch_info (gdbarch)->bits_per_byte);
  249. }
  250. /* Max saved register size. */
  251. #define MAX_MIPS_ABI_REGSIZE 8
  252. /* Return the currently configured (or set) saved register size. */
  253. unsigned int
  254. mips_abi_regsize (struct gdbarch *gdbarch)
  255. {
  256. switch (mips_abi (gdbarch))
  257. {
  258. case MIPS_ABI_EABI32:
  259. case MIPS_ABI_O32:
  260. return 4;
  261. case MIPS_ABI_N32:
  262. case MIPS_ABI_N64:
  263. case MIPS_ABI_O64:
  264. case MIPS_ABI_EABI64:
  265. return 8;
  266. case MIPS_ABI_UNKNOWN:
  267. case MIPS_ABI_LAST:
  268. default:
  269. internal_error (__FILE__, __LINE__, _("bad switch"));
  270. }
  271. }
  272. /* MIPS16/microMIPS function addresses are odd (bit 0 is set). Here
  273. are some functions to handle addresses associated with compressed
  274. code including but not limited to testing, setting, or clearing
  275. bit 0 of such addresses. */
  276. /* Return one iff compressed code is the MIPS16 instruction set. */
  277. static int
  278. is_mips16_isa (struct gdbarch *gdbarch)
  279. {
  280. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  281. return tdep->mips_isa == ISA_MIPS16;
  282. }
  283. /* Return one iff compressed code is the microMIPS instruction set. */
  284. static int
  285. is_micromips_isa (struct gdbarch *gdbarch)
  286. {
  287. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  288. return tdep->mips_isa == ISA_MICROMIPS;
  289. }
  290. /* Return one iff ADDR denotes compressed code. */
  291. static int
  292. is_compact_addr (CORE_ADDR addr)
  293. {
  294. return ((addr) & 1);
  295. }
  296. /* Return one iff ADDR denotes standard ISA code. */
  297. static int
  298. is_mips_addr (CORE_ADDR addr)
  299. {
  300. return !is_compact_addr (addr);
  301. }
  302. /* Return one iff ADDR denotes MIPS16 code. */
  303. static int
  304. is_mips16_addr (struct gdbarch *gdbarch, CORE_ADDR addr)
  305. {
  306. return is_compact_addr (addr) && is_mips16_isa (gdbarch);
  307. }
  308. /* Return one iff ADDR denotes microMIPS code. */
  309. static int
  310. is_micromips_addr (struct gdbarch *gdbarch, CORE_ADDR addr)
  311. {
  312. return is_compact_addr (addr) && is_micromips_isa (gdbarch);
  313. }
  314. /* Strip the ISA (compression) bit off from ADDR. */
  315. static CORE_ADDR
  316. unmake_compact_addr (CORE_ADDR addr)
  317. {
  318. return ((addr) & ~(CORE_ADDR) 1);
  319. }
  320. /* Add the ISA (compression) bit to ADDR. */
  321. static CORE_ADDR
  322. make_compact_addr (CORE_ADDR addr)
  323. {
  324. return ((addr) | (CORE_ADDR) 1);
  325. }
  326. /* Extern version of unmake_compact_addr; we use a separate function
  327. so that unmake_compact_addr can be inlined throughout this file. */
  328. CORE_ADDR
  329. mips_unmake_compact_addr (CORE_ADDR addr)
  330. {
  331. return unmake_compact_addr (addr);
  332. }
  333. /* Functions for setting and testing a bit in a minimal symbol that
  334. marks it as MIPS16 or microMIPS function. The MSB of the minimal
  335. symbol's "info" field is used for this purpose.
  336. gdbarch_elf_make_msymbol_special tests whether an ELF symbol is
  337. "special", i.e. refers to a MIPS16 or microMIPS function, and sets
  338. one of the "special" bits in a minimal symbol to mark it accordingly.
  339. The test checks an ELF-private flag that is valid for true function
  340. symbols only; for synthetic symbols such as for PLT stubs that have
  341. no ELF-private part at all the MIPS BFD backend arranges for this
  342. information to be carried in the asymbol's udata field instead.
  343. msymbol_is_mips16 and msymbol_is_micromips test the "special" bit
  344. in a minimal symbol. */
  345. static void
  346. mips_elf_make_msymbol_special (asymbol * sym, struct minimal_symbol *msym)
  347. {
  348. elf_symbol_type *elfsym = (elf_symbol_type *) sym;
  349. unsigned char st_other;
  350. if ((sym->flags & BSF_SYNTHETIC) == 0)
  351. st_other = elfsym->internal_elf_sym.st_other;
  352. else if ((sym->flags & BSF_FUNCTION) != 0)
  353. st_other = sym->udata.i;
  354. else
  355. return;
  356. if (ELF_ST_IS_MICROMIPS (st_other))
  357. {
  358. MSYMBOL_TARGET_FLAG_MICROMIPS (msym) = 1;
  359. SET_MSYMBOL_VALUE_ADDRESS (msym, MSYMBOL_VALUE_RAW_ADDRESS (msym) | 1);
  360. }
  361. else if (ELF_ST_IS_MIPS16 (st_other))
  362. {
  363. MSYMBOL_TARGET_FLAG_MIPS16 (msym) = 1;
  364. SET_MSYMBOL_VALUE_ADDRESS (msym, MSYMBOL_VALUE_RAW_ADDRESS (msym) | 1);
  365. }
  366. }
  367. /* Return one iff MSYM refers to standard ISA code. */
  368. static int
  369. msymbol_is_mips (struct minimal_symbol *msym)
  370. {
  371. return !(MSYMBOL_TARGET_FLAG_MIPS16 (msym)
  372. | MSYMBOL_TARGET_FLAG_MICROMIPS (msym));
  373. }
  374. /* Return one iff MSYM refers to MIPS16 code. */
  375. static int
  376. msymbol_is_mips16 (struct minimal_symbol *msym)
  377. {
  378. return MSYMBOL_TARGET_FLAG_MIPS16 (msym);
  379. }
  380. /* Return one iff MSYM refers to microMIPS code. */
  381. static int
  382. msymbol_is_micromips (struct minimal_symbol *msym)
  383. {
  384. return MSYMBOL_TARGET_FLAG_MICROMIPS (msym);
  385. }
  386. /* Set the ISA bit in the main symbol too, complementing the corresponding
  387. minimal symbol setting and reflecting the run-time value of the symbol.
  388. The need for comes from the ISA bit having been cleared as code in
  389. `_bfd_mips_elf_symbol_processing' separated it into the ELF symbol's
  390. `st_other' STO_MIPS16 or STO_MICROMIPS annotation, making the values
  391. of symbols referring to compressed code different in GDB to the values
  392. used by actual code. That in turn makes them evaluate incorrectly in
  393. expressions, producing results different to what the same expressions
  394. yield when compiled into the program being debugged. */
  395. static void
  396. mips_make_symbol_special (struct symbol *sym, struct objfile *objfile)
  397. {
  398. if (sym->aclass () == LOC_BLOCK)
  399. {
  400. /* We are in symbol reading so it is OK to cast away constness. */
  401. struct block *block = (struct block *) SYMBOL_BLOCK_VALUE (sym);
  402. CORE_ADDR compact_block_start;
  403. struct bound_minimal_symbol msym;
  404. compact_block_start = BLOCK_START (block) | 1;
  405. msym = lookup_minimal_symbol_by_pc (compact_block_start);
  406. if (msym.minsym && !msymbol_is_mips (msym.minsym))
  407. {
  408. BLOCK_START (block) = compact_block_start;
  409. }
  410. }
  411. }
  412. /* XFER a value from the big/little/left end of the register.
  413. Depending on the size of the value it might occupy the entire
  414. register or just part of it. Make an allowance for this, aligning
  415. things accordingly. */
  416. static void
  417. mips_xfer_register (struct gdbarch *gdbarch, struct regcache *regcache,
  418. int reg_num, int length,
  419. enum bfd_endian endian, gdb_byte *in,
  420. const gdb_byte *out, int buf_offset)
  421. {
  422. int reg_offset = 0;
  423. gdb_assert (reg_num >= gdbarch_num_regs (gdbarch));
  424. /* Need to transfer the left or right part of the register, based on
  425. the targets byte order. */
  426. switch (endian)
  427. {
  428. case BFD_ENDIAN_BIG:
  429. reg_offset = register_size (gdbarch, reg_num) - length;
  430. break;
  431. case BFD_ENDIAN_LITTLE:
  432. reg_offset = 0;
  433. break;
  434. case BFD_ENDIAN_UNKNOWN: /* Indicates no alignment. */
  435. reg_offset = 0;
  436. break;
  437. default:
  438. internal_error (__FILE__, __LINE__, _("bad switch"));
  439. }
  440. if (mips_debug)
  441. gdb_printf (gdb_stderr,
  442. "xfer $%d, reg offset %d, buf offset %d, length %d, ",
  443. reg_num, reg_offset, buf_offset, length);
  444. if (mips_debug && out != NULL)
  445. {
  446. int i;
  447. gdb_printf (gdb_stdlog, "out ");
  448. for (i = 0; i < length; i++)
  449. gdb_printf (gdb_stdlog, "%02x", out[buf_offset + i]);
  450. }
  451. if (in != NULL)
  452. regcache->cooked_read_part (reg_num, reg_offset, length, in + buf_offset);
  453. if (out != NULL)
  454. regcache->cooked_write_part (reg_num, reg_offset, length, out + buf_offset);
  455. if (mips_debug && in != NULL)
  456. {
  457. int i;
  458. gdb_printf (gdb_stdlog, "in ");
  459. for (i = 0; i < length; i++)
  460. gdb_printf (gdb_stdlog, "%02x", in[buf_offset + i]);
  461. }
  462. if (mips_debug)
  463. gdb_printf (gdb_stdlog, "\n");
  464. }
  465. /* Determine if a MIPS3 or later cpu is operating in MIPS{1,2} FPU
  466. compatiblity mode. A return value of 1 means that we have
  467. physical 64-bit registers, but should treat them as 32-bit registers. */
  468. static int
  469. mips2_fp_compat (struct frame_info *frame)
  470. {
  471. struct gdbarch *gdbarch = get_frame_arch (frame);
  472. /* MIPS1 and MIPS2 have only 32 bit FPRs, and the FR bit is not
  473. meaningful. */
  474. if (register_size (gdbarch, mips_regnum (gdbarch)->fp0) == 4)
  475. return 0;
  476. #if 0
  477. /* FIXME drow 2002-03-10: This is disabled until we can do it consistently,
  478. in all the places we deal with FP registers. PR gdb/413. */
  479. /* Otherwise check the FR bit in the status register - it controls
  480. the FP compatiblity mode. If it is clear we are in compatibility
  481. mode. */
  482. if ((get_frame_register_unsigned (frame, MIPS_PS_REGNUM) & ST0_FR) == 0)
  483. return 1;
  484. #endif
  485. return 0;
  486. }
  487. #define VM_MIN_ADDRESS (CORE_ADDR)0x400000
  488. static CORE_ADDR heuristic_proc_start (struct gdbarch *, CORE_ADDR);
  489. /* The list of available "set mips " and "show mips " commands. */
  490. static struct cmd_list_element *setmipscmdlist = NULL;
  491. static struct cmd_list_element *showmipscmdlist = NULL;
  492. /* Integer registers 0 thru 31 are handled explicitly by
  493. mips_register_name(). Processor specific registers 32 and above
  494. are listed in the following tables. */
  495. enum
  496. { NUM_MIPS_PROCESSOR_REGS = (90 - 32) };
  497. /* Generic MIPS. */
  498. static const char * const mips_generic_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
  499. "sr", "lo", "hi", "bad", "cause", "pc",
  500. "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
  501. "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
  502. "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
  503. "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
  504. "fsr", "fir",
  505. };
  506. /* Names of tx39 registers. */
  507. static const char * const mips_tx39_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
  508. "sr", "lo", "hi", "bad", "cause", "pc",
  509. "", "", "", "", "", "", "", "",
  510. "", "", "", "", "", "", "", "",
  511. "", "", "", "", "", "", "", "",
  512. "", "", "", "", "", "", "", "",
  513. "", "", "", "",
  514. "", "", "", "", "", "", "", "",
  515. "", "", "config", "cache", "debug", "depc", "epc",
  516. };
  517. /* Names of registers with Linux kernels. */
  518. static const char * const mips_linux_reg_names[NUM_MIPS_PROCESSOR_REGS] = {
  519. "sr", "lo", "hi", "bad", "cause", "pc",
  520. "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
  521. "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
  522. "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
  523. "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
  524. "fsr", "fir"
  525. };
  526. /* Return the name of the register corresponding to REGNO. */
  527. static const char *
  528. mips_register_name (struct gdbarch *gdbarch, int regno)
  529. {
  530. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  531. /* GPR names for all ABIs other than n32/n64. */
  532. static const char *mips_gpr_names[] = {
  533. "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
  534. "t0", "t1", "t2", "t3", "t4", "t5", "t6", "t7",
  535. "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
  536. "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra",
  537. };
  538. /* GPR names for n32 and n64 ABIs. */
  539. static const char *mips_n32_n64_gpr_names[] = {
  540. "zero", "at", "v0", "v1", "a0", "a1", "a2", "a3",
  541. "a4", "a5", "a6", "a7", "t0", "t1", "t2", "t3",
  542. "s0", "s1", "s2", "s3", "s4", "s5", "s6", "s7",
  543. "t8", "t9", "k0", "k1", "gp", "sp", "s8", "ra"
  544. };
  545. enum mips_abi abi = mips_abi (gdbarch);
  546. /* Map [gdbarch_num_regs .. 2*gdbarch_num_regs) onto the raw registers,
  547. but then don't make the raw register names visible. This (upper)
  548. range of user visible register numbers are the pseudo-registers.
  549. This approach was adopted accommodate the following scenario:
  550. It is possible to debug a 64-bit device using a 32-bit
  551. programming model. In such instances, the raw registers are
  552. configured to be 64-bits wide, while the pseudo registers are
  553. configured to be 32-bits wide. The registers that the user
  554. sees - the pseudo registers - match the users expectations
  555. given the programming model being used. */
  556. int rawnum = regno % gdbarch_num_regs (gdbarch);
  557. if (regno < gdbarch_num_regs (gdbarch))
  558. return "";
  559. /* The MIPS integer registers are always mapped from 0 to 31. The
  560. names of the registers (which reflects the conventions regarding
  561. register use) vary depending on the ABI. */
  562. if (0 <= rawnum && rawnum < 32)
  563. {
  564. if (abi == MIPS_ABI_N32 || abi == MIPS_ABI_N64)
  565. return mips_n32_n64_gpr_names[rawnum];
  566. else
  567. return mips_gpr_names[rawnum];
  568. }
  569. else if (tdesc_has_registers (gdbarch_target_desc (gdbarch)))
  570. return tdesc_register_name (gdbarch, rawnum);
  571. else if (32 <= rawnum && rawnum < gdbarch_num_regs (gdbarch))
  572. {
  573. gdb_assert (rawnum - 32 < NUM_MIPS_PROCESSOR_REGS);
  574. if (tdep->mips_processor_reg_names[rawnum - 32])
  575. return tdep->mips_processor_reg_names[rawnum - 32];
  576. return "";
  577. }
  578. else
  579. internal_error (__FILE__, __LINE__,
  580. _("mips_register_name: bad register number %d"), rawnum);
  581. }
  582. /* Return the groups that a MIPS register can be categorised into. */
  583. static int
  584. mips_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
  585. const struct reggroup *reggroup)
  586. {
  587. int vector_p;
  588. int float_p;
  589. int raw_p;
  590. int rawnum = regnum % gdbarch_num_regs (gdbarch);
  591. int pseudo = regnum / gdbarch_num_regs (gdbarch);
  592. if (reggroup == all_reggroup)
  593. return pseudo;
  594. vector_p = register_type (gdbarch, regnum)->is_vector ();
  595. float_p = register_type (gdbarch, regnum)->code () == TYPE_CODE_FLT;
  596. /* FIXME: cagney/2003-04-13: Can't yet use gdbarch_num_regs
  597. (gdbarch), as not all architectures are multi-arch. */
  598. raw_p = rawnum < gdbarch_num_regs (gdbarch);
  599. if (gdbarch_register_name (gdbarch, regnum) == NULL
  600. || gdbarch_register_name (gdbarch, regnum)[0] == '\0')
  601. return 0;
  602. if (reggroup == float_reggroup)
  603. return float_p && pseudo;
  604. if (reggroup == vector_reggroup)
  605. return vector_p && pseudo;
  606. if (reggroup == general_reggroup)
  607. return (!vector_p && !float_p) && pseudo;
  608. /* Save the pseudo registers. Need to make certain that any code
  609. extracting register values from a saved register cache also uses
  610. pseudo registers. */
  611. if (reggroup == save_reggroup)
  612. return raw_p && pseudo;
  613. /* Restore the same pseudo register. */
  614. if (reggroup == restore_reggroup)
  615. return raw_p && pseudo;
  616. return 0;
  617. }
  618. /* Return the groups that a MIPS register can be categorised into.
  619. This version is only used if we have a target description which
  620. describes real registers (and their groups). */
  621. static int
  622. mips_tdesc_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
  623. const struct reggroup *reggroup)
  624. {
  625. int rawnum = regnum % gdbarch_num_regs (gdbarch);
  626. int pseudo = regnum / gdbarch_num_regs (gdbarch);
  627. int ret;
  628. /* Only save, restore, and display the pseudo registers. Need to
  629. make certain that any code extracting register values from a
  630. saved register cache also uses pseudo registers.
  631. Note: saving and restoring the pseudo registers is slightly
  632. strange; if we have 64 bits, we should save and restore all
  633. 64 bits. But this is hard and has little benefit. */
  634. if (!pseudo)
  635. return 0;
  636. ret = tdesc_register_in_reggroup_p (gdbarch, rawnum, reggroup);
  637. if (ret != -1)
  638. return ret;
  639. return mips_register_reggroup_p (gdbarch, regnum, reggroup);
  640. }
  641. /* Map the symbol table registers which live in the range [1 *
  642. gdbarch_num_regs .. 2 * gdbarch_num_regs) back onto the corresponding raw
  643. registers. Take care of alignment and size problems. */
  644. static enum register_status
  645. mips_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
  646. int cookednum, gdb_byte *buf)
  647. {
  648. int rawnum = cookednum % gdbarch_num_regs (gdbarch);
  649. gdb_assert (cookednum >= gdbarch_num_regs (gdbarch)
  650. && cookednum < 2 * gdbarch_num_regs (gdbarch));
  651. if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum))
  652. return regcache->raw_read (rawnum, buf);
  653. else if (register_size (gdbarch, rawnum) >
  654. register_size (gdbarch, cookednum))
  655. {
  656. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  657. if (tdep->mips64_transfers_32bit_regs_p)
  658. return regcache->raw_read_part (rawnum, 0, 4, buf);
  659. else
  660. {
  661. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  662. LONGEST regval;
  663. enum register_status status;
  664. status = regcache->raw_read (rawnum, &regval);
  665. if (status == REG_VALID)
  666. store_signed_integer (buf, 4, byte_order, regval);
  667. return status;
  668. }
  669. }
  670. else
  671. internal_error (__FILE__, __LINE__, _("bad register size"));
  672. }
  673. static void
  674. mips_pseudo_register_write (struct gdbarch *gdbarch,
  675. struct regcache *regcache, int cookednum,
  676. const gdb_byte *buf)
  677. {
  678. int rawnum = cookednum % gdbarch_num_regs (gdbarch);
  679. gdb_assert (cookednum >= gdbarch_num_regs (gdbarch)
  680. && cookednum < 2 * gdbarch_num_regs (gdbarch));
  681. if (register_size (gdbarch, rawnum) == register_size (gdbarch, cookednum))
  682. regcache->raw_write (rawnum, buf);
  683. else if (register_size (gdbarch, rawnum) >
  684. register_size (gdbarch, cookednum))
  685. {
  686. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  687. if (tdep->mips64_transfers_32bit_regs_p)
  688. regcache->raw_write_part (rawnum, 0, 4, buf);
  689. else
  690. {
  691. /* Sign extend the shortened version of the register prior
  692. to placing it in the raw register. This is required for
  693. some mips64 parts in order to avoid unpredictable behavior. */
  694. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  695. LONGEST regval = extract_signed_integer (buf, 4, byte_order);
  696. regcache_raw_write_signed (regcache, rawnum, regval);
  697. }
  698. }
  699. else
  700. internal_error (__FILE__, __LINE__, _("bad register size"));
  701. }
  702. static int
  703. mips_ax_pseudo_register_collect (struct gdbarch *gdbarch,
  704. struct agent_expr *ax, int reg)
  705. {
  706. int rawnum = reg % gdbarch_num_regs (gdbarch);
  707. gdb_assert (reg >= gdbarch_num_regs (gdbarch)
  708. && reg < 2 * gdbarch_num_regs (gdbarch));
  709. ax_reg_mask (ax, rawnum);
  710. return 0;
  711. }
  712. static int
  713. mips_ax_pseudo_register_push_stack (struct gdbarch *gdbarch,
  714. struct agent_expr *ax, int reg)
  715. {
  716. int rawnum = reg % gdbarch_num_regs (gdbarch);
  717. gdb_assert (reg >= gdbarch_num_regs (gdbarch)
  718. && reg < 2 * gdbarch_num_regs (gdbarch));
  719. if (register_size (gdbarch, rawnum) >= register_size (gdbarch, reg))
  720. {
  721. ax_reg (ax, rawnum);
  722. if (register_size (gdbarch, rawnum) > register_size (gdbarch, reg))
  723. {
  724. mips_gdbarch_tdep *tdep
  725. = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  726. if (!tdep->mips64_transfers_32bit_regs_p
  727. || gdbarch_byte_order (gdbarch) != BFD_ENDIAN_BIG)
  728. {
  729. ax_const_l (ax, 32);
  730. ax_simple (ax, aop_lsh);
  731. }
  732. ax_const_l (ax, 32);
  733. ax_simple (ax, aop_rsh_signed);
  734. }
  735. }
  736. else
  737. internal_error (__FILE__, __LINE__, _("bad register size"));
  738. return 0;
  739. }
  740. /* Table to translate 3-bit register field to actual register number. */
  741. static const signed char mips_reg3_to_reg[8] = { 16, 17, 2, 3, 4, 5, 6, 7 };
  742. /* Heuristic_proc_start may hunt through the text section for a long
  743. time across a 2400 baud serial line. Allows the user to limit this
  744. search. */
  745. static int heuristic_fence_post = 0;
  746. /* Number of bytes of storage in the actual machine representation for
  747. register N. NOTE: This defines the pseudo register type so need to
  748. rebuild the architecture vector. */
  749. static bool mips64_transfers_32bit_regs_p = false;
  750. static void
  751. set_mips64_transfers_32bit_regs (const char *args, int from_tty,
  752. struct cmd_list_element *c)
  753. {
  754. struct gdbarch_info info;
  755. /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
  756. instead of relying on globals. Doing that would let generic code
  757. handle the search for this specific architecture. */
  758. if (!gdbarch_update_p (info))
  759. {
  760. mips64_transfers_32bit_regs_p = 0;
  761. error (_("32-bit compatibility mode not supported"));
  762. }
  763. }
  764. /* Convert to/from a register and the corresponding memory value. */
  765. /* This predicate tests for the case of an 8 byte floating point
  766. value that is being transferred to or from a pair of floating point
  767. registers each of which are (or are considered to be) only 4 bytes
  768. wide. */
  769. static int
  770. mips_convert_register_float_case_p (struct gdbarch *gdbarch, int regnum,
  771. struct type *type)
  772. {
  773. return (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
  774. && register_size (gdbarch, regnum) == 4
  775. && mips_float_register_p (gdbarch, regnum)
  776. && type->code () == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8);
  777. }
  778. /* This predicate tests for the case of a value of less than 8
  779. bytes in width that is being transfered to or from an 8 byte
  780. general purpose register. */
  781. static int
  782. mips_convert_register_gpreg_case_p (struct gdbarch *gdbarch, int regnum,
  783. struct type *type)
  784. {
  785. int num_regs = gdbarch_num_regs (gdbarch);
  786. return (register_size (gdbarch, regnum) == 8
  787. && regnum % num_regs > 0 && regnum % num_regs < 32
  788. && TYPE_LENGTH (type) < 8);
  789. }
  790. static int
  791. mips_convert_register_p (struct gdbarch *gdbarch,
  792. int regnum, struct type *type)
  793. {
  794. return (mips_convert_register_float_case_p (gdbarch, regnum, type)
  795. || mips_convert_register_gpreg_case_p (gdbarch, regnum, type));
  796. }
  797. static int
  798. mips_register_to_value (struct frame_info *frame, int regnum,
  799. struct type *type, gdb_byte *to,
  800. int *optimizedp, int *unavailablep)
  801. {
  802. struct gdbarch *gdbarch = get_frame_arch (frame);
  803. if (mips_convert_register_float_case_p (gdbarch, regnum, type))
  804. {
  805. get_frame_register (frame, regnum + 0, to + 4);
  806. get_frame_register (frame, regnum + 1, to + 0);
  807. if (!get_frame_register_bytes (frame, regnum + 0, 0, {to + 4, 4},
  808. optimizedp, unavailablep))
  809. return 0;
  810. if (!get_frame_register_bytes (frame, regnum + 1, 0, {to + 0, 4},
  811. optimizedp, unavailablep))
  812. return 0;
  813. *optimizedp = *unavailablep = 0;
  814. return 1;
  815. }
  816. else if (mips_convert_register_gpreg_case_p (gdbarch, regnum, type))
  817. {
  818. size_t len = TYPE_LENGTH (type);
  819. CORE_ADDR offset;
  820. offset = gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG ? 8 - len : 0;
  821. if (!get_frame_register_bytes (frame, regnum, offset, {to, len},
  822. optimizedp, unavailablep))
  823. return 0;
  824. *optimizedp = *unavailablep = 0;
  825. return 1;
  826. }
  827. else
  828. {
  829. internal_error (__FILE__, __LINE__,
  830. _("mips_register_to_value: unrecognized case"));
  831. }
  832. }
  833. static void
  834. mips_value_to_register (struct frame_info *frame, int regnum,
  835. struct type *type, const gdb_byte *from)
  836. {
  837. struct gdbarch *gdbarch = get_frame_arch (frame);
  838. if (mips_convert_register_float_case_p (gdbarch, regnum, type))
  839. {
  840. put_frame_register (frame, regnum + 0, from + 4);
  841. put_frame_register (frame, regnum + 1, from + 0);
  842. }
  843. else if (mips_convert_register_gpreg_case_p (gdbarch, regnum, type))
  844. {
  845. gdb_byte fill[8];
  846. size_t len = TYPE_LENGTH (type);
  847. /* Sign extend values, irrespective of type, that are stored to
  848. a 64-bit general purpose register. (32-bit unsigned values
  849. are stored as signed quantities within a 64-bit register.
  850. When performing an operation, in compiled code, that combines
  851. a 32-bit unsigned value with a signed 64-bit value, a type
  852. conversion is first performed that zeroes out the high 32 bits.) */
  853. if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  854. {
  855. if (from[0] & 0x80)
  856. store_signed_integer (fill, 8, BFD_ENDIAN_BIG, -1);
  857. else
  858. store_signed_integer (fill, 8, BFD_ENDIAN_BIG, 0);
  859. put_frame_register_bytes (frame, regnum, 0, {fill, 8 - len});
  860. put_frame_register_bytes (frame, regnum, 8 - len, {from, len});
  861. }
  862. else
  863. {
  864. if (from[len-1] & 0x80)
  865. store_signed_integer (fill, 8, BFD_ENDIAN_LITTLE, -1);
  866. else
  867. store_signed_integer (fill, 8, BFD_ENDIAN_LITTLE, 0);
  868. put_frame_register_bytes (frame, regnum, 0, {from, len});
  869. put_frame_register_bytes (frame, regnum, len, {fill, 8 - len});
  870. }
  871. }
  872. else
  873. {
  874. internal_error (__FILE__, __LINE__,
  875. _("mips_value_to_register: unrecognized case"));
  876. }
  877. }
  878. /* Return the GDB type object for the "standard" data type of data in
  879. register REG. */
  880. static struct type *
  881. mips_register_type (struct gdbarch *gdbarch, int regnum)
  882. {
  883. gdb_assert (regnum >= 0 && regnum < 2 * gdbarch_num_regs (gdbarch));
  884. if (mips_float_register_p (gdbarch, regnum))
  885. {
  886. /* The floating-point registers raw, or cooked, always match
  887. mips_isa_regsize(), and also map 1:1, byte for byte. */
  888. if (mips_isa_regsize (gdbarch) == 4)
  889. return builtin_type (gdbarch)->builtin_float;
  890. else
  891. return builtin_type (gdbarch)->builtin_double;
  892. }
  893. else if (regnum < gdbarch_num_regs (gdbarch))
  894. {
  895. /* The raw or ISA registers. These are all sized according to
  896. the ISA regsize. */
  897. if (mips_isa_regsize (gdbarch) == 4)
  898. return builtin_type (gdbarch)->builtin_int32;
  899. else
  900. return builtin_type (gdbarch)->builtin_int64;
  901. }
  902. else
  903. {
  904. int rawnum = regnum - gdbarch_num_regs (gdbarch);
  905. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  906. /* The cooked or ABI registers. These are sized according to
  907. the ABI (with a few complications). */
  908. if (rawnum == mips_regnum (gdbarch)->fp_control_status
  909. || rawnum == mips_regnum (gdbarch)->fp_implementation_revision)
  910. return builtin_type (gdbarch)->builtin_int32;
  911. else if (gdbarch_osabi (gdbarch) != GDB_OSABI_LINUX
  912. && rawnum >= MIPS_FIRST_EMBED_REGNUM
  913. && rawnum <= MIPS_LAST_EMBED_REGNUM)
  914. /* The pseudo/cooked view of the embedded registers is always
  915. 32-bit. The raw view is handled below. */
  916. return builtin_type (gdbarch)->builtin_int32;
  917. else if (tdep->mips64_transfers_32bit_regs_p)
  918. /* The target, while possibly using a 64-bit register buffer,
  919. is only transfering 32-bits of each integer register.
  920. Reflect this in the cooked/pseudo (ABI) register value. */
  921. return builtin_type (gdbarch)->builtin_int32;
  922. else if (mips_abi_regsize (gdbarch) == 4)
  923. /* The ABI is restricted to 32-bit registers (the ISA could be
  924. 32- or 64-bit). */
  925. return builtin_type (gdbarch)->builtin_int32;
  926. else
  927. /* 64-bit ABI. */
  928. return builtin_type (gdbarch)->builtin_int64;
  929. }
  930. }
  931. /* Return the GDB type for the pseudo register REGNUM, which is the
  932. ABI-level view. This function is only called if there is a target
  933. description which includes registers, so we know precisely the
  934. types of hardware registers. */
  935. static struct type *
  936. mips_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
  937. {
  938. const int num_regs = gdbarch_num_regs (gdbarch);
  939. int rawnum = regnum % num_regs;
  940. struct type *rawtype;
  941. gdb_assert (regnum >= num_regs && regnum < 2 * num_regs);
  942. /* Absent registers are still absent. */
  943. rawtype = gdbarch_register_type (gdbarch, rawnum);
  944. if (TYPE_LENGTH (rawtype) == 0)
  945. return rawtype;
  946. /* Present the floating point registers however the hardware did;
  947. do not try to convert between FPU layouts. */
  948. if (mips_float_register_p (gdbarch, rawnum))
  949. return rawtype;
  950. /* Floating-point control registers are always 32-bit even though for
  951. backwards compatibility reasons 64-bit targets will transfer them
  952. as 64-bit quantities even if using XML descriptions. */
  953. if (rawnum == mips_regnum (gdbarch)->fp_control_status
  954. || rawnum == mips_regnum (gdbarch)->fp_implementation_revision)
  955. return builtin_type (gdbarch)->builtin_int32;
  956. /* Use pointer types for registers if we can. For n32 we can not,
  957. since we do not have a 64-bit pointer type. */
  958. if (mips_abi_regsize (gdbarch)
  959. == TYPE_LENGTH (builtin_type (gdbarch)->builtin_data_ptr))
  960. {
  961. if (rawnum == MIPS_SP_REGNUM
  962. || rawnum == mips_regnum (gdbarch)->badvaddr)
  963. return builtin_type (gdbarch)->builtin_data_ptr;
  964. else if (rawnum == mips_regnum (gdbarch)->pc)
  965. return builtin_type (gdbarch)->builtin_func_ptr;
  966. }
  967. if (mips_abi_regsize (gdbarch) == 4 && TYPE_LENGTH (rawtype) == 8
  968. && ((rawnum >= MIPS_ZERO_REGNUM && rawnum <= MIPS_PS_REGNUM)
  969. || rawnum == mips_regnum (gdbarch)->lo
  970. || rawnum == mips_regnum (gdbarch)->hi
  971. || rawnum == mips_regnum (gdbarch)->badvaddr
  972. || rawnum == mips_regnum (gdbarch)->cause
  973. || rawnum == mips_regnum (gdbarch)->pc
  974. || (mips_regnum (gdbarch)->dspacc != -1
  975. && rawnum >= mips_regnum (gdbarch)->dspacc
  976. && rawnum < mips_regnum (gdbarch)->dspacc + 6)))
  977. return builtin_type (gdbarch)->builtin_int32;
  978. /* The pseudo/cooked view of embedded registers is always
  979. 32-bit, even if the target transfers 64-bit values for them.
  980. New targets relying on XML descriptions should only transfer
  981. the necessary 32 bits, but older versions of GDB expected 64,
  982. so allow the target to provide 64 bits without interfering
  983. with the displayed type. */
  984. if (gdbarch_osabi (gdbarch) != GDB_OSABI_LINUX
  985. && rawnum >= MIPS_FIRST_EMBED_REGNUM
  986. && rawnum <= MIPS_LAST_EMBED_REGNUM)
  987. return builtin_type (gdbarch)->builtin_int32;
  988. /* For all other registers, pass through the hardware type. */
  989. return rawtype;
  990. }
  991. /* Should the upper word of 64-bit addresses be zeroed? */
  992. static enum auto_boolean mask_address_var = AUTO_BOOLEAN_AUTO;
  993. static int
  994. mips_mask_address_p (mips_gdbarch_tdep *tdep)
  995. {
  996. switch (mask_address_var)
  997. {
  998. case AUTO_BOOLEAN_TRUE:
  999. return 1;
  1000. case AUTO_BOOLEAN_FALSE:
  1001. return 0;
  1002. break;
  1003. case AUTO_BOOLEAN_AUTO:
  1004. return tdep->default_mask_address_p;
  1005. default:
  1006. internal_error (__FILE__, __LINE__,
  1007. _("mips_mask_address_p: bad switch"));
  1008. return -1;
  1009. }
  1010. }
  1011. static void
  1012. show_mask_address (struct ui_file *file, int from_tty,
  1013. struct cmd_list_element *c, const char *value)
  1014. {
  1015. mips_gdbarch_tdep *tdep
  1016. = (mips_gdbarch_tdep *) gdbarch_tdep (target_gdbarch ());
  1017. deprecated_show_value_hack (file, from_tty, c, value);
  1018. switch (mask_address_var)
  1019. {
  1020. case AUTO_BOOLEAN_TRUE:
  1021. gdb_printf (file, "The 32 bit mips address mask is enabled\n");
  1022. break;
  1023. case AUTO_BOOLEAN_FALSE:
  1024. gdb_printf (file, "The 32 bit mips address mask is disabled\n");
  1025. break;
  1026. case AUTO_BOOLEAN_AUTO:
  1027. gdb_printf
  1028. (file,
  1029. "The 32 bit address mask is set automatically. Currently %s\n",
  1030. mips_mask_address_p (tdep) ? "enabled" : "disabled");
  1031. break;
  1032. default:
  1033. internal_error (__FILE__, __LINE__, _("show_mask_address: bad switch"));
  1034. break;
  1035. }
  1036. }
  1037. /* Tell if the program counter value in MEMADDR is in a standard ISA
  1038. function. */
  1039. int
  1040. mips_pc_is_mips (CORE_ADDR memaddr)
  1041. {
  1042. struct bound_minimal_symbol sym;
  1043. /* Flags indicating that this is a MIPS16 or microMIPS function is
  1044. stored by elfread.c in the high bit of the info field. Use this
  1045. to decide if the function is standard MIPS. Otherwise if bit 0
  1046. of the address is clear, then this is a standard MIPS function. */
  1047. sym = lookup_minimal_symbol_by_pc (make_compact_addr (memaddr));
  1048. if (sym.minsym)
  1049. return msymbol_is_mips (sym.minsym);
  1050. else
  1051. return is_mips_addr (memaddr);
  1052. }
  1053. /* Tell if the program counter value in MEMADDR is in a MIPS16 function. */
  1054. int
  1055. mips_pc_is_mips16 (struct gdbarch *gdbarch, CORE_ADDR memaddr)
  1056. {
  1057. struct bound_minimal_symbol sym;
  1058. /* A flag indicating that this is a MIPS16 function is stored by
  1059. elfread.c in the high bit of the info field. Use this to decide
  1060. if the function is MIPS16. Otherwise if bit 0 of the address is
  1061. set, then ELF file flags will tell if this is a MIPS16 function. */
  1062. sym = lookup_minimal_symbol_by_pc (make_compact_addr (memaddr));
  1063. if (sym.minsym)
  1064. return msymbol_is_mips16 (sym.minsym);
  1065. else
  1066. return is_mips16_addr (gdbarch, memaddr);
  1067. }
  1068. /* Tell if the program counter value in MEMADDR is in a microMIPS function. */
  1069. int
  1070. mips_pc_is_micromips (struct gdbarch *gdbarch, CORE_ADDR memaddr)
  1071. {
  1072. struct bound_minimal_symbol sym;
  1073. /* A flag indicating that this is a microMIPS function is stored by
  1074. elfread.c in the high bit of the info field. Use this to decide
  1075. if the function is microMIPS. Otherwise if bit 0 of the address
  1076. is set, then ELF file flags will tell if this is a microMIPS
  1077. function. */
  1078. sym = lookup_minimal_symbol_by_pc (make_compact_addr (memaddr));
  1079. if (sym.minsym)
  1080. return msymbol_is_micromips (sym.minsym);
  1081. else
  1082. return is_micromips_addr (gdbarch, memaddr);
  1083. }
  1084. /* Tell the ISA type of the function the program counter value in MEMADDR
  1085. is in. */
  1086. static enum mips_isa
  1087. mips_pc_isa (struct gdbarch *gdbarch, CORE_ADDR memaddr)
  1088. {
  1089. struct bound_minimal_symbol sym;
  1090. /* A flag indicating that this is a MIPS16 or a microMIPS function
  1091. is stored by elfread.c in the high bit of the info field. Use
  1092. this to decide if the function is MIPS16 or microMIPS or normal
  1093. MIPS. Otherwise if bit 0 of the address is set, then ELF file
  1094. flags will tell if this is a MIPS16 or a microMIPS function. */
  1095. sym = lookup_minimal_symbol_by_pc (make_compact_addr (memaddr));
  1096. if (sym.minsym)
  1097. {
  1098. if (msymbol_is_micromips (sym.minsym))
  1099. return ISA_MICROMIPS;
  1100. else if (msymbol_is_mips16 (sym.minsym))
  1101. return ISA_MIPS16;
  1102. else
  1103. return ISA_MIPS;
  1104. }
  1105. else
  1106. {
  1107. if (is_mips_addr (memaddr))
  1108. return ISA_MIPS;
  1109. else if (is_micromips_addr (gdbarch, memaddr))
  1110. return ISA_MICROMIPS;
  1111. else
  1112. return ISA_MIPS16;
  1113. }
  1114. }
  1115. /* Set the ISA bit correctly in the PC, used by DWARF-2 machinery.
  1116. The need for comes from the ISA bit having been cleared, making
  1117. addresses in FDE, range records, etc. referring to compressed code
  1118. different to those in line information, the symbol table and finally
  1119. the PC register. That in turn confuses many operations. */
  1120. static CORE_ADDR
  1121. mips_adjust_dwarf2_addr (CORE_ADDR pc)
  1122. {
  1123. pc = unmake_compact_addr (pc);
  1124. return mips_pc_is_mips (pc) ? pc : make_compact_addr (pc);
  1125. }
  1126. /* Recalculate the line record requested so that the resulting PC has
  1127. the ISA bit set correctly, used by DWARF-2 machinery. The need for
  1128. this adjustment comes from some records associated with compressed
  1129. code having the ISA bit cleared, most notably at function prologue
  1130. ends. The ISA bit is in this context retrieved from the minimal
  1131. symbol covering the address requested, which in turn has been
  1132. constructed from the binary's symbol table rather than DWARF-2
  1133. information. The correct setting of the ISA bit is required for
  1134. breakpoint addresses to correctly match against the stop PC.
  1135. As line entries can specify relative address adjustments we need to
  1136. keep track of the absolute value of the last line address recorded
  1137. in line information, so that we can calculate the actual address to
  1138. apply the ISA bit adjustment to. We use PC for this tracking and
  1139. keep the original address there.
  1140. As such relative address adjustments can be odd within compressed
  1141. code we need to keep track of the last line address with the ISA
  1142. bit adjustment applied too, as the original address may or may not
  1143. have had the ISA bit set. We use ADJ_PC for this tracking and keep
  1144. the adjusted address there.
  1145. For relative address adjustments we then use these variables to
  1146. calculate the address intended by line information, which will be
  1147. PC-relative, and return an updated adjustment carrying ISA bit
  1148. information, which will be ADJ_PC-relative. For absolute address
  1149. adjustments we just return the same address that we store in ADJ_PC
  1150. too.
  1151. As the first line entry can be relative to an implied address value
  1152. of 0 we need to have the initial address set up that we store in PC
  1153. and ADJ_PC. This is arranged with a call from `dwarf_decode_lines_1'
  1154. that sets PC to 0 and ADJ_PC accordingly, usually 0 as well. */
  1155. static CORE_ADDR
  1156. mips_adjust_dwarf2_line (CORE_ADDR addr, int rel)
  1157. {
  1158. static CORE_ADDR adj_pc;
  1159. static CORE_ADDR pc;
  1160. CORE_ADDR isa_pc;
  1161. pc = rel ? pc + addr : addr;
  1162. isa_pc = mips_adjust_dwarf2_addr (pc);
  1163. addr = rel ? isa_pc - adj_pc : isa_pc;
  1164. adj_pc = isa_pc;
  1165. return addr;
  1166. }
  1167. /* Various MIPS16 thunk (aka stub or trampoline) names. */
  1168. static const char mips_str_mips16_call_stub[] = "__mips16_call_stub_";
  1169. static const char mips_str_mips16_ret_stub[] = "__mips16_ret_";
  1170. static const char mips_str_call_fp_stub[] = "__call_stub_fp_";
  1171. static const char mips_str_call_stub[] = "__call_stub_";
  1172. static const char mips_str_fn_stub[] = "__fn_stub_";
  1173. /* This is used as a PIC thunk prefix. */
  1174. static const char mips_str_pic[] = ".pic.";
  1175. /* Return non-zero if the PC is inside a call thunk (aka stub or
  1176. trampoline) that should be treated as a temporary frame. */
  1177. static int
  1178. mips_in_frame_stub (CORE_ADDR pc)
  1179. {
  1180. CORE_ADDR start_addr;
  1181. const char *name;
  1182. /* Find the starting address of the function containing the PC. */
  1183. if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
  1184. return 0;
  1185. /* If the PC is in __mips16_call_stub_*, this is a call/return stub. */
  1186. if (startswith (name, mips_str_mips16_call_stub))
  1187. return 1;
  1188. /* If the PC is in __call_stub_*, this is a call/return or a call stub. */
  1189. if (startswith (name, mips_str_call_stub))
  1190. return 1;
  1191. /* If the PC is in __fn_stub_*, this is a call stub. */
  1192. if (startswith (name, mips_str_fn_stub))
  1193. return 1;
  1194. return 0; /* Not a stub. */
  1195. }
  1196. /* MIPS believes that the PC has a sign extended value. Perhaps the
  1197. all registers should be sign extended for simplicity? */
  1198. static CORE_ADDR
  1199. mips_read_pc (readable_regcache *regcache)
  1200. {
  1201. int regnum = gdbarch_pc_regnum (regcache->arch ());
  1202. LONGEST pc;
  1203. regcache->cooked_read (regnum, &pc);
  1204. return pc;
  1205. }
  1206. static CORE_ADDR
  1207. mips_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
  1208. {
  1209. CORE_ADDR pc;
  1210. pc = frame_unwind_register_signed (next_frame, gdbarch_pc_regnum (gdbarch));
  1211. /* macro/2012-04-20: This hack skips over MIPS16 call thunks as
  1212. intermediate frames. In this case we can get the caller's address
  1213. from $ra, or if $ra contains an address within a thunk as well, then
  1214. it must be in the return path of __mips16_call_stub_{s,d}{f,c}_{0..10}
  1215. and thus the caller's address is in $s2. */
  1216. if (frame_relative_level (next_frame) >= 0 && mips_in_frame_stub (pc))
  1217. {
  1218. pc = frame_unwind_register_signed
  1219. (next_frame, gdbarch_num_regs (gdbarch) + MIPS_RA_REGNUM);
  1220. if (mips_in_frame_stub (pc))
  1221. pc = frame_unwind_register_signed
  1222. (next_frame, gdbarch_num_regs (gdbarch) + MIPS_S2_REGNUM);
  1223. }
  1224. return pc;
  1225. }
  1226. static CORE_ADDR
  1227. mips_unwind_sp (struct gdbarch *gdbarch, struct frame_info *next_frame)
  1228. {
  1229. return frame_unwind_register_signed
  1230. (next_frame, gdbarch_num_regs (gdbarch) + MIPS_SP_REGNUM);
  1231. }
  1232. /* Assuming THIS_FRAME is a dummy, return the frame ID of that
  1233. dummy frame. The frame ID's base needs to match the TOS value
  1234. saved by save_dummy_frame_tos(), and the PC match the dummy frame's
  1235. breakpoint. */
  1236. static struct frame_id
  1237. mips_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
  1238. {
  1239. return frame_id_build
  1240. (get_frame_register_signed (this_frame,
  1241. gdbarch_num_regs (gdbarch)
  1242. + MIPS_SP_REGNUM),
  1243. get_frame_pc (this_frame));
  1244. }
  1245. /* Implement the "write_pc" gdbarch method. */
  1246. void
  1247. mips_write_pc (struct regcache *regcache, CORE_ADDR pc)
  1248. {
  1249. int regnum = gdbarch_pc_regnum (regcache->arch ());
  1250. regcache_cooked_write_unsigned (regcache, regnum, pc);
  1251. }
  1252. /* Fetch and return instruction from the specified location. Handle
  1253. MIPS16/microMIPS as appropriate. */
  1254. static ULONGEST
  1255. mips_fetch_instruction (struct gdbarch *gdbarch,
  1256. enum mips_isa isa, CORE_ADDR addr, int *errp)
  1257. {
  1258. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1259. gdb_byte buf[MIPS_INSN32_SIZE];
  1260. int instlen;
  1261. int err;
  1262. switch (isa)
  1263. {
  1264. case ISA_MICROMIPS:
  1265. case ISA_MIPS16:
  1266. instlen = MIPS_INSN16_SIZE;
  1267. addr = unmake_compact_addr (addr);
  1268. break;
  1269. case ISA_MIPS:
  1270. instlen = MIPS_INSN32_SIZE;
  1271. break;
  1272. default:
  1273. internal_error (__FILE__, __LINE__, _("invalid ISA"));
  1274. break;
  1275. }
  1276. err = target_read_memory (addr, buf, instlen);
  1277. if (errp != NULL)
  1278. *errp = err;
  1279. if (err != 0)
  1280. {
  1281. if (errp == NULL)
  1282. memory_error (TARGET_XFER_E_IO, addr);
  1283. return 0;
  1284. }
  1285. return extract_unsigned_integer (buf, instlen, byte_order);
  1286. }
  1287. /* These are the fields of 32 bit mips instructions. */
  1288. #define mips32_op(x) (x >> 26)
  1289. #define itype_op(x) (x >> 26)
  1290. #define itype_rs(x) ((x >> 21) & 0x1f)
  1291. #define itype_rt(x) ((x >> 16) & 0x1f)
  1292. #define itype_immediate(x) (x & 0xffff)
  1293. #define jtype_op(x) (x >> 26)
  1294. #define jtype_target(x) (x & 0x03ffffff)
  1295. #define rtype_op(x) (x >> 26)
  1296. #define rtype_rs(x) ((x >> 21) & 0x1f)
  1297. #define rtype_rt(x) ((x >> 16) & 0x1f)
  1298. #define rtype_rd(x) ((x >> 11) & 0x1f)
  1299. #define rtype_shamt(x) ((x >> 6) & 0x1f)
  1300. #define rtype_funct(x) (x & 0x3f)
  1301. /* MicroMIPS instruction fields. */
  1302. #define micromips_op(x) ((x) >> 10)
  1303. /* 16-bit/32-bit-high-part instruction formats, B and S refer to the lowest
  1304. bit and the size respectively of the field extracted. */
  1305. #define b0s4_imm(x) ((x) & 0xf)
  1306. #define b0s5_imm(x) ((x) & 0x1f)
  1307. #define b0s5_reg(x) ((x) & 0x1f)
  1308. #define b0s7_imm(x) ((x) & 0x7f)
  1309. #define b0s10_imm(x) ((x) & 0x3ff)
  1310. #define b1s4_imm(x) (((x) >> 1) & 0xf)
  1311. #define b1s9_imm(x) (((x) >> 1) & 0x1ff)
  1312. #define b2s3_cc(x) (((x) >> 2) & 0x7)
  1313. #define b4s2_regl(x) (((x) >> 4) & 0x3)
  1314. #define b5s5_op(x) (((x) >> 5) & 0x1f)
  1315. #define b5s5_reg(x) (((x) >> 5) & 0x1f)
  1316. #define b6s4_op(x) (((x) >> 6) & 0xf)
  1317. #define b7s3_reg(x) (((x) >> 7) & 0x7)
  1318. /* 32-bit instruction formats, B and S refer to the lowest bit and the size
  1319. respectively of the field extracted. */
  1320. #define b0s6_op(x) ((x) & 0x3f)
  1321. #define b0s11_op(x) ((x) & 0x7ff)
  1322. #define b0s12_imm(x) ((x) & 0xfff)
  1323. #define b0s16_imm(x) ((x) & 0xffff)
  1324. #define b0s26_imm(x) ((x) & 0x3ffffff)
  1325. #define b6s10_ext(x) (((x) >> 6) & 0x3ff)
  1326. #define b11s5_reg(x) (((x) >> 11) & 0x1f)
  1327. #define b12s4_op(x) (((x) >> 12) & 0xf)
  1328. /* Return the size in bytes of the instruction INSN encoded in the ISA
  1329. instruction set. */
  1330. static int
  1331. mips_insn_size (enum mips_isa isa, ULONGEST insn)
  1332. {
  1333. switch (isa)
  1334. {
  1335. case ISA_MICROMIPS:
  1336. if ((micromips_op (insn) & 0x4) == 0x4
  1337. || (micromips_op (insn) & 0x7) == 0x0)
  1338. return 2 * MIPS_INSN16_SIZE;
  1339. else
  1340. return MIPS_INSN16_SIZE;
  1341. case ISA_MIPS16:
  1342. if ((insn & 0xf800) == 0xf000)
  1343. return 2 * MIPS_INSN16_SIZE;
  1344. else
  1345. return MIPS_INSN16_SIZE;
  1346. case ISA_MIPS:
  1347. return MIPS_INSN32_SIZE;
  1348. }
  1349. internal_error (__FILE__, __LINE__, _("invalid ISA"));
  1350. }
  1351. static LONGEST
  1352. mips32_relative_offset (ULONGEST inst)
  1353. {
  1354. return ((itype_immediate (inst) ^ 0x8000) - 0x8000) << 2;
  1355. }
  1356. /* Determine the address of the next instruction executed after the INST
  1357. floating condition branch instruction at PC. COUNT specifies the
  1358. number of the floating condition bits tested by the branch. */
  1359. static CORE_ADDR
  1360. mips32_bc1_pc (struct gdbarch *gdbarch, struct regcache *regcache,
  1361. ULONGEST inst, CORE_ADDR pc, int count)
  1362. {
  1363. int fcsr = mips_regnum (gdbarch)->fp_control_status;
  1364. int cnum = (itype_rt (inst) >> 2) & (count - 1);
  1365. int tf = itype_rt (inst) & 1;
  1366. int mask = (1 << count) - 1;
  1367. ULONGEST fcs;
  1368. int cond;
  1369. if (fcsr == -1)
  1370. /* No way to handle; it'll most likely trap anyway. */
  1371. return pc;
  1372. fcs = regcache_raw_get_unsigned (regcache, fcsr);
  1373. cond = ((fcs >> 24) & 0xfe) | ((fcs >> 23) & 0x01);
  1374. if (((cond >> cnum) & mask) != mask * !tf)
  1375. pc += mips32_relative_offset (inst);
  1376. else
  1377. pc += 4;
  1378. return pc;
  1379. }
  1380. /* Return nonzero if the gdbarch is an Octeon series. */
  1381. static int
  1382. is_octeon (struct gdbarch *gdbarch)
  1383. {
  1384. const struct bfd_arch_info *info = gdbarch_bfd_arch_info (gdbarch);
  1385. return (info->mach == bfd_mach_mips_octeon
  1386. || info->mach == bfd_mach_mips_octeonp
  1387. || info->mach == bfd_mach_mips_octeon2);
  1388. }
  1389. /* Return true if the OP represents the Octeon's BBIT instruction. */
  1390. static int
  1391. is_octeon_bbit_op (int op, struct gdbarch *gdbarch)
  1392. {
  1393. if (!is_octeon (gdbarch))
  1394. return 0;
  1395. /* BBIT0 is encoded as LWC2: 110 010. */
  1396. /* BBIT032 is encoded as LDC2: 110 110. */
  1397. /* BBIT1 is encoded as SWC2: 111 010. */
  1398. /* BBIT132 is encoded as SDC2: 111 110. */
  1399. if (op == 50 || op == 54 || op == 58 || op == 62)
  1400. return 1;
  1401. return 0;
  1402. }
  1403. /* Determine where to set a single step breakpoint while considering
  1404. branch prediction. */
  1405. static CORE_ADDR
  1406. mips32_next_pc (struct regcache *regcache, CORE_ADDR pc)
  1407. {
  1408. struct gdbarch *gdbarch = regcache->arch ();
  1409. unsigned long inst;
  1410. int op;
  1411. inst = mips_fetch_instruction (gdbarch, ISA_MIPS, pc, NULL);
  1412. op = itype_op (inst);
  1413. if ((inst & 0xe0000000) != 0) /* Not a special, jump or branch
  1414. instruction. */
  1415. {
  1416. if (op >> 2 == 5)
  1417. /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */
  1418. {
  1419. switch (op & 0x03)
  1420. {
  1421. case 0: /* BEQL */
  1422. goto equal_branch;
  1423. case 1: /* BNEL */
  1424. goto neq_branch;
  1425. case 2: /* BLEZL */
  1426. goto less_branch;
  1427. case 3: /* BGTZL */
  1428. goto greater_branch;
  1429. default:
  1430. pc += 4;
  1431. }
  1432. }
  1433. else if (op == 17 && itype_rs (inst) == 8)
  1434. /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */
  1435. pc = mips32_bc1_pc (gdbarch, regcache, inst, pc + 4, 1);
  1436. else if (op == 17 && itype_rs (inst) == 9
  1437. && (itype_rt (inst) & 2) == 0)
  1438. /* BC1ANY2F, BC1ANY2T: 010001 01001 xxx0x */
  1439. pc = mips32_bc1_pc (gdbarch, regcache, inst, pc + 4, 2);
  1440. else if (op == 17 && itype_rs (inst) == 10
  1441. && (itype_rt (inst) & 2) == 0)
  1442. /* BC1ANY4F, BC1ANY4T: 010001 01010 xxx0x */
  1443. pc = mips32_bc1_pc (gdbarch, regcache, inst, pc + 4, 4);
  1444. else if (op == 29)
  1445. /* JALX: 011101 */
  1446. /* The new PC will be alternate mode. */
  1447. {
  1448. unsigned long reg;
  1449. reg = jtype_target (inst) << 2;
  1450. /* Add 1 to indicate 16-bit mode -- invert ISA mode. */
  1451. pc = ((pc + 4) & ~(CORE_ADDR) 0x0fffffff) + reg + 1;
  1452. }
  1453. else if (is_octeon_bbit_op (op, gdbarch))
  1454. {
  1455. int bit, branch_if;
  1456. branch_if = op == 58 || op == 62;
  1457. bit = itype_rt (inst);
  1458. /* Take into account the *32 instructions. */
  1459. if (op == 54 || op == 62)
  1460. bit += 32;
  1461. if (((regcache_raw_get_signed (regcache,
  1462. itype_rs (inst)) >> bit) & 1)
  1463. == branch_if)
  1464. pc += mips32_relative_offset (inst) + 4;
  1465. else
  1466. pc += 8; /* After the delay slot. */
  1467. }
  1468. else
  1469. pc += 4; /* Not a branch, next instruction is easy. */
  1470. }
  1471. else
  1472. { /* This gets way messy. */
  1473. /* Further subdivide into SPECIAL, REGIMM and other. */
  1474. switch (op & 0x07) /* Extract bits 28,27,26. */
  1475. {
  1476. case 0: /* SPECIAL */
  1477. op = rtype_funct (inst);
  1478. switch (op)
  1479. {
  1480. case 8: /* JR */
  1481. case 9: /* JALR */
  1482. /* Set PC to that address. */
  1483. pc = regcache_raw_get_signed (regcache, rtype_rs (inst));
  1484. break;
  1485. case 12: /* SYSCALL */
  1486. {
  1487. mips_gdbarch_tdep *tdep
  1488. = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  1489. if (tdep->syscall_next_pc != NULL)
  1490. pc = tdep->syscall_next_pc (get_current_frame ());
  1491. else
  1492. pc += 4;
  1493. }
  1494. break;
  1495. default:
  1496. pc += 4;
  1497. }
  1498. break; /* end SPECIAL */
  1499. case 1: /* REGIMM */
  1500. {
  1501. op = itype_rt (inst); /* branch condition */
  1502. switch (op)
  1503. {
  1504. case 0: /* BLTZ */
  1505. case 2: /* BLTZL */
  1506. case 16: /* BLTZAL */
  1507. case 18: /* BLTZALL */
  1508. less_branch:
  1509. if (regcache_raw_get_signed (regcache, itype_rs (inst)) < 0)
  1510. pc += mips32_relative_offset (inst) + 4;
  1511. else
  1512. pc += 8; /* after the delay slot */
  1513. break;
  1514. case 1: /* BGEZ */
  1515. case 3: /* BGEZL */
  1516. case 17: /* BGEZAL */
  1517. case 19: /* BGEZALL */
  1518. if (regcache_raw_get_signed (regcache, itype_rs (inst)) >= 0)
  1519. pc += mips32_relative_offset (inst) + 4;
  1520. else
  1521. pc += 8; /* after the delay slot */
  1522. break;
  1523. case 0x1c: /* BPOSGE32 */
  1524. case 0x1e: /* BPOSGE64 */
  1525. pc += 4;
  1526. if (itype_rs (inst) == 0)
  1527. {
  1528. unsigned int pos = (op & 2) ? 64 : 32;
  1529. int dspctl = mips_regnum (gdbarch)->dspctl;
  1530. if (dspctl == -1)
  1531. /* No way to handle; it'll most likely trap anyway. */
  1532. break;
  1533. if ((regcache_raw_get_unsigned (regcache,
  1534. dspctl) & 0x7f) >= pos)
  1535. pc += mips32_relative_offset (inst);
  1536. else
  1537. pc += 4;
  1538. }
  1539. break;
  1540. /* All of the other instructions in the REGIMM category */
  1541. default:
  1542. pc += 4;
  1543. }
  1544. }
  1545. break; /* end REGIMM */
  1546. case 2: /* J */
  1547. case 3: /* JAL */
  1548. {
  1549. unsigned long reg;
  1550. reg = jtype_target (inst) << 2;
  1551. /* Upper four bits get never changed... */
  1552. pc = reg + ((pc + 4) & ~(CORE_ADDR) 0x0fffffff);
  1553. }
  1554. break;
  1555. case 4: /* BEQ, BEQL */
  1556. equal_branch:
  1557. if (regcache_raw_get_signed (regcache, itype_rs (inst)) ==
  1558. regcache_raw_get_signed (regcache, itype_rt (inst)))
  1559. pc += mips32_relative_offset (inst) + 4;
  1560. else
  1561. pc += 8;
  1562. break;
  1563. case 5: /* BNE, BNEL */
  1564. neq_branch:
  1565. if (regcache_raw_get_signed (regcache, itype_rs (inst)) !=
  1566. regcache_raw_get_signed (regcache, itype_rt (inst)))
  1567. pc += mips32_relative_offset (inst) + 4;
  1568. else
  1569. pc += 8;
  1570. break;
  1571. case 6: /* BLEZ, BLEZL */
  1572. if (regcache_raw_get_signed (regcache, itype_rs (inst)) <= 0)
  1573. pc += mips32_relative_offset (inst) + 4;
  1574. else
  1575. pc += 8;
  1576. break;
  1577. case 7:
  1578. default:
  1579. greater_branch: /* BGTZ, BGTZL */
  1580. if (regcache_raw_get_signed (regcache, itype_rs (inst)) > 0)
  1581. pc += mips32_relative_offset (inst) + 4;
  1582. else
  1583. pc += 8;
  1584. break;
  1585. } /* switch */
  1586. } /* else */
  1587. return pc;
  1588. } /* mips32_next_pc */
  1589. /* Extract the 7-bit signed immediate offset from the microMIPS instruction
  1590. INSN. */
  1591. static LONGEST
  1592. micromips_relative_offset7 (ULONGEST insn)
  1593. {
  1594. return ((b0s7_imm (insn) ^ 0x40) - 0x40) << 1;
  1595. }
  1596. /* Extract the 10-bit signed immediate offset from the microMIPS instruction
  1597. INSN. */
  1598. static LONGEST
  1599. micromips_relative_offset10 (ULONGEST insn)
  1600. {
  1601. return ((b0s10_imm (insn) ^ 0x200) - 0x200) << 1;
  1602. }
  1603. /* Extract the 16-bit signed immediate offset from the microMIPS instruction
  1604. INSN. */
  1605. static LONGEST
  1606. micromips_relative_offset16 (ULONGEST insn)
  1607. {
  1608. return ((b0s16_imm (insn) ^ 0x8000) - 0x8000) << 1;
  1609. }
  1610. /* Return the size in bytes of the microMIPS instruction at the address PC. */
  1611. static int
  1612. micromips_pc_insn_size (struct gdbarch *gdbarch, CORE_ADDR pc)
  1613. {
  1614. ULONGEST insn;
  1615. insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, NULL);
  1616. return mips_insn_size (ISA_MICROMIPS, insn);
  1617. }
  1618. /* Calculate the address of the next microMIPS instruction to execute
  1619. after the INSN coprocessor 1 conditional branch instruction at the
  1620. address PC. COUNT denotes the number of coprocessor condition bits
  1621. examined by the branch. */
  1622. static CORE_ADDR
  1623. micromips_bc1_pc (struct gdbarch *gdbarch, struct regcache *regcache,
  1624. ULONGEST insn, CORE_ADDR pc, int count)
  1625. {
  1626. int fcsr = mips_regnum (gdbarch)->fp_control_status;
  1627. int cnum = b2s3_cc (insn >> 16) & (count - 1);
  1628. int tf = b5s5_op (insn >> 16) & 1;
  1629. int mask = (1 << count) - 1;
  1630. ULONGEST fcs;
  1631. int cond;
  1632. if (fcsr == -1)
  1633. /* No way to handle; it'll most likely trap anyway. */
  1634. return pc;
  1635. fcs = regcache_raw_get_unsigned (regcache, fcsr);
  1636. cond = ((fcs >> 24) & 0xfe) | ((fcs >> 23) & 0x01);
  1637. if (((cond >> cnum) & mask) != mask * !tf)
  1638. pc += micromips_relative_offset16 (insn);
  1639. else
  1640. pc += micromips_pc_insn_size (gdbarch, pc);
  1641. return pc;
  1642. }
  1643. /* Calculate the address of the next microMIPS instruction to execute
  1644. after the instruction at the address PC. */
  1645. static CORE_ADDR
  1646. micromips_next_pc (struct regcache *regcache, CORE_ADDR pc)
  1647. {
  1648. struct gdbarch *gdbarch = regcache->arch ();
  1649. ULONGEST insn;
  1650. insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, NULL);
  1651. pc += MIPS_INSN16_SIZE;
  1652. switch (mips_insn_size (ISA_MICROMIPS, insn))
  1653. {
  1654. /* 32-bit instructions. */
  1655. case 2 * MIPS_INSN16_SIZE:
  1656. insn <<= 16;
  1657. insn |= mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, NULL);
  1658. pc += MIPS_INSN16_SIZE;
  1659. switch (micromips_op (insn >> 16))
  1660. {
  1661. case 0x00: /* POOL32A: bits 000000 */
  1662. switch (b0s6_op (insn))
  1663. {
  1664. case 0x3c: /* POOL32Axf: bits 000000 ... 111100 */
  1665. switch (b6s10_ext (insn))
  1666. {
  1667. case 0x3c: /* JALR: 000000 0000111100 111100 */
  1668. case 0x7c: /* JALR.HB: 000000 0001111100 111100 */
  1669. case 0x13c: /* JALRS: 000000 0100111100 111100 */
  1670. case 0x17c: /* JALRS.HB: 000000 0101111100 111100 */
  1671. pc = regcache_raw_get_signed (regcache,
  1672. b0s5_reg (insn >> 16));
  1673. break;
  1674. case 0x22d: /* SYSCALL: 000000 1000101101 111100 */
  1675. {
  1676. mips_gdbarch_tdep *tdep
  1677. = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  1678. if (tdep->syscall_next_pc != NULL)
  1679. pc = tdep->syscall_next_pc (get_current_frame ());
  1680. }
  1681. break;
  1682. }
  1683. break;
  1684. }
  1685. break;
  1686. case 0x10: /* POOL32I: bits 010000 */
  1687. switch (b5s5_op (insn >> 16))
  1688. {
  1689. case 0x00: /* BLTZ: bits 010000 00000 */
  1690. case 0x01: /* BLTZAL: bits 010000 00001 */
  1691. case 0x11: /* BLTZALS: bits 010000 10001 */
  1692. if (regcache_raw_get_signed (regcache,
  1693. b0s5_reg (insn >> 16)) < 0)
  1694. pc += micromips_relative_offset16 (insn);
  1695. else
  1696. pc += micromips_pc_insn_size (gdbarch, pc);
  1697. break;
  1698. case 0x02: /* BGEZ: bits 010000 00010 */
  1699. case 0x03: /* BGEZAL: bits 010000 00011 */
  1700. case 0x13: /* BGEZALS: bits 010000 10011 */
  1701. if (regcache_raw_get_signed (regcache,
  1702. b0s5_reg (insn >> 16)) >= 0)
  1703. pc += micromips_relative_offset16 (insn);
  1704. else
  1705. pc += micromips_pc_insn_size (gdbarch, pc);
  1706. break;
  1707. case 0x04: /* BLEZ: bits 010000 00100 */
  1708. if (regcache_raw_get_signed (regcache,
  1709. b0s5_reg (insn >> 16)) <= 0)
  1710. pc += micromips_relative_offset16 (insn);
  1711. else
  1712. pc += micromips_pc_insn_size (gdbarch, pc);
  1713. break;
  1714. case 0x05: /* BNEZC: bits 010000 00101 */
  1715. if (regcache_raw_get_signed (regcache,
  1716. b0s5_reg (insn >> 16)) != 0)
  1717. pc += micromips_relative_offset16 (insn);
  1718. break;
  1719. case 0x06: /* BGTZ: bits 010000 00110 */
  1720. if (regcache_raw_get_signed (regcache,
  1721. b0s5_reg (insn >> 16)) > 0)
  1722. pc += micromips_relative_offset16 (insn);
  1723. else
  1724. pc += micromips_pc_insn_size (gdbarch, pc);
  1725. break;
  1726. case 0x07: /* BEQZC: bits 010000 00111 */
  1727. if (regcache_raw_get_signed (regcache,
  1728. b0s5_reg (insn >> 16)) == 0)
  1729. pc += micromips_relative_offset16 (insn);
  1730. break;
  1731. case 0x14: /* BC2F: bits 010000 10100 xxx00 */
  1732. case 0x15: /* BC2T: bits 010000 10101 xxx00 */
  1733. if (((insn >> 16) & 0x3) == 0x0)
  1734. /* BC2F, BC2T: don't know how to handle these. */
  1735. break;
  1736. break;
  1737. case 0x1a: /* BPOSGE64: bits 010000 11010 */
  1738. case 0x1b: /* BPOSGE32: bits 010000 11011 */
  1739. {
  1740. unsigned int pos = (b5s5_op (insn >> 16) & 1) ? 32 : 64;
  1741. int dspctl = mips_regnum (gdbarch)->dspctl;
  1742. if (dspctl == -1)
  1743. /* No way to handle; it'll most likely trap anyway. */
  1744. break;
  1745. if ((regcache_raw_get_unsigned (regcache,
  1746. dspctl) & 0x7f) >= pos)
  1747. pc += micromips_relative_offset16 (insn);
  1748. else
  1749. pc += micromips_pc_insn_size (gdbarch, pc);
  1750. }
  1751. break;
  1752. case 0x1c: /* BC1F: bits 010000 11100 xxx00 */
  1753. /* BC1ANY2F: bits 010000 11100 xxx01 */
  1754. case 0x1d: /* BC1T: bits 010000 11101 xxx00 */
  1755. /* BC1ANY2T: bits 010000 11101 xxx01 */
  1756. if (((insn >> 16) & 0x2) == 0x0)
  1757. pc = micromips_bc1_pc (gdbarch, regcache, insn, pc,
  1758. ((insn >> 16) & 0x1) + 1);
  1759. break;
  1760. case 0x1e: /* BC1ANY4F: bits 010000 11110 xxx01 */
  1761. case 0x1f: /* BC1ANY4T: bits 010000 11111 xxx01 */
  1762. if (((insn >> 16) & 0x3) == 0x1)
  1763. pc = micromips_bc1_pc (gdbarch, regcache, insn, pc, 4);
  1764. break;
  1765. }
  1766. break;
  1767. case 0x1d: /* JALS: bits 011101 */
  1768. case 0x35: /* J: bits 110101 */
  1769. case 0x3d: /* JAL: bits 111101 */
  1770. pc = ((pc | 0x7fffffe) ^ 0x7fffffe) | (b0s26_imm (insn) << 1);
  1771. break;
  1772. case 0x25: /* BEQ: bits 100101 */
  1773. if (regcache_raw_get_signed (regcache, b0s5_reg (insn >> 16))
  1774. == regcache_raw_get_signed (regcache, b5s5_reg (insn >> 16)))
  1775. pc += micromips_relative_offset16 (insn);
  1776. else
  1777. pc += micromips_pc_insn_size (gdbarch, pc);
  1778. break;
  1779. case 0x2d: /* BNE: bits 101101 */
  1780. if (regcache_raw_get_signed (regcache, b0s5_reg (insn >> 16))
  1781. != regcache_raw_get_signed (regcache, b5s5_reg (insn >> 16)))
  1782. pc += micromips_relative_offset16 (insn);
  1783. else
  1784. pc += micromips_pc_insn_size (gdbarch, pc);
  1785. break;
  1786. case 0x3c: /* JALX: bits 111100 */
  1787. pc = ((pc | 0xfffffff) ^ 0xfffffff) | (b0s26_imm (insn) << 2);
  1788. break;
  1789. }
  1790. break;
  1791. /* 16-bit instructions. */
  1792. case MIPS_INSN16_SIZE:
  1793. switch (micromips_op (insn))
  1794. {
  1795. case 0x11: /* POOL16C: bits 010001 */
  1796. if ((b5s5_op (insn) & 0x1c) == 0xc)
  1797. /* JR16, JRC, JALR16, JALRS16: 010001 011xx */
  1798. pc = regcache_raw_get_signed (regcache, b0s5_reg (insn));
  1799. else if (b5s5_op (insn) == 0x18)
  1800. /* JRADDIUSP: bits 010001 11000 */
  1801. pc = regcache_raw_get_signed (regcache, MIPS_RA_REGNUM);
  1802. break;
  1803. case 0x23: /* BEQZ16: bits 100011 */
  1804. {
  1805. int rs = mips_reg3_to_reg[b7s3_reg (insn)];
  1806. if (regcache_raw_get_signed (regcache, rs) == 0)
  1807. pc += micromips_relative_offset7 (insn);
  1808. else
  1809. pc += micromips_pc_insn_size (gdbarch, pc);
  1810. }
  1811. break;
  1812. case 0x2b: /* BNEZ16: bits 101011 */
  1813. {
  1814. int rs = mips_reg3_to_reg[b7s3_reg (insn)];
  1815. if (regcache_raw_get_signed (regcache, rs) != 0)
  1816. pc += micromips_relative_offset7 (insn);
  1817. else
  1818. pc += micromips_pc_insn_size (gdbarch, pc);
  1819. }
  1820. break;
  1821. case 0x33: /* B16: bits 110011 */
  1822. pc += micromips_relative_offset10 (insn);
  1823. break;
  1824. }
  1825. break;
  1826. }
  1827. return pc;
  1828. }
  1829. /* Decoding the next place to set a breakpoint is irregular for the
  1830. mips 16 variant, but fortunately, there fewer instructions. We have
  1831. to cope ith extensions for 16 bit instructions and a pair of actual
  1832. 32 bit instructions. We dont want to set a single step instruction
  1833. on the extend instruction either. */
  1834. /* Lots of mips16 instruction formats */
  1835. /* Predicting jumps requires itype,ritype,i8type
  1836. and their extensions extItype,extritype,extI8type. */
  1837. enum mips16_inst_fmts
  1838. {
  1839. itype, /* 0 immediate 5,10 */
  1840. ritype, /* 1 5,3,8 */
  1841. rrtype, /* 2 5,3,3,5 */
  1842. rritype, /* 3 5,3,3,5 */
  1843. rrrtype, /* 4 5,3,3,3,2 */
  1844. rriatype, /* 5 5,3,3,1,4 */
  1845. shifttype, /* 6 5,3,3,3,2 */
  1846. i8type, /* 7 5,3,8 */
  1847. i8movtype, /* 8 5,3,3,5 */
  1848. i8mov32rtype, /* 9 5,3,5,3 */
  1849. i64type, /* 10 5,3,8 */
  1850. ri64type, /* 11 5,3,3,5 */
  1851. jalxtype, /* 12 5,1,5,5,16 - a 32 bit instruction */
  1852. exiItype, /* 13 5,6,5,5,1,1,1,1,1,1,5 */
  1853. extRitype, /* 14 5,6,5,5,3,1,1,1,5 */
  1854. extRRItype, /* 15 5,5,5,5,3,3,5 */
  1855. extRRIAtype, /* 16 5,7,4,5,3,3,1,4 */
  1856. EXTshifttype, /* 17 5,5,1,1,1,1,1,1,5,3,3,1,1,1,2 */
  1857. extI8type, /* 18 5,6,5,5,3,1,1,1,5 */
  1858. extI64type, /* 19 5,6,5,5,3,1,1,1,5 */
  1859. extRi64type, /* 20 5,6,5,5,3,3,5 */
  1860. extshift64type /* 21 5,5,1,1,1,1,1,1,5,1,1,1,3,5 */
  1861. };
  1862. /* I am heaping all the fields of the formats into one structure and
  1863. then, only the fields which are involved in instruction extension. */
  1864. struct upk_mips16
  1865. {
  1866. CORE_ADDR offset;
  1867. unsigned int regx; /* Function in i8 type. */
  1868. unsigned int regy;
  1869. };
  1870. /* The EXT-I, EXT-ri nad EXT-I8 instructions all have the same format
  1871. for the bits which make up the immediate extension. */
  1872. static CORE_ADDR
  1873. extended_offset (unsigned int extension)
  1874. {
  1875. CORE_ADDR value;
  1876. value = (extension >> 16) & 0x1f; /* Extract 15:11. */
  1877. value = value << 6;
  1878. value |= (extension >> 21) & 0x3f; /* Extract 10:5. */
  1879. value = value << 5;
  1880. value |= extension & 0x1f; /* Extract 4:0. */
  1881. return value;
  1882. }
  1883. /* Only call this function if you know that this is an extendable
  1884. instruction. It won't malfunction, but why make excess remote memory
  1885. references? If the immediate operands get sign extended or something,
  1886. do it after the extension is performed. */
  1887. /* FIXME: Every one of these cases needs to worry about sign extension
  1888. when the offset is to be used in relative addressing. */
  1889. static unsigned int
  1890. fetch_mips_16 (struct gdbarch *gdbarch, CORE_ADDR pc)
  1891. {
  1892. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1893. gdb_byte buf[8];
  1894. pc = unmake_compact_addr (pc); /* Clear the low order bit. */
  1895. target_read_memory (pc, buf, 2);
  1896. return extract_unsigned_integer (buf, 2, byte_order);
  1897. }
  1898. static void
  1899. unpack_mips16 (struct gdbarch *gdbarch, CORE_ADDR pc,
  1900. unsigned int extension,
  1901. unsigned int inst,
  1902. enum mips16_inst_fmts insn_format, struct upk_mips16 *upk)
  1903. {
  1904. CORE_ADDR offset;
  1905. int regx;
  1906. int regy;
  1907. switch (insn_format)
  1908. {
  1909. case itype:
  1910. {
  1911. CORE_ADDR value;
  1912. if (extension)
  1913. {
  1914. value = extended_offset ((extension << 16) | inst);
  1915. value = (value ^ 0x8000) - 0x8000; /* Sign-extend. */
  1916. }
  1917. else
  1918. {
  1919. value = inst & 0x7ff;
  1920. value = (value ^ 0x400) - 0x400; /* Sign-extend. */
  1921. }
  1922. offset = value;
  1923. regx = -1;
  1924. regy = -1;
  1925. }
  1926. break;
  1927. case ritype:
  1928. case i8type:
  1929. { /* A register identifier and an offset. */
  1930. /* Most of the fields are the same as I type but the
  1931. immediate value is of a different length. */
  1932. CORE_ADDR value;
  1933. if (extension)
  1934. {
  1935. value = extended_offset ((extension << 16) | inst);
  1936. value = (value ^ 0x8000) - 0x8000; /* Sign-extend. */
  1937. }
  1938. else
  1939. {
  1940. value = inst & 0xff; /* 8 bits */
  1941. value = (value ^ 0x80) - 0x80; /* Sign-extend. */
  1942. }
  1943. offset = value;
  1944. regx = (inst >> 8) & 0x07; /* i8 funct */
  1945. regy = -1;
  1946. break;
  1947. }
  1948. case jalxtype:
  1949. {
  1950. unsigned long value;
  1951. unsigned int nexthalf;
  1952. value = ((inst & 0x1f) << 5) | ((inst >> 5) & 0x1f);
  1953. value = value << 16;
  1954. nexthalf = mips_fetch_instruction (gdbarch, ISA_MIPS16, pc + 2, NULL);
  1955. /* Low bit still set. */
  1956. value |= nexthalf;
  1957. offset = value;
  1958. regx = -1;
  1959. regy = -1;
  1960. break;
  1961. }
  1962. default:
  1963. internal_error (__FILE__, __LINE__, _("bad switch"));
  1964. }
  1965. upk->offset = offset;
  1966. upk->regx = regx;
  1967. upk->regy = regy;
  1968. }
  1969. /* Calculate the destination of a branch whose 16-bit opcode word is at PC,
  1970. and having a signed 16-bit OFFSET. */
  1971. static CORE_ADDR
  1972. add_offset_16 (CORE_ADDR pc, int offset)
  1973. {
  1974. return pc + (offset << 1) + 2;
  1975. }
  1976. static CORE_ADDR
  1977. extended_mips16_next_pc (regcache *regcache, CORE_ADDR pc,
  1978. unsigned int extension, unsigned int insn)
  1979. {
  1980. struct gdbarch *gdbarch = regcache->arch ();
  1981. int op = (insn >> 11);
  1982. switch (op)
  1983. {
  1984. case 2: /* Branch */
  1985. {
  1986. struct upk_mips16 upk;
  1987. unpack_mips16 (gdbarch, pc, extension, insn, itype, &upk);
  1988. pc = add_offset_16 (pc, upk.offset);
  1989. break;
  1990. }
  1991. case 3: /* JAL , JALX - Watch out, these are 32 bit
  1992. instructions. */
  1993. {
  1994. struct upk_mips16 upk;
  1995. unpack_mips16 (gdbarch, pc, extension, insn, jalxtype, &upk);
  1996. pc = ((pc + 2) & (~(CORE_ADDR) 0x0fffffff)) | (upk.offset << 2);
  1997. if ((insn >> 10) & 0x01) /* Exchange mode */
  1998. pc = pc & ~0x01; /* Clear low bit, indicate 32 bit mode. */
  1999. else
  2000. pc |= 0x01;
  2001. break;
  2002. }
  2003. case 4: /* beqz */
  2004. {
  2005. struct upk_mips16 upk;
  2006. int reg;
  2007. unpack_mips16 (gdbarch, pc, extension, insn, ritype, &upk);
  2008. reg = regcache_raw_get_signed (regcache, mips_reg3_to_reg[upk.regx]);
  2009. if (reg == 0)
  2010. pc = add_offset_16 (pc, upk.offset);
  2011. else
  2012. pc += 2;
  2013. break;
  2014. }
  2015. case 5: /* bnez */
  2016. {
  2017. struct upk_mips16 upk;
  2018. int reg;
  2019. unpack_mips16 (gdbarch, pc, extension, insn, ritype, &upk);
  2020. reg = regcache_raw_get_signed (regcache, mips_reg3_to_reg[upk.regx]);
  2021. if (reg != 0)
  2022. pc = add_offset_16 (pc, upk.offset);
  2023. else
  2024. pc += 2;
  2025. break;
  2026. }
  2027. case 12: /* I8 Formats btez btnez */
  2028. {
  2029. struct upk_mips16 upk;
  2030. int reg;
  2031. unpack_mips16 (gdbarch, pc, extension, insn, i8type, &upk);
  2032. /* upk.regx contains the opcode */
  2033. /* Test register is 24 */
  2034. reg = regcache_raw_get_signed (regcache, 24);
  2035. if (((upk.regx == 0) && (reg == 0)) /* BTEZ */
  2036. || ((upk.regx == 1) && (reg != 0))) /* BTNEZ */
  2037. pc = add_offset_16 (pc, upk.offset);
  2038. else
  2039. pc += 2;
  2040. break;
  2041. }
  2042. case 29: /* RR Formats JR, JALR, JALR-RA */
  2043. {
  2044. struct upk_mips16 upk;
  2045. /* upk.fmt = rrtype; */
  2046. op = insn & 0x1f;
  2047. if (op == 0)
  2048. {
  2049. int reg;
  2050. upk.regx = (insn >> 8) & 0x07;
  2051. upk.regy = (insn >> 5) & 0x07;
  2052. if ((upk.regy & 1) == 0)
  2053. reg = mips_reg3_to_reg[upk.regx];
  2054. else
  2055. reg = 31; /* Function return instruction. */
  2056. pc = regcache_raw_get_signed (regcache, reg);
  2057. }
  2058. else
  2059. pc += 2;
  2060. break;
  2061. }
  2062. case 30:
  2063. /* This is an instruction extension. Fetch the real instruction
  2064. (which follows the extension) and decode things based on
  2065. that. */
  2066. {
  2067. pc += 2;
  2068. pc = extended_mips16_next_pc (regcache, pc, insn,
  2069. fetch_mips_16 (gdbarch, pc));
  2070. break;
  2071. }
  2072. default:
  2073. {
  2074. pc += 2;
  2075. break;
  2076. }
  2077. }
  2078. return pc;
  2079. }
  2080. static CORE_ADDR
  2081. mips16_next_pc (struct regcache *regcache, CORE_ADDR pc)
  2082. {
  2083. struct gdbarch *gdbarch = regcache->arch ();
  2084. unsigned int insn = fetch_mips_16 (gdbarch, pc);
  2085. return extended_mips16_next_pc (regcache, pc, 0, insn);
  2086. }
  2087. /* The mips_next_pc function supports single_step when the remote
  2088. target monitor or stub is not developed enough to do a single_step.
  2089. It works by decoding the current instruction and predicting where a
  2090. branch will go. This isn't hard because all the data is available.
  2091. The MIPS32, MIPS16 and microMIPS variants are quite different. */
  2092. static CORE_ADDR
  2093. mips_next_pc (struct regcache *regcache, CORE_ADDR pc)
  2094. {
  2095. struct gdbarch *gdbarch = regcache->arch ();
  2096. if (mips_pc_is_mips16 (gdbarch, pc))
  2097. return mips16_next_pc (regcache, pc);
  2098. else if (mips_pc_is_micromips (gdbarch, pc))
  2099. return micromips_next_pc (regcache, pc);
  2100. else
  2101. return mips32_next_pc (regcache, pc);
  2102. }
  2103. /* Return non-zero if the MIPS16 instruction INSN is a compact branch
  2104. or jump. */
  2105. static int
  2106. mips16_instruction_is_compact_branch (unsigned short insn)
  2107. {
  2108. switch (insn & 0xf800)
  2109. {
  2110. case 0xe800:
  2111. return (insn & 0x009f) == 0x80; /* JALRC/JRC */
  2112. case 0x6000:
  2113. return (insn & 0x0600) == 0; /* BTNEZ/BTEQZ */
  2114. case 0x2800: /* BNEZ */
  2115. case 0x2000: /* BEQZ */
  2116. case 0x1000: /* B */
  2117. return 1;
  2118. default:
  2119. return 0;
  2120. }
  2121. }
  2122. /* Return non-zero if the microMIPS instruction INSN is a compact branch
  2123. or jump. */
  2124. static int
  2125. micromips_instruction_is_compact_branch (unsigned short insn)
  2126. {
  2127. switch (micromips_op (insn))
  2128. {
  2129. case 0x11: /* POOL16C: bits 010001 */
  2130. return (b5s5_op (insn) == 0x18
  2131. /* JRADDIUSP: bits 010001 11000 */
  2132. || b5s5_op (insn) == 0xd);
  2133. /* JRC: bits 010011 01101 */
  2134. case 0x10: /* POOL32I: bits 010000 */
  2135. return (b5s5_op (insn) & 0x1d) == 0x5;
  2136. /* BEQZC/BNEZC: bits 010000 001x1 */
  2137. default:
  2138. return 0;
  2139. }
  2140. }
  2141. struct mips_frame_cache
  2142. {
  2143. CORE_ADDR base;
  2144. trad_frame_saved_reg *saved_regs;
  2145. };
  2146. /* Set a register's saved stack address in temp_saved_regs. If an
  2147. address has already been set for this register, do nothing; this
  2148. way we will only recognize the first save of a given register in a
  2149. function prologue.
  2150. For simplicity, save the address in both [0 .. gdbarch_num_regs) and
  2151. [gdbarch_num_regs .. 2*gdbarch_num_regs).
  2152. Strictly speaking, only the second range is used as it is only second
  2153. range (the ABI instead of ISA registers) that comes into play when finding
  2154. saved registers in a frame. */
  2155. static void
  2156. set_reg_offset (struct gdbarch *gdbarch, struct mips_frame_cache *this_cache,
  2157. int regnum, CORE_ADDR offset)
  2158. {
  2159. if (this_cache != NULL
  2160. && this_cache->saved_regs[regnum].is_realreg ()
  2161. && this_cache->saved_regs[regnum].realreg () == regnum)
  2162. {
  2163. this_cache->saved_regs[regnum + 0
  2164. * gdbarch_num_regs (gdbarch)].set_addr (offset);
  2165. this_cache->saved_regs[regnum + 1
  2166. * gdbarch_num_regs (gdbarch)].set_addr (offset);
  2167. }
  2168. }
  2169. /* Fetch the immediate value from a MIPS16 instruction.
  2170. If the previous instruction was an EXTEND, use it to extend
  2171. the upper bits of the immediate value. This is a helper function
  2172. for mips16_scan_prologue. */
  2173. static int
  2174. mips16_get_imm (unsigned short prev_inst, /* previous instruction */
  2175. unsigned short inst, /* current instruction */
  2176. int nbits, /* number of bits in imm field */
  2177. int scale, /* scale factor to be applied to imm */
  2178. int is_signed) /* is the imm field signed? */
  2179. {
  2180. int offset;
  2181. if ((prev_inst & 0xf800) == 0xf000) /* prev instruction was EXTEND? */
  2182. {
  2183. offset = ((prev_inst & 0x1f) << 11) | (prev_inst & 0x7e0);
  2184. if (offset & 0x8000) /* check for negative extend */
  2185. offset = 0 - (0x10000 - (offset & 0xffff));
  2186. return offset | (inst & 0x1f);
  2187. }
  2188. else
  2189. {
  2190. int max_imm = 1 << nbits;
  2191. int mask = max_imm - 1;
  2192. int sign_bit = max_imm >> 1;
  2193. offset = inst & mask;
  2194. if (is_signed && (offset & sign_bit))
  2195. offset = 0 - (max_imm - offset);
  2196. return offset * scale;
  2197. }
  2198. }
  2199. /* Analyze the function prologue from START_PC to LIMIT_PC. Builds
  2200. the associated FRAME_CACHE if not null.
  2201. Return the address of the first instruction past the prologue. */
  2202. static CORE_ADDR
  2203. mips16_scan_prologue (struct gdbarch *gdbarch,
  2204. CORE_ADDR start_pc, CORE_ADDR limit_pc,
  2205. struct frame_info *this_frame,
  2206. struct mips_frame_cache *this_cache)
  2207. {
  2208. int prev_non_prologue_insn = 0;
  2209. int this_non_prologue_insn;
  2210. int non_prologue_insns = 0;
  2211. CORE_ADDR prev_pc;
  2212. CORE_ADDR cur_pc;
  2213. CORE_ADDR frame_addr = 0; /* Value of $r17, used as frame pointer. */
  2214. CORE_ADDR sp;
  2215. long frame_offset = 0; /* Size of stack frame. */
  2216. long frame_adjust = 0; /* Offset of FP from SP. */
  2217. int frame_reg = MIPS_SP_REGNUM;
  2218. unsigned short prev_inst = 0; /* saved copy of previous instruction. */
  2219. unsigned inst = 0; /* current instruction */
  2220. unsigned entry_inst = 0; /* the entry instruction */
  2221. unsigned save_inst = 0; /* the save instruction */
  2222. int prev_delay_slot = 0;
  2223. int in_delay_slot;
  2224. int reg, offset;
  2225. int extend_bytes = 0;
  2226. int prev_extend_bytes = 0;
  2227. CORE_ADDR end_prologue_addr;
  2228. /* Can be called when there's no process, and hence when there's no
  2229. THIS_FRAME. */
  2230. if (this_frame != NULL)
  2231. sp = get_frame_register_signed (this_frame,
  2232. gdbarch_num_regs (gdbarch)
  2233. + MIPS_SP_REGNUM);
  2234. else
  2235. sp = 0;
  2236. if (limit_pc > start_pc + 200)
  2237. limit_pc = start_pc + 200;
  2238. prev_pc = start_pc;
  2239. /* Permit at most one non-prologue non-control-transfer instruction
  2240. in the middle which may have been reordered by the compiler for
  2241. optimisation. */
  2242. for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN16_SIZE)
  2243. {
  2244. this_non_prologue_insn = 0;
  2245. in_delay_slot = 0;
  2246. /* Save the previous instruction. If it's an EXTEND, we'll extract
  2247. the immediate offset extension from it in mips16_get_imm. */
  2248. prev_inst = inst;
  2249. /* Fetch and decode the instruction. */
  2250. inst = (unsigned short) mips_fetch_instruction (gdbarch, ISA_MIPS16,
  2251. cur_pc, NULL);
  2252. /* Normally we ignore extend instructions. However, if it is
  2253. not followed by a valid prologue instruction, then this
  2254. instruction is not part of the prologue either. We must
  2255. remember in this case to adjust the end_prologue_addr back
  2256. over the extend. */
  2257. if ((inst & 0xf800) == 0xf000) /* extend */
  2258. {
  2259. extend_bytes = MIPS_INSN16_SIZE;
  2260. continue;
  2261. }
  2262. prev_extend_bytes = extend_bytes;
  2263. extend_bytes = 0;
  2264. if ((inst & 0xff00) == 0x6300 /* addiu sp */
  2265. || (inst & 0xff00) == 0xfb00) /* daddiu sp */
  2266. {
  2267. offset = mips16_get_imm (prev_inst, inst, 8, 8, 1);
  2268. if (offset < 0) /* Negative stack adjustment? */
  2269. frame_offset -= offset;
  2270. else
  2271. /* Exit loop if a positive stack adjustment is found, which
  2272. usually means that the stack cleanup code in the function
  2273. epilogue is reached. */
  2274. break;
  2275. }
  2276. else if ((inst & 0xf800) == 0xd000) /* sw reg,n($sp) */
  2277. {
  2278. offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
  2279. reg = mips_reg3_to_reg[(inst & 0x700) >> 8];
  2280. set_reg_offset (gdbarch, this_cache, reg, sp + offset);
  2281. }
  2282. else if ((inst & 0xff00) == 0xf900) /* sd reg,n($sp) */
  2283. {
  2284. offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
  2285. reg = mips_reg3_to_reg[(inst & 0xe0) >> 5];
  2286. set_reg_offset (gdbarch, this_cache, reg, sp + offset);
  2287. }
  2288. else if ((inst & 0xff00) == 0x6200) /* sw $ra,n($sp) */
  2289. {
  2290. offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
  2291. set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset);
  2292. }
  2293. else if ((inst & 0xff00) == 0xfa00) /* sd $ra,n($sp) */
  2294. {
  2295. offset = mips16_get_imm (prev_inst, inst, 8, 8, 0);
  2296. set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset);
  2297. }
  2298. else if (inst == 0x673d) /* move $s1, $sp */
  2299. {
  2300. frame_addr = sp;
  2301. frame_reg = 17;
  2302. }
  2303. else if ((inst & 0xff00) == 0x0100) /* addiu $s1,sp,n */
  2304. {
  2305. offset = mips16_get_imm (prev_inst, inst, 8, 4, 0);
  2306. frame_addr = sp + offset;
  2307. frame_reg = 17;
  2308. frame_adjust = offset;
  2309. }
  2310. else if ((inst & 0xFF00) == 0xd900) /* sw reg,offset($s1) */
  2311. {
  2312. offset = mips16_get_imm (prev_inst, inst, 5, 4, 0);
  2313. reg = mips_reg3_to_reg[(inst & 0xe0) >> 5];
  2314. set_reg_offset (gdbarch, this_cache, reg, frame_addr + offset);
  2315. }
  2316. else if ((inst & 0xFF00) == 0x7900) /* sd reg,offset($s1) */
  2317. {
  2318. offset = mips16_get_imm (prev_inst, inst, 5, 8, 0);
  2319. reg = mips_reg3_to_reg[(inst & 0xe0) >> 5];
  2320. set_reg_offset (gdbarch, this_cache, reg, frame_addr + offset);
  2321. }
  2322. else if ((inst & 0xf81f) == 0xe809
  2323. && (inst & 0x700) != 0x700) /* entry */
  2324. entry_inst = inst; /* Save for later processing. */
  2325. else if ((inst & 0xff80) == 0x6480) /* save */
  2326. {
  2327. save_inst = inst; /* Save for later processing. */
  2328. if (prev_extend_bytes) /* extend */
  2329. save_inst |= prev_inst << 16;
  2330. }
  2331. else if ((inst & 0xff1c) == 0x6704) /* move reg,$a0-$a3 */
  2332. {
  2333. /* This instruction is part of the prologue, but we don't
  2334. need to do anything special to handle it. */
  2335. }
  2336. else if (mips16_instruction_has_delay_slot (inst, 0))
  2337. /* JAL/JALR/JALX/JR */
  2338. {
  2339. /* The instruction in the delay slot can be a part
  2340. of the prologue, so move forward once more. */
  2341. in_delay_slot = 1;
  2342. if (mips16_instruction_has_delay_slot (inst, 1))
  2343. /* JAL/JALX */
  2344. {
  2345. prev_extend_bytes = MIPS_INSN16_SIZE;
  2346. cur_pc += MIPS_INSN16_SIZE; /* 32-bit instruction */
  2347. }
  2348. }
  2349. else
  2350. {
  2351. this_non_prologue_insn = 1;
  2352. }
  2353. non_prologue_insns += this_non_prologue_insn;
  2354. /* A jump or branch, or enough non-prologue insns seen? If so,
  2355. then we must have reached the end of the prologue by now. */
  2356. if (prev_delay_slot || non_prologue_insns > 1
  2357. || mips16_instruction_is_compact_branch (inst))
  2358. break;
  2359. prev_non_prologue_insn = this_non_prologue_insn;
  2360. prev_delay_slot = in_delay_slot;
  2361. prev_pc = cur_pc - prev_extend_bytes;
  2362. }
  2363. /* The entry instruction is typically the first instruction in a function,
  2364. and it stores registers at offsets relative to the value of the old SP
  2365. (before the prologue). But the value of the sp parameter to this
  2366. function is the new SP (after the prologue has been executed). So we
  2367. can't calculate those offsets until we've seen the entire prologue,
  2368. and can calculate what the old SP must have been. */
  2369. if (entry_inst != 0)
  2370. {
  2371. int areg_count = (entry_inst >> 8) & 7;
  2372. int sreg_count = (entry_inst >> 6) & 3;
  2373. /* The entry instruction always subtracts 32 from the SP. */
  2374. frame_offset += 32;
  2375. /* Now we can calculate what the SP must have been at the
  2376. start of the function prologue. */
  2377. sp += frame_offset;
  2378. /* Check if a0-a3 were saved in the caller's argument save area. */
  2379. for (reg = 4, offset = 0; reg < areg_count + 4; reg++)
  2380. {
  2381. set_reg_offset (gdbarch, this_cache, reg, sp + offset);
  2382. offset += mips_abi_regsize (gdbarch);
  2383. }
  2384. /* Check if the ra register was pushed on the stack. */
  2385. offset = -4;
  2386. if (entry_inst & 0x20)
  2387. {
  2388. set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset);
  2389. offset -= mips_abi_regsize (gdbarch);
  2390. }
  2391. /* Check if the s0 and s1 registers were pushed on the stack. */
  2392. for (reg = 16; reg < sreg_count + 16; reg++)
  2393. {
  2394. set_reg_offset (gdbarch, this_cache, reg, sp + offset);
  2395. offset -= mips_abi_regsize (gdbarch);
  2396. }
  2397. }
  2398. /* The SAVE instruction is similar to ENTRY, except that defined by the
  2399. MIPS16e ASE of the MIPS Architecture. Unlike with ENTRY though, the
  2400. size of the frame is specified as an immediate field of instruction
  2401. and an extended variation exists which lets additional registers and
  2402. frame space to be specified. The instruction always treats registers
  2403. as 32-bit so its usefulness for 64-bit ABIs is questionable. */
  2404. if (save_inst != 0 && mips_abi_regsize (gdbarch) == 4)
  2405. {
  2406. static int args_table[16] = {
  2407. 0, 0, 0, 0, 1, 1, 1, 1,
  2408. 2, 2, 2, 0, 3, 3, 4, -1,
  2409. };
  2410. static int astatic_table[16] = {
  2411. 0, 1, 2, 3, 0, 1, 2, 3,
  2412. 0, 1, 2, 4, 0, 1, 0, -1,
  2413. };
  2414. int aregs = (save_inst >> 16) & 0xf;
  2415. int xsregs = (save_inst >> 24) & 0x7;
  2416. int args = args_table[aregs];
  2417. int astatic = astatic_table[aregs];
  2418. long frame_size;
  2419. if (args < 0)
  2420. {
  2421. warning (_("Invalid number of argument registers encoded in SAVE."));
  2422. args = 0;
  2423. }
  2424. if (astatic < 0)
  2425. {
  2426. warning (_("Invalid number of static registers encoded in SAVE."));
  2427. astatic = 0;
  2428. }
  2429. /* For standard SAVE the frame size of 0 means 128. */
  2430. frame_size = ((save_inst >> 16) & 0xf0) | (save_inst & 0xf);
  2431. if (frame_size == 0 && (save_inst >> 16) == 0)
  2432. frame_size = 16;
  2433. frame_size *= 8;
  2434. frame_offset += frame_size;
  2435. /* Now we can calculate what the SP must have been at the
  2436. start of the function prologue. */
  2437. sp += frame_offset;
  2438. /* Check if A0-A3 were saved in the caller's argument save area. */
  2439. for (reg = MIPS_A0_REGNUM, offset = 0; reg < args + 4; reg++)
  2440. {
  2441. set_reg_offset (gdbarch, this_cache, reg, sp + offset);
  2442. offset += mips_abi_regsize (gdbarch);
  2443. }
  2444. offset = -4;
  2445. /* Check if the RA register was pushed on the stack. */
  2446. if (save_inst & 0x40)
  2447. {
  2448. set_reg_offset (gdbarch, this_cache, MIPS_RA_REGNUM, sp + offset);
  2449. offset -= mips_abi_regsize (gdbarch);
  2450. }
  2451. /* Check if the S8 register was pushed on the stack. */
  2452. if (xsregs > 6)
  2453. {
  2454. set_reg_offset (gdbarch, this_cache, 30, sp + offset);
  2455. offset -= mips_abi_regsize (gdbarch);
  2456. xsregs--;
  2457. }
  2458. /* Check if S2-S7 were pushed on the stack. */
  2459. for (reg = 18 + xsregs - 1; reg > 18 - 1; reg--)
  2460. {
  2461. set_reg_offset (gdbarch, this_cache, reg, sp + offset);
  2462. offset -= mips_abi_regsize (gdbarch);
  2463. }
  2464. /* Check if the S1 register was pushed on the stack. */
  2465. if (save_inst & 0x10)
  2466. {
  2467. set_reg_offset (gdbarch, this_cache, 17, sp + offset);
  2468. offset -= mips_abi_regsize (gdbarch);
  2469. }
  2470. /* Check if the S0 register was pushed on the stack. */
  2471. if (save_inst & 0x20)
  2472. {
  2473. set_reg_offset (gdbarch, this_cache, 16, sp + offset);
  2474. offset -= mips_abi_regsize (gdbarch);
  2475. }
  2476. /* Check if A0-A3 were pushed on the stack. */
  2477. for (reg = MIPS_A0_REGNUM + 3; reg > MIPS_A0_REGNUM + 3 - astatic; reg--)
  2478. {
  2479. set_reg_offset (gdbarch, this_cache, reg, sp + offset);
  2480. offset -= mips_abi_regsize (gdbarch);
  2481. }
  2482. }
  2483. if (this_cache != NULL)
  2484. {
  2485. this_cache->base =
  2486. (get_frame_register_signed (this_frame,
  2487. gdbarch_num_regs (gdbarch) + frame_reg)
  2488. + frame_offset - frame_adjust);
  2489. /* FIXME: brobecker/2004-10-10: Just as in the mips32 case, we should
  2490. be able to get rid of the assignment below, evetually. But it's
  2491. still needed for now. */
  2492. this_cache->saved_regs[gdbarch_num_regs (gdbarch)
  2493. + mips_regnum (gdbarch)->pc]
  2494. = this_cache->saved_regs[gdbarch_num_regs (gdbarch) + MIPS_RA_REGNUM];
  2495. }
  2496. /* Set end_prologue_addr to the address of the instruction immediately
  2497. after the last one we scanned. Unless the last one looked like a
  2498. non-prologue instruction (and we looked ahead), in which case use
  2499. its address instead. */
  2500. end_prologue_addr = (prev_non_prologue_insn || prev_delay_slot
  2501. ? prev_pc : cur_pc - prev_extend_bytes);
  2502. return end_prologue_addr;
  2503. }
  2504. /* Heuristic unwinder for 16-bit MIPS instruction set (aka MIPS16).
  2505. Procedures that use the 32-bit instruction set are handled by the
  2506. mips_insn32 unwinder. */
  2507. static struct mips_frame_cache *
  2508. mips_insn16_frame_cache (struct frame_info *this_frame, void **this_cache)
  2509. {
  2510. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  2511. struct mips_frame_cache *cache;
  2512. if ((*this_cache) != NULL)
  2513. return (struct mips_frame_cache *) (*this_cache);
  2514. cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache);
  2515. (*this_cache) = cache;
  2516. cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
  2517. /* Analyze the function prologue. */
  2518. {
  2519. const CORE_ADDR pc = get_frame_address_in_block (this_frame);
  2520. CORE_ADDR start_addr;
  2521. find_pc_partial_function (pc, NULL, &start_addr, NULL);
  2522. if (start_addr == 0)
  2523. start_addr = heuristic_proc_start (gdbarch, pc);
  2524. /* We can't analyze the prologue if we couldn't find the begining
  2525. of the function. */
  2526. if (start_addr == 0)
  2527. return cache;
  2528. mips16_scan_prologue (gdbarch, start_addr, pc, this_frame,
  2529. (struct mips_frame_cache *) *this_cache);
  2530. }
  2531. /* gdbarch_sp_regnum contains the value and not the address. */
  2532. cache->saved_regs[gdbarch_num_regs (gdbarch)
  2533. + MIPS_SP_REGNUM].set_value (cache->base);
  2534. return (struct mips_frame_cache *) (*this_cache);
  2535. }
  2536. static void
  2537. mips_insn16_frame_this_id (struct frame_info *this_frame, void **this_cache,
  2538. struct frame_id *this_id)
  2539. {
  2540. struct mips_frame_cache *info = mips_insn16_frame_cache (this_frame,
  2541. this_cache);
  2542. /* This marks the outermost frame. */
  2543. if (info->base == 0)
  2544. return;
  2545. (*this_id) = frame_id_build (info->base, get_frame_func (this_frame));
  2546. }
  2547. static struct value *
  2548. mips_insn16_frame_prev_register (struct frame_info *this_frame,
  2549. void **this_cache, int regnum)
  2550. {
  2551. struct mips_frame_cache *info = mips_insn16_frame_cache (this_frame,
  2552. this_cache);
  2553. return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
  2554. }
  2555. static int
  2556. mips_insn16_frame_sniffer (const struct frame_unwind *self,
  2557. struct frame_info *this_frame, void **this_cache)
  2558. {
  2559. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  2560. CORE_ADDR pc = get_frame_pc (this_frame);
  2561. if (mips_pc_is_mips16 (gdbarch, pc))
  2562. return 1;
  2563. return 0;
  2564. }
  2565. static const struct frame_unwind mips_insn16_frame_unwind =
  2566. {
  2567. "mips insn16 prologue",
  2568. NORMAL_FRAME,
  2569. default_frame_unwind_stop_reason,
  2570. mips_insn16_frame_this_id,
  2571. mips_insn16_frame_prev_register,
  2572. NULL,
  2573. mips_insn16_frame_sniffer
  2574. };
  2575. static CORE_ADDR
  2576. mips_insn16_frame_base_address (struct frame_info *this_frame,
  2577. void **this_cache)
  2578. {
  2579. struct mips_frame_cache *info = mips_insn16_frame_cache (this_frame,
  2580. this_cache);
  2581. return info->base;
  2582. }
  2583. static const struct frame_base mips_insn16_frame_base =
  2584. {
  2585. &mips_insn16_frame_unwind,
  2586. mips_insn16_frame_base_address,
  2587. mips_insn16_frame_base_address,
  2588. mips_insn16_frame_base_address
  2589. };
  2590. static const struct frame_base *
  2591. mips_insn16_frame_base_sniffer (struct frame_info *this_frame)
  2592. {
  2593. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  2594. CORE_ADDR pc = get_frame_pc (this_frame);
  2595. if (mips_pc_is_mips16 (gdbarch, pc))
  2596. return &mips_insn16_frame_base;
  2597. else
  2598. return NULL;
  2599. }
  2600. /* Decode a 9-bit signed immediate argument of ADDIUSP -- -2 is mapped
  2601. to -258, -1 -- to -257, 0 -- to 256, 1 -- to 257 and other values are
  2602. interpreted directly, and then multiplied by 4. */
  2603. static int
  2604. micromips_decode_imm9 (int imm)
  2605. {
  2606. imm = (imm ^ 0x100) - 0x100;
  2607. if (imm > -3 && imm < 2)
  2608. imm ^= 0x100;
  2609. return imm << 2;
  2610. }
  2611. /* Analyze the function prologue from START_PC to LIMIT_PC. Return
  2612. the address of the first instruction past the prologue. */
  2613. static CORE_ADDR
  2614. micromips_scan_prologue (struct gdbarch *gdbarch,
  2615. CORE_ADDR start_pc, CORE_ADDR limit_pc,
  2616. struct frame_info *this_frame,
  2617. struct mips_frame_cache *this_cache)
  2618. {
  2619. CORE_ADDR end_prologue_addr;
  2620. int prev_non_prologue_insn = 0;
  2621. int frame_reg = MIPS_SP_REGNUM;
  2622. int this_non_prologue_insn;
  2623. int non_prologue_insns = 0;
  2624. long frame_offset = 0; /* Size of stack frame. */
  2625. long frame_adjust = 0; /* Offset of FP from SP. */
  2626. int prev_delay_slot = 0;
  2627. int in_delay_slot;
  2628. CORE_ADDR prev_pc;
  2629. CORE_ADDR cur_pc;
  2630. ULONGEST insn; /* current instruction */
  2631. CORE_ADDR sp;
  2632. long offset;
  2633. long sp_adj;
  2634. long v1_off = 0; /* The assumption is LUI will replace it. */
  2635. int reglist;
  2636. int breg;
  2637. int dreg;
  2638. int sreg;
  2639. int treg;
  2640. int loc;
  2641. int op;
  2642. int s;
  2643. int i;
  2644. /* Can be called when there's no process, and hence when there's no
  2645. THIS_FRAME. */
  2646. if (this_frame != NULL)
  2647. sp = get_frame_register_signed (this_frame,
  2648. gdbarch_num_regs (gdbarch)
  2649. + MIPS_SP_REGNUM);
  2650. else
  2651. sp = 0;
  2652. if (limit_pc > start_pc + 200)
  2653. limit_pc = start_pc + 200;
  2654. prev_pc = start_pc;
  2655. /* Permit at most one non-prologue non-control-transfer instruction
  2656. in the middle which may have been reordered by the compiler for
  2657. optimisation. */
  2658. for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += loc)
  2659. {
  2660. this_non_prologue_insn = 0;
  2661. in_delay_slot = 0;
  2662. sp_adj = 0;
  2663. loc = 0;
  2664. insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, cur_pc, NULL);
  2665. loc += MIPS_INSN16_SIZE;
  2666. switch (mips_insn_size (ISA_MICROMIPS, insn))
  2667. {
  2668. /* 32-bit instructions. */
  2669. case 2 * MIPS_INSN16_SIZE:
  2670. insn <<= 16;
  2671. insn |= mips_fetch_instruction (gdbarch,
  2672. ISA_MICROMIPS, cur_pc + loc, NULL);
  2673. loc += MIPS_INSN16_SIZE;
  2674. switch (micromips_op (insn >> 16))
  2675. {
  2676. /* Record $sp/$fp adjustment. */
  2677. /* Discard (D)ADDU $gp,$jp used for PIC code. */
  2678. case 0x0: /* POOL32A: bits 000000 */
  2679. case 0x16: /* POOL32S: bits 010110 */
  2680. op = b0s11_op (insn);
  2681. sreg = b0s5_reg (insn >> 16);
  2682. treg = b5s5_reg (insn >> 16);
  2683. dreg = b11s5_reg (insn);
  2684. if (op == 0x1d0
  2685. /* SUBU: bits 000000 00111010000 */
  2686. /* DSUBU: bits 010110 00111010000 */
  2687. && dreg == MIPS_SP_REGNUM && sreg == MIPS_SP_REGNUM
  2688. && treg == 3)
  2689. /* (D)SUBU $sp, $v1 */
  2690. sp_adj = v1_off;
  2691. else if (op != 0x150
  2692. /* ADDU: bits 000000 00101010000 */
  2693. /* DADDU: bits 010110 00101010000 */
  2694. || dreg != 28 || sreg != 28 || treg != MIPS_T9_REGNUM)
  2695. this_non_prologue_insn = 1;
  2696. break;
  2697. case 0x8: /* POOL32B: bits 001000 */
  2698. op = b12s4_op (insn);
  2699. breg = b0s5_reg (insn >> 16);
  2700. reglist = sreg = b5s5_reg (insn >> 16);
  2701. offset = (b0s12_imm (insn) ^ 0x800) - 0x800;
  2702. if ((op == 0x9 || op == 0xc)
  2703. /* SWP: bits 001000 1001 */
  2704. /* SDP: bits 001000 1100 */
  2705. && breg == MIPS_SP_REGNUM && sreg < MIPS_RA_REGNUM)
  2706. /* S[DW]P reg,offset($sp) */
  2707. {
  2708. s = 4 << ((b12s4_op (insn) & 0x4) == 0x4);
  2709. set_reg_offset (gdbarch, this_cache,
  2710. sreg, sp + offset);
  2711. set_reg_offset (gdbarch, this_cache,
  2712. sreg + 1, sp + offset + s);
  2713. }
  2714. else if ((op == 0xd || op == 0xf)
  2715. /* SWM: bits 001000 1101 */
  2716. /* SDM: bits 001000 1111 */
  2717. && breg == MIPS_SP_REGNUM
  2718. /* SWM reglist,offset($sp) */
  2719. && ((reglist >= 1 && reglist <= 9)
  2720. || (reglist >= 16 && reglist <= 25)))
  2721. {
  2722. int sreglist = std::min(reglist & 0xf, 8);
  2723. s = 4 << ((b12s4_op (insn) & 0x2) == 0x2);
  2724. for (i = 0; i < sreglist; i++)
  2725. set_reg_offset (gdbarch, this_cache, 16 + i, sp + s * i);
  2726. if ((reglist & 0xf) > 8)
  2727. set_reg_offset (gdbarch, this_cache, 30, sp + s * i++);
  2728. if ((reglist & 0x10) == 0x10)
  2729. set_reg_offset (gdbarch, this_cache,
  2730. MIPS_RA_REGNUM, sp + s * i++);
  2731. }
  2732. else
  2733. this_non_prologue_insn = 1;
  2734. break;
  2735. /* Record $sp/$fp adjustment. */
  2736. /* Discard (D)ADDIU $gp used for PIC code. */
  2737. case 0xc: /* ADDIU: bits 001100 */
  2738. case 0x17: /* DADDIU: bits 010111 */
  2739. sreg = b0s5_reg (insn >> 16);
  2740. dreg = b5s5_reg (insn >> 16);
  2741. offset = (b0s16_imm (insn) ^ 0x8000) - 0x8000;
  2742. if (sreg == MIPS_SP_REGNUM && dreg == MIPS_SP_REGNUM)
  2743. /* (D)ADDIU $sp, imm */
  2744. sp_adj = offset;
  2745. else if (sreg == MIPS_SP_REGNUM && dreg == 30)
  2746. /* (D)ADDIU $fp, $sp, imm */
  2747. {
  2748. frame_adjust = offset;
  2749. frame_reg = 30;
  2750. }
  2751. else if (sreg != 28 || dreg != 28)
  2752. /* (D)ADDIU $gp, imm */
  2753. this_non_prologue_insn = 1;
  2754. break;
  2755. /* LUI $v1 is used for larger $sp adjustments. */
  2756. /* Discard LUI $gp used for PIC code. */
  2757. case 0x10: /* POOL32I: bits 010000 */
  2758. if (b5s5_op (insn >> 16) == 0xd
  2759. /* LUI: bits 010000 001101 */
  2760. && b0s5_reg (insn >> 16) == 3)
  2761. /* LUI $v1, imm */
  2762. v1_off = ((b0s16_imm (insn) << 16) ^ 0x80000000) - 0x80000000;
  2763. else if (b5s5_op (insn >> 16) != 0xd
  2764. /* LUI: bits 010000 001101 */
  2765. || b0s5_reg (insn >> 16) != 28)
  2766. /* LUI $gp, imm */
  2767. this_non_prologue_insn = 1;
  2768. break;
  2769. /* ORI $v1 is used for larger $sp adjustments. */
  2770. case 0x14: /* ORI: bits 010100 */
  2771. sreg = b0s5_reg (insn >> 16);
  2772. dreg = b5s5_reg (insn >> 16);
  2773. if (sreg == 3 && dreg == 3)
  2774. /* ORI $v1, imm */
  2775. v1_off |= b0s16_imm (insn);
  2776. else
  2777. this_non_prologue_insn = 1;
  2778. break;
  2779. case 0x26: /* SWC1: bits 100110 */
  2780. case 0x2e: /* SDC1: bits 101110 */
  2781. breg = b0s5_reg (insn >> 16);
  2782. if (breg != MIPS_SP_REGNUM)
  2783. /* S[DW]C1 reg,offset($sp) */
  2784. this_non_prologue_insn = 1;
  2785. break;
  2786. case 0x36: /* SD: bits 110110 */
  2787. case 0x3e: /* SW: bits 111110 */
  2788. breg = b0s5_reg (insn >> 16);
  2789. sreg = b5s5_reg (insn >> 16);
  2790. offset = (b0s16_imm (insn) ^ 0x8000) - 0x8000;
  2791. if (breg == MIPS_SP_REGNUM)
  2792. /* S[DW] reg,offset($sp) */
  2793. set_reg_offset (gdbarch, this_cache, sreg, sp + offset);
  2794. else
  2795. this_non_prologue_insn = 1;
  2796. break;
  2797. default:
  2798. /* The instruction in the delay slot can be a part
  2799. of the prologue, so move forward once more. */
  2800. if (micromips_instruction_has_delay_slot (insn, 0))
  2801. in_delay_slot = 1;
  2802. else
  2803. this_non_prologue_insn = 1;
  2804. break;
  2805. }
  2806. insn >>= 16;
  2807. break;
  2808. /* 16-bit instructions. */
  2809. case MIPS_INSN16_SIZE:
  2810. switch (micromips_op (insn))
  2811. {
  2812. case 0x3: /* MOVE: bits 000011 */
  2813. sreg = b0s5_reg (insn);
  2814. dreg = b5s5_reg (insn);
  2815. if (sreg == MIPS_SP_REGNUM && dreg == 30)
  2816. /* MOVE $fp, $sp */
  2817. frame_reg = 30;
  2818. else if ((sreg & 0x1c) != 0x4)
  2819. /* MOVE reg, $a0-$a3 */
  2820. this_non_prologue_insn = 1;
  2821. break;
  2822. case 0x11: /* POOL16C: bits 010001 */
  2823. if (b6s4_op (insn) == 0x5)
  2824. /* SWM: bits 010001 0101 */
  2825. {
  2826. offset = ((b0s4_imm (insn) << 2) ^ 0x20) - 0x20;
  2827. reglist = b4s2_regl (insn);
  2828. for (i = 0; i <= reglist; i++)
  2829. set_reg_offset (gdbarch, this_cache, 16 + i, sp + 4 * i);
  2830. set_reg_offset (gdbarch, this_cache,
  2831. MIPS_RA_REGNUM, sp + 4 * i++);
  2832. }
  2833. else
  2834. this_non_prologue_insn = 1;
  2835. break;
  2836. case 0x13: /* POOL16D: bits 010011 */
  2837. if ((insn & 0x1) == 0x1)
  2838. /* ADDIUSP: bits 010011 1 */
  2839. sp_adj = micromips_decode_imm9 (b1s9_imm (insn));
  2840. else if (b5s5_reg (insn) == MIPS_SP_REGNUM)
  2841. /* ADDIUS5: bits 010011 0 */
  2842. /* ADDIUS5 $sp, imm */
  2843. sp_adj = (b1s4_imm (insn) ^ 8) - 8;
  2844. else
  2845. this_non_prologue_insn = 1;
  2846. break;
  2847. case 0x32: /* SWSP: bits 110010 */
  2848. offset = b0s5_imm (insn) << 2;
  2849. sreg = b5s5_reg (insn);
  2850. set_reg_offset (gdbarch, this_cache, sreg, sp + offset);
  2851. break;
  2852. default:
  2853. /* The instruction in the delay slot can be a part
  2854. of the prologue, so move forward once more. */
  2855. if (micromips_instruction_has_delay_slot (insn << 16, 0))
  2856. in_delay_slot = 1;
  2857. else
  2858. this_non_prologue_insn = 1;
  2859. break;
  2860. }
  2861. break;
  2862. }
  2863. if (sp_adj < 0)
  2864. frame_offset -= sp_adj;
  2865. non_prologue_insns += this_non_prologue_insn;
  2866. /* A jump or branch, enough non-prologue insns seen or positive
  2867. stack adjustment? If so, then we must have reached the end
  2868. of the prologue by now. */
  2869. if (prev_delay_slot || non_prologue_insns > 1 || sp_adj > 0
  2870. || micromips_instruction_is_compact_branch (insn))
  2871. break;
  2872. prev_non_prologue_insn = this_non_prologue_insn;
  2873. prev_delay_slot = in_delay_slot;
  2874. prev_pc = cur_pc;
  2875. }
  2876. if (this_cache != NULL)
  2877. {
  2878. this_cache->base =
  2879. (get_frame_register_signed (this_frame,
  2880. gdbarch_num_regs (gdbarch) + frame_reg)
  2881. + frame_offset - frame_adjust);
  2882. /* FIXME: brobecker/2004-10-10: Just as in the mips32 case, we should
  2883. be able to get rid of the assignment below, evetually. But it's
  2884. still needed for now. */
  2885. this_cache->saved_regs[gdbarch_num_regs (gdbarch)
  2886. + mips_regnum (gdbarch)->pc]
  2887. = this_cache->saved_regs[gdbarch_num_regs (gdbarch) + MIPS_RA_REGNUM];
  2888. }
  2889. /* Set end_prologue_addr to the address of the instruction immediately
  2890. after the last one we scanned. Unless the last one looked like a
  2891. non-prologue instruction (and we looked ahead), in which case use
  2892. its address instead. */
  2893. end_prologue_addr
  2894. = prev_non_prologue_insn || prev_delay_slot ? prev_pc : cur_pc;
  2895. return end_prologue_addr;
  2896. }
  2897. /* Heuristic unwinder for procedures using microMIPS instructions.
  2898. Procedures that use the 32-bit instruction set are handled by the
  2899. mips_insn32 unwinder. Likewise MIPS16 and the mips_insn16 unwinder. */
  2900. static struct mips_frame_cache *
  2901. mips_micro_frame_cache (struct frame_info *this_frame, void **this_cache)
  2902. {
  2903. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  2904. struct mips_frame_cache *cache;
  2905. if ((*this_cache) != NULL)
  2906. return (struct mips_frame_cache *) (*this_cache);
  2907. cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache);
  2908. (*this_cache) = cache;
  2909. cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
  2910. /* Analyze the function prologue. */
  2911. {
  2912. const CORE_ADDR pc = get_frame_address_in_block (this_frame);
  2913. CORE_ADDR start_addr;
  2914. find_pc_partial_function (pc, NULL, &start_addr, NULL);
  2915. if (start_addr == 0)
  2916. start_addr = heuristic_proc_start (get_frame_arch (this_frame), pc);
  2917. /* We can't analyze the prologue if we couldn't find the begining
  2918. of the function. */
  2919. if (start_addr == 0)
  2920. return cache;
  2921. micromips_scan_prologue (gdbarch, start_addr, pc, this_frame,
  2922. (struct mips_frame_cache *) *this_cache);
  2923. }
  2924. /* gdbarch_sp_regnum contains the value and not the address. */
  2925. cache->saved_regs[gdbarch_num_regs (gdbarch)
  2926. + MIPS_SP_REGNUM].set_value (cache->base);
  2927. return (struct mips_frame_cache *) (*this_cache);
  2928. }
  2929. static void
  2930. mips_micro_frame_this_id (struct frame_info *this_frame, void **this_cache,
  2931. struct frame_id *this_id)
  2932. {
  2933. struct mips_frame_cache *info = mips_micro_frame_cache (this_frame,
  2934. this_cache);
  2935. /* This marks the outermost frame. */
  2936. if (info->base == 0)
  2937. return;
  2938. (*this_id) = frame_id_build (info->base, get_frame_func (this_frame));
  2939. }
  2940. static struct value *
  2941. mips_micro_frame_prev_register (struct frame_info *this_frame,
  2942. void **this_cache, int regnum)
  2943. {
  2944. struct mips_frame_cache *info = mips_micro_frame_cache (this_frame,
  2945. this_cache);
  2946. return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
  2947. }
  2948. static int
  2949. mips_micro_frame_sniffer (const struct frame_unwind *self,
  2950. struct frame_info *this_frame, void **this_cache)
  2951. {
  2952. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  2953. CORE_ADDR pc = get_frame_pc (this_frame);
  2954. if (mips_pc_is_micromips (gdbarch, pc))
  2955. return 1;
  2956. return 0;
  2957. }
  2958. static const struct frame_unwind mips_micro_frame_unwind =
  2959. {
  2960. "mips micro prologue",
  2961. NORMAL_FRAME,
  2962. default_frame_unwind_stop_reason,
  2963. mips_micro_frame_this_id,
  2964. mips_micro_frame_prev_register,
  2965. NULL,
  2966. mips_micro_frame_sniffer
  2967. };
  2968. static CORE_ADDR
  2969. mips_micro_frame_base_address (struct frame_info *this_frame,
  2970. void **this_cache)
  2971. {
  2972. struct mips_frame_cache *info = mips_micro_frame_cache (this_frame,
  2973. this_cache);
  2974. return info->base;
  2975. }
  2976. static const struct frame_base mips_micro_frame_base =
  2977. {
  2978. &mips_micro_frame_unwind,
  2979. mips_micro_frame_base_address,
  2980. mips_micro_frame_base_address,
  2981. mips_micro_frame_base_address
  2982. };
  2983. static const struct frame_base *
  2984. mips_micro_frame_base_sniffer (struct frame_info *this_frame)
  2985. {
  2986. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  2987. CORE_ADDR pc = get_frame_pc (this_frame);
  2988. if (mips_pc_is_micromips (gdbarch, pc))
  2989. return &mips_micro_frame_base;
  2990. else
  2991. return NULL;
  2992. }
  2993. /* Mark all the registers as unset in the saved_regs array
  2994. of THIS_CACHE. Do nothing if THIS_CACHE is null. */
  2995. static void
  2996. reset_saved_regs (struct gdbarch *gdbarch, struct mips_frame_cache *this_cache)
  2997. {
  2998. if (this_cache == NULL || this_cache->saved_regs == NULL)
  2999. return;
  3000. {
  3001. const int num_regs = gdbarch_num_regs (gdbarch);
  3002. int i;
  3003. /* Reset the register values to their default state. Register i's value
  3004. is in register i. */
  3005. for (i = 0; i < num_regs; i++)
  3006. this_cache->saved_regs[i].set_realreg (i);
  3007. }
  3008. }
  3009. /* Analyze the function prologue from START_PC to LIMIT_PC. Builds
  3010. the associated FRAME_CACHE if not null.
  3011. Return the address of the first instruction past the prologue. */
  3012. static CORE_ADDR
  3013. mips32_scan_prologue (struct gdbarch *gdbarch,
  3014. CORE_ADDR start_pc, CORE_ADDR limit_pc,
  3015. struct frame_info *this_frame,
  3016. struct mips_frame_cache *this_cache)
  3017. {
  3018. int prev_non_prologue_insn;
  3019. int this_non_prologue_insn;
  3020. int non_prologue_insns;
  3021. CORE_ADDR frame_addr = 0; /* Value of $r30. Used by gcc for
  3022. frame-pointer. */
  3023. int prev_delay_slot;
  3024. CORE_ADDR prev_pc;
  3025. CORE_ADDR cur_pc;
  3026. CORE_ADDR sp;
  3027. long frame_offset;
  3028. int frame_reg = MIPS_SP_REGNUM;
  3029. CORE_ADDR end_prologue_addr;
  3030. int seen_sp_adjust = 0;
  3031. int load_immediate_bytes = 0;
  3032. int in_delay_slot;
  3033. int regsize_is_64_bits = (mips_abi_regsize (gdbarch) == 8);
  3034. /* Can be called when there's no process, and hence when there's no
  3035. THIS_FRAME. */
  3036. if (this_frame != NULL)
  3037. sp = get_frame_register_signed (this_frame,
  3038. gdbarch_num_regs (gdbarch)
  3039. + MIPS_SP_REGNUM);
  3040. else
  3041. sp = 0;
  3042. if (limit_pc > start_pc + 200)
  3043. limit_pc = start_pc + 200;
  3044. restart:
  3045. prev_non_prologue_insn = 0;
  3046. non_prologue_insns = 0;
  3047. prev_delay_slot = 0;
  3048. prev_pc = start_pc;
  3049. /* Permit at most one non-prologue non-control-transfer instruction
  3050. in the middle which may have been reordered by the compiler for
  3051. optimisation. */
  3052. frame_offset = 0;
  3053. for (cur_pc = start_pc; cur_pc < limit_pc; cur_pc += MIPS_INSN32_SIZE)
  3054. {
  3055. unsigned long inst, high_word;
  3056. long offset;
  3057. int reg;
  3058. this_non_prologue_insn = 0;
  3059. in_delay_slot = 0;
  3060. /* Fetch the instruction. */
  3061. inst = (unsigned long) mips_fetch_instruction (gdbarch, ISA_MIPS,
  3062. cur_pc, NULL);
  3063. /* Save some code by pre-extracting some useful fields. */
  3064. high_word = (inst >> 16) & 0xffff;
  3065. offset = ((inst & 0xffff) ^ 0x8000) - 0x8000;
  3066. reg = high_word & 0x1f;
  3067. if (high_word == 0x27bd /* addiu $sp,$sp,-i */
  3068. || high_word == 0x23bd /* addi $sp,$sp,-i */
  3069. || high_word == 0x67bd) /* daddiu $sp,$sp,-i */
  3070. {
  3071. if (offset < 0) /* Negative stack adjustment? */
  3072. frame_offset -= offset;
  3073. else
  3074. /* Exit loop if a positive stack adjustment is found, which
  3075. usually means that the stack cleanup code in the function
  3076. epilogue is reached. */
  3077. break;
  3078. seen_sp_adjust = 1;
  3079. }
  3080. else if (((high_word & 0xFFE0) == 0xafa0) /* sw reg,offset($sp) */
  3081. && !regsize_is_64_bits)
  3082. {
  3083. set_reg_offset (gdbarch, this_cache, reg, sp + offset);
  3084. }
  3085. else if (((high_word & 0xFFE0) == 0xffa0) /* sd reg,offset($sp) */
  3086. && regsize_is_64_bits)
  3087. {
  3088. /* Irix 6.2 N32 ABI uses sd instructions for saving $gp and $ra. */
  3089. set_reg_offset (gdbarch, this_cache, reg, sp + offset);
  3090. }
  3091. else if (high_word == 0x27be) /* addiu $30,$sp,size */
  3092. {
  3093. /* Old gcc frame, r30 is virtual frame pointer. */
  3094. if (offset != frame_offset)
  3095. frame_addr = sp + offset;
  3096. else if (this_frame && frame_reg == MIPS_SP_REGNUM)
  3097. {
  3098. unsigned alloca_adjust;
  3099. frame_reg = 30;
  3100. frame_addr = get_frame_register_signed
  3101. (this_frame, gdbarch_num_regs (gdbarch) + 30);
  3102. frame_offset = 0;
  3103. alloca_adjust = (unsigned) (frame_addr - (sp + offset));
  3104. if (alloca_adjust > 0)
  3105. {
  3106. /* FP > SP + frame_size. This may be because of
  3107. an alloca or somethings similar. Fix sp to
  3108. "pre-alloca" value, and try again. */
  3109. sp += alloca_adjust;
  3110. /* Need to reset the status of all registers. Otherwise,
  3111. we will hit a guard that prevents the new address
  3112. for each register to be recomputed during the second
  3113. pass. */
  3114. reset_saved_regs (gdbarch, this_cache);
  3115. goto restart;
  3116. }
  3117. }
  3118. }
  3119. /* move $30,$sp. With different versions of gas this will be either
  3120. `addu $30,$sp,$zero' or `or $30,$sp,$zero' or `daddu 30,sp,$0'.
  3121. Accept any one of these. */
  3122. else if (inst == 0x03A0F021 || inst == 0x03a0f025 || inst == 0x03a0f02d)
  3123. {
  3124. /* New gcc frame, virtual frame pointer is at r30 + frame_size. */
  3125. if (this_frame && frame_reg == MIPS_SP_REGNUM)
  3126. {
  3127. unsigned alloca_adjust;
  3128. frame_reg = 30;
  3129. frame_addr = get_frame_register_signed
  3130. (this_frame, gdbarch_num_regs (gdbarch) + 30);
  3131. alloca_adjust = (unsigned) (frame_addr - sp);
  3132. if (alloca_adjust > 0)
  3133. {
  3134. /* FP > SP + frame_size. This may be because of
  3135. an alloca or somethings similar. Fix sp to
  3136. "pre-alloca" value, and try again. */
  3137. sp = frame_addr;
  3138. /* Need to reset the status of all registers. Otherwise,
  3139. we will hit a guard that prevents the new address
  3140. for each register to be recomputed during the second
  3141. pass. */
  3142. reset_saved_regs (gdbarch, this_cache);
  3143. goto restart;
  3144. }
  3145. }
  3146. }
  3147. else if ((high_word & 0xFFE0) == 0xafc0 /* sw reg,offset($30) */
  3148. && !regsize_is_64_bits)
  3149. {
  3150. set_reg_offset (gdbarch, this_cache, reg, frame_addr + offset);
  3151. }
  3152. else if ((high_word & 0xFFE0) == 0xE7A0 /* swc1 freg,n($sp) */
  3153. || (high_word & 0xF3E0) == 0xA3C0 /* sx reg,n($s8) */
  3154. || (inst & 0xFF9F07FF) == 0x00800021 /* move reg,$a0-$a3 */
  3155. || high_word == 0x3c1c /* lui $gp,n */
  3156. || high_word == 0x279c /* addiu $gp,$gp,n */
  3157. || inst == 0x0399e021 /* addu $gp,$gp,$t9 */
  3158. || inst == 0x033ce021 /* addu $gp,$t9,$gp */
  3159. )
  3160. {
  3161. /* These instructions are part of the prologue, but we don't
  3162. need to do anything special to handle them. */
  3163. }
  3164. /* The instructions below load $at or $t0 with an immediate
  3165. value in preparation for a stack adjustment via
  3166. subu $sp,$sp,[$at,$t0]. These instructions could also
  3167. initialize a local variable, so we accept them only before
  3168. a stack adjustment instruction was seen. */
  3169. else if (!seen_sp_adjust
  3170. && !prev_delay_slot
  3171. && (high_word == 0x3c01 /* lui $at,n */
  3172. || high_word == 0x3c08 /* lui $t0,n */
  3173. || high_word == 0x3421 /* ori $at,$at,n */
  3174. || high_word == 0x3508 /* ori $t0,$t0,n */
  3175. || high_word == 0x3401 /* ori $at,$zero,n */
  3176. || high_word == 0x3408 /* ori $t0,$zero,n */
  3177. ))
  3178. {
  3179. load_immediate_bytes += MIPS_INSN32_SIZE; /* FIXME! */
  3180. }
  3181. /* Check for branches and jumps. The instruction in the delay
  3182. slot can be a part of the prologue, so move forward once more. */
  3183. else if (mips32_instruction_has_delay_slot (gdbarch, inst))
  3184. {
  3185. in_delay_slot = 1;
  3186. }
  3187. /* This instruction is not an instruction typically found
  3188. in a prologue, so we must have reached the end of the
  3189. prologue. */
  3190. else
  3191. {
  3192. this_non_prologue_insn = 1;
  3193. }
  3194. non_prologue_insns += this_non_prologue_insn;
  3195. /* A jump or branch, or enough non-prologue insns seen? If so,
  3196. then we must have reached the end of the prologue by now. */
  3197. if (prev_delay_slot || non_prologue_insns > 1)
  3198. break;
  3199. prev_non_prologue_insn = this_non_prologue_insn;
  3200. prev_delay_slot = in_delay_slot;
  3201. prev_pc = cur_pc;
  3202. }
  3203. if (this_cache != NULL)
  3204. {
  3205. this_cache->base =
  3206. (get_frame_register_signed (this_frame,
  3207. gdbarch_num_regs (gdbarch) + frame_reg)
  3208. + frame_offset);
  3209. /* FIXME: brobecker/2004-09-15: We should be able to get rid of
  3210. this assignment below, eventually. But it's still needed
  3211. for now. */
  3212. this_cache->saved_regs[gdbarch_num_regs (gdbarch)
  3213. + mips_regnum (gdbarch)->pc]
  3214. = this_cache->saved_regs[gdbarch_num_regs (gdbarch)
  3215. + MIPS_RA_REGNUM];
  3216. }
  3217. /* Set end_prologue_addr to the address of the instruction immediately
  3218. after the last one we scanned. Unless the last one looked like a
  3219. non-prologue instruction (and we looked ahead), in which case use
  3220. its address instead. */
  3221. end_prologue_addr
  3222. = prev_non_prologue_insn || prev_delay_slot ? prev_pc : cur_pc;
  3223. /* In a frameless function, we might have incorrectly
  3224. skipped some load immediate instructions. Undo the skipping
  3225. if the load immediate was not followed by a stack adjustment. */
  3226. if (load_immediate_bytes && !seen_sp_adjust)
  3227. end_prologue_addr -= load_immediate_bytes;
  3228. return end_prologue_addr;
  3229. }
  3230. /* Heuristic unwinder for procedures using 32-bit instructions (covers
  3231. both 32-bit and 64-bit MIPS ISAs). Procedures using 16-bit
  3232. instructions (a.k.a. MIPS16) are handled by the mips_insn16
  3233. unwinder. Likewise microMIPS and the mips_micro unwinder. */
  3234. static struct mips_frame_cache *
  3235. mips_insn32_frame_cache (struct frame_info *this_frame, void **this_cache)
  3236. {
  3237. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  3238. struct mips_frame_cache *cache;
  3239. if ((*this_cache) != NULL)
  3240. return (struct mips_frame_cache *) (*this_cache);
  3241. cache = FRAME_OBSTACK_ZALLOC (struct mips_frame_cache);
  3242. (*this_cache) = cache;
  3243. cache->saved_regs = trad_frame_alloc_saved_regs (this_frame);
  3244. /* Analyze the function prologue. */
  3245. {
  3246. const CORE_ADDR pc = get_frame_address_in_block (this_frame);
  3247. CORE_ADDR start_addr;
  3248. find_pc_partial_function (pc, NULL, &start_addr, NULL);
  3249. if (start_addr == 0)
  3250. start_addr = heuristic_proc_start (gdbarch, pc);
  3251. /* We can't analyze the prologue if we couldn't find the begining
  3252. of the function. */
  3253. if (start_addr == 0)
  3254. return cache;
  3255. mips32_scan_prologue (gdbarch, start_addr, pc, this_frame,
  3256. (struct mips_frame_cache *) *this_cache);
  3257. }
  3258. /* gdbarch_sp_regnum contains the value and not the address. */
  3259. cache->saved_regs[gdbarch_num_regs (gdbarch)
  3260. + MIPS_SP_REGNUM].set_value (cache->base);
  3261. return (struct mips_frame_cache *) (*this_cache);
  3262. }
  3263. static void
  3264. mips_insn32_frame_this_id (struct frame_info *this_frame, void **this_cache,
  3265. struct frame_id *this_id)
  3266. {
  3267. struct mips_frame_cache *info = mips_insn32_frame_cache (this_frame,
  3268. this_cache);
  3269. /* This marks the outermost frame. */
  3270. if (info->base == 0)
  3271. return;
  3272. (*this_id) = frame_id_build (info->base, get_frame_func (this_frame));
  3273. }
  3274. static struct value *
  3275. mips_insn32_frame_prev_register (struct frame_info *this_frame,
  3276. void **this_cache, int regnum)
  3277. {
  3278. struct mips_frame_cache *info = mips_insn32_frame_cache (this_frame,
  3279. this_cache);
  3280. return trad_frame_get_prev_register (this_frame, info->saved_regs, regnum);
  3281. }
  3282. static int
  3283. mips_insn32_frame_sniffer (const struct frame_unwind *self,
  3284. struct frame_info *this_frame, void **this_cache)
  3285. {
  3286. CORE_ADDR pc = get_frame_pc (this_frame);
  3287. if (mips_pc_is_mips (pc))
  3288. return 1;
  3289. return 0;
  3290. }
  3291. static const struct frame_unwind mips_insn32_frame_unwind =
  3292. {
  3293. "mips insn32 prologue",
  3294. NORMAL_FRAME,
  3295. default_frame_unwind_stop_reason,
  3296. mips_insn32_frame_this_id,
  3297. mips_insn32_frame_prev_register,
  3298. NULL,
  3299. mips_insn32_frame_sniffer
  3300. };
  3301. static CORE_ADDR
  3302. mips_insn32_frame_base_address (struct frame_info *this_frame,
  3303. void **this_cache)
  3304. {
  3305. struct mips_frame_cache *info = mips_insn32_frame_cache (this_frame,
  3306. this_cache);
  3307. return info->base;
  3308. }
  3309. static const struct frame_base mips_insn32_frame_base =
  3310. {
  3311. &mips_insn32_frame_unwind,
  3312. mips_insn32_frame_base_address,
  3313. mips_insn32_frame_base_address,
  3314. mips_insn32_frame_base_address
  3315. };
  3316. static const struct frame_base *
  3317. mips_insn32_frame_base_sniffer (struct frame_info *this_frame)
  3318. {
  3319. CORE_ADDR pc = get_frame_pc (this_frame);
  3320. if (mips_pc_is_mips (pc))
  3321. return &mips_insn32_frame_base;
  3322. else
  3323. return NULL;
  3324. }
  3325. static struct trad_frame_cache *
  3326. mips_stub_frame_cache (struct frame_info *this_frame, void **this_cache)
  3327. {
  3328. CORE_ADDR pc;
  3329. CORE_ADDR start_addr;
  3330. CORE_ADDR stack_addr;
  3331. struct trad_frame_cache *this_trad_cache;
  3332. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  3333. int num_regs = gdbarch_num_regs (gdbarch);
  3334. if ((*this_cache) != NULL)
  3335. return (struct trad_frame_cache *) (*this_cache);
  3336. this_trad_cache = trad_frame_cache_zalloc (this_frame);
  3337. (*this_cache) = this_trad_cache;
  3338. /* The return address is in the link register. */
  3339. trad_frame_set_reg_realreg (this_trad_cache,
  3340. gdbarch_pc_regnum (gdbarch),
  3341. num_regs + MIPS_RA_REGNUM);
  3342. /* Frame ID, since it's a frameless / stackless function, no stack
  3343. space is allocated and SP on entry is the current SP. */
  3344. pc = get_frame_pc (this_frame);
  3345. find_pc_partial_function (pc, NULL, &start_addr, NULL);
  3346. stack_addr = get_frame_register_signed (this_frame,
  3347. num_regs + MIPS_SP_REGNUM);
  3348. trad_frame_set_id (this_trad_cache, frame_id_build (stack_addr, start_addr));
  3349. /* Assume that the frame's base is the same as the
  3350. stack-pointer. */
  3351. trad_frame_set_this_base (this_trad_cache, stack_addr);
  3352. return this_trad_cache;
  3353. }
  3354. static void
  3355. mips_stub_frame_this_id (struct frame_info *this_frame, void **this_cache,
  3356. struct frame_id *this_id)
  3357. {
  3358. struct trad_frame_cache *this_trad_cache
  3359. = mips_stub_frame_cache (this_frame, this_cache);
  3360. trad_frame_get_id (this_trad_cache, this_id);
  3361. }
  3362. static struct value *
  3363. mips_stub_frame_prev_register (struct frame_info *this_frame,
  3364. void **this_cache, int regnum)
  3365. {
  3366. struct trad_frame_cache *this_trad_cache
  3367. = mips_stub_frame_cache (this_frame, this_cache);
  3368. return trad_frame_get_register (this_trad_cache, this_frame, regnum);
  3369. }
  3370. static int
  3371. mips_stub_frame_sniffer (const struct frame_unwind *self,
  3372. struct frame_info *this_frame, void **this_cache)
  3373. {
  3374. gdb_byte dummy[4];
  3375. CORE_ADDR pc = get_frame_address_in_block (this_frame);
  3376. struct bound_minimal_symbol msym;
  3377. /* Use the stub unwinder for unreadable code. */
  3378. if (target_read_memory (get_frame_pc (this_frame), dummy, 4) != 0)
  3379. return 1;
  3380. if (in_plt_section (pc) || in_mips_stubs_section (pc))
  3381. return 1;
  3382. /* Calling a PIC function from a non-PIC function passes through a
  3383. stub. The stub for foo is named ".pic.foo". */
  3384. msym = lookup_minimal_symbol_by_pc (pc);
  3385. if (msym.minsym != NULL
  3386. && msym.minsym->linkage_name () != NULL
  3387. && startswith (msym.minsym->linkage_name (), ".pic."))
  3388. return 1;
  3389. return 0;
  3390. }
  3391. static const struct frame_unwind mips_stub_frame_unwind =
  3392. {
  3393. "mips stub",
  3394. NORMAL_FRAME,
  3395. default_frame_unwind_stop_reason,
  3396. mips_stub_frame_this_id,
  3397. mips_stub_frame_prev_register,
  3398. NULL,
  3399. mips_stub_frame_sniffer
  3400. };
  3401. static CORE_ADDR
  3402. mips_stub_frame_base_address (struct frame_info *this_frame,
  3403. void **this_cache)
  3404. {
  3405. struct trad_frame_cache *this_trad_cache
  3406. = mips_stub_frame_cache (this_frame, this_cache);
  3407. return trad_frame_get_this_base (this_trad_cache);
  3408. }
  3409. static const struct frame_base mips_stub_frame_base =
  3410. {
  3411. &mips_stub_frame_unwind,
  3412. mips_stub_frame_base_address,
  3413. mips_stub_frame_base_address,
  3414. mips_stub_frame_base_address
  3415. };
  3416. static const struct frame_base *
  3417. mips_stub_frame_base_sniffer (struct frame_info *this_frame)
  3418. {
  3419. if (mips_stub_frame_sniffer (&mips_stub_frame_unwind, this_frame, NULL))
  3420. return &mips_stub_frame_base;
  3421. else
  3422. return NULL;
  3423. }
  3424. /* mips_addr_bits_remove - remove useless address bits */
  3425. static CORE_ADDR
  3426. mips_addr_bits_remove (struct gdbarch *gdbarch, CORE_ADDR addr)
  3427. {
  3428. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  3429. if (mips_mask_address_p (tdep) && (((ULONGEST) addr) >> 32 == 0xffffffffUL))
  3430. /* This hack is a work-around for existing boards using PMON, the
  3431. simulator, and any other 64-bit targets that doesn't have true
  3432. 64-bit addressing. On these targets, the upper 32 bits of
  3433. addresses are ignored by the hardware. Thus, the PC or SP are
  3434. likely to have been sign extended to all 1s by instruction
  3435. sequences that load 32-bit addresses. For example, a typical
  3436. piece of code that loads an address is this:
  3437. lui $r2, <upper 16 bits>
  3438. ori $r2, <lower 16 bits>
  3439. But the lui sign-extends the value such that the upper 32 bits
  3440. may be all 1s. The workaround is simply to mask off these
  3441. bits. In the future, gcc may be changed to support true 64-bit
  3442. addressing, and this masking will have to be disabled. */
  3443. return addr &= 0xffffffffUL;
  3444. else
  3445. return addr;
  3446. }
  3447. /* Checks for an atomic sequence of instructions beginning with a LL/LLD
  3448. instruction and ending with a SC/SCD instruction. If such a sequence
  3449. is found, attempt to step through it. A breakpoint is placed at the end of
  3450. the sequence. */
  3451. /* Instructions used during single-stepping of atomic sequences, standard
  3452. ISA version. */
  3453. #define LL_OPCODE 0x30
  3454. #define LLD_OPCODE 0x34
  3455. #define SC_OPCODE 0x38
  3456. #define SCD_OPCODE 0x3c
  3457. static std::vector<CORE_ADDR>
  3458. mips_deal_with_atomic_sequence (struct gdbarch *gdbarch, CORE_ADDR pc)
  3459. {
  3460. CORE_ADDR breaks[2] = {CORE_ADDR_MAX, CORE_ADDR_MAX};
  3461. CORE_ADDR loc = pc;
  3462. CORE_ADDR branch_bp; /* Breakpoint at branch instruction's destination. */
  3463. ULONGEST insn;
  3464. int insn_count;
  3465. int index;
  3466. int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed). */
  3467. const int atomic_sequence_length = 16; /* Instruction sequence length. */
  3468. insn = mips_fetch_instruction (gdbarch, ISA_MIPS, loc, NULL);
  3469. /* Assume all atomic sequences start with a ll/lld instruction. */
  3470. if (itype_op (insn) != LL_OPCODE && itype_op (insn) != LLD_OPCODE)
  3471. return {};
  3472. /* Assume that no atomic sequence is longer than "atomic_sequence_length"
  3473. instructions. */
  3474. for (insn_count = 0; insn_count < atomic_sequence_length; ++insn_count)
  3475. {
  3476. int is_branch = 0;
  3477. loc += MIPS_INSN32_SIZE;
  3478. insn = mips_fetch_instruction (gdbarch, ISA_MIPS, loc, NULL);
  3479. /* Assume that there is at most one branch in the atomic
  3480. sequence. If a branch is found, put a breakpoint in its
  3481. destination address. */
  3482. switch (itype_op (insn))
  3483. {
  3484. case 0: /* SPECIAL */
  3485. if (rtype_funct (insn) >> 1 == 4) /* JR, JALR */
  3486. return {}; /* fallback to the standard single-step code. */
  3487. break;
  3488. case 1: /* REGIMM */
  3489. is_branch = ((itype_rt (insn) & 0xc) == 0 /* B{LT,GE}Z* */
  3490. || ((itype_rt (insn) & 0x1e) == 0
  3491. && itype_rs (insn) == 0)); /* BPOSGE* */
  3492. break;
  3493. case 2: /* J */
  3494. case 3: /* JAL */
  3495. return {}; /* fallback to the standard single-step code. */
  3496. case 4: /* BEQ */
  3497. case 5: /* BNE */
  3498. case 6: /* BLEZ */
  3499. case 7: /* BGTZ */
  3500. case 20: /* BEQL */
  3501. case 21: /* BNEL */
  3502. case 22: /* BLEZL */
  3503. case 23: /* BGTTL */
  3504. is_branch = 1;
  3505. break;
  3506. case 17: /* COP1 */
  3507. is_branch = ((itype_rs (insn) == 9 || itype_rs (insn) == 10)
  3508. && (itype_rt (insn) & 0x2) == 0);
  3509. if (is_branch) /* BC1ANY2F, BC1ANY2T, BC1ANY4F, BC1ANY4T */
  3510. break;
  3511. /* Fall through. */
  3512. case 18: /* COP2 */
  3513. case 19: /* COP3 */
  3514. is_branch = (itype_rs (insn) == 8); /* BCzF, BCzFL, BCzT, BCzTL */
  3515. break;
  3516. }
  3517. if (is_branch)
  3518. {
  3519. branch_bp = loc + mips32_relative_offset (insn) + 4;
  3520. if (last_breakpoint >= 1)
  3521. return {}; /* More than one branch found, fallback to the
  3522. standard single-step code. */
  3523. breaks[1] = branch_bp;
  3524. last_breakpoint++;
  3525. }
  3526. if (itype_op (insn) == SC_OPCODE || itype_op (insn) == SCD_OPCODE)
  3527. break;
  3528. }
  3529. /* Assume that the atomic sequence ends with a sc/scd instruction. */
  3530. if (itype_op (insn) != SC_OPCODE && itype_op (insn) != SCD_OPCODE)
  3531. return {};
  3532. loc += MIPS_INSN32_SIZE;
  3533. /* Insert a breakpoint right after the end of the atomic sequence. */
  3534. breaks[0] = loc;
  3535. /* Check for duplicated breakpoints. Check also for a breakpoint
  3536. placed (branch instruction's destination) in the atomic sequence. */
  3537. if (last_breakpoint && pc <= breaks[1] && breaks[1] <= breaks[0])
  3538. last_breakpoint = 0;
  3539. std::vector<CORE_ADDR> next_pcs;
  3540. /* Effectively inserts the breakpoints. */
  3541. for (index = 0; index <= last_breakpoint; index++)
  3542. next_pcs.push_back (breaks[index]);
  3543. return next_pcs;
  3544. }
  3545. static std::vector<CORE_ADDR>
  3546. micromips_deal_with_atomic_sequence (struct gdbarch *gdbarch,
  3547. CORE_ADDR pc)
  3548. {
  3549. const int atomic_sequence_length = 16; /* Instruction sequence length. */
  3550. int last_breakpoint = 0; /* Defaults to 0 (no breakpoints placed). */
  3551. CORE_ADDR breaks[2] = {CORE_ADDR_MAX, CORE_ADDR_MAX};
  3552. CORE_ADDR branch_bp = 0; /* Breakpoint at branch instruction's
  3553. destination. */
  3554. CORE_ADDR loc = pc;
  3555. int sc_found = 0;
  3556. ULONGEST insn;
  3557. int insn_count;
  3558. int index;
  3559. /* Assume all atomic sequences start with a ll/lld instruction. */
  3560. insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, loc, NULL);
  3561. if (micromips_op (insn) != 0x18) /* POOL32C: bits 011000 */
  3562. return {};
  3563. loc += MIPS_INSN16_SIZE;
  3564. insn <<= 16;
  3565. insn |= mips_fetch_instruction (gdbarch, ISA_MICROMIPS, loc, NULL);
  3566. if ((b12s4_op (insn) & 0xb) != 0x3) /* LL, LLD: bits 011000 0x11 */
  3567. return {};
  3568. loc += MIPS_INSN16_SIZE;
  3569. /* Assume all atomic sequences end with an sc/scd instruction. Assume
  3570. that no atomic sequence is longer than "atomic_sequence_length"
  3571. instructions. */
  3572. for (insn_count = 0;
  3573. !sc_found && insn_count < atomic_sequence_length;
  3574. ++insn_count)
  3575. {
  3576. int is_branch = 0;
  3577. insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, loc, NULL);
  3578. loc += MIPS_INSN16_SIZE;
  3579. /* Assume that there is at most one conditional branch in the
  3580. atomic sequence. If a branch is found, put a breakpoint in
  3581. its destination address. */
  3582. switch (mips_insn_size (ISA_MICROMIPS, insn))
  3583. {
  3584. /* 32-bit instructions. */
  3585. case 2 * MIPS_INSN16_SIZE:
  3586. switch (micromips_op (insn))
  3587. {
  3588. case 0x10: /* POOL32I: bits 010000 */
  3589. if ((b5s5_op (insn) & 0x18) != 0x0
  3590. /* BLTZ, BLTZAL, BGEZ, BGEZAL: 010000 000xx */
  3591. /* BLEZ, BNEZC, BGTZ, BEQZC: 010000 001xx */
  3592. && (b5s5_op (insn) & 0x1d) != 0x11
  3593. /* BLTZALS, BGEZALS: bits 010000 100x1 */
  3594. && ((b5s5_op (insn) & 0x1e) != 0x14
  3595. || (insn & 0x3) != 0x0)
  3596. /* BC2F, BC2T: bits 010000 1010x xxx00 */
  3597. && (b5s5_op (insn) & 0x1e) != 0x1a
  3598. /* BPOSGE64, BPOSGE32: bits 010000 1101x */
  3599. && ((b5s5_op (insn) & 0x1e) != 0x1c
  3600. || (insn & 0x3) != 0x0)
  3601. /* BC1F, BC1T: bits 010000 1110x xxx00 */
  3602. && ((b5s5_op (insn) & 0x1c) != 0x1c
  3603. || (insn & 0x3) != 0x1))
  3604. /* BC1ANY*: bits 010000 111xx xxx01 */
  3605. break;
  3606. /* Fall through. */
  3607. case 0x25: /* BEQ: bits 100101 */
  3608. case 0x2d: /* BNE: bits 101101 */
  3609. insn <<= 16;
  3610. insn |= mips_fetch_instruction (gdbarch,
  3611. ISA_MICROMIPS, loc, NULL);
  3612. branch_bp = (loc + MIPS_INSN16_SIZE
  3613. + micromips_relative_offset16 (insn));
  3614. is_branch = 1;
  3615. break;
  3616. case 0x00: /* POOL32A: bits 000000 */
  3617. insn <<= 16;
  3618. insn |= mips_fetch_instruction (gdbarch,
  3619. ISA_MICROMIPS, loc, NULL);
  3620. if (b0s6_op (insn) != 0x3c
  3621. /* POOL32Axf: bits 000000 ... 111100 */
  3622. || (b6s10_ext (insn) & 0x2bf) != 0x3c)
  3623. /* JALR, JALR.HB: 000000 000x111100 111100 */
  3624. /* JALRS, JALRS.HB: 000000 010x111100 111100 */
  3625. break;
  3626. /* Fall through. */
  3627. case 0x1d: /* JALS: bits 011101 */
  3628. case 0x35: /* J: bits 110101 */
  3629. case 0x3d: /* JAL: bits 111101 */
  3630. case 0x3c: /* JALX: bits 111100 */
  3631. return {}; /* Fall back to the standard single-step code. */
  3632. case 0x18: /* POOL32C: bits 011000 */
  3633. if ((b12s4_op (insn) & 0xb) == 0xb)
  3634. /* SC, SCD: bits 011000 1x11 */
  3635. sc_found = 1;
  3636. break;
  3637. }
  3638. loc += MIPS_INSN16_SIZE;
  3639. break;
  3640. /* 16-bit instructions. */
  3641. case MIPS_INSN16_SIZE:
  3642. switch (micromips_op (insn))
  3643. {
  3644. case 0x23: /* BEQZ16: bits 100011 */
  3645. case 0x2b: /* BNEZ16: bits 101011 */
  3646. branch_bp = loc + micromips_relative_offset7 (insn);
  3647. is_branch = 1;
  3648. break;
  3649. case 0x11: /* POOL16C: bits 010001 */
  3650. if ((b5s5_op (insn) & 0x1c) != 0xc
  3651. /* JR16, JRC, JALR16, JALRS16: 010001 011xx */
  3652. && b5s5_op (insn) != 0x18)
  3653. /* JRADDIUSP: bits 010001 11000 */
  3654. break;
  3655. return {}; /* Fall back to the standard single-step code. */
  3656. case 0x33: /* B16: bits 110011 */
  3657. return {}; /* Fall back to the standard single-step code. */
  3658. }
  3659. break;
  3660. }
  3661. if (is_branch)
  3662. {
  3663. if (last_breakpoint >= 1)
  3664. return {}; /* More than one branch found, fallback to the
  3665. standard single-step code. */
  3666. breaks[1] = branch_bp;
  3667. last_breakpoint++;
  3668. }
  3669. }
  3670. if (!sc_found)
  3671. return {};
  3672. /* Insert a breakpoint right after the end of the atomic sequence. */
  3673. breaks[0] = loc;
  3674. /* Check for duplicated breakpoints. Check also for a breakpoint
  3675. placed (branch instruction's destination) in the atomic sequence */
  3676. if (last_breakpoint && pc <= breaks[1] && breaks[1] <= breaks[0])
  3677. last_breakpoint = 0;
  3678. std::vector<CORE_ADDR> next_pcs;
  3679. /* Effectively inserts the breakpoints. */
  3680. for (index = 0; index <= last_breakpoint; index++)
  3681. next_pcs.push_back (breaks[index]);
  3682. return next_pcs;
  3683. }
  3684. static std::vector<CORE_ADDR>
  3685. deal_with_atomic_sequence (struct gdbarch *gdbarch, CORE_ADDR pc)
  3686. {
  3687. if (mips_pc_is_mips (pc))
  3688. return mips_deal_with_atomic_sequence (gdbarch, pc);
  3689. else if (mips_pc_is_micromips (gdbarch, pc))
  3690. return micromips_deal_with_atomic_sequence (gdbarch, pc);
  3691. else
  3692. return {};
  3693. }
  3694. /* mips_software_single_step() is called just before we want to resume
  3695. the inferior, if we want to single-step it but there is no hardware
  3696. or kernel single-step support (MIPS on GNU/Linux for example). We find
  3697. the target of the coming instruction and breakpoint it. */
  3698. std::vector<CORE_ADDR>
  3699. mips_software_single_step (struct regcache *regcache)
  3700. {
  3701. struct gdbarch *gdbarch = regcache->arch ();
  3702. CORE_ADDR pc, next_pc;
  3703. pc = regcache_read_pc (regcache);
  3704. std::vector<CORE_ADDR> next_pcs = deal_with_atomic_sequence (gdbarch, pc);
  3705. if (!next_pcs.empty ())
  3706. return next_pcs;
  3707. next_pc = mips_next_pc (regcache, pc);
  3708. return {next_pc};
  3709. }
  3710. /* Test whether the PC points to the return instruction at the
  3711. end of a function. */
  3712. static int
  3713. mips_about_to_return (struct gdbarch *gdbarch, CORE_ADDR pc)
  3714. {
  3715. ULONGEST insn;
  3716. ULONGEST hint;
  3717. /* This used to check for MIPS16, but this piece of code is never
  3718. called for MIPS16 functions. And likewise microMIPS ones. */
  3719. gdb_assert (mips_pc_is_mips (pc));
  3720. insn = mips_fetch_instruction (gdbarch, ISA_MIPS, pc, NULL);
  3721. hint = 0x7c0;
  3722. return (insn & ~hint) == 0x3e00008; /* jr(.hb) $ra */
  3723. }
  3724. /* This fencepost looks highly suspicious to me. Removing it also
  3725. seems suspicious as it could affect remote debugging across serial
  3726. lines. */
  3727. static CORE_ADDR
  3728. heuristic_proc_start (struct gdbarch *gdbarch, CORE_ADDR pc)
  3729. {
  3730. CORE_ADDR start_pc;
  3731. CORE_ADDR fence;
  3732. int instlen;
  3733. int seen_adjsp = 0;
  3734. struct inferior *inf;
  3735. pc = gdbarch_addr_bits_remove (gdbarch, pc);
  3736. start_pc = pc;
  3737. fence = start_pc - heuristic_fence_post;
  3738. if (start_pc == 0)
  3739. return 0;
  3740. if (heuristic_fence_post == -1 || fence < VM_MIN_ADDRESS)
  3741. fence = VM_MIN_ADDRESS;
  3742. instlen = mips_pc_is_mips (pc) ? MIPS_INSN32_SIZE : MIPS_INSN16_SIZE;
  3743. inf = current_inferior ();
  3744. /* Search back for previous return. */
  3745. for (start_pc -= instlen;; start_pc -= instlen)
  3746. if (start_pc < fence)
  3747. {
  3748. /* It's not clear to me why we reach this point when
  3749. stop_soon, but with this test, at least we
  3750. don't print out warnings for every child forked (eg, on
  3751. decstation). 22apr93 rich@cygnus.com. */
  3752. if (inf->control.stop_soon == NO_STOP_QUIETLY)
  3753. {
  3754. static int blurb_printed = 0;
  3755. warning (_("GDB can't find the start of the function at %s."),
  3756. paddress (gdbarch, pc));
  3757. if (!blurb_printed)
  3758. {
  3759. /* This actually happens frequently in embedded
  3760. development, when you first connect to a board
  3761. and your stack pointer and pc are nowhere in
  3762. particular. This message needs to give people
  3763. in that situation enough information to
  3764. determine that it's no big deal. */
  3765. gdb_printf ("\n\
  3766. GDB is unable to find the start of the function at %s\n\
  3767. and thus can't determine the size of that function's stack frame.\n\
  3768. This means that GDB may be unable to access that stack frame, or\n\
  3769. the frames below it.\n\
  3770. This problem is most likely caused by an invalid program counter or\n\
  3771. stack pointer.\n\
  3772. However, if you think GDB should simply search farther back\n\
  3773. from %s for code which looks like the beginning of a\n\
  3774. function, you can increase the range of the search using the `set\n\
  3775. heuristic-fence-post' command.\n",
  3776. paddress (gdbarch, pc), paddress (gdbarch, pc));
  3777. blurb_printed = 1;
  3778. }
  3779. }
  3780. return 0;
  3781. }
  3782. else if (mips_pc_is_mips16 (gdbarch, start_pc))
  3783. {
  3784. unsigned short inst;
  3785. /* On MIPS16, any one of the following is likely to be the
  3786. start of a function:
  3787. extend save
  3788. save
  3789. entry
  3790. addiu sp,-n
  3791. daddiu sp,-n
  3792. extend -n followed by 'addiu sp,+n' or 'daddiu sp,+n'. */
  3793. inst = mips_fetch_instruction (gdbarch, ISA_MIPS16, start_pc, NULL);
  3794. if ((inst & 0xff80) == 0x6480) /* save */
  3795. {
  3796. if (start_pc - instlen >= fence)
  3797. {
  3798. inst = mips_fetch_instruction (gdbarch, ISA_MIPS16,
  3799. start_pc - instlen, NULL);
  3800. if ((inst & 0xf800) == 0xf000) /* extend */
  3801. start_pc -= instlen;
  3802. }
  3803. break;
  3804. }
  3805. else if (((inst & 0xf81f) == 0xe809
  3806. && (inst & 0x700) != 0x700) /* entry */
  3807. || (inst & 0xff80) == 0x6380 /* addiu sp,-n */
  3808. || (inst & 0xff80) == 0xfb80 /* daddiu sp,-n */
  3809. || ((inst & 0xf810) == 0xf010 && seen_adjsp)) /* extend -n */
  3810. break;
  3811. else if ((inst & 0xff00) == 0x6300 /* addiu sp */
  3812. || (inst & 0xff00) == 0xfb00) /* daddiu sp */
  3813. seen_adjsp = 1;
  3814. else
  3815. seen_adjsp = 0;
  3816. }
  3817. else if (mips_pc_is_micromips (gdbarch, start_pc))
  3818. {
  3819. ULONGEST insn;
  3820. int stop = 0;
  3821. long offset;
  3822. int dreg;
  3823. int sreg;
  3824. /* On microMIPS, any one of the following is likely to be the
  3825. start of a function:
  3826. ADDIUSP -imm
  3827. (D)ADDIU $sp, -imm
  3828. LUI $gp, imm */
  3829. insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, NULL);
  3830. switch (micromips_op (insn))
  3831. {
  3832. case 0xc: /* ADDIU: bits 001100 */
  3833. case 0x17: /* DADDIU: bits 010111 */
  3834. sreg = b0s5_reg (insn);
  3835. dreg = b5s5_reg (insn);
  3836. insn <<= 16;
  3837. insn |= mips_fetch_instruction (gdbarch, ISA_MICROMIPS,
  3838. pc + MIPS_INSN16_SIZE, NULL);
  3839. offset = (b0s16_imm (insn) ^ 0x8000) - 0x8000;
  3840. if (sreg == MIPS_SP_REGNUM && dreg == MIPS_SP_REGNUM
  3841. /* (D)ADDIU $sp, imm */
  3842. && offset < 0)
  3843. stop = 1;
  3844. break;
  3845. case 0x10: /* POOL32I: bits 010000 */
  3846. if (b5s5_op (insn) == 0xd
  3847. /* LUI: bits 010000 001101 */
  3848. && b0s5_reg (insn >> 16) == 28)
  3849. /* LUI $gp, imm */
  3850. stop = 1;
  3851. break;
  3852. case 0x13: /* POOL16D: bits 010011 */
  3853. if ((insn & 0x1) == 0x1)
  3854. /* ADDIUSP: bits 010011 1 */
  3855. {
  3856. offset = micromips_decode_imm9 (b1s9_imm (insn));
  3857. if (offset < 0)
  3858. /* ADDIUSP -imm */
  3859. stop = 1;
  3860. }
  3861. else
  3862. /* ADDIUS5: bits 010011 0 */
  3863. {
  3864. dreg = b5s5_reg (insn);
  3865. offset = (b1s4_imm (insn) ^ 8) - 8;
  3866. if (dreg == MIPS_SP_REGNUM && offset < 0)
  3867. /* ADDIUS5 $sp, -imm */
  3868. stop = 1;
  3869. }
  3870. break;
  3871. }
  3872. if (stop)
  3873. break;
  3874. }
  3875. else if (mips_about_to_return (gdbarch, start_pc))
  3876. {
  3877. /* Skip return and its delay slot. */
  3878. start_pc += 2 * MIPS_INSN32_SIZE;
  3879. break;
  3880. }
  3881. return start_pc;
  3882. }
  3883. struct mips_objfile_private
  3884. {
  3885. bfd_size_type size;
  3886. char *contents;
  3887. };
  3888. /* According to the current ABI, should the type be passed in a
  3889. floating-point register (assuming that there is space)? When there
  3890. is no FPU, FP are not even considered as possible candidates for
  3891. FP registers and, consequently this returns false - forces FP
  3892. arguments into integer registers. */
  3893. static int
  3894. fp_register_arg_p (struct gdbarch *gdbarch, enum type_code typecode,
  3895. struct type *arg_type)
  3896. {
  3897. return ((typecode == TYPE_CODE_FLT
  3898. || (mips_eabi (gdbarch)
  3899. && (typecode == TYPE_CODE_STRUCT
  3900. || typecode == TYPE_CODE_UNION)
  3901. && arg_type->num_fields () == 1
  3902. && check_typedef (arg_type->field (0).type ())->code ()
  3903. == TYPE_CODE_FLT))
  3904. && mips_get_fpu_type (gdbarch) != MIPS_FPU_NONE);
  3905. }
  3906. /* On o32, argument passing in GPRs depends on the alignment of the type being
  3907. passed. Return 1 if this type must be aligned to a doubleword boundary. */
  3908. static int
  3909. mips_type_needs_double_align (struct type *type)
  3910. {
  3911. enum type_code typecode = type->code ();
  3912. if (typecode == TYPE_CODE_FLT && TYPE_LENGTH (type) == 8)
  3913. return 1;
  3914. else if (typecode == TYPE_CODE_STRUCT)
  3915. {
  3916. if (type->num_fields () < 1)
  3917. return 0;
  3918. return mips_type_needs_double_align (type->field (0).type ());
  3919. }
  3920. else if (typecode == TYPE_CODE_UNION)
  3921. {
  3922. int i, n;
  3923. n = type->num_fields ();
  3924. for (i = 0; i < n; i++)
  3925. if (mips_type_needs_double_align (type->field (i).type ()))
  3926. return 1;
  3927. return 0;
  3928. }
  3929. return 0;
  3930. }
  3931. /* Adjust the address downward (direction of stack growth) so that it
  3932. is correctly aligned for a new stack frame. */
  3933. static CORE_ADDR
  3934. mips_frame_align (struct gdbarch *gdbarch, CORE_ADDR addr)
  3935. {
  3936. return align_down (addr, 16);
  3937. }
  3938. /* Implement the "push_dummy_code" gdbarch method. */
  3939. static CORE_ADDR
  3940. mips_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp,
  3941. CORE_ADDR funaddr, struct value **args,
  3942. int nargs, struct type *value_type,
  3943. CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
  3944. struct regcache *regcache)
  3945. {
  3946. static gdb_byte nop_insn[] = { 0, 0, 0, 0 };
  3947. CORE_ADDR nop_addr;
  3948. CORE_ADDR bp_slot;
  3949. /* Reserve enough room on the stack for our breakpoint instruction. */
  3950. bp_slot = sp - sizeof (nop_insn);
  3951. /* Return to microMIPS mode if calling microMIPS code to avoid
  3952. triggering an address error exception on processors that only
  3953. support microMIPS execution. */
  3954. *bp_addr = (mips_pc_is_micromips (gdbarch, funaddr)
  3955. ? make_compact_addr (bp_slot) : bp_slot);
  3956. /* The breakpoint layer automatically adjusts the address of
  3957. breakpoints inserted in a branch delay slot. With enough
  3958. bad luck, the 4 bytes located just before our breakpoint
  3959. instruction could look like a branch instruction, and thus
  3960. trigger the adjustement, and break the function call entirely.
  3961. So, we reserve those 4 bytes and write a nop instruction
  3962. to prevent that from happening. */
  3963. nop_addr = bp_slot - sizeof (nop_insn);
  3964. write_memory (nop_addr, nop_insn, sizeof (nop_insn));
  3965. sp = mips_frame_align (gdbarch, nop_addr);
  3966. /* Inferior resumes at the function entry point. */
  3967. *real_pc = funaddr;
  3968. return sp;
  3969. }
  3970. static CORE_ADDR
  3971. mips_eabi_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
  3972. struct regcache *regcache, CORE_ADDR bp_addr,
  3973. int nargs, struct value **args, CORE_ADDR sp,
  3974. function_call_return_method return_method,
  3975. CORE_ADDR struct_addr)
  3976. {
  3977. int argreg;
  3978. int float_argreg;
  3979. int argnum;
  3980. int arg_space = 0;
  3981. int stack_offset = 0;
  3982. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  3983. CORE_ADDR func_addr = find_function_addr (function, NULL);
  3984. int abi_regsize = mips_abi_regsize (gdbarch);
  3985. /* For shared libraries, "t9" needs to point at the function
  3986. address. */
  3987. regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr);
  3988. /* Set the return address register to point to the entry point of
  3989. the program, where a breakpoint lies in wait. */
  3990. regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr);
  3991. /* First ensure that the stack and structure return address (if any)
  3992. are properly aligned. The stack has to be at least 64-bit
  3993. aligned even on 32-bit machines, because doubles must be 64-bit
  3994. aligned. For n32 and n64, stack frames need to be 128-bit
  3995. aligned, so we round to this widest known alignment. */
  3996. sp = align_down (sp, 16);
  3997. struct_addr = align_down (struct_addr, 16);
  3998. /* Now make space on the stack for the args. We allocate more
  3999. than necessary for EABI, because the first few arguments are
  4000. passed in registers, but that's OK. */
  4001. for (argnum = 0; argnum < nargs; argnum++)
  4002. arg_space += align_up (TYPE_LENGTH (value_type (args[argnum])), abi_regsize);
  4003. sp -= align_up (arg_space, 16);
  4004. if (mips_debug)
  4005. gdb_printf (gdb_stdlog,
  4006. "mips_eabi_push_dummy_call: sp=%s allocated %ld\n",
  4007. paddress (gdbarch, sp),
  4008. (long) align_up (arg_space, 16));
  4009. /* Initialize the integer and float register pointers. */
  4010. argreg = MIPS_A0_REGNUM;
  4011. float_argreg = mips_fpa0_regnum (gdbarch);
  4012. /* The struct_return pointer occupies the first parameter-passing reg. */
  4013. if (return_method == return_method_struct)
  4014. {
  4015. if (mips_debug)
  4016. gdb_printf (gdb_stdlog,
  4017. "mips_eabi_push_dummy_call: "
  4018. "struct_return reg=%d %s\n",
  4019. argreg, paddress (gdbarch, struct_addr));
  4020. regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
  4021. }
  4022. /* Now load as many as possible of the first arguments into
  4023. registers, and push the rest onto the stack. Loop thru args
  4024. from first to last. */
  4025. for (argnum = 0; argnum < nargs; argnum++)
  4026. {
  4027. const gdb_byte *val;
  4028. /* This holds the address of structures that are passed by
  4029. reference. */
  4030. gdb_byte ref_valbuf[MAX_MIPS_ABI_REGSIZE];
  4031. struct value *arg = args[argnum];
  4032. struct type *arg_type = check_typedef (value_type (arg));
  4033. int len = TYPE_LENGTH (arg_type);
  4034. enum type_code typecode = arg_type->code ();
  4035. if (mips_debug)
  4036. gdb_printf (gdb_stdlog,
  4037. "mips_eabi_push_dummy_call: %d len=%d type=%d",
  4038. argnum + 1, len, (int) typecode);
  4039. /* The EABI passes structures that do not fit in a register by
  4040. reference. */
  4041. if (len > abi_regsize
  4042. && (typecode == TYPE_CODE_STRUCT || typecode == TYPE_CODE_UNION))
  4043. {
  4044. gdb_assert (abi_regsize <= ARRAY_SIZE (ref_valbuf));
  4045. store_unsigned_integer (ref_valbuf, abi_regsize, byte_order,
  4046. value_address (arg));
  4047. typecode = TYPE_CODE_PTR;
  4048. len = abi_regsize;
  4049. val = ref_valbuf;
  4050. if (mips_debug)
  4051. gdb_printf (gdb_stdlog, " push");
  4052. }
  4053. else
  4054. val = value_contents (arg).data ();
  4055. /* 32-bit ABIs always start floating point arguments in an
  4056. even-numbered floating point register. Round the FP register
  4057. up before the check to see if there are any FP registers
  4058. left. Non MIPS_EABI targets also pass the FP in the integer
  4059. registers so also round up normal registers. */
  4060. if (abi_regsize < 8 && fp_register_arg_p (gdbarch, typecode, arg_type))
  4061. {
  4062. if ((float_argreg & 1))
  4063. float_argreg++;
  4064. }
  4065. /* Floating point arguments passed in registers have to be
  4066. treated specially. On 32-bit architectures, doubles
  4067. are passed in register pairs; the even register gets
  4068. the low word, and the odd register gets the high word.
  4069. On non-EABI processors, the first two floating point arguments are
  4070. also copied to general registers, because MIPS16 functions
  4071. don't use float registers for arguments. This duplication of
  4072. arguments in general registers can't hurt non-MIPS16 functions
  4073. because those registers are normally skipped. */
  4074. /* MIPS_EABI squeezes a struct that contains a single floating
  4075. point value into an FP register instead of pushing it onto the
  4076. stack. */
  4077. if (fp_register_arg_p (gdbarch, typecode, arg_type)
  4078. && float_argreg <= mips_last_fp_arg_regnum (gdbarch))
  4079. {
  4080. /* EABI32 will pass doubles in consecutive registers, even on
  4081. 64-bit cores. At one time, we used to check the size of
  4082. `float_argreg' to determine whether or not to pass doubles
  4083. in consecutive registers, but this is not sufficient for
  4084. making the ABI determination. */
  4085. if (len == 8 && mips_abi (gdbarch) == MIPS_ABI_EABI32)
  4086. {
  4087. int low_offset = gdbarch_byte_order (gdbarch)
  4088. == BFD_ENDIAN_BIG ? 4 : 0;
  4089. long regval;
  4090. /* Write the low word of the double to the even register(s). */
  4091. regval = extract_signed_integer (val + low_offset,
  4092. 4, byte_order);
  4093. if (mips_debug)
  4094. gdb_printf (gdb_stdlog, " - fpreg=%d val=%s",
  4095. float_argreg, phex (regval, 4));
  4096. regcache_cooked_write_signed (regcache, float_argreg++, regval);
  4097. /* Write the high word of the double to the odd register(s). */
  4098. regval = extract_signed_integer (val + 4 - low_offset,
  4099. 4, byte_order);
  4100. if (mips_debug)
  4101. gdb_printf (gdb_stdlog, " - fpreg=%d val=%s",
  4102. float_argreg, phex (regval, 4));
  4103. regcache_cooked_write_signed (regcache, float_argreg++, regval);
  4104. }
  4105. else
  4106. {
  4107. /* This is a floating point value that fits entirely
  4108. in a single register. */
  4109. /* On 32 bit ABI's the float_argreg is further adjusted
  4110. above to ensure that it is even register aligned. */
  4111. LONGEST regval = extract_signed_integer (val, len, byte_order);
  4112. if (mips_debug)
  4113. gdb_printf (gdb_stdlog, " - fpreg=%d val=%s",
  4114. float_argreg, phex (regval, len));
  4115. regcache_cooked_write_signed (regcache, float_argreg++, regval);
  4116. }
  4117. }
  4118. else
  4119. {
  4120. /* Copy the argument to general registers or the stack in
  4121. register-sized pieces. Large arguments are split between
  4122. registers and stack. */
  4123. /* Note: structs whose size is not a multiple of abi_regsize
  4124. are treated specially: Irix cc passes
  4125. them in registers where gcc sometimes puts them on the
  4126. stack. For maximum compatibility, we will put them in
  4127. both places. */
  4128. int odd_sized_struct = (len > abi_regsize && len % abi_regsize != 0);
  4129. /* Note: Floating-point values that didn't fit into an FP
  4130. register are only written to memory. */
  4131. while (len > 0)
  4132. {
  4133. /* Remember if the argument was written to the stack. */
  4134. int stack_used_p = 0;
  4135. int partial_len = (len < abi_regsize ? len : abi_regsize);
  4136. if (mips_debug)
  4137. gdb_printf (gdb_stdlog, " -- partial=%d",
  4138. partial_len);
  4139. /* Write this portion of the argument to the stack. */
  4140. if (argreg > mips_last_arg_regnum (gdbarch)
  4141. || odd_sized_struct
  4142. || fp_register_arg_p (gdbarch, typecode, arg_type))
  4143. {
  4144. /* Should shorter than int integer values be
  4145. promoted to int before being stored? */
  4146. int longword_offset = 0;
  4147. CORE_ADDR addr;
  4148. stack_used_p = 1;
  4149. if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  4150. {
  4151. if (abi_regsize == 8
  4152. && (typecode == TYPE_CODE_INT
  4153. || typecode == TYPE_CODE_PTR
  4154. || typecode == TYPE_CODE_FLT) && len <= 4)
  4155. longword_offset = abi_regsize - len;
  4156. else if ((typecode == TYPE_CODE_STRUCT
  4157. || typecode == TYPE_CODE_UNION)
  4158. && TYPE_LENGTH (arg_type) < abi_regsize)
  4159. longword_offset = abi_regsize - len;
  4160. }
  4161. if (mips_debug)
  4162. {
  4163. gdb_printf (gdb_stdlog, " - stack_offset=%s",
  4164. paddress (gdbarch, stack_offset));
  4165. gdb_printf (gdb_stdlog, " longword_offset=%s",
  4166. paddress (gdbarch, longword_offset));
  4167. }
  4168. addr = sp + stack_offset + longword_offset;
  4169. if (mips_debug)
  4170. {
  4171. int i;
  4172. gdb_printf (gdb_stdlog, " @%s ",
  4173. paddress (gdbarch, addr));
  4174. for (i = 0; i < partial_len; i++)
  4175. {
  4176. gdb_printf (gdb_stdlog, "%02x",
  4177. val[i] & 0xff);
  4178. }
  4179. }
  4180. write_memory (addr, val, partial_len);
  4181. }
  4182. /* Note!!! This is NOT an else clause. Odd sized
  4183. structs may go thru BOTH paths. Floating point
  4184. arguments will not. */
  4185. /* Write this portion of the argument to a general
  4186. purpose register. */
  4187. if (argreg <= mips_last_arg_regnum (gdbarch)
  4188. && !fp_register_arg_p (gdbarch, typecode, arg_type))
  4189. {
  4190. LONGEST regval =
  4191. extract_signed_integer (val, partial_len, byte_order);
  4192. if (mips_debug)
  4193. gdb_printf (gdb_stdlog, " - reg=%d val=%s",
  4194. argreg,
  4195. phex (regval, abi_regsize));
  4196. regcache_cooked_write_signed (regcache, argreg, regval);
  4197. argreg++;
  4198. }
  4199. len -= partial_len;
  4200. val += partial_len;
  4201. /* Compute the offset into the stack at which we will
  4202. copy the next parameter.
  4203. In the new EABI (and the NABI32), the stack_offset
  4204. only needs to be adjusted when it has been used. */
  4205. if (stack_used_p)
  4206. stack_offset += align_up (partial_len, abi_regsize);
  4207. }
  4208. }
  4209. if (mips_debug)
  4210. gdb_printf (gdb_stdlog, "\n");
  4211. }
  4212. regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
  4213. /* Return adjusted stack pointer. */
  4214. return sp;
  4215. }
  4216. /* Determine the return value convention being used. */
  4217. static enum return_value_convention
  4218. mips_eabi_return_value (struct gdbarch *gdbarch, struct value *function,
  4219. struct type *type, struct regcache *regcache,
  4220. gdb_byte *readbuf, const gdb_byte *writebuf)
  4221. {
  4222. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  4223. int fp_return_type = 0;
  4224. int offset, regnum, xfer;
  4225. if (TYPE_LENGTH (type) > 2 * mips_abi_regsize (gdbarch))
  4226. return RETURN_VALUE_STRUCT_CONVENTION;
  4227. /* Floating point type? */
  4228. if (tdep->mips_fpu_type != MIPS_FPU_NONE)
  4229. {
  4230. if (type->code () == TYPE_CODE_FLT)
  4231. fp_return_type = 1;
  4232. /* Structs with a single field of float type
  4233. are returned in a floating point register. */
  4234. if ((type->code () == TYPE_CODE_STRUCT
  4235. || type->code () == TYPE_CODE_UNION)
  4236. && type->num_fields () == 1)
  4237. {
  4238. struct type *fieldtype = type->field (0).type ();
  4239. if (check_typedef (fieldtype)->code () == TYPE_CODE_FLT)
  4240. fp_return_type = 1;
  4241. }
  4242. }
  4243. if (fp_return_type)
  4244. {
  4245. /* A floating-point value belongs in the least significant part
  4246. of FP0/FP1. */
  4247. if (mips_debug)
  4248. gdb_printf (gdb_stderr, "Return float in $fp0\n");
  4249. regnum = mips_regnum (gdbarch)->fp0;
  4250. }
  4251. else
  4252. {
  4253. /* An integer value goes in V0/V1. */
  4254. if (mips_debug)
  4255. gdb_printf (gdb_stderr, "Return scalar in $v0\n");
  4256. regnum = MIPS_V0_REGNUM;
  4257. }
  4258. for (offset = 0;
  4259. offset < TYPE_LENGTH (type);
  4260. offset += mips_abi_regsize (gdbarch), regnum++)
  4261. {
  4262. xfer = mips_abi_regsize (gdbarch);
  4263. if (offset + xfer > TYPE_LENGTH (type))
  4264. xfer = TYPE_LENGTH (type) - offset;
  4265. mips_xfer_register (gdbarch, regcache,
  4266. gdbarch_num_regs (gdbarch) + regnum, xfer,
  4267. gdbarch_byte_order (gdbarch), readbuf, writebuf,
  4268. offset);
  4269. }
  4270. return RETURN_VALUE_REGISTER_CONVENTION;
  4271. }
  4272. /* N32/N64 ABI stuff. */
  4273. /* Search for a naturally aligned double at OFFSET inside a struct
  4274. ARG_TYPE. The N32 / N64 ABIs pass these in floating point
  4275. registers. */
  4276. static int
  4277. mips_n32n64_fp_arg_chunk_p (struct gdbarch *gdbarch, struct type *arg_type,
  4278. int offset)
  4279. {
  4280. int i;
  4281. if (arg_type->code () != TYPE_CODE_STRUCT)
  4282. return 0;
  4283. if (mips_get_fpu_type (gdbarch) != MIPS_FPU_DOUBLE)
  4284. return 0;
  4285. if (TYPE_LENGTH (arg_type) < offset + MIPS64_REGSIZE)
  4286. return 0;
  4287. for (i = 0; i < arg_type->num_fields (); i++)
  4288. {
  4289. int pos;
  4290. struct type *field_type;
  4291. /* We're only looking at normal fields. */
  4292. if (field_is_static (&arg_type->field (i))
  4293. || (arg_type->field (i).loc_bitpos () % 8) != 0)
  4294. continue;
  4295. /* If we have gone past the offset, there is no double to pass. */
  4296. pos = arg_type->field (i).loc_bitpos () / 8;
  4297. if (pos > offset)
  4298. return 0;
  4299. field_type = check_typedef (arg_type->field (i).type ());
  4300. /* If this field is entirely before the requested offset, go
  4301. on to the next one. */
  4302. if (pos + TYPE_LENGTH (field_type) <= offset)
  4303. continue;
  4304. /* If this is our special aligned double, we can stop. */
  4305. if (field_type->code () == TYPE_CODE_FLT
  4306. && TYPE_LENGTH (field_type) == MIPS64_REGSIZE)
  4307. return 1;
  4308. /* This field starts at or before the requested offset, and
  4309. overlaps it. If it is a structure, recurse inwards. */
  4310. return mips_n32n64_fp_arg_chunk_p (gdbarch, field_type, offset - pos);
  4311. }
  4312. return 0;
  4313. }
  4314. static CORE_ADDR
  4315. mips_n32n64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
  4316. struct regcache *regcache, CORE_ADDR bp_addr,
  4317. int nargs, struct value **args, CORE_ADDR sp,
  4318. function_call_return_method return_method,
  4319. CORE_ADDR struct_addr)
  4320. {
  4321. int argreg;
  4322. int float_argreg;
  4323. int argnum;
  4324. int arg_space = 0;
  4325. int stack_offset = 0;
  4326. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  4327. CORE_ADDR func_addr = find_function_addr (function, NULL);
  4328. /* For shared libraries, "t9" needs to point at the function
  4329. address. */
  4330. regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr);
  4331. /* Set the return address register to point to the entry point of
  4332. the program, where a breakpoint lies in wait. */
  4333. regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr);
  4334. /* First ensure that the stack and structure return address (if any)
  4335. are properly aligned. The stack has to be at least 64-bit
  4336. aligned even on 32-bit machines, because doubles must be 64-bit
  4337. aligned. For n32 and n64, stack frames need to be 128-bit
  4338. aligned, so we round to this widest known alignment. */
  4339. sp = align_down (sp, 16);
  4340. struct_addr = align_down (struct_addr, 16);
  4341. /* Now make space on the stack for the args. */
  4342. for (argnum = 0; argnum < nargs; argnum++)
  4343. arg_space += align_up (TYPE_LENGTH (value_type (args[argnum])), MIPS64_REGSIZE);
  4344. sp -= align_up (arg_space, 16);
  4345. if (mips_debug)
  4346. gdb_printf (gdb_stdlog,
  4347. "mips_n32n64_push_dummy_call: sp=%s allocated %ld\n",
  4348. paddress (gdbarch, sp),
  4349. (long) align_up (arg_space, 16));
  4350. /* Initialize the integer and float register pointers. */
  4351. argreg = MIPS_A0_REGNUM;
  4352. float_argreg = mips_fpa0_regnum (gdbarch);
  4353. /* The struct_return pointer occupies the first parameter-passing reg. */
  4354. if (return_method == return_method_struct)
  4355. {
  4356. if (mips_debug)
  4357. gdb_printf (gdb_stdlog,
  4358. "mips_n32n64_push_dummy_call: "
  4359. "struct_return reg=%d %s\n",
  4360. argreg, paddress (gdbarch, struct_addr));
  4361. regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
  4362. }
  4363. /* Now load as many as possible of the first arguments into
  4364. registers, and push the rest onto the stack. Loop thru args
  4365. from first to last. */
  4366. for (argnum = 0; argnum < nargs; argnum++)
  4367. {
  4368. const gdb_byte *val;
  4369. struct value *arg = args[argnum];
  4370. struct type *arg_type = check_typedef (value_type (arg));
  4371. int len = TYPE_LENGTH (arg_type);
  4372. enum type_code typecode = arg_type->code ();
  4373. if (mips_debug)
  4374. gdb_printf (gdb_stdlog,
  4375. "mips_n32n64_push_dummy_call: %d len=%d type=%d",
  4376. argnum + 1, len, (int) typecode);
  4377. val = value_contents (arg).data ();
  4378. /* A 128-bit long double value requires an even-odd pair of
  4379. floating-point registers. */
  4380. if (len == 16
  4381. && fp_register_arg_p (gdbarch, typecode, arg_type)
  4382. && (float_argreg & 1))
  4383. {
  4384. float_argreg++;
  4385. argreg++;
  4386. }
  4387. if (fp_register_arg_p (gdbarch, typecode, arg_type)
  4388. && argreg <= mips_last_arg_regnum (gdbarch))
  4389. {
  4390. /* This is a floating point value that fits entirely
  4391. in a single register or a pair of registers. */
  4392. int reglen = (len <= MIPS64_REGSIZE ? len : MIPS64_REGSIZE);
  4393. LONGEST regval = extract_unsigned_integer (val, reglen, byte_order);
  4394. if (mips_debug)
  4395. gdb_printf (gdb_stdlog, " - fpreg=%d val=%s",
  4396. float_argreg, phex (regval, reglen));
  4397. regcache_cooked_write_unsigned (regcache, float_argreg, regval);
  4398. if (mips_debug)
  4399. gdb_printf (gdb_stdlog, " - reg=%d val=%s",
  4400. argreg, phex (regval, reglen));
  4401. regcache_cooked_write_unsigned (regcache, argreg, regval);
  4402. float_argreg++;
  4403. argreg++;
  4404. if (len == 16)
  4405. {
  4406. regval = extract_unsigned_integer (val + reglen,
  4407. reglen, byte_order);
  4408. if (mips_debug)
  4409. gdb_printf (gdb_stdlog, " - fpreg=%d val=%s",
  4410. float_argreg, phex (regval, reglen));
  4411. regcache_cooked_write_unsigned (regcache, float_argreg, regval);
  4412. if (mips_debug)
  4413. gdb_printf (gdb_stdlog, " - reg=%d val=%s",
  4414. argreg, phex (regval, reglen));
  4415. regcache_cooked_write_unsigned (regcache, argreg, regval);
  4416. float_argreg++;
  4417. argreg++;
  4418. }
  4419. }
  4420. else
  4421. {
  4422. /* Copy the argument to general registers or the stack in
  4423. register-sized pieces. Large arguments are split between
  4424. registers and stack. */
  4425. /* For N32/N64, structs, unions, or other composite types are
  4426. treated as a sequence of doublewords, and are passed in integer
  4427. or floating point registers as though they were simple scalar
  4428. parameters to the extent that they fit, with any excess on the
  4429. stack packed according to the normal memory layout of the
  4430. object.
  4431. The caller does not reserve space for the register arguments;
  4432. the callee is responsible for reserving it if required. */
  4433. /* Note: Floating-point values that didn't fit into an FP
  4434. register are only written to memory. */
  4435. while (len > 0)
  4436. {
  4437. /* Remember if the argument was written to the stack. */
  4438. int stack_used_p = 0;
  4439. int partial_len = (len < MIPS64_REGSIZE ? len : MIPS64_REGSIZE);
  4440. if (mips_debug)
  4441. gdb_printf (gdb_stdlog, " -- partial=%d",
  4442. partial_len);
  4443. if (fp_register_arg_p (gdbarch, typecode, arg_type))
  4444. gdb_assert (argreg > mips_last_arg_regnum (gdbarch));
  4445. /* Write this portion of the argument to the stack. */
  4446. if (argreg > mips_last_arg_regnum (gdbarch))
  4447. {
  4448. /* Should shorter than int integer values be
  4449. promoted to int before being stored? */
  4450. int longword_offset = 0;
  4451. CORE_ADDR addr;
  4452. stack_used_p = 1;
  4453. if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  4454. {
  4455. if ((typecode == TYPE_CODE_INT
  4456. || typecode == TYPE_CODE_PTR)
  4457. && len <= 4)
  4458. longword_offset = MIPS64_REGSIZE - len;
  4459. }
  4460. if (mips_debug)
  4461. {
  4462. gdb_printf (gdb_stdlog, " - stack_offset=%s",
  4463. paddress (gdbarch, stack_offset));
  4464. gdb_printf (gdb_stdlog, " longword_offset=%s",
  4465. paddress (gdbarch, longword_offset));
  4466. }
  4467. addr = sp + stack_offset + longword_offset;
  4468. if (mips_debug)
  4469. {
  4470. int i;
  4471. gdb_printf (gdb_stdlog, " @%s ",
  4472. paddress (gdbarch, addr));
  4473. for (i = 0; i < partial_len; i++)
  4474. {
  4475. gdb_printf (gdb_stdlog, "%02x",
  4476. val[i] & 0xff);
  4477. }
  4478. }
  4479. write_memory (addr, val, partial_len);
  4480. }
  4481. /* Note!!! This is NOT an else clause. Odd sized
  4482. structs may go thru BOTH paths. */
  4483. /* Write this portion of the argument to a general
  4484. purpose register. */
  4485. if (argreg <= mips_last_arg_regnum (gdbarch))
  4486. {
  4487. LONGEST regval;
  4488. /* Sign extend pointers, 32-bit integers and signed
  4489. 16-bit and 8-bit integers; everything else is taken
  4490. as is. */
  4491. if ((partial_len == 4
  4492. && (typecode == TYPE_CODE_PTR
  4493. || typecode == TYPE_CODE_INT))
  4494. || (partial_len < 4
  4495. && typecode == TYPE_CODE_INT
  4496. && !arg_type->is_unsigned ()))
  4497. regval = extract_signed_integer (val, partial_len,
  4498. byte_order);
  4499. else
  4500. regval = extract_unsigned_integer (val, partial_len,
  4501. byte_order);
  4502. /* A non-floating-point argument being passed in a
  4503. general register. If a struct or union, and if
  4504. the remaining length is smaller than the register
  4505. size, we have to adjust the register value on
  4506. big endian targets.
  4507. It does not seem to be necessary to do the
  4508. same for integral types. */
  4509. if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
  4510. && partial_len < MIPS64_REGSIZE
  4511. && (typecode == TYPE_CODE_STRUCT
  4512. || typecode == TYPE_CODE_UNION))
  4513. regval <<= ((MIPS64_REGSIZE - partial_len)
  4514. * TARGET_CHAR_BIT);
  4515. if (mips_debug)
  4516. gdb_printf (gdb_stdlog, " - reg=%d val=%s",
  4517. argreg,
  4518. phex (regval, MIPS64_REGSIZE));
  4519. regcache_cooked_write_unsigned (regcache, argreg, regval);
  4520. if (mips_n32n64_fp_arg_chunk_p (gdbarch, arg_type,
  4521. TYPE_LENGTH (arg_type) - len))
  4522. {
  4523. if (mips_debug)
  4524. gdb_printf (gdb_stdlog, " - fpreg=%d val=%s",
  4525. float_argreg,
  4526. phex (regval, MIPS64_REGSIZE));
  4527. regcache_cooked_write_unsigned (regcache, float_argreg,
  4528. regval);
  4529. }
  4530. float_argreg++;
  4531. argreg++;
  4532. }
  4533. len -= partial_len;
  4534. val += partial_len;
  4535. /* Compute the offset into the stack at which we will
  4536. copy the next parameter.
  4537. In N32 (N64?), the stack_offset only needs to be
  4538. adjusted when it has been used. */
  4539. if (stack_used_p)
  4540. stack_offset += align_up (partial_len, MIPS64_REGSIZE);
  4541. }
  4542. }
  4543. if (mips_debug)
  4544. gdb_printf (gdb_stdlog, "\n");
  4545. }
  4546. regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
  4547. /* Return adjusted stack pointer. */
  4548. return sp;
  4549. }
  4550. static enum return_value_convention
  4551. mips_n32n64_return_value (struct gdbarch *gdbarch, struct value *function,
  4552. struct type *type, struct regcache *regcache,
  4553. gdb_byte *readbuf, const gdb_byte *writebuf)
  4554. {
  4555. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  4556. /* From MIPSpro N32 ABI Handbook, Document Number: 007-2816-004
  4557. Function results are returned in $2 (and $3 if needed), or $f0 (and $f2
  4558. if needed), as appropriate for the type. Composite results (struct,
  4559. union, or array) are returned in $2/$f0 and $3/$f2 according to the
  4560. following rules:
  4561. * A struct with only one or two floating point fields is returned in $f0
  4562. (and $f2 if necessary). This is a generalization of the Fortran COMPLEX
  4563. case.
  4564. * Any other composite results of at most 128 bits are returned in
  4565. $2 (first 64 bits) and $3 (remainder, if necessary).
  4566. * Larger composite results are handled by converting the function to a
  4567. procedure with an implicit first parameter, which is a pointer to an area
  4568. reserved by the caller to receive the result. [The o32-bit ABI requires
  4569. that all composite results be handled by conversion to implicit first
  4570. parameters. The MIPS/SGI Fortran implementation has always made a
  4571. specific exception to return COMPLEX results in the floating point
  4572. registers.]
  4573. From MIPSpro Assembly Language Programmer's Guide, Document Number:
  4574. 007-2418-004
  4575. Software
  4576. Register Name(from
  4577. Name fgregdef.h) Use and Linkage
  4578. -----------------------------------------------------------------
  4579. $f0, $f2 fv0, fv1 Hold results of floating-point type function
  4580. ($f0) and complex type function ($f0 has the
  4581. real part, $f2 has the imaginary part.) */
  4582. if (TYPE_LENGTH (type) > 2 * MIPS64_REGSIZE)
  4583. return RETURN_VALUE_STRUCT_CONVENTION;
  4584. else if ((type->code () == TYPE_CODE_COMPLEX
  4585. || (type->code () == TYPE_CODE_FLT && TYPE_LENGTH (type) == 16))
  4586. && tdep->mips_fpu_type != MIPS_FPU_NONE)
  4587. {
  4588. /* A complex value of up to 128 bits in width as well as a 128-bit
  4589. floating-point value goes in both $f0 and $f2. A single complex
  4590. value is held in the lower halves only of the respective registers.
  4591. The two registers are used in the same as memory order, so the
  4592. bytes with the lower memory address are in $f0. */
  4593. if (mips_debug)
  4594. gdb_printf (gdb_stderr, "Return float in $f0 and $f2\n");
  4595. mips_xfer_register (gdbarch, regcache,
  4596. (gdbarch_num_regs (gdbarch)
  4597. + mips_regnum (gdbarch)->fp0),
  4598. TYPE_LENGTH (type) / 2, gdbarch_byte_order (gdbarch),
  4599. readbuf, writebuf, 0);
  4600. mips_xfer_register (gdbarch, regcache,
  4601. (gdbarch_num_regs (gdbarch)
  4602. + mips_regnum (gdbarch)->fp0 + 2),
  4603. TYPE_LENGTH (type) / 2, gdbarch_byte_order (gdbarch),
  4604. readbuf ? readbuf + TYPE_LENGTH (type) / 2 : readbuf,
  4605. (writebuf
  4606. ? writebuf + TYPE_LENGTH (type) / 2 : writebuf), 0);
  4607. return RETURN_VALUE_REGISTER_CONVENTION;
  4608. }
  4609. else if (type->code () == TYPE_CODE_FLT
  4610. && tdep->mips_fpu_type != MIPS_FPU_NONE)
  4611. {
  4612. /* A single or double floating-point value that fits in FP0. */
  4613. if (mips_debug)
  4614. gdb_printf (gdb_stderr, "Return float in $fp0\n");
  4615. mips_xfer_register (gdbarch, regcache,
  4616. (gdbarch_num_regs (gdbarch)
  4617. + mips_regnum (gdbarch)->fp0),
  4618. TYPE_LENGTH (type),
  4619. gdbarch_byte_order (gdbarch),
  4620. readbuf, writebuf, 0);
  4621. return RETURN_VALUE_REGISTER_CONVENTION;
  4622. }
  4623. else if (type->code () == TYPE_CODE_STRUCT
  4624. && type->num_fields () <= 2
  4625. && type->num_fields () >= 1
  4626. && ((type->num_fields () == 1
  4627. && (check_typedef (type->field (0).type ())->code ()
  4628. == TYPE_CODE_FLT))
  4629. || (type->num_fields () == 2
  4630. && (check_typedef (type->field (0).type ())->code ()
  4631. == TYPE_CODE_FLT)
  4632. && (check_typedef (type->field (1).type ())->code ()
  4633. == TYPE_CODE_FLT))))
  4634. {
  4635. /* A struct that contains one or two floats. Each value is part
  4636. in the least significant part of their floating point
  4637. register (or GPR, for soft float). */
  4638. int regnum;
  4639. int field;
  4640. for (field = 0, regnum = (tdep->mips_fpu_type != MIPS_FPU_NONE
  4641. ? mips_regnum (gdbarch)->fp0
  4642. : MIPS_V0_REGNUM);
  4643. field < type->num_fields (); field++, regnum += 2)
  4644. {
  4645. int offset = type->field (field).loc_bitpos () / TARGET_CHAR_BIT;
  4646. if (mips_debug)
  4647. gdb_printf (gdb_stderr, "Return float struct+%d\n",
  4648. offset);
  4649. if (TYPE_LENGTH (type->field (field).type ()) == 16)
  4650. {
  4651. /* A 16-byte long double field goes in two consecutive
  4652. registers. */
  4653. mips_xfer_register (gdbarch, regcache,
  4654. gdbarch_num_regs (gdbarch) + regnum,
  4655. 8,
  4656. gdbarch_byte_order (gdbarch),
  4657. readbuf, writebuf, offset);
  4658. mips_xfer_register (gdbarch, regcache,
  4659. gdbarch_num_regs (gdbarch) + regnum + 1,
  4660. 8,
  4661. gdbarch_byte_order (gdbarch),
  4662. readbuf, writebuf, offset + 8);
  4663. }
  4664. else
  4665. mips_xfer_register (gdbarch, regcache,
  4666. gdbarch_num_regs (gdbarch) + regnum,
  4667. TYPE_LENGTH (type->field (field).type ()),
  4668. gdbarch_byte_order (gdbarch),
  4669. readbuf, writebuf, offset);
  4670. }
  4671. return RETURN_VALUE_REGISTER_CONVENTION;
  4672. }
  4673. else if (type->code () == TYPE_CODE_STRUCT
  4674. || type->code () == TYPE_CODE_UNION
  4675. || type->code () == TYPE_CODE_ARRAY)
  4676. {
  4677. /* A composite type. Extract the left justified value,
  4678. regardless of the byte order. I.e. DO NOT USE
  4679. mips_xfer_lower. */
  4680. int offset;
  4681. int regnum;
  4682. for (offset = 0, regnum = MIPS_V0_REGNUM;
  4683. offset < TYPE_LENGTH (type);
  4684. offset += register_size (gdbarch, regnum), regnum++)
  4685. {
  4686. int xfer = register_size (gdbarch, regnum);
  4687. if (offset + xfer > TYPE_LENGTH (type))
  4688. xfer = TYPE_LENGTH (type) - offset;
  4689. if (mips_debug)
  4690. gdb_printf (gdb_stderr, "Return struct+%d:%d in $%d\n",
  4691. offset, xfer, regnum);
  4692. mips_xfer_register (gdbarch, regcache,
  4693. gdbarch_num_regs (gdbarch) + regnum,
  4694. xfer, BFD_ENDIAN_UNKNOWN, readbuf, writebuf,
  4695. offset);
  4696. }
  4697. return RETURN_VALUE_REGISTER_CONVENTION;
  4698. }
  4699. else
  4700. {
  4701. /* A scalar extract each part but least-significant-byte
  4702. justified. */
  4703. int offset;
  4704. int regnum;
  4705. for (offset = 0, regnum = MIPS_V0_REGNUM;
  4706. offset < TYPE_LENGTH (type);
  4707. offset += register_size (gdbarch, regnum), regnum++)
  4708. {
  4709. int xfer = register_size (gdbarch, regnum);
  4710. if (offset + xfer > TYPE_LENGTH (type))
  4711. xfer = TYPE_LENGTH (type) - offset;
  4712. if (mips_debug)
  4713. gdb_printf (gdb_stderr, "Return scalar+%d:%d in $%d\n",
  4714. offset, xfer, regnum);
  4715. mips_xfer_register (gdbarch, regcache,
  4716. gdbarch_num_regs (gdbarch) + regnum,
  4717. xfer, gdbarch_byte_order (gdbarch),
  4718. readbuf, writebuf, offset);
  4719. }
  4720. return RETURN_VALUE_REGISTER_CONVENTION;
  4721. }
  4722. }
  4723. /* Which registers to use for passing floating-point values between
  4724. function calls, one of floating-point, general and both kinds of
  4725. registers. O32 and O64 use different register kinds for standard
  4726. MIPS and MIPS16 code; to make the handling of cases where we may
  4727. not know what kind of code is being used (e.g. no debug information)
  4728. easier we sometimes use both kinds. */
  4729. enum mips_fval_reg
  4730. {
  4731. mips_fval_fpr,
  4732. mips_fval_gpr,
  4733. mips_fval_both
  4734. };
  4735. /* O32 ABI stuff. */
  4736. static CORE_ADDR
  4737. mips_o32_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
  4738. struct regcache *regcache, CORE_ADDR bp_addr,
  4739. int nargs, struct value **args, CORE_ADDR sp,
  4740. function_call_return_method return_method,
  4741. CORE_ADDR struct_addr)
  4742. {
  4743. int argreg;
  4744. int float_argreg;
  4745. int argnum;
  4746. int arg_space = 0;
  4747. int stack_offset = 0;
  4748. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  4749. CORE_ADDR func_addr = find_function_addr (function, NULL);
  4750. /* For shared libraries, "t9" needs to point at the function
  4751. address. */
  4752. regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr);
  4753. /* Set the return address register to point to the entry point of
  4754. the program, where a breakpoint lies in wait. */
  4755. regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr);
  4756. /* First ensure that the stack and structure return address (if any)
  4757. are properly aligned. The stack has to be at least 64-bit
  4758. aligned even on 32-bit machines, because doubles must be 64-bit
  4759. aligned. For n32 and n64, stack frames need to be 128-bit
  4760. aligned, so we round to this widest known alignment. */
  4761. sp = align_down (sp, 16);
  4762. struct_addr = align_down (struct_addr, 16);
  4763. /* Now make space on the stack for the args. */
  4764. for (argnum = 0; argnum < nargs; argnum++)
  4765. {
  4766. struct type *arg_type = check_typedef (value_type (args[argnum]));
  4767. /* Align to double-word if necessary. */
  4768. if (mips_type_needs_double_align (arg_type))
  4769. arg_space = align_up (arg_space, MIPS32_REGSIZE * 2);
  4770. /* Allocate space on the stack. */
  4771. arg_space += align_up (TYPE_LENGTH (arg_type), MIPS32_REGSIZE);
  4772. }
  4773. sp -= align_up (arg_space, 16);
  4774. if (mips_debug)
  4775. gdb_printf (gdb_stdlog,
  4776. "mips_o32_push_dummy_call: sp=%s allocated %ld\n",
  4777. paddress (gdbarch, sp),
  4778. (long) align_up (arg_space, 16));
  4779. /* Initialize the integer and float register pointers. */
  4780. argreg = MIPS_A0_REGNUM;
  4781. float_argreg = mips_fpa0_regnum (gdbarch);
  4782. /* The struct_return pointer occupies the first parameter-passing reg. */
  4783. if (return_method == return_method_struct)
  4784. {
  4785. if (mips_debug)
  4786. gdb_printf (gdb_stdlog,
  4787. "mips_o32_push_dummy_call: "
  4788. "struct_return reg=%d %s\n",
  4789. argreg, paddress (gdbarch, struct_addr));
  4790. regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
  4791. stack_offset += MIPS32_REGSIZE;
  4792. }
  4793. /* Now load as many as possible of the first arguments into
  4794. registers, and push the rest onto the stack. Loop thru args
  4795. from first to last. */
  4796. for (argnum = 0; argnum < nargs; argnum++)
  4797. {
  4798. const gdb_byte *val;
  4799. struct value *arg = args[argnum];
  4800. struct type *arg_type = check_typedef (value_type (arg));
  4801. int len = TYPE_LENGTH (arg_type);
  4802. enum type_code typecode = arg_type->code ();
  4803. if (mips_debug)
  4804. gdb_printf (gdb_stdlog,
  4805. "mips_o32_push_dummy_call: %d len=%d type=%d",
  4806. argnum + 1, len, (int) typecode);
  4807. val = value_contents (arg).data ();
  4808. /* 32-bit ABIs always start floating point arguments in an
  4809. even-numbered floating point register. Round the FP register
  4810. up before the check to see if there are any FP registers
  4811. left. O32 targets also pass the FP in the integer registers
  4812. so also round up normal registers. */
  4813. if (fp_register_arg_p (gdbarch, typecode, arg_type))
  4814. {
  4815. if ((float_argreg & 1))
  4816. float_argreg++;
  4817. }
  4818. /* Floating point arguments passed in registers have to be
  4819. treated specially. On 32-bit architectures, doubles are
  4820. passed in register pairs; the even FP register gets the
  4821. low word, and the odd FP register gets the high word.
  4822. On O32, the first two floating point arguments are also
  4823. copied to general registers, following their memory order,
  4824. because MIPS16 functions don't use float registers for
  4825. arguments. This duplication of arguments in general
  4826. registers can't hurt non-MIPS16 functions, because those
  4827. registers are normally skipped. */
  4828. if (fp_register_arg_p (gdbarch, typecode, arg_type)
  4829. && float_argreg <= mips_last_fp_arg_regnum (gdbarch))
  4830. {
  4831. if (register_size (gdbarch, float_argreg) < 8 && len == 8)
  4832. {
  4833. int freg_offset = gdbarch_byte_order (gdbarch)
  4834. == BFD_ENDIAN_BIG ? 1 : 0;
  4835. unsigned long regval;
  4836. /* First word. */
  4837. regval = extract_unsigned_integer (val, 4, byte_order);
  4838. if (mips_debug)
  4839. gdb_printf (gdb_stdlog, " - fpreg=%d val=%s",
  4840. float_argreg + freg_offset,
  4841. phex (regval, 4));
  4842. regcache_cooked_write_unsigned (regcache,
  4843. float_argreg++ + freg_offset,
  4844. regval);
  4845. if (mips_debug)
  4846. gdb_printf (gdb_stdlog, " - reg=%d val=%s",
  4847. argreg, phex (regval, 4));
  4848. regcache_cooked_write_unsigned (regcache, argreg++, regval);
  4849. /* Second word. */
  4850. regval = extract_unsigned_integer (val + 4, 4, byte_order);
  4851. if (mips_debug)
  4852. gdb_printf (gdb_stdlog, " - fpreg=%d val=%s",
  4853. float_argreg - freg_offset,
  4854. phex (regval, 4));
  4855. regcache_cooked_write_unsigned (regcache,
  4856. float_argreg++ - freg_offset,
  4857. regval);
  4858. if (mips_debug)
  4859. gdb_printf (gdb_stdlog, " - reg=%d val=%s",
  4860. argreg, phex (regval, 4));
  4861. regcache_cooked_write_unsigned (regcache, argreg++, regval);
  4862. }
  4863. else
  4864. {
  4865. /* This is a floating point value that fits entirely
  4866. in a single register. */
  4867. /* On 32 bit ABI's the float_argreg is further adjusted
  4868. above to ensure that it is even register aligned. */
  4869. LONGEST regval = extract_unsigned_integer (val, len, byte_order);
  4870. if (mips_debug)
  4871. gdb_printf (gdb_stdlog, " - fpreg=%d val=%s",
  4872. float_argreg, phex (regval, len));
  4873. regcache_cooked_write_unsigned (regcache,
  4874. float_argreg++, regval);
  4875. /* Although two FP registers are reserved for each
  4876. argument, only one corresponding integer register is
  4877. reserved. */
  4878. if (mips_debug)
  4879. gdb_printf (gdb_stdlog, " - reg=%d val=%s",
  4880. argreg, phex (regval, len));
  4881. regcache_cooked_write_unsigned (regcache, argreg++, regval);
  4882. }
  4883. /* Reserve space for the FP register. */
  4884. stack_offset += align_up (len, MIPS32_REGSIZE);
  4885. }
  4886. else
  4887. {
  4888. /* Copy the argument to general registers or the stack in
  4889. register-sized pieces. Large arguments are split between
  4890. registers and stack. */
  4891. /* Note: structs whose size is not a multiple of MIPS32_REGSIZE
  4892. are treated specially: Irix cc passes
  4893. them in registers where gcc sometimes puts them on the
  4894. stack. For maximum compatibility, we will put them in
  4895. both places. */
  4896. int odd_sized_struct = (len > MIPS32_REGSIZE
  4897. && len % MIPS32_REGSIZE != 0);
  4898. /* Structures should be aligned to eight bytes (even arg registers)
  4899. on MIPS_ABI_O32, if their first member has double precision. */
  4900. if (mips_type_needs_double_align (arg_type))
  4901. {
  4902. if ((argreg & 1))
  4903. {
  4904. argreg++;
  4905. stack_offset += MIPS32_REGSIZE;
  4906. }
  4907. }
  4908. while (len > 0)
  4909. {
  4910. int partial_len = (len < MIPS32_REGSIZE ? len : MIPS32_REGSIZE);
  4911. if (mips_debug)
  4912. gdb_printf (gdb_stdlog, " -- partial=%d",
  4913. partial_len);
  4914. /* Write this portion of the argument to the stack. */
  4915. if (argreg > mips_last_arg_regnum (gdbarch)
  4916. || odd_sized_struct)
  4917. {
  4918. /* Should shorter than int integer values be
  4919. promoted to int before being stored? */
  4920. int longword_offset = 0;
  4921. CORE_ADDR addr;
  4922. if (mips_debug)
  4923. {
  4924. gdb_printf (gdb_stdlog, " - stack_offset=%s",
  4925. paddress (gdbarch, stack_offset));
  4926. gdb_printf (gdb_stdlog, " longword_offset=%s",
  4927. paddress (gdbarch, longword_offset));
  4928. }
  4929. addr = sp + stack_offset + longword_offset;
  4930. if (mips_debug)
  4931. {
  4932. int i;
  4933. gdb_printf (gdb_stdlog, " @%s ",
  4934. paddress (gdbarch, addr));
  4935. for (i = 0; i < partial_len; i++)
  4936. {
  4937. gdb_printf (gdb_stdlog, "%02x",
  4938. val[i] & 0xff);
  4939. }
  4940. }
  4941. write_memory (addr, val, partial_len);
  4942. }
  4943. /* Note!!! This is NOT an else clause. Odd sized
  4944. structs may go thru BOTH paths. */
  4945. /* Write this portion of the argument to a general
  4946. purpose register. */
  4947. if (argreg <= mips_last_arg_regnum (gdbarch))
  4948. {
  4949. LONGEST regval = extract_signed_integer (val, partial_len,
  4950. byte_order);
  4951. /* Value may need to be sign extended, because
  4952. mips_isa_regsize() != mips_abi_regsize(). */
  4953. /* A non-floating-point argument being passed in a
  4954. general register. If a struct or union, and if
  4955. the remaining length is smaller than the register
  4956. size, we have to adjust the register value on
  4957. big endian targets.
  4958. It does not seem to be necessary to do the
  4959. same for integral types.
  4960. Also don't do this adjustment on O64 binaries.
  4961. cagney/2001-07-23: gdb/179: Also, GCC, when
  4962. outputting LE O32 with sizeof (struct) <
  4963. mips_abi_regsize(), generates a left shift
  4964. as part of storing the argument in a register
  4965. (the left shift isn't generated when
  4966. sizeof (struct) >= mips_abi_regsize()). Since
  4967. it is quite possible that this is GCC
  4968. contradicting the LE/O32 ABI, GDB has not been
  4969. adjusted to accommodate this. Either someone
  4970. needs to demonstrate that the LE/O32 ABI
  4971. specifies such a left shift OR this new ABI gets
  4972. identified as such and GDB gets tweaked
  4973. accordingly. */
  4974. if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
  4975. && partial_len < MIPS32_REGSIZE
  4976. && (typecode == TYPE_CODE_STRUCT
  4977. || typecode == TYPE_CODE_UNION))
  4978. regval <<= ((MIPS32_REGSIZE - partial_len)
  4979. * TARGET_CHAR_BIT);
  4980. if (mips_debug)
  4981. gdb_printf (gdb_stdlog, " - reg=%d val=%s",
  4982. argreg,
  4983. phex (regval, MIPS32_REGSIZE));
  4984. regcache_cooked_write_unsigned (regcache, argreg, regval);
  4985. argreg++;
  4986. /* Prevent subsequent floating point arguments from
  4987. being passed in floating point registers. */
  4988. float_argreg = mips_last_fp_arg_regnum (gdbarch) + 1;
  4989. }
  4990. len -= partial_len;
  4991. val += partial_len;
  4992. /* Compute the offset into the stack at which we will
  4993. copy the next parameter.
  4994. In older ABIs, the caller reserved space for
  4995. registers that contained arguments. This was loosely
  4996. refered to as their "home". Consequently, space is
  4997. always allocated. */
  4998. stack_offset += align_up (partial_len, MIPS32_REGSIZE);
  4999. }
  5000. }
  5001. if (mips_debug)
  5002. gdb_printf (gdb_stdlog, "\n");
  5003. }
  5004. regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
  5005. /* Return adjusted stack pointer. */
  5006. return sp;
  5007. }
  5008. static enum return_value_convention
  5009. mips_o32_return_value (struct gdbarch *gdbarch, struct value *function,
  5010. struct type *type, struct regcache *regcache,
  5011. gdb_byte *readbuf, const gdb_byte *writebuf)
  5012. {
  5013. CORE_ADDR func_addr = function ? find_function_addr (function, NULL) : 0;
  5014. int mips16 = mips_pc_is_mips16 (gdbarch, func_addr);
  5015. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  5016. enum mips_fval_reg fval_reg;
  5017. fval_reg = readbuf ? mips16 ? mips_fval_gpr : mips_fval_fpr : mips_fval_both;
  5018. if (type->code () == TYPE_CODE_STRUCT
  5019. || type->code () == TYPE_CODE_UNION
  5020. || type->code () == TYPE_CODE_ARRAY)
  5021. return RETURN_VALUE_STRUCT_CONVENTION;
  5022. else if (type->code () == TYPE_CODE_FLT
  5023. && TYPE_LENGTH (type) == 4 && tdep->mips_fpu_type != MIPS_FPU_NONE)
  5024. {
  5025. /* A single-precision floating-point value. If reading in or copying,
  5026. then we get it from/put it to FP0 for standard MIPS code or GPR2
  5027. for MIPS16 code. If writing out only, then we put it to both FP0
  5028. and GPR2. We do not support reading in with no function known, if
  5029. this safety check ever triggers, then we'll have to try harder. */
  5030. gdb_assert (function || !readbuf);
  5031. if (mips_debug)
  5032. switch (fval_reg)
  5033. {
  5034. case mips_fval_fpr:
  5035. gdb_printf (gdb_stderr, "Return float in $fp0\n");
  5036. break;
  5037. case mips_fval_gpr:
  5038. gdb_printf (gdb_stderr, "Return float in $2\n");
  5039. break;
  5040. case mips_fval_both:
  5041. gdb_printf (gdb_stderr, "Return float in $fp0 and $2\n");
  5042. break;
  5043. }
  5044. if (fval_reg != mips_fval_gpr)
  5045. mips_xfer_register (gdbarch, regcache,
  5046. (gdbarch_num_regs (gdbarch)
  5047. + mips_regnum (gdbarch)->fp0),
  5048. TYPE_LENGTH (type),
  5049. gdbarch_byte_order (gdbarch),
  5050. readbuf, writebuf, 0);
  5051. if (fval_reg != mips_fval_fpr)
  5052. mips_xfer_register (gdbarch, regcache,
  5053. gdbarch_num_regs (gdbarch) + 2,
  5054. TYPE_LENGTH (type),
  5055. gdbarch_byte_order (gdbarch),
  5056. readbuf, writebuf, 0);
  5057. return RETURN_VALUE_REGISTER_CONVENTION;
  5058. }
  5059. else if (type->code () == TYPE_CODE_FLT
  5060. && TYPE_LENGTH (type) == 8 && tdep->mips_fpu_type != MIPS_FPU_NONE)
  5061. {
  5062. /* A double-precision floating-point value. If reading in or copying,
  5063. then we get it from/put it to FP1 and FP0 for standard MIPS code or
  5064. GPR2 and GPR3 for MIPS16 code. If writing out only, then we put it
  5065. to both FP1/FP0 and GPR2/GPR3. We do not support reading in with
  5066. no function known, if this safety check ever triggers, then we'll
  5067. have to try harder. */
  5068. gdb_assert (function || !readbuf);
  5069. if (mips_debug)
  5070. switch (fval_reg)
  5071. {
  5072. case mips_fval_fpr:
  5073. gdb_printf (gdb_stderr, "Return float in $fp1/$fp0\n");
  5074. break;
  5075. case mips_fval_gpr:
  5076. gdb_printf (gdb_stderr, "Return float in $2/$3\n");
  5077. break;
  5078. case mips_fval_both:
  5079. gdb_printf (gdb_stderr,
  5080. "Return float in $fp1/$fp0 and $2/$3\n");
  5081. break;
  5082. }
  5083. if (fval_reg != mips_fval_gpr)
  5084. {
  5085. /* The most significant part goes in FP1, and the least significant
  5086. in FP0. */
  5087. switch (gdbarch_byte_order (gdbarch))
  5088. {
  5089. case BFD_ENDIAN_LITTLE:
  5090. mips_xfer_register (gdbarch, regcache,
  5091. (gdbarch_num_regs (gdbarch)
  5092. + mips_regnum (gdbarch)->fp0 + 0),
  5093. 4, gdbarch_byte_order (gdbarch),
  5094. readbuf, writebuf, 0);
  5095. mips_xfer_register (gdbarch, regcache,
  5096. (gdbarch_num_regs (gdbarch)
  5097. + mips_regnum (gdbarch)->fp0 + 1),
  5098. 4, gdbarch_byte_order (gdbarch),
  5099. readbuf, writebuf, 4);
  5100. break;
  5101. case BFD_ENDIAN_BIG:
  5102. mips_xfer_register (gdbarch, regcache,
  5103. (gdbarch_num_regs (gdbarch)
  5104. + mips_regnum (gdbarch)->fp0 + 1),
  5105. 4, gdbarch_byte_order (gdbarch),
  5106. readbuf, writebuf, 0);
  5107. mips_xfer_register (gdbarch, regcache,
  5108. (gdbarch_num_regs (gdbarch)
  5109. + mips_regnum (gdbarch)->fp0 + 0),
  5110. 4, gdbarch_byte_order (gdbarch),
  5111. readbuf, writebuf, 4);
  5112. break;
  5113. default:
  5114. internal_error (__FILE__, __LINE__, _("bad switch"));
  5115. }
  5116. }
  5117. if (fval_reg != mips_fval_fpr)
  5118. {
  5119. /* The two 32-bit parts are always placed in GPR2 and GPR3
  5120. following these registers' memory order. */
  5121. mips_xfer_register (gdbarch, regcache,
  5122. gdbarch_num_regs (gdbarch) + 2,
  5123. 4, gdbarch_byte_order (gdbarch),
  5124. readbuf, writebuf, 0);
  5125. mips_xfer_register (gdbarch, regcache,
  5126. gdbarch_num_regs (gdbarch) + 3,
  5127. 4, gdbarch_byte_order (gdbarch),
  5128. readbuf, writebuf, 4);
  5129. }
  5130. return RETURN_VALUE_REGISTER_CONVENTION;
  5131. }
  5132. #if 0
  5133. else if (type->code () == TYPE_CODE_STRUCT
  5134. && type->num_fields () <= 2
  5135. && type->num_fields () >= 1
  5136. && ((type->num_fields () == 1
  5137. && (TYPE_CODE (type->field (0).type ())
  5138. == TYPE_CODE_FLT))
  5139. || (type->num_fields () == 2
  5140. && (TYPE_CODE (type->field (0).type ())
  5141. == TYPE_CODE_FLT)
  5142. && (TYPE_CODE (type->field (1).type ())
  5143. == TYPE_CODE_FLT)))
  5144. && tdep->mips_fpu_type != MIPS_FPU_NONE)
  5145. {
  5146. /* A struct that contains one or two floats. Each value is part
  5147. in the least significant part of their floating point
  5148. register.. */
  5149. int regnum;
  5150. int field;
  5151. for (field = 0, regnum = mips_regnum (gdbarch)->fp0;
  5152. field < type->num_fields (); field++, regnum += 2)
  5153. {
  5154. int offset = (type->fields ()[field].loc_bitpos () / TARGET_CHAR_BIT);
  5155. if (mips_debug)
  5156. gdb_printf (gdb_stderr, "Return float struct+%d\n",
  5157. offset);
  5158. mips_xfer_register (gdbarch, regcache,
  5159. gdbarch_num_regs (gdbarch) + regnum,
  5160. TYPE_LENGTH (type->field (field).type ()),
  5161. gdbarch_byte_order (gdbarch),
  5162. readbuf, writebuf, offset);
  5163. }
  5164. return RETURN_VALUE_REGISTER_CONVENTION;
  5165. }
  5166. #endif
  5167. #if 0
  5168. else if (type->code () == TYPE_CODE_STRUCT
  5169. || type->code () == TYPE_CODE_UNION)
  5170. {
  5171. /* A structure or union. Extract the left justified value,
  5172. regardless of the byte order. I.e. DO NOT USE
  5173. mips_xfer_lower. */
  5174. int offset;
  5175. int regnum;
  5176. for (offset = 0, regnum = MIPS_V0_REGNUM;
  5177. offset < TYPE_LENGTH (type);
  5178. offset += register_size (gdbarch, regnum), regnum++)
  5179. {
  5180. int xfer = register_size (gdbarch, regnum);
  5181. if (offset + xfer > TYPE_LENGTH (type))
  5182. xfer = TYPE_LENGTH (type) - offset;
  5183. if (mips_debug)
  5184. gdb_printf (gdb_stderr, "Return struct+%d:%d in $%d\n",
  5185. offset, xfer, regnum);
  5186. mips_xfer_register (gdbarch, regcache,
  5187. gdbarch_num_regs (gdbarch) + regnum, xfer,
  5188. BFD_ENDIAN_UNKNOWN, readbuf, writebuf, offset);
  5189. }
  5190. return RETURN_VALUE_REGISTER_CONVENTION;
  5191. }
  5192. #endif
  5193. else
  5194. {
  5195. /* A scalar extract each part but least-significant-byte
  5196. justified. o32 thinks registers are 4 byte, regardless of
  5197. the ISA. */
  5198. int offset;
  5199. int regnum;
  5200. for (offset = 0, regnum = MIPS_V0_REGNUM;
  5201. offset < TYPE_LENGTH (type);
  5202. offset += MIPS32_REGSIZE, regnum++)
  5203. {
  5204. int xfer = MIPS32_REGSIZE;
  5205. if (offset + xfer > TYPE_LENGTH (type))
  5206. xfer = TYPE_LENGTH (type) - offset;
  5207. if (mips_debug)
  5208. gdb_printf (gdb_stderr, "Return scalar+%d:%d in $%d\n",
  5209. offset, xfer, regnum);
  5210. mips_xfer_register (gdbarch, regcache,
  5211. gdbarch_num_regs (gdbarch) + regnum, xfer,
  5212. gdbarch_byte_order (gdbarch),
  5213. readbuf, writebuf, offset);
  5214. }
  5215. return RETURN_VALUE_REGISTER_CONVENTION;
  5216. }
  5217. }
  5218. /* O64 ABI. This is a hacked up kind of 64-bit version of the o32
  5219. ABI. */
  5220. static CORE_ADDR
  5221. mips_o64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
  5222. struct regcache *regcache, CORE_ADDR bp_addr,
  5223. int nargs,
  5224. struct value **args, CORE_ADDR sp,
  5225. function_call_return_method return_method, CORE_ADDR struct_addr)
  5226. {
  5227. int argreg;
  5228. int float_argreg;
  5229. int argnum;
  5230. int arg_space = 0;
  5231. int stack_offset = 0;
  5232. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  5233. CORE_ADDR func_addr = find_function_addr (function, NULL);
  5234. /* For shared libraries, "t9" needs to point at the function
  5235. address. */
  5236. regcache_cooked_write_signed (regcache, MIPS_T9_REGNUM, func_addr);
  5237. /* Set the return address register to point to the entry point of
  5238. the program, where a breakpoint lies in wait. */
  5239. regcache_cooked_write_signed (regcache, MIPS_RA_REGNUM, bp_addr);
  5240. /* First ensure that the stack and structure return address (if any)
  5241. are properly aligned. The stack has to be at least 64-bit
  5242. aligned even on 32-bit machines, because doubles must be 64-bit
  5243. aligned. For n32 and n64, stack frames need to be 128-bit
  5244. aligned, so we round to this widest known alignment. */
  5245. sp = align_down (sp, 16);
  5246. struct_addr = align_down (struct_addr, 16);
  5247. /* Now make space on the stack for the args. */
  5248. for (argnum = 0; argnum < nargs; argnum++)
  5249. {
  5250. struct type *arg_type = check_typedef (value_type (args[argnum]));
  5251. /* Allocate space on the stack. */
  5252. arg_space += align_up (TYPE_LENGTH (arg_type), MIPS64_REGSIZE);
  5253. }
  5254. sp -= align_up (arg_space, 16);
  5255. if (mips_debug)
  5256. gdb_printf (gdb_stdlog,
  5257. "mips_o64_push_dummy_call: sp=%s allocated %ld\n",
  5258. paddress (gdbarch, sp),
  5259. (long) align_up (arg_space, 16));
  5260. /* Initialize the integer and float register pointers. */
  5261. argreg = MIPS_A0_REGNUM;
  5262. float_argreg = mips_fpa0_regnum (gdbarch);
  5263. /* The struct_return pointer occupies the first parameter-passing reg. */
  5264. if (return_method == return_method_struct)
  5265. {
  5266. if (mips_debug)
  5267. gdb_printf (gdb_stdlog,
  5268. "mips_o64_push_dummy_call: "
  5269. "struct_return reg=%d %s\n",
  5270. argreg, paddress (gdbarch, struct_addr));
  5271. regcache_cooked_write_unsigned (regcache, argreg++, struct_addr);
  5272. stack_offset += MIPS64_REGSIZE;
  5273. }
  5274. /* Now load as many as possible of the first arguments into
  5275. registers, and push the rest onto the stack. Loop thru args
  5276. from first to last. */
  5277. for (argnum = 0; argnum < nargs; argnum++)
  5278. {
  5279. const gdb_byte *val;
  5280. struct value *arg = args[argnum];
  5281. struct type *arg_type = check_typedef (value_type (arg));
  5282. int len = TYPE_LENGTH (arg_type);
  5283. enum type_code typecode = arg_type->code ();
  5284. if (mips_debug)
  5285. gdb_printf (gdb_stdlog,
  5286. "mips_o64_push_dummy_call: %d len=%d type=%d",
  5287. argnum + 1, len, (int) typecode);
  5288. val = value_contents (arg).data ();
  5289. /* Floating point arguments passed in registers have to be
  5290. treated specially. On 32-bit architectures, doubles are
  5291. passed in register pairs; the even FP register gets the
  5292. low word, and the odd FP register gets the high word.
  5293. On O64, the first two floating point arguments are also
  5294. copied to general registers, because MIPS16 functions
  5295. don't use float registers for arguments. This duplication
  5296. of arguments in general registers can't hurt non-MIPS16
  5297. functions because those registers are normally skipped. */
  5298. if (fp_register_arg_p (gdbarch, typecode, arg_type)
  5299. && float_argreg <= mips_last_fp_arg_regnum (gdbarch))
  5300. {
  5301. LONGEST regval = extract_unsigned_integer (val, len, byte_order);
  5302. if (mips_debug)
  5303. gdb_printf (gdb_stdlog, " - fpreg=%d val=%s",
  5304. float_argreg, phex (regval, len));
  5305. regcache_cooked_write_unsigned (regcache, float_argreg++, regval);
  5306. if (mips_debug)
  5307. gdb_printf (gdb_stdlog, " - reg=%d val=%s",
  5308. argreg, phex (regval, len));
  5309. regcache_cooked_write_unsigned (regcache, argreg, regval);
  5310. argreg++;
  5311. /* Reserve space for the FP register. */
  5312. stack_offset += align_up (len, MIPS64_REGSIZE);
  5313. }
  5314. else
  5315. {
  5316. /* Copy the argument to general registers or the stack in
  5317. register-sized pieces. Large arguments are split between
  5318. registers and stack. */
  5319. /* Note: structs whose size is not a multiple of MIPS64_REGSIZE
  5320. are treated specially: Irix cc passes them in registers
  5321. where gcc sometimes puts them on the stack. For maximum
  5322. compatibility, we will put them in both places. */
  5323. int odd_sized_struct = (len > MIPS64_REGSIZE
  5324. && len % MIPS64_REGSIZE != 0);
  5325. while (len > 0)
  5326. {
  5327. int partial_len = (len < MIPS64_REGSIZE ? len : MIPS64_REGSIZE);
  5328. if (mips_debug)
  5329. gdb_printf (gdb_stdlog, " -- partial=%d",
  5330. partial_len);
  5331. /* Write this portion of the argument to the stack. */
  5332. if (argreg > mips_last_arg_regnum (gdbarch)
  5333. || odd_sized_struct)
  5334. {
  5335. /* Should shorter than int integer values be
  5336. promoted to int before being stored? */
  5337. int longword_offset = 0;
  5338. CORE_ADDR addr;
  5339. if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  5340. {
  5341. if ((typecode == TYPE_CODE_INT
  5342. || typecode == TYPE_CODE_PTR
  5343. || typecode == TYPE_CODE_FLT)
  5344. && len <= 4)
  5345. longword_offset = MIPS64_REGSIZE - len;
  5346. }
  5347. if (mips_debug)
  5348. {
  5349. gdb_printf (gdb_stdlog, " - stack_offset=%s",
  5350. paddress (gdbarch, stack_offset));
  5351. gdb_printf (gdb_stdlog, " longword_offset=%s",
  5352. paddress (gdbarch, longword_offset));
  5353. }
  5354. addr = sp + stack_offset + longword_offset;
  5355. if (mips_debug)
  5356. {
  5357. int i;
  5358. gdb_printf (gdb_stdlog, " @%s ",
  5359. paddress (gdbarch, addr));
  5360. for (i = 0; i < partial_len; i++)
  5361. {
  5362. gdb_printf (gdb_stdlog, "%02x",
  5363. val[i] & 0xff);
  5364. }
  5365. }
  5366. write_memory (addr, val, partial_len);
  5367. }
  5368. /* Note!!! This is NOT an else clause. Odd sized
  5369. structs may go thru BOTH paths. */
  5370. /* Write this portion of the argument to a general
  5371. purpose register. */
  5372. if (argreg <= mips_last_arg_regnum (gdbarch))
  5373. {
  5374. LONGEST regval = extract_signed_integer (val, partial_len,
  5375. byte_order);
  5376. /* Value may need to be sign extended, because
  5377. mips_isa_regsize() != mips_abi_regsize(). */
  5378. /* A non-floating-point argument being passed in a
  5379. general register. If a struct or union, and if
  5380. the remaining length is smaller than the register
  5381. size, we have to adjust the register value on
  5382. big endian targets.
  5383. It does not seem to be necessary to do the
  5384. same for integral types. */
  5385. if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
  5386. && partial_len < MIPS64_REGSIZE
  5387. && (typecode == TYPE_CODE_STRUCT
  5388. || typecode == TYPE_CODE_UNION))
  5389. regval <<= ((MIPS64_REGSIZE - partial_len)
  5390. * TARGET_CHAR_BIT);
  5391. if (mips_debug)
  5392. gdb_printf (gdb_stdlog, " - reg=%d val=%s",
  5393. argreg,
  5394. phex (regval, MIPS64_REGSIZE));
  5395. regcache_cooked_write_unsigned (regcache, argreg, regval);
  5396. argreg++;
  5397. /* Prevent subsequent floating point arguments from
  5398. being passed in floating point registers. */
  5399. float_argreg = mips_last_fp_arg_regnum (gdbarch) + 1;
  5400. }
  5401. len -= partial_len;
  5402. val += partial_len;
  5403. /* Compute the offset into the stack at which we will
  5404. copy the next parameter.
  5405. In older ABIs, the caller reserved space for
  5406. registers that contained arguments. This was loosely
  5407. refered to as their "home". Consequently, space is
  5408. always allocated. */
  5409. stack_offset += align_up (partial_len, MIPS64_REGSIZE);
  5410. }
  5411. }
  5412. if (mips_debug)
  5413. gdb_printf (gdb_stdlog, "\n");
  5414. }
  5415. regcache_cooked_write_signed (regcache, MIPS_SP_REGNUM, sp);
  5416. /* Return adjusted stack pointer. */
  5417. return sp;
  5418. }
  5419. static enum return_value_convention
  5420. mips_o64_return_value (struct gdbarch *gdbarch, struct value *function,
  5421. struct type *type, struct regcache *regcache,
  5422. gdb_byte *readbuf, const gdb_byte *writebuf)
  5423. {
  5424. CORE_ADDR func_addr = function ? find_function_addr (function, NULL) : 0;
  5425. int mips16 = mips_pc_is_mips16 (gdbarch, func_addr);
  5426. enum mips_fval_reg fval_reg;
  5427. fval_reg = readbuf ? mips16 ? mips_fval_gpr : mips_fval_fpr : mips_fval_both;
  5428. if (type->code () == TYPE_CODE_STRUCT
  5429. || type->code () == TYPE_CODE_UNION
  5430. || type->code () == TYPE_CODE_ARRAY)
  5431. return RETURN_VALUE_STRUCT_CONVENTION;
  5432. else if (fp_register_arg_p (gdbarch, type->code (), type))
  5433. {
  5434. /* A floating-point value. If reading in or copying, then we get it
  5435. from/put it to FP0 for standard MIPS code or GPR2 for MIPS16 code.
  5436. If writing out only, then we put it to both FP0 and GPR2. We do
  5437. not support reading in with no function known, if this safety
  5438. check ever triggers, then we'll have to try harder. */
  5439. gdb_assert (function || !readbuf);
  5440. if (mips_debug)
  5441. switch (fval_reg)
  5442. {
  5443. case mips_fval_fpr:
  5444. gdb_printf (gdb_stderr, "Return float in $fp0\n");
  5445. break;
  5446. case mips_fval_gpr:
  5447. gdb_printf (gdb_stderr, "Return float in $2\n");
  5448. break;
  5449. case mips_fval_both:
  5450. gdb_printf (gdb_stderr, "Return float in $fp0 and $2\n");
  5451. break;
  5452. }
  5453. if (fval_reg != mips_fval_gpr)
  5454. mips_xfer_register (gdbarch, regcache,
  5455. (gdbarch_num_regs (gdbarch)
  5456. + mips_regnum (gdbarch)->fp0),
  5457. TYPE_LENGTH (type),
  5458. gdbarch_byte_order (gdbarch),
  5459. readbuf, writebuf, 0);
  5460. if (fval_reg != mips_fval_fpr)
  5461. mips_xfer_register (gdbarch, regcache,
  5462. gdbarch_num_regs (gdbarch) + 2,
  5463. TYPE_LENGTH (type),
  5464. gdbarch_byte_order (gdbarch),
  5465. readbuf, writebuf, 0);
  5466. return RETURN_VALUE_REGISTER_CONVENTION;
  5467. }
  5468. else
  5469. {
  5470. /* A scalar extract each part but least-significant-byte
  5471. justified. */
  5472. int offset;
  5473. int regnum;
  5474. for (offset = 0, regnum = MIPS_V0_REGNUM;
  5475. offset < TYPE_LENGTH (type);
  5476. offset += MIPS64_REGSIZE, regnum++)
  5477. {
  5478. int xfer = MIPS64_REGSIZE;
  5479. if (offset + xfer > TYPE_LENGTH (type))
  5480. xfer = TYPE_LENGTH (type) - offset;
  5481. if (mips_debug)
  5482. gdb_printf (gdb_stderr, "Return scalar+%d:%d in $%d\n",
  5483. offset, xfer, regnum);
  5484. mips_xfer_register (gdbarch, regcache,
  5485. gdbarch_num_regs (gdbarch) + regnum,
  5486. xfer, gdbarch_byte_order (gdbarch),
  5487. readbuf, writebuf, offset);
  5488. }
  5489. return RETURN_VALUE_REGISTER_CONVENTION;
  5490. }
  5491. }
  5492. /* Floating point register management.
  5493. Background: MIPS1 & 2 fp registers are 32 bits wide. To support
  5494. 64bit operations, these early MIPS cpus treat fp register pairs
  5495. (f0,f1) as a single register (d0). Later MIPS cpu's have 64 bit fp
  5496. registers and offer a compatibility mode that emulates the MIPS2 fp
  5497. model. When operating in MIPS2 fp compat mode, later cpu's split
  5498. double precision floats into two 32-bit chunks and store them in
  5499. consecutive fp regs. To display 64-bit floats stored in this
  5500. fashion, we have to combine 32 bits from f0 and 32 bits from f1.
  5501. Throw in user-configurable endianness and you have a real mess.
  5502. The way this works is:
  5503. - If we are in 32-bit mode or on a 32-bit processor, then a 64-bit
  5504. double-precision value will be split across two logical registers.
  5505. The lower-numbered logical register will hold the low-order bits,
  5506. regardless of the processor's endianness.
  5507. - If we are on a 64-bit processor, and we are looking for a
  5508. single-precision value, it will be in the low ordered bits
  5509. of a 64-bit GPR (after mfc1, for example) or a 64-bit register
  5510. save slot in memory.
  5511. - If we are in 64-bit mode, everything is straightforward.
  5512. Note that this code only deals with "live" registers at the top of the
  5513. stack. We will attempt to deal with saved registers later, when
  5514. the raw/cooked register interface is in place. (We need a general
  5515. interface that can deal with dynamic saved register sizes -- fp
  5516. regs could be 32 bits wide in one frame and 64 on the frame above
  5517. and below). */
  5518. /* Copy a 32-bit single-precision value from the current frame
  5519. into rare_buffer. */
  5520. static void
  5521. mips_read_fp_register_single (struct frame_info *frame, int regno,
  5522. gdb_byte *rare_buffer)
  5523. {
  5524. struct gdbarch *gdbarch = get_frame_arch (frame);
  5525. int raw_size = register_size (gdbarch, regno);
  5526. gdb_byte *raw_buffer = (gdb_byte *) alloca (raw_size);
  5527. if (!deprecated_frame_register_read (frame, regno, raw_buffer))
  5528. error (_("can't read register %d (%s)"),
  5529. regno, gdbarch_register_name (gdbarch, regno));
  5530. if (raw_size == 8)
  5531. {
  5532. /* We have a 64-bit value for this register. Find the low-order
  5533. 32 bits. */
  5534. int offset;
  5535. if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  5536. offset = 4;
  5537. else
  5538. offset = 0;
  5539. memcpy (rare_buffer, raw_buffer + offset, 4);
  5540. }
  5541. else
  5542. {
  5543. memcpy (rare_buffer, raw_buffer, 4);
  5544. }
  5545. }
  5546. /* Copy a 64-bit double-precision value from the current frame into
  5547. rare_buffer. This may include getting half of it from the next
  5548. register. */
  5549. static void
  5550. mips_read_fp_register_double (struct frame_info *frame, int regno,
  5551. gdb_byte *rare_buffer)
  5552. {
  5553. struct gdbarch *gdbarch = get_frame_arch (frame);
  5554. int raw_size = register_size (gdbarch, regno);
  5555. if (raw_size == 8 && !mips2_fp_compat (frame))
  5556. {
  5557. /* We have a 64-bit value for this register, and we should use
  5558. all 64 bits. */
  5559. if (!deprecated_frame_register_read (frame, regno, rare_buffer))
  5560. error (_("can't read register %d (%s)"),
  5561. regno, gdbarch_register_name (gdbarch, regno));
  5562. }
  5563. else
  5564. {
  5565. int rawnum = regno % gdbarch_num_regs (gdbarch);
  5566. if ((rawnum - mips_regnum (gdbarch)->fp0) & 1)
  5567. internal_error (__FILE__, __LINE__,
  5568. _("mips_read_fp_register_double: bad access to "
  5569. "odd-numbered FP register"));
  5570. /* mips_read_fp_register_single will find the correct 32 bits from
  5571. each register. */
  5572. if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  5573. {
  5574. mips_read_fp_register_single (frame, regno, rare_buffer + 4);
  5575. mips_read_fp_register_single (frame, regno + 1, rare_buffer);
  5576. }
  5577. else
  5578. {
  5579. mips_read_fp_register_single (frame, regno, rare_buffer);
  5580. mips_read_fp_register_single (frame, regno + 1, rare_buffer + 4);
  5581. }
  5582. }
  5583. }
  5584. static void
  5585. mips_print_fp_register (struct ui_file *file, struct frame_info *frame,
  5586. int regnum)
  5587. { /* Do values for FP (float) regs. */
  5588. struct gdbarch *gdbarch = get_frame_arch (frame);
  5589. gdb_byte *raw_buffer;
  5590. std::string flt_str, dbl_str;
  5591. const struct type *flt_type = builtin_type (gdbarch)->builtin_float;
  5592. const struct type *dbl_type = builtin_type (gdbarch)->builtin_double;
  5593. raw_buffer
  5594. = ((gdb_byte *)
  5595. alloca (2 * register_size (gdbarch, mips_regnum (gdbarch)->fp0)));
  5596. gdb_printf (file, "%s:", gdbarch_register_name (gdbarch, regnum));
  5597. gdb_printf (file, "%*s",
  5598. 4 - (int) strlen (gdbarch_register_name (gdbarch, regnum)),
  5599. "");
  5600. if (register_size (gdbarch, regnum) == 4 || mips2_fp_compat (frame))
  5601. {
  5602. struct value_print_options opts;
  5603. /* 4-byte registers: Print hex and floating. Also print even
  5604. numbered registers as doubles. */
  5605. mips_read_fp_register_single (frame, regnum, raw_buffer);
  5606. flt_str = target_float_to_string (raw_buffer, flt_type, "%-17.9g");
  5607. get_formatted_print_options (&opts, 'x');
  5608. print_scalar_formatted (raw_buffer,
  5609. builtin_type (gdbarch)->builtin_uint32,
  5610. &opts, 'w', file);
  5611. gdb_printf (file, " flt: %s", flt_str.c_str ());
  5612. if ((regnum - gdbarch_num_regs (gdbarch)) % 2 == 0)
  5613. {
  5614. mips_read_fp_register_double (frame, regnum, raw_buffer);
  5615. dbl_str = target_float_to_string (raw_buffer, dbl_type, "%-24.17g");
  5616. gdb_printf (file, " dbl: %s", dbl_str.c_str ());
  5617. }
  5618. }
  5619. else
  5620. {
  5621. struct value_print_options opts;
  5622. /* Eight byte registers: print each one as hex, float and double. */
  5623. mips_read_fp_register_single (frame, regnum, raw_buffer);
  5624. flt_str = target_float_to_string (raw_buffer, flt_type, "%-17.9g");
  5625. mips_read_fp_register_double (frame, regnum, raw_buffer);
  5626. dbl_str = target_float_to_string (raw_buffer, dbl_type, "%-24.17g");
  5627. get_formatted_print_options (&opts, 'x');
  5628. print_scalar_formatted (raw_buffer,
  5629. builtin_type (gdbarch)->builtin_uint64,
  5630. &opts, 'g', file);
  5631. gdb_printf (file, " flt: %s", flt_str.c_str ());
  5632. gdb_printf (file, " dbl: %s", dbl_str.c_str ());
  5633. }
  5634. }
  5635. static void
  5636. mips_print_register (struct ui_file *file, struct frame_info *frame,
  5637. int regnum)
  5638. {
  5639. struct gdbarch *gdbarch = get_frame_arch (frame);
  5640. struct value_print_options opts;
  5641. struct value *val;
  5642. if (mips_float_register_p (gdbarch, regnum))
  5643. {
  5644. mips_print_fp_register (file, frame, regnum);
  5645. return;
  5646. }
  5647. val = get_frame_register_value (frame, regnum);
  5648. gdb_puts (gdbarch_register_name (gdbarch, regnum), file);
  5649. /* The problem with printing numeric register names (r26, etc.) is that
  5650. the user can't use them on input. Probably the best solution is to
  5651. fix it so that either the numeric or the funky (a2, etc.) names
  5652. are accepted on input. */
  5653. if (regnum < MIPS_NUMREGS)
  5654. gdb_printf (file, "(r%d): ", regnum);
  5655. else
  5656. gdb_printf (file, ": ");
  5657. get_formatted_print_options (&opts, 'x');
  5658. value_print_scalar_formatted (val, &opts, 0, file);
  5659. }
  5660. /* Print IEEE exception condition bits in FLAGS. */
  5661. static void
  5662. print_fpu_flags (struct ui_file *file, int flags)
  5663. {
  5664. if (flags & (1 << 0))
  5665. gdb_puts (" inexact", file);
  5666. if (flags & (1 << 1))
  5667. gdb_puts (" uflow", file);
  5668. if (flags & (1 << 2))
  5669. gdb_puts (" oflow", file);
  5670. if (flags & (1 << 3))
  5671. gdb_puts (" div0", file);
  5672. if (flags & (1 << 4))
  5673. gdb_puts (" inval", file);
  5674. if (flags & (1 << 5))
  5675. gdb_puts (" unimp", file);
  5676. gdb_putc ('\n', file);
  5677. }
  5678. /* Print interesting information about the floating point processor
  5679. (if present) or emulator. */
  5680. static void
  5681. mips_print_float_info (struct gdbarch *gdbarch, struct ui_file *file,
  5682. struct frame_info *frame, const char *args)
  5683. {
  5684. int fcsr = mips_regnum (gdbarch)->fp_control_status;
  5685. enum mips_fpu_type type = mips_get_fpu_type (gdbarch);
  5686. ULONGEST fcs = 0;
  5687. int i;
  5688. if (fcsr == -1 || !read_frame_register_unsigned (frame, fcsr, &fcs))
  5689. type = MIPS_FPU_NONE;
  5690. gdb_printf (file, "fpu type: %s\n",
  5691. type == MIPS_FPU_DOUBLE ? "double-precision"
  5692. : type == MIPS_FPU_SINGLE ? "single-precision"
  5693. : "none / unused");
  5694. if (type == MIPS_FPU_NONE)
  5695. return;
  5696. gdb_printf (file, "reg size: %d bits\n",
  5697. register_size (gdbarch, mips_regnum (gdbarch)->fp0) * 8);
  5698. gdb_puts ("cond :", file);
  5699. if (fcs & (1 << 23))
  5700. gdb_puts (" 0", file);
  5701. for (i = 1; i <= 7; i++)
  5702. if (fcs & (1 << (24 + i)))
  5703. gdb_printf (file, " %d", i);
  5704. gdb_putc ('\n', file);
  5705. gdb_puts ("cause :", file);
  5706. print_fpu_flags (file, (fcs >> 12) & 0x3f);
  5707. fputs ("mask :", stdout);
  5708. print_fpu_flags (file, (fcs >> 7) & 0x1f);
  5709. fputs ("flags :", stdout);
  5710. print_fpu_flags (file, (fcs >> 2) & 0x1f);
  5711. gdb_puts ("rounding: ", file);
  5712. switch (fcs & 3)
  5713. {
  5714. case 0: gdb_puts ("nearest\n", file); break;
  5715. case 1: gdb_puts ("zero\n", file); break;
  5716. case 2: gdb_puts ("+inf\n", file); break;
  5717. case 3: gdb_puts ("-inf\n", file); break;
  5718. }
  5719. gdb_puts ("flush :", file);
  5720. if (fcs & (1 << 21))
  5721. gdb_puts (" nearest", file);
  5722. if (fcs & (1 << 22))
  5723. gdb_puts (" override", file);
  5724. if (fcs & (1 << 24))
  5725. gdb_puts (" zero", file);
  5726. if ((fcs & (0xb << 21)) == 0)
  5727. gdb_puts (" no", file);
  5728. gdb_putc ('\n', file);
  5729. gdb_printf (file, "nan2008 : %s\n", fcs & (1 << 18) ? "yes" : "no");
  5730. gdb_printf (file, "abs2008 : %s\n", fcs & (1 << 19) ? "yes" : "no");
  5731. gdb_putc ('\n', file);
  5732. default_print_float_info (gdbarch, file, frame, args);
  5733. }
  5734. /* Replacement for generic do_registers_info.
  5735. Print regs in pretty columns. */
  5736. static int
  5737. print_fp_register_row (struct ui_file *file, struct frame_info *frame,
  5738. int regnum)
  5739. {
  5740. gdb_printf (file, " ");
  5741. mips_print_fp_register (file, frame, regnum);
  5742. gdb_printf (file, "\n");
  5743. return regnum + 1;
  5744. }
  5745. /* Print a row's worth of GP (int) registers, with name labels above. */
  5746. static int
  5747. print_gp_register_row (struct ui_file *file, struct frame_info *frame,
  5748. int start_regnum)
  5749. {
  5750. struct gdbarch *gdbarch = get_frame_arch (frame);
  5751. /* Do values for GP (int) regs. */
  5752. const gdb_byte *raw_buffer;
  5753. struct value *value;
  5754. int ncols = (mips_abi_regsize (gdbarch) == 8 ? 4 : 8); /* display cols
  5755. per row. */
  5756. int col, byte;
  5757. int regnum;
  5758. /* For GP registers, we print a separate row of names above the vals. */
  5759. for (col = 0, regnum = start_regnum;
  5760. col < ncols && regnum < gdbarch_num_cooked_regs (gdbarch);
  5761. regnum++)
  5762. {
  5763. if (*gdbarch_register_name (gdbarch, regnum) == '\0')
  5764. continue; /* unused register */
  5765. if (mips_float_register_p (gdbarch, regnum))
  5766. break; /* End the row: reached FP register. */
  5767. /* Large registers are handled separately. */
  5768. if (register_size (gdbarch, regnum) > mips_abi_regsize (gdbarch))
  5769. {
  5770. if (col > 0)
  5771. break; /* End the row before this register. */
  5772. /* Print this register on a row by itself. */
  5773. mips_print_register (file, frame, regnum);
  5774. gdb_printf (file, "\n");
  5775. return regnum + 1;
  5776. }
  5777. if (col == 0)
  5778. gdb_printf (file, " ");
  5779. gdb_printf (file,
  5780. mips_abi_regsize (gdbarch) == 8 ? "%17s" : "%9s",
  5781. gdbarch_register_name (gdbarch, regnum));
  5782. col++;
  5783. }
  5784. if (col == 0)
  5785. return regnum;
  5786. /* Print the R0 to R31 names. */
  5787. if ((start_regnum % gdbarch_num_regs (gdbarch)) < MIPS_NUMREGS)
  5788. gdb_printf (file, "\n R%-4d",
  5789. start_regnum % gdbarch_num_regs (gdbarch));
  5790. else
  5791. gdb_printf (file, "\n ");
  5792. /* Now print the values in hex, 4 or 8 to the row. */
  5793. for (col = 0, regnum = start_regnum;
  5794. col < ncols && regnum < gdbarch_num_cooked_regs (gdbarch);
  5795. regnum++)
  5796. {
  5797. if (*gdbarch_register_name (gdbarch, regnum) == '\0')
  5798. continue; /* unused register */
  5799. if (mips_float_register_p (gdbarch, regnum))
  5800. break; /* End row: reached FP register. */
  5801. if (register_size (gdbarch, regnum) > mips_abi_regsize (gdbarch))
  5802. break; /* End row: large register. */
  5803. /* OK: get the data in raw format. */
  5804. value = get_frame_register_value (frame, regnum);
  5805. if (value_optimized_out (value)
  5806. || !value_entirely_available (value))
  5807. {
  5808. gdb_printf (file, "%*s ",
  5809. (int) mips_abi_regsize (gdbarch) * 2,
  5810. (mips_abi_regsize (gdbarch) == 4 ? "<unavl>"
  5811. : "<unavailable>"));
  5812. col++;
  5813. continue;
  5814. }
  5815. raw_buffer = value_contents_all (value).data ();
  5816. /* pad small registers */
  5817. for (byte = 0;
  5818. byte < (mips_abi_regsize (gdbarch)
  5819. - register_size (gdbarch, regnum)); byte++)
  5820. gdb_printf (file, " ");
  5821. /* Now print the register value in hex, endian order. */
  5822. if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  5823. for (byte =
  5824. register_size (gdbarch, regnum) - register_size (gdbarch, regnum);
  5825. byte < register_size (gdbarch, regnum); byte++)
  5826. gdb_printf (file, "%02x", raw_buffer[byte]);
  5827. else
  5828. for (byte = register_size (gdbarch, regnum) - 1;
  5829. byte >= 0; byte--)
  5830. gdb_printf (file, "%02x", raw_buffer[byte]);
  5831. gdb_printf (file, " ");
  5832. col++;
  5833. }
  5834. if (col > 0) /* ie. if we actually printed anything... */
  5835. gdb_printf (file, "\n");
  5836. return regnum;
  5837. }
  5838. /* MIPS_DO_REGISTERS_INFO(): called by "info register" command. */
  5839. static void
  5840. mips_print_registers_info (struct gdbarch *gdbarch, struct ui_file *file,
  5841. struct frame_info *frame, int regnum, int all)
  5842. {
  5843. if (regnum != -1) /* Do one specified register. */
  5844. {
  5845. gdb_assert (regnum >= gdbarch_num_regs (gdbarch));
  5846. if (*(gdbarch_register_name (gdbarch, regnum)) == '\0')
  5847. error (_("Not a valid register for the current processor type"));
  5848. mips_print_register (file, frame, regnum);
  5849. gdb_printf (file, "\n");
  5850. }
  5851. else
  5852. /* Do all (or most) registers. */
  5853. {
  5854. regnum = gdbarch_num_regs (gdbarch);
  5855. while (regnum < gdbarch_num_cooked_regs (gdbarch))
  5856. {
  5857. if (mips_float_register_p (gdbarch, regnum))
  5858. {
  5859. if (all) /* True for "INFO ALL-REGISTERS" command. */
  5860. regnum = print_fp_register_row (file, frame, regnum);
  5861. else
  5862. regnum += MIPS_NUMREGS; /* Skip floating point regs. */
  5863. }
  5864. else
  5865. regnum = print_gp_register_row (file, frame, regnum);
  5866. }
  5867. }
  5868. }
  5869. static int
  5870. mips_single_step_through_delay (struct gdbarch *gdbarch,
  5871. struct frame_info *frame)
  5872. {
  5873. CORE_ADDR pc = get_frame_pc (frame);
  5874. enum mips_isa isa;
  5875. ULONGEST insn;
  5876. int size;
  5877. if ((mips_pc_is_mips (pc)
  5878. && !mips32_insn_at_pc_has_delay_slot (gdbarch, pc))
  5879. || (mips_pc_is_micromips (gdbarch, pc)
  5880. && !micromips_insn_at_pc_has_delay_slot (gdbarch, pc, 0))
  5881. || (mips_pc_is_mips16 (gdbarch, pc)
  5882. && !mips16_insn_at_pc_has_delay_slot (gdbarch, pc, 0)))
  5883. return 0;
  5884. isa = mips_pc_isa (gdbarch, pc);
  5885. /* _has_delay_slot above will have validated the read. */
  5886. insn = mips_fetch_instruction (gdbarch, isa, pc, NULL);
  5887. size = mips_insn_size (isa, insn);
  5888. const address_space *aspace = get_frame_address_space (frame);
  5889. return breakpoint_here_p (aspace, pc + size) != no_breakpoint_here;
  5890. }
  5891. /* To skip prologues, I use this predicate. Returns either PC itself
  5892. if the code at PC does not look like a function prologue; otherwise
  5893. returns an address that (if we're lucky) follows the prologue. If
  5894. LENIENT, then we must skip everything which is involved in setting
  5895. up the frame (it's OK to skip more, just so long as we don't skip
  5896. anything which might clobber the registers which are being saved.
  5897. We must skip more in the case where part of the prologue is in the
  5898. delay slot of a non-prologue instruction). */
  5899. static CORE_ADDR
  5900. mips_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
  5901. {
  5902. CORE_ADDR limit_pc;
  5903. CORE_ADDR func_addr;
  5904. /* See if we can determine the end of the prologue via the symbol table.
  5905. If so, then return either PC, or the PC after the prologue, whichever
  5906. is greater. */
  5907. if (find_pc_partial_function (pc, NULL, &func_addr, NULL))
  5908. {
  5909. CORE_ADDR post_prologue_pc
  5910. = skip_prologue_using_sal (gdbarch, func_addr);
  5911. if (post_prologue_pc != 0)
  5912. return std::max (pc, post_prologue_pc);
  5913. }
  5914. /* Can't determine prologue from the symbol table, need to examine
  5915. instructions. */
  5916. /* Find an upper limit on the function prologue using the debug
  5917. information. If the debug information could not be used to provide
  5918. that bound, then use an arbitrary large number as the upper bound. */
  5919. limit_pc = skip_prologue_using_sal (gdbarch, pc);
  5920. if (limit_pc == 0)
  5921. limit_pc = pc + 100; /* Magic. */
  5922. if (mips_pc_is_mips16 (gdbarch, pc))
  5923. return mips16_scan_prologue (gdbarch, pc, limit_pc, NULL, NULL);
  5924. else if (mips_pc_is_micromips (gdbarch, pc))
  5925. return micromips_scan_prologue (gdbarch, pc, limit_pc, NULL, NULL);
  5926. else
  5927. return mips32_scan_prologue (gdbarch, pc, limit_pc, NULL, NULL);
  5928. }
  5929. /* Implement the stack_frame_destroyed_p gdbarch method (32-bit version).
  5930. This is a helper function for mips_stack_frame_destroyed_p. */
  5931. static int
  5932. mips32_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
  5933. {
  5934. CORE_ADDR func_addr = 0, func_end = 0;
  5935. if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
  5936. {
  5937. /* The MIPS epilogue is max. 12 bytes long. */
  5938. CORE_ADDR addr = func_end - 12;
  5939. if (addr < func_addr + 4)
  5940. addr = func_addr + 4;
  5941. if (pc < addr)
  5942. return 0;
  5943. for (; pc < func_end; pc += MIPS_INSN32_SIZE)
  5944. {
  5945. unsigned long high_word;
  5946. unsigned long inst;
  5947. inst = mips_fetch_instruction (gdbarch, ISA_MIPS, pc, NULL);
  5948. high_word = (inst >> 16) & 0xffff;
  5949. if (high_word != 0x27bd /* addiu $sp,$sp,offset */
  5950. && high_word != 0x67bd /* daddiu $sp,$sp,offset */
  5951. && inst != 0x03e00008 /* jr $ra */
  5952. && inst != 0x00000000) /* nop */
  5953. return 0;
  5954. }
  5955. return 1;
  5956. }
  5957. return 0;
  5958. }
  5959. /* Implement the stack_frame_destroyed_p gdbarch method (microMIPS version).
  5960. This is a helper function for mips_stack_frame_destroyed_p. */
  5961. static int
  5962. micromips_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
  5963. {
  5964. CORE_ADDR func_addr = 0;
  5965. CORE_ADDR func_end = 0;
  5966. CORE_ADDR addr;
  5967. ULONGEST insn;
  5968. long offset;
  5969. int dreg;
  5970. int sreg;
  5971. int loc;
  5972. if (!find_pc_partial_function (pc, NULL, &func_addr, &func_end))
  5973. return 0;
  5974. /* The microMIPS epilogue is max. 12 bytes long. */
  5975. addr = func_end - 12;
  5976. if (addr < func_addr + 2)
  5977. addr = func_addr + 2;
  5978. if (pc < addr)
  5979. return 0;
  5980. for (; pc < func_end; pc += loc)
  5981. {
  5982. loc = 0;
  5983. insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, NULL);
  5984. loc += MIPS_INSN16_SIZE;
  5985. switch (mips_insn_size (ISA_MICROMIPS, insn))
  5986. {
  5987. /* 32-bit instructions. */
  5988. case 2 * MIPS_INSN16_SIZE:
  5989. insn <<= 16;
  5990. insn |= mips_fetch_instruction (gdbarch,
  5991. ISA_MICROMIPS, pc + loc, NULL);
  5992. loc += MIPS_INSN16_SIZE;
  5993. switch (micromips_op (insn >> 16))
  5994. {
  5995. case 0xc: /* ADDIU: bits 001100 */
  5996. case 0x17: /* DADDIU: bits 010111 */
  5997. sreg = b0s5_reg (insn >> 16);
  5998. dreg = b5s5_reg (insn >> 16);
  5999. offset = (b0s16_imm (insn) ^ 0x8000) - 0x8000;
  6000. if (sreg == MIPS_SP_REGNUM && dreg == MIPS_SP_REGNUM
  6001. /* (D)ADDIU $sp, imm */
  6002. && offset >= 0)
  6003. break;
  6004. return 0;
  6005. default:
  6006. return 0;
  6007. }
  6008. break;
  6009. /* 16-bit instructions. */
  6010. case MIPS_INSN16_SIZE:
  6011. switch (micromips_op (insn))
  6012. {
  6013. case 0x3: /* MOVE: bits 000011 */
  6014. sreg = b0s5_reg (insn);
  6015. dreg = b5s5_reg (insn);
  6016. if (sreg == 0 && dreg == 0)
  6017. /* MOVE $zero, $zero aka NOP */
  6018. break;
  6019. return 0;
  6020. case 0x11: /* POOL16C: bits 010001 */
  6021. if (b5s5_op (insn) == 0x18
  6022. /* JRADDIUSP: bits 010011 11000 */
  6023. || (b5s5_op (insn) == 0xd
  6024. /* JRC: bits 010011 01101 */
  6025. && b0s5_reg (insn) == MIPS_RA_REGNUM))
  6026. /* JRC $ra */
  6027. break;
  6028. return 0;
  6029. case 0x13: /* POOL16D: bits 010011 */
  6030. offset = micromips_decode_imm9 (b1s9_imm (insn));
  6031. if ((insn & 0x1) == 0x1
  6032. /* ADDIUSP: bits 010011 1 */
  6033. && offset > 0)
  6034. break;
  6035. return 0;
  6036. default:
  6037. return 0;
  6038. }
  6039. }
  6040. }
  6041. return 1;
  6042. }
  6043. /* Implement the stack_frame_destroyed_p gdbarch method (16-bit version).
  6044. This is a helper function for mips_stack_frame_destroyed_p. */
  6045. static int
  6046. mips16_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
  6047. {
  6048. CORE_ADDR func_addr = 0, func_end = 0;
  6049. if (find_pc_partial_function (pc, NULL, &func_addr, &func_end))
  6050. {
  6051. /* The MIPS epilogue is max. 12 bytes long. */
  6052. CORE_ADDR addr = func_end - 12;
  6053. if (addr < func_addr + 4)
  6054. addr = func_addr + 4;
  6055. if (pc < addr)
  6056. return 0;
  6057. for (; pc < func_end; pc += MIPS_INSN16_SIZE)
  6058. {
  6059. unsigned short inst;
  6060. inst = mips_fetch_instruction (gdbarch, ISA_MIPS16, pc, NULL);
  6061. if ((inst & 0xf800) == 0xf000) /* extend */
  6062. continue;
  6063. if (inst != 0x6300 /* addiu $sp,offset */
  6064. && inst != 0xfb00 /* daddiu $sp,$sp,offset */
  6065. && inst != 0xe820 /* jr $ra */
  6066. && inst != 0xe8a0 /* jrc $ra */
  6067. && inst != 0x6500) /* nop */
  6068. return 0;
  6069. }
  6070. return 1;
  6071. }
  6072. return 0;
  6073. }
  6074. /* Implement the stack_frame_destroyed_p gdbarch method.
  6075. The epilogue is defined here as the area at the end of a function,
  6076. after an instruction which destroys the function's stack frame. */
  6077. static int
  6078. mips_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
  6079. {
  6080. if (mips_pc_is_mips16 (gdbarch, pc))
  6081. return mips16_stack_frame_destroyed_p (gdbarch, pc);
  6082. else if (mips_pc_is_micromips (gdbarch, pc))
  6083. return micromips_stack_frame_destroyed_p (gdbarch, pc);
  6084. else
  6085. return mips32_stack_frame_destroyed_p (gdbarch, pc);
  6086. }
  6087. /* Commands to show/set the MIPS FPU type. */
  6088. static void
  6089. show_mipsfpu_command (const char *args, int from_tty)
  6090. {
  6091. const char *fpu;
  6092. if (gdbarch_bfd_arch_info (target_gdbarch ())->arch != bfd_arch_mips)
  6093. {
  6094. gdb_printf
  6095. ("The MIPS floating-point coprocessor is unknown "
  6096. "because the current architecture is not MIPS.\n");
  6097. return;
  6098. }
  6099. switch (mips_get_fpu_type (target_gdbarch ()))
  6100. {
  6101. case MIPS_FPU_SINGLE:
  6102. fpu = "single-precision";
  6103. break;
  6104. case MIPS_FPU_DOUBLE:
  6105. fpu = "double-precision";
  6106. break;
  6107. case MIPS_FPU_NONE:
  6108. fpu = "absent (none)";
  6109. break;
  6110. default:
  6111. internal_error (__FILE__, __LINE__, _("bad switch"));
  6112. }
  6113. if (mips_fpu_type_auto)
  6114. gdb_printf ("The MIPS floating-point coprocessor "
  6115. "is set automatically (currently %s)\n",
  6116. fpu);
  6117. else
  6118. gdb_printf
  6119. ("The MIPS floating-point coprocessor is assumed to be %s\n", fpu);
  6120. }
  6121. static void
  6122. set_mipsfpu_single_command (const char *args, int from_tty)
  6123. {
  6124. struct gdbarch_info info;
  6125. mips_fpu_type = MIPS_FPU_SINGLE;
  6126. mips_fpu_type_auto = 0;
  6127. /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
  6128. instead of relying on globals. Doing that would let generic code
  6129. handle the search for this specific architecture. */
  6130. if (!gdbarch_update_p (info))
  6131. internal_error (__FILE__, __LINE__, _("set mipsfpu failed"));
  6132. }
  6133. static void
  6134. set_mipsfpu_double_command (const char *args, int from_tty)
  6135. {
  6136. struct gdbarch_info info;
  6137. mips_fpu_type = MIPS_FPU_DOUBLE;
  6138. mips_fpu_type_auto = 0;
  6139. /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
  6140. instead of relying on globals. Doing that would let generic code
  6141. handle the search for this specific architecture. */
  6142. if (!gdbarch_update_p (info))
  6143. internal_error (__FILE__, __LINE__, _("set mipsfpu failed"));
  6144. }
  6145. static void
  6146. set_mipsfpu_none_command (const char *args, int from_tty)
  6147. {
  6148. struct gdbarch_info info;
  6149. mips_fpu_type = MIPS_FPU_NONE;
  6150. mips_fpu_type_auto = 0;
  6151. /* FIXME: cagney/2003-11-15: Should be setting a field in "info"
  6152. instead of relying on globals. Doing that would let generic code
  6153. handle the search for this specific architecture. */
  6154. if (!gdbarch_update_p (info))
  6155. internal_error (__FILE__, __LINE__, _("set mipsfpu failed"));
  6156. }
  6157. static void
  6158. set_mipsfpu_auto_command (const char *args, int from_tty)
  6159. {
  6160. mips_fpu_type_auto = 1;
  6161. }
  6162. /* Just like reinit_frame_cache, but with the right arguments to be
  6163. callable as an sfunc. */
  6164. static void
  6165. reinit_frame_cache_sfunc (const char *args, int from_tty,
  6166. struct cmd_list_element *c)
  6167. {
  6168. reinit_frame_cache ();
  6169. }
  6170. static int
  6171. gdb_print_insn_mips (bfd_vma memaddr, struct disassemble_info *info)
  6172. {
  6173. gdb_disassembler *di
  6174. = static_cast<gdb_disassembler *>(info->application_data);
  6175. struct gdbarch *gdbarch = di->arch ();
  6176. /* FIXME: cagney/2003-06-26: Is this even necessary? The
  6177. disassembler needs to be able to locally determine the ISA, and
  6178. not rely on GDB. Otherwize the stand-alone 'objdump -d' will not
  6179. work. */
  6180. if (mips_pc_is_mips16 (gdbarch, memaddr))
  6181. info->mach = bfd_mach_mips16;
  6182. else if (mips_pc_is_micromips (gdbarch, memaddr))
  6183. info->mach = bfd_mach_mips_micromips;
  6184. /* Round down the instruction address to the appropriate boundary. */
  6185. memaddr &= (info->mach == bfd_mach_mips16
  6186. || info->mach == bfd_mach_mips_micromips) ? ~1 : ~3;
  6187. return default_print_insn (memaddr, info);
  6188. }
  6189. /* Implement the breakpoint_kind_from_pc gdbarch method. */
  6190. static int
  6191. mips_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
  6192. {
  6193. CORE_ADDR pc = *pcptr;
  6194. if (mips_pc_is_mips16 (gdbarch, pc))
  6195. {
  6196. *pcptr = unmake_compact_addr (pc);
  6197. return MIPS_BP_KIND_MIPS16;
  6198. }
  6199. else if (mips_pc_is_micromips (gdbarch, pc))
  6200. {
  6201. ULONGEST insn;
  6202. int status;
  6203. *pcptr = unmake_compact_addr (pc);
  6204. insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, pc, &status);
  6205. if (status || (mips_insn_size (ISA_MICROMIPS, insn) == 2))
  6206. return MIPS_BP_KIND_MICROMIPS16;
  6207. else
  6208. return MIPS_BP_KIND_MICROMIPS32;
  6209. }
  6210. else
  6211. return MIPS_BP_KIND_MIPS32;
  6212. }
  6213. /* Implement the sw_breakpoint_from_kind gdbarch method. */
  6214. static const gdb_byte *
  6215. mips_sw_breakpoint_from_kind (struct gdbarch *gdbarch, int kind, int *size)
  6216. {
  6217. enum bfd_endian byte_order_for_code = gdbarch_byte_order_for_code (gdbarch);
  6218. switch (kind)
  6219. {
  6220. case MIPS_BP_KIND_MIPS16:
  6221. {
  6222. static gdb_byte mips16_big_breakpoint[] = { 0xe8, 0xa5 };
  6223. static gdb_byte mips16_little_breakpoint[] = { 0xa5, 0xe8 };
  6224. *size = 2;
  6225. if (byte_order_for_code == BFD_ENDIAN_BIG)
  6226. return mips16_big_breakpoint;
  6227. else
  6228. return mips16_little_breakpoint;
  6229. }
  6230. case MIPS_BP_KIND_MICROMIPS16:
  6231. {
  6232. static gdb_byte micromips16_big_breakpoint[] = { 0x46, 0x85 };
  6233. static gdb_byte micromips16_little_breakpoint[] = { 0x85, 0x46 };
  6234. *size = 2;
  6235. if (byte_order_for_code == BFD_ENDIAN_BIG)
  6236. return micromips16_big_breakpoint;
  6237. else
  6238. return micromips16_little_breakpoint;
  6239. }
  6240. case MIPS_BP_KIND_MICROMIPS32:
  6241. {
  6242. static gdb_byte micromips32_big_breakpoint[] = { 0, 0x5, 0, 0x7 };
  6243. static gdb_byte micromips32_little_breakpoint[] = { 0x5, 0, 0x7, 0 };
  6244. *size = 4;
  6245. if (byte_order_for_code == BFD_ENDIAN_BIG)
  6246. return micromips32_big_breakpoint;
  6247. else
  6248. return micromips32_little_breakpoint;
  6249. }
  6250. case MIPS_BP_KIND_MIPS32:
  6251. {
  6252. static gdb_byte big_breakpoint[] = { 0, 0x5, 0, 0xd };
  6253. static gdb_byte little_breakpoint[] = { 0xd, 0, 0x5, 0 };
  6254. *size = 4;
  6255. if (byte_order_for_code == BFD_ENDIAN_BIG)
  6256. return big_breakpoint;
  6257. else
  6258. return little_breakpoint;
  6259. }
  6260. default:
  6261. gdb_assert_not_reached ("unexpected mips breakpoint kind");
  6262. };
  6263. }
  6264. /* Return non-zero if the standard MIPS instruction INST has a branch
  6265. delay slot (i.e. it is a jump or branch instruction). This function
  6266. is based on mips32_next_pc. */
  6267. static int
  6268. mips32_instruction_has_delay_slot (struct gdbarch *gdbarch, ULONGEST inst)
  6269. {
  6270. int op;
  6271. int rs;
  6272. int rt;
  6273. op = itype_op (inst);
  6274. if ((inst & 0xe0000000) != 0)
  6275. {
  6276. rs = itype_rs (inst);
  6277. rt = itype_rt (inst);
  6278. return (is_octeon_bbit_op (op, gdbarch)
  6279. || op >> 2 == 5 /* BEQL, BNEL, BLEZL, BGTZL: bits 0101xx */
  6280. || op == 29 /* JALX: bits 011101 */
  6281. || (op == 17
  6282. && (rs == 8
  6283. /* BC1F, BC1FL, BC1T, BC1TL: 010001 01000 */
  6284. || (rs == 9 && (rt & 0x2) == 0)
  6285. /* BC1ANY2F, BC1ANY2T: bits 010001 01001 */
  6286. || (rs == 10 && (rt & 0x2) == 0))));
  6287. /* BC1ANY4F, BC1ANY4T: bits 010001 01010 */
  6288. }
  6289. else
  6290. switch (op & 0x07) /* extract bits 28,27,26 */
  6291. {
  6292. case 0: /* SPECIAL */
  6293. op = rtype_funct (inst);
  6294. return (op == 8 /* JR */
  6295. || op == 9); /* JALR */
  6296. break; /* end SPECIAL */
  6297. case 1: /* REGIMM */
  6298. rs = itype_rs (inst);
  6299. rt = itype_rt (inst); /* branch condition */
  6300. return ((rt & 0xc) == 0
  6301. /* BLTZ, BLTZL, BGEZ, BGEZL: bits 000xx */
  6302. /* BLTZAL, BLTZALL, BGEZAL, BGEZALL: 100xx */
  6303. || ((rt & 0x1e) == 0x1c && rs == 0));
  6304. /* BPOSGE32, BPOSGE64: bits 1110x */
  6305. break; /* end REGIMM */
  6306. default: /* J, JAL, BEQ, BNE, BLEZ, BGTZ */
  6307. return 1;
  6308. break;
  6309. }
  6310. }
  6311. /* Return non-zero if a standard MIPS instruction at ADDR has a branch
  6312. delay slot (i.e. it is a jump or branch instruction). */
  6313. static int
  6314. mips32_insn_at_pc_has_delay_slot (struct gdbarch *gdbarch, CORE_ADDR addr)
  6315. {
  6316. ULONGEST insn;
  6317. int status;
  6318. insn = mips_fetch_instruction (gdbarch, ISA_MIPS, addr, &status);
  6319. if (status)
  6320. return 0;
  6321. return mips32_instruction_has_delay_slot (gdbarch, insn);
  6322. }
  6323. /* Return non-zero if the microMIPS instruction INSN, comprising the
  6324. 16-bit major opcode word in the high 16 bits and any second word
  6325. in the low 16 bits, has a branch delay slot (i.e. it is a non-compact
  6326. jump or branch instruction). The instruction must be 32-bit if
  6327. MUSTBE32 is set or can be any instruction otherwise. */
  6328. static int
  6329. micromips_instruction_has_delay_slot (ULONGEST insn, int mustbe32)
  6330. {
  6331. ULONGEST major = insn >> 16;
  6332. switch (micromips_op (major))
  6333. {
  6334. /* 16-bit instructions. */
  6335. case 0x33: /* B16: bits 110011 */
  6336. case 0x2b: /* BNEZ16: bits 101011 */
  6337. case 0x23: /* BEQZ16: bits 100011 */
  6338. return !mustbe32;
  6339. case 0x11: /* POOL16C: bits 010001 */
  6340. return (!mustbe32
  6341. && ((b5s5_op (major) == 0xc
  6342. /* JR16: bits 010001 01100 */
  6343. || (b5s5_op (major) & 0x1e) == 0xe)));
  6344. /* JALR16, JALRS16: bits 010001 0111x */
  6345. /* 32-bit instructions. */
  6346. case 0x3d: /* JAL: bits 111101 */
  6347. case 0x3c: /* JALX: bits 111100 */
  6348. case 0x35: /* J: bits 110101 */
  6349. case 0x2d: /* BNE: bits 101101 */
  6350. case 0x25: /* BEQ: bits 100101 */
  6351. case 0x1d: /* JALS: bits 011101 */
  6352. return 1;
  6353. case 0x10: /* POOL32I: bits 010000 */
  6354. return ((b5s5_op (major) & 0x1c) == 0x0
  6355. /* BLTZ, BLTZAL, BGEZ, BGEZAL: 010000 000xx */
  6356. || (b5s5_op (major) & 0x1d) == 0x4
  6357. /* BLEZ, BGTZ: bits 010000 001x0 */
  6358. || (b5s5_op (major) & 0x1d) == 0x11
  6359. /* BLTZALS, BGEZALS: bits 010000 100x1 */
  6360. || ((b5s5_op (major) & 0x1e) == 0x14
  6361. && (major & 0x3) == 0x0)
  6362. /* BC2F, BC2T: bits 010000 1010x xxx00 */
  6363. || (b5s5_op (major) & 0x1e) == 0x1a
  6364. /* BPOSGE64, BPOSGE32: bits 010000 1101x */
  6365. || ((b5s5_op (major) & 0x1e) == 0x1c
  6366. && (major & 0x3) == 0x0)
  6367. /* BC1F, BC1T: bits 010000 1110x xxx00 */
  6368. || ((b5s5_op (major) & 0x1c) == 0x1c
  6369. && (major & 0x3) == 0x1));
  6370. /* BC1ANY*: bits 010000 111xx xxx01 */
  6371. case 0x0: /* POOL32A: bits 000000 */
  6372. return (b0s6_op (insn) == 0x3c
  6373. /* POOL32Axf: bits 000000 ... 111100 */
  6374. && (b6s10_ext (insn) & 0x2bf) == 0x3c);
  6375. /* JALR, JALR.HB: 000000 000x111100 111100 */
  6376. /* JALRS, JALRS.HB: 000000 010x111100 111100 */
  6377. default:
  6378. return 0;
  6379. }
  6380. }
  6381. /* Return non-zero if a microMIPS instruction at ADDR has a branch delay
  6382. slot (i.e. it is a non-compact jump instruction). The instruction
  6383. must be 32-bit if MUSTBE32 is set or can be any instruction otherwise. */
  6384. static int
  6385. micromips_insn_at_pc_has_delay_slot (struct gdbarch *gdbarch,
  6386. CORE_ADDR addr, int mustbe32)
  6387. {
  6388. ULONGEST insn;
  6389. int status;
  6390. int size;
  6391. insn = mips_fetch_instruction (gdbarch, ISA_MICROMIPS, addr, &status);
  6392. if (status)
  6393. return 0;
  6394. size = mips_insn_size (ISA_MICROMIPS, insn);
  6395. insn <<= 16;
  6396. if (size == 2 * MIPS_INSN16_SIZE)
  6397. {
  6398. insn |= mips_fetch_instruction (gdbarch, ISA_MICROMIPS, addr, &status);
  6399. if (status)
  6400. return 0;
  6401. }
  6402. return micromips_instruction_has_delay_slot (insn, mustbe32);
  6403. }
  6404. /* Return non-zero if the MIPS16 instruction INST, which must be
  6405. a 32-bit instruction if MUSTBE32 is set or can be any instruction
  6406. otherwise, has a branch delay slot (i.e. it is a non-compact jump
  6407. instruction). This function is based on mips16_next_pc. */
  6408. static int
  6409. mips16_instruction_has_delay_slot (unsigned short inst, int mustbe32)
  6410. {
  6411. if ((inst & 0xf89f) == 0xe800) /* JR/JALR (16-bit instruction) */
  6412. return !mustbe32;
  6413. return (inst & 0xf800) == 0x1800; /* JAL/JALX (32-bit instruction) */
  6414. }
  6415. /* Return non-zero if a MIPS16 instruction at ADDR has a branch delay
  6416. slot (i.e. it is a non-compact jump instruction). The instruction
  6417. must be 32-bit if MUSTBE32 is set or can be any instruction otherwise. */
  6418. static int
  6419. mips16_insn_at_pc_has_delay_slot (struct gdbarch *gdbarch,
  6420. CORE_ADDR addr, int mustbe32)
  6421. {
  6422. unsigned short insn;
  6423. int status;
  6424. insn = mips_fetch_instruction (gdbarch, ISA_MIPS16, addr, &status);
  6425. if (status)
  6426. return 0;
  6427. return mips16_instruction_has_delay_slot (insn, mustbe32);
  6428. }
  6429. /* Calculate the starting address of the MIPS memory segment BPADDR is in.
  6430. This assumes KSSEG exists. */
  6431. static CORE_ADDR
  6432. mips_segment_boundary (CORE_ADDR bpaddr)
  6433. {
  6434. CORE_ADDR mask = CORE_ADDR_MAX;
  6435. int segsize;
  6436. if (sizeof (CORE_ADDR) == 8)
  6437. /* Get the topmost two bits of bpaddr in a 32-bit safe manner (avoid
  6438. a compiler warning produced where CORE_ADDR is a 32-bit type even
  6439. though in that case this is dead code). */
  6440. switch (bpaddr >> ((sizeof (CORE_ADDR) << 3) - 2) & 3)
  6441. {
  6442. case 3:
  6443. if (bpaddr == (bfd_signed_vma) (int32_t) bpaddr)
  6444. segsize = 29; /* 32-bit compatibility segment */
  6445. else
  6446. segsize = 62; /* xkseg */
  6447. break;
  6448. case 2: /* xkphys */
  6449. segsize = 59;
  6450. break;
  6451. default: /* xksseg (1), xkuseg/kuseg (0) */
  6452. segsize = 62;
  6453. break;
  6454. }
  6455. else if (bpaddr & 0x80000000) /* kernel segment */
  6456. segsize = 29;
  6457. else
  6458. segsize = 31; /* user segment */
  6459. mask <<= segsize;
  6460. return bpaddr & mask;
  6461. }
  6462. /* Move the breakpoint at BPADDR out of any branch delay slot by shifting
  6463. it backwards if necessary. Return the address of the new location. */
  6464. static CORE_ADDR
  6465. mips_adjust_breakpoint_address (struct gdbarch *gdbarch, CORE_ADDR bpaddr)
  6466. {
  6467. CORE_ADDR prev_addr;
  6468. CORE_ADDR boundary;
  6469. CORE_ADDR func_addr;
  6470. /* If a breakpoint is set on the instruction in a branch delay slot,
  6471. GDB gets confused. When the breakpoint is hit, the PC isn't on
  6472. the instruction in the branch delay slot, the PC will point to
  6473. the branch instruction. Since the PC doesn't match any known
  6474. breakpoints, GDB reports a trap exception.
  6475. There are two possible fixes for this problem.
  6476. 1) When the breakpoint gets hit, see if the BD bit is set in the
  6477. Cause register (which indicates the last exception occurred in a
  6478. branch delay slot). If the BD bit is set, fix the PC to point to
  6479. the instruction in the branch delay slot.
  6480. 2) When the user sets the breakpoint, don't allow him to set the
  6481. breakpoint on the instruction in the branch delay slot. Instead
  6482. move the breakpoint to the branch instruction (which will have
  6483. the same result).
  6484. The problem with the first solution is that if the user then
  6485. single-steps the processor, the branch instruction will get
  6486. skipped (since GDB thinks the PC is on the instruction in the
  6487. branch delay slot).
  6488. So, we'll use the second solution. To do this we need to know if
  6489. the instruction we're trying to set the breakpoint on is in the
  6490. branch delay slot. */
  6491. boundary = mips_segment_boundary (bpaddr);
  6492. /* Make sure we don't scan back before the beginning of the current
  6493. function, since we may fetch constant data or insns that look like
  6494. a jump. Of course we might do that anyway if the compiler has
  6495. moved constants inline. :-( */
  6496. if (find_pc_partial_function (bpaddr, NULL, &func_addr, NULL)
  6497. && func_addr > boundary && func_addr <= bpaddr)
  6498. boundary = func_addr;
  6499. if (mips_pc_is_mips (bpaddr))
  6500. {
  6501. if (bpaddr == boundary)
  6502. return bpaddr;
  6503. /* If the previous instruction has a branch delay slot, we have
  6504. to move the breakpoint to the branch instruction. */
  6505. prev_addr = bpaddr - 4;
  6506. if (mips32_insn_at_pc_has_delay_slot (gdbarch, prev_addr))
  6507. bpaddr = prev_addr;
  6508. }
  6509. else
  6510. {
  6511. int (*insn_at_pc_has_delay_slot) (struct gdbarch *, CORE_ADDR, int);
  6512. CORE_ADDR addr, jmpaddr;
  6513. int i;
  6514. boundary = unmake_compact_addr (boundary);
  6515. /* The only MIPS16 instructions with delay slots are JAL, JALX,
  6516. JALR and JR. An absolute JAL/JALX is always 4 bytes long,
  6517. so try for that first, then try the 2 byte JALR/JR.
  6518. The microMIPS ASE has a whole range of jumps and branches
  6519. with delay slots, some of which take 4 bytes and some take
  6520. 2 bytes, so the idea is the same.
  6521. FIXME: We have to assume that bpaddr is not the second half
  6522. of an extended instruction. */
  6523. insn_at_pc_has_delay_slot = (mips_pc_is_micromips (gdbarch, bpaddr)
  6524. ? micromips_insn_at_pc_has_delay_slot
  6525. : mips16_insn_at_pc_has_delay_slot);
  6526. jmpaddr = 0;
  6527. addr = bpaddr;
  6528. for (i = 1; i < 4; i++)
  6529. {
  6530. if (unmake_compact_addr (addr) == boundary)
  6531. break;
  6532. addr -= MIPS_INSN16_SIZE;
  6533. if (i == 1 && insn_at_pc_has_delay_slot (gdbarch, addr, 0))
  6534. /* Looks like a JR/JALR at [target-1], but it could be
  6535. the second word of a previous JAL/JALX, so record it
  6536. and check back one more. */
  6537. jmpaddr = addr;
  6538. else if (i > 1 && insn_at_pc_has_delay_slot (gdbarch, addr, 1))
  6539. {
  6540. if (i == 2)
  6541. /* Looks like a JAL/JALX at [target-2], but it could also
  6542. be the second word of a previous JAL/JALX, record it,
  6543. and check back one more. */
  6544. jmpaddr = addr;
  6545. else
  6546. /* Looks like a JAL/JALX at [target-3], so any previously
  6547. recorded JAL/JALX or JR/JALR must be wrong, because:
  6548. >-3: JAL
  6549. -2: JAL-ext (can't be JAL/JALX)
  6550. -1: bdslot (can't be JR/JALR)
  6551. 0: target insn
  6552. Of course it could be another JAL-ext which looks
  6553. like a JAL, but in that case we'd have broken out
  6554. of this loop at [target-2]:
  6555. -4: JAL
  6556. >-3: JAL-ext
  6557. -2: bdslot (can't be jmp)
  6558. -1: JR/JALR
  6559. 0: target insn */
  6560. jmpaddr = 0;
  6561. }
  6562. else
  6563. {
  6564. /* Not a jump instruction: if we're at [target-1] this
  6565. could be the second word of a JAL/JALX, so continue;
  6566. otherwise we're done. */
  6567. if (i > 1)
  6568. break;
  6569. }
  6570. }
  6571. if (jmpaddr)
  6572. bpaddr = jmpaddr;
  6573. }
  6574. return bpaddr;
  6575. }
  6576. /* Return non-zero if SUFFIX is one of the numeric suffixes used for MIPS16
  6577. call stubs, one of 1, 2, 5, 6, 9, 10, or, if ZERO is non-zero, also 0. */
  6578. static int
  6579. mips_is_stub_suffix (const char *suffix, int zero)
  6580. {
  6581. switch (suffix[0])
  6582. {
  6583. case '0':
  6584. return zero && suffix[1] == '\0';
  6585. case '1':
  6586. return suffix[1] == '\0' || (suffix[1] == '0' && suffix[2] == '\0');
  6587. case '2':
  6588. case '5':
  6589. case '6':
  6590. case '9':
  6591. return suffix[1] == '\0';
  6592. default:
  6593. return 0;
  6594. }
  6595. }
  6596. /* Return non-zero if MODE is one of the mode infixes used for MIPS16
  6597. call stubs, one of sf, df, sc, or dc. */
  6598. static int
  6599. mips_is_stub_mode (const char *mode)
  6600. {
  6601. return ((mode[0] == 's' || mode[0] == 'd')
  6602. && (mode[1] == 'f' || mode[1] == 'c'));
  6603. }
  6604. /* Code at PC is a compiler-generated stub. Such a stub for a function
  6605. bar might have a name like __fn_stub_bar, and might look like this:
  6606. mfc1 $4, $f13
  6607. mfc1 $5, $f12
  6608. mfc1 $6, $f15
  6609. mfc1 $7, $f14
  6610. followed by (or interspersed with):
  6611. j bar
  6612. or:
  6613. lui $25, %hi(bar)
  6614. addiu $25, $25, %lo(bar)
  6615. jr $25
  6616. ($1 may be used in old code; for robustness we accept any register)
  6617. or, in PIC code:
  6618. lui $28, %hi(_gp_disp)
  6619. addiu $28, $28, %lo(_gp_disp)
  6620. addu $28, $28, $25
  6621. lw $25, %got(bar)
  6622. addiu $25, $25, %lo(bar)
  6623. jr $25
  6624. In the case of a __call_stub_bar stub, the sequence to set up
  6625. arguments might look like this:
  6626. mtc1 $4, $f13
  6627. mtc1 $5, $f12
  6628. mtc1 $6, $f15
  6629. mtc1 $7, $f14
  6630. followed by (or interspersed with) one of the jump sequences above.
  6631. In the case of a __call_stub_fp_bar stub, JAL or JALR is used instead
  6632. of J or JR, respectively, followed by:
  6633. mfc1 $2, $f0
  6634. mfc1 $3, $f1
  6635. jr $18
  6636. We are at the beginning of the stub here, and scan down and extract
  6637. the target address from the jump immediate instruction or, if a jump
  6638. register instruction is used, from the register referred. Return
  6639. the value of PC calculated or 0 if inconclusive.
  6640. The limit on the search is arbitrarily set to 20 instructions. FIXME. */
  6641. static CORE_ADDR
  6642. mips_get_mips16_fn_stub_pc (struct frame_info *frame, CORE_ADDR pc)
  6643. {
  6644. struct gdbarch *gdbarch = get_frame_arch (frame);
  6645. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  6646. int addrreg = MIPS_ZERO_REGNUM;
  6647. CORE_ADDR start_pc = pc;
  6648. CORE_ADDR target_pc = 0;
  6649. CORE_ADDR addr = 0;
  6650. CORE_ADDR gp = 0;
  6651. int status = 0;
  6652. int i;
  6653. for (i = 0;
  6654. status == 0 && target_pc == 0 && i < 20;
  6655. i++, pc += MIPS_INSN32_SIZE)
  6656. {
  6657. ULONGEST inst = mips_fetch_instruction (gdbarch, ISA_MIPS, pc, NULL);
  6658. CORE_ADDR imm;
  6659. int rt;
  6660. int rs;
  6661. int rd;
  6662. switch (itype_op (inst))
  6663. {
  6664. case 0: /* SPECIAL */
  6665. switch (rtype_funct (inst))
  6666. {
  6667. case 8: /* JR */
  6668. case 9: /* JALR */
  6669. rs = rtype_rs (inst);
  6670. if (rs == MIPS_GP_REGNUM)
  6671. target_pc = gp; /* Hmm... */
  6672. else if (rs == addrreg)
  6673. target_pc = addr;
  6674. break;
  6675. case 0x21: /* ADDU */
  6676. rt = rtype_rt (inst);
  6677. rs = rtype_rs (inst);
  6678. rd = rtype_rd (inst);
  6679. if (rd == MIPS_GP_REGNUM
  6680. && ((rs == MIPS_GP_REGNUM && rt == MIPS_T9_REGNUM)
  6681. || (rs == MIPS_T9_REGNUM && rt == MIPS_GP_REGNUM)))
  6682. gp += start_pc;
  6683. break;
  6684. }
  6685. break;
  6686. case 2: /* J */
  6687. case 3: /* JAL */
  6688. target_pc = jtype_target (inst) << 2;
  6689. target_pc += ((pc + 4) & ~(CORE_ADDR) 0x0fffffff);
  6690. break;
  6691. case 9: /* ADDIU */
  6692. rt = itype_rt (inst);
  6693. rs = itype_rs (inst);
  6694. if (rt == rs)
  6695. {
  6696. imm = (itype_immediate (inst) ^ 0x8000) - 0x8000;
  6697. if (rt == MIPS_GP_REGNUM)
  6698. gp += imm;
  6699. else if (rt == addrreg)
  6700. addr += imm;
  6701. }
  6702. break;
  6703. case 0xf: /* LUI */
  6704. rt = itype_rt (inst);
  6705. imm = ((itype_immediate (inst) ^ 0x8000) - 0x8000) << 16;
  6706. if (rt == MIPS_GP_REGNUM)
  6707. gp = imm;
  6708. else if (rt != MIPS_ZERO_REGNUM)
  6709. {
  6710. addrreg = rt;
  6711. addr = imm;
  6712. }
  6713. break;
  6714. case 0x23: /* LW */
  6715. rt = itype_rt (inst);
  6716. rs = itype_rs (inst);
  6717. imm = (itype_immediate (inst) ^ 0x8000) - 0x8000;
  6718. if (gp != 0 && rs == MIPS_GP_REGNUM)
  6719. {
  6720. gdb_byte buf[4];
  6721. memset (buf, 0, sizeof (buf));
  6722. status = target_read_memory (gp + imm, buf, sizeof (buf));
  6723. addrreg = rt;
  6724. addr = extract_signed_integer (buf, sizeof (buf), byte_order);
  6725. }
  6726. break;
  6727. }
  6728. }
  6729. return target_pc;
  6730. }
  6731. /* If PC is in a MIPS16 call or return stub, return the address of the
  6732. target PC, which is either the callee or the caller. There are several
  6733. cases which must be handled:
  6734. * If the PC is in __mips16_ret_{d,s}{f,c}, this is a return stub
  6735. and the target PC is in $31 ($ra).
  6736. * If the PC is in __mips16_call_stub_{1..10}, this is a call stub
  6737. and the target PC is in $2.
  6738. * If the PC at the start of __mips16_call_stub_{s,d}{f,c}_{0..10},
  6739. i.e. before the JALR instruction, this is effectively a call stub
  6740. and the target PC is in $2. Otherwise this is effectively
  6741. a return stub and the target PC is in $18.
  6742. * If the PC is at the start of __call_stub_fp_*, i.e. before the
  6743. JAL or JALR instruction, this is effectively a call stub and the
  6744. target PC is buried in the instruction stream. Otherwise this
  6745. is effectively a return stub and the target PC is in $18.
  6746. * If the PC is in __call_stub_* or in __fn_stub_*, this is a call
  6747. stub and the target PC is buried in the instruction stream.
  6748. See the source code for the stubs in gcc/config/mips/mips16.S, or the
  6749. stub builder in gcc/config/mips/mips.c (mips16_build_call_stub) for the
  6750. gory details. */
  6751. static CORE_ADDR
  6752. mips_skip_mips16_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
  6753. {
  6754. struct gdbarch *gdbarch = get_frame_arch (frame);
  6755. CORE_ADDR start_addr;
  6756. const char *name;
  6757. size_t prefixlen;
  6758. /* Find the starting address and name of the function containing the PC. */
  6759. if (find_pc_partial_function (pc, &name, &start_addr, NULL) == 0)
  6760. return 0;
  6761. /* If the PC is in __mips16_ret_{d,s}{f,c}, this is a return stub
  6762. and the target PC is in $31 ($ra). */
  6763. prefixlen = strlen (mips_str_mips16_ret_stub);
  6764. if (strncmp (name, mips_str_mips16_ret_stub, prefixlen) == 0
  6765. && mips_is_stub_mode (name + prefixlen)
  6766. && name[prefixlen + 2] == '\0')
  6767. return get_frame_register_signed
  6768. (frame, gdbarch_num_regs (gdbarch) + MIPS_RA_REGNUM);
  6769. /* If the PC is in __mips16_call_stub_*, this is one of the call
  6770. call/return stubs. */
  6771. prefixlen = strlen (mips_str_mips16_call_stub);
  6772. if (strncmp (name, mips_str_mips16_call_stub, prefixlen) == 0)
  6773. {
  6774. /* If the PC is in __mips16_call_stub_{1..10}, this is a call stub
  6775. and the target PC is in $2. */
  6776. if (mips_is_stub_suffix (name + prefixlen, 0))
  6777. return get_frame_register_signed
  6778. (frame, gdbarch_num_regs (gdbarch) + MIPS_V0_REGNUM);
  6779. /* If the PC at the start of __mips16_call_stub_{s,d}{f,c}_{0..10},
  6780. i.e. before the JALR instruction, this is effectively a call stub
  6781. and the target PC is in $2. Otherwise this is effectively
  6782. a return stub and the target PC is in $18. */
  6783. else if (mips_is_stub_mode (name + prefixlen)
  6784. && name[prefixlen + 2] == '_'
  6785. && mips_is_stub_suffix (name + prefixlen + 3, 0))
  6786. {
  6787. if (pc == start_addr)
  6788. /* This is the 'call' part of a call stub. The return
  6789. address is in $2. */
  6790. return get_frame_register_signed
  6791. (frame, gdbarch_num_regs (gdbarch) + MIPS_V0_REGNUM);
  6792. else
  6793. /* This is the 'return' part of a call stub. The return
  6794. address is in $18. */
  6795. return get_frame_register_signed
  6796. (frame, gdbarch_num_regs (gdbarch) + MIPS_S2_REGNUM);
  6797. }
  6798. else
  6799. return 0; /* Not a stub. */
  6800. }
  6801. /* If the PC is in __call_stub_* or __fn_stub*, this is one of the
  6802. compiler-generated call or call/return stubs. */
  6803. if (startswith (name, mips_str_fn_stub)
  6804. || startswith (name, mips_str_call_stub))
  6805. {
  6806. if (pc == start_addr)
  6807. /* This is the 'call' part of a call stub. Call this helper
  6808. to scan through this code for interesting instructions
  6809. and determine the final PC. */
  6810. return mips_get_mips16_fn_stub_pc (frame, pc);
  6811. else
  6812. /* This is the 'return' part of a call stub. The return address
  6813. is in $18. */
  6814. return get_frame_register_signed
  6815. (frame, gdbarch_num_regs (gdbarch) + MIPS_S2_REGNUM);
  6816. }
  6817. return 0; /* Not a stub. */
  6818. }
  6819. /* Return non-zero if the PC is inside a return thunk (aka stub or trampoline).
  6820. This implements the IN_SOLIB_RETURN_TRAMPOLINE macro. */
  6821. static int
  6822. mips_in_return_stub (struct gdbarch *gdbarch, CORE_ADDR pc, const char *name)
  6823. {
  6824. CORE_ADDR start_addr;
  6825. size_t prefixlen;
  6826. /* Find the starting address of the function containing the PC. */
  6827. if (find_pc_partial_function (pc, NULL, &start_addr, NULL) == 0)
  6828. return 0;
  6829. /* If the PC is in __mips16_call_stub_{s,d}{f,c}_{0..10} but not at
  6830. the start, i.e. after the JALR instruction, this is effectively
  6831. a return stub. */
  6832. prefixlen = strlen (mips_str_mips16_call_stub);
  6833. if (pc != start_addr
  6834. && strncmp (name, mips_str_mips16_call_stub, prefixlen) == 0
  6835. && mips_is_stub_mode (name + prefixlen)
  6836. && name[prefixlen + 2] == '_'
  6837. && mips_is_stub_suffix (name + prefixlen + 3, 1))
  6838. return 1;
  6839. /* If the PC is in __call_stub_fp_* but not at the start, i.e. after
  6840. the JAL or JALR instruction, this is effectively a return stub. */
  6841. prefixlen = strlen (mips_str_call_fp_stub);
  6842. if (pc != start_addr
  6843. && strncmp (name, mips_str_call_fp_stub, prefixlen) == 0)
  6844. return 1;
  6845. /* Consume the .pic. prefix of any PIC stub, this function must return
  6846. true when the PC is in a PIC stub of a __mips16_ret_{d,s}{f,c} stub
  6847. or the call stub path will trigger in handle_inferior_event causing
  6848. it to go astray. */
  6849. prefixlen = strlen (mips_str_pic);
  6850. if (strncmp (name, mips_str_pic, prefixlen) == 0)
  6851. name += prefixlen;
  6852. /* If the PC is in __mips16_ret_{d,s}{f,c}, this is a return stub. */
  6853. prefixlen = strlen (mips_str_mips16_ret_stub);
  6854. if (strncmp (name, mips_str_mips16_ret_stub, prefixlen) == 0
  6855. && mips_is_stub_mode (name + prefixlen)
  6856. && name[prefixlen + 2] == '\0')
  6857. return 1;
  6858. return 0; /* Not a stub. */
  6859. }
  6860. /* If the current PC is the start of a non-PIC-to-PIC stub, return the
  6861. PC of the stub target. The stub just loads $t9 and jumps to it,
  6862. so that $t9 has the correct value at function entry. */
  6863. static CORE_ADDR
  6864. mips_skip_pic_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
  6865. {
  6866. struct gdbarch *gdbarch = get_frame_arch (frame);
  6867. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  6868. struct bound_minimal_symbol msym;
  6869. int i;
  6870. gdb_byte stub_code[16];
  6871. int32_t stub_words[4];
  6872. /* The stub for foo is named ".pic.foo", and is either two
  6873. instructions inserted before foo or a three instruction sequence
  6874. which jumps to foo. */
  6875. msym = lookup_minimal_symbol_by_pc (pc);
  6876. if (msym.minsym == NULL
  6877. || BMSYMBOL_VALUE_ADDRESS (msym) != pc
  6878. || msym.minsym->linkage_name () == NULL
  6879. || !startswith (msym.minsym->linkage_name (), ".pic."))
  6880. return 0;
  6881. /* A two-instruction header. */
  6882. if (MSYMBOL_SIZE (msym.minsym) == 8)
  6883. return pc + 8;
  6884. /* A three-instruction (plus delay slot) trampoline. */
  6885. if (MSYMBOL_SIZE (msym.minsym) == 16)
  6886. {
  6887. if (target_read_memory (pc, stub_code, 16) != 0)
  6888. return 0;
  6889. for (i = 0; i < 4; i++)
  6890. stub_words[i] = extract_unsigned_integer (stub_code + i * 4,
  6891. 4, byte_order);
  6892. /* A stub contains these instructions:
  6893. lui t9, %hi(target)
  6894. j target
  6895. addiu t9, t9, %lo(target)
  6896. nop
  6897. This works even for N64, since stubs are only generated with
  6898. -msym32. */
  6899. if ((stub_words[0] & 0xffff0000U) == 0x3c190000
  6900. && (stub_words[1] & 0xfc000000U) == 0x08000000
  6901. && (stub_words[2] & 0xffff0000U) == 0x27390000
  6902. && stub_words[3] == 0x00000000)
  6903. return ((((stub_words[0] & 0x0000ffff) << 16)
  6904. + (stub_words[2] & 0x0000ffff)) ^ 0x8000) - 0x8000;
  6905. }
  6906. /* Not a recognized stub. */
  6907. return 0;
  6908. }
  6909. static CORE_ADDR
  6910. mips_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
  6911. {
  6912. CORE_ADDR requested_pc = pc;
  6913. CORE_ADDR target_pc;
  6914. CORE_ADDR new_pc;
  6915. do
  6916. {
  6917. target_pc = pc;
  6918. new_pc = mips_skip_mips16_trampoline_code (frame, pc);
  6919. if (new_pc)
  6920. pc = new_pc;
  6921. new_pc = find_solib_trampoline_target (frame, pc);
  6922. if (new_pc)
  6923. pc = new_pc;
  6924. new_pc = mips_skip_pic_trampoline_code (frame, pc);
  6925. if (new_pc)
  6926. pc = new_pc;
  6927. }
  6928. while (pc != target_pc);
  6929. return pc != requested_pc ? pc : 0;
  6930. }
  6931. /* Convert a dbx stab register number (from `r' declaration) to a GDB
  6932. [1 * gdbarch_num_regs .. 2 * gdbarch_num_regs) REGNUM. */
  6933. static int
  6934. mips_stab_reg_to_regnum (struct gdbarch *gdbarch, int num)
  6935. {
  6936. int regnum;
  6937. if (num >= 0 && num < 32)
  6938. regnum = num;
  6939. else if (num >= 38 && num < 70)
  6940. regnum = num + mips_regnum (gdbarch)->fp0 - 38;
  6941. else if (num == 70)
  6942. regnum = mips_regnum (gdbarch)->hi;
  6943. else if (num == 71)
  6944. regnum = mips_regnum (gdbarch)->lo;
  6945. else if (mips_regnum (gdbarch)->dspacc != -1 && num >= 72 && num < 78)
  6946. regnum = num + mips_regnum (gdbarch)->dspacc - 72;
  6947. else
  6948. return -1;
  6949. return gdbarch_num_regs (gdbarch) + regnum;
  6950. }
  6951. /* Convert a dwarf, dwarf2, or ecoff register number to a GDB [1 *
  6952. gdbarch_num_regs .. 2 * gdbarch_num_regs) REGNUM. */
  6953. static int
  6954. mips_dwarf_dwarf2_ecoff_reg_to_regnum (struct gdbarch *gdbarch, int num)
  6955. {
  6956. int regnum;
  6957. if (num >= 0 && num < 32)
  6958. regnum = num;
  6959. else if (num >= 32 && num < 64)
  6960. regnum = num + mips_regnum (gdbarch)->fp0 - 32;
  6961. else if (num == 64)
  6962. regnum = mips_regnum (gdbarch)->hi;
  6963. else if (num == 65)
  6964. regnum = mips_regnum (gdbarch)->lo;
  6965. else if (mips_regnum (gdbarch)->dspacc != -1 && num >= 66 && num < 72)
  6966. regnum = num + mips_regnum (gdbarch)->dspacc - 66;
  6967. else
  6968. return -1;
  6969. return gdbarch_num_regs (gdbarch) + regnum;
  6970. }
  6971. static int
  6972. mips_register_sim_regno (struct gdbarch *gdbarch, int regnum)
  6973. {
  6974. /* Only makes sense to supply raw registers. */
  6975. gdb_assert (regnum >= 0 && regnum < gdbarch_num_regs (gdbarch));
  6976. /* FIXME: cagney/2002-05-13: Need to look at the pseudo register to
  6977. decide if it is valid. Should instead define a standard sim/gdb
  6978. register numbering scheme. */
  6979. if (gdbarch_register_name (gdbarch,
  6980. gdbarch_num_regs (gdbarch) + regnum) != NULL
  6981. && gdbarch_register_name (gdbarch,
  6982. gdbarch_num_regs (gdbarch)
  6983. + regnum)[0] != '\0')
  6984. return regnum;
  6985. else
  6986. return LEGACY_SIM_REGNO_IGNORE;
  6987. }
  6988. /* Convert an integer into an address. Extracting the value signed
  6989. guarantees a correctly sign extended address. */
  6990. static CORE_ADDR
  6991. mips_integer_to_address (struct gdbarch *gdbarch,
  6992. struct type *type, const gdb_byte *buf)
  6993. {
  6994. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  6995. return extract_signed_integer (buf, TYPE_LENGTH (type), byte_order);
  6996. }
  6997. /* Dummy virtual frame pointer method. This is no more or less accurate
  6998. than most other architectures; we just need to be explicit about it,
  6999. because the pseudo-register gdbarch_sp_regnum will otherwise lead to
  7000. an assertion failure. */
  7001. static void
  7002. mips_virtual_frame_pointer (struct gdbarch *gdbarch,
  7003. CORE_ADDR pc, int *reg, LONGEST *offset)
  7004. {
  7005. *reg = MIPS_SP_REGNUM;
  7006. *offset = 0;
  7007. }
  7008. static void
  7009. mips_find_abi_section (bfd *abfd, asection *sect, void *obj)
  7010. {
  7011. enum mips_abi *abip = (enum mips_abi *) obj;
  7012. const char *name = bfd_section_name (sect);
  7013. if (*abip != MIPS_ABI_UNKNOWN)
  7014. return;
  7015. if (!startswith (name, ".mdebug."))
  7016. return;
  7017. if (strcmp (name, ".mdebug.abi32") == 0)
  7018. *abip = MIPS_ABI_O32;
  7019. else if (strcmp (name, ".mdebug.abiN32") == 0)
  7020. *abip = MIPS_ABI_N32;
  7021. else if (strcmp (name, ".mdebug.abi64") == 0)
  7022. *abip = MIPS_ABI_N64;
  7023. else if (strcmp (name, ".mdebug.abiO64") == 0)
  7024. *abip = MIPS_ABI_O64;
  7025. else if (strcmp (name, ".mdebug.eabi32") == 0)
  7026. *abip = MIPS_ABI_EABI32;
  7027. else if (strcmp (name, ".mdebug.eabi64") == 0)
  7028. *abip = MIPS_ABI_EABI64;
  7029. else
  7030. warning (_("unsupported ABI %s."), name + 8);
  7031. }
  7032. static void
  7033. mips_find_long_section (bfd *abfd, asection *sect, void *obj)
  7034. {
  7035. int *lbp = (int *) obj;
  7036. const char *name = bfd_section_name (sect);
  7037. if (startswith (name, ".gcc_compiled_long32"))
  7038. *lbp = 32;
  7039. else if (startswith (name, ".gcc_compiled_long64"))
  7040. *lbp = 64;
  7041. else if (startswith (name, ".gcc_compiled_long"))
  7042. warning (_("unrecognized .gcc_compiled_longXX"));
  7043. }
  7044. static enum mips_abi
  7045. global_mips_abi (void)
  7046. {
  7047. int i;
  7048. for (i = 0; mips_abi_strings[i] != NULL; i++)
  7049. if (mips_abi_strings[i] == mips_abi_string)
  7050. return (enum mips_abi) i;
  7051. internal_error (__FILE__, __LINE__, _("unknown ABI string"));
  7052. }
  7053. /* Return the default compressed instruction set, either of MIPS16
  7054. or microMIPS, selected when none could have been determined from
  7055. the ELF header of the binary being executed (or no binary has been
  7056. selected. */
  7057. static enum mips_isa
  7058. global_mips_compression (void)
  7059. {
  7060. int i;
  7061. for (i = 0; mips_compression_strings[i] != NULL; i++)
  7062. if (mips_compression_strings[i] == mips_compression_string)
  7063. return (enum mips_isa) i;
  7064. internal_error (__FILE__, __LINE__, _("unknown compressed ISA string"));
  7065. }
  7066. static void
  7067. mips_register_g_packet_guesses (struct gdbarch *gdbarch)
  7068. {
  7069. /* If the size matches the set of 32-bit or 64-bit integer registers,
  7070. assume that's what we've got. */
  7071. register_remote_g_packet_guess (gdbarch, 38 * 4, mips_tdesc_gp32);
  7072. register_remote_g_packet_guess (gdbarch, 38 * 8, mips_tdesc_gp64);
  7073. /* If the size matches the full set of registers GDB traditionally
  7074. knows about, including floating point, for either 32-bit or
  7075. 64-bit, assume that's what we've got. */
  7076. register_remote_g_packet_guess (gdbarch, 90 * 4, mips_tdesc_gp32);
  7077. register_remote_g_packet_guess (gdbarch, 90 * 8, mips_tdesc_gp64);
  7078. /* Otherwise we don't have a useful guess. */
  7079. }
  7080. static struct value *
  7081. value_of_mips_user_reg (struct frame_info *frame, const void *baton)
  7082. {
  7083. const int *reg_p = (const int *) baton;
  7084. return value_of_register (*reg_p, frame);
  7085. }
  7086. static struct gdbarch *
  7087. mips_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
  7088. {
  7089. struct gdbarch *gdbarch;
  7090. int elf_flags;
  7091. enum mips_abi mips_abi, found_abi, wanted_abi;
  7092. int i, num_regs;
  7093. enum mips_fpu_type fpu_type;
  7094. tdesc_arch_data_up tdesc_data;
  7095. int elf_fpu_type = Val_GNU_MIPS_ABI_FP_ANY;
  7096. const char * const *reg_names;
  7097. struct mips_regnum mips_regnum, *regnum;
  7098. enum mips_isa mips_isa;
  7099. int dspacc;
  7100. int dspctl;
  7101. /* First of all, extract the elf_flags, if available. */
  7102. if (info.abfd && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
  7103. elf_flags = elf_elfheader (info.abfd)->e_flags;
  7104. else if (arches != NULL)
  7105. {
  7106. mips_gdbarch_tdep *tdep
  7107. = (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
  7108. elf_flags = tdep->elf_flags;
  7109. }
  7110. else
  7111. elf_flags = 0;
  7112. if (gdbarch_debug)
  7113. gdb_printf (gdb_stdlog,
  7114. "mips_gdbarch_init: elf_flags = 0x%08x\n", elf_flags);
  7115. /* Check ELF_FLAGS to see if it specifies the ABI being used. */
  7116. switch ((elf_flags & EF_MIPS_ABI))
  7117. {
  7118. case E_MIPS_ABI_O32:
  7119. found_abi = MIPS_ABI_O32;
  7120. break;
  7121. case E_MIPS_ABI_O64:
  7122. found_abi = MIPS_ABI_O64;
  7123. break;
  7124. case E_MIPS_ABI_EABI32:
  7125. found_abi = MIPS_ABI_EABI32;
  7126. break;
  7127. case E_MIPS_ABI_EABI64:
  7128. found_abi = MIPS_ABI_EABI64;
  7129. break;
  7130. default:
  7131. if ((elf_flags & EF_MIPS_ABI2))
  7132. found_abi = MIPS_ABI_N32;
  7133. else
  7134. found_abi = MIPS_ABI_UNKNOWN;
  7135. break;
  7136. }
  7137. /* GCC creates a pseudo-section whose name describes the ABI. */
  7138. if (found_abi == MIPS_ABI_UNKNOWN && info.abfd != NULL)
  7139. bfd_map_over_sections (info.abfd, mips_find_abi_section, &found_abi);
  7140. /* If we have no useful BFD information, use the ABI from the last
  7141. MIPS architecture (if there is one). */
  7142. if (found_abi == MIPS_ABI_UNKNOWN && info.abfd == NULL && arches != NULL)
  7143. {
  7144. mips_gdbarch_tdep *tdep
  7145. = (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
  7146. found_abi = tdep->found_abi;
  7147. }
  7148. /* Try the architecture for any hint of the correct ABI. */
  7149. if (found_abi == MIPS_ABI_UNKNOWN
  7150. && info.bfd_arch_info != NULL
  7151. && info.bfd_arch_info->arch == bfd_arch_mips)
  7152. {
  7153. switch (info.bfd_arch_info->mach)
  7154. {
  7155. case bfd_mach_mips3900:
  7156. found_abi = MIPS_ABI_EABI32;
  7157. break;
  7158. case bfd_mach_mips4100:
  7159. case bfd_mach_mips5000:
  7160. found_abi = MIPS_ABI_EABI64;
  7161. break;
  7162. case bfd_mach_mips8000:
  7163. case bfd_mach_mips10000:
  7164. /* On Irix, ELF64 executables use the N64 ABI. The
  7165. pseudo-sections which describe the ABI aren't present
  7166. on IRIX. (Even for executables created by gcc.) */
  7167. if (info.abfd != NULL
  7168. && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
  7169. && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
  7170. found_abi = MIPS_ABI_N64;
  7171. else
  7172. found_abi = MIPS_ABI_N32;
  7173. break;
  7174. }
  7175. }
  7176. /* Default 64-bit objects to N64 instead of O32. */
  7177. if (found_abi == MIPS_ABI_UNKNOWN
  7178. && info.abfd != NULL
  7179. && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour
  7180. && elf_elfheader (info.abfd)->e_ident[EI_CLASS] == ELFCLASS64)
  7181. found_abi = MIPS_ABI_N64;
  7182. if (gdbarch_debug)
  7183. gdb_printf (gdb_stdlog, "mips_gdbarch_init: found_abi = %d\n",
  7184. found_abi);
  7185. /* What has the user specified from the command line? */
  7186. wanted_abi = global_mips_abi ();
  7187. if (gdbarch_debug)
  7188. gdb_printf (gdb_stdlog, "mips_gdbarch_init: wanted_abi = %d\n",
  7189. wanted_abi);
  7190. /* Now that we have found what the ABI for this binary would be,
  7191. check whether the user is overriding it. */
  7192. if (wanted_abi != MIPS_ABI_UNKNOWN)
  7193. mips_abi = wanted_abi;
  7194. else if (found_abi != MIPS_ABI_UNKNOWN)
  7195. mips_abi = found_abi;
  7196. else
  7197. mips_abi = MIPS_ABI_O32;
  7198. if (gdbarch_debug)
  7199. gdb_printf (gdb_stdlog, "mips_gdbarch_init: mips_abi = %d\n",
  7200. mips_abi);
  7201. /* Make sure we don't use a 32-bit architecture with a 64-bit ABI. */
  7202. if (mips_abi != MIPS_ABI_EABI32
  7203. && mips_abi != MIPS_ABI_O32
  7204. && info.bfd_arch_info != NULL
  7205. && info.bfd_arch_info->arch == bfd_arch_mips
  7206. && info.bfd_arch_info->bits_per_word < 64)
  7207. info.bfd_arch_info = bfd_lookup_arch (bfd_arch_mips, bfd_mach_mips4000);
  7208. /* Determine the default compressed ISA. */
  7209. if ((elf_flags & EF_MIPS_ARCH_ASE_MICROMIPS) != 0
  7210. && (elf_flags & EF_MIPS_ARCH_ASE_M16) == 0)
  7211. mips_isa = ISA_MICROMIPS;
  7212. else if ((elf_flags & EF_MIPS_ARCH_ASE_M16) != 0
  7213. && (elf_flags & EF_MIPS_ARCH_ASE_MICROMIPS) == 0)
  7214. mips_isa = ISA_MIPS16;
  7215. else
  7216. mips_isa = global_mips_compression ();
  7217. mips_compression_string = mips_compression_strings[mips_isa];
  7218. /* Also used when doing an architecture lookup. */
  7219. if (gdbarch_debug)
  7220. gdb_printf (gdb_stdlog,
  7221. "mips_gdbarch_init: "
  7222. "mips64_transfers_32bit_regs_p = %d\n",
  7223. mips64_transfers_32bit_regs_p);
  7224. /* Determine the MIPS FPU type. */
  7225. #ifdef HAVE_ELF
  7226. if (info.abfd
  7227. && bfd_get_flavour (info.abfd) == bfd_target_elf_flavour)
  7228. elf_fpu_type = bfd_elf_get_obj_attr_int (info.abfd, OBJ_ATTR_GNU,
  7229. Tag_GNU_MIPS_ABI_FP);
  7230. #endif /* HAVE_ELF */
  7231. if (!mips_fpu_type_auto)
  7232. fpu_type = mips_fpu_type;
  7233. else if (elf_fpu_type != Val_GNU_MIPS_ABI_FP_ANY)
  7234. {
  7235. switch (elf_fpu_type)
  7236. {
  7237. case Val_GNU_MIPS_ABI_FP_DOUBLE:
  7238. fpu_type = MIPS_FPU_DOUBLE;
  7239. break;
  7240. case Val_GNU_MIPS_ABI_FP_SINGLE:
  7241. fpu_type = MIPS_FPU_SINGLE;
  7242. break;
  7243. case Val_GNU_MIPS_ABI_FP_SOFT:
  7244. default:
  7245. /* Soft float or unknown. */
  7246. fpu_type = MIPS_FPU_NONE;
  7247. break;
  7248. }
  7249. }
  7250. else if (info.bfd_arch_info != NULL
  7251. && info.bfd_arch_info->arch == bfd_arch_mips)
  7252. switch (info.bfd_arch_info->mach)
  7253. {
  7254. case bfd_mach_mips3900:
  7255. case bfd_mach_mips4100:
  7256. case bfd_mach_mips4111:
  7257. case bfd_mach_mips4120:
  7258. fpu_type = MIPS_FPU_NONE;
  7259. break;
  7260. case bfd_mach_mips4650:
  7261. fpu_type = MIPS_FPU_SINGLE;
  7262. break;
  7263. default:
  7264. fpu_type = MIPS_FPU_DOUBLE;
  7265. break;
  7266. }
  7267. else if (arches != NULL)
  7268. fpu_type = mips_get_fpu_type (arches->gdbarch);
  7269. else
  7270. fpu_type = MIPS_FPU_DOUBLE;
  7271. if (gdbarch_debug)
  7272. gdb_printf (gdb_stdlog,
  7273. "mips_gdbarch_init: fpu_type = %d\n", fpu_type);
  7274. /* Check for blatant incompatibilities. */
  7275. /* If we have only 32-bit registers, then we can't debug a 64-bit
  7276. ABI. */
  7277. if (info.target_desc
  7278. && tdesc_property (info.target_desc, PROPERTY_GP32) != NULL
  7279. && mips_abi != MIPS_ABI_EABI32
  7280. && mips_abi != MIPS_ABI_O32)
  7281. return NULL;
  7282. /* Fill in the OS dependent register numbers and names. */
  7283. if (info.osabi == GDB_OSABI_LINUX)
  7284. {
  7285. mips_regnum.fp0 = 38;
  7286. mips_regnum.pc = 37;
  7287. mips_regnum.cause = 36;
  7288. mips_regnum.badvaddr = 35;
  7289. mips_regnum.hi = 34;
  7290. mips_regnum.lo = 33;
  7291. mips_regnum.fp_control_status = 70;
  7292. mips_regnum.fp_implementation_revision = 71;
  7293. mips_regnum.dspacc = -1;
  7294. mips_regnum.dspctl = -1;
  7295. dspacc = 72;
  7296. dspctl = 78;
  7297. num_regs = 90;
  7298. reg_names = mips_linux_reg_names;
  7299. }
  7300. else
  7301. {
  7302. mips_regnum.lo = MIPS_EMBED_LO_REGNUM;
  7303. mips_regnum.hi = MIPS_EMBED_HI_REGNUM;
  7304. mips_regnum.badvaddr = MIPS_EMBED_BADVADDR_REGNUM;
  7305. mips_regnum.cause = MIPS_EMBED_CAUSE_REGNUM;
  7306. mips_regnum.pc = MIPS_EMBED_PC_REGNUM;
  7307. mips_regnum.fp0 = MIPS_EMBED_FP0_REGNUM;
  7308. mips_regnum.fp_control_status = 70;
  7309. mips_regnum.fp_implementation_revision = 71;
  7310. mips_regnum.dspacc = dspacc = -1;
  7311. mips_regnum.dspctl = dspctl = -1;
  7312. num_regs = MIPS_LAST_EMBED_REGNUM + 1;
  7313. if (info.bfd_arch_info != NULL
  7314. && info.bfd_arch_info->mach == bfd_mach_mips3900)
  7315. reg_names = mips_tx39_reg_names;
  7316. else
  7317. reg_names = mips_generic_reg_names;
  7318. }
  7319. /* Check any target description for validity. */
  7320. if (tdesc_has_registers (info.target_desc))
  7321. {
  7322. static const char *const mips_gprs[] = {
  7323. "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  7324. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  7325. "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
  7326. "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31"
  7327. };
  7328. static const char *const mips_fprs[] = {
  7329. "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
  7330. "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
  7331. "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
  7332. "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
  7333. };
  7334. const struct tdesc_feature *feature;
  7335. int valid_p;
  7336. feature = tdesc_find_feature (info.target_desc,
  7337. "org.gnu.gdb.mips.cpu");
  7338. if (feature == NULL)
  7339. return NULL;
  7340. tdesc_data = tdesc_data_alloc ();
  7341. valid_p = 1;
  7342. for (i = MIPS_ZERO_REGNUM; i <= MIPS_RA_REGNUM; i++)
  7343. valid_p &= tdesc_numbered_register (feature, tdesc_data.get (), i,
  7344. mips_gprs[i]);
  7345. valid_p &= tdesc_numbered_register (feature, tdesc_data.get (),
  7346. mips_regnum.lo, "lo");
  7347. valid_p &= tdesc_numbered_register (feature, tdesc_data.get (),
  7348. mips_regnum.hi, "hi");
  7349. valid_p &= tdesc_numbered_register (feature, tdesc_data.get (),
  7350. mips_regnum.pc, "pc");
  7351. if (!valid_p)
  7352. return NULL;
  7353. feature = tdesc_find_feature (info.target_desc,
  7354. "org.gnu.gdb.mips.cp0");
  7355. if (feature == NULL)
  7356. return NULL;
  7357. valid_p = 1;
  7358. valid_p &= tdesc_numbered_register (feature, tdesc_data.get (),
  7359. mips_regnum.badvaddr, "badvaddr");
  7360. valid_p &= tdesc_numbered_register (feature, tdesc_data.get (),
  7361. MIPS_PS_REGNUM, "status");
  7362. valid_p &= tdesc_numbered_register (feature, tdesc_data.get (),
  7363. mips_regnum.cause, "cause");
  7364. if (!valid_p)
  7365. return NULL;
  7366. /* FIXME drow/2007-05-17: The FPU should be optional. The MIPS
  7367. backend is not prepared for that, though. */
  7368. feature = tdesc_find_feature (info.target_desc,
  7369. "org.gnu.gdb.mips.fpu");
  7370. if (feature == NULL)
  7371. return NULL;
  7372. valid_p = 1;
  7373. for (i = 0; i < 32; i++)
  7374. valid_p &= tdesc_numbered_register (feature, tdesc_data.get (),
  7375. i + mips_regnum.fp0, mips_fprs[i]);
  7376. valid_p &= tdesc_numbered_register (feature, tdesc_data.get (),
  7377. mips_regnum.fp_control_status,
  7378. "fcsr");
  7379. valid_p
  7380. &= tdesc_numbered_register (feature, tdesc_data.get (),
  7381. mips_regnum.fp_implementation_revision,
  7382. "fir");
  7383. if (!valid_p)
  7384. return NULL;
  7385. num_regs = mips_regnum.fp_implementation_revision + 1;
  7386. if (dspacc >= 0)
  7387. {
  7388. feature = tdesc_find_feature (info.target_desc,
  7389. "org.gnu.gdb.mips.dsp");
  7390. /* The DSP registers are optional; it's OK if they are absent. */
  7391. if (feature != NULL)
  7392. {
  7393. i = 0;
  7394. valid_p = 1;
  7395. valid_p &= tdesc_numbered_register (feature, tdesc_data.get (),
  7396. dspacc + i++, "hi1");
  7397. valid_p &= tdesc_numbered_register (feature, tdesc_data.get (),
  7398. dspacc + i++, "lo1");
  7399. valid_p &= tdesc_numbered_register (feature, tdesc_data.get (),
  7400. dspacc + i++, "hi2");
  7401. valid_p &= tdesc_numbered_register (feature, tdesc_data.get (),
  7402. dspacc + i++, "lo2");
  7403. valid_p &= tdesc_numbered_register (feature, tdesc_data.get (),
  7404. dspacc + i++, "hi3");
  7405. valid_p &= tdesc_numbered_register (feature, tdesc_data.get (),
  7406. dspacc + i++, "lo3");
  7407. valid_p &= tdesc_numbered_register (feature, tdesc_data.get (),
  7408. dspctl, "dspctl");
  7409. if (!valid_p)
  7410. return NULL;
  7411. mips_regnum.dspacc = dspacc;
  7412. mips_regnum.dspctl = dspctl;
  7413. num_regs = mips_regnum.dspctl + 1;
  7414. }
  7415. }
  7416. /* It would be nice to detect an attempt to use a 64-bit ABI
  7417. when only 32-bit registers are provided. */
  7418. reg_names = NULL;
  7419. }
  7420. /* Try to find a pre-existing architecture. */
  7421. for (arches = gdbarch_list_lookup_by_info (arches, &info);
  7422. arches != NULL;
  7423. arches = gdbarch_list_lookup_by_info (arches->next, &info))
  7424. {
  7425. mips_gdbarch_tdep *tdep
  7426. = (mips_gdbarch_tdep *) gdbarch_tdep (arches->gdbarch);
  7427. /* MIPS needs to be pedantic about which ABI and the compressed
  7428. ISA variation the object is using. */
  7429. if (tdep->elf_flags != elf_flags)
  7430. continue;
  7431. if (tdep->mips_abi != mips_abi)
  7432. continue;
  7433. if (tdep->mips_isa != mips_isa)
  7434. continue;
  7435. /* Need to be pedantic about which register virtual size is
  7436. used. */
  7437. if (tdep->mips64_transfers_32bit_regs_p
  7438. != mips64_transfers_32bit_regs_p)
  7439. continue;
  7440. /* Be pedantic about which FPU is selected. */
  7441. if (mips_get_fpu_type (arches->gdbarch) != fpu_type)
  7442. continue;
  7443. return arches->gdbarch;
  7444. }
  7445. /* Need a new architecture. Fill in a target specific vector. */
  7446. mips_gdbarch_tdep *tdep = new mips_gdbarch_tdep;
  7447. gdbarch = gdbarch_alloc (&info, tdep);
  7448. tdep->elf_flags = elf_flags;
  7449. tdep->mips64_transfers_32bit_regs_p = mips64_transfers_32bit_regs_p;
  7450. tdep->found_abi = found_abi;
  7451. tdep->mips_abi = mips_abi;
  7452. tdep->mips_isa = mips_isa;
  7453. tdep->mips_fpu_type = fpu_type;
  7454. tdep->register_size_valid_p = 0;
  7455. tdep->register_size = 0;
  7456. if (info.target_desc)
  7457. {
  7458. /* Some useful properties can be inferred from the target. */
  7459. if (tdesc_property (info.target_desc, PROPERTY_GP32) != NULL)
  7460. {
  7461. tdep->register_size_valid_p = 1;
  7462. tdep->register_size = 4;
  7463. }
  7464. else if (tdesc_property (info.target_desc, PROPERTY_GP64) != NULL)
  7465. {
  7466. tdep->register_size_valid_p = 1;
  7467. tdep->register_size = 8;
  7468. }
  7469. }
  7470. /* Initially set everything according to the default ABI/ISA. */
  7471. set_gdbarch_short_bit (gdbarch, 16);
  7472. set_gdbarch_int_bit (gdbarch, 32);
  7473. set_gdbarch_float_bit (gdbarch, 32);
  7474. set_gdbarch_double_bit (gdbarch, 64);
  7475. set_gdbarch_long_double_bit (gdbarch, 64);
  7476. set_gdbarch_register_reggroup_p (gdbarch, mips_register_reggroup_p);
  7477. set_gdbarch_pseudo_register_read (gdbarch, mips_pseudo_register_read);
  7478. set_gdbarch_pseudo_register_write (gdbarch, mips_pseudo_register_write);
  7479. set_gdbarch_ax_pseudo_register_collect (gdbarch,
  7480. mips_ax_pseudo_register_collect);
  7481. set_gdbarch_ax_pseudo_register_push_stack
  7482. (gdbarch, mips_ax_pseudo_register_push_stack);
  7483. set_gdbarch_elf_make_msymbol_special (gdbarch,
  7484. mips_elf_make_msymbol_special);
  7485. set_gdbarch_make_symbol_special (gdbarch, mips_make_symbol_special);
  7486. set_gdbarch_adjust_dwarf2_addr (gdbarch, mips_adjust_dwarf2_addr);
  7487. set_gdbarch_adjust_dwarf2_line (gdbarch, mips_adjust_dwarf2_line);
  7488. regnum = GDBARCH_OBSTACK_ZALLOC (gdbarch, struct mips_regnum);
  7489. *regnum = mips_regnum;
  7490. set_gdbarch_fp0_regnum (gdbarch, regnum->fp0);
  7491. set_gdbarch_num_regs (gdbarch, num_regs);
  7492. set_gdbarch_num_pseudo_regs (gdbarch, num_regs);
  7493. set_gdbarch_register_name (gdbarch, mips_register_name);
  7494. set_gdbarch_virtual_frame_pointer (gdbarch, mips_virtual_frame_pointer);
  7495. tdep->mips_processor_reg_names = reg_names;
  7496. tdep->regnum = regnum;
  7497. switch (mips_abi)
  7498. {
  7499. case MIPS_ABI_O32:
  7500. set_gdbarch_push_dummy_call (gdbarch, mips_o32_push_dummy_call);
  7501. set_gdbarch_return_value (gdbarch, mips_o32_return_value);
  7502. tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 4 - 1;
  7503. tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1;
  7504. tdep->default_mask_address_p = 0;
  7505. set_gdbarch_long_bit (gdbarch, 32);
  7506. set_gdbarch_ptr_bit (gdbarch, 32);
  7507. set_gdbarch_long_long_bit (gdbarch, 64);
  7508. break;
  7509. case MIPS_ABI_O64:
  7510. set_gdbarch_push_dummy_call (gdbarch, mips_o64_push_dummy_call);
  7511. set_gdbarch_return_value (gdbarch, mips_o64_return_value);
  7512. tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 4 - 1;
  7513. tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 4 - 1;
  7514. tdep->default_mask_address_p = 0;
  7515. set_gdbarch_long_bit (gdbarch, 32);
  7516. set_gdbarch_ptr_bit (gdbarch, 32);
  7517. set_gdbarch_long_long_bit (gdbarch, 64);
  7518. break;
  7519. case MIPS_ABI_EABI32:
  7520. set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
  7521. set_gdbarch_return_value (gdbarch, mips_eabi_return_value);
  7522. tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1;
  7523. tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
  7524. tdep->default_mask_address_p = 0;
  7525. set_gdbarch_long_bit (gdbarch, 32);
  7526. set_gdbarch_ptr_bit (gdbarch, 32);
  7527. set_gdbarch_long_long_bit (gdbarch, 64);
  7528. break;
  7529. case MIPS_ABI_EABI64:
  7530. set_gdbarch_push_dummy_call (gdbarch, mips_eabi_push_dummy_call);
  7531. set_gdbarch_return_value (gdbarch, mips_eabi_return_value);
  7532. tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1;
  7533. tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
  7534. tdep->default_mask_address_p = 0;
  7535. set_gdbarch_long_bit (gdbarch, 64);
  7536. set_gdbarch_ptr_bit (gdbarch, 64);
  7537. set_gdbarch_long_long_bit (gdbarch, 64);
  7538. break;
  7539. case MIPS_ABI_N32:
  7540. set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
  7541. set_gdbarch_return_value (gdbarch, mips_n32n64_return_value);
  7542. tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1;
  7543. tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
  7544. tdep->default_mask_address_p = 0;
  7545. set_gdbarch_long_bit (gdbarch, 32);
  7546. set_gdbarch_ptr_bit (gdbarch, 32);
  7547. set_gdbarch_long_long_bit (gdbarch, 64);
  7548. set_gdbarch_long_double_bit (gdbarch, 128);
  7549. set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
  7550. break;
  7551. case MIPS_ABI_N64:
  7552. set_gdbarch_push_dummy_call (gdbarch, mips_n32n64_push_dummy_call);
  7553. set_gdbarch_return_value (gdbarch, mips_n32n64_return_value);
  7554. tdep->mips_last_arg_regnum = MIPS_A0_REGNUM + 8 - 1;
  7555. tdep->mips_last_fp_arg_regnum = tdep->regnum->fp0 + 12 + 8 - 1;
  7556. tdep->default_mask_address_p = 0;
  7557. set_gdbarch_long_bit (gdbarch, 64);
  7558. set_gdbarch_ptr_bit (gdbarch, 64);
  7559. set_gdbarch_long_long_bit (gdbarch, 64);
  7560. set_gdbarch_long_double_bit (gdbarch, 128);
  7561. set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
  7562. break;
  7563. default:
  7564. internal_error (__FILE__, __LINE__, _("unknown ABI in switch"));
  7565. }
  7566. /* GCC creates a pseudo-section whose name specifies the size of
  7567. longs, since -mlong32 or -mlong64 may be used independent of
  7568. other options. How those options affect pointer sizes is ABI and
  7569. architecture dependent, so use them to override the default sizes
  7570. set by the ABI. This table shows the relationship between ABI,
  7571. -mlongXX, and size of pointers:
  7572. ABI -mlongXX ptr bits
  7573. --- -------- --------
  7574. o32 32 32
  7575. o32 64 32
  7576. n32 32 32
  7577. n32 64 64
  7578. o64 32 32
  7579. o64 64 64
  7580. n64 32 32
  7581. n64 64 64
  7582. eabi32 32 32
  7583. eabi32 64 32
  7584. eabi64 32 32
  7585. eabi64 64 64
  7586. Note that for o32 and eabi32, pointers are always 32 bits
  7587. regardless of any -mlongXX option. For all others, pointers and
  7588. longs are the same, as set by -mlongXX or set by defaults. */
  7589. if (info.abfd != NULL)
  7590. {
  7591. int long_bit = 0;
  7592. bfd_map_over_sections (info.abfd, mips_find_long_section, &long_bit);
  7593. if (long_bit)
  7594. {
  7595. set_gdbarch_long_bit (gdbarch, long_bit);
  7596. switch (mips_abi)
  7597. {
  7598. case MIPS_ABI_O32:
  7599. case MIPS_ABI_EABI32:
  7600. break;
  7601. case MIPS_ABI_N32:
  7602. case MIPS_ABI_O64:
  7603. case MIPS_ABI_N64:
  7604. case MIPS_ABI_EABI64:
  7605. set_gdbarch_ptr_bit (gdbarch, long_bit);
  7606. break;
  7607. default:
  7608. internal_error (__FILE__, __LINE__, _("unknown ABI in switch"));
  7609. }
  7610. }
  7611. }
  7612. /* FIXME: jlarmour/2000-04-07: There *is* a flag EF_MIPS_32BIT_MODE
  7613. that could indicate -gp32 BUT gas/config/tc-mips.c contains the
  7614. comment:
  7615. ``We deliberately don't allow "-gp32" to set the MIPS_32BITMODE
  7616. flag in object files because to do so would make it impossible to
  7617. link with libraries compiled without "-gp32". This is
  7618. unnecessarily restrictive.
  7619. We could solve this problem by adding "-gp32" multilibs to gcc,
  7620. but to set this flag before gcc is built with such multilibs will
  7621. break too many systems.''
  7622. But even more unhelpfully, the default linker output target for
  7623. mips64-elf is elf32-bigmips, and has EF_MIPS_32BIT_MODE set, even
  7624. for 64-bit programs - you need to change the ABI to change this,
  7625. and not all gcc targets support that currently. Therefore using
  7626. this flag to detect 32-bit mode would do the wrong thing given
  7627. the current gcc - it would make GDB treat these 64-bit programs
  7628. as 32-bit programs by default. */
  7629. set_gdbarch_read_pc (gdbarch, mips_read_pc);
  7630. set_gdbarch_write_pc (gdbarch, mips_write_pc);
  7631. /* Add/remove bits from an address. The MIPS needs be careful to
  7632. ensure that all 32 bit addresses are sign extended to 64 bits. */
  7633. set_gdbarch_addr_bits_remove (gdbarch, mips_addr_bits_remove);
  7634. /* Unwind the frame. */
  7635. set_gdbarch_unwind_pc (gdbarch, mips_unwind_pc);
  7636. set_gdbarch_unwind_sp (gdbarch, mips_unwind_sp);
  7637. set_gdbarch_dummy_id (gdbarch, mips_dummy_id);
  7638. /* Map debug register numbers onto internal register numbers. */
  7639. set_gdbarch_stab_reg_to_regnum (gdbarch, mips_stab_reg_to_regnum);
  7640. set_gdbarch_ecoff_reg_to_regnum (gdbarch,
  7641. mips_dwarf_dwarf2_ecoff_reg_to_regnum);
  7642. set_gdbarch_dwarf2_reg_to_regnum (gdbarch,
  7643. mips_dwarf_dwarf2_ecoff_reg_to_regnum);
  7644. set_gdbarch_register_sim_regno (gdbarch, mips_register_sim_regno);
  7645. /* MIPS version of CALL_DUMMY. */
  7646. set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
  7647. set_gdbarch_push_dummy_code (gdbarch, mips_push_dummy_code);
  7648. set_gdbarch_frame_align (gdbarch, mips_frame_align);
  7649. set_gdbarch_print_float_info (gdbarch, mips_print_float_info);
  7650. set_gdbarch_convert_register_p (gdbarch, mips_convert_register_p);
  7651. set_gdbarch_register_to_value (gdbarch, mips_register_to_value);
  7652. set_gdbarch_value_to_register (gdbarch, mips_value_to_register);
  7653. set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
  7654. set_gdbarch_breakpoint_kind_from_pc (gdbarch, mips_breakpoint_kind_from_pc);
  7655. set_gdbarch_sw_breakpoint_from_kind (gdbarch, mips_sw_breakpoint_from_kind);
  7656. set_gdbarch_adjust_breakpoint_address (gdbarch,
  7657. mips_adjust_breakpoint_address);
  7658. set_gdbarch_skip_prologue (gdbarch, mips_skip_prologue);
  7659. set_gdbarch_stack_frame_destroyed_p (gdbarch, mips_stack_frame_destroyed_p);
  7660. set_gdbarch_pointer_to_address (gdbarch, signed_pointer_to_address);
  7661. set_gdbarch_address_to_pointer (gdbarch, address_to_signed_pointer);
  7662. set_gdbarch_integer_to_address (gdbarch, mips_integer_to_address);
  7663. set_gdbarch_register_type (gdbarch, mips_register_type);
  7664. set_gdbarch_print_registers_info (gdbarch, mips_print_registers_info);
  7665. set_gdbarch_print_insn (gdbarch, gdb_print_insn_mips);
  7666. if (mips_abi == MIPS_ABI_N64)
  7667. set_gdbarch_disassembler_options_implicit
  7668. (gdbarch, (const char *) mips_disassembler_options_n64);
  7669. else if (mips_abi == MIPS_ABI_N32)
  7670. set_gdbarch_disassembler_options_implicit
  7671. (gdbarch, (const char *) mips_disassembler_options_n32);
  7672. else
  7673. set_gdbarch_disassembler_options_implicit
  7674. (gdbarch, (const char *) mips_disassembler_options_o32);
  7675. set_gdbarch_disassembler_options (gdbarch, &mips_disassembler_options);
  7676. set_gdbarch_valid_disassembler_options (gdbarch,
  7677. disassembler_options_mips ());
  7678. /* FIXME: cagney/2003-08-29: The macros target_have_steppable_watchpoint,
  7679. HAVE_NONSTEPPABLE_WATCHPOINT, and target_have_continuable_watchpoint
  7680. need to all be folded into the target vector. Since they are
  7681. being used as guards for target_stopped_by_watchpoint, why not have
  7682. target_stopped_by_watchpoint return the type of watchpoint that the code
  7683. is sitting on? */
  7684. set_gdbarch_have_nonsteppable_watchpoint (gdbarch, 1);
  7685. set_gdbarch_skip_trampoline_code (gdbarch, mips_skip_trampoline_code);
  7686. /* NOTE drow/2012-04-25: We overload the core solib trampoline code
  7687. to support MIPS16. This is a bad thing. Make sure not to do it
  7688. if we have an OS ABI that actually supports shared libraries, since
  7689. shared library support is more important. If we have an OS someday
  7690. that supports both shared libraries and MIPS16, we'll have to find
  7691. a better place for these.
  7692. macro/2012-04-25: But that applies to return trampolines only and
  7693. currently no MIPS OS ABI uses shared libraries that have them. */
  7694. set_gdbarch_in_solib_return_trampoline (gdbarch, mips_in_return_stub);
  7695. set_gdbarch_single_step_through_delay (gdbarch,
  7696. mips_single_step_through_delay);
  7697. /* Virtual tables. */
  7698. set_gdbarch_vbit_in_delta (gdbarch, 1);
  7699. mips_register_g_packet_guesses (gdbarch);
  7700. /* Hook in OS ABI-specific overrides, if they have been registered. */
  7701. info.tdesc_data = tdesc_data.get ();
  7702. gdbarch_init_osabi (info, gdbarch);
  7703. /* The hook may have adjusted num_regs, fetch the final value and
  7704. set pc_regnum and sp_regnum now that it has been fixed. */
  7705. num_regs = gdbarch_num_regs (gdbarch);
  7706. set_gdbarch_pc_regnum (gdbarch, regnum->pc + num_regs);
  7707. set_gdbarch_sp_regnum (gdbarch, MIPS_SP_REGNUM + num_regs);
  7708. /* Unwind the frame. */
  7709. dwarf2_append_unwinders (gdbarch);
  7710. frame_unwind_append_unwinder (gdbarch, &mips_stub_frame_unwind);
  7711. frame_unwind_append_unwinder (gdbarch, &mips_insn16_frame_unwind);
  7712. frame_unwind_append_unwinder (gdbarch, &mips_micro_frame_unwind);
  7713. frame_unwind_append_unwinder (gdbarch, &mips_insn32_frame_unwind);
  7714. frame_base_append_sniffer (gdbarch, dwarf2_frame_base_sniffer);
  7715. frame_base_append_sniffer (gdbarch, mips_stub_frame_base_sniffer);
  7716. frame_base_append_sniffer (gdbarch, mips_insn16_frame_base_sniffer);
  7717. frame_base_append_sniffer (gdbarch, mips_micro_frame_base_sniffer);
  7718. frame_base_append_sniffer (gdbarch, mips_insn32_frame_base_sniffer);
  7719. if (tdesc_data != nullptr)
  7720. {
  7721. set_tdesc_pseudo_register_type (gdbarch, mips_pseudo_register_type);
  7722. tdesc_use_registers (gdbarch, info.target_desc, std::move (tdesc_data));
  7723. /* Override the normal target description methods to handle our
  7724. dual real and pseudo registers. */
  7725. set_gdbarch_register_name (gdbarch, mips_register_name);
  7726. set_gdbarch_register_reggroup_p (gdbarch,
  7727. mips_tdesc_register_reggroup_p);
  7728. num_regs = gdbarch_num_regs (gdbarch);
  7729. set_gdbarch_num_pseudo_regs (gdbarch, num_regs);
  7730. set_gdbarch_pc_regnum (gdbarch, tdep->regnum->pc + num_regs);
  7731. set_gdbarch_sp_regnum (gdbarch, MIPS_SP_REGNUM + num_regs);
  7732. }
  7733. /* Add ABI-specific aliases for the registers. */
  7734. if (mips_abi == MIPS_ABI_N32 || mips_abi == MIPS_ABI_N64)
  7735. for (i = 0; i < ARRAY_SIZE (mips_n32_n64_aliases); i++)
  7736. user_reg_add (gdbarch, mips_n32_n64_aliases[i].name,
  7737. value_of_mips_user_reg, &mips_n32_n64_aliases[i].regnum);
  7738. else
  7739. for (i = 0; i < ARRAY_SIZE (mips_o32_aliases); i++)
  7740. user_reg_add (gdbarch, mips_o32_aliases[i].name,
  7741. value_of_mips_user_reg, &mips_o32_aliases[i].regnum);
  7742. /* Add some other standard aliases. */
  7743. for (i = 0; i < ARRAY_SIZE (mips_register_aliases); i++)
  7744. user_reg_add (gdbarch, mips_register_aliases[i].name,
  7745. value_of_mips_user_reg, &mips_register_aliases[i].regnum);
  7746. for (i = 0; i < ARRAY_SIZE (mips_numeric_register_aliases); i++)
  7747. user_reg_add (gdbarch, mips_numeric_register_aliases[i].name,
  7748. value_of_mips_user_reg,
  7749. &mips_numeric_register_aliases[i].regnum);
  7750. return gdbarch;
  7751. }
  7752. static void
  7753. mips_abi_update (const char *ignore_args,
  7754. int from_tty, struct cmd_list_element *c)
  7755. {
  7756. struct gdbarch_info info;
  7757. /* Force the architecture to update, and (if it's a MIPS architecture)
  7758. mips_gdbarch_init will take care of the rest. */
  7759. gdbarch_update_p (info);
  7760. }
  7761. /* Print out which MIPS ABI is in use. */
  7762. static void
  7763. show_mips_abi (struct ui_file *file,
  7764. int from_tty,
  7765. struct cmd_list_element *ignored_cmd,
  7766. const char *ignored_value)
  7767. {
  7768. if (gdbarch_bfd_arch_info (target_gdbarch ())->arch != bfd_arch_mips)
  7769. gdb_printf
  7770. (file,
  7771. "The MIPS ABI is unknown because the current architecture "
  7772. "is not MIPS.\n");
  7773. else
  7774. {
  7775. enum mips_abi global_abi = global_mips_abi ();
  7776. enum mips_abi actual_abi = mips_abi (target_gdbarch ());
  7777. const char *actual_abi_str = mips_abi_strings[actual_abi];
  7778. if (global_abi == MIPS_ABI_UNKNOWN)
  7779. gdb_printf
  7780. (file,
  7781. "The MIPS ABI is set automatically (currently \"%s\").\n",
  7782. actual_abi_str);
  7783. else if (global_abi == actual_abi)
  7784. gdb_printf
  7785. (file,
  7786. "The MIPS ABI is assumed to be \"%s\" (due to user setting).\n",
  7787. actual_abi_str);
  7788. else
  7789. {
  7790. /* Probably shouldn't happen... */
  7791. gdb_printf (file,
  7792. "The (auto detected) MIPS ABI \"%s\" is in use "
  7793. "even though the user setting was \"%s\".\n",
  7794. actual_abi_str, mips_abi_strings[global_abi]);
  7795. }
  7796. }
  7797. }
  7798. /* Print out which MIPS compressed ISA encoding is used. */
  7799. static void
  7800. show_mips_compression (struct ui_file *file, int from_tty,
  7801. struct cmd_list_element *c, const char *value)
  7802. {
  7803. gdb_printf (file, _("The compressed ISA encoding used is %s.\n"),
  7804. value);
  7805. }
  7806. /* Return a textual name for MIPS FPU type FPU_TYPE. */
  7807. static const char *
  7808. mips_fpu_type_str (enum mips_fpu_type fpu_type)
  7809. {
  7810. switch (fpu_type)
  7811. {
  7812. case MIPS_FPU_NONE:
  7813. return "none";
  7814. case MIPS_FPU_SINGLE:
  7815. return "single";
  7816. case MIPS_FPU_DOUBLE:
  7817. return "double";
  7818. default:
  7819. return "???";
  7820. }
  7821. }
  7822. static void
  7823. mips_dump_tdep (struct gdbarch *gdbarch, struct ui_file *file)
  7824. {
  7825. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  7826. if (tdep != NULL)
  7827. {
  7828. int ef_mips_arch;
  7829. int ef_mips_32bitmode;
  7830. /* Determine the ISA. */
  7831. switch (tdep->elf_flags & EF_MIPS_ARCH)
  7832. {
  7833. case E_MIPS_ARCH_1:
  7834. ef_mips_arch = 1;
  7835. break;
  7836. case E_MIPS_ARCH_2:
  7837. ef_mips_arch = 2;
  7838. break;
  7839. case E_MIPS_ARCH_3:
  7840. ef_mips_arch = 3;
  7841. break;
  7842. case E_MIPS_ARCH_4:
  7843. ef_mips_arch = 4;
  7844. break;
  7845. default:
  7846. ef_mips_arch = 0;
  7847. break;
  7848. }
  7849. /* Determine the size of a pointer. */
  7850. ef_mips_32bitmode = (tdep->elf_flags & EF_MIPS_32BITMODE);
  7851. gdb_printf (file,
  7852. "mips_dump_tdep: tdep->elf_flags = 0x%x\n",
  7853. tdep->elf_flags);
  7854. gdb_printf (file,
  7855. "mips_dump_tdep: ef_mips_32bitmode = %d\n",
  7856. ef_mips_32bitmode);
  7857. gdb_printf (file,
  7858. "mips_dump_tdep: ef_mips_arch = %d\n",
  7859. ef_mips_arch);
  7860. gdb_printf (file,
  7861. "mips_dump_tdep: tdep->mips_abi = %d (%s)\n",
  7862. tdep->mips_abi, mips_abi_strings[tdep->mips_abi]);
  7863. gdb_printf (file,
  7864. "mips_dump_tdep: "
  7865. "mips_mask_address_p() %d (default %d)\n",
  7866. mips_mask_address_p (tdep),
  7867. tdep->default_mask_address_p);
  7868. }
  7869. gdb_printf (file,
  7870. "mips_dump_tdep: MIPS_DEFAULT_FPU_TYPE = %d (%s)\n",
  7871. MIPS_DEFAULT_FPU_TYPE,
  7872. mips_fpu_type_str (MIPS_DEFAULT_FPU_TYPE));
  7873. gdb_printf (file, "mips_dump_tdep: MIPS_EABI = %d\n",
  7874. mips_eabi (gdbarch));
  7875. gdb_printf (file,
  7876. "mips_dump_tdep: MIPS_FPU_TYPE = %d (%s)\n",
  7877. mips_get_fpu_type (gdbarch),
  7878. mips_fpu_type_str (mips_get_fpu_type (gdbarch)));
  7879. }
  7880. void _initialize_mips_tdep ();
  7881. void
  7882. _initialize_mips_tdep ()
  7883. {
  7884. static struct cmd_list_element *mipsfpulist = NULL;
  7885. mips_abi_string = mips_abi_strings[MIPS_ABI_UNKNOWN];
  7886. if (MIPS_ABI_LAST + 1
  7887. != sizeof (mips_abi_strings) / sizeof (mips_abi_strings[0]))
  7888. internal_error (__FILE__, __LINE__, _("mips_abi_strings out of sync"));
  7889. gdbarch_register (bfd_arch_mips, mips_gdbarch_init, mips_dump_tdep);
  7890. /* Create feature sets with the appropriate properties. The values
  7891. are not important. */
  7892. mips_tdesc_gp32 = allocate_target_description ().release ();
  7893. set_tdesc_property (mips_tdesc_gp32, PROPERTY_GP32, "");
  7894. mips_tdesc_gp64 = allocate_target_description ().release ();
  7895. set_tdesc_property (mips_tdesc_gp64, PROPERTY_GP64, "");
  7896. /* Add root prefix command for all "set mips"/"show mips" commands. */
  7897. add_setshow_prefix_cmd ("mips", no_class,
  7898. _("Various MIPS specific commands."),
  7899. _("Various MIPS specific commands."),
  7900. &setmipscmdlist, &showmipscmdlist,
  7901. &setlist, &showlist);
  7902. /* Allow the user to override the ABI. */
  7903. add_setshow_enum_cmd ("abi", class_obscure, mips_abi_strings,
  7904. &mips_abi_string, _("\
  7905. Set the MIPS ABI used by this program."), _("\
  7906. Show the MIPS ABI used by this program."), _("\
  7907. This option can be set to one of:\n\
  7908. auto - the default ABI associated with the current binary\n\
  7909. o32\n\
  7910. o64\n\
  7911. n32\n\
  7912. n64\n\
  7913. eabi32\n\
  7914. eabi64"),
  7915. mips_abi_update,
  7916. show_mips_abi,
  7917. &setmipscmdlist, &showmipscmdlist);
  7918. /* Allow the user to set the ISA to assume for compressed code if ELF
  7919. file flags don't tell or there is no program file selected. This
  7920. setting is updated whenever unambiguous ELF file flags are interpreted,
  7921. and carried over to subsequent sessions. */
  7922. add_setshow_enum_cmd ("compression", class_obscure, mips_compression_strings,
  7923. &mips_compression_string, _("\
  7924. Set the compressed ISA encoding used by MIPS code."), _("\
  7925. Show the compressed ISA encoding used by MIPS code."), _("\
  7926. Select the compressed ISA encoding used in functions that have no symbol\n\
  7927. information available. The encoding can be set to either of:\n\
  7928. mips16\n\
  7929. micromips\n\
  7930. and is updated automatically from ELF file flags if available."),
  7931. mips_abi_update,
  7932. show_mips_compression,
  7933. &setmipscmdlist, &showmipscmdlist);
  7934. /* Let the user turn off floating point and set the fence post for
  7935. heuristic_proc_start. */
  7936. add_basic_prefix_cmd ("mipsfpu", class_support,
  7937. _("Set use of MIPS floating-point coprocessor."),
  7938. &mipsfpulist, 0, &setlist);
  7939. add_cmd ("single", class_support, set_mipsfpu_single_command,
  7940. _("Select single-precision MIPS floating-point coprocessor."),
  7941. &mipsfpulist);
  7942. cmd_list_element *set_mipsfpu_double_cmd
  7943. = add_cmd ("double", class_support, set_mipsfpu_double_command,
  7944. _("Select double-precision MIPS floating-point coprocessor."),
  7945. &mipsfpulist);
  7946. add_alias_cmd ("on", set_mipsfpu_double_cmd, class_support, 1, &mipsfpulist);
  7947. add_alias_cmd ("yes", set_mipsfpu_double_cmd, class_support, 1, &mipsfpulist);
  7948. add_alias_cmd ("1", set_mipsfpu_double_cmd, class_support, 1, &mipsfpulist);
  7949. cmd_list_element *set_mipsfpu_none_cmd
  7950. = add_cmd ("none", class_support, set_mipsfpu_none_command,
  7951. _("Select no MIPS floating-point coprocessor."), &mipsfpulist);
  7952. add_alias_cmd ("off", set_mipsfpu_none_cmd, class_support, 1, &mipsfpulist);
  7953. add_alias_cmd ("no", set_mipsfpu_none_cmd, class_support, 1, &mipsfpulist);
  7954. add_alias_cmd ("0", set_mipsfpu_none_cmd, class_support, 1, &mipsfpulist);
  7955. add_cmd ("auto", class_support, set_mipsfpu_auto_command,
  7956. _("Select MIPS floating-point coprocessor automatically."),
  7957. &mipsfpulist);
  7958. add_cmd ("mipsfpu", class_support, show_mipsfpu_command,
  7959. _("Show current use of MIPS floating-point coprocessor target."),
  7960. &showlist);
  7961. /* We really would like to have both "0" and "unlimited" work, but
  7962. command.c doesn't deal with that. So make it a var_zinteger
  7963. because the user can always use "999999" or some such for unlimited. */
  7964. add_setshow_zinteger_cmd ("heuristic-fence-post", class_support,
  7965. &heuristic_fence_post, _("\
  7966. Set the distance searched for the start of a function."), _("\
  7967. Show the distance searched for the start of a function."), _("\
  7968. If you are debugging a stripped executable, GDB needs to search through the\n\
  7969. program for the start of a function. This command sets the distance of the\n\
  7970. search. The only need to set it is when debugging a stripped executable."),
  7971. reinit_frame_cache_sfunc,
  7972. NULL, /* FIXME: i18n: The distance searched for
  7973. the start of a function is %s. */
  7974. &setlist, &showlist);
  7975. /* Allow the user to control whether the upper bits of 64-bit
  7976. addresses should be zeroed. */
  7977. add_setshow_auto_boolean_cmd ("mask-address", no_class,
  7978. &mask_address_var, _("\
  7979. Set zeroing of upper 32 bits of 64-bit addresses."), _("\
  7980. Show zeroing of upper 32 bits of 64-bit addresses."), _("\
  7981. Use \"on\" to enable the masking, \"off\" to disable it and \"auto\" to\n\
  7982. allow GDB to determine the correct value."),
  7983. NULL, show_mask_address,
  7984. &setmipscmdlist, &showmipscmdlist);
  7985. /* Allow the user to control the size of 32 bit registers within the
  7986. raw remote packet. */
  7987. add_setshow_boolean_cmd ("remote-mips64-transfers-32bit-regs", class_obscure,
  7988. &mips64_transfers_32bit_regs_p, _("\
  7989. Set compatibility with 64-bit MIPS target that transfers 32-bit quantities."),
  7990. _("\
  7991. Show compatibility with 64-bit MIPS target that transfers 32-bit quantities."),
  7992. _("\
  7993. Use \"on\" to enable backward compatibility with older MIPS 64 GDB+target\n\
  7994. that would transfer 32 bits for some registers (e.g. SR, FSR) and\n\
  7995. 64 bits for others. Use \"off\" to disable compatibility mode"),
  7996. set_mips64_transfers_32bit_regs,
  7997. NULL, /* FIXME: i18n: Compatibility with 64-bit
  7998. MIPS target that transfers 32-bit
  7999. quantities is %s. */
  8000. &setlist, &showlist);
  8001. /* Debug this files internals. */
  8002. add_setshow_zuinteger_cmd ("mips", class_maintenance,
  8003. &mips_debug, _("\
  8004. Set mips debugging."), _("\
  8005. Show mips debugging."), _("\
  8006. When non-zero, mips specific debugging is enabled."),
  8007. NULL,
  8008. NULL, /* FIXME: i18n: Mips debugging is
  8009. currently %s. */
  8010. &setdebuglist, &showdebuglist);
  8011. }