X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=cpu%2FCyclone%2FOpBranch.cpp;h=d1c2391876b78d729614a03c8fee11f69a4c632d;hb=2270612aa7ee7d04549e95c2ab4d72f6aa67fa8d;hp=31e82fc26b94cafdbb61a5e79e3b6175c4c28aa1;hpb=cfb3dfa0f2a36569a6b090e87568b1a1c423f75c;p=picodrive.git diff --git a/cpu/Cyclone/OpBranch.cpp b/cpu/Cyclone/OpBranch.cpp index 31e82fc..d1c2391 100644 --- a/cpu/Cyclone/OpBranch.cpp +++ b/cpu/Cyclone/OpBranch.cpp @@ -11,8 +11,7 @@ static void CheckPc(int reg) ot(" ldr pc,[r7,#0x64] ;@ Call checkpc()\n"); ot(" mov r4,r0\n"); #else - if (reg != 4) - ot(" mov r4,r%i\n", reg); + ot(" bic r4,r%d,#1\n",reg); // we do not emulate address errors #endif ot("\n"); } @@ -139,8 +138,8 @@ int OpUnlk(int op) OpStart(op,0x10); ot(";@ Get An\n"); - EaCalc(10, 7, 8, 2, 1); - EaRead(10, 0, 8, 2, 7, 1); + EaCalc(10, 0xf, 8, 2, 1); + EaRead(10, 0, 8, 2, 0xf, 1); ot(" add r11,r0,#4 ;@ A7+=4\n"); ot("\n"); @@ -151,18 +150,19 @@ int OpUnlk(int op) ot("\n"); ot(";@ An = value from stack:\n"); EaWrite(10, 0, 8, 2, 7, 1); - + Cycles=12; OpEnd(0x10); return 0; } // --------------------- Opcodes 0x4e70+ --------------------- +// 01001110 01110ttt int Op4E70(int op) { int type=0; - type=op&7; // 01001110 01110ttt, reset/nop/stop/rte/rtd/rts/trapv/rtr + type=op&7; // reset/nop/stop/rte/rtd/rts/trapv/rtr switch (type) { @@ -181,7 +181,6 @@ int Op4E70(int op) SuperChange(op); CheckInterrupt(op); OpEnd(0x10); - SuperEnd(op); return 0; case 5: // rts @@ -194,7 +193,7 @@ int Op4E70(int op) case 6: // trapv OpStart(op,0x10); Cycles=4; ot(" tst r9,#0x10000000\n"); - ot(" subne r5,r5,#%i\n",30); + ot(" subne r5,r5,#%i\n",34); ot(" movne r0,#0x1c ;@ TRAPV exception\n"); ot(" blne Exception\n"); OpEnd(0x10); @@ -225,7 +224,7 @@ int OpJsr(int op) // See if we can do this opcode: if (EaCanRead(sea,-1)==0) return 1; - use=OpBase(op); + use=OpBase(op,0); if (op!=use) { OpUse(op,use); return 0; } // Use existing handler OpStart(op,(op&0x40)?0:0x10); @@ -237,17 +236,17 @@ int OpJsr(int op) ot(";@ Jump - Get new PC from r0\n"); if (op&0x40) { - // Jmp - Get new PC from r0 + // Jmp - Get new PC from r11 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(" mov r1,r1,lsl #8\n"); ot(" ldr r0,[r7,#0x3c]\n"); - ot(" mov r1,r1,asr #8\n"); + ot(" sub r1,r4,r10 ;@ r1 = Old PC\n"); +// ot(" mov r1,r1,lsl #8\n"); +// ot(" mov r1,r1,asr #8\n"); ot(";@ Push r1 onto stack\n"); ot(" sub r0,r0,#4 ;@ Predecrement A7\n"); ot(" str r0,[r7,#0x3c] ;@ Save A7\n"); @@ -287,50 +286,84 @@ int OpDbra(int op) if (op!=use) { OpUse(op,use); return 0; } // Use existing handler OpStart(op); - if (cc>=2) + switch (cc) { - ot(";@ Is the condition true?\n"); - if ((cc&~1)==2) ot(" eor r9,r9,#0x20000000 ;@ Invert carry for hi/ls\n"); - ot(" msr cpsr_flg,r9 ;@ ARM flags = 68000 flags\n"); - if ((cc&~1)==2) ot(" eor r9,r9,#0x20000000\n"); - ot(";@ If so, don't dbra\n"); - ot(" b%s DbraTrue%.4x\n",Cond[cc],op); - ot("\n"); + case 0: // T + case 1: // F + break; + case 2: // hi + ot(" tst r9,#0x60000000 ;@ hi: !C && !Z\n"); + ot(" beq DbraTrue\n\n"); + break; + case 3: // ls + ot(" tst r9,#0x60000000 ;@ ls: C || Z\n"); + ot(" bne DbraTrue\n\n"); + break; + default: + ot(";@ Is the condition true?\n"); + ot(" msr cpsr_flg,r9 ;@ ARM flags = 68000 flags\n"); + ot(";@ If so, don't dbra\n"); + ot(" b%s DbraTrue\n\n",Cond[cc]); + break; } - ot(";@ Decrement Dn.w\n"); - ot(" and r1,r8,#0x0007\n"); - ot(" mov r1,r1,lsl #2\n"); - ot(" ldrsh r0,[r7,r1]\n"); - ot(" sub r0,r0,#1\n"); - ot(" strh r0,[r7,r1]\n"); - ot("\n"); + if (cc!=0) + { + ot(";@ Decrement Dn.w\n"); + ot(" and r1,r8,#0x0007\n"); + ot(" mov r1,r1,lsl #2\n"); + ot(" ldrsh r0,[r7,r1]\n"); + ot(" sub r0,r0,#1\n"); + ot(" strh r0,[r7,r1]\n"); + ot("\n"); - ot(";@ Check if Dn.w is -1\n"); - ot(" cmps r0,#-1\n"); - ot(" beq DbraMin1%.4x\n",op); - ot("\n"); + ot(";@ Check if Dn.w is -1\n"); + ot(" cmn r0,#1\n"); - ot(";@ Get Branch offset:\n"); - ot(" ldrsh r0,[r4]\n"); - ot(" add r4,r4,r0 ;@ r4 = New PC\n"); - ot("\n"); - Cycles=12-2; - OpEnd(); +#if USE_CHECKPC_CALLBACK && USE_CHECKPC_DBRA + ot(" beq DbraMin1\n"); + ot("\n"); + + ot(";@ Get Branch offset:\n"); + ot(" ldrsh r0,[r4]\n"); + ot(" add r0,r4,r0 ;@ r4 = New PC\n"); + CheckPc(0); +#else + ot("\n"); + ot(";@ Get Branch offset:\n"); + ot(" ldrnesh r0,[r4]\n"); + ot(" addeq r4,r4,#2 ;@ Skip branch offset\n"); + ot(" subeq r5,r5,#4 ;@ additional cycles\n"); + ot(" addne r4,r4,r0 ;@ r4 = New PC\n"); + ot(" bic r4,r4,#1\n"); // we do not emulate address errors + ot("\n"); +#endif + Cycles=12-2; + OpEnd(); + } - ot(";@ Dn.w is -1:\n"); - ot("DbraMin1%.4x%s\n", op, ms?"":":"); - ot(" add r4,r4,#2 ;@ Skip branch offset\n"); - ot("\n"); - Cycles=12+2; - OpEnd(); + //if (cc==0||cc>=2) + if (op==0x50c8) + { + ot(";@ condition true:\n"); + ot("DbraTrue%s\n", ms?"":":"); + ot(" add r4,r4,#2 ;@ Skip branch offset\n"); + ot("\n"); + Cycles=12; + OpEnd(); + } - ot(";@ condition true:\n"); - ot("DbraTrue%.4x%s\n", op, ms?"":":"); - ot(" add r4,r4,#2 ;@ Skip branch offset\n"); - ot("\n"); - Cycles=12; - OpEnd(); +#if USE_CHECKPC_CALLBACK && USE_CHECKPC_DBRA + if (op==0x51c8) + { + ot(";@ Dn.w is -1:\n"); + ot("DbraMin1%s\n", ms?"":":"); + ot(" add r4,r4,#2 ;@ Skip branch offset\n"); + ot("\n"); + Cycles=12+2; + OpEnd(); + } +#endif return 0; } @@ -339,9 +372,10 @@ int OpDbra(int op) // Emit a Branch opcode 0110cccc nn (cccc=condition) int OpBranch(int op) { - int size=0,use=0; + int size=0,use=0,checkpc=0; int offset=0; int cc=0; + char *asr_r11=""; offset=(char)(op&0xff); cc=(op>>8)&15; @@ -350,87 +384,104 @@ int OpBranch(int op) if (offset==0) size=1; if (offset==-1) size=2; + if (size==2) size=0; // 000 model does not support long displacement if (size) use=op; // 16-bit or 32-bit 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,size?0x10:0); - - ot(";@ Get Branch offset:\n"); - if (size) - { - 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 (cc==1) ot(" ldr r10,[r7,#0x60] ;@ Get Memory base\n"); - if (cc>=2) + switch (cc) { - ot(";@ Is the condition true?\n"); - if ((cc&~1)==2) ot(" eor r9,r9,#0x20000000 ;@ Invert carry for hi/ls\n"); - ot(" msr cpsr_flg,r9 ;@ ARM flags = 68000 flags\n"); - if ((cc&~1)==2) ot(" eor r9,r9,#0x20000000\n"); - - ot(" b%s DontBranch%.4x\n",Cond[cc^1],op); - ot("\n"); + case 0: // T + case 1: // F + break; + case 2: // hi + ot(" tst r9,#0x60000000 ;@ hi: !C && !Z\n"); + ot(" bne BccDontBranch%i\n\n",8<=2) + // since all "DontBranch" code is same for every size, output only once + if (cc>=2&&(op&0xff00)==0x6200) { - ot("DontBranch%.4x%s\n", op, ms?"":":"); - Cycles+=(size==1)? 2 : -2; // Branch not taken - OpEnd(size?0x10:0); + ot("BccDontBranch%i%s\n", 8<