]> Shamusworld >> Repos - rmac/blobdiff - sect.c
Fixed regression in RISC JR cc, <label> handling.
[rmac] / sect.c
diff --git a/sect.c b/sect.c
index 53ba02b85edd65aa786d444a82a985d7169014f2..f797300395474822bef6688f02c9fabfd8f9846a 100644 (file)
--- a/sect.c
+++ b/sect.c
 #include "symbol.h"
 #include "token.h"
 
+
 // Section descriptors
-SECT sect[NSECTS];                                             // All sections... 
-int cursect;                                                   // Current section number
+SECT sect[NSECTS];                             // All sections... 
+int cursect;                                   // Current section number
 
 // These are copied from the section descriptor, the current code chunk
 // descriptor and the current fixup chunk descriptor when a switch is made into
 // a section.  They are copied back to the descriptors when the section is left.
-WORD scattr;                                                   // Section attributes 
-LONG sloc;                                                             // Current loc in section 
+WORD scattr;                                   // Section attributes 
+LONG sloc;                                             // Current loc in section 
 
-CHUNK * scode;                                                 // Current (last) code chunk 
-LONG challoc;                                                  // # bytes alloc'd to code chunk 
-LONG ch_size;                                                  // # bytes used in code chunk 
-char * chptr;                                                  // Deposit point in code chunk buffer 
+CHUNK * scode;                                 // Current (last) code chunk 
+LONG challoc;                                  // # bytes alloc'd to code chunk 
+LONG ch_size;                                  // # bytes used in code chunk 
+char * chptr;                                  // Deposit point in code chunk buffer 
 
-CHUNK * sfix;                                                  // Current (last) fixup chunk
-LONG fchalloc;                                                 // # bytes alloc'd to fixup chunk
-LONG fchsize;                                                  // # bytes used in fixup chunk
-PTR fchptr;                                                            // Deposit point in fixup chunk buffer
+CHUNK * sfix;                                  // Current (last) fixup chunk
+LONG fchalloc;                                 // # bytes alloc'd to fixup chunk
+LONG fchsize;                                  // # bytes used in fixup chunk
+PTR fchptr;                                            // Deposit point in fixup chunk buffer
 
-unsigned fwdjump[MAXFWDJUMPS];                 // forward jump check table
-unsigned fwindex = 0;                                  // forward jump index
+unsigned fwdjump[MAXFWDJUMPS]; // forward jump check table
+unsigned fwindex = 0;                  // forward jump index
 
 // Return a size (SIZB, SIZW, SIZL) or 0, depending on what kind of fixup is
 // associated with a location.
 static char fusiztab[] = {
-   0,                                          // FU_QUICK
-   1,                                          // FU_BYTE
-   2,                                          // FU_WORD
-   2,                                          // FU_WBYTE
-   4,                                          // FU_LONG
-   1,                                          // FU_BBRA
-   0,                                          // (unused)
-   1,                                          // FU_6BRA
+   0,  // FU_QUICK
+   1,  // FU_BYTE
+   2,  // FU_WORD
+   2,  // FU_WBYTE
+   4,  // FU_LONG
+   1,  // FU_BBRA
+   0,  // (unused)
+   1,  // FU_6BRA
 };
 
 // Offset to REAL fixup location
 static char fusizoffs[] = {
-   0,                                          // FU_QUICK
-   0,                                          // FU_BYTE
-   0,                                          // FU_WORD
-   1,                                          // FU_WBYTE
-   0,                                          // FU_LONG
-   1,                                          // FU_BBRA
-   0,                                          // (unused)
-   0,                                          // FU_6BRA
+   0,  // FU_QUICK
+   0,  // FU_BYTE
+   0,  // FU_WORD
+   1,  // FU_WBYTE
+   0,  // FU_LONG
+   1,  // FU_BBRA
+   0,  // (unused)
+   0,  // FU_6BRA
 };
 
 
@@ -71,9 +72,7 @@ static char fusizoffs[] = {
 //
 void mksect(int sno, WORD attr)
 {
-       SECT * p;                                                 // Section pointer
-
-       p = &sect[sno];
+       SECT * p = &sect[sno];
        p->scattr = attr;
        p->sloc = 0;
        p->scode = p->sfcode = NULL;
@@ -125,13 +124,13 @@ void savsect(void)
 {
        SECT * p = &sect[cursect];
 
-       p->scattr = scattr;                                      // Bailout section vars
+       p->scattr = scattr;                                             // Bailout section vars
        p->sloc = sloc;
 
-       if (scode != NULL)                                        // Bailout code chunk
+       if (scode != NULL)                                              // Bailout code chunk
                scode->ch_size = ch_size;
 
-       if (sfix != NULL)                                         // Bailout fixup chunk
+       if (sfix != NULL)                                               // Bailout fixup chunk
                sfix->ch_size = fchsize;
 }
 
@@ -212,6 +211,7 @@ int fixtest(int sno, LONG loc)
 //
 int chcheck(LONG amt)
 {
+       DEBUG { printf("chcheck(%u)\n", amt); }
        // If in BSS section, no allocation required
        if (scattr & SBSS)
                return 0;
@@ -219,12 +219,14 @@ int chcheck(LONG amt)
        if (!amt)
                amt = CH_THRESHOLD;
 
+       DEBUG { printf("    challoc=%i, ch_size=%i, diff=%i\n", challoc, ch_size, challoc-ch_size); }
        if ((int)(challoc - ch_size) >= (int)amt) 
                return 0;
 
        if (amt < CH_CODE_SIZE)
                amt = CH_CODE_SIZE;
 
+       DEBUG { printf("    amt (adjusted)=%u\n", amt); }
        SECT * p = &sect[cursect];
        CHUNK * cp = malloc(sizeof(CHUNK) + amt);
 
@@ -279,7 +281,8 @@ int fixup(WORD attr, LONG loc, TOKEN * fexpr)
                if ((attr & 0x0F00) == FU_JR)
                {
 //                     i = 18;
-                       i = FIXUP_BASE_SIZE + (sizeof(LONG) * 2);
+//                     i = FIXUP_BASE_SIZE + (sizeof(LONG) * 2);
+                       i = FIXUP_BASE_SIZE + sizeof(SYM *) + sizeof(LONG);
                }
                else
                {
@@ -452,6 +455,10 @@ int ResolveFixups(int sno)
                        loc = *fup.lp++;
                        cfileno = *fup.wp++;
                        curlineno = (int)*fup.wp++;
+DEBUG { printf("ResolveFixups: cfileno=%u\n", cfileno); }
+                       // This is based on global vars cfileno, curfname :-P
+                       // This approach is kinda meh as well. I think we can do better than this.
+                       SetFilenameForErrorReporting();
 
                        esym = NULL;