00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #if 0
00024 #define TARGET_PAGE_SIZE 4096
00025 #define SEGMENT_SIZE TARGET_PAGE_SIZE
00026 #define TEXT_START_ADDR 0
00027 #endif
00028
00029 #include "bfd.h"
00030 #include "sysdep.h"
00031 #include "libbfd.h"
00032 #include "aout/aout64.h"
00033 #include "aout/stab_gnu.h"
00034 #include "aout/ar.h"
00035 #include "libaout.h"
00036
00037 const bfd_target *encap_real_callback ();
00038
00039 const bfd_target *
00040 encap_object_p (abfd)
00041 bfd *abfd;
00042 {
00043 unsigned char magicbuf[4];
00044 unsigned long magic;
00045 short coff_magic;
00046 struct external_exec exec_bytes;
00047 struct internal_exec exec;
00048 bfd_size_type amt = sizeof (magicbuf);
00049
00050 if (bfd_bread ((PTR) magicbuf, amt, abfd) != amt)
00051 {
00052 if (bfd_get_error () != bfd_error_system_call)
00053 bfd_set_error (bfd_error_wrong_format);
00054 return 0;
00055 }
00056
00057 coff_magic = H_GET_16 (abfd, magicbuf);
00058 if (coff_magic != COFF_MAGIC)
00059 return 0;
00060
00061 magic = H_GET_32 (abfd, magicbuf);
00062
00063 if (N_BADMAG (*((struct internal_exec *) &magic)))
00064 return 0;
00065
00066 if (bfd_seek (abfd, (file_ptr) sizeof (struct coffheader), SEEK_SET) != 0)
00067 return 0;
00068
00069 amt = EXEC_BYTES_SIZE;
00070 if (bfd_bread ((PTR) &exec_bytes, amt, abfd) != amt)
00071 {
00072 if (bfd_get_error () != bfd_error_system_call)
00073 bfd_set_error (bfd_error_wrong_format);
00074 return 0;
00075 }
00076 NAME(aout,swap_exec_header_in) (abfd, &exec_bytes, &exec);
00077
00078 return aout_32_some_aout_object_p (abfd, &exec, encap_realcallback);
00079 }
00080
00081
00082 const bfd_target *
00083 encap_real_callback (abfd)
00084 bfd *abfd;
00085 {
00086 struct internal_exec *execp = exec_hdr (abfd);
00087
00088 MY(callback) (abfd, execp);
00089
00090
00091
00092
00093 if (N_FLAGS(exec_aouthdr) & N_FLAGS_COFF_ENCAPSULATE)
00094 {
00095 struct coffheader ch;
00096 int val;
00097 val = lseek (execchan, -(sizeof (AOUTHDR) + sizeof (ch)), 1);
00098 if (val == -1)
00099 perror_with_name (filename);
00100 val = myread (execchan, &ch, sizeof (ch));
00101 if (val < 0)
00102 perror_with_name (filename);
00103 text_start = ch.text_start;
00104 exec_data_start = ch.data_start;
00105 }
00106 else
00107 {
00108 text_start =
00109 IS_OBJECT_FILE (exec_aouthdr) ? 0 : N_TXTADDR (exec_aouthdr);
00110 exec_data_start = (IS_OBJECT_FILE (exec_aouthdr)
00111 ? exec_aouthdr.a_text
00112 : N_DATADDR (exec_aouthdr));
00113 }
00114
00115
00116 bfd_default_set_arch_mach(abfd, bfd_arch_m68k, 0);
00117
00118 return abfd->xvec;
00119 }
00120
00121
00122
00123
00124
00125 bfd_boolean
00126 encap_write_object_contents (abfd)
00127 bfd *abfd;
00128 {
00129 bfd_size_type data_pad = 0;
00130 struct external_exec exec_bytes;
00131 struct internal_exec *execp = exec_hdr (abfd);
00132
00133
00134
00135 struct coffheader coffheader;
00136 int need_coff_header;
00137
00138
00139
00140
00141
00142 N_SET_MAGIC (outheader, magic);
00143 #ifdef INITIALIZE_HEADER
00144 INITIALIZE_HEADER;
00145 #endif
00146
00147 text_size = sizeof (struct exec);
00148 #ifdef COFF_ENCAPSULATE
00149 if (relocatable_output == 0 && file_table[0].just_syms_flag == 0)
00150 {
00151 need_coff_header = 1;
00152
00153 N_SET_FLAGS (outheader, aout_backend_info (abfd)->exec_hdr_flags);
00154 text_size += sizeof (struct coffheader);
00155 }
00156 #endif
00157
00158 #ifdef COFF_ENCAPSULATE
00159 if (need_coff_header)
00160 {
00161
00162 struct coffscn *tp, *dp, *bp;
00163
00164 tp = &coffheader.scns[0];
00165 dp = &coffheader.scns[1];
00166 bp = &coffheader.scns[2];
00167
00168 strcpy (tp->s_name, ".text");
00169 tp->s_paddr = text_start;
00170 tp->s_vaddr = text_start;
00171 tp->s_size = text_size;
00172 tp->s_scnptr = sizeof (struct coffheader) + sizeof (struct exec);
00173 tp->s_relptr = 0;
00174 tp->s_lnnoptr = 0;
00175 tp->s_nreloc = 0;
00176 tp->s_nlnno = 0;
00177 tp->s_flags = 0x20;
00178 strcpy (dp->s_name, ".data");
00179 dp->s_paddr = data_start;
00180 dp->s_vaddr = data_start;
00181 dp->s_size = data_size;
00182 dp->s_scnptr = tp->s_scnptr + tp->s_size;
00183 dp->s_relptr = 0;
00184 dp->s_lnnoptr = 0;
00185 dp->s_nreloc = 0;
00186 dp->s_nlnno = 0;
00187 dp->s_flags = 0x40;
00188 strcpy (bp->s_name, ".bss");
00189 bp->s_paddr = dp->s_vaddr + dp->s_size;
00190 bp->s_vaddr = bp->s_paddr;
00191 bp->s_size = bss_size;
00192 bp->s_scnptr = 0;
00193 bp->s_relptr = 0;
00194 bp->s_lnnoptr = 0;
00195 bp->s_nreloc = 0;
00196 bp->s_nlnno = 0;
00197 bp->s_flags = 0x80;
00198
00199 coffheader.f_magic = COFF_MAGIC;
00200 coffheader.f_nscns = 3;
00201
00202
00203
00204 coffheader.f_timdat = 1;
00205 coffheader.f_symptr = 0;
00206 coffheader.f_nsyms = 0;
00207 coffheader.f_opthdr = 28;
00208 coffheader.f_flags = 0x103;
00209
00210 coffheader.magic = ZMAGIC;
00211 coffheader.vstamp = 0;
00212 coffheader.tsize = tp->s_size;
00213 coffheader.dsize = dp->s_size;
00214 coffheader.bsize = bp->s_size;
00215 coffheader.entry = outheader.a_entry;
00216 coffheader.text_start = tp->s_vaddr;
00217 coffheader.data_start = dp->s_vaddr;
00218 }
00219 #endif
00220
00221 #ifdef COFF_ENCAPSULATE
00222 if (need_coff_header)
00223 mywrite (&coffheader, sizeof coffheader, 1, outdesc);
00224 #endif
00225
00226 #ifndef COFF_ENCAPSULATE
00227 padfile (N_TXTOFF (outheader) - sizeof outheader, outdesc);
00228 #endif
00229
00230 text_size -= N_TXTOFF (outheader);
00231 WRITE_HEADERS(abfd, execp);
00232 return TRUE;
00233 }
00234
00235 #define MY_write_object_content encap_write_object_contents
00236 #define MY_object_p encap_object_p
00237 #define MY_exec_hdr_flags N_FLAGS_COFF_ENCAPSULATE
00238
00239 #include "aout-target.h"