X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=cpu%2FCyclone%2FMain.cpp;h=96de268c12c3d027b9ed0f58c50c9fff2abbc882;hb=c6a4c892866387e150ffcaa3af8b8c18d9ec6d58;hp=e4f7107806ef5e0993c95d7c474e72eaac6cbd47;hpb=a9a5a6e0b1788acaf45adaa84a7c2bc9541e5abc;p=picodrive.git diff --git a/cpu/Cyclone/Main.cpp b/cpu/Cyclone/Main.cpp index e4f7107..96de268 100644 --- a/cpu/Cyclone/Main.cpp +++ b/cpu/Cyclone/Main.cpp @@ -3,12 +3,14 @@ static FILE *AsmFile=NULL; -static int CycloneVer=0x0086; // Version number of library +static int CycloneVer=0x0087; // Version number of library int *CyJump=NULL; // Jump table int ms=USE_MS_SYNTAX; // If non-zero, output in Microsoft ARMASM format char *Narm[4]={ "b", "h","",""}; // Normal ARM Extensions for operand sizes 0,1,2 char *Sarm[4]={"sb","sh","",""}; // Sign-extend ARM Extensions for operand sizes 0,1,2 int Cycles; // Current cycles for opcode +int pc_dirty; // something changed PC during processing +static int arm_op_count; void ot(const char *format, ...) @@ -21,6 +23,9 @@ void ot(const char *format, ...) for(i=0, len=strlen(format); i < len && format[i] != '\n'; i++); if(i < len-1 && format[len-1] != '\n') printf("\nWARNING: possible improper newline placement:\n%s\n", format); + if (format[0] == ' ' && format[1] == ' ' && format[2] != ' ' && format[2] != '.') + arm_op_count++; + va_start(valist,format); if (AsmFile) vfprintf(AsmFile,format,valist); va_end(valist); @@ -142,6 +147,15 @@ void CheckInterrupt(int op) ot("\n"); } +void FlushPC(void) +{ +#if MEMHANDLERS_NEED_PC + if (pc_dirty) + ot(" str r4,[r7,#0x40] ;@ Save PC\n"); +#endif + pc_dirty = 0; +} + static void PrintFramework() { ot(";@ --------------------------- Framework --------------------------\n"); @@ -263,6 +277,7 @@ static void PrintFramework() ot(" bx lr\n"); ot("\n"); #endif + // 68k: XNZVC, ARM: NZCV if (ms) ot("CycloneSetSr\n"); else ot("CycloneSetSr:\n"); ot(" mov r2,r1,lsr #8\n"); @@ -277,8 +292,8 @@ static void PrintFramework() ot(" str r3,[r0,#0x3C]\n"); ot(" str r2,[r0,#0x48]\n"); ot("setsr_noswap%s\n",ms?"":":"); - ot(" mov r2,r1,lsr #3\n"); - ot(" strb r2,[r0,#0x45] ;@ the X flag\n"); + ot(" mov r2,r1,lsl #25\n"); + ot(" str r2,[r0,#0x4c] ;@ the X flag\n"); ot(" bic r2,r1,#0xf3\n"); ot(" tst r1,#1\n"); ot(" orrne r2,r2,#2\n"); @@ -296,8 +311,8 @@ static void PrintFramework() ot(" orrne r2,r2,#2\n"); ot(" tst r1,#2\n"); ot(" orrne r2,r2,#1\n"); - ot(" ldrb r1,[r0,#0x45] ;@ the X flag\n"); - ot(" tst r1,#2\n"); + ot(" ldr r1,[r0,#0x4c] ;@ the X flag\n"); + ot(" tst r1,#0x20000000\n"); ot(" orrne r2,r2,#0x10\n"); ot(" ldrb r1,[r0,#0x44] ;@ the SR high\n"); ot(" orr r0,r2,r1,lsl #8\n"); @@ -367,7 +382,6 @@ static void PrintFramework() ot("\n"); ot("Exception%s\n", ms?"":":"); - ot("\n"); ot(" stmdb sp!,{lr} ;@ Preserve ARM return address\n"); PrintException(0); ot(" ldmia sp!,{pc} ;@ Return\n"); @@ -377,7 +391,7 @@ static void PrintFramework() // --------------------------------------------------------------------------- // Call Read(r0), Write(r0,r1) or Fetch(r0) // Trashes r0-r3,r12,lr -int MemHandler(int type,int size) +int MemHandler(int type,int size,int addrreg) { int func=0; func=0x68+type*0xc+(size<<2); // Find correct offset @@ -386,20 +400,31 @@ int MemHandler(int type,int size) ot(" mov r3,r9,lsr #28\n"); ot(" strb r3,[r7,#0x46] ;@ Save Flags (NZCV)\n"); #endif + FlushPC(); #if (MEMHANDLERS_ADDR_MASK & 0xff000000) - ot(" bic r0,r0,#0x%08x\n", MEMHANDLERS_ADDR_MASK & 0xff000000); + ot(" bic r0,r%i,#0x%08x\n", addrreg, MEMHANDLERS_ADDR_MASK & 0xff000000); + addrreg=0; #endif #if (MEMHANDLERS_ADDR_MASK & 0x00ff0000) - ot(" bic r0,r0,#0x%08x\n", MEMHANDLERS_ADDR_MASK & 0x00ff0000); + ot(" bic r0,r%i,#0x%08x\n", addrreg, MEMHANDLERS_ADDR_MASK & 0x00ff0000); + addrreg=0; #endif #if (MEMHANDLERS_ADDR_MASK & 0x0000ff00) - ot(" bic r0,r0,#0x%08x\n", MEMHANDLERS_ADDR_MASK & 0x0000ff00); + ot(" bic r0,r%i,#0x%08x\n", addrreg, MEMHANDLERS_ADDR_MASK & 0x0000ff00); + addrreg=0; #endif #if (MEMHANDLERS_ADDR_MASK & 0x000000ff) - ot(" bic r0,r0,#0x%08x\n", MEMHANDLERS_ADDR_MASK & 0x000000ff); + ot(" bic r0,r%i,#0x%08x\n", addrreg, MEMHANDLERS_ADDR_MASK & 0x000000ff); + addrreg=0; #endif - ot(" mov lr,pc\n"); + if (addrreg != 0) + { + ot(" add lr,pc,#4\n"); // helps to prevent interlocks + ot(" mov r0,r%i\n", addrreg); + } + else + ot(" mov lr,pc\n"); ot(" ldr pc,[r7,#0x%x] ;@ Call ",func); // Document what we are calling: @@ -411,9 +436,6 @@ int MemHandler(int type,int size) else ot("%d(r0)", 8<