summaryrefslogtreecommitdiff
path: root/rdoff/rdoff.h
diff options
context:
space:
mode:
Diffstat (limited to 'rdoff/rdoff.h')
-rw-r--r--rdoff/rdoff.h98
1 files changed, 75 insertions, 23 deletions
diff --git a/rdoff/rdoff.h b/rdoff/rdoff.h
index 0f74b80a..e23ffa40 100644
--- a/rdoff/rdoff.h
+++ b/rdoff/rdoff.h
@@ -4,28 +4,39 @@
* Julian Hall. All rights reserved. The software is
* redistributable under the licence given in the file "Licence"
* distributed in the NASM archive.
+ *
+ * Permission to use this file in your own projects is granted, as long
+ * as acknowledgement is given in an appropriate manner to its authors,
+ * with instructions of how to obtain a copy via ftp.
*/
#ifndef _RDOFF_H
-#define _RDOFF_H "RDOFF1 support routines v0.1"
+#define _RDOFF_H "RDOFF2 support routines v0.3"
+
+/* Some systems don't define this automatically */
+extern char *strdup(const char *);
-typedef short int16; /* not sure if this will be required to be altered
- at all... best to typedef it just in case */
+typedef unsigned short int16;
+typedef unsigned char byte;
+
+#define RDF_MAXSEGS 64
/* the records that can be found in the RDOFF header */
struct RelocRec {
- char type; /* must be 1 */
- char segment; /* only 0 for code, or 1 for data supported,
+ byte type; /* must be 1 */
+ byte reclen; /* content length */
+ byte segment; /* only 0 for code, or 1 for data supported,
but add 64 for relative refs (ie do not require
reloc @ loadtime, only linkage) */
long offset; /* from start of segment in which reference is loc'd */
- char length; /* 1 2 or 4 bytes */
+ byte length; /* 1 2 or 4 bytes */
int16 refseg; /* segment to which reference refers to */
};
struct ImportRec {
- char type; /* must be 2 */
+ byte type; /* must be 2 */
+ byte reclen; /* content length */
int16 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
@@ -35,42 +46,71 @@ struct ImportRec {
};
struct ExportRec {
- char type; /* must be 3 */
- char segment; /* segment referred to (0/1) */
+ byte type; /* must be 3 */
+ byte reclen; /* content length */
+ byte segment; /* segment referred to (0/1) */
long offset; /* offset within segment */
char label[33]; /* zero terminated as above. max len = 32 chars */
};
struct DLLRec {
- char type; /* must be 4 */
+ byte type; /* must be 4 */
+ byte reclen; /* content length */
char libname[128]; /* name of library to link with at load time */
};
struct BSSRec {
- char type; /* must be 5 */
+ byte type; /* must be 5 */
+ byte reclen; /* content length */
long amount; /* number of bytes BSS to reserve */
};
-
+
+/* GenericRec - contains the type and length field, plus a 128 byte
+ char array 'data', which will probably never be used! */
+
+struct GenericRec {
+ byte type;
+ byte reclen;
+ char data[128];
+};
+
typedef union RDFHeaderRec {
char type; /* invariant throughout all below */
- struct RelocRec r; /* type == 1 */
- struct ImportRec i; /* type == 2 */
+ struct GenericRec g;
+ struct RelocRec r; /* type == 1 / 6 */
+ struct ImportRec i; /* type == 2 / 7 */
struct ExportRec e; /* type == 3 */
struct DLLRec d; /* type == 4 */
struct BSSRec b; /* type == 5 */
} rdfheaderrec;
+struct SegmentHeaderRec {
+ /* information from file */
+ int16 type;
+ int16 number;
+ int16 reserved;
+ long length;
+
+ /* information built up here */
+ long offset;
+ byte *data; /* pointer to segment data if it exists in memory */
+};
+
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 code_len;
- long data_len;
long header_ofs;
- long code_ofs;
- long data_ofs;
- char *header_loc; /* keep location of header */
+
+ byte *header_loc; /* keep location of header */
long header_fp; /* current location within header for reading */
+
+ struct SegmentHeaderRec seg[RDF_MAXSEGS];
+ int nsegs;
+
+ 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 */
} rdffile;
@@ -79,11 +119,15 @@ typedef struct RDFFileInfo {
* on 80x86 machines for efficiency */
typedef struct memorybuffer {
int length;
- char buffer[BUF_BLOCK_LEN];
+ byte buffer[BUF_BLOCK_LEN];
struct memorybuffer *next;
} memorybuffer;
-typedef memorybuffer rdf_headerbuf;
+typedef struct {
+ memorybuffer * buf; /* buffer containing header records */
+ int nsegments; /* number of segments to be written */
+ long seglength; /* total length of all the segments */
+} rdf_headerbuf;
/* segments used by RDOFF, understood by rdoffloadseg */
#define RDOFF_CODE 0
@@ -96,10 +140,15 @@ typedef memorybuffer rdf_headerbuf;
extern int rdf_errno;
+/* utility functions */
+int16 translateshort(int16 in);
+long translatelong(long in);
+
/* RDOFF file manipulation functions */
int rdfopen(rdffile *f,const char *name);
-int rdfopenhere(rdffile *f, FILE *fp, int *refcount, char *name);
+int rdfopenhere(rdffile *f, FILE *fp, int *refcount, const char *name);
int rdfclose(rdffile *f);
+int rdffindsegment(rdffile * f, int segno);
int rdfloadseg(rdffile *f,int segment,void *buffer);
rdfheaderrec *rdfgetheaderrec(rdffile *f); /* returns static storage */
void rdfheaderrewind(rdffile *f); /* back to start of header */
@@ -107,11 +156,14 @@ void rdfperror(const char *app,const char *name);
/* functions to write a new RDOFF header to a file -
use rdfnewheader to allocate a header, rdfaddheader to add records to it,
- rdfwriteheader to write 'RDOFF1', length of header, and the header itself
+ rdfaddsegment to notify the header routines that a segment exists, and
+ to tell it how long the segment will be.
+ rdfwriteheader to write the file id, object length, and header
to a file, and then rdfdoneheader to dispose of the header */
rdf_headerbuf *rdfnewheader(void);
int rdfaddheader(rdf_headerbuf *h,rdfheaderrec *r);
+int rdfaddsegment(rdf_headerbuf *h, long seglength);
int rdfwriteheader(FILE *fp,rdf_headerbuf *h);
void rdfdoneheader(rdf_headerbuf *h);