ppc-linux-tdep.c 71 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251
  1. /* Target-dependent code for GDB, the GNU debugger.
  2. Copyright (C) 1986-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 "frame.h"
  16. #include "inferior.h"
  17. #include "symtab.h"
  18. #include "target.h"
  19. #include "gdbcore.h"
  20. #include "gdbcmd.h"
  21. #include "symfile.h"
  22. #include "objfiles.h"
  23. #include "regcache.h"
  24. #include "value.h"
  25. #include "osabi.h"
  26. #include "regset.h"
  27. #include "solib-svr4.h"
  28. #include "solib.h"
  29. #include "solist.h"
  30. #include "ppc-tdep.h"
  31. #include "ppc64-tdep.h"
  32. #include "ppc-linux-tdep.h"
  33. #include "arch/ppc-linux-common.h"
  34. #include "arch/ppc-linux-tdesc.h"
  35. #include "glibc-tdep.h"
  36. #include "trad-frame.h"
  37. #include "frame-unwind.h"
  38. #include "tramp-frame.h"
  39. #include "observable.h"
  40. #include "auxv.h"
  41. #include "elf/common.h"
  42. #include "elf/ppc64.h"
  43. #include "arch-utils.h"
  44. #include "xml-syscall.h"
  45. #include "linux-tdep.h"
  46. #include "linux-record.h"
  47. #include "record-full.h"
  48. #include "infrun.h"
  49. #include "expop.h"
  50. #include "stap-probe.h"
  51. #include "ax.h"
  52. #include "ax-gdb.h"
  53. #include "cli/cli-utils.h"
  54. #include "parser-defs.h"
  55. #include "user-regs.h"
  56. #include <ctype.h>
  57. #include "elf-bfd.h"
  58. #include "features/rs6000/powerpc-32l.c"
  59. #include "features/rs6000/powerpc-altivec32l.c"
  60. #include "features/rs6000/powerpc-vsx32l.c"
  61. #include "features/rs6000/powerpc-isa205-32l.c"
  62. #include "features/rs6000/powerpc-isa205-altivec32l.c"
  63. #include "features/rs6000/powerpc-isa205-vsx32l.c"
  64. #include "features/rs6000/powerpc-isa205-ppr-dscr-vsx32l.c"
  65. #include "features/rs6000/powerpc-isa207-vsx32l.c"
  66. #include "features/rs6000/powerpc-isa207-htm-vsx32l.c"
  67. #include "features/rs6000/powerpc-64l.c"
  68. #include "features/rs6000/powerpc-altivec64l.c"
  69. #include "features/rs6000/powerpc-vsx64l.c"
  70. #include "features/rs6000/powerpc-isa205-64l.c"
  71. #include "features/rs6000/powerpc-isa205-altivec64l.c"
  72. #include "features/rs6000/powerpc-isa205-vsx64l.c"
  73. #include "features/rs6000/powerpc-isa205-ppr-dscr-vsx64l.c"
  74. #include "features/rs6000/powerpc-isa207-vsx64l.c"
  75. #include "features/rs6000/powerpc-isa207-htm-vsx64l.c"
  76. #include "features/rs6000/powerpc-e500l.c"
  77. /* Shared library operations for PowerPC-Linux. */
  78. static struct target_so_ops powerpc_so_ops;
  79. /* The syscall's XML filename for PPC and PPC64. */
  80. #define XML_SYSCALL_FILENAME_PPC "syscalls/ppc-linux.xml"
  81. #define XML_SYSCALL_FILENAME_PPC64 "syscalls/ppc64-linux.xml"
  82. /* ppc_linux_memory_remove_breakpoints attempts to remove a breakpoint
  83. in much the same fashion as memory_remove_breakpoint in mem-break.c,
  84. but is careful not to write back the previous contents if the code
  85. in question has changed in between inserting the breakpoint and
  86. removing it.
  87. Here is the problem that we're trying to solve...
  88. Once upon a time, before introducing this function to remove
  89. breakpoints from the inferior, setting a breakpoint on a shared
  90. library function prior to running the program would not work
  91. properly. In order to understand the problem, it is first
  92. necessary to understand a little bit about dynamic linking on
  93. this platform.
  94. A call to a shared library function is accomplished via a bl
  95. (branch-and-link) instruction whose branch target is an entry
  96. in the procedure linkage table (PLT). The PLT in the object
  97. file is uninitialized. To gdb, prior to running the program, the
  98. entries in the PLT are all zeros.
  99. Once the program starts running, the shared libraries are loaded
  100. and the procedure linkage table is initialized, but the entries in
  101. the table are not (necessarily) resolved. Once a function is
  102. actually called, the code in the PLT is hit and the function is
  103. resolved. In order to better illustrate this, an example is in
  104. order; the following example is from the gdb testsuite.
  105. We start the program shmain.
  106. [kev@arroyo testsuite]$ ../gdb gdb.base/shmain
  107. [...]
  108. We place two breakpoints, one on shr1 and the other on main.
  109. (gdb) b shr1
  110. Breakpoint 1 at 0x100409d4
  111. (gdb) b main
  112. Breakpoint 2 at 0x100006a0: file gdb.base/shmain.c, line 44.
  113. Examine the instruction (and the immediatly following instruction)
  114. upon which the breakpoint was placed. Note that the PLT entry
  115. for shr1 contains zeros.
  116. (gdb) x/2i 0x100409d4
  117. 0x100409d4 <shr1>: .long 0x0
  118. 0x100409d8 <shr1+4>: .long 0x0
  119. Now run 'til main.
  120. (gdb) r
  121. Starting program: gdb.base/shmain
  122. Breakpoint 1 at 0xffaf790: file gdb.base/shr1.c, line 19.
  123. Breakpoint 2, main ()
  124. at gdb.base/shmain.c:44
  125. 44 g = 1;
  126. Examine the PLT again. Note that the loading of the shared
  127. library has initialized the PLT to code which loads a constant
  128. (which I think is an index into the GOT) into r11 and then
  129. branches a short distance to the code which actually does the
  130. resolving.
  131. (gdb) x/2i 0x100409d4
  132. 0x100409d4 <shr1>: li r11,4
  133. 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
  134. (gdb) c
  135. Continuing.
  136. Breakpoint 1, shr1 (x=1)
  137. at gdb.base/shr1.c:19
  138. 19 l = 1;
  139. Now we've hit the breakpoint at shr1. (The breakpoint was
  140. reset from the PLT entry to the actual shr1 function after the
  141. shared library was loaded.) Note that the PLT entry has been
  142. resolved to contain a branch that takes us directly to shr1.
  143. (The real one, not the PLT entry.)
  144. (gdb) x/2i 0x100409d4
  145. 0x100409d4 <shr1>: b 0xffaf76c <shr1>
  146. 0x100409d8 <shr1+4>: b 0x10040984 <sg+4>
  147. The thing to note here is that the PLT entry for shr1 has been
  148. changed twice.
  149. Now the problem should be obvious. GDB places a breakpoint (a
  150. trap instruction) on the zero value of the PLT entry for shr1.
  151. Later on, after the shared library had been loaded and the PLT
  152. initialized, GDB gets a signal indicating this fact and attempts
  153. (as it always does when it stops) to remove all the breakpoints.
  154. The breakpoint removal was causing the former contents (a zero
  155. word) to be written back to the now initialized PLT entry thus
  156. destroying a portion of the initialization that had occurred only a
  157. short time ago. When execution continued, the zero word would be
  158. executed as an instruction an illegal instruction trap was
  159. generated instead. (0 is not a legal instruction.)
  160. The fix for this problem was fairly straightforward. The function
  161. memory_remove_breakpoint from mem-break.c was copied to this file,
  162. modified slightly, and renamed to ppc_linux_memory_remove_breakpoint.
  163. In tm-linux.h, MEMORY_REMOVE_BREAKPOINT is defined to call this new
  164. function.
  165. The differences between ppc_linux_memory_remove_breakpoint () and
  166. memory_remove_breakpoint () are minor. All that the former does
  167. that the latter does not is check to make sure that the breakpoint
  168. location actually contains a breakpoint (trap instruction) prior
  169. to attempting to write back the old contents. If it does contain
  170. a trap instruction, we allow the old contents to be written back.
  171. Otherwise, we silently do nothing.
  172. The big question is whether memory_remove_breakpoint () should be
  173. changed to have the same functionality. The downside is that more
  174. traffic is generated for remote targets since we'll have an extra
  175. fetch of a memory word each time a breakpoint is removed.
  176. For the time being, we'll leave this self-modifying-code-friendly
  177. version in ppc-linux-tdep.c, but it ought to be migrated somewhere
  178. else in the event that some other platform has similar needs with
  179. regard to removing breakpoints in some potentially self modifying
  180. code. */
  181. static int
  182. ppc_linux_memory_remove_breakpoint (struct gdbarch *gdbarch,
  183. struct bp_target_info *bp_tgt)
  184. {
  185. CORE_ADDR addr = bp_tgt->reqstd_address;
  186. const unsigned char *bp;
  187. int val;
  188. int bplen;
  189. gdb_byte old_contents[BREAKPOINT_MAX];
  190. /* Determine appropriate breakpoint contents and size for this address. */
  191. bp = gdbarch_breakpoint_from_pc (gdbarch, &addr, &bplen);
  192. /* Make sure we see the memory breakpoints. */
  193. scoped_restore restore_memory
  194. = make_scoped_restore_show_memory_breakpoints (1);
  195. val = target_read_memory (addr, old_contents, bplen);
  196. /* If our breakpoint is no longer at the address, this means that the
  197. program modified the code on us, so it is wrong to put back the
  198. old value. */
  199. if (val == 0 && memcmp (bp, old_contents, bplen) == 0)
  200. val = target_write_raw_memory (addr, bp_tgt->shadow_contents, bplen);
  201. return val;
  202. }
  203. /* For historic reasons, PPC 32 GNU/Linux follows PowerOpen rather
  204. than the 32 bit SYSV R4 ABI structure return convention - all
  205. structures, no matter their size, are put in memory. Vectors,
  206. which were added later, do get returned in a register though. */
  207. static enum return_value_convention
  208. ppc_linux_return_value (struct gdbarch *gdbarch, struct value *function,
  209. struct type *valtype, struct regcache *regcache,
  210. gdb_byte *readbuf, const gdb_byte *writebuf)
  211. {
  212. if ((valtype->code () == TYPE_CODE_STRUCT
  213. || valtype->code () == TYPE_CODE_UNION)
  214. && !((TYPE_LENGTH (valtype) == 16 || TYPE_LENGTH (valtype) == 8)
  215. && valtype->is_vector ()))
  216. return RETURN_VALUE_STRUCT_CONVENTION;
  217. else
  218. return ppc_sysv_abi_return_value (gdbarch, function, valtype, regcache,
  219. readbuf, writebuf);
  220. }
  221. /* PLT stub in an executable. */
  222. static const struct ppc_insn_pattern powerpc32_plt_stub[] =
  223. {
  224. { 0xffff0000, 0x3d600000, 0 }, /* lis r11, xxxx */
  225. { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */
  226. { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
  227. { 0xffffffff, 0x4e800420, 0 }, /* bctr */
  228. { 0, 0, 0 }
  229. };
  230. /* PLT stubs in a shared library or PIE.
  231. The first variant is used when the PLT entry is within +/-32k of
  232. the GOT pointer (r30). */
  233. static const struct ppc_insn_pattern powerpc32_plt_stub_so_1[] =
  234. {
  235. { 0xffff0000, 0x817e0000, 0 }, /* lwz r11, xxxx(r30) */
  236. { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
  237. { 0xffffffff, 0x4e800420, 0 }, /* bctr */
  238. { 0, 0, 0 }
  239. };
  240. /* The second variant is used when the PLT entry is more than +/-32k
  241. from the GOT pointer (r30). */
  242. static const struct ppc_insn_pattern powerpc32_plt_stub_so_2[] =
  243. {
  244. { 0xffff0000, 0x3d7e0000, 0 }, /* addis r11, r30, xxxx */
  245. { 0xffff0000, 0x816b0000, 0 }, /* lwz r11, xxxx(r11) */
  246. { 0xffffffff, 0x7d6903a6, 0 }, /* mtctr r11 */
  247. { 0xffffffff, 0x4e800420, 0 }, /* bctr */
  248. { 0, 0, 0 }
  249. };
  250. /* The max number of insns we check using ppc_insns_match_pattern. */
  251. #define POWERPC32_PLT_CHECK_LEN (ARRAY_SIZE (powerpc32_plt_stub) - 1)
  252. /* Check if PC is in PLT stub. For non-secure PLT, stub is in .plt
  253. section. For secure PLT, stub is in .text and we need to check
  254. instruction patterns. */
  255. static int
  256. powerpc_linux_in_dynsym_resolve_code (CORE_ADDR pc)
  257. {
  258. struct bound_minimal_symbol sym;
  259. /* Check whether PC is in the dynamic linker. This also checks
  260. whether it is in the .plt section, used by non-PIC executables. */
  261. if (svr4_in_dynsym_resolve_code (pc))
  262. return 1;
  263. /* Check if we are in the resolver. */
  264. sym = lookup_minimal_symbol_by_pc (pc);
  265. if (sym.minsym != NULL
  266. && (strcmp (sym.minsym->linkage_name (), "__glink") == 0
  267. || strcmp (sym.minsym->linkage_name (), "__glink_PLTresolve") == 0))
  268. return 1;
  269. return 0;
  270. }
  271. /* Follow PLT stub to actual routine.
  272. When the execution direction is EXEC_REVERSE, scan backward to
  273. check whether we are in the middle of a PLT stub. Currently,
  274. we only look-behind at most 4 instructions (the max length of a PLT
  275. stub sequence. */
  276. static CORE_ADDR
  277. ppc_skip_trampoline_code (struct frame_info *frame, CORE_ADDR pc)
  278. {
  279. unsigned int insnbuf[POWERPC32_PLT_CHECK_LEN];
  280. struct gdbarch *gdbarch = get_frame_arch (frame);
  281. ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  282. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  283. CORE_ADDR target = 0;
  284. int scan_limit, i;
  285. scan_limit = 1;
  286. /* When reverse-debugging, scan backward to check whether we are
  287. in the middle of trampoline code. */
  288. if (execution_direction == EXEC_REVERSE)
  289. scan_limit = 4; /* At most 4 instructions. */
  290. for (i = 0; i < scan_limit; i++)
  291. {
  292. if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub, insnbuf))
  293. {
  294. /* Calculate PLT entry address from
  295. lis r11, xxxx
  296. lwz r11, xxxx(r11). */
  297. target = ((ppc_insn_d_field (insnbuf[0]) << 16)
  298. + ppc_insn_d_field (insnbuf[1]));
  299. }
  300. else if (i < ARRAY_SIZE (powerpc32_plt_stub_so_1) - 1
  301. && ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so_1,
  302. insnbuf))
  303. {
  304. /* Calculate PLT entry address from
  305. lwz r11, xxxx(r30). */
  306. target = (ppc_insn_d_field (insnbuf[0])
  307. + get_frame_register_unsigned (frame,
  308. tdep->ppc_gp0_regnum + 30));
  309. }
  310. else if (ppc_insns_match_pattern (frame, pc, powerpc32_plt_stub_so_2,
  311. insnbuf))
  312. {
  313. /* Calculate PLT entry address from
  314. addis r11, r30, xxxx
  315. lwz r11, xxxx(r11). */
  316. target = ((ppc_insn_d_field (insnbuf[0]) << 16)
  317. + ppc_insn_d_field (insnbuf[1])
  318. + get_frame_register_unsigned (frame,
  319. tdep->ppc_gp0_regnum + 30));
  320. }
  321. else
  322. {
  323. /* Scan backward one more instruction if it doesn't match. */
  324. pc -= 4;
  325. continue;
  326. }
  327. target = read_memory_unsigned_integer (target, 4, byte_order);
  328. return target;
  329. }
  330. return 0;
  331. }
  332. /* Wrappers to handle Linux-only registers. */
  333. static void
  334. ppc_linux_supply_gregset (const struct regset *regset,
  335. struct regcache *regcache,
  336. int regnum, const void *gregs, size_t len)
  337. {
  338. const struct ppc_reg_offsets *offsets
  339. = (const struct ppc_reg_offsets *) regset->regmap;
  340. ppc_supply_gregset (regset, regcache, regnum, gregs, len);
  341. if (ppc_linux_trap_reg_p (regcache->arch ()))
  342. {
  343. /* "orig_r3" is stored 2 slots after "pc". */
  344. if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
  345. ppc_supply_reg (regcache, PPC_ORIG_R3_REGNUM, (const gdb_byte *) gregs,
  346. offsets->pc_offset + 2 * offsets->gpr_size,
  347. offsets->gpr_size);
  348. /* "trap" is stored 8 slots after "pc". */
  349. if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
  350. ppc_supply_reg (regcache, PPC_TRAP_REGNUM, (const gdb_byte *) gregs,
  351. offsets->pc_offset + 8 * offsets->gpr_size,
  352. offsets->gpr_size);
  353. }
  354. }
  355. static void
  356. ppc_linux_collect_gregset (const struct regset *regset,
  357. const struct regcache *regcache,
  358. int regnum, void *gregs, size_t len)
  359. {
  360. const struct ppc_reg_offsets *offsets
  361. = (const struct ppc_reg_offsets *) regset->regmap;
  362. /* Clear areas in the linux gregset not written elsewhere. */
  363. if (regnum == -1)
  364. memset (gregs, 0, len);
  365. ppc_collect_gregset (regset, regcache, regnum, gregs, len);
  366. if (ppc_linux_trap_reg_p (regcache->arch ()))
  367. {
  368. /* "orig_r3" is stored 2 slots after "pc". */
  369. if (regnum == -1 || regnum == PPC_ORIG_R3_REGNUM)
  370. ppc_collect_reg (regcache, PPC_ORIG_R3_REGNUM, (gdb_byte *) gregs,
  371. offsets->pc_offset + 2 * offsets->gpr_size,
  372. offsets->gpr_size);
  373. /* "trap" is stored 8 slots after "pc". */
  374. if (regnum == -1 || regnum == PPC_TRAP_REGNUM)
  375. ppc_collect_reg (regcache, PPC_TRAP_REGNUM, (gdb_byte *) gregs,
  376. offsets->pc_offset + 8 * offsets->gpr_size,
  377. offsets->gpr_size);
  378. }
  379. }
  380. /* Regset descriptions. */
  381. static const struct ppc_reg_offsets ppc32_linux_reg_offsets =
  382. {
  383. /* General-purpose registers. */
  384. /* .r0_offset = */ 0,
  385. /* .gpr_size = */ 4,
  386. /* .xr_size = */ 4,
  387. /* .pc_offset = */ 128,
  388. /* .ps_offset = */ 132,
  389. /* .cr_offset = */ 152,
  390. /* .lr_offset = */ 144,
  391. /* .ctr_offset = */ 140,
  392. /* .xer_offset = */ 148,
  393. /* .mq_offset = */ 156,
  394. /* Floating-point registers. */
  395. /* .f0_offset = */ 0,
  396. /* .fpscr_offset = */ 256,
  397. /* .fpscr_size = */ 8
  398. };
  399. static const struct ppc_reg_offsets ppc64_linux_reg_offsets =
  400. {
  401. /* General-purpose registers. */
  402. /* .r0_offset = */ 0,
  403. /* .gpr_size = */ 8,
  404. /* .xr_size = */ 8,
  405. /* .pc_offset = */ 256,
  406. /* .ps_offset = */ 264,
  407. /* .cr_offset = */ 304,
  408. /* .lr_offset = */ 288,
  409. /* .ctr_offset = */ 280,
  410. /* .xer_offset = */ 296,
  411. /* .mq_offset = */ 312,
  412. /* Floating-point registers. */
  413. /* .f0_offset = */ 0,
  414. /* .fpscr_offset = */ 256,
  415. /* .fpscr_size = */ 8
  416. };
  417. static const struct regset ppc32_linux_gregset = {
  418. &ppc32_linux_reg_offsets,
  419. ppc_linux_supply_gregset,
  420. ppc_linux_collect_gregset
  421. };
  422. static const struct regset ppc64_linux_gregset = {
  423. &ppc64_linux_reg_offsets,
  424. ppc_linux_supply_gregset,
  425. ppc_linux_collect_gregset
  426. };
  427. static const struct regset ppc32_linux_fpregset = {
  428. &ppc32_linux_reg_offsets,
  429. ppc_supply_fpregset,
  430. ppc_collect_fpregset
  431. };
  432. static const struct regcache_map_entry ppc32_le_linux_vrregmap[] =
  433. {
  434. { 32, PPC_VR0_REGNUM, 16 },
  435. { 1, PPC_VSCR_REGNUM, 4 },
  436. { 1, REGCACHE_MAP_SKIP, 12 },
  437. { 1, PPC_VRSAVE_REGNUM, 4 },
  438. { 1, REGCACHE_MAP_SKIP, 12 },
  439. { 0 }
  440. };
  441. static const struct regcache_map_entry ppc32_be_linux_vrregmap[] =
  442. {
  443. { 32, PPC_VR0_REGNUM, 16 },
  444. { 1, REGCACHE_MAP_SKIP, 12},
  445. { 1, PPC_VSCR_REGNUM, 4 },
  446. { 1, PPC_VRSAVE_REGNUM, 4 },
  447. { 1, REGCACHE_MAP_SKIP, 12 },
  448. { 0 }
  449. };
  450. static const struct regset ppc32_le_linux_vrregset = {
  451. ppc32_le_linux_vrregmap,
  452. regcache_supply_regset,
  453. regcache_collect_regset
  454. };
  455. static const struct regset ppc32_be_linux_vrregset = {
  456. ppc32_be_linux_vrregmap,
  457. regcache_supply_regset,
  458. regcache_collect_regset
  459. };
  460. static const struct regcache_map_entry ppc32_linux_vsxregmap[] =
  461. {
  462. { 32, PPC_VSR0_UPPER_REGNUM, 8 },
  463. { 0 }
  464. };
  465. static const struct regset ppc32_linux_vsxregset = {
  466. ppc32_linux_vsxregmap,
  467. regcache_supply_regset,
  468. regcache_collect_regset
  469. };
  470. /* Program Priorty Register regmap. */
  471. static const struct regcache_map_entry ppc32_regmap_ppr[] =
  472. {
  473. { 1, PPC_PPR_REGNUM, 8 },
  474. { 0 }
  475. };
  476. /* Program Priorty Register regset. */
  477. const struct regset ppc32_linux_pprregset = {
  478. ppc32_regmap_ppr,
  479. regcache_supply_regset,
  480. regcache_collect_regset
  481. };
  482. /* Data Stream Control Register regmap. */
  483. static const struct regcache_map_entry ppc32_regmap_dscr[] =
  484. {
  485. { 1, PPC_DSCR_REGNUM, 8 },
  486. { 0 }
  487. };
  488. /* Data Stream Control Register regset. */
  489. const struct regset ppc32_linux_dscrregset = {
  490. ppc32_regmap_dscr,
  491. regcache_supply_regset,
  492. regcache_collect_regset
  493. };
  494. /* Target Address Register regmap. */
  495. static const struct regcache_map_entry ppc32_regmap_tar[] =
  496. {
  497. { 1, PPC_TAR_REGNUM, 8 },
  498. { 0 }
  499. };
  500. /* Target Address Register regset. */
  501. const struct regset ppc32_linux_tarregset = {
  502. ppc32_regmap_tar,
  503. regcache_supply_regset,
  504. regcache_collect_regset
  505. };
  506. /* Event-Based Branching regmap. */
  507. static const struct regcache_map_entry ppc32_regmap_ebb[] =
  508. {
  509. { 1, PPC_EBBRR_REGNUM, 8 },
  510. { 1, PPC_EBBHR_REGNUM, 8 },
  511. { 1, PPC_BESCR_REGNUM, 8 },
  512. { 0 }
  513. };
  514. /* Event-Based Branching regset. */
  515. const struct regset ppc32_linux_ebbregset = {
  516. ppc32_regmap_ebb,
  517. regcache_supply_regset,
  518. regcache_collect_regset
  519. };
  520. /* Performance Monitoring Unit regmap. */
  521. static const struct regcache_map_entry ppc32_regmap_pmu[] =
  522. {
  523. { 1, PPC_SIAR_REGNUM, 8 },
  524. { 1, PPC_SDAR_REGNUM, 8 },
  525. { 1, PPC_SIER_REGNUM, 8 },
  526. { 1, PPC_MMCR2_REGNUM, 8 },
  527. { 1, PPC_MMCR0_REGNUM, 8 },
  528. { 0 }
  529. };
  530. /* Performance Monitoring Unit regset. */
  531. const struct regset ppc32_linux_pmuregset = {
  532. ppc32_regmap_pmu,
  533. regcache_supply_regset,
  534. regcache_collect_regset
  535. };
  536. /* Hardware Transactional Memory special-purpose register regmap. */
  537. static const struct regcache_map_entry ppc32_regmap_tm_spr[] =
  538. {
  539. { 1, PPC_TFHAR_REGNUM, 8 },
  540. { 1, PPC_TEXASR_REGNUM, 8 },
  541. { 1, PPC_TFIAR_REGNUM, 8 },
  542. { 0 }
  543. };
  544. /* Hardware Transactional Memory special-purpose register regset. */
  545. const struct regset ppc32_linux_tm_sprregset = {
  546. ppc32_regmap_tm_spr,
  547. regcache_supply_regset,
  548. regcache_collect_regset
  549. };
  550. /* Regmaps for the Hardware Transactional Memory checkpointed
  551. general-purpose regsets for 32-bit, 64-bit big-endian, and 64-bit
  552. little endian targets. The ptrace and core file buffers for 64-bit
  553. targets use 8-byte fields for the 4-byte registers, and the
  554. position of the register in the fields depends on the endianness.
  555. The 32-bit regmap is the same for both endian types because the
  556. fields are all 4-byte long.
  557. The layout of checkpointed GPR regset is the same as a regular
  558. struct pt_regs, but we skip all registers that are not actually
  559. checkpointed by the processor (e.g. msr, nip), except when
  560. generating a core file. The 64-bit regset is 48 * 8 bytes long.
  561. In some 64-bit kernels, the regset for a 32-bit inferior has the
  562. same length, but all the registers are squeezed in the first half
  563. (48 * 4 bytes). The pt_regs struct calls the regular cr ccr, but
  564. we use ccr for "checkpointed condition register". Note that CR
  565. (condition register) field 0 is not checkpointed, but the kernel
  566. returns all 4 bytes. The skipped registers should not be touched
  567. when writing the regset to the inferior (with
  568. PTRACE_SETREGSET). */
  569. static const struct regcache_map_entry ppc32_regmap_cgpr[] =
  570. {
  571. { 32, PPC_CR0_REGNUM, 4 },
  572. { 3, REGCACHE_MAP_SKIP, 4 }, /* nip, msr, orig_gpr3. */
  573. { 1, PPC_CCTR_REGNUM, 4 },
  574. { 1, PPC_CLR_REGNUM, 4 },
  575. { 1, PPC_CXER_REGNUM, 4 },
  576. { 1, PPC_CCR_REGNUM, 4 },
  577. { 9, REGCACHE_MAP_SKIP, 4 }, /* All the rest. */
  578. { 0 }
  579. };
  580. static const struct regcache_map_entry ppc64_le_regmap_cgpr[] =
  581. {
  582. { 32, PPC_CR0_REGNUM, 8 },
  583. { 3, REGCACHE_MAP_SKIP, 8 },
  584. { 1, PPC_CCTR_REGNUM, 8 },
  585. { 1, PPC_CLR_REGNUM, 8 },
  586. { 1, PPC_CXER_REGNUM, 4 },
  587. { 1, REGCACHE_MAP_SKIP, 4 }, /* CXER padding. */
  588. { 1, PPC_CCR_REGNUM, 4 },
  589. { 1, REGCACHE_MAP_SKIP, 4}, /* CCR padding. */
  590. { 9, REGCACHE_MAP_SKIP, 8},
  591. { 0 }
  592. };
  593. static const struct regcache_map_entry ppc64_be_regmap_cgpr[] =
  594. {
  595. { 32, PPC_CR0_REGNUM, 8 },
  596. { 3, REGCACHE_MAP_SKIP, 8 },
  597. { 1, PPC_CCTR_REGNUM, 8 },
  598. { 1, PPC_CLR_REGNUM, 8 },
  599. { 1, REGCACHE_MAP_SKIP, 4}, /* CXER padding. */
  600. { 1, PPC_CXER_REGNUM, 4 },
  601. { 1, REGCACHE_MAP_SKIP, 4}, /* CCR padding. */
  602. { 1, PPC_CCR_REGNUM, 4 },
  603. { 9, REGCACHE_MAP_SKIP, 8},
  604. { 0 }
  605. };
  606. /* Regsets for the Hardware Transactional Memory checkpointed
  607. general-purpose registers for 32-bit, 64-bit big-endian, and 64-bit
  608. little endian targets.
  609. Some 64-bit kernels generate a checkpointed gpr note section with
  610. 48*8 bytes for a 32-bit thread, of which only 48*4 are actually
  611. used, so we set the variable size flag in the corresponding regset
  612. to accept this case. */
  613. static const struct regset ppc32_linux_cgprregset = {
  614. ppc32_regmap_cgpr,
  615. regcache_supply_regset,
  616. regcache_collect_regset,
  617. REGSET_VARIABLE_SIZE
  618. };
  619. static const struct regset ppc64_be_linux_cgprregset = {
  620. ppc64_be_regmap_cgpr,
  621. regcache_supply_regset,
  622. regcache_collect_regset
  623. };
  624. static const struct regset ppc64_le_linux_cgprregset = {
  625. ppc64_le_regmap_cgpr,
  626. regcache_supply_regset,
  627. regcache_collect_regset
  628. };
  629. /* Hardware Transactional Memory checkpointed floating-point regmap. */
  630. static const struct regcache_map_entry ppc32_regmap_cfpr[] =
  631. {
  632. { 32, PPC_CF0_REGNUM, 8 },
  633. { 1, PPC_CFPSCR_REGNUM, 8 },
  634. { 0 }
  635. };
  636. /* Hardware Transactional Memory checkpointed floating-point regset. */
  637. const struct regset ppc32_linux_cfprregset = {
  638. ppc32_regmap_cfpr,
  639. regcache_supply_regset,
  640. regcache_collect_regset
  641. };
  642. /* Regmaps for the Hardware Transactional Memory checkpointed vector
  643. regsets, for big and little endian targets. The position of the
  644. 4-byte VSCR in its 16-byte field depends on the endianness. */
  645. static const struct regcache_map_entry ppc32_le_regmap_cvmx[] =
  646. {
  647. { 32, PPC_CVR0_REGNUM, 16 },
  648. { 1, PPC_CVSCR_REGNUM, 4 },
  649. { 1, REGCACHE_MAP_SKIP, 12 },
  650. { 1, PPC_CVRSAVE_REGNUM, 4 },
  651. { 1, REGCACHE_MAP_SKIP, 12 },
  652. { 0 }
  653. };
  654. static const struct regcache_map_entry ppc32_be_regmap_cvmx[] =
  655. {
  656. { 32, PPC_CVR0_REGNUM, 16 },
  657. { 1, REGCACHE_MAP_SKIP, 12 },
  658. { 1, PPC_CVSCR_REGNUM, 4 },
  659. { 1, PPC_CVRSAVE_REGNUM, 4 },
  660. { 1, REGCACHE_MAP_SKIP, 12},
  661. { 0 }
  662. };
  663. /* Hardware Transactional Memory checkpointed vector regsets, for little
  664. and big endian targets. */
  665. static const struct regset ppc32_le_linux_cvmxregset = {
  666. ppc32_le_regmap_cvmx,
  667. regcache_supply_regset,
  668. regcache_collect_regset
  669. };
  670. static const struct regset ppc32_be_linux_cvmxregset = {
  671. ppc32_be_regmap_cvmx,
  672. regcache_supply_regset,
  673. regcache_collect_regset
  674. };
  675. /* Hardware Transactional Memory checkpointed vector-scalar regmap. */
  676. static const struct regcache_map_entry ppc32_regmap_cvsx[] =
  677. {
  678. { 32, PPC_CVSR0_UPPER_REGNUM, 8 },
  679. { 0 }
  680. };
  681. /* Hardware Transactional Memory checkpointed vector-scalar regset. */
  682. const struct regset ppc32_linux_cvsxregset = {
  683. ppc32_regmap_cvsx,
  684. regcache_supply_regset,
  685. regcache_collect_regset
  686. };
  687. /* Hardware Transactional Memory checkpointed Program Priority Register
  688. regmap. */
  689. static const struct regcache_map_entry ppc32_regmap_cppr[] =
  690. {
  691. { 1, PPC_CPPR_REGNUM, 8 },
  692. { 0 }
  693. };
  694. /* Hardware Transactional Memory checkpointed Program Priority Register
  695. regset. */
  696. const struct regset ppc32_linux_cpprregset = {
  697. ppc32_regmap_cppr,
  698. regcache_supply_regset,
  699. regcache_collect_regset
  700. };
  701. /* Hardware Transactional Memory checkpointed Data Stream Control
  702. Register regmap. */
  703. static const struct regcache_map_entry ppc32_regmap_cdscr[] =
  704. {
  705. { 1, PPC_CDSCR_REGNUM, 8 },
  706. { 0 }
  707. };
  708. /* Hardware Transactional Memory checkpointed Data Stream Control
  709. Register regset. */
  710. const struct regset ppc32_linux_cdscrregset = {
  711. ppc32_regmap_cdscr,
  712. regcache_supply_regset,
  713. regcache_collect_regset
  714. };
  715. /* Hardware Transactional Memory checkpointed Target Address Register
  716. regmap. */
  717. static const struct regcache_map_entry ppc32_regmap_ctar[] =
  718. {
  719. { 1, PPC_CTAR_REGNUM, 8 },
  720. { 0 }
  721. };
  722. /* Hardware Transactional Memory checkpointed Target Address Register
  723. regset. */
  724. const struct regset ppc32_linux_ctarregset = {
  725. ppc32_regmap_ctar,
  726. regcache_supply_regset,
  727. regcache_collect_regset
  728. };
  729. const struct regset *
  730. ppc_linux_gregset (int wordsize)
  731. {
  732. return wordsize == 8 ? &ppc64_linux_gregset : &ppc32_linux_gregset;
  733. }
  734. const struct regset *
  735. ppc_linux_fpregset (void)
  736. {
  737. return &ppc32_linux_fpregset;
  738. }
  739. const struct regset *
  740. ppc_linux_vrregset (struct gdbarch *gdbarch)
  741. {
  742. if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  743. return &ppc32_be_linux_vrregset;
  744. else
  745. return &ppc32_le_linux_vrregset;
  746. }
  747. const struct regset *
  748. ppc_linux_vsxregset (void)
  749. {
  750. return &ppc32_linux_vsxregset;
  751. }
  752. const struct regset *
  753. ppc_linux_cgprregset (struct gdbarch *gdbarch)
  754. {
  755. ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  756. if (tdep->wordsize == 4)
  757. {
  758. return &ppc32_linux_cgprregset;
  759. }
  760. else
  761. {
  762. if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  763. return &ppc64_be_linux_cgprregset;
  764. else
  765. return &ppc64_le_linux_cgprregset;
  766. }
  767. }
  768. const struct regset *
  769. ppc_linux_cvmxregset (struct gdbarch *gdbarch)
  770. {
  771. if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  772. return &ppc32_be_linux_cvmxregset;
  773. else
  774. return &ppc32_le_linux_cvmxregset;
  775. }
  776. /* Collect function used to generate the core note for the
  777. checkpointed GPR regset. Here, we don't want to skip the
  778. "checkpointed" NIP and MSR, so that the note section we generate is
  779. similar to the one generated by the kernel. To avoid having to
  780. define additional registers in GDB which are not actually
  781. checkpointed in the architecture, we copy TFHAR to the checkpointed
  782. NIP slot, which is what the kernel does, and copy the regular MSR
  783. to the checkpointed MSR slot, which will have a similar value in
  784. most cases. */
  785. static void
  786. ppc_linux_collect_core_cpgrregset (const struct regset *regset,
  787. const struct regcache *regcache,
  788. int regnum, void *buf, size_t len)
  789. {
  790. struct gdbarch *gdbarch = regcache->arch ();
  791. ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  792. const struct regset *cgprregset = ppc_linux_cgprregset (gdbarch);
  793. /* We collect the checkpointed GPRs already defined in the regular
  794. regmap, then overlay TFHAR/MSR on the checkpointed NIP/MSR
  795. slots. */
  796. cgprregset->collect_regset (cgprregset, regcache, regnum, buf, len);
  797. /* Check that we are collecting all the registers, which should be
  798. the case when generating a core file. */
  799. if (regnum != -1)
  800. return;
  801. /* PT_NIP and PT_MSR are 32 and 33 for powerpc. Don't redefine
  802. these symbols since this file can run on clients in other
  803. architectures where they can already be defined to other
  804. values. */
  805. int pt_offset = 32;
  806. /* Check that our buffer is long enough to hold two slots at
  807. pt_offset * wordsize, one for NIP and one for MSR. */
  808. gdb_assert ((pt_offset + 2) * tdep->wordsize <= len);
  809. /* TFHAR is 8 bytes wide, but the NIP slot for a 32-bit thread is
  810. 4-bytes long. We use raw_collect_integer which handles
  811. differences in the sizes for the source and destination buffers
  812. for both endian modes. */
  813. (regcache->raw_collect_integer
  814. (PPC_TFHAR_REGNUM, ((gdb_byte *) buf) + pt_offset * tdep->wordsize,
  815. tdep->wordsize, false));
  816. pt_offset = 33;
  817. (regcache->raw_collect_integer
  818. (PPC_MSR_REGNUM, ((gdb_byte *) buf) + pt_offset * tdep->wordsize,
  819. tdep->wordsize, false));
  820. }
  821. /* Iterate over supported core file register note sections. */
  822. static void
  823. ppc_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
  824. iterate_over_regset_sections_cb *cb,
  825. void *cb_data,
  826. const struct regcache *regcache)
  827. {
  828. ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  829. int have_altivec = tdep->ppc_vr0_regnum != -1;
  830. int have_vsx = tdep->ppc_vsr0_upper_regnum != -1;
  831. int have_ppr = tdep->ppc_ppr_regnum != -1;
  832. int have_dscr = tdep->ppc_dscr_regnum != -1;
  833. int have_tar = tdep->ppc_tar_regnum != -1;
  834. if (tdep->wordsize == 4)
  835. cb (".reg", 48 * 4, 48 * 4, &ppc32_linux_gregset, NULL, cb_data);
  836. else
  837. cb (".reg", 48 * 8, 48 * 8, &ppc64_linux_gregset, NULL, cb_data);
  838. cb (".reg2", 264, 264, &ppc32_linux_fpregset, NULL, cb_data);
  839. if (have_altivec)
  840. {
  841. const struct regset *vrregset = ppc_linux_vrregset (gdbarch);
  842. cb (".reg-ppc-vmx", PPC_LINUX_SIZEOF_VRREGSET, PPC_LINUX_SIZEOF_VRREGSET,
  843. vrregset, "ppc Altivec", cb_data);
  844. }
  845. if (have_vsx)
  846. cb (".reg-ppc-vsx", PPC_LINUX_SIZEOF_VSXREGSET, PPC_LINUX_SIZEOF_VSXREGSET,
  847. &ppc32_linux_vsxregset, "POWER7 VSX", cb_data);
  848. if (have_ppr)
  849. cb (".reg-ppc-ppr", PPC_LINUX_SIZEOF_PPRREGSET,
  850. PPC_LINUX_SIZEOF_PPRREGSET,
  851. &ppc32_linux_pprregset, "Priority Program Register", cb_data);
  852. if (have_dscr)
  853. cb (".reg-ppc-dscr", PPC_LINUX_SIZEOF_DSCRREGSET,
  854. PPC_LINUX_SIZEOF_DSCRREGSET,
  855. &ppc32_linux_dscrregset, "Data Stream Control Register",
  856. cb_data);
  857. if (have_tar)
  858. cb (".reg-ppc-tar", PPC_LINUX_SIZEOF_TARREGSET,
  859. PPC_LINUX_SIZEOF_TARREGSET,
  860. &ppc32_linux_tarregset, "Target Address Register", cb_data);
  861. /* EBB registers are unavailable when ptrace returns ENODATA. Check
  862. availability when generating a core file (regcache != NULL). */
  863. if (tdep->have_ebb)
  864. if (regcache == NULL
  865. || REG_VALID == regcache->get_register_status (PPC_BESCR_REGNUM))
  866. cb (".reg-ppc-ebb", PPC_LINUX_SIZEOF_EBBREGSET,
  867. PPC_LINUX_SIZEOF_EBBREGSET,
  868. &ppc32_linux_ebbregset, "Event-based Branching Registers",
  869. cb_data);
  870. if (tdep->ppc_mmcr0_regnum != -1)
  871. cb (".reg-ppc-pmu", PPC_LINUX_SIZEOF_PMUREGSET,
  872. PPC_LINUX_SIZEOF_PMUREGSET,
  873. &ppc32_linux_pmuregset, "Performance Monitor Registers",
  874. cb_data);
  875. if (tdep->have_htm_spr)
  876. cb (".reg-ppc-tm-spr", PPC_LINUX_SIZEOF_TM_SPRREGSET,
  877. PPC_LINUX_SIZEOF_TM_SPRREGSET,
  878. &ppc32_linux_tm_sprregset,
  879. "Hardware Transactional Memory Special Purpose Registers",
  880. cb_data);
  881. /* Checkpointed registers can be unavailable, don't call back if
  882. we are generating a core file. */
  883. if (tdep->have_htm_core)
  884. {
  885. /* Only generate the checkpointed GPR core note if we also have
  886. access to the HTM SPRs, because we need TFHAR to fill the
  887. "checkpointed" NIP slot. We can read a core file without it
  888. since GDB is not aware of this NIP as a visible register. */
  889. if (regcache == NULL ||
  890. (REG_VALID == regcache->get_register_status (PPC_CR0_REGNUM)
  891. && tdep->have_htm_spr))
  892. {
  893. int cgpr_size = (tdep->wordsize == 4?
  894. PPC32_LINUX_SIZEOF_CGPRREGSET
  895. : PPC64_LINUX_SIZEOF_CGPRREGSET);
  896. const struct regset *cgprregset =
  897. ppc_linux_cgprregset (gdbarch);
  898. if (regcache != NULL)
  899. {
  900. struct regset core_cgprregset = *cgprregset;
  901. core_cgprregset.collect_regset
  902. = ppc_linux_collect_core_cpgrregset;
  903. cb (".reg-ppc-tm-cgpr",
  904. cgpr_size, cgpr_size,
  905. &core_cgprregset,
  906. "Checkpointed General Purpose Registers", cb_data);
  907. }
  908. else
  909. {
  910. cb (".reg-ppc-tm-cgpr",
  911. cgpr_size, cgpr_size,
  912. cgprregset,
  913. "Checkpointed General Purpose Registers", cb_data);
  914. }
  915. }
  916. }
  917. if (tdep->have_htm_fpu)
  918. {
  919. if (regcache == NULL ||
  920. REG_VALID == regcache->get_register_status (PPC_CF0_REGNUM))
  921. cb (".reg-ppc-tm-cfpr", PPC_LINUX_SIZEOF_CFPRREGSET,
  922. PPC_LINUX_SIZEOF_CFPRREGSET,
  923. &ppc32_linux_cfprregset,
  924. "Checkpointed Floating Point Registers", cb_data);
  925. }
  926. if (tdep->have_htm_altivec)
  927. {
  928. if (regcache == NULL ||
  929. REG_VALID == regcache->get_register_status (PPC_CVR0_REGNUM))
  930. {
  931. const struct regset *cvmxregset =
  932. ppc_linux_cvmxregset (gdbarch);
  933. cb (".reg-ppc-tm-cvmx", PPC_LINUX_SIZEOF_CVMXREGSET,
  934. PPC_LINUX_SIZEOF_CVMXREGSET,
  935. cvmxregset,
  936. "Checkpointed Altivec (VMX) Registers", cb_data);
  937. }
  938. }
  939. if (tdep->have_htm_vsx)
  940. {
  941. if (regcache == NULL ||
  942. (REG_VALID
  943. == regcache->get_register_status (PPC_CVSR0_UPPER_REGNUM)))
  944. cb (".reg-ppc-tm-cvsx", PPC_LINUX_SIZEOF_CVSXREGSET,
  945. PPC_LINUX_SIZEOF_CVSXREGSET,
  946. &ppc32_linux_cvsxregset,
  947. "Checkpointed VSX Registers", cb_data);
  948. }
  949. if (tdep->ppc_cppr_regnum != -1)
  950. {
  951. if (regcache == NULL ||
  952. REG_VALID == regcache->get_register_status (PPC_CPPR_REGNUM))
  953. cb (".reg-ppc-tm-cppr", PPC_LINUX_SIZEOF_CPPRREGSET,
  954. PPC_LINUX_SIZEOF_CPPRREGSET,
  955. &ppc32_linux_cpprregset,
  956. "Checkpointed Priority Program Register", cb_data);
  957. }
  958. if (tdep->ppc_cdscr_regnum != -1)
  959. {
  960. if (regcache == NULL ||
  961. REG_VALID == regcache->get_register_status (PPC_CDSCR_REGNUM))
  962. cb (".reg-ppc-tm-cdscr", PPC_LINUX_SIZEOF_CDSCRREGSET,
  963. PPC_LINUX_SIZEOF_CDSCRREGSET,
  964. &ppc32_linux_cdscrregset,
  965. "Checkpointed Data Stream Control Register", cb_data);
  966. }
  967. if (tdep->ppc_ctar_regnum)
  968. {
  969. if ( regcache == NULL ||
  970. REG_VALID == regcache->get_register_status (PPC_CTAR_REGNUM))
  971. cb (".reg-ppc-tm-ctar", PPC_LINUX_SIZEOF_CTARREGSET,
  972. PPC_LINUX_SIZEOF_CTARREGSET,
  973. &ppc32_linux_ctarregset,
  974. "Checkpointed Target Address Register", cb_data);
  975. }
  976. }
  977. static void
  978. ppc_linux_sigtramp_cache (struct frame_info *this_frame,
  979. struct trad_frame_cache *this_cache,
  980. CORE_ADDR func, LONGEST offset,
  981. int bias)
  982. {
  983. CORE_ADDR base;
  984. CORE_ADDR regs;
  985. CORE_ADDR gpregs;
  986. CORE_ADDR fpregs;
  987. int i;
  988. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  989. ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  990. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  991. base = get_frame_register_unsigned (this_frame,
  992. gdbarch_sp_regnum (gdbarch));
  993. if (bias > 0 && get_frame_pc (this_frame) != func)
  994. /* See below, some signal trampolines increment the stack as their
  995. first instruction, need to compensate for that. */
  996. base -= bias;
  997. /* Find the address of the register buffer pointer. */
  998. regs = base + offset;
  999. /* Use that to find the address of the corresponding register
  1000. buffers. */
  1001. gpregs = read_memory_unsigned_integer (regs, tdep->wordsize, byte_order);
  1002. fpregs = gpregs + 48 * tdep->wordsize;
  1003. /* General purpose. */
  1004. for (i = 0; i < 32; i++)
  1005. {
  1006. int regnum = i + tdep->ppc_gp0_regnum;
  1007. trad_frame_set_reg_addr (this_cache,
  1008. regnum, gpregs + i * tdep->wordsize);
  1009. }
  1010. trad_frame_set_reg_addr (this_cache,
  1011. gdbarch_pc_regnum (gdbarch),
  1012. gpregs + 32 * tdep->wordsize);
  1013. trad_frame_set_reg_addr (this_cache, tdep->ppc_ctr_regnum,
  1014. gpregs + 35 * tdep->wordsize);
  1015. trad_frame_set_reg_addr (this_cache, tdep->ppc_lr_regnum,
  1016. gpregs + 36 * tdep->wordsize);
  1017. trad_frame_set_reg_addr (this_cache, tdep->ppc_xer_regnum,
  1018. gpregs + 37 * tdep->wordsize);
  1019. trad_frame_set_reg_addr (this_cache, tdep->ppc_cr_regnum,
  1020. gpregs + 38 * tdep->wordsize);
  1021. if (ppc_linux_trap_reg_p (gdbarch))
  1022. {
  1023. trad_frame_set_reg_addr (this_cache, PPC_ORIG_R3_REGNUM,
  1024. gpregs + 34 * tdep->wordsize);
  1025. trad_frame_set_reg_addr (this_cache, PPC_TRAP_REGNUM,
  1026. gpregs + 40 * tdep->wordsize);
  1027. }
  1028. if (ppc_floating_point_unit_p (gdbarch))
  1029. {
  1030. /* Floating point registers. */
  1031. for (i = 0; i < 32; i++)
  1032. {
  1033. int regnum = i + gdbarch_fp0_regnum (gdbarch);
  1034. trad_frame_set_reg_addr (this_cache, regnum,
  1035. fpregs + i * tdep->wordsize);
  1036. }
  1037. trad_frame_set_reg_addr (this_cache, tdep->ppc_fpscr_regnum,
  1038. fpregs + 32 * tdep->wordsize);
  1039. }
  1040. trad_frame_set_id (this_cache, frame_id_build (base, func));
  1041. }
  1042. static void
  1043. ppc32_linux_sigaction_cache_init (const struct tramp_frame *self,
  1044. struct frame_info *this_frame,
  1045. struct trad_frame_cache *this_cache,
  1046. CORE_ADDR func)
  1047. {
  1048. ppc_linux_sigtramp_cache (this_frame, this_cache, func,
  1049. 0xd0 /* Offset to ucontext_t. */
  1050. + 0x30 /* Offset to .reg. */,
  1051. 0);
  1052. }
  1053. static void
  1054. ppc64_linux_sigaction_cache_init (const struct tramp_frame *self,
  1055. struct frame_info *this_frame,
  1056. struct trad_frame_cache *this_cache,
  1057. CORE_ADDR func)
  1058. {
  1059. ppc_linux_sigtramp_cache (this_frame, this_cache, func,
  1060. 0x80 /* Offset to ucontext_t. */
  1061. + 0xe0 /* Offset to .reg. */,
  1062. 128);
  1063. }
  1064. static void
  1065. ppc32_linux_sighandler_cache_init (const struct tramp_frame *self,
  1066. struct frame_info *this_frame,
  1067. struct trad_frame_cache *this_cache,
  1068. CORE_ADDR func)
  1069. {
  1070. ppc_linux_sigtramp_cache (this_frame, this_cache, func,
  1071. 0x40 /* Offset to ucontext_t. */
  1072. + 0x1c /* Offset to .reg. */,
  1073. 0);
  1074. }
  1075. static void
  1076. ppc64_linux_sighandler_cache_init (const struct tramp_frame *self,
  1077. struct frame_info *this_frame,
  1078. struct trad_frame_cache *this_cache,
  1079. CORE_ADDR func)
  1080. {
  1081. ppc_linux_sigtramp_cache (this_frame, this_cache, func,
  1082. 0x80 /* Offset to struct sigcontext. */
  1083. + 0x38 /* Offset to .reg. */,
  1084. 128);
  1085. }
  1086. static struct tramp_frame ppc32_linux_sigaction_tramp_frame = {
  1087. SIGTRAMP_FRAME,
  1088. 4,
  1089. {
  1090. { 0x380000ac, ULONGEST_MAX }, /* li r0, 172 */
  1091. { 0x44000002, ULONGEST_MAX }, /* sc */
  1092. { TRAMP_SENTINEL_INSN },
  1093. },
  1094. ppc32_linux_sigaction_cache_init
  1095. };
  1096. static struct tramp_frame ppc64_linux_sigaction_tramp_frame = {
  1097. SIGTRAMP_FRAME,
  1098. 4,
  1099. {
  1100. { 0x38210080, ULONGEST_MAX }, /* addi r1,r1,128 */
  1101. { 0x380000ac, ULONGEST_MAX }, /* li r0, 172 */
  1102. { 0x44000002, ULONGEST_MAX }, /* sc */
  1103. { TRAMP_SENTINEL_INSN },
  1104. },
  1105. ppc64_linux_sigaction_cache_init
  1106. };
  1107. static struct tramp_frame ppc32_linux_sighandler_tramp_frame = {
  1108. SIGTRAMP_FRAME,
  1109. 4,
  1110. {
  1111. { 0x38000077, ULONGEST_MAX }, /* li r0,119 */
  1112. { 0x44000002, ULONGEST_MAX }, /* sc */
  1113. { TRAMP_SENTINEL_INSN },
  1114. },
  1115. ppc32_linux_sighandler_cache_init
  1116. };
  1117. static struct tramp_frame ppc64_linux_sighandler_tramp_frame = {
  1118. SIGTRAMP_FRAME,
  1119. 4,
  1120. {
  1121. { 0x38210080, ULONGEST_MAX }, /* addi r1,r1,128 */
  1122. { 0x38000077, ULONGEST_MAX }, /* li r0,119 */
  1123. { 0x44000002, ULONGEST_MAX }, /* sc */
  1124. { TRAMP_SENTINEL_INSN },
  1125. },
  1126. ppc64_linux_sighandler_cache_init
  1127. };
  1128. /* Return 1 if PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM are usable. */
  1129. int
  1130. ppc_linux_trap_reg_p (struct gdbarch *gdbarch)
  1131. {
  1132. /* If we do not have a target description with registers, then
  1133. the special registers will not be included in the register set. */
  1134. if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
  1135. return 0;
  1136. /* If we do, then it is safe to check the size. */
  1137. return register_size (gdbarch, PPC_ORIG_R3_REGNUM) > 0
  1138. && register_size (gdbarch, PPC_TRAP_REGNUM) > 0;
  1139. }
  1140. /* Return the current system call's number present in the
  1141. r0 register. When the function fails, it returns -1. */
  1142. static LONGEST
  1143. ppc_linux_get_syscall_number (struct gdbarch *gdbarch,
  1144. thread_info *thread)
  1145. {
  1146. struct regcache *regcache = get_thread_regcache (thread);
  1147. ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  1148. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1149. /* Make sure we're in a 32- or 64-bit machine */
  1150. gdb_assert (tdep->wordsize == 4 || tdep->wordsize == 8);
  1151. /* The content of a register */
  1152. gdb::byte_vector buf (tdep->wordsize);
  1153. /* Getting the system call number from the register.
  1154. When dealing with PowerPC architecture, this information
  1155. is stored at 0th register. */
  1156. regcache->cooked_read (tdep->ppc_gp0_regnum, buf.data ());
  1157. return extract_signed_integer (buf.data (), tdep->wordsize, byte_order);
  1158. }
  1159. /* PPC process record-replay */
  1160. static struct linux_record_tdep ppc_linux_record_tdep;
  1161. static struct linux_record_tdep ppc64_linux_record_tdep;
  1162. /* ppc_canonicalize_syscall maps from the native PowerPC Linux set of
  1163. syscall ids into a canonical set of syscall ids used by process
  1164. record. (See arch/powerpc/include/uapi/asm/unistd.h in kernel tree.)
  1165. Return -1 if this system call is not supported by process record.
  1166. Otherwise, return the syscall number for process record of given
  1167. SYSCALL. */
  1168. static enum gdb_syscall
  1169. ppc_canonicalize_syscall (int syscall, int wordsize)
  1170. {
  1171. int result = -1;
  1172. if (syscall <= 165)
  1173. result = syscall;
  1174. else if (syscall >= 167 && syscall <= 190) /* Skip query_module 166 */
  1175. result = syscall + 1;
  1176. else if (syscall >= 192 && syscall <= 197) /* mmap2 */
  1177. result = syscall;
  1178. else if (syscall == 208) /* tkill */
  1179. result = gdb_sys_tkill;
  1180. else if (syscall >= 207 && syscall <= 220) /* gettid */
  1181. result = syscall + 224 - 207;
  1182. else if (syscall >= 234 && syscall <= 239) /* exit_group */
  1183. result = syscall + 252 - 234;
  1184. else if (syscall >= 240 && syscall <= 248) /* timer_create */
  1185. result = syscall += 259 - 240;
  1186. else if (syscall >= 250 && syscall <= 251) /* tgkill */
  1187. result = syscall + 270 - 250;
  1188. else if (syscall == 286)
  1189. result = gdb_sys_openat;
  1190. else if (syscall == 291)
  1191. {
  1192. if (wordsize == 64)
  1193. result = gdb_sys_newfstatat;
  1194. else
  1195. result = gdb_sys_fstatat64;
  1196. }
  1197. else if (syscall == 336)
  1198. result = gdb_sys_recv;
  1199. else if (syscall == 337)
  1200. result = gdb_sys_recvfrom;
  1201. else if (syscall == 342)
  1202. result = gdb_sys_recvmsg;
  1203. return (enum gdb_syscall) result;
  1204. }
  1205. /* Record registers which might be clobbered during system call.
  1206. Return 0 if successful. */
  1207. static int
  1208. ppc_linux_syscall_record (struct regcache *regcache)
  1209. {
  1210. struct gdbarch *gdbarch = regcache->arch ();
  1211. ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  1212. ULONGEST scnum;
  1213. enum gdb_syscall syscall_gdb;
  1214. int ret;
  1215. regcache_raw_read_unsigned (regcache, tdep->ppc_gp0_regnum, &scnum);
  1216. syscall_gdb = ppc_canonicalize_syscall (scnum, tdep->wordsize);
  1217. if (syscall_gdb < 0)
  1218. {
  1219. gdb_printf (gdb_stderr,
  1220. _("Process record and replay target doesn't "
  1221. "support syscall number %d\n"), (int) scnum);
  1222. return 0;
  1223. }
  1224. if (syscall_gdb == gdb_sys_sigreturn
  1225. || syscall_gdb == gdb_sys_rt_sigreturn)
  1226. {
  1227. int i, j;
  1228. int regsets[] = { tdep->ppc_gp0_regnum,
  1229. tdep->ppc_fp0_regnum,
  1230. tdep->ppc_vr0_regnum,
  1231. tdep->ppc_vsr0_upper_regnum };
  1232. for (j = 0; j < 4; j++)
  1233. {
  1234. if (regsets[j] == -1)
  1235. continue;
  1236. for (i = 0; i < 32; i++)
  1237. {
  1238. if (record_full_arch_list_add_reg (regcache, regsets[j] + i))
  1239. return -1;
  1240. }
  1241. }
  1242. if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum))
  1243. return -1;
  1244. if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum))
  1245. return -1;
  1246. if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum))
  1247. return -1;
  1248. if (record_full_arch_list_add_reg (regcache, tdep->ppc_xer_regnum))
  1249. return -1;
  1250. return 0;
  1251. }
  1252. if (tdep->wordsize == 8)
  1253. ret = record_linux_system_call (syscall_gdb, regcache,
  1254. &ppc64_linux_record_tdep);
  1255. else
  1256. ret = record_linux_system_call (syscall_gdb, regcache,
  1257. &ppc_linux_record_tdep);
  1258. if (ret != 0)
  1259. return ret;
  1260. /* Record registers clobbered during syscall. */
  1261. for (int i = 3; i <= 12; i++)
  1262. {
  1263. if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + i))
  1264. return -1;
  1265. }
  1266. if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + 0))
  1267. return -1;
  1268. if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum))
  1269. return -1;
  1270. if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum))
  1271. return -1;
  1272. if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum))
  1273. return -1;
  1274. return 0;
  1275. }
  1276. /* Record registers which might be clobbered during signal handling.
  1277. Return 0 if successful. */
  1278. static int
  1279. ppc_linux_record_signal (struct gdbarch *gdbarch, struct regcache *regcache,
  1280. enum gdb_signal signal)
  1281. {
  1282. /* See handle_rt_signal64 in arch/powerpc/kernel/signal_64.c
  1283. handle_rt_signal32 in arch/powerpc/kernel/signal_32.c
  1284. arch/powerpc/include/asm/ptrace.h
  1285. for details. */
  1286. const int SIGNAL_FRAMESIZE = 128;
  1287. const int sizeof_rt_sigframe = 1440 * 2 + 8 * 2 + 4 * 6 + 8 + 8 + 128 + 512;
  1288. ULONGEST sp;
  1289. ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  1290. int i;
  1291. for (i = 3; i <= 12; i++)
  1292. {
  1293. if (record_full_arch_list_add_reg (regcache, tdep->ppc_gp0_regnum + i))
  1294. return -1;
  1295. }
  1296. if (record_full_arch_list_add_reg (regcache, tdep->ppc_lr_regnum))
  1297. return -1;
  1298. if (record_full_arch_list_add_reg (regcache, tdep->ppc_cr_regnum))
  1299. return -1;
  1300. if (record_full_arch_list_add_reg (regcache, tdep->ppc_ctr_regnum))
  1301. return -1;
  1302. if (record_full_arch_list_add_reg (regcache, gdbarch_pc_regnum (gdbarch)))
  1303. return -1;
  1304. if (record_full_arch_list_add_reg (regcache, gdbarch_sp_regnum (gdbarch)))
  1305. return -1;
  1306. /* Record the change in the stack.
  1307. frame-size = sizeof (struct rt_sigframe) + SIGNAL_FRAMESIZE */
  1308. regcache_raw_read_unsigned (regcache, gdbarch_sp_regnum (gdbarch), &sp);
  1309. sp -= SIGNAL_FRAMESIZE;
  1310. sp -= sizeof_rt_sigframe;
  1311. if (record_full_arch_list_add_mem (sp, SIGNAL_FRAMESIZE + sizeof_rt_sigframe))
  1312. return -1;
  1313. if (record_full_arch_list_add_end ())
  1314. return -1;
  1315. return 0;
  1316. }
  1317. static void
  1318. ppc_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
  1319. {
  1320. struct gdbarch *gdbarch = regcache->arch ();
  1321. regcache_cooked_write_unsigned (regcache, gdbarch_pc_regnum (gdbarch), pc);
  1322. /* Set special TRAP register to -1 to prevent the kernel from
  1323. messing with the PC we just installed, if we happen to be
  1324. within an interrupted system call that the kernel wants to
  1325. restart.
  1326. Note that after we return from the dummy call, the TRAP and
  1327. ORIG_R3 registers will be automatically restored, and the
  1328. kernel continues to restart the system call at this point. */
  1329. if (ppc_linux_trap_reg_p (gdbarch))
  1330. regcache_cooked_write_unsigned (regcache, PPC_TRAP_REGNUM, -1);
  1331. }
  1332. static const struct target_desc *
  1333. ppc_linux_core_read_description (struct gdbarch *gdbarch,
  1334. struct target_ops *target,
  1335. bfd *abfd)
  1336. {
  1337. struct ppc_linux_features features = ppc_linux_no_features;
  1338. asection *altivec = bfd_get_section_by_name (abfd, ".reg-ppc-vmx");
  1339. asection *vsx = bfd_get_section_by_name (abfd, ".reg-ppc-vsx");
  1340. asection *section = bfd_get_section_by_name (abfd, ".reg");
  1341. asection *ppr = bfd_get_section_by_name (abfd, ".reg-ppc-ppr");
  1342. asection *dscr = bfd_get_section_by_name (abfd, ".reg-ppc-dscr");
  1343. asection *tar = bfd_get_section_by_name (abfd, ".reg-ppc-tar");
  1344. asection *pmu = bfd_get_section_by_name (abfd, ".reg-ppc-pmu");
  1345. asection *htmspr = bfd_get_section_by_name (abfd, ".reg-ppc-tm-spr");
  1346. if (! section)
  1347. return NULL;
  1348. switch (bfd_section_size (section))
  1349. {
  1350. case 48 * 4:
  1351. features.wordsize = 4;
  1352. break;
  1353. case 48 * 8:
  1354. features.wordsize = 8;
  1355. break;
  1356. default:
  1357. return NULL;
  1358. }
  1359. if (altivec)
  1360. features.altivec = true;
  1361. if (vsx)
  1362. features.vsx = true;
  1363. CORE_ADDR hwcap = linux_get_hwcap (target);
  1364. features.isa205 = ppc_linux_has_isa205 (hwcap);
  1365. if (ppr && dscr)
  1366. {
  1367. features.ppr_dscr = true;
  1368. /* We don't require the EBB note section to be present in the
  1369. core file to select isa207 because these registers could have
  1370. been unavailable when the core file was created. They will
  1371. be in the tdep but will show as unavailable. */
  1372. if (tar && pmu)
  1373. {
  1374. features.isa207 = true;
  1375. if (htmspr)
  1376. features.htm = true;
  1377. }
  1378. }
  1379. return ppc_linux_match_description (features);
  1380. }
  1381. /* Implementation of `gdbarch_elf_make_msymbol_special', as defined in
  1382. gdbarch.h. This implementation is used for the ELFv2 ABI only. */
  1383. static void
  1384. ppc_elfv2_elf_make_msymbol_special (asymbol *sym, struct minimal_symbol *msym)
  1385. {
  1386. elf_symbol_type *elf_sym = (elf_symbol_type *)sym;
  1387. /* If the symbol is marked as having a local entry point, set a target
  1388. flag in the msymbol. We currently only support local entry point
  1389. offsets of 8 bytes, which is the only entry point offset ever used
  1390. by current compilers. If/when other offsets are ever used, we will
  1391. have to use additional target flag bits to store them. */
  1392. switch (PPC64_LOCAL_ENTRY_OFFSET (elf_sym->internal_elf_sym.st_other))
  1393. {
  1394. default:
  1395. break;
  1396. case 8:
  1397. MSYMBOL_TARGET_FLAG_1 (msym) = 1;
  1398. break;
  1399. }
  1400. }
  1401. /* Implementation of `gdbarch_skip_entrypoint', as defined in
  1402. gdbarch.h. This implementation is used for the ELFv2 ABI only. */
  1403. static CORE_ADDR
  1404. ppc_elfv2_skip_entrypoint (struct gdbarch *gdbarch, CORE_ADDR pc)
  1405. {
  1406. struct bound_minimal_symbol fun;
  1407. int local_entry_offset = 0;
  1408. fun = lookup_minimal_symbol_by_pc (pc);
  1409. if (fun.minsym == NULL)
  1410. return pc;
  1411. /* See ppc_elfv2_elf_make_msymbol_special for how local entry point
  1412. offset values are encoded. */
  1413. if (MSYMBOL_TARGET_FLAG_1 (fun.minsym))
  1414. local_entry_offset = 8;
  1415. if (BMSYMBOL_VALUE_ADDRESS (fun) <= pc
  1416. && pc < BMSYMBOL_VALUE_ADDRESS (fun) + local_entry_offset)
  1417. return BMSYMBOL_VALUE_ADDRESS (fun) + local_entry_offset;
  1418. return pc;
  1419. }
  1420. /* Implementation of `gdbarch_stap_is_single_operand', as defined in
  1421. gdbarch.h. */
  1422. static int
  1423. ppc_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
  1424. {
  1425. return (*s == 'i' /* Literal number. */
  1426. || (isdigit (*s) && s[1] == '('
  1427. && isdigit (s[2])) /* Displacement. */
  1428. || (*s == '(' && isdigit (s[1])) /* Register indirection. */
  1429. || isdigit (*s)); /* Register value. */
  1430. }
  1431. /* Implementation of `gdbarch_stap_parse_special_token', as defined in
  1432. gdbarch.h. */
  1433. static expr::operation_up
  1434. ppc_stap_parse_special_token (struct gdbarch *gdbarch,
  1435. struct stap_parse_info *p)
  1436. {
  1437. if (isdigit (*p->arg))
  1438. {
  1439. /* This temporary pointer is needed because we have to do a lookahead.
  1440. We could be dealing with a register displacement, and in such case
  1441. we would not need to do anything. */
  1442. const char *s = p->arg;
  1443. char *regname;
  1444. int len;
  1445. while (isdigit (*s))
  1446. ++s;
  1447. if (*s == '(')
  1448. {
  1449. /* It is a register displacement indeed. Returning 0 means we are
  1450. deferring the treatment of this case to the generic parser. */
  1451. return {};
  1452. }
  1453. len = s - p->arg;
  1454. regname = (char *) alloca (len + 2);
  1455. regname[0] = 'r';
  1456. strncpy (regname + 1, p->arg, len);
  1457. ++len;
  1458. regname[len] = '\0';
  1459. if (user_reg_map_name_to_regnum (gdbarch, regname, len) == -1)
  1460. error (_("Invalid register name `%s' on expression `%s'."),
  1461. regname, p->saved_arg);
  1462. p->arg = s;
  1463. return expr::make_operation<expr::register_operation> (regname);
  1464. }
  1465. /* All the other tokens should be handled correctly by the generic
  1466. parser. */
  1467. return {};
  1468. }
  1469. /* Initialize linux_record_tdep if not initialized yet.
  1470. WORDSIZE is 4 or 8 for 32- or 64-bit PowerPC Linux respectively.
  1471. Sizes of data structures are initialized accordingly. */
  1472. static void
  1473. ppc_init_linux_record_tdep (struct linux_record_tdep *record_tdep,
  1474. int wordsize)
  1475. {
  1476. /* Simply return if it had been initialized. */
  1477. if (record_tdep->size_pointer != 0)
  1478. return;
  1479. /* These values are the size of the type that will be used in a system
  1480. call. They are obtained from Linux Kernel source. */
  1481. if (wordsize == 8)
  1482. {
  1483. record_tdep->size_pointer = 8;
  1484. record_tdep->size__old_kernel_stat = 32;
  1485. record_tdep->size_tms = 32;
  1486. record_tdep->size_loff_t = 8;
  1487. record_tdep->size_flock = 32;
  1488. record_tdep->size_oldold_utsname = 45;
  1489. record_tdep->size_ustat = 32;
  1490. record_tdep->size_old_sigaction = 32;
  1491. record_tdep->size_old_sigset_t = 8;
  1492. record_tdep->size_rlimit = 16;
  1493. record_tdep->size_rusage = 144;
  1494. record_tdep->size_timeval = 16;
  1495. record_tdep->size_timezone = 8;
  1496. record_tdep->size_old_gid_t = 4;
  1497. record_tdep->size_old_uid_t = 4;
  1498. record_tdep->size_fd_set = 128;
  1499. record_tdep->size_old_dirent = 280;
  1500. record_tdep->size_statfs = 120;
  1501. record_tdep->size_statfs64 = 120;
  1502. record_tdep->size_sockaddr = 16;
  1503. record_tdep->size_int = 4;
  1504. record_tdep->size_long = 8;
  1505. record_tdep->size_ulong = 8;
  1506. record_tdep->size_msghdr = 56;
  1507. record_tdep->size_itimerval = 32;
  1508. record_tdep->size_stat = 144;
  1509. record_tdep->size_old_utsname = 325;
  1510. record_tdep->size_sysinfo = 112;
  1511. record_tdep->size_msqid_ds = 120;
  1512. record_tdep->size_shmid_ds = 112;
  1513. record_tdep->size_new_utsname = 390;
  1514. record_tdep->size_timex = 208;
  1515. record_tdep->size_mem_dqinfo = 24;
  1516. record_tdep->size_if_dqblk = 72;
  1517. record_tdep->size_fs_quota_stat = 80;
  1518. record_tdep->size_timespec = 16;
  1519. record_tdep->size_pollfd = 8;
  1520. record_tdep->size_NFS_FHSIZE = 32;
  1521. record_tdep->size_knfsd_fh = 132;
  1522. record_tdep->size_TASK_COMM_LEN = 16;
  1523. record_tdep->size_sigaction = 32;
  1524. record_tdep->size_sigset_t = 8;
  1525. record_tdep->size_siginfo_t = 128;
  1526. record_tdep->size_cap_user_data_t = 8;
  1527. record_tdep->size_stack_t = 24;
  1528. record_tdep->size_off_t = 8;
  1529. record_tdep->size_stat64 = 104;
  1530. record_tdep->size_gid_t = 4;
  1531. record_tdep->size_uid_t = 4;
  1532. record_tdep->size_PAGE_SIZE = 0x10000; /* 64KB */
  1533. record_tdep->size_flock64 = 32;
  1534. record_tdep->size_io_event = 32;
  1535. record_tdep->size_iocb = 64;
  1536. record_tdep->size_epoll_event = 16;
  1537. record_tdep->size_itimerspec = 32;
  1538. record_tdep->size_mq_attr = 64;
  1539. record_tdep->size_termios = 44;
  1540. record_tdep->size_pid_t = 4;
  1541. record_tdep->size_winsize = 8;
  1542. record_tdep->size_serial_struct = 72;
  1543. record_tdep->size_serial_icounter_struct = 80;
  1544. record_tdep->size_size_t = 8;
  1545. record_tdep->size_iovec = 16;
  1546. record_tdep->size_time_t = 8;
  1547. }
  1548. else if (wordsize == 4)
  1549. {
  1550. record_tdep->size_pointer = 4;
  1551. record_tdep->size__old_kernel_stat = 32;
  1552. record_tdep->size_tms = 16;
  1553. record_tdep->size_loff_t = 8;
  1554. record_tdep->size_flock = 16;
  1555. record_tdep->size_oldold_utsname = 45;
  1556. record_tdep->size_ustat = 20;
  1557. record_tdep->size_old_sigaction = 16;
  1558. record_tdep->size_old_sigset_t = 4;
  1559. record_tdep->size_rlimit = 8;
  1560. record_tdep->size_rusage = 72;
  1561. record_tdep->size_timeval = 8;
  1562. record_tdep->size_timezone = 8;
  1563. record_tdep->size_old_gid_t = 4;
  1564. record_tdep->size_old_uid_t = 4;
  1565. record_tdep->size_fd_set = 128;
  1566. record_tdep->size_old_dirent = 268;
  1567. record_tdep->size_statfs = 64;
  1568. record_tdep->size_statfs64 = 88;
  1569. record_tdep->size_sockaddr = 16;
  1570. record_tdep->size_int = 4;
  1571. record_tdep->size_long = 4;
  1572. record_tdep->size_ulong = 4;
  1573. record_tdep->size_msghdr = 28;
  1574. record_tdep->size_itimerval = 16;
  1575. record_tdep->size_stat = 88;
  1576. record_tdep->size_old_utsname = 325;
  1577. record_tdep->size_sysinfo = 64;
  1578. record_tdep->size_msqid_ds = 68;
  1579. record_tdep->size_shmid_ds = 60;
  1580. record_tdep->size_new_utsname = 390;
  1581. record_tdep->size_timex = 128;
  1582. record_tdep->size_mem_dqinfo = 24;
  1583. record_tdep->size_if_dqblk = 72;
  1584. record_tdep->size_fs_quota_stat = 80;
  1585. record_tdep->size_timespec = 8;
  1586. record_tdep->size_pollfd = 8;
  1587. record_tdep->size_NFS_FHSIZE = 32;
  1588. record_tdep->size_knfsd_fh = 132;
  1589. record_tdep->size_TASK_COMM_LEN = 16;
  1590. record_tdep->size_sigaction = 20;
  1591. record_tdep->size_sigset_t = 8;
  1592. record_tdep->size_siginfo_t = 128;
  1593. record_tdep->size_cap_user_data_t = 4;
  1594. record_tdep->size_stack_t = 12;
  1595. record_tdep->size_off_t = 4;
  1596. record_tdep->size_stat64 = 104;
  1597. record_tdep->size_gid_t = 4;
  1598. record_tdep->size_uid_t = 4;
  1599. record_tdep->size_PAGE_SIZE = 0x10000; /* 64KB */
  1600. record_tdep->size_flock64 = 32;
  1601. record_tdep->size_io_event = 32;
  1602. record_tdep->size_iocb = 64;
  1603. record_tdep->size_epoll_event = 16;
  1604. record_tdep->size_itimerspec = 16;
  1605. record_tdep->size_mq_attr = 32;
  1606. record_tdep->size_termios = 44;
  1607. record_tdep->size_pid_t = 4;
  1608. record_tdep->size_winsize = 8;
  1609. record_tdep->size_serial_struct = 60;
  1610. record_tdep->size_serial_icounter_struct = 80;
  1611. record_tdep->size_size_t = 4;
  1612. record_tdep->size_iovec = 8;
  1613. record_tdep->size_time_t = 4;
  1614. }
  1615. else
  1616. internal_error (__FILE__, __LINE__, _("unexpected wordsize"));
  1617. /* These values are the second argument of system call "sys_fcntl"
  1618. and "sys_fcntl64". They are obtained from Linux Kernel source. */
  1619. record_tdep->fcntl_F_GETLK = 5;
  1620. record_tdep->fcntl_F_GETLK64 = 12;
  1621. record_tdep->fcntl_F_SETLK64 = 13;
  1622. record_tdep->fcntl_F_SETLKW64 = 14;
  1623. record_tdep->arg1 = PPC_R0_REGNUM + 3;
  1624. record_tdep->arg2 = PPC_R0_REGNUM + 4;
  1625. record_tdep->arg3 = PPC_R0_REGNUM + 5;
  1626. record_tdep->arg4 = PPC_R0_REGNUM + 6;
  1627. record_tdep->arg5 = PPC_R0_REGNUM + 7;
  1628. record_tdep->arg6 = PPC_R0_REGNUM + 8;
  1629. /* These values are the second argument of system call "sys_ioctl".
  1630. They are obtained from Linux Kernel source.
  1631. See arch/powerpc/include/uapi/asm/ioctls.h. */
  1632. record_tdep->ioctl_TCGETS = 0x403c7413;
  1633. record_tdep->ioctl_TCSETS = 0x803c7414;
  1634. record_tdep->ioctl_TCSETSW = 0x803c7415;
  1635. record_tdep->ioctl_TCSETSF = 0x803c7416;
  1636. record_tdep->ioctl_TCGETA = 0x40147417;
  1637. record_tdep->ioctl_TCSETA = 0x80147418;
  1638. record_tdep->ioctl_TCSETAW = 0x80147419;
  1639. record_tdep->ioctl_TCSETAF = 0x8014741c;
  1640. record_tdep->ioctl_TCSBRK = 0x2000741d;
  1641. record_tdep->ioctl_TCXONC = 0x2000741e;
  1642. record_tdep->ioctl_TCFLSH = 0x2000741f;
  1643. record_tdep->ioctl_TIOCEXCL = 0x540c;
  1644. record_tdep->ioctl_TIOCNXCL = 0x540d;
  1645. record_tdep->ioctl_TIOCSCTTY = 0x540e;
  1646. record_tdep->ioctl_TIOCGPGRP = 0x40047477;
  1647. record_tdep->ioctl_TIOCSPGRP = 0x80047476;
  1648. record_tdep->ioctl_TIOCOUTQ = 0x40047473;
  1649. record_tdep->ioctl_TIOCSTI = 0x5412;
  1650. record_tdep->ioctl_TIOCGWINSZ = 0x40087468;
  1651. record_tdep->ioctl_TIOCSWINSZ = 0x80087467;
  1652. record_tdep->ioctl_TIOCMGET = 0x5415;
  1653. record_tdep->ioctl_TIOCMBIS = 0x5416;
  1654. record_tdep->ioctl_TIOCMBIC = 0x5417;
  1655. record_tdep->ioctl_TIOCMSET = 0x5418;
  1656. record_tdep->ioctl_TIOCGSOFTCAR = 0x5419;
  1657. record_tdep->ioctl_TIOCSSOFTCAR = 0x541a;
  1658. record_tdep->ioctl_FIONREAD = 0x4004667f;
  1659. record_tdep->ioctl_TIOCINQ = 0x4004667f;
  1660. record_tdep->ioctl_TIOCLINUX = 0x541c;
  1661. record_tdep->ioctl_TIOCCONS = 0x541d;
  1662. record_tdep->ioctl_TIOCGSERIAL = 0x541e;
  1663. record_tdep->ioctl_TIOCSSERIAL = 0x541f;
  1664. record_tdep->ioctl_TIOCPKT = 0x5420;
  1665. record_tdep->ioctl_FIONBIO = 0x8004667e;
  1666. record_tdep->ioctl_TIOCNOTTY = 0x5422;
  1667. record_tdep->ioctl_TIOCSETD = 0x5423;
  1668. record_tdep->ioctl_TIOCGETD = 0x5424;
  1669. record_tdep->ioctl_TCSBRKP = 0x5425;
  1670. record_tdep->ioctl_TIOCSBRK = 0x5427;
  1671. record_tdep->ioctl_TIOCCBRK = 0x5428;
  1672. record_tdep->ioctl_TIOCGSID = 0x5429;
  1673. record_tdep->ioctl_TIOCGPTN = 0x40045430;
  1674. record_tdep->ioctl_TIOCSPTLCK = 0x80045431;
  1675. record_tdep->ioctl_FIONCLEX = 0x20006602;
  1676. record_tdep->ioctl_FIOCLEX = 0x20006601;
  1677. record_tdep->ioctl_FIOASYNC = 0x8004667d;
  1678. record_tdep->ioctl_TIOCSERCONFIG = 0x5453;
  1679. record_tdep->ioctl_TIOCSERGWILD = 0x5454;
  1680. record_tdep->ioctl_TIOCSERSWILD = 0x5455;
  1681. record_tdep->ioctl_TIOCGLCKTRMIOS = 0x5456;
  1682. record_tdep->ioctl_TIOCSLCKTRMIOS = 0x5457;
  1683. record_tdep->ioctl_TIOCSERGSTRUCT = 0x5458;
  1684. record_tdep->ioctl_TIOCSERGETLSR = 0x5459;
  1685. record_tdep->ioctl_TIOCSERGETMULTI = 0x545a;
  1686. record_tdep->ioctl_TIOCSERSETMULTI = 0x545b;
  1687. record_tdep->ioctl_TIOCMIWAIT = 0x545c;
  1688. record_tdep->ioctl_TIOCGICOUNT = 0x545d;
  1689. record_tdep->ioctl_FIOQSIZE = 0x40086680;
  1690. }
  1691. /* Return a floating-point format for a floating-point variable of
  1692. length LEN in bits. If non-NULL, NAME is the name of its type.
  1693. If no suitable type is found, return NULL. */
  1694. static const struct floatformat **
  1695. ppc_floatformat_for_type (struct gdbarch *gdbarch,
  1696. const char *name, int len)
  1697. {
  1698. if (len == 128 && name)
  1699. {
  1700. if (strcmp (name, "__float128") == 0
  1701. || strcmp (name, "_Float128") == 0
  1702. || strcmp (name, "_Float64x") == 0
  1703. || strcmp (name, "complex _Float128") == 0
  1704. || strcmp (name, "complex _Float64x") == 0)
  1705. return floatformats_ieee_quad;
  1706. if (strcmp (name, "__ibm128") == 0)
  1707. return floatformats_ibm_long_double;
  1708. }
  1709. return default_floatformat_for_type (gdbarch, name, len);
  1710. }
  1711. /* Specify the powerpc64le target triplet.
  1712. This can be variations of
  1713. ppc64le-{distro}-linux-gcc
  1714. and
  1715. powerpc64le-{distro}-linux-gcc. */
  1716. static const char *
  1717. ppc64le_gnu_triplet_regexp (struct gdbarch *gdbarch)
  1718. {
  1719. return "p(ower)?pc64le";
  1720. }
  1721. /* Specify the powerpc64 target triplet.
  1722. This can be variations of
  1723. ppc64-{distro}-linux-gcc
  1724. and
  1725. powerpc64-{distro}-linux-gcc. */
  1726. static const char *
  1727. ppc64_gnu_triplet_regexp (struct gdbarch *gdbarch)
  1728. {
  1729. return "p(ower)?pc64";
  1730. }
  1731. /* Implement the linux_gcc_target_options method. */
  1732. static std::string
  1733. ppc64_linux_gcc_target_options (struct gdbarch *gdbarch)
  1734. {
  1735. return "";
  1736. }
  1737. static displaced_step_prepare_status
  1738. ppc_linux_displaced_step_prepare (gdbarch *arch, thread_info *thread,
  1739. CORE_ADDR &displaced_pc)
  1740. {
  1741. ppc_inferior_data *per_inferior = get_ppc_per_inferior (thread->inf);
  1742. if (!per_inferior->disp_step_buf.has_value ())
  1743. {
  1744. /* Figure out where the displaced step buffer is. */
  1745. CORE_ADDR disp_step_buf_addr
  1746. = linux_displaced_step_location (thread->inf->gdbarch);
  1747. per_inferior->disp_step_buf.emplace (disp_step_buf_addr);
  1748. }
  1749. return per_inferior->disp_step_buf->prepare (thread, displaced_pc);
  1750. }
  1751. static void
  1752. ppc_linux_init_abi (struct gdbarch_info info,
  1753. struct gdbarch *gdbarch)
  1754. {
  1755. ppc_gdbarch_tdep *tdep = (ppc_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  1756. struct tdesc_arch_data *tdesc_data = info.tdesc_data;
  1757. static const char *const stap_integer_prefixes[] = { "i", NULL };
  1758. static const char *const stap_register_indirection_prefixes[] = { "(",
  1759. NULL };
  1760. static const char *const stap_register_indirection_suffixes[] = { ")",
  1761. NULL };
  1762. linux_init_abi (info, gdbarch, 0);
  1763. /* PPC GNU/Linux uses either 64-bit or 128-bit long doubles; where
  1764. 128-bit, they can be either IBM long double or IEEE quad long double.
  1765. The 64-bit long double case will be detected automatically using
  1766. the size specified in debug info. We use a .gnu.attribute flag
  1767. to distinguish between the IBM long double and IEEE quad cases. */
  1768. set_gdbarch_long_double_bit (gdbarch, 16 * TARGET_CHAR_BIT);
  1769. if (tdep->long_double_abi == POWERPC_LONG_DOUBLE_IEEE128)
  1770. set_gdbarch_long_double_format (gdbarch, floatformats_ieee_quad);
  1771. else
  1772. set_gdbarch_long_double_format (gdbarch, floatformats_ibm_long_double);
  1773. /* Support for floating-point data type variants. */
  1774. set_gdbarch_floatformat_for_type (gdbarch, ppc_floatformat_for_type);
  1775. /* Handle inferior calls during interrupted system calls. */
  1776. set_gdbarch_write_pc (gdbarch, ppc_linux_write_pc);
  1777. /* Get the syscall number from the arch's register. */
  1778. set_gdbarch_get_syscall_number (gdbarch, ppc_linux_get_syscall_number);
  1779. /* SystemTap functions. */
  1780. set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes);
  1781. set_gdbarch_stap_register_indirection_prefixes (gdbarch,
  1782. stap_register_indirection_prefixes);
  1783. set_gdbarch_stap_register_indirection_suffixes (gdbarch,
  1784. stap_register_indirection_suffixes);
  1785. set_gdbarch_stap_gdb_register_prefix (gdbarch, "r");
  1786. set_gdbarch_stap_is_single_operand (gdbarch, ppc_stap_is_single_operand);
  1787. set_gdbarch_stap_parse_special_token (gdbarch,
  1788. ppc_stap_parse_special_token);
  1789. if (tdep->wordsize == 4)
  1790. {
  1791. /* Until November 2001, gcc did not comply with the 32 bit SysV
  1792. R4 ABI requirement that structures less than or equal to 8
  1793. bytes should be returned in registers. Instead GCC was using
  1794. the AIX/PowerOpen ABI - everything returned in memory
  1795. (well ignoring vectors that is). When this was corrected, it
  1796. wasn't fixed for GNU/Linux native platform. Use the
  1797. PowerOpen struct convention. */
  1798. set_gdbarch_return_value (gdbarch, ppc_linux_return_value);
  1799. set_gdbarch_memory_remove_breakpoint (gdbarch,
  1800. ppc_linux_memory_remove_breakpoint);
  1801. /* Shared library handling. */
  1802. set_gdbarch_skip_trampoline_code (gdbarch, ppc_skip_trampoline_code);
  1803. set_solib_svr4_fetch_link_map_offsets
  1804. (gdbarch, linux_ilp32_fetch_link_map_offsets);
  1805. /* Setting the correct XML syscall filename. */
  1806. set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_PPC);
  1807. /* Trampolines. */
  1808. tramp_frame_prepend_unwinder (gdbarch,
  1809. &ppc32_linux_sigaction_tramp_frame);
  1810. tramp_frame_prepend_unwinder (gdbarch,
  1811. &ppc32_linux_sighandler_tramp_frame);
  1812. /* BFD target for core files. */
  1813. if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
  1814. set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpcle");
  1815. else
  1816. set_gdbarch_gcore_bfd_target (gdbarch, "elf32-powerpc");
  1817. if (powerpc_so_ops.in_dynsym_resolve_code == NULL)
  1818. {
  1819. powerpc_so_ops = svr4_so_ops;
  1820. /* Override dynamic resolve function. */
  1821. powerpc_so_ops.in_dynsym_resolve_code =
  1822. powerpc_linux_in_dynsym_resolve_code;
  1823. }
  1824. set_solib_ops (gdbarch, &powerpc_so_ops);
  1825. set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
  1826. }
  1827. if (tdep->wordsize == 8)
  1828. {
  1829. if (tdep->elf_abi == POWERPC_ELF_V1)
  1830. {
  1831. /* Handle PPC GNU/Linux 64-bit function pointers (which are really
  1832. function descriptors). */
  1833. set_gdbarch_convert_from_func_ptr_addr
  1834. (gdbarch, ppc64_convert_from_func_ptr_addr);
  1835. set_gdbarch_elf_make_msymbol_special
  1836. (gdbarch, ppc64_elf_make_msymbol_special);
  1837. }
  1838. else
  1839. {
  1840. set_gdbarch_elf_make_msymbol_special
  1841. (gdbarch, ppc_elfv2_elf_make_msymbol_special);
  1842. set_gdbarch_skip_entrypoint (gdbarch, ppc_elfv2_skip_entrypoint);
  1843. }
  1844. /* Shared library handling. */
  1845. set_gdbarch_skip_trampoline_code (gdbarch, ppc64_skip_trampoline_code);
  1846. set_solib_svr4_fetch_link_map_offsets
  1847. (gdbarch, linux_lp64_fetch_link_map_offsets);
  1848. /* Setting the correct XML syscall filename. */
  1849. set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_PPC64);
  1850. /* Trampolines. */
  1851. tramp_frame_prepend_unwinder (gdbarch,
  1852. &ppc64_linux_sigaction_tramp_frame);
  1853. tramp_frame_prepend_unwinder (gdbarch,
  1854. &ppc64_linux_sighandler_tramp_frame);
  1855. /* BFD target for core files. */
  1856. if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
  1857. set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpcle");
  1858. else
  1859. set_gdbarch_gcore_bfd_target (gdbarch, "elf64-powerpc");
  1860. /* Set compiler triplet. */
  1861. if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_LITTLE)
  1862. set_gdbarch_gnu_triplet_regexp (gdbarch, ppc64le_gnu_triplet_regexp);
  1863. else
  1864. set_gdbarch_gnu_triplet_regexp (gdbarch, ppc64_gnu_triplet_regexp);
  1865. /* Set GCC target options. */
  1866. set_gdbarch_gcc_target_options (gdbarch, ppc64_linux_gcc_target_options);
  1867. }
  1868. set_gdbarch_core_read_description (gdbarch, ppc_linux_core_read_description);
  1869. set_gdbarch_iterate_over_regset_sections (gdbarch,
  1870. ppc_linux_iterate_over_regset_sections);
  1871. /* Enable TLS support. */
  1872. set_gdbarch_fetch_tls_load_module_address (gdbarch,
  1873. svr4_fetch_objfile_link_map);
  1874. if (tdesc_data)
  1875. {
  1876. const struct tdesc_feature *feature;
  1877. /* If we have target-described registers, then we can safely
  1878. reserve a number for PPC_ORIG_R3_REGNUM and PPC_TRAP_REGNUM
  1879. (whether they are described or not). */
  1880. gdb_assert (gdbarch_num_regs (gdbarch) <= PPC_ORIG_R3_REGNUM);
  1881. set_gdbarch_num_regs (gdbarch, PPC_TRAP_REGNUM + 1);
  1882. /* If they are present, then assign them to the reserved number. */
  1883. feature = tdesc_find_feature (info.target_desc,
  1884. "org.gnu.gdb.power.linux");
  1885. if (feature != NULL)
  1886. {
  1887. tdesc_numbered_register (feature, tdesc_data,
  1888. PPC_ORIG_R3_REGNUM, "orig_r3");
  1889. tdesc_numbered_register (feature, tdesc_data,
  1890. PPC_TRAP_REGNUM, "trap");
  1891. }
  1892. }
  1893. /* Support reverse debugging. */
  1894. set_gdbarch_process_record (gdbarch, ppc_process_record);
  1895. set_gdbarch_process_record_signal (gdbarch, ppc_linux_record_signal);
  1896. tdep->ppc_syscall_record = ppc_linux_syscall_record;
  1897. ppc_init_linux_record_tdep (&ppc_linux_record_tdep, 4);
  1898. ppc_init_linux_record_tdep (&ppc64_linux_record_tdep, 8);
  1899. /* Setup displaced stepping. */
  1900. set_gdbarch_displaced_step_prepare (gdbarch,
  1901. ppc_linux_displaced_step_prepare);
  1902. }
  1903. void _initialize_ppc_linux_tdep ();
  1904. void
  1905. _initialize_ppc_linux_tdep ()
  1906. {
  1907. /* Register for all sub-families of the POWER/PowerPC: 32-bit and
  1908. 64-bit PowerPC, and the older rs6k. */
  1909. gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc, GDB_OSABI_LINUX,
  1910. ppc_linux_init_abi);
  1911. gdbarch_register_osabi (bfd_arch_powerpc, bfd_mach_ppc64, GDB_OSABI_LINUX,
  1912. ppc_linux_init_abi);
  1913. gdbarch_register_osabi (bfd_arch_rs6000, bfd_mach_rs6k, GDB_OSABI_LINUX,
  1914. ppc_linux_init_abi);
  1915. /* Initialize the Linux target descriptions. */
  1916. initialize_tdesc_powerpc_32l ();
  1917. initialize_tdesc_powerpc_altivec32l ();
  1918. initialize_tdesc_powerpc_vsx32l ();
  1919. initialize_tdesc_powerpc_isa205_32l ();
  1920. initialize_tdesc_powerpc_isa205_altivec32l ();
  1921. initialize_tdesc_powerpc_isa205_vsx32l ();
  1922. initialize_tdesc_powerpc_isa205_ppr_dscr_vsx32l ();
  1923. initialize_tdesc_powerpc_isa207_vsx32l ();
  1924. initialize_tdesc_powerpc_isa207_htm_vsx32l ();
  1925. initialize_tdesc_powerpc_64l ();
  1926. initialize_tdesc_powerpc_altivec64l ();
  1927. initialize_tdesc_powerpc_vsx64l ();
  1928. initialize_tdesc_powerpc_isa205_64l ();
  1929. initialize_tdesc_powerpc_isa205_altivec64l ();
  1930. initialize_tdesc_powerpc_isa205_vsx64l ();
  1931. initialize_tdesc_powerpc_isa205_ppr_dscr_vsx64l ();
  1932. initialize_tdesc_powerpc_isa207_vsx64l ();
  1933. initialize_tdesc_powerpc_isa207_htm_vsx64l ();
  1934. initialize_tdesc_powerpc_e500l ();
  1935. }