thermosphere: reduce usage of nonvolatile memory by around 4KB
This commit is contained in:
@@ -24,7 +24,7 @@
|
||||
|
||||
/// Structure to synchronize and keep track of breakpoints
|
||||
typedef struct BreakpointManager {
|
||||
DebugRegisterPair breakpoints[16];
|
||||
DebugRegisterPair breakpoints[MAX_BCR];
|
||||
RecursiveSpinlock lock;
|
||||
u32 maxBreakpoints;
|
||||
u16 allocationBitmap;
|
||||
|
||||
@@ -16,25 +16,32 @@
|
||||
|
||||
#include "asm_macros.s"
|
||||
|
||||
.altmacro
|
||||
|
||||
.macro LOAD_DBG_REG_PAIRS what, id
|
||||
msr dbg\what\()cr\id\()_el1, x2
|
||||
msr dbg\what\()vr\id\()_el1, x3
|
||||
.if \id != 0
|
||||
LOAD_DBG_REG_PAIRS \what, %(\id - 1)
|
||||
.endif
|
||||
.endm
|
||||
|
||||
// Precondition: x1 <= 16
|
||||
FUNCTION loadBreakpointRegs
|
||||
// x1 = number
|
||||
dmb ish
|
||||
|
||||
adr x16, 1f
|
||||
add x0, x0, #(16 * 8)
|
||||
mov x4, #(16 * 12)
|
||||
add x0, x0, #(MAX_BCR * 8)
|
||||
mov x4, #(MAX_BCR * 12)
|
||||
sub x4, x4, x1,lsl #3
|
||||
sub x4, x4, x1,lsl #2
|
||||
add x16, x16, x4
|
||||
br x16
|
||||
|
||||
1:
|
||||
.irp count, 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
|
||||
ldp x2, x3, [x0, #-0x10]!
|
||||
msr dbgbcr\count\()_el1, x2
|
||||
msr dbgbvr\count\()_el1, x3
|
||||
.endr
|
||||
LOAD_DBG_REG_PAIRS b, MAX_BCR
|
||||
|
||||
dsb ish
|
||||
isb
|
||||
ret
|
||||
@@ -46,19 +53,16 @@ FUNCTION loadWatchpointRegs
|
||||
dmb ish
|
||||
|
||||
adr x16, 1f
|
||||
add x0, x0, #(16 * 8)
|
||||
mov x4, #(16 * 12)
|
||||
add x0, x0, #(MAX_WCR * 8)
|
||||
mov x4, #(MAX_WCR * 12)
|
||||
sub x4, x4, x1,lsl #3
|
||||
sub x4, x4, x1,lsl #2
|
||||
add x16, x16, x4
|
||||
br x16
|
||||
|
||||
1:
|
||||
.irp count, 15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0
|
||||
ldp x2, x3, [x0, #-0x10]!
|
||||
msr dbgwcr\count\()_el1, x2
|
||||
msr dbgwvr\count\()_el1, x3
|
||||
.endr
|
||||
LOAD_DBG_REG_PAIRS w, MAX_WCR
|
||||
|
||||
dsb ish
|
||||
isb
|
||||
ret
|
||||
|
||||
@@ -50,9 +50,9 @@ static const struct{
|
||||
GDBCommandHandler handler;
|
||||
} gdbCommandHandlers[] = {
|
||||
{ '?', GDB_HANDLER(GetStopReason) },
|
||||
{ '!', GDB_HANDLER(EnableExtendedMode) }, // note: stubbed
|
||||
{ 'c', GDB_HANDLER(ContinueOrStepDeprecated) },
|
||||
{ 'C', GDB_HANDLER(ContinueOrStepDeprecated) },
|
||||
//{ '!', GDB_HANDLER(EnableExtendedMode) }, // note: stubbed
|
||||
//{ 'c', GDB_HANDLER(ContinueOrStepDeprecated) },
|
||||
//{ 'C', GDB_HANDLER(ContinueOrStepDeprecated) },
|
||||
{ 'D', GDB_HANDLER(Detach) },
|
||||
{ 'F', GDB_HANDLER(HioReply) },
|
||||
{ 'g', GDB_HANDLER(ReadRegisters) },
|
||||
@@ -65,8 +65,8 @@ static const struct{
|
||||
{ 'P', GDB_HANDLER(WriteRegister) },
|
||||
{ 'q', GDB_HANDLER(ReadQuery) },
|
||||
{ 'Q', GDB_HANDLER(WriteQuery) },
|
||||
{ 's', GDB_HANDLER(ContinueOrStepDeprecated) },
|
||||
{ 'S', GDB_HANDLER(ContinueOrStepDeprecated) },
|
||||
//{ 's', GDB_HANDLER(ContinueOrStepDeprecated) },
|
||||
//{ 'S', GDB_HANDLER(ContinueOrStepDeprecated) },
|
||||
{ 'T', GDB_HANDLER(IsThreadAlive) },
|
||||
{ 'v', GDB_HANDLER(VerboseCommand) },
|
||||
{ 'X', GDB_HANDLER(WriteMemoryRaw) },
|
||||
|
||||
@@ -45,14 +45,14 @@ void memoryMapSetupMmu(const LoadImageLayout *layout, u64 *mmuTable)
|
||||
Layout in physmem:
|
||||
Location1
|
||||
Image (code and data incl. BSS)
|
||||
Part of "temp" (tempbss, stacks) if there's enough space left
|
||||
Location2
|
||||
Remaining of "temp" (note: we don't and can't check if there's enough mem left!)
|
||||
tempbss
|
||||
MMU table (taken from temp physmem)
|
||||
|
||||
Layout in vmem:
|
||||
Location1
|
||||
Image
|
||||
padding
|
||||
tempbss
|
||||
Location2
|
||||
Crash stacks
|
||||
@@ -62,32 +62,18 @@ void memoryMapSetupMmu(const LoadImageLayout *layout, u64 *mmuTable)
|
||||
*/
|
||||
|
||||
// Map our code & data (.text/other code, .rodata, .data, .bss) at the bottom of our L3 range, all RWX
|
||||
// Note that BSS is page-aligned
|
||||
// Note that the end of "image" is page-aligned
|
||||
// See LD script for more details
|
||||
uintptr_t curVa = MEMORY_MAP_VA_IMAGE;
|
||||
uintptr_t curPa = layout->startPa;
|
||||
|
||||
size_t tempInImageRegionMaxSize = layout->maxImageSize - layout->imageSize;
|
||||
size_t tempInImageRegionSize;
|
||||
size_t tempExtraSize;
|
||||
if (layout->tempSize <= tempInImageRegionMaxSize) {
|
||||
tempInImageRegionSize = layout->tempSize;
|
||||
tempExtraSize = 0;
|
||||
} else {
|
||||
// We need extra data
|
||||
tempInImageRegionSize = tempInImageRegionMaxSize;
|
||||
tempExtraSize = layout->tempSize - tempInImageRegionSize;
|
||||
}
|
||||
size_t imageRegionMapSize = (layout->imageSize + tempInImageRegionSize + 0xFFF) & ~0xFFFul;
|
||||
size_t tempExtraMapSize = (tempExtraSize + 0xFFF) & ~0xFFFul;
|
||||
|
||||
// Do not map the MMU table in that mapping:
|
||||
mmu_map_page_range(mmuTable, curVa, curPa, imageRegionMapSize, normalAttribs);
|
||||
mmu_map_page_range(mmuTable, curVa, curPa, layout->imageSize, normalAttribs);
|
||||
|
||||
curVa += imageRegionMapSize;
|
||||
curVa += layout->imageSize;
|
||||
curPa = layout->tempPa;
|
||||
mmu_map_page_range(mmuTable, curVa, curPa, tempExtraMapSize, normalAttribs);
|
||||
curPa += tempExtraMapSize;
|
||||
mmu_map_page_range(mmuTable, curVa, curPa, layout->tempSize , normalAttribs);
|
||||
curPa += layout->tempSize;
|
||||
|
||||
// Map the remaining temporary data as stacks, aligned 0x1000
|
||||
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
|
||||
typedef struct LoadImageLayout {
|
||||
uintptr_t startPa;
|
||||
size_t maxImageSize;
|
||||
size_t imageSize; // "image" includes "real" BSS but not tempbss
|
||||
|
||||
uintptr_t tempPa;
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
#include <stdatomic.h>
|
||||
#include "spinlock.h"
|
||||
|
||||
#define MAX_SW_BREAKPOINTS 32
|
||||
#define MAX_SW_BREAKPOINTS 16
|
||||
|
||||
typedef struct SoftwareBreakpoint {
|
||||
uintptr_t address; // VA
|
||||
|
||||
@@ -59,7 +59,7 @@ _startCommon:
|
||||
// Temporarily use temp end region as stack, then create the translation table
|
||||
// The stack top is also equal to the mmu table address...
|
||||
adr x0, g_loadImageLayout
|
||||
ldp x2, x3, [x0, #0x18]
|
||||
ldp x2, x3, [x0, #0x10]
|
||||
add x1, x2, x3
|
||||
mov sp, x1
|
||||
bl memoryMapSetupMmu
|
||||
@@ -111,23 +111,9 @@ _postMmuEnableReturnAddr:
|
||||
|
||||
.pool
|
||||
|
||||
/*
|
||||
typedef struct LoadImageLayout {
|
||||
uintptr_t startPa;
|
||||
size_t imageSize; // "image" includes "real" BSS but not tempbss
|
||||
size_t maxImageSize;
|
||||
|
||||
uintptr_t tempPa;
|
||||
size_t maxTempSize;
|
||||
size_t tempSize;
|
||||
|
||||
uintptr_t vbar;
|
||||
} LoadImageLayout;
|
||||
*/
|
||||
.global g_loadImageLayout
|
||||
g_loadImageLayout:
|
||||
.quad __start_pa__
|
||||
.quad __max_image_size__
|
||||
.quad __image_size__
|
||||
.quad __temp_pa__
|
||||
.quad __max_temp_size__
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include "preprocessor.h"
|
||||
#include "debug_log.h"
|
||||
|
||||
#define MAX_CORE 4
|
||||
#define BIT(n) (1u << (n))
|
||||
#define BITL(n) (1ull << (n))
|
||||
#define MASK(n) (BIT(n) - 1)
|
||||
|
||||
@@ -29,7 +29,7 @@ typedef struct WatchpointManager {
|
||||
u32 maxWatchpoints;
|
||||
u32 maxSplitWatchpoints;
|
||||
u16 allocationBitmap;
|
||||
DebugRegisterPair splitWatchpoints[16 * 8];
|
||||
DebugRegisterPair splitWatchpoints[MAX_WCR * 8];
|
||||
} WatchpointManager;
|
||||
|
||||
extern WatchpointManager g_watchpointManager;
|
||||
|
||||
Reference in New Issue
Block a user