mips-linux-tdep.c 50 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655
  1. /* Target-dependent code for GNU/Linux on MIPS processors.
  2. Copyright (C) 2001-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 "gdbcore.h"
  16. #include "target.h"
  17. #include "solib-svr4.h"
  18. #include "osabi.h"
  19. #include "mips-tdep.h"
  20. #include "frame.h"
  21. #include "regcache.h"
  22. #include "trad-frame.h"
  23. #include "tramp-frame.h"
  24. #include "gdbtypes.h"
  25. #include "objfiles.h"
  26. #include "solib.h"
  27. #include "solist.h"
  28. #include "symtab.h"
  29. #include "target-descriptions.h"
  30. #include "regset.h"
  31. #include "mips-linux-tdep.h"
  32. #include "glibc-tdep.h"
  33. #include "linux-tdep.h"
  34. #include "xml-syscall.h"
  35. #include "gdbsupport/gdb_signals.h"
  36. #include "features/mips-linux.c"
  37. #include "features/mips-dsp-linux.c"
  38. #include "features/mips64-linux.c"
  39. #include "features/mips64-dsp-linux.c"
  40. static struct target_so_ops mips_svr4_so_ops;
  41. /* This enum represents the signals' numbers on the MIPS
  42. architecture. It just contains the signal definitions which are
  43. different from the generic implementation.
  44. It is derived from the file <arch/mips/include/uapi/asm/signal.h>,
  45. from the Linux kernel tree. */
  46. enum
  47. {
  48. MIPS_LINUX_SIGEMT = 7,
  49. MIPS_LINUX_SIGBUS = 10,
  50. MIPS_LINUX_SIGSYS = 12,
  51. MIPS_LINUX_SIGUSR1 = 16,
  52. MIPS_LINUX_SIGUSR2 = 17,
  53. MIPS_LINUX_SIGCHLD = 18,
  54. MIPS_LINUX_SIGCLD = MIPS_LINUX_SIGCHLD,
  55. MIPS_LINUX_SIGPWR = 19,
  56. MIPS_LINUX_SIGWINCH = 20,
  57. MIPS_LINUX_SIGURG = 21,
  58. MIPS_LINUX_SIGIO = 22,
  59. MIPS_LINUX_SIGPOLL = MIPS_LINUX_SIGIO,
  60. MIPS_LINUX_SIGSTOP = 23,
  61. MIPS_LINUX_SIGTSTP = 24,
  62. MIPS_LINUX_SIGCONT = 25,
  63. MIPS_LINUX_SIGTTIN = 26,
  64. MIPS_LINUX_SIGTTOU = 27,
  65. MIPS_LINUX_SIGVTALRM = 28,
  66. MIPS_LINUX_SIGPROF = 29,
  67. MIPS_LINUX_SIGXCPU = 30,
  68. MIPS_LINUX_SIGXFSZ = 31,
  69. MIPS_LINUX_SIGRTMIN = 32,
  70. MIPS_LINUX_SIGRT64 = 64,
  71. MIPS_LINUX_SIGRTMAX = 127,
  72. };
  73. /* Figure out where the longjmp will land.
  74. We expect the first arg to be a pointer to the jmp_buf structure
  75. from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
  76. at. The pc is copied into PC. This routine returns 1 on
  77. success. */
  78. #define MIPS_LINUX_JB_ELEMENT_SIZE 4
  79. #define MIPS_LINUX_JB_PC 0
  80. static int
  81. mips_linux_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
  82. {
  83. CORE_ADDR jb_addr;
  84. struct gdbarch *gdbarch = get_frame_arch (frame);
  85. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  86. gdb_byte buf[gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT];
  87. jb_addr = get_frame_register_unsigned (frame, MIPS_A0_REGNUM);
  88. if (target_read_memory ((jb_addr
  89. + MIPS_LINUX_JB_PC * MIPS_LINUX_JB_ELEMENT_SIZE),
  90. buf, gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
  91. return 0;
  92. *pc = extract_unsigned_integer (buf,
  93. gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT,
  94. byte_order);
  95. return 1;
  96. }
  97. /* Transform the bits comprising a 32-bit register to the right size
  98. for regcache_raw_supply(). This is needed when mips_isa_regsize()
  99. is 8. */
  100. static void
  101. supply_32bit_reg (struct regcache *regcache, int regnum, const void *addr)
  102. {
  103. regcache->raw_supply_integer (regnum, (const gdb_byte *) addr, 4, true);
  104. }
  105. /* Unpack an elf_gregset_t into GDB's register cache. */
  106. void
  107. mips_supply_gregset (struct regcache *regcache,
  108. const mips_elf_gregset_t *gregsetp)
  109. {
  110. int regi;
  111. const mips_elf_greg_t *regp = *gregsetp;
  112. struct gdbarch *gdbarch = regcache->arch ();
  113. for (regi = EF_REG0 + 1; regi <= EF_REG31; regi++)
  114. supply_32bit_reg (regcache, regi - EF_REG0, regp + regi);
  115. if (mips_linux_restart_reg_p (gdbarch))
  116. supply_32bit_reg (regcache, MIPS_RESTART_REGNUM, regp + EF_REG0);
  117. supply_32bit_reg (regcache, mips_regnum (gdbarch)->lo, regp + EF_LO);
  118. supply_32bit_reg (regcache, mips_regnum (gdbarch)->hi, regp + EF_HI);
  119. supply_32bit_reg (regcache, mips_regnum (gdbarch)->pc,
  120. regp + EF_CP0_EPC);
  121. supply_32bit_reg (regcache, mips_regnum (gdbarch)->badvaddr,
  122. regp + EF_CP0_BADVADDR);
  123. supply_32bit_reg (regcache, MIPS_PS_REGNUM, regp + EF_CP0_STATUS);
  124. supply_32bit_reg (regcache, mips_regnum (gdbarch)->cause,
  125. regp + EF_CP0_CAUSE);
  126. /* Fill the inaccessible zero register with zero. */
  127. regcache->raw_supply_zeroed (MIPS_ZERO_REGNUM);
  128. }
  129. static void
  130. mips_supply_gregset_wrapper (const struct regset *regset,
  131. struct regcache *regcache,
  132. int regnum, const void *gregs, size_t len)
  133. {
  134. gdb_assert (len >= sizeof (mips_elf_gregset_t));
  135. mips_supply_gregset (regcache, (const mips_elf_gregset_t *)gregs);
  136. }
  137. /* Pack our registers (or one register) into an elf_gregset_t. */
  138. void
  139. mips_fill_gregset (const struct regcache *regcache,
  140. mips_elf_gregset_t *gregsetp, int regno)
  141. {
  142. struct gdbarch *gdbarch = regcache->arch ();
  143. int regaddr, regi;
  144. mips_elf_greg_t *regp = *gregsetp;
  145. void *dst;
  146. if (regno == -1)
  147. {
  148. memset (regp, 0, sizeof (mips_elf_gregset_t));
  149. for (regi = 1; regi < 32; regi++)
  150. mips_fill_gregset (regcache, gregsetp, regi);
  151. mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->lo);
  152. mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->hi);
  153. mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->pc);
  154. mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->badvaddr);
  155. mips_fill_gregset (regcache, gregsetp, MIPS_PS_REGNUM);
  156. mips_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->cause);
  157. mips_fill_gregset (regcache, gregsetp, MIPS_RESTART_REGNUM);
  158. return;
  159. }
  160. if (regno > 0 && regno < 32)
  161. {
  162. dst = regp + regno + EF_REG0;
  163. regcache->raw_collect (regno, dst);
  164. return;
  165. }
  166. if (regno == mips_regnum (gdbarch)->lo)
  167. regaddr = EF_LO;
  168. else if (regno == mips_regnum (gdbarch)->hi)
  169. regaddr = EF_HI;
  170. else if (regno == mips_regnum (gdbarch)->pc)
  171. regaddr = EF_CP0_EPC;
  172. else if (regno == mips_regnum (gdbarch)->badvaddr)
  173. regaddr = EF_CP0_BADVADDR;
  174. else if (regno == MIPS_PS_REGNUM)
  175. regaddr = EF_CP0_STATUS;
  176. else if (regno == mips_regnum (gdbarch)->cause)
  177. regaddr = EF_CP0_CAUSE;
  178. else if (mips_linux_restart_reg_p (gdbarch)
  179. && regno == MIPS_RESTART_REGNUM)
  180. regaddr = EF_REG0;
  181. else
  182. regaddr = -1;
  183. if (regaddr != -1)
  184. {
  185. dst = regp + regaddr;
  186. regcache->raw_collect (regno, dst);
  187. }
  188. }
  189. static void
  190. mips_fill_gregset_wrapper (const struct regset *regset,
  191. const struct regcache *regcache,
  192. int regnum, void *gregs, size_t len)
  193. {
  194. gdb_assert (len >= sizeof (mips_elf_gregset_t));
  195. mips_fill_gregset (regcache, (mips_elf_gregset_t *)gregs, regnum);
  196. }
  197. /* Support for 64-bit ABIs. */
  198. /* Figure out where the longjmp will land.
  199. We expect the first arg to be a pointer to the jmp_buf structure
  200. from which we extract the pc (MIPS_LINUX_JB_PC) that we will land
  201. at. The pc is copied into PC. This routine returns 1 on
  202. success. */
  203. /* Details about jmp_buf. */
  204. #define MIPS64_LINUX_JB_PC 0
  205. static int
  206. mips64_linux_get_longjmp_target (struct frame_info *frame, CORE_ADDR *pc)
  207. {
  208. CORE_ADDR jb_addr;
  209. struct gdbarch *gdbarch = get_frame_arch (frame);
  210. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  211. gdb_byte *buf
  212. = (gdb_byte *) alloca (gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT);
  213. int element_size = gdbarch_ptr_bit (gdbarch) == 32 ? 4 : 8;
  214. jb_addr = get_frame_register_unsigned (frame, MIPS_A0_REGNUM);
  215. if (target_read_memory (jb_addr + MIPS64_LINUX_JB_PC * element_size,
  216. buf,
  217. gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT))
  218. return 0;
  219. *pc = extract_unsigned_integer (buf,
  220. gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT,
  221. byte_order);
  222. return 1;
  223. }
  224. /* Register set support functions. These operate on standard 64-bit
  225. regsets, but work whether the target is 32-bit or 64-bit. A 32-bit
  226. target will still use the 64-bit format for PTRACE_GETREGS. */
  227. /* Supply a 64-bit register. */
  228. static void
  229. supply_64bit_reg (struct regcache *regcache, int regnum,
  230. const gdb_byte *buf)
  231. {
  232. struct gdbarch *gdbarch = regcache->arch ();
  233. if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG
  234. && register_size (gdbarch, regnum) == 4)
  235. regcache->raw_supply (regnum, buf + 4);
  236. else
  237. regcache->raw_supply (regnum, buf);
  238. }
  239. /* Unpack a 64-bit elf_gregset_t into GDB's register cache. */
  240. void
  241. mips64_supply_gregset (struct regcache *regcache,
  242. const mips64_elf_gregset_t *gregsetp)
  243. {
  244. int regi;
  245. const mips64_elf_greg_t *regp = *gregsetp;
  246. struct gdbarch *gdbarch = regcache->arch ();
  247. for (regi = MIPS64_EF_REG0 + 1; regi <= MIPS64_EF_REG31; regi++)
  248. supply_64bit_reg (regcache, regi - MIPS64_EF_REG0,
  249. (const gdb_byte *) (regp + regi));
  250. if (mips_linux_restart_reg_p (gdbarch))
  251. supply_64bit_reg (regcache, MIPS_RESTART_REGNUM,
  252. (const gdb_byte *) (regp + MIPS64_EF_REG0));
  253. supply_64bit_reg (regcache, mips_regnum (gdbarch)->lo,
  254. (const gdb_byte *) (regp + MIPS64_EF_LO));
  255. supply_64bit_reg (regcache, mips_regnum (gdbarch)->hi,
  256. (const gdb_byte *) (regp + MIPS64_EF_HI));
  257. supply_64bit_reg (regcache, mips_regnum (gdbarch)->pc,
  258. (const gdb_byte *) (regp + MIPS64_EF_CP0_EPC));
  259. supply_64bit_reg (regcache, mips_regnum (gdbarch)->badvaddr,
  260. (const gdb_byte *) (regp + MIPS64_EF_CP0_BADVADDR));
  261. supply_64bit_reg (regcache, MIPS_PS_REGNUM,
  262. (const gdb_byte *) (regp + MIPS64_EF_CP0_STATUS));
  263. supply_64bit_reg (regcache, mips_regnum (gdbarch)->cause,
  264. (const gdb_byte *) (regp + MIPS64_EF_CP0_CAUSE));
  265. /* Fill the inaccessible zero register with zero. */
  266. regcache->raw_supply_zeroed (MIPS_ZERO_REGNUM);
  267. }
  268. static void
  269. mips64_supply_gregset_wrapper (const struct regset *regset,
  270. struct regcache *regcache,
  271. int regnum, const void *gregs, size_t len)
  272. {
  273. gdb_assert (len >= sizeof (mips64_elf_gregset_t));
  274. mips64_supply_gregset (regcache, (const mips64_elf_gregset_t *)gregs);
  275. }
  276. /* Pack our registers (or one register) into a 64-bit elf_gregset_t. */
  277. void
  278. mips64_fill_gregset (const struct regcache *regcache,
  279. mips64_elf_gregset_t *gregsetp, int regno)
  280. {
  281. struct gdbarch *gdbarch = regcache->arch ();
  282. int regaddr, regi;
  283. mips64_elf_greg_t *regp = *gregsetp;
  284. void *dst;
  285. if (regno == -1)
  286. {
  287. memset (regp, 0, sizeof (mips64_elf_gregset_t));
  288. for (regi = 1; regi < 32; regi++)
  289. mips64_fill_gregset (regcache, gregsetp, regi);
  290. mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->lo);
  291. mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->hi);
  292. mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->pc);
  293. mips64_fill_gregset (regcache, gregsetp,
  294. mips_regnum (gdbarch)->badvaddr);
  295. mips64_fill_gregset (regcache, gregsetp, MIPS_PS_REGNUM);
  296. mips64_fill_gregset (regcache, gregsetp, mips_regnum (gdbarch)->cause);
  297. mips64_fill_gregset (regcache, gregsetp, MIPS_RESTART_REGNUM);
  298. return;
  299. }
  300. if (regno > 0 && regno < 32)
  301. regaddr = regno + MIPS64_EF_REG0;
  302. else if (regno == mips_regnum (gdbarch)->lo)
  303. regaddr = MIPS64_EF_LO;
  304. else if (regno == mips_regnum (gdbarch)->hi)
  305. regaddr = MIPS64_EF_HI;
  306. else if (regno == mips_regnum (gdbarch)->pc)
  307. regaddr = MIPS64_EF_CP0_EPC;
  308. else if (regno == mips_regnum (gdbarch)->badvaddr)
  309. regaddr = MIPS64_EF_CP0_BADVADDR;
  310. else if (regno == MIPS_PS_REGNUM)
  311. regaddr = MIPS64_EF_CP0_STATUS;
  312. else if (regno == mips_regnum (gdbarch)->cause)
  313. regaddr = MIPS64_EF_CP0_CAUSE;
  314. else if (mips_linux_restart_reg_p (gdbarch)
  315. && regno == MIPS_RESTART_REGNUM)
  316. regaddr = MIPS64_EF_REG0;
  317. else
  318. regaddr = -1;
  319. if (regaddr != -1)
  320. {
  321. dst = regp + regaddr;
  322. regcache->raw_collect_integer (regno, (gdb_byte *) dst, 8, true);
  323. }
  324. }
  325. static void
  326. mips64_fill_gregset_wrapper (const struct regset *regset,
  327. const struct regcache *regcache,
  328. int regnum, void *gregs, size_t len)
  329. {
  330. gdb_assert (len >= sizeof (mips64_elf_gregset_t));
  331. mips64_fill_gregset (regcache, (mips64_elf_gregset_t *)gregs, regnum);
  332. }
  333. /* Likewise, unpack an elf_fpregset_t. Linux only uses even-numbered
  334. FPR slots in the Status.FR=0 mode, storing even-odd FPR pairs as the
  335. SDC1 instruction would. When run on MIPS I architecture processors
  336. all FPR slots used to be used, unusually, holding the respective FPRs
  337. in the first 4 bytes, but that was corrected for consistency, with
  338. `linux-mips.org' (LMO) commit 42533948caac ("Major pile of FP emulator
  339. changes."), the fix corrected with LMO commit 849fa7a50dff ("R3k FPU
  340. ptrace() handling fixes."), and then broken and fixed over and over
  341. again, until last time fixed with commit 80cbfad79096 ("MIPS: Correct
  342. MIPS I FP context layout"). */
  343. void
  344. mips64_supply_fpregset (struct regcache *regcache,
  345. const mips64_elf_fpregset_t *fpregsetp)
  346. {
  347. struct gdbarch *gdbarch = regcache->arch ();
  348. int regi;
  349. if (register_size (gdbarch, gdbarch_fp0_regnum (gdbarch)) == 4)
  350. for (regi = 0; regi < 32; regi++)
  351. {
  352. const gdb_byte *reg_ptr
  353. = (const gdb_byte *) (*fpregsetp + (regi & ~1));
  354. if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1))
  355. reg_ptr += 4;
  356. regcache->raw_supply (gdbarch_fp0_regnum (gdbarch) + regi, reg_ptr);
  357. }
  358. else
  359. for (regi = 0; regi < 32; regi++)
  360. regcache->raw_supply (gdbarch_fp0_regnum (gdbarch) + regi,
  361. (const char *) (*fpregsetp + regi));
  362. supply_32bit_reg (regcache, mips_regnum (gdbarch)->fp_control_status,
  363. (const gdb_byte *) (*fpregsetp + 32));
  364. /* The ABI doesn't tell us how to supply FCRIR, and core dumps don't
  365. include it - but the result of PTRACE_GETFPREGS does. The best we
  366. can do is to assume that its value is present. */
  367. supply_32bit_reg (regcache,
  368. mips_regnum (gdbarch)->fp_implementation_revision,
  369. (const gdb_byte *) (*fpregsetp + 32) + 4);
  370. }
  371. static void
  372. mips64_supply_fpregset_wrapper (const struct regset *regset,
  373. struct regcache *regcache,
  374. int regnum, const void *gregs, size_t len)
  375. {
  376. gdb_assert (len >= sizeof (mips64_elf_fpregset_t));
  377. mips64_supply_fpregset (regcache, (const mips64_elf_fpregset_t *)gregs);
  378. }
  379. /* Likewise, pack one or all floating point registers into an
  380. elf_fpregset_t. See `mips_supply_fpregset' for an explanation
  381. of the layout. */
  382. void
  383. mips64_fill_fpregset (const struct regcache *regcache,
  384. mips64_elf_fpregset_t *fpregsetp, int regno)
  385. {
  386. struct gdbarch *gdbarch = regcache->arch ();
  387. gdb_byte *to;
  388. if ((regno >= gdbarch_fp0_regnum (gdbarch))
  389. && (regno < gdbarch_fp0_regnum (gdbarch) + 32))
  390. {
  391. if (register_size (gdbarch, regno) == 4)
  392. {
  393. int regi = regno - gdbarch_fp0_regnum (gdbarch);
  394. to = (gdb_byte *) (*fpregsetp + (regi & ~1));
  395. if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (regi & 1))
  396. to += 4;
  397. regcache->raw_collect (regno, to);
  398. }
  399. else
  400. {
  401. to = (gdb_byte *) (*fpregsetp + regno
  402. - gdbarch_fp0_regnum (gdbarch));
  403. regcache->raw_collect (regno, to);
  404. }
  405. }
  406. else if (regno == mips_regnum (gdbarch)->fp_control_status)
  407. {
  408. to = (gdb_byte *) (*fpregsetp + 32);
  409. regcache->raw_collect_integer (regno, to, 4, true);
  410. }
  411. else if (regno == mips_regnum (gdbarch)->fp_implementation_revision)
  412. {
  413. to = (gdb_byte *) (*fpregsetp + 32) + 4;
  414. regcache->raw_collect_integer (regno, to, 4, true);
  415. }
  416. else if (regno == -1)
  417. {
  418. int regi;
  419. for (regi = 0; regi < 32; regi++)
  420. mips64_fill_fpregset (regcache, fpregsetp,
  421. gdbarch_fp0_regnum (gdbarch) + regi);
  422. mips64_fill_fpregset (regcache, fpregsetp,
  423. mips_regnum (gdbarch)->fp_control_status);
  424. mips64_fill_fpregset (regcache, fpregsetp,
  425. mips_regnum (gdbarch)->fp_implementation_revision);
  426. }
  427. }
  428. static void
  429. mips64_fill_fpregset_wrapper (const struct regset *regset,
  430. const struct regcache *regcache,
  431. int regnum, void *gregs, size_t len)
  432. {
  433. gdb_assert (len >= sizeof (mips64_elf_fpregset_t));
  434. mips64_fill_fpregset (regcache, (mips64_elf_fpregset_t *)gregs, regnum);
  435. }
  436. static const struct regset mips_linux_gregset =
  437. {
  438. NULL, mips_supply_gregset_wrapper, mips_fill_gregset_wrapper
  439. };
  440. static const struct regset mips64_linux_gregset =
  441. {
  442. NULL, mips64_supply_gregset_wrapper, mips64_fill_gregset_wrapper
  443. };
  444. static const struct regset mips64_linux_fpregset =
  445. {
  446. NULL, mips64_supply_fpregset_wrapper, mips64_fill_fpregset_wrapper
  447. };
  448. static void
  449. mips_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
  450. iterate_over_regset_sections_cb *cb,
  451. void *cb_data,
  452. const struct regcache *regcache)
  453. {
  454. if (register_size (gdbarch, MIPS_ZERO_REGNUM) == 4)
  455. {
  456. cb (".reg", sizeof (mips_elf_gregset_t), sizeof (mips_elf_gregset_t),
  457. &mips_linux_gregset, NULL, cb_data);
  458. cb (".reg2", sizeof (mips64_elf_fpregset_t),
  459. sizeof (mips64_elf_fpregset_t), &mips64_linux_fpregset,
  460. NULL, cb_data);
  461. }
  462. else
  463. {
  464. cb (".reg", sizeof (mips64_elf_gregset_t), sizeof (mips64_elf_gregset_t),
  465. &mips64_linux_gregset, NULL, cb_data);
  466. cb (".reg2", sizeof (mips64_elf_fpregset_t),
  467. sizeof (mips64_elf_fpregset_t), &mips64_linux_fpregset,
  468. NULL, cb_data);
  469. }
  470. }
  471. static const struct target_desc *
  472. mips_linux_core_read_description (struct gdbarch *gdbarch,
  473. struct target_ops *target,
  474. bfd *abfd)
  475. {
  476. asection *section = bfd_get_section_by_name (abfd, ".reg");
  477. if (! section)
  478. return NULL;
  479. switch (bfd_section_size (section))
  480. {
  481. case sizeof (mips_elf_gregset_t):
  482. return mips_tdesc_gp32;
  483. case sizeof (mips64_elf_gregset_t):
  484. return mips_tdesc_gp64;
  485. default:
  486. return NULL;
  487. }
  488. }
  489. /* Check the code at PC for a dynamic linker lazy resolution stub.
  490. GNU ld for MIPS has put lazy resolution stubs into a ".MIPS.stubs"
  491. section uniformly since version 2.15. If the pc is in that section,
  492. then we are in such a stub. Before that ".stub" was used in 32-bit
  493. ELF binaries, however we do not bother checking for that since we
  494. have never had and that case should be extremely rare these days.
  495. Instead we pattern-match on the code generated by GNU ld. They look
  496. like this:
  497. lw t9,0x8010(gp)
  498. addu t7,ra
  499. jalr t9,ra
  500. addiu t8,zero,INDEX
  501. (with the appropriate doubleword instructions for N64). As any lazy
  502. resolution stubs in microMIPS binaries will always be in a
  503. ".MIPS.stubs" section we only ever verify standard MIPS patterns. */
  504. static int
  505. mips_linux_in_dynsym_stub (CORE_ADDR pc)
  506. {
  507. gdb_byte buf[28], *p;
  508. ULONGEST insn, insn1;
  509. int n64 = (mips_abi (target_gdbarch ()) == MIPS_ABI_N64);
  510. enum bfd_endian byte_order = gdbarch_byte_order (target_gdbarch ());
  511. if (in_mips_stubs_section (pc))
  512. return 1;
  513. read_memory (pc - 12, buf, 28);
  514. if (n64)
  515. {
  516. /* ld t9,0x8010(gp) */
  517. insn1 = 0xdf998010;
  518. }
  519. else
  520. {
  521. /* lw t9,0x8010(gp) */
  522. insn1 = 0x8f998010;
  523. }
  524. p = buf + 12;
  525. while (p >= buf)
  526. {
  527. insn = extract_unsigned_integer (p, 4, byte_order);
  528. if (insn == insn1)
  529. break;
  530. p -= 4;
  531. }
  532. if (p < buf)
  533. return 0;
  534. insn = extract_unsigned_integer (p + 4, 4, byte_order);
  535. if (n64)
  536. {
  537. /* 'daddu t7,ra' or 'or t7, ra, zero'*/
  538. if (insn != 0x03e0782d && insn != 0x03e07825)
  539. return 0;
  540. }
  541. else
  542. {
  543. /* 'addu t7,ra' or 'or t7, ra, zero'*/
  544. if (insn != 0x03e07821 && insn != 0x03e07825)
  545. return 0;
  546. }
  547. insn = extract_unsigned_integer (p + 8, 4, byte_order);
  548. /* jalr t9,ra */
  549. if (insn != 0x0320f809)
  550. return 0;
  551. insn = extract_unsigned_integer (p + 12, 4, byte_order);
  552. if (n64)
  553. {
  554. /* daddiu t8,zero,0 */
  555. if ((insn & 0xffff0000) != 0x64180000)
  556. return 0;
  557. }
  558. else
  559. {
  560. /* addiu t8,zero,0 */
  561. if ((insn & 0xffff0000) != 0x24180000)
  562. return 0;
  563. }
  564. return 1;
  565. }
  566. /* Return non-zero iff PC belongs to the dynamic linker resolution
  567. code, a PLT entry, or a lazy binding stub. */
  568. static int
  569. mips_linux_in_dynsym_resolve_code (CORE_ADDR pc)
  570. {
  571. /* Check whether PC is in the dynamic linker. This also checks
  572. whether it is in the .plt section, used by non-PIC executables. */
  573. if (svr4_in_dynsym_resolve_code (pc))
  574. return 1;
  575. /* Likewise for the stubs. They live in the .MIPS.stubs section these
  576. days, so we check if the PC is within, than fall back to a pattern
  577. match. */
  578. if (mips_linux_in_dynsym_stub (pc))
  579. return 1;
  580. return 0;
  581. }
  582. /* See the comments for SKIP_SOLIB_RESOLVER at the top of infrun.c,
  583. and glibc_skip_solib_resolver in glibc-tdep.c. The normal glibc
  584. implementation of this triggers at "fixup" from the same objfile as
  585. "_dl_runtime_resolve"; MIPS GNU/Linux can trigger at
  586. "__dl_runtime_resolve" directly. An unresolved lazy binding
  587. stub will point to _dl_runtime_resolve, which will first call
  588. __dl_runtime_resolve, and then pass control to the resolved
  589. function. */
  590. static CORE_ADDR
  591. mips_linux_skip_resolver (struct gdbarch *gdbarch, CORE_ADDR pc)
  592. {
  593. struct bound_minimal_symbol resolver;
  594. resolver = lookup_minimal_symbol ("__dl_runtime_resolve", NULL, NULL);
  595. if (resolver.minsym && BMSYMBOL_VALUE_ADDRESS (resolver) == pc)
  596. return frame_unwind_caller_pc (get_current_frame ());
  597. return glibc_skip_solib_resolver (gdbarch, pc);
  598. }
  599. /* Signal trampoline support. There are four supported layouts for a
  600. signal frame: o32 sigframe, o32 rt_sigframe, n32 rt_sigframe, and
  601. n64 rt_sigframe. We handle them all independently; not the most
  602. efficient way, but simplest. First, declare all the unwinders. */
  603. static void mips_linux_o32_sigframe_init (const struct tramp_frame *self,
  604. struct frame_info *this_frame,
  605. struct trad_frame_cache *this_cache,
  606. CORE_ADDR func);
  607. static void mips_linux_n32n64_sigframe_init (const struct tramp_frame *self,
  608. struct frame_info *this_frame,
  609. struct trad_frame_cache *this_cache,
  610. CORE_ADDR func);
  611. static int mips_linux_sigframe_validate (const struct tramp_frame *self,
  612. struct frame_info *this_frame,
  613. CORE_ADDR *pc);
  614. static int micromips_linux_sigframe_validate (const struct tramp_frame *self,
  615. struct frame_info *this_frame,
  616. CORE_ADDR *pc);
  617. #define MIPS_NR_LINUX 4000
  618. #define MIPS_NR_N64_LINUX 5000
  619. #define MIPS_NR_N32_LINUX 6000
  620. #define MIPS_NR_sigreturn MIPS_NR_LINUX + 119
  621. #define MIPS_NR_rt_sigreturn MIPS_NR_LINUX + 193
  622. #define MIPS_NR_N64_rt_sigreturn MIPS_NR_N64_LINUX + 211
  623. #define MIPS_NR_N32_rt_sigreturn MIPS_NR_N32_LINUX + 211
  624. #define MIPS_INST_LI_V0_SIGRETURN 0x24020000 + MIPS_NR_sigreturn
  625. #define MIPS_INST_LI_V0_RT_SIGRETURN 0x24020000 + MIPS_NR_rt_sigreturn
  626. #define MIPS_INST_LI_V0_N64_RT_SIGRETURN 0x24020000 + MIPS_NR_N64_rt_sigreturn
  627. #define MIPS_INST_LI_V0_N32_RT_SIGRETURN 0x24020000 + MIPS_NR_N32_rt_sigreturn
  628. #define MIPS_INST_SYSCALL 0x0000000c
  629. #define MICROMIPS_INST_LI_V0 0x3040
  630. #define MICROMIPS_INST_POOL32A 0x0000
  631. #define MICROMIPS_INST_SYSCALL 0x8b7c
  632. static const struct tramp_frame mips_linux_o32_sigframe = {
  633. SIGTRAMP_FRAME,
  634. 4,
  635. {
  636. { MIPS_INST_LI_V0_SIGRETURN, ULONGEST_MAX },
  637. { MIPS_INST_SYSCALL, ULONGEST_MAX },
  638. { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
  639. },
  640. mips_linux_o32_sigframe_init,
  641. mips_linux_sigframe_validate
  642. };
  643. static const struct tramp_frame mips_linux_o32_rt_sigframe = {
  644. SIGTRAMP_FRAME,
  645. 4,
  646. {
  647. { MIPS_INST_LI_V0_RT_SIGRETURN, ULONGEST_MAX },
  648. { MIPS_INST_SYSCALL, ULONGEST_MAX },
  649. { TRAMP_SENTINEL_INSN, ULONGEST_MAX } },
  650. mips_linux_o32_sigframe_init,
  651. mips_linux_sigframe_validate
  652. };
  653. static const struct tramp_frame mips_linux_n32_rt_sigframe = {
  654. SIGTRAMP_FRAME,
  655. 4,
  656. {
  657. { MIPS_INST_LI_V0_N32_RT_SIGRETURN, ULONGEST_MAX },
  658. { MIPS_INST_SYSCALL, ULONGEST_MAX },
  659. { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
  660. },
  661. mips_linux_n32n64_sigframe_init,
  662. mips_linux_sigframe_validate
  663. };
  664. static const struct tramp_frame mips_linux_n64_rt_sigframe = {
  665. SIGTRAMP_FRAME,
  666. 4,
  667. {
  668. { MIPS_INST_LI_V0_N64_RT_SIGRETURN, ULONGEST_MAX },
  669. { MIPS_INST_SYSCALL, ULONGEST_MAX },
  670. { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
  671. },
  672. mips_linux_n32n64_sigframe_init,
  673. mips_linux_sigframe_validate
  674. };
  675. static const struct tramp_frame micromips_linux_o32_sigframe = {
  676. SIGTRAMP_FRAME,
  677. 2,
  678. {
  679. { MICROMIPS_INST_LI_V0, ULONGEST_MAX },
  680. { MIPS_NR_sigreturn, ULONGEST_MAX },
  681. { MICROMIPS_INST_POOL32A, ULONGEST_MAX },
  682. { MICROMIPS_INST_SYSCALL, ULONGEST_MAX },
  683. { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
  684. },
  685. mips_linux_o32_sigframe_init,
  686. micromips_linux_sigframe_validate
  687. };
  688. static const struct tramp_frame micromips_linux_o32_rt_sigframe = {
  689. SIGTRAMP_FRAME,
  690. 2,
  691. {
  692. { MICROMIPS_INST_LI_V0, ULONGEST_MAX },
  693. { MIPS_NR_rt_sigreturn, ULONGEST_MAX },
  694. { MICROMIPS_INST_POOL32A, ULONGEST_MAX },
  695. { MICROMIPS_INST_SYSCALL, ULONGEST_MAX },
  696. { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
  697. },
  698. mips_linux_o32_sigframe_init,
  699. micromips_linux_sigframe_validate
  700. };
  701. static const struct tramp_frame micromips_linux_n32_rt_sigframe = {
  702. SIGTRAMP_FRAME,
  703. 2,
  704. {
  705. { MICROMIPS_INST_LI_V0, ULONGEST_MAX },
  706. { MIPS_NR_N32_rt_sigreturn, ULONGEST_MAX },
  707. { MICROMIPS_INST_POOL32A, ULONGEST_MAX },
  708. { MICROMIPS_INST_SYSCALL, ULONGEST_MAX },
  709. { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
  710. },
  711. mips_linux_n32n64_sigframe_init,
  712. micromips_linux_sigframe_validate
  713. };
  714. static const struct tramp_frame micromips_linux_n64_rt_sigframe = {
  715. SIGTRAMP_FRAME,
  716. 2,
  717. {
  718. { MICROMIPS_INST_LI_V0, ULONGEST_MAX },
  719. { MIPS_NR_N64_rt_sigreturn, ULONGEST_MAX },
  720. { MICROMIPS_INST_POOL32A, ULONGEST_MAX },
  721. { MICROMIPS_INST_SYSCALL, ULONGEST_MAX },
  722. { TRAMP_SENTINEL_INSN, ULONGEST_MAX }
  723. },
  724. mips_linux_n32n64_sigframe_init,
  725. micromips_linux_sigframe_validate
  726. };
  727. /* *INDENT-OFF* */
  728. /* The unwinder for o32 signal frames. The legacy structures look
  729. like this:
  730. struct sigframe {
  731. u32 sf_ass[4]; [argument save space for o32]
  732. u32 sf_code[2]; [signal trampoline or fill]
  733. struct sigcontext sf_sc;
  734. sigset_t sf_mask;
  735. };
  736. Pre-2.6.12 sigcontext:
  737. struct sigcontext {
  738. unsigned int sc_regmask; [Unused]
  739. unsigned int sc_status;
  740. unsigned long long sc_pc;
  741. unsigned long long sc_regs[32];
  742. unsigned long long sc_fpregs[32];
  743. unsigned int sc_ownedfp;
  744. unsigned int sc_fpc_csr;
  745. unsigned int sc_fpc_eir; [Unused]
  746. unsigned int sc_used_math;
  747. unsigned int sc_ssflags; [Unused]
  748. [Alignment hole of four bytes]
  749. unsigned long long sc_mdhi;
  750. unsigned long long sc_mdlo;
  751. unsigned int sc_cause; [Unused]
  752. unsigned int sc_badvaddr; [Unused]
  753. unsigned long sc_sigset[4]; [kernel's sigset_t]
  754. };
  755. Post-2.6.12 sigcontext (SmartMIPS/DSP support added):
  756. struct sigcontext {
  757. unsigned int sc_regmask; [Unused]
  758. unsigned int sc_status; [Unused]
  759. unsigned long long sc_pc;
  760. unsigned long long sc_regs[32];
  761. unsigned long long sc_fpregs[32];
  762. unsigned int sc_acx;
  763. unsigned int sc_fpc_csr;
  764. unsigned int sc_fpc_eir; [Unused]
  765. unsigned int sc_used_math;
  766. unsigned int sc_dsp;
  767. [Alignment hole of four bytes]
  768. unsigned long long sc_mdhi;
  769. unsigned long long sc_mdlo;
  770. unsigned long sc_hi1;
  771. unsigned long sc_lo1;
  772. unsigned long sc_hi2;
  773. unsigned long sc_lo2;
  774. unsigned long sc_hi3;
  775. unsigned long sc_lo3;
  776. };
  777. The RT signal frames look like this:
  778. struct rt_sigframe {
  779. u32 rs_ass[4]; [argument save space for o32]
  780. u32 rs_code[2] [signal trampoline or fill]
  781. struct siginfo rs_info;
  782. struct ucontext rs_uc;
  783. };
  784. struct ucontext {
  785. unsigned long uc_flags;
  786. struct ucontext *uc_link;
  787. stack_t uc_stack;
  788. [Alignment hole of four bytes]
  789. struct sigcontext uc_mcontext;
  790. sigset_t uc_sigmask;
  791. }; */
  792. /* *INDENT-ON* */
  793. #define SIGFRAME_SIGCONTEXT_OFFSET (6 * 4)
  794. #define RTSIGFRAME_SIGINFO_SIZE 128
  795. #define STACK_T_SIZE (3 * 4)
  796. #define UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + STACK_T_SIZE + 4)
  797. #define RTSIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
  798. + RTSIGFRAME_SIGINFO_SIZE \
  799. + UCONTEXT_SIGCONTEXT_OFFSET)
  800. #define SIGCONTEXT_PC (1 * 8)
  801. #define SIGCONTEXT_REGS (2 * 8)
  802. #define SIGCONTEXT_FPREGS (34 * 8)
  803. #define SIGCONTEXT_FPCSR (66 * 8 + 4)
  804. #define SIGCONTEXT_DSPCTL (68 * 8 + 0)
  805. #define SIGCONTEXT_HI (69 * 8)
  806. #define SIGCONTEXT_LO (70 * 8)
  807. #define SIGCONTEXT_CAUSE (71 * 8 + 0)
  808. #define SIGCONTEXT_BADVADDR (71 * 8 + 4)
  809. #define SIGCONTEXT_HI1 (71 * 8 + 0)
  810. #define SIGCONTEXT_LO1 (71 * 8 + 4)
  811. #define SIGCONTEXT_HI2 (72 * 8 + 0)
  812. #define SIGCONTEXT_LO2 (72 * 8 + 4)
  813. #define SIGCONTEXT_HI3 (73 * 8 + 0)
  814. #define SIGCONTEXT_LO3 (73 * 8 + 4)
  815. #define SIGCONTEXT_REG_SIZE 8
  816. static void
  817. mips_linux_o32_sigframe_init (const struct tramp_frame *self,
  818. struct frame_info *this_frame,
  819. struct trad_frame_cache *this_cache,
  820. CORE_ADDR func)
  821. {
  822. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  823. int ireg;
  824. CORE_ADDR frame_sp = get_frame_sp (this_frame);
  825. CORE_ADDR sigcontext_base;
  826. const struct mips_regnum *regs = mips_regnum (gdbarch);
  827. CORE_ADDR regs_base;
  828. if (self == &mips_linux_o32_sigframe
  829. || self == &micromips_linux_o32_sigframe)
  830. sigcontext_base = frame_sp + SIGFRAME_SIGCONTEXT_OFFSET;
  831. else
  832. sigcontext_base = frame_sp + RTSIGFRAME_SIGCONTEXT_OFFSET;
  833. /* I'm not proud of this hack. Eventually we will have the
  834. infrastructure to indicate the size of saved registers on a
  835. per-frame basis, but right now we don't; the kernel saves eight
  836. bytes but we only want four. Use regs_base to access any
  837. 64-bit fields. */
  838. if (gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG)
  839. regs_base = sigcontext_base + 4;
  840. else
  841. regs_base = sigcontext_base;
  842. if (mips_linux_restart_reg_p (gdbarch))
  843. trad_frame_set_reg_addr (this_cache,
  844. (MIPS_RESTART_REGNUM
  845. + gdbarch_num_regs (gdbarch)),
  846. regs_base + SIGCONTEXT_REGS);
  847. for (ireg = 1; ireg < 32; ireg++)
  848. trad_frame_set_reg_addr (this_cache,
  849. (ireg + MIPS_ZERO_REGNUM
  850. + gdbarch_num_regs (gdbarch)),
  851. (regs_base + SIGCONTEXT_REGS
  852. + ireg * SIGCONTEXT_REG_SIZE));
  853. for (ireg = 0; ireg < 32; ireg++)
  854. if ((gdbarch_byte_order (gdbarch) == BFD_ENDIAN_BIG) != (ireg & 1))
  855. trad_frame_set_reg_addr (this_cache,
  856. ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
  857. (sigcontext_base + SIGCONTEXT_FPREGS + 4
  858. + (ireg & ~1) * SIGCONTEXT_REG_SIZE));
  859. else
  860. trad_frame_set_reg_addr (this_cache,
  861. ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
  862. (sigcontext_base + SIGCONTEXT_FPREGS
  863. + (ireg & ~1) * SIGCONTEXT_REG_SIZE));
  864. trad_frame_set_reg_addr (this_cache,
  865. regs->pc + gdbarch_num_regs (gdbarch),
  866. regs_base + SIGCONTEXT_PC);
  867. trad_frame_set_reg_addr (this_cache,
  868. (regs->fp_control_status
  869. + gdbarch_num_regs (gdbarch)),
  870. sigcontext_base + SIGCONTEXT_FPCSR);
  871. if (regs->dspctl != -1)
  872. trad_frame_set_reg_addr (this_cache,
  873. regs->dspctl + gdbarch_num_regs (gdbarch),
  874. sigcontext_base + SIGCONTEXT_DSPCTL);
  875. trad_frame_set_reg_addr (this_cache,
  876. regs->hi + gdbarch_num_regs (gdbarch),
  877. regs_base + SIGCONTEXT_HI);
  878. trad_frame_set_reg_addr (this_cache,
  879. regs->lo + gdbarch_num_regs (gdbarch),
  880. regs_base + SIGCONTEXT_LO);
  881. if (regs->dspacc != -1)
  882. {
  883. trad_frame_set_reg_addr (this_cache,
  884. regs->dspacc + 0 + gdbarch_num_regs (gdbarch),
  885. sigcontext_base + SIGCONTEXT_HI1);
  886. trad_frame_set_reg_addr (this_cache,
  887. regs->dspacc + 1 + gdbarch_num_regs (gdbarch),
  888. sigcontext_base + SIGCONTEXT_LO1);
  889. trad_frame_set_reg_addr (this_cache,
  890. regs->dspacc + 2 + gdbarch_num_regs (gdbarch),
  891. sigcontext_base + SIGCONTEXT_HI2);
  892. trad_frame_set_reg_addr (this_cache,
  893. regs->dspacc + 3 + gdbarch_num_regs (gdbarch),
  894. sigcontext_base + SIGCONTEXT_LO2);
  895. trad_frame_set_reg_addr (this_cache,
  896. regs->dspacc + 4 + gdbarch_num_regs (gdbarch),
  897. sigcontext_base + SIGCONTEXT_HI3);
  898. trad_frame_set_reg_addr (this_cache,
  899. regs->dspacc + 5 + gdbarch_num_regs (gdbarch),
  900. sigcontext_base + SIGCONTEXT_LO3);
  901. }
  902. else
  903. {
  904. trad_frame_set_reg_addr (this_cache,
  905. regs->cause + gdbarch_num_regs (gdbarch),
  906. sigcontext_base + SIGCONTEXT_CAUSE);
  907. trad_frame_set_reg_addr (this_cache,
  908. regs->badvaddr + gdbarch_num_regs (gdbarch),
  909. sigcontext_base + SIGCONTEXT_BADVADDR);
  910. }
  911. /* Choice of the bottom of the sigframe is somewhat arbitrary. */
  912. trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
  913. }
  914. /* *INDENT-OFF* */
  915. /* For N32/N64 things look different. There is no non-rt signal frame.
  916. struct rt_sigframe_n32 {
  917. u32 rs_ass[4]; [ argument save space for o32 ]
  918. u32 rs_code[2]; [ signal trampoline or fill ]
  919. struct siginfo rs_info;
  920. struct ucontextn32 rs_uc;
  921. };
  922. struct ucontextn32 {
  923. u32 uc_flags;
  924. s32 uc_link;
  925. stack32_t uc_stack;
  926. struct sigcontext uc_mcontext;
  927. sigset_t uc_sigmask; [ mask last for extensibility ]
  928. };
  929. struct rt_sigframe {
  930. u32 rs_ass[4]; [ argument save space for o32 ]
  931. u32 rs_code[2]; [ signal trampoline ]
  932. struct siginfo rs_info;
  933. struct ucontext rs_uc;
  934. };
  935. struct ucontext {
  936. unsigned long uc_flags;
  937. struct ucontext *uc_link;
  938. stack_t uc_stack;
  939. struct sigcontext uc_mcontext;
  940. sigset_t uc_sigmask; [ mask last for extensibility ]
  941. };
  942. And the sigcontext is different (this is for both n32 and n64):
  943. struct sigcontext {
  944. unsigned long long sc_regs[32];
  945. unsigned long long sc_fpregs[32];
  946. unsigned long long sc_mdhi;
  947. unsigned long long sc_hi1;
  948. unsigned long long sc_hi2;
  949. unsigned long long sc_hi3;
  950. unsigned long long sc_mdlo;
  951. unsigned long long sc_lo1;
  952. unsigned long long sc_lo2;
  953. unsigned long long sc_lo3;
  954. unsigned long long sc_pc;
  955. unsigned int sc_fpc_csr;
  956. unsigned int sc_used_math;
  957. unsigned int sc_dsp;
  958. unsigned int sc_reserved;
  959. };
  960. That is the post-2.6.12 definition of the 64-bit sigcontext; before
  961. then, there were no hi1-hi3 or lo1-lo3. Cause and badvaddr were
  962. included too. */
  963. /* *INDENT-ON* */
  964. #define N32_STACK_T_SIZE STACK_T_SIZE
  965. #define N64_STACK_T_SIZE (2 * 8 + 4)
  966. #define N32_UCONTEXT_SIGCONTEXT_OFFSET (2 * 4 + N32_STACK_T_SIZE + 4)
  967. #define N64_UCONTEXT_SIGCONTEXT_OFFSET (2 * 8 + N64_STACK_T_SIZE + 4)
  968. #define N32_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
  969. + RTSIGFRAME_SIGINFO_SIZE \
  970. + N32_UCONTEXT_SIGCONTEXT_OFFSET)
  971. #define N64_SIGFRAME_SIGCONTEXT_OFFSET (SIGFRAME_SIGCONTEXT_OFFSET \
  972. + RTSIGFRAME_SIGINFO_SIZE \
  973. + N64_UCONTEXT_SIGCONTEXT_OFFSET)
  974. #define N64_SIGCONTEXT_REGS (0 * 8)
  975. #define N64_SIGCONTEXT_FPREGS (32 * 8)
  976. #define N64_SIGCONTEXT_HI (64 * 8)
  977. #define N64_SIGCONTEXT_HI1 (65 * 8)
  978. #define N64_SIGCONTEXT_HI2 (66 * 8)
  979. #define N64_SIGCONTEXT_HI3 (67 * 8)
  980. #define N64_SIGCONTEXT_LO (68 * 8)
  981. #define N64_SIGCONTEXT_LO1 (69 * 8)
  982. #define N64_SIGCONTEXT_LO2 (70 * 8)
  983. #define N64_SIGCONTEXT_LO3 (71 * 8)
  984. #define N64_SIGCONTEXT_PC (72 * 8)
  985. #define N64_SIGCONTEXT_FPCSR (73 * 8 + 0)
  986. #define N64_SIGCONTEXT_DSPCTL (74 * 8 + 0)
  987. #define N64_SIGCONTEXT_REG_SIZE 8
  988. static void
  989. mips_linux_n32n64_sigframe_init (const struct tramp_frame *self,
  990. struct frame_info *this_frame,
  991. struct trad_frame_cache *this_cache,
  992. CORE_ADDR func)
  993. {
  994. struct gdbarch *gdbarch = get_frame_arch (this_frame);
  995. int ireg;
  996. CORE_ADDR frame_sp = get_frame_sp (this_frame);
  997. CORE_ADDR sigcontext_base;
  998. const struct mips_regnum *regs = mips_regnum (gdbarch);
  999. if (self == &mips_linux_n32_rt_sigframe
  1000. || self == &micromips_linux_n32_rt_sigframe)
  1001. sigcontext_base = frame_sp + N32_SIGFRAME_SIGCONTEXT_OFFSET;
  1002. else
  1003. sigcontext_base = frame_sp + N64_SIGFRAME_SIGCONTEXT_OFFSET;
  1004. if (mips_linux_restart_reg_p (gdbarch))
  1005. trad_frame_set_reg_addr (this_cache,
  1006. (MIPS_RESTART_REGNUM
  1007. + gdbarch_num_regs (gdbarch)),
  1008. sigcontext_base + N64_SIGCONTEXT_REGS);
  1009. for (ireg = 1; ireg < 32; ireg++)
  1010. trad_frame_set_reg_addr (this_cache,
  1011. (ireg + MIPS_ZERO_REGNUM
  1012. + gdbarch_num_regs (gdbarch)),
  1013. (sigcontext_base + N64_SIGCONTEXT_REGS
  1014. + ireg * N64_SIGCONTEXT_REG_SIZE));
  1015. for (ireg = 0; ireg < 32; ireg++)
  1016. trad_frame_set_reg_addr (this_cache,
  1017. ireg + regs->fp0 + gdbarch_num_regs (gdbarch),
  1018. (sigcontext_base + N64_SIGCONTEXT_FPREGS
  1019. + ireg * N64_SIGCONTEXT_REG_SIZE));
  1020. trad_frame_set_reg_addr (this_cache,
  1021. regs->pc + gdbarch_num_regs (gdbarch),
  1022. sigcontext_base + N64_SIGCONTEXT_PC);
  1023. trad_frame_set_reg_addr (this_cache,
  1024. (regs->fp_control_status
  1025. + gdbarch_num_regs (gdbarch)),
  1026. sigcontext_base + N64_SIGCONTEXT_FPCSR);
  1027. trad_frame_set_reg_addr (this_cache,
  1028. regs->hi + gdbarch_num_regs (gdbarch),
  1029. sigcontext_base + N64_SIGCONTEXT_HI);
  1030. trad_frame_set_reg_addr (this_cache,
  1031. regs->lo + gdbarch_num_regs (gdbarch),
  1032. sigcontext_base + N64_SIGCONTEXT_LO);
  1033. if (regs->dspacc != -1)
  1034. {
  1035. trad_frame_set_reg_addr (this_cache,
  1036. regs->dspacc + 0 + gdbarch_num_regs (gdbarch),
  1037. sigcontext_base + N64_SIGCONTEXT_HI1);
  1038. trad_frame_set_reg_addr (this_cache,
  1039. regs->dspacc + 1 + gdbarch_num_regs (gdbarch),
  1040. sigcontext_base + N64_SIGCONTEXT_LO1);
  1041. trad_frame_set_reg_addr (this_cache,
  1042. regs->dspacc + 2 + gdbarch_num_regs (gdbarch),
  1043. sigcontext_base + N64_SIGCONTEXT_HI2);
  1044. trad_frame_set_reg_addr (this_cache,
  1045. regs->dspacc + 3 + gdbarch_num_regs (gdbarch),
  1046. sigcontext_base + N64_SIGCONTEXT_LO2);
  1047. trad_frame_set_reg_addr (this_cache,
  1048. regs->dspacc + 4 + gdbarch_num_regs (gdbarch),
  1049. sigcontext_base + N64_SIGCONTEXT_HI3);
  1050. trad_frame_set_reg_addr (this_cache,
  1051. regs->dspacc + 5 + gdbarch_num_regs (gdbarch),
  1052. sigcontext_base + N64_SIGCONTEXT_LO3);
  1053. }
  1054. if (regs->dspctl != -1)
  1055. trad_frame_set_reg_addr (this_cache,
  1056. regs->dspctl + gdbarch_num_regs (gdbarch),
  1057. sigcontext_base + N64_SIGCONTEXT_DSPCTL);
  1058. /* Choice of the bottom of the sigframe is somewhat arbitrary. */
  1059. trad_frame_set_id (this_cache, frame_id_build (frame_sp, func));
  1060. }
  1061. /* Implement struct tramp_frame's "validate" method for standard MIPS code. */
  1062. static int
  1063. mips_linux_sigframe_validate (const struct tramp_frame *self,
  1064. struct frame_info *this_frame,
  1065. CORE_ADDR *pc)
  1066. {
  1067. return mips_pc_is_mips (*pc);
  1068. }
  1069. /* Implement struct tramp_frame's "validate" method for microMIPS code. */
  1070. static int
  1071. micromips_linux_sigframe_validate (const struct tramp_frame *self,
  1072. struct frame_info *this_frame,
  1073. CORE_ADDR *pc)
  1074. {
  1075. if (mips_pc_is_micromips (get_frame_arch (this_frame), *pc))
  1076. {
  1077. *pc = mips_unmake_compact_addr (*pc);
  1078. return 1;
  1079. }
  1080. else
  1081. return 0;
  1082. }
  1083. /* Implement the "write_pc" gdbarch method. */
  1084. static void
  1085. mips_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
  1086. {
  1087. struct gdbarch *gdbarch = regcache->arch ();
  1088. mips_write_pc (regcache, pc);
  1089. /* Clear the syscall restart flag. */
  1090. if (mips_linux_restart_reg_p (gdbarch))
  1091. regcache_cooked_write_unsigned (regcache, MIPS_RESTART_REGNUM, 0);
  1092. }
  1093. /* Return 1 if MIPS_RESTART_REGNUM is usable. */
  1094. int
  1095. mips_linux_restart_reg_p (struct gdbarch *gdbarch)
  1096. {
  1097. /* If we do not have a target description with registers, then
  1098. MIPS_RESTART_REGNUM will not be included in the register set. */
  1099. if (!tdesc_has_registers (gdbarch_target_desc (gdbarch)))
  1100. return 0;
  1101. /* If we do, then MIPS_RESTART_REGNUM is safe to check; it will
  1102. either be GPR-sized or missing. */
  1103. return register_size (gdbarch, MIPS_RESTART_REGNUM) > 0;
  1104. }
  1105. /* When FRAME is at a syscall instruction, return the PC of the next
  1106. instruction to be executed. */
  1107. static CORE_ADDR
  1108. mips_linux_syscall_next_pc (struct frame_info *frame)
  1109. {
  1110. CORE_ADDR pc = get_frame_pc (frame);
  1111. ULONGEST v0 = get_frame_register_unsigned (frame, MIPS_V0_REGNUM);
  1112. /* If we are about to make a sigreturn syscall, use the unwinder to
  1113. decode the signal frame. */
  1114. if (v0 == MIPS_NR_sigreturn
  1115. || v0 == MIPS_NR_rt_sigreturn
  1116. || v0 == MIPS_NR_N64_rt_sigreturn
  1117. || v0 == MIPS_NR_N32_rt_sigreturn)
  1118. return frame_unwind_caller_pc (get_current_frame ());
  1119. return pc + 4;
  1120. }
  1121. /* Return the current system call's number present in the
  1122. v0 register. When the function fails, it returns -1. */
  1123. static LONGEST
  1124. mips_linux_get_syscall_number (struct gdbarch *gdbarch,
  1125. thread_info *thread)
  1126. {
  1127. struct regcache *regcache = get_thread_regcache (thread);
  1128. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  1129. enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
  1130. int regsize = register_size (gdbarch, MIPS_V0_REGNUM);
  1131. /* The content of a register */
  1132. gdb_byte buf[8];
  1133. /* The result */
  1134. LONGEST ret;
  1135. /* Make sure we're in a known ABI */
  1136. gdb_assert (tdep->mips_abi == MIPS_ABI_O32
  1137. || tdep->mips_abi == MIPS_ABI_N32
  1138. || tdep->mips_abi == MIPS_ABI_N64);
  1139. gdb_assert (regsize <= sizeof (buf));
  1140. /* Getting the system call number from the register.
  1141. syscall number is in v0 or $2. */
  1142. regcache->cooked_read (MIPS_V0_REGNUM, buf);
  1143. ret = extract_signed_integer (buf, regsize, byte_order);
  1144. return ret;
  1145. }
  1146. /* Implementation of `gdbarch_gdb_signal_to_target', as defined in
  1147. gdbarch.h. */
  1148. static int
  1149. mips_gdb_signal_to_target (struct gdbarch *gdbarch,
  1150. enum gdb_signal signal)
  1151. {
  1152. switch (signal)
  1153. {
  1154. case GDB_SIGNAL_EMT:
  1155. return MIPS_LINUX_SIGEMT;
  1156. case GDB_SIGNAL_BUS:
  1157. return MIPS_LINUX_SIGBUS;
  1158. case GDB_SIGNAL_SYS:
  1159. return MIPS_LINUX_SIGSYS;
  1160. case GDB_SIGNAL_USR1:
  1161. return MIPS_LINUX_SIGUSR1;
  1162. case GDB_SIGNAL_USR2:
  1163. return MIPS_LINUX_SIGUSR2;
  1164. case GDB_SIGNAL_CHLD:
  1165. return MIPS_LINUX_SIGCHLD;
  1166. case GDB_SIGNAL_PWR:
  1167. return MIPS_LINUX_SIGPWR;
  1168. case GDB_SIGNAL_WINCH:
  1169. return MIPS_LINUX_SIGWINCH;
  1170. case GDB_SIGNAL_URG:
  1171. return MIPS_LINUX_SIGURG;
  1172. case GDB_SIGNAL_IO:
  1173. return MIPS_LINUX_SIGIO;
  1174. case GDB_SIGNAL_POLL:
  1175. return MIPS_LINUX_SIGPOLL;
  1176. case GDB_SIGNAL_STOP:
  1177. return MIPS_LINUX_SIGSTOP;
  1178. case GDB_SIGNAL_TSTP:
  1179. return MIPS_LINUX_SIGTSTP;
  1180. case GDB_SIGNAL_CONT:
  1181. return MIPS_LINUX_SIGCONT;
  1182. case GDB_SIGNAL_TTIN:
  1183. return MIPS_LINUX_SIGTTIN;
  1184. case GDB_SIGNAL_TTOU:
  1185. return MIPS_LINUX_SIGTTOU;
  1186. case GDB_SIGNAL_VTALRM:
  1187. return MIPS_LINUX_SIGVTALRM;
  1188. case GDB_SIGNAL_PROF:
  1189. return MIPS_LINUX_SIGPROF;
  1190. case GDB_SIGNAL_XCPU:
  1191. return MIPS_LINUX_SIGXCPU;
  1192. case GDB_SIGNAL_XFSZ:
  1193. return MIPS_LINUX_SIGXFSZ;
  1194. /* GDB_SIGNAL_REALTIME_32 is not continuous in <gdb/signals.def>,
  1195. therefore we have to handle it here. */
  1196. case GDB_SIGNAL_REALTIME_32:
  1197. return MIPS_LINUX_SIGRTMIN;
  1198. }
  1199. if (signal >= GDB_SIGNAL_REALTIME_33
  1200. && signal <= GDB_SIGNAL_REALTIME_63)
  1201. {
  1202. int offset = signal - GDB_SIGNAL_REALTIME_33;
  1203. return MIPS_LINUX_SIGRTMIN + 1 + offset;
  1204. }
  1205. else if (signal >= GDB_SIGNAL_REALTIME_64
  1206. && signal <= GDB_SIGNAL_REALTIME_127)
  1207. {
  1208. int offset = signal - GDB_SIGNAL_REALTIME_64;
  1209. return MIPS_LINUX_SIGRT64 + offset;
  1210. }
  1211. return linux_gdb_signal_to_target (gdbarch, signal);
  1212. }
  1213. /* Translate signals based on MIPS signal values.
  1214. Adapted from gdb/gdbsupport/signals.c. */
  1215. static enum gdb_signal
  1216. mips_gdb_signal_from_target (struct gdbarch *gdbarch, int signal)
  1217. {
  1218. switch (signal)
  1219. {
  1220. case MIPS_LINUX_SIGEMT:
  1221. return GDB_SIGNAL_EMT;
  1222. case MIPS_LINUX_SIGBUS:
  1223. return GDB_SIGNAL_BUS;
  1224. case MIPS_LINUX_SIGSYS:
  1225. return GDB_SIGNAL_SYS;
  1226. case MIPS_LINUX_SIGUSR1:
  1227. return GDB_SIGNAL_USR1;
  1228. case MIPS_LINUX_SIGUSR2:
  1229. return GDB_SIGNAL_USR2;
  1230. case MIPS_LINUX_SIGCHLD:
  1231. return GDB_SIGNAL_CHLD;
  1232. case MIPS_LINUX_SIGPWR:
  1233. return GDB_SIGNAL_PWR;
  1234. case MIPS_LINUX_SIGWINCH:
  1235. return GDB_SIGNAL_WINCH;
  1236. case MIPS_LINUX_SIGURG:
  1237. return GDB_SIGNAL_URG;
  1238. /* No way to differentiate between SIGIO and SIGPOLL.
  1239. Therefore, we just handle the first one. */
  1240. case MIPS_LINUX_SIGIO:
  1241. return GDB_SIGNAL_IO;
  1242. case MIPS_LINUX_SIGSTOP:
  1243. return GDB_SIGNAL_STOP;
  1244. case MIPS_LINUX_SIGTSTP:
  1245. return GDB_SIGNAL_TSTP;
  1246. case MIPS_LINUX_SIGCONT:
  1247. return GDB_SIGNAL_CONT;
  1248. case MIPS_LINUX_SIGTTIN:
  1249. return GDB_SIGNAL_TTIN;
  1250. case MIPS_LINUX_SIGTTOU:
  1251. return GDB_SIGNAL_TTOU;
  1252. case MIPS_LINUX_SIGVTALRM:
  1253. return GDB_SIGNAL_VTALRM;
  1254. case MIPS_LINUX_SIGPROF:
  1255. return GDB_SIGNAL_PROF;
  1256. case MIPS_LINUX_SIGXCPU:
  1257. return GDB_SIGNAL_XCPU;
  1258. case MIPS_LINUX_SIGXFSZ:
  1259. return GDB_SIGNAL_XFSZ;
  1260. }
  1261. if (signal >= MIPS_LINUX_SIGRTMIN && signal <= MIPS_LINUX_SIGRTMAX)
  1262. {
  1263. /* GDB_SIGNAL_REALTIME values are not contiguous, map parts of
  1264. the MIPS block to the respective GDB_SIGNAL_REALTIME blocks. */
  1265. int offset = signal - MIPS_LINUX_SIGRTMIN;
  1266. if (offset == 0)
  1267. return GDB_SIGNAL_REALTIME_32;
  1268. else if (offset < 32)
  1269. return (enum gdb_signal) (offset - 1
  1270. + (int) GDB_SIGNAL_REALTIME_33);
  1271. else
  1272. return (enum gdb_signal) (offset - 32
  1273. + (int) GDB_SIGNAL_REALTIME_64);
  1274. }
  1275. return linux_gdb_signal_from_target (gdbarch, signal);
  1276. }
  1277. /* Initialize one of the GNU/Linux OS ABIs. */
  1278. static void
  1279. mips_linux_init_abi (struct gdbarch_info info,
  1280. struct gdbarch *gdbarch)
  1281. {
  1282. mips_gdbarch_tdep *tdep = (mips_gdbarch_tdep *) gdbarch_tdep (gdbarch);
  1283. enum mips_abi abi = mips_abi (gdbarch);
  1284. struct tdesc_arch_data *tdesc_data = info.tdesc_data;
  1285. linux_init_abi (info, gdbarch, 0);
  1286. /* Get the syscall number from the arch's register. */
  1287. set_gdbarch_get_syscall_number (gdbarch, mips_linux_get_syscall_number);
  1288. switch (abi)
  1289. {
  1290. case MIPS_ABI_O32:
  1291. set_gdbarch_get_longjmp_target (gdbarch,
  1292. mips_linux_get_longjmp_target);
  1293. set_solib_svr4_fetch_link_map_offsets
  1294. (gdbarch, linux_ilp32_fetch_link_map_offsets);
  1295. tramp_frame_prepend_unwinder (gdbarch, &micromips_linux_o32_sigframe);
  1296. tramp_frame_prepend_unwinder (gdbarch,
  1297. &micromips_linux_o32_rt_sigframe);
  1298. tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_sigframe);
  1299. tramp_frame_prepend_unwinder (gdbarch, &mips_linux_o32_rt_sigframe);
  1300. set_xml_syscall_file_name (gdbarch, "syscalls/mips-o32-linux.xml");
  1301. break;
  1302. case MIPS_ABI_N32:
  1303. set_gdbarch_get_longjmp_target (gdbarch,
  1304. mips_linux_get_longjmp_target);
  1305. set_solib_svr4_fetch_link_map_offsets
  1306. (gdbarch, linux_ilp32_fetch_link_map_offsets);
  1307. set_gdbarch_long_double_bit (gdbarch, 128);
  1308. set_gdbarch_long_double_format (gdbarch, floatformats_ieee_quad);
  1309. tramp_frame_prepend_unwinder (gdbarch,
  1310. &micromips_linux_n32_rt_sigframe);
  1311. tramp_frame_prepend_unwinder (gdbarch, &mips_linux_n32_rt_sigframe);
  1312. set_xml_syscall_file_name (gdbarch, "syscalls/mips-n32-linux.xml");
  1313. break;
  1314. case MIPS_ABI_N64:
  1315. set_gdbarch_get_longjmp_target (gdbarch,
  1316. mips64_linux_get_longjmp_target);
  1317. set_solib_svr4_fetch_link_map_offsets
  1318. (gdbarch, linux_lp64_fetch_link_map_offsets);
  1319. set_gdbarch_long_double_bit (gdbarch, 128);
  1320. set_gdbarch_long_double_format (gdbarch, floatformats_ieee_quad);
  1321. tramp_frame_prepend_unwinder (gdbarch,
  1322. &micromips_linux_n64_rt_sigframe);
  1323. tramp_frame_prepend_unwinder (gdbarch, &mips_linux_n64_rt_sigframe);
  1324. set_xml_syscall_file_name (gdbarch, "syscalls/mips-n64-linux.xml");
  1325. break;
  1326. default:
  1327. break;
  1328. }
  1329. set_gdbarch_skip_solib_resolver (gdbarch, mips_linux_skip_resolver);
  1330. set_gdbarch_software_single_step (gdbarch, mips_software_single_step);
  1331. /* Enable TLS support. */
  1332. set_gdbarch_fetch_tls_load_module_address (gdbarch,
  1333. svr4_fetch_objfile_link_map);
  1334. /* Initialize this lazily, to avoid an initialization order
  1335. dependency on solib-svr4.c's _initialize routine. */
  1336. if (mips_svr4_so_ops.in_dynsym_resolve_code == NULL)
  1337. {
  1338. mips_svr4_so_ops = svr4_so_ops;
  1339. mips_svr4_so_ops.in_dynsym_resolve_code
  1340. = mips_linux_in_dynsym_resolve_code;
  1341. }
  1342. set_solib_ops (gdbarch, &mips_svr4_so_ops);
  1343. set_gdbarch_write_pc (gdbarch, mips_linux_write_pc);
  1344. set_gdbarch_core_read_description (gdbarch,
  1345. mips_linux_core_read_description);
  1346. set_gdbarch_iterate_over_regset_sections
  1347. (gdbarch, mips_linux_iterate_over_regset_sections);
  1348. set_gdbarch_gdb_signal_from_target (gdbarch,
  1349. mips_gdb_signal_from_target);
  1350. set_gdbarch_gdb_signal_to_target (gdbarch,
  1351. mips_gdb_signal_to_target);
  1352. tdep->syscall_next_pc = mips_linux_syscall_next_pc;
  1353. if (tdesc_data)
  1354. {
  1355. const struct tdesc_feature *feature;
  1356. /* If we have target-described registers, then we can safely
  1357. reserve a number for MIPS_RESTART_REGNUM (whether it is
  1358. described or not). */
  1359. gdb_assert (gdbarch_num_regs (gdbarch) <= MIPS_RESTART_REGNUM);
  1360. set_gdbarch_num_regs (gdbarch, MIPS_RESTART_REGNUM + 1);
  1361. set_gdbarch_num_pseudo_regs (gdbarch, MIPS_RESTART_REGNUM + 1);
  1362. /* If it's present, then assign it to the reserved number. */
  1363. feature = tdesc_find_feature (info.target_desc,
  1364. "org.gnu.gdb.mips.linux");
  1365. if (feature != NULL)
  1366. tdesc_numbered_register (feature, tdesc_data, MIPS_RESTART_REGNUM,
  1367. "restart");
  1368. }
  1369. }
  1370. void _initialize_mips_linux_tdep ();
  1371. void
  1372. _initialize_mips_linux_tdep ()
  1373. {
  1374. const struct bfd_arch_info *arch_info;
  1375. for (arch_info = bfd_lookup_arch (bfd_arch_mips, 0);
  1376. arch_info != NULL;
  1377. arch_info = arch_info->next)
  1378. {
  1379. gdbarch_register_osabi (bfd_arch_mips, arch_info->mach,
  1380. GDB_OSABI_LINUX,
  1381. mips_linux_init_abi);
  1382. }
  1383. /* Initialize the standard target descriptions. */
  1384. initialize_tdesc_mips_linux ();
  1385. initialize_tdesc_mips_dsp_linux ();
  1386. initialize_tdesc_mips64_linux ();
  1387. initialize_tdesc_mips64_dsp_linux ();
  1388. }