]> Shamusworld >> Repos - rmac/commitdiff
Fix silly mask bugs, added check for use of undefined register equates.
authorShamus Hammons <jlhamm@acm.org>
Sat, 2 Mar 2013 20:22:33 +0000 (14:22 -0600)
committerShamus Hammons <jlhamm@acm.org>
Sat, 2 Mar 2013 20:22:33 +0000 (14:22 -0600)
15 files changed:
direct.c
eagen.c
expr.c
mach.c
makefile
mark.c
object.c
procln.c
riscasm.c [moved from risca.c with 98% similarity]
riscasm.h [moved from risca.h with 100% similarity]
rmac.c
sect.c
symbol.c
token.h
version.h

index 100db425f7afe7bad4fad3a0e5e64603fcfbb587..1d77c1c7b441e797b3a022ebf41209e7ea9315bc 100644 (file)
--- a/direct.c
+++ b/direct.c
@@ -8,7 +8,7 @@
 
 #include "direct.h"
 #include "sect.h"
 
 #include "direct.h"
 #include "sect.h"
-#include "risca.h"
+#include "riscasm.h"
 #include "error.h"
 #include "token.h"
 #include "procln.h"
 #include "error.h"
 #include "token.h"
 #include "procln.h"
@@ -26,60 +26,60 @@ SYM * symbolPtr[1000000];   // Symbol pointers table
 
 // Directive handler table
 int (*dirtab[])() = {
 
 // Directive handler table
 int (*dirtab[])() = {
-   d_org,                              // 0 org
-   d_even,                             // 1 even
-   d_unimpl,                   // 2 .6502
-   d_68000,                            // 3 .68000 
-   d_bss,                              // 4 bss
-   d_data,                             // 5 data 
-   d_text,                             // 6 text 
-   d_abs,                              // 7 abs 
-   d_comm,                             // 8 comm 
-   d_init,                             // 9 init 
-   d_cargs,                            // 10 cargs 
-   d_goto,                             // 11 goto 
-   d_dc,                               // 12 dc 
-   d_ds,                               // 13 ds 
-   d_undmac,                   // 14 undefmac 
-   d_gpu,                              // 15 .gpu
-   d_dsp,                              // 16 .dsp
-   d_dcb,                              // 17 dcb 
-   d_unimpl,                   // 18* set 
-   d_unimpl,                   // 19* reg 
-   d_unimpl,                   // 20 dump 
-   d_incbin,                   // 21 .incbin //load 
-   d_unimpl,                   // 22 disable 
-   d_unimpl,                   // 23 enable 
-   d_globl,                            // 24 globl 
-   d_regbank0,                 // 25 .regbank0
-   d_regbank1,                 // 26 .regbank1
-   d_unimpl,                   // 27 xdef 
-   d_assert,                   // 28 assert 
-   d_unimpl,                   // 29* if 
-   d_unimpl,                   // 30* endif 
-   d_unimpl,                   // 31* endc 
-   d_unimpl,                   // 32* iif 
-   d_include,                  // 33 include 
-   fpop,                               // 34 end 
-   d_unimpl,                   // 35* macro 
-   ExitMacro,                  // 36* exitm 
-   d_unimpl,                   // 37* endm 
-   d_list,                             // 38 list 
-   d_nlist,                            // 39 nlist 
-   d_long,                             // 40* rept 
-   d_phrase,                   // 41* endr 
-   d_dphrase,                  // 42 struct 
-   d_qphrase,                  // 43 ends 
-   d_title,                            // 44 title 
-   d_subttl,                   // 45 subttl 
-   eject,                              // 46 eject 
-   d_unimpl,                   // 47 error 
-   d_unimpl,                   // 48 warn 
-   d_noclear,                  // 49 .noclear
-   d_equrundef,                        // 50 .equrundef/.regundef
-   d_ccundef,                  // 51 .ccundef
-   d_print,                            // 52 .print
-   d_cstruct,                  // 53 .cstruct
+       d_org,                          // 0 org
+       d_even,                         // 1 even
+       d_unimpl,                       // 2 .6502
+       d_68000,                        // 3 .68000 
+       d_bss,                          // 4 bss
+       d_data,                         // 5 data 
+       d_text,                         // 6 text 
+       d_abs,                          // 7 abs 
+       d_comm,                         // 8 comm 
+       d_init,                         // 9 init 
+       d_cargs,                        // 10 cargs 
+       d_goto,                         // 11 goto 
+       d_dc,                           // 12 dc 
+       d_ds,                           // 13 ds 
+       d_undmac,                       // 14 undefmac 
+       d_gpu,                          // 15 .gpu
+       d_dsp,                          // 16 .dsp
+       d_dcb,                          // 17 dcb 
+       d_unimpl,                       // 18* set 
+       d_unimpl,                       // 19* reg 
+       d_unimpl,                       // 20 dump 
+       d_incbin,                       // 21 .incbin //load 
+       d_unimpl,                       // 22 disable 
+       d_unimpl,                       // 23 enable 
+       d_globl,                        // 24 globl 
+       d_regbank0,                     // 25 .regbank0
+       d_regbank1,                     // 26 .regbank1
+       d_unimpl,                       // 27 xdef 
+       d_assert,                       // 28 assert 
+       d_unimpl,                       // 29* if 
+       d_unimpl,                       // 30* endif 
+       d_unimpl,                       // 31* endc 
+       d_unimpl,                       // 32* iif 
+       d_include,                      // 33 include 
+       fpop,                           // 34 end 
+       d_unimpl,                       // 35* macro 
+       ExitMacro,                      // 36* exitm 
+       d_unimpl,                       // 37* endm 
+       d_list,                         // 38 list 
+       d_nlist,                        // 39 nlist 
+       d_long,                         // 40* rept 
+       d_phrase,                       // 41* endr 
+       d_dphrase,                      // 42 struct 
+       d_qphrase,                      // 43 ends 
+       d_title,                        // 44 title 
+       d_subttl,                       // 45 subttl 
+       eject,                          // 46 eject 
+       d_unimpl,                       // 47 error 
+       d_unimpl,                       // 48 warn 
+       d_noclear,                      // 49 .noclear
+       d_equrundef,            // 50 .equrundef/.regundef
+       d_ccundef,                      // 51 .ccundef
+       d_print,                        // 52 .print
+       d_cstruct,                      // 53 .cstruct
 };
 
 
 };
 
 
@@ -258,7 +258,7 @@ int d_equrundef(void)
 
        while (*tok != EOL)
        {
 
        while (*tok != EOL)
        {
-               // Skip preceeding or seperating commas
+               // Skip preceeding or seperating commas (if any)
                if (*tok == ',')
                        tok++;
 
                if (*tok == ',')
                        tok++;
 
@@ -316,31 +316,6 @@ int d_incbin(void)
                return ERROR;
        }
 
                return ERROR;
        }
 
-#if 0
-       if ((j = open(string[tok[1]],  _OPEN_INC)) >= 0)
-       {
-               size = lseek(j, 0L, SEEK_END);
-               chcheck(size);
-               pos = lseek(j, 0L, SEEK_SET);
-
-               DEBUG
-               {
-                       printf("INCBIN: File '%s' is %li bytes.\n", string[tok[1]], size);
-               }
-
-               for(i=0; i<size; i++)
-               {
-                       buf = '\0';
-                       bytes = read(j, &buf, 1);
-                       D_byte(buf);
-               }
-       }
-       else
-       {
-               errors("cannot open include binary file (%s)", string[tok[1]]);
-               return ERROR;
-       }
-#else
        if ((fd = open(string[tok[1]],  _OPEN_INC)) < 0)
        {
                errors("cannot open include binary file (%s)", string[tok[1]]);
        if ((fd = open(string[tok[1]],  _OPEN_INC)) < 0)
        {
                errors("cannot open include binary file (%s)", string[tok[1]]);
@@ -351,19 +326,8 @@ int d_incbin(void)
        pos = lseek(fd, 0L, SEEK_SET);
        chcheck(size);
 
        pos = lseek(fd, 0L, SEEK_SET);
        chcheck(size);
 
-       DEBUG
-       {
-               printf("INCBIN: File '%s' is %li bytes.\n", string[tok[1]], size);
-       }
+       DEBUG { printf("INCBIN: File '%s' is %li bytes.\n", string[tok[1]], size); }
 
 
-#if 0
-       for(i=0; i<size; i++)
-       {
-               buf = '\0';
-               bytes = read(j, &buf, 1);
-               D_byte(buf);
-       }
-#else
        char * fileBuffer = (char *)malloc(size);
        bytesRead = read(fd, fileBuffer, size);
 
        char * fileBuffer = (char *)malloc(size);
        bytesRead = read(fd, fileBuffer, size);
 
@@ -384,9 +348,6 @@ int d_incbin(void)
                orgaddr += size;
 
        free(fileBuffer);
                orgaddr += size;
 
        free(fileBuffer);
-#endif
-#endif
-
        close(fd);
        return 0;
 }
        close(fd);
        return 0;
 }
diff --git a/eagen.c b/eagen.c
index a45f4bd4af0a2609e724f81cacd528267124d9a7..f76e51e04170ac822b2f983e7cb6221bc21980b0 100644 (file)
--- a/eagen.c
+++ b/eagen.c
@@ -12,7 +12,7 @@
 #include "mark.h"
 #include "error.h"
 #include "mach.h"
 #include "mark.h"
 #include "error.h"
 #include "mach.h"
-#include "risca.h"
+#include "riscasm.h"
 
 #define eaNgen    ea0gen
 #define amN       am0
 
 #define eaNgen    ea0gen
 #define amN       am0
diff --git a/expr.c b/expr.c
index 23f6a14afcbb0c46561c101b6d0e43e382acbb56..e552c39e9becf0d853436565d7bc4d731f5730b1 100644 (file)
--- a/expr.c
+++ b/expr.c
@@ -12,7 +12,7 @@
 #include "listing.h"
 #include "mach.h"
 #include "procln.h"
 #include "listing.h"
 #include "mach.h"
 #include "procln.h"
-#include "risca.h"
+#include "riscasm.h"
 #include "sect.h"
 #include "symbol.h"
 #include "token.h"
 #include "sect.h"
 #include "symbol.h"
 #include "token.h"
@@ -337,7 +337,7 @@ int expr(TOKEN * otk, VALUE * a_value, WORD * a_attr, SYM ** a_esym)
        int j;
 
        tk = otk;                       // Set token pointer to 'exprbuf' (direct.c)
        int j;
 
        tk = otk;                       // Set token pointer to 'exprbuf' (direct.c)
-                                               // Also set in various other places too (risca.c, e.g.)
+                                               // Also set in various other places too (riscasm.c, e.g.)
 //     symbolNum = 0;          // Set symbol number in symbolPtr[] to 0
 
        // Optimize for single constant or single symbol.
 //     symbolNum = 0;          // Set symbol number in symbolPtr[] to 0
 
        // Optimize for single constant or single symbol.
@@ -386,15 +386,16 @@ int expr(TOKEN * otk, VALUE * a_value, WORD * a_attr, SYM ** a_esym)
                }
                else
                {
                }
                else
                {
-#if 0
-                       p = (char *)tok[1];
-#else
                        p = string[tok[1]];
                        p = string[tok[1]];
-#endif
+
+#if 0
                        j = 0;
 
                        if (*p == '.')
                                j = curenv;
                        j = 0;
 
                        if (*p == '.')
                                j = curenv;
+#else
+                       j = (*p == '.' ? curenv : 0);
+#endif
 
                        sy = lookup(p, LABEL, j);
 
 
                        sy = lookup(p, LABEL, j);
 
@@ -403,14 +404,22 @@ int expr(TOKEN * otk, VALUE * a_value, WORD * a_attr, SYM ** a_esym)
 
                        sy->sattr |= REFERENCED;
 
 
                        sy->sattr |= REFERENCED;
 
+                       // Check for undefined register equates
+                       if (sy->sattre & UNDEF_EQUR)
+                       {
+                               errors("undefined register equate '%s'", sy->sname);
+//if we return right away, it returns some spurious errors...
+//                             return ERROR;
+                       }
+
                        // Check register bank usage
                        if (sy->sattre & EQUATEDREG)
                        {
                                if ((regbank == BANK_0) && (sy->sattre & BANK_1) && !altbankok)   
                        // Check register bank usage
                        if (sy->sattre & EQUATEDREG)
                        {
                                if ((regbank == BANK_0) && (sy->sattre & BANK_1) && !altbankok)   
-                                       warns("equated symbol \'%s\' cannot be used in register bank 0", sy->sname);
+                                       warns("equated symbol '%s' cannot be used in register bank 0", sy->sname);
 
                                if ((regbank == BANK_1) && (sy->sattre & BANK_0) && !altbankok)
 
                                if ((regbank == BANK_1) && (sy->sattre & BANK_0) && !altbankok)
-                                       warns("equated symbol \'%s\' cannot be used in register bank 1", sy->sname);
+                                       warns("equated symbol '%s' cannot be used in register bank 1", sy->sname);
                        }
 
                        *tk++ = SYMBOL;
                        }
 
                        *tk++ = SYMBOL;
diff --git a/mach.c b/mach.c
index 47896a9fc79d87cf1761547b71b830a5f660e325..2220d0fd79d30f7a149b8afdb62eb232845c67ea 100644 (file)
--- a/mach.c
+++ b/mach.c
@@ -12,7 +12,7 @@
 #include "direct.h"
 #include "token.h"
 #include "procln.h"
 #include "direct.h"
 #include "token.h"
 #include "procln.h"
-#include "risca.h"
+#include "riscasm.h"
 
 #define DEF_KW
 #include "kwtab.h"
 
 #define DEF_KW
 #include "kwtab.h"
index 5e377d3fd4d6d77ad7d6d4d2ea08cfe2834061b8..8b46eed9cd6273ac53d3533d1ad275dfe0c5fbad 100644 (file)
--- a/makefile
+++ b/makefile
@@ -11,9 +11,9 @@ HOSTCC = gcc
 
 CFLAGS = -g -D__GCCUNIX__ -I. -O2
 
 
 CFLAGS = -g -D__GCCUNIX__ -I. -O2
 
-SRCS = amode.c debug.c direct.c eagen.c error.c expr.c listing.c mach.c macro.c mark.c object.c procln.c risca.c rmac.c sect.c symbol.c token.c 
+SRCS = amode.c debug.c direct.c eagen.c error.c expr.c listing.c mach.c macro.c mark.c object.c procln.c riscasm.c rmac.c sect.c symbol.c token.c 
 
 
-OBJS = amode.o debug.o direct.o eagen.o error.o expr.o listing.o mach.o macro.o mark.o object.o procln.o risca.o rmac.o sect.o symbol.o token.o
+OBJS = amode.o debug.o direct.o eagen.o error.o expr.o listing.o mach.o macro.o mark.o object.o procln.o riscasm.o rmac.o sect.o symbol.o token.o
 
 #
 # Build everything
 
 #
 # Build everything
diff --git a/mark.c b/mark.c
index 0ca98f0f033c2e8b6773a3dc3497b0b6507a6bf1..eacebf50a07c8318211285b78ba113df25082221 100644 (file)
--- a/mark.c
+++ b/mark.c
@@ -9,7 +9,7 @@
 #include "mark.h"
 #include "error.h"
 #include "object.h"
 #include "mark.h"
 #include "error.h"
 #include "object.h"
-#include "risca.h"
+#include "riscasm.h"
 
 
 MCHUNK * firstmch;             // First mark chunk
 
 
 MCHUNK * firstmch;             // First mark chunk
index c2b8d53c9910de64d581de05b27ec02d4f822e71..4f9309af0299f5a4f4417d8ec0164d082b244498 100644 (file)
--- a/object.c
+++ b/object.c
@@ -11,7 +11,7 @@
 #include "symbol.h"
 #include "mark.h"
 #include "error.h"
 #include "symbol.h"
 #include "mark.h"
 #include "error.h"
-#include "risca.h"
+#include "riscasm.h"
 
 LONG symsize = 0;                                                      // Size of BSD symbol table
 LONG strindx = 0x00000004;                                     // BSD string table index
 
 LONG symsize = 0;                                                      // Size of BSD symbol table
 LONG strindx = 0x00000004;                                     // BSD string table index
index ab9d53a0eefc98397348f71a3a55cfd7f7565608..4ab0f7d44fb720b9d13541f3f7b0676a61939e60 100644 (file)
--- a/procln.c
+++ b/procln.c
@@ -16,7 +16,7 @@
 #include "direct.h"
 #include "macro.h"
 #include "symbol.h"
 #include "direct.h"
 #include "macro.h"
 #include "symbol.h"
-#include "risca.h"
+#include "riscasm.h"
 
 #define DEF_KW                                 // Declare keyword values 
 #include "kwtab.h"                             // Incl generated keyword tables & defs
 
 #define DEF_KW                                 // Declare keyword values 
 #include "kwtab.h"                             // Incl generated keyword tables & defs
@@ -375,12 +375,14 @@ normal:
                {
                        if ((equtyp == EQUREG) && (sy->sattre & UNDEF_EQUR))
                        {
                {
                        if ((equtyp == EQUREG) && (sy->sattre & UNDEF_EQUR))
                        {
-                               sy->sattre |= ~UNDEF_EQUR; 
+//REALLY?                              sy->sattre |= ~UNDEF_EQUR; 
+                               sy->sattre &= ~UNDEF_EQUR; 
                                sy->svalue  = 0;
                        }
                        else if ((equtyp == CCDEF) && (sy->sattre & UNDEF_CC))
                        {
                                sy->svalue  = 0;
                        }
                        else if ((equtyp == CCDEF) && (sy->sattre & UNDEF_CC))
                        {
-                               sy->sattre |= ~UNDEF_CC;
+//REALLY?                              sy->sattre |= ~UNDEF_CC;
+                               sy->sattre &= ~UNDEF_CC;
                                sy->svalue = 0;
                        }
                        else
                                sy->svalue = 0;
                        }
                        else
similarity index 98%
rename from risca.c
rename to riscasm.c
index 472e4f1e3d1da6b068b0f55959c01bebb53a6b60..fbc8f81cf605ff2a14178c7754b9c64bac94718b 100644 (file)
--- a/risca.c
+++ b/riscasm.c
@@ -6,7 +6,7 @@
 // Source Utilised with the Kind Permission of Landon Dyer
 //
 
 // Source Utilised with the Kind Permission of Landon Dyer
 //
 
-#include "risca.h"
+#include "riscasm.h"
 #include "error.h"
 #include "sect.h"
 #include "token.h"
 #include "error.h"
 #include "sect.h"
 #include "token.h"
@@ -171,6 +171,15 @@ int GetRegister(WORD rattr)
        if ((challoc - ch_size) < 4)
                chcheck(4L);
 
        if ((challoc - ch_size) < 4)
                chcheck(4L);
 
+       // See if this symbol has been defined, then undefined:
+//does nothing
+//segfaults now (esym == NULL?)
+/*     if (esym->sattre & UNDEF_EQUR)
+       {
+               error("undefined register");
+               return ERROR;
+       }*/
+
        if (!(eattr & DEFINED))
        {
                fixup((WORD)(FU_WORD | rattr), sloc, r_expr);      
        if (!(eattr & DEFINED))
        {
                fixup((WORD)(FU_WORD | rattr), sloc, r_expr);      
similarity index 100%
rename from risca.h
rename to riscasm.h
diff --git a/rmac.c b/rmac.c
index 8dde4c6d9a34925a534de81a25cd2c7fb8b8b8b4..02bdcfd6e90c9ef6b52b73dd45073e611759ec44 100644 (file)
--- a/rmac.c
+++ b/rmac.c
@@ -15,7 +15,7 @@
 #include "sect.h"
 #include "mark.h"
 #include "macro.h"
 #include "sect.h"
 #include "mark.h"
 #include "macro.h"
-#include "risca.h"
+#include "riscasm.h"
 #include "direct.h"
 #include "version.h"
 #include "debug.h"
 #include "direct.h"
 #include "version.h"
 #include "debug.h"
diff --git a/sect.c b/sect.c
index 21591a0219146b127a7321dbd07dcea4cab0ba1f..b8d62407e12987f1acfab80e0abc8a43880126cb 100644 (file)
--- a/sect.c
+++ b/sect.c
@@ -13,7 +13,7 @@
 #include "listing.h"
 #include "mach.h"
 #include "mark.h"
 #include "listing.h"
 #include "mach.h"
 #include "mark.h"
-#include "risca.h"
+#include "riscasm.h"
 #include "symbol.h"
 #include "token.h"
 
 #include "symbol.h"
 #include "token.h"
 
index f10c55ad85b2a723425b1f6c479ee4baff32be20..f8d8424ff99de0886df08bd03cd459b85cf94d68 100644 (file)
--- a/symbol.c
+++ b/symbol.c
@@ -151,13 +151,14 @@ SYM * lookup(char * name, int type, int envno)
                if (symbol->stype == type                       // Type, envno and name must match
                        && symbol->senv  == envno
                        && *name == *symbol->sname              // Fast check for first character
                if (symbol->stype == type                       // Type, envno and name must match
                        && symbol->senv  == envno
                        && *name == *symbol->sname              // Fast check for first character
-                       && !strcmp(name, symbol->sname))
+                       && !strcmp(name, symbol->sname))        // More expensive check
                        break;
 
                symbol = symbol->snext;
        }
 
                        break;
 
                symbol = symbol->snext;
        }
 
-       return symbol;                                                  // Return NULL or matching symbol
+       // Return NULL or matching symbol
+       return symbol;
 }
 
 
 }
 
 
diff --git a/token.h b/token.h
index becd0747f9a6ba93e79566ef258025afad109feb..0109489f588cf0e409974b57f8faab6539672382 100644 (file)
--- a/token.h
+++ b/token.h
@@ -10,7 +10,6 @@
 #define __TOKEN_H__
 
 #include "rmac.h"
 #define __TOKEN_H__
 
 #include "rmac.h"
-//#include "risca.h"
 
 // Include Files and Macros
 #define SRC_IFILE       0                                      // Input source is IFILE
 
 // Include Files and Macros
 #define SRC_IFILE       0                                      // Input source is IFILE
index 0187394d2218df8f3ae77a61126db08898dda154..3017afc7b60a7dff90f936e1cb82c15c01c22fbd 100644 (file)
--- a/version.h
+++ b/version.h
@@ -13,6 +13,6 @@
 
 #define MAJOR   1                      // Major version number
 #define MINOR   2                      // Minor version number
 
 #define MAJOR   1                      // Major version number
 #define MINOR   2                      // Minor version number
-#define PATCH   2                      // Patch release number
+#define PATCH   3                      // Patch release number
 
 #endif // __VERSION_H__
 
 #endif // __VERSION_H__