mirror of
https://github.com/Atmosphere-NX/Atmosphere
synced 2025-01-03 11:11:14 +00:00
thermosphere: add CFI where needed, add PANIC macro, etc.
This commit is contained in:
parent
3a13ab2e46
commit
ef79908594
7 changed files with 76 additions and 26 deletions
|
@ -118,18 +118,26 @@ finished:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
.section .text.flush_dcache_all, "ax", %progbits
|
.section .text.flush_dcache_all, "ax", %progbits
|
||||||
.type flush_dcache_all, %function
|
|
||||||
.global flush_dcache_all
|
.global flush_dcache_all
|
||||||
|
.type flush_dcache_all, %function
|
||||||
|
.func flush_dcache_all
|
||||||
|
.cfi_startproc
|
||||||
flush_dcache_all:
|
flush_dcache_all:
|
||||||
mov x0, #0
|
mov x0, #0
|
||||||
b __asm_dcache_all
|
b __asm_dcache_all
|
||||||
|
.endfunc
|
||||||
|
.cfi_endproc
|
||||||
|
|
||||||
.section .text.invalidate_dcache_all, "ax", %progbits
|
.section .text.invalidate_dcache_all, "ax", %progbits
|
||||||
.type invalidate_dcache_all, %function
|
|
||||||
.global invalidate_dcache_all
|
.global invalidate_dcache_all
|
||||||
|
.type invalidate_dcache_all, %function
|
||||||
|
.func invalidate_dcache_all
|
||||||
|
.cfi_startproc
|
||||||
invalidate_dcache_all:
|
invalidate_dcache_all:
|
||||||
mov x0, #1
|
mov x0, #1
|
||||||
b __asm_dcache_all
|
b __asm_dcache_all
|
||||||
|
.endfunc
|
||||||
|
.cfi_endproc
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* void __asm_flush_dcache_range(start, end) (renamed -> flush_dcache_range)
|
* void __asm_flush_dcache_range(start, end) (renamed -> flush_dcache_range)
|
||||||
|
@ -140,8 +148,10 @@ invalidate_dcache_all:
|
||||||
* x1: end address
|
* x1: end address
|
||||||
*/
|
*/
|
||||||
.section .text.flush_dcache_range, "ax", %progbits
|
.section .text.flush_dcache_range, "ax", %progbits
|
||||||
.type flush_dcache_range, %function
|
|
||||||
.global flush_dcache_range
|
.global flush_dcache_range
|
||||||
|
.type flush_dcache_range, %function
|
||||||
|
.func flush_dcache_range
|
||||||
|
.cfi_startproc
|
||||||
flush_dcache_range:
|
flush_dcache_range:
|
||||||
mrs x3, ctr_el0
|
mrs x3, ctr_el0
|
||||||
lsr x3, x3, #16
|
lsr x3, x3, #16
|
||||||
|
@ -158,6 +168,8 @@ flush_dcache_range:
|
||||||
b.lo 1b
|
b.lo 1b
|
||||||
dsb sy
|
dsb sy
|
||||||
ret
|
ret
|
||||||
|
.endfunc
|
||||||
|
.cfi_endproc
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* void __asm_invalidate_dcache_range(start, end) (-> invalidate_dcache_range)
|
* void __asm_invalidate_dcache_range(start, end) (-> invalidate_dcache_range)
|
||||||
|
@ -168,8 +180,10 @@ flush_dcache_range:
|
||||||
* x1: end address
|
* x1: end address
|
||||||
*/
|
*/
|
||||||
.section .text.invalidate_dcache_range, "ax", %progbits
|
.section .text.invalidate_dcache_range, "ax", %progbits
|
||||||
.type invalidate_dcache_range, %function
|
|
||||||
.global invalidate_dcache_range
|
.global invalidate_dcache_range
|
||||||
|
.type invalidate_dcache_range, %function
|
||||||
|
.func invalidate_dcache_range
|
||||||
|
.cfi_startproc
|
||||||
invalidate_dcache_range:
|
invalidate_dcache_range:
|
||||||
mrs x3, ctr_el0
|
mrs x3, ctr_el0
|
||||||
ubfm x3, x3, #16, #19
|
ubfm x3, x3, #16, #19
|
||||||
|
@ -185,6 +199,8 @@ invalidate_dcache_range:
|
||||||
b.lo 1b
|
b.lo 1b
|
||||||
dsb sy
|
dsb sy
|
||||||
ret
|
ret
|
||||||
|
.endfunc
|
||||||
|
.cfi_endproc
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* void __asm_invalidate_icache_all(void) (-> invalidate_icache_inner_shareable)
|
* void __asm_invalidate_icache_all(void) (-> invalidate_icache_inner_shareable)
|
||||||
|
@ -192,8 +208,10 @@ invalidate_dcache_range:
|
||||||
* invalidate all icache entries.
|
* invalidate all icache entries.
|
||||||
*/
|
*/
|
||||||
.section .text.invalidate_icache_all_inner_shareable, "ax", %progbits
|
.section .text.invalidate_icache_all_inner_shareable, "ax", %progbits
|
||||||
.type invalidate_icache_all_inner_shareable, %function
|
|
||||||
.global invalidate_icache_all_inner_shareable
|
.global invalidate_icache_all_inner_shareable
|
||||||
|
.type invalidate_icache_all_inner_shareable, %function
|
||||||
|
.func invalidate_icache_all_inner_shareable
|
||||||
|
.cfi_startproc
|
||||||
invalidate_icache_all_inner_shareable:
|
invalidate_icache_all_inner_shareable:
|
||||||
dsb ish
|
dsb ish
|
||||||
isb
|
isb
|
||||||
|
@ -201,10 +219,14 @@ invalidate_icache_all_inner_shareable:
|
||||||
dsb ish
|
dsb ish
|
||||||
isb
|
isb
|
||||||
ret
|
ret
|
||||||
|
.endfunc
|
||||||
|
.cfi_endproc
|
||||||
|
|
||||||
.section .text.invalidate_icache_all, "ax", %progbits
|
.section .text.invalidate_icache_all, "ax", %progbits
|
||||||
.type invalidate_icache_all, %function
|
|
||||||
.global invalidate_icache_all
|
.global invalidate_icache_all
|
||||||
|
.type invalidate_icache_all, %function
|
||||||
|
.func invalidate_icache_all
|
||||||
|
.cfi_startproc
|
||||||
invalidate_icache_all:
|
invalidate_icache_all:
|
||||||
dsb sy
|
dsb sy
|
||||||
isb
|
isb
|
||||||
|
@ -212,10 +234,14 @@ invalidate_icache_all:
|
||||||
dsb sy
|
dsb sy
|
||||||
isb
|
isb
|
||||||
ret
|
ret
|
||||||
|
.endfunc
|
||||||
|
.cfi_endproc
|
||||||
|
|
||||||
.section .text.set_memory_registers_enable_mmu, "ax", %progbits
|
.section .text.set_memory_registers_enable_mmu, "ax", %progbits
|
||||||
.type set_memory_registers_enable_mmu, %function
|
|
||||||
.global set_memory_registers_enable_mmu
|
.global set_memory_registers_enable_mmu
|
||||||
|
.type set_memory_registers_enable_mmu, %function
|
||||||
|
.func set_memory_registers_enable_mmu
|
||||||
|
.cfi_startproc
|
||||||
set_memory_registers_enable_mmu:
|
set_memory_registers_enable_mmu:
|
||||||
msr ttbr0_el2, x0
|
msr ttbr0_el2, x0
|
||||||
msr tcr_el2, x1
|
msr tcr_el2, x1
|
||||||
|
@ -238,10 +264,14 @@ set_memory_registers_enable_mmu:
|
||||||
isb
|
isb
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
.endfunc
|
||||||
|
.cfi_endproc
|
||||||
|
|
||||||
.section .text.set_memory_registers_enable_stage2, "ax", %progbits
|
.section .text.set_memory_registers_enable_stage2, "ax", %progbits
|
||||||
.type set_memory_registers_enable_stage2, %function
|
|
||||||
.global set_memory_registers_enable_stage2
|
.global set_memory_registers_enable_stage2
|
||||||
|
.type set_memory_registers_enable_stage2, %function
|
||||||
|
.func set_memory_registers_enable_stage2
|
||||||
|
.cfi_startproc
|
||||||
set_memory_registers_enable_stage2:
|
set_memory_registers_enable_stage2:
|
||||||
msr vttbr_el2, x0
|
msr vttbr_el2, x0
|
||||||
msr vtcr_el2, x1
|
msr vtcr_el2, x1
|
||||||
|
@ -262,3 +292,5 @@ set_memory_registers_enable_stage2:
|
||||||
isb
|
isb
|
||||||
|
|
||||||
ret
|
ret
|
||||||
|
.endfunc
|
||||||
|
.cfi_endproc
|
||||||
|
|
|
@ -17,8 +17,10 @@
|
||||||
|
|
||||||
// Precondition: x1 <= 16
|
// Precondition: x1 <= 16
|
||||||
.section .text.loadBreakpointRegs, "ax", %progbits
|
.section .text.loadBreakpointRegs, "ax", %progbits
|
||||||
.type loadBreakpointRegs, %function
|
|
||||||
.global loadBreakpointRegs
|
.global loadBreakpointRegs
|
||||||
|
.type loadBreakpointRegs, %function
|
||||||
|
.func loadBreakpointRegs
|
||||||
|
.cfi_startproc
|
||||||
loadBreakpointRegs:
|
loadBreakpointRegs:
|
||||||
// x1 = number
|
// x1 = number
|
||||||
adr x16, 1f
|
adr x16, 1f
|
||||||
|
@ -38,11 +40,15 @@ loadBreakpointRegs:
|
||||||
dsb sy
|
dsb sy
|
||||||
isb
|
isb
|
||||||
ret
|
ret
|
||||||
|
.endfunc
|
||||||
|
.cfi_endproc
|
||||||
|
|
||||||
// Precondition: x1 <= 16
|
// Precondition: x1 <= 16
|
||||||
.section .text.loadWatchpointRegs, "ax", %progbits
|
.section .text.loadWatchpointRegs, "ax", %progbits
|
||||||
.type loadWatchpointRegs, %function
|
|
||||||
.global loadWatchpointRegs
|
.global loadWatchpointRegs
|
||||||
|
.type loadWatchpointRegs, %function
|
||||||
|
.func loadWatchpointRegs
|
||||||
|
.cfi_startproc
|
||||||
loadWatchpointRegs:
|
loadWatchpointRegs:
|
||||||
// x1 = number
|
// x1 = number
|
||||||
adr x16, 1f
|
adr x16, 1f
|
||||||
|
@ -62,3 +68,5 @@ loadWatchpointRegs:
|
||||||
dsb sy
|
dsb sy
|
||||||
isb
|
isb
|
||||||
ret
|
ret
|
||||||
|
.endfunc
|
||||||
|
.cfi_endproc
|
||||||
|
|
|
@ -15,6 +15,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <stdio.h>
|
||||||
#include "data_abort.h"
|
#include "data_abort.h"
|
||||||
#include "sysreg.h"
|
#include "sysreg.h"
|
||||||
#include "debug_log.h"
|
#include "debug_log.h"
|
||||||
|
@ -25,20 +26,20 @@
|
||||||
|
|
||||||
void dumpUnhandledDataAbort(DataAbortIss dabtIss, u64 far, const char *msg)
|
void dumpUnhandledDataAbort(DataAbortIss dabtIss, u64 far, const char *msg)
|
||||||
{
|
{
|
||||||
DEBUG("Unhandled");
|
char s1[64], s2[32], s3[64] = "";
|
||||||
DEBUG(" %s ", msg);
|
(void)s1; (void)s2; (void)s3;
|
||||||
DEBUG("%s at ", dabtIss.wnr ? "write" : "read");
|
sprintf(s1, "Unhandled %s %s", msg , dabtIss.wnr ? "write" : "read");
|
||||||
if (dabtIss.fnv) {
|
if (dabtIss.fnv) {
|
||||||
DEBUG("<unk>");
|
sprintf(s2, "<unk>");
|
||||||
} else {
|
} else {
|
||||||
DEBUG("%016llx", far);
|
sprintf(s2, "%016lx", far);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dabtIss.isv) {
|
if (dabtIss.isv) {
|
||||||
DEBUG(" size %u Rt=%u", BIT(dabtIss.sas), dabtIss.srt);
|
sprintf(s3, ", size %u Rt=%u", BIT(dabtIss.sas), dabtIss.srt);
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG("\n");
|
DEBUG("%s at %s%s\n", s1, s2, s3);
|
||||||
}
|
}
|
||||||
|
|
||||||
void handleLowerElDataAbortException(ExceptionStackFrame *frame, ExceptionSyndromeRegister esr)
|
void handleLowerElDataAbortException(ExceptionStackFrame *frame, ExceptionSyndromeRegister esr)
|
||||||
|
|
|
@ -25,13 +25,11 @@ static void loadKernelViaSemihosting(void)
|
||||||
DEBUG("Loading kernel via semihosted 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);
|
PANIC("failed to open file (%ld)!\n", handle);
|
||||||
panic();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((ret = semihosting_file_read(handle, &len, buf)) < 0) {
|
if ((ret = semihosting_file_read(handle, &len, buf)) < 0) {
|
||||||
DEBUG("failed to read file (%ld)!\n", ret);
|
PANIC("failed to read file (%ld)!\n", ret);
|
||||||
panic();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG("OK!\n");
|
DEBUG("OK!\n");
|
||||||
|
@ -39,7 +37,7 @@ static void loadKernelViaSemihosting(void)
|
||||||
currentCoreCtx->kernelEntrypoint = buf;
|
currentCoreCtx->kernelEntrypoint = buf;
|
||||||
}
|
}
|
||||||
|
|
||||||
void main(ExceptionStackFrame *frame)
|
void thermosphereMain(ExceptionStackFrame *frame)
|
||||||
{
|
{
|
||||||
enableTraps();
|
enableTraps();
|
||||||
enableBreakpointsAndWatchpoints();
|
enableBreakpointsAndWatchpoints();
|
||||||
|
@ -58,8 +56,7 @@ void main(ExceptionStackFrame *frame)
|
||||||
if (semihosting_connection_supported()) {
|
if (semihosting_connection_supported()) {
|
||||||
loadKernelViaSemihosting();
|
loadKernelViaSemihosting();
|
||||||
} else {
|
} else {
|
||||||
DEBUG("Kernel not loaded!\n");
|
PANIC("Kernel not loaded!\n");
|
||||||
panic();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,8 +23,10 @@
|
||||||
* SPDX-License-Identifier: BSD-3-Clause
|
* SPDX-License-Identifier: BSD-3-Clause
|
||||||
*/
|
*/
|
||||||
|
|
||||||
.global spinlockLock
|
.global spinlockLock
|
||||||
.type spinlockLock, %function
|
.type spinlockLock, %function
|
||||||
|
.func spinlockLock
|
||||||
|
.cfi_startproc
|
||||||
spinlockLock:
|
spinlockLock:
|
||||||
mov w2, #1
|
mov w2, #1
|
||||||
sevl
|
sevl
|
||||||
|
@ -36,10 +38,16 @@ spinlockLock:
|
||||||
stxr w1, w2, [x0]
|
stxr w1, w2, [x0]
|
||||||
cbnz w1, l2
|
cbnz w1, l2
|
||||||
ret
|
ret
|
||||||
|
.endfunc
|
||||||
|
.cfi_endproc
|
||||||
|
|
||||||
.global spinlockUnlock
|
.global spinlockUnlock
|
||||||
.type spinlockUnlock, %function
|
.type spinlockUnlock, %function
|
||||||
|
.func spinlockUnlock
|
||||||
|
.cfi_startproc
|
||||||
spinlockUnlock:
|
spinlockUnlock:
|
||||||
stlr wzr, [x0]
|
stlr wzr, [x0]
|
||||||
sev
|
sev
|
||||||
ret
|
ret
|
||||||
|
.endfunc
|
||||||
|
.cfi_endproc
|
|
@ -75,7 +75,7 @@ _startCommon:
|
||||||
isb
|
isb
|
||||||
|
|
||||||
mov x0, sp
|
mov x0, sp
|
||||||
bl main
|
bl thermosphereMain
|
||||||
|
|
||||||
dsb sy
|
dsb sy
|
||||||
isb
|
isb
|
||||||
|
|
|
@ -38,6 +38,8 @@
|
||||||
|
|
||||||
#define FOREACH_BIT(tmpmsk, var, word) for (u64 tmpmsk = (word), var = __builtin_ctzll(word); tmpmsk != 0; tmpmsk &= ~BITL(var), var = __builtin_ctzll(tmpmsk))
|
#define FOREACH_BIT(tmpmsk, var, word) for (u64 tmpmsk = (word), var = __builtin_ctzll(word); tmpmsk != 0; tmpmsk &= ~BITL(var), var = __builtin_ctzll(tmpmsk))
|
||||||
|
|
||||||
|
#define PANIC(...) do { DEBUG(__VA_ARGS__); panic(); } while (false)
|
||||||
|
|
||||||
static inline void __dsb_sy(void)
|
static inline void __dsb_sy(void)
|
||||||
{
|
{
|
||||||
__asm__ __volatile__ ("dsb sy" ::: "memory");
|
__asm__ __volatile__ ("dsb sy" ::: "memory");
|
||||||
|
@ -68,6 +70,8 @@ bool readEl1Memory(void *dst, uintptr_t addr, size_t size);
|
||||||
bool writeEl1Memory(uintptr_t addr, const void *src, size_t size);
|
bool writeEl1Memory(uintptr_t addr, const void *src, size_t size);
|
||||||
|
|
||||||
static inline void panic(void) {
|
static inline void panic(void) {
|
||||||
|
#ifndef PLATFORM_QEMU
|
||||||
__builtin_trap();
|
__builtin_trap();
|
||||||
|
#endif
|
||||||
for (;;);
|
for (;;);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue