X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=cpu%2Ffame%2Ffamec.c;h=508a12f7bfcf653ce0205b44801e0b989ced1a8e;hb=12f23dac6f91eb707f985ef00a5d48e9e5ef8838;hp=6891526014c5e14e8edb8c34269ea15643856a40;hpb=9a1f192a146e9b9752ec1a760745b1261fe9bdec;p=picodrive.git diff --git a/cpu/fame/famec.c b/cpu/fame/famec.c index 6891526..508a12f 100644 --- a/cpu/fame/famec.c +++ b/cpu/fame/famec.c @@ -35,7 +35,17 @@ #define PICODRIVE_HACK // Options // - +#ifndef FAMEC_NO_GOTOS +// computed gotos is a GNU extension +#ifndef __GNUC__ +#define FAMEC_NO_GOTOS +#endif +// as of 3.3, clang takes over 3h to compile this in computed goto mode.. +#ifdef __clang__ +#define FAMEC_NO_GOTOS +#endif +#endif + #undef INLINE #ifdef _MSC_VER #define INLINE @@ -546,7 +556,7 @@ M68K_CONTEXT *g_m68kcontext; static u32 initialised = 0; #ifdef PICODRIVE_HACK -extern M68K_CONTEXT PicoCpuFM68k, PicoCpuFS68k; +extern M68K_CONTEXT PicoCpuFS68k; #endif /* Custom function handler */ @@ -630,6 +640,7 @@ static const s32 exception_cycle_table[256] = 4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4,4 }; +static int init_jump_table(void); /***********************/ /* core main functions */ @@ -646,8 +657,8 @@ void fm68k_init(void) puts("Initializing FAME..."); #endif - if (!initialised) - fm68k_emulate(0, 0, 0); + if (!initialised) + init_jump_table(); #ifdef FAMEC_DEBUG puts("FAME initialized."); @@ -663,10 +674,12 @@ void fm68k_init(void) /* M68K_NO_SUP_ADDR_SPACE (2): No se puede resetear porque no hay mapa */ /* de memoria supervisor de extraccion de opcodes */ /******************************************************************************/ -int fm68k_reset(void) +int fm68k_reset(M68K_CONTEXT *ctx) { if (!initialised) - fm68k_emulate(0, 0, 0); + init_jump_table(); + + g_m68kcontext = ctx; // Si la CPU esta en ejecucion, salir con M68K_RUNNING if (m68kcontext.execinfo & M68K_RUNNING) @@ -721,7 +734,7 @@ static FAMEC_EXTRA_INLINE s32 interrupt_chk__(void) return 0; } -int fm68k_would_interrupt(void) +int fm68k_would_interrupt(M68K_CONTEXT *ctx) { return interrupt_chk__(); } @@ -732,6 +745,9 @@ static FAMEC_EXTRA_INLINE u32 execute_exception(s32 vect, u32 oldPC, u32 oldSR) //u32 oldSR = GET_SR; m68kcontext.io_cycle_counter -= exception_cycle_table[vect]; +#ifdef FAMEC_EMULATE_TRACE + m68kcontext.execinfo &= ~FM68K_EMULATE_TRACE; +#endif PRE_IO @@ -753,6 +769,7 @@ static FAMEC_EXTRA_INLINE u32 execute_exception(s32 vect, u32 oldPC, u32 oldSR) /* adjust SR */ flag_S = M68K_SR_S; + flag_T = 0; #ifndef FAMEC_32BIT_PC newPC&=M68K_ADR_MASK @@ -794,7 +811,7 @@ static FAMEC_EXTRA_INLINE u32 execute_exception_group_0(s32 vect, s32 addr, u16 // main exec function ////////////////////// -int fm68k_emulate(s32 cycles, int dualcore, int idle_mode) +int fm68k_emulate(M68K_CONTEXT *ctx, s32 cycles, fm68k_call_reason reason) { #ifndef FAMEC_NO_GOTOS u32 Opcode; @@ -806,19 +823,23 @@ int fm68k_emulate(s32 cycles, int dualcore, int idle_mode) u32 flag_NotZ; u32 flag_N; u32 flag_X; -#endif - if (!initialised) + switch (reason) { + case fm68k_reason_init: goto init_jump_table; - } - #ifdef PICODRIVE_HACK - if (dualcore) goto dualcore_mode; - if (idle_mode == 1) goto idle_install; - else if (idle_mode == 2) goto idle_remove; -famec_restart: + case fm68k_reason_idle_install: + goto idle_install; + case fm68k_reason_idle_remove: + goto idle_remove; #endif + case fm68k_reason_emulate: + break; + } +#endif // FAMEC_NO_GOTOS + + g_m68kcontext = ctx; // won't emulate double fault // if (m68kcontext.execinfo & M68K_FAULTED) return -1; @@ -908,12 +929,11 @@ famec_Exec: #ifdef FAMEC_EMULATE_TRACE if (m68kcontext.execinfo & FM68K_EMULATE_TRACE) { - m68kcontext.io_cycle_counter = cycles_needed; + m68kcontext.io_cycle_counter += cycles_needed; cycles_needed = 0; m68kcontext.execinfo &= ~FM68K_EMULATE_TRACE; m68kcontext.execinfo |= FM68K_DO_TRACE; SET_PC(execute_exception(M68K_TRACE_EX, GET_PC, GET_SR)); - flag_T=0; if (m68kcontext.io_cycle_counter > 0) { //NEXT @@ -925,9 +945,9 @@ famec_Exec: if (cycles_needed != 0) { u32 line; - m68kcontext.io_cycle_counter = cycles_needed; + m68kcontext.io_cycle_counter += cycles_needed; cycles_needed = 0; - if (m68kcontext.io_cycle_counter <= 0) goto famec_End; + //if (m68kcontext.io_cycle_counter <= 0) goto famec_End; line=interrupt_chk__(); if (line>0) { @@ -962,60 +982,15 @@ famec_End: printf("pc: 0x%08x\n",m68kcontext.pc); #endif -#ifdef PICODRIVE_HACK - if (!dualcore) -#endif - return cycles - m68kcontext.io_cycle_counter; + return cycles - m68kcontext.io_cycle_counter; -#ifdef PICODRIVE_HACK -dualcore_mode: +#ifndef FAMEC_NO_GOTOS +init_jump_table: +#else +} - while (1) - { - extern int SekCycleAim, SekCycleCnt, SekCycleAimS68k, SekCycleCntS68k; - #define PS_STEP_M68K ((488<<16)/20) // ~24 - if (dualcore == 1) - { - dualcore = (488<<16); // ~ cycn in Pico.c - // adjust for first iteration - g_m68kcontext = &PicoCpuFS68k; - cycles = m68kcontext.io_cycle_counter = 0; - } - if (g_m68kcontext == &PicoCpuFS68k) - { - SekCycleCntS68k += cycles - m68kcontext.io_cycle_counter; - // end? - dualcore -= PS_STEP_M68K; - if (dualcore < 0) return 0; - // become main 68k - g_m68kcontext = &PicoCpuFM68k; - if ((cycles = SekCycleAim-SekCycleCnt-(dualcore>>16)) > 0) - { - if ((m68kcontext.execinfo & FM68K_HALTED) && m68kcontext.interrupts[0] <= (M68K_PPL)) - SekCycleCnt += cycles; // halted - else goto famec_restart; - //else { printf("go main %i\n", cycles); goto famec_restart; } - } - cycles = m68kcontext.io_cycle_counter = 0; - } - if (g_m68kcontext == &PicoCpuFM68k) - { - int cycn_s68k = (dualcore + dualcore/2 + dualcore/8) >> 16; - SekCycleCnt += cycles - m68kcontext.io_cycle_counter; - // become sub 68k - g_m68kcontext = &PicoCpuFS68k; - if ((cycles = SekCycleAimS68k-SekCycleCntS68k-cycn_s68k) > 0) - { - if ((m68kcontext.execinfo & FM68K_HALTED) && m68kcontext.interrupts[0] <= (M68K_PPL)) - SekCycleCntS68k += cycles; // halted - else goto famec_restart; - } - cycles = m68kcontext.io_cycle_counter = 0; - } - } +static int init_jump_table(void) #endif - -init_jump_table: { u32 i, j; @@ -5045,7 +5020,12 @@ init_jump_table: JumpTable[fake_op_base] = JumpTable[fake_op_base|0x0200] = CAST_OP(0x4AFC); \ JumpTable[real_op] = CAST_OP(normal_handler) +#ifndef FAMEC_NO_GOTOS idle_install: +#else +int fm68k_idle_install(void) +#endif +{ // printf("install..\n"); INSTALL_IDLE(0x71fa, 0x66fa, idle_detector_bcc8, 0x6601_idle, 0x6601); INSTALL_IDLE(0x71f8, 0x66f8, idle_detector_bcc8, 0x6601_idle, 0x6601); @@ -5058,8 +5038,14 @@ idle_install: INSTALL_IDLE(0x7dfe, 0x60fe, idle_detector_bcc8, 0x6001_idle, 0x6001); INSTALL_IDLE(0x7dfc, 0x60fc, idle_detector_bcc8, 0x6001_idle, 0x6001); return 0; +} +#ifndef FAMEC_NO_GOTOS idle_remove: +#else +int fm68k_idle_remove(void) +#endif +{ // printf("remove..\n"); UNDO_IDLE(0x71fa, 0x66fa, 0x6601); UNDO_IDLE(0x71f8, 0x66f8, 0x6601); @@ -5072,9 +5058,26 @@ idle_remove: UNDO_IDLE(0x7dfe, 0x60fe, 0x6001); UNDO_IDLE(0x7dfc, 0x60fc, 0x6001); return 0; +} +#endif // PICODRIVE_HACK -#endif +#ifndef FAMEC_NO_GOTOS +} + +static int init_jump_table(void) +{ + return fm68k_emulate(NULL, 0, fm68k_reason_init); } -void *get_jumptab(void) { return JumpTable; } +#ifdef PICODRIVE_HACK +int fm68k_idle_install(void) +{ + return fm68k_emulate(NULL, 0, fm68k_reason_idle_install); +} +int fm68k_idle_remove(void) +{ + return fm68k_emulate(NULL, 0, fm68k_reason_idle_remove); +} +#endif +#endif // FAMEC_NO_GOTOS