]> Shamusworld >> Repos - rmac/commitdiff
Added missing d_ds handling, add kludge for 56K fixups.
authorShamus Hammons <jlhamm@acm.org>
Thu, 8 Aug 2019 20:01:34 +0000 (15:01 -0500)
committerShamus Hammons <jlhamm@acm.org>
Thu, 8 Aug 2019 20:01:34 +0000 (15:01 -0500)
Also added code to prevent dumping a 6502 section that had nothing in
it, as this is very annoying.

debug.c
direct.c
rmac.c
sect.c

diff --git a/debug.c b/debug.c
index 1b9b651515202ec2da47006af0a0d259fce563e2..e3ef93fd458b31cb956dcf888ea27cbc1f3869b6 100644 (file)
--- a/debug.c
+++ b/debug.c
@@ -7,6 +7,7 @@
 //
 
 #include "debug.h"
 //
 
 #include "debug.h"
+#include "6502.h"
 #include "amode.h"
 #include "direct.h"
 #include "expr.h"
 #include "amode.h"
 #include "direct.h"
 #include "expr.h"
@@ -220,8 +221,6 @@ int mdump(char * start, LONG count, int flg, LONG base)
                                start[i+2] & 0xFF, start[i+3] & 0xFF);
                        i += 4;
                        break;
                                start[i+2] & 0xFF, start[i+3] & 0xFF);
                        i += 4;
                        break;
-               case 3:
-                       break;
                }
 
                if (base != -1)
                }
 
                if (base != -1)
@@ -417,6 +416,10 @@ void DumpTokens(TOKEN * tokenBuffer)
 //
 int dump_everything(void)
 {
 //
 int dump_everything(void)
 {
+       // FFS
+       if ((currentorg[1] - currentorg[0]) == 0)
+               sect[M6502].sfcode = NULL;
+
        for(int i=1; i<NSECTS; i++)
        {
                if (sect[i].scattr & SUSED)
        for(int i=1; i<NSECTS; i++)
        {
                if (sect[i].scattr & SUSED)
index 1864b86e266142964f630166ca37390a48a40d39..b17f9dde6393fc515f74df779a52b469d5a60464 100644 (file)
--- a/direct.c
+++ b/direct.c
@@ -1094,9 +1094,32 @@ int d_ds(WORD siz)
 
                just_bss = 1;                                   // No data deposited (8-bit CPU mode)
        }
 
                just_bss = 1;                                   // No data deposited (8-bit CPU mode)
        }
+       else if (cursect == M56001P || cursect == M56001X || cursect == M56001Y || cursect == M56001L)
+       {
+               // Change segment instead of marking blanks.
+               // Only mark segments we actually wrote something
+               if (chptr != dsp_currentorg->start && dsp_written_data_in_current_org)
+               {
+                       dsp_currentorg->end = chptr;
+                       dsp_currentorg++;
+                       dsp_currentorg->memtype = dsp_currentorg[-1].memtype;
+               }
+
+               listvalue((uint32_t)eval);
+               sloc += (uint32_t)eval;
+
+               // And now let's create a new segment
+               dsp_currentorg->start = chptr;
+               dsp_currentorg->chunk = scode;  // Mark down which chunk this org starts from (will be needed when outputting)
+               sect[cursect].orgaddr = sloc;
+               dsp_currentorg->orgadr = sloc;
+               dsp_written_data_in_current_org = 0;
+
+               just_bss = 1;                                   // No data deposited
+       }
        else
        {
        else
        {
-               dep_block(eval, siz, 0, (WORD)(DEFINED | ABS), NULL);
+               dep_block(eval, siz, 0, (DEFINED | ABS), NULL);
        }
 
        ErrorIfNotAtEOL();
        }
 
        ErrorIfNotAtEOL();
@@ -1545,11 +1568,8 @@ int d_init(WORD def_siz)
 //
 int dep_block(uint32_t count, WORD siz, uint32_t eval, WORD eattr, TOKEN * exprbuf)
 {
 //
 int dep_block(uint32_t count, WORD siz, uint32_t eval, WORD eattr, TOKEN * exprbuf)
 {
-       WORD tdb;
-       WORD defined;
-
-       tdb = (WORD)(eattr & TDB);
-       defined = (WORD)(eattr & DEFINED);
+       WORD tdb = eattr & TDB;
+       WORD defined = eattr & DEFINED;
 
        while (count--)
        {
 
        while (count--)
        {
diff --git a/rmac.c b/rmac.c
index c92f1549bb107d5fccb24485888187b308171ddf..7858040c9c7c8378d1fd366159f06f7a8a3b4a05 100644 (file)
--- a/rmac.c
+++ b/rmac.c
@@ -268,33 +268,35 @@ int Process(int argc, char ** argv)
        char fnbuf[FNSIZ];                              // Filename buffer
        int i;                                                  // Iterator
 
        char fnbuf[FNSIZ];                              // Filename buffer
        int i;                                                  // Iterator
 
-       errcnt = 0;                                             // Initialise error count
-       listing = 0;                                    // Initialise listing level
-       list_flag = 0;                                  // Initialise listing flag
-       verb_flag = perm_verb_flag;             // Initialise verbose flag
-       as68_flag = 0;                                  // Initialise as68 kludge mode
-       glob_flag = 0;                                  // Initialise .globl flag
-       sbra_flag = 0;                                  // Initialise short branch flag
-       debug = 0;                                              // Initialise debug flag
-       searchpath = NULL;                              // Initialise search path
-       objfname = NULL;                                // Initialise object filename
-       list_fname = NULL;                              // Initialise listing filename
-       err_fname = NULL;                               // Initialise error filename
-       obj_format = BSD;                               // Initialise object format
-       firstfname = NULL;                              // Initialise first filename
-       err_fd = ERROUT;                                // Initialise error file descriptor
-       err_flag = 0;                                   // Initialise error flag
-       rgpu = 0;                                               // Initialise GPU assembly flag
-       rdsp = 0;                                               // Initialise DSP assembly flag
-       robjproc = 0;                                   // Initialise OP assembly flag
+       errcnt = 0;                                             // Initialize error count
+       listing = 0;                                    // Initialize listing level
+       list_flag = 0;                                  // Initialize listing flag
+       verb_flag = perm_verb_flag;             // Initialize verbose flag
+       as68_flag = 0;                                  // Initialize as68 kludge mode
+       glob_flag = 0;                                  // Initialize .globl flag
+       sbra_flag = 0;                                  // Initialize short branch flag
+       debug = 0;                                              // Initialize debug flag
+       searchpath = NULL;                              // Initialize search path
+       objfname = NULL;                                // Initialize object filename
+       list_fname = NULL;                              // Initialize listing filename
+       err_fname = NULL;                               // Initialize error filename
+       obj_format = BSD;                               // Initialize object format
+       firstfname = NULL;                              // Initialize first filename
+       err_fd = ERROUT;                                // Initialize error file descriptor
+       err_flag = 0;                                   // Initialize error flag
+       rgpu = 0;                                               // Initialize GPU assembly flag
+       rdsp = 0;                                               // Initialize DSP assembly flag
+       robjproc = 0;                                   // Initialize OP assembly flag
        lsym_flag = 1;                                  // Include local symbols in object file
        regbank = BANK_N;                               // No RISC register bank specified
        orgactive = 0;                                  // Not in RISC org section
        orgwarning = 0;                                 // No ORG warning issued
        lsym_flag = 1;                                  // Include local symbols in object file
        regbank = BANK_N;                               // No RISC register bank specified
        orgactive = 0;                                  // Not in RISC org section
        orgwarning = 0;                                 // No ORG warning issued
-       segpadsize = 2;                                 // Initialise segment padding size
+       segpadsize = 2;                                 // Initialize segment padding size
+    dsp_orgmap[0].start = 0;           // Initialize 56001 org initial address
+    dsp_orgmap[0].memtype = ORG_P;     // Initialize 56001 org start segment
        m6502 = 0;                                              // 6502 mode off by default
 
        m6502 = 0;                                              // 6502 mode off by default
 
-       // Initialise modules
+       // Initialize modules
        InitSymbolTable();                              // Symbol table
        InitTokenizer();                                // Tokenizer
        InitLineProcessor();                    // Line processor
        InitSymbolTable();                              // Symbol table
        InitTokenizer();                                // Tokenizer
        InitLineProcessor();                    // Line processor
diff --git a/sect.c b/sect.c
index 49806a02b9d4e8d7570b19b5d27f35ca89b6dc86..7fcb2996bc30051a819e656b08f7ffa6db0b5e61 100644 (file)
--- a/sect.c
+++ b/sect.c
@@ -159,7 +159,7 @@ void SaveSection(void)
        sp->sloc = sloc;
        sp->orgaddr = orgaddr;
 
        sp->sloc = sloc;
        sp->orgaddr = orgaddr;
 
-       if (scode != NULL)                              // Bailout code chunk
+       if (scode != NULL)                              // Bailout code chunk (if any)
                scode->ch_size = ch_size;
 }
 
                scode->ch_size = ch_size;
 }
 
@@ -218,29 +218,43 @@ void chcheck(uint32_t amt)
        DEBUG { printf("    amt (adjusted)=%u\n", amt); }
        SECT * p = &sect[cursect];
        CHUNK * cp = malloc(sizeof(CHUNK) + amt);
        DEBUG { printf("    amt (adjusted)=%u\n", amt); }
        SECT * p = &sect[cursect];
        CHUNK * cp = malloc(sizeof(CHUNK) + amt);
+       int first = 0;
 
 
-       // First chunk in section
        if (scode == NULL)
        {
        if (scode == NULL)
        {
+               // First chunk in section
                cp->chprev = NULL;
                p->sfcode = cp;
                cp->chprev = NULL;
                p->sfcode = cp;
+               first = 1;
        }
        }
-       // Add chunk to other chunks
        else
        {
        else
        {
+               // Add second and on to previous chunk
                cp->chprev = scode;
                scode->chnext = cp;
                scode->ch_size = ch_size;       // Save old chunk's globals
        }
 
        // Setup chunk and global vars
                cp->chprev = scode;
                scode->chnext = cp;
                scode->ch_size = ch_size;       // Save old chunk's globals
        }
 
        // Setup chunk and global vars
-       cp->chloc = sloc;
+/*
+So, whenever there's an ORG in a 56K section, it sets sloc TO THE ADDRESS IN THE ORG.  Also, the loc/sloc are incremented by 1s, which means to alias correctly to the byte-oriented memory model we have here, we have to fix that kind of crap.
+*/
+       cp->chloc = sloc; // <-- HERE'S THE PROBLEM FOR 56K  :-/
        cp->chnext = NULL;
        challoc = cp->challoc = amt;
        ch_size = cp->ch_size = 0;
        chptr = cp->chptr = ((uint8_t *)cp) + sizeof(CHUNK);
        scode = p->scode = cp;
 
        cp->chnext = NULL;
        challoc = cp->challoc = amt;
        ch_size = cp->ch_size = 0;
        chptr = cp->chptr = ((uint8_t *)cp) + sizeof(CHUNK);
        scode = p->scode = cp;
 
+       // A quick kludge
+/*
+OK, so this is a bit shite, but at least it gets things working the way they should.  The right way to do this is not rely on sloc & friends for the right fixup address but to have an accurate model of the thing.  That will probably come with v2.0.1  :-P
+
+So the problem is, d_org sets sloc to the address of the ORG statement, and that gives an incorrect base for the fixup.  And so when a second (or later) chunk is allocated, it gets set wrong.  Further complicating things is that the orgaddress *does not* get used in a typical way with the DSP56001 code, and, as such, causes incorrect addresses to be generated.  All that has to be dealt with in order to get this right and do away with this kludge.
+*/
+       if (((cursect == M56001P) || (cursect == M56001X) || (cursect == M56001Y)) && !first)
+               cp->chloc = cp->chprev->chloc + cp->chprev->ch_size;
+
        return;
 }
 
        return;
 }
 
@@ -276,7 +290,7 @@ int AddFixup(uint32_t attr, uint32_t loc, TOKEN * fexpr)
        {
                attr |= FU_56001;
                // Save the exact spot in this chunk where the fixup should go
        {
                attr |= FU_56001;
                // Save the exact spot in this chunk where the fixup should go
-               _orgaddr = chptr - scode->chptr;
+               _orgaddr = chptr - scode->chptr + scode->chloc;
        }
 
        // Allocate space for the fixup + any expression
        }
 
        // Allocate space for the fixup + any expression
@@ -398,6 +412,7 @@ int ResolveFixups(int sno)
                // Complex expression
                if (dw & FU_EXPR)
                {
                // Complex expression
                if (dw & FU_EXPR)
                {
+                       // evexpr presumably issues the errors/warnings here
                        if (evexpr(fup->expr, &eval, &eattr, &esym) != OK)
                                continue;
                }
                        if (evexpr(fup->expr, &eval, &eattr, &esym) != OK)
                                continue;
                }
@@ -415,6 +430,8 @@ int ResolveFixups(int sno)
                        // If the symbol is not defined, but global, set esym to sy
                        if ((eattr & (GLOBAL | DEFINED)) == GLOBAL)
                                esym = sy;
                        // If the symbol is not defined, but global, set esym to sy
                        if ((eattr & (GLOBAL | DEFINED)) == GLOBAL)
                                esym = sy;
+
+                       DEBUG { printf("               name: %s, value: $%" PRIX64 "\n", sy->sname, sy->svalue); }
                }
 
                uint16_t tdb = eattr & TDB;
                }
 
                uint16_t tdb = eattr & TDB;