Start GDB work (broken rn)

This commit is contained in:
CrashOveride95
2021-04-16 20:50:06 -04:00
parent cf77e2db67
commit 4068afb39f
7 changed files with 67 additions and 43 deletions

View File

@@ -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.

80
sm64.ld
View File

@@ -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/ :
{

View File

@@ -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;

View File

@@ -3,6 +3,7 @@
#include <string.h>
#include <stdio.h>
#include <stdarg.h>
#include <stddef.h>
#define MAX_PACKET_SIZE 0x4000
#define MAX_DEBUGGER_THREADS 8

View File

@@ -4,7 +4,7 @@
u8 (*gdbSerialCanRead)();
#if USE_UNF_LOADER
#include "usb.h"
#include <usb/usb.h>
u32 gdbPendingUNFHeader;
u32 gdbPendingUNFData;

View File

@@ -4,7 +4,7 @@
#include <ultra64.h>
// #define USE_UNF_LOADER 1
//#define USE_UNF_LOADER 1
enum GDBError {
GDBErrorNone,