X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=cpu%2FCyclone%2FOpBranch.cpp;h=31e82fc26b94cafdbb61a5e79e3b6175c4c28aa1;hb=cfb3dfa0f2a36569a6b090e87568b1a1c423f75c;hp=71f9785838fae0f070998f7bc878a46e51948c81;hpb=cc68a136aa179a5f32fe40208371eb9c2b0aadae;p=picodrive.git diff --git a/cpu/Cyclone/OpBranch.cpp b/cpu/Cyclone/OpBranch.cpp index 71f9785..31e82fc 100644 --- a/cpu/Cyclone/OpBranch.cpp +++ b/cpu/Cyclone/OpBranch.cpp @@ -1,17 +1,21 @@ #include "app.h" -#if USE_CHECKPC_CALLBACK -static void CheckPc() +static void CheckPc(int reg) { +#if USE_CHECKPC_CALLBACK ot(";@ Check Memory Base+pc (r4)\n"); - ot(" add lr,pc,#4\n"); - ot(" mov r0,r4\n"); + if (reg != 0) + ot(" mov r0,r%i\n", reg); + ot(" mov lr,pc\n"); ot(" ldr pc,[r7,#0x64] ;@ Call checkpc()\n"); ot(" mov r4,r0\n"); +#else + if (reg != 4) + ot(" mov r4,r%i\n", reg); +#endif ot("\n"); } -#endif // Push 32-bit value in r1 - trashes r0-r3,r12,lr void OpPush32() @@ -56,9 +60,9 @@ static void PopPc() ot(" add r1,r0,#4 ;@ Postincrement A7\n"); ot(" str r1,[r7,#0x3c] ;@ Save A7\n"); MemHandler(0,2); - ot(" add r4,r0,r10 ;@ r4=Memory Base+PC\n"); + ot(" add r0,r0,r10 ;@ Memory Base+PC\n"); ot("\n"); - CheckPc(); + CheckPc(0); } int OpTrap(int op) @@ -68,14 +72,14 @@ int OpTrap(int op) use=op&~0xf; if (op!=use) { OpUse(op,use); return 0; } // Use existing handler - OpStart(op); + OpStart(op,0x10); ot(" and r0,r8,#0xf ;@ Get trap number\n"); ot(" orr r0,r0,#0x20\n"); ot(" mov r0,r0,asl #2\n"); ot(" bl Exception\n"); ot("\n"); - Cycles=38; OpEnd(); + Cycles=38; OpEnd(0x10); return 0; } @@ -90,7 +94,7 @@ int OpLink(int op) if (reg==7) use=op; if (op!=use) { OpUse(op,use); return 0; } // Use existing handler - OpStart(op); + OpStart(op,0x10); if(reg!=7) { ot(";@ Get An\n"); @@ -120,7 +124,7 @@ int OpLink(int op) ot("\n"); Cycles=16; - OpEnd(); + OpEnd(0x10); return 0; } @@ -132,7 +136,7 @@ int OpUnlk(int op) use=op&~7; if (op!=use) { OpUse(op,use); return 0; } // Use existing handler - OpStart(op); + OpStart(op,0x10); ot(";@ Get An\n"); EaCalc(10, 7, 8, 2, 1); @@ -149,7 +153,7 @@ int OpUnlk(int op) EaWrite(10, 0, 8, 2, 7, 1); Cycles=12; - OpEnd(); + OpEnd(0x10); return 0; } @@ -168,40 +172,40 @@ int Op4E70(int op) OpEnd(); return 0; - case 3: // rte - OpStart(op); Cycles=20; - SuperCheck(op); + case 3: // rte + OpStart(op,0x10); Cycles=20; + SuperCheck(op); PopSr(1); ot(" ldr r10,[r7,#0x60] ;@ Get Memory base\n"); PopPc(); - SuperChange(op); + SuperChange(op); CheckInterrupt(op); - OpEnd(); - SuperEnd(op); + OpEnd(0x10); + SuperEnd(op); return 0; case 5: // rts - OpStart(op); Cycles=16; + OpStart(op,0x10); Cycles=16; ot(" ldr r10,[r7,#0x60] ;@ Get Memory base\n"); PopPc(); - OpEnd(); + OpEnd(0x10); return 0; case 6: // trapv - OpStart(op); Cycles=4; + OpStart(op,0x10); Cycles=4; ot(" tst r9,#0x10000000\n"); ot(" subne r5,r5,#%i\n",30); ot(" movne r0,#0x1c ;@ TRAPV exception\n"); ot(" blne Exception\n"); - OpEnd(); + OpEnd(0x10); return 0; case 7: // rtr - OpStart(op); Cycles=20; + OpStart(op,0x10); Cycles=20; PopSr(0); ot(" ldr r10,[r7,#0x60] ;@ Get Memory base\n"); PopPc(); - OpEnd(); + OpEnd(0x10); return 0; default: @@ -224,24 +228,23 @@ int OpJsr(int op) use=OpBase(op); if (op!=use) { OpUse(op,use); return 0; } // Use existing handler - OpStart(op); + OpStart(op,(op&0x40)?0:0x10); ot(" ldr r10,[r7,#0x60] ;@ Get Memory base\n"); ot("\n"); - EaCalc(0,0x003f,sea,0); + EaCalc(11,0x003f,sea,0); ot(";@ Jump - Get new PC from r0\n"); if (op&0x40) { // Jmp - Get new PC from r0 - ot(" add r4,r0,r10 ;@ r4 = Memory Base + New PC\n"); + ot(" add r0,r11,r10 ;@ Memory Base + New PC\n"); ot("\n"); } else { ot(";@ Jsr - Push old PC first\n"); ot(" sub r1,r4,r10 ;@ r1 = Old PC\n"); - ot(" add r4,r0,r10 ;@ r4 = Memory Base + New PC\n"); ot(" mov r1,r1,lsl #8\n"); ot(" ldr r0,[r7,#0x3c]\n"); ot(" mov r1,r1,asr #8\n"); @@ -249,17 +252,16 @@ int OpJsr(int op) ot(" sub r0,r0,#4 ;@ Predecrement A7\n"); ot(" str r0,[r7,#0x3c] ;@ Save A7\n"); MemHandler(1,2); + ot(" add r0,r11,r10 ;@ Memory Base + New PC\n"); ot("\n"); } -#if USE_CHECKPC_CALLBACK - CheckPc(); -#endif + CheckPc(0); Cycles=(op&0x40) ? 4 : 12; Cycles+=Ea_add_ns((op&0x40) ? g_jmp_cycle_table : g_jsr_cycle_table, sea); - OpEnd(); + OpEnd((op&0x40)?0:0x10); return 0; } @@ -352,7 +354,7 @@ int OpBranch(int op) else use=(op&0xff00)+1; // Use same opcode for all 8-bit branches if (op!=use) { OpUse(op,use); return 0; } // Use existing handler - OpStart(op); + OpStart(op,size?0x10:0); ot(";@ Get Branch offset:\n"); if (size) @@ -360,12 +362,12 @@ int OpBranch(int op) EaCalc(0,0,0x3c,size); EaRead(0,0,0x3c,size,0); } + else + ot(" mov r0,r8,asl #24 ;@ Shift 8-bit signed offset up...\n\n"); // above code messes cycles Cycles=10; // Assume branch taken - if (size==0) ot(" mov r0,r8,asl #24 ;@ Shift 8-bit signed offset up...\n\n"); - if (cc==1) ot(" ldr r10,[r7,#0x60] ;@ Get Memory base\n"); if (cc>=2) @@ -375,16 +377,11 @@ int OpBranch(int op) ot(" msr cpsr_flg,r9 ;@ ARM flags = 68000 flags\n"); if ((cc&~1)==2) ot(" eor r9,r9,#0x20000000\n"); - if (size==0) ot(" mov r0,r0,asr #24 ;@ ...shift down\n\n"); - ot(" b%s DontBranch%.4x\n",Cond[cc^1],op); - ot("\n"); } - else - { - if (size==0) ot(" mov r0,r0,asr #24 ;@ ...shift down\n\n"); - } + + if (size==0) ot(" mov r0,r0,asr #24 ;@ ...shift down\n\n"); ot(";@ Branch taken - Add on r0 to PC\n"); @@ -404,29 +401,36 @@ int OpBranch(int op) MemHandler(1,2); ot("\n"); Cycles=18; // always 18 + if (offset==0 || offset==-1) + { + ot(";@ Branch is quite far, so may be a good idea to check Memory Base+pc\n"); + CheckPc(4); + } } else { if (size) ot(" sub r4,r4,#%d ;@ (Branch is relative to Opcode+2)\n",1<=2) { ot("DontBranch%.4x%s\n", op, ms?"":":"); Cycles+=(size==1)? 2 : -2; // Branch not taken - OpEnd(); + OpEnd(size?0x10:0); } return 0;