Skip to content

Commit

Permalink
chore: restore exception.S
Browse files Browse the repository at this point in the history
  • Loading branch information
AndreCostaaa committed Feb 6, 2025
1 parent 352eec8 commit 97ddb69
Showing 1 changed file with 64 additions and 73 deletions.
137 changes: 64 additions & 73 deletions so3/arch/arm32/exception.S
Original file line number Diff line number Diff line change
Expand Up @@ -210,34 +210,31 @@ syscall_interrupt:

__after_push_sp_usr:

@Restore r0 - r2 ldmia sp,
{
r0 - r2
}
@ Restore r0-r2
ldmia sp, {r0-r2}

#ifdef CONFIG_MMU
@Give a chance to a ptrace tracer to monitor us(before the syscall) stmfd sp !,
{ r0 - r4 } bl __check_ptrace_syscall ldmfd sp !,
{ r0 - r4 }
@ Give a chance to a ptrace tracer to monitor us (before the syscall)
stmfd sp!, {r0-r4}
bl __check_ptrace_syscall
ldmfd sp!, {r0-r4}
#endif

mov r0,
sp
mov r0, sp

cpsie i @Re -
enable interrupts bl syscall_handle cpsid i @Re -
disable interrupts to be safe in regs manipulation
cpsie i @ Re-enable interrupts
bl syscall_handle
cpsid i @ Re-disable interrupts to be safe in regs manipulation

@Check if sigreturn has been called.In this case,
we @clean the stack frame which has been used to manage the user handler
.cmp r7,
#SYSCALL_SIGRETURN bne __no_sigreturn
@ Check if sigreturn has been called. In this case, we
@ clean the stack frame which has been used to manage the user handler.
cmp r7, #SYSCALL_SIGRETURN
bne __no_sigreturn

@Reset the stack frame by removing the one issued from sigreturn add sp,
sp,
#SVC_STACK_FRAME_SIZE
@ Reset the stack frame by removing the one issued from sigreturn
add sp, sp, #SVC_STACK_FRAME_SIZE

__no_sigreturn:
__no_sigreturn:

#ifdef CONFIG_MMU
@ Give a chance to a ptrace tracer to monitor us (after the syscall)
Expand All @@ -262,74 +259,68 @@ __ret_from_fork:
msr spsr, lr

@ Restoring user mode registers (sp_usr, lr_usr)
add lr, sp, #OFFSET_SP_USR ldmia lr,
{ sp, lr } ^
add lr, sp, #OFFSET_SP_USR
ldmia lr, {sp, lr}^

ldmia sp,
{ r0 - r12 } add sp, sp,
#OFFSET_SP
ldmia sp, {r0-r12}
add sp, sp, #OFFSET_SP

dsb isb
dsb
isb

ldmia sp,
{ sp, lr, pc } ^
ldmia sp, {sp, lr, pc}^

@Used at entry point of a fork'd process (setting the return value to 0) ret_from_fork
: mov r0,
# 0


b __ret_from_fork
@ Used at entry point of a fork'd process (setting the return value to 0)
ret_from_fork:
mov r0, #0

.align 5 prefetch_abort :
b __ret_from_fork

.align 5
prefetch_abort:

@Call the C data abort handler with the following args
: @r0 = IFAR,
r1 = IFSR,
r2 = LR
@ Call the C data abort handler with the following args:
@ r0 = IFAR, r1 = IFSR, r2 = LR

mrc p15,
0, r0, c6, c0, 2 @get IFAR mrc p15, 0, r1, c5, c0,
1 @get IFSR mov r2,
lr
mrc p15, 0, r0, c6, c0, 2 @ get IFAR
mrc p15, 0, r1, c5, c0, 1 @ get IFSR
mov r2, lr

b __prefetch_abort
b __prefetch_abort

.align 5 data_abort :
.align 5
data_abort:

@Call the C data abort handler with the following args
: @r0 = FAR,
r1 = FSR,
r2 = LR
@ Call the C data abort handler with the following args:
@ r0 = FAR, r1 = FSR, r2 = LR

mrc p15,
0, r1, c5, c0, 0 @get FSR mrc p15, 0, r0, c6, c0,
0 @get FAR mov r2,
lr
mrc p15, 0, r1, c5, c0, 0 @ get FSR
mrc p15, 0, r0, c6, c0, 0 @ get FAR
mov r2, lr

b __data_abort
b __data_abort

.align 5 not_used : b not_used
.align 5
not_used:
b not_used

.align 5 irq :
.align 5
irq:

@IRQ mode(lr_irq, sp_irq, cpsr_irq)
@ IRQ mode (lr_irq, sp_irq, cpsr_irq)

@Store original r0,
and lr_irq in the IRQ stack sp =
sp_irq @sp_irq is a simple array declared in arch
/ arm /
setup.c(so address can be ascending)
@ Store original r0, and lr_irq in the IRQ stack sp = sp_irq
@ sp_irq is a simple array declared in arch/arm/setup.c (so address can be ascending)

str r0,
[sp] @original r0 str lr,
[sp, #4] @lr_irq
str r0, [sp] @ original r0
str lr, [sp, #4] @ lr_irq

mrs r0,
spsr @to preserve irq bit str r0,
[sp, #8] @spsr_irq
mrs r0, spsr @ to preserve irq bit
str r0, [sp, #8] @ spsr_irq

mov r0,
sp @to maintain a reference on sp_irq; r0 will not be affected after mode switch
mov r0, sp @ to maintain a reference on sp_irq; r0 will not be affected after mode switch

@ Now switch back to SVC. IRQs are disabled
mrs lr, cpsr
Expand Down Expand Up @@ -421,10 +412,10 @@ __ret_from_fork:

.align 5
fiq:
b
fiq
b fiq

.LCcurrent
:.word current_thread
.LCcurrent:
.word current_thread

.LClog :.word 0
.LClog:
.word 0

0 comments on commit 97ddb69

Please sign in to comment.