]> Shamusworld >> Repos - rmac/blobdiff - amode.c
Added floating point support to expression evaluator, introduced FLOAT token, fixup...
[rmac] / amode.c
diff --git a/amode.c b/amode.c
index 511e168610c74bdd36c02b7e5209ca58393142ee..73f2bdaa15f19cdf0b671481eb69f59b8b939d52 100644 (file)
--- a/amode.c
+++ b/amode.c
 #define DEF_MN
 #include "mntab.h"
 
+extern char unsupport[];
 
 // Address-mode information
 int nmodes;                                    // Number of addr'ing modes found
 int am0;                                       // Addressing mode
 int a0reg;                                     // Register
 TOKEN a0expr[EXPRSIZE];                // Expression
-VALUE a0exval;                         // Expression's value
+uint64_t a0exval;                      // Expression's value
 WORD a0exattr;                         // Expression's attribute
 int a0ixreg;                           // Index register
 int a0ixsiz;                           // Index register size (and scale)
 TOKEN a0oexpr[EXPRSIZE];       // Outer displacement expression
-VALUE a0oexval;                                // Outer displacement value
+uint64_t a0oexval;                     // Outer displacement value
 WORD a0oexattr;                                // Outer displacement attribute
 SYM * a0esym;                          // External symbol involved in expr
 TOKEN a0bexpr[EXPRSIZE];       // Base displacement expression
-VALUE a0bexval;                                // Base displacement value
+uint64_t a0bexval;                     // Base displacement value
 WORD a0bexattr;                                // Base displacement attribute
 WORD a0bsize;                          // Base displacement size
 WORD a0extension;                      // 020+ extension address word
@@ -44,28 +45,30 @@ WORD am0_030;                               // ea bits for 020+ addressing modes
 int am1;                                       // Addressing mode
 int a1reg;                                     // Register
 TOKEN a1expr[EXPRSIZE];                // Expression
-VALUE a1exval;                         // Expression's value
+uint64_t a1exval;                      // Expression's value
 WORD a1exattr;                         // Expression's attribute
 int a1ixreg;                           // Index register
 int a1ixsiz;                           // Index register size (and scale)
 TOKEN a1oexpr[EXPRSIZE];       // Outer displacement expression
-VALUE a1oexval;                                // Outer displacement value
+uint64_t a1oexval;                     // Outer displacement value
 WORD a1oexattr;                                // Outer displacement attribute
 SYM * a1esym;                          // External symbol involved in expr
 TOKEN a1bexpr[EXPRSIZE];       // Base displacement expression
-VALUE a1bexval;                                // Base displacement value
+uint64_t a1bexval;                     // Base displacement value
 WORD a1bexattr;                                // Base displacement attribute
 WORD a1bsize;                          // Base displacement size
 WORD a1extension;                      // 020+ extension address word
 WORD am1_030;                          // ea bits for 020+ addressing modes
 
 int a2reg;                                     // Register for div.l (68020+)
-WORD mulmode;                          // To distinguish between 32 and 64 bit multiplications (68020+)
+WORD mulmode;                          // to distinguish between 32 and 64 bit multiplications (68020+)
 
-int bfparam1;                          // bfxxx instruction parameter 1
-int bfparam2;                          // bfxxx instruction parameter 2
+int bfparam1;                          // bfxxx / fmove instruction parameter 1
+int bfparam2;                          // bfxxx / fmove instruction parameter 2
+int bfval1;                                    //bfxxx / fmove value 1
+int bfval2;                                    //bfxxx / fmove value 2
 TOKEN bf0expr[EXPRSIZE];       // Expression
-VALUE bf0exval;                                // Expression's value
+uint64_t bf0exval;                     // Expression's value
 WORD bf0exattr;                                // Expression's attribute
 SYM * bf0esym;                         // External symbol involved in expr
 
@@ -85,7 +88,8 @@ int amode(int acount)
        a0exattr = a0oexattr = a1exattr = a1oexattr = 0;
        a0esym = a1esym = NULL;
        a0bexpr[0] = a1bexpr[0] = ENDEXPR;
-       a0bexval = a0bsize = a0extension = a1bexval = a1bsize = a1extension = 0;
+       a0bexval = a1bexval = 0;
+       a0bsize = a0extension = a1bsize = a1extension = 0;
        am0_030 = am1_030 = 0;
        bfparam1 = bfparam2 = 0;
        bf0expr[0] = ENDEXPR;
@@ -128,8 +132,9 @@ int amode(int acount)
 
        // it's a bitfield instruction--check the parameters inside the {} block
        // for validity
-       if ((*tok == '{') && (check030bf() == ERROR))
-               return ERROR;
+       if (*tok == '{')
+               if (check030bf() == ERROR)
+                       return ERROR;
 
        if ((acount == 0) || (*tok != ','))
                return 1;
@@ -165,7 +170,8 @@ int amode(int acount)
 
        // It's a bitfield instruction--check the parameters inside the {} block
        // for validity
-       if ((*tok == '{') && (check030bf() == ERROR))
+       if (*tok == '{')
+        if (check030bf() == ERROR)
                return ERROR;
 
        // At this point, it is legal for 020+ to have a ':'. For example divu.l
@@ -304,6 +310,8 @@ int fpu_reglist_left(WORD * a_rmask)
                else
                        cnt = 0;
 
+               r = 0;
+
                while (cnt-- >= 0)
                        rmask |= msktab_minus[r++];
 
@@ -376,23 +384,17 @@ int fpu_reglist_right(WORD * a_rmask)
 //
 int check030bf(void)
 {
-       WARNING(Add more strict checks as well as checks for non defined (yet) labels)
-
-       if ((activecpu & (CPU_68020 | CPU_68030 | CPU_68040)) == 0)
-               return error(unsupport);
-
+       CHECK00;
        tok++;
 
        if (*tok == CONST)
        {
                tok++;
-               bfparam1 = *(int *)tok;
-
-               if ((bfparam1 > 31) || (bfparam1 < 0))
-                       return error("bfxxx offset: immediate value must be between 0 and 31");
+               bfval1 = (int)*(uint64_t *)tok;
 
                // Do=0, offset=immediate - shift it to place
-               bfparam1 = (bfparam1 << 6) | (0 << 11);
+               bfparam1 = (0 << 11);
+               tok++;
                tok++;
        }
        else if (*tok == SYMBOL)
@@ -400,18 +402,19 @@ int check030bf(void)
                if (expr(bf0expr, &bf0exval, &bf0exattr, &bf0esym) != OK)
                        return ERROR;
 
-               bfparam1 = bf0exval;
+               if (!(bf0exattr & DEFINED))
+                       return error("bfxxx offset: immediate value must evaluate");
 
-               if ((bfparam1 > 31) || (bfparam1 < 0))
-                       return error("bfxxx offset: immediate value must be between 0 and 31");
+               bfval1 = (int)bf0exval;
 
                // Do=0, offset=immediate - shift it to place
-               bfparam1 = (bfparam1 << 6) | (0 << 11);
+               bfparam1 = (0 << 11);
        }
        else if ((*tok >= KW_D0) && (*tok <= KW_D7))
        {
                // Do=1, offset=data register - shift it to place
-               bfparam1 = ((*(int *)tok - 128) << 6) | (1 << 11);
+               bfparam1 = (1 << 11);
+               bfval1 = (*(int *)tok - 128);
                tok++;
        }
        else
@@ -430,32 +433,31 @@ int check030bf(void)
        if (*tok == CONST)
        {
                tok++;
-               bfparam2 = *(int *)tok;
-
-               if (bfparam2 > 31 || bfparam2 < 0)
-                       return error("bfxxx width: immediate value must be between 0 and 31");
+               bfval2 = (int)*(uint64_t *)tok;
 
                // Do=0, offset=immediate - shift it to place
-               bfparam2 = (bfparam2 << 0) | (0 << 5);
+               bfparam2 = (0 << 5);
                tok++;
+        tok++;
        }
        else if (*tok == SYMBOL)
        {
                if (expr(bf0expr, &bf0exval, &bf0exattr, &bf0esym) != OK)
                        return ERROR;
 
-               bfparam2 = bf0exval;
+               bfval2 = (int)bf0exval;
 
-               if (bfparam2 > 31 || bfparam2 < 0)
-                       return error("bfxxx width: immediate value must be between 0 and 31");
+               if (!(bf0exattr & DEFINED))
+                       return error("bfxxx width: immediate value must evaluate");
 
                // Do=0, offset=immediate - shift it to place
-               bfparam2 = (bfparam2 << 0) | (0 << 5);
+               bfparam2 = (0 << 5);
        }
        else if ((*tok >= KW_D0) && (*tok <= KW_D7))
        {
                // Do=1, offset=data register - shift it to place
-               bfparam2 = ((*(int *)tok - 128) << 0) | (1 << 5);
+               bfval2 = ((*(int *)tok - 128));
+               bfparam2 = (1 << 5);
                tok++;
        }
        else