thermosphere: major refactor of memory map

- use recursive stage 1 page table (thanks @fincs for this idea)
- NULL now unmapped
- no identity mapping
- image + GICv2 now mapped at the same address for every platform
- tempbss mapped just after "real" bss, can now steal unused mem from
the latter
- no hardcoded VAs for other MMIO devices
- tegra: remove timers, use the generic timer instead
This commit is contained in:
TuxSH
2020-01-17 22:10:26 +00:00
parent 92a291cd41
commit 626f0ecb98
47 changed files with 795 additions and 469 deletions

View File

@@ -32,16 +32,13 @@ g_initialKernelEntrypoint:
start:
mov x19, #1
b _startCommon
.global start2
.type start2, %function
start2:
mov x19, xzr
_startCommon:
// Disable interrupts, select sp_el2
msr daifset, 0b1111
msr spsel, #1
// Disable interrupts, select sp_el0 before mmu is enabled
mrs x20, cntpct_el0
msr daifset, 0b1111
msr spsel, #0
// Set sctlr_el2 ASAP to disable mmu/caching if not already done.
mov x1, #0x0838
@@ -52,25 +49,39 @@ _startCommon:
bl cacheClearLocalDataCacheOnBoot
cbz x19, 1f
// "Boot core only" stuff:
bl cacheClearSharedDataCachesOnBoot
// 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]
add x1, x2, x3
mov sp, x1
bl memoryMapSetupMmu
1:
// Enable MMU, note that the function is not allowed to use any stack
adr x0, g_loadImageLayout
ldr x18, =_postMmuEnableReturnAddr
bl memoryMapEnableMmu
// This is where we will land on exception return after enabling the MMU:
_postMmuEnableReturnAddr:
// Select sp_el2
msr spsel, #1
// Get core ID
// Ensure Aff0 is 4-1 at most (4 cores), and that Aff1, 2 and 3 are 0 (1 cluster only)
mrs x0, mpidr_el1
tst x0, #(0xFF << 32)
bne .
and x0, x0, #0x00FFFFFF // Aff0 to 2
cmp x0, #4
bhs .
mrs x8, mpidr_el1
and x8, x8, #0xFF
// Set stack pointer
adrp x8, __stacks_top__
lsl x9, x0, #10
sub sp, x8, x9
mov w0, w8
bl memoryMapGetStackTop
mov sp, x0
// Set up x18, other sysregs, BSS, MMU, etc.
// Set up x18, other sysregs, BSS, etc.
// Don't call init array to save space?
mov w0, w8
mov w1, w19
bl initSystem
@@ -92,3 +103,26 @@ _startCommon:
b _restoreAllRegisters
.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__
.quad __temp_size__
.quad __vectors_start__