]> Shamusworld >> Repos - rmac/commitdiff
Fix for D_foo() macros.
authorShamus Hammons <jlhamm@acm.org>
Sat, 10 Feb 2018 14:30:54 +0000 (08:30 -0600)
committerShamus Hammons <jlhamm@acm.org>
Sat, 10 Feb 2018 14:30:54 +0000 (08:30 -0600)
Seems that no bounds checking was been done for the majority of the
D_foo() macros; that has been fixed. Now at v1.12.1.

sect.c
sect.h
version.h

diff --git a/sect.c b/sect.c
index f4ce7889e1f6a65a6ee5b11f28d8e01488c803f7..95f9747f7d8d3d3a54556d4db242bf5925583e07 100644 (file)
--- a/sect.c
+++ b/sect.c
@@ -177,26 +177,26 @@ int fixtest(int sno, uint32_t loc)
 
 //
 // Check that there are at least 'amt' bytes left in the current chunk. If
 
 //
 // Check that there are at least 'amt' bytes left in the current chunk. If
-// there are not, allocate another chunk of at least 'amt' bytes (and probably
-// more).
+// there are not, allocate another chunk of at least CH_CODE_SIZE bytes or
+// 'amt', whichever is larger.
 //
 // If 'amt' is zero, ensure there are at least CH_THRESHOLD bytes, likewise.
 //
 //
 // If 'amt' is zero, ensure there are at least CH_THRESHOLD bytes, likewise.
 //
-int chcheck(uint32_t amt)
+void chcheck(uint32_t amt)
 {
        DEBUG { printf("chcheck(%u)\n", amt); }
 
        // If in BSS section, no allocation required
        if (scattr & SBSS)
 {
        DEBUG { printf("chcheck(%u)\n", amt); }
 
        // If in BSS section, no allocation required
        if (scattr & SBSS)
-               return 0;
+               return;
 
 
-       if (!amt)
+       if (amt == 0)
                amt = CH_THRESHOLD;
 
                amt = CH_THRESHOLD;
 
-       DEBUG { printf("    challoc=%i, ch_size=%i, diff=%i\n", challoc, ch_size, challoc-ch_size); }
+       DEBUG { printf("    challoc=%i, ch_size=%i, diff=%i\n", challoc, ch_size, challoc - ch_size); }
 
        if ((int)(challoc - ch_size) >= (int)amt)
 
        if ((int)(challoc - ch_size) >= (int)amt)
-               return 0;
+               return;
 
        if (amt < CH_CODE_SIZE)
                amt = CH_CODE_SIZE;
 
        if (amt < CH_CODE_SIZE)
                amt = CH_CODE_SIZE;
@@ -216,7 +216,7 @@ int chcheck(uint32_t amt)
        {
                cp->chprev = scode;
                scode->chnext = cp;
        {
                cp->chprev = scode;
                scode->chnext = cp;
-               scode->ch_size = ch_size;                       // Save old chunk's globals
+               scode->ch_size = ch_size;       // Save old chunk's globals
        }
 
        // Setup chunk and global vars
        }
 
        // Setup chunk and global vars
@@ -227,7 +227,7 @@ int chcheck(uint32_t amt)
        chptr = cp->chptr = ((uint8_t *)cp) + sizeof(CHUNK);
        scode = p->scode = cp;
 
        chptr = cp->chptr = ((uint8_t *)cp) + sizeof(CHUNK);
        scode = p->scode = cp;
 
-       return 0;
+       return;
 }
 
 
 }
 
 
diff --git a/sect.h b/sect.h
index b3f6e0f6bfdc04acfe87555e6e763e7d4f1dcf4d..58c81ec6be7e5b3164f9b87258609cebeeeb7bbe 100644 (file)
--- a/sect.h
+++ b/sect.h
 #include "rmac.h"
 
 // Macros to deposit code in the current section (in Big Endian)
 #include "rmac.h"
 
 // Macros to deposit code in the current section (in Big Endian)
-// D_rword deposits a "6502" format (low, high) word (01).
-#define D_byte(b)      {*chptr++=(uint8_t)(b); sloc++; ch_size++; \
-                                               if(orgactive) orgaddr++;}
+#define D_byte(b)      {chcheck(1);*chptr++=(uint8_t)(b); sloc++; ch_size++; \
+       if(orgactive) orgaddr++;}
 #define D_word(w)      {chcheck(2);*chptr++=(uint8_t)((w)>>8); \
 #define D_word(w)      {chcheck(2);*chptr++=(uint8_t)((w)>>8); \
-                                               *chptr++=(uint8_t)(w); \
-                                               sloc += 2; ch_size += 2; if(orgactive) orgaddr += 2;}
-#define D_long(lw)     {*chptr++=(uint8_t)((lw)>>24); \
-                                               *chptr++=(uint8_t)((lw)>>16);\
-                                               *chptr++=(uint8_t)((lw)>>8); \
-                                               *chptr++=(uint8_t)(lw); \
-                                               sloc += 4; ch_size += 4; if(orgactive) orgaddr += 4;}
-#define D_quad(qw)     {*chptr++=(uint8_t)((qw)>>56); \
-                                               *chptr++=(uint8_t)((qw)>>48);\
-                                               *chptr++=(uint8_t)((qw)>>40);\
-                                               *chptr++=(uint8_t)((qw)>>32);\
-                                               *chptr++=(uint8_t)((qw)>>24);\
-                                               *chptr++=(uint8_t)((qw)>>16);\
-                                               *chptr++=(uint8_t)((qw)>>8); \
-                                               *chptr++=(uint8_t)(qw); \
-                                               sloc += 8; ch_size += 8; if(orgactive) orgaddr += 8;}
-#define D_rword(w)     {*chptr++=(uint8_t)(w); *chptr++=(uint8_t)((w)>>8); \
-                                               sloc+=2; ch_size+=2;if(orgactive) orgaddr += 2;}
+       *chptr++=(uint8_t)(w); \
+       sloc += 2; ch_size += 2; if(orgactive) orgaddr += 2;}
+#define D_long(lw)     {chcheck(4);*chptr++=(uint8_t)((lw)>>24); \
+       *chptr++=(uint8_t)((lw)>>16);\
+       *chptr++=(uint8_t)((lw)>>8); \
+       *chptr++=(uint8_t)(lw); \
+       sloc += 4; ch_size += 4; if(orgactive) orgaddr += 4;}
+#define D_quad(qw)     {chcheck(8);*chptr++=(uint8_t)((qw)>>56); \
+       *chptr++=(uint8_t)((qw)>>48);\
+       *chptr++=(uint8_t)((qw)>>40);\
+       *chptr++=(uint8_t)((qw)>>32);\
+       *chptr++=(uint8_t)((qw)>>24);\
+       *chptr++=(uint8_t)((qw)>>16);\
+       *chptr++=(uint8_t)((qw)>>8); \
+       *chptr++=(uint8_t)(qw); \
+       sloc += 8; ch_size += 8; if(orgactive) orgaddr += 8;}
+
+// D_rword deposits a "6502" format (low, high) word (01).
+#define D_rword(w)     {chcheck(2);*chptr++=(uint8_t)(w); \
+       *chptr++=(uint8_t)((w)>>8); \
+       sloc+=2; ch_size+=2;if(orgactive) orgaddr += 2;}
 
 // Macro for the 56001. Word size on this device is 24 bits wide. I hope that
 // orgaddr += 1 means that the addresses in the device reflect this.
 
 // Macro for the 56001. Word size on this device is 24 bits wide. I hope that
 // orgaddr += 1 means that the addresses in the device reflect this.
-#define D_dsp(w)    {chcheck(3);*chptr++=(uint8_t)(w>>16); \
+#define D_dsp(w)       {chcheck(3);*chptr++=(uint8_t)(w>>16); \
        *chptr++=(uint8_t)(w>>8); *chptr++=(uint8_t)w; \
        sloc+=1; ch_size += 3; if(orgactive) orgaddr += 1; \
        dsp_written_data_in_current_org=1;}
 
 // This macro expects to get an array of uint8_ts with the hi bits in a[0] and
 // the low bits in a[11] (Big Endian).
        *chptr++=(uint8_t)(w>>8); *chptr++=(uint8_t)w; \
        sloc+=1; ch_size += 3; if(orgactive) orgaddr += 1; \
        dsp_written_data_in_current_org=1;}
 
 // This macro expects to get an array of uint8_ts with the hi bits in a[0] and
 // the low bits in a[11] (Big Endian).
-#define D_extend(a) {memcpy(chptr, a, 12); chptr+=12; sloc+=12, ch_size+=12;\
-                                       if (orgactive) orgaddr+=12;}
+#define D_extend(a)    {chcheck(12); memcpy(chptr, a, 12); chptr+=12; sloc+=12, \
+       ch_size+=12; if (orgactive) orgaddr+=12;}
 
 // Fill n bytes with zeroes
 
 // Fill n bytes with zeroes
-#define D_ZEROFILL(n)  {memset(chptr, 0, n); chptr+=n; sloc+=n; ch_size+=n;\
-                                               if (orgactive) orgaddr+=n;}
+#define D_ZEROFILL(n)  {chcheck(n); memset(chptr, 0, n); chptr+=n; sloc+=n; \
+       ch_size+=n; if (orgactive) orgaddr+=n;}
 
 #define NSECTS       16                        // Max. number of sections
 
 // Tunable (storage) definitions
 
 #define NSECTS       16                        // Max. number of sections
 
 // Tunable (storage) definitions
-#define CH_THRESHOLD    64             // Minimum amount of space in code chunk
-#define CH_CODE_SIZE    2048   // Code chunk normal allocation
-#define CH_FIXUP_SIZE   1024   // Fixup chunk normal allocation
+#define CH_THRESHOLD    32             // Minimum amount of space in code chunk
+#define CH_CODE_SIZE    4096   // Code chunk normal allocation (4K)
 
 // Section attributes (.scattr)
 #define SUSED        0x8000            // Section is used (really, valid)
 
 // Section attributes (.scattr)
 #define SUSED        0x8000            // Section is used (really, valid)
 #define SABS         0x2000            // Section is absolute
 #define SPIC         0x1000            // Section is position-independent code
 
 #define SABS         0x2000            // Section is absolute
 #define SPIC         0x1000            // Section is position-independent code
 
-// N.B.: THIS IS NO LONGER TRUE
-// Fixup record a WORD of these bits, followed by a loc and then a pointer
-// to a symbol or an ENDEXPR-terminated postfix expression.
-//
-// SYMBOL              EXPRESSION
-// ------              ----------
-// ~FU_EXPR    FU_EXPR     fixup type
-// loc.L       loc.L       location in section
-// fileno.W    fileno.W    file number fixup occurred in
-// lineno.W    lineno.W    line number fixup occurred in
-// symbol.L    size.W      &symbol  /  size of expression
-// token.L     expression list
-// (etc)
-// ENDEXPR.L   (end of expression)
+// FIXUP attributes
 #define FUMASK       0x000F            // Mask for fixup cases:
 #define FU_QUICK     0x0000            // Fixup 3-bit quick instruction field
 #define FU_BYTE      0x0001            // Fixup byte
 #define FUMASK       0x000F            // Mask for fixup cases:
 #define FU_QUICK     0x0000            // Fixup 3-bit quick instruction field
 #define FU_BYTE      0x0001            // Fixup byte
@@ -193,7 +181,7 @@ void InitSection(void);
 void SwitchSection(int);
 void SaveSection(void);
 int fixtest(int, uint32_t);
 void SwitchSection(int);
 void SaveSection(void);
 int fixtest(int, uint32_t);
-int chcheck(uint32_t);
+void chcheck(uint32_t);
 int AddFixup(uint32_t, uint32_t, TOKEN *);
 int ResolveAllFixups(void);
 
 int AddFixup(uint32_t, uint32_t, TOKEN *);
 int ResolveAllFixups(void);
 
index d95ff7eaf5c81cf10496e5f44f04f645b5c6db33..1e9bc9604181d63a62bd56e2e03845e9c4511866 100644 (file)
--- a/version.h
+++ b/version.h
@@ -15,7 +15,7 @@
 
 #define MAJOR   1              // Major version number
 #define MINOR   12             // Minor version number
 
 #define MAJOR   1              // Major version number
 #define MINOR   12             // Minor version number
-#define PATCH   0              // Patch release number
+#define PATCH   1              // Patch release number
 
 #endif // __VERSION_H__
 
 
 #endif // __VERSION_H__