mirror of
https://github.com/Atmosphere-NX/Atmosphere.git
synced 2025-06-02 15:49:48 -04:00
kern: add hardware single step extension
This commit is contained in:
parent
904ab19823
commit
4075d24e0c
10 changed files with 226 additions and 4 deletions
|
@ -15,6 +15,39 @@
|
|||
*/
|
||||
#include <mesosphere/kern_select_assembly_offsets.h>
|
||||
|
||||
#if defined(MESOSPHERE_ENABLE_HARDWARE_SINGLE_STEP)
|
||||
.macro disable_single_step, scratch
|
||||
/* Clear MDSCR_EL1.SS. */
|
||||
mrs \scratch, mdscr_el1
|
||||
bic \scratch, \scratch, #1
|
||||
msr mdscr_el1, \scratch
|
||||
.endm
|
||||
|
||||
.macro check_enable_single_step, scratch1, scratch2, spsr_value
|
||||
/* Check if single-step is requested. */
|
||||
ldrb \scratch1, [sp, #(EXCEPTION_CONTEXT_SIZE + THREAD_STACK_PARAMETERS_IS_SINGLE_STEP)]
|
||||
tbz \scratch1, #0, .skip_single_step\@
|
||||
|
||||
/* If single-step is requested, enable the single-step machine by setting MDSCR_EL1.SS. */
|
||||
mrs \scratch2, mdscr_el1
|
||||
orr \scratch2, \scratch2, #1
|
||||
msr mdscr_el1, \scratch2
|
||||
|
||||
/* Since we're returning from an exception, set SPSR.SS so we actually advance an instruction. */
|
||||
orr \spsr_value, \spsr_value, #(1 << 21)
|
||||
|
||||
isb
|
||||
|
||||
.skip_single_step\@:
|
||||
.endm
|
||||
#else
|
||||
.macro disable_single_step, scratch
|
||||
.endm
|
||||
|
||||
.macro check_enable_single_step, scratch1, scratch2, spsr_value
|
||||
.endm
|
||||
#endif
|
||||
|
||||
/* ams::kern::svc::CallReturnFromException64(Result result) */
|
||||
.section .text._ZN3ams4kern3svc25CallReturnFromException64Ev, "ax", %progbits
|
||||
.global _ZN3ams4kern3svc25CallReturnFromException64Ev
|
||||
|
@ -89,6 +122,9 @@ _ZN3ams4kern3svc14RestoreContextEm:
|
|||
ldp x30, x8, [sp, #(EXCEPTION_CONTEXT_X30_SP)]
|
||||
ldp x9, x10, [sp, #(EXCEPTION_CONTEXT_PC_PSR)]
|
||||
ldr x11, [sp, #(EXCEPTION_CONTEXT_TPIDR)]
|
||||
|
||||
check_enable_single_step w0, x0, x10
|
||||
|
||||
msr sp_el0, x8
|
||||
msr elr_el1, x9
|
||||
msr spsr_el1, x10
|
||||
|
|
|
@ -16,6 +16,39 @@
|
|||
#include <mesosphere/kern_build_config.hpp>
|
||||
#include <mesosphere/kern_select_assembly_offsets.h>
|
||||
|
||||
#if defined(MESOSPHERE_ENABLE_HARDWARE_SINGLE_STEP)
|
||||
.macro disable_single_step, scratch
|
||||
/* Clear MDSCR_EL1.SS. */
|
||||
mrs \scratch, mdscr_el1
|
||||
bic \scratch, \scratch, #1
|
||||
msr mdscr_el1, \scratch
|
||||
.endm
|
||||
|
||||
.macro check_enable_single_step, scratch1, scratch2, spsr_value
|
||||
/* Check if single-step is requested. */
|
||||
ldrb \scratch1, [sp, #(EXCEPTION_CONTEXT_SIZE + THREAD_STACK_PARAMETERS_IS_SINGLE_STEP)]
|
||||
tbz \scratch1, #0, .skip_single_step\@
|
||||
|
||||
/* If single-step is requested, enable the single-step machine by setting MDSCR_EL1.SS. */
|
||||
mrs \scratch2, mdscr_el1
|
||||
orr \scratch2, \scratch2, #1
|
||||
msr mdscr_el1, \scratch2
|
||||
|
||||
/* Since we're returning from an SVC, make sure SPSR.SS is cleared so we break instantly on the instruction after the SVC. */
|
||||
bic \spsr_value, \spsr_value, #(1 << 21)
|
||||
|
||||
isb
|
||||
|
||||
.skip_single_step\@:
|
||||
.endm
|
||||
#else
|
||||
.macro disable_single_step, scratch
|
||||
.endm
|
||||
|
||||
.macro check_enable_single_step, scratch1, scratch2, spsr_value
|
||||
.endm
|
||||
#endif
|
||||
|
||||
/* ams::kern::arch::arm64::SvcHandler64() */
|
||||
.section .text._ZN3ams4kern4arch5arm6412SvcHandler64Ev, "ax", %progbits
|
||||
.global _ZN3ams4kern4arch5arm6412SvcHandler64Ev
|
||||
|
@ -51,6 +84,9 @@ _ZN3ams4kern4arch5arm6412SvcHandler64Ev:
|
|||
stp x8, x9, [sp, #(EXCEPTION_CONTEXT_SP_PC)]
|
||||
stp x10, x11, [sp, #(EXCEPTION_CONTEXT_PSR_TPIDR)]
|
||||
|
||||
/* Disable single-step. */
|
||||
disable_single_step x8
|
||||
|
||||
/* Check if the SVC index is out of range. */
|
||||
mrs x8, esr_el1
|
||||
and x8, x8, #0xFF
|
||||
|
@ -154,6 +190,9 @@ _ZN3ams4kern4arch5arm6412SvcHandler64Ev:
|
|||
ldp x30, x8, [sp, #(EXCEPTION_CONTEXT_X30_SP)]
|
||||
ldp x9, x10, [sp, #(EXCEPTION_CONTEXT_PC_PSR)]
|
||||
ldr x11, [sp, #(EXCEPTION_CONTEXT_TPIDR)]
|
||||
|
||||
check_enable_single_step w0, x0, x10
|
||||
|
||||
msr sp_el0, x8
|
||||
msr elr_el1, x9
|
||||
msr spsr_el1, x10
|
||||
|
@ -203,6 +242,9 @@ _ZN3ams4kern4arch5arm6412SvcHandler64Ev:
|
|||
ldp x9, x10, [sp, #(EXCEPTION_CONTEXT_PC_PSR)]
|
||||
ldr x11, [sp, #(EXCEPTION_CONTEXT_TPIDR)]
|
||||
ldr x18, [sp, #(EXCEPTION_CONTEXT_X18)]
|
||||
|
||||
check_enable_single_step w12, x12, x10
|
||||
|
||||
msr sp_el0, x8
|
||||
msr elr_el1, x9
|
||||
msr spsr_el1, x10
|
||||
|
@ -260,6 +302,9 @@ _ZN3ams4kern4arch5arm6412SvcHandler32Ev:
|
|||
stp x12, x13, [sp, #(EXCEPTION_CONTEXT_X12_X13)]
|
||||
stp x14, xzr, [sp, #(EXCEPTION_CONTEXT_X14_X15)]
|
||||
|
||||
/* Disable single-step. */
|
||||
disable_single_step x8
|
||||
|
||||
/* Check if the SVC index is out of range. */
|
||||
mrs x16, esr_el1
|
||||
and x16, x16, #0xFF
|
||||
|
@ -359,6 +404,9 @@ _ZN3ams4kern4arch5arm6412SvcHandler32Ev:
|
|||
/* Restore registers. */
|
||||
ldp x17, x20, [sp, #(EXCEPTION_CONTEXT_PC_PSR)]
|
||||
ldr x19, [sp, #(EXCEPTION_CONTEXT_TPIDR)]
|
||||
|
||||
check_enable_single_step w0, x0, x20
|
||||
|
||||
msr elr_el1, x17
|
||||
msr spsr_el1, x20
|
||||
msr tpidr_el0, x19
|
||||
|
@ -402,6 +450,9 @@ _ZN3ams4kern4arch5arm6412SvcHandler32Ev:
|
|||
ldp x14, xzr, [sp, #(EXCEPTION_CONTEXT_X14_X15)]
|
||||
ldp x17, x20, [sp, #(EXCEPTION_CONTEXT_PC_PSR)]
|
||||
ldr x19, [sp, #(EXCEPTION_CONTEXT_TPIDR)]
|
||||
|
||||
check_enable_single_step w21, x21, x20
|
||||
|
||||
msr elr_el1, x17
|
||||
msr spsr_el1, x20
|
||||
msr tpidr_el0, x19
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue