1 /*** bfd backend for NewsOS3 (Sony, 68k) binaries */
3 /* Copyright (C) 1990, 1991 Free Software Foundation, Inc.
5 This file is part of BFD, the Binary File Diddler.
7 BFD is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 1, or (at your option)
12 BFD is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with BFD; see the file COPYING. If not, write to
19 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
21 #define TARGET_BYTE_ORDER_BIG_P 1
28 int vfprintf(file
, format
, args
) /* Temporary crock! */
29 FILE *file
; char *format
; char *args
;
31 return _doprnt (format
, args
, file
);
34 #define PAGE_SIZE 4096
35 #define SEGMENT_SIZE 0x2000 /* FIXME, is this right?? */
36 #define TEXT_START_ADDR PAGE_SIZE
38 #include "a.out.gnu.h"
41 #include "liba.out.h" /* BFD a.out internal data structures */
43 bfd_target
*newsos3_callback ();
46 newsos3_object_p (abfd
)
49 unsigned char magicbuf
[LONG_SIZE
]; /* Raw bytes of magic number from file */
50 unsigned long magic
; /* Swapped magic number */
52 bfd_error
= system_call_error
;
54 if (bfd_read ((PTR
)magicbuf
, 1, sizeof (magicbuf
), abfd
) !=
57 magic
= bfd_h_getlong (abfd
, magicbuf
);
59 if (N_BADMAG (*((struct exec
*) &magic
))) return 0;
61 return some_aout_object_p (abfd
, newsos3_callback
);
64 /* Finish up the reading of a NEWS-OS a.out file header */
66 newsos3_callback (abfd
)
69 struct exec
*execp
= exec_hdr (abfd
);
71 /* The virtual memory addresses of the sections */
72 obj_datasec (abfd
)->vma
= N_DATADDR(*execp
);
73 obj_bsssec (abfd
)->vma
= N_BSSADDR(*execp
);
74 obj_textsec (abfd
)->vma
= N_TXTADDR(*execp
);
76 /* The file offsets of the sections */
77 obj_textsec (abfd
)->filepos
= N_TXTOFF(*execp
);
78 obj_datasec (abfd
)->filepos
= N_DATOFF(*execp
);
80 /* The file offsets of the relocation info */
81 obj_textsec (abfd
)->rel_filepos
= N_TRELOFF(*execp
);
82 obj_datasec (abfd
)->rel_filepos
= N_DRELOFF(*execp
);
84 /* The file offsets of the string table and symbol table. */
85 obj_str_filepos (abfd
) = N_STROFF (*execp
);
86 obj_sym_filepos (abfd
) = N_SYMOFF (*execp
);
88 /* Determine the architecture and machine type of the object file. */
89 abfd
->obj_arch
= bfd_arch_m68k
;
90 abfd
->obj_machine
= 0;
95 /* Write an object file in NEWS-OS format.
96 Section contents have already been written. We write the
97 file header, symbols, and relocation. */
100 newsos3_write_object_contents (abfd
)
104 unsigned char exec_bytes
[EXEC_BYTES_SIZE
];
105 struct exec
*execp
= exec_hdr (abfd
);
107 execp
->a_text
= obj_textsec (abfd
)->size
;
109 if (abfd
->flags
& D_PAGED
)
110 execp
->a_info
= ZMAGIC
;
111 else if (abfd
->flags
& WP_TEXT
)
112 execp
->a_info
= NMAGIC
;
114 execp
->a_info
= OMAGIC
;
116 if (abfd
->flags
& D_PAGED
)
118 data_pad
= ((obj_datasec(abfd
)->size
+ PAGE_SIZE
-1)
119 & (- PAGE_SIZE
)) - obj_datasec(abfd
)->size
;
121 if (data_pad
> obj_bsssec(abfd
)->size
)
124 execp
->a_bss
= obj_bsssec(abfd
)->size
- data_pad
;
125 execp
->a_data
= obj_datasec(abfd
)->size
+ data_pad
;
129 execp
->a_data
= obj_datasec (abfd
)->size
;
130 execp
->a_bss
= obj_bsssec (abfd
)->size
;
133 execp
->a_syms
= bfd_get_symcount (abfd
) * sizeof (struct nlist
);
134 execp
->a_entry
= bfd_get_start_address (abfd
);
136 execp
->a_trsize
= ((obj_textsec (abfd
)->reloc_count
) *
137 obj_reloc_entry_size (abfd
));
139 execp
->a_drsize
= ((obj_datasec (abfd
)->reloc_count
) *
140 obj_reloc_entry_size (abfd
));
142 bfd_aout_swap_exec_header_out (abfd
, execp
, exec_bytes
);
144 bfd_seek (abfd
, 0L, false);
145 bfd_write ((PTR
) exec_bytes
, 1, EXEC_BYTES_SIZE
, abfd
);
147 /* Now write out reloc info, followed by syms and strings */
149 if (bfd_get_symcount (abfd
) != 0)
151 bfd_seek (abfd
, (long)(N_SYMOFF(*execp
)), false);
152 aout_write_syms (abfd
);
154 bfd_seek (abfd
, (long)(N_TRELOFF(*execp
)), false);
155 if (!aout_squirt_out_relocs (abfd
, obj_textsec (abfd
))) return false;
157 bfd_seek (abfd
, (long)(N_DRELOFF(*execp
)), false);
158 if (!aout_squirt_out_relocs (abfd
, obj_datasec (abfd
))) return false;
163 /* Transfer vectors for NEWS-OS version 3 */
165 /* We use BFD generic archive files. */
166 #define aout_openr_next_archived_file bfd_generic_openr_next_archived_file
167 #define aout_generic_stat_arch_elt bfd_generic_stat_arch_elt
168 #define aout_slurp_armap bfd_slurp_bsd_armap
169 #define aout_slurp_extended_name_table bfd_true
170 #define aout_write_armap bsd_write_armap
171 #define aout_truncate_arname bfd_bsd_truncate_arname
173 /* We don't support core files yet. FIXME. */
174 #define aout_core_file_failing_command _bfd_dummy_core_file_failing_command
175 #define aout_core_file_failing_signal _bfd_dummy_core_file_failing_signal
176 #define aout_core_file_matches_executable_p \
177 _bfd_dummy_core_file_matches_executable_p
178 #define aout_core_file_p _bfd_dummy_target
180 /* We define our own versions of these routines. */
183 bfd_target newsos3_vec
= /* Sony 68k-based machines running newos3 */
185 "a.out-newos3", /* name */
186 bfd_target_aout_flavour_enum
,
187 true, /* target byte order */
188 true, /* target headers byte order */
189 (HAS_RELOC
| EXEC_P
| /* object flags */
190 HAS_LINENO
| HAS_DEBUG
|
191 HAS_SYMS
| HAS_LOCALS
| DYNAMIC
| WP_TEXT
| D_PAGED
),
192 (SEC_HAS_CONTENTS
| SEC_ALLOC
| SEC_LOAD
| SEC_RELOC
), /* section flags */
193 ' ', /* ar_pad_char */
194 16, /* ar_max_namelen */
196 _do_getblong
, _do_putblong
, _do_getbshort
, _do_putbshort
, /* data */
197 _do_getblong
, _do_putblong
, _do_getbshort
, _do_putbshort
, /* hdrs */
199 {_bfd_dummy_target
, newsos3_object_p
, /* bfd_check_format */
200 bfd_generic_archive_p
, aout_core_file_p
},
201 {bfd_false
, aout_mkobject
, /* bfd_set_format */
202 _bfd_generic_mkarchive
, bfd_false
},
203 {bfd_false
, newsos3_write_object_contents
, /* bfd_write_contents */
204 _bfd_write_archive_contents
, bfd_false
},