ecoffswap.h 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772
  1. /* Generic ECOFF swapping routines, for BFD.
  2. Copyright (C) 1992-2022 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. /* NOTE: This is a header file, but it contains executable routines.
  18. This is done this way because these routines are substantially
  19. similar, but are not identical, for all ECOFF targets.
  20. These are routines to swap the ECOFF symbolic information in and
  21. out. The routines are defined statically. You can set breakpoints
  22. on them in gdb by naming the including source file; e.g.,
  23. 'coff-mips.c':ecoff_swap_hdr_in.
  24. Before including this header file, one of ECOFF_32, ECOFF_64,
  25. ECOFF_SIGNED_32 or ECOFF_SIGNED_64 must be defined. These are
  26. checked when swapping information that depends upon the target
  27. size. This code works for 32 bit and 64 bit ECOFF, but may need to
  28. be generalized in the future.
  29. Some header file which defines the external forms of these
  30. structures must also be included before including this header file.
  31. Currently this is either coff/mips.h or coff/alpha.h.
  32. If the symbol TEST is defined when this file is compiled, a
  33. comparison is made to ensure that, in fact, the output is
  34. bit-for-bit the same as the input. Of course, this symbol should
  35. only be defined when deliberately testing the code on a machine
  36. with the proper byte sex and such. */
  37. #ifdef ECOFF_32
  38. #define ECOFF_GET_OFF H_GET_32
  39. #define ECOFF_PUT_OFF H_PUT_32
  40. #endif
  41. #ifdef ECOFF_64
  42. #define ECOFF_GET_OFF H_GET_64
  43. #define ECOFF_PUT_OFF H_PUT_64
  44. #endif
  45. #ifdef ECOFF_SIGNED_32
  46. #define ECOFF_GET_OFF H_GET_S32
  47. #define ECOFF_PUT_OFF H_PUT_S32
  48. #endif
  49. #ifdef ECOFF_SIGNED_64
  50. #define ECOFF_GET_OFF H_GET_S64
  51. #define ECOFF_PUT_OFF H_PUT_S64
  52. #endif
  53. /* ECOFF auxiliary information swapping routines. These are the same
  54. for all ECOFF targets, so they are defined in ecofflink.c. */
  55. extern void _bfd_ecoff_swap_tir_in
  56. (int, const struct tir_ext *, TIR *);
  57. extern void _bfd_ecoff_swap_tir_out
  58. (int, const TIR *, struct tir_ext *);
  59. extern void _bfd_ecoff_swap_rndx_in
  60. (int, const struct rndx_ext *, RNDXR *);
  61. extern void _bfd_ecoff_swap_rndx_out
  62. (int, const RNDXR *, struct rndx_ext *);
  63. /* Prototypes for functions defined in this file. */
  64. static void ecoff_swap_hdr_in (bfd *, void *, HDRR *);
  65. static void ecoff_swap_hdr_out (bfd *, const HDRR *, void *);
  66. static void ecoff_swap_fdr_in (bfd *, void *, FDR *);
  67. static void ecoff_swap_fdr_out (bfd *, const FDR *, void *);
  68. static void ecoff_swap_pdr_in (bfd *, void *, PDR *);
  69. static void ecoff_swap_pdr_out (bfd *, const PDR *, void *);
  70. static void ecoff_swap_sym_in (bfd *, void *, SYMR *);
  71. static void ecoff_swap_sym_out (bfd *, const SYMR *, void *);
  72. static void ecoff_swap_ext_in (bfd *, void *, EXTR *);
  73. static void ecoff_swap_ext_out (bfd *, const EXTR *, void *);
  74. static void ecoff_swap_rfd_in (bfd *, void *, RFDT *);
  75. static void ecoff_swap_rfd_out (bfd *, const RFDT *, void *);
  76. static void ecoff_swap_opt_in (bfd *, void *, OPTR *);
  77. static void ecoff_swap_opt_out (bfd *, const OPTR *, void *);
  78. static void ecoff_swap_dnr_in (bfd *, void *, DNR *);
  79. static void ecoff_swap_dnr_out (bfd *, const DNR *, void *);
  80. /* Swap in the symbolic header. */
  81. static void
  82. ecoff_swap_hdr_in (bfd *abfd, void * ext_copy, HDRR *intern)
  83. {
  84. struct hdr_ext ext[1];
  85. *ext = *(struct hdr_ext *) ext_copy;
  86. intern->magic = H_GET_S16 (abfd, ext->h_magic);
  87. intern->vstamp = H_GET_S16 (abfd, ext->h_vstamp);
  88. intern->ilineMax = H_GET_32 (abfd, ext->h_ilineMax);
  89. intern->cbLine = ECOFF_GET_OFF (abfd, ext->h_cbLine);
  90. intern->cbLineOffset = ECOFF_GET_OFF (abfd, ext->h_cbLineOffset);
  91. intern->idnMax = H_GET_32 (abfd, ext->h_idnMax);
  92. intern->cbDnOffset = ECOFF_GET_OFF (abfd, ext->h_cbDnOffset);
  93. intern->ipdMax = H_GET_32 (abfd, ext->h_ipdMax);
  94. intern->cbPdOffset = ECOFF_GET_OFF (abfd, ext->h_cbPdOffset);
  95. intern->isymMax = H_GET_32 (abfd, ext->h_isymMax);
  96. intern->cbSymOffset = ECOFF_GET_OFF (abfd, ext->h_cbSymOffset);
  97. intern->ioptMax = H_GET_32 (abfd, ext->h_ioptMax);
  98. intern->cbOptOffset = ECOFF_GET_OFF (abfd, ext->h_cbOptOffset);
  99. intern->iauxMax = H_GET_32 (abfd, ext->h_iauxMax);
  100. intern->cbAuxOffset = ECOFF_GET_OFF (abfd, ext->h_cbAuxOffset);
  101. intern->issMax = H_GET_32 (abfd, ext->h_issMax);
  102. intern->cbSsOffset = ECOFF_GET_OFF (abfd, ext->h_cbSsOffset);
  103. intern->issExtMax = H_GET_32 (abfd, ext->h_issExtMax);
  104. intern->cbSsExtOffset = ECOFF_GET_OFF (abfd, ext->h_cbSsExtOffset);
  105. intern->ifdMax = H_GET_32 (abfd, ext->h_ifdMax);
  106. intern->cbFdOffset = ECOFF_GET_OFF (abfd, ext->h_cbFdOffset);
  107. intern->crfd = H_GET_32 (abfd, ext->h_crfd);
  108. intern->cbRfdOffset = ECOFF_GET_OFF (abfd, ext->h_cbRfdOffset);
  109. intern->iextMax = H_GET_32 (abfd, ext->h_iextMax);
  110. intern->cbExtOffset = ECOFF_GET_OFF (abfd, ext->h_cbExtOffset);
  111. #ifdef TEST
  112. if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
  113. abort ();
  114. #endif
  115. }
  116. /* Swap out the symbolic header. */
  117. static void
  118. ecoff_swap_hdr_out (bfd *abfd, const HDRR *intern_copy, void * ext_ptr)
  119. {
  120. struct hdr_ext *ext = (struct hdr_ext *) ext_ptr;
  121. HDRR intern[1];
  122. *intern = *intern_copy;
  123. H_PUT_S16 (abfd, intern->magic, ext->h_magic);
  124. H_PUT_S16 (abfd, intern->vstamp, ext->h_vstamp);
  125. H_PUT_32 (abfd, intern->ilineMax, ext->h_ilineMax);
  126. ECOFF_PUT_OFF (abfd, intern->cbLine, ext->h_cbLine);
  127. ECOFF_PUT_OFF (abfd, intern->cbLineOffset, ext->h_cbLineOffset);
  128. H_PUT_32 (abfd, intern->idnMax, ext->h_idnMax);
  129. ECOFF_PUT_OFF (abfd, intern->cbDnOffset, ext->h_cbDnOffset);
  130. H_PUT_32 (abfd, intern->ipdMax, ext->h_ipdMax);
  131. ECOFF_PUT_OFF (abfd, intern->cbPdOffset, ext->h_cbPdOffset);
  132. H_PUT_32 (abfd, intern->isymMax, ext->h_isymMax);
  133. ECOFF_PUT_OFF (abfd, intern->cbSymOffset, ext->h_cbSymOffset);
  134. H_PUT_32 (abfd, intern->ioptMax, ext->h_ioptMax);
  135. ECOFF_PUT_OFF (abfd, intern->cbOptOffset, ext->h_cbOptOffset);
  136. H_PUT_32 (abfd, intern->iauxMax, ext->h_iauxMax);
  137. ECOFF_PUT_OFF (abfd, intern->cbAuxOffset, ext->h_cbAuxOffset);
  138. H_PUT_32 (abfd, intern->issMax, ext->h_issMax);
  139. ECOFF_PUT_OFF (abfd, intern->cbSsOffset, ext->h_cbSsOffset);
  140. H_PUT_32 (abfd, intern->issExtMax, ext->h_issExtMax);
  141. ECOFF_PUT_OFF (abfd, intern->cbSsExtOffset, ext->h_cbSsExtOffset);
  142. H_PUT_32 (abfd, intern->ifdMax, ext->h_ifdMax);
  143. ECOFF_PUT_OFF (abfd, intern->cbFdOffset, ext->h_cbFdOffset);
  144. H_PUT_32 (abfd, intern->crfd, ext->h_crfd);
  145. ECOFF_PUT_OFF (abfd, intern->cbRfdOffset, ext->h_cbRfdOffset);
  146. H_PUT_32 (abfd, intern->iextMax, ext->h_iextMax);
  147. ECOFF_PUT_OFF (abfd, intern->cbExtOffset, ext->h_cbExtOffset);
  148. #ifdef TEST
  149. if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
  150. abort ();
  151. #endif
  152. }
  153. /* Swap in the file descriptor record. */
  154. static void
  155. ecoff_swap_fdr_in (bfd *abfd, void * ext_copy, FDR *intern)
  156. {
  157. struct fdr_ext ext[1];
  158. *ext = *(struct fdr_ext *) ext_copy;
  159. intern->adr = ECOFF_GET_OFF (abfd, ext->f_adr);
  160. intern->rss = H_GET_32 (abfd, ext->f_rss);
  161. #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
  162. if (intern->rss == (signed long) 0xffffffff)
  163. intern->rss = -1;
  164. #endif
  165. intern->issBase = H_GET_32 (abfd, ext->f_issBase);
  166. intern->cbSs = ECOFF_GET_OFF (abfd, ext->f_cbSs);
  167. intern->isymBase = H_GET_32 (abfd, ext->f_isymBase);
  168. intern->csym = H_GET_32 (abfd, ext->f_csym);
  169. intern->ilineBase = H_GET_32 (abfd, ext->f_ilineBase);
  170. intern->cline = H_GET_32 (abfd, ext->f_cline);
  171. intern->ioptBase = H_GET_32 (abfd, ext->f_ioptBase);
  172. intern->copt = H_GET_32 (abfd, ext->f_copt);
  173. #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
  174. intern->ipdFirst = H_GET_16 (abfd, ext->f_ipdFirst);
  175. intern->cpd = H_GET_16 (abfd, ext->f_cpd);
  176. #endif
  177. #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
  178. intern->ipdFirst = H_GET_32 (abfd, ext->f_ipdFirst);
  179. intern->cpd = H_GET_32 (abfd, ext->f_cpd);
  180. #endif
  181. intern->iauxBase = H_GET_32 (abfd, ext->f_iauxBase);
  182. intern->caux = H_GET_32 (abfd, ext->f_caux);
  183. intern->rfdBase = H_GET_32 (abfd, ext->f_rfdBase);
  184. intern->crfd = H_GET_32 (abfd, ext->f_crfd);
  185. /* Now the fun stuff... */
  186. if (bfd_header_big_endian (abfd))
  187. {
  188. intern->lang = ((ext->f_bits1[0] & FDR_BITS1_LANG_BIG)
  189. >> FDR_BITS1_LANG_SH_BIG);
  190. intern->fMerge = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_BIG);
  191. intern->fReadin = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_BIG);
  192. intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_BIG);
  193. intern->glevel = ((ext->f_bits2[0] & FDR_BITS2_GLEVEL_BIG)
  194. >> FDR_BITS2_GLEVEL_SH_BIG);
  195. }
  196. else
  197. {
  198. intern->lang = ((ext->f_bits1[0] & FDR_BITS1_LANG_LITTLE)
  199. >> FDR_BITS1_LANG_SH_LITTLE);
  200. intern->fMerge = 0 != (ext->f_bits1[0] & FDR_BITS1_FMERGE_LITTLE);
  201. intern->fReadin = 0 != (ext->f_bits1[0] & FDR_BITS1_FREADIN_LITTLE);
  202. intern->fBigendian = 0 != (ext->f_bits1[0] & FDR_BITS1_FBIGENDIAN_LITTLE);
  203. intern->glevel = ((ext->f_bits2[0] & FDR_BITS2_GLEVEL_LITTLE)
  204. >> FDR_BITS2_GLEVEL_SH_LITTLE);
  205. }
  206. intern->reserved = 0;
  207. intern->cbLineOffset = ECOFF_GET_OFF (abfd, ext->f_cbLineOffset);
  208. intern->cbLine = ECOFF_GET_OFF (abfd, ext->f_cbLine);
  209. #ifdef TEST
  210. if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
  211. abort ();
  212. #endif
  213. }
  214. /* Swap out the file descriptor record. */
  215. static void
  216. ecoff_swap_fdr_out (bfd *abfd, const FDR *intern_copy, void * ext_ptr)
  217. {
  218. struct fdr_ext *ext = (struct fdr_ext *) ext_ptr;
  219. FDR intern[1];
  220. /* Make it reasonable to do in-place. */
  221. *intern = *intern_copy;
  222. ECOFF_PUT_OFF (abfd, intern->adr, ext->f_adr);
  223. H_PUT_32 (abfd, intern->rss, ext->f_rss);
  224. H_PUT_32 (abfd, intern->issBase, ext->f_issBase);
  225. ECOFF_PUT_OFF (abfd, intern->cbSs, ext->f_cbSs);
  226. H_PUT_32 (abfd, intern->isymBase, ext->f_isymBase);
  227. H_PUT_32 (abfd, intern->csym, ext->f_csym);
  228. H_PUT_32 (abfd, intern->ilineBase, ext->f_ilineBase);
  229. H_PUT_32 (abfd, intern->cline, ext->f_cline);
  230. H_PUT_32 (abfd, intern->ioptBase, ext->f_ioptBase);
  231. H_PUT_32 (abfd, intern->copt, ext->f_copt);
  232. #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
  233. H_PUT_16 (abfd, intern->ipdFirst, ext->f_ipdFirst);
  234. H_PUT_16 (abfd, intern->cpd, ext->f_cpd);
  235. #endif
  236. #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
  237. H_PUT_32 (abfd, intern->ipdFirst, ext->f_ipdFirst);
  238. H_PUT_32 (abfd, intern->cpd, ext->f_cpd);
  239. #endif
  240. H_PUT_32 (abfd, intern->iauxBase, ext->f_iauxBase);
  241. H_PUT_32 (abfd, intern->caux, ext->f_caux);
  242. H_PUT_32 (abfd, intern->rfdBase, ext->f_rfdBase);
  243. H_PUT_32 (abfd, intern->crfd, ext->f_crfd);
  244. /* Now the fun stuff... */
  245. if (bfd_header_big_endian (abfd))
  246. {
  247. ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_BIG)
  248. & FDR_BITS1_LANG_BIG)
  249. | (intern->fMerge ? FDR_BITS1_FMERGE_BIG : 0)
  250. | (intern->fReadin ? FDR_BITS1_FREADIN_BIG : 0)
  251. | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_BIG : 0));
  252. ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_BIG)
  253. & FDR_BITS2_GLEVEL_BIG);
  254. ext->f_bits2[1] = 0;
  255. ext->f_bits2[2] = 0;
  256. }
  257. else
  258. {
  259. ext->f_bits1[0] = (((intern->lang << FDR_BITS1_LANG_SH_LITTLE)
  260. & FDR_BITS1_LANG_LITTLE)
  261. | (intern->fMerge ? FDR_BITS1_FMERGE_LITTLE : 0)
  262. | (intern->fReadin ? FDR_BITS1_FREADIN_LITTLE : 0)
  263. | (intern->fBigendian ? FDR_BITS1_FBIGENDIAN_LITTLE : 0));
  264. ext->f_bits2[0] = ((intern->glevel << FDR_BITS2_GLEVEL_SH_LITTLE)
  265. & FDR_BITS2_GLEVEL_LITTLE);
  266. ext->f_bits2[1] = 0;
  267. ext->f_bits2[2] = 0;
  268. }
  269. ECOFF_PUT_OFF (abfd, intern->cbLineOffset, ext->f_cbLineOffset);
  270. ECOFF_PUT_OFF (abfd, intern->cbLine, ext->f_cbLine);
  271. #ifdef TEST
  272. if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
  273. abort ();
  274. #endif
  275. }
  276. /* Swap in the procedure descriptor record. */
  277. static void
  278. ecoff_swap_pdr_in (bfd *abfd, void * ext_copy, PDR *intern)
  279. {
  280. struct pdr_ext ext[1];
  281. *ext = *(struct pdr_ext *) ext_copy;
  282. memset ((void *) intern, 0, sizeof (*intern));
  283. intern->adr = ECOFF_GET_OFF (abfd, ext->p_adr);
  284. intern->isym = H_GET_32 (abfd, ext->p_isym);
  285. intern->iline = H_GET_32 (abfd, ext->p_iline);
  286. intern->regmask = H_GET_32 (abfd, ext->p_regmask);
  287. intern->regoffset = H_GET_S32 (abfd, ext->p_regoffset);
  288. intern->iopt = H_GET_S32 (abfd, ext->p_iopt);
  289. intern->fregmask = H_GET_32 (abfd, ext->p_fregmask);
  290. intern->fregoffset = H_GET_S32 (abfd, ext->p_fregoffset);
  291. intern->frameoffset = H_GET_S32 (abfd, ext->p_frameoffset);
  292. intern->framereg = H_GET_16 (abfd, ext->p_framereg);
  293. intern->pcreg = H_GET_16 (abfd, ext->p_pcreg);
  294. intern->lnLow = H_GET_32 (abfd, ext->p_lnLow);
  295. intern->lnHigh = H_GET_32 (abfd, ext->p_lnHigh);
  296. intern->cbLineOffset = ECOFF_GET_OFF (abfd, ext->p_cbLineOffset);
  297. #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
  298. if (intern->isym == (signed long) 0xffffffff)
  299. intern->isym = -1;
  300. if (intern->iline == (signed long) 0xffffffff)
  301. intern->iline = -1;
  302. intern->gp_prologue = H_GET_8 (abfd, ext->p_gp_prologue);
  303. if (bfd_header_big_endian (abfd))
  304. {
  305. intern->gp_used = 0 != (ext->p_bits1[0] & PDR_BITS1_GP_USED_BIG);
  306. intern->reg_frame = 0 != (ext->p_bits1[0] & PDR_BITS1_REG_FRAME_BIG);
  307. intern->prof = 0 != (ext->p_bits1[0] & PDR_BITS1_PROF_BIG);
  308. intern->reserved = (((ext->p_bits1[0] & PDR_BITS1_RESERVED_BIG)
  309. << PDR_BITS1_RESERVED_SH_LEFT_BIG)
  310. | ((ext->p_bits2[0] & PDR_BITS2_RESERVED_BIG)
  311. >> PDR_BITS2_RESERVED_SH_BIG));
  312. }
  313. else
  314. {
  315. intern->gp_used = 0 != (ext->p_bits1[0] & PDR_BITS1_GP_USED_LITTLE);
  316. intern->reg_frame = 0 != (ext->p_bits1[0] & PDR_BITS1_REG_FRAME_LITTLE);
  317. intern->prof = 0 != (ext->p_bits1[0] & PDR_BITS1_PROF_LITTLE);
  318. intern->reserved = (((ext->p_bits1[0] & PDR_BITS1_RESERVED_LITTLE)
  319. >> PDR_BITS1_RESERVED_SH_LITTLE)
  320. | ((ext->p_bits2[0] & PDR_BITS2_RESERVED_LITTLE)
  321. << PDR_BITS2_RESERVED_SH_LEFT_LITTLE));
  322. }
  323. intern->localoff = H_GET_8 (abfd, ext->p_localoff);
  324. #endif
  325. #ifdef TEST
  326. if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
  327. abort ();
  328. #endif
  329. }
  330. /* Swap out the procedure descriptor record. */
  331. static void
  332. ecoff_swap_pdr_out (bfd *abfd, const PDR *intern_copy, void * ext_ptr)
  333. {
  334. struct pdr_ext *ext = (struct pdr_ext *) ext_ptr;
  335. PDR intern[1];
  336. /* Make it reasonable to do in-place. */
  337. *intern = *intern_copy;
  338. ECOFF_PUT_OFF (abfd, intern->adr, ext->p_adr);
  339. H_PUT_32 (abfd, intern->isym, ext->p_isym);
  340. H_PUT_32 (abfd, intern->iline, ext->p_iline);
  341. H_PUT_32 (abfd, intern->regmask, ext->p_regmask);
  342. H_PUT_32 (abfd, intern->regoffset, ext->p_regoffset);
  343. H_PUT_32 (abfd, intern->iopt, ext->p_iopt);
  344. H_PUT_32 (abfd, intern->fregmask, ext->p_fregmask);
  345. H_PUT_32 (abfd, intern->fregoffset, ext->p_fregoffset);
  346. H_PUT_32 (abfd, intern->frameoffset, ext->p_frameoffset);
  347. H_PUT_16 (abfd, intern->framereg, ext->p_framereg);
  348. H_PUT_16 (abfd, intern->pcreg, ext->p_pcreg);
  349. H_PUT_32 (abfd, intern->lnLow, ext->p_lnLow);
  350. H_PUT_32 (abfd, intern->lnHigh, ext->p_lnHigh);
  351. ECOFF_PUT_OFF (abfd, intern->cbLineOffset, ext->p_cbLineOffset);
  352. #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
  353. H_PUT_8 (abfd, intern->gp_prologue, ext->p_gp_prologue);
  354. if (bfd_header_big_endian (abfd))
  355. {
  356. ext->p_bits1[0] = ((intern->gp_used ? PDR_BITS1_GP_USED_BIG : 0)
  357. | (intern->reg_frame ? PDR_BITS1_REG_FRAME_BIG : 0)
  358. | (intern->prof ? PDR_BITS1_PROF_BIG : 0)
  359. | ((intern->reserved
  360. >> PDR_BITS1_RESERVED_SH_LEFT_BIG)
  361. & PDR_BITS1_RESERVED_BIG));
  362. ext->p_bits2[0] = ((intern->reserved << PDR_BITS2_RESERVED_SH_BIG)
  363. & PDR_BITS2_RESERVED_BIG);
  364. }
  365. else
  366. {
  367. ext->p_bits1[0] = ((intern->gp_used ? PDR_BITS1_GP_USED_LITTLE : 0)
  368. | (intern->reg_frame ? PDR_BITS1_REG_FRAME_LITTLE : 0)
  369. | (intern->prof ? PDR_BITS1_PROF_LITTLE : 0)
  370. | ((intern->reserved << PDR_BITS1_RESERVED_SH_LITTLE)
  371. & PDR_BITS1_RESERVED_LITTLE));
  372. ext->p_bits2[0] = ((intern->reserved >>
  373. PDR_BITS2_RESERVED_SH_LEFT_LITTLE)
  374. & PDR_BITS2_RESERVED_LITTLE);
  375. }
  376. H_PUT_8 (abfd, intern->localoff, ext->p_localoff);
  377. #endif
  378. #ifdef TEST
  379. if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
  380. abort ();
  381. #endif
  382. }
  383. /* Swap in a symbol record. */
  384. static void
  385. ecoff_swap_sym_in (bfd *abfd, void * ext_copy, SYMR *intern)
  386. {
  387. struct sym_ext ext[1];
  388. *ext = *(struct sym_ext *) ext_copy;
  389. intern->iss = H_GET_32 (abfd, ext->s_iss);
  390. intern->value = ECOFF_GET_OFF (abfd, ext->s_value);
  391. #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
  392. if (intern->iss == (signed long) 0xffffffff)
  393. intern->iss = -1;
  394. #endif
  395. /* Now the fun stuff... */
  396. if (bfd_header_big_endian (abfd))
  397. {
  398. intern->st = (ext->s_bits1[0] & SYM_BITS1_ST_BIG)
  399. >> SYM_BITS1_ST_SH_BIG;
  400. intern->sc = ((ext->s_bits1[0] & SYM_BITS1_SC_BIG)
  401. << SYM_BITS1_SC_SH_LEFT_BIG)
  402. | ((ext->s_bits2[0] & SYM_BITS2_SC_BIG)
  403. >> SYM_BITS2_SC_SH_BIG);
  404. intern->reserved = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_BIG);
  405. intern->index = ((ext->s_bits2[0] & SYM_BITS2_INDEX_BIG)
  406. << SYM_BITS2_INDEX_SH_LEFT_BIG)
  407. | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_BIG)
  408. | (ext->s_bits4[0] << SYM_BITS4_INDEX_SH_LEFT_BIG);
  409. }
  410. else
  411. {
  412. intern->st = (ext->s_bits1[0] & SYM_BITS1_ST_LITTLE)
  413. >> SYM_BITS1_ST_SH_LITTLE;
  414. intern->sc = ((ext->s_bits1[0] & SYM_BITS1_SC_LITTLE)
  415. >> SYM_BITS1_SC_SH_LITTLE)
  416. | ((ext->s_bits2[0] & SYM_BITS2_SC_LITTLE)
  417. << SYM_BITS2_SC_SH_LEFT_LITTLE);
  418. intern->reserved = 0 != (ext->s_bits2[0] & SYM_BITS2_RESERVED_LITTLE);
  419. intern->index = ((ext->s_bits2[0] & SYM_BITS2_INDEX_LITTLE)
  420. >> SYM_BITS2_INDEX_SH_LITTLE)
  421. | (ext->s_bits3[0] << SYM_BITS3_INDEX_SH_LEFT_LITTLE)
  422. | ((unsigned int) ext->s_bits4[0]
  423. << SYM_BITS4_INDEX_SH_LEFT_LITTLE);
  424. }
  425. #ifdef TEST
  426. if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
  427. abort ();
  428. #endif
  429. }
  430. /* Swap out a symbol record. */
  431. static void
  432. ecoff_swap_sym_out (bfd *abfd, const SYMR *intern_copy, void * ext_ptr)
  433. {
  434. struct sym_ext *ext = (struct sym_ext *) ext_ptr;
  435. SYMR intern[1];
  436. /* Make it reasonable to do in-place. */
  437. *intern = *intern_copy;
  438. H_PUT_32 (abfd, intern->iss, ext->s_iss);
  439. ECOFF_PUT_OFF (abfd, intern->value, ext->s_value);
  440. /* Now the fun stuff... */
  441. if (bfd_header_big_endian (abfd))
  442. {
  443. ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_BIG)
  444. & SYM_BITS1_ST_BIG)
  445. | ((intern->sc >> SYM_BITS1_SC_SH_LEFT_BIG)
  446. & SYM_BITS1_SC_BIG));
  447. ext->s_bits2[0] = (((intern->sc << SYM_BITS2_SC_SH_BIG)
  448. & SYM_BITS2_SC_BIG)
  449. | (intern->reserved ? SYM_BITS2_RESERVED_BIG : 0)
  450. | ((intern->index >> SYM_BITS2_INDEX_SH_LEFT_BIG)
  451. & SYM_BITS2_INDEX_BIG));
  452. ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_BIG) & 0xff;
  453. ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_BIG) & 0xff;
  454. }
  455. else
  456. {
  457. ext->s_bits1[0] = (((intern->st << SYM_BITS1_ST_SH_LITTLE)
  458. & SYM_BITS1_ST_LITTLE)
  459. | ((intern->sc << SYM_BITS1_SC_SH_LITTLE)
  460. & SYM_BITS1_SC_LITTLE));
  461. ext->s_bits2[0] = (((intern->sc >> SYM_BITS2_SC_SH_LEFT_LITTLE)
  462. & SYM_BITS2_SC_LITTLE)
  463. | (intern->reserved ? SYM_BITS2_RESERVED_LITTLE : 0)
  464. | ((intern->index << SYM_BITS2_INDEX_SH_LITTLE)
  465. & SYM_BITS2_INDEX_LITTLE));
  466. ext->s_bits3[0] = (intern->index >> SYM_BITS3_INDEX_SH_LEFT_LITTLE) & 0xff;
  467. ext->s_bits4[0] = (intern->index >> SYM_BITS4_INDEX_SH_LEFT_LITTLE) & 0xff;
  468. }
  469. #ifdef TEST
  470. if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
  471. abort ();
  472. #endif
  473. }
  474. /* Swap in an external symbol record. */
  475. static void
  476. ecoff_swap_ext_in (bfd *abfd, void * ext_copy, EXTR *intern)
  477. {
  478. struct ext_ext ext[1];
  479. *ext = *(struct ext_ext *) ext_copy;
  480. /* Now the fun stuff... */
  481. if (bfd_header_big_endian (abfd))
  482. {
  483. intern->jmptbl = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_BIG);
  484. intern->cobol_main = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_BIG);
  485. intern->weakext = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_BIG);
  486. }
  487. else
  488. {
  489. intern->jmptbl = 0 != (ext->es_bits1[0] & EXT_BITS1_JMPTBL_LITTLE);
  490. intern->cobol_main = 0 != (ext->es_bits1[0] & EXT_BITS1_COBOL_MAIN_LITTLE);
  491. intern->weakext = 0 != (ext->es_bits1[0] & EXT_BITS1_WEAKEXT_LITTLE);
  492. }
  493. intern->reserved = 0;
  494. #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
  495. intern->ifd = H_GET_S16 (abfd, ext->es_ifd);
  496. #endif
  497. #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
  498. intern->ifd = H_GET_S32 (abfd, ext->es_ifd);
  499. #endif
  500. ecoff_swap_sym_in (abfd, &ext->es_asym, &intern->asym);
  501. #ifdef TEST
  502. if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
  503. abort ();
  504. #endif
  505. }
  506. /* Swap out an external symbol record. */
  507. static void
  508. ecoff_swap_ext_out (bfd *abfd, const EXTR *intern_copy, void * ext_ptr)
  509. {
  510. struct ext_ext *ext = (struct ext_ext *) ext_ptr;
  511. EXTR intern[1];
  512. /* Make it reasonable to do in-place. */
  513. *intern = *intern_copy;
  514. /* Now the fun stuff... */
  515. if (bfd_header_big_endian (abfd))
  516. {
  517. ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_BIG : 0)
  518. | (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_BIG : 0)
  519. | (intern->weakext ? EXT_BITS1_WEAKEXT_BIG : 0));
  520. ext->es_bits2[0] = 0;
  521. #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
  522. ext->es_bits2[1] = 0;
  523. ext->es_bits2[2] = 0;
  524. #endif
  525. }
  526. else
  527. {
  528. ext->es_bits1[0] = ((intern->jmptbl ? EXT_BITS1_JMPTBL_LITTLE : 0)
  529. | (intern->cobol_main ? EXT_BITS1_COBOL_MAIN_LITTLE : 0)
  530. | (intern->weakext ? EXT_BITS1_WEAKEXT_LITTLE : 0));
  531. ext->es_bits2[0] = 0;
  532. #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
  533. ext->es_bits2[1] = 0;
  534. ext->es_bits2[2] = 0;
  535. #endif
  536. }
  537. #if defined (ECOFF_32) || defined (ECOFF_SIGNED_32)
  538. H_PUT_S16 (abfd, intern->ifd, ext->es_ifd);
  539. #endif
  540. #if defined (ECOFF_64) || defined (ECOFF_SIGNED_64)
  541. H_PUT_S32 (abfd, intern->ifd, ext->es_ifd);
  542. #endif
  543. ecoff_swap_sym_out (abfd, &intern->asym, &ext->es_asym);
  544. #ifdef TEST
  545. if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
  546. abort ();
  547. #endif
  548. }
  549. /* Swap in a relative file descriptor. */
  550. static void
  551. ecoff_swap_rfd_in (bfd *abfd, void * ext_ptr, RFDT *intern)
  552. {
  553. struct rfd_ext *ext = (struct rfd_ext *) ext_ptr;
  554. *intern = H_GET_32 (abfd, ext->rfd);
  555. #ifdef TEST
  556. if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
  557. abort ();
  558. #endif
  559. }
  560. /* Swap out a relative file descriptor. */
  561. static void
  562. ecoff_swap_rfd_out (bfd *abfd, const RFDT *intern, void * ext_ptr)
  563. {
  564. struct rfd_ext *ext = (struct rfd_ext *) ext_ptr;
  565. H_PUT_32 (abfd, *intern, ext->rfd);
  566. #ifdef TEST
  567. if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
  568. abort ();
  569. #endif
  570. }
  571. /* Swap in an optimization symbol. */
  572. static void
  573. ecoff_swap_opt_in (bfd *abfd, void * ext_copy, OPTR * intern)
  574. {
  575. struct opt_ext ext[1];
  576. *ext = *(struct opt_ext *) ext_copy;
  577. if (bfd_header_big_endian (abfd))
  578. {
  579. intern->ot = ext->o_bits1[0];
  580. intern->value = (((unsigned int) ext->o_bits2[0]
  581. << OPT_BITS2_VALUE_SH_LEFT_BIG)
  582. | ((unsigned int) ext->o_bits3[0]
  583. << OPT_BITS2_VALUE_SH_LEFT_BIG)
  584. | ((unsigned int) ext->o_bits4[0]
  585. << OPT_BITS2_VALUE_SH_LEFT_BIG));
  586. }
  587. else
  588. {
  589. intern->ot = ext->o_bits1[0];
  590. intern->value = ((ext->o_bits2[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
  591. | (ext->o_bits3[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE)
  592. | (ext->o_bits4[0] << OPT_BITS2_VALUE_SH_LEFT_LITTLE));
  593. }
  594. _bfd_ecoff_swap_rndx_in (bfd_header_big_endian (abfd),
  595. &ext->o_rndx, &intern->rndx);
  596. intern->offset = H_GET_32 (abfd, ext->o_offset);
  597. #ifdef TEST
  598. if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
  599. abort ();
  600. #endif
  601. }
  602. /* Swap out an optimization symbol. */
  603. static void
  604. ecoff_swap_opt_out (bfd *abfd, const OPTR *intern_copy, void * ext_ptr)
  605. {
  606. struct opt_ext *ext = (struct opt_ext *) ext_ptr;
  607. OPTR intern[1];
  608. /* Make it reasonable to do in-place. */
  609. *intern = *intern_copy;
  610. if (bfd_header_big_endian (abfd))
  611. {
  612. ext->o_bits1[0] = intern->ot;
  613. ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_BIG;
  614. ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_BIG;
  615. ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_BIG;
  616. }
  617. else
  618. {
  619. ext->o_bits1[0] = intern->ot;
  620. ext->o_bits2[0] = intern->value >> OPT_BITS2_VALUE_SH_LEFT_LITTLE;
  621. ext->o_bits3[0] = intern->value >> OPT_BITS3_VALUE_SH_LEFT_LITTLE;
  622. ext->o_bits4[0] = intern->value >> OPT_BITS4_VALUE_SH_LEFT_LITTLE;
  623. }
  624. _bfd_ecoff_swap_rndx_out (bfd_header_big_endian (abfd),
  625. &intern->rndx, &ext->o_rndx);
  626. H_PUT_32 (abfd, intern->value, ext->o_offset);
  627. #ifdef TEST
  628. if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
  629. abort ();
  630. #endif
  631. }
  632. /* Swap in a dense number. */
  633. static void
  634. ecoff_swap_dnr_in (bfd *abfd, void * ext_copy, DNR *intern)
  635. {
  636. struct dnr_ext ext[1];
  637. *ext = *(struct dnr_ext *) ext_copy;
  638. intern->rfd = H_GET_32 (abfd, ext->d_rfd);
  639. intern->index = H_GET_32 (abfd, ext->d_index);
  640. #ifdef TEST
  641. if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
  642. abort ();
  643. #endif
  644. }
  645. /* Swap out a dense number. */
  646. static void
  647. ecoff_swap_dnr_out (bfd *abfd, const DNR *intern_copy, void * ext_ptr)
  648. {
  649. struct dnr_ext *ext = (struct dnr_ext *) ext_ptr;
  650. DNR intern[1];
  651. /* Make it reasonable to do in-place. */
  652. *intern = *intern_copy;
  653. H_PUT_32 (abfd, intern->rfd, ext->d_rfd);
  654. H_PUT_32 (abfd, intern->index, ext->d_index);
  655. #ifdef TEST
  656. if (memcmp ((char *) ext, (char *) intern, sizeof (*intern)) != 0)
  657. abort ();
  658. #endif
  659. }