00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #include "bfd.h"
00028 #include "sysdep.h"
00029 #include "libbfd.h"
00030 #include "bfdlink.h"
00031 #include "libaout.h"
00032 #include "os9k.h"
00033
00034 static const bfd_target * os9k_callback
00035 PARAMS ((bfd *));
00036 static const bfd_target * os9k_object_p
00037 PARAMS ((bfd *));
00038 static int os9k_sizeof_headers
00039 PARAMS ((bfd *, bfd_boolean));
00040 bfd_boolean os9k_swap_exec_header_in
00041 PARAMS ((bfd *, mh_com *, struct internal_exec *));
00042
00043
00044
00045 bfd_boolean
00046 os9k_swap_exec_header_in (abfd, raw_bytes, execp)
00047 bfd *abfd;
00048 mh_com *raw_bytes;
00049 struct internal_exec *execp;
00050 {
00051 mh_com *bytes = (mh_com *) raw_bytes;
00052 unsigned int dload, dmemsize, dmemstart;
00053
00054
00055 execp->a_info = H_GET_16 (abfd, bytes->m_sync);
00056 execp->a_syms = 0;
00057 execp->a_entry = H_GET_32 (abfd, bytes->m_exec);
00058 execp->a_talign = 2;
00059 execp->a_dalign = 2;
00060 execp->a_balign = 2;
00061
00062 dload = H_GET_32 (abfd, bytes->m_idata);
00063 execp->a_data = dload + 8;
00064
00065 if (bfd_seek (abfd, (file_ptr) dload, SEEK_SET) != 0
00066 || (bfd_bread (&dmemstart, (bfd_size_type) sizeof (dmemstart), abfd)
00067 != sizeof (dmemstart))
00068 || (bfd_bread (&dmemsize, (bfd_size_type) sizeof (dmemsize), abfd)
00069 != sizeof (dmemsize)))
00070 return FALSE;
00071
00072 execp->a_tload = 0;
00073 execp->a_dload = H_GET_32 (abfd, (unsigned char *) &dmemstart);
00074 execp->a_text = dload - execp->a_tload;
00075 execp->a_data = H_GET_32 (abfd, (unsigned char *) &dmemsize);
00076 execp->a_bss = H_GET_32 (abfd, bytes->m_data) - execp->a_data;
00077
00078 execp->a_trsize = 0;
00079 execp->a_drsize = 0;
00080
00081 return TRUE;
00082 }
00083
00084 static const bfd_target *
00085 os9k_object_p (abfd)
00086 bfd *abfd;
00087 {
00088 struct internal_exec anexec;
00089 mh_com exec_bytes;
00090
00091 if (bfd_bread ((PTR) &exec_bytes, (bfd_size_type) MHCOM_BYTES_SIZE, abfd)
00092 != MHCOM_BYTES_SIZE)
00093 {
00094 if (bfd_get_error () != bfd_error_system_call)
00095 bfd_set_error (bfd_error_wrong_format);
00096 return 0;
00097 }
00098
00099 anexec.a_info = H_GET_16 (abfd, exec_bytes.m_sync);
00100 if (N_BADMAG (anexec))
00101 {
00102 bfd_set_error (bfd_error_wrong_format);
00103 return 0;
00104 }
00105
00106 if (! os9k_swap_exec_header_in (abfd, &exec_bytes, &anexec))
00107 {
00108 if (bfd_get_error () != bfd_error_system_call)
00109 bfd_set_error (bfd_error_wrong_format);
00110 return NULL;
00111 }
00112 return aout_32_some_aout_object_p (abfd, &anexec, os9k_callback);
00113 }
00114
00115
00116
00117
00118
00119 static const bfd_target *
00120 os9k_callback (abfd)
00121 bfd *abfd;
00122 {
00123 struct internal_exec *execp = exec_hdr (abfd);
00124 unsigned long bss_start;
00125
00126
00127 bfd_set_arch_mach (abfd, bfd_arch_i386, 0);
00128
00129
00130 obj_str_filepos (abfd) = 0;
00131 obj_sym_filepos (abfd) = 0;
00132
00133
00134 obj_textsec (abfd)->alignment_power = execp->a_talign;
00135 obj_datasec (abfd)->alignment_power = execp->a_dalign;
00136 obj_bsssec (abfd)->alignment_power = execp->a_balign;
00137
00138
00139 obj_textsec (abfd)->vma = execp->a_tload;
00140 obj_datasec (abfd)->vma = execp->a_dload;
00141
00142
00143 obj_textsec (abfd)->size = execp->a_text;
00144
00145 bss_start = execp->a_dload + execp->a_data;
00146 obj_bsssec (abfd)->vma = align_power (bss_start, execp->a_balign);
00147
00148
00149 obj_textsec (abfd)->filepos = execp->a_entry;
00150 obj_datasec (abfd)->filepos = execp->a_dload;
00151
00152
00153
00154
00155
00156 adata (abfd).page_size = 1;
00157 adata (abfd).segment_size = 1;
00158 adata (abfd).exec_bytes_size = MHCOM_BYTES_SIZE;
00159
00160 return abfd->xvec;
00161 }
00162
00163 static int
00164 os9k_sizeof_headers (ignore_abfd, ignore)
00165 bfd *ignore_abfd ATTRIBUTE_UNUSED;
00166 bfd_boolean ignore ATTRIBUTE_UNUSED;
00167 {
00168 return sizeof (struct internal_exec);
00169 }
00170
00171
00172
00173 #define aout_32_close_and_cleanup aout_32_bfd_free_cached_info
00174
00175 #define aout_32_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
00176
00177 #define aout_32_bfd_reloc_type_lookup _bfd_norelocs_bfd_reloc_type_lookup
00178
00179 #define aout_32_get_section_contents_in_window \
00180 _bfd_generic_get_section_contents_in_window
00181
00182 #define os9k_bfd_get_relocated_section_contents \
00183 bfd_generic_get_relocated_section_contents
00184 #define os9k_bfd_relax_section bfd_generic_relax_section
00185 #define os9k_bfd_gc_sections bfd_generic_gc_sections
00186 #define os9k_bfd_merge_sections bfd_generic_merge_sections
00187 #define os9k_bfd_is_group_section bfd_generic_is_group_section
00188 #define os9k_bfd_discard_group bfd_generic_discard_group
00189 #define os9k_section_already_linked \
00190 _bfd_generic_section_already_linked
00191 #define os9k_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
00192 #define os9k_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
00193 #define os9k_bfd_link_add_symbols _bfd_generic_link_add_symbols
00194 #define os9k_bfd_link_just_syms _bfd_generic_link_just_syms
00195 #define os9k_bfd_final_link _bfd_generic_final_link
00196 #define os9k_bfd_link_split_section _bfd_generic_link_split_section
00197
00198 const bfd_target i386os9k_vec =
00199 {
00200 "i386os9k",
00201 bfd_target_os9k_flavour,
00202 BFD_ENDIAN_LITTLE,
00203 BFD_ENDIAN_LITTLE,
00204 (HAS_RELOC | EXEC_P | WP_TEXT),
00205 (SEC_HAS_CONTENTS | SEC_ALLOC | SEC_LOAD),
00206 0,
00207 ' ',
00208 16,
00209
00210 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
00211 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
00212 bfd_getl16, bfd_getl_signed_16, bfd_putl16,
00213 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
00214 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
00215 bfd_getl16, bfd_getl_signed_16, bfd_putl16,
00216 {_bfd_dummy_target, os9k_object_p,
00217 bfd_generic_archive_p, _bfd_dummy_target},
00218 {bfd_false, bfd_false,
00219 _bfd_generic_mkarchive, bfd_false},
00220 {bfd_false, bfd_false,
00221 _bfd_write_archive_contents, bfd_false},
00222
00223 BFD_JUMP_TABLE_GENERIC (aout_32),
00224 BFD_JUMP_TABLE_COPY (_bfd_generic),
00225 BFD_JUMP_TABLE_CORE (_bfd_nocore),
00226 BFD_JUMP_TABLE_ARCHIVE (_bfd_archive_bsd),
00227 BFD_JUMP_TABLE_SYMBOLS (aout_32),
00228 BFD_JUMP_TABLE_RELOCS (aout_32),
00229 BFD_JUMP_TABLE_WRITE (aout_32),
00230 BFD_JUMP_TABLE_LINK (os9k),
00231 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
00232
00233 NULL,
00234
00235 (PTR) 0,
00236 };