ia64-tdep.c 126 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023
  1. /* Target-dependent code for the IA-64 for GDB, the GNU debugger.
  2. Copyright (C) 1999-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 "inferior.h"
  16. #include "gdbcore.h"
  17. #include "arch-utils.h"
  18. #include "floatformat.h"
  19. #include "gdbtypes.h"
  20. #include "regcache.h"
  21. #include "reggroups.h"
  22. #include "frame.h"
  23. #include "frame-base.h"
  24. #include "frame-unwind.h"
  25. #include "target-float.h"
  26. #include "value.h"
  27. #include "objfiles.h"
  28. #include "elf/common.h" /* for DT_PLTGOT value */
  29. #include "elf-bfd.h"
  30. #include "dis-asm.h"
  31. #include "infcall.h"
  32. #include "osabi.h"
  33. #include "ia64-tdep.h"
  34. #include "cp-abi.h"
  35. #ifdef HAVE_LIBUNWIND_IA64_H
  36. #include "elf/ia64.h" /* for PT_IA_64_UNWIND value */
  37. #include "ia64-libunwind-tdep.h"
  38. /* Note: KERNEL_START is supposed to be an address which is not going
  39. to ever contain any valid unwind info. For ia64 linux, the choice
  40. of 0xc000000000000000 is fairly safe since that's uncached space.
  41. We use KERNEL_START as follows: after obtaining the kernel's
  42. unwind table via getunwind(), we project its unwind data into
  43. address-range KERNEL_START-(KERNEL_START+ktab_size) and then
  44. when ia64_access_mem() sees a memory access to this
  45. address-range, we redirect it to ktab instead.
  46. None of this hackery is needed with a modern kernel/libcs
  47. which uses the kernel virtual DSO to provide access to the
  48. kernel's unwind info. In that case, ktab_size remains 0 and
  49. hence the value of KERNEL_START doesn't matter. */
  50. #define KERNEL_START 0xc000000000000000ULL
  51. static size_t ktab_size = 0;
  52. struct ia64_table_entry
  53. {
  54. uint64_t start_offset;
  55. uint64_t end_offset;
  56. uint64_t info_offset;
  57. };
  58. static struct ia64_table_entry *ktab = NULL;
  59. static gdb::optional<gdb::byte_vector> ktab_buf;
  60. #endif
  61. /* An enumeration of the different IA-64 instruction types. */
  62. typedef enum instruction_type
  63. {
  64. A, /* Integer ALU ; I-unit or M-unit */
  65. I, /* Non-ALU integer; I-unit */
  66. M, /* Memory ; M-unit */
  67. F, /* Floating-point ; F-unit */
  68. B, /* Branch ; B-unit */
  69. L, /* Extended (L+X) ; I-unit */
  70. X, /* Extended (L+X) ; I-unit */
  71. undefined /* undefined or reserved */
  72. } instruction_type;
  73. /* We represent IA-64 PC addresses as the value of the instruction
  74. pointer or'd with some bit combination in the low nibble which
  75. represents the slot number in the bundle addressed by the
  76. instruction pointer. The problem is that the Linux kernel
  77. multiplies its slot numbers (for exceptions) by one while the
  78. disassembler multiplies its slot numbers by 6. In addition, I've
  79. heard it said that the simulator uses 1 as the multiplier.
  80. I've fixed the disassembler so that the bytes_per_line field will
  81. be the slot multiplier. If bytes_per_line comes in as zero, it
  82. is set to six (which is how it was set up initially). -- objdump
  83. displays pretty disassembly dumps with this value. For our purposes,
  84. we'll set bytes_per_line to SLOT_MULTIPLIER. This is okay since we
  85. never want to also display the raw bytes the way objdump does. */
  86. #define SLOT_MULTIPLIER 1
  87. /* Length in bytes of an instruction bundle. */
  88. #define BUNDLE_LEN 16
  89. /* See the saved memory layout comment for ia64_memory_insert_breakpoint. */
  90. #if BREAKPOINT_MAX < BUNDLE_LEN - 2
  91. # error "BREAKPOINT_MAX < BUNDLE_LEN - 2"
  92. #endif
  93. static gdbarch_init_ftype ia64_gdbarch_init;
  94. static gdbarch_register_name_ftype ia64_register_name;
  95. static gdbarch_register_type_ftype ia64_register_type;
  96. static gdbarch_breakpoint_from_pc_ftype ia64_breakpoint_from_pc;
  97. static gdbarch_skip_prologue_ftype ia64_skip_prologue;
  98. static struct type *is_float_or_hfa_type (struct type *t);
  99. static CORE_ADDR ia64_find_global_pointer (struct gdbarch *gdbarch,
  100. CORE_ADDR faddr);
  101. #define NUM_IA64_RAW_REGS 462
  102. /* Big enough to hold a FP register in bytes. */
  103. #define IA64_FP_REGISTER_SIZE 16
  104. static int sp_regnum = IA64_GR12_REGNUM;
  105. /* NOTE: we treat the register stack registers r32-r127 as
  106. pseudo-registers because they may not be accessible via the ptrace
  107. register get/set interfaces. */
  108. enum pseudo_regs { FIRST_PSEUDO_REGNUM = NUM_IA64_RAW_REGS,
  109. VBOF_REGNUM = IA64_NAT127_REGNUM + 1, V32_REGNUM,
  110. V127_REGNUM = V32_REGNUM + 95,
  111. VP0_REGNUM, VP16_REGNUM = VP0_REGNUM + 16,
  112. VP63_REGNUM = VP0_REGNUM + 63, LAST_PSEUDO_REGNUM };
  113. /* Array of register names; There should be ia64_num_regs strings in
  114. the initializer. */
  115. static const char * const ia64_register_names[] =
  116. { "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
  117. "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
  118. "r16", "r17", "r18", "r19", "r20", "r21", "r22", "r23",
  119. "r24", "r25", "r26", "r27", "r28", "r29", "r30", "r31",
  120. "", "", "", "", "", "", "", "",
  121. "", "", "", "", "", "", "", "",
  122. "", "", "", "", "", "", "", "",
  123. "", "", "", "", "", "", "", "",
  124. "", "", "", "", "", "", "", "",
  125. "", "", "", "", "", "", "", "",
  126. "", "", "", "", "", "", "", "",
  127. "", "", "", "", "", "", "", "",
  128. "", "", "", "", "", "", "", "",
  129. "", "", "", "", "", "", "", "",
  130. "", "", "", "", "", "", "", "",
  131. "", "", "", "", "", "", "", "",
  132. "f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7",
  133. "f8", "f9", "f10", "f11", "f12", "f13", "f14", "f15",
  134. "f16", "f17", "f18", "f19", "f20", "f21", "f22", "f23",
  135. "f24", "f25", "f26", "f27", "f28", "f29", "f30", "f31",
  136. "f32", "f33", "f34", "f35", "f36", "f37", "f38", "f39",
  137. "f40", "f41", "f42", "f43", "f44", "f45", "f46", "f47",
  138. "f48", "f49", "f50", "f51", "f52", "f53", "f54", "f55",
  139. "f56", "f57", "f58", "f59", "f60", "f61", "f62", "f63",
  140. "f64", "f65", "f66", "f67", "f68", "f69", "f70", "f71",
  141. "f72", "f73", "f74", "f75", "f76", "f77", "f78", "f79",
  142. "f80", "f81", "f82", "f83", "f84", "f85", "f86", "f87",
  143. "f88", "f89", "f90", "f91", "f92", "f93", "f94", "f95",
  144. "f96", "f97", "f98", "f99", "f100", "f101", "f102", "f103",
  145. "f104", "f105", "f106", "f107", "f108", "f109", "f110", "f111",
  146. "f112", "f113", "f114", "f115", "f116", "f117", "f118", "f119",
  147. "f120", "f121", "f122", "f123", "f124", "f125", "f126", "f127",
  148. "", "", "", "", "", "", "", "",
  149. "", "", "", "", "", "", "", "",
  150. "", "", "", "", "", "", "", "",
  151. "", "", "", "", "", "", "", "",
  152. "", "", "", "", "", "", "", "",
  153. "", "", "", "", "", "", "", "",
  154. "", "", "", "", "", "", "", "",
  155. "", "", "", "", "", "", "", "",
  156. "b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7",
  157. "vfp", "vrap",
  158. "pr", "ip", "psr", "cfm",
  159. "kr0", "kr1", "kr2", "kr3", "kr4", "kr5", "kr6", "kr7",
  160. "", "", "", "", "", "", "", "",
  161. "rsc", "bsp", "bspstore", "rnat",
  162. "", "fcr", "", "",
  163. "eflag", "csd", "ssd", "cflg", "fsr", "fir", "fdr", "",
  164. "ccv", "", "", "", "unat", "", "", "",
  165. "fpsr", "", "", "", "itc",
  166. "", "", "", "", "", "", "", "", "", "",
  167. "", "", "", "", "", "", "", "", "",
  168. "pfs", "lc", "ec",
  169. "", "", "", "", "", "", "", "", "", "",
  170. "", "", "", "", "", "", "", "", "", "",
  171. "", "", "", "", "", "", "", "", "", "",
  172. "", "", "", "", "", "", "", "", "", "",
  173. "", "", "", "", "", "", "", "", "", "",
  174. "", "", "", "", "", "", "", "", "", "",
  175. "",
  176. "nat0", "nat1", "nat2", "nat3", "nat4", "nat5", "nat6", "nat7",
  177. "nat8", "nat9", "nat10", "nat11", "nat12", "nat13", "nat14", "nat15",
  178. "nat16", "nat17", "nat18", "nat19", "nat20", "nat21", "nat22", "nat23",
  179. "nat24", "nat25", "nat26", "nat27", "nat28", "nat29", "nat30", "nat31",
  180. "nat32", "nat33", "nat34", "nat35", "nat36", "nat37", "nat38", "nat39",
  181. "nat40", "nat41", "nat42", "nat43", "nat44", "nat45", "nat46", "nat47",
  182. "nat48", "nat49", "nat50", "nat51", "nat52", "nat53", "nat54", "nat55",
  183. "nat56", "nat57", "nat58", "nat59", "nat60", "nat61", "nat62", "nat63",
  184. "nat64", "nat65", "nat66", "nat67", "nat68", "nat69", "nat70", "nat71",
  185. "nat72", "nat73", "nat74", "nat75", "nat76", "nat77", "nat78", "nat79",
  186. "nat80", "nat81", "nat82", "nat83", "nat84", "nat85", "nat86", "nat87",
  187. "nat88", "nat89", "nat90", "nat91", "nat92", "nat93", "nat94", "nat95",
  188. "nat96", "nat97", "nat98", "nat99", "nat100","nat101","nat102","nat103",
  189. "nat104","nat105","nat106","nat107","nat108","nat109","nat110","nat111",
  190. "nat112","nat113","nat114","nat115","nat116","nat117","nat118","nat119",
  191. "nat120","nat121","nat122","nat123","nat124","nat125","nat126","nat127",
  192. "bof",
  193. "r32", "r33", "r34", "r35", "r36", "r37", "r38", "r39",
  194. "r40", "r41", "r42", "r43", "r44", "r45", "r46", "r47",
  195. "r48", "r49", "r50", "r51", "r52", "r53", "r54", "r55",
  196. "r56", "r57", "r58", "r59", "r60", "r61", "r62", "r63",
  197. "r64", "r65", "r66", "r67", "r68", "r69", "r70", "r71",
  198. "r72", "r73", "r74", "r75", "r76", "r77", "r78", "r79",
  199. "r80", "r81", "r82", "r83", "r84", "r85", "r86", "r87",
  200. "r88", "r89", "r90", "r91", "r92", "r93", "r94", "r95",
  201. "r96", "r97", "r98", "r99", "r100", "r101", "r102", "r103",
  202. "r104", "r105", "r106", "r107", "r108", "r109", "r110", "r111",
  203. "r112", "r113", "r114", "r115", "r116", "r117", "r118", "r119",
  204. "r120", "r121", "r122", "r123", "r124", "r125", "r126", "r127",
  205. "p0", "p1", "p2", "p3", "p4", "p5", "p6", "p7",
  206. "p8", "p9", "p10", "p11", "p12", "p13", "p14", "p15",
  207. "p16", "p17", "p18", "p19", "p20", "p21", "p22", "p23",
  208. "p24", "p25", "p26", "p27", "p28", "p29", "p30", "p31",
  209. "p32", "p33", "p34", "p35", "p36", "p37", "p38", "p39",
  210. "p40", "p41", "p42", "p43", "p44", "p45", "p46", "p47",
  211. "p48", "p49", "p50", "p51", "p52", "p53", "p54", "p55",
  212. "p56", "p57", "p58", "p59", "p60", "p61", "p62", "p63",
  213. };
  214. struct ia64_frame_cache
  215. {
  216. CORE_ADDR base; /* frame pointer base for frame */
  217. CORE_ADDR pc; /* function start pc for frame */
  218. CORE_ADDR saved_sp; /* stack pointer for frame */
  219. CORE_ADDR bsp; /* points at r32 for the current frame */
  220. CORE_ADDR cfm; /* cfm value for current frame */
  221. CORE_ADDR prev_cfm; /* cfm value for previous frame */
  222. int frameless;
  223. int sof; /* Size of frame (decoded from cfm value). */
  224. int sol; /* Size of locals (decoded from cfm value). */
  225. int sor; /* Number of rotating registers (decoded from
  226. cfm value). */
  227. CORE_ADDR after_prologue;
  228. /* Address of first instruction after the last
  229. prologue instruction; Note that there may
  230. be instructions from the function's body
  231. intermingled with the prologue. */
  232. int mem_stack_frame_size;
  233. /* Size of the memory stack frame (may be zero),
  234. or -1 if it has not been determined yet. */
  235. int fp_reg; /* Register number (if any) used a frame pointer
  236. for this frame. 0 if no register is being used
  237. as the frame pointer. */
  238. /* Saved registers. */
  239. CORE_ADDR saved_regs[NUM_IA64_RAW_REGS];
  240. };
  241. static int
  242. floatformat_valid (const struct floatformat *fmt, const void *from)
  243. {
  244. return 1;
  245. }
  246. static const struct floatformat floatformat_ia64_ext_little =
  247. {
  248. floatformat_little, 82, 0, 1, 17, 65535, 0x1ffff, 18, 64,
  249. floatformat_intbit_yes, "floatformat_ia64_ext_little", floatformat_valid, NULL
  250. };
  251. static const struct floatformat floatformat_ia64_ext_big =
  252. {
  253. floatformat_big, 82, 46, 47, 17, 65535, 0x1ffff, 64, 64,
  254. floatformat_intbit_yes, "floatformat_ia64_ext_big", floatformat_valid
  255. };
  256. static const struct floatformat *floatformats_ia64_ext[2] =
  257. {
  258. &floatformat_ia64_ext_big,
  259. &floatformat_ia64_ext_little
  260. };
  261. static struct type *
  262. ia64_ext_type (struct gdbarch *gdbarch)
  263. {
  264. ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  265. if (!tdep->ia64_ext_type)
  266. tdep->ia64_ext_type
  267. = arch_float_type (gdbarch, 128, "builtin_type_ia64_ext",
  268. floatformats_ia64_ext);
  269. return tdep->ia64_ext_type;
  270. }
  271. static int
  272. ia64_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
  273. const struct reggroup *group)
  274. {
  275. int vector_p;
  276. int float_p;
  277. int raw_p;
  278. if (group == all_reggroup)
  279. return 1;
  280. vector_p = register_type (gdbarch, regnum)->is_vector ();
  281. float_p = register_type (gdbarch, regnum)->code () == TYPE_CODE_FLT;
  282. raw_p = regnum < NUM_IA64_RAW_REGS;
  283. if (group == float_reggroup)
  284. return float_p;
  285. if (group == vector_reggroup)
  286. return vector_p;
  287. if (group == general_reggroup)
  288. return (!vector_p && !float_p);
  289. if (group == save_reggroup || group == restore_reggroup)
  290. return raw_p;
  291. return 0;
  292. }
  293. static const char *
  294. ia64_register_name (struct gdbarch *gdbarch, int reg)
  295. {
  296. return ia64_register_names[reg];
  297. }
  298. struct type *
  299. ia64_register_type (struct gdbarch *arch, int reg)
  300. {
  301. if (reg >= IA64_FR0_REGNUM && reg <= IA64_FR127_REGNUM)
  302. return ia64_ext_type (arch);
  303. else
  304. return builtin_type (arch)->builtin_long;
  305. }
  306. static int
  307. ia64_dwarf_reg_to_regnum (struct gdbarch *gdbarch, int reg)
  308. {
  309. if (reg >= IA64_GR32_REGNUM && reg <= IA64_GR127_REGNUM)
  310. return V32_REGNUM + (reg - IA64_GR32_REGNUM);
  311. return reg;
  312. }
  313. /* Extract ``len'' bits from an instruction bundle starting at
  314. bit ``from''. */
  315. static long long
  316. extract_bit_field (const gdb_byte *bundle, int from, int len)
  317. {
  318. long long result = 0LL;
  319. int to = from + len;
  320. int from_byte = from / 8;
  321. int to_byte = to / 8;
  322. unsigned char *b = (unsigned char *) bundle;
  323. unsigned char c;
  324. int lshift;
  325. int i;
  326. c = b[from_byte];
  327. if (from_byte == to_byte)
  328. c = ((unsigned char) (c << (8 - to % 8))) >> (8 - to % 8);
  329. result = c >> (from % 8);
  330. lshift = 8 - (from % 8);
  331. for (i = from_byte+1; i < to_byte; i++)
  332. {
  333. result |= ((long long) b[i]) << lshift;
  334. lshift += 8;
  335. }
  336. if (from_byte < to_byte && (to % 8 != 0))
  337. {
  338. c = b[to_byte];
  339. c = ((unsigned char) (c << (8 - to % 8))) >> (8 - to % 8);
  340. result |= ((long long) c) << lshift;
  341. }
  342. return result;
  343. }
  344. /* Replace the specified bits in an instruction bundle. */
  345. static void
  346. replace_bit_field (gdb_byte *bundle, long long val, int from, int len)
  347. {
  348. int to = from + len;
  349. int from_byte = from / 8;
  350. int to_byte = to / 8;
  351. unsigned char *b = (unsigned char *) bundle;
  352. unsigned char c;
  353. if (from_byte == to_byte)
  354. {
  355. unsigned char left, right;
  356. c = b[from_byte];
  357. left = (c >> (to % 8)) << (to % 8);
  358. right = ((unsigned char) (c << (8 - from % 8))) >> (8 - from % 8);
  359. c = (unsigned char) (val & 0xff);
  360. c = (unsigned char) (c << (from % 8 + 8 - to % 8)) >> (8 - to % 8);
  361. c |= right | left;
  362. b[from_byte] = c;
  363. }
  364. else
  365. {
  366. int i;
  367. c = b[from_byte];
  368. c = ((unsigned char) (c << (8 - from % 8))) >> (8 - from % 8);
  369. c = c | (val << (from % 8));
  370. b[from_byte] = c;
  371. val >>= 8 - from % 8;
  372. for (i = from_byte+1; i < to_byte; i++)
  373. {
  374. c = val & 0xff;
  375. val >>= 8;
  376. b[i] = c;
  377. }
  378. if (to % 8 != 0)
  379. {
  380. unsigned char cv = (unsigned char) val;
  381. c = b[to_byte];
  382. c = c >> (to % 8) << (to % 8);
  383. c |= ((unsigned char) (cv << (8 - to % 8))) >> (8 - to % 8);
  384. b[to_byte] = c;
  385. }
  386. }
  387. }
  388. /* Return the contents of slot N (for N = 0, 1, or 2) in
  389. and instruction bundle. */
  390. static long long
  391. slotN_contents (gdb_byte *bundle, int slotnum)
  392. {
  393. return extract_bit_field (bundle, 5+41*slotnum, 41);
  394. }
  395. /* Store an instruction in an instruction bundle. */
  396. static void
  397. replace_slotN_contents (gdb_byte *bundle, long long instr, int slotnum)
  398. {
  399. replace_bit_field (bundle, instr, 5+41*slotnum, 41);
  400. }
  401. static const enum instruction_type template_encoding_table[32][3] =
  402. {
  403. { M, I, I }, /* 00 */
  404. { M, I, I }, /* 01 */
  405. { M, I, I }, /* 02 */
  406. { M, I, I }, /* 03 */
  407. { M, L, X }, /* 04 */
  408. { M, L, X }, /* 05 */
  409. { undefined, undefined, undefined }, /* 06 */
  410. { undefined, undefined, undefined }, /* 07 */
  411. { M, M, I }, /* 08 */
  412. { M, M, I }, /* 09 */
  413. { M, M, I }, /* 0A */
  414. { M, M, I }, /* 0B */
  415. { M, F, I }, /* 0C */
  416. { M, F, I }, /* 0D */
  417. { M, M, F }, /* 0E */
  418. { M, M, F }, /* 0F */
  419. { M, I, B }, /* 10 */
  420. { M, I, B }, /* 11 */
  421. { M, B, B }, /* 12 */
  422. { M, B, B }, /* 13 */
  423. { undefined, undefined, undefined }, /* 14 */
  424. { undefined, undefined, undefined }, /* 15 */
  425. { B, B, B }, /* 16 */
  426. { B, B, B }, /* 17 */
  427. { M, M, B }, /* 18 */
  428. { M, M, B }, /* 19 */
  429. { undefined, undefined, undefined }, /* 1A */
  430. { undefined, undefined, undefined }, /* 1B */
  431. { M, F, B }, /* 1C */
  432. { M, F, B }, /* 1D */
  433. { undefined, undefined, undefined }, /* 1E */
  434. { undefined, undefined, undefined }, /* 1F */
  435. };
  436. /* Fetch and (partially) decode an instruction at ADDR and return the
  437. address of the next instruction to fetch. */
  438. static CORE_ADDR
  439. fetch_instruction (CORE_ADDR addr, instruction_type *it, long long *instr)
  440. {
  441. gdb_byte bundle[BUNDLE_LEN];
  442. int slotnum = (int) (addr & 0x0f) / SLOT_MULTIPLIER;
  443. long long templ;
  444. int val;
  445. /* Warn about slot numbers greater than 2. We used to generate
  446. an error here on the assumption that the user entered an invalid
  447. address. But, sometimes GDB itself requests an invalid address.
  448. This can (easily) happen when execution stops in a function for
  449. which there are no symbols. The prologue scanner will attempt to
  450. find the beginning of the function - if the nearest symbol
  451. happens to not be aligned on a bundle boundary (16 bytes), the
  452. resulting starting address will cause GDB to think that the slot
  453. number is too large.
  454. So we warn about it and set the slot number to zero. It is
  455. not necessarily a fatal condition, particularly if debugging
  456. at the assembly language level. */
  457. if (slotnum > 2)
  458. {
  459. warning (_("Can't fetch instructions for slot numbers greater than 2.\n"
  460. "Using slot 0 instead"));
  461. slotnum = 0;
  462. }
  463. addr &= ~0x0f;
  464. val = target_read_memory (addr, bundle, BUNDLE_LEN);
  465. if (val != 0)
  466. return 0;
  467. *instr = slotN_contents (bundle, slotnum);
  468. templ = extract_bit_field (bundle, 0, 5);
  469. *it = template_encoding_table[(int)templ][slotnum];
  470. if (slotnum == 2 || (slotnum == 1 && *it == L))
  471. addr += 16;
  472. else
  473. addr += (slotnum + 1) * SLOT_MULTIPLIER;
  474. return addr;
  475. }
  476. /* There are 5 different break instructions (break.i, break.b,
  477. break.m, break.f, and break.x), but they all have the same
  478. encoding. (The five bit template in the low five bits of the
  479. instruction bundle distinguishes one from another.)
  480. The runtime architecture manual specifies that break instructions
  481. used for debugging purposes must have the upper two bits of the 21
  482. bit immediate set to a 0 and a 1 respectively. A breakpoint
  483. instruction encodes the most significant bit of its 21 bit
  484. immediate at bit 36 of the 41 bit instruction. The penultimate msb
  485. is at bit 25 which leads to the pattern below.
  486. Originally, I had this set up to do, e.g, a "break.i 0x80000" But
  487. it turns out that 0x80000 was used as the syscall break in the early
  488. simulators. So I changed the pattern slightly to do "break.i 0x080001"
  489. instead. But that didn't work either (I later found out that this
  490. pattern was used by the simulator that I was using.) So I ended up
  491. using the pattern seen below.
  492. SHADOW_CONTENTS has byte-based addressing (PLACED_ADDRESS and SHADOW_LEN)
  493. while we need bit-based addressing as the instructions length is 41 bits and
  494. we must not modify/corrupt the adjacent slots in the same bundle.
  495. Fortunately we may store larger memory incl. the adjacent bits with the
  496. original memory content (not the possibly already stored breakpoints there).
  497. We need to be careful in ia64_memory_remove_breakpoint to always restore
  498. only the specific bits of this instruction ignoring any adjacent stored
  499. bits.
  500. We use the original addressing with the low nibble in the range <0..2> which
  501. gets incorrectly interpreted by generic non-ia64 breakpoint_restore_shadows
  502. as the direct byte offset of SHADOW_CONTENTS. We store whole BUNDLE_LEN
  503. bytes just without these two possibly skipped bytes to not to exceed to the
  504. next bundle.
  505. If we would like to store the whole bundle to SHADOW_CONTENTS we would have
  506. to store already the base address (`address & ~0x0f') into PLACED_ADDRESS.
  507. In such case there is no other place where to store
  508. SLOTNUM (`adress & 0x0f', value in the range <0..2>). We need to know
  509. SLOTNUM in ia64_memory_remove_breakpoint.
  510. There is one special case where we need to be extra careful:
  511. L-X instructions, which are instructions that occupy 2 slots
  512. (The L part is always in slot 1, and the X part is always in
  513. slot 2). We must refuse to insert breakpoints for an address
  514. that points at slot 2 of a bundle where an L-X instruction is
  515. present, since there is logically no instruction at that address.
  516. However, to make things more interesting, the opcode of L-X
  517. instructions is located in slot 2. This means that, to insert
  518. a breakpoint at an address that points to slot 1, we actually
  519. need to write the breakpoint in slot 2! Slot 1 is actually
  520. the extended operand, so writing the breakpoint there would not
  521. have the desired effect. Another side-effect of this issue
  522. is that we need to make sure that the shadow contents buffer
  523. does save byte 15 of our instruction bundle (this is the tail
  524. end of slot 2, which wouldn't be saved if we were to insert
  525. the breakpoint in slot 1).
  526. ia64 16-byte bundle layout:
  527. | 5 bits | slot 0 with 41 bits | slot 1 with 41 bits | slot 2 with 41 bits |
  528. The current addressing used by the code below:
  529. original PC placed_address placed_size required covered
  530. == bp_tgt->shadow_len reqd \subset covered
  531. 0xABCDE0 0xABCDE0 0x10 <0x0...0x5> <0x0..0xF>
  532. 0xABCDE1 0xABCDE1 0xF <0x5...0xA> <0x1..0xF>
  533. 0xABCDE2 0xABCDE2 0xE <0xA...0xF> <0x2..0xF>
  534. L-X instructions are treated a little specially, as explained above:
  535. 0xABCDE1 0xABCDE1 0xF <0xA...0xF> <0x1..0xF>
  536. `objdump -d' and some other tools show a bit unjustified offsets:
  537. original PC byte where starts the instruction objdump offset
  538. 0xABCDE0 0xABCDE0 0xABCDE0
  539. 0xABCDE1 0xABCDE5 0xABCDE6
  540. 0xABCDE2 0xABCDEA 0xABCDEC
  541. */
  542. #define IA64_BREAKPOINT 0x00003333300LL
  543. static int
  544. ia64_memory_insert_breakpoint (struct gdbarch *gdbarch,
  545. struct bp_target_info *bp_tgt)
  546. {
  547. CORE_ADDR addr = bp_tgt->placed_address = bp_tgt->reqstd_address;
  548. gdb_byte bundle[BUNDLE_LEN];
  549. int slotnum = (int) (addr & 0x0f) / SLOT_MULTIPLIER, shadow_slotnum;
  550. long long instr_breakpoint;
  551. int val;
  552. int templ;
  553. if (slotnum > 2)
  554. error (_("Can't insert breakpoint for slot numbers greater than 2."));
  555. addr &= ~0x0f;
  556. /* Enable the automatic memory restoration from breakpoints while
  557. we read our instruction bundle for the purpose of SHADOW_CONTENTS.
  558. Otherwise, we could possibly store into the shadow parts of the adjacent
  559. placed breakpoints. It is due to our SHADOW_CONTENTS overlapping the real
  560. breakpoint instruction bits region. */
  561. scoped_restore restore_memory_0
  562. = make_scoped_restore_show_memory_breakpoints (0);
  563. val = target_read_memory (addr, bundle, BUNDLE_LEN);
  564. if (val != 0)
  565. return val;
  566. /* SHADOW_SLOTNUM saves the original slot number as expected by the caller
  567. for addressing the SHADOW_CONTENTS placement. */
  568. shadow_slotnum = slotnum;
  569. /* Always cover the last byte of the bundle in case we are inserting
  570. a breakpoint on an L-X instruction. */
  571. bp_tgt->shadow_len = BUNDLE_LEN - shadow_slotnum;
  572. templ = extract_bit_field (bundle, 0, 5);
  573. if (template_encoding_table[templ][slotnum] == X)
  574. {
  575. /* X unit types can only be used in slot 2, and are actually
  576. part of a 2-slot L-X instruction. We cannot break at this
  577. address, as this is the second half of an instruction that
  578. lives in slot 1 of that bundle. */
  579. gdb_assert (slotnum == 2);
  580. error (_("Can't insert breakpoint for non-existing slot X"));
  581. }
  582. if (template_encoding_table[templ][slotnum] == L)
  583. {
  584. /* L unit types can only be used in slot 1. But the associated
  585. opcode for that instruction is in slot 2, so bump the slot number
  586. accordingly. */
  587. gdb_assert (slotnum == 1);
  588. slotnum = 2;
  589. }
  590. /* Store the whole bundle, except for the initial skipped bytes by the slot
  591. number interpreted as bytes offset in PLACED_ADDRESS. */
  592. memcpy (bp_tgt->shadow_contents, bundle + shadow_slotnum,
  593. bp_tgt->shadow_len);
  594. /* Re-read the same bundle as above except that, this time, read it in order
  595. to compute the new bundle inside which we will be inserting the
  596. breakpoint. Therefore, disable the automatic memory restoration from
  597. breakpoints while we read our instruction bundle. Otherwise, the general
  598. restoration mechanism kicks in and we would possibly remove parts of the
  599. adjacent placed breakpoints. It is due to our SHADOW_CONTENTS overlapping
  600. the real breakpoint instruction bits region. */
  601. scoped_restore restore_memory_1
  602. = make_scoped_restore_show_memory_breakpoints (1);
  603. val = target_read_memory (addr, bundle, BUNDLE_LEN);
  604. if (val != 0)
  605. return val;
  606. /* Breakpoints already present in the code will get detected and not get
  607. reinserted by bp_loc_is_permanent. Multiple breakpoints at the same
  608. location cannot induce the internal error as they are optimized into
  609. a single instance by update_global_location_list. */
  610. instr_breakpoint = slotN_contents (bundle, slotnum);
  611. if (instr_breakpoint == IA64_BREAKPOINT)
  612. internal_error (__FILE__, __LINE__,
  613. _("Address %s already contains a breakpoint."),
  614. paddress (gdbarch, bp_tgt->placed_address));
  615. replace_slotN_contents (bundle, IA64_BREAKPOINT, slotnum);
  616. val = target_write_memory (addr + shadow_slotnum, bundle + shadow_slotnum,
  617. bp_tgt->shadow_len);
  618. return val;
  619. }
  620. static int
  621. ia64_memory_remove_breakpoint (struct gdbarch *gdbarch,
  622. struct bp_target_info *bp_tgt)
  623. {
  624. CORE_ADDR addr = bp_tgt->placed_address;
  625. gdb_byte bundle_mem[BUNDLE_LEN], bundle_saved[BUNDLE_LEN];
  626. int slotnum = (addr & 0x0f) / SLOT_MULTIPLIER, shadow_slotnum;
  627. long long instr_breakpoint, instr_saved;
  628. int val;
  629. int templ;
  630. addr &= ~0x0f;
  631. /* Disable the automatic memory restoration from breakpoints while
  632. we read our instruction bundle. Otherwise, the general restoration
  633. mechanism kicks in and we would possibly remove parts of the adjacent
  634. placed breakpoints. It is due to our SHADOW_CONTENTS overlapping the real
  635. breakpoint instruction bits region. */
  636. scoped_restore restore_memory_1
  637. = make_scoped_restore_show_memory_breakpoints (1);
  638. val = target_read_memory (addr, bundle_mem, BUNDLE_LEN);
  639. if (val != 0)
  640. return val;
  641. /* SHADOW_SLOTNUM saves the original slot number as expected by the caller
  642. for addressing the SHADOW_CONTENTS placement. */
  643. shadow_slotnum = slotnum;
  644. templ = extract_bit_field (bundle_mem, 0, 5);
  645. if (template_encoding_table[templ][slotnum] == X)
  646. {
  647. /* X unit types can only be used in slot 2, and are actually
  648. part of a 2-slot L-X instruction. We refuse to insert
  649. breakpoints at this address, so there should be no reason
  650. for us attempting to remove one there, except if the program's
  651. code somehow got modified in memory. */
  652. gdb_assert (slotnum == 2);
  653. warning (_("Cannot remove breakpoint at address %s from non-existing "
  654. "X-type slot, memory has changed underneath"),
  655. paddress (gdbarch, bp_tgt->placed_address));
  656. return -1;
  657. }
  658. if (template_encoding_table[templ][slotnum] == L)
  659. {
  660. /* L unit types can only be used in slot 1. But the breakpoint
  661. was actually saved using slot 2, so update the slot number
  662. accordingly. */
  663. gdb_assert (slotnum == 1);
  664. slotnum = 2;
  665. }
  666. gdb_assert (bp_tgt->shadow_len == BUNDLE_LEN - shadow_slotnum);
  667. instr_breakpoint = slotN_contents (bundle_mem, slotnum);
  668. if (instr_breakpoint != IA64_BREAKPOINT)
  669. {
  670. warning (_("Cannot remove breakpoint at address %s, "
  671. "no break instruction at such address."),
  672. paddress (gdbarch, bp_tgt->placed_address));
  673. return -1;
  674. }
  675. /* Extract the original saved instruction from SLOTNUM normalizing its
  676. bit-shift for INSTR_SAVED. */
  677. memcpy (bundle_saved, bundle_mem, BUNDLE_LEN);
  678. memcpy (bundle_saved + shadow_slotnum, bp_tgt->shadow_contents,
  679. bp_tgt->shadow_len);
  680. instr_saved = slotN_contents (bundle_saved, slotnum);
  681. /* In BUNDLE_MEM, be careful to modify only the bits belonging to SLOTNUM
  682. and not any of the other ones that are stored in SHADOW_CONTENTS. */
  683. replace_slotN_contents (bundle_mem, instr_saved, slotnum);
  684. val = target_write_raw_memory (addr, bundle_mem, BUNDLE_LEN);
  685. return val;
  686. }
  687. /* Implement the breakpoint_kind_from_pc gdbarch method. */
  688. static int
  689. ia64_breakpoint_kind_from_pc (struct gdbarch *gdbarch, CORE_ADDR *pcptr)
  690. {
  691. /* A place holder of gdbarch method breakpoint_kind_from_pc. */
  692. return 0;
  693. }
  694. /* As gdbarch_breakpoint_from_pc ranges have byte granularity and ia64
  695. instruction slots ranges are bit-granular (41 bits) we have to provide an
  696. extended range as described for ia64_memory_insert_breakpoint. We also take
  697. care of preserving the `break' instruction 21-bit (or 62-bit) parameter to
  698. make a match for permanent breakpoints. */
  699. static const gdb_byte *
  700. ia64_breakpoint_from_pc (struct gdbarch *gdbarch,
  701. CORE_ADDR *pcptr, int *lenptr)
  702. {
  703. CORE_ADDR addr = *pcptr;
  704. static gdb_byte bundle[BUNDLE_LEN];
  705. int slotnum = (int) (*pcptr & 0x0f) / SLOT_MULTIPLIER, shadow_slotnum;
  706. long long instr_fetched;
  707. int val;
  708. int templ;
  709. if (slotnum > 2)
  710. error (_("Can't insert breakpoint for slot numbers greater than 2."));
  711. addr &= ~0x0f;
  712. /* Enable the automatic memory restoration from breakpoints while
  713. we read our instruction bundle to match bp_loc_is_permanent. */
  714. {
  715. scoped_restore restore_memory_0
  716. = make_scoped_restore_show_memory_breakpoints (0);
  717. val = target_read_memory (addr, bundle, BUNDLE_LEN);
  718. }
  719. /* The memory might be unreachable. This can happen, for instance,
  720. when the user inserts a breakpoint at an invalid address. */
  721. if (val != 0)
  722. return NULL;
  723. /* SHADOW_SLOTNUM saves the original slot number as expected by the caller
  724. for addressing the SHADOW_CONTENTS placement. */
  725. shadow_slotnum = slotnum;
  726. /* Cover always the last byte of the bundle for the L-X slot case. */
  727. *lenptr = BUNDLE_LEN - shadow_slotnum;
  728. /* Check for L type instruction in slot 1, if present then bump up the slot
  729. number to the slot 2. */
  730. templ = extract_bit_field (bundle, 0, 5);
  731. if (template_encoding_table[templ][slotnum] == X)
  732. {
  733. gdb_assert (slotnum == 2);
  734. error (_("Can't insert breakpoint for non-existing slot X"));
  735. }
  736. if (template_encoding_table[templ][slotnum] == L)
  737. {
  738. gdb_assert (slotnum == 1);
  739. slotnum = 2;
  740. }
  741. /* A break instruction has its all its opcode bits cleared except for
  742. the parameter value. For L+X slot pair we are at the X slot (slot 2) so
  743. we should not touch the L slot - the upper 41 bits of the parameter. */
  744. instr_fetched = slotN_contents (bundle, slotnum);
  745. instr_fetched &= 0x1003ffffc0LL;
  746. replace_slotN_contents (bundle, instr_fetched, slotnum);
  747. return bundle + shadow_slotnum;
  748. }
  749. static CORE_ADDR
  750. ia64_read_pc (readable_regcache *regcache)
  751. {
  752. ULONGEST psr_value, pc_value;
  753. int slot_num;
  754. regcache->cooked_read (IA64_PSR_REGNUM, &psr_value);
  755. regcache->cooked_read (IA64_IP_REGNUM, &pc_value);
  756. slot_num = (psr_value >> 41) & 3;
  757. return pc_value | (slot_num * SLOT_MULTIPLIER);
  758. }
  759. void
  760. ia64_write_pc (struct regcache *regcache, CORE_ADDR new_pc)
  761. {
  762. int slot_num = (int) (new_pc & 0xf) / SLOT_MULTIPLIER;
  763. ULONGEST psr_value;
  764. regcache_cooked_read_unsigned (regcache, IA64_PSR_REGNUM, &psr_value);
  765. psr_value &= ~(3LL << 41);
  766. psr_value |= (ULONGEST)(slot_num & 0x3) << 41;
  767. new_pc &= ~0xfLL;
  768. regcache_cooked_write_unsigned (regcache, IA64_PSR_REGNUM, psr_value);
  769. regcache_cooked_write_unsigned (regcache, IA64_IP_REGNUM, new_pc);
  770. }
  771. #define IS_NaT_COLLECTION_ADDR(addr) ((((addr) >> 3) & 0x3f) == 0x3f)
  772. /* Returns the address of the slot that's NSLOTS slots away from
  773. the address ADDR. NSLOTS may be positive or negative. */
  774. static CORE_ADDR
  775. rse_address_add(CORE_ADDR addr, int nslots)
  776. {
  777. CORE_ADDR new_addr;
  778. int mandatory_nat_slots = nslots / 63;
  779. int direction = nslots < 0 ? -1 : 1;
  780. new_addr = addr + 8 * (nslots + mandatory_nat_slots);
  781. if ((new_addr >> 9) != ((addr + 8 * 64 * mandatory_nat_slots) >> 9))
  782. new_addr += 8 * direction;
  783. if (IS_NaT_COLLECTION_ADDR(new_addr))
  784. new_addr += 8 * direction;
  785. return new_addr;
  786. }
  787. static enum register_status
  788. ia64_pseudo_register_read (struct gdbarch *gdbarch, readable_regcache *regcache,
  789. int regnum, gdb_byte *buf)
  790. {
  791. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  792. enum register_status status;
  793. if (regnum >= V32_REGNUM && regnum <= V127_REGNUM)
  794. {
  795. #ifdef HAVE_LIBUNWIND_IA64_H
  796. /* First try and use the libunwind special reg accessor,
  797. otherwise fallback to standard logic. */
  798. if (!libunwind_is_initialized ()
  799. || libunwind_get_reg_special (gdbarch, regcache, regnum, buf) != 0)
  800. #endif
  801. {
  802. /* The fallback position is to assume that r32-r127 are
  803. found sequentially in memory starting at $bof. This
  804. isn't always true, but without libunwind, this is the
  805. best we can do. */
  806. ULONGEST cfm;
  807. ULONGEST bsp;
  808. CORE_ADDR reg;
  809. status = regcache->cooked_read (IA64_BSP_REGNUM, &bsp);
  810. if (status != REG_VALID)
  811. return status;
  812. status = regcache->cooked_read (IA64_CFM_REGNUM, &cfm);
  813. if (status != REG_VALID)
  814. return status;
  815. /* The bsp points at the end of the register frame so we
  816. subtract the size of frame from it to get start of
  817. register frame. */
  818. bsp = rse_address_add (bsp, -(cfm & 0x7f));
  819. if ((cfm & 0x7f) > regnum - V32_REGNUM)
  820. {
  821. ULONGEST reg_addr = rse_address_add (bsp, (regnum - V32_REGNUM));
  822. reg = read_memory_integer ((CORE_ADDR)reg_addr, 8, byte_order);
  823. store_unsigned_integer (buf, register_size (gdbarch, regnum),
  824. byte_order, reg);
  825. }
  826. else
  827. store_unsigned_integer (buf, register_size (gdbarch, regnum),
  828. byte_order, 0);
  829. }
  830. }
  831. else if (IA64_NAT0_REGNUM <= regnum && regnum <= IA64_NAT31_REGNUM)
  832. {
  833. ULONGEST unatN_val;
  834. ULONGEST unat;
  835. status = regcache->cooked_read (IA64_UNAT_REGNUM, &unat);
  836. if (status != REG_VALID)
  837. return status;
  838. unatN_val = (unat & (1LL << (regnum - IA64_NAT0_REGNUM))) != 0;
  839. store_unsigned_integer (buf, register_size (gdbarch, regnum),
  840. byte_order, unatN_val);
  841. }
  842. else if (IA64_NAT32_REGNUM <= regnum && regnum <= IA64_NAT127_REGNUM)
  843. {
  844. ULONGEST natN_val = 0;
  845. ULONGEST bsp;
  846. ULONGEST cfm;
  847. CORE_ADDR gr_addr = 0;
  848. status = regcache->cooked_read (IA64_BSP_REGNUM, &bsp);
  849. if (status != REG_VALID)
  850. return status;
  851. status = regcache->cooked_read (IA64_CFM_REGNUM, &cfm);
  852. if (status != REG_VALID)
  853. return status;
  854. /* The bsp points at the end of the register frame so we
  855. subtract the size of frame from it to get start of register frame. */
  856. bsp = rse_address_add (bsp, -(cfm & 0x7f));
  857. if ((cfm & 0x7f) > regnum - V32_REGNUM)
  858. gr_addr = rse_address_add (bsp, (regnum - V32_REGNUM));
  859. if (gr_addr != 0)
  860. {
  861. /* Compute address of nat collection bits. */
  862. CORE_ADDR nat_addr = gr_addr | 0x1f8;
  863. ULONGEST nat_collection;
  864. int nat_bit;
  865. /* If our nat collection address is bigger than bsp, we have to get
  866. the nat collection from rnat. Otherwise, we fetch the nat
  867. collection from the computed address. */
  868. if (nat_addr >= bsp)
  869. regcache->cooked_read (IA64_RNAT_REGNUM, &nat_collection);
  870. else
  871. nat_collection = read_memory_integer (nat_addr, 8, byte_order);
  872. nat_bit = (gr_addr >> 3) & 0x3f;
  873. natN_val = (nat_collection >> nat_bit) & 1;
  874. }
  875. store_unsigned_integer (buf, register_size (gdbarch, regnum),
  876. byte_order, natN_val);
  877. }
  878. else if (regnum == VBOF_REGNUM)
  879. {
  880. /* A virtual register frame start is provided for user convenience.
  881. It can be calculated as the bsp - sof (sizeof frame). */
  882. ULONGEST bsp, vbsp;
  883. ULONGEST cfm;
  884. status = regcache->cooked_read (IA64_BSP_REGNUM, &bsp);
  885. if (status != REG_VALID)
  886. return status;
  887. status = regcache->cooked_read (IA64_CFM_REGNUM, &cfm);
  888. if (status != REG_VALID)
  889. return status;
  890. /* The bsp points at the end of the register frame so we
  891. subtract the size of frame from it to get beginning of frame. */
  892. vbsp = rse_address_add (bsp, -(cfm & 0x7f));
  893. store_unsigned_integer (buf, register_size (gdbarch, regnum),
  894. byte_order, vbsp);
  895. }
  896. else if (VP0_REGNUM <= regnum && regnum <= VP63_REGNUM)
  897. {
  898. ULONGEST pr;
  899. ULONGEST cfm;
  900. ULONGEST prN_val;
  901. status = regcache->cooked_read (IA64_PR_REGNUM, &pr);
  902. if (status != REG_VALID)
  903. return status;
  904. status = regcache->cooked_read (IA64_CFM_REGNUM, &cfm);
  905. if (status != REG_VALID)
  906. return status;
  907. if (VP16_REGNUM <= regnum && regnum <= VP63_REGNUM)
  908. {
  909. /* Fetch predicate register rename base from current frame
  910. marker for this frame. */
  911. int rrb_pr = (cfm >> 32) & 0x3f;
  912. /* Adjust the register number to account for register rotation. */
  913. regnum = VP16_REGNUM
  914. + ((regnum - VP16_REGNUM) + rrb_pr) % 48;
  915. }
  916. prN_val = (pr & (1LL << (regnum - VP0_REGNUM))) != 0;
  917. store_unsigned_integer (buf, register_size (gdbarch, regnum),
  918. byte_order, prN_val);
  919. }
  920. else
  921. memset (buf, 0, register_size (gdbarch, regnum));
  922. return REG_VALID;
  923. }
  924. static void
  925. ia64_pseudo_register_write (struct gdbarch *gdbarch, struct regcache *regcache,
  926. int regnum, const gdb_byte *buf)
  927. {
  928. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  929. if (regnum >= V32_REGNUM && regnum <= V127_REGNUM)
  930. {
  931. ULONGEST bsp;
  932. ULONGEST cfm;
  933. regcache_cooked_read_unsigned (regcache, IA64_BSP_REGNUM, &bsp);
  934. regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm);
  935. bsp = rse_address_add (bsp, -(cfm & 0x7f));
  936. if ((cfm & 0x7f) > regnum - V32_REGNUM)
  937. {
  938. ULONGEST reg_addr = rse_address_add (bsp, (regnum - V32_REGNUM));
  939. write_memory (reg_addr, buf, 8);
  940. }
  941. }
  942. else if (IA64_NAT0_REGNUM <= regnum && regnum <= IA64_NAT31_REGNUM)
  943. {
  944. ULONGEST unatN_val, unat, unatN_mask;
  945. regcache_cooked_read_unsigned (regcache, IA64_UNAT_REGNUM, &unat);
  946. unatN_val = extract_unsigned_integer (buf, register_size (gdbarch,
  947. regnum),
  948. byte_order);
  949. unatN_mask = (1LL << (regnum - IA64_NAT0_REGNUM));
  950. if (unatN_val == 0)
  951. unat &= ~unatN_mask;
  952. else if (unatN_val == 1)
  953. unat |= unatN_mask;
  954. regcache_cooked_write_unsigned (regcache, IA64_UNAT_REGNUM, unat);
  955. }
  956. else if (IA64_NAT32_REGNUM <= regnum && regnum <= IA64_NAT127_REGNUM)
  957. {
  958. ULONGEST natN_val;
  959. ULONGEST bsp;
  960. ULONGEST cfm;
  961. CORE_ADDR gr_addr = 0;
  962. regcache_cooked_read_unsigned (regcache, IA64_BSP_REGNUM, &bsp);
  963. regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm);
  964. /* The bsp points at the end of the register frame so we
  965. subtract the size of frame from it to get start of register frame. */
  966. bsp = rse_address_add (bsp, -(cfm & 0x7f));
  967. if ((cfm & 0x7f) > regnum - V32_REGNUM)
  968. gr_addr = rse_address_add (bsp, (regnum - V32_REGNUM));
  969. natN_val = extract_unsigned_integer (buf, register_size (gdbarch,
  970. regnum),
  971. byte_order);
  972. if (gr_addr != 0 && (natN_val == 0 || natN_val == 1))
  973. {
  974. /* Compute address of nat collection bits. */
  975. CORE_ADDR nat_addr = gr_addr | 0x1f8;
  976. CORE_ADDR nat_collection;
  977. int natN_bit = (gr_addr >> 3) & 0x3f;
  978. ULONGEST natN_mask = (1LL << natN_bit);
  979. /* If our nat collection address is bigger than bsp, we have to get
  980. the nat collection from rnat. Otherwise, we fetch the nat
  981. collection from the computed address. */
  982. if (nat_addr >= bsp)
  983. {
  984. regcache_cooked_read_unsigned (regcache,
  985. IA64_RNAT_REGNUM,
  986. &nat_collection);
  987. if (natN_val)
  988. nat_collection |= natN_mask;
  989. else
  990. nat_collection &= ~natN_mask;
  991. regcache_cooked_write_unsigned (regcache, IA64_RNAT_REGNUM,
  992. nat_collection);
  993. }
  994. else
  995. {
  996. gdb_byte nat_buf[8];
  997. nat_collection = read_memory_integer (nat_addr, 8, byte_order);
  998. if (natN_val)
  999. nat_collection |= natN_mask;
  1000. else
  1001. nat_collection &= ~natN_mask;
  1002. store_unsigned_integer (nat_buf, register_size (gdbarch, regnum),
  1003. byte_order, nat_collection);
  1004. write_memory (nat_addr, nat_buf, 8);
  1005. }
  1006. }
  1007. }
  1008. else if (VP0_REGNUM <= regnum && regnum <= VP63_REGNUM)
  1009. {
  1010. ULONGEST pr;
  1011. ULONGEST cfm;
  1012. ULONGEST prN_val;
  1013. ULONGEST prN_mask;
  1014. regcache_cooked_read_unsigned (regcache, IA64_PR_REGNUM, &pr);
  1015. regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm);
  1016. if (VP16_REGNUM <= regnum && regnum <= VP63_REGNUM)
  1017. {
  1018. /* Fetch predicate register rename base from current frame
  1019. marker for this frame. */
  1020. int rrb_pr = (cfm >> 32) & 0x3f;
  1021. /* Adjust the register number to account for register rotation. */
  1022. regnum = VP16_REGNUM
  1023. + ((regnum - VP16_REGNUM) + rrb_pr) % 48;
  1024. }
  1025. prN_val = extract_unsigned_integer (buf, register_size (gdbarch, regnum),
  1026. byte_order);
  1027. prN_mask = (1LL << (regnum - VP0_REGNUM));
  1028. if (prN_val == 0)
  1029. pr &= ~prN_mask;
  1030. else if (prN_val == 1)
  1031. pr |= prN_mask;
  1032. regcache_cooked_write_unsigned (regcache, IA64_PR_REGNUM, pr);
  1033. }
  1034. }
  1035. /* The ia64 needs to convert between various ieee floating-point formats
  1036. and the special ia64 floating point register format. */
  1037. static int
  1038. ia64_convert_register_p (struct gdbarch *gdbarch, int regno, struct type *type)
  1039. {
  1040. return (regno >= IA64_FR0_REGNUM && regno <= IA64_FR127_REGNUM
  1041. && type->code () == TYPE_CODE_FLT
  1042. && type != ia64_ext_type (gdbarch));
  1043. }
  1044. static int
  1045. ia64_register_to_value (struct frame_info *frame, int regnum,
  1046. struct type *valtype, gdb_byte *out,
  1047. int *optimizedp, int *unavailablep)
  1048. {
  1049. struct gdbarch *gdbarch = get_frame_arch (frame);
  1050. gdb_byte in[IA64_FP_REGISTER_SIZE];
  1051. /* Convert to TYPE. */
  1052. if (!get_frame_register_bytes (frame, regnum, 0,
  1053. gdb::make_array_view (in,
  1054. register_size (gdbarch,
  1055. regnum)),
  1056. optimizedp, unavailablep))
  1057. return 0;
  1058. target_float_convert (in, ia64_ext_type (gdbarch), out, valtype);
  1059. *optimizedp = *unavailablep = 0;
  1060. return 1;
  1061. }
  1062. static void
  1063. ia64_value_to_register (struct frame_info *frame, int regnum,
  1064. struct type *valtype, const gdb_byte *in)
  1065. {
  1066. struct gdbarch *gdbarch = get_frame_arch (frame);
  1067. gdb_byte out[IA64_FP_REGISTER_SIZE];
  1068. target_float_convert (in, valtype, out, ia64_ext_type (gdbarch));
  1069. put_frame_register (frame, regnum, out);
  1070. }
  1071. /* Limit the number of skipped non-prologue instructions since examining
  1072. of the prologue is expensive. */
  1073. static int max_skip_non_prologue_insns = 40;
  1074. /* Given PC representing the starting address of a function, and
  1075. LIM_PC which is the (sloppy) limit to which to scan when looking
  1076. for a prologue, attempt to further refine this limit by using
  1077. the line data in the symbol table. If successful, a better guess
  1078. on where the prologue ends is returned, otherwise the previous
  1079. value of lim_pc is returned. TRUST_LIMIT is a pointer to a flag
  1080. which will be set to indicate whether the returned limit may be
  1081. used with no further scanning in the event that the function is
  1082. frameless. */
  1083. /* FIXME: cagney/2004-02-14: This function and logic have largely been
  1084. superseded by skip_prologue_using_sal. */
  1085. static CORE_ADDR
  1086. refine_prologue_limit (CORE_ADDR pc, CORE_ADDR lim_pc, int *trust_limit)
  1087. {
  1088. struct symtab_and_line prologue_sal;
  1089. CORE_ADDR start_pc = pc;
  1090. CORE_ADDR end_pc;
  1091. /* The prologue can not possibly go past the function end itself,
  1092. so we can already adjust LIM_PC accordingly. */
  1093. if (find_pc_partial_function (pc, NULL, NULL, &end_pc) && end_pc < lim_pc)
  1094. lim_pc = end_pc;
  1095. /* Start off not trusting the limit. */
  1096. *trust_limit = 0;
  1097. prologue_sal = find_pc_line (pc, 0);
  1098. if (prologue_sal.line != 0)
  1099. {
  1100. int i;
  1101. CORE_ADDR addr = prologue_sal.end;
  1102. /* Handle the case in which compiler's optimizer/scheduler
  1103. has moved instructions into the prologue. We scan ahead
  1104. in the function looking for address ranges whose corresponding
  1105. line number is less than or equal to the first one that we
  1106. found for the function. (It can be less than when the
  1107. scheduler puts a body instruction before the first prologue
  1108. instruction.) */
  1109. for (i = 2 * max_skip_non_prologue_insns;
  1110. i > 0 && (lim_pc == 0 || addr < lim_pc);
  1111. i--)
  1112. {
  1113. struct symtab_and_line sal;
  1114. sal = find_pc_line (addr, 0);
  1115. if (sal.line == 0)
  1116. break;
  1117. if (sal.line <= prologue_sal.line
  1118. && sal.symtab == prologue_sal.symtab)
  1119. {
  1120. prologue_sal = sal;
  1121. }
  1122. addr = sal.end;
  1123. }
  1124. if (lim_pc == 0 || prologue_sal.end < lim_pc)
  1125. {
  1126. lim_pc = prologue_sal.end;
  1127. if (start_pc == get_pc_function_start (lim_pc))
  1128. *trust_limit = 1;
  1129. }
  1130. }
  1131. return lim_pc;
  1132. }
  1133. #define isScratch(_regnum_) ((_regnum_) == 2 || (_regnum_) == 3 \
  1134. || (8 <= (_regnum_) && (_regnum_) <= 11) \
  1135. || (14 <= (_regnum_) && (_regnum_) <= 31))
  1136. #define imm9(_instr_) \
  1137. ( ((((_instr_) & 0x01000000000LL) ? -1 : 0) << 8) \
  1138. | (((_instr_) & 0x00008000000LL) >> 20) \
  1139. | (((_instr_) & 0x00000001fc0LL) >> 6))
  1140. /* Allocate and initialize a frame cache. */
  1141. static struct ia64_frame_cache *
  1142. ia64_alloc_frame_cache (void)
  1143. {
  1144. struct ia64_frame_cache *cache;
  1145. int i;
  1146. cache = FRAME_OBSTACK_ZALLOC (struct ia64_frame_cache);
  1147. /* Base address. */
  1148. cache->base = 0;
  1149. cache->pc = 0;
  1150. cache->cfm = 0;
  1151. cache->prev_cfm = 0;
  1152. cache->sof = 0;
  1153. cache->sol = 0;
  1154. cache->sor = 0;
  1155. cache->bsp = 0;
  1156. cache->fp_reg = 0;
  1157. cache->frameless = 1;
  1158. for (i = 0; i < NUM_IA64_RAW_REGS; i++)
  1159. cache->saved_regs[i] = 0;
  1160. return cache;
  1161. }
  1162. static CORE_ADDR
  1163. examine_prologue (CORE_ADDR pc, CORE_ADDR lim_pc,
  1164. struct frame_info *this_frame,
  1165. struct ia64_frame_cache *cache)
  1166. {
  1167. CORE_ADDR next_pc;
  1168. CORE_ADDR last_prologue_pc = pc;
  1169. instruction_type it;
  1170. long long instr;
  1171. int cfm_reg = 0;
  1172. int ret_reg = 0;
  1173. int fp_reg = 0;
  1174. int unat_save_reg = 0;
  1175. int pr_save_reg = 0;
  1176. int mem_stack_frame_size = 0;
  1177. int spill_reg = 0;
  1178. CORE_ADDR spill_addr = 0;
  1179. char instores[8];
  1180. char infpstores[8];
  1181. char reg_contents[256];
  1182. int trust_limit;
  1183. int frameless = 1;
  1184. int i;
  1185. CORE_ADDR addr;
  1186. gdb_byte buf[8];
  1187. CORE_ADDR bof, sor, sol, sof, cfm, rrb_gr;
  1188. memset (instores, 0, sizeof instores);
  1189. memset (infpstores, 0, sizeof infpstores);
  1190. memset (reg_contents, 0, sizeof reg_contents);
  1191. if (cache->after_prologue != 0
  1192. && cache->after_prologue <= lim_pc)
  1193. return cache->after_prologue;
  1194. lim_pc = refine_prologue_limit (pc, lim_pc, &trust_limit);
  1195. next_pc = fetch_instruction (pc, &it, &instr);
  1196. /* We want to check if we have a recognizable function start before we
  1197. look ahead for a prologue. */
  1198. if (pc < lim_pc && next_pc
  1199. && it == M && ((instr & 0x1ee0000003fLL) == 0x02c00000000LL))
  1200. {
  1201. /* alloc - start of a regular function. */
  1202. int sol_bits = (int) ((instr & 0x00007f00000LL) >> 20);
  1203. int sof_bits = (int) ((instr & 0x000000fe000LL) >> 13);
  1204. int rN = (int) ((instr & 0x00000001fc0LL) >> 6);
  1205. /* Verify that the current cfm matches what we think is the
  1206. function start. If we have somehow jumped within a function,
  1207. we do not want to interpret the prologue and calculate the
  1208. addresses of various registers such as the return address.
  1209. We will instead treat the frame as frameless. */
  1210. if (!this_frame ||
  1211. (sof_bits == (cache->cfm & 0x7f) &&
  1212. sol_bits == ((cache->cfm >> 7) & 0x7f)))
  1213. frameless = 0;
  1214. cfm_reg = rN;
  1215. last_prologue_pc = next_pc;
  1216. pc = next_pc;
  1217. }
  1218. else
  1219. {
  1220. /* Look for a leaf routine. */
  1221. if (pc < lim_pc && next_pc
  1222. && (it == I || it == M)
  1223. && ((instr & 0x1ee00000000LL) == 0x10800000000LL))
  1224. {
  1225. /* adds rN = imm14, rM (or mov rN, rM when imm14 is 0) */
  1226. int imm = (int) ((((instr & 0x01000000000LL) ? -1 : 0) << 13)
  1227. | ((instr & 0x001f8000000LL) >> 20)
  1228. | ((instr & 0x000000fe000LL) >> 13));
  1229. int rM = (int) ((instr & 0x00007f00000LL) >> 20);
  1230. int rN = (int) ((instr & 0x00000001fc0LL) >> 6);
  1231. int qp = (int) (instr & 0x0000000003fLL);
  1232. if (qp == 0 && rN == 2 && imm == 0 && rM == 12 && fp_reg == 0)
  1233. {
  1234. /* mov r2, r12 - beginning of leaf routine. */
  1235. fp_reg = rN;
  1236. last_prologue_pc = next_pc;
  1237. }
  1238. }
  1239. /* If we don't recognize a regular function or leaf routine, we are
  1240. done. */
  1241. if (!fp_reg)
  1242. {
  1243. pc = lim_pc;
  1244. if (trust_limit)
  1245. last_prologue_pc = lim_pc;
  1246. }
  1247. }
  1248. /* Loop, looking for prologue instructions, keeping track of
  1249. where preserved registers were spilled. */
  1250. while (pc < lim_pc)
  1251. {
  1252. next_pc = fetch_instruction (pc, &it, &instr);
  1253. if (next_pc == 0)
  1254. break;
  1255. if (it == B && ((instr & 0x1e1f800003fLL) != 0x04000000000LL))
  1256. {
  1257. /* Exit loop upon hitting a non-nop branch instruction. */
  1258. if (trust_limit)
  1259. lim_pc = pc;
  1260. break;
  1261. }
  1262. else if (((instr & 0x3fLL) != 0LL) &&
  1263. (frameless || ret_reg != 0))
  1264. {
  1265. /* Exit loop upon hitting a predicated instruction if
  1266. we already have the return register or if we are frameless. */
  1267. if (trust_limit)
  1268. lim_pc = pc;
  1269. break;
  1270. }
  1271. else if (it == I && ((instr & 0x1eff8000000LL) == 0x00188000000LL))
  1272. {
  1273. /* Move from BR */
  1274. int b2 = (int) ((instr & 0x0000000e000LL) >> 13);
  1275. int rN = (int) ((instr & 0x00000001fc0LL) >> 6);
  1276. int qp = (int) (instr & 0x0000000003f);
  1277. if (qp == 0 && b2 == 0 && rN >= 32 && ret_reg == 0)
  1278. {
  1279. ret_reg = rN;
  1280. last_prologue_pc = next_pc;
  1281. }
  1282. }
  1283. else if ((it == I || it == M)
  1284. && ((instr & 0x1ee00000000LL) == 0x10800000000LL))
  1285. {
  1286. /* adds rN = imm14, rM (or mov rN, rM when imm14 is 0) */
  1287. int imm = (int) ((((instr & 0x01000000000LL) ? -1 : 0) << 13)
  1288. | ((instr & 0x001f8000000LL) >> 20)
  1289. | ((instr & 0x000000fe000LL) >> 13));
  1290. int rM = (int) ((instr & 0x00007f00000LL) >> 20);
  1291. int rN = (int) ((instr & 0x00000001fc0LL) >> 6);
  1292. int qp = (int) (instr & 0x0000000003fLL);
  1293. if (qp == 0 && rN >= 32 && imm == 0 && rM == 12 && fp_reg == 0)
  1294. {
  1295. /* mov rN, r12 */
  1296. fp_reg = rN;
  1297. last_prologue_pc = next_pc;
  1298. }
  1299. else if (qp == 0 && rN == 12 && rM == 12)
  1300. {
  1301. /* adds r12, -mem_stack_frame_size, r12 */
  1302. mem_stack_frame_size -= imm;
  1303. last_prologue_pc = next_pc;
  1304. }
  1305. else if (qp == 0 && rN == 2
  1306. && ((rM == fp_reg && fp_reg != 0) || rM == 12))
  1307. {
  1308. CORE_ADDR saved_sp = 0;
  1309. /* adds r2, spilloffset, rFramePointer
  1310. or
  1311. adds r2, spilloffset, r12
  1312. Get ready for stf.spill or st8.spill instructions.
  1313. The address to start spilling at is loaded into r2.
  1314. FIXME: Why r2? That's what gcc currently uses; it
  1315. could well be different for other compilers. */
  1316. /* Hmm... whether or not this will work will depend on
  1317. where the pc is. If it's still early in the prologue
  1318. this'll be wrong. FIXME */
  1319. if (this_frame)
  1320. saved_sp = get_frame_register_unsigned (this_frame,
  1321. sp_regnum);
  1322. spill_addr = saved_sp
  1323. + (rM == 12 ? 0 : mem_stack_frame_size)
  1324. + imm;
  1325. spill_reg = rN;
  1326. last_prologue_pc = next_pc;
  1327. }
  1328. else if (qp == 0 && rM >= 32 && rM < 40 && !instores[rM-32] &&
  1329. rN < 256 && imm == 0)
  1330. {
  1331. /* mov rN, rM where rM is an input register. */
  1332. reg_contents[rN] = rM;
  1333. last_prologue_pc = next_pc;
  1334. }
  1335. else if (frameless && qp == 0 && rN == fp_reg && imm == 0 &&
  1336. rM == 2)
  1337. {
  1338. /* mov r12, r2 */
  1339. last_prologue_pc = next_pc;
  1340. break;
  1341. }
  1342. }
  1343. else if (it == M
  1344. && ( ((instr & 0x1efc0000000LL) == 0x0eec0000000LL)
  1345. || ((instr & 0x1ffc8000000LL) == 0x0cec0000000LL) ))
  1346. {
  1347. /* stf.spill [rN] = fM, imm9
  1348. or
  1349. stf.spill [rN] = fM */
  1350. int imm = imm9(instr);
  1351. int rN = (int) ((instr & 0x00007f00000LL) >> 20);
  1352. int fM = (int) ((instr & 0x000000fe000LL) >> 13);
  1353. int qp = (int) (instr & 0x0000000003fLL);
  1354. if (qp == 0 && rN == spill_reg && spill_addr != 0
  1355. && ((2 <= fM && fM <= 5) || (16 <= fM && fM <= 31)))
  1356. {
  1357. cache->saved_regs[IA64_FR0_REGNUM + fM] = spill_addr;
  1358. if ((instr & 0x1efc0000000LL) == 0x0eec0000000LL)
  1359. spill_addr += imm;
  1360. else
  1361. spill_addr = 0; /* last one; must be done. */
  1362. last_prologue_pc = next_pc;
  1363. }
  1364. }
  1365. else if ((it == M && ((instr & 0x1eff8000000LL) == 0x02110000000LL))
  1366. || (it == I && ((instr & 0x1eff8000000LL) == 0x00050000000LL)) )
  1367. {
  1368. /* mov.m rN = arM
  1369. or
  1370. mov.i rN = arM */
  1371. int arM = (int) ((instr & 0x00007f00000LL) >> 20);
  1372. int rN = (int) ((instr & 0x00000001fc0LL) >> 6);
  1373. int qp = (int) (instr & 0x0000000003fLL);
  1374. if (qp == 0 && isScratch (rN) && arM == 36 /* ar.unat */)
  1375. {
  1376. /* We have something like "mov.m r3 = ar.unat". Remember the
  1377. r3 (or whatever) and watch for a store of this register... */
  1378. unat_save_reg = rN;
  1379. last_prologue_pc = next_pc;
  1380. }
  1381. }
  1382. else if (it == I && ((instr & 0x1eff8000000LL) == 0x00198000000LL))
  1383. {
  1384. /* mov rN = pr */
  1385. int rN = (int) ((instr & 0x00000001fc0LL) >> 6);
  1386. int qp = (int) (instr & 0x0000000003fLL);
  1387. if (qp == 0 && isScratch (rN))
  1388. {
  1389. pr_save_reg = rN;
  1390. last_prologue_pc = next_pc;
  1391. }
  1392. }
  1393. else if (it == M
  1394. && ( ((instr & 0x1ffc8000000LL) == 0x08cc0000000LL)
  1395. || ((instr & 0x1efc0000000LL) == 0x0acc0000000LL)))
  1396. {
  1397. /* st8 [rN] = rM
  1398. or
  1399. st8 [rN] = rM, imm9 */
  1400. int rN = (int) ((instr & 0x00007f00000LL) >> 20);
  1401. int rM = (int) ((instr & 0x000000fe000LL) >> 13);
  1402. int qp = (int) (instr & 0x0000000003fLL);
  1403. int indirect = rM < 256 ? reg_contents[rM] : 0;
  1404. if (qp == 0 && rN == spill_reg && spill_addr != 0
  1405. && (rM == unat_save_reg || rM == pr_save_reg))
  1406. {
  1407. /* We've found a spill of either the UNAT register or the PR
  1408. register. (Well, not exactly; what we've actually found is
  1409. a spill of the register that UNAT or PR was moved to).
  1410. Record that fact and move on... */
  1411. if (rM == unat_save_reg)
  1412. {
  1413. /* Track UNAT register. */
  1414. cache->saved_regs[IA64_UNAT_REGNUM] = spill_addr;
  1415. unat_save_reg = 0;
  1416. }
  1417. else
  1418. {
  1419. /* Track PR register. */
  1420. cache->saved_regs[IA64_PR_REGNUM] = spill_addr;
  1421. pr_save_reg = 0;
  1422. }
  1423. if ((instr & 0x1efc0000000LL) == 0x0acc0000000LL)
  1424. /* st8 [rN] = rM, imm9 */
  1425. spill_addr += imm9(instr);
  1426. else
  1427. spill_addr = 0; /* Must be done spilling. */
  1428. last_prologue_pc = next_pc;
  1429. }
  1430. else if (qp == 0 && 32 <= rM && rM < 40 && !instores[rM-32])
  1431. {
  1432. /* Allow up to one store of each input register. */
  1433. instores[rM-32] = 1;
  1434. last_prologue_pc = next_pc;
  1435. }
  1436. else if (qp == 0 && 32 <= indirect && indirect < 40 &&
  1437. !instores[indirect-32])
  1438. {
  1439. /* Allow an indirect store of an input register. */
  1440. instores[indirect-32] = 1;
  1441. last_prologue_pc = next_pc;
  1442. }
  1443. }
  1444. else if (it == M && ((instr & 0x1ff08000000LL) == 0x08c00000000LL))
  1445. {
  1446. /* One of
  1447. st1 [rN] = rM
  1448. st2 [rN] = rM
  1449. st4 [rN] = rM
  1450. st8 [rN] = rM
  1451. Note that the st8 case is handled in the clause above.
  1452. Advance over stores of input registers. One store per input
  1453. register is permitted. */
  1454. int rM = (int) ((instr & 0x000000fe000LL) >> 13);
  1455. int qp = (int) (instr & 0x0000000003fLL);
  1456. int indirect = rM < 256 ? reg_contents[rM] : 0;
  1457. if (qp == 0 && 32 <= rM && rM < 40 && !instores[rM-32])
  1458. {
  1459. instores[rM-32] = 1;
  1460. last_prologue_pc = next_pc;
  1461. }
  1462. else if (qp == 0 && 32 <= indirect && indirect < 40 &&
  1463. !instores[indirect-32])
  1464. {
  1465. /* Allow an indirect store of an input register. */
  1466. instores[indirect-32] = 1;
  1467. last_prologue_pc = next_pc;
  1468. }
  1469. }
  1470. else if (it == M && ((instr & 0x1ff88000000LL) == 0x0cc80000000LL))
  1471. {
  1472. /* Either
  1473. stfs [rN] = fM
  1474. or
  1475. stfd [rN] = fM
  1476. Advance over stores of floating point input registers. Again
  1477. one store per register is permitted. */
  1478. int fM = (int) ((instr & 0x000000fe000LL) >> 13);
  1479. int qp = (int) (instr & 0x0000000003fLL);
  1480. if (qp == 0 && 8 <= fM && fM < 16 && !infpstores[fM - 8])
  1481. {
  1482. infpstores[fM-8] = 1;
  1483. last_prologue_pc = next_pc;
  1484. }
  1485. }
  1486. else if (it == M
  1487. && ( ((instr & 0x1ffc8000000LL) == 0x08ec0000000LL)
  1488. || ((instr & 0x1efc0000000LL) == 0x0aec0000000LL)))
  1489. {
  1490. /* st8.spill [rN] = rM
  1491. or
  1492. st8.spill [rN] = rM, imm9 */
  1493. int rN = (int) ((instr & 0x00007f00000LL) >> 20);
  1494. int rM = (int) ((instr & 0x000000fe000LL) >> 13);
  1495. int qp = (int) (instr & 0x0000000003fLL);
  1496. if (qp == 0 && rN == spill_reg && 4 <= rM && rM <= 7)
  1497. {
  1498. /* We've found a spill of one of the preserved general purpose
  1499. regs. Record the spill address and advance the spill
  1500. register if appropriate. */
  1501. cache->saved_regs[IA64_GR0_REGNUM + rM] = spill_addr;
  1502. if ((instr & 0x1efc0000000LL) == 0x0aec0000000LL)
  1503. /* st8.spill [rN] = rM, imm9 */
  1504. spill_addr += imm9(instr);
  1505. else
  1506. spill_addr = 0; /* Done spilling. */
  1507. last_prologue_pc = next_pc;
  1508. }
  1509. }
  1510. pc = next_pc;
  1511. }
  1512. /* If not frameless and we aren't called by skip_prologue, then we need
  1513. to calculate registers for the previous frame which will be needed
  1514. later. */
  1515. if (!frameless && this_frame)
  1516. {
  1517. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  1518. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1519. /* Extract the size of the rotating portion of the stack
  1520. frame and the register rename base from the current
  1521. frame marker. */
  1522. cfm = cache->cfm;
  1523. sor = cache->sor;
  1524. sof = cache->sof;
  1525. sol = cache->sol;
  1526. rrb_gr = (cfm >> 18) & 0x7f;
  1527. /* Find the bof (beginning of frame). */
  1528. bof = rse_address_add (cache->bsp, -sof);
  1529. for (i = 0, addr = bof;
  1530. i < sof;
  1531. i++, addr += 8)
  1532. {
  1533. if (IS_NaT_COLLECTION_ADDR (addr))
  1534. {
  1535. addr += 8;
  1536. }
  1537. if (i+32 == cfm_reg)
  1538. cache->saved_regs[IA64_CFM_REGNUM] = addr;
  1539. if (i+32 == ret_reg)
  1540. cache->saved_regs[IA64_VRAP_REGNUM] = addr;
  1541. if (i+32 == fp_reg)
  1542. cache->saved_regs[IA64_VFP_REGNUM] = addr;
  1543. }
  1544. /* For the previous argument registers we require the previous bof.
  1545. If we can't find the previous cfm, then we can do nothing. */
  1546. cfm = 0;
  1547. if (cache->saved_regs[IA64_CFM_REGNUM] != 0)
  1548. {
  1549. cfm = read_memory_integer (cache->saved_regs[IA64_CFM_REGNUM],
  1550. 8, byte_order);
  1551. }
  1552. else if (cfm_reg != 0)
  1553. {
  1554. get_frame_register (this_frame, cfm_reg, buf);
  1555. cfm = extract_unsigned_integer (buf, 8, byte_order);
  1556. }
  1557. cache->prev_cfm = cfm;
  1558. if (cfm != 0)
  1559. {
  1560. sor = ((cfm >> 14) & 0xf) * 8;
  1561. sof = (cfm & 0x7f);
  1562. sol = (cfm >> 7) & 0x7f;
  1563. rrb_gr = (cfm >> 18) & 0x7f;
  1564. /* The previous bof only requires subtraction of the sol (size of
  1565. locals) due to the overlap between output and input of
  1566. subsequent frames. */
  1567. bof = rse_address_add (bof, -sol);
  1568. for (i = 0, addr = bof;
  1569. i < sof;
  1570. i++, addr += 8)
  1571. {
  1572. if (IS_NaT_COLLECTION_ADDR (addr))
  1573. {
  1574. addr += 8;
  1575. }
  1576. if (i < sor)
  1577. cache->saved_regs[IA64_GR32_REGNUM
  1578. + ((i + (sor - rrb_gr)) % sor)]
  1579. = addr;
  1580. else
  1581. cache->saved_regs[IA64_GR32_REGNUM + i] = addr;
  1582. }
  1583. }
  1584. }
  1585. /* Try and trust the lim_pc value whenever possible. */
  1586. if (trust_limit && lim_pc >= last_prologue_pc)
  1587. last_prologue_pc = lim_pc;
  1588. cache->frameless = frameless;
  1589. cache->after_prologue = last_prologue_pc;
  1590. cache->mem_stack_frame_size = mem_stack_frame_size;
  1591. cache->fp_reg = fp_reg;
  1592. return last_prologue_pc;
  1593. }
  1594. CORE_ADDR
  1595. ia64_skip_prologue (struct gdbarch *gdbarch, CORE_ADDR pc)
  1596. {
  1597. struct ia64_frame_cache cache;
  1598. cache.base = 0;
  1599. cache.after_prologue = 0;
  1600. cache.cfm = 0;
  1601. cache.bsp = 0;
  1602. /* Call examine_prologue with - as third argument since we don't
  1603. have a next frame pointer to send. */
  1604. return examine_prologue (pc, pc+1024, 0, &cache);
  1605. }
  1606. /* Normal frames. */
  1607. static struct ia64_frame_cache *
  1608. ia64_frame_cache (struct frame_info *this_frame, void **this_cache)
  1609. {
  1610. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  1611. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1612. struct ia64_frame_cache *cache;
  1613. gdb_byte buf[8];
  1614. CORE_ADDR cfm;
  1615. if (*this_cache)
  1616. return (struct ia64_frame_cache *) *this_cache;
  1617. cache = ia64_alloc_frame_cache ();
  1618. *this_cache = cache;
  1619. get_frame_register (this_frame, sp_regnum, buf);
  1620. cache->saved_sp = extract_unsigned_integer (buf, 8, byte_order);
  1621. /* We always want the bsp to point to the end of frame.
  1622. This way, we can always get the beginning of frame (bof)
  1623. by subtracting frame size. */
  1624. get_frame_register (this_frame, IA64_BSP_REGNUM, buf);
  1625. cache->bsp = extract_unsigned_integer (buf, 8, byte_order);
  1626. get_frame_register (this_frame, IA64_PSR_REGNUM, buf);
  1627. get_frame_register (this_frame, IA64_CFM_REGNUM, buf);
  1628. cfm = extract_unsigned_integer (buf, 8, byte_order);
  1629. cache->sof = (cfm & 0x7f);
  1630. cache->sol = (cfm >> 7) & 0x7f;
  1631. cache->sor = ((cfm >> 14) & 0xf) * 8;
  1632. cache->cfm = cfm;
  1633. cache->pc = get_frame_func (this_frame);
  1634. if (cache->pc != 0)
  1635. examine_prologue (cache->pc, get_frame_pc (this_frame), this_frame, cache);
  1636. cache->base = cache->saved_sp + cache->mem_stack_frame_size;
  1637. return cache;
  1638. }
  1639. static void
  1640. ia64_frame_this_id (struct frame_info *this_frame, void **this_cache,
  1641. struct frame_id *this_id)
  1642. {
  1643. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  1644. struct ia64_frame_cache *cache =
  1645. ia64_frame_cache (this_frame, this_cache);
  1646. /* If outermost frame, mark with null frame id. */
  1647. if (cache->base != 0)
  1648. (*this_id) = frame_id_build_special (cache->base, cache->pc, cache->bsp);
  1649. if (gdbarch_debug >= 1)
  1650. gdb_printf (gdb_stdlog,
  1651. "regular frame id: code %s, stack %s, "
  1652. "special %s, this_frame %s\n",
  1653. paddress (gdbarch, this_id->code_addr),
  1654. paddress (gdbarch, this_id->stack_addr),
  1655. paddress (gdbarch, cache->bsp),
  1656. host_address_to_string (this_frame));
  1657. }
  1658. static struct value *
  1659. ia64_frame_prev_register (struct frame_info *this_frame, void **this_cache,
  1660. int regnum)
  1661. {
  1662. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  1663. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1664. struct ia64_frame_cache *cache = ia64_frame_cache (this_frame, this_cache);
  1665. gdb_byte buf[8];
  1666. gdb_assert (regnum >= 0);
  1667. if (!target_has_registers ())
  1668. error (_("No registers."));
  1669. if (regnum == gdbarch_sp_regnum (gdbarch))
  1670. return frame_unwind_got_constant (this_frame, regnum, cache->base);
  1671. else if (regnum == IA64_BSP_REGNUM)
  1672. {
  1673. struct value *val;
  1674. CORE_ADDR prev_cfm, bsp, prev_bsp;
  1675. /* We want to calculate the previous bsp as the end of the previous
  1676. register stack frame. This corresponds to what the hardware bsp
  1677. register will be if we pop the frame back which is why we might
  1678. have been called. We know the beginning of the current frame is
  1679. cache->bsp - cache->sof. This value in the previous frame points
  1680. to the start of the output registers. We can calculate the end of
  1681. that frame by adding the size of output:
  1682. (sof (size of frame) - sol (size of locals)). */
  1683. val = ia64_frame_prev_register (this_frame, this_cache, IA64_CFM_REGNUM);
  1684. prev_cfm = extract_unsigned_integer (value_contents_all (val).data (),
  1685. 8, byte_order);
  1686. bsp = rse_address_add (cache->bsp, -(cache->sof));
  1687. prev_bsp =
  1688. rse_address_add (bsp, (prev_cfm & 0x7f) - ((prev_cfm >> 7) & 0x7f));
  1689. return frame_unwind_got_constant (this_frame, regnum, prev_bsp);
  1690. }
  1691. else if (regnum == IA64_CFM_REGNUM)
  1692. {
  1693. CORE_ADDR addr = cache->saved_regs[IA64_CFM_REGNUM];
  1694. if (addr != 0)
  1695. return frame_unwind_got_memory (this_frame, regnum, addr);
  1696. if (cache->prev_cfm)
  1697. return frame_unwind_got_constant (this_frame, regnum, cache->prev_cfm);
  1698. if (cache->frameless)
  1699. return frame_unwind_got_register (this_frame, IA64_PFS_REGNUM,
  1700. IA64_PFS_REGNUM);
  1701. return frame_unwind_got_register (this_frame, regnum, 0);
  1702. }
  1703. else if (regnum == IA64_VFP_REGNUM)
  1704. {
  1705. /* If the function in question uses an automatic register (r32-r127)
  1706. for the frame pointer, it'll be found by ia64_find_saved_register()
  1707. above. If the function lacks one of these frame pointers, we can
  1708. still provide a value since we know the size of the frame. */
  1709. return frame_unwind_got_constant (this_frame, regnum, cache->base);
  1710. }
  1711. else if (VP0_REGNUM <= regnum && regnum <= VP63_REGNUM)
  1712. {
  1713. struct value *pr_val;
  1714. ULONGEST prN;
  1715. pr_val = ia64_frame_prev_register (this_frame, this_cache,
  1716. IA64_PR_REGNUM);
  1717. if (VP16_REGNUM <= regnum && regnum <= VP63_REGNUM)
  1718. {
  1719. /* Fetch predicate register rename base from current frame
  1720. marker for this frame. */
  1721. int rrb_pr = (cache->cfm >> 32) & 0x3f;
  1722. /* Adjust the register number to account for register rotation. */
  1723. regnum = VP16_REGNUM + ((regnum - VP16_REGNUM) + rrb_pr) % 48;
  1724. }
  1725. prN = extract_bit_field (value_contents_all (pr_val).data (),
  1726. regnum - VP0_REGNUM, 1);
  1727. return frame_unwind_got_constant (this_frame, regnum, prN);
  1728. }
  1729. else if (IA64_NAT0_REGNUM <= regnum && regnum <= IA64_NAT31_REGNUM)
  1730. {
  1731. struct value *unat_val;
  1732. ULONGEST unatN;
  1733. unat_val = ia64_frame_prev_register (this_frame, this_cache,
  1734. IA64_UNAT_REGNUM);
  1735. unatN = extract_bit_field (value_contents_all (unat_val).data (),
  1736. regnum - IA64_NAT0_REGNUM, 1);
  1737. return frame_unwind_got_constant (this_frame, regnum, unatN);
  1738. }
  1739. else if (IA64_NAT32_REGNUM <= regnum && regnum <= IA64_NAT127_REGNUM)
  1740. {
  1741. int natval = 0;
  1742. /* Find address of general register corresponding to nat bit we're
  1743. interested in. */
  1744. CORE_ADDR gr_addr;
  1745. gr_addr = cache->saved_regs[regnum - IA64_NAT0_REGNUM + IA64_GR0_REGNUM];
  1746. if (gr_addr != 0)
  1747. {
  1748. /* Compute address of nat collection bits. */
  1749. CORE_ADDR nat_addr = gr_addr | 0x1f8;
  1750. CORE_ADDR bsp;
  1751. CORE_ADDR nat_collection;
  1752. int nat_bit;
  1753. /* If our nat collection address is bigger than bsp, we have to get
  1754. the nat collection from rnat. Otherwise, we fetch the nat
  1755. collection from the computed address. */
  1756. get_frame_register (this_frame, IA64_BSP_REGNUM, buf);
  1757. bsp = extract_unsigned_integer (buf, 8, byte_order);
  1758. if (nat_addr >= bsp)
  1759. {
  1760. get_frame_register (this_frame, IA64_RNAT_REGNUM, buf);
  1761. nat_collection = extract_unsigned_integer (buf, 8, byte_order);
  1762. }
  1763. else
  1764. nat_collection = read_memory_integer (nat_addr, 8, byte_order);
  1765. nat_bit = (gr_addr >> 3) & 0x3f;
  1766. natval = (nat_collection >> nat_bit) & 1;
  1767. }
  1768. return frame_unwind_got_constant (this_frame, regnum, natval);
  1769. }
  1770. else if (regnum == IA64_IP_REGNUM)
  1771. {
  1772. CORE_ADDR pc = 0;
  1773. CORE_ADDR addr = cache->saved_regs[IA64_VRAP_REGNUM];
  1774. if (addr != 0)
  1775. {
  1776. read_memory (addr, buf, register_size (gdbarch, IA64_IP_REGNUM));
  1777. pc = extract_unsigned_integer (buf, 8, byte_order);
  1778. }
  1779. else if (cache->frameless)
  1780. {
  1781. get_frame_register (this_frame, IA64_BR0_REGNUM, buf);
  1782. pc = extract_unsigned_integer (buf, 8, byte_order);
  1783. }
  1784. pc &= ~0xf;
  1785. return frame_unwind_got_constant (this_frame, regnum, pc);
  1786. }
  1787. else if (regnum == IA64_PSR_REGNUM)
  1788. {
  1789. /* We don't know how to get the complete previous PSR, but we need it
  1790. for the slot information when we unwind the pc (pc is formed of IP
  1791. register plus slot information from PSR). To get the previous
  1792. slot information, we mask it off the return address. */
  1793. ULONGEST slot_num = 0;
  1794. CORE_ADDR pc = 0;
  1795. CORE_ADDR psr = 0;
  1796. CORE_ADDR addr = cache->saved_regs[IA64_VRAP_REGNUM];
  1797. get_frame_register (this_frame, IA64_PSR_REGNUM, buf);
  1798. psr = extract_unsigned_integer (buf, 8, byte_order);
  1799. if (addr != 0)
  1800. {
  1801. read_memory (addr, buf, register_size (gdbarch, IA64_IP_REGNUM));
  1802. pc = extract_unsigned_integer (buf, 8, byte_order);
  1803. }
  1804. else if (cache->frameless)
  1805. {
  1806. get_frame_register (this_frame, IA64_BR0_REGNUM, buf);
  1807. pc = extract_unsigned_integer (buf, 8, byte_order);
  1808. }
  1809. psr &= ~(3LL << 41);
  1810. slot_num = pc & 0x3LL;
  1811. psr |= (CORE_ADDR)slot_num << 41;
  1812. return frame_unwind_got_constant (this_frame, regnum, psr);
  1813. }
  1814. else if (regnum == IA64_BR0_REGNUM)
  1815. {
  1816. CORE_ADDR addr = cache->saved_regs[IA64_BR0_REGNUM];
  1817. if (addr != 0)
  1818. return frame_unwind_got_memory (this_frame, regnum, addr);
  1819. return frame_unwind_got_constant (this_frame, regnum, 0);
  1820. }
  1821. else if ((regnum >= IA64_GR32_REGNUM && regnum <= IA64_GR127_REGNUM)
  1822. || (regnum >= V32_REGNUM && regnum <= V127_REGNUM))
  1823. {
  1824. CORE_ADDR addr = 0;
  1825. if (regnum >= V32_REGNUM)
  1826. regnum = IA64_GR32_REGNUM + (regnum - V32_REGNUM);
  1827. addr = cache->saved_regs[regnum];
  1828. if (addr != 0)
  1829. return frame_unwind_got_memory (this_frame, regnum, addr);
  1830. if (cache->frameless)
  1831. {
  1832. struct value *reg_val;
  1833. CORE_ADDR prev_cfm, prev_bsp, prev_bof;
  1834. /* FIXME: brobecker/2008-05-01: Doesn't this seem redundant
  1835. with the same code above? */
  1836. if (regnum >= V32_REGNUM)
  1837. regnum = IA64_GR32_REGNUM + (regnum - V32_REGNUM);
  1838. reg_val = ia64_frame_prev_register (this_frame, this_cache,
  1839. IA64_CFM_REGNUM);
  1840. prev_cfm = extract_unsigned_integer
  1841. (value_contents_all (reg_val).data (), 8, byte_order);
  1842. reg_val = ia64_frame_prev_register (this_frame, this_cache,
  1843. IA64_BSP_REGNUM);
  1844. prev_bsp = extract_unsigned_integer
  1845. (value_contents_all (reg_val).data (), 8, byte_order);
  1846. prev_bof = rse_address_add (prev_bsp, -(prev_cfm & 0x7f));
  1847. addr = rse_address_add (prev_bof, (regnum - IA64_GR32_REGNUM));
  1848. return frame_unwind_got_memory (this_frame, regnum, addr);
  1849. }
  1850. return frame_unwind_got_constant (this_frame, regnum, 0);
  1851. }
  1852. else /* All other registers. */
  1853. {
  1854. CORE_ADDR addr = 0;
  1855. if (IA64_FR32_REGNUM <= regnum && regnum <= IA64_FR127_REGNUM)
  1856. {
  1857. /* Fetch floating point register rename base from current
  1858. frame marker for this frame. */
  1859. int rrb_fr = (cache->cfm >> 25) & 0x7f;
  1860. /* Adjust the floating point register number to account for
  1861. register rotation. */
  1862. regnum = IA64_FR32_REGNUM
  1863. + ((regnum - IA64_FR32_REGNUM) + rrb_fr) % 96;
  1864. }
  1865. /* If we have stored a memory address, access the register. */
  1866. addr = cache->saved_regs[regnum];
  1867. if (addr != 0)
  1868. return frame_unwind_got_memory (this_frame, regnum, addr);
  1869. /* Otherwise, punt and get the current value of the register. */
  1870. else
  1871. return frame_unwind_got_register (this_frame, regnum, regnum);
  1872. }
  1873. }
  1874. static const struct frame_unwind ia64_frame_unwind =
  1875. {
  1876. "ia64 prologue",
  1877. NORMAL_FRAME,
  1878. default_frame_unwind_stop_reason,
  1879. &ia64_frame_this_id,
  1880. &ia64_frame_prev_register,
  1881. NULL,
  1882. default_frame_sniffer
  1883. };
  1884. /* Signal trampolines. */
  1885. static void
  1886. ia64_sigtramp_frame_init_saved_regs (struct frame_info *this_frame,
  1887. struct ia64_frame_cache *cache)
  1888. {
  1889. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  1890. ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  1891. if (tdep->sigcontext_register_address)
  1892. {
  1893. int regno;
  1894. cache->saved_regs[IA64_VRAP_REGNUM]
  1895. = tdep->sigcontext_register_address (gdbarch, cache->base,
  1896. IA64_IP_REGNUM);
  1897. cache->saved_regs[IA64_CFM_REGNUM]
  1898. = tdep->sigcontext_register_address (gdbarch, cache->base,
  1899. IA64_CFM_REGNUM);
  1900. cache->saved_regs[IA64_PSR_REGNUM]
  1901. = tdep->sigcontext_register_address (gdbarch, cache->base,
  1902. IA64_PSR_REGNUM);
  1903. cache->saved_regs[IA64_BSP_REGNUM]
  1904. = tdep->sigcontext_register_address (gdbarch, cache->base,
  1905. IA64_BSP_REGNUM);
  1906. cache->saved_regs[IA64_RNAT_REGNUM]
  1907. = tdep->sigcontext_register_address (gdbarch, cache->base,
  1908. IA64_RNAT_REGNUM);
  1909. cache->saved_regs[IA64_CCV_REGNUM]
  1910. = tdep->sigcontext_register_address (gdbarch, cache->base,
  1911. IA64_CCV_REGNUM);
  1912. cache->saved_regs[IA64_UNAT_REGNUM]
  1913. = tdep->sigcontext_register_address (gdbarch, cache->base,
  1914. IA64_UNAT_REGNUM);
  1915. cache->saved_regs[IA64_FPSR_REGNUM]
  1916. = tdep->sigcontext_register_address (gdbarch, cache->base,
  1917. IA64_FPSR_REGNUM);
  1918. cache->saved_regs[IA64_PFS_REGNUM]
  1919. = tdep->sigcontext_register_address (gdbarch, cache->base,
  1920. IA64_PFS_REGNUM);
  1921. cache->saved_regs[IA64_LC_REGNUM]
  1922. = tdep->sigcontext_register_address (gdbarch, cache->base,
  1923. IA64_LC_REGNUM);
  1924. for (regno = IA64_GR1_REGNUM; regno <= IA64_GR31_REGNUM; regno++)
  1925. cache->saved_regs[regno] =
  1926. tdep->sigcontext_register_address (gdbarch, cache->base, regno);
  1927. for (regno = IA64_BR0_REGNUM; regno <= IA64_BR7_REGNUM; regno++)
  1928. cache->saved_regs[regno] =
  1929. tdep->sigcontext_register_address (gdbarch, cache->base, regno);
  1930. for (regno = IA64_FR2_REGNUM; regno <= IA64_FR31_REGNUM; regno++)
  1931. cache->saved_regs[regno] =
  1932. tdep->sigcontext_register_address (gdbarch, cache->base, regno);
  1933. }
  1934. }
  1935. static struct ia64_frame_cache *
  1936. ia64_sigtramp_frame_cache (struct frame_info *this_frame, void **this_cache)
  1937. {
  1938. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  1939. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1940. struct ia64_frame_cache *cache;
  1941. gdb_byte buf[8];
  1942. if (*this_cache)
  1943. return (struct ia64_frame_cache *) *this_cache;
  1944. cache = ia64_alloc_frame_cache ();
  1945. get_frame_register (this_frame, sp_regnum, buf);
  1946. /* Note that frame size is hard-coded below. We cannot calculate it
  1947. via prologue examination. */
  1948. cache->base = extract_unsigned_integer (buf, 8, byte_order) + 16;
  1949. get_frame_register (this_frame, IA64_BSP_REGNUM, buf);
  1950. cache->bsp = extract_unsigned_integer (buf, 8, byte_order);
  1951. get_frame_register (this_frame, IA64_CFM_REGNUM, buf);
  1952. cache->cfm = extract_unsigned_integer (buf, 8, byte_order);
  1953. cache->sof = cache->cfm & 0x7f;
  1954. ia64_sigtramp_frame_init_saved_regs (this_frame, cache);
  1955. *this_cache = cache;
  1956. return cache;
  1957. }
  1958. static void
  1959. ia64_sigtramp_frame_this_id (struct frame_info *this_frame,
  1960. void **this_cache, struct frame_id *this_id)
  1961. {
  1962. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  1963. struct ia64_frame_cache *cache =
  1964. ia64_sigtramp_frame_cache (this_frame, this_cache);
  1965. (*this_id) = frame_id_build_special (cache->base,
  1966. get_frame_pc (this_frame),
  1967. cache->bsp);
  1968. if (gdbarch_debug >= 1)
  1969. gdb_printf (gdb_stdlog,
  1970. "sigtramp frame id: code %s, stack %s, "
  1971. "special %s, this_frame %s\n",
  1972. paddress (gdbarch, this_id->code_addr),
  1973. paddress (gdbarch, this_id->stack_addr),
  1974. paddress (gdbarch, cache->bsp),
  1975. host_address_to_string (this_frame));
  1976. }
  1977. static struct value *
  1978. ia64_sigtramp_frame_prev_register (struct frame_info *this_frame,
  1979. void **this_cache, int regnum)
  1980. {
  1981. struct ia64_frame_cache *cache =
  1982. ia64_sigtramp_frame_cache (this_frame, this_cache);
  1983. gdb_assert (regnum >= 0);
  1984. if (!target_has_registers ())
  1985. error (_("No registers."));
  1986. if (regnum == IA64_IP_REGNUM)
  1987. {
  1988. CORE_ADDR pc = 0;
  1989. CORE_ADDR addr = cache->saved_regs[IA64_VRAP_REGNUM];
  1990. if (addr != 0)
  1991. {
  1992. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  1993. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1994. pc = read_memory_unsigned_integer (addr, 8, byte_order);
  1995. }
  1996. pc &= ~0xf;
  1997. return frame_unwind_got_constant (this_frame, regnum, pc);
  1998. }
  1999. else if ((regnum >= IA64_GR32_REGNUM && regnum <= IA64_GR127_REGNUM)
  2000. || (regnum >= V32_REGNUM && regnum <= V127_REGNUM))
  2001. {
  2002. CORE_ADDR addr = 0;
  2003. if (regnum >= V32_REGNUM)
  2004. regnum = IA64_GR32_REGNUM + (regnum - V32_REGNUM);
  2005. addr = cache->saved_regs[regnum];
  2006. if (addr != 0)
  2007. return frame_unwind_got_memory (this_frame, regnum, addr);
  2008. return frame_unwind_got_constant (this_frame, regnum, 0);
  2009. }
  2010. else /* All other registers not listed above. */
  2011. {
  2012. CORE_ADDR addr = cache->saved_regs[regnum];
  2013. if (addr != 0)
  2014. return frame_unwind_got_memory (this_frame, regnum, addr);
  2015. return frame_unwind_got_constant (this_frame, regnum, 0);
  2016. }
  2017. }
  2018. static int
  2019. ia64_sigtramp_frame_sniffer (const struct frame_unwind *self,
  2020. struct frame_info *this_frame,
  2021. void **this_cache)
  2022. {
  2023. gdbarch *arch = get_frame_arch (this_frame);
  2024. ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (arch);
  2025. if (tdep->pc_in_sigtramp)
  2026. {
  2027. CORE_ADDR pc = get_frame_pc (this_frame);
  2028. if (tdep->pc_in_sigtramp (pc))
  2029. return 1;
  2030. }
  2031. return 0;
  2032. }
  2033. static const struct frame_unwind ia64_sigtramp_frame_unwind =
  2034. {
  2035. "ia64 sigtramp",
  2036. SIGTRAMP_FRAME,
  2037. default_frame_unwind_stop_reason,
  2038. ia64_sigtramp_frame_this_id,
  2039. ia64_sigtramp_frame_prev_register,
  2040. NULL,
  2041. ia64_sigtramp_frame_sniffer
  2042. };
  2043. static CORE_ADDR
  2044. ia64_frame_base_address (struct frame_info *this_frame, void **this_cache)
  2045. {
  2046. struct ia64_frame_cache *cache = ia64_frame_cache (this_frame, this_cache);
  2047. return cache->base;
  2048. }
  2049. static const struct frame_base ia64_frame_base =
  2050. {
  2051. &ia64_frame_unwind,
  2052. ia64_frame_base_address,
  2053. ia64_frame_base_address,
  2054. ia64_frame_base_address
  2055. };
  2056. #ifdef HAVE_LIBUNWIND_IA64_H
  2057. struct ia64_unwind_table_entry
  2058. {
  2059. unw_word_t start_offset;
  2060. unw_word_t end_offset;
  2061. unw_word_t info_offset;
  2062. };
  2063. static __inline__ uint64_t
  2064. ia64_rse_slot_num (uint64_t addr)
  2065. {
  2066. return (addr >> 3) & 0x3f;
  2067. }
  2068. /* Skip over a designated number of registers in the backing
  2069. store, remembering every 64th position is for NAT. */
  2070. static __inline__ uint64_t
  2071. ia64_rse_skip_regs (uint64_t addr, long num_regs)
  2072. {
  2073. long delta = ia64_rse_slot_num(addr) + num_regs;
  2074. if (num_regs < 0)
  2075. delta -= 0x3e;
  2076. return addr + ((num_regs + delta/0x3f) << 3);
  2077. }
  2078. /* Gdb ia64-libunwind-tdep callback function to convert from an ia64 gdb
  2079. register number to a libunwind register number. */
  2080. static int
  2081. ia64_gdb2uw_regnum (int regnum)
  2082. {
  2083. if (regnum == sp_regnum)
  2084. return UNW_IA64_SP;
  2085. else if (regnum == IA64_BSP_REGNUM)
  2086. return UNW_IA64_BSP;
  2087. else if ((unsigned) (regnum - IA64_GR0_REGNUM) < 128)
  2088. return UNW_IA64_GR + (regnum - IA64_GR0_REGNUM);
  2089. else if ((unsigned) (regnum - V32_REGNUM) < 95)
  2090. return UNW_IA64_GR + 32 + (regnum - V32_REGNUM);
  2091. else if ((unsigned) (regnum - IA64_FR0_REGNUM) < 128)
  2092. return UNW_IA64_FR + (regnum - IA64_FR0_REGNUM);
  2093. else if ((unsigned) (regnum - IA64_PR0_REGNUM) < 64)
  2094. return -1;
  2095. else if ((unsigned) (regnum - IA64_BR0_REGNUM) < 8)
  2096. return UNW_IA64_BR + (regnum - IA64_BR0_REGNUM);
  2097. else if (regnum == IA64_PR_REGNUM)
  2098. return UNW_IA64_PR;
  2099. else if (regnum == IA64_IP_REGNUM)
  2100. return UNW_REG_IP;
  2101. else if (regnum == IA64_CFM_REGNUM)
  2102. return UNW_IA64_CFM;
  2103. else if ((unsigned) (regnum - IA64_AR0_REGNUM) < 128)
  2104. return UNW_IA64_AR + (regnum - IA64_AR0_REGNUM);
  2105. else if ((unsigned) (regnum - IA64_NAT0_REGNUM) < 128)
  2106. return UNW_IA64_NAT + (regnum - IA64_NAT0_REGNUM);
  2107. else
  2108. return -1;
  2109. }
  2110. /* Gdb ia64-libunwind-tdep callback function to convert from a libunwind
  2111. register number to a ia64 gdb register number. */
  2112. static int
  2113. ia64_uw2gdb_regnum (int uw_regnum)
  2114. {
  2115. if (uw_regnum == UNW_IA64_SP)
  2116. return sp_regnum;
  2117. else if (uw_regnum == UNW_IA64_BSP)
  2118. return IA64_BSP_REGNUM;
  2119. else if ((unsigned) (uw_regnum - UNW_IA64_GR) < 32)
  2120. return IA64_GR0_REGNUM + (uw_regnum - UNW_IA64_GR);
  2121. else if ((unsigned) (uw_regnum - UNW_IA64_GR) < 128)
  2122. return V32_REGNUM + (uw_regnum - (IA64_GR0_REGNUM + 32));
  2123. else if ((unsigned) (uw_regnum - UNW_IA64_FR) < 128)
  2124. return IA64_FR0_REGNUM + (uw_regnum - UNW_IA64_FR);
  2125. else if ((unsigned) (uw_regnum - UNW_IA64_BR) < 8)
  2126. return IA64_BR0_REGNUM + (uw_regnum - UNW_IA64_BR);
  2127. else if (uw_regnum == UNW_IA64_PR)
  2128. return IA64_PR_REGNUM;
  2129. else if (uw_regnum == UNW_REG_IP)
  2130. return IA64_IP_REGNUM;
  2131. else if (uw_regnum == UNW_IA64_CFM)
  2132. return IA64_CFM_REGNUM;
  2133. else if ((unsigned) (uw_regnum - UNW_IA64_AR) < 128)
  2134. return IA64_AR0_REGNUM + (uw_regnum - UNW_IA64_AR);
  2135. else if ((unsigned) (uw_regnum - UNW_IA64_NAT) < 128)
  2136. return IA64_NAT0_REGNUM + (uw_regnum - UNW_IA64_NAT);
  2137. else
  2138. return -1;
  2139. }
  2140. /* Gdb ia64-libunwind-tdep callback function to reveal if register is
  2141. a float register or not. */
  2142. static int
  2143. ia64_is_fpreg (int uw_regnum)
  2144. {
  2145. return unw_is_fpreg (uw_regnum);
  2146. }
  2147. /* Libunwind callback accessor function for general registers. */
  2148. static int
  2149. ia64_access_reg (unw_addr_space_t as, unw_regnum_t uw_regnum, unw_word_t *val,
  2150. int write, void *arg)
  2151. {
  2152. int regnum = ia64_uw2gdb_regnum (uw_regnum);
  2153. unw_word_t bsp, sof, cfm, psr, ip;
  2154. struct frame_info *this_frame = (struct frame_info *) arg;
  2155. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  2156. ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  2157. /* We never call any libunwind routines that need to write registers. */
  2158. gdb_assert (!write);
  2159. switch (uw_regnum)
  2160. {
  2161. case UNW_REG_IP:
  2162. /* Libunwind expects to see the pc value which means the slot number
  2163. from the psr must be merged with the ip word address. */
  2164. ip = get_frame_register_unsigned (this_frame, IA64_IP_REGNUM);
  2165. psr = get_frame_register_unsigned (this_frame, IA64_PSR_REGNUM);
  2166. *val = ip | ((psr >> 41) & 0x3);
  2167. break;
  2168. case UNW_IA64_AR_BSP:
  2169. /* Libunwind expects to see the beginning of the current
  2170. register frame so we must account for the fact that
  2171. ptrace() will return a value for bsp that points *after*
  2172. the current register frame. */
  2173. bsp = get_frame_register_unsigned (this_frame, IA64_BSP_REGNUM);
  2174. cfm = get_frame_register_unsigned (this_frame, IA64_CFM_REGNUM);
  2175. sof = tdep->size_of_register_frame (this_frame, cfm);
  2176. *val = ia64_rse_skip_regs (bsp, -sof);
  2177. break;
  2178. case UNW_IA64_AR_BSPSTORE:
  2179. /* Libunwind wants bspstore to be after the current register frame.
  2180. This is what ptrace() and gdb treats as the regular bsp value. */
  2181. *val = get_frame_register_unsigned (this_frame, IA64_BSP_REGNUM);
  2182. break;
  2183. default:
  2184. /* For all other registers, just unwind the value directly. */
  2185. *val = get_frame_register_unsigned (this_frame, regnum);
  2186. break;
  2187. }
  2188. if (gdbarch_debug >= 1)
  2189. gdb_printf (gdb_stdlog,
  2190. " access_reg: from cache: %4s=%s\n",
  2191. (((unsigned) regnum <= IA64_NAT127_REGNUM)
  2192. ? ia64_register_names[regnum] : "r??"),
  2193. paddress (gdbarch, *val));
  2194. return 0;
  2195. }
  2196. /* Libunwind callback accessor function for floating-point registers. */
  2197. static int
  2198. ia64_access_fpreg (unw_addr_space_t as, unw_regnum_t uw_regnum,
  2199. unw_fpreg_t *val, int write, void *arg)
  2200. {
  2201. int regnum = ia64_uw2gdb_regnum (uw_regnum);
  2202. struct frame_info *this_frame = (struct frame_info *) arg;
  2203. /* We never call any libunwind routines that need to write registers. */
  2204. gdb_assert (!write);
  2205. get_frame_register (this_frame, regnum, (gdb_byte *) val);
  2206. return 0;
  2207. }
  2208. /* Libunwind callback accessor function for top-level rse registers. */
  2209. static int
  2210. ia64_access_rse_reg (unw_addr_space_t as, unw_regnum_t uw_regnum,
  2211. unw_word_t *val, int write, void *arg)
  2212. {
  2213. int regnum = ia64_uw2gdb_regnum (uw_regnum);
  2214. unw_word_t bsp, sof, cfm, psr, ip;
  2215. struct regcache *regcache = (struct regcache *) arg;
  2216. struct gdbarch *gdbarch = regcache->arch ();
  2217. /* We never call any libunwind routines that need to write registers. */
  2218. gdb_assert (!write);
  2219. switch (uw_regnum)
  2220. {
  2221. case UNW_REG_IP:
  2222. /* Libunwind expects to see the pc value which means the slot number
  2223. from the psr must be merged with the ip word address. */
  2224. regcache_cooked_read_unsigned (regcache, IA64_IP_REGNUM, &ip);
  2225. regcache_cooked_read_unsigned (regcache, IA64_PSR_REGNUM, &psr);
  2226. *val = ip | ((psr >> 41) & 0x3);
  2227. break;
  2228. case UNW_IA64_AR_BSP:
  2229. /* Libunwind expects to see the beginning of the current
  2230. register frame so we must account for the fact that
  2231. ptrace() will return a value for bsp that points *after*
  2232. the current register frame. */
  2233. regcache_cooked_read_unsigned (regcache, IA64_BSP_REGNUM, &bsp);
  2234. regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm);
  2235. sof = (cfm & 0x7f);
  2236. *val = ia64_rse_skip_regs (bsp, -sof);
  2237. break;
  2238. case UNW_IA64_AR_BSPSTORE:
  2239. /* Libunwind wants bspstore to be after the current register frame.
  2240. This is what ptrace() and gdb treats as the regular bsp value. */
  2241. regcache_cooked_read_unsigned (regcache, IA64_BSP_REGNUM, val);
  2242. break;
  2243. default:
  2244. /* For all other registers, just unwind the value directly. */
  2245. regcache_cooked_read_unsigned (regcache, regnum, val);
  2246. break;
  2247. }
  2248. if (gdbarch_debug >= 1)
  2249. gdb_printf (gdb_stdlog,
  2250. " access_rse_reg: from cache: %4s=%s\n",
  2251. (((unsigned) regnum <= IA64_NAT127_REGNUM)
  2252. ? ia64_register_names[regnum] : "r??"),
  2253. paddress (gdbarch, *val));
  2254. return 0;
  2255. }
  2256. /* Libunwind callback accessor function for top-level fp registers. */
  2257. static int
  2258. ia64_access_rse_fpreg (unw_addr_space_t as, unw_regnum_t uw_regnum,
  2259. unw_fpreg_t *val, int write, void *arg)
  2260. {
  2261. int regnum = ia64_uw2gdb_regnum (uw_regnum);
  2262. struct regcache *regcache = (struct regcache *) arg;
  2263. /* We never call any libunwind routines that need to write registers. */
  2264. gdb_assert (!write);
  2265. regcache->cooked_read (regnum, (gdb_byte *) val);
  2266. return 0;
  2267. }
  2268. /* Libunwind callback accessor function for accessing memory. */
  2269. static int
  2270. ia64_access_mem (unw_addr_space_t as,
  2271. unw_word_t addr, unw_word_t *val,
  2272. int write, void *arg)
  2273. {
  2274. if (addr - KERNEL_START < ktab_size)
  2275. {
  2276. unw_word_t *laddr = (unw_word_t*) ((char *) ktab
  2277. + (addr - KERNEL_START));
  2278. if (write)
  2279. *laddr = *val;
  2280. else
  2281. *val = *laddr;
  2282. return 0;
  2283. }
  2284. /* XXX do we need to normalize byte-order here? */
  2285. if (write)
  2286. return target_write_memory (addr, (gdb_byte *) val, sizeof (unw_word_t));
  2287. else
  2288. return target_read_memory (addr, (gdb_byte *) val, sizeof (unw_word_t));
  2289. }
  2290. /* Call low-level function to access the kernel unwind table. */
  2291. static gdb::optional<gdb::byte_vector>
  2292. getunwind_table ()
  2293. {
  2294. /* FIXME drow/2005-09-10: This code used to call
  2295. ia64_linux_xfer_unwind_table directly to fetch the unwind table
  2296. for the currently running ia64-linux kernel. That data should
  2297. come from the core file and be accessed via the auxv vector; if
  2298. we want to preserve fall back to the running kernel's table, then
  2299. we should find a way to override the corefile layer's
  2300. xfer_partial method. */
  2301. return target_read_alloc (current_inferior ()->top_target (),
  2302. TARGET_OBJECT_UNWIND_TABLE, NULL);
  2303. }
  2304. /* Get the kernel unwind table. */
  2305. static int
  2306. get_kernel_table (unw_word_t ip, unw_dyn_info_t *di)
  2307. {
  2308. static struct ia64_table_entry *etab;
  2309. if (!ktab)
  2310. {
  2311. ktab_buf = getunwind_table ();
  2312. if (!ktab_buf)
  2313. return -UNW_ENOINFO;
  2314. ktab = (struct ia64_table_entry *) ktab_buf->data ();
  2315. ktab_size = ktab_buf->size ();
  2316. for (etab = ktab; etab->start_offset; ++etab)
  2317. etab->info_offset += KERNEL_START;
  2318. }
  2319. if (ip < ktab[0].start_offset || ip >= etab[-1].end_offset)
  2320. return -UNW_ENOINFO;
  2321. di->format = UNW_INFO_FORMAT_TABLE;
  2322. di->gp = 0;
  2323. di->start_ip = ktab[0].start_offset;
  2324. di->end_ip = etab[-1].end_offset;
  2325. di->u.ti.name_ptr = (unw_word_t) "<kernel>";
  2326. di->u.ti.segbase = 0;
  2327. di->u.ti.table_len = ((char *) etab - (char *) ktab) / sizeof (unw_word_t);
  2328. di->u.ti.table_data = (unw_word_t *) ktab;
  2329. if (gdbarch_debug >= 1)
  2330. gdb_printf (gdb_stdlog, "get_kernel_table: found table `%s': "
  2331. "segbase=%s, length=%s, gp=%s\n",
  2332. (char *) di->u.ti.name_ptr,
  2333. hex_string (di->u.ti.segbase),
  2334. pulongest (di->u.ti.table_len),
  2335. hex_string (di->gp));
  2336. return 0;
  2337. }
  2338. /* Find the unwind table entry for a specified address. */
  2339. static int
  2340. ia64_find_unwind_table (struct objfile *objfile, unw_word_t ip,
  2341. unw_dyn_info_t *dip, void **buf)
  2342. {
  2343. Elf_Internal_Phdr *phdr, *p_text = NULL, *p_unwind = NULL;
  2344. Elf_Internal_Ehdr *ehdr;
  2345. unw_word_t segbase = 0;
  2346. CORE_ADDR load_base;
  2347. bfd *bfd;
  2348. int i;
  2349. bfd = objfile->obfd;
  2350. ehdr = elf_tdata (bfd)->elf_header;
  2351. phdr = elf_tdata (bfd)->phdr;
  2352. load_base = objfile->text_section_offset ();
  2353. for (i = 0; i < ehdr->e_phnum; ++i)
  2354. {
  2355. switch (phdr[i].p_type)
  2356. {
  2357. case PT_LOAD:
  2358. if ((unw_word_t) (ip - load_base - phdr[i].p_vaddr)
  2359. < phdr[i].p_memsz)
  2360. p_text = phdr + i;
  2361. break;
  2362. case PT_IA_64_UNWIND:
  2363. p_unwind = phdr + i;
  2364. break;
  2365. default:
  2366. break;
  2367. }
  2368. }
  2369. if (!p_text || !p_unwind)
  2370. return -UNW_ENOINFO;
  2371. /* Verify that the segment that contains the IP also contains
  2372. the static unwind table. If not, we may be in the Linux kernel's
  2373. DSO gate page in which case the unwind table is another segment.
  2374. Otherwise, we are dealing with runtime-generated code, for which we
  2375. have no info here. */
  2376. segbase = p_text->p_vaddr + load_base;
  2377. if ((p_unwind->p_vaddr - p_text->p_vaddr) >= p_text->p_memsz)
  2378. {
  2379. int ok = 0;
  2380. for (i = 0; i < ehdr->e_phnum; ++i)
  2381. {
  2382. if (phdr[i].p_type == PT_LOAD
  2383. && (p_unwind->p_vaddr - phdr[i].p_vaddr) < phdr[i].p_memsz)
  2384. {
  2385. ok = 1;
  2386. /* Get the segbase from the section containing the
  2387. libunwind table. */
  2388. segbase = phdr[i].p_vaddr + load_base;
  2389. }
  2390. }
  2391. if (!ok)
  2392. return -UNW_ENOINFO;
  2393. }
  2394. dip->start_ip = p_text->p_vaddr + load_base;
  2395. dip->end_ip = dip->start_ip + p_text->p_memsz;
  2396. dip->gp = ia64_find_global_pointer (objfile->arch (), ip);
  2397. dip->format = UNW_INFO_FORMAT_REMOTE_TABLE;
  2398. dip->u.rti.name_ptr = (unw_word_t) bfd_get_filename (bfd);
  2399. dip->u.rti.segbase = segbase;
  2400. dip->u.rti.table_len = p_unwind->p_memsz / sizeof (unw_word_t);
  2401. dip->u.rti.table_data = p_unwind->p_vaddr + load_base;
  2402. return 0;
  2403. }
  2404. /* Libunwind callback accessor function to acquire procedure unwind-info. */
  2405. static int
  2406. ia64_find_proc_info_x (unw_addr_space_t as, unw_word_t ip, unw_proc_info_t *pi,
  2407. int need_unwind_info, void *arg)
  2408. {
  2409. struct obj_section *sec = find_pc_section (ip);
  2410. unw_dyn_info_t di;
  2411. int ret;
  2412. void *buf = NULL;
  2413. if (!sec)
  2414. {
  2415. /* XXX This only works if the host and the target architecture are
  2416. both ia64 and if the have (more or less) the same kernel
  2417. version. */
  2418. if (get_kernel_table (ip, &di) < 0)
  2419. return -UNW_ENOINFO;
  2420. if (gdbarch_debug >= 1)
  2421. gdb_printf (gdb_stdlog, "ia64_find_proc_info_x: %s -> "
  2422. "(name=`%s',segbase=%s,start=%s,end=%s,gp=%s,"
  2423. "length=%s,data=%s)\n",
  2424. hex_string (ip), (char *)di.u.ti.name_ptr,
  2425. hex_string (di.u.ti.segbase),
  2426. hex_string (di.start_ip), hex_string (di.end_ip),
  2427. hex_string (di.gp),
  2428. pulongest (di.u.ti.table_len),
  2429. hex_string ((CORE_ADDR)di.u.ti.table_data));
  2430. }
  2431. else
  2432. {
  2433. ret = ia64_find_unwind_table (sec->objfile, ip, &di, &buf);
  2434. if (ret < 0)
  2435. return ret;
  2436. if (gdbarch_debug >= 1)
  2437. gdb_printf (gdb_stdlog, "ia64_find_proc_info_x: %s -> "
  2438. "(name=`%s',segbase=%s,start=%s,end=%s,gp=%s,"
  2439. "length=%s,data=%s)\n",
  2440. hex_string (ip), (char *)di.u.rti.name_ptr,
  2441. hex_string (di.u.rti.segbase),
  2442. hex_string (di.start_ip), hex_string (di.end_ip),
  2443. hex_string (di.gp),
  2444. pulongest (di.u.rti.table_len),
  2445. hex_string (di.u.rti.table_data));
  2446. }
  2447. ret = libunwind_search_unwind_table (&as, ip, &di, pi, need_unwind_info,
  2448. arg);
  2449. /* We no longer need the dyn info storage so free it. */
  2450. xfree (buf);
  2451. return ret;
  2452. }
  2453. /* Libunwind callback accessor function for cleanup. */
  2454. static void
  2455. ia64_put_unwind_info (unw_addr_space_t as,
  2456. unw_proc_info_t *pip, void *arg)
  2457. {
  2458. /* Nothing required for now. */
  2459. }
  2460. /* Libunwind callback accessor function to get head of the dynamic
  2461. unwind-info registration list. */
  2462. static int
  2463. ia64_get_dyn_info_list (unw_addr_space_t as,
  2464. unw_word_t *dilap, void *arg)
  2465. {
  2466. struct obj_section *text_sec;
  2467. unw_word_t ip, addr;
  2468. unw_dyn_info_t di;
  2469. int ret;
  2470. if (!libunwind_is_initialized ())
  2471. return -UNW_ENOINFO;
  2472. for (objfile *objfile : current_program_space->objfiles ())
  2473. {
  2474. void *buf = NULL;
  2475. text_sec = objfile->sections + SECT_OFF_TEXT (objfile);
  2476. ip = text_sec->addr ();
  2477. ret = ia64_find_unwind_table (objfile, ip, &di, &buf);
  2478. if (ret >= 0)
  2479. {
  2480. addr = libunwind_find_dyn_list (as, &di, arg);
  2481. /* We no longer need the dyn info storage so free it. */
  2482. xfree (buf);
  2483. if (addr)
  2484. {
  2485. if (gdbarch_debug >= 1)
  2486. gdb_printf (gdb_stdlog,
  2487. "dynamic unwind table in objfile %s "
  2488. "at %s (gp=%s)\n",
  2489. bfd_get_filename (objfile->obfd),
  2490. hex_string (addr), hex_string (di.gp));
  2491. *dilap = addr;
  2492. return 0;
  2493. }
  2494. }
  2495. }
  2496. return -UNW_ENOINFO;
  2497. }
  2498. /* Frame interface functions for libunwind. */
  2499. static void
  2500. ia64_libunwind_frame_this_id (struct frame_info *this_frame, void **this_cache,
  2501. struct frame_id *this_id)
  2502. {
  2503. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  2504. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  2505. struct frame_id id = outer_frame_id;
  2506. gdb_byte buf[8];
  2507. CORE_ADDR bsp;
  2508. libunwind_frame_this_id (this_frame, this_cache, &id);
  2509. if (frame_id_eq (id, outer_frame_id))
  2510. {
  2511. (*this_id) = outer_frame_id;
  2512. return;
  2513. }
  2514. /* We must add the bsp as the special address for frame comparison
  2515. purposes. */
  2516. get_frame_register (this_frame, IA64_BSP_REGNUM, buf);
  2517. bsp = extract_unsigned_integer (buf, 8, byte_order);
  2518. (*this_id) = frame_id_build_special (id.stack_addr, id.code_addr, bsp);
  2519. if (gdbarch_debug >= 1)
  2520. gdb_printf (gdb_stdlog,
  2521. "libunwind frame id: code %s, stack %s, "
  2522. "special %s, this_frame %s\n",
  2523. paddress (gdbarch, id.code_addr),
  2524. paddress (gdbarch, id.stack_addr),
  2525. paddress (gdbarch, bsp),
  2526. host_address_to_string (this_frame));
  2527. }
  2528. static struct value *
  2529. ia64_libunwind_frame_prev_register (struct frame_info *this_frame,
  2530. void **this_cache, int regnum)
  2531. {
  2532. int reg = regnum;
  2533. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  2534. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  2535. struct value *val;
  2536. if (VP0_REGNUM <= regnum && regnum <= VP63_REGNUM)
  2537. reg = IA64_PR_REGNUM;
  2538. else if (IA64_NAT0_REGNUM <= regnum && regnum <= IA64_NAT127_REGNUM)
  2539. reg = IA64_UNAT_REGNUM;
  2540. /* Let libunwind do most of the work. */
  2541. val = libunwind_frame_prev_register (this_frame, this_cache, reg);
  2542. if (VP0_REGNUM <= regnum && regnum <= VP63_REGNUM)
  2543. {
  2544. ULONGEST prN_val;
  2545. if (VP16_REGNUM <= regnum && regnum <= VP63_REGNUM)
  2546. {
  2547. int rrb_pr = 0;
  2548. ULONGEST cfm;
  2549. /* Fetch predicate register rename base from current frame
  2550. marker for this frame. */
  2551. cfm = get_frame_register_unsigned (this_frame, IA64_CFM_REGNUM);
  2552. rrb_pr = (cfm >> 32) & 0x3f;
  2553. /* Adjust the register number to account for register rotation. */
  2554. regnum = VP16_REGNUM + ((regnum - VP16_REGNUM) + rrb_pr) % 48;
  2555. }
  2556. prN_val = extract_bit_field (value_contents_all (val).data (),
  2557. regnum - VP0_REGNUM, 1);
  2558. return frame_unwind_got_constant (this_frame, regnum, prN_val);
  2559. }
  2560. else if (IA64_NAT0_REGNUM <= regnum && regnum <= IA64_NAT127_REGNUM)
  2561. {
  2562. ULONGEST unatN_val;
  2563. unatN_val = extract_bit_field (value_contents_all (val).data (),
  2564. regnum - IA64_NAT0_REGNUM, 1);
  2565. return frame_unwind_got_constant (this_frame, regnum, unatN_val);
  2566. }
  2567. else if (regnum == IA64_BSP_REGNUM)
  2568. {
  2569. struct value *cfm_val;
  2570. CORE_ADDR prev_bsp, prev_cfm;
  2571. /* We want to calculate the previous bsp as the end of the previous
  2572. register stack frame. This corresponds to what the hardware bsp
  2573. register will be if we pop the frame back which is why we might
  2574. have been called. We know that libunwind will pass us back the
  2575. beginning of the current frame so we should just add sof to it. */
  2576. prev_bsp = extract_unsigned_integer (value_contents_all (val).data (),
  2577. 8, byte_order);
  2578. cfm_val = libunwind_frame_prev_register (this_frame, this_cache,
  2579. IA64_CFM_REGNUM);
  2580. prev_cfm = extract_unsigned_integer (value_contents_all (cfm_val).data (),
  2581. 8, byte_order);
  2582. prev_bsp = rse_address_add (prev_bsp, (prev_cfm & 0x7f));
  2583. return frame_unwind_got_constant (this_frame, regnum, prev_bsp);
  2584. }
  2585. else
  2586. return val;
  2587. }
  2588. static int
  2589. ia64_libunwind_frame_sniffer (const struct frame_unwind *self,
  2590. struct frame_info *this_frame,
  2591. void **this_cache)
  2592. {
  2593. if (libunwind_is_initialized ()
  2594. && libunwind_frame_sniffer (self, this_frame, this_cache))
  2595. return 1;
  2596. return 0;
  2597. }
  2598. static const struct frame_unwind ia64_libunwind_frame_unwind =
  2599. {
  2600. "ia64 libunwind",
  2601. NORMAL_FRAME,
  2602. default_frame_unwind_stop_reason,
  2603. ia64_libunwind_frame_this_id,
  2604. ia64_libunwind_frame_prev_register,
  2605. NULL,
  2606. ia64_libunwind_frame_sniffer,
  2607. libunwind_frame_dealloc_cache
  2608. };
  2609. static void
  2610. ia64_libunwind_sigtramp_frame_this_id (struct frame_info *this_frame,
  2611. void **this_cache,
  2612. struct frame_id *this_id)
  2613. {
  2614. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  2615. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  2616. gdb_byte buf[8];
  2617. CORE_ADDR bsp;
  2618. struct frame_id id = outer_frame_id;
  2619. libunwind_frame_this_id (this_frame, this_cache, &id);
  2620. if (frame_id_eq (id, outer_frame_id))
  2621. {
  2622. (*this_id) = outer_frame_id;
  2623. return;
  2624. }
  2625. /* We must add the bsp as the special address for frame comparison
  2626. purposes. */
  2627. get_frame_register (this_frame, IA64_BSP_REGNUM, buf);
  2628. bsp = extract_unsigned_integer (buf, 8, byte_order);
  2629. /* For a sigtramp frame, we don't make the check for previous ip being 0. */
  2630. (*this_id) = frame_id_build_special (id.stack_addr, id.code_addr, bsp);
  2631. if (gdbarch_debug >= 1)
  2632. gdb_printf (gdb_stdlog,
  2633. "libunwind sigtramp frame id: code %s, "
  2634. "stack %s, special %s, this_frame %s\n",
  2635. paddress (gdbarch, id.code_addr),
  2636. paddress (gdbarch, id.stack_addr),
  2637. paddress (gdbarch, bsp),
  2638. host_address_to_string (this_frame));
  2639. }
  2640. static struct value *
  2641. ia64_libunwind_sigtramp_frame_prev_register (struct frame_info *this_frame,
  2642. void **this_cache, int regnum)
  2643. {
  2644. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  2645. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  2646. struct value *prev_ip_val;
  2647. CORE_ADDR prev_ip;
  2648. /* If the previous frame pc value is 0, then we want to use the SIGCONTEXT
  2649. method of getting previous registers. */
  2650. prev_ip_val = libunwind_frame_prev_register (this_frame, this_cache,
  2651. IA64_IP_REGNUM);
  2652. prev_ip = extract_unsigned_integer (value_contents_all (prev_ip_val).data (),
  2653. 8, byte_order);
  2654. if (prev_ip == 0)
  2655. {
  2656. void *tmp_cache = NULL;
  2657. return ia64_sigtramp_frame_prev_register (this_frame, &tmp_cache,
  2658. regnum);
  2659. }
  2660. else
  2661. return ia64_libunwind_frame_prev_register (this_frame, this_cache, regnum);
  2662. }
  2663. static int
  2664. ia64_libunwind_sigtramp_frame_sniffer (const struct frame_unwind *self,
  2665. struct frame_info *this_frame,
  2666. void **this_cache)
  2667. {
  2668. if (libunwind_is_initialized ())
  2669. {
  2670. if (libunwind_sigtramp_frame_sniffer (self, this_frame, this_cache))
  2671. return 1;
  2672. return 0;
  2673. }
  2674. else
  2675. return ia64_sigtramp_frame_sniffer (self, this_frame, this_cache);
  2676. }
  2677. static const struct frame_unwind ia64_libunwind_sigtramp_frame_unwind =
  2678. {
  2679. "ia64 libunwind sigtramp",
  2680. SIGTRAMP_FRAME,
  2681. default_frame_unwind_stop_reason,
  2682. ia64_libunwind_sigtramp_frame_this_id,
  2683. ia64_libunwind_sigtramp_frame_prev_register,
  2684. NULL,
  2685. ia64_libunwind_sigtramp_frame_sniffer
  2686. };
  2687. /* Set of libunwind callback acccessor functions. */
  2688. unw_accessors_t ia64_unw_accessors =
  2689. {
  2690. ia64_find_proc_info_x,
  2691. ia64_put_unwind_info,
  2692. ia64_get_dyn_info_list,
  2693. ia64_access_mem,
  2694. ia64_access_reg,
  2695. ia64_access_fpreg,
  2696. /* resume */
  2697. /* get_proc_name */
  2698. };
  2699. /* Set of special libunwind callback acccessor functions specific for accessing
  2700. the rse registers. At the top of the stack, we want libunwind to figure out
  2701. how to read r32 - r127. Though usually they are found sequentially in
  2702. memory starting from $bof, this is not always true. */
  2703. unw_accessors_t ia64_unw_rse_accessors =
  2704. {
  2705. ia64_find_proc_info_x,
  2706. ia64_put_unwind_info,
  2707. ia64_get_dyn_info_list,
  2708. ia64_access_mem,
  2709. ia64_access_rse_reg,
  2710. ia64_access_rse_fpreg,
  2711. /* resume */
  2712. /* get_proc_name */
  2713. };
  2714. /* Set of ia64-libunwind-tdep gdb callbacks and data for generic
  2715. ia64-libunwind-tdep code to use. */
  2716. struct libunwind_descr ia64_libunwind_descr =
  2717. {
  2718. ia64_gdb2uw_regnum,
  2719. ia64_uw2gdb_regnum,
  2720. ia64_is_fpreg,
  2721. &ia64_unw_accessors,
  2722. &ia64_unw_rse_accessors,
  2723. };
  2724. #endif /* HAVE_LIBUNWIND_IA64_H */
  2725. static int
  2726. ia64_use_struct_convention (struct type *type)
  2727. {
  2728. struct type *float_elt_type;
  2729. /* Don't use the struct convention for anything but structure,
  2730. union, or array types. */
  2731. if (!(type->code () == TYPE_CODE_STRUCT
  2732. || type->code () == TYPE_CODE_UNION
  2733. || type->code () == TYPE_CODE_ARRAY))
  2734. return 0;
  2735. /* HFAs are structures (or arrays) consisting entirely of floating
  2736. point values of the same length. Up to 8 of these are returned
  2737. in registers. Don't use the struct convention when this is the
  2738. case. */
  2739. float_elt_type = is_float_or_hfa_type (type);
  2740. if (float_elt_type != NULL
  2741. && TYPE_LENGTH (type) / TYPE_LENGTH (float_elt_type) <= 8)
  2742. return 0;
  2743. /* Other structs of length 32 or less are returned in r8-r11.
  2744. Don't use the struct convention for those either. */
  2745. return TYPE_LENGTH (type) > 32;
  2746. }
  2747. /* Return non-zero if TYPE is a structure or union type. */
  2748. static int
  2749. ia64_struct_type_p (const struct type *type)
  2750. {
  2751. return (type->code () == TYPE_CODE_STRUCT
  2752. || type->code () == TYPE_CODE_UNION);
  2753. }
  2754. static void
  2755. ia64_extract_return_value (struct type *type, struct regcache *regcache,
  2756. gdb_byte *valbuf)
  2757. {
  2758. struct gdbarch *gdbarch = regcache->arch ();
  2759. struct type *float_elt_type;
  2760. float_elt_type = is_float_or_hfa_type (type);
  2761. if (float_elt_type != NULL)
  2762. {
  2763. gdb_byte from[IA64_FP_REGISTER_SIZE];
  2764. int offset = 0;
  2765. int regnum = IA64_FR8_REGNUM;
  2766. int n = TYPE_LENGTH (type) / TYPE_LENGTH (float_elt_type);
  2767. while (n-- > 0)
  2768. {
  2769. regcache->cooked_read (regnum, from);
  2770. target_float_convert (from, ia64_ext_type (gdbarch),
  2771. valbuf + offset, float_elt_type);
  2772. offset += TYPE_LENGTH (float_elt_type);
  2773. regnum++;
  2774. }
  2775. }
  2776. else if (!ia64_struct_type_p (type) && TYPE_LENGTH (type) < 8)
  2777. {
  2778. /* This is an integral value, and its size is less than 8 bytes.
  2779. These values are LSB-aligned, so extract the relevant bytes,
  2780. and copy them into VALBUF. */
  2781. /* brobecker/2005-12-30: Actually, all integral values are LSB aligned,
  2782. so I suppose we should also add handling here for integral values
  2783. whose size is greater than 8. But I wasn't able to create such
  2784. a type, neither in C nor in Ada, so not worrying about these yet. */
  2785. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  2786. ULONGEST val;
  2787. regcache_cooked_read_unsigned (regcache, IA64_GR8_REGNUM, &val);
  2788. store_unsigned_integer (valbuf, TYPE_LENGTH (type), byte_order, val);
  2789. }
  2790. else
  2791. {
  2792. ULONGEST val;
  2793. int offset = 0;
  2794. int regnum = IA64_GR8_REGNUM;
  2795. int reglen = TYPE_LENGTH (register_type (gdbarch, IA64_GR8_REGNUM));
  2796. int n = TYPE_LENGTH (type) / reglen;
  2797. int m = TYPE_LENGTH (type) % reglen;
  2798. while (n-- > 0)
  2799. {
  2800. ULONGEST regval;
  2801. regcache_cooked_read_unsigned (regcache, regnum, &regval);
  2802. memcpy ((char *)valbuf + offset, &regval, reglen);
  2803. offset += reglen;
  2804. regnum++;
  2805. }
  2806. if (m)
  2807. {
  2808. regcache_cooked_read_unsigned (regcache, regnum, &val);
  2809. memcpy ((char *)valbuf + offset, &val, m);
  2810. }
  2811. }
  2812. }
  2813. static void
  2814. ia64_store_return_value (struct type *type, struct regcache *regcache,
  2815. const gdb_byte *valbuf)
  2816. {
  2817. struct gdbarch *gdbarch = regcache->arch ();
  2818. struct type *float_elt_type;
  2819. float_elt_type = is_float_or_hfa_type (type);
  2820. if (float_elt_type != NULL)
  2821. {
  2822. gdb_byte to[IA64_FP_REGISTER_SIZE];
  2823. int offset = 0;
  2824. int regnum = IA64_FR8_REGNUM;
  2825. int n = TYPE_LENGTH (type) / TYPE_LENGTH (float_elt_type);
  2826. while (n-- > 0)
  2827. {
  2828. target_float_convert (valbuf + offset, float_elt_type,
  2829. to, ia64_ext_type (gdbarch));
  2830. regcache->cooked_write (regnum, to);
  2831. offset += TYPE_LENGTH (float_elt_type);
  2832. regnum++;
  2833. }
  2834. }
  2835. else
  2836. {
  2837. int offset = 0;
  2838. int regnum = IA64_GR8_REGNUM;
  2839. int reglen = TYPE_LENGTH (register_type (gdbarch, IA64_GR8_REGNUM));
  2840. int n = TYPE_LENGTH (type) / reglen;
  2841. int m = TYPE_LENGTH (type) % reglen;
  2842. while (n-- > 0)
  2843. {
  2844. ULONGEST val;
  2845. memcpy (&val, (char *)valbuf + offset, reglen);
  2846. regcache_cooked_write_unsigned (regcache, regnum, val);
  2847. offset += reglen;
  2848. regnum++;
  2849. }
  2850. if (m)
  2851. {
  2852. ULONGEST val;
  2853. memcpy (&val, (char *)valbuf + offset, m);
  2854. regcache_cooked_write_unsigned (regcache, regnum, val);
  2855. }
  2856. }
  2857. }
  2858. static enum return_value_convention
  2859. ia64_return_value (struct gdbarch *gdbarch, struct value *function,
  2860. struct type *valtype, struct regcache *regcache,
  2861. gdb_byte *readbuf, const gdb_byte *writebuf)
  2862. {
  2863. int struct_return = ia64_use_struct_convention (valtype);
  2864. if (writebuf != NULL)
  2865. {
  2866. gdb_assert (!struct_return);
  2867. ia64_store_return_value (valtype, regcache, writebuf);
  2868. }
  2869. if (readbuf != NULL)
  2870. {
  2871. gdb_assert (!struct_return);
  2872. ia64_extract_return_value (valtype, regcache, readbuf);
  2873. }
  2874. if (struct_return)
  2875. return RETURN_VALUE_STRUCT_CONVENTION;
  2876. else
  2877. return RETURN_VALUE_REGISTER_CONVENTION;
  2878. }
  2879. static int
  2880. is_float_or_hfa_type_recurse (struct type *t, struct type **etp)
  2881. {
  2882. switch (t->code ())
  2883. {
  2884. case TYPE_CODE_FLT:
  2885. if (*etp)
  2886. return TYPE_LENGTH (*etp) == TYPE_LENGTH (t);
  2887. else
  2888. {
  2889. *etp = t;
  2890. return 1;
  2891. }
  2892. break;
  2893. case TYPE_CODE_ARRAY:
  2894. return
  2895. is_float_or_hfa_type_recurse (check_typedef (TYPE_TARGET_TYPE (t)),
  2896. etp);
  2897. break;
  2898. case TYPE_CODE_STRUCT:
  2899. {
  2900. int i;
  2901. for (i = 0; i < t->num_fields (); i++)
  2902. if (!is_float_or_hfa_type_recurse
  2903. (check_typedef (t->field (i).type ()), etp))
  2904. return 0;
  2905. return 1;
  2906. }
  2907. break;
  2908. default:
  2909. return 0;
  2910. break;
  2911. }
  2912. }
  2913. /* Determine if the given type is one of the floating point types or
  2914. and HFA (which is a struct, array, or combination thereof whose
  2915. bottom-most elements are all of the same floating point type). */
  2916. static struct type *
  2917. is_float_or_hfa_type (struct type *t)
  2918. {
  2919. struct type *et = 0;
  2920. return is_float_or_hfa_type_recurse (t, &et) ? et : 0;
  2921. }
  2922. /* Return 1 if the alignment of T is such that the next even slot
  2923. should be used. Return 0, if the next available slot should
  2924. be used. (See section 8.5.1 of the IA-64 Software Conventions
  2925. and Runtime manual). */
  2926. static int
  2927. slot_alignment_is_next_even (struct type *t)
  2928. {
  2929. switch (t->code ())
  2930. {
  2931. case TYPE_CODE_INT:
  2932. case TYPE_CODE_FLT:
  2933. if (TYPE_LENGTH (t) > 8)
  2934. return 1;
  2935. else
  2936. return 0;
  2937. case TYPE_CODE_ARRAY:
  2938. return
  2939. slot_alignment_is_next_even (check_typedef (TYPE_TARGET_TYPE (t)));
  2940. case TYPE_CODE_STRUCT:
  2941. {
  2942. int i;
  2943. for (i = 0; i < t->num_fields (); i++)
  2944. if (slot_alignment_is_next_even
  2945. (check_typedef (t->field (i).type ())))
  2946. return 1;
  2947. return 0;
  2948. }
  2949. default:
  2950. return 0;
  2951. }
  2952. }
  2953. /* Attempt to find (and return) the global pointer for the given
  2954. function.
  2955. This is a rather nasty bit of code searchs for the .dynamic section
  2956. in the objfile corresponding to the pc of the function we're trying
  2957. to call. Once it finds the addresses at which the .dynamic section
  2958. lives in the child process, it scans the Elf64_Dyn entries for a
  2959. DT_PLTGOT tag. If it finds one of these, the corresponding
  2960. d_un.d_ptr value is the global pointer. */
  2961. static CORE_ADDR
  2962. ia64_find_global_pointer_from_dynamic_section (struct gdbarch *gdbarch,
  2963. CORE_ADDR faddr)
  2964. {
  2965. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  2966. struct obj_section *faddr_sect;
  2967. faddr_sect = find_pc_section (faddr);
  2968. if (faddr_sect != NULL)
  2969. {
  2970. struct obj_section *osect;
  2971. ALL_OBJFILE_OSECTIONS (faddr_sect->objfile, osect)
  2972. {
  2973. if (strcmp (osect->the_bfd_section->name, ".dynamic") == 0)
  2974. break;
  2975. }
  2976. if (osect < faddr_sect->objfile->sections_end)
  2977. {
  2978. CORE_ADDR addr = osect->addr ();
  2979. CORE_ADDR endaddr = osect->endaddr ();
  2980. while (addr < endaddr)
  2981. {
  2982. int status;
  2983. LONGEST tag;
  2984. gdb_byte buf[8];
  2985. status = target_read_memory (addr, buf, sizeof (buf));
  2986. if (status != 0)
  2987. break;
  2988. tag = extract_signed_integer (buf, byte_order);
  2989. if (tag == DT_PLTGOT)
  2990. {
  2991. CORE_ADDR global_pointer;
  2992. status = target_read_memory (addr + 8, buf, sizeof (buf));
  2993. if (status != 0)
  2994. break;
  2995. global_pointer = extract_unsigned_integer (buf, sizeof (buf),
  2996. byte_order);
  2997. /* The payoff... */
  2998. return global_pointer;
  2999. }
  3000. if (tag == DT_NULL)
  3001. break;
  3002. addr += 16;
  3003. }
  3004. }
  3005. }
  3006. return 0;
  3007. }
  3008. /* Attempt to find (and return) the global pointer for the given
  3009. function. We first try the find_global_pointer_from_solib routine
  3010. from the gdbarch tdep vector, if provided. And if that does not
  3011. work, then we try ia64_find_global_pointer_from_dynamic_section. */
  3012. static CORE_ADDR
  3013. ia64_find_global_pointer (struct gdbarch *gdbarch, CORE_ADDR faddr)
  3014. {
  3015. ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  3016. CORE_ADDR addr = 0;
  3017. if (tdep->find_global_pointer_from_solib)
  3018. addr = tdep->find_global_pointer_from_solib (gdbarch, faddr);
  3019. if (addr == 0)
  3020. addr = ia64_find_global_pointer_from_dynamic_section (gdbarch, faddr);
  3021. return addr;
  3022. }
  3023. /* Given a function's address, attempt to find (and return) the
  3024. corresponding (canonical) function descriptor. Return 0 if
  3025. not found. */
  3026. static CORE_ADDR
  3027. find_extant_func_descr (struct gdbarch *gdbarch, CORE_ADDR faddr)
  3028. {
  3029. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  3030. struct obj_section *faddr_sect;
  3031. /* Return early if faddr is already a function descriptor. */
  3032. faddr_sect = find_pc_section (faddr);
  3033. if (faddr_sect && strcmp (faddr_sect->the_bfd_section->name, ".opd") == 0)
  3034. return faddr;
  3035. if (faddr_sect != NULL)
  3036. {
  3037. struct obj_section *osect;
  3038. ALL_OBJFILE_OSECTIONS (faddr_sect->objfile, osect)
  3039. {
  3040. if (strcmp (osect->the_bfd_section->name, ".opd") == 0)
  3041. break;
  3042. }
  3043. if (osect < faddr_sect->objfile->sections_end)
  3044. {
  3045. CORE_ADDR addr = osect->addr ();
  3046. CORE_ADDR endaddr = osect->endaddr ();
  3047. while (addr < endaddr)
  3048. {
  3049. int status;
  3050. LONGEST faddr2;
  3051. gdb_byte buf[8];
  3052. status = target_read_memory (addr, buf, sizeof (buf));
  3053. if (status != 0)
  3054. break;
  3055. faddr2 = extract_signed_integer (buf, byte_order);
  3056. if (faddr == faddr2)
  3057. return addr;
  3058. addr += 16;
  3059. }
  3060. }
  3061. }
  3062. return 0;
  3063. }
  3064. /* Attempt to find a function descriptor corresponding to the
  3065. given address. If none is found, construct one on the
  3066. stack using the address at fdaptr. */
  3067. static CORE_ADDR
  3068. find_func_descr (struct regcache *regcache, CORE_ADDR faddr, CORE_ADDR *fdaptr)
  3069. {
  3070. struct gdbarch *gdbarch = regcache->arch ();
  3071. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  3072. CORE_ADDR fdesc;
  3073. fdesc = find_extant_func_descr (gdbarch, faddr);
  3074. if (fdesc == 0)
  3075. {
  3076. ULONGEST global_pointer;
  3077. gdb_byte buf[16];
  3078. fdesc = *fdaptr;
  3079. *fdaptr += 16;
  3080. global_pointer = ia64_find_global_pointer (gdbarch, faddr);
  3081. if (global_pointer == 0)
  3082. regcache_cooked_read_unsigned (regcache,
  3083. IA64_GR1_REGNUM, &global_pointer);
  3084. store_unsigned_integer (buf, 8, byte_order, faddr);
  3085. store_unsigned_integer (buf + 8, 8, byte_order, global_pointer);
  3086. write_memory (fdesc, buf, 16);
  3087. }
  3088. return fdesc;
  3089. }
  3090. /* Use the following routine when printing out function pointers
  3091. so the user can see the function address rather than just the
  3092. function descriptor. */
  3093. static CORE_ADDR
  3094. ia64_convert_from_func_ptr_addr (struct gdbarch *gdbarch, CORE_ADDR addr,
  3095. struct target_ops *targ)
  3096. {
  3097. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  3098. struct obj_section *s;
  3099. gdb_byte buf[8];
  3100. s = find_pc_section (addr);
  3101. /* check if ADDR points to a function descriptor. */
  3102. if (s && strcmp (s->the_bfd_section->name, ".opd") == 0)
  3103. return read_memory_unsigned_integer (addr, 8, byte_order);
  3104. /* Normally, functions live inside a section that is executable.
  3105. So, if ADDR points to a non-executable section, then treat it
  3106. as a function descriptor and return the target address iff
  3107. the target address itself points to a section that is executable.
  3108. Check first the memory of the whole length of 8 bytes is readable. */
  3109. if (s && (s->the_bfd_section->flags & SEC_CODE) == 0
  3110. && target_read_memory (addr, buf, 8) == 0)
  3111. {
  3112. CORE_ADDR pc = extract_unsigned_integer (buf, 8, byte_order);
  3113. struct obj_section *pc_section = find_pc_section (pc);
  3114. if (pc_section && (pc_section->the_bfd_section->flags & SEC_CODE))
  3115. return pc;
  3116. }
  3117. /* There are also descriptors embedded in vtables. */
  3118. if (s)
  3119. {
  3120. struct bound_minimal_symbol minsym;
  3121. minsym = lookup_minimal_symbol_by_pc (addr);
  3122. if (minsym.minsym
  3123. && is_vtable_name (minsym.minsym->linkage_name ()))
  3124. return read_memory_unsigned_integer (addr, 8, byte_order);
  3125. }
  3126. return addr;
  3127. }
  3128. static CORE_ADDR
  3129. ia64_frame_align (struct gdbarch *gdbarch, CORE_ADDR sp)
  3130. {
  3131. return sp & ~0xfLL;
  3132. }
  3133. /* The default "allocate_new_rse_frame" ia64_infcall_ops routine for ia64. */
  3134. static void
  3135. ia64_allocate_new_rse_frame (struct regcache *regcache, ULONGEST bsp, int sof)
  3136. {
  3137. ULONGEST cfm, pfs, new_bsp;
  3138. regcache_cooked_read_unsigned (regcache, IA64_CFM_REGNUM, &cfm);
  3139. new_bsp = rse_address_add (bsp, sof);
  3140. regcache_cooked_write_unsigned (regcache, IA64_BSP_REGNUM, new_bsp);
  3141. regcache_cooked_read_unsigned (regcache, IA64_PFS_REGNUM, &pfs);
  3142. pfs &= 0xc000000000000000LL;
  3143. pfs |= (cfm & 0xffffffffffffLL);
  3144. regcache_cooked_write_unsigned (regcache, IA64_PFS_REGNUM, pfs);
  3145. cfm &= 0xc000000000000000LL;
  3146. cfm |= sof;
  3147. regcache_cooked_write_unsigned (regcache, IA64_CFM_REGNUM, cfm);
  3148. }
  3149. /* The default "store_argument_in_slot" ia64_infcall_ops routine for
  3150. ia64. */
  3151. static void
  3152. ia64_store_argument_in_slot (struct regcache *regcache, CORE_ADDR bsp,
  3153. int slotnum, gdb_byte *buf)
  3154. {
  3155. write_memory (rse_address_add (bsp, slotnum), buf, 8);
  3156. }
  3157. /* The default "set_function_addr" ia64_infcall_ops routine for ia64. */
  3158. static void
  3159. ia64_set_function_addr (struct regcache *regcache, CORE_ADDR func_addr)
  3160. {
  3161. /* Nothing needed. */
  3162. }
  3163. static CORE_ADDR
  3164. ia64_push_dummy_call (struct gdbarch *gdbarch, struct value *function,
  3165. struct regcache *regcache, CORE_ADDR bp_addr,
  3166. int nargs, struct value **args, CORE_ADDR sp,
  3167. function_call_return_method return_method,
  3168. CORE_ADDR struct_addr)
  3169. {
  3170. ia64_gdbarch_tdep *tdep = (ia64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  3171. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  3172. int argno;
  3173. struct value *arg;
  3174. struct type *type;
  3175. int len, argoffset;
  3176. int nslots, rseslots, memslots, slotnum, nfuncargs;
  3177. int floatreg;
  3178. ULONGEST bsp;
  3179. CORE_ADDR funcdescaddr, global_pointer;
  3180. CORE_ADDR func_addr = find_function_addr (function, NULL);
  3181. nslots = 0;
  3182. nfuncargs = 0;
  3183. /* Count the number of slots needed for the arguments. */
  3184. for (argno = 0; argno < nargs; argno++)
  3185. {
  3186. arg = args[argno];
  3187. type = check_typedef (value_type (arg));
  3188. len = TYPE_LENGTH (type);
  3189. if ((nslots & 1) && slot_alignment_is_next_even (type))
  3190. nslots++;
  3191. if (type->code () == TYPE_CODE_FUNC)
  3192. nfuncargs++;
  3193. nslots += (len + 7) / 8;
  3194. }
  3195. /* Divvy up the slots between the RSE and the memory stack. */
  3196. rseslots = (nslots > 8) ? 8 : nslots;
  3197. memslots = nslots - rseslots;
  3198. /* Allocate a new RSE frame. */
  3199. regcache_cooked_read_unsigned (regcache, IA64_BSP_REGNUM, &bsp);
  3200. tdep->infcall_ops.allocate_new_rse_frame (regcache, bsp, rseslots);
  3201. /* We will attempt to find function descriptors in the .opd segment,
  3202. but if we can't we'll construct them ourselves. That being the
  3203. case, we'll need to reserve space on the stack for them. */
  3204. funcdescaddr = sp - nfuncargs * 16;
  3205. funcdescaddr &= ~0xfLL;
  3206. /* Adjust the stack pointer to it's new value. The calling conventions
  3207. require us to have 16 bytes of scratch, plus whatever space is
  3208. necessary for the memory slots and our function descriptors. */
  3209. sp = sp - 16 - (memslots + nfuncargs) * 8;
  3210. sp &= ~0xfLL; /* Maintain 16 byte alignment. */
  3211. /* Place the arguments where they belong. The arguments will be
  3212. either placed in the RSE backing store or on the memory stack.
  3213. In addition, floating point arguments or HFAs are placed in
  3214. floating point registers. */
  3215. slotnum = 0;
  3216. floatreg = IA64_FR8_REGNUM;
  3217. for (argno = 0; argno < nargs; argno++)
  3218. {
  3219. struct type *float_elt_type;
  3220. arg = args[argno];
  3221. type = check_typedef (value_type (arg));
  3222. len = TYPE_LENGTH (type);
  3223. /* Special handling for function parameters. */
  3224. if (len == 8
  3225. && type->code () == TYPE_CODE_PTR
  3226. && TYPE_TARGET_TYPE (type)->code () == TYPE_CODE_FUNC)
  3227. {
  3228. gdb_byte val_buf[8];
  3229. ULONGEST faddr = extract_unsigned_integer
  3230. (value_contents (arg).data (), 8, byte_order);
  3231. store_unsigned_integer (val_buf, 8, byte_order,
  3232. find_func_descr (regcache, faddr,
  3233. &funcdescaddr));
  3234. if (slotnum < rseslots)
  3235. tdep->infcall_ops.store_argument_in_slot (regcache, bsp,
  3236. slotnum, val_buf);
  3237. else
  3238. write_memory (sp + 16 + 8 * (slotnum - rseslots), val_buf, 8);
  3239. slotnum++;
  3240. continue;
  3241. }
  3242. /* Normal slots. */
  3243. /* Skip odd slot if necessary... */
  3244. if ((slotnum & 1) && slot_alignment_is_next_even (type))
  3245. slotnum++;
  3246. argoffset = 0;
  3247. while (len > 0)
  3248. {
  3249. gdb_byte val_buf[8];
  3250. memset (val_buf, 0, 8);
  3251. if (!ia64_struct_type_p (type) && len < 8)
  3252. {
  3253. /* Integral types are LSB-aligned, so we have to be careful
  3254. to insert the argument on the correct side of the buffer.
  3255. This is why we use store_unsigned_integer. */
  3256. store_unsigned_integer
  3257. (val_buf, 8, byte_order,
  3258. extract_unsigned_integer (value_contents (arg).data (), len,
  3259. byte_order));
  3260. }
  3261. else
  3262. {
  3263. /* This is either an 8bit integral type, or an aggregate.
  3264. For 8bit integral type, there is no problem, we just
  3265. copy the value over.
  3266. For aggregates, the only potentially tricky portion
  3267. is to write the last one if it is less than 8 bytes.
  3268. In this case, the data is Byte0-aligned. Happy news,
  3269. this means that we don't need to differentiate the
  3270. handling of 8byte blocks and less-than-8bytes blocks. */
  3271. memcpy (val_buf, value_contents (arg).data () + argoffset,
  3272. (len > 8) ? 8 : len);
  3273. }
  3274. if (slotnum < rseslots)
  3275. tdep->infcall_ops.store_argument_in_slot (regcache, bsp,
  3276. slotnum, val_buf);
  3277. else
  3278. write_memory (sp + 16 + 8 * (slotnum - rseslots), val_buf, 8);
  3279. argoffset += 8;
  3280. len -= 8;
  3281. slotnum++;
  3282. }
  3283. /* Handle floating point types (including HFAs). */
  3284. float_elt_type = is_float_or_hfa_type (type);
  3285. if (float_elt_type != NULL)
  3286. {
  3287. argoffset = 0;
  3288. len = TYPE_LENGTH (type);
  3289. while (len > 0 && floatreg < IA64_FR16_REGNUM)
  3290. {
  3291. gdb_byte to[IA64_FP_REGISTER_SIZE];
  3292. target_float_convert (value_contents (arg).data () + argoffset,
  3293. float_elt_type, to,
  3294. ia64_ext_type (gdbarch));
  3295. regcache->cooked_write (floatreg, to);
  3296. floatreg++;
  3297. argoffset += TYPE_LENGTH (float_elt_type);
  3298. len -= TYPE_LENGTH (float_elt_type);
  3299. }
  3300. }
  3301. }
  3302. /* Store the struct return value in r8 if necessary. */
  3303. if (return_method == return_method_struct)
  3304. regcache_cooked_write_unsigned (regcache, IA64_GR8_REGNUM,
  3305. (ULONGEST) struct_addr);
  3306. global_pointer = ia64_find_global_pointer (gdbarch, func_addr);
  3307. if (global_pointer != 0)
  3308. regcache_cooked_write_unsigned (regcache, IA64_GR1_REGNUM, global_pointer);
  3309. /* The following is not necessary on HP-UX, because we're using
  3310. a dummy code sequence pushed on the stack to make the call, and
  3311. this sequence doesn't need b0 to be set in order for our dummy
  3312. breakpoint to be hit. Nonetheless, this doesn't interfere, and
  3313. it's needed for other OSes, so we do this unconditionaly. */
  3314. regcache_cooked_write_unsigned (regcache, IA64_BR0_REGNUM, bp_addr);
  3315. regcache_cooked_write_unsigned (regcache, sp_regnum, sp);
  3316. tdep->infcall_ops.set_function_addr (regcache, func_addr);
  3317. return sp;
  3318. }
  3319. static const struct ia64_infcall_ops ia64_infcall_ops =
  3320. {
  3321. ia64_allocate_new_rse_frame,
  3322. ia64_store_argument_in_slot,
  3323. ia64_set_function_addr
  3324. };
  3325. static struct frame_id
  3326. ia64_dummy_id (struct gdbarch *gdbarch, struct frame_info *this_frame)
  3327. {
  3328. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  3329. gdb_byte buf[8];
  3330. CORE_ADDR sp, bsp;
  3331. get_frame_register (this_frame, sp_regnum, buf);
  3332. sp = extract_unsigned_integer (buf, 8, byte_order);
  3333. get_frame_register (this_frame, IA64_BSP_REGNUM, buf);
  3334. bsp = extract_unsigned_integer (buf, 8, byte_order);
  3335. if (gdbarch_debug >= 1)
  3336. gdb_printf (gdb_stdlog,
  3337. "dummy frame id: code %s, stack %s, special %s\n",
  3338. paddress (gdbarch, get_frame_pc (this_frame)),
  3339. paddress (gdbarch, sp), paddress (gdbarch, bsp));
  3340. return frame_id_build_special (sp, get_frame_pc (this_frame), bsp);
  3341. }
  3342. static CORE_ADDR
  3343. ia64_unwind_pc (struct gdbarch *gdbarch, struct frame_info *next_frame)
  3344. {
  3345. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  3346. gdb_byte buf[8];
  3347. CORE_ADDR ip, psr, pc;
  3348. frame_unwind_register (next_frame, IA64_IP_REGNUM, buf);
  3349. ip = extract_unsigned_integer (buf, 8, byte_order);
  3350. frame_unwind_register (next_frame, IA64_PSR_REGNUM, buf);
  3351. psr = extract_unsigned_integer (buf, 8, byte_order);
  3352. pc = (ip & ~0xf) | ((psr >> 41) & 3);
  3353. return pc;
  3354. }
  3355. static int
  3356. ia64_print_insn (bfd_vma memaddr, struct disassemble_info *info)
  3357. {
  3358. info->bytes_per_line = SLOT_MULTIPLIER;
  3359. return default_print_insn (memaddr, info);
  3360. }
  3361. /* The default "size_of_register_frame" gdbarch_tdep routine for ia64. */
  3362. static int
  3363. ia64_size_of_register_frame (struct frame_info *this_frame, ULONGEST cfm)
  3364. {
  3365. return (cfm & 0x7f);
  3366. }
  3367. static struct gdbarch *
  3368. ia64_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
  3369. {
  3370. struct gdbarch *gdbarch;
  3371. /* If there is already a candidate, use it. */
  3372. arches = gdbarch_list_lookup_by_info (arches, &info);
  3373. if (arches != NULL)
  3374. return arches->gdbarch;
  3375. ia64_gdbarch_tdep *tdep = new ia64_gdbarch_tdep;
  3376. gdbarch = gdbarch_alloc (&info, tdep);
  3377. tdep->size_of_register_frame = ia64_size_of_register_frame;
  3378. /* According to the ia64 specs, instructions that store long double
  3379. floats in memory use a long-double format different than that
  3380. used in the floating registers. The memory format matches the
  3381. x86 extended float format which is 80 bits. An OS may choose to
  3382. use this format (e.g. GNU/Linux) or choose to use a different
  3383. format for storing long doubles (e.g. HPUX). In the latter case,
  3384. the setting of the format may be moved/overridden in an
  3385. OS-specific tdep file. */
  3386. set_gdbarch_long_double_format (gdbarch, floatformats_i387_ext);
  3387. set_gdbarch_short_bit (gdbarch, 16);
  3388. set_gdbarch_int_bit (gdbarch, 32);
  3389. set_gdbarch_long_bit (gdbarch, 64);
  3390. set_gdbarch_long_long_bit (gdbarch, 64);
  3391. set_gdbarch_float_bit (gdbarch, 32);
  3392. set_gdbarch_double_bit (gdbarch, 64);
  3393. set_gdbarch_long_double_bit (gdbarch, 128);
  3394. set_gdbarch_ptr_bit (gdbarch, 64);
  3395. set_gdbarch_num_regs (gdbarch, NUM_IA64_RAW_REGS);
  3396. set_gdbarch_num_pseudo_regs (gdbarch,
  3397. LAST_PSEUDO_REGNUM - FIRST_PSEUDO_REGNUM);
  3398. set_gdbarch_sp_regnum (gdbarch, sp_regnum);
  3399. set_gdbarch_fp0_regnum (gdbarch, IA64_FR0_REGNUM);
  3400. set_gdbarch_register_name (gdbarch, ia64_register_name);
  3401. set_gdbarch_register_type (gdbarch, ia64_register_type);
  3402. set_gdbarch_pseudo_register_read (gdbarch, ia64_pseudo_register_read);
  3403. set_gdbarch_pseudo_register_write (gdbarch, ia64_pseudo_register_write);
  3404. set_gdbarch_dwarf2_reg_to_regnum (gdbarch, ia64_dwarf_reg_to_regnum);
  3405. set_gdbarch_register_reggroup_p (gdbarch, ia64_register_reggroup_p);
  3406. set_gdbarch_convert_register_p (gdbarch, ia64_convert_register_p);
  3407. set_gdbarch_register_to_value (gdbarch, ia64_register_to_value);
  3408. set_gdbarch_value_to_register (gdbarch, ia64_value_to_register);
  3409. set_gdbarch_skip_prologue (gdbarch, ia64_skip_prologue);
  3410. set_gdbarch_return_value (gdbarch, ia64_return_value);
  3411. set_gdbarch_memory_insert_breakpoint (gdbarch,
  3412. ia64_memory_insert_breakpoint);
  3413. set_gdbarch_memory_remove_breakpoint (gdbarch,
  3414. ia64_memory_remove_breakpoint);
  3415. set_gdbarch_breakpoint_from_pc (gdbarch, ia64_breakpoint_from_pc);
  3416. set_gdbarch_breakpoint_kind_from_pc (gdbarch, ia64_breakpoint_kind_from_pc);
  3417. set_gdbarch_read_pc (gdbarch, ia64_read_pc);
  3418. set_gdbarch_write_pc (gdbarch, ia64_write_pc);
  3419. /* Settings for calling functions in the inferior. */
  3420. set_gdbarch_push_dummy_call (gdbarch, ia64_push_dummy_call);
  3421. tdep->infcall_ops = ia64_infcall_ops;
  3422. set_gdbarch_frame_align (gdbarch, ia64_frame_align);
  3423. set_gdbarch_dummy_id (gdbarch, ia64_dummy_id);
  3424. set_gdbarch_unwind_pc (gdbarch, ia64_unwind_pc);
  3425. #ifdef HAVE_LIBUNWIND_IA64_H
  3426. frame_unwind_append_unwinder (gdbarch,
  3427. &ia64_libunwind_sigtramp_frame_unwind);
  3428. frame_unwind_append_unwinder (gdbarch, &ia64_libunwind_frame_unwind);
  3429. frame_unwind_append_unwinder (gdbarch, &ia64_sigtramp_frame_unwind);
  3430. libunwind_frame_set_descr (gdbarch, &ia64_libunwind_descr);
  3431. #else
  3432. frame_unwind_append_unwinder (gdbarch, &ia64_sigtramp_frame_unwind);
  3433. #endif
  3434. frame_unwind_append_unwinder (gdbarch, &ia64_frame_unwind);
  3435. frame_base_set_default (gdbarch, &ia64_frame_base);
  3436. /* Settings that should be unnecessary. */
  3437. set_gdbarch_inner_than (gdbarch, core_addr_lessthan);
  3438. set_gdbarch_print_insn (gdbarch, ia64_print_insn);
  3439. set_gdbarch_convert_from_func_ptr_addr (gdbarch,
  3440. ia64_convert_from_func_ptr_addr);
  3441. /* The virtual table contains 16-byte descriptors, not pointers to
  3442. descriptors. */
  3443. set_gdbarch_vtable_function_descriptors (gdbarch, 1);
  3444. /* Hook in ABI-specific overrides, if they have been registered. */
  3445. gdbarch_init_osabi (info, gdbarch);
  3446. return gdbarch;
  3447. }
  3448. void _initialize_ia64_tdep ();
  3449. void
  3450. _initialize_ia64_tdep ()
  3451. {
  3452. gdbarch_register (bfd_arch_ia64, ia64_gdbarch_init, NULL);
  3453. }