Commit bf241682 authored by Guo Ren's avatar Guo Ren

csky: Reconstruct signal processing

Linux kernel has provided some apis for arch signal's implementation.
For example:
	restore_saved_sigmask()
	set_current_blocked()
	restore_altstack()

But in last version of csky signal.c didn't use them and some codes are
confusing, so reconstruct signal.c with reference to riscv's code.

Now csky signal.c implementation are very close to riscv and we can
get the following benefits:
 - Clear code structure
 - The signal code of riscv and csky can be reviewed together
 - Promoting the unification of arch's signal implementation

Also modified the related code in entry.S
Signed-off-by: default avatarGuo Ren <ren_guo@c-sky.com>
Cc: Arnd Bergmann <arnd@arndb.de>
parent f4625ee0
...@@ -16,9 +16,6 @@ ...@@ -16,9 +16,6 @@
#define LSAVE_A4 40 #define LSAVE_A4 40
#define LSAVE_A5 44 #define LSAVE_A5 44
#define EPC_INCREASE 2
#define EPC_KEEP 0
.macro USPTOKSP .macro USPTOKSP
mtcr sp, ss1 mtcr sp, ss1
mfcr sp, ss0 mfcr sp, ss0
...@@ -29,10 +26,6 @@ ...@@ -29,10 +26,6 @@
mfcr sp, ss1 mfcr sp, ss1
.endm .endm
.macro INCTRAP rx
addi \rx, EPC_INCREASE
.endm
.macro SAVE_ALL epc_inc .macro SAVE_ALL epc_inc
mtcr r13, ss2 mtcr r13, ss2
mfcr r13, epsr mfcr r13, epsr
......
...@@ -21,4 +21,6 @@ ...@@ -21,4 +21,6 @@
#define SYSTRACE_SAVENUM 2 #define SYSTRACE_SAVENUM 2
#define TRAP0_SIZE 2
#endif /* __ASM_CSKY_REGDEF_H */ #endif /* __ASM_CSKY_REGDEF_H */
...@@ -14,18 +14,11 @@ ...@@ -14,18 +14,11 @@
#define LSAVE_A2 32 #define LSAVE_A2 32
#define LSAVE_A3 36 #define LSAVE_A3 36
#define EPC_INCREASE 4
#define EPC_KEEP 0
#define KSPTOUSP #define KSPTOUSP
#define USPTOKSP #define USPTOKSP
#define usp cr<14, 1> #define usp cr<14, 1>
.macro INCTRAP rx
addi \rx, EPC_INCREASE
.endm
.macro SAVE_ALL epc_inc .macro SAVE_ALL epc_inc
subi sp, 152 subi sp, 152
stw tls, (sp, 0) stw tls, (sp, 0)
......
...@@ -21,4 +21,6 @@ ...@@ -21,4 +21,6 @@
#define SYSTRACE_SAVENUM 5 #define SYSTRACE_SAVENUM 5
#define TRAP0_SIZE 4
#endif /* __ASM_CSKY_REGDEF_H */ #endif /* __ASM_CSKY_REGDEF_H */
...@@ -12,11 +12,10 @@ ...@@ -12,11 +12,10 @@
* If *ptr != oldval && return 1, * If *ptr != oldval && return 1,
* else *ptr = newval return 0. * else *ptr = newval return 0.
*/ */
#ifdef CONFIG_CPU_HAS_LDSTEX
ENTRY(csky_cmpxchg) ENTRY(csky_cmpxchg)
USPTOKSP USPTOKSP
mfcr a3, epc mfcr a3, epc
INCTRAP a3 addi a3, TRAP0_SIZE
subi sp, 8 subi sp, 8
stw a3, (sp, 0) stw a3, (sp, 0)
...@@ -24,6 +23,7 @@ ENTRY(csky_cmpxchg) ...@@ -24,6 +23,7 @@ ENTRY(csky_cmpxchg)
stw a3, (sp, 4) stw a3, (sp, 4)
psrset ee psrset ee
#ifdef CONFIG_CPU_HAS_LDSTEX
1: 1:
ldex a3, (a2) ldex a3, (a2)
cmpne a0, a3 cmpne a0, a3
...@@ -33,27 +33,7 @@ ENTRY(csky_cmpxchg) ...@@ -33,27 +33,7 @@ ENTRY(csky_cmpxchg)
bez a3, 1b bez a3, 1b
2: 2:
sync.is sync.is
mvc a0
ldw a3, (sp, 0)
mtcr a3, epc
ldw a3, (sp, 4)
mtcr a3, epsr
addi sp, 8
KSPTOUSP
rte
END(csky_cmpxchg)
#else #else
ENTRY(csky_cmpxchg)
USPTOKSP
mfcr a3, epc
INCTRAP a3
subi sp, 8
stw a3, (sp, 0)
mfcr a3, epsr
stw a3, (sp, 4)
psrset ee
1: 1:
ldw a3, (a2) ldw a3, (a2)
cmpne a0, a3 cmpne a0, a3
...@@ -61,6 +41,7 @@ ENTRY(csky_cmpxchg) ...@@ -61,6 +41,7 @@ ENTRY(csky_cmpxchg)
2: 2:
stw a1, (a2) stw a1, (a2)
3: 3:
#endif
mvc a0 mvc a0
ldw a3, (sp, 0) ldw a3, (sp, 0)
mtcr a3, epc mtcr a3, epc
...@@ -71,6 +52,7 @@ ENTRY(csky_cmpxchg) ...@@ -71,6 +52,7 @@ ENTRY(csky_cmpxchg)
rte rte
END(csky_cmpxchg) END(csky_cmpxchg)
#ifndef CONFIG_CPU_HAS_LDSTEX
/* /*
* Called from tlbmodified exception * Called from tlbmodified exception
*/ */
......
...@@ -91,7 +91,7 @@ ENTRY(csky_\name) ...@@ -91,7 +91,7 @@ ENTRY(csky_\name)
mfcr a3, ss2 mfcr a3, ss2
mfcr r6, ss3 mfcr r6, ss3
mfcr a2, ss4 mfcr a2, ss4
SAVE_ALL EPC_KEEP SAVE_ALL 0
.endm .endm
.macro tlbop_end is_write .macro tlbop_end is_write
RD_MEH a2 RD_MEH a2
...@@ -117,7 +117,7 @@ jbsr csky_cmpxchg_fixup ...@@ -117,7 +117,7 @@ jbsr csky_cmpxchg_fixup
tlbop_end 1 tlbop_end 1
ENTRY(csky_systemcall) ENTRY(csky_systemcall)
SAVE_ALL EPC_INCREASE SAVE_ALL TRAP0_SIZE
psrset ee, ie psrset ee, ie
...@@ -190,11 +190,9 @@ ENTRY(ret_from_fork) ...@@ -190,11 +190,9 @@ ENTRY(ret_from_fork)
ldw r8, (r9, TINFO_FLAGS) ldw r8, (r9, TINFO_FLAGS)
ANDI_R3 r8, (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_AUDIT) ANDI_R3 r8, (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_TRACEPOINT | _TIF_SYSCALL_AUDIT)
cmpnei r8, 0 cmpnei r8, 0
bf 3f bf ret_from_exception
mov a0, sp /* sp = pt_regs pointer */ mov a0, sp /* sp = pt_regs pointer */
jbsr syscall_trace_exit jbsr syscall_trace_exit
3:
jbsr ret_from_exception
ret_from_exception: ret_from_exception:
ld syscallid, (sp, LSAVE_PSR) ld syscallid, (sp, LSAVE_PSR)
...@@ -209,34 +207,29 @@ ret_from_exception: ...@@ -209,34 +207,29 @@ ret_from_exception:
bmaski r10, THREAD_SHIFT bmaski r10, THREAD_SHIFT
andn r9, r10 andn r9, r10
resume_userspace:
ldw r8, (r9, TINFO_FLAGS) ldw r8, (r9, TINFO_FLAGS)
andi r8, (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED) andi r8, (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED)
cmpnei r8, 0 cmpnei r8, 0
bt exit_work bt exit_work
1: RESTORE_ALL 1:
RESTORE_ALL
exit_work: exit_work:
lrw syscallid, ret_from_exception
mov lr, syscallid
btsti r8, TIF_NEED_RESCHED btsti r8, TIF_NEED_RESCHED
bt work_resched bt work_resched
/* If thread_info->flag is empty, RESTORE_ALL */
cmpnei r8, 0 mov a0, sp
bf 1b mov a1, r8
mov a0, r8 jmpi do_notify_resume
mov a1, sp
jbsr do_notify_resume /* do signals */
br resume_userspace
work_resched: work_resched:
lrw syscallid, ret_from_exception
mov r15, syscallid /* Return address in link */
jmpi schedule jmpi schedule
ENTRY(sys_rt_sigreturn)
jmpi do_rt_sigreturn
ENTRY(csky_trap) ENTRY(csky_trap)
SAVE_ALL EPC_KEEP SAVE_ALL 0
psrset ee psrset ee
mov a0, sp /* Push Stack pointer arg */ mov a0, sp /* Push Stack pointer arg */
jbsr trap_c /* Call C-level trap handler */ jbsr trap_c /* Call C-level trap handler */
...@@ -252,7 +245,7 @@ ENTRY(csky_get_tls) ...@@ -252,7 +245,7 @@ ENTRY(csky_get_tls)
/* increase epc for continue */ /* increase epc for continue */
mfcr a0, epc mfcr a0, epc
INCTRAP a0 addi a0, TRAP0_SIZE
mtcr a0, epc mtcr a0, epc
/* get current task thread_info with kernel 8K stack */ /* get current task thread_info with kernel 8K stack */
...@@ -269,7 +262,7 @@ ENTRY(csky_get_tls) ...@@ -269,7 +262,7 @@ ENTRY(csky_get_tls)
rte rte
ENTRY(csky_irq) ENTRY(csky_irq)
SAVE_ALL EPC_KEEP SAVE_ALL 0
psrset ee psrset ee
#ifdef CONFIG_PREEMPT #ifdef CONFIG_PREEMPT
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment