From 524d4a27e4e5a27ea10c9486e775789a6aa65e4d Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Wed, 6 Feb 2019 22:53:44 -0500 Subject: [PATCH] halt_printf, control-c, etc set a halt bit. This now invokes the debugger, asynchronously (ie, after the current instruction finishes execution). --- src/debug_shell.re2c | 6 ++++++ src/defcomm.h | 3 +-- src/engine_c.c | 3 ++- src/sim65816.c | 25 +++++++++++-------------- 4 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/debug_shell.re2c b/src/debug_shell.re2c index 5ecf337..472607a 100644 --- a/src/debug_shell.re2c +++ b/src/debug_shell.re2c @@ -876,6 +876,12 @@ int debug_shell(int code) { } printf("%06x: %0*x\n", g_abort_address, g_abort_bytes * 2, g_abort_value); } + if (code == RET_BRK) { + /* hit a BRK op */ + } + if (code == RET_HALT) { + /* halt_printf */ + } do_list(engine.kpc, &psr, 1); diff --git a/src/defcomm.h b/src/defcomm.h index ae86aef..aaca6c0 100644 --- a/src/defcomm.h +++ b/src/defcomm.h @@ -88,8 +88,7 @@ #define RET_MVN 0x5 #define RET_WAI 0x6 #define RET_STP 0x7 -#define RET_ADD_DEC_8 0x8 -#define RET_ADD_DEC_16 0x9 +#define RET_HALT 0x8 #define RET_C700 0xa #define RET_C70A 0xb #define RET_C70D 0xc diff --git a/src/engine_c.c b/src/engine_c.c index 511e7f1..a4cf77c 100644 --- a/src/engine_c.c +++ b/src/engine_c.c @@ -880,7 +880,8 @@ word32 get_itimer() { } void set_halt_act(int val) { - if(val == 1 && g_ignore_halts && !g_user_halt_bad) { + extern int g_dbg_shell; + if(val == 1 && g_ignore_halts && !g_user_halt_bad && !g_dbg_shell) { g_code_red++; } else { halt_sim |= val; diff --git a/src/sim65816.c b/src/sim65816.c index 1e83171..7cc7ddf 100644 --- a/src/sim65816.c +++ b/src/sim65816.c @@ -1514,11 +1514,11 @@ int run_prog() { ret >>= 28; } - if(halt_sim == HALT_EVENT) { + if(halt_sim & HALT_EVENT) { g_engine_halt_event++; /* if we needed to stop to check for interrupts, */ /* clear halt */ - halt_sim = 0; + halt_sim &= ~HALT_EVENT; } #if 0 @@ -1535,7 +1535,7 @@ int run_prog() { this_event = g_event_start.next; while(dcycs >= this_event->dcycs) { - if(halt_sim != 0 && halt_sim != HALT_EVENT) { + if(halt_sim & ~HALT_EVENT) { break; } if(g_stepping) { @@ -1605,9 +1605,7 @@ int run_prog() { } #endif - if(halt_sim != 0 && halt_sim != HALT_EVENT) { - break; - } + if (ret == RET_MP) break; if (ret == RET_BP) break; engine.flags &= ~(FLAG_IGNORE_BP | FLAG_IGNORE_MP); @@ -1615,6 +1613,12 @@ int run_prog() { ret = 0; break; } + if(halt_sim & 0x07) { + halt_sim &= ~0x07; + ret = RET_HALT; + break; + } + } #if 0 @@ -2256,14 +2260,6 @@ void handle_action(word32 ret) { case RET_C70D: do_c70d(ret); break; -#if 0 - case RET_ADD_DEC_8: - do_add_dec_8(ret); - break; - case RET_ADD_DEC_16: - do_add_dec_16(ret); - break; -#endif case RET_IRQ: irq_printf("Special fast IRQ response. irq_pending: %x\n", g_irq_pending); @@ -2277,6 +2273,7 @@ void handle_action(word32 ret) { case RET_BP: case RET_MP: case RET_BRK: + case RET_HALT: /* handled elsewhere */ break; default: