aarch64-linux-tdep.c 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079
  1. /* Target-dependent code for GNU/Linux AArch64.
  2. Copyright (C) 2009-2022 Free Software Foundation, Inc.
  3. Contributed by ARM Ltd.
  4. This file is part of GDB.
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 3 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  15. #include "defs.h"
  16. #include "gdbarch.h"
  17. #include "glibc-tdep.h"
  18. #include "linux-tdep.h"
  19. #include "aarch64-tdep.h"
  20. #include "aarch64-linux-tdep.h"
  21. #include "osabi.h"
  22. #include "solib-svr4.h"
  23. #include "symtab.h"
  24. #include "tramp-frame.h"
  25. #include "trad-frame.h"
  26. #include "target.h"
  27. #include "target/target.h"
  28. #include "expop.h"
  29. #include "regcache.h"
  30. #include "regset.h"
  31. #include "stap-probe.h"
  32. #include "parser-defs.h"
  33. #include "user-regs.h"
  34. #include "xml-syscall.h"
  35. #include <ctype.h>
  36. #include "record-full.h"
  37. #include "linux-record.h"
  38. #include "arch/aarch64-mte-linux.h"
  39. #include "arch-utils.h"
  40. #include "value.h"
  41. #include "gdbsupport/selftest.h"
  42. /* Signal frame handling.
  43. +------------+ ^
  44. | saved lr | |
  45. +->| saved fp |--+
  46. | | |
  47. | | |
  48. | +------------+
  49. | | saved lr |
  50. +--| saved fp |
  51. ^ | |
  52. | | |
  53. | +------------+
  54. ^ | |
  55. | | signal |
  56. | | | SIGTRAMP_FRAME (struct rt_sigframe)
  57. | | saved regs |
  58. +--| saved sp |--> interrupted_sp
  59. | | saved pc |--> interrupted_pc
  60. | | |
  61. | +------------+
  62. | | saved lr |--> default_restorer (movz x8, NR_sys_rt_sigreturn; svc 0)
  63. +--| saved fp |<- FP
  64. | | NORMAL_FRAME
  65. | |<- SP
  66. +------------+
  67. On signal delivery, the kernel will create a signal handler stack
  68. frame and setup the return address in LR to point at restorer stub.
  69. The signal stack frame is defined by:
  70. struct rt_sigframe
  71. {
  72. siginfo_t info;
  73. struct ucontext uc;
  74. };
  75. The ucontext has the following form:
  76. struct ucontext
  77. {
  78. unsigned long uc_flags;
  79. struct ucontext *uc_link;
  80. stack_t uc_stack;
  81. sigset_t uc_sigmask;
  82. struct sigcontext uc_mcontext;
  83. };
  84. struct sigcontext
  85. {
  86. unsigned long fault_address;
  87. unsigned long regs[31];
  88. unsigned long sp; / * 31 * /
  89. unsigned long pc; / * 32 * /
  90. unsigned long pstate; / * 33 * /
  91. __u8 __reserved[4096]
  92. };
  93. The reserved space in sigcontext contains additional structures, each starting
  94. with a aarch64_ctx, which specifies a unique identifier and the total size of
  95. the structure. The final structure in reserved will start will a null
  96. aarch64_ctx. The penultimate entry in reserved may be a extra_context which
  97. then points to a further block of reserved space.
  98. struct aarch64_ctx {
  99. u32 magic;
  100. u32 size;
  101. };
  102. The restorer stub will always have the form:
  103. d28015a8 movz x8, #0xad
  104. d4000001 svc #0x0
  105. This is a system call sys_rt_sigreturn.
  106. We detect signal frames by snooping the return code for the restorer
  107. instruction sequence.
  108. The handler then needs to recover the saved register set from
  109. ucontext.uc_mcontext. */
  110. /* These magic numbers need to reflect the layout of the kernel
  111. defined struct rt_sigframe and ucontext. */
  112. #define AARCH64_SIGCONTEXT_REG_SIZE 8
  113. #define AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET 128
  114. #define AARCH64_UCONTEXT_SIGCONTEXT_OFFSET 176
  115. #define AARCH64_SIGCONTEXT_XO_OFFSET 8
  116. #define AARCH64_SIGCONTEXT_RESERVED_OFFSET 288
  117. #define AARCH64_SIGCONTEXT_RESERVED_SIZE 4096
  118. /* Unique identifiers that may be used for aarch64_ctx.magic. */
  119. #define AARCH64_EXTRA_MAGIC 0x45585401
  120. #define AARCH64_FPSIMD_MAGIC 0x46508001
  121. #define AARCH64_SVE_MAGIC 0x53564501
  122. /* Defines for the extra_context that follows an AARCH64_EXTRA_MAGIC. */
  123. #define AARCH64_EXTRA_DATAP_OFFSET 8
  124. /* Defines for the fpsimd that follows an AARCH64_FPSIMD_MAGIC. */
  125. #define AARCH64_FPSIMD_FPSR_OFFSET 8
  126. #define AARCH64_FPSIMD_FPCR_OFFSET 12
  127. #define AARCH64_FPSIMD_V0_OFFSET 16
  128. #define AARCH64_FPSIMD_VREG_SIZE 16
  129. /* Defines for the sve structure that follows an AARCH64_SVE_MAGIC. */
  130. #define AARCH64_SVE_CONTEXT_VL_OFFSET 8
  131. #define AARCH64_SVE_CONTEXT_REGS_OFFSET 16
  132. #define AARCH64_SVE_CONTEXT_P_REGS_OFFSET(vq) (32 * vq * 16)
  133. #define AARCH64_SVE_CONTEXT_FFR_OFFSET(vq) \
  134. (AARCH64_SVE_CONTEXT_P_REGS_OFFSET (vq) + (16 * vq * 2))
  135. #define AARCH64_SVE_CONTEXT_SIZE(vq) \
  136. (AARCH64_SVE_CONTEXT_FFR_OFFSET (vq) + (vq * 2))
  137. /* Read an aarch64_ctx, returning the magic value, and setting *SIZE to the
  138. size, or return 0 on error. */
  139. static uint32_t
  140. read_aarch64_ctx (CORE_ADDR ctx_addr, enum bfd_endian byte_order,
  141. uint32_t *size)
  142. {
  143. uint32_t magic = 0;
  144. gdb_byte buf[4];
  145. if (target_read_memory (ctx_addr, buf, 4) != 0)
  146. return 0;
  147. magic = extract_unsigned_integer (buf, 4, byte_order);
  148. if (target_read_memory (ctx_addr + 4, buf, 4) != 0)
  149. return 0;
  150. *size = extract_unsigned_integer (buf, 4, byte_order);
  151. return magic;
  152. }
  153. /* Given CACHE, use the trad_frame* functions to restore the FPSIMD
  154. registers from a signal frame.
  155. VREG_NUM is the number of the V register being restored, OFFSET is the
  156. address containing the register value, BYTE_ORDER is the endianness and
  157. HAS_SVE tells us if we have a valid SVE context or not. */
  158. static void
  159. aarch64_linux_restore_vreg (struct trad_frame_cache *cache, int num_regs,
  160. int vreg_num, CORE_ADDR offset,
  161. enum bfd_endian byte_order, bool has_sve)
  162. {
  163. /* WARNING: SIMD state is laid out in memory in target-endian format.
  164. So we have a couple cases to consider:
  165. 1 - If the target is big endian, then SIMD state is big endian,
  166. requiring a byteswap.
  167. 2 - If the target is little endian, then SIMD state is little endian, so
  168. no byteswap is needed. */
  169. if (byte_order == BFD_ENDIAN_BIG)
  170. {
  171. gdb_byte buf[V_REGISTER_SIZE];
  172. if (target_read_memory (offset, buf, V_REGISTER_SIZE) != 0)
  173. {
  174. size_t size = V_REGISTER_SIZE/2;
  175. /* Read the two halves of the V register in reverse byte order. */
  176. CORE_ADDR u64 = extract_unsigned_integer (buf, size,
  177. byte_order);
  178. CORE_ADDR l64 = extract_unsigned_integer (buf + size, size,
  179. byte_order);
  180. /* Copy the reversed bytes to the buffer. */
  181. store_unsigned_integer (buf, size, BFD_ENDIAN_LITTLE, l64);
  182. store_unsigned_integer (buf + size , size, BFD_ENDIAN_LITTLE, u64);
  183. /* Now we can store the correct bytes for the V register. */
  184. trad_frame_set_reg_value_bytes (cache, AARCH64_V0_REGNUM + vreg_num,
  185. {buf, V_REGISTER_SIZE});
  186. trad_frame_set_reg_value_bytes (cache,
  187. num_regs + AARCH64_Q0_REGNUM
  188. + vreg_num, {buf, Q_REGISTER_SIZE});
  189. trad_frame_set_reg_value_bytes (cache,
  190. num_regs + AARCH64_D0_REGNUM
  191. + vreg_num, {buf, D_REGISTER_SIZE});
  192. trad_frame_set_reg_value_bytes (cache,
  193. num_regs + AARCH64_S0_REGNUM
  194. + vreg_num, {buf, S_REGISTER_SIZE});
  195. trad_frame_set_reg_value_bytes (cache,
  196. num_regs + AARCH64_H0_REGNUM
  197. + vreg_num, {buf, H_REGISTER_SIZE});
  198. trad_frame_set_reg_value_bytes (cache,
  199. num_regs + AARCH64_B0_REGNUM
  200. + vreg_num, {buf, B_REGISTER_SIZE});
  201. if (has_sve)
  202. trad_frame_set_reg_value_bytes (cache,
  203. num_regs + AARCH64_SVE_V0_REGNUM
  204. + vreg_num, {buf, V_REGISTER_SIZE});
  205. }
  206. return;
  207. }
  208. /* Little endian, just point at the address containing the register
  209. value. */
  210. trad_frame_set_reg_addr (cache, AARCH64_V0_REGNUM + vreg_num, offset);
  211. trad_frame_set_reg_addr (cache, num_regs + AARCH64_Q0_REGNUM + vreg_num,
  212. offset);
  213. trad_frame_set_reg_addr (cache, num_regs + AARCH64_D0_REGNUM + vreg_num,
  214. offset);
  215. trad_frame_set_reg_addr (cache, num_regs + AARCH64_S0_REGNUM + vreg_num,
  216. offset);
  217. trad_frame_set_reg_addr (cache, num_regs + AARCH64_H0_REGNUM + vreg_num,
  218. offset);
  219. trad_frame_set_reg_addr (cache, num_regs + AARCH64_B0_REGNUM + vreg_num,
  220. offset);
  221. if (has_sve)
  222. trad_frame_set_reg_addr (cache, num_regs + AARCH64_SVE_V0_REGNUM
  223. + vreg_num, offset);
  224. }
  225. /* Implement the "init" method of struct tramp_frame. */
  226. static void
  227. aarch64_linux_sigframe_init (const struct tramp_frame *self,
  228. struct frame_info *this_frame,
  229. struct trad_frame_cache *this_cache,
  230. CORE_ADDR func)
  231. {
  232. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  233. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  234. aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  235. CORE_ADDR sp = get_frame_register_unsigned (this_frame, AARCH64_SP_REGNUM);
  236. CORE_ADDR sigcontext_addr = (sp + AARCH64_RT_SIGFRAME_UCONTEXT_OFFSET
  237. + AARCH64_UCONTEXT_SIGCONTEXT_OFFSET );
  238. CORE_ADDR section = sigcontext_addr + AARCH64_SIGCONTEXT_RESERVED_OFFSET;
  239. CORE_ADDR section_end = section + AARCH64_SIGCONTEXT_RESERVED_SIZE;
  240. CORE_ADDR fpsimd = 0;
  241. CORE_ADDR sve_regs = 0;
  242. uint32_t size, magic;
  243. bool extra_found = false;
  244. int num_regs = gdbarch_num_regs (gdbarch);
  245. /* Read in the integer registers. */
  246. for (int i = 0; i < 31; i++)
  247. {
  248. trad_frame_set_reg_addr (this_cache,
  249. AARCH64_X0_REGNUM + i,
  250. sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
  251. + i * AARCH64_SIGCONTEXT_REG_SIZE);
  252. }
  253. trad_frame_set_reg_addr (this_cache, AARCH64_SP_REGNUM,
  254. sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
  255. + 31 * AARCH64_SIGCONTEXT_REG_SIZE);
  256. trad_frame_set_reg_addr (this_cache, AARCH64_PC_REGNUM,
  257. sigcontext_addr + AARCH64_SIGCONTEXT_XO_OFFSET
  258. + 32 * AARCH64_SIGCONTEXT_REG_SIZE);
  259. /* Search for the FP and SVE sections, stopping at null. */
  260. while ((magic = read_aarch64_ctx (section, byte_order, &size)) != 0
  261. && size != 0)
  262. {
  263. switch (magic)
  264. {
  265. case AARCH64_FPSIMD_MAGIC:
  266. fpsimd = section;
  267. section += size;
  268. break;
  269. case AARCH64_SVE_MAGIC:
  270. {
  271. /* Check if the section is followed by a full SVE dump, and set
  272. sve_regs if it is. */
  273. gdb_byte buf[4];
  274. uint16_t vq;
  275. if (!tdep->has_sve ())
  276. break;
  277. if (target_read_memory (section + AARCH64_SVE_CONTEXT_VL_OFFSET,
  278. buf, 2) != 0)
  279. {
  280. section += size;
  281. break;
  282. }
  283. vq = sve_vq_from_vl (extract_unsigned_integer (buf, 2, byte_order));
  284. if (vq != tdep->vq)
  285. error (_("Invalid vector length in signal frame %d vs %s."), vq,
  286. pulongest (tdep->vq));
  287. if (size >= AARCH64_SVE_CONTEXT_SIZE (vq))
  288. sve_regs = section + AARCH64_SVE_CONTEXT_REGS_OFFSET;
  289. section += size;
  290. break;
  291. }
  292. case AARCH64_EXTRA_MAGIC:
  293. {
  294. /* Extra is always the last valid section in reserved and points to
  295. an additional block of memory filled with more sections. Reset
  296. the address to the extra section and continue looking for more
  297. structures. */
  298. gdb_byte buf[8];
  299. if (target_read_memory (section + AARCH64_EXTRA_DATAP_OFFSET,
  300. buf, 8) != 0)
  301. {
  302. section += size;
  303. break;
  304. }
  305. section = extract_unsigned_integer (buf, 8, byte_order);
  306. extra_found = true;
  307. break;
  308. }
  309. default:
  310. section += size;
  311. break;
  312. }
  313. /* Prevent searching past the end of the reserved section. The extra
  314. section does not have a hard coded limit - we have to rely on it ending
  315. with nulls. */
  316. if (!extra_found && section > section_end)
  317. break;
  318. }
  319. if (sve_regs != 0)
  320. {
  321. CORE_ADDR offset;
  322. for (int i = 0; i < 32; i++)
  323. {
  324. offset = sve_regs + (i * tdep->vq * 16);
  325. trad_frame_set_reg_addr (this_cache, AARCH64_SVE_Z0_REGNUM + i,
  326. offset);
  327. trad_frame_set_reg_addr (this_cache,
  328. num_regs + AARCH64_SVE_V0_REGNUM + i,
  329. offset);
  330. trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_Q0_REGNUM + i,
  331. offset);
  332. trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_D0_REGNUM + i,
  333. offset);
  334. trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_S0_REGNUM + i,
  335. offset);
  336. trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_H0_REGNUM + i,
  337. offset);
  338. trad_frame_set_reg_addr (this_cache, num_regs + AARCH64_B0_REGNUM + i,
  339. offset);
  340. }
  341. offset = sve_regs + AARCH64_SVE_CONTEXT_P_REGS_OFFSET (tdep->vq);
  342. for (int i = 0; i < 16; i++)
  343. trad_frame_set_reg_addr (this_cache, AARCH64_SVE_P0_REGNUM + i,
  344. offset + (i * tdep->vq * 2));
  345. offset = sve_regs + AARCH64_SVE_CONTEXT_FFR_OFFSET (tdep->vq);
  346. trad_frame_set_reg_addr (this_cache, AARCH64_SVE_FFR_REGNUM, offset);
  347. }
  348. if (fpsimd != 0)
  349. {
  350. trad_frame_set_reg_addr (this_cache, AARCH64_FPSR_REGNUM,
  351. fpsimd + AARCH64_FPSIMD_FPSR_OFFSET);
  352. trad_frame_set_reg_addr (this_cache, AARCH64_FPCR_REGNUM,
  353. fpsimd + AARCH64_FPSIMD_FPCR_OFFSET);
  354. /* If there was no SVE section then set up the V registers. */
  355. if (sve_regs == 0)
  356. {
  357. for (int i = 0; i < 32; i++)
  358. {
  359. CORE_ADDR offset = (fpsimd + AARCH64_FPSIMD_V0_OFFSET
  360. + (i * AARCH64_FPSIMD_VREG_SIZE));
  361. aarch64_linux_restore_vreg (this_cache, num_regs, i, offset,
  362. byte_order, tdep->has_sve ());
  363. }
  364. }
  365. }
  366. trad_frame_set_id (this_cache, frame_id_build (sp, func));
  367. }
  368. static const struct tramp_frame aarch64_linux_rt_sigframe =
  369. {
  370. SIGTRAMP_FRAME,
  371. 4,
  372. {
  373. /* movz x8, 0x8b (S=1,o=10,h=0,i=0x8b,r=8)
  374. Soo1 0010 1hhi iiii iiii iiii iiir rrrr */
  375. {0xd2801168, ULONGEST_MAX},
  376. /* svc 0x0 (o=0, l=1)
  377. 1101 0100 oooi iiii iiii iiii iii0 00ll */
  378. {0xd4000001, ULONGEST_MAX},
  379. {TRAMP_SENTINEL_INSN, ULONGEST_MAX}
  380. },
  381. aarch64_linux_sigframe_init
  382. };
  383. /* Register maps. */
  384. static const struct regcache_map_entry aarch64_linux_gregmap[] =
  385. {
  386. { 31, AARCH64_X0_REGNUM, 8 }, /* x0 ... x30 */
  387. { 1, AARCH64_SP_REGNUM, 8 },
  388. { 1, AARCH64_PC_REGNUM, 8 },
  389. { 1, AARCH64_CPSR_REGNUM, 8 },
  390. { 0 }
  391. };
  392. static const struct regcache_map_entry aarch64_linux_fpregmap[] =
  393. {
  394. { 32, AARCH64_V0_REGNUM, 16 }, /* v0 ... v31 */
  395. { 1, AARCH64_FPSR_REGNUM, 4 },
  396. { 1, AARCH64_FPCR_REGNUM, 4 },
  397. { 0 }
  398. };
  399. /* Register set definitions. */
  400. const struct regset aarch64_linux_gregset =
  401. {
  402. aarch64_linux_gregmap,
  403. regcache_supply_regset, regcache_collect_regset
  404. };
  405. const struct regset aarch64_linux_fpregset =
  406. {
  407. aarch64_linux_fpregmap,
  408. regcache_supply_regset, regcache_collect_regset
  409. };
  410. /* The fields in an SVE header at the start of a SVE regset. */
  411. #define SVE_HEADER_SIZE_LENGTH 4
  412. #define SVE_HEADER_MAX_SIZE_LENGTH 4
  413. #define SVE_HEADER_VL_LENGTH 2
  414. #define SVE_HEADER_MAX_VL_LENGTH 2
  415. #define SVE_HEADER_FLAGS_LENGTH 2
  416. #define SVE_HEADER_RESERVED_LENGTH 2
  417. #define SVE_HEADER_SIZE_OFFSET 0
  418. #define SVE_HEADER_MAX_SIZE_OFFSET \
  419. (SVE_HEADER_SIZE_OFFSET + SVE_HEADER_SIZE_LENGTH)
  420. #define SVE_HEADER_VL_OFFSET \
  421. (SVE_HEADER_MAX_SIZE_OFFSET + SVE_HEADER_MAX_SIZE_LENGTH)
  422. #define SVE_HEADER_MAX_VL_OFFSET \
  423. (SVE_HEADER_VL_OFFSET + SVE_HEADER_VL_LENGTH)
  424. #define SVE_HEADER_FLAGS_OFFSET \
  425. (SVE_HEADER_MAX_VL_OFFSET + SVE_HEADER_MAX_VL_LENGTH)
  426. #define SVE_HEADER_RESERVED_OFFSET \
  427. (SVE_HEADER_FLAGS_OFFSET + SVE_HEADER_FLAGS_LENGTH)
  428. #define SVE_HEADER_SIZE \
  429. (SVE_HEADER_RESERVED_OFFSET + SVE_HEADER_RESERVED_LENGTH)
  430. #define SVE_HEADER_FLAG_SVE 1
  431. /* Get VQ value from SVE section in the core dump. */
  432. static uint64_t
  433. aarch64_linux_core_read_vq (struct gdbarch *gdbarch, bfd *abfd)
  434. {
  435. gdb_byte header[SVE_HEADER_SIZE];
  436. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  437. asection *sve_section = bfd_get_section_by_name (abfd, ".reg-aarch-sve");
  438. if (sve_section == nullptr)
  439. {
  440. /* No SVE state. */
  441. return 0;
  442. }
  443. size_t size = bfd_section_size (sve_section);
  444. /* Check extended state size. */
  445. if (size < SVE_HEADER_SIZE)
  446. {
  447. warning (_("'.reg-aarch-sve' section in core file too small."));
  448. return 0;
  449. }
  450. if (!bfd_get_section_contents (abfd, sve_section, header, 0, SVE_HEADER_SIZE))
  451. {
  452. warning (_("Couldn't read sve header from "
  453. "'.reg-aarch-sve' section in core file."));
  454. return 0;
  455. }
  456. uint64_t vl = extract_unsigned_integer (header + SVE_HEADER_VL_OFFSET,
  457. SVE_HEADER_VL_LENGTH, byte_order);
  458. uint64_t vq = sve_vq_from_vl (vl);
  459. if (vq > AARCH64_MAX_SVE_VQ)
  460. {
  461. warning (_("SVE Vector length in core file not supported by this version"
  462. " of GDB. (VQ=%s)"), pulongest (vq));
  463. return 0;
  464. }
  465. else if (vq == 0)
  466. {
  467. warning (_("SVE Vector length in core file is invalid. (VQ=%s"),
  468. pulongest (vq));
  469. return 0;
  470. }
  471. return vq;
  472. }
  473. /* Supply register REGNUM from BUF to REGCACHE, using the register map
  474. in REGSET. If REGNUM is -1, do this for all registers in REGSET.
  475. If BUF is NULL, set the registers to "unavailable" status. */
  476. static void
  477. aarch64_linux_supply_sve_regset (const struct regset *regset,
  478. struct regcache *regcache,
  479. int regnum, const void *buf, size_t size)
  480. {
  481. gdb_byte *header = (gdb_byte *) buf;
  482. struct gdbarch *gdbarch = regcache->arch ();
  483. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  484. if (buf == nullptr)
  485. return regcache->supply_regset (regset, regnum, nullptr, size);
  486. gdb_assert (size > SVE_HEADER_SIZE);
  487. /* BUF contains an SVE header followed by a register dump of either the
  488. passed in SVE regset or a NEON fpregset. */
  489. /* Extract required fields from the header. */
  490. ULONGEST vl = extract_unsigned_integer (header + SVE_HEADER_VL_OFFSET,
  491. SVE_HEADER_VL_LENGTH, byte_order);
  492. uint16_t flags = extract_unsigned_integer (header + SVE_HEADER_FLAGS_OFFSET,
  493. SVE_HEADER_FLAGS_LENGTH,
  494. byte_order);
  495. if (regnum == -1 || regnum == AARCH64_SVE_VG_REGNUM)
  496. {
  497. gdb_byte vg_target[8];
  498. store_integer ((gdb_byte *)&vg_target, sizeof (uint64_t), byte_order,
  499. sve_vg_from_vl (vl));
  500. regcache->raw_supply (AARCH64_SVE_VG_REGNUM, &vg_target);
  501. }
  502. if (flags & SVE_HEADER_FLAG_SVE)
  503. {
  504. /* Register dump is a SVE structure. */
  505. regcache->supply_regset (regset, regnum,
  506. (gdb_byte *) buf + SVE_HEADER_SIZE,
  507. size - SVE_HEADER_SIZE);
  508. }
  509. else
  510. {
  511. /* Register dump is a fpsimd structure. First clear the SVE
  512. registers. */
  513. for (int i = 0; i < AARCH64_SVE_Z_REGS_NUM; i++)
  514. regcache->raw_supply_zeroed (AARCH64_SVE_Z0_REGNUM + i);
  515. for (int i = 0; i < AARCH64_SVE_P_REGS_NUM; i++)
  516. regcache->raw_supply_zeroed (AARCH64_SVE_P0_REGNUM + i);
  517. regcache->raw_supply_zeroed (AARCH64_SVE_FFR_REGNUM);
  518. /* Then supply the fpsimd registers. */
  519. regcache->supply_regset (&aarch64_linux_fpregset, regnum,
  520. (gdb_byte *) buf + SVE_HEADER_SIZE,
  521. size - SVE_HEADER_SIZE);
  522. }
  523. }
  524. /* Collect register REGNUM from REGCACHE to BUF, using the register
  525. map in REGSET. If REGNUM is -1, do this for all registers in
  526. REGSET. */
  527. static void
  528. aarch64_linux_collect_sve_regset (const struct regset *regset,
  529. const struct regcache *regcache,
  530. int regnum, void *buf, size_t size)
  531. {
  532. gdb_byte *header = (gdb_byte *) buf;
  533. struct gdbarch *gdbarch = regcache->arch ();
  534. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  535. aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  536. uint64_t vq = tdep->vq;
  537. gdb_assert (buf != NULL);
  538. gdb_assert (size > SVE_HEADER_SIZE);
  539. /* BUF starts with a SVE header prior to the register dump. */
  540. store_unsigned_integer (header + SVE_HEADER_SIZE_OFFSET,
  541. SVE_HEADER_SIZE_LENGTH, byte_order, size);
  542. store_unsigned_integer (header + SVE_HEADER_MAX_SIZE_OFFSET,
  543. SVE_HEADER_MAX_SIZE_LENGTH, byte_order, size);
  544. store_unsigned_integer (header + SVE_HEADER_VL_OFFSET, SVE_HEADER_VL_LENGTH,
  545. byte_order, sve_vl_from_vq (vq));
  546. store_unsigned_integer (header + SVE_HEADER_MAX_VL_OFFSET,
  547. SVE_HEADER_MAX_VL_LENGTH, byte_order,
  548. sve_vl_from_vq (vq));
  549. store_unsigned_integer (header + SVE_HEADER_FLAGS_OFFSET,
  550. SVE_HEADER_FLAGS_LENGTH, byte_order,
  551. SVE_HEADER_FLAG_SVE);
  552. store_unsigned_integer (header + SVE_HEADER_RESERVED_OFFSET,
  553. SVE_HEADER_RESERVED_LENGTH, byte_order, 0);
  554. /* The SVE register dump follows. */
  555. regcache->collect_regset (regset, regnum, (gdb_byte *) buf + SVE_HEADER_SIZE,
  556. size - SVE_HEADER_SIZE);
  557. }
  558. /* Implement the "iterate_over_regset_sections" gdbarch method. */
  559. static void
  560. aarch64_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
  561. iterate_over_regset_sections_cb *cb,
  562. void *cb_data,
  563. const struct regcache *regcache)
  564. {
  565. aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  566. cb (".reg", AARCH64_LINUX_SIZEOF_GREGSET, AARCH64_LINUX_SIZEOF_GREGSET,
  567. &aarch64_linux_gregset, NULL, cb_data);
  568. if (tdep->has_sve ())
  569. {
  570. /* Create this on the fly in order to handle vector register sizes. */
  571. const struct regcache_map_entry sve_regmap[] =
  572. {
  573. { 32, AARCH64_SVE_Z0_REGNUM, (int) (tdep->vq * 16) },
  574. { 16, AARCH64_SVE_P0_REGNUM, (int) (tdep->vq * 16 / 8) },
  575. { 1, AARCH64_SVE_FFR_REGNUM, (int) (tdep->vq * 16 / 8) },
  576. { 1, AARCH64_FPSR_REGNUM, 4 },
  577. { 1, AARCH64_FPCR_REGNUM, 4 },
  578. { 0 }
  579. };
  580. const struct regset aarch64_linux_sve_regset =
  581. {
  582. sve_regmap,
  583. aarch64_linux_supply_sve_regset, aarch64_linux_collect_sve_regset,
  584. REGSET_VARIABLE_SIZE
  585. };
  586. cb (".reg-aarch-sve",
  587. SVE_HEADER_SIZE + regcache_map_entry_size (aarch64_linux_fpregmap),
  588. SVE_HEADER_SIZE + regcache_map_entry_size (sve_regmap),
  589. &aarch64_linux_sve_regset, "SVE registers", cb_data);
  590. }
  591. else
  592. cb (".reg2", AARCH64_LINUX_SIZEOF_FPREGSET, AARCH64_LINUX_SIZEOF_FPREGSET,
  593. &aarch64_linux_fpregset, NULL, cb_data);
  594. if (tdep->has_pauth ())
  595. {
  596. /* Create this on the fly in order to handle the variable location. */
  597. const struct regcache_map_entry pauth_regmap[] =
  598. {
  599. { 2, AARCH64_PAUTH_DMASK_REGNUM (tdep->pauth_reg_base), 8},
  600. { 0 }
  601. };
  602. const struct regset aarch64_linux_pauth_regset =
  603. {
  604. pauth_regmap, regcache_supply_regset, regcache_collect_regset
  605. };
  606. cb (".reg-aarch-pauth", AARCH64_LINUX_SIZEOF_PAUTH,
  607. AARCH64_LINUX_SIZEOF_PAUTH, &aarch64_linux_pauth_regset,
  608. "pauth registers", cb_data);
  609. }
  610. /* Handle MTE registers. */
  611. if (tdep->has_mte ())
  612. {
  613. /* Create this on the fly in order to handle the variable location. */
  614. const struct regcache_map_entry mte_regmap[] =
  615. {
  616. { 1, tdep->mte_reg_base, 8},
  617. { 0 }
  618. };
  619. const struct regset aarch64_linux_mte_regset =
  620. {
  621. mte_regmap, regcache_supply_regset, regcache_collect_regset
  622. };
  623. cb (".reg-aarch-mte", AARCH64_LINUX_SIZEOF_MTE_REGSET,
  624. AARCH64_LINUX_SIZEOF_MTE_REGSET, &aarch64_linux_mte_regset,
  625. "MTE registers", cb_data);
  626. }
  627. }
  628. /* Implement the "core_read_description" gdbarch method. */
  629. static const struct target_desc *
  630. aarch64_linux_core_read_description (struct gdbarch *gdbarch,
  631. struct target_ops *target, bfd *abfd)
  632. {
  633. CORE_ADDR hwcap = linux_get_hwcap (target);
  634. CORE_ADDR hwcap2 = linux_get_hwcap2 (target);
  635. bool pauth_p = hwcap & AARCH64_HWCAP_PACA;
  636. bool mte_p = hwcap2 & HWCAP2_MTE;
  637. return aarch64_read_description (aarch64_linux_core_read_vq (gdbarch, abfd),
  638. pauth_p, mte_p);
  639. }
  640. /* Implementation of `gdbarch_stap_is_single_operand', as defined in
  641. gdbarch.h. */
  642. static int
  643. aarch64_stap_is_single_operand (struct gdbarch *gdbarch, const char *s)
  644. {
  645. return (*s == '#' || isdigit (*s) /* Literal number. */
  646. || *s == '[' /* Register indirection. */
  647. || isalpha (*s)); /* Register value. */
  648. }
  649. /* This routine is used to parse a special token in AArch64's assembly.
  650. The special tokens parsed by it are:
  651. - Register displacement (e.g, [fp, #-8])
  652. It returns one if the special token has been parsed successfully,
  653. or zero if the current token is not considered special. */
  654. static expr::operation_up
  655. aarch64_stap_parse_special_token (struct gdbarch *gdbarch,
  656. struct stap_parse_info *p)
  657. {
  658. if (*p->arg == '[')
  659. {
  660. /* Temporary holder for lookahead. */
  661. const char *tmp = p->arg;
  662. char *endp;
  663. /* Used to save the register name. */
  664. const char *start;
  665. int len;
  666. int got_minus = 0;
  667. long displacement;
  668. ++tmp;
  669. start = tmp;
  670. /* Register name. */
  671. while (isalnum (*tmp))
  672. ++tmp;
  673. if (*tmp != ',')
  674. return {};
  675. len = tmp - start;
  676. std::string regname (start, len);
  677. if (user_reg_map_name_to_regnum (gdbarch, regname.c_str (), len) == -1)
  678. error (_("Invalid register name `%s' on expression `%s'."),
  679. regname.c_str (), p->saved_arg);
  680. ++tmp;
  681. tmp = skip_spaces (tmp);
  682. /* Now we expect a number. It can begin with '#' or simply
  683. a digit. */
  684. if (*tmp == '#')
  685. ++tmp;
  686. if (*tmp == '-')
  687. {
  688. ++tmp;
  689. got_minus = 1;
  690. }
  691. else if (*tmp == '+')
  692. ++tmp;
  693. if (!isdigit (*tmp))
  694. return {};
  695. displacement = strtol (tmp, &endp, 10);
  696. tmp = endp;
  697. /* Skipping last `]'. */
  698. if (*tmp++ != ']')
  699. return {};
  700. p->arg = tmp;
  701. using namespace expr;
  702. /* The displacement. */
  703. struct type *long_type = builtin_type (gdbarch)->builtin_long;
  704. if (got_minus)
  705. displacement = -displacement;
  706. operation_up disp = make_operation<long_const_operation> (long_type,
  707. displacement);
  708. /* The register name. */
  709. operation_up reg
  710. = make_operation<register_operation> (std::move (regname));
  711. operation_up sum
  712. = make_operation<add_operation> (std::move (reg), std::move (disp));
  713. /* Casting to the expected type. */
  714. struct type *arg_ptr_type = lookup_pointer_type (p->arg_type);
  715. sum = make_operation<unop_cast_operation> (std::move (sum),
  716. arg_ptr_type);
  717. return make_operation<unop_ind_operation> (std::move (sum));
  718. }
  719. return {};
  720. }
  721. /* AArch64 process record-replay constructs: syscall, signal etc. */
  722. static linux_record_tdep aarch64_linux_record_tdep;
  723. /* Enum that defines the AArch64 linux specific syscall identifiers used for
  724. process record/replay. */
  725. enum aarch64_syscall {
  726. aarch64_sys_io_setup = 0,
  727. aarch64_sys_io_destroy = 1,
  728. aarch64_sys_io_submit = 2,
  729. aarch64_sys_io_cancel = 3,
  730. aarch64_sys_io_getevents = 4,
  731. aarch64_sys_setxattr = 5,
  732. aarch64_sys_lsetxattr = 6,
  733. aarch64_sys_fsetxattr = 7,
  734. aarch64_sys_getxattr = 8,
  735. aarch64_sys_lgetxattr = 9,
  736. aarch64_sys_fgetxattr = 10,
  737. aarch64_sys_listxattr = 11,
  738. aarch64_sys_llistxattr = 12,
  739. aarch64_sys_flistxattr = 13,
  740. aarch64_sys_removexattr = 14,
  741. aarch64_sys_lremovexattr = 15,
  742. aarch64_sys_fremovexattr = 16,
  743. aarch64_sys_getcwd = 17,
  744. aarch64_sys_lookup_dcookie = 18,
  745. aarch64_sys_eventfd2 = 19,
  746. aarch64_sys_epoll_create1 = 20,
  747. aarch64_sys_epoll_ctl = 21,
  748. aarch64_sys_epoll_pwait = 22,
  749. aarch64_sys_dup = 23,
  750. aarch64_sys_dup3 = 24,
  751. aarch64_sys_fcntl = 25,
  752. aarch64_sys_inotify_init1 = 26,
  753. aarch64_sys_inotify_add_watch = 27,
  754. aarch64_sys_inotify_rm_watch = 28,
  755. aarch64_sys_ioctl = 29,
  756. aarch64_sys_ioprio_set = 30,
  757. aarch64_sys_ioprio_get = 31,
  758. aarch64_sys_flock = 32,
  759. aarch64_sys_mknodat = 33,
  760. aarch64_sys_mkdirat = 34,
  761. aarch64_sys_unlinkat = 35,
  762. aarch64_sys_symlinkat = 36,
  763. aarch64_sys_linkat = 37,
  764. aarch64_sys_renameat = 38,
  765. aarch64_sys_umount2 = 39,
  766. aarch64_sys_mount = 40,
  767. aarch64_sys_pivot_root = 41,
  768. aarch64_sys_nfsservctl = 42,
  769. aarch64_sys_statfs = 43,
  770. aarch64_sys_fstatfs = 44,
  771. aarch64_sys_truncate = 45,
  772. aarch64_sys_ftruncate = 46,
  773. aarch64_sys_fallocate = 47,
  774. aarch64_sys_faccessat = 48,
  775. aarch64_sys_chdir = 49,
  776. aarch64_sys_fchdir = 50,
  777. aarch64_sys_chroot = 51,
  778. aarch64_sys_fchmod = 52,
  779. aarch64_sys_fchmodat = 53,
  780. aarch64_sys_fchownat = 54,
  781. aarch64_sys_fchown = 55,
  782. aarch64_sys_openat = 56,
  783. aarch64_sys_close = 57,
  784. aarch64_sys_vhangup = 58,
  785. aarch64_sys_pipe2 = 59,
  786. aarch64_sys_quotactl = 60,
  787. aarch64_sys_getdents64 = 61,
  788. aarch64_sys_lseek = 62,
  789. aarch64_sys_read = 63,
  790. aarch64_sys_write = 64,
  791. aarch64_sys_readv = 65,
  792. aarch64_sys_writev = 66,
  793. aarch64_sys_pread64 = 67,
  794. aarch64_sys_pwrite64 = 68,
  795. aarch64_sys_preadv = 69,
  796. aarch64_sys_pwritev = 70,
  797. aarch64_sys_sendfile = 71,
  798. aarch64_sys_pselect6 = 72,
  799. aarch64_sys_ppoll = 73,
  800. aarch64_sys_signalfd4 = 74,
  801. aarch64_sys_vmsplice = 75,
  802. aarch64_sys_splice = 76,
  803. aarch64_sys_tee = 77,
  804. aarch64_sys_readlinkat = 78,
  805. aarch64_sys_newfstatat = 79,
  806. aarch64_sys_fstat = 80,
  807. aarch64_sys_sync = 81,
  808. aarch64_sys_fsync = 82,
  809. aarch64_sys_fdatasync = 83,
  810. aarch64_sys_sync_file_range2 = 84,
  811. aarch64_sys_sync_file_range = 84,
  812. aarch64_sys_timerfd_create = 85,
  813. aarch64_sys_timerfd_settime = 86,
  814. aarch64_sys_timerfd_gettime = 87,
  815. aarch64_sys_utimensat = 88,
  816. aarch64_sys_acct = 89,
  817. aarch64_sys_capget = 90,
  818. aarch64_sys_capset = 91,
  819. aarch64_sys_personality = 92,
  820. aarch64_sys_exit = 93,
  821. aarch64_sys_exit_group = 94,
  822. aarch64_sys_waitid = 95,
  823. aarch64_sys_set_tid_address = 96,
  824. aarch64_sys_unshare = 97,
  825. aarch64_sys_futex = 98,
  826. aarch64_sys_set_robust_list = 99,
  827. aarch64_sys_get_robust_list = 100,
  828. aarch64_sys_nanosleep = 101,
  829. aarch64_sys_getitimer = 102,
  830. aarch64_sys_setitimer = 103,
  831. aarch64_sys_kexec_load = 104,
  832. aarch64_sys_init_module = 105,
  833. aarch64_sys_delete_module = 106,
  834. aarch64_sys_timer_create = 107,
  835. aarch64_sys_timer_gettime = 108,
  836. aarch64_sys_timer_getoverrun = 109,
  837. aarch64_sys_timer_settime = 110,
  838. aarch64_sys_timer_delete = 111,
  839. aarch64_sys_clock_settime = 112,
  840. aarch64_sys_clock_gettime = 113,
  841. aarch64_sys_clock_getres = 114,
  842. aarch64_sys_clock_nanosleep = 115,
  843. aarch64_sys_syslog = 116,
  844. aarch64_sys_ptrace = 117,
  845. aarch64_sys_sched_setparam = 118,
  846. aarch64_sys_sched_setscheduler = 119,
  847. aarch64_sys_sched_getscheduler = 120,
  848. aarch64_sys_sched_getparam = 121,
  849. aarch64_sys_sched_setaffinity = 122,
  850. aarch64_sys_sched_getaffinity = 123,
  851. aarch64_sys_sched_yield = 124,
  852. aarch64_sys_sched_get_priority_max = 125,
  853. aarch64_sys_sched_get_priority_min = 126,
  854. aarch64_sys_sched_rr_get_interval = 127,
  855. aarch64_sys_kill = 129,
  856. aarch64_sys_tkill = 130,
  857. aarch64_sys_tgkill = 131,
  858. aarch64_sys_sigaltstack = 132,
  859. aarch64_sys_rt_sigsuspend = 133,
  860. aarch64_sys_rt_sigaction = 134,
  861. aarch64_sys_rt_sigprocmask = 135,
  862. aarch64_sys_rt_sigpending = 136,
  863. aarch64_sys_rt_sigtimedwait = 137,
  864. aarch64_sys_rt_sigqueueinfo = 138,
  865. aarch64_sys_rt_sigreturn = 139,
  866. aarch64_sys_setpriority = 140,
  867. aarch64_sys_getpriority = 141,
  868. aarch64_sys_reboot = 142,
  869. aarch64_sys_setregid = 143,
  870. aarch64_sys_setgid = 144,
  871. aarch64_sys_setreuid = 145,
  872. aarch64_sys_setuid = 146,
  873. aarch64_sys_setresuid = 147,
  874. aarch64_sys_getresuid = 148,
  875. aarch64_sys_setresgid = 149,
  876. aarch64_sys_getresgid = 150,
  877. aarch64_sys_setfsuid = 151,
  878. aarch64_sys_setfsgid = 152,
  879. aarch64_sys_times = 153,
  880. aarch64_sys_setpgid = 154,
  881. aarch64_sys_getpgid = 155,
  882. aarch64_sys_getsid = 156,
  883. aarch64_sys_setsid = 157,
  884. aarch64_sys_getgroups = 158,
  885. aarch64_sys_setgroups = 159,
  886. aarch64_sys_uname = 160,
  887. aarch64_sys_sethostname = 161,
  888. aarch64_sys_setdomainname = 162,
  889. aarch64_sys_getrlimit = 163,
  890. aarch64_sys_setrlimit = 164,
  891. aarch64_sys_getrusage = 165,
  892. aarch64_sys_umask = 166,
  893. aarch64_sys_prctl = 167,
  894. aarch64_sys_getcpu = 168,
  895. aarch64_sys_gettimeofday = 169,
  896. aarch64_sys_settimeofday = 170,
  897. aarch64_sys_adjtimex = 171,
  898. aarch64_sys_getpid = 172,
  899. aarch64_sys_getppid = 173,
  900. aarch64_sys_getuid = 174,
  901. aarch64_sys_geteuid = 175,
  902. aarch64_sys_getgid = 176,
  903. aarch64_sys_getegid = 177,
  904. aarch64_sys_gettid = 178,
  905. aarch64_sys_sysinfo = 179,
  906. aarch64_sys_mq_open = 180,
  907. aarch64_sys_mq_unlink = 181,
  908. aarch64_sys_mq_timedsend = 182,
  909. aarch64_sys_mq_timedreceive = 183,
  910. aarch64_sys_mq_notify = 184,
  911. aarch64_sys_mq_getsetattr = 185,
  912. aarch64_sys_msgget = 186,
  913. aarch64_sys_msgctl = 187,
  914. aarch64_sys_msgrcv = 188,
  915. aarch64_sys_msgsnd = 189,
  916. aarch64_sys_semget = 190,
  917. aarch64_sys_semctl = 191,
  918. aarch64_sys_semtimedop = 192,
  919. aarch64_sys_semop = 193,
  920. aarch64_sys_shmget = 194,
  921. aarch64_sys_shmctl = 195,
  922. aarch64_sys_shmat = 196,
  923. aarch64_sys_shmdt = 197,
  924. aarch64_sys_socket = 198,
  925. aarch64_sys_socketpair = 199,
  926. aarch64_sys_bind = 200,
  927. aarch64_sys_listen = 201,
  928. aarch64_sys_accept = 202,
  929. aarch64_sys_connect = 203,
  930. aarch64_sys_getsockname = 204,
  931. aarch64_sys_getpeername = 205,
  932. aarch64_sys_sendto = 206,
  933. aarch64_sys_recvfrom = 207,
  934. aarch64_sys_setsockopt = 208,
  935. aarch64_sys_getsockopt = 209,
  936. aarch64_sys_shutdown = 210,
  937. aarch64_sys_sendmsg = 211,
  938. aarch64_sys_recvmsg = 212,
  939. aarch64_sys_readahead = 213,
  940. aarch64_sys_brk = 214,
  941. aarch64_sys_munmap = 215,
  942. aarch64_sys_mremap = 216,
  943. aarch64_sys_add_key = 217,
  944. aarch64_sys_request_key = 218,
  945. aarch64_sys_keyctl = 219,
  946. aarch64_sys_clone = 220,
  947. aarch64_sys_execve = 221,
  948. aarch64_sys_mmap = 222,
  949. aarch64_sys_fadvise64 = 223,
  950. aarch64_sys_swapon = 224,
  951. aarch64_sys_swapoff = 225,
  952. aarch64_sys_mprotect = 226,
  953. aarch64_sys_msync = 227,
  954. aarch64_sys_mlock = 228,
  955. aarch64_sys_munlock = 229,
  956. aarch64_sys_mlockall = 230,
  957. aarch64_sys_munlockall = 231,
  958. aarch64_sys_mincore = 232,
  959. aarch64_sys_madvise = 233,
  960. aarch64_sys_remap_file_pages = 234,
  961. aarch64_sys_mbind = 235,
  962. aarch64_sys_get_mempolicy = 236,
  963. aarch64_sys_set_mempolicy = 237,
  964. aarch64_sys_migrate_pages = 238,
  965. aarch64_sys_move_pages = 239,
  966. aarch64_sys_rt_tgsigqueueinfo = 240,
  967. aarch64_sys_perf_event_open = 241,
  968. aarch64_sys_accept4 = 242,
  969. aarch64_sys_recvmmsg = 243,
  970. aarch64_sys_wait4 = 260,
  971. aarch64_sys_prlimit64 = 261,
  972. aarch64_sys_fanotify_init = 262,
  973. aarch64_sys_fanotify_mark = 263,
  974. aarch64_sys_name_to_handle_at = 264,
  975. aarch64_sys_open_by_handle_at = 265,
  976. aarch64_sys_clock_adjtime = 266,
  977. aarch64_sys_syncfs = 267,
  978. aarch64_sys_setns = 268,
  979. aarch64_sys_sendmmsg = 269,
  980. aarch64_sys_process_vm_readv = 270,
  981. aarch64_sys_process_vm_writev = 271,
  982. aarch64_sys_kcmp = 272,
  983. aarch64_sys_finit_module = 273,
  984. aarch64_sys_sched_setattr = 274,
  985. aarch64_sys_sched_getattr = 275,
  986. };
  987. /* aarch64_canonicalize_syscall maps syscall ids from the native AArch64
  988. linux set of syscall ids into a canonical set of syscall ids used by
  989. process record. */
  990. static enum gdb_syscall
  991. aarch64_canonicalize_syscall (enum aarch64_syscall syscall_number)
  992. {
  993. #define SYSCALL_MAP(SYSCALL) case aarch64_sys_##SYSCALL: \
  994. return gdb_sys_##SYSCALL
  995. #define UNSUPPORTED_SYSCALL_MAP(SYSCALL) case aarch64_sys_##SYSCALL: \
  996. return gdb_sys_no_syscall
  997. switch (syscall_number)
  998. {
  999. SYSCALL_MAP (io_setup);
  1000. SYSCALL_MAP (io_destroy);
  1001. SYSCALL_MAP (io_submit);
  1002. SYSCALL_MAP (io_cancel);
  1003. SYSCALL_MAP (io_getevents);
  1004. SYSCALL_MAP (setxattr);
  1005. SYSCALL_MAP (lsetxattr);
  1006. SYSCALL_MAP (fsetxattr);
  1007. SYSCALL_MAP (getxattr);
  1008. SYSCALL_MAP (lgetxattr);
  1009. SYSCALL_MAP (fgetxattr);
  1010. SYSCALL_MAP (listxattr);
  1011. SYSCALL_MAP (llistxattr);
  1012. SYSCALL_MAP (flistxattr);
  1013. SYSCALL_MAP (removexattr);
  1014. SYSCALL_MAP (lremovexattr);
  1015. SYSCALL_MAP (fremovexattr);
  1016. SYSCALL_MAP (getcwd);
  1017. SYSCALL_MAP (lookup_dcookie);
  1018. SYSCALL_MAP (eventfd2);
  1019. SYSCALL_MAP (epoll_create1);
  1020. SYSCALL_MAP (epoll_ctl);
  1021. SYSCALL_MAP (epoll_pwait);
  1022. SYSCALL_MAP (dup);
  1023. SYSCALL_MAP (dup3);
  1024. SYSCALL_MAP (fcntl);
  1025. SYSCALL_MAP (inotify_init1);
  1026. SYSCALL_MAP (inotify_add_watch);
  1027. SYSCALL_MAP (inotify_rm_watch);
  1028. SYSCALL_MAP (ioctl);
  1029. SYSCALL_MAP (ioprio_set);
  1030. SYSCALL_MAP (ioprio_get);
  1031. SYSCALL_MAP (flock);
  1032. SYSCALL_MAP (mknodat);
  1033. SYSCALL_MAP (mkdirat);
  1034. SYSCALL_MAP (unlinkat);
  1035. SYSCALL_MAP (symlinkat);
  1036. SYSCALL_MAP (linkat);
  1037. SYSCALL_MAP (renameat);
  1038. UNSUPPORTED_SYSCALL_MAP (umount2);
  1039. SYSCALL_MAP (mount);
  1040. SYSCALL_MAP (pivot_root);
  1041. SYSCALL_MAP (nfsservctl);
  1042. SYSCALL_MAP (statfs);
  1043. SYSCALL_MAP (truncate);
  1044. SYSCALL_MAP (ftruncate);
  1045. SYSCALL_MAP (fallocate);
  1046. SYSCALL_MAP (faccessat);
  1047. SYSCALL_MAP (fchdir);
  1048. SYSCALL_MAP (chroot);
  1049. SYSCALL_MAP (fchmod);
  1050. SYSCALL_MAP (fchmodat);
  1051. SYSCALL_MAP (fchownat);
  1052. SYSCALL_MAP (fchown);
  1053. SYSCALL_MAP (openat);
  1054. SYSCALL_MAP (close);
  1055. SYSCALL_MAP (vhangup);
  1056. SYSCALL_MAP (pipe2);
  1057. SYSCALL_MAP (quotactl);
  1058. SYSCALL_MAP (getdents64);
  1059. SYSCALL_MAP (lseek);
  1060. SYSCALL_MAP (read);
  1061. SYSCALL_MAP (write);
  1062. SYSCALL_MAP (readv);
  1063. SYSCALL_MAP (writev);
  1064. SYSCALL_MAP (pread64);
  1065. SYSCALL_MAP (pwrite64);
  1066. UNSUPPORTED_SYSCALL_MAP (preadv);
  1067. UNSUPPORTED_SYSCALL_MAP (pwritev);
  1068. SYSCALL_MAP (sendfile);
  1069. SYSCALL_MAP (pselect6);
  1070. SYSCALL_MAP (ppoll);
  1071. UNSUPPORTED_SYSCALL_MAP (signalfd4);
  1072. SYSCALL_MAP (vmsplice);
  1073. SYSCALL_MAP (splice);
  1074. SYSCALL_MAP (tee);
  1075. SYSCALL_MAP (readlinkat);
  1076. SYSCALL_MAP (newfstatat);
  1077. SYSCALL_MAP (fstat);
  1078. SYSCALL_MAP (sync);
  1079. SYSCALL_MAP (fsync);
  1080. SYSCALL_MAP (fdatasync);
  1081. SYSCALL_MAP (sync_file_range);
  1082. UNSUPPORTED_SYSCALL_MAP (timerfd_create);
  1083. UNSUPPORTED_SYSCALL_MAP (timerfd_settime);
  1084. UNSUPPORTED_SYSCALL_MAP (timerfd_gettime);
  1085. UNSUPPORTED_SYSCALL_MAP (utimensat);
  1086. SYSCALL_MAP (acct);
  1087. SYSCALL_MAP (capget);
  1088. SYSCALL_MAP (capset);
  1089. SYSCALL_MAP (personality);
  1090. SYSCALL_MAP (exit);
  1091. SYSCALL_MAP (exit_group);
  1092. SYSCALL_MAP (waitid);
  1093. SYSCALL_MAP (set_tid_address);
  1094. SYSCALL_MAP (unshare);
  1095. SYSCALL_MAP (futex);
  1096. SYSCALL_MAP (set_robust_list);
  1097. SYSCALL_MAP (get_robust_list);
  1098. SYSCALL_MAP (nanosleep);
  1099. SYSCALL_MAP (getitimer);
  1100. SYSCALL_MAP (setitimer);
  1101. SYSCALL_MAP (kexec_load);
  1102. SYSCALL_MAP (init_module);
  1103. SYSCALL_MAP (delete_module);
  1104. SYSCALL_MAP (timer_create);
  1105. SYSCALL_MAP (timer_settime);
  1106. SYSCALL_MAP (timer_gettime);
  1107. SYSCALL_MAP (timer_getoverrun);
  1108. SYSCALL_MAP (timer_delete);
  1109. SYSCALL_MAP (clock_settime);
  1110. SYSCALL_MAP (clock_gettime);
  1111. SYSCALL_MAP (clock_getres);
  1112. SYSCALL_MAP (clock_nanosleep);
  1113. SYSCALL_MAP (syslog);
  1114. SYSCALL_MAP (ptrace);
  1115. SYSCALL_MAP (sched_setparam);
  1116. SYSCALL_MAP (sched_setscheduler);
  1117. SYSCALL_MAP (sched_getscheduler);
  1118. SYSCALL_MAP (sched_getparam);
  1119. SYSCALL_MAP (sched_setaffinity);
  1120. SYSCALL_MAP (sched_getaffinity);
  1121. SYSCALL_MAP (sched_yield);
  1122. SYSCALL_MAP (sched_get_priority_max);
  1123. SYSCALL_MAP (sched_get_priority_min);
  1124. SYSCALL_MAP (sched_rr_get_interval);
  1125. SYSCALL_MAP (kill);
  1126. SYSCALL_MAP (tkill);
  1127. SYSCALL_MAP (tgkill);
  1128. SYSCALL_MAP (sigaltstack);
  1129. SYSCALL_MAP (rt_sigsuspend);
  1130. SYSCALL_MAP (rt_sigaction);
  1131. SYSCALL_MAP (rt_sigprocmask);
  1132. SYSCALL_MAP (rt_sigpending);
  1133. SYSCALL_MAP (rt_sigtimedwait);
  1134. SYSCALL_MAP (rt_sigqueueinfo);
  1135. SYSCALL_MAP (rt_sigreturn);
  1136. SYSCALL_MAP (setpriority);
  1137. SYSCALL_MAP (getpriority);
  1138. SYSCALL_MAP (reboot);
  1139. SYSCALL_MAP (setregid);
  1140. SYSCALL_MAP (setgid);
  1141. SYSCALL_MAP (setreuid);
  1142. SYSCALL_MAP (setuid);
  1143. SYSCALL_MAP (setresuid);
  1144. SYSCALL_MAP (getresuid);
  1145. SYSCALL_MAP (setresgid);
  1146. SYSCALL_MAP (getresgid);
  1147. SYSCALL_MAP (setfsuid);
  1148. SYSCALL_MAP (setfsgid);
  1149. SYSCALL_MAP (times);
  1150. SYSCALL_MAP (setpgid);
  1151. SYSCALL_MAP (getpgid);
  1152. SYSCALL_MAP (getsid);
  1153. SYSCALL_MAP (setsid);
  1154. SYSCALL_MAP (getgroups);
  1155. SYSCALL_MAP (setgroups);
  1156. SYSCALL_MAP (uname);
  1157. SYSCALL_MAP (sethostname);
  1158. SYSCALL_MAP (setdomainname);
  1159. SYSCALL_MAP (getrlimit);
  1160. SYSCALL_MAP (setrlimit);
  1161. SYSCALL_MAP (getrusage);
  1162. SYSCALL_MAP (umask);
  1163. SYSCALL_MAP (prctl);
  1164. SYSCALL_MAP (getcpu);
  1165. SYSCALL_MAP (gettimeofday);
  1166. SYSCALL_MAP (settimeofday);
  1167. SYSCALL_MAP (adjtimex);
  1168. SYSCALL_MAP (getpid);
  1169. SYSCALL_MAP (getppid);
  1170. SYSCALL_MAP (getuid);
  1171. SYSCALL_MAP (geteuid);
  1172. SYSCALL_MAP (getgid);
  1173. SYSCALL_MAP (getegid);
  1174. SYSCALL_MAP (gettid);
  1175. SYSCALL_MAP (sysinfo);
  1176. SYSCALL_MAP (mq_open);
  1177. SYSCALL_MAP (mq_unlink);
  1178. SYSCALL_MAP (mq_timedsend);
  1179. SYSCALL_MAP (mq_timedreceive);
  1180. SYSCALL_MAP (mq_notify);
  1181. SYSCALL_MAP (mq_getsetattr);
  1182. SYSCALL_MAP (msgget);
  1183. SYSCALL_MAP (msgctl);
  1184. SYSCALL_MAP (msgrcv);
  1185. SYSCALL_MAP (msgsnd);
  1186. SYSCALL_MAP (semget);
  1187. SYSCALL_MAP (semctl);
  1188. SYSCALL_MAP (semtimedop);
  1189. SYSCALL_MAP (semop);
  1190. SYSCALL_MAP (shmget);
  1191. SYSCALL_MAP (shmctl);
  1192. SYSCALL_MAP (shmat);
  1193. SYSCALL_MAP (shmdt);
  1194. SYSCALL_MAP (socket);
  1195. SYSCALL_MAP (socketpair);
  1196. SYSCALL_MAP (bind);
  1197. SYSCALL_MAP (listen);
  1198. SYSCALL_MAP (accept);
  1199. SYSCALL_MAP (connect);
  1200. SYSCALL_MAP (getsockname);
  1201. SYSCALL_MAP (getpeername);
  1202. SYSCALL_MAP (sendto);
  1203. SYSCALL_MAP (recvfrom);
  1204. SYSCALL_MAP (setsockopt);
  1205. SYSCALL_MAP (getsockopt);
  1206. SYSCALL_MAP (shutdown);
  1207. SYSCALL_MAP (sendmsg);
  1208. SYSCALL_MAP (recvmsg);
  1209. SYSCALL_MAP (readahead);
  1210. SYSCALL_MAP (brk);
  1211. SYSCALL_MAP (munmap);
  1212. SYSCALL_MAP (mremap);
  1213. SYSCALL_MAP (add_key);
  1214. SYSCALL_MAP (request_key);
  1215. SYSCALL_MAP (keyctl);
  1216. SYSCALL_MAP (clone);
  1217. SYSCALL_MAP (execve);
  1218. case aarch64_sys_mmap:
  1219. return gdb_sys_mmap2;
  1220. SYSCALL_MAP (fadvise64);
  1221. SYSCALL_MAP (swapon);
  1222. SYSCALL_MAP (swapoff);
  1223. SYSCALL_MAP (mprotect);
  1224. SYSCALL_MAP (msync);
  1225. SYSCALL_MAP (mlock);
  1226. SYSCALL_MAP (munlock);
  1227. SYSCALL_MAP (mlockall);
  1228. SYSCALL_MAP (munlockall);
  1229. SYSCALL_MAP (mincore);
  1230. SYSCALL_MAP (madvise);
  1231. SYSCALL_MAP (remap_file_pages);
  1232. SYSCALL_MAP (mbind);
  1233. SYSCALL_MAP (get_mempolicy);
  1234. SYSCALL_MAP (set_mempolicy);
  1235. SYSCALL_MAP (migrate_pages);
  1236. SYSCALL_MAP (move_pages);
  1237. UNSUPPORTED_SYSCALL_MAP (rt_tgsigqueueinfo);
  1238. UNSUPPORTED_SYSCALL_MAP (perf_event_open);
  1239. UNSUPPORTED_SYSCALL_MAP (accept4);
  1240. UNSUPPORTED_SYSCALL_MAP (recvmmsg);
  1241. SYSCALL_MAP (wait4);
  1242. UNSUPPORTED_SYSCALL_MAP (prlimit64);
  1243. UNSUPPORTED_SYSCALL_MAP (fanotify_init);
  1244. UNSUPPORTED_SYSCALL_MAP (fanotify_mark);
  1245. UNSUPPORTED_SYSCALL_MAP (name_to_handle_at);
  1246. UNSUPPORTED_SYSCALL_MAP (open_by_handle_at);
  1247. UNSUPPORTED_SYSCALL_MAP (clock_adjtime);
  1248. UNSUPPORTED_SYSCALL_MAP (syncfs);
  1249. UNSUPPORTED_SYSCALL_MAP (setns);
  1250. UNSUPPORTED_SYSCALL_MAP (sendmmsg);
  1251. UNSUPPORTED_SYSCALL_MAP (process_vm_readv);
  1252. UNSUPPORTED_SYSCALL_MAP (process_vm_writev);
  1253. UNSUPPORTED_SYSCALL_MAP (kcmp);
  1254. UNSUPPORTED_SYSCALL_MAP (finit_module);
  1255. UNSUPPORTED_SYSCALL_MAP (sched_setattr);
  1256. UNSUPPORTED_SYSCALL_MAP (sched_getattr);
  1257. default:
  1258. return gdb_sys_no_syscall;
  1259. }
  1260. }
  1261. /* Retrieve the syscall number at a ptrace syscall-stop, either on syscall entry
  1262. or exit. Return -1 upon error. */
  1263. static LONGEST
  1264. aarch64_linux_get_syscall_number (struct gdbarch *gdbarch, thread_info *thread)
  1265. {
  1266. struct regcache *regs = get_thread_regcache (thread);
  1267. LONGEST ret;
  1268. /* Get the system call number from register x8. */
  1269. regs->cooked_read (AARCH64_X0_REGNUM + 8, &ret);
  1270. /* On exit from a successful execve, we will be in a new process and all the
  1271. registers will be cleared - x0 to x30 will be 0, except for a 1 in x7.
  1272. This function will only ever get called when stopped at the entry or exit
  1273. of a syscall, so by checking for 0 in x0 (arg0/retval), x1 (arg1), x8
  1274. (syscall), x29 (FP) and x30 (LR) we can infer:
  1275. 1) Either inferior is at exit from successful execve.
  1276. 2) Or inferior is at entry to a call to io_setup with invalid arguments and
  1277. a corrupted FP and LR.
  1278. It should be safe enough to assume case 1. */
  1279. if (ret == 0)
  1280. {
  1281. LONGEST x1 = -1, fp = -1, lr = -1;
  1282. regs->cooked_read (AARCH64_X0_REGNUM + 1, &x1);
  1283. regs->cooked_read (AARCH64_FP_REGNUM, &fp);
  1284. regs->cooked_read (AARCH64_LR_REGNUM, &lr);
  1285. if (x1 == 0 && fp ==0 && lr == 0)
  1286. return aarch64_sys_execve;
  1287. }
  1288. return ret;
  1289. }
  1290. /* Record all registers but PC register for process-record. */
  1291. static int
  1292. aarch64_all_but_pc_registers_record (struct regcache *regcache)
  1293. {
  1294. int i;
  1295. for (i = AARCH64_X0_REGNUM; i < AARCH64_PC_REGNUM; i++)
  1296. if (record_full_arch_list_add_reg (regcache, i))
  1297. return -1;
  1298. if (record_full_arch_list_add_reg (regcache, AARCH64_CPSR_REGNUM))
  1299. return -1;
  1300. return 0;
  1301. }
  1302. /* Handler for aarch64 system call instruction recording. */
  1303. static int
  1304. aarch64_linux_syscall_record (struct regcache *regcache,
  1305. unsigned long svc_number)
  1306. {
  1307. int ret = 0;
  1308. enum gdb_syscall syscall_gdb;
  1309. syscall_gdb =
  1310. aarch64_canonicalize_syscall ((enum aarch64_syscall) svc_number);
  1311. if (syscall_gdb < 0)
  1312. {
  1313. gdb_printf (gdb_stderr,
  1314. _("Process record and replay target doesn't "
  1315. "support syscall number %s\n"),
  1316. plongest (svc_number));
  1317. return -1;
  1318. }
  1319. if (syscall_gdb == gdb_sys_sigreturn
  1320. || syscall_gdb == gdb_sys_rt_sigreturn)
  1321. {
  1322. if (aarch64_all_but_pc_registers_record (regcache))
  1323. return -1;
  1324. return 0;
  1325. }
  1326. ret = record_linux_system_call (syscall_gdb, regcache,
  1327. &aarch64_linux_record_tdep);
  1328. if (ret != 0)
  1329. return ret;
  1330. /* Record the return value of the system call. */
  1331. if (record_full_arch_list_add_reg (regcache, AARCH64_X0_REGNUM))
  1332. return -1;
  1333. /* Record LR. */
  1334. if (record_full_arch_list_add_reg (regcache, AARCH64_LR_REGNUM))
  1335. return -1;
  1336. /* Record CPSR. */
  1337. if (record_full_arch_list_add_reg (regcache, AARCH64_CPSR_REGNUM))
  1338. return -1;
  1339. return 0;
  1340. }
  1341. /* Implement the "gcc_target_options" gdbarch method. */
  1342. static std::string
  1343. aarch64_linux_gcc_target_options (struct gdbarch *gdbarch)
  1344. {
  1345. /* GCC doesn't know "-m64". */
  1346. return {};
  1347. }
  1348. /* Helper to get the allocation tag from a 64-bit ADDRESS.
  1349. Return the allocation tag if successful and nullopt otherwise. */
  1350. static gdb::optional<CORE_ADDR>
  1351. aarch64_mte_get_atag (CORE_ADDR address)
  1352. {
  1353. gdb::byte_vector tags;
  1354. /* Attempt to fetch the allocation tag. */
  1355. if (!target_fetch_memtags (address, 1, tags,
  1356. static_cast<int> (memtag_type::allocation)))
  1357. return {};
  1358. /* Only one tag should've been returned. Make sure we got exactly that. */
  1359. if (tags.size () != 1)
  1360. error (_("Target returned an unexpected number of tags."));
  1361. /* Although our tags are 4 bits in size, they are stored in a
  1362. byte. */
  1363. return tags[0];
  1364. }
  1365. /* Implement the tagged_address_p gdbarch method. */
  1366. static bool
  1367. aarch64_linux_tagged_address_p (struct gdbarch *gdbarch, struct value *address)
  1368. {
  1369. gdb_assert (address != nullptr);
  1370. CORE_ADDR addr = value_as_address (address);
  1371. /* Remove the top byte for the memory range check. */
  1372. addr = address_significant (gdbarch, addr);
  1373. /* Check if the page that contains ADDRESS is mapped with PROT_MTE. */
  1374. if (!linux_address_in_memtag_page (addr))
  1375. return false;
  1376. /* We have a valid tag in the top byte of the 64-bit address. */
  1377. return true;
  1378. }
  1379. /* Implement the memtag_matches_p gdbarch method. */
  1380. static bool
  1381. aarch64_linux_memtag_matches_p (struct gdbarch *gdbarch,
  1382. struct value *address)
  1383. {
  1384. gdb_assert (address != nullptr);
  1385. /* Make sure we are dealing with a tagged address to begin with. */
  1386. if (!aarch64_linux_tagged_address_p (gdbarch, address))
  1387. return true;
  1388. CORE_ADDR addr = value_as_address (address);
  1389. /* Fetch the allocation tag for ADDRESS. */
  1390. gdb::optional<CORE_ADDR> atag
  1391. = aarch64_mte_get_atag (address_significant (gdbarch, addr));
  1392. if (!atag.has_value ())
  1393. return true;
  1394. /* Fetch the logical tag for ADDRESS. */
  1395. gdb_byte ltag = aarch64_mte_get_ltag (addr);
  1396. /* Are the tags the same? */
  1397. return ltag == *atag;
  1398. }
  1399. /* Implement the set_memtags gdbarch method. */
  1400. static bool
  1401. aarch64_linux_set_memtags (struct gdbarch *gdbarch, struct value *address,
  1402. size_t length, const gdb::byte_vector &tags,
  1403. memtag_type tag_type)
  1404. {
  1405. gdb_assert (!tags.empty ());
  1406. gdb_assert (address != nullptr);
  1407. CORE_ADDR addr = value_as_address (address);
  1408. /* Set the logical tag or the allocation tag. */
  1409. if (tag_type == memtag_type::logical)
  1410. {
  1411. /* When setting logical tags, we don't care about the length, since
  1412. we are only setting a single logical tag. */
  1413. addr = aarch64_mte_set_ltag (addr, tags[0]);
  1414. /* Update the value's content with the tag. */
  1415. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1416. gdb_byte *srcbuf = value_contents_raw (address).data ();
  1417. store_unsigned_integer (srcbuf, sizeof (addr), byte_order, addr);
  1418. }
  1419. else
  1420. {
  1421. /* Remove the top byte. */
  1422. addr = address_significant (gdbarch, addr);
  1423. /* Make sure we are dealing with a tagged address to begin with. */
  1424. if (!aarch64_linux_tagged_address_p (gdbarch, address))
  1425. return false;
  1426. /* With G being the number of tag granules and N the number of tags
  1427. passed in, we can have the following cases:
  1428. 1 - G == N: Store all the N tags to memory.
  1429. 2 - G < N : Warn about having more tags than granules, but write G
  1430. tags.
  1431. 3 - G > N : This is a "fill tags" operation. We should use the tags
  1432. as a pattern to fill the granules repeatedly until we have
  1433. written G tags to memory.
  1434. */
  1435. size_t g = aarch64_mte_get_tag_granules (addr, length,
  1436. AARCH64_MTE_GRANULE_SIZE);
  1437. size_t n = tags.size ();
  1438. if (g < n)
  1439. warning (_("Got more tags than memory granules. Tags will be "
  1440. "truncated."));
  1441. else if (g > n)
  1442. warning (_("Using tag pattern to fill memory range."));
  1443. if (!target_store_memtags (addr, length, tags,
  1444. static_cast<int> (memtag_type::allocation)))
  1445. return false;
  1446. }
  1447. return true;
  1448. }
  1449. /* Implement the get_memtag gdbarch method. */
  1450. static struct value *
  1451. aarch64_linux_get_memtag (struct gdbarch *gdbarch, struct value *address,
  1452. memtag_type tag_type)
  1453. {
  1454. gdb_assert (address != nullptr);
  1455. CORE_ADDR addr = value_as_address (address);
  1456. CORE_ADDR tag = 0;
  1457. /* Get the logical tag or the allocation tag. */
  1458. if (tag_type == memtag_type::logical)
  1459. tag = aarch64_mte_get_ltag (addr);
  1460. else
  1461. {
  1462. /* Make sure we are dealing with a tagged address to begin with. */
  1463. if (!aarch64_linux_tagged_address_p (gdbarch, address))
  1464. return nullptr;
  1465. /* Remove the top byte. */
  1466. addr = address_significant (gdbarch, addr);
  1467. gdb::optional<CORE_ADDR> atag = aarch64_mte_get_atag (addr);
  1468. if (!atag.has_value ())
  1469. return nullptr;
  1470. tag = *atag;
  1471. }
  1472. /* Convert the tag to a value. */
  1473. return value_from_ulongest (builtin_type (gdbarch)->builtin_unsigned_int,
  1474. tag);
  1475. }
  1476. /* Implement the memtag_to_string gdbarch method. */
  1477. static std::string
  1478. aarch64_linux_memtag_to_string (struct gdbarch *gdbarch, struct value *tag_value)
  1479. {
  1480. if (tag_value == nullptr)
  1481. return "";
  1482. CORE_ADDR tag = value_as_address (tag_value);
  1483. return string_printf ("0x%s", phex_nz (tag, sizeof (tag)));
  1484. }
  1485. /* AArch64 Linux implementation of the report_signal_info gdbarch
  1486. hook. Displays information about possible memory tag violations. */
  1487. static void
  1488. aarch64_linux_report_signal_info (struct gdbarch *gdbarch,
  1489. struct ui_out *uiout,
  1490. enum gdb_signal siggnal)
  1491. {
  1492. aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  1493. if (!tdep->has_mte () || siggnal != GDB_SIGNAL_SEGV)
  1494. return;
  1495. CORE_ADDR fault_addr = 0;
  1496. long si_code = 0;
  1497. try
  1498. {
  1499. /* Sigcode tells us if the segfault is actually a memory tag
  1500. violation. */
  1501. si_code = parse_and_eval_long ("$_siginfo.si_code");
  1502. fault_addr
  1503. = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr");
  1504. }
  1505. catch (const gdb_exception_error &exception)
  1506. {
  1507. exception_print (gdb_stderr, exception);
  1508. return;
  1509. }
  1510. /* If this is not a memory tag violation, just return. */
  1511. if (si_code != SEGV_MTEAERR && si_code != SEGV_MTESERR)
  1512. return;
  1513. uiout->text ("\n");
  1514. uiout->field_string ("sigcode-meaning", _("Memory tag violation"));
  1515. /* For synchronous faults, show additional information. */
  1516. if (si_code == SEGV_MTESERR)
  1517. {
  1518. uiout->text (_(" while accessing address "));
  1519. uiout->field_core_addr ("fault-addr", gdbarch, fault_addr);
  1520. uiout->text ("\n");
  1521. gdb::optional<CORE_ADDR> atag
  1522. = aarch64_mte_get_atag (address_significant (gdbarch, fault_addr));
  1523. gdb_byte ltag = aarch64_mte_get_ltag (fault_addr);
  1524. if (!atag.has_value ())
  1525. uiout->text (_("Allocation tag unavailable"));
  1526. else
  1527. {
  1528. uiout->text (_("Allocation tag "));
  1529. uiout->field_string ("allocation-tag", hex_string (*atag));
  1530. uiout->text ("\n");
  1531. uiout->text (_("Logical tag "));
  1532. uiout->field_string ("logical-tag", hex_string (ltag));
  1533. }
  1534. }
  1535. else
  1536. {
  1537. uiout->text ("\n");
  1538. uiout->text (_("Fault address unavailable"));
  1539. }
  1540. }
  1541. static void
  1542. aarch64_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
  1543. {
  1544. static const char *const stap_integer_prefixes[] = { "#", "", NULL };
  1545. static const char *const stap_register_prefixes[] = { "", NULL };
  1546. static const char *const stap_register_indirection_prefixes[] = { "[",
  1547. NULL };
  1548. static const char *const stap_register_indirection_suffixes[] = { "]",
  1549. NULL };
  1550. aarch64_gdbarch_tdep *tdep = (aarch64_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  1551. tdep->lowest_pc = 0x8000;
  1552. linux_init_abi (info, gdbarch, 1);
  1553. set_solib_svr4_fetch_link_map_offsets (gdbarch,
  1554. linux_lp64_fetch_link_map_offsets);
  1555. /* Enable TLS support. */
  1556. set_gdbarch_fetch_tls_load_module_address (gdbarch,
  1557. svr4_fetch_objfile_link_map);
  1558. /* Shared library handling. */
  1559. set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
  1560. set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
  1561. tramp_frame_prepend_unwinder (gdbarch, &aarch64_linux_rt_sigframe);
  1562. /* Enable longjmp. */
  1563. tdep->jb_pc = 11;
  1564. set_gdbarch_iterate_over_regset_sections
  1565. (gdbarch, aarch64_linux_iterate_over_regset_sections);
  1566. set_gdbarch_core_read_description
  1567. (gdbarch, aarch64_linux_core_read_description);
  1568. /* SystemTap related. */
  1569. set_gdbarch_stap_integer_prefixes (gdbarch, stap_integer_prefixes);
  1570. set_gdbarch_stap_register_prefixes (gdbarch, stap_register_prefixes);
  1571. set_gdbarch_stap_register_indirection_prefixes (gdbarch,
  1572. stap_register_indirection_prefixes);
  1573. set_gdbarch_stap_register_indirection_suffixes (gdbarch,
  1574. stap_register_indirection_suffixes);
  1575. set_gdbarch_stap_is_single_operand (gdbarch, aarch64_stap_is_single_operand);
  1576. set_gdbarch_stap_parse_special_token (gdbarch,
  1577. aarch64_stap_parse_special_token);
  1578. /* Reversible debugging, process record. */
  1579. set_gdbarch_process_record (gdbarch, aarch64_process_record);
  1580. /* Syscall record. */
  1581. tdep->aarch64_syscall_record = aarch64_linux_syscall_record;
  1582. /* The top byte of a user space address known as the "tag",
  1583. is ignored by the kernel and can be regarded as additional
  1584. data associated with the address. */
  1585. set_gdbarch_significant_addr_bit (gdbarch, 56);
  1586. /* MTE-specific settings and hooks. */
  1587. if (tdep->has_mte ())
  1588. {
  1589. /* Register a hook for checking if an address is tagged or not. */
  1590. set_gdbarch_tagged_address_p (gdbarch, aarch64_linux_tagged_address_p);
  1591. /* Register a hook for checking if there is a memory tag match. */
  1592. set_gdbarch_memtag_matches_p (gdbarch,
  1593. aarch64_linux_memtag_matches_p);
  1594. /* Register a hook for setting the logical/allocation tags for
  1595. a range of addresses. */
  1596. set_gdbarch_set_memtags (gdbarch, aarch64_linux_set_memtags);
  1597. /* Register a hook for extracting the logical/allocation tag from an
  1598. address. */
  1599. set_gdbarch_get_memtag (gdbarch, aarch64_linux_get_memtag);
  1600. /* Set the allocation tag granule size to 16 bytes. */
  1601. set_gdbarch_memtag_granule_size (gdbarch, AARCH64_MTE_GRANULE_SIZE);
  1602. /* Register a hook for converting a memory tag to a string. */
  1603. set_gdbarch_memtag_to_string (gdbarch, aarch64_linux_memtag_to_string);
  1604. set_gdbarch_report_signal_info (gdbarch,
  1605. aarch64_linux_report_signal_info);
  1606. }
  1607. /* Initialize the aarch64_linux_record_tdep. */
  1608. /* These values are the size of the type that will be used in a system
  1609. call. They are obtained from Linux Kernel source. */
  1610. aarch64_linux_record_tdep.size_pointer
  1611. = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
  1612. aarch64_linux_record_tdep.size__old_kernel_stat = 32;
  1613. aarch64_linux_record_tdep.size_tms = 32;
  1614. aarch64_linux_record_tdep.size_loff_t = 8;
  1615. aarch64_linux_record_tdep.size_flock = 32;
  1616. aarch64_linux_record_tdep.size_oldold_utsname = 45;
  1617. aarch64_linux_record_tdep.size_ustat = 32;
  1618. aarch64_linux_record_tdep.size_old_sigaction = 32;
  1619. aarch64_linux_record_tdep.size_old_sigset_t = 8;
  1620. aarch64_linux_record_tdep.size_rlimit = 16;
  1621. aarch64_linux_record_tdep.size_rusage = 144;
  1622. aarch64_linux_record_tdep.size_timeval = 16;
  1623. aarch64_linux_record_tdep.size_timezone = 8;
  1624. aarch64_linux_record_tdep.size_old_gid_t = 2;
  1625. aarch64_linux_record_tdep.size_old_uid_t = 2;
  1626. aarch64_linux_record_tdep.size_fd_set = 128;
  1627. aarch64_linux_record_tdep.size_old_dirent = 280;
  1628. aarch64_linux_record_tdep.size_statfs = 120;
  1629. aarch64_linux_record_tdep.size_statfs64 = 120;
  1630. aarch64_linux_record_tdep.size_sockaddr = 16;
  1631. aarch64_linux_record_tdep.size_int
  1632. = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
  1633. aarch64_linux_record_tdep.size_long
  1634. = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
  1635. aarch64_linux_record_tdep.size_ulong
  1636. = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
  1637. aarch64_linux_record_tdep.size_msghdr = 56;
  1638. aarch64_linux_record_tdep.size_itimerval = 32;
  1639. aarch64_linux_record_tdep.size_stat = 144;
  1640. aarch64_linux_record_tdep.size_old_utsname = 325;
  1641. aarch64_linux_record_tdep.size_sysinfo = 112;
  1642. aarch64_linux_record_tdep.size_msqid_ds = 120;
  1643. aarch64_linux_record_tdep.size_shmid_ds = 112;
  1644. aarch64_linux_record_tdep.size_new_utsname = 390;
  1645. aarch64_linux_record_tdep.size_timex = 208;
  1646. aarch64_linux_record_tdep.size_mem_dqinfo = 24;
  1647. aarch64_linux_record_tdep.size_if_dqblk = 72;
  1648. aarch64_linux_record_tdep.size_fs_quota_stat = 80;
  1649. aarch64_linux_record_tdep.size_timespec = 16;
  1650. aarch64_linux_record_tdep.size_pollfd = 8;
  1651. aarch64_linux_record_tdep.size_NFS_FHSIZE = 32;
  1652. aarch64_linux_record_tdep.size_knfsd_fh = 132;
  1653. aarch64_linux_record_tdep.size_TASK_COMM_LEN = 16;
  1654. aarch64_linux_record_tdep.size_sigaction = 32;
  1655. aarch64_linux_record_tdep.size_sigset_t = 8;
  1656. aarch64_linux_record_tdep.size_siginfo_t = 128;
  1657. aarch64_linux_record_tdep.size_cap_user_data_t = 8;
  1658. aarch64_linux_record_tdep.size_stack_t = 24;
  1659. aarch64_linux_record_tdep.size_off_t = 8;
  1660. aarch64_linux_record_tdep.size_stat64 = 144;
  1661. aarch64_linux_record_tdep.size_gid_t = 4;
  1662. aarch64_linux_record_tdep.size_uid_t = 4;
  1663. aarch64_linux_record_tdep.size_PAGE_SIZE = 4096;
  1664. aarch64_linux_record_tdep.size_flock64 = 32;
  1665. aarch64_linux_record_tdep.size_user_desc = 16;
  1666. aarch64_linux_record_tdep.size_io_event = 32;
  1667. aarch64_linux_record_tdep.size_iocb = 64;
  1668. aarch64_linux_record_tdep.size_epoll_event = 12;
  1669. aarch64_linux_record_tdep.size_itimerspec = 32;
  1670. aarch64_linux_record_tdep.size_mq_attr = 64;
  1671. aarch64_linux_record_tdep.size_termios = 36;
  1672. aarch64_linux_record_tdep.size_termios2 = 44;
  1673. aarch64_linux_record_tdep.size_pid_t = 4;
  1674. aarch64_linux_record_tdep.size_winsize = 8;
  1675. aarch64_linux_record_tdep.size_serial_struct = 72;
  1676. aarch64_linux_record_tdep.size_serial_icounter_struct = 80;
  1677. aarch64_linux_record_tdep.size_hayes_esp_config = 12;
  1678. aarch64_linux_record_tdep.size_size_t = 8;
  1679. aarch64_linux_record_tdep.size_iovec = 16;
  1680. aarch64_linux_record_tdep.size_time_t = 8;
  1681. /* These values are the second argument of system call "sys_ioctl".
  1682. They are obtained from Linux Kernel source. */
  1683. aarch64_linux_record_tdep.ioctl_TCGETS = 0x5401;
  1684. aarch64_linux_record_tdep.ioctl_TCSETS = 0x5402;
  1685. aarch64_linux_record_tdep.ioctl_TCSETSW = 0x5403;
  1686. aarch64_linux_record_tdep.ioctl_TCSETSF = 0x5404;
  1687. aarch64_linux_record_tdep.ioctl_TCGETA = 0x5405;
  1688. aarch64_linux_record_tdep.ioctl_TCSETA = 0x5406;
  1689. aarch64_linux_record_tdep.ioctl_TCSETAW = 0x5407;
  1690. aarch64_linux_record_tdep.ioctl_TCSETAF = 0x5408;
  1691. aarch64_linux_record_tdep.ioctl_TCSBRK = 0x5409;
  1692. aarch64_linux_record_tdep.ioctl_TCXONC = 0x540a;
  1693. aarch64_linux_record_tdep.ioctl_TCFLSH = 0x540b;
  1694. aarch64_linux_record_tdep.ioctl_TIOCEXCL = 0x540c;
  1695. aarch64_linux_record_tdep.ioctl_TIOCNXCL = 0x540d;
  1696. aarch64_linux_record_tdep.ioctl_TIOCSCTTY = 0x540e;
  1697. aarch64_linux_record_tdep.ioctl_TIOCGPGRP = 0x540f;
  1698. aarch64_linux_record_tdep.ioctl_TIOCSPGRP = 0x5410;
  1699. aarch64_linux_record_tdep.ioctl_TIOCOUTQ = 0x5411;
  1700. aarch64_linux_record_tdep.ioctl_TIOCSTI = 0x5412;
  1701. aarch64_linux_record_tdep.ioctl_TIOCGWINSZ = 0x5413;
  1702. aarch64_linux_record_tdep.ioctl_TIOCSWINSZ = 0x5414;
  1703. aarch64_linux_record_tdep.ioctl_TIOCMGET = 0x5415;
  1704. aarch64_linux_record_tdep.ioctl_TIOCMBIS = 0x5416;
  1705. aarch64_linux_record_tdep.ioctl_TIOCMBIC = 0x5417;
  1706. aarch64_linux_record_tdep.ioctl_TIOCMSET = 0x5418;
  1707. aarch64_linux_record_tdep.ioctl_TIOCGSOFTCAR = 0x5419;
  1708. aarch64_linux_record_tdep.ioctl_TIOCSSOFTCAR = 0x541a;
  1709. aarch64_linux_record_tdep.ioctl_FIONREAD = 0x541b;
  1710. aarch64_linux_record_tdep.ioctl_TIOCINQ = 0x541b;
  1711. aarch64_linux_record_tdep.ioctl_TIOCLINUX = 0x541c;
  1712. aarch64_linux_record_tdep.ioctl_TIOCCONS = 0x541d;
  1713. aarch64_linux_record_tdep.ioctl_TIOCGSERIAL = 0x541e;
  1714. aarch64_linux_record_tdep.ioctl_TIOCSSERIAL = 0x541f;
  1715. aarch64_linux_record_tdep.ioctl_TIOCPKT = 0x5420;
  1716. aarch64_linux_record_tdep.ioctl_FIONBIO = 0x5421;
  1717. aarch64_linux_record_tdep.ioctl_TIOCNOTTY = 0x5422;
  1718. aarch64_linux_record_tdep.ioctl_TIOCSETD = 0x5423;
  1719. aarch64_linux_record_tdep.ioctl_TIOCGETD = 0x5424;
  1720. aarch64_linux_record_tdep.ioctl_TCSBRKP = 0x5425;
  1721. aarch64_linux_record_tdep.ioctl_TIOCTTYGSTRUCT = 0x5426;
  1722. aarch64_linux_record_tdep.ioctl_TIOCSBRK = 0x5427;
  1723. aarch64_linux_record_tdep.ioctl_TIOCCBRK = 0x5428;
  1724. aarch64_linux_record_tdep.ioctl_TIOCGSID = 0x5429;
  1725. aarch64_linux_record_tdep.ioctl_TCGETS2 = 0x802c542a;
  1726. aarch64_linux_record_tdep.ioctl_TCSETS2 = 0x402c542b;
  1727. aarch64_linux_record_tdep.ioctl_TCSETSW2 = 0x402c542c;
  1728. aarch64_linux_record_tdep.ioctl_TCSETSF2 = 0x402c542d;
  1729. aarch64_linux_record_tdep.ioctl_TIOCGPTN = 0x80045430;
  1730. aarch64_linux_record_tdep.ioctl_TIOCSPTLCK = 0x40045431;
  1731. aarch64_linux_record_tdep.ioctl_FIONCLEX = 0x5450;
  1732. aarch64_linux_record_tdep.ioctl_FIOCLEX = 0x5451;
  1733. aarch64_linux_record_tdep.ioctl_FIOASYNC = 0x5452;
  1734. aarch64_linux_record_tdep.ioctl_TIOCSERCONFIG = 0x5453;
  1735. aarch64_linux_record_tdep.ioctl_TIOCSERGWILD = 0x5454;
  1736. aarch64_linux_record_tdep.ioctl_TIOCSERSWILD = 0x5455;
  1737. aarch64_linux_record_tdep.ioctl_TIOCGLCKTRMIOS = 0x5456;
  1738. aarch64_linux_record_tdep.ioctl_TIOCSLCKTRMIOS = 0x5457;
  1739. aarch64_linux_record_tdep.ioctl_TIOCSERGSTRUCT = 0x5458;
  1740. aarch64_linux_record_tdep.ioctl_TIOCSERGETLSR = 0x5459;
  1741. aarch64_linux_record_tdep.ioctl_TIOCSERGETMULTI = 0x545a;
  1742. aarch64_linux_record_tdep.ioctl_TIOCSERSETMULTI = 0x545b;
  1743. aarch64_linux_record_tdep.ioctl_TIOCMIWAIT = 0x545c;
  1744. aarch64_linux_record_tdep.ioctl_TIOCGICOUNT = 0x545d;
  1745. aarch64_linux_record_tdep.ioctl_TIOCGHAYESESP = 0x545e;
  1746. aarch64_linux_record_tdep.ioctl_TIOCSHAYESESP = 0x545f;
  1747. aarch64_linux_record_tdep.ioctl_FIOQSIZE = 0x5460;
  1748. /* These values are the second argument of system call "sys_fcntl"
  1749. and "sys_fcntl64". They are obtained from Linux Kernel source. */
  1750. aarch64_linux_record_tdep.fcntl_F_GETLK = 5;
  1751. aarch64_linux_record_tdep.fcntl_F_GETLK64 = 12;
  1752. aarch64_linux_record_tdep.fcntl_F_SETLK64 = 13;
  1753. aarch64_linux_record_tdep.fcntl_F_SETLKW64 = 14;
  1754. /* The AArch64 syscall calling convention: reg x0-x6 for arguments,
  1755. reg x8 for syscall number and return value in reg x0. */
  1756. aarch64_linux_record_tdep.arg1 = AARCH64_X0_REGNUM + 0;
  1757. aarch64_linux_record_tdep.arg2 = AARCH64_X0_REGNUM + 1;
  1758. aarch64_linux_record_tdep.arg3 = AARCH64_X0_REGNUM + 2;
  1759. aarch64_linux_record_tdep.arg4 = AARCH64_X0_REGNUM + 3;
  1760. aarch64_linux_record_tdep.arg5 = AARCH64_X0_REGNUM + 4;
  1761. aarch64_linux_record_tdep.arg6 = AARCH64_X0_REGNUM + 5;
  1762. aarch64_linux_record_tdep.arg7 = AARCH64_X0_REGNUM + 6;
  1763. /* `catch syscall' */
  1764. set_xml_syscall_file_name (gdbarch, "syscalls/aarch64-linux.xml");
  1765. set_gdbarch_get_syscall_number (gdbarch, aarch64_linux_get_syscall_number);
  1766. /* Displaced stepping. */
  1767. set_gdbarch_max_insn_length (gdbarch, 4 * AARCH64_DISPLACED_MODIFIED_INSNS);
  1768. set_gdbarch_displaced_step_copy_insn (gdbarch,
  1769. aarch64_displaced_step_copy_insn);
  1770. set_gdbarch_displaced_step_fixup (gdbarch, aarch64_displaced_step_fixup);
  1771. set_gdbarch_displaced_step_hw_singlestep (gdbarch,
  1772. aarch64_displaced_step_hw_singlestep);
  1773. set_gdbarch_gcc_target_options (gdbarch, aarch64_linux_gcc_target_options);
  1774. }
  1775. #if GDB_SELF_TEST
  1776. namespace selftests {
  1777. /* Verify functions to read and write logical tags. */
  1778. static void
  1779. aarch64_linux_ltag_tests (void)
  1780. {
  1781. /* We have 4 bits of tags, but we test writing all the bits of the top
  1782. byte of address. */
  1783. for (int i = 0; i < 1 << 8; i++)
  1784. {
  1785. CORE_ADDR addr = ((CORE_ADDR) i << 56) | 0xdeadbeef;
  1786. SELF_CHECK (aarch64_mte_get_ltag (addr) == (i & 0xf));
  1787. addr = aarch64_mte_set_ltag (0xdeadbeef, i);
  1788. SELF_CHECK (addr = ((CORE_ADDR) (i & 0xf) << 56) | 0xdeadbeef);
  1789. }
  1790. }
  1791. } // namespace selftests
  1792. #endif /* GDB_SELF_TEST */
  1793. void _initialize_aarch64_linux_tdep ();
  1794. void
  1795. _initialize_aarch64_linux_tdep ()
  1796. {
  1797. gdbarch_register_osabi (bfd_arch_aarch64, 0, GDB_OSABI_LINUX,
  1798. aarch64_linux_init_abi);
  1799. #if GDB_SELF_TEST
  1800. selftests::register_test ("aarch64-linux-tagged-address",
  1801. selftests::aarch64_linux_ltag_tests);
  1802. #endif
  1803. }