From fe810c3696ec5c3b2ee276c2ef07112dde6c6149 Mon Sep 17 00:00:00 2001 From: shaojinchun Date: Mon, 14 Feb 2022 17:39:01 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96check=20debug=E6=93=8D?= =?UTF-8?q?=E4=BD=9C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../lwp/arch/aarch64/cortex-a/lwp_gcc.S | 77 +++++-------------- components/lwp/arch/arm/cortex-a/lwp_gcc.S | 21 ++--- libcpu/aarch64/common/context_gcc.S | 12 --- libcpu/arm/cortex-a/context_gcc.S | 4 - libcpu/arm/cortex-a/start_gcc.S | 5 -- 5 files changed, 32 insertions(+), 87 deletions(-) diff --git a/components/lwp/arch/aarch64/cortex-a/lwp_gcc.S b/components/lwp/arch/aarch64/cortex-a/lwp_gcc.S index ef15f104ec..0d597c5865 100644 --- a/components/lwp/arch/aarch64/cortex-a/lwp_gcc.S +++ b/components/lwp/arch/aarch64/cortex-a/lwp_gcc.S @@ -278,21 +278,26 @@ ret_to_user: stp x0, x1, [sp, #-0x10]! stp x29, x30, [sp, #-0x10]! + bl lwp_check_debug + bl lwp_check_exit_request + cbz w0, 1f + mov x0, xzr + b sys_exit +1: ldr x0, =rt_dbg_ops ldr x0, [x0] cbz x0, 3f bl dbg_thread_in_debug mov x1, #(1 << 21) mrs x2, spsr_el1 - cbz w0, 1f + cbz w0, 2f orr x2, x2, x1 - b 2f -1: - bic x2, x2, x1 + msr spsr_el1, x2 + b 3f 2: + bic x2, x2, x1 msr spsr_el1, x2 3: - bl lwp_signal_check cmp x0, xzr @@ -422,37 +427,12 @@ lwp_check_debug: cbnz x0, 1f ret 1: - SAVE_FPU sp - stp x0, x1, [sp, #-0x10]! - stp x2, x3, [sp, #-0x10]! - stp x4, x5, [sp, #-0x10]! - stp x6, x7, [sp, #-0x10]! - stp x10, x11, [sp, #-0x10]! - stp x12, x13, [sp, #-0x10]! - stp x14, x15, [sp, #-0x10]! - stp x16, x17, [sp, #-0x10]! - stp x18, x19, [sp, #-0x10]! - stp x20, x21, [sp, #-0x10]! - stp x22, x23, [sp, #-0x10]! - stp x24, x25, [sp, #-0x10]! - stp x26, x27, [sp, #-0x10]! - stp x28, x29, [sp, #-0x10]! - - mrs x0, fpcr - mrs x1, fpsr - stp x0, x1, [sp, #-0x10]! stp x29, x30, [sp, #-0x10]! - - bl lwp_check_exit_request - cbz x0, 1f - mov x0, xzr - b sys_exit -1: bl dbg_check_suspend cbz w0, lwp_check_debug_quit mrs x2, sp_el0 - sub x2, x2, #8 + sub x2, x2, #0x10 mov x3, x2 msr sp_el0, x2 ldr x0, =lwp_debugreturn @@ -471,43 +451,28 @@ lwp_check_debug: ic ialluis isb sy - msr elr_el1, x3 /* lwp_debugreturn */ + mrs x0, elr_el1 mrs x1, spsr_el1 stp x0, x1, [sp, #-0x10]! + msr elr_el1, x3 /* lwp_debugreturn */ mov x1, #(SPSR_Mode(0) | SPSR_A64) + orr x1, x1, #(1 << 21) msr spsr_el1, x1 eret ret_from_user: - /* sp_el0 += 8 for drop ins lwp_debugreturn */ + /* sp_el0 += 16 for drop ins lwp_debugreturn */ mrs x0, sp_el0 - add x0, x0, #8 + add x0, x0, #0x10 msr sp_el0, x0 /* now is el1, sp is pos(empty) - sizeof(context) */ mov x0, sp - add x0, x0, #0x220 /* sizeof(context) */ + add x0, x0, #0x220 mov sp, x0 - ldp x0, x1, [sp], #0x10 /* x0 is origin spsr_el1 */ - msr spsr_el1, x0 + ldp x0, x1, [sp], #0x10 /* x1 is origin spsr_el1 */ + msr elr_el1, x0 /* x0 is origin elr_el1 */ + msr spsr_el1, x1 lwp_check_debug_quit: ldp x29, x30, [sp], #0x10 - ldp x0, x1, [sp], #0x10 - msr fpcr, x0 - msr fpsr, x1 - ldp x28, x29, [sp], #0x10 - ldp x26, x27, [sp], #0x10 - ldp x24, x25, [sp], #0x10 - ldp x22, x23, [sp], #0x10 - ldp x20, x21, [sp], #0x10 - ldp x18, x19, [sp], #0x10 - ldp x16, x17, [sp], #0x10 - ldp x14, x15, [sp], #0x10 - ldp x12, x13, [sp], #0x10 - ldp x10, x11, [sp], #0x10 - ldp x6, x7, [sp], #0x10 - ldp x4, x5, [sp], #0x10 - ldp x2, x3, [sp], #0x10 - ldp x0, x1, [sp], #0x10 - RESTORE_FPU sp ret lwp_signal_quit: @@ -609,7 +574,7 @@ user_do_signal: eret lwp_debugreturn: - mov x9, 0xf000 + mov x8, 0xf000 svc #0 lwp_sigreturn: diff --git a/components/lwp/arch/arm/cortex-a/lwp_gcc.S b/components/lwp/arch/arm/cortex-a/lwp_gcc.S index 81d1418c3e..8ccbf205e9 100644 --- a/components/lwp/arch/arm/cortex-a/lwp_gcc.S +++ b/components/lwp/arch/arm/cortex-a/lwp_gcc.S @@ -189,6 +189,13 @@ svc_exit: .global ret_to_user ret_to_user: push {r0-r3, r12, lr} + bl lwp_check_debug + bl lwp_check_exit_request + cmp r0, #0 + beq 1f + mov r0, #0 + b sys_exit +1: bl lwp_signal_check cmp r0, #0 pop {r0-r3, r12, lr} @@ -199,12 +206,12 @@ ret_to_user: ldr r0, [r0] cmp r0, #0 pop {r0} - beq 1f + beq 2f push {r0-r3, r12, lr} mov r0, lr bl dbg_attach_req pop {r0-r3, r12, lr} -1: +2: movs pc, lr #ifdef RT_USING_LWP @@ -216,13 +223,7 @@ lwp_check_debug: bne 1f bx lr 1: - push {r0 - r12, lr} - bl lwp_check_exit_request - cmp r0, #0 - beq 2f - mov r0, #0 - bl sys_exit -2: + push {lr} bl dbg_check_suspend cmp r0, #0 beq lwp_check_debug_quit @@ -265,7 +266,7 @@ ret_from_user: pop {r4} msr spsr_cxsf, r4 lwp_check_debug_quit: - pop {r0 - r12, pc} + pop {pc} lwp_signal_quit: cpsid i diff --git a/libcpu/aarch64/common/context_gcc.S b/libcpu/aarch64/common/context_gcc.S index afb92b30a5..cbc1e6aa4f 100644 --- a/libcpu/aarch64/common/context_gcc.S +++ b/libcpu/aarch64/common/context_gcc.S @@ -144,10 +144,6 @@ rt_hw_get_gtimer_frq: /* Set the SP to point to the stack of the task being restored. */ MOV SP, X0 -#ifdef RT_USING_LWP - BL lwp_check_debug -#endif - LDP X2, X3, [SP], #0x10 /* SPSR and ELR. */ TST X3, #0x1f @@ -185,10 +181,6 @@ rt_hw_get_gtimer_frq: /* Set the SP to point to the stack of the task being restored. */ MOV SP, X0 -#ifdef RT_USING_LWP - bl lwp_check_debug -#endif - BL rt_thread_self MOV X19, X0 BL lwp_mmu_switch @@ -231,10 +223,6 @@ rt_hw_get_gtimer_frq: .macro RESTORE_CONTEXT_WITHOUT_MMU_SWITCH /* the SP is already ok */ -#ifdef RT_USING_LWP - bl lwp_check_debug -#endif - LDP X2, X3, [SP], #0x10 /* SPSR and ELR. */ TST X3, #0x1f diff --git a/libcpu/arm/cortex-a/context_gcc.S b/libcpu/arm/cortex-a/context_gcc.S index f537f003cf..fe73c0f258 100644 --- a/libcpu/arm/cortex-a/context_gcc.S +++ b/libcpu/arm/cortex-a/context_gcc.S @@ -246,10 +246,6 @@ rt_hw_context_switch_exit: ldmfd sp!, {r1} msr spsr_cxsf, r1 /* original mode */ -#ifdef RT_USING_LWP - bl lwp_check_debug -#endif - #ifdef RT_USING_LWP and r1, #0x1f cmp r1, #0x10 diff --git a/libcpu/arm/cortex-a/start_gcc.S b/libcpu/arm/cortex-a/start_gcc.S index 3e4083d7f0..0311aa0fb6 100644 --- a/libcpu/arm/cortex-a/start_gcc.S +++ b/libcpu/arm/cortex-a/start_gcc.S @@ -407,7 +407,6 @@ vector_irq: mrs r4, spsr sub r5, lr, #4 cps #Mode_SVC - bl lwp_check_debug and r6, r4, #0x1f cmp r6, #0x10 bne 1f @@ -505,10 +504,6 @@ rt_hw_context_switch_interrupt_do: ldmfd sp!, {r4} /* pop new task's cpsr to spsr */ msr spsr_cxsf, r4 -#ifdef RT_USING_LWP - bl lwp_check_debug -#endif - #ifdef RT_USING_LWP and r4, #0x1f cmp r4, #0x10 -- Gitee