Initial revision
[ssr] / StraySrc / Libraries / Core / AOF / h / aof
1 /*
2 * aof.h
3 *
4 * Definitions for Acorn Object Format
5 *
6 * © 1993-1998 Straylight
7 */
8
9 /*----- Licensing note ----------------------------------------------------*
10 *
11 * This file is part of Straylight's AOF library (aoflib).
12 *
13 * Aoflib is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
16 * any later version.
17 *
18 * Aoflib is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with Aoflib. If not, write to the Free Software Foundation,
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
26 */
27
28 #ifndef __aof_h
29 #define __aof_h
30
31 #define aof_RELOC (0xC5E2D080ul) /* Relocatable object type */
32
33 typedef struct
34 {
35 unsigned long type; /* Type of object file */
36 int version; /* Version number of the format */
37 int areas; /* Number of AREAs defined */
38 int symbols; /* Number of symbols in table */
39 int entryArea; /* Index of AREA with ENTRY att */
40 int entryOff; /* Offset in AREA for ENTRY */
41 }
42 aof_fixedHeader;
43
44 typedef struct
45 {
46 int name; /* AREA name (OBJ_STRT offset) */
47
48 int alignment :8; /* AREA alignment (must be 2) */
49
50 int :1; /* Reserved bit */
51 int code :1; /* AREA contains code */
52 int common :1; /* Common AREA definition */
53 int commonRef :1; /* Reference to common AREA */
54 int zinit :1; /* AREA is zero-initialised */
55 int readonly :1; /* AREA is (sort-of) readonly */
56 int :1; /* Reserved bit */
57 int debug :1; /* AREA contains debug tables */
58 int :16; /* Reserved shortword */
59
60 int size; /* Size of this AREA */
61 int relocs; /* Number of relocations */
62 int :32; /* Reserved word */
63 }
64 aof_areaEntry;
65
66 typedef struct
67 {
68 aof_fixedHeader hdr; /* The fixed header info */
69 aof_areaEntry table[1]; /* AREA table (unsized array) */
70 }
71 aof_header;
72
73 typedef struct
74 {
75 int name; /* Name string table entry */
76
77 int defined :1; /* Symbol defined in file */
78 int export :1; /* Symbol is exported globally */
79 int absolute :1; /* Symbol not relative to AREA */
80 int ignoreCase :1; /* Symbol is not case sensitive */
81 int weak :1; /* Symbol is weak external ref */
82 int strong :1; /* Symbol is strong global */
83 int common :1; /* Symbol is in a common AREA */
84 int :32-7; /* Pad out to integer boundary */
85
86 int value; /* Value of the symbol */
87 int area; /* Offset of AREA name */
88 }
89 aof_symbol;
90
91 typedef struct
92 {
93 int offset; /* Offset of word to relocate */
94 union
95 {
96 struct
97 {
98 int symbol :16; /* Symbol to relocate by/to */
99 int field :2; /* Field size to alter */
100 int type :1; /* Relocation type */
101 int symreloc :1; /* Relocation is symbol-relative*/
102 int :12; /* Reserved bits */
103 }
104 type_1; /* Type 1 relocation directive */
105
106 struct
107 {
108 int symbol :24; /* Symbol to relocate by/to */
109 int field :2; /* Field size to alter */
110 int type :1; /* Relocation type */
111 int symreloc :1; /* Relocation is symbol-relative*/
112 int :3; /* Reserved bits */
113 int set_me :1; /* Set this bit for type 2 */
114 }
115 type_2; /* Type 2 relocation directive */
116 }
117 t;
118 }
119 aof_relocstr;
120
121 enum
122 {
123 aof_BYTE,
124 aof_HALFWORD,
125 aof_FULLWORD
126 };
127
128 enum
129 {
130 aof_ADDITIVE,
131 aof_PCRELATIVE
132 };
133
134 typedef struct
135 {
136 char *p; /* Pointer to string table */
137 int size; /* Current allocated size */
138 int next; /* Next position to fill */
139 }
140 aof_chunkinfo;
141
142 typedef struct
143 {
144 aof_chunkinfo *area;
145 aof_chunkinfo *symt;
146 aof_chunkinfo *strt;
147 aof_chunkinfo *reloc;
148 }
149 aof_file;
150
151 int aof_fillBlock(void *p,size_t offset,size_t l,aof_chunkinfo *i);
152
153 int aof_addBlock(void *p,size_t l,aof_chunkinfo *i);
154
155 #define aof_string(string,i) \
156 (aof_addBlock(string,strlen(string)+1,i))
157 #define aof_add(z,i) \
158 (aof_addBlock(&(z),sizeof(z),i))
159 #define aof_fill(z,o,i) \
160 (aof_fillBlock(&(z),o,sizeof(z),i))
161 #define aof_int(x,i) \
162 (aof_addBlock((o=x,&o),sizeof(int),i))
163 #define aof_byte(x,i) \
164 (aof_addBlock((o=x,&o),1,i))
165 #define aof_align(i) \
166 (aof_addBlock((o=0,&o),(4-i.next)&3,&i))
167
168 int aof_branch(int from,int to);
169
170 void aof_reloc(char *name,int offset,int weak,aof_file *f);
171
172 void aof_reloc_b(char *name,int offset,aof_file *f);
173
174 void aof_roff(int offset,aof_file *f);
175
176 void aof_addsym(char *name,int offset,int local,int area,aof_file *f);
177
178 #endif