From 0509fa57ca826056edc51e276e9a6ef0345dfed5 Mon Sep 17 00:00:00 2001 From: TuxSH <1922548+TuxSH@users.noreply.github.com> Date: Fri, 31 Jan 2020 01:58:56 +0000 Subject: [PATCH] thermosphere: add src/gdb to build list, fix subsequent warnings and errors --- thermosphere/Makefile | 2 +- thermosphere/src/gdb/context.h | 2 +- thermosphere/src/gdb/hio.c | 9 ++++----- thermosphere/src/gdb/mem.c | 2 +- thermosphere/src/gdb/regs.c | 22 +++++++++------------- thermosphere/src/guest_memory.h | 2 +- 6 files changed, 17 insertions(+), 22 deletions(-) diff --git a/thermosphere/Makefile b/thermosphere/Makefile index 21b4043ce..ee578277b 100644 --- a/thermosphere/Makefile +++ b/thermosphere/Makefile @@ -49,7 +49,7 @@ endif #--------------------------------------------------------------------------------- TARGET := $(notdir $(CURDIR)) BUILD := build -SOURCES := src src/platform $(PLATFORM_SOURCES) +SOURCES := src src/platform src/gdb $(PLATFORM_SOURCES) DATA := data INCLUDES := include ../common/include diff --git a/thermosphere/src/gdb/context.h b/thermosphere/src/gdb/context.h index c91df58f0..0ad36a650 100644 --- a/thermosphere/src/gdb/context.h +++ b/thermosphere/src/gdb/context.h @@ -93,7 +93,7 @@ typedef struct GDBContext { char *commandData, *commandEnd; size_t lastSentPacketSize; - char *buffer[GDB_BUF_LEN + 4]; + char buffer[GDB_BUF_LEN + 4]; char *workBuffer; } GDBContext; diff --git a/thermosphere/src/gdb/hio.c b/thermosphere/src/gdb/hio.c index 31b1f89f0..cf5c138b5 100644 --- a/thermosphere/src/gdb/hio.c +++ b/thermosphere/src/gdb/hio.c @@ -7,11 +7,10 @@ #include -#include "gdb/hio.h" -#include "gdb/net.h" -#include "gdb/mem.h" -#include "gdb/debug.h" -#include "fmt.h" +#include "hio.h" +#include "net.h" +#include "mem.h" +#include "debug.h" bool GDB_FetchPackedHioRequest(GDBContext *ctx, u32 addr) { diff --git a/thermosphere/src/gdb/mem.c b/thermosphere/src/gdb/mem.c index 98cf2eae3..42ad8cd14 100644 --- a/thermosphere/src/gdb/mem.c +++ b/thermosphere/src/gdb/mem.c @@ -48,7 +48,7 @@ u32 GDB_SearchMemory(bool *found, GDBContext *ctx, uintptr_t addr, size_t len, c { // Note: need to ensure GDB_WORK_BUF_LEN is at least 0x1000 bytes in size - char *buf = ctx->workBuffer; + u8 *buf = (u8 *)ctx->workBuffer; size_t maxNbPages = GDB_WORK_BUF_LEN / 0x1000; uintptr_t curAddr = addr; diff --git a/thermosphere/src/gdb/regs.c b/thermosphere/src/gdb/regs.c index 53fde5b26..e17bb3008 100644 --- a/thermosphere/src/gdb/regs.c +++ b/thermosphere/src/gdb/regs.c @@ -20,13 +20,13 @@ GDB_DECLARE_HANDLER(ReadRegisters) { ENSURE(ctx->selectedThreadId == currentCoreCtx->coreId); - const ExceptionStackFrame *frame = currentCoreCtx->guestFrame; - const FpuRegisterCache *fpuRegCache = fpuReadRegisters(); + ExceptionStackFrame *frame = currentCoreCtx->guestFrame; + FpuRegisterCache *fpuRegCache = fpuReadRegisters(); char *buf = ctx->buffer + 1; size_t n = 0; - struct PACKED ALIGN(4) { + struct { u64 sp; u64 pc; u32 cpsr; @@ -35,7 +35,6 @@ GDB_DECLARE_HANDLER(ReadRegisters) .pc = frame->elr_el2, .cpsr = (u32)frame->spsr_el2, }; - static_assert(sizeof(cpuSprs) == 12, "sizeof(cpuSprs) != 12"); u32 fpuSprs[2] = { (u32)fpuRegCache->fpsr, @@ -44,7 +43,7 @@ GDB_DECLARE_HANDLER(ReadRegisters) n += GDB_EncodeHex(buf + n, frame->x, sizeof(frame->x)); - n += GDB_EncodeHex(buf + n, &cpuSprs, sizeof(cpuSprs)); + n += GDB_EncodeHex(buf + n, &cpuSprs, 8+8+4); n += GDB_EncodeHex(buf + n, fpuRegCache->q, sizeof(fpuRegCache->q)); n += GDB_EncodeHex(buf + n, fpuSprs, sizeof(fpuSprs)); @@ -64,12 +63,11 @@ GDB_DECLARE_HANDLER(WriteRegisters) size_t n = 0; size_t m = 0; - struct PACKED ALIGN(4) { + struct { u64 sp; u64 pc; u32 cpsr; } cpuSprs; - static_assert(sizeof(cpuSprs) == 12, "sizeof(cpuSprs) != 12"); u32 fpuSprs[2]; @@ -78,7 +76,7 @@ GDB_DECLARE_HANDLER(WriteRegisters) size_t sz; } info[4] = { { frame->x, sizeof(frame->x) }, - { &cpuSprs, sizeof(cpuSprs) }, + { &cpuSprs, 8+8+4 }, { fpuRegCache->q, sizeof(fpuRegCache->q) }, { fpuSprs, sizeof(fpuSprs) }, }; @@ -142,10 +140,9 @@ GDB_DECLARE_HANDLER(ReadRegister) { ENSURE(ctx->selectedThreadId == currentCoreCtx->coreId); - const ExceptionStackFrame *frame = currentCoreCtx->guestFrame; - const FpuRegisterCache *fpuRegCache = NULL; + ExceptionStackFrame *frame = currentCoreCtx->guestFrame; + FpuRegisterCache *fpuRegCache = NULL; - char *buf = ctx->buffer + 1; unsigned long gdbRegNum; if (GDB_ParseHexIntegerList(&gdbRegNum, ctx->commandData, 1, 0) == NULL) { @@ -211,6 +208,5 @@ GDB_DECLARE_HANDLER(WriteRegister) fpuCommitRegisters(); } - else - return GDB_ReplyOk(ctx); + return GDB_ReplyOk(ctx); } diff --git a/thermosphere/src/guest_memory.h b/thermosphere/src/guest_memory.h index 4b1ee34a1..a071b87e6 100644 --- a/thermosphere/src/guest_memory.h +++ b/thermosphere/src/guest_memory.h @@ -25,7 +25,7 @@ static inline size_t guestReadMemory(uintptr_t addr, size_t size, void *buf) return guestReadWriteMemory(addr, size, buf, NULL); } -static inline size_t guestWriteMemory(uintptr_t addr, size_t size, void *buf) +static inline size_t guestWriteMemory(uintptr_t addr, size_t size, const void *buf) { return guestReadWriteMemory(addr, size, NULL, buf); }