]> Shamusworld >> Repos - rmac/blobdiff - mach.c
Partial fix for bug #108 (Fixup cleanups).
[rmac] / mach.c
diff --git a/mach.c b/mach.c
index 162757f41023d66fd18dbc99e5f25d31aab3d975..08a9bab8f14e78e62ceb76c4813783a108582a88 100644 (file)
--- a/mach.c
+++ b/mach.c
@@ -1,7 +1,7 @@
 //
 // RMAC - Reboot's Macro Assembler for all Atari computers
 // MACH.C - Code Generation
-// Copyright (C) 199x Landon Dyer, 2011-2017 Reboot and Friends
+// Copyright (C) 199x Landon Dyer, 2011-2018 Reboot and Friends
 // RMAC derived from MADMAC v1.07 Written by Landon Dyer, 1986
 // Source utilised with the kind permission of Landon Dyer
 //
@@ -24,7 +24,7 @@
 int movep = 0; // Global flag to indicate we're generating a movep instruction
 
 // Function prototypes
-int m_unimp(WORD, WORD), m_badmode(WORD, WORD), m_bad6mode(WORD, WORD), m_bad6inst(WORD, WORD);
+int m_unimp(WORD, WORD), m_badmode(WORD, WORD);
 int m_self(WORD, WORD);
 int m_abcd(WORD, WORD);
 int m_reg(WORD, WORD);
@@ -73,12 +73,15 @@ int m_cinv(WORD inst, WORD siz);
 int m_cprest(WORD inst, WORD siz);
 int m_movec(WORD inst, WORD siz);
 int m_moves(WORD inst, WORD siz);
+int m_lpstop(WORD inst, WORD siz);
+int m_plpa(WORD inst, WORD siz);
 
 // PMMU
 int m_pbcc(WORD inst, WORD siz);
 int m_pflusha(WORD inst, WORD siz);
 int m_pflush(WORD inst, WORD siz);
 int m_pflushr(WORD inst, WORD siz);
+int m_pflushan(WORD inst, WORD siz);
 int m_pload(WORD inst, WORD siz, WORD extension);
 int m_pmove(WORD inst, WORD siz);
 int m_pmovefd(WORD inst, WORD siz);
@@ -400,8 +403,13 @@ int m_ea030(WORD inst, WORD siz)
                        // a corner case, so kludge it
                        a0reg = a0reg + 8;
                else if (am0 == PCDISP)
-                       //Another corner case (possibly!), so kludge ahoy
+                       // Another corner case (possibly!), so kludge ahoy
                        inst |= am0;                            // Get ea0 into instr
+               else if (am0 == IMMED && am1 == MEMPOST)
+               {
+                       // Added for addi/andi/cmpi/eori/ori/subi #xx,(bd,An,Dm)
+                       inst |= a1reg | AINDEXED;
+               }
                else if (am0 == IMMED)
                        inst |= am0 | a0reg;            // Get ea0 into instr
                else if (am0 == AM_CCR)
@@ -601,7 +609,7 @@ int m_dbra(WORD inst, WORD siz)
                if ((a1exattr & TDB) != cursect)
                        return error(rel_error);
 
-               uint32_t v = a1exval - sloc;
+               uint32_t v = (uint32_t)a1exval - sloc;
 
                if (v + 0x8000 > 0x10000)
                        return error(range_error);
@@ -676,12 +684,12 @@ int m_link(WORD inst, WORD siz)
 
 WORD extra_addressing[16]=
 {
-       0,     // 0100 (bd,An,Xn)
-       0,     // 0101 ([bd,An],Xn,od)
-       0x180, // 0102 ([bc,An,Xn],od) (111 110 110 111)
-       0,     // 0103 (bd,PC,Xn)
-       0,     // 0104 ([bd,PC],Xn,od)
-       0,     // 0105 ([bc,PC,Xn],od)
+       0x30,  // 0100 (bd,An,Xn)
+       0x30,  // 0101 ([bd,An],Xn,od)
+       0x30,  // 0102 ([bc,An,Xn],od)
+       0x30,  // 0103 (bd,PC,Xn)
+       0x30,  // 0104 ([bd,PC],Xn,od)
+       0x30,  // 0105 ([bc,PC,Xn],od)
        0,     // 0106
        0,     // 0107
        0,     // 0110
@@ -753,14 +761,12 @@ int m_move(WORD inst, WORD size)
 
 //
 // Handle MOVE <C_ALL030> <C_ALTDATA>
-//        MOVE <C_ALL030> <M_AREG>
+//             MOVE <C_ALL030> <M_AREG>
 //
 int m_move30(WORD inst, WORD size)
 {
        int siz = (int)size;
-       // TODO: is extra_addressing necessary/correct?
-       //inst |= siz_12[siz] | reg_9[a1reg & 7] | a0reg | extra_addressing[am0 - ABASE];
-       inst |= siz_12[siz] | reg_9[a1reg & 7] | a0reg;
+       inst |= siz_12[siz] | reg_9[a1reg & 7] | a0reg | extra_addressing[am0 - ABASE];
 
        D_word(inst);
 
@@ -1042,7 +1048,7 @@ immed1:
                        rmask = 0;
 
                        for(i=0x8000; i; i>>=1, w>>=1)
-                               rmask = (WORD)((rmask << 1) | w & 1);
+                               rmask = (WORD)((rmask << 1) | (w & 1));
                }
        }
        else
@@ -1178,19 +1184,42 @@ int m_bfop(WORD inst, WORD siz)
        else
                bfparam1 = bfval1 << 12;
 
-       D_word((inst | am0 | a0reg | am1 | a1reg));
+       //D_word((inst | am0 | a0reg | am1 | a1reg));
+       if (inst == B16(11101111, 11000000))
+       {
+               // bfins special case
+               D_word((inst | am1 | a1reg));
+       }
+       else
+       {
+               D_word((inst | am0 | a0reg));
+       }
+
        ea0gen(siz);    // Generate EA
 
        // Second instruction word - Dest register (if exists), Do, Offset, Dw, Width
-       inst = bfparam1 | bfparam2;
+       if (inst == B16(11101111, 11000000))
+       {
+               // bfins special case
+               inst = bfparam1 | bfparam2;
 
-       if (am1 == DREG)
-               inst |= a1reg << 0;
+               if (am1 == DREG)
+                       inst |= a0reg << 12;
 
-       if (am0 == DREG)
-               inst |= a0reg << 12;
+               D_word(inst);
+       }
+       else
+       {
+               inst = bfparam1 | bfparam2;
 
-       D_word(inst);
+               if (am1 == DREG)
+                       inst |= a0reg << 0;
+
+               if (am0 == DREG)
+                       inst |= a1reg << 12;
+
+               D_word(inst);
+       }
 
        return OK;
 }
@@ -1513,11 +1542,12 @@ int m_chk2(WORD inst, WORD siz)
 
 
 //
-// cpbcc(68020, 68030)
+// cpbcc(68020, 68030, 68040 (FBcc), 68060 (FBcc))
+// TODO: Better checks for different instructions?
 //
 int m_cpbr(WORD inst, WORD siz)
 {
-       if ((activecpu & (CPU_68020 | CPU_68030)) == 0)
+       if ((activecpu & (CPU_68020 | CPU_68030)) && (!activefpu == 0))
                return error(unsupport);
 
        if (a0exattr & DEFINED)
@@ -1538,7 +1568,7 @@ int m_cpbr(WORD inst, WORD siz)
                                return OK;
                        }
                }
-        else // SIZW/SIZN
+               else // SIZW/SIZN
                {
                        if ((v + 0x8000) >= 0x10000)
                                return error(range_error);
@@ -1609,6 +1639,7 @@ int m_cpdbr(WORD inst, WORD siz)
        }
 
        return OK;
+
 }
 
 
@@ -1629,7 +1660,7 @@ int m_muls(WORD inst, WORD siz)
 
        if (flg & 16)
        {
-               // OR-in register number 
+               // OR-in register number
                if (flg & 8)
                        inst |= reg_9[a1reg];           // ea1reg in bits 9..11
                else
@@ -1658,7 +1689,7 @@ int m_muls(WORD inst, WORD siz)
 
                 D_word(inst);
 
-               // Generate ea0 if requested 
+               // Generate ea0 if requested
                if (flg & 2)
                        ea0gen(siz);
 
@@ -1726,7 +1757,7 @@ int m_move16b(WORD inst, WORD siz)
                        return error("Wasn't this suppose to call m_move16a???");
                else
                {
-                       //move16 (ax)+,(xxx).L
+                       // move16 (ax)+,(xxx).L
                        inst |= 0 << 3;
                        v = (int)a1exval;
                }
@@ -1735,20 +1766,20 @@ int m_move16b(WORD inst, WORD siz)
        {
                if (am1 == AIND)
                {
-                       //move16 (xxx).L,(ax)+
+                       // move16 (xxx).L,(ax)+
                        inst |= 1 << 3;
                        v = (int)a0exval;
                }
-               else //APOSTINC
+               else // APOSTINC
                {
-                       //move16 (xxx).L,(ax)
+                       // move16 (xxx).L,(ax)
                        inst |= 3 << 3;
                        v = (int)a0exval;
                }
        }
        else if (am0 == AIND)
        {
-               //move16 (ax),(xxx).L
+               // move16 (ax),(xxx).L
                inst |= 2 << 3;
                v = (int)a1exval;
        }
@@ -1920,7 +1951,7 @@ int m_trapcc(WORD inst, WORD siz)
 
 
 //
-// cinvl/p/a (68040)
+// cinvl/p/a (68040/68060)
 //
 int m_cinv(WORD inst, WORD siz)
 {
@@ -1983,7 +2014,7 @@ int m_frestore(WORD inst, WORD siz)
 
 
 //
-// movec (68010, 68020, 68030, 68040, CPU32)
+// movec (68010, 68020, 68030, 68040, 68060, CPU32)
 //
 int m_movec(WORD inst, WORD siz)
 {
@@ -2138,7 +2169,7 @@ int m_pflush(WORD inst, WORD siz)
                        if ((a0exattr & DEFINED) == 0)
                                return error("function code immediate should be defined");
 
-                       if (a0exval > 7 && a0exval < 0)
+                       if (a0exval > 7)
                                return error("function code out of range (0-7)");
 
                        fc = (uint16_t)a0exval;
@@ -2180,7 +2211,7 @@ int m_pflush(WORD inst, WORD siz)
                if ((a0exattr & DEFINED) == 0)
                        return error("mask immediate value should be defined");
 
-               if (a0exval > 7 && a0exval < 0)
+               if (a0exval > 7)
                        return error("function code out of range (0-7)");
 
                mask = (uint16_t)a0exval << 5;
@@ -2254,6 +2285,18 @@ int m_pflush(WORD inst, WORD siz)
 }
 
 
+//
+// pflushan (68040, 68060)
+//
+int m_pflushan(WORD inst, WORD siz)
+{
+       if (activecpu == CPU_68040 || activecpu == CPU_68060)
+               D_word(inst);
+
+       return OK;
+}
+
+
 //
 // pflushr (68851)
 //
@@ -2392,7 +2435,7 @@ int m_pmove(WORD inst, WORD siz)
 
        // The instruction is a quad-word (8 byte) operation
        // for the CPU root pointer and the supervisor root pointer.
-       // It is a long - word operation for the translation control register
+       // It is a long-word operation for the translation control register
        // and the transparent translation registers(TT0 and TT1).
        // It is a word operation for the MMU status register.
 
@@ -2414,7 +2457,7 @@ int m_pmove(WORD inst, WORD siz)
        }
        else if (am1 == CREG)
        {
-       inst |= am0 | a0reg;
+               inst |= am0 | a0reg;
                D_word(inst);
        }
 
@@ -2468,7 +2511,7 @@ int m_pmovefd(WORD inst, WORD siz)
 //
 int m_ptrapcc(WORD inst, WORD siz)
 {
-    CHECKNO20;
+       CHECKNO20;
        // We stash the 5 condition bits inside the opcode in 68ktab (bits 0-4),
        // so we need to extract them first and fill in the clobbered bits.
        WORD opcode = inst & 0x1F;
@@ -2869,7 +2912,7 @@ int m_fintrz(WORD inst, WORD siz)
 
        if (activefpu == FPU_68040)
                warn("Instruction is emulated in 68040");
-       
+
        return gen_fpu(inst, siz, B8(00000011), FPU_NOWARN);
 }
 
@@ -3376,7 +3419,7 @@ int m_fsmul(WORD inst, WORD siz)
 {
        if (activefpu & (FPU_68040 | FPU_68060))
                return gen_fpu(inst, siz, B8(01100011), FPU_NOWARN);
-       
+
        return error("Unsupported in current FPU");
 }
 
@@ -3405,7 +3448,7 @@ int m_fneg(WORD inst, WORD siz)
                a1reg = a0reg;
                return gen_fpu(inst, siz, B8(00011010), FPU_NOWARN);
        }
-       
+
        return gen_fpu(inst, siz, B8(00011010), FPU_NOWARN);
 }
 
@@ -3422,7 +3465,7 @@ int m_fsneg(WORD inst, WORD siz)
                        a1reg = a0reg;
                        return gen_fpu(inst, siz, B8(01011010), FPU_NOWARN);
                }
-               
+
                return gen_fpu(inst, siz, B8(01011010), FPU_NOWARN);
        }
 
@@ -3584,7 +3627,7 @@ int m_fsfsqrt(WORD inst, WORD siz)
 {
        if (activefpu & (FPU_68040 | FPU_68060))
                return gen_fpu(inst, siz, B8(01000001), FPU_NOWARN);
-       
+
        return error("Unsupported in current FPU");
 }
 
@@ -3725,3 +3768,45 @@ int m_ftwotox(WORD inst, WORD siz)
        return gen_fpu(inst, siz, B8(00010001), FPU_FPSP);
 }
 
+
+/////////////////////////////////
+//                             //
+// 68060 specific instructions //
+//                             //
+/////////////////////////////////
+
+
+//
+// lpstop (68060)
+//
+int m_lpstop(WORD inst, WORD siz)
+{
+       CHECKNO60;
+       D_word(B16(00000001, 11000000));
+
+       if (a0exattr & DEFINED)
+       {
+               D_word(a0exval);
+       }
+       else
+       {
+               AddFixup(FU_WORD, sloc, a0expr);
+               D_word(0);
+       }
+
+       return OK;
+}
+
+
+//
+// plpa (68060)
+//
+int m_plpa(WORD inst, WORD siz)
+{
+       CHECKNO60;
+       inst |= a0reg;          // Install register
+       D_word(inst);
+
+       return OK;
+}
+