%{_arch} doesn't work with newer RPMs; use %{_target_cpu} instead
[nasm/avx512.git] / rdoff / rdoff.h
blobee00c34215d3a522143a0d44e81366117b38e93b
1 /* rdoff.h RDOFF Object File manipulation routines header file
3 * The Netwide Assembler is copyright (C) 1996 Simon Tatham and
4 * Julian Hall. All rights reserved. The software is
5 * redistributable under the licence given in the file "Licence"
6 * distributed in the NASM archive.
8 * Permission to use this file in your own projects is granted, as long
9 * as acknowledgement is given in an appropriate manner to its authors,
10 * with instructions of how to obtain a copy via ftp.
13 #ifndef _RDOFF_H
14 #define _RDOFF_H "RDOFF2 support routines v0.3"
16 /* Some systems don't define this automatically */
17 extern char *strdup(const char *);
19 typedef unsigned short int16;
20 typedef unsigned char byte;
22 #define RDF_MAXSEGS 64
24 /* the records that can be found in the RDOFF header */
25 #define RDFREC_RELOC 1
26 #define RDFREC_IMPORT 2
27 #define RDFREC_GLOBAL 3
28 #define RDFREC_DLL 4
29 #define RDFREC_BSS 5
30 #define RDFREC_SEGRELOC 6
31 #define RDFREC_FARIMPORT 7
32 #define RDFREC_MODNAME 8
33 #define RDFREC_COMMON 10
34 #define RDFREC_GENERIC 0
36 struct RelocRec {
37 byte type; /* must be 1 */
38 byte reclen; /* content length */
39 byte segment; /* only 0 for code, or 1 for data supported,
40 but add 64 for relative refs (ie do not require
41 reloc @ loadtime, only linkage) */
42 long offset; /* from start of segment in which reference is loc'd */
43 byte length; /* 1 2 or 4 bytes */
44 int16 refseg; /* segment to which reference refers to */
47 struct ImportRec {
48 byte type; /* must be 2 */
49 byte reclen; /* content length */
50 int16 segment; /* segment number allocated to the label for reloc
51 records - label is assumed to be at offset zero
52 in this segment, so linker must fix up with offset
53 of segment and of offset within segment */
54 char label[33]; /* zero terminated... should be written to file until
55 the zero, but not after it - max len = 32 chars */
58 struct ExportRec {
59 byte type; /* must be 3 */
60 byte reclen; /* content length */
61 byte flags; /* SYM_* flags (see below) */
62 byte segment; /* segment referred to (0/1/2) */
63 long offset; /* offset within segment */
64 char label[33]; /* zero terminated as above. max len = 32 chars */
67 struct DLLRec {
68 byte type; /* must be 4 */
69 byte reclen; /* content length */
70 char libname[128]; /* name of library to link with at load time */
73 struct BSSRec {
74 byte type; /* must be 5 */
75 byte reclen; /* content length */
76 long amount; /* number of bytes BSS to reserve */
79 struct ModRec {
80 byte type; /* must be 8 */
81 byte reclen; /* content length */
82 char modname[128]; /* module name */
85 struct CommonRec {
86 byte type; /* must be 10 */
87 byte reclen; /* equals 7+label length */
88 int16 segment; /* segment number */
89 long size; /* size of common variable */
90 int16 align; /* alignment (power of two) */
91 char label[33]; /* zero terminated as above. max len = 32 chars */
94 /* Flags for ExportRec */
95 #define SYM_DATA 0x01
96 #define SYM_FUNCTION 0x02
97 #define SYM_GLOBAL 0x04
99 /*
100 * GenericRec - contains the type and length field, plus a 128 byte
101 * char array 'data'
103 struct GenericRec {
104 byte type;
105 byte reclen;
106 char data[128];
109 typedef union RDFHeaderRec {
110 char type; /* invariant throughout all below */
111 struct GenericRec g; /* type 0 */
112 struct RelocRec r; /* type == 1 / 6 */
113 struct ImportRec i; /* type == 2 / 7 */
114 struct ExportRec e; /* type == 3 */
115 struct DLLRec d; /* type == 4 */
116 struct BSSRec b; /* type == 5 */
117 struct ModRec m; /* type == 8 */
118 struct CommonRec c; /* type == 10 */
119 } rdfheaderrec;
121 struct SegmentHeaderRec {
122 /* information from file */
123 int16 type;
124 int16 number;
125 int16 reserved;
126 long length;
128 /* information built up here */
129 long offset;
130 byte *data; /* pointer to segment data if it exists in memory */
133 typedef struct RDFFileInfo {
134 FILE *fp; /* file descriptor; must be open to use this struct */
135 int rdoff_ver; /* should be 1; any higher => not guaranteed to work */
136 long header_len;
137 long header_ofs;
139 byte *header_loc; /* keep location of header */
140 long header_fp; /* current location within header for reading */
142 struct SegmentHeaderRec seg[RDF_MAXSEGS];
143 int nsegs;
145 long eof_offset; /* offset of the first byte beyond the end of this
146 module */
148 char *name; /* name of module in libraries */
149 int *refcount; /* pointer to reference count on file, or NULL */
150 } rdffile;
152 #define BUF_BLOCK_LEN 4088 /* selected to match page size (4096)
153 * on 80x86 machines for efficiency */
154 typedef struct memorybuffer {
155 int length;
156 byte buffer[BUF_BLOCK_LEN];
157 struct memorybuffer *next;
158 } memorybuffer;
160 typedef struct {
161 memorybuffer * buf; /* buffer containing header records */
162 int nsegments; /* number of segments to be written */
163 long seglength; /* total length of all the segments */
164 } rdf_headerbuf;
166 /* segments used by RDOFF, understood by rdoffloadseg */
167 #define RDOFF_CODE 0
168 #define RDOFF_DATA 1
169 #define RDOFF_HEADER -1
170 /* mask for 'segment' in relocation records to find if relative relocation */
171 #define RDOFF_RELATIVEMASK 64
172 /* mask to find actual segment value in relocation records */
173 #define RDOFF_SEGMENTMASK 63
175 extern int rdf_errno;
177 /* utility functions */
178 int16 translateshort(int16 in);
179 long translatelong(long in);
181 /* RDOFF file manipulation functions */
182 int rdfopen(rdffile *f,const char *name);
183 int rdfopenhere(rdffile *f, FILE *fp, int *refcount, const char *name);
184 int rdfclose(rdffile *f);
185 int rdffindsegment(rdffile * f, int segno);
186 int rdfloadseg(rdffile *f,int segment,void *buffer);
187 rdfheaderrec *rdfgetheaderrec(rdffile *f); /* returns static storage */
188 void rdfheaderrewind(rdffile *f); /* back to start of header */
189 void rdfperror(const char *app,const char *name);
191 /* functions to write a new RDOFF header to a file -
192 use rdfnewheader to allocate a header, rdfaddheader to add records to it,
193 rdfaddsegment to notify the header routines that a segment exists, and
194 to tell it how long the segment will be.
195 rdfwriteheader to write the file id, object length, and header
196 to a file, and then rdfdoneheader to dispose of the header */
198 rdf_headerbuf *rdfnewheader(void);
199 int rdfaddheader(rdf_headerbuf *h,rdfheaderrec *r);
200 int rdfaddsegment(rdf_headerbuf *h, long seglength);
201 int rdfwriteheader(FILE *fp,rdf_headerbuf *h);
202 void rdfdoneheader(rdf_headerbuf *h);
204 #endif /* _RDOFF_H */