-int object(WORD fd) {
- LONG t; // Scratch long
- LONG tds; // TEXT & DATA segment size
- int i; // Temporary int
- CHUNK *cp; // Chunk (for gather)
- char *buf; // Scratch area
- char *p; // Temporary ptr
- LONG ssize; // Size of symbols
- LONG trsize, drsize; // Size of relocations
-
- // Write requested object file...
- switch(obj_format) {
- case BSD:
- ssize = ((LONG)sy_assign(NULL, NULL)); // Assign index numbers to the symbols
- tds = sect[TEXT].sloc + sect[DATA].sloc; // Get size of TEXT and DATA segment
- buf = malloc(0x400000); // Allocate 4mb object file image memory
- if(buf == NULL) {
- error("cannot allocate object file memory (in BSD mode)");
- return(ERROR);
- }
- memset(buf, 0, 0x400000); // Reset allocated memory
- objimage = buf; // Set global object image pointer
- strtable = malloc(0x200000); // Allocate 2mb scratch buffer
- if(strtable == NULL) {
- error("cannot allocate string table memory (in BSD mode)");
- return(ERROR);
- }
- memset(strtable, 0, 0x200000); // Reset allocated memory
-
- // Build object file header
- chptr = buf; // Base of header
- t = 0x00000107;
- D_long(t); // Magic number
- t = sect[TEXT].sloc; // TEXT size
- D_long(t);
- t = sect[DATA].sloc; // DATA size
- D_long(t);
- t = sect[BSS].sloc; // BSS size
- D_long(t);
- t = 0x00000000;
- D_long(t); // Symbol size
- D_long(t); // First entry (0L)
- D_long(t); // TEXT relocation size
- D_long(t); // BSD relocation size
-
- // Construct TEXT and DATA segments (without relocation changes)
- p = buf + BSDHDRSIZE;
- for(i = TEXT; i <= DATA; ++i)
- for(cp = sect[i].sfcode; cp != NULL; cp = cp->chnext) {
- copy(p, cp->chptr, cp->ch_size);
- p += cp->ch_size;
- }
-
- // Do relocation tables (and make changes to segment data)
- p = buf + (BSDHDRSIZE + tds); // Move obj image ptr to reloc info
- trsize = bsdmarkimg(p, tds, sect[TEXT].sloc, TEXT);// Do TEXT relocation table
- chptr = buf + 24; // Point to relocation hdr entry
- D_long(trsize); // Write the relocation table size
- p = buf + (BSDHDRSIZE + tds + trsize); // Move obj image ptr to reloc info
- drsize = bsdmarkimg(p, tds, sect[TEXT].sloc, DATA);// Do DATA relocation table
- chptr = buf + 28; // Point to relocation hdr entry
- D_long(drsize); // Write the relocation table size
-
- p = buf + (BSDHDRSIZE + tds + trsize + drsize); // Point to start of symbol table
- sy_assign(p, constr_bsdsymtab); // Build symbol and string tables
- chptr = buf + 16; // Point to sym table size hdr entry
- D_long(symsize); // Write the symbol table size
-
- // Point to string table
- p = buf + (BSDHDRSIZE + tds + trsize + drsize + symsize);
-
- memcpy(p, strtable, strindx); // Copy string table to object image
- if(buf) free(strtable); // Free allocated memory
- chptr = p; // Point to string table size long
- D_long(strindx); // Write string table size
-
- // Write the BSD object file from the object image buffer
- write(fd, buf, BSDHDRSIZE + tds + trsize + drsize + symsize + strindx + 4);
-
- if(buf) free(buf); // Free allocated memory
- break;
- }
-
- return(0);
-}
+ // Write requested object file...
+ switch (obj_format)
+ {
+ case BSD:
+ ssize = ((LONG)sy_assign(NULL, NULL)); // Assign index numbers to the symbols
+ tds = sect[TEXT].sloc + sect[DATA].sloc; // Get size of TEXT and DATA segment
+ buf = malloc(0x600000); // Allocate 6mb object file image memory
+
+ if (buf == NULL)
+ {
+ error("cannot allocate object file memory (in BSD mode)");
+ return ERROR;
+ }
+
+ memset(buf, 0, 0x600000); // Reset allocated memory
+ objImage = buf; // Set global object image pointer
+ strtable = malloc(0x200000); // Allocate 2mb scratch buffer
+
+ if (strtable == NULL)
+ {
+ error("cannot allocate string table memory (in BSD mode)");
+ return ERROR;
+ }
+
+ memset(strtable, 0, 0x200000); // Reset allocated memory
+
+ // Build object file header
+ chptr = buf; // Base of header
+ D_long(0x00000107); // Magic number
+ D_long(sect[TEXT].sloc); // TEXT size
+ D_long(sect[DATA].sloc); // DATA size
+ D_long(sect[BSS].sloc); // BSS size
+ D_long(0x00000000); // Symbol size
+ D_long(0x00000000); // First entry (0L)
+ D_long(0x00000000); // TEXT relocation size
+ D_long(0x00000000); // BSD relocation size
+
+ // Construct TEXT and DATA segments (without relocation changes)
+ p = buf + BSDHDRSIZE;
+
+ for(i=TEXT; i<=DATA; ++i)
+ {
+ for(cp=sect[i].sfcode; cp!=NULL; cp=cp->chnext)
+ {
+ memcpy(p, cp->chptr, cp->ch_size);
+ p += cp->ch_size;
+ }
+ }
+
+ // Do relocation tables (and make changes to segment data)
+ p = buf + (BSDHDRSIZE + tds); // Move obj image ptr to reloc info
+ trsize = bsdmarkimg(p, tds, sect[TEXT].sloc, TEXT);// Do TEXT relocation table
+ chptr = buf + 24; // Point to relocation hdr entry
+ D_long(trsize); // Write the relocation table size
+ p = buf + (BSDHDRSIZE + tds + trsize); // Move obj image ptr to reloc info
+ drsize = bsdmarkimg(p, tds, sect[TEXT].sloc, DATA);// Do DATA relocation table
+ chptr = buf + 28; // Point to relocation hdr entry
+ D_long(drsize); // Write the relocation table size
+
+ p = buf + (BSDHDRSIZE + tds + trsize + drsize);// Point to start of symbol table
+ sy_assign(p, constr_bsdsymtab); // Build symbol and string tables
+ chptr = buf + 16; // Point to sym table size hdr entry
+ D_long(symsize); // Write the symbol table size
+
+ // Point to string table
+ p = buf + (BSDHDRSIZE + tds + trsize + drsize + symsize);