i386-tdep.c 242 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127
  1. /* Intel 386 target-dependent stuff.
  2. Copyright (C) 1988-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #include "defs.h"
  15. #include "opcode/i386.h"
  16. #include "arch-utils.h"
  17. #include "command.h"
  18. #include "dummy-frame.h"
  19. #include "dwarf2/frame.h"
  20. #include "frame.h"
  21. #include "frame-base.h"
  22. #include "frame-unwind.h"
  23. #include "inferior.h"
  24. #include "infrun.h"
  25. #include "gdbcmd.h"
  26. #include "gdbcore.h"
  27. #include "gdbtypes.h"
  28. #include "objfiles.h"
  29. #include "osabi.h"
  30. #include "regcache.h"
  31. #include "reggroups.h"
  32. #include "regset.h"
  33. #include "symfile.h"
  34. #include "symtab.h"
  35. #include "target.h"
  36. #include "target-float.h"
  37. #include "value.h"
  38. #include "dis-asm.h"
  39. #include "disasm.h"
  40. #include "remote.h"
  41. #include "i386-tdep.h"
  42. #include "i387-tdep.h"
  43. #include "gdbsupport/x86-xstate.h"
  44. #include "x86-tdep.h"
  45. #include "expop.h"
  46. #include "record.h"
  47. #include "record-full.h"
  48. #include "target-descriptions.h"
  49. #include "arch/i386.h"
  50. #include "ax.h"
  51. #include "ax-gdb.h"
  52. #include "stap-probe.h"
  53. #include "user-regs.h"
  54. #include "cli/cli-utils.h"
  55. #include "expression.h"
  56. #include "parser-defs.h"
  57. #include <ctype.h>
  58. #include <algorithm>
  59. #include <unordered_set>
  60. #include "producer.h"
  61. #include "infcall.h"
  62. #include "maint.h"
  63. /* Register names. */
  64. static const char * const i386_register_names[] =
  65. {
  66. "eax", "ecx", "edx", "ebx",
  67. "esp", "ebp", "esi", "edi",
  68. "eip", "eflags", "cs", "ss",
  69. "ds", "es", "fs", "gs",
  70. "st0", "st1", "st2", "st3",
  71. "st4", "st5", "st6", "st7",
  72. "fctrl", "fstat", "ftag", "fiseg",
  73. "fioff", "foseg", "fooff", "fop",
  74. "xmm0", "xmm1", "xmm2", "xmm3",
  75. "xmm4", "xmm5", "xmm6", "xmm7",
  76. "mxcsr"
  77. };
  78. static const char * const i386_zmm_names[] =
  79. {
  80. "zmm0", "zmm1", "zmm2", "zmm3",
  81. "zmm4", "zmm5", "zmm6", "zmm7"
  82. };
  83. static const char * const i386_zmmh_names[] =
  84. {
  85. "zmm0h", "zmm1h", "zmm2h", "zmm3h",
  86. "zmm4h", "zmm5h", "zmm6h", "zmm7h"
  87. };
  88. static const char * const i386_k_names[] =
  89. {
  90. "k0", "k1", "k2", "k3",
  91. "k4", "k5", "k6", "k7"
  92. };
  93. static const char * const i386_ymm_names[] =
  94. {
  95. "ymm0", "ymm1", "ymm2", "ymm3",
  96. "ymm4", "ymm5", "ymm6", "ymm7",
  97. };
  98. static const char * const i386_ymmh_names[] =
  99. {
  100. "ymm0h", "ymm1h", "ymm2h", "ymm3h",
  101. "ymm4h", "ymm5h", "ymm6h", "ymm7h",
  102. };
  103. static const char * const i386_mpx_names[] =
  104. {
  105. "bnd0raw", "bnd1raw", "bnd2raw", "bnd3raw", "bndcfgu", "bndstatus"
  106. };
  107. static const char * const i386_pkeys_names[] =
  108. {
  109. "pkru"
  110. };
  111. /* Register names for MPX pseudo-registers. */
  112. static const char * const i386_bnd_names[] =
  113. {
  114. "bnd0", "bnd1", "bnd2", "bnd3"
  115. };
  116. /* Register names for MMX pseudo-registers. */
  117. static const char * const i386_mmx_names[] =
  118. {
  119. "mm0", "mm1", "mm2", "mm3",
  120. "mm4", "mm5", "mm6", "mm7"
  121. };
  122. /* Register names for byte pseudo-registers. */
  123. static const char * const i386_byte_names[] =
  124. {
  125. "al", "cl", "dl", "bl",
  126. "ah", "ch", "dh", "bh"
  127. };
  128. /* Register names for word pseudo-registers. */
  129. static const char * const i386_word_names[] =
  130. {
  131. "ax", "cx", "dx", "bx",
  132. "", "bp", "si", "di"
  133. };
  134. /* Constant used for reading/writing pseudo registers. In 64-bit mode, we have
  135. 16 lower ZMM regs that extend corresponding xmm/ymm registers. In addition,
  136. we have 16 upper ZMM regs that have to be handled differently. */
  137. const int num_lower_zmm_regs = 16;
  138. /* MMX register? */
  139. static int
  140. i386_mmx_regnum_p (struct gdbarch *gdbarch, int regnum)
  141. {
  142. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  143. int mm0_regnum = tdep->mm0_regnum;
  144. if (mm0_regnum < 0)
  145. return 0;
  146. regnum -= mm0_regnum;
  147. return regnum >= 0 && regnum < tdep->num_mmx_regs;
  148. }
  149. /* Byte register? */
  150. int
  151. i386_byte_regnum_p (struct gdbarch *gdbarch, int regnum)
  152. {
  153. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  154. regnum -= tdep->al_regnum;
  155. return regnum >= 0 && regnum < tdep->num_byte_regs;
  156. }
  157. /* Word register? */
  158. int
  159. i386_word_regnum_p (struct gdbarch *gdbarch, int regnum)
  160. {
  161. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  162. regnum -= tdep->ax_regnum;
  163. return regnum >= 0 && regnum < tdep->num_word_regs;
  164. }
  165. /* Dword register? */
  166. int
  167. i386_dword_regnum_p (struct gdbarch *gdbarch, int regnum)
  168. {
  169. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  170. int eax_regnum = tdep->eax_regnum;
  171. if (eax_regnum < 0)
  172. return 0;
  173. regnum -= eax_regnum;
  174. return regnum >= 0 && regnum < tdep->num_dword_regs;
  175. }
  176. /* AVX512 register? */
  177. int
  178. i386_zmmh_regnum_p (struct gdbarch *gdbarch, int regnum)
  179. {
  180. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  181. int zmm0h_regnum = tdep->zmm0h_regnum;
  182. if (zmm0h_regnum < 0)
  183. return 0;
  184. regnum -= zmm0h_regnum;
  185. return regnum >= 0 && regnum < tdep->num_zmm_regs;
  186. }
  187. int
  188. i386_zmm_regnum_p (struct gdbarch *gdbarch, int regnum)
  189. {
  190. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  191. int zmm0_regnum = tdep->zmm0_regnum;
  192. if (zmm0_regnum < 0)
  193. return 0;
  194. regnum -= zmm0_regnum;
  195. return regnum >= 0 && regnum < tdep->num_zmm_regs;
  196. }
  197. int
  198. i386_k_regnum_p (struct gdbarch *gdbarch, int regnum)
  199. {
  200. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  201. int k0_regnum = tdep->k0_regnum;
  202. if (k0_regnum < 0)
  203. return 0;
  204. regnum -= k0_regnum;
  205. return regnum >= 0 && regnum < I387_NUM_K_REGS;
  206. }
  207. static int
  208. i386_ymmh_regnum_p (struct gdbarch *gdbarch, int regnum)
  209. {
  210. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  211. int ymm0h_regnum = tdep->ymm0h_regnum;
  212. if (ymm0h_regnum < 0)
  213. return 0;
  214. regnum -= ymm0h_regnum;
  215. return regnum >= 0 && regnum < tdep->num_ymm_regs;
  216. }
  217. /* AVX register? */
  218. int
  219. i386_ymm_regnum_p (struct gdbarch *gdbarch, int regnum)
  220. {
  221. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  222. int ymm0_regnum = tdep->ymm0_regnum;
  223. if (ymm0_regnum < 0)
  224. return 0;
  225. regnum -= ymm0_regnum;
  226. return regnum >= 0 && regnum < tdep->num_ymm_regs;
  227. }
  228. static int
  229. i386_ymmh_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
  230. {
  231. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  232. int ymm16h_regnum = tdep->ymm16h_regnum;
  233. if (ymm16h_regnum < 0)
  234. return 0;
  235. regnum -= ymm16h_regnum;
  236. return regnum >= 0 && regnum < tdep->num_ymm_avx512_regs;
  237. }
  238. int
  239. i386_ymm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
  240. {
  241. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  242. int ymm16_regnum = tdep->ymm16_regnum;
  243. if (ymm16_regnum < 0)
  244. return 0;
  245. regnum -= ymm16_regnum;
  246. return regnum >= 0 && regnum < tdep->num_ymm_avx512_regs;
  247. }
  248. /* BND register? */
  249. int
  250. i386_bnd_regnum_p (struct gdbarch *gdbarch, int regnum)
  251. {
  252. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  253. int bnd0_regnum = tdep->bnd0_regnum;
  254. if (bnd0_regnum < 0)
  255. return 0;
  256. regnum -= bnd0_regnum;
  257. return regnum >= 0 && regnum < I387_NUM_BND_REGS;
  258. }
  259. /* SSE register? */
  260. int
  261. i386_xmm_regnum_p (struct gdbarch *gdbarch, int regnum)
  262. {
  263. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  264. int num_xmm_regs = I387_NUM_XMM_REGS (tdep);
  265. if (num_xmm_regs == 0)
  266. return 0;
  267. regnum -= I387_XMM0_REGNUM (tdep);
  268. return regnum >= 0 && regnum < num_xmm_regs;
  269. }
  270. /* XMM_512 register? */
  271. int
  272. i386_xmm_avx512_regnum_p (struct gdbarch *gdbarch, int regnum)
  273. {
  274. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  275. int num_xmm_avx512_regs = I387_NUM_XMM_AVX512_REGS (tdep);
  276. if (num_xmm_avx512_regs == 0)
  277. return 0;
  278. regnum -= I387_XMM16_REGNUM (tdep);
  279. return regnum >= 0 && regnum < num_xmm_avx512_regs;
  280. }
  281. static int
  282. i386_mxcsr_regnum_p (struct gdbarch *gdbarch, int regnum)
  283. {
  284. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  285. if (I387_NUM_XMM_REGS (tdep) == 0)
  286. return 0;
  287. return (regnum == I387_MXCSR_REGNUM (tdep));
  288. }
  289. /* FP register? */
  290. int
  291. i386_fp_regnum_p (struct gdbarch *gdbarch, int regnum)
  292. {
  293. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  294. if (I387_ST0_REGNUM (tdep) < 0)
  295. return 0;
  296. return (I387_ST0_REGNUM (tdep) <= regnum
  297. && regnum < I387_FCTRL_REGNUM (tdep));
  298. }
  299. int
  300. i386_fpc_regnum_p (struct gdbarch *gdbarch, int regnum)
  301. {
  302. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  303. if (I387_ST0_REGNUM (tdep) < 0)
  304. return 0;
  305. return (I387_FCTRL_REGNUM (tdep) <= regnum
  306. && regnum < I387_XMM0_REGNUM (tdep));
  307. }
  308. /* BNDr (raw) register? */
  309. static int
  310. i386_bndr_regnum_p (struct gdbarch *gdbarch, int regnum)
  311. {
  312. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  313. if (I387_BND0R_REGNUM (tdep) < 0)
  314. return 0;
  315. regnum -= tdep->bnd0r_regnum;
  316. return regnum >= 0 && regnum < I387_NUM_BND_REGS;
  317. }
  318. /* BND control register? */
  319. static int
  320. i386_mpx_ctrl_regnum_p (struct gdbarch *gdbarch, int regnum)
  321. {
  322. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  323. if (I387_BNDCFGU_REGNUM (tdep) < 0)
  324. return 0;
  325. regnum -= I387_BNDCFGU_REGNUM (tdep);
  326. return regnum >= 0 && regnum < I387_NUM_MPX_CTRL_REGS;
  327. }
  328. /* PKRU register? */
  329. bool
  330. i386_pkru_regnum_p (struct gdbarch *gdbarch, int regnum)
  331. {
  332. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  333. int pkru_regnum = tdep->pkru_regnum;
  334. if (pkru_regnum < 0)
  335. return false;
  336. regnum -= pkru_regnum;
  337. return regnum >= 0 && regnum < I387_NUM_PKEYS_REGS;
  338. }
  339. /* Return the name of register REGNUM, or the empty string if it is
  340. an anonymous register. */
  341. static const char *
  342. i386_register_name (struct gdbarch *gdbarch, int regnum)
  343. {
  344. /* Hide the upper YMM registers. */
  345. if (i386_ymmh_regnum_p (gdbarch, regnum))
  346. return "";
  347. /* Hide the upper YMM16-31 registers. */
  348. if (i386_ymmh_avx512_regnum_p (gdbarch, regnum))
  349. return "";
  350. /* Hide the upper ZMM registers. */
  351. if (i386_zmmh_regnum_p (gdbarch, regnum))
  352. return "";
  353. return tdesc_register_name (gdbarch, regnum);
  354. }
  355. /* Return the name of register REGNUM. */
  356. const char *
  357. i386_pseudo_register_name (struct gdbarch *gdbarch, int regnum)
  358. {
  359. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  360. if (i386_bnd_regnum_p (gdbarch, regnum))
  361. return i386_bnd_names[regnum - tdep->bnd0_regnum];
  362. if (i386_mmx_regnum_p (gdbarch, regnum))
  363. return i386_mmx_names[regnum - I387_MM0_REGNUM (tdep)];
  364. else if (i386_ymm_regnum_p (gdbarch, regnum))
  365. return i386_ymm_names[regnum - tdep->ymm0_regnum];
  366. else if (i386_zmm_regnum_p (gdbarch, regnum))
  367. return i386_zmm_names[regnum - tdep->zmm0_regnum];
  368. else if (i386_byte_regnum_p (gdbarch, regnum))
  369. return i386_byte_names[regnum - tdep->al_regnum];
  370. else if (i386_word_regnum_p (gdbarch, regnum))
  371. return i386_word_names[regnum - tdep->ax_regnum];
  372. internal_error (__FILE__, __LINE__, _("invalid regnum"));
  373. }
  374. /* Convert a dbx register number REG to the appropriate register
  375. number used by GDB. */
  376. static int
  377. i386_dbx_reg_to_regnum (struct gdbarch *gdbarch, int reg)
  378. {
  379. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  380. /* This implements what GCC calls the "default" register map
  381. (dbx_register_map[]). */
  382. if (reg >= 0 && reg <= 7)
  383. {
  384. /* General-purpose registers. The debug info calls %ebp
  385. register 4, and %esp register 5. */
  386. if (reg == 4)
  387. return 5;
  388. else if (reg == 5)
  389. return 4;
  390. else return reg;
  391. }
  392. else if (reg >= 12 && reg <= 19)
  393. {
  394. /* Floating-point registers. */
  395. return reg - 12 + I387_ST0_REGNUM (tdep);
  396. }
  397. else if (reg >= 21 && reg <= 28)
  398. {
  399. /* SSE registers. */
  400. int ymm0_regnum = tdep->ymm0_regnum;
  401. if (ymm0_regnum >= 0
  402. && i386_xmm_regnum_p (gdbarch, reg))
  403. return reg - 21 + ymm0_regnum;
  404. else
  405. return reg - 21 + I387_XMM0_REGNUM (tdep);
  406. }
  407. else if (reg >= 29 && reg <= 36)
  408. {
  409. /* MMX registers. */
  410. return reg - 29 + I387_MM0_REGNUM (tdep);
  411. }
  412. /* This will hopefully provoke a warning. */
  413. return gdbarch_num_cooked_regs (gdbarch);
  414. }
  415. /* Convert SVR4 DWARF register number REG to the appropriate register number
  416. used by GDB. */
  417. static int
  418. i386_svr4_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
  419. {
  420. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  421. /* This implements the GCC register map that tries to be compatible
  422. with the SVR4 C compiler for DWARF (svr4_dbx_register_map[]). */
  423. /* The SVR4 register numbering includes %eip and %eflags, and
  424. numbers the floating point registers differently. */
  425. if (reg >= 0 && reg <= 9)
  426. {
  427. /* General-purpose registers. */
  428. return reg;
  429. }
  430. else if (reg >= 11 && reg <= 18)
  431. {
  432. /* Floating-point registers. */
  433. return reg - 11 + I387_ST0_REGNUM (tdep);
  434. }
  435. else if (reg >= 21 && reg <= 36)
  436. {
  437. /* The SSE and MMX registers have the same numbers as with dbx. */
  438. return i386_dbx_reg_to_regnum (gdbarch, reg);
  439. }
  440. switch (reg)
  441. {
  442. case 37: return I387_FCTRL_REGNUM (tdep);
  443. case 38: return I387_FSTAT_REGNUM (tdep);
  444. case 39: return I387_MXCSR_REGNUM (tdep);
  445. case 40: return I386_ES_REGNUM;
  446. case 41: return I386_CS_REGNUM;
  447. case 42: return I386_SS_REGNUM;
  448. case 43: return I386_DS_REGNUM;
  449. case 44: return I386_FS_REGNUM;
  450. case 45: return I386_GS_REGNUM;
  451. }
  452. return -1;
  453. }
  454. /* Wrapper on i386_svr4_dwarf_reg_to_regnum to return
  455. num_regs + num_pseudo_regs for other debug formats. */
  456. int
  457. i386_svr4_reg_to_regnum (struct gdbarch *gdbarch, int reg)
  458. {
  459. int regnum = i386_svr4_dwarf_reg_to_regnum (gdbarch, reg);
  460. if (regnum == -1)
  461. return gdbarch_num_cooked_regs (gdbarch);
  462. return regnum;
  463. }
  464. /* This is the variable that is set with "set disassembly-flavor", and
  465. its legitimate values. */
  466. static const char att_flavor[] = "att";
  467. static const char intel_flavor[] = "intel";
  468. static const char *const valid_flavors[] =
  469. {
  470. att_flavor,
  471. intel_flavor,
  472. NULL
  473. };
  474. static const char *disassembly_flavor = att_flavor;
  475. /* Use the program counter to determine the contents and size of a
  476. breakpoint instruction. Return a pointer to a string of bytes that
  477. encode a breakpoint instruction, store the length of the string in
  478. *LEN and optionally adjust *PC to point to the correct memory
  479. location for inserting the breakpoint.
  480. On the i386 we have a single breakpoint that fits in a single byte
  481. and can be inserted anywhere.
  482. This function is 64-bit safe. */
  483. constexpr gdb_byte i386_break_insn[] = { 0xcc }; /* int 3 */
  484. typedef BP_MANIPULATION (i386_break_insn) i386_breakpoint;
  485. /* Displaced instruction handling. */
  486. /* Skip the legacy instruction prefixes in INSN.
  487. Not all prefixes are valid for any particular insn
  488. but we needn't care, the insn will fault if it's invalid.
  489. The result is a pointer to the first opcode byte,
  490. or NULL if we run off the end of the buffer. */
  491. static gdb_byte *
  492. i386_skip_prefixes (gdb_byte *insn, size_t max_len)
  493. {
  494. gdb_byte *end = insn + max_len;
  495. while (insn < end)
  496. {
  497. switch (*insn)
  498. {
  499. case DATA_PREFIX_OPCODE:
  500. case ADDR_PREFIX_OPCODE:
  501. case CS_PREFIX_OPCODE:
  502. case DS_PREFIX_OPCODE:
  503. case ES_PREFIX_OPCODE:
  504. case FS_PREFIX_OPCODE:
  505. case GS_PREFIX_OPCODE:
  506. case SS_PREFIX_OPCODE:
  507. case LOCK_PREFIX_OPCODE:
  508. case REPE_PREFIX_OPCODE:
  509. case REPNE_PREFIX_OPCODE:
  510. ++insn;
  511. continue;
  512. default:
  513. return insn;
  514. }
  515. }
  516. return NULL;
  517. }
  518. static int
  519. i386_absolute_jmp_p (const gdb_byte *insn)
  520. {
  521. /* jmp far (absolute address in operand). */
  522. if (insn[0] == 0xea)
  523. return 1;
  524. if (insn[0] == 0xff)
  525. {
  526. /* jump near, absolute indirect (/4). */
  527. if ((insn[1] & 0x38) == 0x20)
  528. return 1;
  529. /* jump far, absolute indirect (/5). */
  530. if ((insn[1] & 0x38) == 0x28)
  531. return 1;
  532. }
  533. return 0;
  534. }
  535. /* Return non-zero if INSN is a jump, zero otherwise. */
  536. static int
  537. i386_jmp_p (const gdb_byte *insn)
  538. {
  539. /* jump short, relative. */
  540. if (insn[0] == 0xeb)
  541. return 1;
  542. /* jump near, relative. */
  543. if (insn[0] == 0xe9)
  544. return 1;
  545. return i386_absolute_jmp_p (insn);
  546. }
  547. static int
  548. i386_absolute_call_p (const gdb_byte *insn)
  549. {
  550. /* call far, absolute. */
  551. if (insn[0] == 0x9a)
  552. return 1;
  553. if (insn[0] == 0xff)
  554. {
  555. /* Call near, absolute indirect (/2). */
  556. if ((insn[1] & 0x38) == 0x10)
  557. return 1;
  558. /* Call far, absolute indirect (/3). */
  559. if ((insn[1] & 0x38) == 0x18)
  560. return 1;
  561. }
  562. return 0;
  563. }
  564. static int
  565. i386_ret_p (const gdb_byte *insn)
  566. {
  567. switch (insn[0])
  568. {
  569. case 0xc2: /* ret near, pop N bytes. */
  570. case 0xc3: /* ret near */
  571. case 0xca: /* ret far, pop N bytes. */
  572. case 0xcb: /* ret far */
  573. case 0xcf: /* iret */
  574. return 1;
  575. default:
  576. return 0;
  577. }
  578. }
  579. static int
  580. i386_call_p (const gdb_byte *insn)
  581. {
  582. if (i386_absolute_call_p (insn))
  583. return 1;
  584. /* call near, relative. */
  585. if (insn[0] == 0xe8)
  586. return 1;
  587. return 0;
  588. }
  589. /* Return non-zero if INSN is a system call, and set *LENGTHP to its
  590. length in bytes. Otherwise, return zero. */
  591. static int
  592. i386_syscall_p (const gdb_byte *insn, int *lengthp)
  593. {
  594. /* Is it 'int $0x80'? */
  595. if ((insn[0] == 0xcd && insn[1] == 0x80)
  596. /* Or is it 'sysenter'? */
  597. || (insn[0] == 0x0f && insn[1] == 0x34)
  598. /* Or is it 'syscall'? */
  599. || (insn[0] == 0x0f && insn[1] == 0x05))
  600. {
  601. *lengthp = 2;
  602. return 1;
  603. }
  604. return 0;
  605. }
  606. /* The gdbarch insn_is_call method. */
  607. static int
  608. i386_insn_is_call (struct gdbarch *gdbarch, CORE_ADDR addr)
  609. {
  610. gdb_byte buf[I386_MAX_INSN_LEN], *insn;
  611. read_code (addr, buf, I386_MAX_INSN_LEN);
  612. insn = i386_skip_prefixes (buf, I386_MAX_INSN_LEN);
  613. return i386_call_p (insn);
  614. }
  615. /* The gdbarch insn_is_ret method. */
  616. static int
  617. i386_insn_is_ret (struct gdbarch *gdbarch, CORE_ADDR addr)
  618. {
  619. gdb_byte buf[I386_MAX_INSN_LEN], *insn;
  620. read_code (addr, buf, I386_MAX_INSN_LEN);
  621. insn = i386_skip_prefixes (buf, I386_MAX_INSN_LEN);
  622. return i386_ret_p (insn);
  623. }
  624. /* The gdbarch insn_is_jump method. */
  625. static int
  626. i386_insn_is_jump (struct gdbarch *gdbarch, CORE_ADDR addr)
  627. {
  628. gdb_byte buf[I386_MAX_INSN_LEN], *insn;
  629. read_code (addr, buf, I386_MAX_INSN_LEN);
  630. insn = i386_skip_prefixes (buf, I386_MAX_INSN_LEN);
  631. return i386_jmp_p (insn);
  632. }
  633. /* Some kernels may run one past a syscall insn, so we have to cope. */
  634. displaced_step_copy_insn_closure_up
  635. i386_displaced_step_copy_insn (struct gdbarch *gdbarch,
  636. CORE_ADDR from, CORE_ADDR to,
  637. struct regcache *regs)
  638. {
  639. size_t len = gdbarch_max_insn_length (gdbarch);
  640. std::unique_ptr<i386_displaced_step_copy_insn_closure> closure
  641. (new i386_displaced_step_copy_insn_closure (len));
  642. gdb_byte *buf = closure->buf.data ();
  643. read_memory (from, buf, len);
  644. /* GDB may get control back after the insn after the syscall.
  645. Presumably this is a kernel bug.
  646. If this is a syscall, make sure there's a nop afterwards. */
  647. {
  648. int syscall_length;
  649. gdb_byte *insn;
  650. insn = i386_skip_prefixes (buf, len);
  651. if (insn != NULL && i386_syscall_p (insn, &syscall_length))
  652. insn[syscall_length] = NOP_OPCODE;
  653. }
  654. write_memory (to, buf, len);
  655. displaced_debug_printf ("%s->%s: %s",
  656. paddress (gdbarch, from), paddress (gdbarch, to),
  657. displaced_step_dump_bytes (buf, len).c_str ());
  658. /* This is a work around for a problem with g++ 4.8. */
  659. return displaced_step_copy_insn_closure_up (closure.release ());
  660. }
  661. /* Fix up the state of registers and memory after having single-stepped
  662. a displaced instruction. */
  663. void
  664. i386_displaced_step_fixup (struct gdbarch *gdbarch,
  665. struct displaced_step_copy_insn_closure *closure_,
  666. CORE_ADDR from, CORE_ADDR to,
  667. struct regcache *regs)
  668. {
  669. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  670. /* The offset we applied to the instruction's address.
  671. This could well be negative (when viewed as a signed 32-bit
  672. value), but ULONGEST won't reflect that, so take care when
  673. applying it. */
  674. ULONGEST insn_offset = to - from;
  675. i386_displaced_step_copy_insn_closure *closure
  676. = (i386_displaced_step_copy_insn_closure *) closure_;
  677. gdb_byte *insn = closure->buf.data ();
  678. /* The start of the insn, needed in case we see some prefixes. */
  679. gdb_byte *insn_start = insn;
  680. displaced_debug_printf ("fixup (%s, %s), insn = 0x%02x 0x%02x ...",
  681. paddress (gdbarch, from), paddress (gdbarch, to),
  682. insn[0], insn[1]);
  683. /* The list of issues to contend with here is taken from
  684. resume_execution in arch/i386/kernel/kprobes.c, Linux 2.6.20.
  685. Yay for Free Software! */
  686. /* Relocate the %eip, if necessary. */
  687. /* The instruction recognizers we use assume any leading prefixes
  688. have been skipped. */
  689. {
  690. /* This is the size of the buffer in closure. */
  691. size_t max_insn_len = gdbarch_max_insn_length (gdbarch);
  692. gdb_byte *opcode = i386_skip_prefixes (insn, max_insn_len);
  693. /* If there are too many prefixes, just ignore the insn.
  694. It will fault when run. */
  695. if (opcode != NULL)
  696. insn = opcode;
  697. }
  698. /* Except in the case of absolute or indirect jump or call
  699. instructions, or a return instruction, the new eip is relative to
  700. the displaced instruction; make it relative. Well, signal
  701. handler returns don't need relocation either, but we use the
  702. value of %eip to recognize those; see below. */
  703. if (! i386_absolute_jmp_p (insn)
  704. && ! i386_absolute_call_p (insn)
  705. && ! i386_ret_p (insn))
  706. {
  707. ULONGEST orig_eip;
  708. int insn_len;
  709. regcache_cooked_read_unsigned (regs, I386_EIP_REGNUM, &orig_eip);
  710. /* A signal trampoline system call changes the %eip, resuming
  711. execution of the main program after the signal handler has
  712. returned. That makes them like 'return' instructions; we
  713. shouldn't relocate %eip.
  714. But most system calls don't, and we do need to relocate %eip.
  715. Our heuristic for distinguishing these cases: if stepping
  716. over the system call instruction left control directly after
  717. the instruction, the we relocate --- control almost certainly
  718. doesn't belong in the displaced copy. Otherwise, we assume
  719. the instruction has put control where it belongs, and leave
  720. it unrelocated. Goodness help us if there are PC-relative
  721. system calls. */
  722. if (i386_syscall_p (insn, &insn_len)
  723. && orig_eip != to + (insn - insn_start) + insn_len
  724. /* GDB can get control back after the insn after the syscall.
  725. Presumably this is a kernel bug.
  726. i386_displaced_step_copy_insn ensures its a nop,
  727. we add one to the length for it. */
  728. && orig_eip != to + (insn - insn_start) + insn_len + 1)
  729. displaced_debug_printf ("syscall changed %%eip; not relocating");
  730. else
  731. {
  732. ULONGEST eip = (orig_eip - insn_offset) & 0xffffffffUL;
  733. /* If we just stepped over a breakpoint insn, we don't backup
  734. the pc on purpose; this is to match behaviour without
  735. stepping. */
  736. regcache_cooked_write_unsigned (regs, I386_EIP_REGNUM, eip);
  737. displaced_debug_printf ("relocated %%eip from %s to %s",
  738. paddress (gdbarch, orig_eip),
  739. paddress (gdbarch, eip));
  740. }
  741. }
  742. /* If the instruction was PUSHFL, then the TF bit will be set in the
  743. pushed value, and should be cleared. We'll leave this for later,
  744. since GDB already messes up the TF flag when stepping over a
  745. pushfl. */
  746. /* If the instruction was a call, the return address now atop the
  747. stack is the address following the copied instruction. We need
  748. to make it the address following the original instruction. */
  749. if (i386_call_p (insn))
  750. {
  751. ULONGEST esp;
  752. ULONGEST retaddr;
  753. const ULONGEST retaddr_len = 4;
  754. regcache_cooked_read_unsigned (regs, I386_ESP_REGNUM, &esp);
  755. retaddr = read_memory_unsigned_integer (esp, retaddr_len, byte_order);
  756. retaddr = (retaddr - insn_offset) & 0xffffffffUL;
  757. write_memory_unsigned_integer (esp, retaddr_len, byte_order, retaddr);
  758. displaced_debug_printf ("relocated return addr at %s to %s",
  759. paddress (gdbarch, esp),
  760. paddress (gdbarch, retaddr));
  761. }
  762. }
  763. static void
  764. append_insns (CORE_ADDR *to, ULONGEST len, const gdb_byte *buf)
  765. {
  766. target_write_memory (*to, buf, len);
  767. *to += len;
  768. }
  769. static void
  770. i386_relocate_instruction (struct gdbarch *gdbarch,
  771. CORE_ADDR *to, CORE_ADDR oldloc)
  772. {
  773. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  774. gdb_byte buf[I386_MAX_INSN_LEN];
  775. int offset = 0, rel32, newrel;
  776. int insn_length;
  777. gdb_byte *insn = buf;
  778. read_memory (oldloc, buf, I386_MAX_INSN_LEN);
  779. insn_length = gdb_buffered_insn_length (gdbarch, insn,
  780. I386_MAX_INSN_LEN, oldloc);
  781. /* Get past the prefixes. */
  782. insn = i386_skip_prefixes (insn, I386_MAX_INSN_LEN);
  783. /* Adjust calls with 32-bit relative addresses as push/jump, with
  784. the address pushed being the location where the original call in
  785. the user program would return to. */
  786. if (insn[0] == 0xe8)
  787. {
  788. gdb_byte push_buf[16];
  789. unsigned int ret_addr;
  790. /* Where "ret" in the original code will return to. */
  791. ret_addr = oldloc + insn_length;
  792. push_buf[0] = 0x68; /* pushq $... */
  793. store_unsigned_integer (&push_buf[1], 4, byte_order, ret_addr);
  794. /* Push the push. */
  795. append_insns (to, 5, push_buf);
  796. /* Convert the relative call to a relative jump. */
  797. insn[0] = 0xe9;
  798. /* Adjust the destination offset. */
  799. rel32 = extract_signed_integer (insn + 1, 4, byte_order);
  800. newrel = (oldloc - *to) + rel32;
  801. store_signed_integer (insn + 1, 4, byte_order, newrel);
  802. displaced_debug_printf ("adjusted insn rel32=%s at %s to rel32=%s at %s",
  803. hex_string (rel32), paddress (gdbarch, oldloc),
  804. hex_string (newrel), paddress (gdbarch, *to));
  805. /* Write the adjusted jump into its displaced location. */
  806. append_insns (to, 5, insn);
  807. return;
  808. }
  809. /* Adjust jumps with 32-bit relative addresses. Calls are already
  810. handled above. */
  811. if (insn[0] == 0xe9)
  812. offset = 1;
  813. /* Adjust conditional jumps. */
  814. else if (insn[0] == 0x0f && (insn[1] & 0xf0) == 0x80)
  815. offset = 2;
  816. if (offset)
  817. {
  818. rel32 = extract_signed_integer (insn + offset, 4, byte_order);
  819. newrel = (oldloc - *to) + rel32;
  820. store_signed_integer (insn + offset, 4, byte_order, newrel);
  821. displaced_debug_printf ("adjusted insn rel32=%s at %s to rel32=%s at %s",
  822. hex_string (rel32), paddress (gdbarch, oldloc),
  823. hex_string (newrel), paddress (gdbarch, *to));
  824. }
  825. /* Write the adjusted instructions into their displaced
  826. location. */
  827. append_insns (to, insn_length, buf);
  828. }
  829. #ifdef I386_REGNO_TO_SYMMETRY
  830. #error "The Sequent Symmetry is no longer supported."
  831. #endif
  832. /* According to the System V ABI, the registers %ebp, %ebx, %edi, %esi
  833. and %esp "belong" to the calling function. Therefore these
  834. registers should be saved if they're going to be modified. */
  835. /* The maximum number of saved registers. This should include all
  836. registers mentioned above, and %eip. */
  837. #define I386_NUM_SAVED_REGS I386_NUM_GREGS
  838. struct i386_frame_cache
  839. {
  840. /* Base address. */
  841. CORE_ADDR base;
  842. int base_p;
  843. LONGEST sp_offset;
  844. CORE_ADDR pc;
  845. /* Saved registers. */
  846. CORE_ADDR saved_regs[I386_NUM_SAVED_REGS];
  847. CORE_ADDR saved_sp;
  848. int saved_sp_reg;
  849. int pc_in_eax;
  850. /* Stack space reserved for local variables. */
  851. long locals;
  852. };
  853. /* Allocate and initialize a frame cache. */
  854. static struct i386_frame_cache *
  855. i386_alloc_frame_cache (void)
  856. {
  857. struct i386_frame_cache *cache;
  858. int i;
  859. cache = FRAME_OBSTACK_ZALLOC (struct i386_frame_cache);
  860. /* Base address. */
  861. cache->base_p = 0;
  862. cache->base = 0;
  863. cache->sp_offset = -4;
  864. cache->pc = 0;
  865. /* Saved registers. We initialize these to -1 since zero is a valid
  866. offset (that's where %ebp is supposed to be stored). */
  867. for (i = 0; i < I386_NUM_SAVED_REGS; i++)
  868. cache->saved_regs[i] = -1;
  869. cache->saved_sp = 0;
  870. cache->saved_sp_reg = -1;
  871. cache->pc_in_eax = 0;
  872. /* Frameless until proven otherwise. */
  873. cache->locals = -1;
  874. return cache;
  875. }
  876. /* If the instruction at PC is a jump, return the address of its
  877. target. Otherwise, return PC. */
  878. static CORE_ADDR
  879. i386_follow_jump (struct gdbarch *gdbarch, CORE_ADDR pc)
  880. {
  881. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  882. gdb_byte op;
  883. long delta = 0;
  884. int data16 = 0;
  885. if (target_read_code (pc, &op, 1))
  886. return pc;
  887. if (op == 0x66)
  888. {
  889. data16 = 1;
  890. op = read_code_unsigned_integer (pc + 1, 1, byte_order);
  891. }
  892. switch (op)
  893. {
  894. case 0xe9:
  895. /* Relative jump: if data16 == 0, disp32, else disp16. */
  896. if (data16)
  897. {
  898. delta = read_memory_integer (pc + 2, 2, byte_order);
  899. /* Include the size of the jmp instruction (including the
  900. 0x66 prefix). */
  901. delta += 4;
  902. }
  903. else
  904. {
  905. delta = read_memory_integer (pc + 1, 4, byte_order);
  906. /* Include the size of the jmp instruction. */
  907. delta += 5;
  908. }
  909. break;
  910. case 0xeb:
  911. /* Relative jump, disp8 (ignore data16). */
  912. delta = read_memory_integer (pc + data16 + 1, 1, byte_order);
  913. delta += data16 + 2;
  914. break;
  915. }
  916. return pc + delta;
  917. }
  918. /* Check whether PC points at a prologue for a function returning a
  919. structure or union. If so, it updates CACHE and returns the
  920. address of the first instruction after the code sequence that
  921. removes the "hidden" argument from the stack or CURRENT_PC,
  922. whichever is smaller. Otherwise, return PC. */
  923. static CORE_ADDR
  924. i386_analyze_struct_return (CORE_ADDR pc, CORE_ADDR current_pc,
  925. struct i386_frame_cache *cache)
  926. {
  927. /* Functions that return a structure or union start with:
  928. popl %eax 0x58
  929. xchgl %eax, (%esp) 0x87 0x04 0x24
  930. or xchgl %eax, 0(%esp) 0x87 0x44 0x24 0x00
  931. (the System V compiler puts out the second `xchg' instruction,
  932. and the assembler doesn't try to optimize it, so the 'sib' form
  933. gets generated). This sequence is used to get the address of the
  934. return buffer for a function that returns a structure. */
  935. static gdb_byte proto1[3] = { 0x87, 0x04, 0x24 };
  936. static gdb_byte proto2[4] = { 0x87, 0x44, 0x24, 0x00 };
  937. gdb_byte buf[4];
  938. gdb_byte op;
  939. if (current_pc <= pc)
  940. return pc;
  941. if (target_read_code (pc, &op, 1))
  942. return pc;
  943. if (op != 0x58) /* popl %eax */
  944. return pc;
  945. if (target_read_code (pc + 1, buf, 4))
  946. return pc;
  947. if (memcmp (buf, proto1, 3) != 0 && memcmp (buf, proto2, 4) != 0)
  948. return pc;
  949. if (current_pc == pc)
  950. {
  951. cache->sp_offset += 4;
  952. return current_pc;
  953. }
  954. if (current_pc == pc + 1)
  955. {
  956. cache->pc_in_eax = 1;
  957. return current_pc;
  958. }
  959. if (buf[1] == proto1[1])
  960. return pc + 4;
  961. else
  962. return pc + 5;
  963. }
  964. static CORE_ADDR
  965. i386_skip_probe (CORE_ADDR pc)
  966. {
  967. /* A function may start with
  968. pushl constant
  969. call _probe
  970. addl $4, %esp
  971. followed by
  972. pushl %ebp
  973. etc. */
  974. gdb_byte buf[8];
  975. gdb_byte op;
  976. if (target_read_code (pc, &op, 1))
  977. return pc;
  978. if (op == 0x68 || op == 0x6a)
  979. {
  980. int delta;
  981. /* Skip past the `pushl' instruction; it has either a one-byte or a
  982. four-byte operand, depending on the opcode. */
  983. if (op == 0x68)
  984. delta = 5;
  985. else
  986. delta = 2;
  987. /* Read the following 8 bytes, which should be `call _probe' (6
  988. bytes) followed by `addl $4,%esp' (2 bytes). */
  989. read_memory (pc + delta, buf, sizeof (buf));
  990. if (buf[0] == 0xe8 && buf[6] == 0xc4 && buf[7] == 0x4)
  991. pc += delta + sizeof (buf);
  992. }
  993. return pc;
  994. }
  995. /* GCC 4.1 and later, can put code in the prologue to realign the
  996. stack pointer. Check whether PC points to such code, and update
  997. CACHE accordingly. Return the first instruction after the code
  998. sequence or CURRENT_PC, whichever is smaller. If we don't
  999. recognize the code, return PC. */
  1000. static CORE_ADDR
  1001. i386_analyze_stack_align (CORE_ADDR pc, CORE_ADDR current_pc,
  1002. struct i386_frame_cache *cache)
  1003. {
  1004. /* There are 2 code sequences to re-align stack before the frame
  1005. gets set up:
  1006. 1. Use a caller-saved saved register:
  1007. leal 4(%esp), %reg
  1008. andl $-XXX, %esp
  1009. pushl -4(%reg)
  1010. 2. Use a callee-saved saved register:
  1011. pushl %reg
  1012. leal 8(%esp), %reg
  1013. andl $-XXX, %esp
  1014. pushl -4(%reg)
  1015. "andl $-XXX, %esp" can be either 3 bytes or 6 bytes:
  1016. 0x83 0xe4 0xf0 andl $-16, %esp
  1017. 0x81 0xe4 0x00 0xff 0xff 0xff andl $-256, %esp
  1018. */
  1019. gdb_byte buf[14];
  1020. int reg;
  1021. int offset, offset_and;
  1022. static int regnums[8] = {
  1023. I386_EAX_REGNUM, /* %eax */
  1024. I386_ECX_REGNUM, /* %ecx */
  1025. I386_EDX_REGNUM, /* %edx */
  1026. I386_EBX_REGNUM, /* %ebx */
  1027. I386_ESP_REGNUM, /* %esp */
  1028. I386_EBP_REGNUM, /* %ebp */
  1029. I386_ESI_REGNUM, /* %esi */
  1030. I386_EDI_REGNUM /* %edi */
  1031. };
  1032. if (target_read_code (pc, buf, sizeof buf))
  1033. return pc;
  1034. /* Check caller-saved saved register. The first instruction has
  1035. to be "leal 4(%esp), %reg". */
  1036. if (buf[0] == 0x8d && buf[2] == 0x24 && buf[3] == 0x4)
  1037. {
  1038. /* MOD must be binary 10 and R/M must be binary 100. */
  1039. if ((buf[1] & 0xc7) != 0x44)
  1040. return pc;
  1041. /* REG has register number. */
  1042. reg = (buf[1] >> 3) & 7;
  1043. offset = 4;
  1044. }
  1045. else
  1046. {
  1047. /* Check callee-saved saved register. The first instruction
  1048. has to be "pushl %reg". */
  1049. if ((buf[0] & 0xf8) != 0x50)
  1050. return pc;
  1051. /* Get register. */
  1052. reg = buf[0] & 0x7;
  1053. /* The next instruction has to be "leal 8(%esp), %reg". */
  1054. if (buf[1] != 0x8d || buf[3] != 0x24 || buf[4] != 0x8)
  1055. return pc;
  1056. /* MOD must be binary 10 and R/M must be binary 100. */
  1057. if ((buf[2] & 0xc7) != 0x44)
  1058. return pc;
  1059. /* REG has register number. Registers in pushl and leal have to
  1060. be the same. */
  1061. if (reg != ((buf[2] >> 3) & 7))
  1062. return pc;
  1063. offset = 5;
  1064. }
  1065. /* Rigister can't be %esp nor %ebp. */
  1066. if (reg == 4 || reg == 5)
  1067. return pc;
  1068. /* The next instruction has to be "andl $-XXX, %esp". */
  1069. if (buf[offset + 1] != 0xe4
  1070. || (buf[offset] != 0x81 && buf[offset] != 0x83))
  1071. return pc;
  1072. offset_and = offset;
  1073. offset += buf[offset] == 0x81 ? 6 : 3;
  1074. /* The next instruction has to be "pushl -4(%reg)". 8bit -4 is
  1075. 0xfc. REG must be binary 110 and MOD must be binary 01. */
  1076. if (buf[offset] != 0xff
  1077. || buf[offset + 2] != 0xfc
  1078. || (buf[offset + 1] & 0xf8) != 0x70)
  1079. return pc;
  1080. /* R/M has register. Registers in leal and pushl have to be the
  1081. same. */
  1082. if (reg != (buf[offset + 1] & 7))
  1083. return pc;
  1084. if (current_pc > pc + offset_and)
  1085. cache->saved_sp_reg = regnums[reg];
  1086. return std::min (pc + offset + 3, current_pc);
  1087. }
  1088. /* Maximum instruction length we need to handle. */
  1089. #define I386_MAX_MATCHED_INSN_LEN 6
  1090. /* Instruction description. */
  1091. struct i386_insn
  1092. {
  1093. size_t len;
  1094. gdb_byte insn[I386_MAX_MATCHED_INSN_LEN];
  1095. gdb_byte mask[I386_MAX_MATCHED_INSN_LEN];
  1096. };
  1097. /* Return whether instruction at PC matches PATTERN. */
  1098. static int
  1099. i386_match_pattern (CORE_ADDR pc, struct i386_insn pattern)
  1100. {
  1101. gdb_byte op;
  1102. if (target_read_code (pc, &op, 1))
  1103. return 0;
  1104. if ((op & pattern.mask[0]) == pattern.insn[0])
  1105. {
  1106. gdb_byte buf[I386_MAX_MATCHED_INSN_LEN - 1];
  1107. int insn_matched = 1;
  1108. size_t i;
  1109. gdb_assert (pattern.len > 1);
  1110. gdb_assert (pattern.len <= I386_MAX_MATCHED_INSN_LEN);
  1111. if (target_read_code (pc + 1, buf, pattern.len - 1))
  1112. return 0;
  1113. for (i = 1; i < pattern.len; i++)
  1114. {
  1115. if ((buf[i - 1] & pattern.mask[i]) != pattern.insn[i])
  1116. insn_matched = 0;
  1117. }
  1118. return insn_matched;
  1119. }
  1120. return 0;
  1121. }
  1122. /* Search for the instruction at PC in the list INSN_PATTERNS. Return
  1123. the first instruction description that matches. Otherwise, return
  1124. NULL. */
  1125. static struct i386_insn *
  1126. i386_match_insn (CORE_ADDR pc, struct i386_insn *insn_patterns)
  1127. {
  1128. struct i386_insn *pattern;
  1129. for (pattern = insn_patterns; pattern->len > 0; pattern++)
  1130. {
  1131. if (i386_match_pattern (pc, *pattern))
  1132. return pattern;
  1133. }
  1134. return NULL;
  1135. }
  1136. /* Return whether PC points inside a sequence of instructions that
  1137. matches INSN_PATTERNS. */
  1138. static int
  1139. i386_match_insn_block (CORE_ADDR pc, struct i386_insn *insn_patterns)
  1140. {
  1141. CORE_ADDR current_pc;
  1142. int ix, i;
  1143. struct i386_insn *insn;
  1144. insn = i386_match_insn (pc, insn_patterns);
  1145. if (insn == NULL)
  1146. return 0;
  1147. current_pc = pc;
  1148. ix = insn - insn_patterns;
  1149. for (i = ix - 1; i >= 0; i--)
  1150. {
  1151. current_pc -= insn_patterns[i].len;
  1152. if (!i386_match_pattern (current_pc, insn_patterns[i]))
  1153. return 0;
  1154. }
  1155. current_pc = pc + insn->len;
  1156. for (insn = insn_patterns + ix + 1; insn->len > 0; insn++)
  1157. {
  1158. if (!i386_match_pattern (current_pc, *insn))
  1159. return 0;
  1160. current_pc += insn->len;
  1161. }
  1162. return 1;
  1163. }
  1164. /* Some special instructions that might be migrated by GCC into the
  1165. part of the prologue that sets up the new stack frame. Because the
  1166. stack frame hasn't been setup yet, no registers have been saved
  1167. yet, and only the scratch registers %eax, %ecx and %edx can be
  1168. touched. */
  1169. static i386_insn i386_frame_setup_skip_insns[] =
  1170. {
  1171. /* Check for `movb imm8, r' and `movl imm32, r'.
  1172. ??? Should we handle 16-bit operand-sizes here? */
  1173. /* `movb imm8, %al' and `movb imm8, %ah' */
  1174. /* `movb imm8, %cl' and `movb imm8, %ch' */
  1175. { 2, { 0xb0, 0x00 }, { 0xfa, 0x00 } },
  1176. /* `movb imm8, %dl' and `movb imm8, %dh' */
  1177. { 2, { 0xb2, 0x00 }, { 0xfb, 0x00 } },
  1178. /* `movl imm32, %eax' and `movl imm32, %ecx' */
  1179. { 5, { 0xb8 }, { 0xfe } },
  1180. /* `movl imm32, %edx' */
  1181. { 5, { 0xba }, { 0xff } },
  1182. /* Check for `mov imm32, r32'. Note that there is an alternative
  1183. encoding for `mov m32, %eax'.
  1184. ??? Should we handle SIB addressing here?
  1185. ??? Should we handle 16-bit operand-sizes here? */
  1186. /* `movl m32, %eax' */
  1187. { 5, { 0xa1 }, { 0xff } },
  1188. /* `movl m32, %eax' and `mov; m32, %ecx' */
  1189. { 6, { 0x89, 0x05 }, {0xff, 0xf7 } },
  1190. /* `movl m32, %edx' */
  1191. { 6, { 0x89, 0x15 }, {0xff, 0xff } },
  1192. /* Check for `xorl r32, r32' and the equivalent `subl r32, r32'.
  1193. Because of the symmetry, there are actually two ways to encode
  1194. these instructions; opcode bytes 0x29 and 0x2b for `subl' and
  1195. opcode bytes 0x31 and 0x33 for `xorl'. */
  1196. /* `subl %eax, %eax' */
  1197. { 2, { 0x29, 0xc0 }, { 0xfd, 0xff } },
  1198. /* `subl %ecx, %ecx' */
  1199. { 2, { 0x29, 0xc9 }, { 0xfd, 0xff } },
  1200. /* `subl %edx, %edx' */
  1201. { 2, { 0x29, 0xd2 }, { 0xfd, 0xff } },
  1202. /* `xorl %eax, %eax' */
  1203. { 2, { 0x31, 0xc0 }, { 0xfd, 0xff } },
  1204. /* `xorl %ecx, %ecx' */
  1205. { 2, { 0x31, 0xc9 }, { 0xfd, 0xff } },
  1206. /* `xorl %edx, %edx' */
  1207. { 2, { 0x31, 0xd2 }, { 0xfd, 0xff } },
  1208. { 0 }
  1209. };
  1210. /* Check whether PC points to an endbr32 instruction. */
  1211. static CORE_ADDR
  1212. i386_skip_endbr (CORE_ADDR pc)
  1213. {
  1214. static const gdb_byte endbr32[] = { 0xf3, 0x0f, 0x1e, 0xfb };
  1215. gdb_byte buf[sizeof (endbr32)];
  1216. /* Stop there if we can't read the code */
  1217. if (target_read_code (pc, buf, sizeof (endbr32)))
  1218. return pc;
  1219. /* If the instruction isn't an endbr32, stop */
  1220. if (memcmp (buf, endbr32, sizeof (endbr32)) != 0)
  1221. return pc;
  1222. return pc + sizeof (endbr32);
  1223. }
  1224. /* Check whether PC points to a no-op instruction. */
  1225. static CORE_ADDR
  1226. i386_skip_noop (CORE_ADDR pc)
  1227. {
  1228. gdb_byte op;
  1229. int check = 1;
  1230. if (target_read_code (pc, &op, 1))
  1231. return pc;
  1232. while (check)
  1233. {
  1234. check = 0;
  1235. /* Ignore `nop' instruction. */
  1236. if (op == 0x90)
  1237. {
  1238. pc += 1;
  1239. if (target_read_code (pc, &op, 1))
  1240. return pc;
  1241. check = 1;
  1242. }
  1243. /* Ignore no-op instruction `mov %edi, %edi'.
  1244. Microsoft system dlls often start with
  1245. a `mov %edi,%edi' instruction.
  1246. The 5 bytes before the function start are
  1247. filled with `nop' instructions.
  1248. This pattern can be used for hot-patching:
  1249. The `mov %edi, %edi' instruction can be replaced by a
  1250. near jump to the location of the 5 `nop' instructions
  1251. which can be replaced by a 32-bit jump to anywhere
  1252. in the 32-bit address space. */
  1253. else if (op == 0x8b)
  1254. {
  1255. if (target_read_code (pc + 1, &op, 1))
  1256. return pc;
  1257. if (op == 0xff)
  1258. {
  1259. pc += 2;
  1260. if (target_read_code (pc, &op, 1))
  1261. return pc;
  1262. check = 1;
  1263. }
  1264. }
  1265. }
  1266. return pc;
  1267. }
  1268. /* Check whether PC points at a code that sets up a new stack frame.
  1269. If so, it updates CACHE and returns the address of the first
  1270. instruction after the sequence that sets up the frame or LIMIT,
  1271. whichever is smaller. If we don't recognize the code, return PC. */
  1272. static CORE_ADDR
  1273. i386_analyze_frame_setup (struct gdbarch *gdbarch,
  1274. CORE_ADDR pc, CORE_ADDR limit,
  1275. struct i386_frame_cache *cache)
  1276. {
  1277. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1278. struct i386_insn *insn;
  1279. gdb_byte op;
  1280. int skip = 0;
  1281. if (limit <= pc)
  1282. return limit;
  1283. if (target_read_code (pc, &op, 1))
  1284. return pc;
  1285. if (op == 0x55) /* pushl %ebp */
  1286. {
  1287. /* Take into account that we've executed the `pushl %ebp' that
  1288. starts this instruction sequence. */
  1289. cache->saved_regs[I386_EBP_REGNUM] = 0;
  1290. cache->sp_offset += 4;
  1291. pc++;
  1292. /* If that's all, return now. */
  1293. if (limit <= pc)
  1294. return limit;
  1295. /* Check for some special instructions that might be migrated by
  1296. GCC into the prologue and skip them. At this point in the
  1297. prologue, code should only touch the scratch registers %eax,
  1298. %ecx and %edx, so while the number of possibilities is sheer,
  1299. it is limited.
  1300. Make sure we only skip these instructions if we later see the
  1301. `movl %esp, %ebp' that actually sets up the frame. */
  1302. while (pc + skip < limit)
  1303. {
  1304. insn = i386_match_insn (pc + skip, i386_frame_setup_skip_insns);
  1305. if (insn == NULL)
  1306. break;
  1307. skip += insn->len;
  1308. }
  1309. /* If that's all, return now. */
  1310. if (limit <= pc + skip)
  1311. return limit;
  1312. if (target_read_code (pc + skip, &op, 1))
  1313. return pc + skip;
  1314. /* The i386 prologue looks like
  1315. push %ebp
  1316. mov %esp,%ebp
  1317. sub $0x10,%esp
  1318. and a different prologue can be generated for atom.
  1319. push %ebp
  1320. lea (%esp),%ebp
  1321. lea -0x10(%esp),%esp
  1322. We handle both of them here. */
  1323. switch (op)
  1324. {
  1325. /* Check for `movl %esp, %ebp' -- can be written in two ways. */
  1326. case 0x8b:
  1327. if (read_code_unsigned_integer (pc + skip + 1, 1, byte_order)
  1328. != 0xec)
  1329. return pc;
  1330. pc += (skip + 2);
  1331. break;
  1332. case 0x89:
  1333. if (read_code_unsigned_integer (pc + skip + 1, 1, byte_order)
  1334. != 0xe5)
  1335. return pc;
  1336. pc += (skip + 2);
  1337. break;
  1338. case 0x8d: /* Check for 'lea (%ebp), %ebp'. */
  1339. if (read_code_unsigned_integer (pc + skip + 1, 2, byte_order)
  1340. != 0x242c)
  1341. return pc;
  1342. pc += (skip + 3);
  1343. break;
  1344. default:
  1345. return pc;
  1346. }
  1347. /* OK, we actually have a frame. We just don't know how large
  1348. it is yet. Set its size to zero. We'll adjust it if
  1349. necessary. We also now commit to skipping the special
  1350. instructions mentioned before. */
  1351. cache->locals = 0;
  1352. /* If that's all, return now. */
  1353. if (limit <= pc)
  1354. return limit;
  1355. /* Check for stack adjustment
  1356. subl $XXX, %esp
  1357. or
  1358. lea -XXX(%esp),%esp
  1359. NOTE: You can't subtract a 16-bit immediate from a 32-bit
  1360. reg, so we don't have to worry about a data16 prefix. */
  1361. if (target_read_code (pc, &op, 1))
  1362. return pc;
  1363. if (op == 0x83)
  1364. {
  1365. /* `subl' with 8-bit immediate. */
  1366. if (read_code_unsigned_integer (pc + 1, 1, byte_order) != 0xec)
  1367. /* Some instruction starting with 0x83 other than `subl'. */
  1368. return pc;
  1369. /* `subl' with signed 8-bit immediate (though it wouldn't
  1370. make sense to be negative). */
  1371. cache->locals = read_code_integer (pc + 2, 1, byte_order);
  1372. return pc + 3;
  1373. }
  1374. else if (op == 0x81)
  1375. {
  1376. /* Maybe it is `subl' with a 32-bit immediate. */
  1377. if (read_code_unsigned_integer (pc + 1, 1, byte_order) != 0xec)
  1378. /* Some instruction starting with 0x81 other than `subl'. */
  1379. return pc;
  1380. /* It is `subl' with a 32-bit immediate. */
  1381. cache->locals = read_code_integer (pc + 2, 4, byte_order);
  1382. return pc + 6;
  1383. }
  1384. else if (op == 0x8d)
  1385. {
  1386. /* The ModR/M byte is 0x64. */
  1387. if (read_code_unsigned_integer (pc + 1, 1, byte_order) != 0x64)
  1388. return pc;
  1389. /* 'lea' with 8-bit displacement. */
  1390. cache->locals = -1 * read_code_integer (pc + 3, 1, byte_order);
  1391. return pc + 4;
  1392. }
  1393. else
  1394. {
  1395. /* Some instruction other than `subl' nor 'lea'. */
  1396. return pc;
  1397. }
  1398. }
  1399. else if (op == 0xc8) /* enter */
  1400. {
  1401. cache->locals = read_code_unsigned_integer (pc + 1, 2, byte_order);
  1402. return pc + 4;
  1403. }
  1404. return pc;
  1405. }
  1406. /* Check whether PC points at code that saves registers on the stack.
  1407. If so, it updates CACHE and returns the address of the first
  1408. instruction after the register saves or CURRENT_PC, whichever is
  1409. smaller. Otherwise, return PC. */
  1410. static CORE_ADDR
  1411. i386_analyze_register_saves (CORE_ADDR pc, CORE_ADDR current_pc,
  1412. struct i386_frame_cache *cache)
  1413. {
  1414. CORE_ADDR offset = 0;
  1415. gdb_byte op;
  1416. int i;
  1417. if (cache->locals > 0)
  1418. offset -= cache->locals;
  1419. for (i = 0; i < 8 && pc < current_pc; i++)
  1420. {
  1421. if (target_read_code (pc, &op, 1))
  1422. return pc;
  1423. if (op < 0x50 || op > 0x57)
  1424. break;
  1425. offset -= 4;
  1426. cache->saved_regs[op - 0x50] = offset;
  1427. cache->sp_offset += 4;
  1428. pc++;
  1429. }
  1430. return pc;
  1431. }
  1432. /* Do a full analysis of the prologue at PC and update CACHE
  1433. accordingly. Bail out early if CURRENT_PC is reached. Return the
  1434. address where the analysis stopped.
  1435. We handle these cases:
  1436. The startup sequence can be at the start of the function, or the
  1437. function can start with a branch to startup code at the end.
  1438. %ebp can be set up with either the 'enter' instruction, or "pushl
  1439. %ebp, movl %esp, %ebp" (`enter' is too slow to be useful, but was
  1440. once used in the System V compiler).
  1441. Local space is allocated just below the saved %ebp by either the
  1442. 'enter' instruction, or by "subl $<size>, %esp". 'enter' has a
  1443. 16-bit unsigned argument for space to allocate, and the 'addl'
  1444. instruction could have either a signed byte, or 32-bit immediate.
  1445. Next, the registers used by this function are pushed. With the
  1446. System V compiler they will always be in the order: %edi, %esi,
  1447. %ebx (and sometimes a harmless bug causes it to also save but not
  1448. restore %eax); however, the code below is willing to see the pushes
  1449. in any order, and will handle up to 8 of them.
  1450. If the setup sequence is at the end of the function, then the next
  1451. instruction will be a branch back to the start. */
  1452. static CORE_ADDR
  1453. i386_analyze_prologue (struct gdbarch *gdbarch,
  1454. CORE_ADDR pc, CORE_ADDR current_pc,
  1455. struct i386_frame_cache *cache)
  1456. {
  1457. pc = i386_skip_endbr (pc);
  1458. pc = i386_skip_noop (pc);
  1459. pc = i386_follow_jump (gdbarch, pc);
  1460. pc = i386_analyze_struct_return (pc, current_pc, cache);
  1461. pc = i386_skip_probe (pc);
  1462. pc = i386_analyze_stack_align (pc, current_pc, cache);
  1463. pc = i386_analyze_frame_setup (gdbarch, pc, current_pc, cache);
  1464. return i386_analyze_register_saves (pc, current_pc, cache);
  1465. }
  1466. /* Return PC of first real instruction. */
  1467. static CORE_ADDR
  1468. i386_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR start_pc)
  1469. {
  1470. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1471. static gdb_byte pic_pat[6] =
  1472. {
  1473. 0xe8, 0, 0, 0, 0, /* call 0x0 */
  1474. 0x5b, /* popl %ebx */
  1475. };
  1476. struct i386_frame_cache cache;
  1477. CORE_ADDR pc;
  1478. gdb_byte op;
  1479. int i;
  1480. CORE_ADDR func_addr;
  1481. if (find_pc_partial_function (start_pc, NULL, &func_addr, NULL))
  1482. {
  1483. CORE_ADDR post_prologue_pc
  1484. = skip_prologue_using_sal (gdbarch, func_addr);
  1485. struct compunit_symtab *cust = find_pc_compunit_symtab (func_addr);
  1486. /* LLVM backend (Clang/Flang) always emits a line note before the
  1487. prologue and another one after. We trust clang and newer Intel
  1488. compilers to emit usable line notes. */
  1489. if (post_prologue_pc
  1490. && (cust != NULL
  1491. && cust->producer () != NULL
  1492. && (producer_is_llvm (cust->producer ())
  1493. || producer_is_icc_ge_19 (cust->producer ()))))
  1494. return std::max (start_pc, post_prologue_pc);
  1495. }
  1496. cache.locals = -1;
  1497. pc = i386_analyze_prologue (gdbarch, start_pc, 0xffffffff, &cache);
  1498. if (cache.locals < 0)
  1499. return start_pc;
  1500. /* Found valid frame setup. */
  1501. /* The native cc on SVR4 in -K PIC mode inserts the following code
  1502. to get the address of the global offset table (GOT) into register
  1503. %ebx:
  1504. call 0x0
  1505. popl %ebx
  1506. movl %ebx,x(%ebp) (optional)
  1507. addl y,%ebx
  1508. This code is with the rest of the prologue (at the end of the
  1509. function), so we have to skip it to get to the first real
  1510. instruction at the start of the function. */
  1511. for (i = 0; i < 6; i++)
  1512. {
  1513. if (target_read_code (pc + i, &op, 1))
  1514. return pc;
  1515. if (pic_pat[i] != op)
  1516. break;
  1517. }
  1518. if (i == 6)
  1519. {
  1520. int delta = 6;
  1521. if (target_read_code (pc + delta, &op, 1))
  1522. return pc;
  1523. if (op == 0x89) /* movl %ebx, x(%ebp) */
  1524. {
  1525. op = read_code_unsigned_integer (pc + delta + 1, 1, byte_order);
  1526. if (op == 0x5d) /* One byte offset from %ebp. */
  1527. delta += 3;
  1528. else if (op == 0x9d) /* Four byte offset from %ebp. */
  1529. delta += 6;
  1530. else /* Unexpected instruction. */
  1531. delta = 0;
  1532. if (target_read_code (pc + delta, &op, 1))
  1533. return pc;
  1534. }
  1535. /* addl y,%ebx */
  1536. if (delta > 0 && op == 0x81
  1537. && read_code_unsigned_integer (pc + delta + 1, 1, byte_order)
  1538. == 0xc3)
  1539. {
  1540. pc += delta + 6;
  1541. }
  1542. }
  1543. /* If the function starts with a branch (to startup code at the end)
  1544. the last instruction should bring us back to the first
  1545. instruction of the real code. */
  1546. if (i386_follow_jump (gdbarch, start_pc) != start_pc)
  1547. pc = i386_follow_jump (gdbarch, pc);
  1548. return pc;
  1549. }
  1550. /* Check that the code pointed to by PC corresponds to a call to
  1551. __main, skip it if so. Return PC otherwise. */
  1552. CORE_ADDR
  1553. i386_skip_main_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
  1554. {
  1555. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1556. gdb_byte op;
  1557. if (target_read_code (pc, &op, 1))
  1558. return pc;
  1559. if (op == 0xe8)
  1560. {
  1561. gdb_byte buf[4];
  1562. if (target_read_code (pc + 1, buf, sizeof buf) == 0)
  1563. {
  1564. /* Make sure address is computed correctly as a 32bit
  1565. integer even if CORE_ADDR is 64 bit wide. */
  1566. struct bound_minimal_symbol s;
  1567. CORE_ADDR call_dest;
  1568. call_dest = pc + 5 + extract_signed_integer (buf, 4, byte_order);
  1569. call_dest = call_dest & 0xffffffffU;
  1570. s = lookup_minimal_symbol_by_pc (call_dest);
  1571. if (s.minsym != NULL
  1572. && s.minsym->linkage_name () != NULL
  1573. && strcmp (s.minsym->linkage_name (), "__main") == 0)
  1574. pc += 5;
  1575. }
  1576. }
  1577. return pc;
  1578. }
  1579. /* This function is 64-bit safe. */
  1580. static CORE_ADDR
  1581. i386_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
  1582. {
  1583. gdb_byte buf[8];
  1584. frame_unwind_register (next_frame, gdbarch_pc_regnum (gdbarch), buf);
  1585. return extract_typed_address (buf, builtin_type (gdbarch)->builtin_func_ptr);
  1586. }
  1587. /* Normal frames. */
  1588. static void
  1589. i386_frame_cache_1 (struct frame_info *this_frame,
  1590. struct i386_frame_cache *cache)
  1591. {
  1592. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  1593. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1594. gdb_byte buf[4];
  1595. int i;
  1596. cache->pc = get_frame_func (this_frame);
  1597. /* In principle, for normal frames, %ebp holds the frame pointer,
  1598. which holds the base address for the current stack frame.
  1599. However, for functions that don't need it, the frame pointer is
  1600. optional. For these "frameless" functions the frame pointer is
  1601. actually the frame pointer of the calling frame. Signal
  1602. trampolines are just a special case of a "frameless" function.
  1603. They (usually) share their frame pointer with the frame that was
  1604. in progress when the signal occurred. */
  1605. get_frame_register (this_frame, I386_EBP_REGNUM, buf);
  1606. cache->base = extract_unsigned_integer (buf, 4, byte_order);
  1607. if (cache->base == 0)
  1608. {
  1609. cache->base_p = 1;
  1610. return;
  1611. }
  1612. /* For normal frames, %eip is stored at 4(%ebp). */
  1613. cache->saved_regs[I386_EIP_REGNUM] = 4;
  1614. if (cache->pc != 0)
  1615. i386_analyze_prologue (gdbarch, cache->pc, get_frame_pc (this_frame),
  1616. cache);
  1617. if (cache->locals < 0)
  1618. {
  1619. /* We didn't find a valid frame, which means that CACHE->base
  1620. currently holds the frame pointer for our calling frame. If
  1621. we're at the start of a function, or somewhere half-way its
  1622. prologue, the function's frame probably hasn't been fully
  1623. setup yet. Try to reconstruct the base address for the stack
  1624. frame by looking at the stack pointer. For truly "frameless"
  1625. functions this might work too. */
  1626. if (cache->saved_sp_reg != -1)
  1627. {
  1628. /* Saved stack pointer has been saved. */
  1629. get_frame_register (this_frame, cache->saved_sp_reg, buf);
  1630. cache->saved_sp = extract_unsigned_integer (buf, 4, byte_order);
  1631. /* We're halfway aligning the stack. */
  1632. cache->base = ((cache->saved_sp - 4) & 0xfffffff0) - 4;
  1633. cache->saved_regs[I386_EIP_REGNUM] = cache->saved_sp - 4;
  1634. /* This will be added back below. */
  1635. cache->saved_regs[I386_EIP_REGNUM] -= cache->base;
  1636. }
  1637. else if (cache->pc != 0
  1638. || target_read_code (get_frame_pc (this_frame), buf, 1))
  1639. {
  1640. /* We're in a known function, but did not find a frame
  1641. setup. Assume that the function does not use %ebp.
  1642. Alternatively, we may have jumped to an invalid
  1643. address; in that case there is definitely no new
  1644. frame in %ebp. */
  1645. get_frame_register (this_frame, I386_ESP_REGNUM, buf);
  1646. cache->base = extract_unsigned_integer (buf, 4, byte_order)
  1647. + cache->sp_offset;
  1648. }
  1649. else
  1650. /* We're in an unknown function. We could not find the start
  1651. of the function to analyze the prologue; our best option is
  1652. to assume a typical frame layout with the caller's %ebp
  1653. saved. */
  1654. cache->saved_regs[I386_EBP_REGNUM] = 0;
  1655. }
  1656. if (cache->saved_sp_reg != -1)
  1657. {
  1658. /* Saved stack pointer has been saved (but the SAVED_SP_REG
  1659. register may be unavailable). */
  1660. if (cache->saved_sp == 0
  1661. && deprecated_frame_register_read (this_frame,
  1662. cache->saved_sp_reg, buf))
  1663. cache->saved_sp = extract_unsigned_integer (buf, 4, byte_order);
  1664. }
  1665. /* Now that we have the base address for the stack frame we can
  1666. calculate the value of %esp in the calling frame. */
  1667. else if (cache->saved_sp == 0)
  1668. cache->saved_sp = cache->base + 8;
  1669. /* Adjust all the saved registers such that they contain addresses
  1670. instead of offsets. */
  1671. for (i = 0; i < I386_NUM_SAVED_REGS; i++)
  1672. if (cache->saved_regs[i] != -1)
  1673. cache->saved_regs[i] += cache->base;
  1674. cache->base_p = 1;
  1675. }
  1676. static struct i386_frame_cache *
  1677. i386_frame_cache (struct frame_info *this_frame, void **this_cache)
  1678. {
  1679. struct i386_frame_cache *cache;
  1680. if (*this_cache)
  1681. return (struct i386_frame_cache *) *this_cache;
  1682. cache = i386_alloc_frame_cache ();
  1683. *this_cache = cache;
  1684. try
  1685. {
  1686. i386_frame_cache_1 (this_frame, cache);
  1687. }
  1688. catch (const gdb_exception_error &ex)
  1689. {
  1690. if (ex.error != NOT_AVAILABLE_ERROR)
  1691. throw;
  1692. }
  1693. return cache;
  1694. }
  1695. static void
  1696. i386_frame_this_id (struct frame_info *this_frame, void **this_cache,
  1697. struct frame_id *this_id)
  1698. {
  1699. struct i386_frame_cache *cache = i386_frame_cache (this_frame, this_cache);
  1700. if (!cache->base_p)
  1701. (*this_id) = frame_id_build_unavailable_stack (cache->pc);
  1702. else if (cache->base == 0)
  1703. {
  1704. /* This marks the outermost frame. */
  1705. }
  1706. else
  1707. {
  1708. /* See the end of i386_push_dummy_call. */
  1709. (*this_id) = frame_id_build (cache->base + 8, cache->pc);
  1710. }
  1711. }
  1712. static enum unwind_stop_reason
  1713. i386_frame_unwind_stop_reason (struct frame_info *this_frame,
  1714. void **this_cache)
  1715. {
  1716. struct i386_frame_cache *cache = i386_frame_cache (this_frame, this_cache);
  1717. if (!cache->base_p)
  1718. return UNWIND_UNAVAILABLE;
  1719. /* This marks the outermost frame. */
  1720. if (cache->base == 0)
  1721. return UNWIND_OUTERMOST;
  1722. return UNWIND_NO_REASON;
  1723. }
  1724. static struct value *
  1725. i386_frame_prev_register (struct frame_info *this_frame, void **this_cache,
  1726. int regnum)
  1727. {
  1728. struct i386_frame_cache *cache = i386_frame_cache (this_frame, this_cache);
  1729. gdb_assert (regnum >= 0);
  1730. /* The System V ABI says that:
  1731. "The flags register contains the system flags, such as the
  1732. direction flag and the carry flag. The direction flag must be
  1733. set to the forward (that is, zero) direction before entry and
  1734. upon exit from a function. Other user flags have no specified
  1735. role in the standard calling sequence and are not preserved."
  1736. To guarantee the "upon exit" part of that statement we fake a
  1737. saved flags register that has its direction flag cleared.
  1738. Note that GCC doesn't seem to rely on the fact that the direction
  1739. flag is cleared after a function return; it always explicitly
  1740. clears the flag before operations where it matters.
  1741. FIXME: kettenis/20030316: I'm not quite sure whether this is the
  1742. right thing to do. The way we fake the flags register here makes
  1743. it impossible to change it. */
  1744. if (regnum == I386_EFLAGS_REGNUM)
  1745. {
  1746. ULONGEST val;
  1747. val = get_frame_register_unsigned (this_frame, regnum);
  1748. val &= ~(1 << 10);
  1749. return frame_unwind_got_constant (this_frame, regnum, val);
  1750. }
  1751. if (regnum == I386_EIP_REGNUM && cache->pc_in_eax)
  1752. return frame_unwind_got_register (this_frame, regnum, I386_EAX_REGNUM);
  1753. if (regnum == I386_ESP_REGNUM
  1754. && (cache->saved_sp != 0 || cache->saved_sp_reg != -1))
  1755. {
  1756. /* If the SP has been saved, but we don't know where, then this
  1757. means that SAVED_SP_REG register was found unavailable back
  1758. when we built the cache. */
  1759. if (cache->saved_sp == 0)
  1760. return frame_unwind_got_register (this_frame, regnum,
  1761. cache->saved_sp_reg);
  1762. else
  1763. return frame_unwind_got_constant (this_frame, regnum,
  1764. cache->saved_sp);
  1765. }
  1766. if (regnum < I386_NUM_SAVED_REGS && cache->saved_regs[regnum] != -1)
  1767. return frame_unwind_got_memory (this_frame, regnum,
  1768. cache->saved_regs[regnum]);
  1769. return frame_unwind_got_register (this_frame, regnum, regnum);
  1770. }
  1771. static const struct frame_unwind i386_frame_unwind =
  1772. {
  1773. "i386 prologue",
  1774. NORMAL_FRAME,
  1775. i386_frame_unwind_stop_reason,
  1776. i386_frame_this_id,
  1777. i386_frame_prev_register,
  1778. NULL,
  1779. default_frame_sniffer
  1780. };
  1781. /* Normal frames, but in a function epilogue. */
  1782. /* Implement the stack_frame_destroyed_p gdbarch method.
  1783. The epilogue is defined here as the 'ret' instruction, which will
  1784. follow any instruction such as 'leave' or 'pop %ebp' that destroys
  1785. the function's stack frame. */
  1786. static int
  1787. i386_stack_frame_destroyed_p (struct gdbarch *gdbarch, CORE_ADDR pc)
  1788. {
  1789. gdb_byte insn;
  1790. struct compunit_symtab *cust;
  1791. cust = find_pc_compunit_symtab (pc);
  1792. if (cust != NULL && cust->epilogue_unwind_valid ())
  1793. return 0;
  1794. if (target_read_memory (pc, &insn, 1))
  1795. return 0; /* Can't read memory at pc. */
  1796. if (insn != 0xc3) /* 'ret' instruction. */
  1797. return 0;
  1798. return 1;
  1799. }
  1800. static int
  1801. i386_epilogue_frame_sniffer (const struct frame_unwind *self,
  1802. struct frame_info *this_frame,
  1803. void **this_prologue_cache)
  1804. {
  1805. if (frame_relative_level (this_frame) == 0)
  1806. return i386_stack_frame_destroyed_p (get_frame_arch (this_frame),
  1807. get_frame_pc (this_frame));
  1808. else
  1809. return 0;
  1810. }
  1811. static struct i386_frame_cache *
  1812. i386_epilogue_frame_cache (struct frame_info *this_frame, void **this_cache)
  1813. {
  1814. struct i386_frame_cache *cache;
  1815. CORE_ADDR sp;
  1816. if (*this_cache)
  1817. return (struct i386_frame_cache *) *this_cache;
  1818. cache = i386_alloc_frame_cache ();
  1819. *this_cache = cache;
  1820. try
  1821. {
  1822. cache->pc = get_frame_func (this_frame);
  1823. /* At this point the stack looks as if we just entered the
  1824. function, with the return address at the top of the
  1825. stack. */
  1826. sp = get_frame_register_unsigned (this_frame, I386_ESP_REGNUM);
  1827. cache->base = sp + cache->sp_offset;
  1828. cache->saved_sp = cache->base + 8;
  1829. cache->saved_regs[I386_EIP_REGNUM] = cache->base + 4;
  1830. cache->base_p = 1;
  1831. }
  1832. catch (const gdb_exception_error &ex)
  1833. {
  1834. if (ex.error != NOT_AVAILABLE_ERROR)
  1835. throw;
  1836. }
  1837. return cache;
  1838. }
  1839. static enum unwind_stop_reason
  1840. i386_epilogue_frame_unwind_stop_reason (struct frame_info *this_frame,
  1841. void **this_cache)
  1842. {
  1843. struct i386_frame_cache *cache =
  1844. i386_epilogue_frame_cache (this_frame, this_cache);
  1845. if (!cache->base_p)
  1846. return UNWIND_UNAVAILABLE;
  1847. return UNWIND_NO_REASON;
  1848. }
  1849. static void
  1850. i386_epilogue_frame_this_id (struct frame_info *this_frame,
  1851. void **this_cache,
  1852. struct frame_id *this_id)
  1853. {
  1854. struct i386_frame_cache *cache =
  1855. i386_epilogue_frame_cache (this_frame, this_cache);
  1856. if (!cache->base_p)
  1857. (*this_id) = frame_id_build_unavailable_stack (cache->pc);
  1858. else
  1859. (*this_id) = frame_id_build (cache->base + 8, cache->pc);
  1860. }
  1861. static struct value *
  1862. i386_epilogue_frame_prev_register (struct frame_info *this_frame,
  1863. void **this_cache, int regnum)
  1864. {
  1865. /* Make sure we've initialized the cache. */
  1866. i386_epilogue_frame_cache (this_frame, this_cache);
  1867. return i386_frame_prev_register (this_frame, this_cache, regnum);
  1868. }
  1869. static const struct frame_unwind i386_epilogue_frame_unwind =
  1870. {
  1871. "i386 epilogue",
  1872. NORMAL_FRAME,
  1873. i386_epilogue_frame_unwind_stop_reason,
  1874. i386_epilogue_frame_this_id,
  1875. i386_epilogue_frame_prev_register,
  1876. NULL,
  1877. i386_epilogue_frame_sniffer
  1878. };
  1879. /* Stack-based trampolines. */
  1880. /* These trampolines are used on cross x86 targets, when taking the
  1881. address of a nested function. When executing these trampolines,
  1882. no stack frame is set up, so we are in a similar situation as in
  1883. epilogues and i386_epilogue_frame_this_id can be re-used. */
  1884. /* Static chain passed in register. */
  1885. static i386_insn i386_tramp_chain_in_reg_insns[] =
  1886. {
  1887. /* `movl imm32, %eax' and `movl imm32, %ecx' */
  1888. { 5, { 0xb8 }, { 0xfe } },
  1889. /* `jmp imm32' */
  1890. { 5, { 0xe9 }, { 0xff } },
  1891. {0}
  1892. };
  1893. /* Static chain passed on stack (when regparm=3). */
  1894. static i386_insn i386_tramp_chain_on_stack_insns[] =
  1895. {
  1896. /* `push imm32' */
  1897. { 5, { 0x68 }, { 0xff } },
  1898. /* `jmp imm32' */
  1899. { 5, { 0xe9 }, { 0xff } },
  1900. {0}
  1901. };
  1902. /* Return whether PC points inside a stack trampoline. */
  1903. static int
  1904. i386_in_stack_tramp_p (CORE_ADDR pc)
  1905. {
  1906. gdb_byte insn;
  1907. const char *name;
  1908. /* A stack trampoline is detected if no name is associated
  1909. to the current pc and if it points inside a trampoline
  1910. sequence. */
  1911. find_pc_partial_function (pc, &name, NULL, NULL);
  1912. if (name)
  1913. return 0;
  1914. if (target_read_memory (pc, &insn, 1))
  1915. return 0;
  1916. if (!i386_match_insn_block (pc, i386_tramp_chain_in_reg_insns)
  1917. && !i386_match_insn_block (pc, i386_tramp_chain_on_stack_insns))
  1918. return 0;
  1919. return 1;
  1920. }
  1921. static int
  1922. i386_stack_tramp_frame_sniffer (const struct frame_unwind *self,
  1923. struct frame_info *this_frame,
  1924. void **this_cache)
  1925. {
  1926. if (frame_relative_level (this_frame) == 0)
  1927. return i386_in_stack_tramp_p (get_frame_pc (this_frame));
  1928. else
  1929. return 0;
  1930. }
  1931. static const struct frame_unwind i386_stack_tramp_frame_unwind =
  1932. {
  1933. "i386 stack tramp",
  1934. NORMAL_FRAME,
  1935. i386_epilogue_frame_unwind_stop_reason,
  1936. i386_epilogue_frame_this_id,
  1937. i386_epilogue_frame_prev_register,
  1938. NULL,
  1939. i386_stack_tramp_frame_sniffer
  1940. };
  1941. /* Generate a bytecode expression to get the value of the saved PC. */
  1942. static void
  1943. i386_gen_return_address (struct gdbarch *gdbarch,
  1944. struct agent_expr *ax, struct axs_value *value,
  1945. CORE_ADDR scope)
  1946. {
  1947. /* The following sequence assumes the traditional use of the base
  1948. register. */
  1949. ax_reg (ax, I386_EBP_REGNUM);
  1950. ax_const_l (ax, 4);
  1951. ax_simple (ax, aop_add);
  1952. value->type = register_type (gdbarch, I386_EIP_REGNUM);
  1953. value->kind = axs_lvalue_memory;
  1954. }
  1955. /* Signal trampolines. */
  1956. static struct i386_frame_cache *
  1957. i386_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
  1958. {
  1959. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  1960. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  1961. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1962. struct i386_frame_cache *cache;
  1963. CORE_ADDR addr;
  1964. gdb_byte buf[4];
  1965. if (*this_cache)
  1966. return (struct i386_frame_cache *) *this_cache;
  1967. cache = i386_alloc_frame_cache ();
  1968. try
  1969. {
  1970. get_frame_register (this_frame, I386_ESP_REGNUM, buf);
  1971. cache->base = extract_unsigned_integer (buf, 4, byte_order) - 4;
  1972. addr = tdep->sigcontext_addr (this_frame);
  1973. if (tdep->sc_reg_offset)
  1974. {
  1975. int i;
  1976. gdb_assert (tdep->sc_num_regs <= I386_NUM_SAVED_REGS);
  1977. for (i = 0; i < tdep->sc_num_regs; i++)
  1978. if (tdep->sc_reg_offset[i] != -1)
  1979. cache->saved_regs[i] = addr + tdep->sc_reg_offset[i];
  1980. }
  1981. else
  1982. {
  1983. cache->saved_regs[I386_EIP_REGNUM] = addr + tdep->sc_pc_offset;
  1984. cache->saved_regs[I386_ESP_REGNUM] = addr + tdep->sc_sp_offset;
  1985. }
  1986. cache->base_p = 1;
  1987. }
  1988. catch (const gdb_exception_error &ex)
  1989. {
  1990. if (ex.error != NOT_AVAILABLE_ERROR)
  1991. throw;
  1992. }
  1993. *this_cache = cache;
  1994. return cache;
  1995. }
  1996. static enum unwind_stop_reason
  1997. i386_sigtramp_frame_unwind_stop_reason (struct frame_info *this_frame,
  1998. void **this_cache)
  1999. {
  2000. struct i386_frame_cache *cache =
  2001. i386_sigtramp_frame_cache (this_frame, this_cache);
  2002. if (!cache->base_p)
  2003. return UNWIND_UNAVAILABLE;
  2004. return UNWIND_NO_REASON;
  2005. }
  2006. static void
  2007. i386_sigtramp_frame_this_id (struct frame_info *this_frame, void **this_cache,
  2008. struct frame_id *this_id)
  2009. {
  2010. struct i386_frame_cache *cache =
  2011. i386_sigtramp_frame_cache (this_frame, this_cache);
  2012. if (!cache->base_p)
  2013. (*this_id) = frame_id_build_unavailable_stack (get_frame_pc (this_frame));
  2014. else
  2015. {
  2016. /* See the end of i386_push_dummy_call. */
  2017. (*this_id) = frame_id_build (cache->base + 8, get_frame_pc (this_frame));
  2018. }
  2019. }
  2020. static struct value *
  2021. i386_sigtramp_frame_prev_register (struct frame_info *this_frame,
  2022. void **this_cache, int regnum)
  2023. {
  2024. /* Make sure we've initialized the cache. */
  2025. i386_sigtramp_frame_cache (this_frame, this_cache);
  2026. return i386_frame_prev_register (this_frame, this_cache, regnum);
  2027. }
  2028. static int
  2029. i386_sigtramp_frame_sniffer (const struct frame_unwind *self,
  2030. struct frame_info *this_frame,
  2031. void **this_prologue_cache)
  2032. {
  2033. gdbarch *arch = get_frame_arch (this_frame);
  2034. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
  2035. /* We shouldn't even bother if we don't have a sigcontext_addr
  2036. handler. */
  2037. if (tdep->sigcontext_addr == NULL)
  2038. return 0;
  2039. if (tdep->sigtramp_p != NULL)
  2040. {
  2041. if (tdep->sigtramp_p (this_frame))
  2042. return 1;
  2043. }
  2044. if (tdep->sigtramp_start != 0)
  2045. {
  2046. CORE_ADDR pc = get_frame_pc (this_frame);
  2047. gdb_assert (tdep->sigtramp_end != 0);
  2048. if (pc >= tdep->sigtramp_start && pc < tdep->sigtramp_end)
  2049. return 1;
  2050. }
  2051. return 0;
  2052. }
  2053. static const struct frame_unwind i386_sigtramp_frame_unwind =
  2054. {
  2055. "i386 sigtramp",
  2056. SIGTRAMP_FRAME,
  2057. i386_sigtramp_frame_unwind_stop_reason,
  2058. i386_sigtramp_frame_this_id,
  2059. i386_sigtramp_frame_prev_register,
  2060. NULL,
  2061. i386_sigtramp_frame_sniffer
  2062. };
  2063. static CORE_ADDR
  2064. i386_frame_base_address (struct frame_info *this_frame, void **this_cache)
  2065. {
  2066. struct i386_frame_cache *cache = i386_frame_cache (this_frame, this_cache);
  2067. return cache->base;
  2068. }
  2069. static const struct frame_base i386_frame_base =
  2070. {
  2071. &i386_frame_unwind,
  2072. i386_frame_base_address,
  2073. i386_frame_base_address,
  2074. i386_frame_base_address
  2075. };
  2076. static struct frame_id
  2077. i386_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
  2078. {
  2079. CORE_ADDR fp;
  2080. fp = get_frame_register_unsigned (this_frame, I386_EBP_REGNUM);
  2081. /* See the end of i386_push_dummy_call. */
  2082. return frame_id_build (fp + 8, get_frame_pc (this_frame));
  2083. }
  2084. /* _Decimal128 function return values need 16-byte alignment on the
  2085. stack. */
  2086. static CORE_ADDR
  2087. i386_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
  2088. {
  2089. return sp & -(CORE_ADDR)16;
  2090. }
  2091. /* Figure out where the longjmp will land. Slurp the args out of the
  2092. stack. We expect the first arg to be a pointer to the jmp_buf
  2093. structure from which we extract the address that we will land at.
  2094. This address is copied into PC. This routine returns non-zero on
  2095. success. */
  2096. static int
  2097. i386_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
  2098. {
  2099. gdb_byte buf[4];
  2100. CORE_ADDR sp, jb_addr;
  2101. struct gdbarch *gdbarch = get_frame_arch (frame);
  2102. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  2103. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  2104. int jb_pc_offset = tdep->jb_pc_offset;
  2105. /* If JB_PC_OFFSET is -1, we have no way to find out where the
  2106. longjmp will land. */
  2107. if (jb_pc_offset == -1)
  2108. return 0;
  2109. get_frame_register (frame, I386_ESP_REGNUM, buf);
  2110. sp = extract_unsigned_integer (buf, 4, byte_order);
  2111. if (target_read_memory (sp + 4, buf, 4))
  2112. return 0;
  2113. jb_addr = extract_unsigned_integer (buf, 4, byte_order);
  2114. if (target_read_memory (jb_addr + jb_pc_offset, buf, 4))
  2115. return 0;
  2116. *pc = extract_unsigned_integer (buf, 4, byte_order);
  2117. return 1;
  2118. }
  2119. /* Check whether TYPE must be 16-byte-aligned when passed as a
  2120. function argument. 16-byte vectors, _Decimal128 and structures or
  2121. unions containing such types must be 16-byte-aligned; other
  2122. arguments are 4-byte-aligned. */
  2123. static int
  2124. i386_16_byte_align_p (struct type *type)
  2125. {
  2126. type = check_typedef (type);
  2127. if ((type->code () == TYPE_CODE_DECFLOAT
  2128. || (type->code () == TYPE_CODE_ARRAY && type->is_vector ()))
  2129. && TYPE_LENGTH (type) == 16)
  2130. return 1;
  2131. if (type->code () == TYPE_CODE_ARRAY)
  2132. return i386_16_byte_align_p (TYPE_TARGET_TYPE (type));
  2133. if (type->code () == TYPE_CODE_STRUCT
  2134. || type->code () == TYPE_CODE_UNION)
  2135. {
  2136. int i;
  2137. for (i = 0; i < type->num_fields (); i++)
  2138. {
  2139. if (field_is_static (&type->field (i)))
  2140. continue;
  2141. if (i386_16_byte_align_p (type->field (i).type ()))
  2142. return 1;
  2143. }
  2144. }
  2145. return 0;
  2146. }
  2147. /* Implementation for set_gdbarch_push_dummy_code. */
  2148. static CORE_ADDR
  2149. i386_push_dummy_code (struct gdbarch *gdbarch, CORE_ADDR sp, CORE_ADDR funaddr,
  2150. struct value **args, int nargs, struct type *value_type,
  2151. CORE_ADDR *real_pc, CORE_ADDR *bp_addr,
  2152. struct regcache *regcache)
  2153. {
  2154. /* Use 0xcc breakpoint - 1 byte. */
  2155. *bp_addr = sp - 1;
  2156. *real_pc = funaddr;
  2157. /* Keep the stack aligned. */
  2158. return sp - 16;
  2159. }
  2160. /* The "push_dummy_call" gdbarch method, optionally with the thiscall
  2161. calling convention. */
  2162. CORE_ADDR
  2163. i386_thiscall_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
  2164. struct regcache *regcache, CORE_ADDR bp_addr,
  2165. int nargs, struct value **args, CORE_ADDR sp,
  2166. function_call_return_method return_method,
  2167. CORE_ADDR struct_addr, bool thiscall)
  2168. {
  2169. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  2170. gdb_byte buf[4];
  2171. int i;
  2172. int write_pass;
  2173. int args_space = 0;
  2174. /* BND registers can be in arbitrary values at the moment of the
  2175. inferior call. This can cause boundary violations that are not
  2176. due to a real bug or even desired by the user. The best to be done
  2177. is set the BND registers to allow access to the whole memory, INIT
  2178. state, before pushing the inferior call. */
  2179. i387_reset_bnd_regs (gdbarch, regcache);
  2180. /* Determine the total space required for arguments and struct
  2181. return address in a first pass (allowing for 16-byte-aligned
  2182. arguments), then push arguments in a second pass. */
  2183. for (write_pass = 0; write_pass < 2; write_pass++)
  2184. {
  2185. int args_space_used = 0;
  2186. if (return_method == return_method_struct)
  2187. {
  2188. if (write_pass)
  2189. {
  2190. /* Push value address. */
  2191. store_unsigned_integer (buf, 4, byte_order, struct_addr);
  2192. write_memory (sp, buf, 4);
  2193. args_space_used += 4;
  2194. }
  2195. else
  2196. args_space += 4;
  2197. }
  2198. for (i = thiscall ? 1 : 0; i < nargs; i++)
  2199. {
  2200. int len = TYPE_LENGTH (value_enclosing_type (args[i]));
  2201. if (write_pass)
  2202. {
  2203. if (i386_16_byte_align_p (value_enclosing_type (args[i])))
  2204. args_space_used = align_up (args_space_used, 16);
  2205. write_memory (sp + args_space_used,
  2206. value_contents_all (args[i]).data (), len);
  2207. /* The System V ABI says that:
  2208. "An argument's size is increased, if necessary, to make it a
  2209. multiple of [32-bit] words. This may require tail padding,
  2210. depending on the size of the argument."
  2211. This makes sure the stack stays word-aligned. */
  2212. args_space_used += align_up (len, 4);
  2213. }
  2214. else
  2215. {
  2216. if (i386_16_byte_align_p (value_enclosing_type (args[i])))
  2217. args_space = align_up (args_space, 16);
  2218. args_space += align_up (len, 4);
  2219. }
  2220. }
  2221. if (!write_pass)
  2222. {
  2223. sp -= args_space;
  2224. /* The original System V ABI only requires word alignment,
  2225. but modern incarnations need 16-byte alignment in order
  2226. to support SSE. Since wasting a few bytes here isn't
  2227. harmful we unconditionally enforce 16-byte alignment. */
  2228. sp &= ~0xf;
  2229. }
  2230. }
  2231. /* Store return address. */
  2232. sp -= 4;
  2233. store_unsigned_integer (buf, 4, byte_order, bp_addr);
  2234. write_memory (sp, buf, 4);
  2235. /* Finally, update the stack pointer... */
  2236. store_unsigned_integer (buf, 4, byte_order, sp);
  2237. regcache->cooked_write (I386_ESP_REGNUM, buf);
  2238. /* ...and fake a frame pointer. */
  2239. regcache->cooked_write (I386_EBP_REGNUM, buf);
  2240. /* The 'this' pointer needs to be in ECX. */
  2241. if (thiscall)
  2242. regcache->cooked_write (I386_ECX_REGNUM,
  2243. value_contents_all (args[0]).data ());
  2244. /* If the PLT is position-independent, the SYSTEM V ABI requires %ebx to be
  2245. set to the address of the GOT when doing a call to a PLT address.
  2246. Note that we do not try to determine whether the PLT is
  2247. position-independent, we just set the register regardless. */
  2248. CORE_ADDR func_addr = find_function_addr (function, nullptr, nullptr);
  2249. if (in_plt_section (func_addr))
  2250. {
  2251. struct objfile *objf = nullptr;
  2252. asection *asect = nullptr;
  2253. obj_section *osect = nullptr;
  2254. /* Get object file containing func_addr. */
  2255. obj_section *func_section = find_pc_section (func_addr);
  2256. if (func_section != nullptr)
  2257. objf = func_section->objfile;
  2258. if (objf != nullptr)
  2259. {
  2260. /* Get corresponding .got.plt or .got section. */
  2261. asect = bfd_get_section_by_name (objf->obfd, ".got.plt");
  2262. if (asect == nullptr)
  2263. asect = bfd_get_section_by_name (objf->obfd, ".got");
  2264. }
  2265. if (asect != nullptr)
  2266. /* Translate asection to obj_section. */
  2267. osect = maint_obj_section_from_bfd_section (objf->obfd, asect, objf);
  2268. if (osect != nullptr)
  2269. {
  2270. /* Store the section address in %ebx. */
  2271. store_unsigned_integer (buf, 4, byte_order, osect->addr ());
  2272. regcache->cooked_write (I386_EBX_REGNUM, buf);
  2273. }
  2274. else
  2275. {
  2276. /* If we would only do this for a position-independent PLT, it would
  2277. make sense to issue a warning here. */
  2278. }
  2279. }
  2280. /* MarkK wrote: This "+ 8" is all over the place:
  2281. (i386_frame_this_id, i386_sigtramp_frame_this_id,
  2282. i386_dummy_id). It's there, since all frame unwinders for
  2283. a given target have to agree (within a certain margin) on the
  2284. definition of the stack address of a frame. Otherwise frame id
  2285. comparison might not work correctly. Since DWARF2/GCC uses the
  2286. stack address *before* the function call as a frame's CFA. On
  2287. the i386, when %ebp is used as a frame pointer, the offset
  2288. between the contents %ebp and the CFA as defined by GCC. */
  2289. return sp + 8;
  2290. }
  2291. /* Implement the "push_dummy_call" gdbarch method. */
  2292. static CORE_ADDR
  2293. i386_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
  2294. struct regcache *regcache, CORE_ADDR bp_addr, int nargs,
  2295. struct value **args, CORE_ADDR sp,
  2296. function_call_return_method return_method,
  2297. CORE_ADDR struct_addr)
  2298. {
  2299. return i386_thiscall_push_dummy_call (gdbarch, function, regcache, bp_addr,
  2300. nargs, args, sp, return_method,
  2301. struct_addr, false);
  2302. }
  2303. /* These registers are used for returning integers (and on some
  2304. targets also for returning `struct' and `union' values when their
  2305. size and alignment match an integer type). */
  2306. #define LOW_RETURN_REGNUM I386_EAX_REGNUM /* %eax */
  2307. #define HIGH_RETURN_REGNUM I386_EDX_REGNUM /* %edx */
  2308. /* Read, for architecture GDBARCH, a function return value of TYPE
  2309. from REGCACHE, and copy that into VALBUF. */
  2310. static void
  2311. i386_extract_return_value (struct gdbarch *gdbarch, struct type *type,
  2312. struct regcache *regcache, gdb_byte *valbuf)
  2313. {
  2314. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  2315. int len = TYPE_LENGTH (type);
  2316. gdb_byte buf[I386_MAX_REGISTER_SIZE];
  2317. /* _Float16 and _Float16 _Complex values are returned via xmm0. */
  2318. if (((type->code () == TYPE_CODE_FLT) && len == 2)
  2319. || ((type->code () == TYPE_CODE_COMPLEX) && len == 4))
  2320. {
  2321. regcache->raw_read (I387_XMM0_REGNUM (tdep), valbuf);
  2322. return;
  2323. }
  2324. else if (type->code () == TYPE_CODE_FLT)
  2325. {
  2326. if (tdep->st0_regnum < 0)
  2327. {
  2328. warning (_("Cannot find floating-point return value."));
  2329. memset (valbuf, 0, len);
  2330. return;
  2331. }
  2332. /* Floating-point return values can be found in %st(0). Convert
  2333. its contents to the desired type. This is probably not
  2334. exactly how it would happen on the target itself, but it is
  2335. the best we can do. */
  2336. regcache->raw_read (I386_ST0_REGNUM, buf);
  2337. target_float_convert (buf, i387_ext_type (gdbarch), valbuf, type);
  2338. }
  2339. else
  2340. {
  2341. int low_size = register_size (gdbarch, LOW_RETURN_REGNUM);
  2342. int high_size = register_size (gdbarch, HIGH_RETURN_REGNUM);
  2343. if (len <= low_size)
  2344. {
  2345. regcache->raw_read (LOW_RETURN_REGNUM, buf);
  2346. memcpy (valbuf, buf, len);
  2347. }
  2348. else if (len <= (low_size + high_size))
  2349. {
  2350. regcache->raw_read (LOW_RETURN_REGNUM, buf);
  2351. memcpy (valbuf, buf, low_size);
  2352. regcache->raw_read (HIGH_RETURN_REGNUM, buf);
  2353. memcpy (valbuf + low_size, buf, len - low_size);
  2354. }
  2355. else
  2356. internal_error (__FILE__, __LINE__,
  2357. _("Cannot extract return value of %d bytes long."),
  2358. len);
  2359. }
  2360. }
  2361. /* Write, for architecture GDBARCH, a function return value of TYPE
  2362. from VALBUF into REGCACHE. */
  2363. static void
  2364. i386_store_return_value (struct gdbarch *gdbarch, struct type *type,
  2365. struct regcache *regcache, const gdb_byte *valbuf)
  2366. {
  2367. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  2368. int len = TYPE_LENGTH (type);
  2369. if (type->code () == TYPE_CODE_FLT)
  2370. {
  2371. ULONGEST fstat;
  2372. gdb_byte buf[I386_MAX_REGISTER_SIZE];
  2373. if (tdep->st0_regnum < 0)
  2374. {
  2375. warning (_("Cannot set floating-point return value."));
  2376. return;
  2377. }
  2378. /* Returning floating-point values is a bit tricky. Apart from
  2379. storing the return value in %st(0), we have to simulate the
  2380. state of the FPU at function return point. */
  2381. /* Convert the value found in VALBUF to the extended
  2382. floating-point format used by the FPU. This is probably
  2383. not exactly how it would happen on the target itself, but
  2384. it is the best we can do. */
  2385. target_float_convert (valbuf, type, buf, i387_ext_type (gdbarch));
  2386. regcache->raw_write (I386_ST0_REGNUM, buf);
  2387. /* Set the top of the floating-point register stack to 7. The
  2388. actual value doesn't really matter, but 7 is what a normal
  2389. function return would end up with if the program started out
  2390. with a freshly initialized FPU. */
  2391. regcache_raw_read_unsigned (regcache, I387_FSTAT_REGNUM (tdep), &fstat);
  2392. fstat |= (7 << 11);
  2393. regcache_raw_write_unsigned (regcache, I387_FSTAT_REGNUM (tdep), fstat);
  2394. /* Mark %st(1) through %st(7) as empty. Since we set the top of
  2395. the floating-point register stack to 7, the appropriate value
  2396. for the tag word is 0x3fff. */
  2397. regcache_raw_write_unsigned (regcache, I387_FTAG_REGNUM (tdep), 0x3fff);
  2398. }
  2399. else
  2400. {
  2401. int low_size = register_size (gdbarch, LOW_RETURN_REGNUM);
  2402. int high_size = register_size (gdbarch, HIGH_RETURN_REGNUM);
  2403. if (len <= low_size)
  2404. regcache->raw_write_part (LOW_RETURN_REGNUM, 0, len, valbuf);
  2405. else if (len <= (low_size + high_size))
  2406. {
  2407. regcache->raw_write (LOW_RETURN_REGNUM, valbuf);
  2408. regcache->raw_write_part (HIGH_RETURN_REGNUM, 0, len - low_size,
  2409. valbuf + low_size);
  2410. }
  2411. else
  2412. internal_error (__FILE__, __LINE__,
  2413. _("Cannot store return value of %d bytes long."), len);
  2414. }
  2415. }
  2416. /* This is the variable that is set with "set struct-convention", and
  2417. its legitimate values. */
  2418. static const char default_struct_convention[] = "default";
  2419. static const char pcc_struct_convention[] = "pcc";
  2420. static const char reg_struct_convention[] = "reg";
  2421. static const char *const valid_conventions[] =
  2422. {
  2423. default_struct_convention,
  2424. pcc_struct_convention,
  2425. reg_struct_convention,
  2426. NULL
  2427. };
  2428. static const char *struct_convention = default_struct_convention;
  2429. /* Return non-zero if TYPE, which is assumed to be a structure,
  2430. a union type, or an array type, should be returned in registers
  2431. for architecture GDBARCH. */
  2432. static int
  2433. i386_reg_struct_return_p (struct gdbarch *gdbarch, struct type *type)
  2434. {
  2435. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  2436. enum type_code code = type->code ();
  2437. int len = TYPE_LENGTH (type);
  2438. gdb_assert (code == TYPE_CODE_STRUCT
  2439. || code == TYPE_CODE_UNION
  2440. || code == TYPE_CODE_ARRAY);
  2441. if (struct_convention == pcc_struct_convention
  2442. || (struct_convention == default_struct_convention
  2443. && tdep->struct_return == pcc_struct_return))
  2444. return 0;
  2445. /* Structures consisting of a single `float', `double' or 'long
  2446. double' member are returned in %st(0). */
  2447. if (code == TYPE_CODE_STRUCT && type->num_fields () == 1)
  2448. {
  2449. type = check_typedef (type->field (0).type ());
  2450. if (type->code () == TYPE_CODE_FLT)
  2451. return (len == 4 || len == 8 || len == 12);
  2452. }
  2453. return (len == 1 || len == 2 || len == 4 || len == 8);
  2454. }
  2455. /* Determine, for architecture GDBARCH, how a return value of TYPE
  2456. should be returned. If it is supposed to be returned in registers,
  2457. and READBUF is non-zero, read the appropriate value from REGCACHE,
  2458. and copy it into READBUF. If WRITEBUF is non-zero, write the value
  2459. from WRITEBUF into REGCACHE. */
  2460. static enum return_value_convention
  2461. i386_return_value (struct gdbarch *gdbarch, struct value *function,
  2462. struct type *type, struct regcache *regcache,
  2463. gdb_byte *readbuf, const gdb_byte *writebuf)
  2464. {
  2465. enum type_code code = type->code ();
  2466. if (((code == TYPE_CODE_STRUCT
  2467. || code == TYPE_CODE_UNION
  2468. || code == TYPE_CODE_ARRAY)
  2469. && !i386_reg_struct_return_p (gdbarch, type))
  2470. /* Complex double and long double uses the struct return convention. */
  2471. || (code == TYPE_CODE_COMPLEX && TYPE_LENGTH (type) == 16)
  2472. || (code == TYPE_CODE_COMPLEX && TYPE_LENGTH (type) == 24)
  2473. /* 128-bit decimal float uses the struct return convention. */
  2474. || (code == TYPE_CODE_DECFLOAT && TYPE_LENGTH (type) == 16))
  2475. {
  2476. /* The System V ABI says that:
  2477. "A function that returns a structure or union also sets %eax
  2478. to the value of the original address of the caller's area
  2479. before it returns. Thus when the caller receives control
  2480. again, the address of the returned object resides in register
  2481. %eax and can be used to access the object."
  2482. So the ABI guarantees that we can always find the return
  2483. value just after the function has returned. */
  2484. /* Note that the ABI doesn't mention functions returning arrays,
  2485. which is something possible in certain languages such as Ada.
  2486. In this case, the value is returned as if it was wrapped in
  2487. a record, so the convention applied to records also applies
  2488. to arrays. */
  2489. if (readbuf)
  2490. {
  2491. ULONGEST addr;
  2492. regcache_raw_read_unsigned (regcache, I386_EAX_REGNUM, &addr);
  2493. read_memory (addr, readbuf, TYPE_LENGTH (type));
  2494. }
  2495. return RETURN_VALUE_ABI_RETURNS_ADDRESS;
  2496. }
  2497. /* This special case is for structures consisting of a single
  2498. `float', `double' or 'long double' member. These structures are
  2499. returned in %st(0). For these structures, we call ourselves
  2500. recursively, changing TYPE into the type of the first member of
  2501. the structure. Since that should work for all structures that
  2502. have only one member, we don't bother to check the member's type
  2503. here. */
  2504. if (code == TYPE_CODE_STRUCT && type->num_fields () == 1)
  2505. {
  2506. type = check_typedef (type->field (0).type ());
  2507. return i386_return_value (gdbarch, function, type, regcache,
  2508. readbuf, writebuf);
  2509. }
  2510. if (readbuf)
  2511. i386_extract_return_value (gdbarch, type, regcache, readbuf);
  2512. if (writebuf)
  2513. i386_store_return_value (gdbarch, type, regcache, writebuf);
  2514. return RETURN_VALUE_REGISTER_CONVENTION;
  2515. }
  2516. struct type *
  2517. i387_ext_type (struct gdbarch *gdbarch)
  2518. {
  2519. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  2520. if (!tdep->i387_ext_type)
  2521. {
  2522. tdep->i387_ext_type = tdesc_find_type (gdbarch, "i387_ext");
  2523. gdb_assert (tdep->i387_ext_type != NULL);
  2524. }
  2525. return tdep->i387_ext_type;
  2526. }
  2527. /* Construct type for pseudo BND registers. We can't use
  2528. tdesc_find_type since a complement of one value has to be used
  2529. to describe the upper bound. */
  2530. static struct type *
  2531. i386_bnd_type (struct gdbarch *gdbarch)
  2532. {
  2533. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  2534. if (!tdep->i386_bnd_type)
  2535. {
  2536. struct type *t;
  2537. const struct builtin_type *bt = builtin_type (gdbarch);
  2538. /* The type we're building is described bellow: */
  2539. #if 0
  2540. struct __bound128
  2541. {
  2542. void *lbound;
  2543. void *ubound; /* One complement of raw ubound field. */
  2544. };
  2545. #endif
  2546. t = arch_composite_type (gdbarch,
  2547. "__gdb_builtin_type_bound128", TYPE_CODE_STRUCT);
  2548. append_composite_type_field (t, "lbound", bt->builtin_data_ptr);
  2549. append_composite_type_field (t, "ubound", bt->builtin_data_ptr);
  2550. t->set_name ("builtin_type_bound128");
  2551. tdep->i386_bnd_type = t;
  2552. }
  2553. return tdep->i386_bnd_type;
  2554. }
  2555. /* Construct vector type for pseudo ZMM registers. We can't use
  2556. tdesc_find_type since ZMM isn't described in target description. */
  2557. static struct type *
  2558. i386_zmm_type (struct gdbarch *gdbarch)
  2559. {
  2560. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  2561. if (!tdep->i386_zmm_type)
  2562. {
  2563. const struct builtin_type *bt = builtin_type (gdbarch);
  2564. /* The type we're building is this: */
  2565. #if 0
  2566. union __gdb_builtin_type_vec512i
  2567. {
  2568. int128_t v4_int128[4];
  2569. int64_t v8_int64[8];
  2570. int32_t v16_int32[16];
  2571. int16_t v32_int16[32];
  2572. int8_t v64_int8[64];
  2573. double v8_double[8];
  2574. float v16_float[16];
  2575. float16_t v32_half[32];
  2576. bfloat16_t v32_bfloat16[32];
  2577. };
  2578. #endif
  2579. struct type *t;
  2580. t = arch_composite_type (gdbarch,
  2581. "__gdb_builtin_type_vec512i", TYPE_CODE_UNION);
  2582. append_composite_type_field (t, "v32_bfloat16",
  2583. init_vector_type (bt->builtin_bfloat16, 32));
  2584. append_composite_type_field (t, "v32_half",
  2585. init_vector_type (bt->builtin_half, 32));
  2586. append_composite_type_field (t, "v16_float",
  2587. init_vector_type (bt->builtin_float, 16));
  2588. append_composite_type_field (t, "v8_double",
  2589. init_vector_type (bt->builtin_double, 8));
  2590. append_composite_type_field (t, "v64_int8",
  2591. init_vector_type (bt->builtin_int8, 64));
  2592. append_composite_type_field (t, "v32_int16",
  2593. init_vector_type (bt->builtin_int16, 32));
  2594. append_composite_type_field (t, "v16_int32",
  2595. init_vector_type (bt->builtin_int32, 16));
  2596. append_composite_type_field (t, "v8_int64",
  2597. init_vector_type (bt->builtin_int64, 8));
  2598. append_composite_type_field (t, "v4_int128",
  2599. init_vector_type (bt->builtin_int128, 4));
  2600. t->set_is_vector (true);
  2601. t->set_name ("builtin_type_vec512i");
  2602. tdep->i386_zmm_type = t;
  2603. }
  2604. return tdep->i386_zmm_type;
  2605. }
  2606. /* Construct vector type for pseudo YMM registers. We can't use
  2607. tdesc_find_type since YMM isn't described in target description. */
  2608. static struct type *
  2609. i386_ymm_type (struct gdbarch *gdbarch)
  2610. {
  2611. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  2612. if (!tdep->i386_ymm_type)
  2613. {
  2614. const struct builtin_type *bt = builtin_type (gdbarch);
  2615. /* The type we're building is this: */
  2616. #if 0
  2617. union __gdb_builtin_type_vec256i
  2618. {
  2619. int128_t v2_int128[2];
  2620. int64_t v4_int64[4];
  2621. int32_t v8_int32[8];
  2622. int16_t v16_int16[16];
  2623. int8_t v32_int8[32];
  2624. double v4_double[4];
  2625. float v8_float[8];
  2626. float16_t v16_half[16];
  2627. bfloat16_t v16_bfloat16[16];
  2628. };
  2629. #endif
  2630. struct type *t;
  2631. t = arch_composite_type (gdbarch,
  2632. "__gdb_builtin_type_vec256i", TYPE_CODE_UNION);
  2633. append_composite_type_field (t, "v16_bfloat16",
  2634. init_vector_type (bt->builtin_bfloat16, 16));
  2635. append_composite_type_field (t, "v16_half",
  2636. init_vector_type (bt->builtin_half, 16));
  2637. append_composite_type_field (t, "v8_float",
  2638. init_vector_type (bt->builtin_float, 8));
  2639. append_composite_type_field (t, "v4_double",
  2640. init_vector_type (bt->builtin_double, 4));
  2641. append_composite_type_field (t, "v32_int8",
  2642. init_vector_type (bt->builtin_int8, 32));
  2643. append_composite_type_field (t, "v16_int16",
  2644. init_vector_type (bt->builtin_int16, 16));
  2645. append_composite_type_field (t, "v8_int32",
  2646. init_vector_type (bt->builtin_int32, 8));
  2647. append_composite_type_field (t, "v4_int64",
  2648. init_vector_type (bt->builtin_int64, 4));
  2649. append_composite_type_field (t, "v2_int128",
  2650. init_vector_type (bt->builtin_int128, 2));
  2651. t->set_is_vector (true);
  2652. t->set_name ("builtin_type_vec256i");
  2653. tdep->i386_ymm_type = t;
  2654. }
  2655. return tdep->i386_ymm_type;
  2656. }
  2657. /* Construct vector type for MMX registers. */
  2658. static struct type *
  2659. i386_mmx_type (struct gdbarch *gdbarch)
  2660. {
  2661. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  2662. if (!tdep->i386_mmx_type)
  2663. {
  2664. const struct builtin_type *bt = builtin_type (gdbarch);
  2665. /* The type we're building is this: */
  2666. #if 0
  2667. union __gdb_builtin_type_vec64i
  2668. {
  2669. int64_t uint64;
  2670. int32_t v2_int32[2];
  2671. int16_t v4_int16[4];
  2672. int8_t v8_int8[8];
  2673. };
  2674. #endif
  2675. struct type *t;
  2676. t = arch_composite_type (gdbarch,
  2677. "__gdb_builtin_type_vec64i", TYPE_CODE_UNION);
  2678. append_composite_type_field (t, "uint64", bt->builtin_int64);
  2679. append_composite_type_field (t, "v2_int32",
  2680. init_vector_type (bt->builtin_int32, 2));
  2681. append_composite_type_field (t, "v4_int16",
  2682. init_vector_type (bt->builtin_int16, 4));
  2683. append_composite_type_field (t, "v8_int8",
  2684. init_vector_type (bt->builtin_int8, 8));
  2685. t->set_is_vector (true);
  2686. t->set_name ("builtin_type_vec64i");
  2687. tdep->i386_mmx_type = t;
  2688. }
  2689. return tdep->i386_mmx_type;
  2690. }
  2691. /* Return the GDB type object for the "standard" data type of data in
  2692. register REGNUM. */
  2693. struct type *
  2694. i386_pseudo_register_type (struct gdbarch *gdbarch, int regnum)
  2695. {
  2696. if (i386_bnd_regnum_p (gdbarch, regnum))
  2697. return i386_bnd_type (gdbarch);
  2698. if (i386_mmx_regnum_p (gdbarch, regnum))
  2699. return i386_mmx_type (gdbarch);
  2700. else if (i386_ymm_regnum_p (gdbarch, regnum))
  2701. return i386_ymm_type (gdbarch);
  2702. else if (i386_ymm_avx512_regnum_p (gdbarch, regnum))
  2703. return i386_ymm_type (gdbarch);
  2704. else if (i386_zmm_regnum_p (gdbarch, regnum))
  2705. return i386_zmm_type (gdbarch);
  2706. else
  2707. {
  2708. const struct builtin_type *bt = builtin_type (gdbarch);
  2709. if (i386_byte_regnum_p (gdbarch, regnum))
  2710. return bt->builtin_int8;
  2711. else if (i386_word_regnum_p (gdbarch, regnum))
  2712. return bt->builtin_int16;
  2713. else if (i386_dword_regnum_p (gdbarch, regnum))
  2714. return bt->builtin_int32;
  2715. else if (i386_k_regnum_p (gdbarch, regnum))
  2716. return bt->builtin_int64;
  2717. }
  2718. internal_error (__FILE__, __LINE__, _("invalid regnum"));
  2719. }
  2720. /* Map a cooked register onto a raw register or memory. For the i386,
  2721. the MMX registers need to be mapped onto floating point registers. */
  2722. static int
  2723. i386_mmx_regnum_to_fp_regnum (readable_regcache *regcache, int regnum)
  2724. {
  2725. gdbarch *arch = regcache->arch ();
  2726. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
  2727. int mmxreg, fpreg;
  2728. ULONGEST fstat;
  2729. int tos;
  2730. mmxreg = regnum - tdep->mm0_regnum;
  2731. regcache->raw_read (I387_FSTAT_REGNUM (tdep), &fstat);
  2732. tos = (fstat >> 11) & 0x7;
  2733. fpreg = (mmxreg + tos) % 8;
  2734. return (I387_ST0_REGNUM (tdep) + fpreg);
  2735. }
  2736. /* A helper function for us by i386_pseudo_register_read_value and
  2737. amd64_pseudo_register_read_value. It does all the work but reads
  2738. the data into an already-allocated value. */
  2739. void
  2740. i386_pseudo_register_read_into_value (struct gdbarch *gdbarch,
  2741. readable_regcache *regcache,
  2742. int regnum,
  2743. struct value *result_value)
  2744. {
  2745. gdb_byte raw_buf[I386_MAX_REGISTER_SIZE];
  2746. enum register_status status;
  2747. gdb_byte *buf = value_contents_raw (result_value).data ();
  2748. if (i386_mmx_regnum_p (gdbarch, regnum))
  2749. {
  2750. int fpnum = i386_mmx_regnum_to_fp_regnum (regcache, regnum);
  2751. /* Extract (always little endian). */
  2752. status = regcache->raw_read (fpnum, raw_buf);
  2753. if (status != REG_VALID)
  2754. mark_value_bytes_unavailable (result_value, 0,
  2755. TYPE_LENGTH (value_type (result_value)));
  2756. else
  2757. memcpy (buf, raw_buf, register_size (gdbarch, regnum));
  2758. }
  2759. else
  2760. {
  2761. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  2762. if (i386_bnd_regnum_p (gdbarch, regnum))
  2763. {
  2764. regnum -= tdep->bnd0_regnum;
  2765. /* Extract (always little endian). Read lower 128bits. */
  2766. status = regcache->raw_read (I387_BND0R_REGNUM (tdep) + regnum,
  2767. raw_buf);
  2768. if (status != REG_VALID)
  2769. mark_value_bytes_unavailable (result_value, 0, 16);
  2770. else
  2771. {
  2772. enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
  2773. LONGEST upper, lower;
  2774. int size = TYPE_LENGTH (builtin_type (gdbarch)->builtin_data_ptr);
  2775. lower = extract_unsigned_integer (raw_buf, 8, byte_order);
  2776. upper = extract_unsigned_integer (raw_buf + 8, 8, byte_order);
  2777. upper = ~upper;
  2778. memcpy (buf, &lower, size);
  2779. memcpy (buf + size, &upper, size);
  2780. }
  2781. }
  2782. else if (i386_k_regnum_p (gdbarch, regnum))
  2783. {
  2784. regnum -= tdep->k0_regnum;
  2785. /* Extract (always little endian). */
  2786. status = regcache->raw_read (tdep->k0_regnum + regnum, raw_buf);
  2787. if (status != REG_VALID)
  2788. mark_value_bytes_unavailable (result_value, 0, 8);
  2789. else
  2790. memcpy (buf, raw_buf, 8);
  2791. }
  2792. else if (i386_zmm_regnum_p (gdbarch, regnum))
  2793. {
  2794. regnum -= tdep->zmm0_regnum;
  2795. if (regnum < num_lower_zmm_regs)
  2796. {
  2797. /* Extract (always little endian). Read lower 128bits. */
  2798. status = regcache->raw_read (I387_XMM0_REGNUM (tdep) + regnum,
  2799. raw_buf);
  2800. if (status != REG_VALID)
  2801. mark_value_bytes_unavailable (result_value, 0, 16);
  2802. else
  2803. memcpy (buf, raw_buf, 16);
  2804. /* Extract (always little endian). Read upper 128bits. */
  2805. status = regcache->raw_read (tdep->ymm0h_regnum + regnum,
  2806. raw_buf);
  2807. if (status != REG_VALID)
  2808. mark_value_bytes_unavailable (result_value, 16, 16);
  2809. else
  2810. memcpy (buf + 16, raw_buf, 16);
  2811. }
  2812. else
  2813. {
  2814. /* Extract (always little endian). Read lower 128bits. */
  2815. status = regcache->raw_read (I387_XMM16_REGNUM (tdep) + regnum
  2816. - num_lower_zmm_regs,
  2817. raw_buf);
  2818. if (status != REG_VALID)
  2819. mark_value_bytes_unavailable (result_value, 0, 16);
  2820. else
  2821. memcpy (buf, raw_buf, 16);
  2822. /* Extract (always little endian). Read upper 128bits. */
  2823. status = regcache->raw_read (I387_YMM16H_REGNUM (tdep) + regnum
  2824. - num_lower_zmm_regs,
  2825. raw_buf);
  2826. if (status != REG_VALID)
  2827. mark_value_bytes_unavailable (result_value, 16, 16);
  2828. else
  2829. memcpy (buf + 16, raw_buf, 16);
  2830. }
  2831. /* Read upper 256bits. */
  2832. status = regcache->raw_read (tdep->zmm0h_regnum + regnum,
  2833. raw_buf);
  2834. if (status != REG_VALID)
  2835. mark_value_bytes_unavailable (result_value, 32, 32);
  2836. else
  2837. memcpy (buf + 32, raw_buf, 32);
  2838. }
  2839. else if (i386_ymm_regnum_p (gdbarch, regnum))
  2840. {
  2841. regnum -= tdep->ymm0_regnum;
  2842. /* Extract (always little endian). Read lower 128bits. */
  2843. status = regcache->raw_read (I387_XMM0_REGNUM (tdep) + regnum,
  2844. raw_buf);
  2845. if (status != REG_VALID)
  2846. mark_value_bytes_unavailable (result_value, 0, 16);
  2847. else
  2848. memcpy (buf, raw_buf, 16);
  2849. /* Read upper 128bits. */
  2850. status = regcache->raw_read (tdep->ymm0h_regnum + regnum,
  2851. raw_buf);
  2852. if (status != REG_VALID)
  2853. mark_value_bytes_unavailable (result_value, 16, 32);
  2854. else
  2855. memcpy (buf + 16, raw_buf, 16);
  2856. }
  2857. else if (i386_ymm_avx512_regnum_p (gdbarch, regnum))
  2858. {
  2859. regnum -= tdep->ymm16_regnum;
  2860. /* Extract (always little endian). Read lower 128bits. */
  2861. status = regcache->raw_read (I387_XMM16_REGNUM (tdep) + regnum,
  2862. raw_buf);
  2863. if (status != REG_VALID)
  2864. mark_value_bytes_unavailable (result_value, 0, 16);
  2865. else
  2866. memcpy (buf, raw_buf, 16);
  2867. /* Read upper 128bits. */
  2868. status = regcache->raw_read (tdep->ymm16h_regnum + regnum,
  2869. raw_buf);
  2870. if (status != REG_VALID)
  2871. mark_value_bytes_unavailable (result_value, 16, 16);
  2872. else
  2873. memcpy (buf + 16, raw_buf, 16);
  2874. }
  2875. else if (i386_word_regnum_p (gdbarch, regnum))
  2876. {
  2877. int gpnum = regnum - tdep->ax_regnum;
  2878. /* Extract (always little endian). */
  2879. status = regcache->raw_read (gpnum, raw_buf);
  2880. if (status != REG_VALID)
  2881. mark_value_bytes_unavailable (result_value, 0,
  2882. TYPE_LENGTH (value_type (result_value)));
  2883. else
  2884. memcpy (buf, raw_buf, 2);
  2885. }
  2886. else if (i386_byte_regnum_p (gdbarch, regnum))
  2887. {
  2888. int gpnum = regnum - tdep->al_regnum;
  2889. /* Extract (always little endian). We read both lower and
  2890. upper registers. */
  2891. status = regcache->raw_read (gpnum % 4, raw_buf);
  2892. if (status != REG_VALID)
  2893. mark_value_bytes_unavailable (result_value, 0,
  2894. TYPE_LENGTH (value_type (result_value)));
  2895. else if (gpnum >= 4)
  2896. memcpy (buf, raw_buf + 1, 1);
  2897. else
  2898. memcpy (buf, raw_buf, 1);
  2899. }
  2900. else
  2901. internal_error (__FILE__, __LINE__, _("invalid regnum"));
  2902. }
  2903. }
  2904. static struct value *
  2905. i386_pseudo_register_read_value (struct gdbarch *gdbarch,
  2906. readable_regcache *regcache,
  2907. int regnum)
  2908. {
  2909. struct value *result;
  2910. result = allocate_value (register_type (gdbarch, regnum));
  2911. VALUE_LVAL (result) = lval_register;
  2912. VALUE_REGNUM (result) = regnum;
  2913. i386_pseudo_register_read_into_value (gdbarch, regcache, regnum, result);
  2914. return result;
  2915. }
  2916. void
  2917. i386_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
  2918. int regnum, const gdb_byte *buf)
  2919. {
  2920. gdb_byte raw_buf[I386_MAX_REGISTER_SIZE];
  2921. if (i386_mmx_regnum_p (gdbarch, regnum))
  2922. {
  2923. int fpnum = i386_mmx_regnum_to_fp_regnum (regcache, regnum);
  2924. /* Read ... */
  2925. regcache->raw_read (fpnum, raw_buf);
  2926. /* ... Modify ... (always little endian). */
  2927. memcpy (raw_buf, buf, register_size (gdbarch, regnum));
  2928. /* ... Write. */
  2929. regcache->raw_write (fpnum, raw_buf);
  2930. }
  2931. else
  2932. {
  2933. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  2934. if (i386_bnd_regnum_p (gdbarch, regnum))
  2935. {
  2936. ULONGEST upper, lower;
  2937. int size = TYPE_LENGTH (builtin_type (gdbarch)->builtin_data_ptr);
  2938. enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
  2939. /* New values from input value. */
  2940. regnum -= tdep->bnd0_regnum;
  2941. lower = extract_unsigned_integer (buf, size, byte_order);
  2942. upper = extract_unsigned_integer (buf + size, size, byte_order);
  2943. /* Fetching register buffer. */
  2944. regcache->raw_read (I387_BND0R_REGNUM (tdep) + regnum,
  2945. raw_buf);
  2946. upper = ~upper;
  2947. /* Set register bits. */
  2948. memcpy (raw_buf, &lower, 8);
  2949. memcpy (raw_buf + 8, &upper, 8);
  2950. regcache->raw_write (I387_BND0R_REGNUM (tdep) + regnum, raw_buf);
  2951. }
  2952. else if (i386_k_regnum_p (gdbarch, regnum))
  2953. {
  2954. regnum -= tdep->k0_regnum;
  2955. regcache->raw_write (tdep->k0_regnum + regnum, buf);
  2956. }
  2957. else if (i386_zmm_regnum_p (gdbarch, regnum))
  2958. {
  2959. regnum -= tdep->zmm0_regnum;
  2960. if (regnum < num_lower_zmm_regs)
  2961. {
  2962. /* Write lower 128bits. */
  2963. regcache->raw_write (I387_XMM0_REGNUM (tdep) + regnum, buf);
  2964. /* Write upper 128bits. */
  2965. regcache->raw_write (I387_YMM0_REGNUM (tdep) + regnum, buf + 16);
  2966. }
  2967. else
  2968. {
  2969. /* Write lower 128bits. */
  2970. regcache->raw_write (I387_XMM16_REGNUM (tdep) + regnum
  2971. - num_lower_zmm_regs, buf);
  2972. /* Write upper 128bits. */
  2973. regcache->raw_write (I387_YMM16H_REGNUM (tdep) + regnum
  2974. - num_lower_zmm_regs, buf + 16);
  2975. }
  2976. /* Write upper 256bits. */
  2977. regcache->raw_write (tdep->zmm0h_regnum + regnum, buf + 32);
  2978. }
  2979. else if (i386_ymm_regnum_p (gdbarch, regnum))
  2980. {
  2981. regnum -= tdep->ymm0_regnum;
  2982. /* ... Write lower 128bits. */
  2983. regcache->raw_write (I387_XMM0_REGNUM (tdep) + regnum, buf);
  2984. /* ... Write upper 128bits. */
  2985. regcache->raw_write (tdep->ymm0h_regnum + regnum, buf + 16);
  2986. }
  2987. else if (i386_ymm_avx512_regnum_p (gdbarch, regnum))
  2988. {
  2989. regnum -= tdep->ymm16_regnum;
  2990. /* ... Write lower 128bits. */
  2991. regcache->raw_write (I387_XMM16_REGNUM (tdep) + regnum, buf);
  2992. /* ... Write upper 128bits. */
  2993. regcache->raw_write (tdep->ymm16h_regnum + regnum, buf + 16);
  2994. }
  2995. else if (i386_word_regnum_p (gdbarch, regnum))
  2996. {
  2997. int gpnum = regnum - tdep->ax_regnum;
  2998. /* Read ... */
  2999. regcache->raw_read (gpnum, raw_buf);
  3000. /* ... Modify ... (always little endian). */
  3001. memcpy (raw_buf, buf, 2);
  3002. /* ... Write. */
  3003. regcache->raw_write (gpnum, raw_buf);
  3004. }
  3005. else if (i386_byte_regnum_p (gdbarch, regnum))
  3006. {
  3007. int gpnum = regnum - tdep->al_regnum;
  3008. /* Read ... We read both lower and upper registers. */
  3009. regcache->raw_read (gpnum % 4, raw_buf);
  3010. /* ... Modify ... (always little endian). */
  3011. if (gpnum >= 4)
  3012. memcpy (raw_buf + 1, buf, 1);
  3013. else
  3014. memcpy (raw_buf, buf, 1);
  3015. /* ... Write. */
  3016. regcache->raw_write (gpnum % 4, raw_buf);
  3017. }
  3018. else
  3019. internal_error (__FILE__, __LINE__, _("invalid regnum"));
  3020. }
  3021. }
  3022. /* Implement the 'ax_pseudo_register_collect' gdbarch method. */
  3023. int
  3024. i386_ax_pseudo_register_collect (struct gdbarch *gdbarch,
  3025. struct agent_expr *ax, int regnum)
  3026. {
  3027. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  3028. if (i386_mmx_regnum_p (gdbarch, regnum))
  3029. {
  3030. /* MMX to FPU register mapping depends on current TOS. Let's just
  3031. not care and collect everything... */
  3032. int i;
  3033. ax_reg_mask (ax, I387_FSTAT_REGNUM (tdep));
  3034. for (i = 0; i < 8; i++)
  3035. ax_reg_mask (ax, I387_ST0_REGNUM (tdep) + i);
  3036. return 0;
  3037. }
  3038. else if (i386_bnd_regnum_p (gdbarch, regnum))
  3039. {
  3040. regnum -= tdep->bnd0_regnum;
  3041. ax_reg_mask (ax, I387_BND0R_REGNUM (tdep) + regnum);
  3042. return 0;
  3043. }
  3044. else if (i386_k_regnum_p (gdbarch, regnum))
  3045. {
  3046. regnum -= tdep->k0_regnum;
  3047. ax_reg_mask (ax, tdep->k0_regnum + regnum);
  3048. return 0;
  3049. }
  3050. else if (i386_zmm_regnum_p (gdbarch, regnum))
  3051. {
  3052. regnum -= tdep->zmm0_regnum;
  3053. if (regnum < num_lower_zmm_regs)
  3054. {
  3055. ax_reg_mask (ax, I387_XMM0_REGNUM (tdep) + regnum);
  3056. ax_reg_mask (ax, tdep->ymm0h_regnum + regnum);
  3057. }
  3058. else
  3059. {
  3060. ax_reg_mask (ax, I387_XMM16_REGNUM (tdep) + regnum
  3061. - num_lower_zmm_regs);
  3062. ax_reg_mask (ax, I387_YMM16H_REGNUM (tdep) + regnum
  3063. - num_lower_zmm_regs);
  3064. }
  3065. ax_reg_mask (ax, tdep->zmm0h_regnum + regnum);
  3066. return 0;
  3067. }
  3068. else if (i386_ymm_regnum_p (gdbarch, regnum))
  3069. {
  3070. regnum -= tdep->ymm0_regnum;
  3071. ax_reg_mask (ax, I387_XMM0_REGNUM (tdep) + regnum);
  3072. ax_reg_mask (ax, tdep->ymm0h_regnum + regnum);
  3073. return 0;
  3074. }
  3075. else if (i386_ymm_avx512_regnum_p (gdbarch, regnum))
  3076. {
  3077. regnum -= tdep->ymm16_regnum;
  3078. ax_reg_mask (ax, I387_XMM16_REGNUM (tdep) + regnum);
  3079. ax_reg_mask (ax, tdep->ymm16h_regnum + regnum);
  3080. return 0;
  3081. }
  3082. else if (i386_word_regnum_p (gdbarch, regnum))
  3083. {
  3084. int gpnum = regnum - tdep->ax_regnum;
  3085. ax_reg_mask (ax, gpnum);
  3086. return 0;
  3087. }
  3088. else if (i386_byte_regnum_p (gdbarch, regnum))
  3089. {
  3090. int gpnum = regnum - tdep->al_regnum;
  3091. ax_reg_mask (ax, gpnum % 4);
  3092. return 0;
  3093. }
  3094. else
  3095. internal_error (__FILE__, __LINE__, _("invalid regnum"));
  3096. return 1;
  3097. }
  3098. /* Return the register number of the register allocated by GCC after
  3099. REGNUM, or -1 if there is no such register. */
  3100. static int
  3101. i386_next_regnum (int regnum)
  3102. {
  3103. /* GCC allocates the registers in the order:
  3104. %eax, %edx, %ecx, %ebx, %esi, %edi, %ebp, %esp, ...
  3105. Since storing a variable in %esp doesn't make any sense we return
  3106. -1 for %ebp and for %esp itself. */
  3107. static int next_regnum[] =
  3108. {
  3109. I386_EDX_REGNUM, /* Slot for %eax. */
  3110. I386_EBX_REGNUM, /* Slot for %ecx. */
  3111. I386_ECX_REGNUM, /* Slot for %edx. */
  3112. I386_ESI_REGNUM, /* Slot for %ebx. */
  3113. -1, -1, /* Slots for %esp and %ebp. */
  3114. I386_EDI_REGNUM, /* Slot for %esi. */
  3115. I386_EBP_REGNUM /* Slot for %edi. */
  3116. };
  3117. if (regnum >= 0 && regnum < sizeof (next_regnum) / sizeof (next_regnum[0]))
  3118. return next_regnum[regnum];
  3119. return -1;
  3120. }
  3121. /* Return nonzero if a value of type TYPE stored in register REGNUM
  3122. needs any special handling. */
  3123. static int
  3124. i386_convert_register_p (struct gdbarch *gdbarch,
  3125. int regnum, struct type *type)
  3126. {
  3127. int len = TYPE_LENGTH (type);
  3128. /* Values may be spread across multiple registers. Most debugging
  3129. formats aren't expressive enough to specify the locations, so
  3130. some heuristics is involved. Right now we only handle types that
  3131. have a length that is a multiple of the word size, since GCC
  3132. doesn't seem to put any other types into registers. */
  3133. if (len > 4 && len % 4 == 0)
  3134. {
  3135. int last_regnum = regnum;
  3136. while (len > 4)
  3137. {
  3138. last_regnum = i386_next_regnum (last_regnum);
  3139. len -= 4;
  3140. }
  3141. if (last_regnum != -1)
  3142. return 1;
  3143. }
  3144. return i387_convert_register_p (gdbarch, regnum, type);
  3145. }
  3146. /* Read a value of type TYPE from register REGNUM in frame FRAME, and
  3147. return its contents in TO. */
  3148. static int
  3149. i386_register_to_value (struct frame_info *frame, int regnum,
  3150. struct type *type, gdb_byte *to,
  3151. int *optimizedp, int *unavailablep)
  3152. {
  3153. struct gdbarch *gdbarch = get_frame_arch (frame);
  3154. int len = TYPE_LENGTH (type);
  3155. if (i386_fp_regnum_p (gdbarch, regnum))
  3156. return i387_register_to_value (frame, regnum, type, to,
  3157. optimizedp, unavailablep);
  3158. /* Read a value spread across multiple registers. */
  3159. gdb_assert (len > 4 && len % 4 == 0);
  3160. while (len > 0)
  3161. {
  3162. gdb_assert (regnum != -1);
  3163. gdb_assert (register_size (gdbarch, regnum) == 4);
  3164. if (!get_frame_register_bytes (frame, regnum, 0,
  3165. gdb::make_array_view (to,
  3166. register_size (gdbarch,
  3167. regnum)),
  3168. optimizedp, unavailablep))
  3169. return 0;
  3170. regnum = i386_next_regnum (regnum);
  3171. len -= 4;
  3172. to += 4;
  3173. }
  3174. *optimizedp = *unavailablep = 0;
  3175. return 1;
  3176. }
  3177. /* Write the contents FROM of a value of type TYPE into register
  3178. REGNUM in frame FRAME. */
  3179. static void
  3180. i386_value_to_register (struct frame_info *frame, int regnum,
  3181. struct type *type, const gdb_byte *from)
  3182. {
  3183. int len = TYPE_LENGTH (type);
  3184. if (i386_fp_regnum_p (get_frame_arch (frame), regnum))
  3185. {
  3186. i387_value_to_register (frame, regnum, type, from);
  3187. return;
  3188. }
  3189. /* Write a value spread across multiple registers. */
  3190. gdb_assert (len > 4 && len % 4 == 0);
  3191. while (len > 0)
  3192. {
  3193. gdb_assert (regnum != -1);
  3194. gdb_assert (register_size (get_frame_arch (frame), regnum) == 4);
  3195. put_frame_register (frame, regnum, from);
  3196. regnum = i386_next_regnum (regnum);
  3197. len -= 4;
  3198. from += 4;
  3199. }
  3200. }
  3201. /* Supply register REGNUM from the buffer specified by GREGS and LEN
  3202. in the general-purpose register set REGSET to register cache
  3203. REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
  3204. void
  3205. i386_supply_gregset (const struct regset *regset, struct regcache *regcache,
  3206. int regnum, const void *gregs, size_t len)
  3207. {
  3208. struct gdbarch *gdbarch = regcache->arch ();
  3209. const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  3210. const gdb_byte *regs = (const gdb_byte *) gregs;
  3211. int i;
  3212. gdb_assert (len >= tdep->sizeof_gregset);
  3213. for (i = 0; i < tdep->gregset_num_regs; i++)
  3214. {
  3215. if ((regnum == i || regnum == -1)
  3216. && tdep->gregset_reg_offset[i] != -1)
  3217. regcache->raw_supply (i, regs + tdep->gregset_reg_offset[i]);
  3218. }
  3219. }
  3220. /* Collect register REGNUM from the register cache REGCACHE and store
  3221. it in the buffer specified by GREGS and LEN as described by the
  3222. general-purpose register set REGSET. If REGNUM is -1, do this for
  3223. all registers in REGSET. */
  3224. static void
  3225. i386_collect_gregset (const struct regset *regset,
  3226. const struct regcache *regcache,
  3227. int regnum, void *gregs, size_t len)
  3228. {
  3229. struct gdbarch *gdbarch = regcache->arch ();
  3230. const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  3231. gdb_byte *regs = (gdb_byte *) gregs;
  3232. int i;
  3233. gdb_assert (len >= tdep->sizeof_gregset);
  3234. for (i = 0; i < tdep->gregset_num_regs; i++)
  3235. {
  3236. if ((regnum == i || regnum == -1)
  3237. && tdep->gregset_reg_offset[i] != -1)
  3238. regcache->raw_collect (i, regs + tdep->gregset_reg_offset[i]);
  3239. }
  3240. }
  3241. /* Supply register REGNUM from the buffer specified by FPREGS and LEN
  3242. in the floating-point register set REGSET to register cache
  3243. REGCACHE. If REGNUM is -1, do this for all registers in REGSET. */
  3244. static void
  3245. i386_supply_fpregset (const struct regset *regset, struct regcache *regcache,
  3246. int regnum, const void *fpregs, size_t len)
  3247. {
  3248. struct gdbarch *gdbarch = regcache->arch ();
  3249. const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  3250. if (len == I387_SIZEOF_FXSAVE)
  3251. {
  3252. i387_supply_fxsave (regcache, regnum, fpregs);
  3253. return;
  3254. }
  3255. gdb_assert (len >= tdep->sizeof_fpregset);
  3256. i387_supply_fsave (regcache, regnum, fpregs);
  3257. }
  3258. /* Collect register REGNUM from the register cache REGCACHE and store
  3259. it in the buffer specified by FPREGS and LEN as described by the
  3260. floating-point register set REGSET. If REGNUM is -1, do this for
  3261. all registers in REGSET. */
  3262. static void
  3263. i386_collect_fpregset (const struct regset *regset,
  3264. const struct regcache *regcache,
  3265. int regnum, void *fpregs, size_t len)
  3266. {
  3267. struct gdbarch *gdbarch = regcache->arch ();
  3268. const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  3269. if (len == I387_SIZEOF_FXSAVE)
  3270. {
  3271. i387_collect_fxsave (regcache, regnum, fpregs);
  3272. return;
  3273. }
  3274. gdb_assert (len >= tdep->sizeof_fpregset);
  3275. i387_collect_fsave (regcache, regnum, fpregs);
  3276. }
  3277. /* Register set definitions. */
  3278. const struct regset i386_gregset =
  3279. {
  3280. NULL, i386_supply_gregset, i386_collect_gregset
  3281. };
  3282. const struct regset i386_fpregset =
  3283. {
  3284. NULL, i386_supply_fpregset, i386_collect_fpregset
  3285. };
  3286. /* Default iterator over core file register note sections. */
  3287. void
  3288. i386_iterate_over_regset_sections (struct gdbarch *gdbarch,
  3289. iterate_over_regset_sections_cb *cb,
  3290. void *cb_data,
  3291. const struct regcache *regcache)
  3292. {
  3293. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  3294. cb (".reg", tdep->sizeof_gregset, tdep->sizeof_gregset, &i386_gregset, NULL,
  3295. cb_data);
  3296. if (tdep->sizeof_fpregset)
  3297. cb (".reg2", tdep->sizeof_fpregset, tdep->sizeof_fpregset, tdep->fpregset,
  3298. NULL, cb_data);
  3299. }
  3300. /* Stuff for WIN32 PE style DLL's but is pretty generic really. */
  3301. CORE_ADDR
  3302. i386_pe_skip_trampoline_code (struct frame_info *frame,
  3303. CORE_ADDR pc, char *name)
  3304. {
  3305. struct gdbarch *gdbarch = get_frame_arch (frame);
  3306. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  3307. /* jmp *(dest) */
  3308. if (pc && read_memory_unsigned_integer (pc, 2, byte_order) == 0x25ff)
  3309. {
  3310. unsigned long indirect =
  3311. read_memory_unsigned_integer (pc + 2, 4, byte_order);
  3312. struct minimal_symbol *indsym =
  3313. indirect ? lookup_minimal_symbol_by_pc (indirect).minsym : 0;
  3314. const char *symname = indsym ? indsym->linkage_name () : 0;
  3315. if (symname)
  3316. {
  3317. if (startswith (symname, "__imp_")
  3318. || startswith (symname, "_imp_"))
  3319. return name ? 1 :
  3320. read_memory_unsigned_integer (indirect, 4, byte_order);
  3321. }
  3322. }
  3323. return 0; /* Not a trampoline. */
  3324. }
  3325. /* Return whether the THIS_FRAME corresponds to a sigtramp
  3326. routine. */
  3327. int
  3328. i386_sigtramp_p (struct frame_info *this_frame)
  3329. {
  3330. CORE_ADDR pc = get_frame_pc (this_frame);
  3331. const char *name;
  3332. find_pc_partial_function (pc, &name, NULL, NULL);
  3333. return (name && strcmp ("_sigtramp", name) == 0);
  3334. }
  3335. /* We have two flavours of disassembly. The machinery on this page
  3336. deals with switching between those. */
  3337. static int
  3338. i386_print_insn (bfd_vma pc, struct disassemble_info *info)
  3339. {
  3340. gdb_assert (disassembly_flavor == att_flavor
  3341. || disassembly_flavor == intel_flavor);
  3342. info->disassembler_options = disassembly_flavor;
  3343. return default_print_insn (pc, info);
  3344. }
  3345. /* There are a few i386 architecture variants that differ only
  3346. slightly from the generic i386 target. For now, we don't give them
  3347. their own source file, but include them here. As a consequence,
  3348. they'll always be included. */
  3349. /* System V Release 4 (SVR4). */
  3350. /* Return whether THIS_FRAME corresponds to a SVR4 sigtramp
  3351. routine. */
  3352. static int
  3353. i386_svr4_sigtramp_p (struct frame_info *this_frame)
  3354. {
  3355. CORE_ADDR pc = get_frame_pc (this_frame);
  3356. const char *name;
  3357. /* The origin of these symbols is currently unknown. */
  3358. find_pc_partial_function (pc, &name, NULL, NULL);
  3359. return (name && (strcmp ("_sigreturn", name) == 0
  3360. || strcmp ("sigvechandler", name) == 0));
  3361. }
  3362. /* Assuming THIS_FRAME is for a SVR4 sigtramp routine, return the
  3363. address of the associated sigcontext (ucontext) structure. */
  3364. static CORE_ADDR
  3365. i386_svr4_sigcontext_addr (struct frame_info *this_frame)
  3366. {
  3367. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  3368. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  3369. gdb_byte buf[4];
  3370. CORE_ADDR sp;
  3371. get_frame_register (this_frame, I386_ESP_REGNUM, buf);
  3372. sp = extract_unsigned_integer (buf, 4, byte_order);
  3373. return read_memory_unsigned_integer (sp + 8, 4, byte_order);
  3374. }
  3375. /* Implementation of `gdbarch_stap_is_single_operand', as defined in
  3376. gdbarch.h. */
  3377. int
  3378. i386_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
  3379. {
  3380. return (*s == '$' /* Literal number. */
  3381. || (isdigit (*s) && s[1] == '(' && s[2] == '%') /* Displacement. */
  3382. || (*s == '(' && s[1] == '%') /* Register indirection. */
  3383. || (*s == '%' && isalpha (s[1]))); /* Register access. */
  3384. }
  3385. /* Helper function for i386_stap_parse_special_token.
  3386. This function parses operands of the form `-8+3+1(%rbp)', which
  3387. must be interpreted as `*(-8 + 3 - 1 + (void *) $eax)'.
  3388. Return true if the operand was parsed successfully, false
  3389. otherwise. */
  3390. static expr::operation_up
  3391. i386_stap_parse_special_token_triplet (struct gdbarch *gdbarch,
  3392. struct stap_parse_info *p)
  3393. {
  3394. const char *s = p->arg;
  3395. if (isdigit (*s) || *s == '-' || *s == '+')
  3396. {
  3397. bool got_minus[3];
  3398. int i;
  3399. long displacements[3];
  3400. const char *start;
  3401. int len;
  3402. char *endp;
  3403. got_minus[0] = false;
  3404. if (*s == '+')
  3405. ++s;
  3406. else if (*s == '-')
  3407. {
  3408. ++s;
  3409. got_minus[0] = true;
  3410. }
  3411. if (!isdigit ((unsigned char) *s))
  3412. return {};
  3413. displacements[0] = strtol (s, &endp, 10);
  3414. s = endp;
  3415. if (*s != '+' && *s != '-')
  3416. {
  3417. /* We are not dealing with a triplet. */
  3418. return {};
  3419. }
  3420. got_minus[1] = false;
  3421. if (*s == '+')
  3422. ++s;
  3423. else
  3424. {
  3425. ++s;
  3426. got_minus[1] = true;
  3427. }
  3428. if (!isdigit ((unsigned char) *s))
  3429. return {};
  3430. displacements[1] = strtol (s, &endp, 10);
  3431. s = endp;
  3432. if (*s != '+' && *s != '-')
  3433. {
  3434. /* We are not dealing with a triplet. */
  3435. return {};
  3436. }
  3437. got_minus[2] = false;
  3438. if (*s == '+')
  3439. ++s;
  3440. else
  3441. {
  3442. ++s;
  3443. got_minus[2] = true;
  3444. }
  3445. if (!isdigit ((unsigned char) *s))
  3446. return {};
  3447. displacements[2] = strtol (s, &endp, 10);
  3448. s = endp;
  3449. if (*s != '(' || s[1] != '%')
  3450. return {};
  3451. s += 2;
  3452. start = s;
  3453. while (isalnum (*s))
  3454. ++s;
  3455. if (*s++ != ')')
  3456. return {};
  3457. len = s - start - 1;
  3458. std::string regname (start, len);
  3459. if (user_reg_map_name_to_regnum (gdbarch, regname.c_str (), len) == -1)
  3460. error (_("Invalid register name `%s' on expression `%s'."),
  3461. regname.c_str (), p->saved_arg);
  3462. LONGEST value = 0;
  3463. for (i = 0; i < 3; i++)
  3464. {
  3465. LONGEST this_val = displacements[i];
  3466. if (got_minus[i])
  3467. this_val = -this_val;
  3468. value += this_val;
  3469. }
  3470. p->arg = s;
  3471. using namespace expr;
  3472. struct type *long_type = builtin_type (gdbarch)->builtin_long;
  3473. operation_up offset
  3474. = make_operation<long_const_operation> (long_type, value);
  3475. operation_up reg
  3476. = make_operation<register_operation> (std::move (regname));
  3477. struct type *void_ptr = builtin_type (gdbarch)->builtin_data_ptr;
  3478. reg = make_operation<unop_cast_operation> (std::move (reg), void_ptr);
  3479. operation_up sum
  3480. = make_operation<add_operation> (std::move (reg), std::move (offset));
  3481. struct type *arg_ptr_type = lookup_pointer_type (p->arg_type);
  3482. sum = make_operation<unop_cast_operation> (std::move (sum),
  3483. arg_ptr_type);
  3484. return make_operation<unop_ind_operation> (std::move (sum));
  3485. }
  3486. return {};
  3487. }
  3488. /* Helper function for i386_stap_parse_special_token.
  3489. This function parses operands of the form `register base +
  3490. (register index * size) + offset', as represented in
  3491. `(%rcx,%rax,8)', or `[OFFSET](BASE_REG,INDEX_REG[,SIZE])'.
  3492. Return true if the operand was parsed successfully, false
  3493. otherwise. */
  3494. static expr::operation_up
  3495. i386_stap_parse_special_token_three_arg_disp (struct gdbarch *gdbarch,
  3496. struct stap_parse_info *p)
  3497. {
  3498. const char *s = p->arg;
  3499. if (isdigit (*s) || *s == '(' || *s == '-' || *s == '+')
  3500. {
  3501. bool offset_minus = false;
  3502. long offset = 0;
  3503. bool size_minus = false;
  3504. long size = 0;
  3505. const char *start;
  3506. int len_base;
  3507. int len_index;
  3508. if (*s == '+')
  3509. ++s;
  3510. else if (*s == '-')
  3511. {
  3512. ++s;
  3513. offset_minus = true;
  3514. }
  3515. if (offset_minus && !isdigit (*s))
  3516. return {};
  3517. if (isdigit (*s))
  3518. {
  3519. char *endp;
  3520. offset = strtol (s, &endp, 10);
  3521. s = endp;
  3522. }
  3523. if (*s != '(' || s[1] != '%')
  3524. return {};
  3525. s += 2;
  3526. start = s;
  3527. while (isalnum (*s))
  3528. ++s;
  3529. if (*s != ',' || s[1] != '%')
  3530. return {};
  3531. len_base = s - start;
  3532. std::string base (start, len_base);
  3533. if (user_reg_map_name_to_regnum (gdbarch, base.c_str (), len_base) == -1)
  3534. error (_("Invalid register name `%s' on expression `%s'."),
  3535. base.c_str (), p->saved_arg);
  3536. s += 2;
  3537. start = s;
  3538. while (isalnum (*s))
  3539. ++s;
  3540. len_index = s - start;
  3541. std::string index (start, len_index);
  3542. if (user_reg_map_name_to_regnum (gdbarch, index.c_str (),
  3543. len_index) == -1)
  3544. error (_("Invalid register name `%s' on expression `%s'."),
  3545. index.c_str (), p->saved_arg);
  3546. if (*s != ',' && *s != ')')
  3547. return {};
  3548. if (*s == ',')
  3549. {
  3550. char *endp;
  3551. ++s;
  3552. if (*s == '+')
  3553. ++s;
  3554. else if (*s == '-')
  3555. {
  3556. ++s;
  3557. size_minus = true;
  3558. }
  3559. size = strtol (s, &endp, 10);
  3560. s = endp;
  3561. if (*s != ')')
  3562. return {};
  3563. }
  3564. ++s;
  3565. p->arg = s;
  3566. using namespace expr;
  3567. struct type *long_type = builtin_type (gdbarch)->builtin_long;
  3568. operation_up reg = make_operation<register_operation> (std::move (base));
  3569. if (offset != 0)
  3570. {
  3571. if (offset_minus)
  3572. offset = -offset;
  3573. operation_up value
  3574. = make_operation<long_const_operation> (long_type, offset);
  3575. reg = make_operation<add_operation> (std::move (reg),
  3576. std::move (value));
  3577. }
  3578. operation_up ind_reg
  3579. = make_operation<register_operation> (std::move (index));
  3580. if (size != 0)
  3581. {
  3582. if (size_minus)
  3583. size = -size;
  3584. operation_up value
  3585. = make_operation<long_const_operation> (long_type, size);
  3586. ind_reg = make_operation<mul_operation> (std::move (ind_reg),
  3587. std::move (value));
  3588. }
  3589. operation_up sum
  3590. = make_operation<add_operation> (std::move (reg),
  3591. std::move (ind_reg));
  3592. struct type *arg_ptr_type = lookup_pointer_type (p->arg_type);
  3593. sum = make_operation<unop_cast_operation> (std::move (sum),
  3594. arg_ptr_type);
  3595. return make_operation<unop_ind_operation> (std::move (sum));
  3596. }
  3597. return {};
  3598. }
  3599. /* Implementation of `gdbarch_stap_parse_special_token', as defined in
  3600. gdbarch.h. */
  3601. expr::operation_up
  3602. i386_stap_parse_special_token (struct gdbarch *gdbarch,
  3603. struct stap_parse_info *p)
  3604. {
  3605. /* The special tokens to be parsed here are:
  3606. - `register base + (register index * size) + offset', as represented
  3607. in `(%rcx,%rax,8)', or `[OFFSET](BASE_REG,INDEX_REG[,SIZE])'.
  3608. - Operands of the form `-8+3+1(%rbp)', which must be interpreted as
  3609. `*(-8 + 3 - 1 + (void *) $eax)'. */
  3610. expr::operation_up result
  3611. = i386_stap_parse_special_token_triplet (gdbarch, p);
  3612. if (result == nullptr)
  3613. result = i386_stap_parse_special_token_three_arg_disp (gdbarch, p);
  3614. return result;
  3615. }
  3616. /* Implementation of 'gdbarch_stap_adjust_register', as defined in
  3617. gdbarch.h. */
  3618. static std::string
  3619. i386_stap_adjust_register (struct gdbarch *gdbarch, struct stap_parse_info *p,
  3620. const std::string &regname, int regnum)
  3621. {
  3622. static const std::unordered_set<std::string> reg_assoc
  3623. = { "ax", "bx", "cx", "dx",
  3624. "si", "di", "bp", "sp" };
  3625. /* If we are dealing with a register whose size is less than the size
  3626. specified by the "[-]N@" prefix, and it is one of the registers that
  3627. we know has an extended variant available, then use the extended
  3628. version of the register instead. */
  3629. if (register_size (gdbarch, regnum) < TYPE_LENGTH (p->arg_type)
  3630. && reg_assoc.find (regname) != reg_assoc.end ())
  3631. return "e" + regname;
  3632. /* Otherwise, just use the requested register. */
  3633. return regname;
  3634. }
  3635. /* gdbarch gnu_triplet_regexp method. Both arches are acceptable as GDB always
  3636. also supplies -m64 or -m32 by gdbarch_gcc_target_options. */
  3637. static const char *
  3638. i386_gnu_triplet_regexp (struct gdbarch *gdbarch)
  3639. {
  3640. return "(x86_64|i.86)";
  3641. }
  3642. /* Implement the "in_indirect_branch_thunk" gdbarch function. */
  3643. static bool
  3644. i386_in_indirect_branch_thunk (struct gdbarch *gdbarch, CORE_ADDR pc)
  3645. {
  3646. return x86_in_indirect_branch_thunk (pc, i386_register_names,
  3647. I386_EAX_REGNUM, I386_EIP_REGNUM);
  3648. }
  3649. /* Generic ELF. */
  3650. void
  3651. i386_elf_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  3652. {
  3653. static const char *const stap_integer_prefixes[] = { "$", NULL };
  3654. static const char *const stap_register_prefixes[] = { "%", NULL };
  3655. static const char *const stap_register_indirection_prefixes[] = { "(",
  3656. NULL };
  3657. static const char *const stap_register_indirection_suffixes[] = { ")",
  3658. NULL };
  3659. /* We typically use stabs-in-ELF with the SVR4 register numbering. */
  3660. set_gdbarch_stab_reg_to_regnum (gdbarch, i386_svr4_reg_to_regnum);
  3661. /* Registering SystemTap handlers. */
  3662. set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes);
  3663. set_gdbarch_stap_register_prefixes (gdbarch, stap_register_prefixes);
  3664. set_gdbarch_stap_register_indirection_prefixes (gdbarch,
  3665. stap_register_indirection_prefixes);
  3666. set_gdbarch_stap_register_indirection_suffixes (gdbarch,
  3667. stap_register_indirection_suffixes);
  3668. set_gdbarch_stap_is_single_operand (gdbarch,
  3669. i386_stap_is_single_operand);
  3670. set_gdbarch_stap_parse_special_token (gdbarch,
  3671. i386_stap_parse_special_token);
  3672. set_gdbarch_stap_adjust_register (gdbarch,
  3673. i386_stap_adjust_register);
  3674. set_gdbarch_in_indirect_branch_thunk (gdbarch,
  3675. i386_in_indirect_branch_thunk);
  3676. }
  3677. /* System V Release 4 (SVR4). */
  3678. void
  3679. i386_svr4_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  3680. {
  3681. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  3682. /* System V Release 4 uses ELF. */
  3683. i386_elf_init_abi (info, gdbarch);
  3684. /* System V Release 4 has shared libraries. */
  3685. set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
  3686. tdep->sigtramp_p = i386_svr4_sigtramp_p;
  3687. tdep->sigcontext_addr = i386_svr4_sigcontext_addr;
  3688. tdep->sc_pc_offset = 36 + 14 * 4;
  3689. tdep->sc_sp_offset = 36 + 17 * 4;
  3690. tdep->jb_pc_offset = 20;
  3691. }
  3692. /* i386 register groups. In addition to the normal groups, add "mmx"
  3693. and "sse". */
  3694. static const reggroup *i386_sse_reggroup;
  3695. static const reggroup *i386_mmx_reggroup;
  3696. static void
  3697. i386_init_reggroups (void)
  3698. {
  3699. i386_sse_reggroup = reggroup_new ("sse", USER_REGGROUP);
  3700. i386_mmx_reggroup = reggroup_new ("mmx", USER_REGGROUP);
  3701. }
  3702. static void
  3703. i386_add_reggroups (struct gdbarch *gdbarch)
  3704. {
  3705. reggroup_add (gdbarch, i386_sse_reggroup);
  3706. reggroup_add (gdbarch, i386_mmx_reggroup);
  3707. }
  3708. int
  3709. i386_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
  3710. const struct reggroup *group)
  3711. {
  3712. const i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  3713. int fp_regnum_p, mmx_regnum_p, xmm_regnum_p, mxcsr_regnum_p,
  3714. ymm_regnum_p, ymmh_regnum_p, ymm_avx512_regnum_p, ymmh_avx512_regnum_p,
  3715. bndr_regnum_p, bnd_regnum_p, zmm_regnum_p, zmmh_regnum_p,
  3716. mpx_ctrl_regnum_p, xmm_avx512_regnum_p,
  3717. avx512_p, avx_p, sse_p, pkru_regnum_p;
  3718. /* Don't include pseudo registers, except for MMX, in any register
  3719. groups. */
  3720. if (i386_byte_regnum_p (gdbarch, regnum))
  3721. return 0;
  3722. if (i386_word_regnum_p (gdbarch, regnum))
  3723. return 0;
  3724. if (i386_dword_regnum_p (gdbarch, regnum))
  3725. return 0;
  3726. mmx_regnum_p = i386_mmx_regnum_p (gdbarch, regnum);
  3727. if (group == i386_mmx_reggroup)
  3728. return mmx_regnum_p;
  3729. pkru_regnum_p = i386_pkru_regnum_p(gdbarch, regnum);
  3730. xmm_regnum_p = i386_xmm_regnum_p (gdbarch, regnum);
  3731. xmm_avx512_regnum_p = i386_xmm_avx512_regnum_p (gdbarch, regnum);
  3732. mxcsr_regnum_p = i386_mxcsr_regnum_p (gdbarch, regnum);
  3733. if (group == i386_sse_reggroup)
  3734. return xmm_regnum_p || xmm_avx512_regnum_p || mxcsr_regnum_p;
  3735. ymm_regnum_p = i386_ymm_regnum_p (gdbarch, regnum);
  3736. ymm_avx512_regnum_p = i386_ymm_avx512_regnum_p (gdbarch, regnum);
  3737. zmm_regnum_p = i386_zmm_regnum_p (gdbarch, regnum);
  3738. avx512_p = ((tdep->xcr0 & X86_XSTATE_AVX_AVX512_MASK)
  3739. == X86_XSTATE_AVX_AVX512_MASK);
  3740. avx_p = ((tdep->xcr0 & X86_XSTATE_AVX_AVX512_MASK)
  3741. == X86_XSTATE_AVX_MASK) && !avx512_p;
  3742. sse_p = ((tdep->xcr0 & X86_XSTATE_AVX_AVX512_MASK)
  3743. == X86_XSTATE_SSE_MASK) && !avx512_p && ! avx_p;
  3744. if (group == vector_reggroup)
  3745. return (mmx_regnum_p
  3746. || (zmm_regnum_p && avx512_p)
  3747. || ((ymm_regnum_p || ymm_avx512_regnum_p) && avx_p)
  3748. || ((xmm_regnum_p || xmm_avx512_regnum_p) && sse_p)
  3749. || mxcsr_regnum_p);
  3750. fp_regnum_p = (i386_fp_regnum_p (gdbarch, regnum)
  3751. || i386_fpc_regnum_p (gdbarch, regnum));
  3752. if (group == float_reggroup)
  3753. return fp_regnum_p;
  3754. /* For "info reg all", don't include upper YMM registers nor XMM
  3755. registers when AVX is supported. */
  3756. ymmh_regnum_p = i386_ymmh_regnum_p (gdbarch, regnum);
  3757. ymmh_avx512_regnum_p = i386_ymmh_avx512_regnum_p (gdbarch, regnum);
  3758. zmmh_regnum_p = i386_zmmh_regnum_p (gdbarch, regnum);
  3759. if (group == all_reggroup
  3760. && (((xmm_regnum_p || xmm_avx512_regnum_p) && !sse_p)
  3761. || ((ymm_regnum_p || ymm_avx512_regnum_p) && !avx_p)
  3762. || ymmh_regnum_p
  3763. || ymmh_avx512_regnum_p
  3764. || zmmh_regnum_p))
  3765. return 0;
  3766. bnd_regnum_p = i386_bnd_regnum_p (gdbarch, regnum);
  3767. if (group == all_reggroup
  3768. && ((bnd_regnum_p && (tdep->xcr0 & X86_XSTATE_MPX_MASK))))
  3769. return bnd_regnum_p;
  3770. bndr_regnum_p = i386_bndr_regnum_p (gdbarch, regnum);
  3771. if (group == all_reggroup
  3772. && ((bndr_regnum_p && (tdep->xcr0 & X86_XSTATE_MPX_MASK))))
  3773. return 0;
  3774. mpx_ctrl_regnum_p = i386_mpx_ctrl_regnum_p (gdbarch, regnum);
  3775. if (group == all_reggroup
  3776. && ((mpx_ctrl_regnum_p && (tdep->xcr0 & X86_XSTATE_MPX_MASK))))
  3777. return mpx_ctrl_regnum_p;
  3778. if (group == general_reggroup)
  3779. return (!fp_regnum_p
  3780. && !mmx_regnum_p
  3781. && !mxcsr_regnum_p
  3782. && !xmm_regnum_p
  3783. && !xmm_avx512_regnum_p
  3784. && !ymm_regnum_p
  3785. && !ymmh_regnum_p
  3786. && !ymm_avx512_regnum_p
  3787. && !ymmh_avx512_regnum_p
  3788. && !bndr_regnum_p
  3789. && !bnd_regnum_p
  3790. && !mpx_ctrl_regnum_p
  3791. && !zmm_regnum_p
  3792. && !zmmh_regnum_p
  3793. && !pkru_regnum_p);
  3794. return default_register_reggroup_p (gdbarch, regnum, group);
  3795. }
  3796. /* Get the ARGIth function argument for the current function. */
  3797. static CORE_ADDR
  3798. i386_fetch_pointer_argument (struct frame_info *frame, int argi,
  3799. struct type *type)
  3800. {
  3801. struct gdbarch *gdbarch = get_frame_arch (frame);
  3802. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  3803. CORE_ADDR sp = get_frame_register_unsigned (frame, I386_ESP_REGNUM);
  3804. return read_memory_unsigned_integer (sp + (4 * (argi + 1)), 4, byte_order);
  3805. }
  3806. #define PREFIX_REPZ 0x01
  3807. #define PREFIX_REPNZ 0x02
  3808. #define PREFIX_LOCK 0x04
  3809. #define PREFIX_DATA 0x08
  3810. #define PREFIX_ADDR 0x10
  3811. /* operand size */
  3812. enum
  3813. {
  3814. OT_BYTE = 0,
  3815. OT_WORD,
  3816. OT_LONG,
  3817. OT_QUAD,
  3818. OT_DQUAD,
  3819. };
  3820. /* i386 arith/logic operations */
  3821. enum
  3822. {
  3823. OP_ADDL,
  3824. OP_ORL,
  3825. OP_ADCL,
  3826. OP_SBBL,
  3827. OP_ANDL,
  3828. OP_SUBL,
  3829. OP_XORL,
  3830. OP_CMPL,
  3831. };
  3832. struct i386_record_s
  3833. {
  3834. struct gdbarch *gdbarch;
  3835. struct regcache *regcache;
  3836. CORE_ADDR orig_addr;
  3837. CORE_ADDR addr;
  3838. int aflag;
  3839. int dflag;
  3840. int override;
  3841. uint8_t modrm;
  3842. uint8_t mod, reg, rm;
  3843. int ot;
  3844. uint8_t rex_x;
  3845. uint8_t rex_b;
  3846. int rip_offset;
  3847. int popl_esp_hack;
  3848. const int *regmap;
  3849. };
  3850. /* Parse the "modrm" part of the memory address irp->addr points at.
  3851. Returns -1 if something goes wrong, 0 otherwise. */
  3852. static int
  3853. i386_record_modrm (struct i386_record_s *irp)
  3854. {
  3855. struct gdbarch *gdbarch = irp->gdbarch;
  3856. if (record_read_memory (gdbarch, irp->addr, &irp->modrm, 1))
  3857. return -1;
  3858. irp->addr++;
  3859. irp->mod = (irp->modrm >> 6) & 3;
  3860. irp->reg = (irp->modrm >> 3) & 7;
  3861. irp->rm = irp->modrm & 7;
  3862. return 0;
  3863. }
  3864. /* Extract the memory address that the current instruction writes to,
  3865. and return it in *ADDR. Return -1 if something goes wrong. */
  3866. static int
  3867. i386_record_lea_modrm_addr (struct i386_record_s *irp, uint64_t *addr)
  3868. {
  3869. struct gdbarch *gdbarch = irp->gdbarch;
  3870. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  3871. gdb_byte buf[4];
  3872. ULONGEST offset64;
  3873. *addr = 0;
  3874. if (irp->aflag || irp->regmap[X86_RECORD_R8_REGNUM])
  3875. {
  3876. /* 32/64 bits */
  3877. int havesib = 0;
  3878. uint8_t scale = 0;
  3879. uint8_t byte;
  3880. uint8_t index = 0;
  3881. uint8_t base = irp->rm;
  3882. if (base == 4)
  3883. {
  3884. havesib = 1;
  3885. if (record_read_memory (gdbarch, irp->addr, &byte, 1))
  3886. return -1;
  3887. irp->addr++;
  3888. scale = (byte >> 6) & 3;
  3889. index = ((byte >> 3) & 7) | irp->rex_x;
  3890. base = (byte & 7);
  3891. }
  3892. base |= irp->rex_b;
  3893. switch (irp->mod)
  3894. {
  3895. case 0:
  3896. if ((base & 7) == 5)
  3897. {
  3898. base = 0xff;
  3899. if (record_read_memory (gdbarch, irp->addr, buf, 4))
  3900. return -1;
  3901. irp->addr += 4;
  3902. *addr = extract_signed_integer (buf, 4, byte_order);
  3903. if (irp->regmap[X86_RECORD_R8_REGNUM] && !havesib)
  3904. *addr += irp->addr + irp->rip_offset;
  3905. }
  3906. break;
  3907. case 1:
  3908. if (record_read_memory (gdbarch, irp->addr, buf, 1))
  3909. return -1;
  3910. irp->addr++;
  3911. *addr = (int8_t) buf[0];
  3912. break;
  3913. case 2:
  3914. if (record_read_memory (gdbarch, irp->addr, buf, 4))
  3915. return -1;
  3916. *addr = extract_signed_integer (buf, 4, byte_order);
  3917. irp->addr += 4;
  3918. break;
  3919. }
  3920. offset64 = 0;
  3921. if (base != 0xff)
  3922. {
  3923. if (base == 4 && irp->popl_esp_hack)
  3924. *addr += irp->popl_esp_hack;
  3925. regcache_raw_read_unsigned (irp->regcache, irp->regmap[base],
  3926. &offset64);
  3927. }
  3928. if (irp->aflag == 2)
  3929. {
  3930. *addr += offset64;
  3931. }
  3932. else
  3933. *addr = (uint32_t) (offset64 + *addr);
  3934. if (havesib && (index != 4 || scale != 0))
  3935. {
  3936. regcache_raw_read_unsigned (irp->regcache, irp->regmap[index],
  3937. &offset64);
  3938. if (irp->aflag == 2)
  3939. *addr += offset64 << scale;
  3940. else
  3941. *addr = (uint32_t) (*addr + (offset64 << scale));
  3942. }
  3943. if (!irp->aflag)
  3944. {
  3945. /* Since we are in 64-bit mode with ADDR32 prefix, zero-extend
  3946. address from 32-bit to 64-bit. */
  3947. *addr = (uint32_t) *addr;
  3948. }
  3949. }
  3950. else
  3951. {
  3952. /* 16 bits */
  3953. switch (irp->mod)
  3954. {
  3955. case 0:
  3956. if (irp->rm == 6)
  3957. {
  3958. if (record_read_memory (gdbarch, irp->addr, buf, 2))
  3959. return -1;
  3960. irp->addr += 2;
  3961. *addr = extract_signed_integer (buf, 2, byte_order);
  3962. irp->rm = 0;
  3963. goto no_rm;
  3964. }
  3965. break;
  3966. case 1:
  3967. if (record_read_memory (gdbarch, irp->addr, buf, 1))
  3968. return -1;
  3969. irp->addr++;
  3970. *addr = (int8_t) buf[0];
  3971. break;
  3972. case 2:
  3973. if (record_read_memory (gdbarch, irp->addr, buf, 2))
  3974. return -1;
  3975. irp->addr += 2;
  3976. *addr = extract_signed_integer (buf, 2, byte_order);
  3977. break;
  3978. }
  3979. switch (irp->rm)
  3980. {
  3981. case 0:
  3982. regcache_raw_read_unsigned (irp->regcache,
  3983. irp->regmap[X86_RECORD_REBX_REGNUM],
  3984. &offset64);
  3985. *addr = (uint32_t) (*addr + offset64);
  3986. regcache_raw_read_unsigned (irp->regcache,
  3987. irp->regmap[X86_RECORD_RESI_REGNUM],
  3988. &offset64);
  3989. *addr = (uint32_t) (*addr + offset64);
  3990. break;
  3991. case 1:
  3992. regcache_raw_read_unsigned (irp->regcache,
  3993. irp->regmap[X86_RECORD_REBX_REGNUM],
  3994. &offset64);
  3995. *addr = (uint32_t) (*addr + offset64);
  3996. regcache_raw_read_unsigned (irp->regcache,
  3997. irp->regmap[X86_RECORD_REDI_REGNUM],
  3998. &offset64);
  3999. *addr = (uint32_t) (*addr + offset64);
  4000. break;
  4001. case 2:
  4002. regcache_raw_read_unsigned (irp->regcache,
  4003. irp->regmap[X86_RECORD_REBP_REGNUM],
  4004. &offset64);
  4005. *addr = (uint32_t) (*addr + offset64);
  4006. regcache_raw_read_unsigned (irp->regcache,
  4007. irp->regmap[X86_RECORD_RESI_REGNUM],
  4008. &offset64);
  4009. *addr = (uint32_t) (*addr + offset64);
  4010. break;
  4011. case 3:
  4012. regcache_raw_read_unsigned (irp->regcache,
  4013. irp->regmap[X86_RECORD_REBP_REGNUM],
  4014. &offset64);
  4015. *addr = (uint32_t) (*addr + offset64);
  4016. regcache_raw_read_unsigned (irp->regcache,
  4017. irp->regmap[X86_RECORD_REDI_REGNUM],
  4018. &offset64);
  4019. *addr = (uint32_t) (*addr + offset64);
  4020. break;
  4021. case 4:
  4022. regcache_raw_read_unsigned (irp->regcache,
  4023. irp->regmap[X86_RECORD_RESI_REGNUM],
  4024. &offset64);
  4025. *addr = (uint32_t) (*addr + offset64);
  4026. break;
  4027. case 5:
  4028. regcache_raw_read_unsigned (irp->regcache,
  4029. irp->regmap[X86_RECORD_REDI_REGNUM],
  4030. &offset64);
  4031. *addr = (uint32_t) (*addr + offset64);
  4032. break;
  4033. case 6:
  4034. regcache_raw_read_unsigned (irp->regcache,
  4035. irp->regmap[X86_RECORD_REBP_REGNUM],
  4036. &offset64);
  4037. *addr = (uint32_t) (*addr + offset64);
  4038. break;
  4039. case 7:
  4040. regcache_raw_read_unsigned (irp->regcache,
  4041. irp->regmap[X86_RECORD_REBX_REGNUM],
  4042. &offset64);
  4043. *addr = (uint32_t) (*addr + offset64);
  4044. break;
  4045. }
  4046. *addr &= 0xffff;
  4047. }
  4048. no_rm:
  4049. return 0;
  4050. }
  4051. /* Record the address and contents of the memory that will be changed
  4052. by the current instruction. Return -1 if something goes wrong, 0
  4053. otherwise. */
  4054. static int
  4055. i386_record_lea_modrm (struct i386_record_s *irp)
  4056. {
  4057. struct gdbarch *gdbarch = irp->gdbarch;
  4058. uint64_t addr;
  4059. if (irp->override >= 0)
  4060. {
  4061. if (record_full_memory_query)
  4062. {
  4063. if (yquery (_("\
  4064. Process record ignores the memory change of instruction at address %s\n\
  4065. because it can't get the value of the segment register.\n\
  4066. Do you want to stop the program?"),
  4067. paddress (gdbarch, irp->orig_addr)))
  4068. return -1;
  4069. }
  4070. return 0;
  4071. }
  4072. if (i386_record_lea_modrm_addr (irp, &addr))
  4073. return -1;
  4074. if (record_full_arch_list_add_mem (addr, 1 << irp->ot))
  4075. return -1;
  4076. return 0;
  4077. }
  4078. /* Record the effects of a push operation. Return -1 if something
  4079. goes wrong, 0 otherwise. */
  4080. static int
  4081. i386_record_push (struct i386_record_s *irp, int size)
  4082. {
  4083. ULONGEST addr;
  4084. if (record_full_arch_list_add_reg (irp->regcache,
  4085. irp->regmap[X86_RECORD_RESP_REGNUM]))
  4086. return -1;
  4087. regcache_raw_read_unsigned (irp->regcache,
  4088. irp->regmap[X86_RECORD_RESP_REGNUM],
  4089. &addr);
  4090. if (record_full_arch_list_add_mem ((CORE_ADDR) addr - size, size))
  4091. return -1;
  4092. return 0;
  4093. }
  4094. /* Defines contents to record. */
  4095. #define I386_SAVE_FPU_REGS 0xfffd
  4096. #define I386_SAVE_FPU_ENV 0xfffe
  4097. #define I386_SAVE_FPU_ENV_REG_STACK 0xffff
  4098. /* Record the values of the floating point registers which will be
  4099. changed by the current instruction. Returns -1 if something is
  4100. wrong, 0 otherwise. */
  4101. static int i386_record_floats (struct gdbarch *gdbarch,
  4102. struct i386_record_s *ir,
  4103. uint32_t iregnum)
  4104. {
  4105. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  4106. int i;
  4107. /* Oza: Because of floating point insn push/pop of fpu stack is going to
  4108. happen. Currently we store st0-st7 registers, but we need not store all
  4109. registers all the time, in future we use ftag register and record only
  4110. those who are not marked as an empty. */
  4111. if (I386_SAVE_FPU_REGS == iregnum)
  4112. {
  4113. for (i = I387_ST0_REGNUM (tdep); i <= I387_ST0_REGNUM (tdep) + 7; i++)
  4114. {
  4115. if (record_full_arch_list_add_reg (ir->regcache, i))
  4116. return -1;
  4117. }
  4118. }
  4119. else if (I386_SAVE_FPU_ENV == iregnum)
  4120. {
  4121. for (i = I387_FCTRL_REGNUM (tdep); i <= I387_FOP_REGNUM (tdep); i++)
  4122. {
  4123. if (record_full_arch_list_add_reg (ir->regcache, i))
  4124. return -1;
  4125. }
  4126. }
  4127. else if (I386_SAVE_FPU_ENV_REG_STACK == iregnum)
  4128. {
  4129. for (i = I387_ST0_REGNUM (tdep); i <= I387_FOP_REGNUM (tdep); i++)
  4130. if (record_full_arch_list_add_reg (ir->regcache, i))
  4131. return -1;
  4132. }
  4133. else if ((iregnum >= I387_ST0_REGNUM (tdep)) &&
  4134. (iregnum <= I387_FOP_REGNUM (tdep)))
  4135. {
  4136. if (record_full_arch_list_add_reg (ir->regcache,iregnum))
  4137. return -1;
  4138. }
  4139. else
  4140. {
  4141. /* Parameter error. */
  4142. return -1;
  4143. }
  4144. if(I386_SAVE_FPU_ENV != iregnum)
  4145. {
  4146. for (i = I387_FCTRL_REGNUM (tdep); i <= I387_FOP_REGNUM (tdep); i++)
  4147. {
  4148. if (record_full_arch_list_add_reg (ir->regcache, i))
  4149. return -1;
  4150. }
  4151. }
  4152. return 0;
  4153. }
  4154. /* Parse the current instruction, and record the values of the
  4155. registers and memory that will be changed by the current
  4156. instruction. Returns -1 if something goes wrong, 0 otherwise. */
  4157. #define I386_RECORD_FULL_ARCH_LIST_ADD_REG(regnum) \
  4158. record_full_arch_list_add_reg (ir.regcache, ir.regmap[(regnum)])
  4159. int
  4160. i386_process_record (struct gdbarch *gdbarch, struct regcache *regcache,
  4161. CORE_ADDR input_addr)
  4162. {
  4163. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  4164. int prefixes = 0;
  4165. int regnum = 0;
  4166. uint32_t opcode;
  4167. uint8_t opcode8;
  4168. ULONGEST addr;
  4169. gdb_byte buf[I386_MAX_REGISTER_SIZE];
  4170. struct i386_record_s ir;
  4171. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  4172. uint8_t rex_w = -1;
  4173. uint8_t rex_r = 0;
  4174. memset (&ir, 0, sizeof (struct i386_record_s));
  4175. ir.regcache = regcache;
  4176. ir.addr = input_addr;
  4177. ir.orig_addr = input_addr;
  4178. ir.aflag = 1;
  4179. ir.dflag = 1;
  4180. ir.override = -1;
  4181. ir.popl_esp_hack = 0;
  4182. ir.regmap = tdep->record_regmap;
  4183. ir.gdbarch = gdbarch;
  4184. if (record_debug > 1)
  4185. gdb_printf (gdb_stdlog, "Process record: i386_process_record "
  4186. "addr = %s\n",
  4187. paddress (gdbarch, ir.addr));
  4188. /* prefixes */
  4189. while (1)
  4190. {
  4191. if (record_read_memory (gdbarch, ir.addr, &opcode8, 1))
  4192. return -1;
  4193. ir.addr++;
  4194. switch (opcode8) /* Instruction prefixes */
  4195. {
  4196. case REPE_PREFIX_OPCODE:
  4197. prefixes |= PREFIX_REPZ;
  4198. break;
  4199. case REPNE_PREFIX_OPCODE:
  4200. prefixes |= PREFIX_REPNZ;
  4201. break;
  4202. case LOCK_PREFIX_OPCODE:
  4203. prefixes |= PREFIX_LOCK;
  4204. break;
  4205. case CS_PREFIX_OPCODE:
  4206. ir.override = X86_RECORD_CS_REGNUM;
  4207. break;
  4208. case SS_PREFIX_OPCODE:
  4209. ir.override = X86_RECORD_SS_REGNUM;
  4210. break;
  4211. case DS_PREFIX_OPCODE:
  4212. ir.override = X86_RECORD_DS_REGNUM;
  4213. break;
  4214. case ES_PREFIX_OPCODE:
  4215. ir.override = X86_RECORD_ES_REGNUM;
  4216. break;
  4217. case FS_PREFIX_OPCODE:
  4218. ir.override = X86_RECORD_FS_REGNUM;
  4219. break;
  4220. case GS_PREFIX_OPCODE:
  4221. ir.override = X86_RECORD_GS_REGNUM;
  4222. break;
  4223. case DATA_PREFIX_OPCODE:
  4224. prefixes |= PREFIX_DATA;
  4225. break;
  4226. case ADDR_PREFIX_OPCODE:
  4227. prefixes |= PREFIX_ADDR;
  4228. break;
  4229. case 0x40: /* i386 inc %eax */
  4230. case 0x41: /* i386 inc %ecx */
  4231. case 0x42: /* i386 inc %edx */
  4232. case 0x43: /* i386 inc %ebx */
  4233. case 0x44: /* i386 inc %esp */
  4234. case 0x45: /* i386 inc %ebp */
  4235. case 0x46: /* i386 inc %esi */
  4236. case 0x47: /* i386 inc %edi */
  4237. case 0x48: /* i386 dec %eax */
  4238. case 0x49: /* i386 dec %ecx */
  4239. case 0x4a: /* i386 dec %edx */
  4240. case 0x4b: /* i386 dec %ebx */
  4241. case 0x4c: /* i386 dec %esp */
  4242. case 0x4d: /* i386 dec %ebp */
  4243. case 0x4e: /* i386 dec %esi */
  4244. case 0x4f: /* i386 dec %edi */
  4245. if (ir.regmap[X86_RECORD_R8_REGNUM]) /* 64 bit target */
  4246. {
  4247. /* REX */
  4248. rex_w = (opcode8 >> 3) & 1;
  4249. rex_r = (opcode8 & 0x4) << 1;
  4250. ir.rex_x = (opcode8 & 0x2) << 2;
  4251. ir.rex_b = (opcode8 & 0x1) << 3;
  4252. }
  4253. else /* 32 bit target */
  4254. goto out_prefixes;
  4255. break;
  4256. default:
  4257. goto out_prefixes;
  4258. break;
  4259. }
  4260. }
  4261. out_prefixes:
  4262. if (ir.regmap[X86_RECORD_R8_REGNUM] && rex_w == 1)
  4263. {
  4264. ir.dflag = 2;
  4265. }
  4266. else
  4267. {
  4268. if (prefixes & PREFIX_DATA)
  4269. ir.dflag ^= 1;
  4270. }
  4271. if (prefixes & PREFIX_ADDR)
  4272. ir.aflag ^= 1;
  4273. else if (ir.regmap[X86_RECORD_R8_REGNUM])
  4274. ir.aflag = 2;
  4275. /* Now check op code. */
  4276. opcode = (uint32_t) opcode8;
  4277. reswitch:
  4278. switch (opcode)
  4279. {
  4280. case 0x0f:
  4281. if (record_read_memory (gdbarch, ir.addr, &opcode8, 1))
  4282. return -1;
  4283. ir.addr++;
  4284. opcode = (uint32_t) opcode8 | 0x0f00;
  4285. goto reswitch;
  4286. break;
  4287. case 0x00: /* arith & logic */
  4288. case 0x01:
  4289. case 0x02:
  4290. case 0x03:
  4291. case 0x04:
  4292. case 0x05:
  4293. case 0x08:
  4294. case 0x09:
  4295. case 0x0a:
  4296. case 0x0b:
  4297. case 0x0c:
  4298. case 0x0d:
  4299. case 0x10:
  4300. case 0x11:
  4301. case 0x12:
  4302. case 0x13:
  4303. case 0x14:
  4304. case 0x15:
  4305. case 0x18:
  4306. case 0x19:
  4307. case 0x1a:
  4308. case 0x1b:
  4309. case 0x1c:
  4310. case 0x1d:
  4311. case 0x20:
  4312. case 0x21:
  4313. case 0x22:
  4314. case 0x23:
  4315. case 0x24:
  4316. case 0x25:
  4317. case 0x28:
  4318. case 0x29:
  4319. case 0x2a:
  4320. case 0x2b:
  4321. case 0x2c:
  4322. case 0x2d:
  4323. case 0x30:
  4324. case 0x31:
  4325. case 0x32:
  4326. case 0x33:
  4327. case 0x34:
  4328. case 0x35:
  4329. case 0x38:
  4330. case 0x39:
  4331. case 0x3a:
  4332. case 0x3b:
  4333. case 0x3c:
  4334. case 0x3d:
  4335. if (((opcode >> 3) & 7) != OP_CMPL)
  4336. {
  4337. if ((opcode & 1) == 0)
  4338. ir.ot = OT_BYTE;
  4339. else
  4340. ir.ot = ir.dflag + OT_WORD;
  4341. switch ((opcode >> 1) & 3)
  4342. {
  4343. case 0: /* OP Ev, Gv */
  4344. if (i386_record_modrm (&ir))
  4345. return -1;
  4346. if (ir.mod != 3)
  4347. {
  4348. if (i386_record_lea_modrm (&ir))
  4349. return -1;
  4350. }
  4351. else
  4352. {
  4353. ir.rm |= ir.rex_b;
  4354. if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
  4355. ir.rm &= 0x3;
  4356. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
  4357. }
  4358. break;
  4359. case 1: /* OP Gv, Ev */
  4360. if (i386_record_modrm (&ir))
  4361. return -1;
  4362. ir.reg |= rex_r;
  4363. if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
  4364. ir.reg &= 0x3;
  4365. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
  4366. break;
  4367. case 2: /* OP A, Iv */
  4368. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
  4369. break;
  4370. }
  4371. }
  4372. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4373. break;
  4374. case 0x80: /* GRP1 */
  4375. case 0x81:
  4376. case 0x82:
  4377. case 0x83:
  4378. if (i386_record_modrm (&ir))
  4379. return -1;
  4380. if (ir.reg != OP_CMPL)
  4381. {
  4382. if ((opcode & 1) == 0)
  4383. ir.ot = OT_BYTE;
  4384. else
  4385. ir.ot = ir.dflag + OT_WORD;
  4386. if (ir.mod != 3)
  4387. {
  4388. if (opcode == 0x83)
  4389. ir.rip_offset = 1;
  4390. else
  4391. ir.rip_offset = (ir.ot > OT_LONG) ? 4 : (1 << ir.ot);
  4392. if (i386_record_lea_modrm (&ir))
  4393. return -1;
  4394. }
  4395. else
  4396. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
  4397. }
  4398. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4399. break;
  4400. case 0x40: /* inc */
  4401. case 0x41:
  4402. case 0x42:
  4403. case 0x43:
  4404. case 0x44:
  4405. case 0x45:
  4406. case 0x46:
  4407. case 0x47:
  4408. case 0x48: /* dec */
  4409. case 0x49:
  4410. case 0x4a:
  4411. case 0x4b:
  4412. case 0x4c:
  4413. case 0x4d:
  4414. case 0x4e:
  4415. case 0x4f:
  4416. I386_RECORD_FULL_ARCH_LIST_ADD_REG (opcode & 7);
  4417. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4418. break;
  4419. case 0xf6: /* GRP3 */
  4420. case 0xf7:
  4421. if ((opcode & 1) == 0)
  4422. ir.ot = OT_BYTE;
  4423. else
  4424. ir.ot = ir.dflag + OT_WORD;
  4425. if (i386_record_modrm (&ir))
  4426. return -1;
  4427. if (ir.mod != 3 && ir.reg == 0)
  4428. ir.rip_offset = (ir.ot > OT_LONG) ? 4 : (1 << ir.ot);
  4429. switch (ir.reg)
  4430. {
  4431. case 0: /* test */
  4432. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4433. break;
  4434. case 2: /* not */
  4435. case 3: /* neg */
  4436. if (ir.mod != 3)
  4437. {
  4438. if (i386_record_lea_modrm (&ir))
  4439. return -1;
  4440. }
  4441. else
  4442. {
  4443. ir.rm |= ir.rex_b;
  4444. if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
  4445. ir.rm &= 0x3;
  4446. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
  4447. }
  4448. if (ir.reg == 3) /* neg */
  4449. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4450. break;
  4451. case 4: /* mul */
  4452. case 5: /* imul */
  4453. case 6: /* div */
  4454. case 7: /* idiv */
  4455. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
  4456. if (ir.ot != OT_BYTE)
  4457. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
  4458. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4459. break;
  4460. default:
  4461. ir.addr -= 2;
  4462. opcode = opcode << 8 | ir.modrm;
  4463. goto no_support;
  4464. break;
  4465. }
  4466. break;
  4467. case 0xfe: /* GRP4 */
  4468. case 0xff: /* GRP5 */
  4469. if (i386_record_modrm (&ir))
  4470. return -1;
  4471. if (ir.reg >= 2 && opcode == 0xfe)
  4472. {
  4473. ir.addr -= 2;
  4474. opcode = opcode << 8 | ir.modrm;
  4475. goto no_support;
  4476. }
  4477. switch (ir.reg)
  4478. {
  4479. case 0: /* inc */
  4480. case 1: /* dec */
  4481. if ((opcode & 1) == 0)
  4482. ir.ot = OT_BYTE;
  4483. else
  4484. ir.ot = ir.dflag + OT_WORD;
  4485. if (ir.mod != 3)
  4486. {
  4487. if (i386_record_lea_modrm (&ir))
  4488. return -1;
  4489. }
  4490. else
  4491. {
  4492. ir.rm |= ir.rex_b;
  4493. if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
  4494. ir.rm &= 0x3;
  4495. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
  4496. }
  4497. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4498. break;
  4499. case 2: /* call */
  4500. if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
  4501. ir.dflag = 2;
  4502. if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
  4503. return -1;
  4504. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4505. break;
  4506. case 3: /* lcall */
  4507. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_CS_REGNUM);
  4508. if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
  4509. return -1;
  4510. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4511. break;
  4512. case 4: /* jmp */
  4513. case 5: /* ljmp */
  4514. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4515. break;
  4516. case 6: /* push */
  4517. if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
  4518. ir.dflag = 2;
  4519. if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
  4520. return -1;
  4521. break;
  4522. default:
  4523. ir.addr -= 2;
  4524. opcode = opcode << 8 | ir.modrm;
  4525. goto no_support;
  4526. break;
  4527. }
  4528. break;
  4529. case 0x84: /* test */
  4530. case 0x85:
  4531. case 0xa8:
  4532. case 0xa9:
  4533. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4534. break;
  4535. case 0x98: /* CWDE/CBW */
  4536. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
  4537. break;
  4538. case 0x99: /* CDQ/CWD */
  4539. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
  4540. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
  4541. break;
  4542. case 0x0faf: /* imul */
  4543. case 0x69:
  4544. case 0x6b:
  4545. ir.ot = ir.dflag + OT_WORD;
  4546. if (i386_record_modrm (&ir))
  4547. return -1;
  4548. if (opcode == 0x69)
  4549. ir.rip_offset = (ir.ot > OT_LONG) ? 4 : (1 << ir.ot);
  4550. else if (opcode == 0x6b)
  4551. ir.rip_offset = 1;
  4552. ir.reg |= rex_r;
  4553. if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
  4554. ir.reg &= 0x3;
  4555. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
  4556. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4557. break;
  4558. case 0x0fc0: /* xadd */
  4559. case 0x0fc1:
  4560. if ((opcode & 1) == 0)
  4561. ir.ot = OT_BYTE;
  4562. else
  4563. ir.ot = ir.dflag + OT_WORD;
  4564. if (i386_record_modrm (&ir))
  4565. return -1;
  4566. ir.reg |= rex_r;
  4567. if (ir.mod == 3)
  4568. {
  4569. if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
  4570. ir.reg &= 0x3;
  4571. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
  4572. if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
  4573. ir.rm &= 0x3;
  4574. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
  4575. }
  4576. else
  4577. {
  4578. if (i386_record_lea_modrm (&ir))
  4579. return -1;
  4580. if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
  4581. ir.reg &= 0x3;
  4582. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
  4583. }
  4584. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4585. break;
  4586. case 0x0fb0: /* cmpxchg */
  4587. case 0x0fb1:
  4588. if ((opcode & 1) == 0)
  4589. ir.ot = OT_BYTE;
  4590. else
  4591. ir.ot = ir.dflag + OT_WORD;
  4592. if (i386_record_modrm (&ir))
  4593. return -1;
  4594. if (ir.mod == 3)
  4595. {
  4596. ir.reg |= rex_r;
  4597. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
  4598. if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
  4599. ir.reg &= 0x3;
  4600. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
  4601. }
  4602. else
  4603. {
  4604. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
  4605. if (i386_record_lea_modrm (&ir))
  4606. return -1;
  4607. }
  4608. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4609. break;
  4610. case 0x0fc7: /* cmpxchg8b / rdrand / rdseed */
  4611. if (i386_record_modrm (&ir))
  4612. return -1;
  4613. if (ir.mod == 3)
  4614. {
  4615. /* rdrand and rdseed use the 3 bits of the REG field of ModR/M as
  4616. an extended opcode. rdrand has bits 110 (/6) and rdseed
  4617. has bits 111 (/7). */
  4618. if (ir.reg == 6 || ir.reg == 7)
  4619. {
  4620. /* The storage register is described by the 3 R/M bits, but the
  4621. REX.B prefix may be used to give access to registers
  4622. R8~R15. In this case ir.rex_b + R/M will give us the register
  4623. in the range R8~R15.
  4624. REX.W may also be used to access 64-bit registers, but we
  4625. already record entire registers and not just partial bits
  4626. of them. */
  4627. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rex_b + ir.rm);
  4628. /* These instructions also set conditional bits. */
  4629. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4630. break;
  4631. }
  4632. else
  4633. {
  4634. /* We don't handle this particular instruction yet. */
  4635. ir.addr -= 2;
  4636. opcode = opcode << 8 | ir.modrm;
  4637. goto no_support;
  4638. }
  4639. }
  4640. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
  4641. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
  4642. if (i386_record_lea_modrm (&ir))
  4643. return -1;
  4644. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4645. break;
  4646. case 0x50: /* push */
  4647. case 0x51:
  4648. case 0x52:
  4649. case 0x53:
  4650. case 0x54:
  4651. case 0x55:
  4652. case 0x56:
  4653. case 0x57:
  4654. case 0x68:
  4655. case 0x6a:
  4656. if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
  4657. ir.dflag = 2;
  4658. if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
  4659. return -1;
  4660. break;
  4661. case 0x06: /* push es */
  4662. case 0x0e: /* push cs */
  4663. case 0x16: /* push ss */
  4664. case 0x1e: /* push ds */
  4665. if (ir.regmap[X86_RECORD_R8_REGNUM])
  4666. {
  4667. ir.addr -= 1;
  4668. goto no_support;
  4669. }
  4670. if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
  4671. return -1;
  4672. break;
  4673. case 0x0fa0: /* push fs */
  4674. case 0x0fa8: /* push gs */
  4675. if (ir.regmap[X86_RECORD_R8_REGNUM])
  4676. {
  4677. ir.addr -= 2;
  4678. goto no_support;
  4679. }
  4680. if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
  4681. return -1;
  4682. break;
  4683. case 0x60: /* pusha */
  4684. if (ir.regmap[X86_RECORD_R8_REGNUM])
  4685. {
  4686. ir.addr -= 1;
  4687. goto no_support;
  4688. }
  4689. if (i386_record_push (&ir, 1 << (ir.dflag + 4)))
  4690. return -1;
  4691. break;
  4692. case 0x58: /* pop */
  4693. case 0x59:
  4694. case 0x5a:
  4695. case 0x5b:
  4696. case 0x5c:
  4697. case 0x5d:
  4698. case 0x5e:
  4699. case 0x5f:
  4700. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
  4701. I386_RECORD_FULL_ARCH_LIST_ADD_REG ((opcode & 0x7) | ir.rex_b);
  4702. break;
  4703. case 0x61: /* popa */
  4704. if (ir.regmap[X86_RECORD_R8_REGNUM])
  4705. {
  4706. ir.addr -= 1;
  4707. goto no_support;
  4708. }
  4709. for (regnum = X86_RECORD_REAX_REGNUM;
  4710. regnum <= X86_RECORD_REDI_REGNUM;
  4711. regnum++)
  4712. I386_RECORD_FULL_ARCH_LIST_ADD_REG (regnum);
  4713. break;
  4714. case 0x8f: /* pop */
  4715. if (ir.regmap[X86_RECORD_R8_REGNUM])
  4716. ir.ot = ir.dflag ? OT_QUAD : OT_WORD;
  4717. else
  4718. ir.ot = ir.dflag + OT_WORD;
  4719. if (i386_record_modrm (&ir))
  4720. return -1;
  4721. if (ir.mod == 3)
  4722. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
  4723. else
  4724. {
  4725. ir.popl_esp_hack = 1 << ir.ot;
  4726. if (i386_record_lea_modrm (&ir))
  4727. return -1;
  4728. }
  4729. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
  4730. break;
  4731. case 0xc8: /* enter */
  4732. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBP_REGNUM);
  4733. if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
  4734. ir.dflag = 2;
  4735. if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
  4736. return -1;
  4737. break;
  4738. case 0xc9: /* leave */
  4739. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
  4740. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBP_REGNUM);
  4741. break;
  4742. case 0x07: /* pop es */
  4743. if (ir.regmap[X86_RECORD_R8_REGNUM])
  4744. {
  4745. ir.addr -= 1;
  4746. goto no_support;
  4747. }
  4748. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
  4749. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_ES_REGNUM);
  4750. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4751. break;
  4752. case 0x17: /* pop ss */
  4753. if (ir.regmap[X86_RECORD_R8_REGNUM])
  4754. {
  4755. ir.addr -= 1;
  4756. goto no_support;
  4757. }
  4758. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
  4759. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_SS_REGNUM);
  4760. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4761. break;
  4762. case 0x1f: /* pop ds */
  4763. if (ir.regmap[X86_RECORD_R8_REGNUM])
  4764. {
  4765. ir.addr -= 1;
  4766. goto no_support;
  4767. }
  4768. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
  4769. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_DS_REGNUM);
  4770. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4771. break;
  4772. case 0x0fa1: /* pop fs */
  4773. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
  4774. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_FS_REGNUM);
  4775. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4776. break;
  4777. case 0x0fa9: /* pop gs */
  4778. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
  4779. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_GS_REGNUM);
  4780. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4781. break;
  4782. case 0x88: /* mov */
  4783. case 0x89:
  4784. case 0xc6:
  4785. case 0xc7:
  4786. if ((opcode & 1) == 0)
  4787. ir.ot = OT_BYTE;
  4788. else
  4789. ir.ot = ir.dflag + OT_WORD;
  4790. if (i386_record_modrm (&ir))
  4791. return -1;
  4792. if (ir.mod != 3)
  4793. {
  4794. if (opcode == 0xc6 || opcode == 0xc7)
  4795. ir.rip_offset = (ir.ot > OT_LONG) ? 4 : (1 << ir.ot);
  4796. if (i386_record_lea_modrm (&ir))
  4797. return -1;
  4798. }
  4799. else
  4800. {
  4801. if (opcode == 0xc6 || opcode == 0xc7)
  4802. ir.rm |= ir.rex_b;
  4803. if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
  4804. ir.rm &= 0x3;
  4805. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
  4806. }
  4807. break;
  4808. case 0x8a: /* mov */
  4809. case 0x8b:
  4810. if ((opcode & 1) == 0)
  4811. ir.ot = OT_BYTE;
  4812. else
  4813. ir.ot = ir.dflag + OT_WORD;
  4814. if (i386_record_modrm (&ir))
  4815. return -1;
  4816. ir.reg |= rex_r;
  4817. if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
  4818. ir.reg &= 0x3;
  4819. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
  4820. break;
  4821. case 0x8c: /* mov seg */
  4822. if (i386_record_modrm (&ir))
  4823. return -1;
  4824. if (ir.reg > 5)
  4825. {
  4826. ir.addr -= 2;
  4827. opcode = opcode << 8 | ir.modrm;
  4828. goto no_support;
  4829. }
  4830. if (ir.mod == 3)
  4831. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
  4832. else
  4833. {
  4834. ir.ot = OT_WORD;
  4835. if (i386_record_lea_modrm (&ir))
  4836. return -1;
  4837. }
  4838. break;
  4839. case 0x8e: /* mov seg */
  4840. if (i386_record_modrm (&ir))
  4841. return -1;
  4842. switch (ir.reg)
  4843. {
  4844. case 0:
  4845. regnum = X86_RECORD_ES_REGNUM;
  4846. break;
  4847. case 2:
  4848. regnum = X86_RECORD_SS_REGNUM;
  4849. break;
  4850. case 3:
  4851. regnum = X86_RECORD_DS_REGNUM;
  4852. break;
  4853. case 4:
  4854. regnum = X86_RECORD_FS_REGNUM;
  4855. break;
  4856. case 5:
  4857. regnum = X86_RECORD_GS_REGNUM;
  4858. break;
  4859. default:
  4860. ir.addr -= 2;
  4861. opcode = opcode << 8 | ir.modrm;
  4862. goto no_support;
  4863. break;
  4864. }
  4865. I386_RECORD_FULL_ARCH_LIST_ADD_REG (regnum);
  4866. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  4867. break;
  4868. case 0x0fb6: /* movzbS */
  4869. case 0x0fb7: /* movzwS */
  4870. case 0x0fbe: /* movsbS */
  4871. case 0x0fbf: /* movswS */
  4872. if (i386_record_modrm (&ir))
  4873. return -1;
  4874. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg | rex_r);
  4875. break;
  4876. case 0x8d: /* lea */
  4877. if (i386_record_modrm (&ir))
  4878. return -1;
  4879. if (ir.mod == 3)
  4880. {
  4881. ir.addr -= 2;
  4882. opcode = opcode << 8 | ir.modrm;
  4883. goto no_support;
  4884. }
  4885. ir.ot = ir.dflag;
  4886. ir.reg |= rex_r;
  4887. if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
  4888. ir.reg &= 0x3;
  4889. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
  4890. break;
  4891. case 0xa0: /* mov EAX */
  4892. case 0xa1:
  4893. case 0xd7: /* xlat */
  4894. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
  4895. break;
  4896. case 0xa2: /* mov EAX */
  4897. case 0xa3:
  4898. if (ir.override >= 0)
  4899. {
  4900. if (record_full_memory_query)
  4901. {
  4902. if (yquery (_("\
  4903. Process record ignores the memory change of instruction at address %s\n\
  4904. because it can't get the value of the segment register.\n\
  4905. Do you want to stop the program?"),
  4906. paddress (gdbarch, ir.orig_addr)))
  4907. return -1;
  4908. }
  4909. }
  4910. else
  4911. {
  4912. if ((opcode & 1) == 0)
  4913. ir.ot = OT_BYTE;
  4914. else
  4915. ir.ot = ir.dflag + OT_WORD;
  4916. if (ir.aflag == 2)
  4917. {
  4918. if (record_read_memory (gdbarch, ir.addr, buf, 8))
  4919. return -1;
  4920. ir.addr += 8;
  4921. addr = extract_unsigned_integer (buf, 8, byte_order);
  4922. }
  4923. else if (ir.aflag)
  4924. {
  4925. if (record_read_memory (gdbarch, ir.addr, buf, 4))
  4926. return -1;
  4927. ir.addr += 4;
  4928. addr = extract_unsigned_integer (buf, 4, byte_order);
  4929. }
  4930. else
  4931. {
  4932. if (record_read_memory (gdbarch, ir.addr, buf, 2))
  4933. return -1;
  4934. ir.addr += 2;
  4935. addr = extract_unsigned_integer (buf, 2, byte_order);
  4936. }
  4937. if (record_full_arch_list_add_mem (addr, 1 << ir.ot))
  4938. return -1;
  4939. }
  4940. break;
  4941. case 0xb0: /* mov R, Ib */
  4942. case 0xb1:
  4943. case 0xb2:
  4944. case 0xb3:
  4945. case 0xb4:
  4946. case 0xb5:
  4947. case 0xb6:
  4948. case 0xb7:
  4949. I386_RECORD_FULL_ARCH_LIST_ADD_REG ((ir.regmap[X86_RECORD_R8_REGNUM])
  4950. ? ((opcode & 0x7) | ir.rex_b)
  4951. : ((opcode & 0x7) & 0x3));
  4952. break;
  4953. case 0xb8: /* mov R, Iv */
  4954. case 0xb9:
  4955. case 0xba:
  4956. case 0xbb:
  4957. case 0xbc:
  4958. case 0xbd:
  4959. case 0xbe:
  4960. case 0xbf:
  4961. I386_RECORD_FULL_ARCH_LIST_ADD_REG ((opcode & 0x7) | ir.rex_b);
  4962. break;
  4963. case 0x91: /* xchg R, EAX */
  4964. case 0x92:
  4965. case 0x93:
  4966. case 0x94:
  4967. case 0x95:
  4968. case 0x96:
  4969. case 0x97:
  4970. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
  4971. I386_RECORD_FULL_ARCH_LIST_ADD_REG (opcode & 0x7);
  4972. break;
  4973. case 0x86: /* xchg Ev, Gv */
  4974. case 0x87:
  4975. if ((opcode & 1) == 0)
  4976. ir.ot = OT_BYTE;
  4977. else
  4978. ir.ot = ir.dflag + OT_WORD;
  4979. if (i386_record_modrm (&ir))
  4980. return -1;
  4981. if (ir.mod == 3)
  4982. {
  4983. ir.rm |= ir.rex_b;
  4984. if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
  4985. ir.rm &= 0x3;
  4986. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
  4987. }
  4988. else
  4989. {
  4990. if (i386_record_lea_modrm (&ir))
  4991. return -1;
  4992. }
  4993. ir.reg |= rex_r;
  4994. if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
  4995. ir.reg &= 0x3;
  4996. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
  4997. break;
  4998. case 0xc4: /* les Gv */
  4999. case 0xc5: /* lds Gv */
  5000. if (ir.regmap[X86_RECORD_R8_REGNUM])
  5001. {
  5002. ir.addr -= 1;
  5003. goto no_support;
  5004. }
  5005. /* FALLTHROUGH */
  5006. case 0x0fb2: /* lss Gv */
  5007. case 0x0fb4: /* lfs Gv */
  5008. case 0x0fb5: /* lgs Gv */
  5009. if (i386_record_modrm (&ir))
  5010. return -1;
  5011. if (ir.mod == 3)
  5012. {
  5013. if (opcode > 0xff)
  5014. ir.addr -= 3;
  5015. else
  5016. ir.addr -= 2;
  5017. opcode = opcode << 8 | ir.modrm;
  5018. goto no_support;
  5019. }
  5020. switch (opcode)
  5021. {
  5022. case 0xc4: /* les Gv */
  5023. regnum = X86_RECORD_ES_REGNUM;
  5024. break;
  5025. case 0xc5: /* lds Gv */
  5026. regnum = X86_RECORD_DS_REGNUM;
  5027. break;
  5028. case 0x0fb2: /* lss Gv */
  5029. regnum = X86_RECORD_SS_REGNUM;
  5030. break;
  5031. case 0x0fb4: /* lfs Gv */
  5032. regnum = X86_RECORD_FS_REGNUM;
  5033. break;
  5034. case 0x0fb5: /* lgs Gv */
  5035. regnum = X86_RECORD_GS_REGNUM;
  5036. break;
  5037. }
  5038. I386_RECORD_FULL_ARCH_LIST_ADD_REG (regnum);
  5039. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg | rex_r);
  5040. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5041. break;
  5042. case 0xc0: /* shifts */
  5043. case 0xc1:
  5044. case 0xd0:
  5045. case 0xd1:
  5046. case 0xd2:
  5047. case 0xd3:
  5048. if ((opcode & 1) == 0)
  5049. ir.ot = OT_BYTE;
  5050. else
  5051. ir.ot = ir.dflag + OT_WORD;
  5052. if (i386_record_modrm (&ir))
  5053. return -1;
  5054. if (ir.mod != 3 && (opcode == 0xd2 || opcode == 0xd3))
  5055. {
  5056. if (i386_record_lea_modrm (&ir))
  5057. return -1;
  5058. }
  5059. else
  5060. {
  5061. ir.rm |= ir.rex_b;
  5062. if (ir.ot == OT_BYTE && !ir.regmap[X86_RECORD_R8_REGNUM])
  5063. ir.rm &= 0x3;
  5064. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm);
  5065. }
  5066. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5067. break;
  5068. case 0x0fa4:
  5069. case 0x0fa5:
  5070. case 0x0fac:
  5071. case 0x0fad:
  5072. if (i386_record_modrm (&ir))
  5073. return -1;
  5074. if (ir.mod == 3)
  5075. {
  5076. if (record_full_arch_list_add_reg (ir.regcache, ir.rm))
  5077. return -1;
  5078. }
  5079. else
  5080. {
  5081. if (i386_record_lea_modrm (&ir))
  5082. return -1;
  5083. }
  5084. break;
  5085. case 0xd8: /* Floats. */
  5086. case 0xd9:
  5087. case 0xda:
  5088. case 0xdb:
  5089. case 0xdc:
  5090. case 0xdd:
  5091. case 0xde:
  5092. case 0xdf:
  5093. if (i386_record_modrm (&ir))
  5094. return -1;
  5095. ir.reg |= ((opcode & 7) << 3);
  5096. if (ir.mod != 3)
  5097. {
  5098. /* Memory. */
  5099. uint64_t addr64;
  5100. if (i386_record_lea_modrm_addr (&ir, &addr64))
  5101. return -1;
  5102. switch (ir.reg)
  5103. {
  5104. case 0x02:
  5105. case 0x12:
  5106. case 0x22:
  5107. case 0x32:
  5108. /* For fcom, ficom nothing to do. */
  5109. break;
  5110. case 0x03:
  5111. case 0x13:
  5112. case 0x23:
  5113. case 0x33:
  5114. /* For fcomp, ficomp pop FPU stack, store all. */
  5115. if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
  5116. return -1;
  5117. break;
  5118. case 0x00:
  5119. case 0x01:
  5120. case 0x04:
  5121. case 0x05:
  5122. case 0x06:
  5123. case 0x07:
  5124. case 0x10:
  5125. case 0x11:
  5126. case 0x14:
  5127. case 0x15:
  5128. case 0x16:
  5129. case 0x17:
  5130. case 0x20:
  5131. case 0x21:
  5132. case 0x24:
  5133. case 0x25:
  5134. case 0x26:
  5135. case 0x27:
  5136. case 0x30:
  5137. case 0x31:
  5138. case 0x34:
  5139. case 0x35:
  5140. case 0x36:
  5141. case 0x37:
  5142. /* For fadd, fmul, fsub, fsubr, fdiv, fdivr, fiadd, fimul,
  5143. fisub, fisubr, fidiv, fidivr, modR/M.reg is an extension
  5144. of code, always affects st(0) register. */
  5145. if (i386_record_floats (gdbarch, &ir, I387_ST0_REGNUM (tdep)))
  5146. return -1;
  5147. break;
  5148. case 0x08:
  5149. case 0x0a:
  5150. case 0x0b:
  5151. case 0x18:
  5152. case 0x19:
  5153. case 0x1a:
  5154. case 0x1b:
  5155. case 0x1d:
  5156. case 0x28:
  5157. case 0x29:
  5158. case 0x2a:
  5159. case 0x2b:
  5160. case 0x38:
  5161. case 0x39:
  5162. case 0x3a:
  5163. case 0x3b:
  5164. case 0x3c:
  5165. case 0x3d:
  5166. switch (ir.reg & 7)
  5167. {
  5168. case 0:
  5169. /* Handling fld, fild. */
  5170. if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
  5171. return -1;
  5172. break;
  5173. case 1:
  5174. switch (ir.reg >> 4)
  5175. {
  5176. case 0:
  5177. if (record_full_arch_list_add_mem (addr64, 4))
  5178. return -1;
  5179. break;
  5180. case 2:
  5181. if (record_full_arch_list_add_mem (addr64, 8))
  5182. return -1;
  5183. break;
  5184. case 3:
  5185. break;
  5186. default:
  5187. if (record_full_arch_list_add_mem (addr64, 2))
  5188. return -1;
  5189. break;
  5190. }
  5191. break;
  5192. default:
  5193. switch (ir.reg >> 4)
  5194. {
  5195. case 0:
  5196. if (record_full_arch_list_add_mem (addr64, 4))
  5197. return -1;
  5198. if (3 == (ir.reg & 7))
  5199. {
  5200. /* For fstp m32fp. */
  5201. if (i386_record_floats (gdbarch, &ir,
  5202. I386_SAVE_FPU_REGS))
  5203. return -1;
  5204. }
  5205. break;
  5206. case 1:
  5207. if (record_full_arch_list_add_mem (addr64, 4))
  5208. return -1;
  5209. if ((3 == (ir.reg & 7))
  5210. || (5 == (ir.reg & 7))
  5211. || (7 == (ir.reg & 7)))
  5212. {
  5213. /* For fstp insn. */
  5214. if (i386_record_floats (gdbarch, &ir,
  5215. I386_SAVE_FPU_REGS))
  5216. return -1;
  5217. }
  5218. break;
  5219. case 2:
  5220. if (record_full_arch_list_add_mem (addr64, 8))
  5221. return -1;
  5222. if (3 == (ir.reg & 7))
  5223. {
  5224. /* For fstp m64fp. */
  5225. if (i386_record_floats (gdbarch, &ir,
  5226. I386_SAVE_FPU_REGS))
  5227. return -1;
  5228. }
  5229. break;
  5230. case 3:
  5231. if ((3 <= (ir.reg & 7)) && (6 <= (ir.reg & 7)))
  5232. {
  5233. /* For fistp, fbld, fild, fbstp. */
  5234. if (i386_record_floats (gdbarch, &ir,
  5235. I386_SAVE_FPU_REGS))
  5236. return -1;
  5237. }
  5238. /* Fall through */
  5239. default:
  5240. if (record_full_arch_list_add_mem (addr64, 2))
  5241. return -1;
  5242. break;
  5243. }
  5244. break;
  5245. }
  5246. break;
  5247. case 0x0c:
  5248. /* Insn fldenv. */
  5249. if (i386_record_floats (gdbarch, &ir,
  5250. I386_SAVE_FPU_ENV_REG_STACK))
  5251. return -1;
  5252. break;
  5253. case 0x0d:
  5254. /* Insn fldcw. */
  5255. if (i386_record_floats (gdbarch, &ir, I387_FCTRL_REGNUM (tdep)))
  5256. return -1;
  5257. break;
  5258. case 0x2c:
  5259. /* Insn frstor. */
  5260. if (i386_record_floats (gdbarch, &ir,
  5261. I386_SAVE_FPU_ENV_REG_STACK))
  5262. return -1;
  5263. break;
  5264. case 0x0e:
  5265. if (ir.dflag)
  5266. {
  5267. if (record_full_arch_list_add_mem (addr64, 28))
  5268. return -1;
  5269. }
  5270. else
  5271. {
  5272. if (record_full_arch_list_add_mem (addr64, 14))
  5273. return -1;
  5274. }
  5275. break;
  5276. case 0x0f:
  5277. case 0x2f:
  5278. if (record_full_arch_list_add_mem (addr64, 2))
  5279. return -1;
  5280. /* Insn fstp, fbstp. */
  5281. if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
  5282. return -1;
  5283. break;
  5284. case 0x1f:
  5285. case 0x3e:
  5286. if (record_full_arch_list_add_mem (addr64, 10))
  5287. return -1;
  5288. break;
  5289. case 0x2e:
  5290. if (ir.dflag)
  5291. {
  5292. if (record_full_arch_list_add_mem (addr64, 28))
  5293. return -1;
  5294. addr64 += 28;
  5295. }
  5296. else
  5297. {
  5298. if (record_full_arch_list_add_mem (addr64, 14))
  5299. return -1;
  5300. addr64 += 14;
  5301. }
  5302. if (record_full_arch_list_add_mem (addr64, 80))
  5303. return -1;
  5304. /* Insn fsave. */
  5305. if (i386_record_floats (gdbarch, &ir,
  5306. I386_SAVE_FPU_ENV_REG_STACK))
  5307. return -1;
  5308. break;
  5309. case 0x3f:
  5310. if (record_full_arch_list_add_mem (addr64, 8))
  5311. return -1;
  5312. /* Insn fistp. */
  5313. if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
  5314. return -1;
  5315. break;
  5316. default:
  5317. ir.addr -= 2;
  5318. opcode = opcode << 8 | ir.modrm;
  5319. goto no_support;
  5320. break;
  5321. }
  5322. }
  5323. /* Opcode is an extension of modR/M byte. */
  5324. else
  5325. {
  5326. switch (opcode)
  5327. {
  5328. case 0xd8:
  5329. if (i386_record_floats (gdbarch, &ir, I387_ST0_REGNUM (tdep)))
  5330. return -1;
  5331. break;
  5332. case 0xd9:
  5333. if (0x0c == (ir.modrm >> 4))
  5334. {
  5335. if ((ir.modrm & 0x0f) <= 7)
  5336. {
  5337. if (i386_record_floats (gdbarch, &ir,
  5338. I386_SAVE_FPU_REGS))
  5339. return -1;
  5340. }
  5341. else
  5342. {
  5343. if (i386_record_floats (gdbarch, &ir,
  5344. I387_ST0_REGNUM (tdep)))
  5345. return -1;
  5346. /* If only st(0) is changing, then we have already
  5347. recorded. */
  5348. if ((ir.modrm & 0x0f) - 0x08)
  5349. {
  5350. if (i386_record_floats (gdbarch, &ir,
  5351. I387_ST0_REGNUM (tdep) +
  5352. ((ir.modrm & 0x0f) - 0x08)))
  5353. return -1;
  5354. }
  5355. }
  5356. }
  5357. else
  5358. {
  5359. switch (ir.modrm)
  5360. {
  5361. case 0xe0:
  5362. case 0xe1:
  5363. case 0xf0:
  5364. case 0xf5:
  5365. case 0xf8:
  5366. case 0xfa:
  5367. case 0xfc:
  5368. case 0xfe:
  5369. case 0xff:
  5370. if (i386_record_floats (gdbarch, &ir,
  5371. I387_ST0_REGNUM (tdep)))
  5372. return -1;
  5373. break;
  5374. case 0xf1:
  5375. case 0xf2:
  5376. case 0xf3:
  5377. case 0xf4:
  5378. case 0xf6:
  5379. case 0xf7:
  5380. case 0xe8:
  5381. case 0xe9:
  5382. case 0xea:
  5383. case 0xeb:
  5384. case 0xec:
  5385. case 0xed:
  5386. case 0xee:
  5387. case 0xf9:
  5388. case 0xfb:
  5389. if (i386_record_floats (gdbarch, &ir,
  5390. I386_SAVE_FPU_REGS))
  5391. return -1;
  5392. break;
  5393. case 0xfd:
  5394. if (i386_record_floats (gdbarch, &ir,
  5395. I387_ST0_REGNUM (tdep)))
  5396. return -1;
  5397. if (i386_record_floats (gdbarch, &ir,
  5398. I387_ST0_REGNUM (tdep) + 1))
  5399. return -1;
  5400. break;
  5401. }
  5402. }
  5403. break;
  5404. case 0xda:
  5405. if (0xe9 == ir.modrm)
  5406. {
  5407. if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
  5408. return -1;
  5409. }
  5410. else if ((0x0c == ir.modrm >> 4) || (0x0d == ir.modrm >> 4))
  5411. {
  5412. if (i386_record_floats (gdbarch, &ir,
  5413. I387_ST0_REGNUM (tdep)))
  5414. return -1;
  5415. if (((ir.modrm & 0x0f) > 0) && ((ir.modrm & 0x0f) <= 7))
  5416. {
  5417. if (i386_record_floats (gdbarch, &ir,
  5418. I387_ST0_REGNUM (tdep) +
  5419. (ir.modrm & 0x0f)))
  5420. return -1;
  5421. }
  5422. else if ((ir.modrm & 0x0f) - 0x08)
  5423. {
  5424. if (i386_record_floats (gdbarch, &ir,
  5425. I387_ST0_REGNUM (tdep) +
  5426. ((ir.modrm & 0x0f) - 0x08)))
  5427. return -1;
  5428. }
  5429. }
  5430. break;
  5431. case 0xdb:
  5432. if (0xe3 == ir.modrm)
  5433. {
  5434. if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_ENV))
  5435. return -1;
  5436. }
  5437. else if ((0x0c == ir.modrm >> 4) || (0x0d == ir.modrm >> 4))
  5438. {
  5439. if (i386_record_floats (gdbarch, &ir,
  5440. I387_ST0_REGNUM (tdep)))
  5441. return -1;
  5442. if (((ir.modrm & 0x0f) > 0) && ((ir.modrm & 0x0f) <= 7))
  5443. {
  5444. if (i386_record_floats (gdbarch, &ir,
  5445. I387_ST0_REGNUM (tdep) +
  5446. (ir.modrm & 0x0f)))
  5447. return -1;
  5448. }
  5449. else if ((ir.modrm & 0x0f) - 0x08)
  5450. {
  5451. if (i386_record_floats (gdbarch, &ir,
  5452. I387_ST0_REGNUM (tdep) +
  5453. ((ir.modrm & 0x0f) - 0x08)))
  5454. return -1;
  5455. }
  5456. }
  5457. break;
  5458. case 0xdc:
  5459. if ((0x0c == ir.modrm >> 4)
  5460. || (0x0d == ir.modrm >> 4)
  5461. || (0x0f == ir.modrm >> 4))
  5462. {
  5463. if ((ir.modrm & 0x0f) <= 7)
  5464. {
  5465. if (i386_record_floats (gdbarch, &ir,
  5466. I387_ST0_REGNUM (tdep) +
  5467. (ir.modrm & 0x0f)))
  5468. return -1;
  5469. }
  5470. else
  5471. {
  5472. if (i386_record_floats (gdbarch, &ir,
  5473. I387_ST0_REGNUM (tdep) +
  5474. ((ir.modrm & 0x0f) - 0x08)))
  5475. return -1;
  5476. }
  5477. }
  5478. break;
  5479. case 0xdd:
  5480. if (0x0c == ir.modrm >> 4)
  5481. {
  5482. if (i386_record_floats (gdbarch, &ir,
  5483. I387_FTAG_REGNUM (tdep)))
  5484. return -1;
  5485. }
  5486. else if ((0x0d == ir.modrm >> 4) || (0x0e == ir.modrm >> 4))
  5487. {
  5488. if ((ir.modrm & 0x0f) <= 7)
  5489. {
  5490. if (i386_record_floats (gdbarch, &ir,
  5491. I387_ST0_REGNUM (tdep) +
  5492. (ir.modrm & 0x0f)))
  5493. return -1;
  5494. }
  5495. else
  5496. {
  5497. if (i386_record_floats (gdbarch, &ir,
  5498. I386_SAVE_FPU_REGS))
  5499. return -1;
  5500. }
  5501. }
  5502. break;
  5503. case 0xde:
  5504. if ((0x0c == ir.modrm >> 4)
  5505. || (0x0e == ir.modrm >> 4)
  5506. || (0x0f == ir.modrm >> 4)
  5507. || (0xd9 == ir.modrm))
  5508. {
  5509. if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
  5510. return -1;
  5511. }
  5512. break;
  5513. case 0xdf:
  5514. if (0xe0 == ir.modrm)
  5515. {
  5516. if (record_full_arch_list_add_reg (ir.regcache,
  5517. I386_EAX_REGNUM))
  5518. return -1;
  5519. }
  5520. else if ((0x0f == ir.modrm >> 4) || (0x0e == ir.modrm >> 4))
  5521. {
  5522. if (i386_record_floats (gdbarch, &ir, I386_SAVE_FPU_REGS))
  5523. return -1;
  5524. }
  5525. break;
  5526. }
  5527. }
  5528. break;
  5529. /* string ops */
  5530. case 0xa4: /* movsS */
  5531. case 0xa5:
  5532. case 0xaa: /* stosS */
  5533. case 0xab:
  5534. case 0x6c: /* insS */
  5535. case 0x6d:
  5536. regcache_raw_read_unsigned (ir.regcache,
  5537. ir.regmap[X86_RECORD_RECX_REGNUM],
  5538. &addr);
  5539. if (addr)
  5540. {
  5541. ULONGEST es, ds;
  5542. if ((opcode & 1) == 0)
  5543. ir.ot = OT_BYTE;
  5544. else
  5545. ir.ot = ir.dflag + OT_WORD;
  5546. regcache_raw_read_unsigned (ir.regcache,
  5547. ir.regmap[X86_RECORD_REDI_REGNUM],
  5548. &addr);
  5549. regcache_raw_read_unsigned (ir.regcache,
  5550. ir.regmap[X86_RECORD_ES_REGNUM],
  5551. &es);
  5552. regcache_raw_read_unsigned (ir.regcache,
  5553. ir.regmap[X86_RECORD_DS_REGNUM],
  5554. &ds);
  5555. if (ir.aflag && (es != ds))
  5556. {
  5557. /* addr += ((uint32_t) read_register (I386_ES_REGNUM)) << 4; */
  5558. if (record_full_memory_query)
  5559. {
  5560. if (yquery (_("\
  5561. Process record ignores the memory change of instruction at address %s\n\
  5562. because it can't get the value of the segment register.\n\
  5563. Do you want to stop the program?"),
  5564. paddress (gdbarch, ir.orig_addr)))
  5565. return -1;
  5566. }
  5567. }
  5568. else
  5569. {
  5570. if (record_full_arch_list_add_mem (addr, 1 << ir.ot))
  5571. return -1;
  5572. }
  5573. if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
  5574. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
  5575. if (opcode == 0xa4 || opcode == 0xa5)
  5576. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
  5577. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM);
  5578. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5579. }
  5580. break;
  5581. case 0xa6: /* cmpsS */
  5582. case 0xa7:
  5583. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM);
  5584. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
  5585. if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
  5586. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
  5587. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5588. break;
  5589. case 0xac: /* lodsS */
  5590. case 0xad:
  5591. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
  5592. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
  5593. if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
  5594. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
  5595. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5596. break;
  5597. case 0xae: /* scasS */
  5598. case 0xaf:
  5599. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM);
  5600. if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
  5601. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
  5602. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5603. break;
  5604. case 0x6e: /* outsS */
  5605. case 0x6f:
  5606. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
  5607. if (prefixes & (PREFIX_REPZ | PREFIX_REPNZ))
  5608. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
  5609. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5610. break;
  5611. case 0xe4: /* port I/O */
  5612. case 0xe5:
  5613. case 0xec:
  5614. case 0xed:
  5615. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5616. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
  5617. break;
  5618. case 0xe6:
  5619. case 0xe7:
  5620. case 0xee:
  5621. case 0xef:
  5622. break;
  5623. /* control */
  5624. case 0xc2: /* ret im */
  5625. case 0xc3: /* ret */
  5626. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
  5627. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5628. break;
  5629. case 0xca: /* lret im */
  5630. case 0xcb: /* lret */
  5631. case 0xcf: /* iret */
  5632. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_CS_REGNUM);
  5633. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
  5634. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5635. break;
  5636. case 0xe8: /* call im */
  5637. if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
  5638. ir.dflag = 2;
  5639. if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
  5640. return -1;
  5641. break;
  5642. case 0x9a: /* lcall im */
  5643. if (ir.regmap[X86_RECORD_R8_REGNUM])
  5644. {
  5645. ir.addr -= 1;
  5646. goto no_support;
  5647. }
  5648. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_CS_REGNUM);
  5649. if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
  5650. return -1;
  5651. break;
  5652. case 0xe9: /* jmp im */
  5653. case 0xea: /* ljmp im */
  5654. case 0xeb: /* jmp Jb */
  5655. case 0x70: /* jcc Jb */
  5656. case 0x71:
  5657. case 0x72:
  5658. case 0x73:
  5659. case 0x74:
  5660. case 0x75:
  5661. case 0x76:
  5662. case 0x77:
  5663. case 0x78:
  5664. case 0x79:
  5665. case 0x7a:
  5666. case 0x7b:
  5667. case 0x7c:
  5668. case 0x7d:
  5669. case 0x7e:
  5670. case 0x7f:
  5671. case 0x0f80: /* jcc Jv */
  5672. case 0x0f81:
  5673. case 0x0f82:
  5674. case 0x0f83:
  5675. case 0x0f84:
  5676. case 0x0f85:
  5677. case 0x0f86:
  5678. case 0x0f87:
  5679. case 0x0f88:
  5680. case 0x0f89:
  5681. case 0x0f8a:
  5682. case 0x0f8b:
  5683. case 0x0f8c:
  5684. case 0x0f8d:
  5685. case 0x0f8e:
  5686. case 0x0f8f:
  5687. break;
  5688. case 0x0f90: /* setcc Gv */
  5689. case 0x0f91:
  5690. case 0x0f92:
  5691. case 0x0f93:
  5692. case 0x0f94:
  5693. case 0x0f95:
  5694. case 0x0f96:
  5695. case 0x0f97:
  5696. case 0x0f98:
  5697. case 0x0f99:
  5698. case 0x0f9a:
  5699. case 0x0f9b:
  5700. case 0x0f9c:
  5701. case 0x0f9d:
  5702. case 0x0f9e:
  5703. case 0x0f9f:
  5704. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5705. ir.ot = OT_BYTE;
  5706. if (i386_record_modrm (&ir))
  5707. return -1;
  5708. if (ir.mod == 3)
  5709. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rex_b ? (ir.rm | ir.rex_b)
  5710. : (ir.rm & 0x3));
  5711. else
  5712. {
  5713. if (i386_record_lea_modrm (&ir))
  5714. return -1;
  5715. }
  5716. break;
  5717. case 0x0f40: /* cmov Gv, Ev */
  5718. case 0x0f41:
  5719. case 0x0f42:
  5720. case 0x0f43:
  5721. case 0x0f44:
  5722. case 0x0f45:
  5723. case 0x0f46:
  5724. case 0x0f47:
  5725. case 0x0f48:
  5726. case 0x0f49:
  5727. case 0x0f4a:
  5728. case 0x0f4b:
  5729. case 0x0f4c:
  5730. case 0x0f4d:
  5731. case 0x0f4e:
  5732. case 0x0f4f:
  5733. if (i386_record_modrm (&ir))
  5734. return -1;
  5735. ir.reg |= rex_r;
  5736. if (ir.dflag == OT_BYTE)
  5737. ir.reg &= 0x3;
  5738. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
  5739. break;
  5740. /* flags */
  5741. case 0x9c: /* pushf */
  5742. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5743. if (ir.regmap[X86_RECORD_R8_REGNUM] && ir.dflag)
  5744. ir.dflag = 2;
  5745. if (i386_record_push (&ir, 1 << (ir.dflag + 1)))
  5746. return -1;
  5747. break;
  5748. case 0x9d: /* popf */
  5749. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
  5750. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5751. break;
  5752. case 0x9e: /* sahf */
  5753. if (ir.regmap[X86_RECORD_R8_REGNUM])
  5754. {
  5755. ir.addr -= 1;
  5756. goto no_support;
  5757. }
  5758. /* FALLTHROUGH */
  5759. case 0xf5: /* cmc */
  5760. case 0xf8: /* clc */
  5761. case 0xf9: /* stc */
  5762. case 0xfc: /* cld */
  5763. case 0xfd: /* std */
  5764. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5765. break;
  5766. case 0x9f: /* lahf */
  5767. if (ir.regmap[X86_RECORD_R8_REGNUM])
  5768. {
  5769. ir.addr -= 1;
  5770. goto no_support;
  5771. }
  5772. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5773. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
  5774. break;
  5775. /* bit operations */
  5776. case 0x0fba: /* bt/bts/btr/btc Gv, im */
  5777. ir.ot = ir.dflag + OT_WORD;
  5778. if (i386_record_modrm (&ir))
  5779. return -1;
  5780. if (ir.reg < 4)
  5781. {
  5782. ir.addr -= 2;
  5783. opcode = opcode << 8 | ir.modrm;
  5784. goto no_support;
  5785. }
  5786. if (ir.reg != 4)
  5787. {
  5788. if (ir.mod == 3)
  5789. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
  5790. else
  5791. {
  5792. if (i386_record_lea_modrm (&ir))
  5793. return -1;
  5794. }
  5795. }
  5796. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5797. break;
  5798. case 0x0fa3: /* bt Gv, Ev */
  5799. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5800. break;
  5801. case 0x0fab: /* bts */
  5802. case 0x0fb3: /* btr */
  5803. case 0x0fbb: /* btc */
  5804. ir.ot = ir.dflag + OT_WORD;
  5805. if (i386_record_modrm (&ir))
  5806. return -1;
  5807. if (ir.mod == 3)
  5808. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
  5809. else
  5810. {
  5811. uint64_t addr64;
  5812. if (i386_record_lea_modrm_addr (&ir, &addr64))
  5813. return -1;
  5814. regcache_raw_read_unsigned (ir.regcache,
  5815. ir.regmap[ir.reg | rex_r],
  5816. &addr);
  5817. switch (ir.dflag)
  5818. {
  5819. case 0:
  5820. addr64 += ((int16_t) addr >> 4) << 4;
  5821. break;
  5822. case 1:
  5823. addr64 += ((int32_t) addr >> 5) << 5;
  5824. break;
  5825. case 2:
  5826. addr64 += ((int64_t) addr >> 6) << 6;
  5827. break;
  5828. }
  5829. if (record_full_arch_list_add_mem (addr64, 1 << ir.ot))
  5830. return -1;
  5831. if (i386_record_lea_modrm (&ir))
  5832. return -1;
  5833. }
  5834. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5835. break;
  5836. case 0x0fbc: /* bsf */
  5837. case 0x0fbd: /* bsr */
  5838. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg | rex_r);
  5839. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5840. break;
  5841. /* bcd */
  5842. case 0x27: /* daa */
  5843. case 0x2f: /* das */
  5844. case 0x37: /* aaa */
  5845. case 0x3f: /* aas */
  5846. case 0xd4: /* aam */
  5847. case 0xd5: /* aad */
  5848. if (ir.regmap[X86_RECORD_R8_REGNUM])
  5849. {
  5850. ir.addr -= 1;
  5851. goto no_support;
  5852. }
  5853. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
  5854. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5855. break;
  5856. /* misc */
  5857. case 0x90: /* nop */
  5858. if (prefixes & PREFIX_LOCK)
  5859. {
  5860. ir.addr -= 1;
  5861. goto no_support;
  5862. }
  5863. break;
  5864. case 0x9b: /* fwait */
  5865. if (record_read_memory (gdbarch, ir.addr, &opcode8, 1))
  5866. return -1;
  5867. opcode = (uint32_t) opcode8;
  5868. ir.addr++;
  5869. goto reswitch;
  5870. break;
  5871. /* XXX */
  5872. case 0xcc: /* int3 */
  5873. gdb_printf (gdb_stderr,
  5874. _("Process record does not support instruction "
  5875. "int3.\n"));
  5876. ir.addr -= 1;
  5877. goto no_support;
  5878. break;
  5879. /* XXX */
  5880. case 0xcd: /* int */
  5881. {
  5882. int ret;
  5883. uint8_t interrupt;
  5884. if (record_read_memory (gdbarch, ir.addr, &interrupt, 1))
  5885. return -1;
  5886. ir.addr++;
  5887. if (interrupt != 0x80
  5888. || tdep->i386_intx80_record == NULL)
  5889. {
  5890. gdb_printf (gdb_stderr,
  5891. _("Process record does not support "
  5892. "instruction int 0x%02x.\n"),
  5893. interrupt);
  5894. ir.addr -= 2;
  5895. goto no_support;
  5896. }
  5897. ret = tdep->i386_intx80_record (ir.regcache);
  5898. if (ret)
  5899. return ret;
  5900. }
  5901. break;
  5902. /* XXX */
  5903. case 0xce: /* into */
  5904. gdb_printf (gdb_stderr,
  5905. _("Process record does not support "
  5906. "instruction into.\n"));
  5907. ir.addr -= 1;
  5908. goto no_support;
  5909. break;
  5910. case 0xfa: /* cli */
  5911. case 0xfb: /* sti */
  5912. break;
  5913. case 0x62: /* bound */
  5914. gdb_printf (gdb_stderr,
  5915. _("Process record does not support "
  5916. "instruction bound.\n"));
  5917. ir.addr -= 1;
  5918. goto no_support;
  5919. break;
  5920. case 0x0fc8: /* bswap reg */
  5921. case 0x0fc9:
  5922. case 0x0fca:
  5923. case 0x0fcb:
  5924. case 0x0fcc:
  5925. case 0x0fcd:
  5926. case 0x0fce:
  5927. case 0x0fcf:
  5928. I386_RECORD_FULL_ARCH_LIST_ADD_REG ((opcode & 7) | ir.rex_b);
  5929. break;
  5930. case 0xd6: /* salc */
  5931. if (ir.regmap[X86_RECORD_R8_REGNUM])
  5932. {
  5933. ir.addr -= 1;
  5934. goto no_support;
  5935. }
  5936. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
  5937. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5938. break;
  5939. case 0xe0: /* loopnz */
  5940. case 0xe1: /* loopz */
  5941. case 0xe2: /* loop */
  5942. case 0xe3: /* jecxz */
  5943. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
  5944. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  5945. break;
  5946. case 0x0f30: /* wrmsr */
  5947. gdb_printf (gdb_stderr,
  5948. _("Process record does not support "
  5949. "instruction wrmsr.\n"));
  5950. ir.addr -= 2;
  5951. goto no_support;
  5952. break;
  5953. case 0x0f32: /* rdmsr */
  5954. gdb_printf (gdb_stderr,
  5955. _("Process record does not support "
  5956. "instruction rdmsr.\n"));
  5957. ir.addr -= 2;
  5958. goto no_support;
  5959. break;
  5960. case 0x0f31: /* rdtsc */
  5961. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
  5962. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
  5963. break;
  5964. case 0x0f34: /* sysenter */
  5965. {
  5966. int ret;
  5967. if (ir.regmap[X86_RECORD_R8_REGNUM])
  5968. {
  5969. ir.addr -= 2;
  5970. goto no_support;
  5971. }
  5972. if (tdep->i386_sysenter_record == NULL)
  5973. {
  5974. gdb_printf (gdb_stderr,
  5975. _("Process record does not support "
  5976. "instruction sysenter.\n"));
  5977. ir.addr -= 2;
  5978. goto no_support;
  5979. }
  5980. ret = tdep->i386_sysenter_record (ir.regcache);
  5981. if (ret)
  5982. return ret;
  5983. }
  5984. break;
  5985. case 0x0f35: /* sysexit */
  5986. gdb_printf (gdb_stderr,
  5987. _("Process record does not support "
  5988. "instruction sysexit.\n"));
  5989. ir.addr -= 2;
  5990. goto no_support;
  5991. break;
  5992. case 0x0f05: /* syscall */
  5993. {
  5994. int ret;
  5995. if (tdep->i386_syscall_record == NULL)
  5996. {
  5997. gdb_printf (gdb_stderr,
  5998. _("Process record does not support "
  5999. "instruction syscall.\n"));
  6000. ir.addr -= 2;
  6001. goto no_support;
  6002. }
  6003. ret = tdep->i386_syscall_record (ir.regcache);
  6004. if (ret)
  6005. return ret;
  6006. }
  6007. break;
  6008. case 0x0f07: /* sysret */
  6009. gdb_printf (gdb_stderr,
  6010. _("Process record does not support "
  6011. "instruction sysret.\n"));
  6012. ir.addr -= 2;
  6013. goto no_support;
  6014. break;
  6015. case 0x0fa2: /* cpuid */
  6016. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
  6017. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
  6018. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
  6019. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBX_REGNUM);
  6020. break;
  6021. case 0xf4: /* hlt */
  6022. gdb_printf (gdb_stderr,
  6023. _("Process record does not support "
  6024. "instruction hlt.\n"));
  6025. ir.addr -= 1;
  6026. goto no_support;
  6027. break;
  6028. case 0x0f00:
  6029. if (i386_record_modrm (&ir))
  6030. return -1;
  6031. switch (ir.reg)
  6032. {
  6033. case 0: /* sldt */
  6034. case 1: /* str */
  6035. if (ir.mod == 3)
  6036. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
  6037. else
  6038. {
  6039. ir.ot = OT_WORD;
  6040. if (i386_record_lea_modrm (&ir))
  6041. return -1;
  6042. }
  6043. break;
  6044. case 2: /* lldt */
  6045. case 3: /* ltr */
  6046. break;
  6047. case 4: /* verr */
  6048. case 5: /* verw */
  6049. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  6050. break;
  6051. default:
  6052. ir.addr -= 3;
  6053. opcode = opcode << 8 | ir.modrm;
  6054. goto no_support;
  6055. break;
  6056. }
  6057. break;
  6058. case 0x0f01:
  6059. if (i386_record_modrm (&ir))
  6060. return -1;
  6061. switch (ir.reg)
  6062. {
  6063. case 0: /* sgdt */
  6064. {
  6065. uint64_t addr64;
  6066. if (ir.mod == 3)
  6067. {
  6068. ir.addr -= 3;
  6069. opcode = opcode << 8 | ir.modrm;
  6070. goto no_support;
  6071. }
  6072. if (ir.override >= 0)
  6073. {
  6074. if (record_full_memory_query)
  6075. {
  6076. if (yquery (_("\
  6077. Process record ignores the memory change of instruction at address %s\n\
  6078. because it can't get the value of the segment register.\n\
  6079. Do you want to stop the program?"),
  6080. paddress (gdbarch, ir.orig_addr)))
  6081. return -1;
  6082. }
  6083. }
  6084. else
  6085. {
  6086. if (i386_record_lea_modrm_addr (&ir, &addr64))
  6087. return -1;
  6088. if (record_full_arch_list_add_mem (addr64, 2))
  6089. return -1;
  6090. addr64 += 2;
  6091. if (ir.regmap[X86_RECORD_R8_REGNUM])
  6092. {
  6093. if (record_full_arch_list_add_mem (addr64, 8))
  6094. return -1;
  6095. }
  6096. else
  6097. {
  6098. if (record_full_arch_list_add_mem (addr64, 4))
  6099. return -1;
  6100. }
  6101. }
  6102. }
  6103. break;
  6104. case 1:
  6105. if (ir.mod == 3)
  6106. {
  6107. switch (ir.rm)
  6108. {
  6109. case 0: /* monitor */
  6110. break;
  6111. case 1: /* mwait */
  6112. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  6113. break;
  6114. default:
  6115. ir.addr -= 3;
  6116. opcode = opcode << 8 | ir.modrm;
  6117. goto no_support;
  6118. break;
  6119. }
  6120. }
  6121. else
  6122. {
  6123. /* sidt */
  6124. if (ir.override >= 0)
  6125. {
  6126. if (record_full_memory_query)
  6127. {
  6128. if (yquery (_("\
  6129. Process record ignores the memory change of instruction at address %s\n\
  6130. because it can't get the value of the segment register.\n\
  6131. Do you want to stop the program?"),
  6132. paddress (gdbarch, ir.orig_addr)))
  6133. return -1;
  6134. }
  6135. }
  6136. else
  6137. {
  6138. uint64_t addr64;
  6139. if (i386_record_lea_modrm_addr (&ir, &addr64))
  6140. return -1;
  6141. if (record_full_arch_list_add_mem (addr64, 2))
  6142. return -1;
  6143. addr64 += 2;
  6144. if (ir.regmap[X86_RECORD_R8_REGNUM])
  6145. {
  6146. if (record_full_arch_list_add_mem (addr64, 8))
  6147. return -1;
  6148. }
  6149. else
  6150. {
  6151. if (record_full_arch_list_add_mem (addr64, 4))
  6152. return -1;
  6153. }
  6154. }
  6155. }
  6156. break;
  6157. case 2: /* lgdt */
  6158. if (ir.mod == 3)
  6159. {
  6160. /* xgetbv */
  6161. if (ir.rm == 0)
  6162. {
  6163. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
  6164. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
  6165. break;
  6166. }
  6167. /* xsetbv */
  6168. else if (ir.rm == 1)
  6169. break;
  6170. }
  6171. /* Fall through. */
  6172. case 3: /* lidt */
  6173. if (ir.mod == 3)
  6174. {
  6175. ir.addr -= 3;
  6176. opcode = opcode << 8 | ir.modrm;
  6177. goto no_support;
  6178. }
  6179. break;
  6180. case 4: /* smsw */
  6181. if (ir.mod == 3)
  6182. {
  6183. if (record_full_arch_list_add_reg (ir.regcache, ir.rm | ir.rex_b))
  6184. return -1;
  6185. }
  6186. else
  6187. {
  6188. ir.ot = OT_WORD;
  6189. if (i386_record_lea_modrm (&ir))
  6190. return -1;
  6191. }
  6192. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  6193. break;
  6194. case 6: /* lmsw */
  6195. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  6196. break;
  6197. case 7: /* invlpg */
  6198. if (ir.mod == 3)
  6199. {
  6200. if (ir.rm == 0 && ir.regmap[X86_RECORD_R8_REGNUM])
  6201. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_GS_REGNUM);
  6202. else
  6203. {
  6204. ir.addr -= 3;
  6205. opcode = opcode << 8 | ir.modrm;
  6206. goto no_support;
  6207. }
  6208. }
  6209. else
  6210. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  6211. break;
  6212. default:
  6213. ir.addr -= 3;
  6214. opcode = opcode << 8 | ir.modrm;
  6215. goto no_support;
  6216. break;
  6217. }
  6218. break;
  6219. case 0x0f08: /* invd */
  6220. case 0x0f09: /* wbinvd */
  6221. break;
  6222. case 0x63: /* arpl */
  6223. if (i386_record_modrm (&ir))
  6224. return -1;
  6225. if (ir.mod == 3 || ir.regmap[X86_RECORD_R8_REGNUM])
  6226. {
  6227. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.regmap[X86_RECORD_R8_REGNUM]
  6228. ? (ir.reg | rex_r) : ir.rm);
  6229. }
  6230. else
  6231. {
  6232. ir.ot = ir.dflag ? OT_LONG : OT_WORD;
  6233. if (i386_record_lea_modrm (&ir))
  6234. return -1;
  6235. }
  6236. if (!ir.regmap[X86_RECORD_R8_REGNUM])
  6237. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  6238. break;
  6239. case 0x0f02: /* lar */
  6240. case 0x0f03: /* lsl */
  6241. if (i386_record_modrm (&ir))
  6242. return -1;
  6243. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg | rex_r);
  6244. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  6245. break;
  6246. case 0x0f18:
  6247. if (i386_record_modrm (&ir))
  6248. return -1;
  6249. if (ir.mod == 3 && ir.reg == 3)
  6250. {
  6251. ir.addr -= 3;
  6252. opcode = opcode << 8 | ir.modrm;
  6253. goto no_support;
  6254. }
  6255. break;
  6256. case 0x0f19:
  6257. case 0x0f1a:
  6258. case 0x0f1b:
  6259. case 0x0f1c:
  6260. case 0x0f1d:
  6261. case 0x0f1e:
  6262. case 0x0f1f:
  6263. /* nop (multi byte) */
  6264. break;
  6265. case 0x0f20: /* mov reg, crN */
  6266. case 0x0f22: /* mov crN, reg */
  6267. if (i386_record_modrm (&ir))
  6268. return -1;
  6269. if ((ir.modrm & 0xc0) != 0xc0)
  6270. {
  6271. ir.addr -= 3;
  6272. opcode = opcode << 8 | ir.modrm;
  6273. goto no_support;
  6274. }
  6275. switch (ir.reg)
  6276. {
  6277. case 0:
  6278. case 2:
  6279. case 3:
  6280. case 4:
  6281. case 8:
  6282. if (opcode & 2)
  6283. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  6284. else
  6285. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
  6286. break;
  6287. default:
  6288. ir.addr -= 3;
  6289. opcode = opcode << 8 | ir.modrm;
  6290. goto no_support;
  6291. break;
  6292. }
  6293. break;
  6294. case 0x0f21: /* mov reg, drN */
  6295. case 0x0f23: /* mov drN, reg */
  6296. if (i386_record_modrm (&ir))
  6297. return -1;
  6298. if ((ir.modrm & 0xc0) != 0xc0 || ir.reg == 4
  6299. || ir.reg == 5 || ir.reg >= 8)
  6300. {
  6301. ir.addr -= 3;
  6302. opcode = opcode << 8 | ir.modrm;
  6303. goto no_support;
  6304. }
  6305. if (opcode & 2)
  6306. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  6307. else
  6308. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
  6309. break;
  6310. case 0x0f06: /* clts */
  6311. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  6312. break;
  6313. /* MMX 3DNow! SSE SSE2 SSE3 SSSE3 SSE4 */
  6314. case 0x0f0d: /* 3DNow! prefetch */
  6315. break;
  6316. case 0x0f0e: /* 3DNow! femms */
  6317. case 0x0f77: /* emms */
  6318. if (i386_fpc_regnum_p (gdbarch, I387_FTAG_REGNUM(tdep)))
  6319. goto no_support;
  6320. record_full_arch_list_add_reg (ir.regcache, I387_FTAG_REGNUM(tdep));
  6321. break;
  6322. case 0x0f0f: /* 3DNow! data */
  6323. if (i386_record_modrm (&ir))
  6324. return -1;
  6325. if (record_read_memory (gdbarch, ir.addr, &opcode8, 1))
  6326. return -1;
  6327. ir.addr++;
  6328. switch (opcode8)
  6329. {
  6330. case 0x0c: /* 3DNow! pi2fw */
  6331. case 0x0d: /* 3DNow! pi2fd */
  6332. case 0x1c: /* 3DNow! pf2iw */
  6333. case 0x1d: /* 3DNow! pf2id */
  6334. case 0x8a: /* 3DNow! pfnacc */
  6335. case 0x8e: /* 3DNow! pfpnacc */
  6336. case 0x90: /* 3DNow! pfcmpge */
  6337. case 0x94: /* 3DNow! pfmin */
  6338. case 0x96: /* 3DNow! pfrcp */
  6339. case 0x97: /* 3DNow! pfrsqrt */
  6340. case 0x9a: /* 3DNow! pfsub */
  6341. case 0x9e: /* 3DNow! pfadd */
  6342. case 0xa0: /* 3DNow! pfcmpgt */
  6343. case 0xa4: /* 3DNow! pfmax */
  6344. case 0xa6: /* 3DNow! pfrcpit1 */
  6345. case 0xa7: /* 3DNow! pfrsqit1 */
  6346. case 0xaa: /* 3DNow! pfsubr */
  6347. case 0xae: /* 3DNow! pfacc */
  6348. case 0xb0: /* 3DNow! pfcmpeq */
  6349. case 0xb4: /* 3DNow! pfmul */
  6350. case 0xb6: /* 3DNow! pfrcpit2 */
  6351. case 0xb7: /* 3DNow! pmulhrw */
  6352. case 0xbb: /* 3DNow! pswapd */
  6353. case 0xbf: /* 3DNow! pavgusb */
  6354. if (!i386_mmx_regnum_p (gdbarch, I387_MM0_REGNUM (tdep) + ir.reg))
  6355. goto no_support_3dnow_data;
  6356. record_full_arch_list_add_reg (ir.regcache, ir.reg);
  6357. break;
  6358. default:
  6359. no_support_3dnow_data:
  6360. opcode = (opcode << 8) | opcode8;
  6361. goto no_support;
  6362. break;
  6363. }
  6364. break;
  6365. case 0x0faa: /* rsm */
  6366. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  6367. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REAX_REGNUM);
  6368. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RECX_REGNUM);
  6369. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDX_REGNUM);
  6370. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBX_REGNUM);
  6371. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESP_REGNUM);
  6372. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REBP_REGNUM);
  6373. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_RESI_REGNUM);
  6374. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REDI_REGNUM);
  6375. break;
  6376. case 0x0fae:
  6377. if (i386_record_modrm (&ir))
  6378. return -1;
  6379. switch(ir.reg)
  6380. {
  6381. case 0: /* fxsave */
  6382. {
  6383. uint64_t tmpu64;
  6384. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  6385. if (i386_record_lea_modrm_addr (&ir, &tmpu64))
  6386. return -1;
  6387. if (record_full_arch_list_add_mem (tmpu64, 512))
  6388. return -1;
  6389. }
  6390. break;
  6391. case 1: /* fxrstor */
  6392. {
  6393. int i;
  6394. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  6395. for (i = I387_MM0_REGNUM (tdep);
  6396. i386_mmx_regnum_p (gdbarch, i); i++)
  6397. record_full_arch_list_add_reg (ir.regcache, i);
  6398. for (i = I387_XMM0_REGNUM (tdep);
  6399. i386_xmm_regnum_p (gdbarch, i); i++)
  6400. record_full_arch_list_add_reg (ir.regcache, i);
  6401. if (i386_mxcsr_regnum_p (gdbarch, I387_MXCSR_REGNUM(tdep)))
  6402. record_full_arch_list_add_reg (ir.regcache,
  6403. I387_MXCSR_REGNUM(tdep));
  6404. for (i = I387_ST0_REGNUM (tdep);
  6405. i386_fp_regnum_p (gdbarch, i); i++)
  6406. record_full_arch_list_add_reg (ir.regcache, i);
  6407. for (i = I387_FCTRL_REGNUM (tdep);
  6408. i386_fpc_regnum_p (gdbarch, i); i++)
  6409. record_full_arch_list_add_reg (ir.regcache, i);
  6410. }
  6411. break;
  6412. case 2: /* ldmxcsr */
  6413. if (!i386_mxcsr_regnum_p (gdbarch, I387_MXCSR_REGNUM(tdep)))
  6414. goto no_support;
  6415. record_full_arch_list_add_reg (ir.regcache, I387_MXCSR_REGNUM(tdep));
  6416. break;
  6417. case 3: /* stmxcsr */
  6418. ir.ot = OT_LONG;
  6419. if (i386_record_lea_modrm (&ir))
  6420. return -1;
  6421. break;
  6422. case 5: /* lfence */
  6423. case 6: /* mfence */
  6424. case 7: /* sfence clflush */
  6425. break;
  6426. default:
  6427. opcode = (opcode << 8) | ir.modrm;
  6428. goto no_support;
  6429. break;
  6430. }
  6431. break;
  6432. case 0x0fc3: /* movnti */
  6433. ir.ot = (ir.dflag == 2) ? OT_QUAD : OT_LONG;
  6434. if (i386_record_modrm (&ir))
  6435. return -1;
  6436. if (ir.mod == 3)
  6437. goto no_support;
  6438. ir.reg |= rex_r;
  6439. if (i386_record_lea_modrm (&ir))
  6440. return -1;
  6441. break;
  6442. /* Add prefix to opcode. */
  6443. case 0x0f10:
  6444. case 0x0f11:
  6445. case 0x0f12:
  6446. case 0x0f13:
  6447. case 0x0f14:
  6448. case 0x0f15:
  6449. case 0x0f16:
  6450. case 0x0f17:
  6451. case 0x0f28:
  6452. case 0x0f29:
  6453. case 0x0f2a:
  6454. case 0x0f2b:
  6455. case 0x0f2c:
  6456. case 0x0f2d:
  6457. case 0x0f2e:
  6458. case 0x0f2f:
  6459. case 0x0f38:
  6460. case 0x0f39:
  6461. case 0x0f3a:
  6462. case 0x0f50:
  6463. case 0x0f51:
  6464. case 0x0f52:
  6465. case 0x0f53:
  6466. case 0x0f54:
  6467. case 0x0f55:
  6468. case 0x0f56:
  6469. case 0x0f57:
  6470. case 0x0f58:
  6471. case 0x0f59:
  6472. case 0x0f5a:
  6473. case 0x0f5b:
  6474. case 0x0f5c:
  6475. case 0x0f5d:
  6476. case 0x0f5e:
  6477. case 0x0f5f:
  6478. case 0x0f60:
  6479. case 0x0f61:
  6480. case 0x0f62:
  6481. case 0x0f63:
  6482. case 0x0f64:
  6483. case 0x0f65:
  6484. case 0x0f66:
  6485. case 0x0f67:
  6486. case 0x0f68:
  6487. case 0x0f69:
  6488. case 0x0f6a:
  6489. case 0x0f6b:
  6490. case 0x0f6c:
  6491. case 0x0f6d:
  6492. case 0x0f6e:
  6493. case 0x0f6f:
  6494. case 0x0f70:
  6495. case 0x0f71:
  6496. case 0x0f72:
  6497. case 0x0f73:
  6498. case 0x0f74:
  6499. case 0x0f75:
  6500. case 0x0f76:
  6501. case 0x0f7c:
  6502. case 0x0f7d:
  6503. case 0x0f7e:
  6504. case 0x0f7f:
  6505. case 0x0fb8:
  6506. case 0x0fc2:
  6507. case 0x0fc4:
  6508. case 0x0fc5:
  6509. case 0x0fc6:
  6510. case 0x0fd0:
  6511. case 0x0fd1:
  6512. case 0x0fd2:
  6513. case 0x0fd3:
  6514. case 0x0fd4:
  6515. case 0x0fd5:
  6516. case 0x0fd6:
  6517. case 0x0fd7:
  6518. case 0x0fd8:
  6519. case 0x0fd9:
  6520. case 0x0fda:
  6521. case 0x0fdb:
  6522. case 0x0fdc:
  6523. case 0x0fdd:
  6524. case 0x0fde:
  6525. case 0x0fdf:
  6526. case 0x0fe0:
  6527. case 0x0fe1:
  6528. case 0x0fe2:
  6529. case 0x0fe3:
  6530. case 0x0fe4:
  6531. case 0x0fe5:
  6532. case 0x0fe6:
  6533. case 0x0fe7:
  6534. case 0x0fe8:
  6535. case 0x0fe9:
  6536. case 0x0fea:
  6537. case 0x0feb:
  6538. case 0x0fec:
  6539. case 0x0fed:
  6540. case 0x0fee:
  6541. case 0x0fef:
  6542. case 0x0ff0:
  6543. case 0x0ff1:
  6544. case 0x0ff2:
  6545. case 0x0ff3:
  6546. case 0x0ff4:
  6547. case 0x0ff5:
  6548. case 0x0ff6:
  6549. case 0x0ff7:
  6550. case 0x0ff8:
  6551. case 0x0ff9:
  6552. case 0x0ffa:
  6553. case 0x0ffb:
  6554. case 0x0ffc:
  6555. case 0x0ffd:
  6556. case 0x0ffe:
  6557. /* Mask out PREFIX_ADDR. */
  6558. switch ((prefixes & ~PREFIX_ADDR))
  6559. {
  6560. case PREFIX_REPNZ:
  6561. opcode |= 0xf20000;
  6562. break;
  6563. case PREFIX_DATA:
  6564. opcode |= 0x660000;
  6565. break;
  6566. case PREFIX_REPZ:
  6567. opcode |= 0xf30000;
  6568. break;
  6569. }
  6570. reswitch_prefix_add:
  6571. switch (opcode)
  6572. {
  6573. case 0x0f38:
  6574. case 0x660f38:
  6575. case 0xf20f38:
  6576. case 0x0f3a:
  6577. case 0x660f3a:
  6578. if (record_read_memory (gdbarch, ir.addr, &opcode8, 1))
  6579. return -1;
  6580. ir.addr++;
  6581. opcode = (uint32_t) opcode8 | opcode << 8;
  6582. goto reswitch_prefix_add;
  6583. break;
  6584. case 0x0f10: /* movups */
  6585. case 0x660f10: /* movupd */
  6586. case 0xf30f10: /* movss */
  6587. case 0xf20f10: /* movsd */
  6588. case 0x0f12: /* movlps */
  6589. case 0x660f12: /* movlpd */
  6590. case 0xf30f12: /* movsldup */
  6591. case 0xf20f12: /* movddup */
  6592. case 0x0f14: /* unpcklps */
  6593. case 0x660f14: /* unpcklpd */
  6594. case 0x0f15: /* unpckhps */
  6595. case 0x660f15: /* unpckhpd */
  6596. case 0x0f16: /* movhps */
  6597. case 0x660f16: /* movhpd */
  6598. case 0xf30f16: /* movshdup */
  6599. case 0x0f28: /* movaps */
  6600. case 0x660f28: /* movapd */
  6601. case 0x0f2a: /* cvtpi2ps */
  6602. case 0x660f2a: /* cvtpi2pd */
  6603. case 0xf30f2a: /* cvtsi2ss */
  6604. case 0xf20f2a: /* cvtsi2sd */
  6605. case 0x0f2c: /* cvttps2pi */
  6606. case 0x660f2c: /* cvttpd2pi */
  6607. case 0x0f2d: /* cvtps2pi */
  6608. case 0x660f2d: /* cvtpd2pi */
  6609. case 0x660f3800: /* pshufb */
  6610. case 0x660f3801: /* phaddw */
  6611. case 0x660f3802: /* phaddd */
  6612. case 0x660f3803: /* phaddsw */
  6613. case 0x660f3804: /* pmaddubsw */
  6614. case 0x660f3805: /* phsubw */
  6615. case 0x660f3806: /* phsubd */
  6616. case 0x660f3807: /* phsubsw */
  6617. case 0x660f3808: /* psignb */
  6618. case 0x660f3809: /* psignw */
  6619. case 0x660f380a: /* psignd */
  6620. case 0x660f380b: /* pmulhrsw */
  6621. case 0x660f3810: /* pblendvb */
  6622. case 0x660f3814: /* blendvps */
  6623. case 0x660f3815: /* blendvpd */
  6624. case 0x660f381c: /* pabsb */
  6625. case 0x660f381d: /* pabsw */
  6626. case 0x660f381e: /* pabsd */
  6627. case 0x660f3820: /* pmovsxbw */
  6628. case 0x660f3821: /* pmovsxbd */
  6629. case 0x660f3822: /* pmovsxbq */
  6630. case 0x660f3823: /* pmovsxwd */
  6631. case 0x660f3824: /* pmovsxwq */
  6632. case 0x660f3825: /* pmovsxdq */
  6633. case 0x660f3828: /* pmuldq */
  6634. case 0x660f3829: /* pcmpeqq */
  6635. case 0x660f382a: /* movntdqa */
  6636. case 0x660f3a08: /* roundps */
  6637. case 0x660f3a09: /* roundpd */
  6638. case 0x660f3a0a: /* roundss */
  6639. case 0x660f3a0b: /* roundsd */
  6640. case 0x660f3a0c: /* blendps */
  6641. case 0x660f3a0d: /* blendpd */
  6642. case 0x660f3a0e: /* pblendw */
  6643. case 0x660f3a0f: /* palignr */
  6644. case 0x660f3a20: /* pinsrb */
  6645. case 0x660f3a21: /* insertps */
  6646. case 0x660f3a22: /* pinsrd pinsrq */
  6647. case 0x660f3a40: /* dpps */
  6648. case 0x660f3a41: /* dppd */
  6649. case 0x660f3a42: /* mpsadbw */
  6650. case 0x660f3a60: /* pcmpestrm */
  6651. case 0x660f3a61: /* pcmpestri */
  6652. case 0x660f3a62: /* pcmpistrm */
  6653. case 0x660f3a63: /* pcmpistri */
  6654. case 0x0f51: /* sqrtps */
  6655. case 0x660f51: /* sqrtpd */
  6656. case 0xf20f51: /* sqrtsd */
  6657. case 0xf30f51: /* sqrtss */
  6658. case 0x0f52: /* rsqrtps */
  6659. case 0xf30f52: /* rsqrtss */
  6660. case 0x0f53: /* rcpps */
  6661. case 0xf30f53: /* rcpss */
  6662. case 0x0f54: /* andps */
  6663. case 0x660f54: /* andpd */
  6664. case 0x0f55: /* andnps */
  6665. case 0x660f55: /* andnpd */
  6666. case 0x0f56: /* orps */
  6667. case 0x660f56: /* orpd */
  6668. case 0x0f57: /* xorps */
  6669. case 0x660f57: /* xorpd */
  6670. case 0x0f58: /* addps */
  6671. case 0x660f58: /* addpd */
  6672. case 0xf20f58: /* addsd */
  6673. case 0xf30f58: /* addss */
  6674. case 0x0f59: /* mulps */
  6675. case 0x660f59: /* mulpd */
  6676. case 0xf20f59: /* mulsd */
  6677. case 0xf30f59: /* mulss */
  6678. case 0x0f5a: /* cvtps2pd */
  6679. case 0x660f5a: /* cvtpd2ps */
  6680. case 0xf20f5a: /* cvtsd2ss */
  6681. case 0xf30f5a: /* cvtss2sd */
  6682. case 0x0f5b: /* cvtdq2ps */
  6683. case 0x660f5b: /* cvtps2dq */
  6684. case 0xf30f5b: /* cvttps2dq */
  6685. case 0x0f5c: /* subps */
  6686. case 0x660f5c: /* subpd */
  6687. case 0xf20f5c: /* subsd */
  6688. case 0xf30f5c: /* subss */
  6689. case 0x0f5d: /* minps */
  6690. case 0x660f5d: /* minpd */
  6691. case 0xf20f5d: /* minsd */
  6692. case 0xf30f5d: /* minss */
  6693. case 0x0f5e: /* divps */
  6694. case 0x660f5e: /* divpd */
  6695. case 0xf20f5e: /* divsd */
  6696. case 0xf30f5e: /* divss */
  6697. case 0x0f5f: /* maxps */
  6698. case 0x660f5f: /* maxpd */
  6699. case 0xf20f5f: /* maxsd */
  6700. case 0xf30f5f: /* maxss */
  6701. case 0x660f60: /* punpcklbw */
  6702. case 0x660f61: /* punpcklwd */
  6703. case 0x660f62: /* punpckldq */
  6704. case 0x660f63: /* packsswb */
  6705. case 0x660f64: /* pcmpgtb */
  6706. case 0x660f65: /* pcmpgtw */
  6707. case 0x660f66: /* pcmpgtd */
  6708. case 0x660f67: /* packuswb */
  6709. case 0x660f68: /* punpckhbw */
  6710. case 0x660f69: /* punpckhwd */
  6711. case 0x660f6a: /* punpckhdq */
  6712. case 0x660f6b: /* packssdw */
  6713. case 0x660f6c: /* punpcklqdq */
  6714. case 0x660f6d: /* punpckhqdq */
  6715. case 0x660f6e: /* movd */
  6716. case 0x660f6f: /* movdqa */
  6717. case 0xf30f6f: /* movdqu */
  6718. case 0x660f70: /* pshufd */
  6719. case 0xf20f70: /* pshuflw */
  6720. case 0xf30f70: /* pshufhw */
  6721. case 0x660f74: /* pcmpeqb */
  6722. case 0x660f75: /* pcmpeqw */
  6723. case 0x660f76: /* pcmpeqd */
  6724. case 0x660f7c: /* haddpd */
  6725. case 0xf20f7c: /* haddps */
  6726. case 0x660f7d: /* hsubpd */
  6727. case 0xf20f7d: /* hsubps */
  6728. case 0xf30f7e: /* movq */
  6729. case 0x0fc2: /* cmpps */
  6730. case 0x660fc2: /* cmppd */
  6731. case 0xf20fc2: /* cmpsd */
  6732. case 0xf30fc2: /* cmpss */
  6733. case 0x660fc4: /* pinsrw */
  6734. case 0x0fc6: /* shufps */
  6735. case 0x660fc6: /* shufpd */
  6736. case 0x660fd0: /* addsubpd */
  6737. case 0xf20fd0: /* addsubps */
  6738. case 0x660fd1: /* psrlw */
  6739. case 0x660fd2: /* psrld */
  6740. case 0x660fd3: /* psrlq */
  6741. case 0x660fd4: /* paddq */
  6742. case 0x660fd5: /* pmullw */
  6743. case 0xf30fd6: /* movq2dq */
  6744. case 0x660fd8: /* psubusb */
  6745. case 0x660fd9: /* psubusw */
  6746. case 0x660fda: /* pminub */
  6747. case 0x660fdb: /* pand */
  6748. case 0x660fdc: /* paddusb */
  6749. case 0x660fdd: /* paddusw */
  6750. case 0x660fde: /* pmaxub */
  6751. case 0x660fdf: /* pandn */
  6752. case 0x660fe0: /* pavgb */
  6753. case 0x660fe1: /* psraw */
  6754. case 0x660fe2: /* psrad */
  6755. case 0x660fe3: /* pavgw */
  6756. case 0x660fe4: /* pmulhuw */
  6757. case 0x660fe5: /* pmulhw */
  6758. case 0x660fe6: /* cvttpd2dq */
  6759. case 0xf20fe6: /* cvtpd2dq */
  6760. case 0xf30fe6: /* cvtdq2pd */
  6761. case 0x660fe8: /* psubsb */
  6762. case 0x660fe9: /* psubsw */
  6763. case 0x660fea: /* pminsw */
  6764. case 0x660feb: /* por */
  6765. case 0x660fec: /* paddsb */
  6766. case 0x660fed: /* paddsw */
  6767. case 0x660fee: /* pmaxsw */
  6768. case 0x660fef: /* pxor */
  6769. case 0xf20ff0: /* lddqu */
  6770. case 0x660ff1: /* psllw */
  6771. case 0x660ff2: /* pslld */
  6772. case 0x660ff3: /* psllq */
  6773. case 0x660ff4: /* pmuludq */
  6774. case 0x660ff5: /* pmaddwd */
  6775. case 0x660ff6: /* psadbw */
  6776. case 0x660ff8: /* psubb */
  6777. case 0x660ff9: /* psubw */
  6778. case 0x660ffa: /* psubd */
  6779. case 0x660ffb: /* psubq */
  6780. case 0x660ffc: /* paddb */
  6781. case 0x660ffd: /* paddw */
  6782. case 0x660ffe: /* paddd */
  6783. if (i386_record_modrm (&ir))
  6784. return -1;
  6785. ir.reg |= rex_r;
  6786. if (!i386_xmm_regnum_p (gdbarch, I387_XMM0_REGNUM (tdep) + ir.reg))
  6787. goto no_support;
  6788. record_full_arch_list_add_reg (ir.regcache,
  6789. I387_XMM0_REGNUM (tdep) + ir.reg);
  6790. if ((opcode & 0xfffffffc) == 0x660f3a60)
  6791. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  6792. break;
  6793. case 0x0f11: /* movups */
  6794. case 0x660f11: /* movupd */
  6795. case 0xf30f11: /* movss */
  6796. case 0xf20f11: /* movsd */
  6797. case 0x0f13: /* movlps */
  6798. case 0x660f13: /* movlpd */
  6799. case 0x0f17: /* movhps */
  6800. case 0x660f17: /* movhpd */
  6801. case 0x0f29: /* movaps */
  6802. case 0x660f29: /* movapd */
  6803. case 0x660f3a14: /* pextrb */
  6804. case 0x660f3a15: /* pextrw */
  6805. case 0x660f3a16: /* pextrd pextrq */
  6806. case 0x660f3a17: /* extractps */
  6807. case 0x660f7f: /* movdqa */
  6808. case 0xf30f7f: /* movdqu */
  6809. if (i386_record_modrm (&ir))
  6810. return -1;
  6811. if (ir.mod == 3)
  6812. {
  6813. if (opcode == 0x0f13 || opcode == 0x660f13
  6814. || opcode == 0x0f17 || opcode == 0x660f17)
  6815. goto no_support;
  6816. ir.rm |= ir.rex_b;
  6817. if (!i386_xmm_regnum_p (gdbarch,
  6818. I387_XMM0_REGNUM (tdep) + ir.rm))
  6819. goto no_support;
  6820. record_full_arch_list_add_reg (ir.regcache,
  6821. I387_XMM0_REGNUM (tdep) + ir.rm);
  6822. }
  6823. else
  6824. {
  6825. switch (opcode)
  6826. {
  6827. case 0x660f3a14:
  6828. ir.ot = OT_BYTE;
  6829. break;
  6830. case 0x660f3a15:
  6831. ir.ot = OT_WORD;
  6832. break;
  6833. case 0x660f3a16:
  6834. ir.ot = OT_LONG;
  6835. break;
  6836. case 0x660f3a17:
  6837. ir.ot = OT_QUAD;
  6838. break;
  6839. default:
  6840. ir.ot = OT_DQUAD;
  6841. break;
  6842. }
  6843. if (i386_record_lea_modrm (&ir))
  6844. return -1;
  6845. }
  6846. break;
  6847. case 0x0f2b: /* movntps */
  6848. case 0x660f2b: /* movntpd */
  6849. case 0x0fe7: /* movntq */
  6850. case 0x660fe7: /* movntdq */
  6851. if (ir.mod == 3)
  6852. goto no_support;
  6853. if (opcode == 0x0fe7)
  6854. ir.ot = OT_QUAD;
  6855. else
  6856. ir.ot = OT_DQUAD;
  6857. if (i386_record_lea_modrm (&ir))
  6858. return -1;
  6859. break;
  6860. case 0xf30f2c: /* cvttss2si */
  6861. case 0xf20f2c: /* cvttsd2si */
  6862. case 0xf30f2d: /* cvtss2si */
  6863. case 0xf20f2d: /* cvtsd2si */
  6864. case 0xf20f38f0: /* crc32 */
  6865. case 0xf20f38f1: /* crc32 */
  6866. case 0x0f50: /* movmskps */
  6867. case 0x660f50: /* movmskpd */
  6868. case 0x0fc5: /* pextrw */
  6869. case 0x660fc5: /* pextrw */
  6870. case 0x0fd7: /* pmovmskb */
  6871. case 0x660fd7: /* pmovmskb */
  6872. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg | rex_r);
  6873. break;
  6874. case 0x0f3800: /* pshufb */
  6875. case 0x0f3801: /* phaddw */
  6876. case 0x0f3802: /* phaddd */
  6877. case 0x0f3803: /* phaddsw */
  6878. case 0x0f3804: /* pmaddubsw */
  6879. case 0x0f3805: /* phsubw */
  6880. case 0x0f3806: /* phsubd */
  6881. case 0x0f3807: /* phsubsw */
  6882. case 0x0f3808: /* psignb */
  6883. case 0x0f3809: /* psignw */
  6884. case 0x0f380a: /* psignd */
  6885. case 0x0f380b: /* pmulhrsw */
  6886. case 0x0f381c: /* pabsb */
  6887. case 0x0f381d: /* pabsw */
  6888. case 0x0f381e: /* pabsd */
  6889. case 0x0f382b: /* packusdw */
  6890. case 0x0f3830: /* pmovzxbw */
  6891. case 0x0f3831: /* pmovzxbd */
  6892. case 0x0f3832: /* pmovzxbq */
  6893. case 0x0f3833: /* pmovzxwd */
  6894. case 0x0f3834: /* pmovzxwq */
  6895. case 0x0f3835: /* pmovzxdq */
  6896. case 0x0f3837: /* pcmpgtq */
  6897. case 0x0f3838: /* pminsb */
  6898. case 0x0f3839: /* pminsd */
  6899. case 0x0f383a: /* pminuw */
  6900. case 0x0f383b: /* pminud */
  6901. case 0x0f383c: /* pmaxsb */
  6902. case 0x0f383d: /* pmaxsd */
  6903. case 0x0f383e: /* pmaxuw */
  6904. case 0x0f383f: /* pmaxud */
  6905. case 0x0f3840: /* pmulld */
  6906. case 0x0f3841: /* phminposuw */
  6907. case 0x0f3a0f: /* palignr */
  6908. case 0x0f60: /* punpcklbw */
  6909. case 0x0f61: /* punpcklwd */
  6910. case 0x0f62: /* punpckldq */
  6911. case 0x0f63: /* packsswb */
  6912. case 0x0f64: /* pcmpgtb */
  6913. case 0x0f65: /* pcmpgtw */
  6914. case 0x0f66: /* pcmpgtd */
  6915. case 0x0f67: /* packuswb */
  6916. case 0x0f68: /* punpckhbw */
  6917. case 0x0f69: /* punpckhwd */
  6918. case 0x0f6a: /* punpckhdq */
  6919. case 0x0f6b: /* packssdw */
  6920. case 0x0f6e: /* movd */
  6921. case 0x0f6f: /* movq */
  6922. case 0x0f70: /* pshufw */
  6923. case 0x0f74: /* pcmpeqb */
  6924. case 0x0f75: /* pcmpeqw */
  6925. case 0x0f76: /* pcmpeqd */
  6926. case 0x0fc4: /* pinsrw */
  6927. case 0x0fd1: /* psrlw */
  6928. case 0x0fd2: /* psrld */
  6929. case 0x0fd3: /* psrlq */
  6930. case 0x0fd4: /* paddq */
  6931. case 0x0fd5: /* pmullw */
  6932. case 0xf20fd6: /* movdq2q */
  6933. case 0x0fd8: /* psubusb */
  6934. case 0x0fd9: /* psubusw */
  6935. case 0x0fda: /* pminub */
  6936. case 0x0fdb: /* pand */
  6937. case 0x0fdc: /* paddusb */
  6938. case 0x0fdd: /* paddusw */
  6939. case 0x0fde: /* pmaxub */
  6940. case 0x0fdf: /* pandn */
  6941. case 0x0fe0: /* pavgb */
  6942. case 0x0fe1: /* psraw */
  6943. case 0x0fe2: /* psrad */
  6944. case 0x0fe3: /* pavgw */
  6945. case 0x0fe4: /* pmulhuw */
  6946. case 0x0fe5: /* pmulhw */
  6947. case 0x0fe8: /* psubsb */
  6948. case 0x0fe9: /* psubsw */
  6949. case 0x0fea: /* pminsw */
  6950. case 0x0feb: /* por */
  6951. case 0x0fec: /* paddsb */
  6952. case 0x0fed: /* paddsw */
  6953. case 0x0fee: /* pmaxsw */
  6954. case 0x0fef: /* pxor */
  6955. case 0x0ff1: /* psllw */
  6956. case 0x0ff2: /* pslld */
  6957. case 0x0ff3: /* psllq */
  6958. case 0x0ff4: /* pmuludq */
  6959. case 0x0ff5: /* pmaddwd */
  6960. case 0x0ff6: /* psadbw */
  6961. case 0x0ff8: /* psubb */
  6962. case 0x0ff9: /* psubw */
  6963. case 0x0ffa: /* psubd */
  6964. case 0x0ffb: /* psubq */
  6965. case 0x0ffc: /* paddb */
  6966. case 0x0ffd: /* paddw */
  6967. case 0x0ffe: /* paddd */
  6968. if (i386_record_modrm (&ir))
  6969. return -1;
  6970. if (!i386_mmx_regnum_p (gdbarch, I387_MM0_REGNUM (tdep) + ir.reg))
  6971. goto no_support;
  6972. record_full_arch_list_add_reg (ir.regcache,
  6973. I387_MM0_REGNUM (tdep) + ir.reg);
  6974. break;
  6975. case 0x0f71: /* psllw */
  6976. case 0x0f72: /* pslld */
  6977. case 0x0f73: /* psllq */
  6978. if (i386_record_modrm (&ir))
  6979. return -1;
  6980. if (!i386_mmx_regnum_p (gdbarch, I387_MM0_REGNUM (tdep) + ir.rm))
  6981. goto no_support;
  6982. record_full_arch_list_add_reg (ir.regcache,
  6983. I387_MM0_REGNUM (tdep) + ir.rm);
  6984. break;
  6985. case 0x660f71: /* psllw */
  6986. case 0x660f72: /* pslld */
  6987. case 0x660f73: /* psllq */
  6988. if (i386_record_modrm (&ir))
  6989. return -1;
  6990. ir.rm |= ir.rex_b;
  6991. if (!i386_xmm_regnum_p (gdbarch, I387_XMM0_REGNUM (tdep) + ir.rm))
  6992. goto no_support;
  6993. record_full_arch_list_add_reg (ir.regcache,
  6994. I387_XMM0_REGNUM (tdep) + ir.rm);
  6995. break;
  6996. case 0x0f7e: /* movd */
  6997. case 0x660f7e: /* movd */
  6998. if (i386_record_modrm (&ir))
  6999. return -1;
  7000. if (ir.mod == 3)
  7001. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.rm | ir.rex_b);
  7002. else
  7003. {
  7004. if (ir.dflag == 2)
  7005. ir.ot = OT_QUAD;
  7006. else
  7007. ir.ot = OT_LONG;
  7008. if (i386_record_lea_modrm (&ir))
  7009. return -1;
  7010. }
  7011. break;
  7012. case 0x0f7f: /* movq */
  7013. if (i386_record_modrm (&ir))
  7014. return -1;
  7015. if (ir.mod == 3)
  7016. {
  7017. if (!i386_mmx_regnum_p (gdbarch, I387_MM0_REGNUM (tdep) + ir.rm))
  7018. goto no_support;
  7019. record_full_arch_list_add_reg (ir.regcache,
  7020. I387_MM0_REGNUM (tdep) + ir.rm);
  7021. }
  7022. else
  7023. {
  7024. ir.ot = OT_QUAD;
  7025. if (i386_record_lea_modrm (&ir))
  7026. return -1;
  7027. }
  7028. break;
  7029. case 0xf30fb8: /* popcnt */
  7030. if (i386_record_modrm (&ir))
  7031. return -1;
  7032. I386_RECORD_FULL_ARCH_LIST_ADD_REG (ir.reg);
  7033. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  7034. break;
  7035. case 0x660fd6: /* movq */
  7036. if (i386_record_modrm (&ir))
  7037. return -1;
  7038. if (ir.mod == 3)
  7039. {
  7040. ir.rm |= ir.rex_b;
  7041. if (!i386_xmm_regnum_p (gdbarch,
  7042. I387_XMM0_REGNUM (tdep) + ir.rm))
  7043. goto no_support;
  7044. record_full_arch_list_add_reg (ir.regcache,
  7045. I387_XMM0_REGNUM (tdep) + ir.rm);
  7046. }
  7047. else
  7048. {
  7049. ir.ot = OT_QUAD;
  7050. if (i386_record_lea_modrm (&ir))
  7051. return -1;
  7052. }
  7053. break;
  7054. case 0x660f3817: /* ptest */
  7055. case 0x0f2e: /* ucomiss */
  7056. case 0x660f2e: /* ucomisd */
  7057. case 0x0f2f: /* comiss */
  7058. case 0x660f2f: /* comisd */
  7059. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_EFLAGS_REGNUM);
  7060. break;
  7061. case 0x0ff7: /* maskmovq */
  7062. regcache_raw_read_unsigned (ir.regcache,
  7063. ir.regmap[X86_RECORD_REDI_REGNUM],
  7064. &addr);
  7065. if (record_full_arch_list_add_mem (addr, 64))
  7066. return -1;
  7067. break;
  7068. case 0x660ff7: /* maskmovdqu */
  7069. regcache_raw_read_unsigned (ir.regcache,
  7070. ir.regmap[X86_RECORD_REDI_REGNUM],
  7071. &addr);
  7072. if (record_full_arch_list_add_mem (addr, 128))
  7073. return -1;
  7074. break;
  7075. default:
  7076. goto no_support;
  7077. break;
  7078. }
  7079. break;
  7080. default:
  7081. goto no_support;
  7082. break;
  7083. }
  7084. /* In the future, maybe still need to deal with need_dasm. */
  7085. I386_RECORD_FULL_ARCH_LIST_ADD_REG (X86_RECORD_REIP_REGNUM);
  7086. if (record_full_arch_list_add_end ())
  7087. return -1;
  7088. return 0;
  7089. no_support:
  7090. gdb_printf (gdb_stderr,
  7091. _("Process record does not support instruction 0x%02x "
  7092. "at address %s.\n"),
  7093. (unsigned int) (opcode),
  7094. paddress (gdbarch, ir.orig_addr));
  7095. return -1;
  7096. }
  7097. static const int i386_record_regmap[] =
  7098. {
  7099. I386_EAX_REGNUM, I386_ECX_REGNUM, I386_EDX_REGNUM, I386_EBX_REGNUM,
  7100. I386_ESP_REGNUM, I386_EBP_REGNUM, I386_ESI_REGNUM, I386_EDI_REGNUM,
  7101. 0, 0, 0, 0, 0, 0, 0, 0,
  7102. I386_EIP_REGNUM, I386_EFLAGS_REGNUM, I386_CS_REGNUM, I386_SS_REGNUM,
  7103. I386_DS_REGNUM, I386_ES_REGNUM, I386_FS_REGNUM, I386_GS_REGNUM
  7104. };
  7105. /* Check that the given address appears suitable for a fast
  7106. tracepoint, which on x86-64 means that we need an instruction of at
  7107. least 5 bytes, so that we can overwrite it with a 4-byte-offset
  7108. jump and not have to worry about program jumps to an address in the
  7109. middle of the tracepoint jump. On x86, it may be possible to use
  7110. 4-byte jumps with a 2-byte offset to a trampoline located in the
  7111. bottom 64 KiB of memory. Returns 1 if OK, and writes a size
  7112. of instruction to replace, and 0 if not, plus an explanatory
  7113. string. */
  7114. static int
  7115. i386_fast_tracepoint_valid_at (struct gdbarch *gdbarch, CORE_ADDR addr,
  7116. std::string *msg)
  7117. {
  7118. int len, jumplen;
  7119. /* Ask the target for the minimum instruction length supported. */
  7120. jumplen = target_get_min_fast_tracepoint_insn_len ();
  7121. if (jumplen < 0)
  7122. {
  7123. /* If the target does not support the get_min_fast_tracepoint_insn_len
  7124. operation, assume that fast tracepoints will always be implemented
  7125. using 4-byte relative jumps on both x86 and x86-64. */
  7126. jumplen = 5;
  7127. }
  7128. else if (jumplen == 0)
  7129. {
  7130. /* If the target does support get_min_fast_tracepoint_insn_len but
  7131. returns zero, then the IPA has not loaded yet. In this case,
  7132. we optimistically assume that truncated 2-byte relative jumps
  7133. will be available on x86, and compensate later if this assumption
  7134. turns out to be incorrect. On x86-64 architectures, 4-byte relative
  7135. jumps will always be used. */
  7136. jumplen = (register_size (gdbarch, 0) == 8) ? 5 : 4;
  7137. }
  7138. /* Check for fit. */
  7139. len = gdb_insn_length (gdbarch, addr);
  7140. if (len < jumplen)
  7141. {
  7142. /* Return a bit of target-specific detail to add to the caller's
  7143. generic failure message. */
  7144. if (msg)
  7145. *msg = string_printf (_("; instruction is only %d bytes long, "
  7146. "need at least %d bytes for the jump"),
  7147. len, jumplen);
  7148. return 0;
  7149. }
  7150. else
  7151. {
  7152. if (msg)
  7153. msg->clear ();
  7154. return 1;
  7155. }
  7156. }
  7157. /* Return a floating-point format for a floating-point variable of
  7158. length LEN in bits. If non-NULL, NAME is the name of its type.
  7159. If no suitable type is found, return NULL. */
  7160. static const struct floatformat **
  7161. i386_floatformat_for_type (struct gdbarch *gdbarch,
  7162. const char *name, int len)
  7163. {
  7164. if (len == 128 && name)
  7165. if (strcmp (name, "__float128") == 0
  7166. || strcmp (name, "_Float128") == 0
  7167. || strcmp (name, "complex _Float128") == 0
  7168. || strcmp (name, "complex(kind=16)") == 0
  7169. || strcmp (name, "complex*32") == 0
  7170. || strcmp (name, "COMPLEX*32") == 0
  7171. || strcmp (name, "quad complex") == 0
  7172. || strcmp (name, "real(kind=16)") == 0
  7173. || strcmp (name, "real*16") == 0
  7174. || strcmp (name, "REAL*16") == 0)
  7175. return floatformats_ieee_quad;
  7176. return default_floatformat_for_type (gdbarch, name, len);
  7177. }
  7178. static int
  7179. i386_validate_tdesc_p (i386_gdbarch_tdep *tdep,
  7180. struct tdesc_arch_data *tdesc_data)
  7181. {
  7182. const struct target_desc *tdesc = tdep->tdesc;
  7183. const struct tdesc_feature *feature_core;
  7184. const struct tdesc_feature *feature_sse, *feature_avx, *feature_mpx,
  7185. *feature_avx512, *feature_pkeys, *feature_segments;
  7186. int i, num_regs, valid_p;
  7187. if (! tdesc_has_registers (tdesc))
  7188. return 0;
  7189. /* Get core registers. */
  7190. feature_core = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.core");
  7191. if (feature_core == NULL)
  7192. return 0;
  7193. /* Get SSE registers. */
  7194. feature_sse = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.sse");
  7195. /* Try AVX registers. */
  7196. feature_avx = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.avx");
  7197. /* Try MPX registers. */
  7198. feature_mpx = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.mpx");
  7199. /* Try AVX512 registers. */
  7200. feature_avx512 = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.avx512");
  7201. /* Try segment base registers. */
  7202. feature_segments = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.segments");
  7203. /* Try PKEYS */
  7204. feature_pkeys = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.pkeys");
  7205. valid_p = 1;
  7206. /* The XCR0 bits. */
  7207. if (feature_avx512)
  7208. {
  7209. /* AVX512 register description requires AVX register description. */
  7210. if (!feature_avx)
  7211. return 0;
  7212. tdep->xcr0 = X86_XSTATE_AVX_AVX512_MASK;
  7213. /* It may have been set by OSABI initialization function. */
  7214. if (tdep->k0_regnum < 0)
  7215. {
  7216. tdep->k_register_names = i386_k_names;
  7217. tdep->k0_regnum = I386_K0_REGNUM;
  7218. }
  7219. for (i = 0; i < I387_NUM_K_REGS; i++)
  7220. valid_p &= tdesc_numbered_register (feature_avx512, tdesc_data,
  7221. tdep->k0_regnum + i,
  7222. i386_k_names[i]);
  7223. if (tdep->num_zmm_regs == 0)
  7224. {
  7225. tdep->zmmh_register_names = i386_zmmh_names;
  7226. tdep->num_zmm_regs = 8;
  7227. tdep->zmm0h_regnum = I386_ZMM0H_REGNUM;
  7228. }
  7229. for (i = 0; i < tdep->num_zmm_regs; i++)
  7230. valid_p &= tdesc_numbered_register (feature_avx512, tdesc_data,
  7231. tdep->zmm0h_regnum + i,
  7232. tdep->zmmh_register_names[i]);
  7233. for (i = 0; i < tdep->num_xmm_avx512_regs; i++)
  7234. valid_p &= tdesc_numbered_register (feature_avx512, tdesc_data,
  7235. tdep->xmm16_regnum + i,
  7236. tdep->xmm_avx512_register_names[i]);
  7237. for (i = 0; i < tdep->num_ymm_avx512_regs; i++)
  7238. valid_p &= tdesc_numbered_register (feature_avx512, tdesc_data,
  7239. tdep->ymm16h_regnum + i,
  7240. tdep->ymm16h_register_names[i]);
  7241. }
  7242. if (feature_avx)
  7243. {
  7244. /* AVX register description requires SSE register description. */
  7245. if (!feature_sse)
  7246. return 0;
  7247. if (!feature_avx512)
  7248. tdep->xcr0 = X86_XSTATE_AVX_MASK;
  7249. /* It may have been set by OSABI initialization function. */
  7250. if (tdep->num_ymm_regs == 0)
  7251. {
  7252. tdep->ymmh_register_names = i386_ymmh_names;
  7253. tdep->num_ymm_regs = 8;
  7254. tdep->ymm0h_regnum = I386_YMM0H_REGNUM;
  7255. }
  7256. for (i = 0; i < tdep->num_ymm_regs; i++)
  7257. valid_p &= tdesc_numbered_register (feature_avx, tdesc_data,
  7258. tdep->ymm0h_regnum + i,
  7259. tdep->ymmh_register_names[i]);
  7260. }
  7261. else if (feature_sse)
  7262. tdep->xcr0 = X86_XSTATE_SSE_MASK;
  7263. else
  7264. {
  7265. tdep->xcr0 = X86_XSTATE_X87_MASK;
  7266. tdep->num_xmm_regs = 0;
  7267. }
  7268. num_regs = tdep->num_core_regs;
  7269. for (i = 0; i < num_regs; i++)
  7270. valid_p &= tdesc_numbered_register (feature_core, tdesc_data, i,
  7271. tdep->register_names[i]);
  7272. if (feature_sse)
  7273. {
  7274. /* Need to include %mxcsr, so add one. */
  7275. num_regs += tdep->num_xmm_regs + 1;
  7276. for (; i < num_regs; i++)
  7277. valid_p &= tdesc_numbered_register (feature_sse, tdesc_data, i,
  7278. tdep->register_names[i]);
  7279. }
  7280. if (feature_mpx)
  7281. {
  7282. tdep->xcr0 |= X86_XSTATE_MPX_MASK;
  7283. if (tdep->bnd0r_regnum < 0)
  7284. {
  7285. tdep->mpx_register_names = i386_mpx_names;
  7286. tdep->bnd0r_regnum = I386_BND0R_REGNUM;
  7287. tdep->bndcfgu_regnum = I386_BNDCFGU_REGNUM;
  7288. }
  7289. for (i = 0; i < I387_NUM_MPX_REGS; i++)
  7290. valid_p &= tdesc_numbered_register (feature_mpx, tdesc_data,
  7291. I387_BND0R_REGNUM (tdep) + i,
  7292. tdep->mpx_register_names[i]);
  7293. }
  7294. if (feature_segments)
  7295. {
  7296. if (tdep->fsbase_regnum < 0)
  7297. tdep->fsbase_regnum = I386_FSBASE_REGNUM;
  7298. valid_p &= tdesc_numbered_register (feature_segments, tdesc_data,
  7299. tdep->fsbase_regnum, "fs_base");
  7300. valid_p &= tdesc_numbered_register (feature_segments, tdesc_data,
  7301. tdep->fsbase_regnum + 1, "gs_base");
  7302. }
  7303. if (feature_pkeys)
  7304. {
  7305. tdep->xcr0 |= X86_XSTATE_PKRU;
  7306. if (tdep->pkru_regnum < 0)
  7307. {
  7308. tdep->pkeys_register_names = i386_pkeys_names;
  7309. tdep->pkru_regnum = I386_PKRU_REGNUM;
  7310. tdep->num_pkeys_regs = 1;
  7311. }
  7312. for (i = 0; i < I387_NUM_PKEYS_REGS; i++)
  7313. valid_p &= tdesc_numbered_register (feature_pkeys, tdesc_data,
  7314. I387_PKRU_REGNUM (tdep) + i,
  7315. tdep->pkeys_register_names[i]);
  7316. }
  7317. return valid_p;
  7318. }
  7319. /* Implement the type_align gdbarch function. */
  7320. static ULONGEST
  7321. i386_type_align (struct gdbarch *gdbarch, struct type *type)
  7322. {
  7323. type = check_typedef (type);
  7324. if (gdbarch_ptr_bit (gdbarch) == 32)
  7325. {
  7326. if ((type->code () == TYPE_CODE_INT
  7327. || type->code () == TYPE_CODE_FLT)
  7328. && TYPE_LENGTH (type) > 4)
  7329. return 4;
  7330. /* Handle x86's funny long double. */
  7331. if (type->code () == TYPE_CODE_FLT
  7332. && gdbarch_long_double_bit (gdbarch) == TYPE_LENGTH (type) * 8)
  7333. return 4;
  7334. }
  7335. return 0;
  7336. }
  7337. /* Note: This is called for both i386 and amd64. */
  7338. static struct gdbarch *
  7339. i386_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
  7340. {
  7341. struct gdbarch *gdbarch;
  7342. const struct target_desc *tdesc;
  7343. int mm0_regnum;
  7344. int ymm0_regnum;
  7345. int bnd0_regnum;
  7346. int num_bnd_cooked;
  7347. /* If there is already a candidate, use it. */
  7348. arches = gdbarch_list_lookup_by_info (arches, &info);
  7349. if (arches != NULL)
  7350. return arches->gdbarch;
  7351. /* Allocate space for the new architecture. Assume i386 for now. */
  7352. i386_gdbarch_tdep *tdep = new i386_gdbarch_tdep;
  7353. gdbarch = gdbarch_alloc (&info, tdep);
  7354. /* General-purpose registers. */
  7355. tdep->gregset_reg_offset = NULL;
  7356. tdep->gregset_num_regs = I386_NUM_GREGS;
  7357. tdep->sizeof_gregset = 0;
  7358. /* Floating-point registers. */
  7359. tdep->sizeof_fpregset = I387_SIZEOF_FSAVE;
  7360. tdep->fpregset = &i386_fpregset;
  7361. /* The default settings include the FPU registers, the MMX registers
  7362. and the SSE registers. This can be overridden for a specific ABI
  7363. by adjusting the members `st0_regnum', `mm0_regnum' and
  7364. `num_xmm_regs' of `struct gdbarch_tdep', otherwise the registers
  7365. will show up in the output of "info all-registers". */
  7366. tdep->st0_regnum = I386_ST0_REGNUM;
  7367. /* I386_NUM_XREGS includes %mxcsr, so substract one. */
  7368. tdep->num_xmm_regs = I386_NUM_XREGS - 1;
  7369. tdep->jb_pc_offset = -1;
  7370. tdep->struct_return = pcc_struct_return;
  7371. tdep->sigtramp_start = 0;
  7372. tdep->sigtramp_end = 0;
  7373. tdep->sigtramp_p = i386_sigtramp_p;
  7374. tdep->sigcontext_addr = NULL;
  7375. tdep->sc_reg_offset = NULL;
  7376. tdep->sc_pc_offset = -1;
  7377. tdep->sc_sp_offset = -1;
  7378. tdep->xsave_xcr0_offset = -1;
  7379. tdep->record_regmap = i386_record_regmap;
  7380. set_gdbarch_type_align (gdbarch, i386_type_align);
  7381. /* The format used for `long double' on almost all i386 targets is
  7382. the i387 extended floating-point format. In fact, of all targets
  7383. in the GCC 2.95 tree, only OSF/1 does it different, and insists
  7384. on having a `long double' that's not `long' at all. */
  7385. set_gdbarch_long_double_format (gdbarch, floatformats_i387_ext);
  7386. /* Although the i387 extended floating-point has only 80 significant
  7387. bits, a `long double' actually takes up 96, probably to enforce
  7388. alignment. */
  7389. set_gdbarch_long_double_bit (gdbarch, 96);
  7390. /* Support of bfloat16 format. */
  7391. set_gdbarch_bfloat16_format (gdbarch, floatformats_bfloat16);
  7392. /* Support for floating-point data type variants. */
  7393. set_gdbarch_floatformat_for_type (gdbarch, i386_floatformat_for_type);
  7394. /* Register numbers of various important registers. */
  7395. set_gdbarch_sp_regnum (gdbarch, I386_ESP_REGNUM); /* %esp */
  7396. set_gdbarch_pc_regnum (gdbarch, I386_EIP_REGNUM); /* %eip */
  7397. set_gdbarch_ps_regnum (gdbarch, I386_EFLAGS_REGNUM); /* %eflags */
  7398. set_gdbarch_fp0_regnum (gdbarch, I386_ST0_REGNUM); /* %st(0) */
  7399. /* NOTE: kettenis/20040418: GCC does have two possible register
  7400. numbering schemes on the i386: dbx and SVR4. These schemes
  7401. differ in how they number %ebp, %esp, %eflags, and the
  7402. floating-point registers, and are implemented by the arrays
  7403. dbx_register_map[] and svr4_dbx_register_map in
  7404. gcc/config/i386.c. GCC also defines a third numbering scheme in
  7405. gcc/config/i386.c, which it designates as the "default" register
  7406. map used in 64bit mode. This last register numbering scheme is
  7407. implemented in dbx64_register_map, and is used for AMD64; see
  7408. amd64-tdep.c.
  7409. Currently, each GCC i386 target always uses the same register
  7410. numbering scheme across all its supported debugging formats
  7411. i.e. SDB (COFF), stabs and DWARF 2. This is because
  7412. gcc/sdbout.c, gcc/dbxout.c and gcc/dwarf2out.c all use the
  7413. DBX_REGISTER_NUMBER macro which is defined by each target's
  7414. respective config header in a manner independent of the requested
  7415. output debugging format.
  7416. This does not match the arrangement below, which presumes that
  7417. the SDB and stabs numbering schemes differ from the DWARF and
  7418. DWARF 2 ones. The reason for this arrangement is that it is
  7419. likely to get the numbering scheme for the target's
  7420. default/native debug format right. For targets where GCC is the
  7421. native compiler (FreeBSD, NetBSD, OpenBSD, GNU/Linux) or for
  7422. targets where the native toolchain uses a different numbering
  7423. scheme for a particular debug format (stabs-in-ELF on Solaris)
  7424. the defaults below will have to be overridden, like
  7425. i386_elf_init_abi() does. */
  7426. /* Use the dbx register numbering scheme for stabs and COFF. */
  7427. set_gdbarch_stab_reg_to_regnum (gdbarch, i386_dbx_reg_to_regnum);
  7428. set_gdbarch_sdb_reg_to_regnum (gdbarch, i386_dbx_reg_to_regnum);
  7429. /* Use the SVR4 register numbering scheme for DWARF 2. */
  7430. set_gdbarch_dwarf2_reg_to_regnum (gdbarch, i386_svr4_dwarf_reg_to_regnum);
  7431. /* We don't set gdbarch_stab_reg_to_regnum, since ECOFF doesn't seem to
  7432. be in use on any of the supported i386 targets. */
  7433. set_gdbarch_print_float_info (gdbarch, i387_print_float_info);
  7434. set_gdbarch_get_longjmp_target (gdbarch, i386_get_longjmp_target);
  7435. /* Call dummy code. */
  7436. set_gdbarch_call_dummy_location (gdbarch, ON_STACK);
  7437. set_gdbarch_push_dummy_code (gdbarch, i386_push_dummy_code);
  7438. set_gdbarch_push_dummy_call (gdbarch, i386_push_dummy_call);
  7439. set_gdbarch_frame_align (gdbarch, i386_frame_align);
  7440. set_gdbarch_convert_register_p (gdbarch, i386_convert_register_p);
  7441. set_gdbarch_register_to_value (gdbarch, i386_register_to_value);
  7442. set_gdbarch_value_to_register (gdbarch, i386_value_to_register);
  7443. set_gdbarch_return_value (gdbarch, i386_return_value);
  7444. set_gdbarch_skip_prologue (gdbarch, i386_skip_prologue);
  7445. /* Stack grows downward. */
  7446. set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
  7447. set_gdbarch_breakpoint_kind_from_pc (gdbarch, i386_breakpoint::kind_from_pc);
  7448. set_gdbarch_sw_breakpoint_from_kind (gdbarch, i386_breakpoint::bp_from_kind);
  7449. set_gdbarch_decr_pc_after_break (gdbarch, 1);
  7450. set_gdbarch_max_insn_length (gdbarch, I386_MAX_INSN_LEN);
  7451. set_gdbarch_frame_args_skip (gdbarch, 8);
  7452. set_gdbarch_print_insn (gdbarch, i386_print_insn);
  7453. set_gdbarch_dummy_id (gdbarch, i386_dummy_id);
  7454. set_gdbarch_unwind_pc (gdbarch, i386_unwind_pc);
  7455. /* Add the i386 register groups. */
  7456. i386_add_reggroups (gdbarch);
  7457. tdep->register_reggroup_p = i386_register_reggroup_p;
  7458. /* Helper for function argument information. */
  7459. set_gdbarch_fetch_pointer_argument (gdbarch, i386_fetch_pointer_argument);
  7460. /* Hook the function epilogue frame unwinder. This unwinder is
  7461. appended to the list first, so that it supercedes the DWARF
  7462. unwinder in function epilogues (where the DWARF unwinder
  7463. currently fails). */
  7464. frame_unwind_append_unwinder (gdbarch, &i386_epilogue_frame_unwind);
  7465. /* Hook in the DWARF CFI frame unwinder. This unwinder is appended
  7466. to the list before the prologue-based unwinders, so that DWARF
  7467. CFI info will be used if it is available. */
  7468. dwarf2_append_unwinders (gdbarch);
  7469. frame_base_set_default (gdbarch, &i386_frame_base);
  7470. /* Pseudo registers may be changed by amd64_init_abi. */
  7471. set_gdbarch_pseudo_register_read_value (gdbarch,
  7472. i386_pseudo_register_read_value);
  7473. set_gdbarch_pseudo_register_write (gdbarch, i386_pseudo_register_write);
  7474. set_gdbarch_ax_pseudo_register_collect (gdbarch,
  7475. i386_ax_pseudo_register_collect);
  7476. set_tdesc_pseudo_register_type (gdbarch, i386_pseudo_register_type);
  7477. set_tdesc_pseudo_register_name (gdbarch, i386_pseudo_register_name);
  7478. /* Override the normal target description method to make the AVX
  7479. upper halves anonymous. */
  7480. set_gdbarch_register_name (gdbarch, i386_register_name);
  7481. /* Even though the default ABI only includes general-purpose registers,
  7482. floating-point registers and the SSE registers, we have to leave a
  7483. gap for the upper AVX, MPX and AVX512 registers. */
  7484. set_gdbarch_num_regs (gdbarch, I386_NUM_REGS);
  7485. set_gdbarch_gnu_triplet_regexp (gdbarch, i386_gnu_triplet_regexp);
  7486. /* Get the x86 target description from INFO. */
  7487. tdesc = info.target_desc;
  7488. if (! tdesc_has_registers (tdesc))
  7489. tdesc = i386_target_description (X86_XSTATE_SSE_MASK, false);
  7490. tdep->tdesc = tdesc;
  7491. tdep->num_core_regs = I386_NUM_GREGS + I387_NUM_REGS;
  7492. tdep->register_names = i386_register_names;
  7493. /* No upper YMM registers. */
  7494. tdep->ymmh_register_names = NULL;
  7495. tdep->ymm0h_regnum = -1;
  7496. /* No upper ZMM registers. */
  7497. tdep->zmmh_register_names = NULL;
  7498. tdep->zmm0h_regnum = -1;
  7499. /* No high XMM registers. */
  7500. tdep->xmm_avx512_register_names = NULL;
  7501. tdep->xmm16_regnum = -1;
  7502. /* No upper YMM16-31 registers. */
  7503. tdep->ymm16h_register_names = NULL;
  7504. tdep->ymm16h_regnum = -1;
  7505. tdep->num_byte_regs = 8;
  7506. tdep->num_word_regs = 8;
  7507. tdep->num_dword_regs = 0;
  7508. tdep->num_mmx_regs = 8;
  7509. tdep->num_ymm_regs = 0;
  7510. /* No MPX registers. */
  7511. tdep->bnd0r_regnum = -1;
  7512. tdep->bndcfgu_regnum = -1;
  7513. /* No AVX512 registers. */
  7514. tdep->k0_regnum = -1;
  7515. tdep->num_zmm_regs = 0;
  7516. tdep->num_ymm_avx512_regs = 0;
  7517. tdep->num_xmm_avx512_regs = 0;
  7518. /* No PKEYS registers */
  7519. tdep->pkru_regnum = -1;
  7520. tdep->num_pkeys_regs = 0;
  7521. /* No segment base registers. */
  7522. tdep->fsbase_regnum = -1;
  7523. tdesc_arch_data_up tdesc_data = tdesc_data_alloc ();
  7524. set_gdbarch_relocate_instruction (gdbarch, i386_relocate_instruction);
  7525. set_gdbarch_gen_return_address (gdbarch, i386_gen_return_address);
  7526. set_gdbarch_insn_is_call (gdbarch, i386_insn_is_call);
  7527. set_gdbarch_insn_is_ret (gdbarch, i386_insn_is_ret);
  7528. set_gdbarch_insn_is_jump (gdbarch, i386_insn_is_jump);
  7529. /* Hook in ABI-specific overrides, if they have been registered.
  7530. Note: If INFO specifies a 64 bit arch, this is where we turn
  7531. a 32-bit i386 into a 64-bit amd64. */
  7532. info.tdesc_data = tdesc_data.get ();
  7533. gdbarch_init_osabi (info, gdbarch);
  7534. if (!i386_validate_tdesc_p (tdep, tdesc_data.get ()))
  7535. {
  7536. delete tdep;
  7537. gdbarch_free (gdbarch);
  7538. return NULL;
  7539. }
  7540. num_bnd_cooked = (tdep->bnd0r_regnum > 0 ? I387_NUM_BND_REGS : 0);
  7541. /* Wire in pseudo registers. Number of pseudo registers may be
  7542. changed. */
  7543. set_gdbarch_num_pseudo_regs (gdbarch, (tdep->num_byte_regs
  7544. + tdep->num_word_regs
  7545. + tdep->num_dword_regs
  7546. + tdep->num_mmx_regs
  7547. + tdep->num_ymm_regs
  7548. + num_bnd_cooked
  7549. + tdep->num_ymm_avx512_regs
  7550. + tdep->num_zmm_regs));
  7551. /* Target description may be changed. */
  7552. tdesc = tdep->tdesc;
  7553. tdesc_use_registers (gdbarch, tdesc, std::move (tdesc_data));
  7554. /* Override gdbarch_register_reggroup_p set in tdesc_use_registers. */
  7555. set_gdbarch_register_reggroup_p (gdbarch, tdep->register_reggroup_p);
  7556. /* Make %al the first pseudo-register. */
  7557. tdep->al_regnum = gdbarch_num_regs (gdbarch);
  7558. tdep->ax_regnum = tdep->al_regnum + tdep->num_byte_regs;
  7559. ymm0_regnum = tdep->ax_regnum + tdep->num_word_regs;
  7560. if (tdep->num_dword_regs)
  7561. {
  7562. /* Support dword pseudo-register if it hasn't been disabled. */
  7563. tdep->eax_regnum = ymm0_regnum;
  7564. ymm0_regnum += tdep->num_dword_regs;
  7565. }
  7566. else
  7567. tdep->eax_regnum = -1;
  7568. mm0_regnum = ymm0_regnum;
  7569. if (tdep->num_ymm_regs)
  7570. {
  7571. /* Support YMM pseudo-register if it is available. */
  7572. tdep->ymm0_regnum = ymm0_regnum;
  7573. mm0_regnum += tdep->num_ymm_regs;
  7574. }
  7575. else
  7576. tdep->ymm0_regnum = -1;
  7577. if (tdep->num_ymm_avx512_regs)
  7578. {
  7579. /* Support YMM16-31 pseudo registers if available. */
  7580. tdep->ymm16_regnum = mm0_regnum;
  7581. mm0_regnum += tdep->num_ymm_avx512_regs;
  7582. }
  7583. else
  7584. tdep->ymm16_regnum = -1;
  7585. if (tdep->num_zmm_regs)
  7586. {
  7587. /* Support ZMM pseudo-register if it is available. */
  7588. tdep->zmm0_regnum = mm0_regnum;
  7589. mm0_regnum += tdep->num_zmm_regs;
  7590. }
  7591. else
  7592. tdep->zmm0_regnum = -1;
  7593. bnd0_regnum = mm0_regnum;
  7594. if (tdep->num_mmx_regs != 0)
  7595. {
  7596. /* Support MMX pseudo-register if MMX hasn't been disabled. */
  7597. tdep->mm0_regnum = mm0_regnum;
  7598. bnd0_regnum += tdep->num_mmx_regs;
  7599. }
  7600. else
  7601. tdep->mm0_regnum = -1;
  7602. if (tdep->bnd0r_regnum > 0)
  7603. tdep->bnd0_regnum = bnd0_regnum;
  7604. else
  7605. tdep-> bnd0_regnum = -1;
  7606. /* Hook in the legacy prologue-based unwinders last (fallback). */
  7607. frame_unwind_append_unwinder (gdbarch, &i386_stack_tramp_frame_unwind);
  7608. frame_unwind_append_unwinder (gdbarch, &i386_sigtramp_frame_unwind);
  7609. frame_unwind_append_unwinder (gdbarch, &i386_frame_unwind);
  7610. /* If we have a register mapping, enable the generic core file
  7611. support, unless it has already been enabled. */
  7612. if (tdep->gregset_reg_offset
  7613. && !gdbarch_iterate_over_regset_sections_p (gdbarch))
  7614. set_gdbarch_iterate_over_regset_sections
  7615. (gdbarch, i386_iterate_over_regset_sections);
  7616. set_gdbarch_fast_tracepoint_valid_at (gdbarch,
  7617. i386_fast_tracepoint_valid_at);
  7618. return gdbarch;
  7619. }
  7620. /* Return the target description for a specified XSAVE feature mask. */
  7621. const struct target_desc *
  7622. i386_target_description (uint64_t xcr0, bool segments)
  7623. {
  7624. static target_desc *i386_tdescs \
  7625. [2/*SSE*/][2/*AVX*/][2/*MPX*/][2/*AVX512*/][2/*PKRU*/][2/*segments*/] = {};
  7626. target_desc **tdesc;
  7627. tdesc = &i386_tdescs[(xcr0 & X86_XSTATE_SSE) ? 1 : 0]
  7628. [(xcr0 & X86_XSTATE_AVX) ? 1 : 0]
  7629. [(xcr0 & X86_XSTATE_MPX) ? 1 : 0]
  7630. [(xcr0 & X86_XSTATE_AVX512) ? 1 : 0]
  7631. [(xcr0 & X86_XSTATE_PKRU) ? 1 : 0]
  7632. [segments ? 1 : 0];
  7633. if (*tdesc == NULL)
  7634. *tdesc = i386_create_target_description (xcr0, false, segments);
  7635. return *tdesc;
  7636. }
  7637. #define MPX_BASE_MASK (~(ULONGEST) 0xfff)
  7638. /* Find the bound directory base address. */
  7639. static unsigned long
  7640. i386_mpx_bd_base (void)
  7641. {
  7642. struct regcache *rcache;
  7643. ULONGEST ret;
  7644. enum register_status regstatus;
  7645. rcache = get_current_regcache ();
  7646. gdbarch *arch = rcache->arch ();
  7647. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
  7648. regstatus = regcache_raw_read_unsigned (rcache, tdep->bndcfgu_regnum, &ret);
  7649. if (regstatus != REG_VALID)
  7650. error (_("BNDCFGU register invalid, read status %d."), regstatus);
  7651. return ret & MPX_BASE_MASK;
  7652. }
  7653. int
  7654. i386_mpx_enabled (void)
  7655. {
  7656. gdbarch *arch = get_current_arch ();
  7657. i386_gdbarch_tdep *tdep = (i386_gdbarch_tdep *) gdbarch_tdep (arch);
  7658. const struct target_desc *tdesc = tdep->tdesc;
  7659. return (tdesc_find_feature (tdesc, "org.gnu.gdb.i386.mpx") != NULL);
  7660. }
  7661. #define MPX_BD_MASK 0xfffffff00000ULL /* select bits [47:20] */
  7662. #define MPX_BT_MASK 0x0000000ffff8 /* select bits [19:3] */
  7663. #define MPX_BD_MASK_32 0xfffff000 /* select bits [31:12] */
  7664. #define MPX_BT_MASK_32 0x00000ffc /* select bits [11:2] */
  7665. /* Find the bound table entry given the pointer location and the base
  7666. address of the table. */
  7667. static CORE_ADDR
  7668. i386_mpx_get_bt_entry (CORE_ADDR ptr, CORE_ADDR bd_base)
  7669. {
  7670. CORE_ADDR offset1;
  7671. CORE_ADDR offset2;
  7672. CORE_ADDR mpx_bd_mask, bd_ptr_r_shift, bd_ptr_l_shift;
  7673. CORE_ADDR bt_mask, bt_select_r_shift, bt_select_l_shift;
  7674. CORE_ADDR bd_entry_addr;
  7675. CORE_ADDR bt_addr;
  7676. CORE_ADDR bd_entry;
  7677. struct gdbarch *gdbarch = get_current_arch ();
  7678. struct type *data_ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
  7679. if (gdbarch_ptr_bit (gdbarch) == 64)
  7680. {
  7681. mpx_bd_mask = (CORE_ADDR) MPX_BD_MASK;
  7682. bd_ptr_r_shift = 20;
  7683. bd_ptr_l_shift = 3;
  7684. bt_select_r_shift = 3;
  7685. bt_select_l_shift = 5;
  7686. bt_mask = (CORE_ADDR) MPX_BT_MASK;
  7687. if ( sizeof (CORE_ADDR) == 4)
  7688. error (_("bound table examination not supported\
  7689. for 64-bit process with 32-bit GDB"));
  7690. }
  7691. else
  7692. {
  7693. mpx_bd_mask = MPX_BD_MASK_32;
  7694. bd_ptr_r_shift = 12;
  7695. bd_ptr_l_shift = 2;
  7696. bt_select_r_shift = 2;
  7697. bt_select_l_shift = 4;
  7698. bt_mask = MPX_BT_MASK_32;
  7699. }
  7700. offset1 = ((ptr & mpx_bd_mask) >> bd_ptr_r_shift) << bd_ptr_l_shift;
  7701. bd_entry_addr = bd_base + offset1;
  7702. bd_entry = read_memory_typed_address (bd_entry_addr, data_ptr_type);
  7703. if ((bd_entry & 0x1) == 0)
  7704. error (_("Invalid bounds directory entry at %s."),
  7705. paddress (get_current_arch (), bd_entry_addr));
  7706. /* Clearing status bit. */
  7707. bd_entry--;
  7708. bt_addr = bd_entry & ~bt_select_r_shift;
  7709. offset2 = ((ptr & bt_mask) >> bt_select_r_shift) << bt_select_l_shift;
  7710. return bt_addr + offset2;
  7711. }
  7712. /* Print routine for the mpx bounds. */
  7713. static void
  7714. i386_mpx_print_bounds (const CORE_ADDR bt_entry[4])
  7715. {
  7716. struct ui_out *uiout = current_uiout;
  7717. LONGEST size;
  7718. struct gdbarch *gdbarch = get_current_arch ();
  7719. CORE_ADDR onecompl = ~((CORE_ADDR) 0);
  7720. int bounds_in_map = ((~bt_entry[1] == 0 && bt_entry[0] == onecompl) ? 1 : 0);
  7721. if (bounds_in_map == 1)
  7722. {
  7723. uiout->text ("Null bounds on map:");
  7724. uiout->text (" pointer value = ");
  7725. uiout->field_core_addr ("pointer-value", gdbarch, bt_entry[2]);
  7726. uiout->text (".");
  7727. uiout->text ("\n");
  7728. }
  7729. else
  7730. {
  7731. uiout->text ("{lbound = ");
  7732. uiout->field_core_addr ("lower-bound", gdbarch, bt_entry[0]);
  7733. uiout->text (", ubound = ");
  7734. /* The upper bound is stored in 1's complement. */
  7735. uiout->field_core_addr ("upper-bound", gdbarch, ~bt_entry[1]);
  7736. uiout->text ("}: pointer value = ");
  7737. uiout->field_core_addr ("pointer-value", gdbarch, bt_entry[2]);
  7738. if (gdbarch_ptr_bit (gdbarch) == 64)
  7739. size = ( (~(int64_t) bt_entry[1]) - (int64_t) bt_entry[0]);
  7740. else
  7741. size = ( ~((int32_t) bt_entry[1]) - (int32_t) bt_entry[0]);
  7742. /* In case the bounds are 0x0 and 0xffff... the difference will be -1.
  7743. -1 represents in this sense full memory access, and there is no need
  7744. one to the size. */
  7745. size = (size > -1 ? size + 1 : size);
  7746. uiout->text (", size = ");
  7747. uiout->field_string ("size", plongest (size));
  7748. uiout->text (", metadata = ");
  7749. uiout->field_core_addr ("metadata", gdbarch, bt_entry[3]);
  7750. uiout->text ("\n");
  7751. }
  7752. }
  7753. /* Implement the command "show mpx bound". */
  7754. static void
  7755. i386_mpx_info_bounds (const char *args, int from_tty)
  7756. {
  7757. CORE_ADDR bd_base = 0;
  7758. CORE_ADDR addr;
  7759. CORE_ADDR bt_entry_addr = 0;
  7760. CORE_ADDR bt_entry[4];
  7761. int i;
  7762. struct gdbarch *gdbarch = get_current_arch ();
  7763. struct type *data_ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
  7764. if (gdbarch_bfd_arch_info (gdbarch)->arch != bfd_arch_i386
  7765. || !i386_mpx_enabled ())
  7766. {
  7767. gdb_printf (_("Intel Memory Protection Extensions not "
  7768. "supported on this target.\n"));
  7769. return;
  7770. }
  7771. if (args == NULL)
  7772. {
  7773. gdb_printf (_("Address of pointer variable expected.\n"));
  7774. return;
  7775. }
  7776. addr = parse_and_eval_address (args);
  7777. bd_base = i386_mpx_bd_base ();
  7778. bt_entry_addr = i386_mpx_get_bt_entry (addr, bd_base);
  7779. memset (bt_entry, 0, sizeof (bt_entry));
  7780. for (i = 0; i < 4; i++)
  7781. bt_entry[i] = read_memory_typed_address (bt_entry_addr
  7782. + i * TYPE_LENGTH (data_ptr_type),
  7783. data_ptr_type);
  7784. i386_mpx_print_bounds (bt_entry);
  7785. }
  7786. /* Implement the command "set mpx bound". */
  7787. static void
  7788. i386_mpx_set_bounds (const char *args, int from_tty)
  7789. {
  7790. CORE_ADDR bd_base = 0;
  7791. CORE_ADDR addr, lower, upper;
  7792. CORE_ADDR bt_entry_addr = 0;
  7793. CORE_ADDR bt_entry[2];
  7794. const char *input = args;
  7795. int i;
  7796. struct gdbarch *gdbarch = get_current_arch ();
  7797. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  7798. struct type *data_ptr_type = builtin_type (gdbarch)->builtin_data_ptr;
  7799. if (gdbarch_bfd_arch_info (gdbarch)->arch != bfd_arch_i386
  7800. || !i386_mpx_enabled ())
  7801. error (_("Intel Memory Protection Extensions not supported\
  7802. on this target."));
  7803. if (args == NULL)
  7804. error (_("Pointer value expected."));
  7805. addr = value_as_address (parse_to_comma_and_eval (&input));
  7806. if (input[0] == ',')
  7807. ++input;
  7808. if (input[0] == '\0')
  7809. error (_("wrong number of arguments: missing lower and upper bound."));
  7810. lower = value_as_address (parse_to_comma_and_eval (&input));
  7811. if (input[0] == ',')
  7812. ++input;
  7813. if (input[0] == '\0')
  7814. error (_("Wrong number of arguments; Missing upper bound."));
  7815. upper = value_as_address (parse_to_comma_and_eval (&input));
  7816. bd_base = i386_mpx_bd_base ();
  7817. bt_entry_addr = i386_mpx_get_bt_entry (addr, bd_base);
  7818. for (i = 0; i < 2; i++)
  7819. bt_entry[i] = read_memory_typed_address (bt_entry_addr
  7820. + i * TYPE_LENGTH (data_ptr_type),
  7821. data_ptr_type);
  7822. bt_entry[0] = (uint64_t) lower;
  7823. bt_entry[1] = ~(uint64_t) upper;
  7824. for (i = 0; i < 2; i++)
  7825. write_memory_unsigned_integer (bt_entry_addr
  7826. + i * TYPE_LENGTH (data_ptr_type),
  7827. TYPE_LENGTH (data_ptr_type), byte_order,
  7828. bt_entry[i]);
  7829. }
  7830. static struct cmd_list_element *mpx_set_cmdlist, *mpx_show_cmdlist;
  7831. void _initialize_i386_tdep ();
  7832. void
  7833. _initialize_i386_tdep ()
  7834. {
  7835. register_gdbarch_init (bfd_arch_i386, i386_gdbarch_init);
  7836. /* Add the variable that controls the disassembly flavor. */
  7837. add_setshow_enum_cmd ("disassembly-flavor", no_class, valid_flavors,
  7838. &disassembly_flavor, _("\
  7839. Set the disassembly flavor."), _("\
  7840. Show the disassembly flavor."), _("\
  7841. The valid values are \"att\" and \"intel\", and the default value is \"att\"."),
  7842. NULL,
  7843. NULL, /* FIXME: i18n: */
  7844. &setlist, &showlist);
  7845. /* Add the variable that controls the convention for returning
  7846. structs. */
  7847. add_setshow_enum_cmd ("struct-convention", no_class, valid_conventions,
  7848. &struct_convention, _("\
  7849. Set the convention for returning small structs."), _("\
  7850. Show the convention for returning small structs."), _("\
  7851. Valid values are \"default\", \"pcc\" and \"reg\", and the default value\n\
  7852. is \"default\"."),
  7853. NULL,
  7854. NULL, /* FIXME: i18n: */
  7855. &setlist, &showlist);
  7856. /* Add "mpx" prefix for the set and show commands. */
  7857. add_setshow_prefix_cmd
  7858. ("mpx", class_support,
  7859. _("Set Intel Memory Protection Extensions specific variables."),
  7860. _("Show Intel Memory Protection Extensions specific variables."),
  7861. &mpx_set_cmdlist, &mpx_show_cmdlist, &setlist, &showlist);
  7862. /* Add "bound" command for the show mpx commands list. */
  7863. add_cmd ("bound", no_class, i386_mpx_info_bounds,
  7864. "Show the memory bounds for a given array/pointer storage\
  7865. in the bound table.",
  7866. &mpx_show_cmdlist);
  7867. /* Add "bound" command for the set mpx commands list. */
  7868. add_cmd ("bound", no_class, i386_mpx_set_bounds,
  7869. "Set the memory bounds for a given array/pointer storage\
  7870. in the bound table.",
  7871. &mpx_set_cmdlist);
  7872. gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_SVR4,
  7873. i386_svr4_init_abi);
  7874. /* Initialize the i386-specific register groups. */
  7875. i386_init_reggroups ();
  7876. /* Tell remote stub that we support XML target description. */
  7877. register_remote_support_xml ("i386");
  7878. }