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
00028
00029
00030 #include "bfd.h"
00031 #include "sysdep.h"
00032 #include "libbfd.h"
00033 #include "libaout.h"
00034
00035 #define EXE_MAGIC 0x5a4d
00036 #define EXE_LOAD_HIGH 0x0000
00037 #define EXE_LOAD_LOW 0xffff
00038 #define EXE_PAGE_SIZE 512
00039
00040 static int msdos_sizeof_headers
00041 PARAMS ((bfd *, bfd_boolean));
00042 static bfd_boolean msdos_write_object_contents
00043 PARAMS ((bfd *));
00044 static bfd_boolean msdos_set_section_contents
00045 PARAMS ((bfd *, sec_ptr, const PTR, file_ptr, bfd_size_type));
00046
00047 static int
00048 msdos_sizeof_headers (abfd, exec)
00049 bfd *abfd ATTRIBUTE_UNUSED;
00050 bfd_boolean exec ATTRIBUTE_UNUSED;
00051 {
00052 return 0;
00053 }
00054
00055 static bfd_boolean
00056 msdos_write_object_contents (abfd)
00057 bfd *abfd;
00058 {
00059 static char hdr[EXE_PAGE_SIZE];
00060 file_ptr outfile_size = sizeof(hdr);
00061 bfd_vma high_vma = 0;
00062 asection *sec;
00063
00064
00065 for (sec = abfd->sections; sec != (asection *) NULL; sec = sec->next)
00066 {
00067 if (sec->size == 0)
00068 continue;
00069 if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC)
00070 {
00071 bfd_vma sec_vma = bfd_get_section_vma (abfd, sec) + sec->size;
00072 if (sec_vma > high_vma)
00073 high_vma = sec_vma;
00074 }
00075 if (bfd_get_section_flags (abfd, sec) & SEC_LOAD)
00076 {
00077 file_ptr sec_end = (sizeof (hdr)
00078 + bfd_get_section_vma (abfd, sec)
00079 + sec->size);
00080 if (sec_end > outfile_size)
00081 outfile_size = sec_end;
00082 }
00083 }
00084
00085
00086 if (high_vma > (bfd_vma)0xffff)
00087 {
00088 bfd_set_error(bfd_error_file_too_big);
00089 return FALSE;
00090 }
00091
00092
00093 H_PUT_16 (abfd, EXE_MAGIC, &hdr[0]);
00094 H_PUT_16 (abfd, EXE_PAGE_SIZE / 16, &hdr[8]);
00095 H_PUT_16 (abfd, EXE_LOAD_LOW, &hdr[12]);
00096 H_PUT_16 (abfd, 0x3e, &hdr[24]);
00097 H_PUT_16 (abfd, 0x0001, &hdr[28]);
00098 H_PUT_16 (abfd, 0x30fb, &hdr[30]);
00099 H_PUT_16 (abfd, 0x726a, &hdr[32]);
00100
00101
00102 H_PUT_16 (abfd, outfile_size & (EXE_PAGE_SIZE - 1), &hdr[2]);
00103
00104
00105 H_PUT_16 (abfd, (outfile_size + EXE_PAGE_SIZE - 1) / EXE_PAGE_SIZE, &hdr[4]);
00106
00107
00108
00109 H_PUT_16 (abfd, high_vma, &hdr[16]);
00110
00111 if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0
00112 || bfd_bwrite (hdr, (bfd_size_type) sizeof(hdr), abfd) != sizeof(hdr))
00113 return FALSE;
00114
00115 return TRUE;
00116 }
00117
00118 static bfd_boolean
00119 msdos_set_section_contents (abfd, section, location, offset, count)
00120 bfd *abfd;
00121 sec_ptr section;
00122 const PTR location;
00123 file_ptr offset;
00124 bfd_size_type count;
00125 {
00126
00127 if (count == 0)
00128 return TRUE;
00129
00130 section->filepos = EXE_PAGE_SIZE + bfd_get_section_vma (abfd, section);
00131
00132 if (bfd_get_section_flags (abfd, section) & SEC_LOAD)
00133 {
00134 if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0
00135 || bfd_bwrite (location, count, abfd) != count)
00136 return FALSE;
00137 }
00138
00139 return TRUE;
00140 }
00141
00142
00143
00144 #define msdos_mkobject aout_32_mkobject
00145 #define msdos_make_empty_symbol aout_32_make_empty_symbol
00146 #define msdos_bfd_reloc_type_lookup aout_32_reloc_type_lookup
00147
00148 #define msdos_close_and_cleanup _bfd_generic_close_and_cleanup
00149 #define msdos_bfd_free_cached_info _bfd_generic_bfd_free_cached_info
00150 #define msdos_new_section_hook _bfd_generic_new_section_hook
00151 #define msdos_get_section_contents _bfd_generic_get_section_contents
00152 #define msdos_get_section_contents_in_window \
00153 _bfd_generic_get_section_contents_in_window
00154 #define msdos_bfd_get_relocated_section_contents \
00155 bfd_generic_get_relocated_section_contents
00156 #define msdos_bfd_relax_section bfd_generic_relax_section
00157 #define msdos_bfd_gc_sections bfd_generic_gc_sections
00158 #define msdos_bfd_merge_sections bfd_generic_merge_sections
00159 #define msdos_bfd_is_group_section bfd_generic_is_group_section
00160 #define msdos_bfd_discard_group bfd_generic_discard_group
00161 #define msdos_section_already_linked \
00162 _bfd_generic_section_already_linked
00163 #define msdos_bfd_link_hash_table_create _bfd_generic_link_hash_table_create
00164 #define msdos_bfd_link_hash_table_free _bfd_generic_link_hash_table_free
00165 #define msdos_bfd_link_add_symbols _bfd_generic_link_add_symbols
00166 #define msdos_bfd_link_just_syms _bfd_generic_link_just_syms
00167 #define msdos_bfd_final_link _bfd_generic_final_link
00168 #define msdos_bfd_link_split_section _bfd_generic_link_split_section
00169 #define msdos_set_arch_mach _bfd_generic_set_arch_mach
00170
00171 #define msdos_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound
00172 #define msdos_canonicalize_symtab _bfd_nosymbols_canonicalize_symtab
00173 #define msdos_print_symbol _bfd_nosymbols_print_symbol
00174 #define msdos_get_symbol_info _bfd_nosymbols_get_symbol_info
00175 #define msdos_find_nearest_line _bfd_nosymbols_find_nearest_line
00176 #define msdos_get_lineno _bfd_nosymbols_get_lineno
00177 #define msdos_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false)
00178 #define msdos_bfd_is_local_label_name _bfd_nosymbols_bfd_is_local_label_name
00179 #define msdos_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol
00180 #define msdos_read_minisymbols _bfd_nosymbols_read_minisymbols
00181 #define msdos_minisymbol_to_symbol _bfd_nosymbols_minisymbol_to_symbol
00182
00183 #define msdos_canonicalize_reloc _bfd_norelocs_canonicalize_reloc
00184 #define msdos_get_reloc_upper_bound _bfd_norelocs_get_reloc_upper_bound
00185 #define msdos_32_bfd_link_split_section _bfd_generic_link_split_section
00186
00187 const bfd_target i386msdos_vec =
00188 {
00189 "msdos",
00190 bfd_target_msdos_flavour,
00191 BFD_ENDIAN_LITTLE,
00192 BFD_ENDIAN_LITTLE,
00193 (EXEC_P),
00194 (SEC_CODE | SEC_DATA | SEC_HAS_CONTENTS
00195 | SEC_ALLOC | SEC_LOAD),
00196 0,
00197 ' ',
00198 16,
00199 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
00200 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
00201 bfd_getl16, bfd_getl_signed_16, bfd_putl16,
00202 bfd_getl64, bfd_getl_signed_64, bfd_putl64,
00203 bfd_getl32, bfd_getl_signed_32, bfd_putl32,
00204 bfd_getl16, bfd_getl_signed_16, bfd_putl16,
00205
00206 {
00207 _bfd_dummy_target,
00208 _bfd_dummy_target,
00209 _bfd_dummy_target,
00210 _bfd_dummy_target,
00211 },
00212 {
00213 bfd_false,
00214 msdos_mkobject,
00215 _bfd_generic_mkarchive,
00216 bfd_false,
00217 },
00218 {
00219 bfd_false,
00220 msdos_write_object_contents,
00221 _bfd_write_archive_contents,
00222 bfd_false,
00223 },
00224
00225 BFD_JUMP_TABLE_GENERIC (msdos),
00226 BFD_JUMP_TABLE_COPY (_bfd_generic),
00227 BFD_JUMP_TABLE_CORE (_bfd_nocore),
00228 BFD_JUMP_TABLE_ARCHIVE (_bfd_noarchive),
00229 BFD_JUMP_TABLE_SYMBOLS (msdos),
00230 BFD_JUMP_TABLE_RELOCS (msdos),
00231 BFD_JUMP_TABLE_WRITE (msdos),
00232 BFD_JUMP_TABLE_LINK (msdos),
00233 BFD_JUMP_TABLE_DYNAMIC (_bfd_nodynamic),
00234
00235 NULL,
00236
00237 (PTR) 0
00238 };
00239
00240