*/
/*
- * TODO: actually get this new version working!
- * - finish off write_output() - appears to be done
- * - implement library searching - appears to be done
- * - maybe we only want to do one pass, for performance reasons?
- * this makes things a little harder, but unix 'ld' copes...
- * - implement command line options - appears to be done
- * - improve symbol table implementation - done, thanks to Graeme Defty
+ * TODO:
+ * enhance search of required export symbols in libraries (now depends
+ * on modules order in library)
* - keep a cache of symbol names in each library module so
* we don't have to constantly recheck the file
* - general performance improvements
* BUGS & LIMITATIONS: this program doesn't support multiple code, data
* or bss segments, therefore for 16 bit programs whose code, data or BSS
* segment exceeds 64K in size, it will not work. This program probably
- * wont work if compiled by a 16 bit compiler. Try DJGPP if you're running
+ * won't work if compiled by a 16 bit compiler. Try DJGPP if you're running
* under DOS. '#define STINGY_MEMORY' may help a little.
- *
- * TO FIX: enhance search of required export symbols in libraries (now depends
- * on modules order in library).
*/
#include <stdio.h>
#include "rdlib.h"
#include "segtab.h"
-#define LDRDF_VERSION "1.03"
+#define LDRDF_VERSION "1.04"
#define RDF_MAXSEGS 64
/* #define STINGY_MEMORY */
/* error file */
static FILE * error_file;
-#ifdef _MULTBOOT_H
-
-/* loading address for multiboot header */
-unsigned MBHloadAddr;
-
-/*
- * Tiny code that moves RDF loader to its working memory region:
- * mov esi,SOURCE_ADDR ; BE xx xx xx xx
- * mov edi,DEST_ADDR ; BF xx xx xx xx
- * mov esp,edi ; 89 FC
- * push edi ; 57
- * mov ecx,RDFLDR_LENGTH/4 ; B9 xx xx xx xx
- * cld ; FC
- * rep movsd ; F3 A5
- * ret ; C3
- */
-
-#define RDFLDR_LENGTH 4096 /* Loader will be moved to unused */
-#define RDFLDR_DESTLOC 0xBF000 /* video page */
-
-unsigned char RDFloaderMover[]={
- 0xBE, 0, 0, 0, 0, 0xBF, 0, 0xF0, 0xB, 0,
- 0x89, 0xFC, 0x57,
- 0xB9, 0, 4, 0, 0,
- 0xFC, 0xF3, 0xA5, 0xC3
-};
-
-#endif
-
/* the header of the output file, built up stage by stage */
rdf_headerbuf * newheader = NULL;
int errorcount = 0; /* determines main program exit status */
+/*
+ * Multiboot header support.
+ */
+
+/* loading address for multiboot header */
+unsigned MBHloadAddr;
+
+#define RDFLDR_LENGTH 4096 /* Loader size is 4K */
+#define RDFLDR_DESTLOC 0x100000 /* and its absolute address */
+
+/*
+ * Tiny code that moves RDF setup code to its working memory region
+ */
+unsigned char trampoline_code[] = {
+ 0xBE, 0, 0, 0, 0, /* mov esi,SOURCE_ADDR */
+ 0xBF, 0, 0, 0, 0, /* mov edi,DEST_ADDR */
+ 0x89, 0xFA, /* mov edx,edi */
+ 0xB9, 0, 4, 0, 0, /* mov ecx,RDFLDR_LENGTH/4 */
+ 0xFC, /* cld */
+ 0xF3, 0xA5, /* rep movsd */
+ 0xFF, 0xE2 /* jmp edx */
+};
+
/* =========================================================================
* Utility functions
*/
hr = (rdfheaderrec *) malloc(sizeof(struct MultiBootHdrRec));
hr->mbh.type = 9;
- hr->mbh.reclen = sizeof(struct tMultiBootHeader)+RDFLDRMOVER_SIZE;
+ hr->mbh.reclen = sizeof(struct tMultiBootHeader)+TRAMPOLINESIZE;
hr->mbh.mb.Magic = MB_MAGIC;
hr->mbh.mb.Flags = MB_FL_KLUDGE;
hr->mbh.mb.LoadAddr = MBHloadAddr;
hr->mbh.mb.Entry = MBHloadAddr+16+sizeof(struct tMultiBootHeader);
- memcpy(hr->mbh.mover,RDFloaderMover,RDFLDRMOVER_SIZE);
+ memcpy(hr->mbh.trampoline,trampoline_code,TRAMPOLINESIZE);
rdfaddheader(rdfheader,hr);
free(hr);
* Otherwise, we need to output a new relocation record
* with the references updated segment and offset...
*/
- if (! isrelative
- || cur->seginfo[localseg].dest_seg != seg)
+
+ if (isrelative && cur->seginfo[localseg].dest_seg != seg)
+ {
+ hr->r.segment = cur->seginfo[localseg].dest_seg+64;
+ hr->r.offset += cur->seginfo[localseg].reloc;
+ hr->r.refseg = seg;
+ rdfaddheader(rdfheader, hr);
+ break;
+ }
+
+ if (! isrelative || cur->seginfo[localseg].dest_seg != seg)
{
hr->r.segment = cur->seginfo[localseg].dest_seg;
hr->r.offset += cur->seginfo[localseg].reloc;
struct MultiBootHdrRec *mbhrec = (struct MultiBootHdrRec *)(rdfheader->buf->buffer);
unsigned l = membuflength(rdfheader->buf) + 14 +
10*rdfheader->nsegments + rdfheader->seglength;
- unsigned *ldraddr = (unsigned *)(mbhrec->mover+1);
+ unsigned *ldraddr = (unsigned *)(mbhrec->trampoline+1);
+ unsigned *ldrdest = (unsigned *)(mbhrec->trampoline+6);
mbhrec->mb.LoadEndAddr = MBHloadAddr+l+10+RDFLDR_LENGTH;
mbhrec->mb.BSSendAddr = mbhrec->mb.LoadEndAddr;
+
*ldraddr = MBHloadAddr+l+10;
+ *ldrdest = RDFLDR_DESTLOC;
}
rdfwriteheader(f, rdfheader);
/*
* an rdoff library is simply a sequence of RDOFF object files, each
* preceded by the name of the module, an ASCII string of up to 255
- * characters, terminated by a zero.
+ * characters, terminated by a zero.
+ *
+ * When a library is being created, special signature block is placed
+ * in the beginning of the file. It is a string 'RDLIB' followed by a
+ * version number, then long content size and a long time stamp.
+ * The module name of the signature block is '.sig'.
+ *
*
* There may be an optional directory placed on the end of the file.
* The format of the directory will be 'RDLDD' followed by a version
* directory, the format of which has not yet been designed.
* The module name of the directory must be '.dir'.
*
- * All module names beginning with '.' are reserved
- * for possible future extensions. The linker ignores all such modules,
- * assuming they have the format of a six byte type & version identifier
- * followed by long content size, followed by data.
+ * All module names beginning with '.' are reserved for possible future
+ * extensions. The linker ignores all such modules, assuming they have
+ * the format of a six byte type & version identifier followed by long
+ * content size, followed by data.
*/
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <unistd.h>
+#include <time.h>
/* functions supported:
* create a library (no extra operands required)
" r - replace (module-name filename)\n"
" d - delete (module-name)\n"
" t - list\n";
+
+/* Library signature */
+const char *rdl_signature = "RDLIB2", *sig_modname = ".sig";
char **_argv;
int main(int argc, char **argv)
{
- FILE *fp, *fp2, *fptmp;
+ FILE *fp, *fp2 = NULL, *fptmp;
char *p, buf[256], c;
int i;
long l;
+ time_t t;
char tmptempl[L_tmpnam], rdbuf[10];
_argv = argv;
perror("rdflib");
exit(1);
}
+ fwrite(sig_modname, 1, strlen(sig_modname)+1, fp);
+ fwrite(rdl_signature, 1, strlen(rdl_signature), fp);
+ l = sizeof(t = time(NULL));
+ fwrite(&l, sizeof(l), 1, fp);
+ fwrite(&t, 1, l, fp);
fclose(fp);
break;
#include "rdlib.h"
/*
- * format of rdoff library files:
+ * format of RDOFF library files:
+ * optional signature ('.sig')
* repeat
* null terminated module name (max 255 chars)
* RDOFF module
* until eof
+ * optional directory ('.dir')
*/
/*
i++;
if (feof(fp)) break;
- fread(buf, 6, 1, fp);
- buf[6] = 0;
if (buf[0] == '.') {
/*
- * a special module, eg a directory.
+ * A special module, eg a signature block or a directory.
* Format of such a module is defined to be:
- * six char type identifier (which we've already read)
+ * six char type identifier
* long count bytes content
* content
- * so we can handle it uniformaly with RDOFF2 modules...
- * do nothing here. :-)
+ * so we can handle it uniformaly with RDOFF2 modules.
*/
+ fread(buf, 6, 1, fp);
+ buf[6] = 0;
+ /* Currently, nothing useful to do with signature block.. */
+ } else {
+ fread(buf, 6, 1, fp);
+ buf[6] = 0;
+ if (strncmp(buf, "RDOFF", 5)) {
+ return rdl_error = lastresult = 2;
+ } else if (buf[5] != '2') {
+ return rdl_error = lastresult = 3;
+ }
}
- else if (strncmp(buf, "RDOFF", 5)) {
- return rdl_error = lastresult = 2;
- }
- else if (buf[5] != '2') {
- return rdl_error = lastresult = 3;
- }
-
fread(&length, 4, 1, fp);
fseek(fp, length, SEEK_CUR); /* skip over the module */
}