Rev 5191 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5191 | Rev 6324 | ||
---|---|---|---|
1 | /* Yet Another Try at encapsulating bfd object files in coff. |
1 | /* Yet Another Try at encapsulating bfd object files in coff. |
2 | Copyright 1988, 1989, 1991, 2010 Free Software Foundation, Inc. |
2 | Copyright (C) 1988-2015 Free Software Foundation, Inc. |
3 | Written by Pace Willisson 12/9/88 |
3 | Written by Pace Willisson 12/9/88 |
4 | 4 | ||
5 | This file is obsolete. It needs to be converted to just define a bunch |
5 | This file is obsolete. It needs to be converted to just define a bunch |
6 | of stuff that BFD can use to do coff-encapsulated files. --gnu@cygnus.com |
6 | of stuff that BFD can use to do coff-encapsulated files. --gnu@cygnus.com |
7 | 7 | ||
8 | This program is free software; you can redistribute it and/or modify |
8 | This program is free software; you can redistribute it and/or modify |
9 | it under the terms of the GNU General Public License as published by |
9 | it under the terms of the GNU General Public License as published by |
10 | the Free Software Foundation; either version 3 of the License, or |
10 | the Free Software Foundation; either version 3 of the License, or |
11 | (at your option) any later version. |
11 | (at your option) any later version. |
12 | 12 | ||
13 | This program is distributed in the hope that it will be useful, |
13 | This program is distributed in the hope that it will be useful, |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | GNU General Public License for more details. |
16 | GNU General Public License for more details. |
17 | 17 | ||
18 | You should have received a copy of the GNU General Public License |
18 | You should have received a copy of the GNU General Public License |
19 | along with this program; if not, write to the Free Software |
19 | along with this program; if not, write to the Free Software |
20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
20 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, |
21 | MA 02110-1301, USA. */ |
21 | MA 02110-1301, USA. */ |
22 | 22 | ||
23 | /* |
23 | /* |
24 | * We only use the coff headers to tell the kernel |
24 | * We only use the coff headers to tell the kernel |
25 | * how to exec the file. Therefore, the only fields that need to |
25 | * how to exec the file. Therefore, the only fields that need to |
26 | * be filled in are the scnptr and vaddr for the text and data |
26 | * be filled in are the scnptr and vaddr for the text and data |
27 | * sections, and the vaddr for the bss. As far as coff is concerned, |
27 | * sections, and the vaddr for the bss. As far as coff is concerned, |
28 | * there is no symbol table, relocation, or line numbers. |
28 | * there is no symbol table, relocation, or line numbers. |
29 | * |
29 | * |
30 | * A normal bsd header (struct exec) is placed after the coff headers, |
30 | * A normal bsd header (struct exec) is placed after the coff headers, |
31 | * and before the real text. I defined a the new fields 'a_machtype' |
31 | * and before the real text. I defined a the new fields 'a_machtype' |
32 | * and a_flags. If a_machtype is M_386, and a_flags & A_ENCAP is |
32 | * and a_flags. If a_machtype is M_386, and a_flags & A_ENCAP is |
33 | * true, then the bsd header is preceeded by a coff header. Macros |
33 | * true, then the bsd header is preceeded by a coff header. Macros |
34 | * like N_TXTOFF and N_TXTADDR use this field to find the bsd header. |
34 | * like N_TXTOFF and N_TXTADDR use this field to find the bsd header. |
35 | * |
35 | * |
36 | * The only problem is to track down the bsd exec header. The |
36 | * The only problem is to track down the bsd exec header. The |
37 | * macros HEADER_OFFSET, etc do this. |
37 | * macros HEADER_OFFSET, etc do this. |
38 | */ |
38 | */ |
39 | 39 | ||
40 | #define N_FLAGS_COFF_ENCAPSULATE 0x20 /* coff header precedes bsd header */ |
40 | #define N_FLAGS_COFF_ENCAPSULATE 0x20 /* coff header precedes bsd header */ |
41 | 41 | ||
42 | /* Describe the COFF header used for encapsulation. */ |
42 | /* Describe the COFF header used for encapsulation. */ |
43 | 43 | ||
44 | struct coffheader |
44 | struct coffheader |
45 | { |
45 | { |
46 | /* filehdr */ |
46 | /* filehdr */ |
47 | unsigned short f_magic; |
47 | unsigned short f_magic; |
48 | unsigned short f_nscns; |
48 | unsigned short f_nscns; |
49 | long f_timdat; |
49 | long f_timdat; |
50 | long f_symptr; |
50 | long f_symptr; |
51 | long f_nsyms; |
51 | long f_nsyms; |
52 | unsigned short f_opthdr; |
52 | unsigned short f_opthdr; |
53 | unsigned short f_flags; |
53 | unsigned short f_flags; |
54 | /* aouthdr */ |
54 | /* aouthdr */ |
55 | short magic; |
55 | short magic; |
56 | short vstamp; |
56 | short vstamp; |
57 | long tsize; |
57 | long tsize; |
58 | long dsize; |
58 | long dsize; |
59 | long bsize; |
59 | long bsize; |
60 | long entry; |
60 | long entry; |
61 | long text_start; |
61 | long text_start; |
62 | long data_start; |
62 | long data_start; |
63 | struct coffscn |
63 | struct coffscn |
64 | { |
64 | { |
65 | char s_name[8]; |
65 | char s_name[8]; |
66 | long s_paddr; |
66 | long s_paddr; |
67 | long s_vaddr; |
67 | long s_vaddr; |
68 | long s_size; |
68 | long s_size; |
69 | long s_scnptr; |
69 | long s_scnptr; |
70 | long s_relptr; |
70 | long s_relptr; |
71 | long s_lnnoptr; |
71 | long s_lnnoptr; |
72 | unsigned short s_nreloc; |
72 | unsigned short s_nreloc; |
73 | unsigned short s_nlnno; |
73 | unsigned short s_nlnno; |
74 | long s_flags; |
74 | long s_flags; |
75 | } scns[3]; |
75 | } scns[3]; |
76 | }; |
76 | }; |
77 | 77 | ||
78 | /* Describe some of the parameters of the encapsulation, |
78 | /* Describe some of the parameters of the encapsulation, |
79 | including how to find the encapsulated BSD header. */ |
79 | including how to find the encapsulated BSD header. */ |
80 | 80 | ||
81 | /* FIXME, this is dumb. The same tools can't handle a.outs for different |
81 | /* FIXME, this is dumb. The same tools can't handle a.outs for different |
82 | architectures, just because COFF_MAGIC is different; so you need a |
82 | architectures, just because COFF_MAGIC is different; so you need a |
83 | separate GNU nm for every architecture!!? Unfortunately, it needs to |
83 | separate GNU nm for every architecture!!? Unfortunately, it needs to |
84 | be this way, since the COFF_MAGIC value is determined by the kernel |
84 | be this way, since the COFF_MAGIC value is determined by the kernel |
85 | we're trying to fool here. */ |
85 | we're trying to fool here. */ |
86 | 86 | ||
87 | #define COFF_MAGIC_I386 0514 /* I386MAGIC */ |
87 | #define COFF_MAGIC_I386 0514 /* I386MAGIC */ |
88 | #define COFF_MAGIC_M68K 0520 /* MC68MAGIC */ |
88 | #define COFF_MAGIC_M68K 0520 /* MC68MAGIC */ |
89 | 89 | ||
90 | #ifdef COFF_MAGIC |
90 | #ifdef COFF_MAGIC |
91 | short __header_offset_temp; |
91 | short __header_offset_temp; |
92 | #define HEADER_OFFSET(f) \ |
92 | #define HEADER_OFFSET(f) \ |
93 | (__header_offset_temp = 0, \ |
93 | (__header_offset_temp = 0, \ |
94 | fread ((char *)&__header_offset_temp, sizeof (short), 1, (f)), \ |
94 | fread ((char *)&__header_offset_temp, sizeof (short), 1, (f)), \ |
95 | fseek ((f), -sizeof (short), 1), \ |
95 | fseek ((f), -sizeof (short), 1), \ |
96 | __header_offset_temp==COFF_MAGIC ? sizeof(struct coffheader) : 0) |
96 | __header_offset_temp==COFF_MAGIC ? sizeof(struct coffheader) : 0) |
97 | #else |
97 | #else |
98 | #define HEADER_OFFSET(f) 0 |
98 | #define HEADER_OFFSET(f) 0 |
99 | #endif |
99 | #endif |
100 | 100 | ||
101 | #define HEADER_SEEK(f) (fseek ((f), HEADER_OFFSET((f)), 1)) |
101 | #define HEADER_SEEK(f) (fseek ((f), HEADER_OFFSET((f)), 1)) |
102 | 102 | ||
103 | /* Describe the characteristics of the BSD header |
103 | /* Describe the characteristics of the BSD header |
104 | that appears inside the encapsulation. */ |
104 | that appears inside the encapsulation. */ |
105 | 105 | ||
106 | /* Encapsulated coff files that are linked ZMAGIC have a text segment |
106 | /* Encapsulated coff files that are linked ZMAGIC have a text segment |
107 | offset just past the header (and a matching TXTADDR), excluding |
107 | offset just past the header (and a matching TXTADDR), excluding |
108 | the headers from the text segment proper but keeping the physical |
108 | the headers from the text segment proper but keeping the physical |
109 | layout and the virtual memory layout page-aligned. |
109 | layout and the virtual memory layout page-aligned. |
110 | 110 | ||
111 | Non-encapsulated a.out files that are linked ZMAGIC have a text |
111 | Non-encapsulated a.out files that are linked ZMAGIC have a text |
112 | segment that starts at 0 and an N_TXTADR similarly offset to 0. |
112 | segment that starts at 0 and an N_TXTADR similarly offset to 0. |
113 | They too are page-aligned with each other, but they include the |
113 | They too are page-aligned with each other, but they include the |
114 | a.out header as part of the text. |
114 | a.out header as part of the text. |
115 | 115 | ||
116 | The _N_HDROFF gets sizeof struct exec added to it, so we have |
116 | The _N_HDROFF gets sizeof struct exec added to it, so we have |
117 | to compensate here. See |
117 | to compensate here. See |
118 | 118 | ||
119 | #undef _N_HDROFF |
119 | #undef _N_HDROFF |
120 | #undef N_TXTADDR |
120 | #undef N_TXTADDR |
121 | #undef N_DATADDR |
121 | #undef N_DATADDR |
122 | 122 | ||
123 | #define _N_HDROFF(x) ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \ |
123 | #define _N_HDROFF(x) ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \ |
124 | sizeof (struct coffheader) : 0) |
124 | sizeof (struct coffheader) : 0) |
125 | 125 | ||
126 | /* Address of text segment in memory after it is loaded. */ |
126 | /* Address of text segment in memory after it is loaded. */ |
127 | #define N_TXTADDR(x) \ |
127 | #define N_TXTADDR(x) \ |
128 | ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \ |
128 | ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \ |
129 | sizeof (struct coffheader) + sizeof (struct exec) : 0) |
129 | sizeof (struct coffheader) + sizeof (struct exec) : 0) |
130 | #define SEGMENT_SIZE 0x400000 |
130 | #define SEGMENT_SIZE 0x400000 |
131 | 131 | ||
132 | #define N_DATADDR(x) \ |
132 | #define N_DATADDR(x) \ |
133 | ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \ |
133 | ((N_FLAGS(x) & N_FLAGS_COFF_ENCAPSULATE) ? \ |
134 | (SEGMENT_SIZE + ((N_TXTADDR(x)+(x).a_text-1) & ~(SEGMENT_SIZE-1))) : \ |
134 | (SEGMENT_SIZE + ((N_TXTADDR(x)+(x).a_text-1) & ~(SEGMENT_SIZE-1))) : \ |
135 | (N_TXTADDR(x)+(x).a_text)) |
135 | (N_TXTADDR(x)+(x).a_text)) |