Tighten up ea parsing for 020+ ea modes: PC relative 020+ modes are not allowed in...
authorggn <ggn.dbug@gmail.com>
Sat, 18 Jul 2020 15:15:43 +0000 (18:15 +0300)
committerShamus Hammons <jlhamm@acm.org>
Mon, 3 Aug 2020 16:42:36 +0000 (11:42 -0500)
amode.h
parmode.h

diff --git a/amode.h b/amode.h
index 997307f9582205454eafc16efb580a2bb0d7c5b8..48d39540fa36701a7b118117af6c9758f290038e 100644 (file)
--- a/amode.h
+++ b/amode.h
@@ -77,7 +77,7 @@
 #define C_CTRL       0x000007E4L
 #define C_ALT        0x000001FFL
 #define C_ALL030     0x0003FFFFL
 #define C_CTRL       0x000007E4L
 #define C_ALT        0x000001FFL
 #define C_ALL030     0x0003FFFFL
-#define C_ALT030     0x0003F1FFL
+#define C_ALT030     0x000071FDL
 #define C_FPU030     0x0003FFECL    /* (An), #<data>, (An)+, (d16,An), (d16,PC), (d8, An, Xn), (d8, PC, Xn), (bd, An, Xn), An(bd, PC, Xn), ([bd, An, Xn], od), An([bd, PC, Xn], od), ([bd, An], Xn, od), An([bd, PC], Xn, od) */
 #define C_CTRL030    0x0003F7E4L
 #define C_DATA030    0x0003FFFDL
 #define C_FPU030     0x0003FFECL    /* (An), #<data>, (An)+, (d16,An), (d16,PC), (d8, An, Xn), (d8, PC, Xn), (bd, An, Xn), An(bd, PC, Xn), ([bd, An, Xn], od), An([bd, PC, Xn], od), ([bd, An], Xn, od), An([bd, PC], Xn, od) */
 #define C_CTRL030    0x0003F7E4L
 #define C_DATA030    0x0003FFFDL
index 549f131ea42630df7869042f42bcb3fbd72f8df8..3cefbca164e728125e5deccd27aadcd3ba5875fd 100644 (file)
--- a/parmode.h
+++ b/parmode.h
@@ -55,6 +55,7 @@
        // ([bd,PC,Xn[.siz][*scale]],od)
        else if (*tok == '(')
        {
        // ([bd,PC,Xn[.siz][*scale]],od)
        else if (*tok == '(')
        {
+               int ea_PC = 0;                          // Flag that let us know if we have PC or An relative ea
                tok++;
 
                if ((*tok >= KW_A0) && (*tok <= KW_A7))
                tok++;
 
                if ((*tok >= KW_A0) && (*tok <= KW_A7))
@@ -364,15 +365,15 @@ AMn_IXN:                 // Handle any indexed (tok -> a comma)
 
                                if (*tok == ',')
                                        tok++;
 
                                if (*tok == ',')
                                        tok++;
-                               //else
-                               //      return error("Comma expected after base displacement");
                        }
 
                        }
 
-                       // Check for address register or PC, suppress base register
-                       // otherwise
+                       // Check for address register or PC, 
+                       // suppress base register otherwise
 
                        if (*tok == KW_PC)
                        {                                       // ([bd,PC,...
 
                        if (*tok == KW_PC)
                        {                                       // ([bd,PC,...
+                               ea_PC = 3;                              // Set flag in order to set proper value to AMn below when we can make a decision on ea
+                                                                               // (why "3"? Well, MEMPOST is 3 away from PCMPOST, etc. Have a look at amode.h)
                                AnREG = (7 << 3) | 3;   // PC is special case - stuff 011 to register field and 111 to the mode field
                                tok++;
                        }
                                AnREG = (7 << 3) | 3;   // PC is special case - stuff 011 to register field and 111 to the mode field
                                tok++;
                        }
@@ -488,7 +489,7 @@ AMn_IXN:                 // Handle any indexed (tok -> a comma)
                                {
                                        // Xn and od are non existent, get out of jail free card
                                        tok++;
                                {
                                        // Xn and od are non existent, get out of jail free card
                                        tok++;
-                                       AMn = MEMPRE;                   // ([bc,An,Xn],od) with no Xn and od
+                                       AMn = MEMPRE + ea_PC;                           // ([bc,An,Xn],od) with no Xn and od
                                        AnEXTEN |= EXT_IS | EXT_IISPREN;        // Suppress Xn and od
                                        goto AnOK;
                                }
                                        AnEXTEN |= EXT_IS | EXT_IISPREN;        // Suppress Xn and od
                                        goto AnOK;
                                }
@@ -592,7 +593,7 @@ AMn_IXN:                 // Handle any indexed (tok -> a comma)
                                if (*tok == ')')        // ([bd,An/PC],Xn)
                                {
                                        // od is non existent, get out of jail free card
                                if (*tok == ')')        // ([bd,An/PC],Xn)
                                {
                                        // od is non existent, get out of jail free card
-                                       AMn = MEMPOST;          // let's say it's ([bd,An],Xn,od) with od=0 then
+                                       AMn = MEMPOST + ea_PC;  // let's say it's ([bd,An],Xn,od) with od=0 then
                                        AnEXTEN |= EXT_IISPOSN; // No outer displacement
                                        tok++;
                                        goto AnOK;
                                        AnEXTEN |= EXT_IISPOSN; // No outer displacement
                                        tok++;
                                        goto AnOK;
@@ -609,20 +610,20 @@ CHECKODn:
                                if (CHECK_OPTS(OPT_020_DISP) && (AnEXATTR & DEFINED) && (AnEXVAL == 0))
                                {
                                        // od = 0 so optimise it out
                                if (CHECK_OPTS(OPT_020_DISP) && (AnEXATTR & DEFINED) && (AnEXVAL == 0))
                                {
                                        // od = 0 so optimise it out
-                                       AMn = MEMPOST          // let's say it's ([bd,An],Xn,od) with od=0 then
-                                       AnEXTEN |= EXT_IISPOSN; // No outer displacement
+                                       AMn = MEMPOST + ea_PC;          // let's say it's ([bd,An],Xn,od) with od=0 then
+                                       AnEXTEN |= EXT_IISPOSN;         // No outer displacement
                                        tok++;
                                        goto AnOK;
                                }
 
                                // ([bd,An/PC],Xn,od)
                                        tok++;
                                        goto AnOK;
                                }
 
                                // ([bd,An/PC],Xn,od)
-                                       // Is .W forced here?
+                               // Is .W forced here?
                                if (*tok == DOTW)
                                {
                                        tok++;
                                        // od[.W]
                                        AnEXTEN |= EXT_IISPOSW; // Word outer displacement
                                if (*tok == DOTW)
                                {
                                        tok++;
                                        // od[.W]
                                        AnEXTEN |= EXT_IISPOSW; // Word outer displacement
-                                       AMn = MEMPOST;
+                                       AMn = MEMPOST + ea_PC;
                                }
                                else
                                {
                                }
                                else
                                {
@@ -650,7 +651,7 @@ CHECKODn:
                                                AnBEXPR[i] = 'E';
                                        }
 
                                                AnBEXPR[i] = 'E';
                                        }
 
-                                       AMn = MEMPOST;
+                                       AMn = MEMPOST + ea_PC;
 
                                        // Defined, absolute values from $FFFF8000..$00007FFF get
                                        // optimized to absolute short
 
                                        // Defined, absolute values from $FFFF8000..$00007FFF get
                                        // optimized to absolute short
@@ -659,7 +660,7 @@ CHECKODn:
                                                && (((uint32_t)AnEXVAL + 0x8000) < 0x10000))
                                        {
                                                AnEXTEN |= EXT_IISPOSW; // Word outer displacement
                                                && (((uint32_t)AnEXVAL + 0x8000) < 0x10000))
                                        {
                                                AnEXTEN |= EXT_IISPOSW; // Word outer displacement
-                                               AMn = MEMPOST;
+                                               AMn = MEMPOST + ea_PC;
                                                if (optim_warn_flag)
                                                        warn("absolute value in outer displacement ranging $FFFF8000..$00007FFF optimised to absolute short");
                                        }
                                                if (optim_warn_flag)
                                                        warn("absolute value in outer displacement ranging $FFFF8000..$00007FFF optimised to absolute short");
                                        }
@@ -680,7 +681,7 @@ IS_SUPPRESSEDn:
                                if (*tok == ')')        // ([bd,An/PC],Xn)
                                {
                                        // od is non existent, get out of jail free card
                                if (*tok == ')')        // ([bd,An/PC],Xn)
                                {
                                        // od is non existent, get out of jail free card
-                                       AMn = MEMPOST;          // let's say it's ([bd,An],Xn,od) with od=0 then
+                                       AMn = MEMPOST + ea_PC;          // let's say it's ([bd,An],Xn,od) with od=0 then
                                        AnEXTEN |= EXT_IISNOIN; // No outer displacement
                                        tok++;
                                        goto AnOK;
                                        AnEXTEN |= EXT_IISNOIN; // No outer displacement
                                        tok++;
                                        goto AnOK;
@@ -698,7 +699,7 @@ IS_SUPPRESSEDn:
                                if (CHECK_OPTS(OPT_020_DISP) && (AnEXVAL == 0))
                                {
                                        // od=0 so optimise it out
                                if (CHECK_OPTS(OPT_020_DISP) && (AnEXVAL == 0))
                                {
                                        // od=0 so optimise it out
-                                       AMn = MEMPOST;           // let's say it's ([bd,An],Xn,od) with od=0 then
+                                       AMn = MEMPOST + ea_PC;           // let's say it's ([bd,An],Xn,od) with od=0 then
                                        AnEXTEN |= EXT_IISNOIN; // No outer displacement
                                        tok++;
                                        goto AnOK;
                                        AnEXTEN |= EXT_IISNOIN; // No outer displacement
                                        tok++;
                                        goto AnOK;
@@ -709,19 +710,19 @@ IS_SUPPRESSEDn:
                                {
                                        // expr.L
                                        tok++;
                                {
                                        // expr.L
                                        tok++;
-                                       AMn = MEMPOST;
+                                       AMn = MEMPOST + ea_PC;
                                        AnEXTEN |= EXT_IISNOIL; // Long outer displacement with IS suppressed
                                }
                                else
                                {
                                        // expr[.W][]
                                        AnEXTEN |= EXT_IISNOIW; // Word outer displacement with IS suppressed
                                        AnEXTEN |= EXT_IISNOIL; // Long outer displacement with IS suppressed
                                }
                                else
                                {
                                        // expr[.W][]
                                        AnEXTEN |= EXT_IISNOIW; // Word outer displacement with IS suppressed
-                                       AMn = MEMPRE;
+                                       AMn = MEMPRE + ea_PC;;
 
                                        if (*tok == DOTW)
                                        {
                                                //AnEXTEN|=EXT_IISNOIW; // Word outer displacement
 
                                        if (*tok == DOTW)
                                        {
                                                //AnEXTEN|=EXT_IISNOIW; // Word outer displacement
-                                               AMn = MEMPOST;
+                                               AMn = MEMPOST + ea_PC;
                                                tok++;
                                        }
                                        // Defined, absolute values from $FFFF8000..$00007FFF get
                                                tok++;
                                        }
                                        // Defined, absolute values from $FFFF8000..$00007FFF get
@@ -846,8 +847,7 @@ IS_SUPPRESSEDn:
                                if (*tok == ')')        // ([bd,An/PC,Xn]...
                                {
                                        // od is non existent, get out of jail free card
                                if (*tok == ')')        // ([bd,An/PC,Xn]...
                                {
                                        // od is non existent, get out of jail free card
-                                       //AnEXVAL=0;            // zero outer displacement
-                                       AMn = MEMPRE;                   // let's say it's ([bd,An,Xn],od) with od suppressed then
+                                       AMn = MEMPRE + ea_PC;                   // let's say it's ([bd,An,Xn],od) with od suppressed then
                                        AnEXTEN |= EXT_IISPREN; // No outer displacement
                                        tok++;
                                        goto AnOK;
                                        AnEXTEN |= EXT_IISPREN; // No outer displacement
                                        tok++;
                                        goto AnOK;
@@ -863,7 +863,7 @@ IS_SUPPRESSEDn:
                                        if (CHECK_OPTS(OPT_020_DISP) && (AnEXVAL == 0) && (AnEXATTR & DEFINED))
                                        {
                                                // od=0 so optimise it out
                                        if (CHECK_OPTS(OPT_020_DISP) && (AnEXVAL == 0) && (AnEXATTR & DEFINED))
                                        {
                                                // od=0 so optimise it out
-                                               AMn = MEMPRE;            // let's say it's ([bd,An],Xn,od) with od=0 then
+                                               AMn = MEMPRE + ea_PC;            // let's say it's ([bd,An],Xn,od) with od=0 then
                                                AnEXTEN |= EXT_IISPRE0; // No outer displacement
                                                tok++;
                                                goto AnOK;
                                                AnEXTEN |= EXT_IISPRE0; // No outer displacement
                                                tok++;
                                                goto AnOK;
@@ -874,14 +874,14 @@ IS_SUPPRESSEDn:
                                if (*tok == DOTL)
                                {
                                        // expr.L
                                if (*tok == DOTL)
                                {
                                        // expr.L
-                                       AMn = MEMPRE;
+                                       AMn = MEMPRE + ea_PC;
                                        tok++;
                                        AnEXTEN |= EXT_IISPREL;
                                }
                                else
                                {
                                        // expr.[W]
                                        tok++;
                                        AnEXTEN |= EXT_IISPREL;
                                }
                                else
                                {
                                        // expr.[W]
-                                       AMn = MEMPRE;
+                                       AMn = MEMPRE + ea_PC;
                                        int expr_size = EXT_IISPREW; // Assume we have a .w value
 
                                        if ((AnEXVAL + 0x8000) > 0x10000)
                                        int expr_size = EXT_IISPREW; // Assume we have a .w value
 
                                        if ((AnEXVAL + 0x8000) > 0x10000)
@@ -972,7 +972,6 @@ IS_SUPPRESSEDn:
                                                // Our expression is techically a base displacement,
                                                // so let's copy it to the relevant variables so
                                                // eagen0.c can pick it up properly
                                                // Our expression is techically a base displacement,
                                                // so let's copy it to the relevant variables so
                                                // eagen0.c can pick it up properly
-                                               //AnBEXPR = AnEXPR;
                                                AnBEXVAL = AnEXVAL;
                                                AnBEXATTR = AnEXATTR;
 
                                                AnBEXVAL = AnEXVAL;
                                                AnBEXATTR = AnEXATTR;
 
@@ -999,7 +998,7 @@ IS_SUPPRESSEDn:
                                                                }
                                                        }
                                                        // Check for scale
                                                                }
                                                        }
                                                        // Check for scale
-                                                       if (*tok == '*')                // ([bd,An/PC],Xn*...)
+                                                       if (*tok == '*')                // (d16,An,Dn[.size][*scale])
                                                        {                                               // scale: *1, *2, *4, *8
                                                                tok++;
 
                                                        {                                               // scale: *1, *2, *4, *8
                                                                tok++;