mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2024-11-15 09:36:35 +00:00
thermosphere: fix x18 init, etc.
This commit is contained in:
parent
3fa9133814
commit
a11b0b6e0e
5 changed files with 35 additions and 26 deletions
|
@ -133,7 +133,7 @@ all: $(BUILD)
|
||||||
|
|
||||||
ifeq ($(PLATFORM), qemu)
|
ifeq ($(PLATFORM), qemu)
|
||||||
QEMUFLAGS := -nographic -machine virt,secure=on,virtualization=on,gic-version=2 -cpu cortex-a57 -smp 4 -m 1024\
|
QEMUFLAGS := -nographic -machine virt,secure=on,virtualization=on,gic-version=2 -cpu cortex-a57 -smp 4 -m 1024\
|
||||||
-bios bl1.bin -d unimp,int -semihosting-config enable,target=native -serial mon:stdio
|
-bios bl1.bin -d unimp -semihosting-config enable,target=native -serial mon:stdio
|
||||||
|
|
||||||
# NOTE: copy bl1.bin, bl2.bin, bl31.bin from your own build of Arm Trusted Firmware!
|
# NOTE: copy bl1.bin, bl2.bin, bl31.bin from your own build of Arm Trusted Firmware!
|
||||||
|
|
||||||
|
|
|
@ -16,9 +16,23 @@
|
||||||
|
|
||||||
#include "core_ctx.h"
|
#include "core_ctx.h"
|
||||||
|
|
||||||
|
// start.s
|
||||||
|
extern uintptr_t g_initialKernelEntrypoint;
|
||||||
|
|
||||||
|
// Prevents it from being put in BSS
|
||||||
CoreCtx g_coreCtxs[4] = {
|
CoreCtx g_coreCtxs[4] = {
|
||||||
{ .coreId = 0 },
|
{ .coreId = 0 },
|
||||||
{ .coreId = 1 },
|
{ .coreId = 1 },
|
||||||
{ .coreId = 2 },
|
{ .coreId = 2 },
|
||||||
{ .coreId = 3 },
|
{ .coreId = 3 },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void coreCtxInit(u32 coreId, bool isColdbootCore, u64 argument)
|
||||||
|
{
|
||||||
|
currentCoreCtx = &g_coreCtxs[coreId];
|
||||||
|
currentCoreCtx->isColdbootCore = isColdbootCore;
|
||||||
|
currentCoreCtx->kernelArgument = argument;
|
||||||
|
if (isColdbootCore) {
|
||||||
|
currentCoreCtx->kernelEntrypoint = g_initialKernelEntrypoint;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -21,8 +21,10 @@ typedef struct CoreCtx {
|
||||||
u64 kernelArgument;
|
u64 kernelArgument;
|
||||||
uintptr_t kernelEntrypoint;
|
uintptr_t kernelEntrypoint;
|
||||||
u32 coreId; // @0x10
|
u32 coreId; // @0x10
|
||||||
bool isColdBootCore; // @0x14
|
bool isColdbootCore; // @0x14
|
||||||
} CoreCtx;
|
} CoreCtx;
|
||||||
|
|
||||||
extern CoreCtx g_coreCtxs[4];
|
extern CoreCtx g_coreCtxs[4];
|
||||||
register CoreCtx *currentCoreCtx asm("x18");
|
register CoreCtx *currentCoreCtx asm("x18");
|
||||||
|
|
||||||
|
void coreCtxInit(u32 coreId, bool isColdbootCore, u64 argument);
|
||||||
|
|
|
@ -13,7 +13,7 @@ static void loadKernelViaSemihosting(void)
|
||||||
uintptr_t buf = (uintptr_t)__start__ + (1<<20);
|
uintptr_t buf = (uintptr_t)__start__ + (1<<20);
|
||||||
long handle = -1, ret;
|
long handle = -1, ret;
|
||||||
|
|
||||||
DEBUG("Loading kernel via semihosting file I/O... ");
|
DEBUG("Loading kernel via semihosted file I/O... ");
|
||||||
handle = semihosting_file_open("test_kernel.bin", FOPEN_MODE_RB);
|
handle = semihosting_file_open("test_kernel.bin", FOPEN_MODE_RB);
|
||||||
if (handle < 0) {
|
if (handle < 0) {
|
||||||
DEBUG("failed to open file (%ld)!\n", handle);
|
DEBUG("failed to open file (%ld)!\n", handle);
|
||||||
|
@ -25,7 +25,7 @@ static void loadKernelViaSemihosting(void)
|
||||||
panic();
|
panic();
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG("OK!");
|
DEBUG("OK!\n");
|
||||||
semihosting_file_close(handle);
|
semihosting_file_close(handle);
|
||||||
currentCoreCtx->kernelEntrypoint = buf;
|
currentCoreCtx->kernelEntrypoint = buf;
|
||||||
}
|
}
|
||||||
|
@ -34,9 +34,9 @@ int main(void)
|
||||||
{
|
{
|
||||||
enableTraps();
|
enableTraps();
|
||||||
|
|
||||||
if (currentCoreCtx->isColdBootCore) {
|
if (currentCoreCtx->isColdbootCore) {
|
||||||
uartInit(115200);
|
uartInit(115200);
|
||||||
DEBUG("Hello from Thermosphere!\n");
|
DEBUG("EL2: core %u reached main first!\n", currentCoreCtx->coreId);
|
||||||
if (currentCoreCtx->kernelEntrypoint == 0) {
|
if (currentCoreCtx->kernelEntrypoint == 0) {
|
||||||
if (semihosting_connection_supported()) {
|
if (semihosting_connection_supported()) {
|
||||||
loadKernelViaSemihosting();
|
loadKernelViaSemihosting();
|
||||||
|
@ -48,7 +48,7 @@ int main(void)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
DEBUG("Core %u booted\n", currentCoreCtx->coreId);
|
DEBUG("EL2: core %u reached main!\n", currentCoreCtx->coreId);
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -23,7 +23,8 @@ _start:
|
||||||
b start
|
b start
|
||||||
b start2
|
b start2
|
||||||
|
|
||||||
_initialKernelEntrypoint:
|
.global g_initialKernelEntrypoint
|
||||||
|
g_initialKernelEntrypoint:
|
||||||
.quad 0
|
.quad 0
|
||||||
|
|
||||||
start:
|
start:
|
||||||
|
@ -58,35 +59,27 @@ _startCommon:
|
||||||
dsb sy
|
dsb sy
|
||||||
isb
|
isb
|
||||||
|
|
||||||
|
mov x2, x0
|
||||||
|
|
||||||
// Get core ID
|
// Get core ID
|
||||||
// Ensure Aff0 is 4-1 at most (4 cores), and that Aff1, 2 and 3 are 0 (1 cluster only)
|
// Ensure Aff0 is 4-1 at most (4 cores), and that Aff1, 2 and 3 are 0 (1 cluster only)
|
||||||
mrs x10, mpidr_el1
|
mrs x0, mpidr_el1
|
||||||
and x10, x10, #0x00FFFFFF // Aff0 to 2
|
tst x0, #(0xFF << 32)
|
||||||
and x10, x10, #(0xFF << 32) // Aff3
|
bne .
|
||||||
cmp x10, #4
|
and x0, x0, #0x00FFFFFF // Aff0 to 2
|
||||||
|
cmp x0, #4
|
||||||
bhs .
|
bhs .
|
||||||
|
|
||||||
// Set tmp stack (__stacks_top__ is aligned)
|
// Set tmp stack (__stacks_top__ is aligned)
|
||||||
adrp x8, __stacks_top__
|
adrp x8, __stacks_top__
|
||||||
lsl x9, x10, #10
|
lsl x9, x0, #10
|
||||||
sub sp, x8, x9
|
sub sp, x8, x9
|
||||||
|
|
||||||
// Set up x18
|
// Set up x18
|
||||||
adrp x18, g_coreCtxs
|
mov w1, w19
|
||||||
add x18, x18, #:lo12:g_coreCtxs
|
bl coreCtxInit
|
||||||
add x18, x18, x10, lsl #3
|
|
||||||
stp x18, xzr, [sp, #-0x10]!
|
stp x18, xzr, [sp, #-0x10]!
|
||||||
|
|
||||||
strb w19, [x18, #0x14] // isColdbootCore
|
|
||||||
|
|
||||||
// Store entrypoint if first core
|
|
||||||
cbz x19, _store_arg
|
|
||||||
ldr x8, _initialKernelEntrypoint
|
|
||||||
str x8, [x18, #8]
|
|
||||||
|
|
||||||
_store_arg:
|
|
||||||
str x0, [x18, #0]
|
|
||||||
|
|
||||||
// Don't call init array to save space?
|
// Don't call init array to save space?
|
||||||
// Clear BSS & call main for the first core executing this code
|
// Clear BSS & call main for the first core executing this code
|
||||||
cbz x19, _jump_to_main
|
cbz x19, _jump_to_main
|
||||||
|
|
Loading…
Reference in a new issue