From 21b261d0c97b4310751966a265e947e9367a2e59 Mon Sep 17 00:00:00 2001 From: redoste Date: Sun, 4 Jun 2023 19:41:17 +0200 Subject: [PATCH] gint/gdb: add half-baked GDB menu (display half of the values on mono) --- CMakeLists.txt | 2 + include/gintctl/gint.h | 3 ++ src/gint/gdb.S | 26 ++++++++++++ src/gint/gdb.c | 93 ++++++++++++++++++++++++++++++++++++++++++ src/gintctl.c | 1 + 5 files changed, 125 insertions(+) create mode 100644 src/gint/gdb.S create mode 100644 src/gint/gdb.c diff --git a/CMakeLists.txt b/CMakeLists.txt index fc66340..de21d85 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -26,6 +26,8 @@ set(SOURCES src/gint/dsp.c src/gint/dsp.s src/gint/dump.c + src/gint/gdb.S + src/gint/gdb.c src/gint/gray.c src/gint/image.c src/gint/keyboard.c diff --git a/include/gintctl/gint.h b/include/gintctl/gint.h index 25a4d9a..7518a92 100644 --- a/include/gintctl/gint.h +++ b/include/gintctl/gint.h @@ -71,4 +71,7 @@ void gintctl_gint_gray(void); void gintctl_gint_grayrender(void); +/* gintctl_gint_gdb(): GDB remote serial protocol */ +void gintctl_gint_gdb(void); + #endif /* GINTCTL_GINT */ diff --git a/src/gint/gdb.S b/src/gint/gdb.S new file mode 100644 index 0000000..1700365 --- /dev/null +++ b/src/gint/gdb.S @@ -0,0 +1,26 @@ +.text +.global _gintctl_gint_gdb_bank1_test + +_gintctl_gint_gdb_bank1_test: + // SR.RB = 0 + stc sr, r2 + mov r2, r1 + mov.l .sr_mask, r0 + or r0, r1 + ldc r1, sr + + // Now SR.RB = 1 + mov #0x13, r3 + mov #0x37, r4 + shll8 r3 + or r3, r4 + ldc r4, R0_BANK + + stc R2_BANK, r2 + ldc r2, sr + // Now SR.RB = 0 + rts + nop + +.align 4 +.sr_mask: .long (1 << 29) diff --git a/src/gint/gdb.c b/src/gint/gdb.c new file mode 100644 index 0000000..04ec59a --- /dev/null +++ b/src/gint/gdb.c @@ -0,0 +1,93 @@ +#include +#include +#include +#include +#include + +#include +#include +#include + +#ifdef FXCG50 +static void val(int y, const char *name, uint32_t value) +{ + dtext(0, 20 + y*12, C_BLACK, name); + dprint(88, 20 + y*12, C_BLACK, "%08X", value); +} +#else +static void val(int y, const char *name, uint32_t value) +{ + dtext(0, 8 + y*6, C_BLACK, name); + dprint(40, 8 + y*6, C_BLACK, "%08X", value); +} +#endif + +#define reg(y,n,v) val(y,n,v.lword) + +extern int (*gint_exc_catcher)(uint32_t code); + +int gintctl_gint_gdb_bank1_test(void); + +void gintctl_gint_gdb(void) +{ + int key = 0; + int ret = -1; + while (key != KEY_EXIT) { + dclear(C_WHITE); +#ifdef FXCG50 + row_title("GDB remote serial protocol"); +#else + row_title("GDB"); +#endif + +#ifdef FXCG50 + fkey_action(6, "START"); + fkey_action(5, "PANICR"); + fkey_action(4, "PANICW"); + fkey_action(1, "BANK 1"); +#endif + +#ifdef FX9860G + font_t const *old_font = dfont(&font_mini); +#endif + val(0, "ret", ret); + reg(1, "MSTPCR0", SH7305_POWER.MSTPCR0); + reg(2, "CBR0", SH7305_UBC.CBR0); + reg(3, "CRR0", SH7305_UBC.CRR0); + val(4, "CAR0", SH7305_UBC.CAR0); + val(5, "CAMR0", SH7305_UBC.CAMR0); + reg(6, "CBR1", SH7305_UBC.CBR1); + reg(7, "CRR1", SH7305_UBC.CRR1); + val(8, "CAR1", SH7305_UBC.CAR1); + val(9, "CAMR1", SH7305_UBC.CAMR1); + val(10, "CDR1", SH7305_UBC.CDR1); + val(11, "CDMR1", SH7305_UBC.CDMR1); + reg(12, "CETR1", SH7305_UBC.CETR1); + reg(13, "CCMFR", SH7305_UBC.CCMFR); + reg(14, "CBCR", SH7305_UBC.CBCR); + val(15, "DBR", (uint32_t) ubc_getDBR()); + +#ifdef FXCG50 + dprint(176, 20, C_BLACK, "exc_catcher: %p", gint_exc_catcher); +#endif + +#ifdef FX9860G + dfont(old_font); +#endif + dupdate(); + + key_event_t ev = gintctl_getkey(); + key = ev.key; + + volatile uint32_t* miss = (void*)0x41414140; + if (key == KEY_F6) { + ret = gdb_start(); + } else if (key == KEY_F5) { + ret = *miss; + } else if (key == KEY_F4) { + *miss = 0x1337; + } else if (key == KEY_F1) { + ret = gintctl_gint_gdb_bank1_test(); + } + } +} diff --git a/src/gintctl.c b/src/gintctl.c index e3197b5..f60a5a6 100644 --- a/src/gintctl.c +++ b/src/gintctl.c @@ -61,6 +61,7 @@ struct menu menu_gint = { #if GINT_RENDER_MONO { "Gray rendering", gintctl_gint_grayrender, 0 }, #endif + { "GDB", gintctl_gint_gdb, 0}, { NULL, NULL, 0 }, }};