svp compiler: some adjustments
authornotaz <notasas@gmail.com>
Wed, 5 Mar 2008 21:52:45 +0000 (21:52 +0000)
committernotaz <notasas@gmail.com>
Wed, 5 Mar 2008 21:52:45 +0000 (21:52 +0000)
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@370 be3aeb3a-fb24-0410-a615-afba39da0efa

Pico/carthw/svp/Memory.c
Pico/carthw/svp/compiler.c
Pico/carthw/svp/gen_arm.c
Pico/carthw/svp/stub_arm.S
Pico/carthw/svp/svp.c

index 8a8474a..2a49139 100644 (file)
@@ -108,6 +108,8 @@ void PicoSVPWrite16(unsigned int a, unsigned int d, int realsize)
     //else if (a == 0xa15006) svp->ssp1601.gr[SSP_PM0].h = d | (d << 1);
     // 0xa15006 probably has 'halt'
   }
+  else
+    elprintf(EL_UIO|EL_SVP|EL_ANOMALY, "SVP FIXME: unhandled w%i: [%06x] %04x @%06x", realsize, a&0xffffff, d, SekPc);
 
 
   if (a == 0x30fe06 && d != 0)
index 7b34f41..a3b65e5 100644 (file)
@@ -12,7 +12,7 @@ static int nblocks = 0;
 static int iram_context = 0;
 
 #ifndef ARM
-#define DUMP_BLOCK 0x29a0
+#define DUMP_BLOCK 0x240a
 unsigned int tcache[512*1024];
 void regfile_load(void){}
 void regfile_store(void){}
@@ -638,6 +638,7 @@ static void tr_mov16(int r, int val)
 static void tr_mov16_cond(int cond, int r, int val)
 {
        emit_mov_const(cond, r, val);
+       hostreg_r[r] = -1;
 }
 
 /* read bank word to r0. Thrashes r1. */
@@ -672,7 +673,7 @@ static void tr_bank_write(int addr)
 /* handle RAM bank pointer modifiers. Nothing is trashed. */
 static void tr_ptrr_mod(int r, int mod, int need_modulo)
 {
-       int modulo = -1, modulo_shift = -1;     /* unknown */
+       int modulo_shift = -1;  /* unknown */
 
        if (mod == 0) return;
 
@@ -683,14 +684,27 @@ static void tr_ptrr_mod(int r, int mod, int need_modulo)
                if (modulo_shift == 0) modulo_shift = 8;
        }
 
-       if (mod > 1 && modulo_shift == -1) { printf("need var modulo\n"); exit(1); }
-       modulo = (1 << modulo_shift) - 1;
+       if (mod > 1 && modulo_shift == -1) {
+/* TODO
+               int reg = (r < 4) ? 8 : 9;
+               int ror = ((r&3) + 1)*8 - (8 - modulo_shift);
+               EOP_MOV_REG_ROR(reg,reg,ror);
+               // {add|sub} reg, reg, #1<<shift
+               EOP_C_DOP_IMM(A_COND_AL,(mod==2)?A_OP_SUB:A_OP_ADD,0,reg,reg, 8/2, 1<<(8 - modulo_shift));
+               EOP_MOV_REG_ROR(reg,reg,32-ror);
+*/
 
-       if (known_regb & (1 << (r + 8))) {
+               printf("need var modulo\n"); exit(1);
+       }
+       else if (known_regb & (1 << (r + 8)))
+       {
+               int modulo = (1 << modulo_shift) - 1;
                if (mod == 2)
                     known_regs.r[r] = (known_regs.r[r] & ~modulo) | ((known_regs.r[r] - 1) & modulo);
                else known_regs.r[r] = (known_regs.r[r] & ~modulo) | ((known_regs.r[r] + 1) & modulo);
-       } else {
+       }
+       else
+       {
                int reg = (r < 4) ? 8 : 9;
                int ror = ((r&3) + 1)*8 - (8 - modulo_shift);
                EOP_MOV_REG_ROR(reg,reg,ror);
@@ -985,13 +999,14 @@ static int translate_op(unsigned int op, int *pc, int imm)
                                tr_write_funcs[tmpv]();
                                known_regs.gr[tmpv].h = imm;
                                known_regb |= 1 << tmpv;
-                               ret++; break;
+                               ret += 2; break;
                        }
                        else if (tmpv == 0xe && (PROGRAM(*pc) >> 9) == 4)
                        {
                                // programming PMC..
                                (*pc)++;
                                tmpv = imm | (PROGRAM((*pc)++) << 16);
+                               ret += 2;
                                emit_mov_const(A_COND_AL, 0, tmpv);
                                EOP_LDR_IMM(1,7,0x484);         // ldr r0, [r7, #0x484] // emu_status
                                EOP_STR_IMM(0,7,0x400+14*4);    // PMC
@@ -1049,15 +1064,16 @@ static int translate_op(unsigned int op, int *pc, int imm)
                        }
                        EOP_LDRH_SIMPLE(0,2);                                   // ldrh r0, [r0]
                        hostreg_r[0] = hostreg_r[2] = -1;
+                       known_regb &= ~(1 << tmpv2);
                        tr_write_funcs[tmpv2]();
-                       ret += 2; break; /* should certainly take > 1 */
+                       ret += 3; break; /* should certainly take > 1 */
                }
 
                // ldi (ri), imm
                case 0x06:
                        tr_mov16(0, imm);
                        tr_rX_write1(op);
-                       ret++; break;
+                       ret += 2; break;
 
                // ld adr, a
                case 0x07:
@@ -1125,33 +1141,41 @@ static int translate_op(unsigned int op, int *pc, int imm)
                        dirty_regb |= 1 << (tmpv + 8);
                        ret++; break;
 
+               // call cond, addr
+               case 0x24:
+                       tr_mov16(0, *pc);
+                       tr_r0_to_STACK();
+                       tmpv = tr_cond_check(op);
+                       tr_mov16_cond(tmpv, 0, imm);
+                       if (tmpv != A_COND_AL) {
+                               tr_mov16_cond(tr_neg_cond(tmpv), 0, *pc);
+                       }
+                       tr_r0_to_PC();
+                       ret += 2; break;
+
                // ld d, (a)
                case 0x25:
-                       // tmpv = ((unsigned short *)svp->iram_rom)[rA]; REG_WRITE((op & 0xf0) >> 4, tmpv); break;
                        tmpv2 = (op >> 4) & 0xf;  // dst
                        if (tmpv2 >= 8) return -1; // TODO
 
-                       tr_read_funcs[SSP_A]();
+                       tr_A_to_r0();
                        EOP_LDR_IMM(1,7,0x48c);                                 // ptr_iram_rom
                        EOP_ADD_REG_LSL(0,1,0,1);                               // add  r0, r1, r0, lsl #1
                        EOP_LDRH_SIMPLE(0,0);                                   // ldrh r0, [r0]
                        hostreg_r[0] = hostreg_r[1] = -1;
+                       known_regb &= ~(1 << tmpv2);
                        tr_write_funcs[tmpv2]();
-                       ret += 2; break; /* should certainly take > 1 */
+                       ret += 3; break;
 
                // bra cond, addr
-               case 0x26: {
+               case 0x26:
                        tmpv = tr_cond_check(op);
                        tr_mov16_cond(tmpv, 0, imm);
                        if (tmpv != A_COND_AL) {
-                               EOP_C_DOP_IMM(tmpv, A_OP_ADD, 0, 11, 11, 0, 1); // add 1 to cycles if we jump
                                tr_mov16_cond(tr_neg_cond(tmpv), 0, *pc);
                        }
-                       else
-                               ret++;  // always jump */
-                       tr_write_funcs[SSP_PC]();
-                       ret++; break;
-               }
+                       tr_r0_to_PC();
+                       ret += 2; break;
 
 
 /*
@@ -1179,6 +1203,7 @@ static int translate_op(unsigned int op, int *pc, int imm)
                        known_regs.r[SSP_A].v = 0;
                        known_regb |= (KRREG_A|KRREG_AL);
                        EOP_BIC_IMM(6, 6, 0, 0x0f);             // bic r6, r6, 0xf // flags
+                       EOP_BIC_IMM(6, 6, 0, 0x04);             // bic r6, r6, 4 // set Z
                        // TODO
                        ret++; break;
 */
index 32b9658..d92ae24 100644 (file)
@@ -127,7 +127,6 @@ static void emit_mov_const(int cond, int d, unsigned int val)
 {
        int need_or = 0;
        if (val & 0xff000000) {
-               EOP_MOV_IMM(d,  8/2, (val>>24)&0xff);
                EOP_C_DOP_IMM(cond, A_OP_MOV, 0, 0, d, 8/2, (val>>24)&0xff);
                need_or = 1;
        }
index b812b61..d484fad 100644 (file)
@@ -62,7 +62,7 @@ regfile_load:
     orrne   r8, r8, #0x8
     tst     r6,     #0x20000000
     orrne   r8, r8, #0x4                @ sss0 *           NZ..
-    orr     r6, r8, r9, lsr #12         @ sss0 * .uu. .lll ....
+    orr     r6, r8, r9, lsr #12         @ sss0 * .uu. .lll NZ..
 
     ldr     r8, [r7, #0x440]            @ r0-r2
     ldr     r9, [r7, #0x444]            @ r4-r6
index f41bdea..e76c7ce 100644 (file)
@@ -109,7 +109,6 @@ void PicoSVPStartup(void)
 
        elprintf(EL_SVP, "SVP init");
 
-PicoOpt |= 0x20000;
        tmp = realloc(Pico.rom, 0x200000 + sizeof(*svp));
        if (tmp == NULL)
        {