summaryrefslogtreecommitdiff
path: root/rdoff/rdoff.h
diff options
context:
space:
mode:
Diffstat (limited to 'rdoff/rdoff.h')
-rw-r--r--rdoff/rdoff.h166
1 files changed, 117 insertions, 49 deletions
diff --git a/rdoff/rdoff.h b/rdoff/rdoff.h
index c6957dc..dd43126 100644
--- a/rdoff/rdoff.h
+++ b/rdoff/rdoff.h
@@ -1,4 +1,5 @@
-/* rdoff.h RDOFF Object File manipulation routines header file
+/*
+ * rdoff.h RDOFF Object File manipulation routines header file
*
* The Netwide Assembler is copyright (C) 1996 Simon Tatham and
* Julian Hall. All rights reserved. The software is
@@ -11,17 +12,37 @@
*/
#ifndef _RDOFF_H
-#define _RDOFF_H "RDOFF2 support routines v0.3"
+#define _RDOFF_H
-/* Some systems don't define this automatically */
-extern char *strdup(const char *);
+/*
+ * RDOFF definitions. They are used by RDOFF utilities and by NASM's
+ * 'outrdf2.c' output module.
+ */
-typedef unsigned short int16;
+/* Type definitions */
+typedef unsigned long uint32;
+typedef unsigned short uint16;
typedef unsigned char byte;
+typedef unsigned int bool;
+
+/* RDOFF format revision (currently used only when printing the version) */
+#define RDOFF2_REVISION "0.6.1"
+
+/* RDOFF2 file signature */
+#define RDOFF2_SIGNATURE "RDOFF2"
+
+/* Maximum size of an import/export label (including trailing zero) */
+#define EXIM_LABEL_MAX 64
-#define RDF_MAXSEGS 64
+/* Maximum size of library or module name (including trailing zero) */
+#define MODLIB_NAME_MAX 128
-/* the records that can be found in the RDOFF header */
+/* Maximum number of segments that we can handle in one file */
+#define RDF_MAXSEGS 64
+
+
+/* Record types that may present the RDOFF header */
+#define RDFREC_GENERIC 0
#define RDFREC_RELOC 1
#define RDFREC_IMPORT 2
#define RDFREC_GLOBAL 3
@@ -31,8 +52,21 @@ typedef unsigned char byte;
#define RDFREC_FARIMPORT 7
#define RDFREC_MODNAME 8
#define RDFREC_COMMON 10
-#define RDFREC_GENERIC 0
+
+/*
+ * Generic record - contains the type and length field, plus a 128 byte
+ * char array 'data'
+ */
+struct GenericRec {
+ byte type;
+ byte reclen;
+ char data[128];
+};
+
+/*
+ * Relocation record
+ */
struct RelocRec {
byte type; /* must be 1 */
byte reclen; /* content length */
@@ -41,55 +75,73 @@ struct RelocRec {
reloc @ loadtime, only linkage) */
long offset; /* from start of segment in which reference is loc'd */
byte length; /* 1 2 or 4 bytes */
- int16 refseg; /* segment to which reference refers to */
+ uint16 refseg; /* segment to which reference refers to */
};
+/*
+ * Extern/import record
+ */
struct ImportRec {
byte type; /* must be 2 */
byte reclen; /* content length */
byte flags; /* SYM_* flags (see below) */
- int16 segment; /* segment number allocated to the label for reloc
+ uint16 segment; /* segment number allocated to the label for reloc
records - label is assumed to be at offset zero
in this segment, so linker must fix up with offset
of segment and of offset within segment */
- char label[33]; /* zero terminated... should be written to file until
- the zero, but not after it - max len = 32 chars */
+ char label[EXIM_LABEL_MAX]; /* zero terminated, should be written to file
+ until the zero, but not after it */
};
+/*
+ * Public/export record
+ */
struct ExportRec {
byte type; /* must be 3 */
byte reclen; /* content length */
byte flags; /* SYM_* flags (see below) */
byte segment; /* segment referred to (0/1/2) */
long offset; /* offset within segment */
- char label[33]; /* zero terminated as above. max len = 32 chars */
+ char label[EXIM_LABEL_MAX]; /* zero terminated as in import */
};
+/*
+ * DLL record
+ */
struct DLLRec {
byte type; /* must be 4 */
byte reclen; /* content length */
- char libname[128]; /* name of library to link with at load time */
+ char libname[MODLIB_NAME_MAX]; /* name of library to link with at load time */
};
+/*
+ * BSS record
+ */
struct BSSRec {
byte type; /* must be 5 */
- byte reclen; /* content length */
+ byte reclen; /* content length */
long amount; /* number of bytes BSS to reserve */
};
+/*
+ * Module name record
+ */
struct ModRec {
byte type; /* must be 8 */
byte reclen; /* content length */
- char modname[128]; /* module name */
+ char modname[MODLIB_NAME_MAX]; /* module name */
};
+/*
+ * Common variable record
+ */
struct CommonRec {
byte type; /* must be 10 */
byte reclen; /* equals 7+label length */
- int16 segment; /* segment number */
+ uint16 segment; /* segment number */
long size; /* size of common variable */
- int16 align; /* alignment (power of two) */
- char label[33]; /* zero terminated as above. max len = 32 chars */
+ uint16 align; /* alignment (power of two) */
+ char label[EXIM_LABEL_MAX]; /* zero terminated as in import */
};
/* Flags for ExportRec */
@@ -98,15 +150,13 @@ struct CommonRec {
#define SYM_GLOBAL 4
#define SYM_IMPORT 8
-/*
- * GenericRec - contains the type and length field, plus a 128 byte
- * char array 'data'
- */
-struct GenericRec {
- byte type;
- byte reclen;
- char data[128];
-};
+
+/*** The following part is used only by the utilities *************************/
+
+#ifdef RDOFF_UTILS
+
+/* Some systems don't define this automatically */
+extern char *strdup(const char *);
typedef union RDFHeaderRec {
char type; /* invariant throughout all below */
@@ -122,9 +172,9 @@ typedef union RDFHeaderRec {
struct SegmentHeaderRec {
/* information from file */
- int16 type;
- int16 number;
- int16 reserved;
+ uint16 type;
+ uint16 number;
+ uint16 reserved;
long length;
/* information built up here */
@@ -133,30 +183,30 @@ struct SegmentHeaderRec {
};
typedef struct RDFFileInfo {
- FILE *fp; /* file descriptor; must be open to use this struct */
- int rdoff_ver; /* should be 1; any higher => not guaranteed to work */
- long header_len;
- long header_ofs;
+ FILE *fp; /* file descriptor; must be open to use this struct */
+ int rdoff_ver; /* should be 1; any higher => not guaranteed to work */
+ long header_len;
+ long header_ofs;
- byte *header_loc; /* keep location of header */
- long header_fp; /* current location within header for reading */
+ byte *header_loc; /* keep location of header */
+ long header_fp; /* current location within header for reading */
- struct SegmentHeaderRec seg[RDF_MAXSEGS];
- int nsegs;
+ struct SegmentHeaderRec seg[RDF_MAXSEGS];
+ int nsegs;
- long eof_offset; /* offset of the first byte beyond the end of this
+ long eof_offset; /* offset of the first byte beyond the end of this
module */
- char *name; /* name of module in libraries */
- int *refcount; /* pointer to reference count on file, or NULL */
+ char *name; /* name of module in libraries */
+ int *refcount; /* pointer to reference count on file, or NULL */
} rdffile;
#define BUF_BLOCK_LEN 4088 /* selected to match page size (4096)
* on 80x86 machines for efficiency */
typedef struct memorybuffer {
- int length;
- byte buffer[BUF_BLOCK_LEN];
- struct memorybuffer *next;
+ int length;
+ byte buffer[BUF_BLOCK_LEN];
+ struct memorybuffer *next;
} memorybuffer;
typedef struct {
@@ -166,9 +216,9 @@ typedef struct {
} rdf_headerbuf;
/* segments used by RDOFF, understood by rdoffloadseg */
-#define RDOFF_CODE 0
-#define RDOFF_DATA 1
-#define RDOFF_HEADER -1
+#define RDOFF_CODE 0
+#define RDOFF_DATA 1
+#define RDOFF_HEADER -1
/* mask for 'segment' in relocation records to find if relative relocation */
#define RDOFF_RELATIVEMASK 64
/* mask to find actual segment value in relocation records */
@@ -176,9 +226,25 @@ typedef struct {
extern int rdf_errno;
+/* rdf_errno can hold these error codes */
+enum {
+ /* 0 */ RDF_OK,
+ /* 1 */ RDF_ERR_OPEN,
+ /* 2 */ RDF_ERR_FORMAT,
+ /* 3 */ RDF_ERR_READ,
+ /* 4 */ RDF_ERR_UNKNOWN,
+ /* 5 */ RDF_ERR_HEADER,
+ /* 6 */ RDF_ERR_NOMEM,
+ /* 7 */ RDF_ERR_VER,
+ /* 8 */ RDF_ERR_RECTYPE,
+ /* 9 */ RDF_ERR_RECLEN,
+ /* 10 */ RDF_ERR_SEGMENT
+};
+
/* utility functions */
-int16 translateshort(int16 in);
long translatelong(long in);
+uint16 translateshort(uint16 in);
+char *translatesegmenttype(uint16 type);
/* RDOFF file manipulation functions */
int rdfopen(rdffile *f,const char *name);
@@ -203,4 +269,6 @@ int rdfaddsegment(rdf_headerbuf *h, long seglength);
int rdfwriteheader(FILE *fp,rdf_headerbuf *h);
void rdfdoneheader(rdf_headerbuf *h);
+#endif /* RDOFF_UTILS */
+
#endif /* _RDOFF_H */