X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=cpu%2FCyclone%2FMain.cpp;h=5647fb1d3accc1a6e756856f1bef87983a46aa97;hb=547045e3c65ca34ea2a02a4da55c27aa94d8f316;hp=9bcf2054a951f0286d586fa441d04be2643e0dbe;hpb=2c559c66ef1e7021f92e40244100f60c774fdd2c;p=picodrive.git diff --git a/cpu/Cyclone/Main.cpp b/cpu/Cyclone/Main.cpp index 9bcf205..5647fb1 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); @@ -97,9 +102,10 @@ static void PrintException(int ints) 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"); +// 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"); + ot(" sub r1,r4,r10 ;@ r1 = Old PC\n"); OpPush32(); OpPushSr(1); ot(" mov r0,r11\n"); @@ -142,6 +148,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 +278,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 +293,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 +312,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 +383,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 +392,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 +401,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 +437,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 +687,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"); @@ -700,7 +725,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");