mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2024-12-19 08:52:25 +00:00
thermosphere: clean up start.s & exception_vector.s
This commit is contained in:
parent
6f423fcfab
commit
36f48748a4
3 changed files with 73 additions and 76 deletions
|
@ -108,19 +108,19 @@ vector_entry \name
|
||||||
ldp x18, x19, [sp, #EXCEP_STACK_FRAME_SIZE]
|
ldp x18, x19, [sp, #EXCEP_STACK_FRAME_SIZE]
|
||||||
msr sp_el0, x19
|
msr sp_el0, x19
|
||||||
prfm pstl1keep, [x18]
|
prfm pstl1keep, [x18]
|
||||||
//todo str x0, [x18, #CORECTX_GUEST_FRAME_OFFSET]
|
|
||||||
mov w1, #1
|
mov w1, #1
|
||||||
.else
|
.else
|
||||||
mov w1, #0
|
mov w1, #0
|
||||||
.endif
|
.endif
|
||||||
|
// ams::hvisor::ExceptionEntryPostprocess(ams::hvisor::ExceptionStackFrame*, bool)
|
||||||
bl exceptionEntryPostprocess
|
bl _ZN3ams6hvisor25ExceptionEntryPostprocessEPNS0_19ExceptionStackFrameEb
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
.macro EXCEPTION_HANDLER_END name, type
|
.macro EXCEPTION_HANDLER_END name, type
|
||||||
.if \type != EXCEPTION_TYPE_HOST_CRASH
|
.if \type != EXCEPTION_TYPE_HOST_CRASH
|
||||||
mov x0, sp
|
mov x0, sp
|
||||||
bl exceptionReturnPreprocess
|
// ams::hvisor::ExceptionReturnPreprocess(ams::hvisor::ExceptionStackFrame*)
|
||||||
|
bl _ZN3ams6hvisor25ExceptionReturnPreprocessEPNS0_19ExceptionStackFrameE
|
||||||
b _restoreAllRegisters
|
b _restoreAllRegisters
|
||||||
.else
|
.else
|
||||||
b .
|
b .
|
||||||
|
@ -140,13 +140,25 @@ vector_base g_thermosphereVectors
|
||||||
|
|
||||||
/* Current EL, SP0 */
|
/* Current EL, SP0 */
|
||||||
vector_entry _synchSp0
|
vector_entry _synchSp0
|
||||||
|
// Safecpy
|
||||||
|
cbz x18, _handleSafecpy
|
||||||
|
|
||||||
// Used when we enable the MMU
|
// Used when we enable the MMU
|
||||||
msr elr_el2, x18
|
msr elr_el2, x18
|
||||||
// Note: non-broadcasting TLB maintenance op
|
// Note: non-broadcasting TLB maintenance op
|
||||||
tlbi alle2
|
tlbi alle2
|
||||||
dsb nsh
|
dsb ish
|
||||||
isb
|
isb
|
||||||
eret
|
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
|
check_vector_size _synchSp0
|
||||||
|
|
||||||
_unknownException:
|
_unknownException:
|
||||||
|
@ -154,7 +166,8 @@ _unknownException:
|
||||||
mov x0, x30
|
mov x0, x30
|
||||||
adr x1, g_thermosphereVectors + 4
|
adr x1, g_thermosphereVectors + 4
|
||||||
sub x0, x0, x1
|
sub x0, x0, x1
|
||||||
bl handleUnknownException
|
// ams::hvisor::HandleUnknownException(unsigned int)
|
||||||
|
bl _ZN3ams6hvisor22HandleUnknownExceptionEj
|
||||||
b .
|
b .
|
||||||
|
|
||||||
UNKNOWN_EXCEPTION _irqSp0
|
UNKNOWN_EXCEPTION _irqSp0
|
||||||
|
@ -234,18 +247,6 @@ _restoreAllRegisters:
|
||||||
|
|
||||||
UNKNOWN_EXCEPTION _serrorSp0
|
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.
|
// To save space, insert in an unused vector segment.
|
||||||
|
|
||||||
// ams::hvisor::traps::CallSmc0(ams::hvisor::ExceptionStackFrame*):
|
// ams::hvisor::traps::CallSmc0(ams::hvisor::ExceptionStackFrame*):
|
||||||
|
@ -279,6 +280,7 @@ _ZN3ams6hvisor5traps8CallSmc0EPNS0_19ExceptionStackFrameE:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
_callSmcTemplateEnd:
|
_callSmcTemplateEnd:
|
||||||
|
.cfi_endproc
|
||||||
.endfunc
|
.endfunc
|
||||||
|
|
||||||
// ams::hvisor::traps::callSmcTemplateInstructionOffset
|
// ams::hvisor::traps::callSmcTemplateInstructionOffset
|
||||||
|
@ -315,40 +317,23 @@ _ZN3ams6hvisor5traps8CallSmc1EPNS0_19ExceptionStackFrameE:
|
||||||
|
|
||||||
ldp x19, x20, [sp], #0x10
|
ldp x19, x20, [sp], #0x10
|
||||||
ret
|
ret
|
||||||
|
.cfi_endproc
|
||||||
.endfunc
|
.endfunc
|
||||||
|
|
||||||
/* Current EL, SPx */
|
/* Current EL, SPx */
|
||||||
|
|
||||||
vector_entry _synchSpx
|
EXCEPTION_HANDLER_START _synchSpx, EXCEPTION_TYPE_HOST
|
||||||
// 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
|
|
||||||
|
|
||||||
mov x0, sp
|
mov x0, sp
|
||||||
mov w1, #0
|
// ams::hvisor::HandleSameElSyncException(ams::hvisor::ExceptionStackFrame*):
|
||||||
|
bl _ZN3ams6hvisor25HandleSameElSyncExceptionEPNS0_19ExceptionStackFrameE
|
||||||
bl exceptionEntryPostprocess
|
EXCEPTION_HANDLER_END _synchSpx
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
EXCEPTION_HANDLER_START _irqSpx, EXCEPTION_TYPE_HOST
|
EXCEPTION_HANDLER_START _irqSpx, EXCEPTION_TYPE_HOST
|
||||||
mov x0, sp
|
mov x0, sp
|
||||||
mov w1, wzr
|
mov w1, #0
|
||||||
mov w2, wzr
|
mov w2, #0
|
||||||
bl handleIrqException
|
// ams::hvisor::IrqManager::HandleInterrupt(ams::hvisor::ExceptionStackFrame*):
|
||||||
|
bl _ZN3ams6hvisor10IrqManager15HandleInterruptEPNS0_19ExceptionStackFrameE
|
||||||
EXCEPTION_HANDLER_END _irqSpx, EXCEPTION_TYPE_HOST
|
EXCEPTION_HANDLER_END _irqSpx, EXCEPTION_TYPE_HOST
|
||||||
|
|
||||||
UNKNOWN_EXCEPTION _fiqSpx
|
UNKNOWN_EXCEPTION _fiqSpx
|
||||||
|
@ -358,14 +343,16 @@ UNKNOWN_EXCEPTION _serrorSpx
|
||||||
|
|
||||||
EXCEPTION_HANDLER_START _synchA64, EXCEPTION_TYPE_GUEST
|
EXCEPTION_HANDLER_START _synchA64, EXCEPTION_TYPE_GUEST
|
||||||
mov x0, sp
|
mov x0, sp
|
||||||
bl handleLowerElSyncException
|
// ams::hvisor::HandleLowerElSyncException(ams::hvisor::ExceptionStackFrame*)
|
||||||
|
bl _ZN3ams6hvisor26HandleLowerElSyncExceptionEPNS0_19ExceptionStackFrameE
|
||||||
EXCEPTION_HANDLER_END _synchA64, EXCEPTION_TYPE_GUEST
|
EXCEPTION_HANDLER_END _synchA64, EXCEPTION_TYPE_GUEST
|
||||||
|
|
||||||
EXCEPTION_HANDLER_START _irqA64, EXCEPTION_TYPE_GUEST
|
EXCEPTION_HANDLER_START _irqA64, EXCEPTION_TYPE_GUEST
|
||||||
mov x0, sp
|
mov x0, sp
|
||||||
mov w1, #1
|
mov w1, #1
|
||||||
mov w2, #0
|
mov w2, #0
|
||||||
bl handleIrqException
|
// ams::hvisor::IrqManager::HandleInterrupt(ams::hvisor::ExceptionStackFrame*):
|
||||||
|
bl _ZN3ams6hvisor10IrqManager15HandleInterruptEPNS0_19ExceptionStackFrameE
|
||||||
EXCEPTION_HANDLER_END _irqA64, EXCEPTION_TYPE_GUEST
|
EXCEPTION_HANDLER_END _irqA64, EXCEPTION_TYPE_GUEST
|
||||||
|
|
||||||
UNKNOWN_EXCEPTION _fiqA64
|
UNKNOWN_EXCEPTION _fiqA64
|
||||||
|
@ -375,14 +362,16 @@ UNKNOWN_EXCEPTION _serrorA64
|
||||||
|
|
||||||
EXCEPTION_HANDLER_START _synchA32, EXCEPTION_TYPE_GUEST
|
EXCEPTION_HANDLER_START _synchA32, EXCEPTION_TYPE_GUEST
|
||||||
mov x0, sp
|
mov x0, sp
|
||||||
bl handleLowerElSyncException
|
// ams::hvisor::HandleLowerElSyncException(ams::hvisor::ExceptionStackFrame*)
|
||||||
|
bl _ZN3ams6hvisor26HandleLowerElSyncExceptionEPNS0_19ExceptionStackFrameE
|
||||||
EXCEPTION_HANDLER_END _synchA32, EXCEPTION_TYPE_GUEST
|
EXCEPTION_HANDLER_END _synchA32, EXCEPTION_TYPE_GUEST
|
||||||
|
|
||||||
EXCEPTION_HANDLER_START _irqA32, EXCEPTION_TYPE_GUEST
|
EXCEPTION_HANDLER_START _irqA32, EXCEPTION_TYPE_GUEST
|
||||||
mov x0, sp
|
mov x0, sp
|
||||||
mov w1, #1
|
mov w1, #1
|
||||||
mov w2, #1
|
mov w2, #1
|
||||||
bl handleIrqException
|
// ams::hvisor::IrqManager::HandleInterrupt(ams::hvisor::ExceptionStackFrame*):
|
||||||
|
bl _ZN3ams6hvisor10IrqManager15HandleInterruptEPNS0_19ExceptionStackFrameE
|
||||||
EXCEPTION_HANDLER_END _irqA32, EXCEPTION_TYPE_GUEST
|
EXCEPTION_HANDLER_END _irqA32, EXCEPTION_TYPE_GUEST
|
||||||
|
|
||||||
UNKNOWN_EXCEPTION _fiqA32
|
UNKNOWN_EXCEPTION _fiqA32
|
||||||
|
|
|
@ -93,7 +93,8 @@ void DumpStackFrame(ExceptionStackFrame *frame, bool sameEl)
|
||||||
|
|
||||||
void ExceptionEntryPostprocess(ExceptionStackFrame *frame, bool isLowerEl)
|
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->cntp_ctl_el0 = THERMOSPHERE_GET_SYSREG(cntp_ctl_el0);
|
||||||
frame->cntv_ctl_el0 = THERMOSPHERE_GET_SYSREG(cntv_ctl_el0);
|
frame->cntv_ctl_el0 = THERMOSPHERE_GET_SYSREG(cntv_ctl_el0);
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,17 +22,17 @@
|
||||||
.type _start, %function
|
.type _start, %function
|
||||||
|
|
||||||
_start:
|
_start:
|
||||||
b start
|
b _start1
|
||||||
b start2
|
b _start2
|
||||||
|
|
||||||
.global _ZN3ams6hvisor11CoreContext23initialKernelEntrypointE
|
.global _ZN3ams6hvisor11CoreContext23initialKernelEntrypointE
|
||||||
_ZN3ams6hvisor11CoreContext23initialKernelEntrypointE:
|
_ZN3ams6hvisor11CoreContext23initialKernelEntrypointE:
|
||||||
.quad 0
|
.quad 0
|
||||||
|
|
||||||
start:
|
_start1:
|
||||||
mov x19, #1
|
mov x19, #1
|
||||||
b _startCommon
|
b _startCommon
|
||||||
start2:
|
_start2:
|
||||||
mov x19, xzr
|
mov x19, xzr
|
||||||
_startCommon:
|
_startCommon:
|
||||||
// Disable interrupts, select sp_el0 before mmu is enabled
|
// Disable interrupts, select sp_el0 before mmu is enabled
|
||||||
|
@ -50,73 +50,80 @@ _startCommon:
|
||||||
// Save x0
|
// Save x0
|
||||||
mov x21, 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
|
cbz x19, 1f
|
||||||
|
|
||||||
// "Boot core only" stuff:
|
// "Boot core only" stuff:
|
||||||
bl cacheClearSharedDataCachesOnBoot
|
// ams::hvisor::cpu::ClearSharedDataCachesOnBoot
|
||||||
|
bl _ZN3ams6hvisor3cpu27ClearSharedDataCachesOnBootEv
|
||||||
ic iallu
|
ic iallu
|
||||||
dsb nsh
|
dsb sy
|
||||||
isb
|
isb
|
||||||
|
|
||||||
// Temporarily use temp end region as stack, then create the translation table
|
// Temporarily use temp end region as stack, then create the translation table
|
||||||
// The stack top is also equal to the mmu table address...
|
// The stack top is also equal to the mmu table address...
|
||||||
adr x0, g_loadImageLayout
|
adr x0, _ZN3ams6hvisor9MemoryMap11imageLayoutE
|
||||||
ldp x2, x3, [x0, #0x10]
|
|
||||||
add x1, x2, x3
|
|
||||||
mov sp, x1
|
mov sp, x1
|
||||||
bl memoryMapSetupMmu
|
// ams::hvisor::MemoryMap::SetupMmu(ams::hvisor::MemoryMap::LoadImageLayout const*)
|
||||||
|
bl _ZN3ams6hvisor9MemoryMap8SetupMmuEPKNS1_15LoadImageLayoutE
|
||||||
|
|
||||||
1:
|
1:
|
||||||
// Enable MMU, note that the function is not allowed to use any stack
|
// 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
|
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:
|
// This is where we will land on exception return after enabling the MMU:
|
||||||
_postMmuEnableReturnAddr:
|
_postMmuEnableReturnAddr:
|
||||||
|
// x0 = sp, x1 = crash sp
|
||||||
|
|
||||||
|
mov x23, x1
|
||||||
|
|
||||||
// Select sp_el2
|
// Select sp_el2
|
||||||
msr spsel, #1
|
msr spsel, #1
|
||||||
|
|
||||||
// Get core ID
|
|
||||||
mrs x8, mpidr_el1
|
|
||||||
and x8, x8, #0xFF
|
|
||||||
|
|
||||||
mov w0, w8
|
|
||||||
bl memoryMapGetStackTop
|
|
||||||
mov sp, x0
|
mov sp, x0
|
||||||
|
msr sp_el0, x23
|
||||||
|
|
||||||
// Set up x18, other sysregs, BSS, etc.
|
// Set up x18, other sysregs, BSS, etc.
|
||||||
// Don't call init array to save space?
|
// Don't call init array to save space?
|
||||||
mov w0, w8
|
mov w0, w22
|
||||||
mov w1, w19
|
mov w1, w19
|
||||||
mov x2, x21
|
mov x2, x21
|
||||||
bl initSystem
|
bl initSystem
|
||||||
|
|
||||||
// Save x18, reserve space for exception frame
|
// Save x18, reserve space for exception frame
|
||||||
// TODO: save exception stack too
|
stp x18, x23, [sp, #-0x10]!
|
||||||
stp x18, xzr, [sp, #-0x10]!
|
|
||||||
sub sp, sp, #EXCEP_STACK_FRAME_SIZE
|
sub sp, sp, #EXCEP_STACK_FRAME_SIZE
|
||||||
|
|
||||||
|
prfm pstl1keep, [x18]
|
||||||
|
|
||||||
mov x0, sp
|
mov x0, sp
|
||||||
mov x1, x20
|
mov x1, x20
|
||||||
//str x0, [x18, #CORECTX_GUEST_FRAME_OFFSET]
|
//str x0, [x18, #CORECTX_GUEST_FRAME_OFFSET]
|
||||||
bl thermosphereMain
|
bl thermosphereMain
|
||||||
|
|
||||||
prfm pstl1keep, [x18]
|
|
||||||
|
|
||||||
dsb sy
|
dsb sy
|
||||||
isb
|
isb
|
||||||
|
|
||||||
// Jump to kernel
|
// Jump to kernel
|
||||||
mov x0, sp
|
mov x0, sp
|
||||||
bl exceptionReturnPreprocess
|
// ams::hvisor::ExceptionEntryPostprocess(ams::hvisor::ExceptionStackFrame*, bool)
|
||||||
|
bl _ZN3ams6hvisor25ExceptionEntryPostprocessEPNS0_19ExceptionStackFrameEb
|
||||||
b _restoreAllRegisters
|
b _restoreAllRegisters
|
||||||
|
|
||||||
.pool
|
.pool
|
||||||
|
|
||||||
.global g_loadImageLayout
|
// ams::hvisor::MemoryMap::imageLayout
|
||||||
g_loadImageLayout:
|
.global _ZN3ams6hvisor9MemoryMap11imageLayoutE
|
||||||
|
_ZN3ams6hvisor9MemoryMap11imageLayoutE:
|
||||||
.quad __start_pa__
|
.quad __start_pa__
|
||||||
.quad __image_size__
|
.quad __image_size__
|
||||||
.quad __temp_pa__
|
.quad __temp_pa__
|
||||||
|
|
Loading…
Reference in a new issue