]> Shamusworld >> Repos - rmac/blobdiff - object.c
Lots of fixes for floating point handling; version now at 1.11.0.
[rmac] / object.c
index cbedaab6b0b2cdf5907af53d377a42cb4dc5b8ab..086d407eed73f6d436b6a607828db20e687ad9d5 100644 (file)
--- a/object.c
+++ b/object.c
@@ -1,19 +1,20 @@
 //
-// RMAC - Reboot's Macro Assembler for the Atari Jaguar Console System
+// RMAC - Reboot's Macro Assembler for all Atari computers
 // OBJECT.C - Writing Object Files
-// Copyright (C) 199x Landon Dyer, 2017 Reboot and Friends
+// Copyright (C) 199x Landon Dyer, 2011-2017 Reboot and Friends
 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
 // Source utilised with the kind permission of Landon Dyer
 //
 
 #include "object.h"
+#include "6502.h"
+#include "direct.h"
 #include "error.h"
 #include "mark.h"
 #include "riscasm.h"
 #include "sect.h"
 #include "symbol.h"
 
-
 //#define DEBUG_ELF
 
 uint32_t symsize = 0;                  // Size of BSD/ELF symbol table
@@ -57,7 +58,7 @@ See left.             4 & 5   If these bits are set to 0 (PF_PRIVATE), the processes'
 
 
 //
-// Add entry to symbol table
+// Add entry to symbol table (in ALCYON mode)
 // If 'globflag' is 1, make the symbol global
 // If in .PRG mode, adjust symbol values for fake link
 //
@@ -177,6 +178,7 @@ uint8_t * AddBSDSymEntry(uint8_t * buf, SYM * sym, int globflag)
 uint8_t * AddELFSymEntry(uint8_t * buf, SYM * sym, int globflag)
 {
        chptr = buf;
+       ch_size = 0;
        D_long(strindx);                // st_name
        D_long(sym->svalue);    // st_value
        D_long(0);                              // st_size
@@ -227,6 +229,7 @@ uint8_t * AddELFSymEntry(uint8_t * buf, SYM * sym, int globflag)
 int DepositELFSectionHeader(uint8_t * ptr, uint32_t name, uint32_t type, uint32_t flags, uint32_t addr, uint32_t offset, uint32_t size, uint32_t link, uint32_t info, uint32_t addralign, uint32_t entsize)
 {
        chptr = ptr;
+       ch_size = 0;
        D_long(name);
        D_long(type);
        D_long(flags);
@@ -262,6 +265,7 @@ printf("DepositELFSHSTEntry: s = \"%s\"\n", s);
 uint32_t DepositELFSymbol(uint8_t * ptr, uint32_t name, uint32_t addr, uint32_t size, uint8_t info, uint8_t other, uint16_t shndx)
 {
        chptr = ptr;
+       ch_size = 0;
        D_long(name);
        D_long(addr);
        D_long(size);
@@ -308,7 +312,7 @@ int WriteObject(int fd)
 
                ssize = 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
+               buf = malloc(0x800000);                                         // Allocate 8MB object file image memory
 
                if (buf == NULL)
                {
@@ -316,7 +320,7 @@ int WriteObject(int fd)
                        return ERROR;
                }
 
-               memset(buf, 0, 0x600000);               // Clear allocated memory
+               memset(buf, 0, 0x800000);               // Clear allocated memory
                objImage = buf;                                 // Set global object image pointer
                strtable = malloc(0x200000);    // Allocate 2MB string table buffer
 
@@ -473,7 +477,7 @@ int WriteObject(int fd)
 
                if (buf == NULL)
                {
-                       error("cannot allocate object file memory (in BSD mode)");
+                       error("cannot allocate object file memory (in ELF mode)");
                        return ERROR;
                }
 
@@ -483,7 +487,7 @@ int WriteObject(int fd)
 
                if (strtable == NULL)
                {
-                       error("cannot allocate string table memory (in BSD mode)");
+                       error("cannot allocate string table memory (in ELF mode)");
                        return ERROR;
                }
 
@@ -520,7 +524,7 @@ int WriteObject(int fd)
                {
                        elfHdrNum[ES_TEXT] = shstIndex;
                        shstTab[ES_TEXT] = shstSize;
-                       shstSize += DepositELFSHSTEntry(&shstPtr, "TEXT");
+                       shstSize += DepositELFSHSTEntry(&shstPtr, ".text");
                        shstIndex++;
                        numEntries++;
                }
@@ -529,7 +533,7 @@ int WriteObject(int fd)
                {
                        elfHdrNum[ES_DATA] = shstIndex;
                        shstTab[ES_DATA] = shstSize;
-                       shstSize += DepositELFSHSTEntry(&shstPtr, "DATA");
+                       shstSize += DepositELFSHSTEntry(&shstPtr, ".data");
                        shstIndex++;
                        numEntries++;
                }
@@ -538,7 +542,7 @@ int WriteObject(int fd)
                {
                        elfHdrNum[ES_BSS] = shstIndex;
                        shstTab[ES_BSS] = shstSize;
-                       shstSize += DepositELFSHSTEntry(&shstPtr, "BSS");
+                       shstSize += DepositELFSHSTEntry(&shstPtr, ".bss");
                        shstIndex++;
                        numEntries++;
                }
@@ -619,7 +623,7 @@ for(int j=0; j<i; j++)
                // Construct TEXT section, if any
                if (sect[TEXT].sloc > 0)
                {
-                       headerSize += DepositELFSectionHeader(headers + headerSize, shstTab[ES_TEXT], 1, 6, 0, elfSize, sect[TEXT].sloc, 0, 0, 2, 0);
+                       headerSize += DepositELFSectionHeader(headers + headerSize, shstTab[ES_TEXT], 1, 6, 0, elfSize, sect[TEXT].sloc, 0, 0, largestAlign[0], 0);
 
                        for(CHUNK * cp=sect[TEXT].sfcode; cp!=NULL; cp=cp->chnext)
                        {
@@ -636,7 +640,7 @@ for(int j=0; j<i; j++)
                // Construct DATA section, if any
                if (sect[DATA].sloc > 0)
                {
-                       headerSize += DepositELFSectionHeader(headers + headerSize, shstTab[ES_DATA], 1, 3, 0, elfSize, sect[DATA].sloc, 0, 0, 1, 0);
+                       headerSize += DepositELFSectionHeader(headers + headerSize, shstTab[ES_DATA], 1, 3, 0, elfSize, sect[DATA].sloc, 0, 0, largestAlign[1], 0);
 
                        for(CHUNK * cp=sect[DATA].sfcode; cp!=NULL; cp=cp->chnext)
                        {
@@ -651,7 +655,7 @@ for(int j=0; j<i; j++)
                // Construct BSS section, if any
                if (sect[BSS].sloc > 0)
                {
-                       headerSize += DepositELFSectionHeader(headers + headerSize, shstTab[ES_BSS], 8, 3, 0, elfSize, sect[BSS].sloc, 0, 0, 2, 0);
+                       headerSize += DepositELFSectionHeader(headers + headerSize, shstTab[ES_BSS], 8, 3, 0, elfSize, sect[BSS].sloc, 0, 0, largestAlign[2], 0);
                }
 
                int textrelLoc = headerSize;
@@ -752,6 +756,11 @@ for(int j=0; j<i; j++)
                        free(strtable);
                }
        }
+       else if (obj_format == XEX)
+       {
+               // Just write the object file
+               m6502obj(fd);
+       }
 
        return 0;
 }