From a5527a0117ae89e393958eb2ad2753fa4676baf9 Mon Sep 17 00:00:00 2001 From: Shamus Hammons Date: Sat, 10 Feb 2018 08:30:54 -0600 Subject: [PATCH] Fix for D_foo() macros. 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 | 18 ++++++------- sect.h | 76 +++++++++++++++++++++++-------------------------------- version.h | 2 +- 3 files changed, 42 insertions(+), 54 deletions(-) diff --git a/sect.c b/sect.c index f4ce788..95f9747 100644 --- 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 -// 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. // -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) - return 0; + return; - if (!amt) + if (amt == 0) 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) - return 0; + return; if (amt < CH_CODE_SIZE) amt = CH_CODE_SIZE; @@ -216,7 +216,7 @@ int chcheck(uint32_t amt) { 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 @@ -227,7 +227,7 @@ int chcheck(uint32_t amt) chptr = cp->chptr = ((uint8_t *)cp) + sizeof(CHUNK); scode = p->scode = cp; - return 0; + return; } diff --git a/sect.h b/sect.h index b3f6e0f..58c81ec 100644 --- a/sect.h +++ b/sect.h @@ -12,51 +12,52 @@ #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); \ - *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. -#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). -#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 -#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 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) @@ -64,20 +65,7 @@ #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 @@ -193,7 +181,7 @@ void InitSection(void); 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); diff --git a/version.h b/version.h index d95ff7e..1e9bc96 100644 --- a/version.h +++ b/version.h @@ -15,7 +15,7 @@ #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__ -- 2.37.2