i386os9k.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. /* BFD back-end for os9000 i386 binaries.
  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 "bfdlink.h"
  21. #include "libaout.h" /* BFD a.out internal data structures */
  22. #include "os9k.h"
  23. /* Swaps the information in an executable header taken from a raw byte
  24. stream memory image, into the internal exec_header structure. */
  25. static bfd_boolean
  26. os9k_swap_exec_header_in (bfd *abfd,
  27. mh_com *raw_bytes,
  28. struct internal_exec *execp)
  29. {
  30. mh_com *bytes = (mh_com *) raw_bytes;
  31. unsigned int dload, dmemsize, dmemstart;
  32. /* Now fill in fields in the execp, from the bytes in the raw data. */
  33. execp->a_info = H_GET_16 (abfd, bytes->m_sync);
  34. execp->a_syms = 0;
  35. execp->a_entry = H_GET_32 (abfd, bytes->m_exec);
  36. execp->a_talign = 2;
  37. execp->a_dalign = 2;
  38. execp->a_balign = 2;
  39. dload = H_GET_32 (abfd, bytes->m_idata);
  40. execp->a_data = dload + 8;
  41. if (bfd_seek (abfd, (file_ptr) dload, SEEK_SET) != 0
  42. || (bfd_bread (&dmemstart, (bfd_size_type) sizeof (dmemstart), abfd)
  43. != sizeof (dmemstart))
  44. || (bfd_bread (&dmemsize, (bfd_size_type) sizeof (dmemsize), abfd)
  45. != sizeof (dmemsize)))
  46. return FALSE;
  47. execp->a_tload = 0;
  48. execp->a_dload = H_GET_32 (abfd, (unsigned char *) &dmemstart);
  49. execp->a_text = dload - execp->a_tload;
  50. execp->a_data = H_GET_32 (abfd, (unsigned char *) &dmemsize);
  51. execp->a_bss = H_GET_32 (abfd, bytes->m_data) - execp->a_data;
  52. execp->a_trsize = 0;
  53. execp->a_drsize = 0;
  54. return TRUE;
  55. }
  56. /* Finish up the opening of a b.out file for reading. Fill in all the
  57. fields that are not handled by common code. */
  58. static const bfd_target *
  59. os9k_callback (bfd *abfd)
  60. {
  61. struct internal_exec *execp = exec_hdr (abfd);
  62. unsigned long bss_start;
  63. /* Architecture and machine type. */
  64. bfd_set_arch_mach (abfd, bfd_arch_i386, 0);
  65. /* The positions of the string table and symbol table. */
  66. obj_str_filepos (abfd) = 0;
  67. obj_sym_filepos (abfd) = 0;
  68. /* The alignments of the sections. */
  69. obj_textsec (abfd)->alignment_power = execp->a_talign;
  70. obj_datasec (abfd)->alignment_power = execp->a_dalign;
  71. obj_bsssec (abfd)->alignment_power = execp->a_balign;
  72. /* The starting addresses of the sections. */
  73. obj_textsec (abfd)->vma = execp->a_tload;
  74. obj_datasec (abfd)->vma = execp->a_dload;
  75. /* And reload the sizes, since the aout module zaps them. */
  76. obj_textsec (abfd)->size = execp->a_text;
  77. bss_start = execp->a_dload + execp->a_data; /* BSS = end of data section. */
  78. obj_bsssec (abfd)->vma = align_power (bss_start, execp->a_balign);
  79. /* The file positions of the sections. */
  80. obj_textsec (abfd)->filepos = execp->a_entry;
  81. obj_datasec (abfd)->filepos = execp->a_dload;
  82. /* The file positions of the relocation info ***
  83. obj_textsec (abfd)->rel_filepos = N_TROFF(*execp);
  84. obj_datasec (abfd)->rel_filepos = N_DROFF(*execp); */
  85. adata (abfd).page_size = 1; /* Not applicable. */
  86. adata (abfd).segment_size = 1;/* Not applicable. */
  87. adata (abfd).exec_bytes_size = MHCOM_BYTES_SIZE;
  88. return abfd->xvec;
  89. }
  90. static const bfd_target *
  91. os9k_object_p (bfd *abfd)
  92. {
  93. struct internal_exec anexec;
  94. mh_com exec_bytes;
  95. if (bfd_bread (&exec_bytes, (bfd_size_type) MHCOM_BYTES_SIZE, abfd)
  96. != MHCOM_BYTES_SIZE)
  97. {
  98. if (bfd_get_error () != bfd_error_system_call)
  99. bfd_set_error (bfd_error_wrong_format);
  100. return 0;
  101. }
  102. anexec.a_info = H_GET_16 (abfd, exec_bytes.m_sync);
  103. if (N_BADMAG (anexec))
  104. {
  105. bfd_set_error (bfd_error_wrong_format);
  106. return 0;
  107. }
  108. if (! os9k_swap_exec_header_in (abfd, &exec_bytes, &anexec))
  109. {
  110. if (bfd_get_error () != bfd_error_system_call)
  111. bfd_set_error (bfd_error_wrong_format);
  112. return NULL;
  113. }
  114. return aout_32_some_aout_object_p (abfd, &anexec, os9k_callback);
  115. }
  116. static int
  117. os9k_sizeof_headers (bfd *abfd ATTRIBUTE_UNUSED,
  118. struct bfd_link_info *info ATTRIBUTE_UNUSED)
  119. {
  120. return sizeof (struct internal_exec);
  121. }
  122. #define aout_32_close_and_cleanup aout_32_bfd_free_cached_info
  123. #define aout_32_find_line _bfd_nosymbols_find_line
  124. #define aout_32_get_symbol_version_string \
  125. _bfd_nosymbols_get_symbol_version_string
  126. #define aout_32_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
  127. #define aout_32_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
  128. #define aout_32_bfd_reloc_name_lookup _bfd_norelocs_bfd_reloc_name_lookup
  129. #define aout_32_get_section_contents_in_window \
  130. _bfd_generic_get_section_contents_in_window
  131. #define os9k_bfd_get_relocated_section_contents \
  132. bfd_generic_get_relocated_section_contents
  133. #define os9k_bfd_relax_section bfd_generic_relax_section
  134. #define os9k_bfd_gc_sections bfd_generic_gc_sections
  135. #define os9k_bfd_lookup_section_flags bfd_generic_lookup_section_flags
  136. #define os9k_bfd_merge_sections bfd_generic_merge_sections
  137. #define os9k_bfd_is_group_section bfd_generic_is_group_section
  138. #define os9k_bfd_discard_group bfd_generic_discard_group
  139. #define os9k_section_already_linked \
  140. _bfd_generic_section_already_linked
  141. #define os9k_bfd_define_common_symbol bfd_generic_define_common_symbol
  142. #define os9k_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
  143. #define os9k_bfd_link_add_symbols _bfd_generic_link_add_symbols
  144. #define os9k_bfd_link_just_syms _bfd_generic_link_just_syms
  145. #define os9k_bfd_copy_link_hash_symbol_type \
  146. _bfd_generic_copy_link_hash_symbol_type
  147. #define os9k_bfd_final_link _bfd_generic_final_link
  148. #define os9k_bfd_link_split_section _bfd_generic_link_split_section
  149. const bfd_target i386_aout_os9k_vec =
  150. {
  151. "i386os9k", /* name */
  152. bfd_target_os9k_flavour,
  153. BFD_ENDIAN_LITTLE, /* data byte order is little */
  154. BFD_ENDIAN_LITTLE, /* hdr byte order is little */
  155. (HAS_RELOC | EXEC_P | WP_TEXT), /* object flags */
  156. (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD), /* section flags */
  157. 0, /* symbol leading char */
  158. ' ', /* ar_pad_char */
  159. 16, /* ar_max_namelen */
  160. 0, /* match priority. */
  161. bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  162. bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  163. bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* data */
  164. bfd_getl64, bfd_getl_signed_64, bfd_putl64,
  165. bfd_getl32, bfd_getl_signed_32, bfd_putl32,
  166. bfd_getl16, bfd_getl_signed_16, bfd_putl16, /* hdrs */
  167. {_bfd_dummy_target, os9k_object_p, /* bfd_check_format */
  168. bfd_generic_archive_p, _bfd_dummy_target},
  169. {bfd_false, bfd_false, /* bfd_set_format */
  170. _bfd_generic_mkarchive, bfd_false},
  171. {bfd_false, bfd_false, /* bfd_write_contents */
  172. _bfd_write_archive_contents, bfd_false},
  173. BFD_JUMP_TABLE_GENERIC (aout_32),
  174. BFD_JUMP_TABLE_COPY (_bfd_generic),
  175. BFD_JUMP_TABLE_CORE (_bfd_nocore),
  176. BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd),
  177. BFD_JUMP_TABLE_SYMBOLS (aout_32),
  178. BFD_JUMP_TABLE_RELOCS (aout_32),
  179. BFD_JUMP_TABLE_WRITE (aout_32),
  180. BFD_JUMP_TABLE_LINK (os9k),
  181. BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
  182. NULL,
  183. NULL,
  184. };