From 4068afb39f26d82fdebf3d036a7075dbca729f2c Mon Sep 17 00:00:00 2001 From: CrashOveride95 Date: Fri, 16 Apr 2021 20:50:06 -0400 Subject: [PATCH] Start GDB work (broken rn) --- Makefile | 13 +++++- sm64.ld | 80 ++++++++++++++++++------------------- src/game/main.c | 12 ++++++ src/{usb => gdb}/debugger.c | 1 + src/{usb => gdb}/debugger.h | 0 src/{usb => gdb}/serial.c | 2 +- src/{usb => gdb}/serial.h | 2 +- 7 files changed, 67 insertions(+), 43 deletions(-) rename src/{usb => gdb}/debugger.c (99%) rename src/{usb => gdb}/debugger.h (100%) rename src/{usb => gdb}/serial.c (99%) rename src/{usb => gdb}/serial.h (96%) diff --git a/Makefile b/Makefile index aaab3d93..074ee167 100644 --- a/Makefile +++ b/Makefile @@ -131,7 +131,7 @@ endif ifeq ($(COMPILER),gcc) NON_MATCHING := 1 MIPSISET := -mips3 - OPT_FLAGS := -O2 + OPT_FLAGS := -O2 -g endif @@ -174,6 +174,17 @@ ifeq ($(UNF),1) USE_DEBUG := 1 endif +# GDB - whether to use GDB + UNFLoader +# 1 - includes code in ROM +# 0 - does not +GDB ?= 0 +$(eval $(call validate-option,GDB,0 1)) +ifeq ($(GDB),1) + DEFINES += GDB=1 + SRC_DIRS += src/gdb + USE_DEBUG := 1 +endif + # ISVPRINT - whether to fake IS-Viewer presence, # allowing for usage of CEN64 (and possibly Project64) to print messages to terminal. diff --git a/sm64.ld b/sm64.ld index f2aaeabb..bd73f781 100755 --- a/sm64.ld +++ b/sm64.ld @@ -125,90 +125,63 @@ SECTIONS KEEP(BUILD_DIR/asm/entry.o(.text)); BUILD_DIR/src/game*.o(.text); -#ifdef HVQM BUILD_DIR/src/hvqm*.o(.text); -#endif -#ifdef UNF + BUILD_DIR/src/gdb*.o(.text); BUILD_DIR/src/usb*.o(.text); -#endif BUILD_DIR/src/audio*.o(.text); -#if defined(ISVPRINT) || defined(UNF) +#if defined(ISVPRINT) || defined(UNF) || defined(GDB) */libultra_d.a:*.o(.text); #else */libultra_rom.a:*.o(.text); #endif */libnustd.a:*.o(.text); */libgcc.a:*.o(.text); -#ifdef GZIP */libz.a:*.o(.text); -#endif -#ifdef HVQM */libhvqm2.a:*.o(.text); -#endif - BUILD_DIR/lib/rsp.o(.text); lib/PR/hvqm/hvqm2sp1.o(.text); /* data */ BUILD_DIR/src/game*.o(.*data*); -#ifdef UNF + BUILD_DIR/src/gdb*.o(.*data*); BUILD_DIR/src/usb*.o(.*data*); -#endif BUILD_DIR/src/audio*.o(.*data*); -#ifdef GZIP - */libz.a:*.o(.*data*); -#endif -#if defined(ISVPRINT) || defined(UNF) +#if defined(ISVPRINT) || defined(UNF) || defined(GDB) */libultra_d.a:*.o(.*data*); #else */libultra_rom.a:*.o(.*data*); #endif -#ifdef HVQM */libhvqm2.a:*.o(.*data*); -#endif + */libz.a:*.o(.*data*); BUILD_DIR/lib/rsp.o(.data*); -#ifdef HVQM lib/PR/hvqm/hvqm2sp1.o(.data*); -#endif /* rodata */ BUILD_DIR/src/game*.o(.rodata*); -#ifdef UNF + BUILD_DIR/src/gdb*.o(.*rodata*); BUILD_DIR/src/usb*.o(.rodata*); -#endif BUILD_DIR/src/audio*.o(.rodata*); -#if defined(ISVPRINT) || defined(UNF) +#if defined(ISVPRINT) || defined(UNF) || defined(GDB) */libultra_d.a:*.o(.*rodata*); #else */libultra_rom.a:*.o(.*rodata*); #endif */libgcc.a:*.o(.rodata*); -#ifdef GZIP */libz.a:*.o(.rodata*); -#endif BUILD_DIR/lib/rsp.o(.rodata*); -#ifdef HVQM lib/PR/hvqm/hvqm2sp1.o(.rodata*); -#endif } END_SEG(main) BEGIN_NOLOAD(main) { BUILD_DIR/src/game*.o(.*bss*); -#ifdef HVQM BUILD_DIR/src/hvqm*.o(.*bss*); -#endif -#ifdef UNF + BUILD_DIR/src/gdb*.o(.*bss*); BUILD_DIR/src/usb*.o(.*bss*); -#endif BUILD_DIR/src/audio*.o(.*bss*); -#ifdef GZIP - BUILD_DIR/src/gzip*.o(.bss*); -#endif - BUILD_DIR/src/audio*.o(.*bss*); -#if defined(ISVPRINT) || defined(UNF) +#if defined(ISVPRINT) || defined(UNF) || defined(GDB) */libultra_d.a:*.o(COMMON); */libultra_d.a:*.o(.scommon); */libultra_d.a:*.o(.*bss*); @@ -217,12 +190,8 @@ SECTIONS */libultra_rom.a:*.o(.scommon); */libultra_rom.a:*.o(.*bss*); #endif -#ifdef HVQM */libhvqm2.a:*.o(.bss*); -#endif -#ifdef GZIP */libz.a:*.o(.bss*); -#endif . = ALIGN(0x8); } END_NOLOAD(main) @@ -471,6 +440,37 @@ SECTIONS } END_SEG(capcom) #endif + /* DWARF debug sections. + Symbols in the DWARF debugging sections are relative to the beginning + of the section so we begin them at 0. */ + /* DWARF 1 */ + .debug 0 : { *(.debug) } + .line 0 : { *(.line) } + /* GNU DWARF 1 extensions */ + .debug_srcinfo 0 : { *(.debug_srcinfo) } + .debug_sfnames 0 : { *(.debug_sfnames) } + /* DWARF 1.1 and DWARF 2 */ + .debug_aranges 0 : { *(.debug_aranges) } + .debug_pubnames 0 : { *(.debug_pubnames) } + /* DWARF 2 */ + .debug_info 0 : { *(.debug_info .gnu.linkonce.wi.*) } + .debug_abbrev 0 : { *(.debug_abbrev) } + .debug_line 0 : { *(.debug_line .debug_line.* .debug_line_end ) } + .debug_frame 0 : { *(.debug_frame) } + .debug_str 0 : { *(.debug_str) } + .debug_loc 0 : { *(.debug_loc) } + .debug_macinfo 0 : { *(.debug_macinfo) } + /* SGI/MIPS DWARF 2 extensions */ + .debug_weaknames 0 : { *(.debug_weaknames) } + .debug_funcnames 0 : { *(.debug_funcnames) } + .debug_typenames 0 : { *(.debug_typenames) } + .debug_varnames 0 : { *(.debug_varnames) } + /* DWARF 3 */ + .debug_pubtypes 0 : { *(.debug_pubtypes) } + .debug_ranges 0 : { *(.debug_ranges) } + /* DWARF Extension. */ + .debug_macro 0 : { *(.debug_macro) } + .gnu.attributes 0 : { KEEP (*(.gnu.attributes)) } /* Discard everything not specifically mentioned above. */ /DISCARD/ : { diff --git a/src/game/main.c b/src/game/main.c index fa082f9f..2a13968e 100644 --- a/src/game/main.c +++ b/src/game/main.c @@ -18,6 +18,9 @@ #include "usb/usb.h" #include "usb/debug.h" #endif +#ifdef GDB +#include "gdb/debugger.h" +#endif // Message IDs #define MESG_SP_COMPLETE 100 @@ -312,6 +315,10 @@ void handle_dp_complete(void) { extern void crash_screen_init(void); void thread3_main(UNUSED void *arg) { +#ifdef GDB +OSPiHandle *gdbpihandle; + gdbpihandle = osCartRomInit(); +#endif setup_mesg_queues(); alloc_pool(); load_engine_code_segment(); @@ -331,6 +338,11 @@ void thread3_main(UNUSED void *arg) { create_thread(&gGameLoopThread, 5, thread5_game_loop, NULL, gThread5Stack + 0x2000, 10); osStartThread(&gGameLoopThread); +#ifdef GDB +OSThread* threadPtr = &gMainThread; + gdbInitDebugger(gdbpihandle, &gDmaMesgQueue, &threadPtr, 1); +#endif + while (TRUE) { OSMesg msg; diff --git a/src/usb/debugger.c b/src/gdb/debugger.c similarity index 99% rename from src/usb/debugger.c rename to src/gdb/debugger.c index 2deec7f5..dc09f2e0 100644 --- a/src/usb/debugger.c +++ b/src/gdb/debugger.c @@ -3,6 +3,7 @@ #include #include #include +#include #define MAX_PACKET_SIZE 0x4000 #define MAX_DEBUGGER_THREADS 8 diff --git a/src/usb/debugger.h b/src/gdb/debugger.h similarity index 100% rename from src/usb/debugger.h rename to src/gdb/debugger.h diff --git a/src/usb/serial.c b/src/gdb/serial.c similarity index 99% rename from src/usb/serial.c rename to src/gdb/serial.c index 2e4d164e..a6acef3e 100644 --- a/src/usb/serial.c +++ b/src/gdb/serial.c @@ -4,7 +4,7 @@ u8 (*gdbSerialCanRead)(); #if USE_UNF_LOADER -#include "usb.h" +#include u32 gdbPendingUNFHeader; u32 gdbPendingUNFData; diff --git a/src/usb/serial.h b/src/gdb/serial.h similarity index 96% rename from src/usb/serial.h rename to src/gdb/serial.h index 7523b470..25941698 100644 --- a/src/usb/serial.h +++ b/src/gdb/serial.h @@ -4,7 +4,7 @@ #include -// #define USE_UNF_LOADER 1 +//#define USE_UNF_LOADER 1 enum GDBError { GDBErrorNone,