X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=cpu%2FCyclone%2FMain.cpp;h=9bcf2054a951f0286d586fa441d04be2643e0dbe;hb=2c559c66ef1e7021f92e40244100f60c774fdd2c;hp=aca7f4f70c5d4171ee8047b06a4e5aacf54a493f;hpb=7336a99a49268970e0df89d15210b98dd7798f1e;p=picodrive.git diff --git a/cpu/Cyclone/Main.cpp b/cpu/Cyclone/Main.cpp index aca7f4f..9bcf205 100644 --- a/cpu/Cyclone/Main.cpp +++ b/cpu/Cyclone/Main.cpp @@ -32,6 +32,51 @@ void ltorg() else ot(" .ltorg\n"); } +#if (CYCLONE_FOR_GENESIS == 2) +// r12=ptr to tas in table, trashes r0,r1 +static void ChangeTAS(int norm) +{ + ot(" ldr r0,=Op4ad0%s\n",norm?"_":""); + ot(" mov r1,#8\n"); + ot("setrtas_loop%i0%s ;@ 4ad0-4ad7\n",norm,ms?"":":"); + ot(" subs r1,r1,#1\n"); + ot(" str r0,[r12],#4\n"); + ot(" bne setrtas_loop%i0\n",norm); + ot(" ldr r0,=Op4ad8%s\n",norm?"_":""); + ot(" mov r1,#7\n"); + ot("setrtas_loop%i1%s ;@ 4ad8-4ade\n",norm,ms?"":":"); + ot(" subs r1,r1,#1\n"); + ot(" str r0,[r12],#4\n"); + ot(" bne setrtas_loop%i1\n",norm); + ot(" ldr r0,=Op4adf%s\n",norm?"_":""); + ot(" str r0,[r12],#4\n"); + ot(" ldr r0,=Op4ae0%s\n",norm?"_":""); + ot(" mov r1,#7\n"); + ot("setrtas_loop%i2%s ;@ 4ae0-4ae6\n",norm,ms?"":":"); + ot(" subs r1,r1,#1\n"); + ot(" str r0,[r12],#4\n"); + ot(" bne setrtas_loop%i2\n",norm); + ot(" ldr r0,=Op4ae7%s\n",norm?"_":""); + ot(" str r0,[r12],#4\n"); + ot(" ldr r0,=Op4ae8%s\n",norm?"_":""); + ot(" mov r1,#8\n"); + ot("setrtas_loop%i3%s ;@ 4ae8-4aef\n",norm,ms?"":":"); + ot(" subs r1,r1,#1\n"); + ot(" str r0,[r12],#4\n"); + ot(" bne setrtas_loop%i3\n",norm); + ot(" ldr r0,=Op4af0%s\n",norm?"_":""); + ot(" mov r1,#8\n"); + ot("setrtas_loop%i4%s ;@ 4af0-4af7\n",norm,ms?"":":"); + ot(" subs r1,r1,#1\n"); + ot(" str r0,[r12],#4\n"); + ot(" bne setrtas_loop%i4\n",norm); + ot(" ldr r0,=Op4af8%s\n",norm?"_":""); + ot(" str r0,[r12],#4\n"); + ot(" ldr r0,=Op4af9%s\n",norm?"_":""); + ot(" str r0,[r12],#4\n"); +} +#endif + // trashes all temp regs static void PrintException(int ints) { @@ -86,11 +131,10 @@ static void PrintException(int ints) void CheckInterrupt(int op) { ot(";@ CheckInterrupt:\n"); - ot(" ldr r0,[r7,#0x44]\n"); // same as ldrb r0,[r7,#0x47] - ot(" movs r0,r0,lsr #24 ;@ Get IRQ level (loading word is faster)\n"); + ot(" ldr r1,[r7,#0x44] ;@ Get SR high T_S__III and irq level\n"); + ot(" movs r0,r1,lsr #24 ;@ Get IRQ level\n"); // same as ldrb r0,[r7,#0x47] ot(" beq NoInts%x\n",op); ot(" cmp r0,#6 ;@ irq>6 ?\n"); - ot(" ldrleb r1,[r7,#0x44] ;@ Get SR high: T_S__III\n"); ot(" andle r1,r1,#7 ;@ Get interrupt mask\n"); ot(" cmple r0,r1 ;@ irq<=6: Is irq<=mask ?\n"); ot(" blgt CycloneDoInterrupt\n"); @@ -113,15 +157,14 @@ static void PrintFramework() ot(" ldr r5,[r7,#0x5c] ;@ r5 = Cycles\n"); ot(" ldr r4,[r7,#0x40] ;@ r4 = Current PC + Memory Base\n"); ot(" ;@ r8 = Current Opcode\n"); - ot(" ldr r0,[r7,#0x44]\n"); + ot(" ldr r1,[r7,#0x44] ;@ Get SR high T_S__III and irq level\n"); ot(" mov r9,r9,lsl #28 ;@ r9 = Flags 0xf0000000, cpsr format\n"); ot(" ;@ r10 = Source value / Memory Base\n"); ot("\n"); ot(";@ CheckInterrupt:\n"); - ot(" movs r0,r0,lsr #24 ;@ Get IRQ level\n"); // same as ldrb r0,[r7,#0x47] + ot(" movs r0,r1,lsr #24 ;@ Get IRQ level\n"); // same as ldrb r0,[r7,#0x47] ot(" beq NoInts0\n"); ot(" cmp r0,#6 ;@ irq>6 ?\n"); - ot(" ldrleb r1,[r7,#0x44] ;@ Get SR high: T_S__III\n"); ot(" andle r1,r1,#7 ;@ Get interrupt mask\n"); ot(" cmple r0,r1 ;@ irq<=6: Is irq<=mask ?\n"); ot(" blgt CycloneDoInterrupt\n"); @@ -143,7 +186,7 @@ static void PrintFramework() ot("CycloneEnd%s\n", ms?"":":"); ot(" sub r4,r4,#2\n"); ot("CycloneEndNoBack%s\n", ms?"":":"); -#ifdef CYCLONE_FOR_PICODRIVE +#if (CYCLONE_FOR_GENESIS == 2) ot(" ldr r1,[r7,#0x54]\n"); ot(" mov r9,r9,lsr #28\n"); ot(" tst r1,r1\n"); @@ -173,7 +216,7 @@ static void PrintFramework() ot(" ldr r1,[r0,#-4]\n"); ot(" tst r1,r1\n"); ot(" movne pc,lr ;@ already uncompressed\n"); - ot(" add r3,r12,#0xa000*4 ;@ handler table pointer, r12=dest\n"); + ot(" add r3,r12,#0xa000*4 ;@ handler table pointer, r12=dest\n"); ot("unc_loop%s\n", ms?"":":"); ot(" ldrh r1,[r0],#2\n"); ot(" and r2,r1,#0xf\n"); @@ -261,6 +304,26 @@ static void PrintFramework() ot(" bx lr\n"); ot("\n"); + if (ms) ot("CycloneSetRealTAS\n"); + else ot("CycloneSetRealTAS:\n"); +#if (CYCLONE_FOR_GENESIS == 2) + ot(" ldr r12,=CycloneJumpTab\n"); + ot(" tst r0,r0\n"); + ot(" add r12,r12,#0x4a00*4\n"); + ot(" add r12,r12,#0x00d0*4\n"); + ot(" beq setrtas_off\n"); + ChangeTAS(1); + ot(" bx lr\n"); + ot("setrtas_off%s\n",ms?"":":"); + ChangeTAS(0); + ot(" bx lr\n"); + ltorg(); + ot("\n"); +#else + ot(" bx lr\n"); + ot("\n"); +#endif + ot(";@ DoInterrupt - r0=IRQ number\n"); ot("CycloneDoInterrupt%s\n", ms?"":":"); ot(" stmdb sp!,{lr} ;@ Push ARM return address\n"); @@ -319,17 +382,23 @@ int MemHandler(int type,int size) int func=0; func=0x68+type*0xc+(size<<2); // Find correct offset -#if MEMHANDLERS_NEED_PC - ot(" str r4,[r7,#0x40] ;@ Save PC\n"); -#endif #if MEMHANDLERS_NEED_FLAGS ot(" mov r3,r9,lsr #28\n"); ot(" strb r3,[r7,#0x46] ;@ Save Flags (NZCV)\n"); #endif -#if MEMHANDLERS_NEED_CYCLES - ot(" str r5,[r7,#0x5c] ;@ Save Cycles\n"); -#endif +#if (MEMHANDLERS_ADDR_MASK & 0xff000000) + ot(" bic r0,r0,#0x%08x\n", MEMHANDLERS_ADDR_MASK & 0xff000000); +#endif +#if (MEMHANDLERS_ADDR_MASK & 0x00ff0000) + ot(" bic r0,r0,#0x%08x\n", MEMHANDLERS_ADDR_MASK & 0x00ff0000); +#endif +#if (MEMHANDLERS_ADDR_MASK & 0x0000ff00) + ot(" bic r0,r0,#0x%08x\n", MEMHANDLERS_ADDR_MASK & 0x0000ff00); +#endif +#if (MEMHANDLERS_ADDR_MASK & 0x000000ff) + ot(" bic r0,r0,#0x%08x\n", MEMHANDLERS_ADDR_MASK & 0x000000ff); +#endif ot(" mov lr,pc\n"); ot(" ldr pc,[r7,#0x%x] ;@ Call ",func); @@ -472,90 +541,90 @@ static void PrintJumpTable() ot(";@ -------------------------- Jump Table --------------------------\n"); + // space for decompressed table + ot(ms?" area |.data|, data\n":" .data\n .align 4\n\n"); + #if COMPRESS_JUMPTABLE int handlers=0,reps=0,*indexes,ip,u,out; // use some weird compression on the jump table - indexes=(int *)malloc(0x10000*4); - if(!indexes) { printf("ERROR: out of memory\n"); exit(1); } - len=0x10000; + indexes=(int *)malloc(0x10000*4); + if(!indexes) { printf("ERROR: out of memory\n"); exit(1); } + len=0x10000; - // space for decompressed table - ot(ms?" area |.data|, data\n":" .data\n .align 4\n\n"); - - ot("CycloneJumpTab%s\n", ms?"":":"); - if(ms) { - for(i = 0; i < 0xa000/8; i++) - ot(" dcd 0,0,0,0,0,0,0,0\n"); - } else - ot(" .rept 0x%x\n .long 0,0,0,0,0,0,0,0\n .endr\n", 0xa000/8); + ot("CycloneJumpTab%s\n", ms?"":":"); + if(ms) { + for(i = 0; i < 0xa000/8; i++) + ot(" dcd 0,0,0,0,0,0,0,0\n"); + } else + ot(" .rept 0x%x\n .long 0,0,0,0,0,0,0,0\n .endr\n", 0xa000/8); // hanlers live in "a-line" part of the table - // first output nop,a-line,f-line handlers - ot(ms?" dcd Op____,Op__al,Op__fl,":" .long Op____,Op__al,Op__fl,"); - handlers=3; + // first output nop,a-line,f-line handlers + ot(ms?" dcd Op____,Op__al,Op__fl,":" .long Op____,Op__al,Op__fl,"); + handlers=3; - for(i=0;i=0; u--) if(op == CyJump[u]) break; // already done with this op? - if(u==-1 && op >= 0) { - ott("Op%.4x",op," ;@ %.4x\n",i,handlers,2); - indexes[op] = handlers; - handlers++; + for(u=i-1; u>=0; u--) if(op == CyJump[u]) break; // already done with this op? + if(u==-1 && op >= 0) { + ott("Op%.4x",op," ;@ %.4x\n",i,handlers,2); + indexes[op] = handlers; + handlers++; } - } - if(handlers&7) { - fseek(AsmFile, -1, SEEK_CUR); // remove last comma - for(i = 8-(handlers&7); i > 0; i--) - ot(",000000"); - ot("\n"); - } - if(ms) { - for(i = (0x4000-handlers)/8; i > 0; i--) - ot(" dcd 0,0,0,0,0,0,0,0\n"); - } else { - ot(ms?"":" .rept 0x%x\n .long 0,0,0,0,0,0,0,0\n .endr\n", (0x4000-handlers)/8); - } + } + if(handlers&7) { + fseek(AsmFile, -1, SEEK_CUR); // remove last comma + for(i = 8-(handlers&7); i > 0; i--) + ot(",000000"); + ot("\n"); + } + if(ms) { + for(i = (0x4000-handlers)/8; i > 0; i--) + ot(" dcd 0,0,0,0,0,0,0,0\n"); + } else { + ot(ms?"":" .rept 0x%x\n .long 0,0,0,0,0,0,0,0\n .endr\n", (0x4000-handlers)/8); + } printf("total distinct hanlers: %i\n",handlers); - // output data - for(i=0,ip=0; i < 0xf000; i++, ip++) { + // output data + for(i=0,ip=0; i < 0xf000; i++, ip++) { op=CyJump[i]; - if(op == -2) { - // it must skip a-line area, because we keep our data there - ott("0x%.4x", handlers<<4, "\n",0,ip++,1); - ott("0x%.4x", 0x1000, "\n",0,ip,1); - i+=0xfff; - continue; - } - for(reps=1; i < 0xf000; i++, reps++) if(op != CyJump[i+1]) break; - if(op>=0) out=indexes[op]<<4; else out=0; // unrecognised - if(reps <= 0xe || reps==0x10) { - if(reps!=0x10) out|=reps; else out|=0xf; // 0xf means 0x10 (0xf appeared to be unused anyway) - ott("0x%.4x", out, "\n",0,ip,1); + if(op == -2) { + // it must skip a-line area, because we keep our data there + ott("0x%.4x", handlers<<4, "\n",0,ip++,1); + ott("0x%.4x", 0x1000, "\n",0,ip,1); + i+=0xfff; + continue; + } + for(reps=1; i < 0xf000; i++, reps++) if(op != CyJump[i+1]) break; + if(op>=0) out=indexes[op]<<4; else out=0; // unrecognised + if(reps <= 0xe || reps==0x10) { + if(reps!=0x10) out|=reps; else out|=0xf; // 0xf means 0x10 (0xf appeared to be unused anyway) + ott("0x%.4x", out, "\n",0,ip,1); } else { - ott("0x%.4x", out, "\n",0,ip++,1); - ott("0x%.4x", reps,"\n",0,ip,1); - } + ott("0x%.4x", out, "\n",0,ip++,1); + ott("0x%.4x", reps,"\n",0,ip,1); + } } - if(ip&1) ott("0x%.4x", 0, "\n",0,ip++,1); - if(ip&7) fseek(AsmFile, -1, SEEK_CUR); // remove last comma - ot("\n"); - if(ip&7) { - for(i = 8-(ip&7); i > 0; i--) - ot(",0x0000"); - ot("\n"); - } - if(ms) { - for(i = (0x2000-ip/2)/8+1; i > 0; i--) - ot(" dcd 0,0,0,0,0,0,0,0\n"); - } else { - ot(" .rept 0x%x\n .long 0,0,0,0,0,0,0,0\n .endr\n", (0x2000-ip/2)/8+1); - } - ot("\n"); - free(indexes); + if(ip&1) ott("0x%.4x", 0, "\n",0,ip++,1); + if(ip&7) fseek(AsmFile, -1, SEEK_CUR); // remove last comma + ot("\n"); + if(ip&7) { + for(i = 8-(ip&7); i > 0; i--) + ot(",0x0000"); + ot("\n"); + } + if(ms) { + for(i = (0x2000-ip/2)/8+1; i > 0; i--) + ot(" dcd 0,0,0,0,0,0,0,0\n"); + } else { + ot(" .rept 0x%x\n .long 0,0,0,0,0,0,0,0\n .endr\n", (0x2000-ip/2)/8+1); + } + ot("\n"); + free(indexes); #else - ot("CycloneJumpTab%s\n", ms?"":":"); + ot("CycloneJumpTab%s\n", ms?"":":"); len=0xfffe; // Hmmm, armasm 2.50.8684 messes up with a 0x10000 long jump table // notaz: same thing with GNU as 2.9-psion-98r2 (reloc overflow) // this is due to COFF objects using only 2 bytes for reloc count @@ -569,7 +638,7 @@ static void PrintJumpTable() else if(op==-3) ott("Op__fl",0, " ;@ %.4x\n",i-7,i,2); else ott("Op____",0, " ;@ %.4x\n",i-7,i,2); } - if(i&7) fseek(AsmFile, -1, SEEK_CUR); // remove last comma + if(i&7) fseek(AsmFile, -1, SEEK_CUR); // remove last comma ot("\n"); ot(";@ notaz: we don't want to crash if we run into those 2 missing opcodes\n"); @@ -609,6 +678,7 @@ static int CycloneMake() ot(" export CycloneRun\n"); ot(" export CycloneSetSr\n"); ot(" export CycloneGetSr\n"); + ot(" export CycloneSetRealTAS\n"); ot(" export CycloneVer\n"); ot("\n"); ot("CycloneVer dcd 0x%.4x\n",CycloneVer); @@ -620,7 +690,8 @@ static int CycloneMake() ot(" .global CycloneSetSr\n"); ot(" .global CycloneGetSr\n"); ot(" .global CycloneVer\n"); -#ifdef CYCLONE_FOR_PICODRIVE +#if (CYCLONE_FOR_GENESIS == 2) + ot(" .global CycloneSetRealTAS\n"); ot(" .global CycloneDoInterrupt\n"); ot(" .global CycloneJumpTab\n"); #endif