NASM 0.98-j4
[nasm/avx512.git] / rdoff / rdoff.h
blob0f74b80aea0ac58fcb0c82a122a0be45e9dbb94b
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.
7 */
9 #ifndef _RDOFF_H
10 #define _RDOFF_H "RDOFF1 support routines v0.1"
12 typedef short int16; /* not sure if this will be required to be altered
13 at all... best to typedef it just in case */
15 /* the records that can be found in the RDOFF header */
17 struct RelocRec {
18 char type; /* must be 1 */
19 char segment; /* only 0 for code, or 1 for data supported,
20 but add 64 for relative refs (ie do not require
21 reloc @ loadtime, only linkage) */
22 long offset; /* from start of segment in which reference is loc'd */
23 char length; /* 1 2 or 4 bytes */
24 int16 refseg; /* segment to which reference refers to */
27 struct ImportRec {
28 char type; /* must be 2 */
29 int16 segment; /* segment number allocated to the label for reloc
30 records - label is assumed to be at offset zero
31 in this segment, so linker must fix up with offset
32 of segment and of offset within segment */
33 char label[33]; /* zero terminated... should be written to file until
34 the zero, but not after it - max len = 32 chars */
37 struct ExportRec {
38 char type; /* must be 3 */
39 char segment; /* segment referred to (0/1) */
40 long offset; /* offset within segment */
41 char label[33]; /* zero terminated as above. max len = 32 chars */
44 struct DLLRec {
45 char type; /* must be 4 */
46 char libname[128]; /* name of library to link with at load time */
49 struct BSSRec {
50 char type; /* must be 5 */
51 long amount; /* number of bytes BSS to reserve */
54 typedef union RDFHeaderRec {
55 char type; /* invariant throughout all below */
56 struct RelocRec r; /* type == 1 */
57 struct ImportRec i; /* type == 2 */
58 struct ExportRec e; /* type == 3 */
59 struct DLLRec d; /* type == 4 */
60 struct BSSRec b; /* type == 5 */
61 } rdfheaderrec;
63 typedef struct RDFFileInfo {
64 FILE *fp; /* file descriptor; must be open to use this struct */
65 int rdoff_ver; /* should be 1; any higher => not guaranteed to work */
66 long header_len;
67 long code_len;
68 long data_len;
69 long header_ofs;
70 long code_ofs;
71 long data_ofs;
72 char *header_loc; /* keep location of header */
73 long header_fp; /* current location within header for reading */
74 char *name; /* name of module in libraries */
75 int *refcount; /* pointer to reference count on file, or NULL */
76 } rdffile;
78 #define BUF_BLOCK_LEN 4088 /* selected to match page size (4096)
79 * on 80x86 machines for efficiency */
80 typedef struct memorybuffer {
81 int length;
82 char buffer[BUF_BLOCK_LEN];
83 struct memorybuffer *next;
84 } memorybuffer;
86 typedef memorybuffer rdf_headerbuf;
88 /* segments used by RDOFF, understood by rdoffloadseg */
89 #define RDOFF_CODE 0
90 #define RDOFF_DATA 1
91 #define RDOFF_HEADER -1
92 /* mask for 'segment' in relocation records to find if relative relocation */
93 #define RDOFF_RELATIVEMASK 64
94 /* mask to find actual segment value in relocation records */
95 #define RDOFF_SEGMENTMASK 63
97 extern int rdf_errno;
99 /* RDOFF file manipulation functions */
100 int rdfopen(rdffile *f,const char *name);
101 int rdfopenhere(rdffile *f, FILE *fp, int *refcount, char *name);
102 int rdfclose(rdffile *f);
103 int rdfloadseg(rdffile *f,int segment,void *buffer);
104 rdfheaderrec *rdfgetheaderrec(rdffile *f); /* returns static storage */
105 void rdfheaderrewind(rdffile *f); /* back to start of header */
106 void rdfperror(const char *app,const char *name);
108 /* functions to write a new RDOFF header to a file -
109 use rdfnewheader to allocate a header, rdfaddheader to add records to it,
110 rdfwriteheader to write 'RDOFF1', length of header, and the header itself
111 to a file, and then rdfdoneheader to dispose of the header */
113 rdf_headerbuf *rdfnewheader(void);
114 int rdfaddheader(rdf_headerbuf *h,rdfheaderrec *r);
115 int rdfwriteheader(FILE *fp,rdf_headerbuf *h);
116 void rdfdoneheader(rdf_headerbuf *h);
118 #endif /* _RDOFF_H */