aoutf1.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793
  1. /* A.out "format 1" file handling code for BFD.
  2. Copyright (C) 1990-2015 Free Software Foundation, Inc.
  3. Written by Cygnus Support.
  4. This file is part of BFD, the Binary File Descriptor library.
  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, write to the Free Software
  15. Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
  16. MA 02110-1301, USA. */
  17. #include "sysdep.h"
  18. #include "bfd.h"
  19. #include "libbfd.h"
  20. #include "aout/sun4.h"
  21. #include "libaout.h" /* BFD a.out internal data structures. */
  22. #include "aout/aout64.h"
  23. #include "aout/stab_gnu.h"
  24. #include "aout/ar.h"
  25. /* This is needed to reject a NewsOS file, e.g. in
  26. gdb/testsuite/gdb.t10/crossload.exp. <kingdon@cygnus.com>
  27. I needed to add M_UNKNOWN to recognize a 68000 object, so this will
  28. probably no longer reject a NewsOS object. <ian@cygnus.com>. */
  29. #ifndef MACHTYPE_OK
  30. #define MACHTYPE_OK(mtype) \
  31. (((mtype) == M_SPARC && bfd_lookup_arch (bfd_arch_sparc, 0) != NULL) \
  32. || (((mtype) == M_UNKNOWN || (mtype) == M_68010 || (mtype) == M_68020) \
  33. && bfd_lookup_arch (bfd_arch_m68k, 0) != NULL))
  34. #endif
  35. /* The file @code{aoutf1.h} contains the code for BFD's
  36. a.out back end. Control over the generated back end is given by these
  37. two preprocessor names:
  38. @table @code
  39. @item ARCH_SIZE
  40. This value should be either 32 or 64, depending upon the size of an
  41. int in the target format. It changes the sizes of the structs which
  42. perform the memory/disk mapping of structures.
  43. The 64 bit backend may only be used if the host compiler supports 64
  44. ints (eg long long with gcc), by defining the name @code{BFD_HOST_64_BIT} in @code{bfd.h}.
  45. With this name defined, @emph{all} bfd operations are performed with 64bit
  46. arithmetic, not just those to a 64bit target.
  47. @item TARGETNAME
  48. The name put into the target vector.
  49. @item
  50. @end table. */
  51. #if ARCH_SIZE == 64
  52. #define sunos_set_arch_mach sunos_64_set_arch_mach
  53. #define sunos_write_object_contents aout_64_sunos4_write_object_contents
  54. #else
  55. #define sunos_set_arch_mach sunos_32_set_arch_mach
  56. #define sunos_write_object_contents aout_32_sunos4_write_object_contents
  57. #endif
  58. /* Merge backend data into the output file.
  59. This is necessary on sparclet-aout where we want the resultant machine
  60. number to be M_SPARCLET if any input file is M_SPARCLET. */
  61. #define MY_bfd_merge_private_bfd_data sunos_merge_private_bfd_data
  62. static bfd_boolean
  63. sunos_merge_private_bfd_data (bfd *ibfd, bfd *obfd)
  64. {
  65. if (bfd_get_flavour (ibfd) != bfd_target_aout_flavour
  66. || bfd_get_flavour (obfd) != bfd_target_aout_flavour)
  67. return TRUE;
  68. if (bfd_get_arch (obfd) == bfd_arch_sparc)
  69. {
  70. if (bfd_get_mach (obfd) < bfd_get_mach (ibfd))
  71. bfd_set_arch_mach (obfd, bfd_arch_sparc, bfd_get_mach (ibfd));
  72. }
  73. return TRUE;
  74. }
  75. /* This is either sunos_32_set_arch_mach or sunos_64_set_arch_mach,
  76. depending upon ARCH_SIZE. */
  77. static void
  78. sunos_set_arch_mach (bfd *abfd, enum machine_type machtype)
  79. {
  80. /* Determine the architecture and machine type of the object file. */
  81. enum bfd_architecture arch;
  82. unsigned long machine;
  83. switch (machtype)
  84. {
  85. case M_UNKNOWN:
  86. /* Some Sun3s make magic numbers without cpu types in them, so
  87. we'll default to the 68000. */
  88. arch = bfd_arch_m68k;
  89. machine = bfd_mach_m68000;
  90. break;
  91. case M_68010:
  92. case M_HP200:
  93. arch = bfd_arch_m68k;
  94. machine = bfd_mach_m68010;
  95. break;
  96. case M_68020:
  97. case M_HP300:
  98. arch = bfd_arch_m68k;
  99. machine = bfd_mach_m68020;
  100. break;
  101. case M_SPARC:
  102. arch = bfd_arch_sparc;
  103. machine = 0;
  104. break;
  105. case M_SPARCLET:
  106. arch = bfd_arch_sparc;
  107. machine = bfd_mach_sparc_sparclet;
  108. break;
  109. case M_SPARCLITE_LE:
  110. arch = bfd_arch_sparc;
  111. machine = bfd_mach_sparc_sparclite_le;
  112. break;
  113. case M_386:
  114. case M_386_DYNIX:
  115. arch = bfd_arch_i386;
  116. machine = 0;
  117. break;
  118. case M_HPUX:
  119. arch = bfd_arch_m68k;
  120. machine = 0;
  121. break;
  122. default:
  123. arch = bfd_arch_obscure;
  124. machine = 0;
  125. break;
  126. }
  127. bfd_set_arch_mach (abfd, arch, machine);
  128. }
  129. #define SET_ARCH_MACH(ABFD, EXEC) \
  130. NAME(sunos,set_arch_mach) (ABFD, N_MACHTYPE (EXEC)); \
  131. choose_reloc_size(ABFD);
  132. /* Determine the size of a relocation entry, based on the architecture. */
  133. static void
  134. choose_reloc_size (bfd *abfd)
  135. {
  136. switch (bfd_get_arch (abfd))
  137. {
  138. case bfd_arch_sparc:
  139. obj_reloc_entry_size (abfd) = RELOC_EXT_SIZE;
  140. break;
  141. default:
  142. obj_reloc_entry_size (abfd) = RELOC_STD_SIZE;
  143. break;
  144. }
  145. }
  146. /* Write an object file in SunOS format. Section contents have
  147. already been written. We write the file header, symbols, and
  148. relocation. The real name of this function is either
  149. aout_64_sunos4_write_object_contents or
  150. aout_32_sunos4_write_object_contents, depending upon ARCH_SIZE. */
  151. static bfd_boolean
  152. sunos_write_object_contents (bfd *abfd)
  153. {
  154. struct external_exec exec_bytes;
  155. struct internal_exec *execp = exec_hdr (abfd);
  156. /* Magic number, maestro, please! */
  157. switch (bfd_get_arch (abfd))
  158. {
  159. case bfd_arch_m68k:
  160. switch (bfd_get_mach (abfd))
  161. {
  162. case bfd_mach_m68000:
  163. N_SET_MACHTYPE (*execp, M_UNKNOWN);
  164. break;
  165. case bfd_mach_m68010:
  166. N_SET_MACHTYPE (*execp, M_68010);
  167. break;
  168. default:
  169. case bfd_mach_m68020:
  170. N_SET_MACHTYPE (*execp, M_68020);
  171. break;
  172. }
  173. break;
  174. case bfd_arch_sparc:
  175. switch (bfd_get_mach (abfd))
  176. {
  177. case bfd_mach_sparc_sparclet:
  178. N_SET_MACHTYPE (*execp, M_SPARCLET);
  179. break;
  180. case bfd_mach_sparc_sparclite_le:
  181. N_SET_MACHTYPE (*execp, M_SPARCLITE_LE);
  182. break;
  183. default:
  184. N_SET_MACHTYPE (*execp, M_SPARC);
  185. break;
  186. }
  187. break;
  188. case bfd_arch_i386:
  189. N_SET_MACHTYPE (*execp, M_386);
  190. break;
  191. default:
  192. N_SET_MACHTYPE (*execp, M_UNKNOWN);
  193. }
  194. choose_reloc_size (abfd);
  195. N_SET_FLAGS (*execp, aout_backend_info (abfd)->exec_hdr_flags);
  196. N_SET_DYNAMIC (*execp, (long)(bfd_get_file_flags (abfd) & DYNAMIC));
  197. WRITE_HEADERS (abfd, execp);
  198. return TRUE;
  199. }
  200. /* Core files. */
  201. #define CORE_MAGIC 0x080456
  202. #define CORE_NAMELEN 16
  203. /* The core structure is taken from the Sun documentation.
  204. Unfortunately, they don't document the FPA structure, or at least I
  205. can't find it easily. Fortunately the core header contains its own
  206. length. So this shouldn't cause problems, except for c_ucode, which
  207. so far we don't use but is easy to find with a little arithmetic. */
  208. /* But the reg structure can be gotten from the SPARC processor handbook.
  209. This really should be in a GNU include file though so that gdb can use
  210. the same info. */
  211. struct regs
  212. {
  213. int r_psr;
  214. int r_pc;
  215. int r_npc;
  216. int r_y;
  217. int r_g1;
  218. int r_g2;
  219. int r_g3;
  220. int r_g4;
  221. int r_g5;
  222. int r_g6;
  223. int r_g7;
  224. int r_o0;
  225. int r_o1;
  226. int r_o2;
  227. int r_o3;
  228. int r_o4;
  229. int r_o5;
  230. int r_o6;
  231. int r_o7;
  232. };
  233. /* Taken from Sun documentation: */
  234. /* FIXME: It's worse than we expect. This struct contains TWO substructs
  235. neither of whose size we know, WITH STUFF IN BETWEEN THEM! We can't
  236. even portably access the stuff in between! */
  237. struct external_sparc_core
  238. {
  239. int c_magic; /* Corefile magic number. */
  240. int c_len; /* Sizeof (struct core). */
  241. #define SPARC_CORE_LEN 432
  242. struct regs c_regs; /* General purpose registers -- MACHDEP SIZE. */
  243. struct external_exec c_aouthdr; /* A.out header. */
  244. int c_signo; /* Killing signal, if any. */
  245. int c_tsize; /* Text size (bytes). */
  246. int c_dsize; /* Data size (bytes). */
  247. int c_ssize; /* Stack size (bytes). */
  248. char c_cmdname[CORE_NAMELEN + 1]; /* Command name. */
  249. double fp_stuff[1]; /* External FPU state (size unknown by us). */
  250. /* The type "double" is critical here, for alignment.
  251. SunOS declares a struct here, but the struct's
  252. alignment is double since it contains doubles. */
  253. int c_ucode; /* Exception no. from u_code. */
  254. /* This member is not accessible by name since
  255. we don't portably know the size of fp_stuff. */
  256. };
  257. /* Core files generated by the BCP (the part of Solaris which allows
  258. it to run SunOS4 a.out files). */
  259. struct external_solaris_bcp_core
  260. {
  261. int c_magic; /* Corefile magic number. */
  262. int c_len; /* Sizeof (struct core). */
  263. #define SOLARIS_BCP_CORE_LEN 456
  264. struct regs c_regs; /* General purpose registers -- MACHDEP SIZE. */
  265. int c_exdata_vp; /* Exdata structure. */
  266. int c_exdata_tsize;
  267. int c_exdata_dsize;
  268. int c_exdata_bsize;
  269. int c_exdata_lsize;
  270. int c_exdata_nshlibs;
  271. short c_exdata_mach;
  272. short c_exdata_mag;
  273. int c_exdata_toffset;
  274. int c_exdata_doffset;
  275. int c_exdata_loffset;
  276. int c_exdata_txtorg;
  277. int c_exdata_datorg;
  278. int c_exdata_entloc;
  279. int c_signo; /* Killing signal, if any. */
  280. int c_tsize; /* Text size (bytes). */
  281. int c_dsize; /* Data size (bytes). */
  282. int c_ssize; /* Stack size (bytes). */
  283. char c_cmdname[CORE_NAMELEN + 1]; /* Command name. */
  284. double fp_stuff[1]; /* External FPU state (size unknown by us). */
  285. /* The type "double" is critical here, for alignment.
  286. SunOS declares a struct here, but the struct's
  287. alignment is double since it contains doubles. */
  288. int c_ucode; /* Exception no. from u_code. */
  289. /* This member is not accessible by name since
  290. we don't portably know the size of fp_stuff. */
  291. };
  292. struct external_sun3_core
  293. {
  294. int c_magic; /* Corefile magic number. */
  295. int c_len; /* Sizeof (struct core). */
  296. #define SUN3_CORE_LEN 826 /* As of SunOS 4.1.1. */
  297. int c_regs[18]; /* General purpose registers -- MACHDEP SIZE. */
  298. struct external_exec c_aouthdr; /* A.out header. */
  299. int c_signo; /* Killing signal, if any. */
  300. int c_tsize; /* Text size (bytes). */
  301. int c_dsize; /* Data size (bytes). */
  302. int c_ssize; /* Stack size (bytes). */
  303. char c_cmdname[CORE_NAMELEN + 1]; /* Command name. */
  304. double fp_stuff[1]; /* External FPU state (size unknown by us). */
  305. /* The type "double" is critical here, for alignment.
  306. SunOS declares a struct here, but the struct's
  307. alignment is double since it contains doubles. */
  308. int c_ucode; /* Exception no. from u_code. */
  309. /* This member is not accessible by name since
  310. we don't portably know the size of fp_stuff. */
  311. };
  312. struct internal_sunos_core
  313. {
  314. int c_magic; /* Corefile magic number. */
  315. int c_len; /* Sizeof (struct core). */
  316. long c_regs_pos; /* File offset of General purpose registers. */
  317. int c_regs_size; /* Size of General purpose registers. */
  318. struct internal_exec c_aouthdr; /* A.out header. */
  319. int c_signo; /* Killing signal, if any. */
  320. int c_tsize; /* Text size (bytes). */
  321. int c_dsize; /* Data size (bytes). */
  322. bfd_vma c_data_addr; /* Data start (address). */
  323. int c_ssize; /* Stack size (bytes). */
  324. bfd_vma c_stacktop; /* Stack top (address). */
  325. char c_cmdname[CORE_NAMELEN + 1]; /* Command name. */
  326. long fp_stuff_pos; /* File offset of external FPU state (regs). */
  327. int fp_stuff_size; /* Size of it. */
  328. int c_ucode; /* Exception no. from u_code. */
  329. };
  330. /* Byte-swap in the Sun-3 core structure. */
  331. static void
  332. swapcore_sun3 (bfd *abfd, char *ext, struct internal_sunos_core *intcore)
  333. {
  334. struct external_sun3_core *extcore = (struct external_sun3_core *) ext;
  335. intcore->c_magic = H_GET_32 (abfd, &extcore->c_magic);
  336. intcore->c_len = H_GET_32 (abfd, &extcore->c_len);
  337. intcore->c_regs_pos = offsetof (struct external_sun3_core, c_regs);
  338. intcore->c_regs_size = sizeof (extcore->c_regs);
  339. #if ARCH_SIZE == 64
  340. aout_64_swap_exec_header_in
  341. #else
  342. aout_32_swap_exec_header_in
  343. #endif
  344. (abfd, &extcore->c_aouthdr, &intcore->c_aouthdr);
  345. intcore->c_signo = H_GET_32 (abfd, &extcore->c_signo);
  346. intcore->c_tsize = H_GET_32 (abfd, &extcore->c_tsize);
  347. intcore->c_dsize = H_GET_32 (abfd, &extcore->c_dsize);
  348. intcore->c_data_addr = N_DATADDR (intcore->c_aouthdr);
  349. intcore->c_ssize = H_GET_32 (abfd, &extcore->c_ssize);
  350. memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
  351. intcore->fp_stuff_pos = offsetof (struct external_sun3_core, fp_stuff);
  352. /* FP stuff takes up whole rest of struct, except c_ucode. */
  353. intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
  354. offsetof (struct external_sun3_core, fp_stuff);
  355. /* Ucode is the last thing in the struct -- just before the end. */
  356. intcore->c_ucode = H_GET_32 (abfd,
  357. (intcore->c_len
  358. - sizeof (extcore->c_ucode)
  359. + (unsigned char *) extcore));
  360. intcore->c_stacktop = 0x0E000000; /* By experimentation. */
  361. }
  362. /* Byte-swap in the Sparc core structure. */
  363. static void
  364. swapcore_sparc (bfd *abfd, char *ext, struct internal_sunos_core *intcore)
  365. {
  366. struct external_sparc_core *extcore = (struct external_sparc_core *) ext;
  367. intcore->c_magic = H_GET_32 (abfd, &extcore->c_magic);
  368. intcore->c_len = H_GET_32 (abfd, &extcore->c_len);
  369. intcore->c_regs_pos = offsetof (struct external_sparc_core, c_regs);
  370. intcore->c_regs_size = sizeof (extcore->c_regs);
  371. #if ARCH_SIZE == 64
  372. aout_64_swap_exec_header_in
  373. #else
  374. aout_32_swap_exec_header_in
  375. #endif
  376. (abfd, &extcore->c_aouthdr, &intcore->c_aouthdr);
  377. intcore->c_signo = H_GET_32 (abfd, &extcore->c_signo);
  378. intcore->c_tsize = H_GET_32 (abfd, &extcore->c_tsize);
  379. intcore->c_dsize = H_GET_32 (abfd, &extcore->c_dsize);
  380. intcore->c_data_addr = N_DATADDR (intcore->c_aouthdr);
  381. intcore->c_ssize = H_GET_32 (abfd, &extcore->c_ssize);
  382. memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
  383. intcore->fp_stuff_pos = offsetof (struct external_sparc_core, fp_stuff);
  384. /* FP stuff takes up whole rest of struct, except c_ucode. */
  385. intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
  386. offsetof (struct external_sparc_core, fp_stuff);
  387. /* Ucode is the last thing in the struct -- just before the end. */
  388. intcore->c_ucode = H_GET_32 (abfd,
  389. (intcore->c_len
  390. - sizeof (extcore->c_ucode)
  391. + (unsigned char *) extcore));
  392. /* Supposedly the user stack grows downward from the bottom of kernel memory.
  393. Presuming that this remains true, this definition will work. */
  394. /* Now sun has provided us with another challenge. The value is different
  395. for sparc2 and sparc10 (both running SunOS 4.1.3). We pick one or
  396. the other based on the current value of the stack pointer. This
  397. loses (a) if the stack pointer has been clobbered, or (b) if the stack
  398. is larger than 128 megabytes.
  399. It's times like these you're glad they're switching to ELF.
  400. Note that using include files or nlist on /vmunix would be wrong,
  401. because we want the value for this core file, no matter what kind of
  402. machine we were compiled on or are running on. */
  403. #define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000)
  404. #define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000)
  405. {
  406. bfd_vma sp = H_GET_32 (abfd, &extcore->c_regs.r_o6);
  407. if (sp < SPARC_USRSTACK_SPARC10)
  408. intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
  409. else
  410. intcore->c_stacktop = SPARC_USRSTACK_SPARC2;
  411. }
  412. }
  413. /* Byte-swap in the Solaris BCP core structure. */
  414. static void
  415. swapcore_solaris_bcp (bfd *abfd, char *ext, struct internal_sunos_core *intcore)
  416. {
  417. struct external_solaris_bcp_core *extcore =
  418. (struct external_solaris_bcp_core *) ext;
  419. intcore->c_magic = H_GET_32 (abfd, &extcore->c_magic);
  420. intcore->c_len = H_GET_32 (abfd, &extcore->c_len);
  421. intcore->c_regs_pos = offsetof (struct external_solaris_bcp_core, c_regs);
  422. intcore->c_regs_size = sizeof (extcore->c_regs);
  423. /* The Solaris BCP exdata structure does not contain an a_syms field,
  424. so we are unable to synthesize an internal exec header.
  425. Luckily we are able to figure out the start address of the data section,
  426. which is the only thing needed from the internal exec header,
  427. from the exdata structure.
  428. As of Solaris 2.3, BCP core files for statically linked executables
  429. are buggy. The exdata structure is not properly filled in, and
  430. the data section is written from address zero instead of the data
  431. start address. */
  432. memset ((void *) &intcore->c_aouthdr, 0, sizeof (struct internal_exec));
  433. intcore->c_data_addr = H_GET_32 (abfd, &extcore->c_exdata_datorg);
  434. intcore->c_signo = H_GET_32 (abfd, &extcore->c_signo);
  435. intcore->c_tsize = H_GET_32 (abfd, &extcore->c_tsize);
  436. intcore->c_dsize = H_GET_32 (abfd, &extcore->c_dsize);
  437. intcore->c_ssize = H_GET_32 (abfd, &extcore->c_ssize);
  438. memcpy (intcore->c_cmdname, extcore->c_cmdname, sizeof (intcore->c_cmdname));
  439. intcore->fp_stuff_pos =
  440. offsetof (struct external_solaris_bcp_core, fp_stuff);
  441. /* FP stuff takes up whole rest of struct, except c_ucode. */
  442. intcore->fp_stuff_size = intcore->c_len - (sizeof extcore->c_ucode) -
  443. offsetof (struct external_solaris_bcp_core, fp_stuff);
  444. /* Ucode is the last thing in the struct -- just before the end */
  445. intcore->c_ucode = H_GET_32 (abfd,
  446. (intcore->c_len
  447. - sizeof (extcore->c_ucode)
  448. + (unsigned char *) extcore));
  449. /* Supposedly the user stack grows downward from the bottom of kernel memory.
  450. Presuming that this remains true, this definition will work. */
  451. /* Now sun has provided us with another challenge. The value is different
  452. for sparc2 and sparc10 (both running SunOS 4.1.3). We pick one or
  453. the other based on the current value of the stack pointer. This
  454. loses (a) if the stack pointer has been clobbered, or (b) if the stack
  455. is larger than 128 megabytes.
  456. It's times like these you're glad they're switching to ELF.
  457. Note that using include files or nlist on /vmunix would be wrong,
  458. because we want the value for this core file, no matter what kind of
  459. machine we were compiled on or are running on. */
  460. #define SPARC_USRSTACK_SPARC2 ((bfd_vma)0xf8000000)
  461. #define SPARC_USRSTACK_SPARC10 ((bfd_vma)0xf0000000)
  462. {
  463. bfd_vma sp = H_GET_32 (abfd, &extcore->c_regs.r_o6);
  464. if (sp < SPARC_USRSTACK_SPARC10)
  465. intcore->c_stacktop = SPARC_USRSTACK_SPARC10;
  466. else
  467. intcore->c_stacktop = SPARC_USRSTACK_SPARC2;
  468. }
  469. }
  470. /* Need this cast because ptr is really void *. */
  471. #define core_hdr(bfd) ((bfd)->tdata.sun_core_data)
  472. #define core_datasec(bfd) (core_hdr (bfd)->data_section)
  473. #define core_stacksec(bfd) (core_hdr (bfd)->stack_section)
  474. #define core_regsec(bfd) (core_hdr (bfd)->reg_section)
  475. #define core_reg2sec(bfd) (core_hdr (bfd)->reg2_section)
  476. /* These are stored in the bfd's tdata. */
  477. struct sun_core_struct
  478. {
  479. struct internal_sunos_core *hdr; /* Core file header. */
  480. asection *data_section;
  481. asection *stack_section;
  482. asection *reg_section;
  483. asection *reg2_section;
  484. };
  485. static const bfd_target *
  486. sunos4_core_file_p (bfd *abfd)
  487. {
  488. unsigned char longbuf[4]; /* Raw bytes of various header fields. */
  489. bfd_size_type core_size, amt;
  490. unsigned long core_mag;
  491. struct internal_sunos_core *core;
  492. char *extcore;
  493. struct mergem
  494. {
  495. struct sun_core_struct suncoredata;
  496. struct internal_sunos_core internal_sunos_core;
  497. char external_core[1];
  498. } *mergem;
  499. flagword flags;
  500. if (bfd_bread ((void *) longbuf, (bfd_size_type) sizeof (longbuf), abfd)
  501. != sizeof (longbuf))
  502. return NULL;
  503. core_mag = H_GET_32 (abfd, longbuf);
  504. if (core_mag != CORE_MAGIC)
  505. return NULL;
  506. /* SunOS core headers can vary in length; second word is size; */
  507. if (bfd_bread ((void *) longbuf, (bfd_size_type) sizeof (longbuf), abfd)
  508. != sizeof (longbuf))
  509. return NULL;
  510. core_size = H_GET_32 (abfd, longbuf);
  511. /* Sanity check. */
  512. if (core_size > 20000)
  513. return NULL;
  514. if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0)
  515. return NULL;
  516. amt = core_size + sizeof (struct mergem);
  517. mergem = bfd_zalloc (abfd, amt);
  518. if (mergem == NULL)
  519. return NULL;
  520. extcore = mergem->external_core;
  521. if ((bfd_bread ((void *) extcore, core_size, abfd)) != core_size)
  522. {
  523. loser:
  524. bfd_release (abfd, (char *) mergem);
  525. abfd->tdata.any = NULL;
  526. bfd_section_list_clear (abfd);
  527. return NULL;
  528. }
  529. /* Validate that it's a core file we know how to handle, due to sun
  530. botching the positioning of registers and other fields in a machine
  531. dependent way. */
  532. core = &mergem->internal_sunos_core;
  533. switch (core_size)
  534. {
  535. case SPARC_CORE_LEN:
  536. swapcore_sparc (abfd, extcore, core);
  537. break;
  538. case SUN3_CORE_LEN:
  539. swapcore_sun3 (abfd, extcore, core);
  540. break;
  541. case SOLARIS_BCP_CORE_LEN:
  542. swapcore_solaris_bcp (abfd, extcore, core);
  543. break;
  544. default:
  545. bfd_set_error (bfd_error_system_call); /* FIXME. */
  546. goto loser;
  547. }
  548. abfd->tdata.sun_core_data = &mergem->suncoredata;
  549. abfd->tdata.sun_core_data->hdr = core;
  550. /* Create the sections. */
  551. flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
  552. core_stacksec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".stack",
  553. flags);
  554. if (core_stacksec (abfd) == NULL)
  555. /* bfd_release frees everything allocated after it's arg. */
  556. goto loser;
  557. flags = SEC_ALLOC + SEC_LOAD + SEC_HAS_CONTENTS;
  558. core_datasec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".data",
  559. flags);
  560. if (core_datasec (abfd) == NULL)
  561. goto loser;
  562. flags = SEC_HAS_CONTENTS;
  563. core_regsec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".reg",
  564. flags);
  565. if (core_regsec (abfd) == NULL)
  566. goto loser;
  567. flags = SEC_HAS_CONTENTS;
  568. core_reg2sec (abfd) = bfd_make_section_anyway_with_flags (abfd, ".reg2",
  569. flags);
  570. if (core_reg2sec (abfd) == NULL)
  571. goto loser;
  572. core_stacksec (abfd)->size = core->c_ssize;
  573. core_datasec (abfd)->size = core->c_dsize;
  574. core_regsec (abfd)->size = core->c_regs_size;
  575. core_reg2sec (abfd)->size = core->fp_stuff_size;
  576. core_stacksec (abfd)->vma = (core->c_stacktop - core->c_ssize);
  577. core_datasec (abfd)->vma = core->c_data_addr;
  578. core_regsec (abfd)->vma = 0;
  579. core_reg2sec (abfd)->vma = 0;
  580. core_stacksec (abfd)->filepos = core->c_len + core->c_dsize;
  581. core_datasec (abfd)->filepos = core->c_len;
  582. /* We'll access the regs afresh in the core file, like any section: */
  583. core_regsec (abfd)->filepos = (file_ptr) core->c_regs_pos;
  584. core_reg2sec (abfd)->filepos = (file_ptr) core->fp_stuff_pos;
  585. /* Align to word at least. */
  586. core_stacksec (abfd)->alignment_power = 2;
  587. core_datasec (abfd)->alignment_power = 2;
  588. core_regsec (abfd)->alignment_power = 2;
  589. core_reg2sec (abfd)->alignment_power = 2;
  590. return abfd->xvec;
  591. }
  592. static char *
  593. sunos4_core_file_failing_command (bfd *abfd)
  594. {
  595. return core_hdr (abfd)->hdr->c_cmdname;
  596. }
  597. static int
  598. sunos4_core_file_failing_signal (bfd *abfd)
  599. {
  600. return core_hdr (abfd)->hdr->c_signo;
  601. }
  602. static bfd_boolean
  603. sunos4_core_file_matches_executable_p (bfd *core_bfd, bfd *exec_bfd)
  604. {
  605. if (core_bfd->xvec != exec_bfd->xvec)
  606. {
  607. bfd_set_error (bfd_error_system_call);
  608. return FALSE;
  609. }
  610. /* Solaris core files do not include an aouthdr. */
  611. if ((core_hdr (core_bfd)->hdr)->c_len == SOLARIS_BCP_CORE_LEN)
  612. return TRUE;
  613. return memcmp ((char *) &((core_hdr (core_bfd)->hdr)->c_aouthdr),
  614. (char *) exec_hdr (exec_bfd),
  615. sizeof (struct internal_exec)) == 0;
  616. }
  617. #define MY_set_sizes sunos4_set_sizes
  618. static bfd_boolean
  619. sunos4_set_sizes (bfd *abfd)
  620. {
  621. switch (bfd_get_arch (abfd))
  622. {
  623. default:
  624. return FALSE;
  625. case bfd_arch_sparc:
  626. adata (abfd).page_size = 0x2000;
  627. adata (abfd).segment_size = 0x2000;
  628. adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
  629. return TRUE;
  630. case bfd_arch_m68k:
  631. adata (abfd).page_size = 0x2000;
  632. adata (abfd).segment_size = 0x20000;
  633. adata (abfd).exec_bytes_size = EXEC_BYTES_SIZE;
  634. return TRUE;
  635. }
  636. }
  637. /* We default to setting the toolversion field to 1, as is required by
  638. SunOS. */
  639. #ifndef MY_exec_hdr_flags
  640. #define MY_exec_hdr_flags 1
  641. #endif
  642. #ifndef MY_entry_is_text_address
  643. #define MY_entry_is_text_address 0
  644. #endif
  645. #ifndef MY_add_dynamic_symbols
  646. #define MY_add_dynamic_symbols 0
  647. #endif
  648. #ifndef MY_add_one_symbol
  649. #define MY_add_one_symbol 0
  650. #endif
  651. #ifndef MY_link_dynamic_object
  652. #define MY_link_dynamic_object 0
  653. #endif
  654. #ifndef MY_write_dynamic_symbol
  655. #define MY_write_dynamic_symbol 0
  656. #endif
  657. #ifndef MY_check_dynamic_reloc
  658. #define MY_check_dynamic_reloc 0
  659. #endif
  660. #ifndef MY_finish_dynamic_link
  661. #define MY_finish_dynamic_link 0
  662. #endif
  663. static const struct aout_backend_data sunos4_aout_backend =
  664. {
  665. 0, /* Zmagic files are not contiguous. */
  666. 1, /* Text includes header. */
  667. MY_entry_is_text_address,
  668. MY_exec_hdr_flags,
  669. 0, /* Default text vma. */
  670. sunos4_set_sizes,
  671. 0, /* Header is counted in zmagic text. */
  672. MY_add_dynamic_symbols,
  673. MY_add_one_symbol,
  674. MY_link_dynamic_object,
  675. MY_write_dynamic_symbol,
  676. MY_check_dynamic_reloc,
  677. MY_finish_dynamic_link
  678. };
  679. #define MY_core_file_failing_command sunos4_core_file_failing_command
  680. #define MY_core_file_failing_signal sunos4_core_file_failing_signal
  681. #define MY_core_file_matches_executable_p sunos4_core_file_matches_executable_p
  682. #define MY_bfd_debug_info_start bfd_void
  683. #define MY_bfd_debug_info_end bfd_void
  684. #define MY_bfd_debug_info_accumulate (void (*) (bfd *, struct bfd_section *)) bfd_void
  685. #define MY_core_file_p sunos4_core_file_p
  686. #define MY_write_object_contents NAME(aout, sunos4_write_object_contents)
  687. #define MY_backend_data & sunos4_aout_backend
  688. #ifndef TARGET_IS_LITTLE_ENDIAN_P
  689. #define TARGET_IS_BIG_ENDIAN_P
  690. #endif
  691. #include "aout-target.h"