Skip to content

Commit

Permalink
arch: arc: fix the bug in register clear for USER_SPACE
Browse files Browse the repository at this point in the history
* blink, fp should not be always cleared
* clean up code format
* use a better way to save and restore ER_SEC_STAT

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
  • Loading branch information
Wayne Ren authored and ruuddw committed May 25, 2018
1 parent 77eb883 commit 876a9af
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 42 deletions.
13 changes: 12 additions & 1 deletion arch/arc/core/fault_s.S
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2014 Wind River Systems, Inc.
* Copyright (c) 2018 Synopsys.
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand Down Expand Up @@ -122,7 +123,12 @@ _exc_return:
st_s r2, [r1, _kernel_offset_to_current]

#ifdef CONFIG_ARC_HAS_SECURE
/* ERM to IRM */
/*
* sync up the ERSEC_STAT.ERM and SEC_STAT.IRM.
* use a fake interrupt return to simulate an exception turn.
* ERM and IRM record which mode the cpu should return, 1: secure
* 0: normal
*/
lr r3,[_ARC_V2_ERSEC_STAT]
btst r3, 31
bset.nz r3, r3, 3
Expand Down Expand Up @@ -170,11 +176,16 @@ SECTION_SUBSEC_FUNC(TEXT,__fault,__ev_trap)
mov r6, _SYSCALL_BAD

valid_syscall_id:
#ifdef CONFIG_ARC_HAS_SECURE
lr ilink, [_ARC_V2_ERSEC_STAT]
push ilink
#endif
lr ilink, [_ARC_V2_ERET]
push ilink
lr ilink, [_ARC_V2_ERSTATUS]
push ilink


bclr ilink, ilink, _ARC_V2_STATUS32_U_BIT
sr ilink, [_ARC_V2_ERSTATUS]

Expand Down
88 changes: 47 additions & 41 deletions arch/arc/core/userspace.S
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017 Synopsys.
* Copyright (c) 2018 Synopsys.
*
* SPDX-License-Identifier: Apache-2.0
*/
Expand All @@ -12,40 +12,35 @@
#include <syscall.h>

.macro clear_scratch_regs
mov r1, 0
mov r2, 0
mov r3, 0
mov r4, 0
mov r5, 0
mov r6, 0
mov r7, 0
mov r8, 0
mov r9, 0
mov r10, 0
mov r11, 0
mov r12, 0

mov fp, 0
mov r29, 0
mov r30, 0
mov blink, 0
mov r1, 0
mov r2, 0
mov r3, 0
mov r4, 0
mov r5, 0
mov r6, 0
mov r7, 0
mov r8, 0
mov r9, 0
mov r10, 0
mov r11, 0
mov r12, 0
.endm

.macro clear_callee_regs
mov r25, 0
mov r24, 0
mov r23, 0
mov r22, 0
mov r21, 0
mov r20, 0
mov r19, 0
mov r18, 0
mov r17, 0
mov r16, 0

mov r15, 0
mov r14, 0
mov r13, 0
mov r25, 0
mov r24, 0
mov r23, 0
mov r22, 0
mov r21, 0
mov r20, 0
mov r19, 0
mov r18, 0
mov r17, 0
mov r16, 0

mov r15, 0
mov r14, 0
mov r13, 0
.endm

GTEXT(_arc_userspace_enter)
Expand Down Expand Up @@ -144,6 +139,11 @@ _arc_go_to_user_space:

clear_scratch_regs

mov fp, 0
mov r29, 0
mov r30, 0
mov blink, 0

rtie

/**
Expand All @@ -166,24 +166,30 @@ SECTION_FUNC(TEXT, _arc_do_syscall)

jl [r6]

/*
* no need to clear callee regs, as they will be saved and restored
* automatically
*/
clear_scratch_regs

mov r29, 0
mov r30, 0

pop_s blink

/* through fake exception return, go back to the caller */
kflag _ARC_V2_STATUS32_AE

#ifdef CONFIG_ARC_HAS_SECURE
lr r6, [_ARC_V2_SEC_STAT]
/* the mode returns from exception return is secure mode */
bset r6, r6, 31
sr r6, [_ARC_V2_ERSEC_STAT]
#endif
/* the status and return addesss are saved in trap_s handler */
/* the status and return address are saved in trap_s handler */
pop r6
sr r6, [_ARC_V2_ERSTATUS]
pop r6
sr r6, [_ARC_V2_ERET]
#ifdef CONFIG_ARC_HAS_SECURE
pop r6
sr r6, [_ARC_V2_ERSEC_STAT]
#endif

/* no nned to clear callee regs */
clear_scratch_regs
mov r6, 0

rtie

0 comments on commit 876a9af

Please sign in to comment.