]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
csky: Set regs->usp to kernel sp, when the exception is from kernel
authorGuo Ren <guoren@linux.alibaba.com>
Tue, 17 Dec 2019 03:12:55 +0000 (11:12 +0800)
committerGuo Ren <guoren@linux.alibaba.com>
Fri, 21 Feb 2020 07:43:24 +0000 (15:43 +0800)
In the past, we didn't care about kernel sp when saving pt_reg. But in some
cases, we still need pt_reg->usp to represent the kernel stack before enter
exception.

For cmpxhg in atomic.S, we need save and restore usp for above.

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
arch/csky/abiv1/inc/abi/entry.h
arch/csky/abiv2/inc/abi/entry.h
arch/csky/kernel/atomic.S

index 7ab78bd0f3b13f7e52be13445314ef956566fa73..f35a9f3315ee6f62b126eb54b46f72a90d22da41 100644 (file)
 #define LSAVE_A4       40
 #define LSAVE_A5       44
 
+#define usp ss1
+
 .macro USPTOKSP
-       mtcr    sp, ss1
+       mtcr    sp, usp
        mfcr    sp, ss0
 .endm
 
 .macro KSPTOUSP
        mtcr    sp, ss0
-       mfcr    sp, ss1
+       mfcr    sp, usp
 .endm
 
 .macro SAVE_ALL epc_inc
        add     lr, r13
        stw     lr, (sp, 8)
 
+       mov     lr, sp
+       addi    lr, 32
+       addi    lr, 32
+       addi    lr, 16
+       bt      2f
        mfcr    lr, ss1
+2:
        stw     lr, (sp, 16)
 
        stw     a0, (sp, 20)
        ldw     a0, (sp, 12)
        mtcr    a0, epsr
        btsti   a0, 31
+       bt      1f
        ldw     a0, (sp, 16)
        mtcr    a0, ss1
-
+1:
        ldw     a0, (sp, 24)
        ldw     a1, (sp, 28)
        ldw     a2, (sp, 32)
        addi    sp, 32
        addi    sp, 8
 
-       bt      1f
+       bt      2f
        KSPTOUSP
-1:
+2:
        rte
 .endm
 
index 9897a16b45e5dcc75b4e6638a8ecd1153be661e9..94a7a58765dffe6a0b28bb1acb36bf6c380fbbb6 100644 (file)
 
        mfcr    lr, epsr
        stw     lr, (sp, 12)
+       btsti   lr, 31
+       bf      1f
+       addi    lr, sp, 152
+       br      2f
+1:
        mfcr    lr, usp
+2:
        stw     lr, (sp, 16)
 
        stw     a0, (sp, 20)
        mtcr    a0, epc
        ldw     a0, (sp, 12)
        mtcr    a0, epsr
+       btsti   a0, 31
        ldw     a0, (sp, 16)
        mtcr    a0, usp
+       mtcr    a0, ss0
 
 #ifdef CONFIG_CPU_HAS_HILO
        ldw     a0, (sp, 140)
@@ -86,6 +94,9 @@
        addi    sp, 40
        ldm     r16-r30, (sp)
        addi    sp, 72
+       bf      1f
+       mfcr    sp, ss0
+1:
        rte
 .endm
 
index 5b84f11485aeb8c6794699c54250cf8c54f5a91d..3821ef9b75672d8a5af90839ffa7f95cfdb4da50 100644 (file)
@@ -17,10 +17,12 @@ ENTRY(csky_cmpxchg)
        mfcr    a3, epc
        addi    a3, TRAP0_SIZE
 
-       subi    sp, 8
+       subi    sp, 16
        stw     a3, (sp, 0)
        mfcr    a3, epsr
        stw     a3, (sp, 4)
+       mfcr    a3, usp
+       stw     a3, (sp, 8)
 
        psrset  ee
 #ifdef CONFIG_CPU_HAS_LDSTEX
@@ -47,7 +49,9 @@ ENTRY(csky_cmpxchg)
        mtcr    a3, epc
        ldw     a3, (sp, 4)
        mtcr    a3, epsr
-       addi    sp, 8
+       ldw     a3, (sp, 8)
+       mtcr    a3, usp
+       addi    sp, 16
        KSPTOUSP
        rte
 END(csky_cmpxchg)