1
0
Fork 0
mirror of https://github.com/Atmosphere-NX/Atmosphere.git synced 2024-12-18 08:22:04 +00:00

thermosphere: clean up start.s & exception_vector.s

This commit is contained in:
TuxSH 2020-03-04 02:38:40 +00:00
parent 6f423fcfab
commit 36f48748a4
3 changed files with 73 additions and 76 deletions

View file

@ -108,19 +108,19 @@ vector_entry \name
ldp x18, x19, [sp, #EXCEP_STACK_FRAME_SIZE]
msr sp_el0, x19
prfm pstl1keep, [x18]
//todo str x0, [x18, #CORECTX_GUEST_FRAME_OFFSET]
mov w1, #1
.else
mov w1, #0
.endif
bl exceptionEntryPostprocess
// ams::hvisor::ExceptionEntryPostprocess(ams::hvisor::ExceptionStackFrame*, bool)
bl _ZN3ams6hvisor25ExceptionEntryPostprocessEPNS0_19ExceptionStackFrameEb
.endm
.macro EXCEPTION_HANDLER_END name, type
.if \type != EXCEPTION_TYPE_HOST_CRASH
mov x0, sp
bl exceptionReturnPreprocess
// ams::hvisor::ExceptionReturnPreprocess(ams::hvisor::ExceptionStackFrame*)
bl _ZN3ams6hvisor25ExceptionReturnPreprocessEPNS0_19ExceptionStackFrameE
b _restoreAllRegisters
.else
b .
@ -140,13 +140,25 @@ vector_base g_thermosphereVectors
/* Current EL, SP0 */
vector_entry _synchSp0
// Safecpy
cbz x18, _handleSafecpy
// Used when we enable the MMU
msr elr_el2, x18
// Note: non-broadcasting TLB maintenance op
tlbi alle2
dsb nsh
dsb ish
isb
eret
_handleSafecpy:
// Set Z flag
mrs x18, spsr_el2
orr x18, x18, #(1 << 30)
msr spsr_el2, x18
mov x18, #0
eret
check_vector_size _synchSp0
_unknownException:
@ -154,7 +166,8 @@ _unknownException:
mov x0, x30
adr x1, g_thermosphereVectors + 4
sub x0, x0, x1
bl handleUnknownException
// ams::hvisor::HandleUnknownException(unsigned int)
bl _ZN3ams6hvisor22HandleUnknownExceptionEj
b .
UNKNOWN_EXCEPTION _irqSp0
@ -234,18 +247,6 @@ _restoreAllRegisters:
UNKNOWN_EXCEPTION _serrorSp0
// To save space, insert in an unused vector segment.
.global semihosting_call
.type semihosting_call, %function
.func semihosting_call
.cfi_startproc
.cfi_sections .debug_frame
semihosting_call:
hlt #0xF000
ret
.cfi_endproc
.endfunc
// To save space, insert in an unused vector segment.
// ams::hvisor::traps::CallSmc0(ams::hvisor::ExceptionStackFrame*):
@ -279,6 +280,7 @@ _ZN3ams6hvisor5traps8CallSmc0EPNS0_19ExceptionStackFrameE:
ret
_callSmcTemplateEnd:
.cfi_endproc
.endfunc
// ams::hvisor::traps::callSmcTemplateInstructionOffset
@ -315,40 +317,23 @@ _ZN3ams6hvisor5traps8CallSmc1EPNS0_19ExceptionStackFrameE:
ldp x19, x20, [sp], #0x10
ret
.cfi_endproc
.endfunc
/* Current EL, SPx */
vector_entry _synchSpx
// Ignore crash if x18 is 0, when we're copying memory from the guest (w/ irq masked)
cbz x18, _synchSpxIgnoreCrash
PIVOT_STACK_FOR_CRASH
SAVE_MOST_REGISTERS
EXCEPTION_HANDLER_START _synchSpx, EXCEPTION_TYPE_HOST
mov x0, sp
mov w1, #0
bl exceptionEntryPostprocess
mov x0, sp
mrs x1, esr_el2
bl handleSameElSyncException
b .
_synchSpxIgnoreCrash:
mrs x18, elr_el2
add x18, x18, #4
msr elr_el2, x18
eret
check_vector_size _synchSpx
// ams::hvisor::HandleSameElSyncException(ams::hvisor::ExceptionStackFrame*):
bl _ZN3ams6hvisor25HandleSameElSyncExceptionEPNS0_19ExceptionStackFrameE
EXCEPTION_HANDLER_END _synchSpx
EXCEPTION_HANDLER_START _irqSpx, EXCEPTION_TYPE_HOST
mov x0, sp
mov w1, wzr
mov w2, wzr
bl handleIrqException
mov w1, #0
mov w2, #0
// ams::hvisor::IrqManager::HandleInterrupt(ams::hvisor::ExceptionStackFrame*):
bl _ZN3ams6hvisor10IrqManager15HandleInterruptEPNS0_19ExceptionStackFrameE
EXCEPTION_HANDLER_END _irqSpx, EXCEPTION_TYPE_HOST
UNKNOWN_EXCEPTION _fiqSpx
@ -358,14 +343,16 @@ UNKNOWN_EXCEPTION _serrorSpx
EXCEPTION_HANDLER_START _synchA64, EXCEPTION_TYPE_GUEST
mov x0, sp
bl handleLowerElSyncException
// ams::hvisor::HandleLowerElSyncException(ams::hvisor::ExceptionStackFrame*)
bl _ZN3ams6hvisor26HandleLowerElSyncExceptionEPNS0_19ExceptionStackFrameE
EXCEPTION_HANDLER_END _synchA64, EXCEPTION_TYPE_GUEST
EXCEPTION_HANDLER_START _irqA64, EXCEPTION_TYPE_GUEST
mov x0, sp
mov w1, #1
mov w2, #0
bl handleIrqException
// ams::hvisor::IrqManager::HandleInterrupt(ams::hvisor::ExceptionStackFrame*):
bl _ZN3ams6hvisor10IrqManager15HandleInterruptEPNS0_19ExceptionStackFrameE
EXCEPTION_HANDLER_END _irqA64, EXCEPTION_TYPE_GUEST
UNKNOWN_EXCEPTION _fiqA64
@ -375,14 +362,16 @@ UNKNOWN_EXCEPTION _serrorA64
EXCEPTION_HANDLER_START _synchA32, EXCEPTION_TYPE_GUEST
mov x0, sp
bl handleLowerElSyncException
// ams::hvisor::HandleLowerElSyncException(ams::hvisor::ExceptionStackFrame*)
bl _ZN3ams6hvisor26HandleLowerElSyncExceptionEPNS0_19ExceptionStackFrameE
EXCEPTION_HANDLER_END _synchA32, EXCEPTION_TYPE_GUEST
EXCEPTION_HANDLER_START _irqA32, EXCEPTION_TYPE_GUEST
mov x0, sp
mov w1, #1
mov w2, #1
bl handleIrqException
// ams::hvisor::IrqManager::HandleInterrupt(ams::hvisor::ExceptionStackFrame*):
bl _ZN3ams6hvisor10IrqManager15HandleInterruptEPNS0_19ExceptionStackFrameE
EXCEPTION_HANDLER_END _irqA32, EXCEPTION_TYPE_GUEST
UNKNOWN_EXCEPTION _fiqA32

View file

@ -93,7 +93,8 @@ void DumpStackFrame(ExceptionStackFrame *frame, bool sameEl)
void ExceptionEntryPostprocess(ExceptionStackFrame *frame, bool isLowerEl)
{
if (frame == currentCoreCtx->GetGuestFrame()) {
if (isLowerEl) {
currentCoreCtx->SetGuestFrame(frame);
frame->cntp_ctl_el0 = THERMOSPHERE_GET_SYSREG(cntp_ctl_el0);
frame->cntv_ctl_el0 = THERMOSPHERE_GET_SYSREG(cntv_ctl_el0);
}

View file

@ -22,17 +22,17 @@
.type _start, %function
_start:
b start
b start2
b _start1
b _start2
.global _ZN3ams6hvisor11CoreContext23initialKernelEntrypointE
_ZN3ams6hvisor11CoreContext23initialKernelEntrypointE:
.quad 0
start:
_start1:
mov x19, #1
b _startCommon
start2:
_start2:
mov x19, xzr
_startCommon:
// Disable interrupts, select sp_el0 before mmu is enabled
@ -50,73 +50,80 @@ _startCommon:
// Save x0
mov x21, x0
bl cacheClearLocalDataCacheOnBoot
// Get core ID
mrs x22, mpidr_el1
and x22, x22, #0xFF
// ams::hvisor::cpu::ClearLocalDataCacheOnBoot
bl _ZN3ams6hvisor3cpu25ClearLocalDataCacheOnBootEv
cbz x19, 1f
// "Boot core only" stuff:
bl cacheClearSharedDataCachesOnBoot
// ams::hvisor::cpu::ClearSharedDataCachesOnBoot
bl _ZN3ams6hvisor3cpu27ClearSharedDataCachesOnBootEv
ic iallu
dsb nsh
dsb sy
isb
// 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, #0x10]
add x1, x2, x3
adr x0, _ZN3ams6hvisor9MemoryMap11imageLayoutE
mov sp, x1
bl memoryMapSetupMmu
// ams::hvisor::MemoryMap::SetupMmu(ams::hvisor::MemoryMap::LoadImageLayout const*)
bl _ZN3ams6hvisor9MemoryMap8SetupMmuEPKNS1_15LoadImageLayoutE
1:
// Enable MMU, note that the function is not allowed to use any stack
adr x0, g_loadImageLayout
adr x0, _ZN3ams6hvisor9MemoryMap11imageLayoutE
mov w1, w22
ldr x18, =_postMmuEnableReturnAddr
bl memoryMapEnableMmu
// ams::hvisor::MemoryMap::EnableMmuGetStacks(ams::hvisor::MemoryMap::LoadImageLayout const*, unsigned int)
bl _ZN3ams6hvisor9MemoryMap18EnableMmuGetStacksEPKNS1_15LoadImageLayoutEj
// This is where we will land on exception return after enabling the MMU:
_postMmuEnableReturnAddr:
// x0 = sp, x1 = crash sp
mov x23, x1
// Select sp_el2
msr spsel, #1
// Get core ID
mrs x8, mpidr_el1
and x8, x8, #0xFF
mov w0, w8
bl memoryMapGetStackTop
mov sp, x0
msr sp_el0, x23
// Set up x18, other sysregs, BSS, etc.
// Don't call init array to save space?
mov w0, w8
mov w0, w22
mov w1, w19
mov x2, x21
bl initSystem
// Save x18, reserve space for exception frame
// TODO: save exception stack too
stp x18, xzr, [sp, #-0x10]!
stp x18, x23, [sp, #-0x10]!
sub sp, sp, #EXCEP_STACK_FRAME_SIZE
prfm pstl1keep, [x18]
mov x0, sp
mov x1, x20
//str x0, [x18, #CORECTX_GUEST_FRAME_OFFSET]
bl thermosphereMain
prfm pstl1keep, [x18]
dsb sy
isb
// Jump to kernel
mov x0, sp
bl exceptionReturnPreprocess
// ams::hvisor::ExceptionEntryPostprocess(ams::hvisor::ExceptionStackFrame*, bool)
bl _ZN3ams6hvisor25ExceptionEntryPostprocessEPNS0_19ExceptionStackFrameEb
b _restoreAllRegisters
.pool
.global g_loadImageLayout
g_loadImageLayout:
// ams::hvisor::MemoryMap::imageLayout
.global _ZN3ams6hvisor9MemoryMap11imageLayoutE
_ZN3ams6hvisor9MemoryMap11imageLayoutE:
.quad __start_pa__
.quad __image_size__
.quad __temp_pa__