1 |
/* BFD back-end for MS-DOS executables. |
/* BFD back-end for MS-DOS executables. |
2 |
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2001, 2002 |
Copyright 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2001, 2002, |
3 |
Free Software Foundation, Inc. |
2003, 2004, 2005 Free Software Foundation, Inc. |
4 |
Written by Bryan Ford of the University of Utah. |
Written by Bryan Ford of the University of Utah. |
5 |
|
|
6 |
Contributed by the Center for Software Science at the |
Contributed by the Center for Software Science at the |
28 |
#include "libbfd.h" |
#include "libbfd.h" |
29 |
#include "libaout.h" |
#include "libaout.h" |
30 |
|
|
|
#if 0 |
|
|
struct exe_header |
|
|
{ |
|
|
unsigned short magic; |
|
|
unsigned short bytes_in_last_page; |
|
|
unsigned short npages; /* number of 512-byte "pages" including this header */ |
|
|
unsigned short nrelocs; |
|
|
unsigned short header_paras; /* number of 16-byte paragraphs in header */ |
|
|
unsigned short reserved; |
|
|
unsigned short load_switch; |
|
|
unsigned short ss_ofs; |
|
|
unsigned short sp; |
|
|
unsigned short checksum; |
|
|
unsigned short ip; |
|
|
unsigned short cs_ofs; |
|
|
unsigned short reloc_ofs; |
|
|
unsigned short reserved2; |
|
|
unsigned short something1; |
|
|
unsigned short something2; |
|
|
unsigned short something3; |
|
|
}; |
|
|
#endif |
|
|
|
|
31 |
#define EXE_MAGIC 0x5a4d |
#define EXE_MAGIC 0x5a4d |
32 |
#define EXE_LOAD_HIGH 0x0000 |
#define EXE_LOAD_HIGH 0x0000 |
33 |
#define EXE_LOAD_LOW 0xffff |
#define EXE_LOAD_LOW 0xffff |
34 |
#define EXE_PAGE_SIZE 512 |
#define EXE_PAGE_SIZE 512 |
35 |
|
|
36 |
static int msdos_sizeof_headers PARAMS ((bfd *, boolean)); |
static int msdos_sizeof_headers |
37 |
static boolean msdos_write_object_contents PARAMS ((bfd *)); |
PARAMS ((bfd *, bfd_boolean)); |
38 |
static boolean msdos_set_section_contents PARAMS ((bfd *, sec_ptr, PTR, file_ptr, bfd_size_type)); |
static bfd_boolean msdos_write_object_contents |
39 |
|
PARAMS ((bfd *)); |
40 |
|
static bfd_boolean msdos_set_section_contents |
41 |
|
PARAMS ((bfd *, sec_ptr, const PTR, file_ptr, bfd_size_type)); |
42 |
|
|
43 |
static int |
static int |
44 |
msdos_sizeof_headers (abfd, exec) |
msdos_sizeof_headers (abfd, exec) |
45 |
bfd *abfd ATTRIBUTE_UNUSED; |
bfd *abfd ATTRIBUTE_UNUSED; |
46 |
boolean exec ATTRIBUTE_UNUSED; |
bfd_boolean exec ATTRIBUTE_UNUSED; |
47 |
{ |
{ |
48 |
return 0; |
return 0; |
49 |
} |
} |
50 |
|
|
51 |
static boolean |
static bfd_boolean |
52 |
msdos_write_object_contents (abfd) |
msdos_write_object_contents (abfd) |
53 |
bfd *abfd; |
bfd *abfd; |
54 |
{ |
{ |
60 |
/* Find the total size of the program on disk and in memory. */ |
/* Find the total size of the program on disk and in memory. */ |
61 |
for (sec = abfd->sections; sec != (asection *) NULL; sec = sec->next) |
for (sec = abfd->sections; sec != (asection *) NULL; sec = sec->next) |
62 |
{ |
{ |
63 |
if (bfd_get_section_size_before_reloc (sec) == 0) |
if (sec->size == 0) |
64 |
continue; |
continue; |
65 |
if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC) |
if (bfd_get_section_flags (abfd, sec) & SEC_ALLOC) |
66 |
{ |
{ |
67 |
bfd_vma sec_vma = bfd_get_section_vma (abfd, sec) |
bfd_vma sec_vma = bfd_get_section_vma (abfd, sec) + sec->size; |
|
+ bfd_get_section_size_before_reloc (sec); |
|
68 |
if (sec_vma > high_vma) |
if (sec_vma > high_vma) |
69 |
high_vma = sec_vma; |
high_vma = sec_vma; |
70 |
} |
} |
71 |
if (bfd_get_section_flags (abfd, sec) & SEC_LOAD) |
if (bfd_get_section_flags (abfd, sec) & SEC_LOAD) |
72 |
{ |
{ |
73 |
file_ptr sec_end = sizeof(hdr) |
file_ptr sec_end = (sizeof (hdr) |
74 |
+ bfd_get_section_vma (abfd, sec) |
+ bfd_get_section_vma (abfd, sec) |
75 |
+ bfd_get_section_size_before_reloc (sec); |
+ sec->size); |
76 |
if (sec_end > outfile_size) |
if (sec_end > outfile_size) |
77 |
outfile_size = sec_end; |
outfile_size = sec_end; |
78 |
} |
} |
82 |
if (high_vma > (bfd_vma)0xffff) |
if (high_vma > (bfd_vma)0xffff) |
83 |
{ |
{ |
84 |
bfd_set_error(bfd_error_file_too_big); |
bfd_set_error(bfd_error_file_too_big); |
85 |
return false; |
return FALSE; |
86 |
} |
} |
87 |
|
|
88 |
/* Constants. */ |
/* Constants. */ |
106 |
|
|
107 |
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0 |
if (bfd_seek (abfd, (file_ptr) 0, SEEK_SET) != 0 |
108 |
|| bfd_bwrite (hdr, (bfd_size_type) sizeof(hdr), abfd) != sizeof(hdr)) |
|| bfd_bwrite (hdr, (bfd_size_type) sizeof(hdr), abfd) != sizeof(hdr)) |
109 |
return false; |
return FALSE; |
110 |
|
|
111 |
return true; |
return TRUE; |
112 |
} |
} |
113 |
|
|
114 |
static boolean |
static bfd_boolean |
115 |
msdos_set_section_contents (abfd, section, location, offset, count) |
msdos_set_section_contents (abfd, section, location, offset, count) |
116 |
bfd *abfd; |
bfd *abfd; |
117 |
sec_ptr section; |
sec_ptr section; |
118 |
PTR location; |
const PTR location; |
119 |
file_ptr offset; |
file_ptr offset; |
120 |
bfd_size_type count; |
bfd_size_type count; |
121 |
{ |
{ |
122 |
|
|
123 |
if (count == 0) |
if (count == 0) |
124 |
return true; |
return TRUE; |
125 |
|
|
126 |
section->filepos = EXE_PAGE_SIZE + bfd_get_section_vma (abfd, section); |
section->filepos = EXE_PAGE_SIZE + bfd_get_section_vma (abfd, section); |
127 |
|
|
129 |
{ |
{ |
130 |
if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0 |
if (bfd_seek (abfd, section->filepos + offset, SEEK_SET) != 0 |
131 |
|| bfd_bwrite (location, count, abfd) != count) |
|| bfd_bwrite (location, count, abfd) != count) |
132 |
return false; |
return FALSE; |
133 |
} |
} |
134 |
|
|
135 |
return true; |
return TRUE; |
136 |
} |
} |
137 |
|
|
138 |
|
|
152 |
#define msdos_bfd_relax_section bfd_generic_relax_section |
#define msdos_bfd_relax_section bfd_generic_relax_section |
153 |
#define msdos_bfd_gc_sections bfd_generic_gc_sections |
#define msdos_bfd_gc_sections bfd_generic_gc_sections |
154 |
#define msdos_bfd_merge_sections bfd_generic_merge_sections |
#define msdos_bfd_merge_sections bfd_generic_merge_sections |
155 |
|
#define msdos_bfd_is_group_section bfd_generic_is_group_section |
156 |
#define msdos_bfd_discard_group bfd_generic_discard_group |
#define msdos_bfd_discard_group bfd_generic_discard_group |
157 |
|
#define msdos_section_already_linked \ |
158 |
|
_bfd_generic_section_already_linked |
159 |
#define msdos_bfd_link_hash_table_create _bfd_generic_link_hash_table_create |
#define msdos_bfd_link_hash_table_create _bfd_generic_link_hash_table_create |
160 |
#define msdos_bfd_link_hash_table_free _bfd_generic_link_hash_table_free |
#define msdos_bfd_link_hash_table_free _bfd_generic_link_hash_table_free |
161 |
#define msdos_bfd_link_add_symbols _bfd_generic_link_add_symbols |
#define msdos_bfd_link_add_symbols _bfd_generic_link_add_symbols |
165 |
#define msdos_set_arch_mach _bfd_generic_set_arch_mach |
#define msdos_set_arch_mach _bfd_generic_set_arch_mach |
166 |
|
|
167 |
#define msdos_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound |
#define msdos_get_symtab_upper_bound _bfd_nosymbols_get_symtab_upper_bound |
168 |
#define msdos_get_symtab _bfd_nosymbols_get_symtab |
#define msdos_canonicalize_symtab _bfd_nosymbols_canonicalize_symtab |
169 |
#define msdos_print_symbol _bfd_nosymbols_print_symbol |
#define msdos_print_symbol _bfd_nosymbols_print_symbol |
170 |
#define msdos_get_symbol_info _bfd_nosymbols_get_symbol_info |
#define msdos_get_symbol_info _bfd_nosymbols_get_symbol_info |
171 |
#define msdos_find_nearest_line _bfd_nosymbols_find_nearest_line |
#define msdos_find_nearest_line _bfd_nosymbols_find_nearest_line |
172 |
#define msdos_get_lineno _bfd_nosymbols_get_lineno |
#define msdos_get_lineno _bfd_nosymbols_get_lineno |
173 |
|
#define msdos_bfd_is_target_special_symbol ((bfd_boolean (*) (bfd *, asymbol *)) bfd_false) |
174 |
#define msdos_bfd_is_local_label_name _bfd_nosymbols_bfd_is_local_label_name |
#define msdos_bfd_is_local_label_name _bfd_nosymbols_bfd_is_local_label_name |
175 |
#define msdos_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol |
#define msdos_bfd_make_debug_symbol _bfd_nosymbols_bfd_make_debug_symbol |
176 |
#define msdos_read_minisymbols _bfd_nosymbols_read_minisymbols |
#define msdos_read_minisymbols _bfd_nosymbols_read_minisymbols |