X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=cpu%2FCyclone%2FMain.cpp;h=5fed8ee1a02badb0c6aa1e58ebef4ba8417fe08d;hb=ee5e024ce624b4a5e5efc38e5d7c6a040a48a8b0;hp=1d0318cacf9f9ea5fbbb0878907c71c5c4714e67;hpb=a67855765d6106f3fd8737ec35c2165460d2705f;p=picodrive.git diff --git a/cpu/Cyclone/Main.cpp b/cpu/Cyclone/Main.cpp index 1d0318c..5fed8ee 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 +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); @@ -32,7 +37,7 @@ void ltorg() else ot(" .ltorg\n"); } -#if CYCLONE_FOR_GENESIS +#if (CYCLONE_FOR_GENESIS == 2) // r12=ptr to tas in table, trashes r0,r1 static void ChangeTAS(int norm) { @@ -85,23 +90,22 @@ static void PrintException(int ints) ot(" mov r11,r0\n"); } - ot(";@ swap OSP <-> A7?\n"); ot(" ldr r0,[r7,#0x44] ;@ Get SR high\n"); - ot(" tst r0,#0x20\n"); - ot(" bne no_sp_swap%i\n",ints); - ot(";@ swap OSP and A7:\n"); - ot(" ldr r0,[r7,#0x3C] ;@ Get A7\n"); - ot(" ldr r1,[r7,#0x48] ;@ Get OSP\n"); - ot(" str r0,[r7,#0x48]\n"); - ot(" str r1,[r7,#0x3C]\n"); - ot("no_sp_swap%i%s\n",ints,ms?"":":"); - ot(" ldr r10,[r7,#0x60] ;@ Get Memory base\n"); - ot(" mov r1,r4,lsl #8\n"); - ot(" sub r1,r1,r10,lsl #8 ;@ r1 = Old PC\n"); - ot(" mov r1,r1,asr #8 ;@ push sign extended\n"); - OpPush32(); + ot(" tst r0,#0x20\n"); + ot(";@ get our SP:\n"); + ot(" ldr r0,[r7,#0x3c] ;@ Get A7\n"); + ot(" ldreq r1,[r7,#0x48] ;@ ...or OSP as our stack pointer\n"); + ot(" streq r0,[r7,#0x48]\n"); + ot(" moveq r0,r1\n"); + + ot(" sub r1,r4,r10 ;@ r1 = Old PC\n"); + ot(";@ Push r1 onto stack\n"); + ot(" sub r0,r0,#4 ;@ Predecrement A7\n"); + ot(" str r0,[r7,#0x3c] ;@ Save A7\n"); + MemHandler(1,2); OpPushSr(1); + ot(" mov r0,r11\n"); ot(";@ Read IRQ Vector:\n"); MemHandler(0,2); @@ -116,6 +120,8 @@ static void PrintException(int ints) ot(" mov lr,pc\n"); ot(" ldr pc,[r7,#0x64] ;@ Call checkpc()\n"); ot(" mov r4,r0\n"); +#else + ot(" add r4,r0,r10 ;@ r4 = Memory Base + New PC\n"); #endif ot("\n"); @@ -127,19 +133,13 @@ static void PrintException(int ints) } } -// Trashes r0,r1 -void CheckInterrupt(int op) +void FlushPC(void) { - ot(";@ CheckInterrupt:\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(" andle r1,r1,#7 ;@ Get interrupt mask\n"); - ot(" cmple r0,r1 ;@ irq<=6: Is irq<=mask ?\n"); - ot(" blgt CycloneDoInterrupt\n"); - ot("NoInts%x%s\n", op,ms?"":":"); - ot("\n"); +#if MEMHANDLERS_NEED_PC + if (pc_dirty) + ot(" str r4,[r7,#0x40] ;@ Save PC\n"); +#endif + pc_dirty = 0; } static void PrintFramework() @@ -167,10 +167,7 @@ static void PrintFramework() ot(" cmp r0,#6 ;@ irq>6 ?\n"); ot(" andle r1,r1,#7 ;@ Get interrupt mask\n"); ot(" cmple r0,r1 ;@ irq<=6: Is irq<=mask ?\n"); - ot(" blgt CycloneDoInterrupt\n"); - ot(";@ Check if interrupt used up all the cycles:\n"); - ot(" subs r5,r5,#0\n"); - ot(" blt CycloneEndNoBack\n"); + ot(" bgt CycloneDoInterrupt\n"); ot("NoInts0%s\n", ms?"":":"); ot("\n"); ot(";@ Check if our processor is in stopped state and jump to opcode handler if not\n"); @@ -186,7 +183,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"); @@ -263,6 +260,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 +275,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 +294,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"); @@ -306,7 +304,7 @@ static void PrintFramework() if (ms) ot("CycloneSetRealTAS\n"); else ot("CycloneSetRealTAS:\n"); -#if CYCLONE_FOR_GENESIS +#if (CYCLONE_FOR_GENESIS == 2) ot(" ldr r12,=CycloneJumpTab\n"); ot(" tst r0,r0\n"); ot(" add r12,r12,#0x4a00*4\n"); @@ -325,9 +323,9 @@ static void PrintFramework() #endif ot(";@ DoInterrupt - r0=IRQ number\n"); + ot("CycloneDoInterruptGoBack%s\n", ms?"":":"); + ot(" sub r4,r4,#2\n"); ot("CycloneDoInterrupt%s\n", ms?"":":"); - ot(" stmdb sp!,{lr} ;@ Push ARM return address\n"); - ot(";@ Get IRQ Vector address:\n"); ot(" mov r0,r0,asl #2\n"); ot(" add r11,r0,#0x60\n"); @@ -340,7 +338,6 @@ static void PrintFramework() ot(";@ Clear stopped states:\n"); ot(" str r2,[r7,#0x58]\n"); - ot(" sub r5,r5,#%d ;@ Subtract cycles\n",44); ot("\n"); #if USE_INT_ACK_CALLBACK #if INT_ACK_NEEDS_STUFF @@ -359,15 +356,17 @@ static void PrintFramework() ot(" mov r9,r9,lsl #28\n"); ot(" ldr r4,[r7,#0x40] ;@ Load PC\n"); #endif -#else // not USE_INT_ACK_CALLBACK +#else // !USE_INT_ACK_CALLBACK ot(";@ Clear irq:\n"); - ot(" strb r1,[r7,#0x47]\n"); + ot(" strb r2,[r7,#0x47]\n"); #endif - ot(" ldmia sp!,{pc} ;@ Return\n"); + ot(" ldrh r8,[r4],#2 ;@ Fetch next opcode\n"); + ot(" subs r5,r5,#44 ;@ Subtract cycles\n"); + ot(" ldrge pc,[r6,r8,asl #2] ;@ Jump to opcode handler\n"); + ot(" b CycloneEnd\n"); 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 +376,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 +385,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 +421,6 @@ int MemHandler(int type,int size) else ot("%d(r0)", 8< 0; i--) ot(",0x0000"); - ot("\n"); } + 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"); @@ -662,7 +671,7 @@ static int CycloneMake() ot("\n;@ Dave's Cyclone 68000 Emulator v%x.%.3x - Assembler Output\n\n",CycloneVer>>12,CycloneVer&0xfff); ot(";@ (c) Copyright 2003 Dave, All rights reserved.\n"); - ot(";@ some code (c) Copyright 2005-2006 notaz, All rights reserved.\n"); + ot(";@ some code (c) Copyright 2005-2007 notaz, All rights reserved.\n"); ot(";@ Cyclone 68000 is free for non-commercial use.\n\n"); ot(";@ For commercial use, separate licencing terms must be obtained.\n\n"); @@ -689,9 +698,9 @@ static int CycloneMake() ot(" .global CycloneRun\n"); ot(" .global CycloneSetSr\n"); ot(" .global CycloneGetSr\n"); - ot(" .global CycloneSetRealTAS\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 @@ -700,7 +709,9 @@ static int CycloneMake() ot("\n"); PrintFramework(); + arm_op_count = 0; PrintOpcodes(); + printf("~%i ARM instructions used for opcode handlers\n", arm_op_count); PrintJumpTable(); if (ms) ot(" END\n");