[libcpu][component][debug] add debug info for gdb (#7033)

This commit is contained in:
Shell 2023-05-14 23:48:16 +08:00 committed by GitHub
parent f7337f9db6
commit b7554a70d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
15 changed files with 184 additions and 100 deletions

View File

@ -9,7 +9,7 @@
*/ */
#include "rtconfig.h" #include "rtconfig.h"
#include "asm-generic.h"
#include "asm-fpu.h" #include "asm-fpu.h"
/********************* /*********************
@ -188,10 +188,9 @@ lwp_exec_user:
/* /*
* void SVC_Handler(regs); * void SVC_Handler(regs);
* since this routine reset the SP, we take it as a start point
*/ */
.global SVC_Handler START_POINT(SVC_Handler)
.type SVC_Handler, % function
SVC_Handler:
/* x0 is initial sp */ /* x0 is initial sp */
mov sp, x0 mov sp, x0
@ -220,6 +219,7 @@ SVC_Handler:
blr x30 blr x30
/* jump explictly, make this code position independant */ /* jump explictly, make this code position independant */
b arch_syscall_exit b arch_syscall_exit
START_POINT_END(SVC_Handler)
.global arch_syscall_exit .global arch_syscall_exit
arch_syscall_exit: arch_syscall_exit:

View File

@ -9,6 +9,7 @@
*/ */
#include "rtconfig.h" #include "rtconfig.h"
#include "asm-generic.h"
#define Mode_USR 0x10 #define Mode_USR 0x10
#define Mode_FIQ 0x11 #define Mode_FIQ 0x11
@ -153,7 +154,7 @@ lwp_exec_user:
*/ */
.global vector_swi .global vector_swi
.type vector_swi, % function .type vector_swi, % function
vector_swi: START_POINT(vector_swi)
push {lr} push {lr}
mrs lr, spsr mrs lr, spsr
push {r4, r5, lr} push {r4, r5, lr}
@ -179,6 +180,7 @@ vector_swi:
pop {r0 - r3, r12} pop {r0 - r3, r12}
beq arch_syscall_exit beq arch_syscall_exit
blx lr blx lr
START_POINT_END(vector_swi)
.global arch_syscall_exit .global arch_syscall_exit
arch_syscall_exit: arch_syscall_exit:

View File

@ -21,6 +21,7 @@
#include "cpuport.h" #include "cpuport.h"
#include "encoding.h" #include "encoding.h"
#include "stackframe.h" #include "stackframe.h"
#include "asm-generic.h"
.section .text.lwp .section .text.lwp
@ -269,8 +270,7 @@ arch_fork_exit:
arch_clone_exit: arch_clone_exit:
j arch_syscall_exit j arch_syscall_exit
.global syscall_entry START_POINT(syscall_entry)
syscall_entry:
#ifndef ARCH_USING_NEW_CTX_SWITCH #ifndef ARCH_USING_NEW_CTX_SWITCH
//swap to thread kernel stack //swap to thread kernel stack
csrr t0, sstatus csrr t0, sstatus
@ -319,6 +319,7 @@ copy_context_loop:
OPEN_INTERRUPT OPEN_INTERRUPT
call syscall_handler call syscall_handler
j arch_syscall_exit j arch_syscall_exit
START_POINT_END(syscall_entry)
.global arch_syscall_exit .global arch_syscall_exit
arch_syscall_exit: arch_syscall_exit:

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2006-2023 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-03-12 WangXiaoyao the first version
*/
#ifndef __ASM_GENERIC_H__
#define __ASM_GENERIC_H__
/* use to mark a start point where every task start from */
#define START_POINT(funcname) \
.global funcname; \
.type funcname, %function; \
funcname: \
.cfi_sections .debug_frame, .eh_frame; \
.cfi_startproc; \
.cfi_undefined x30
#define START_POINT_END(name) \
.cfi_endproc; \
.size name, .-name;
#endif /* __ASM_GENERIC_H__ */

View File

@ -1,47 +0,0 @@
/*
* Copyright (c) 2006-2021, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2021-05-18 Jesven the first version
*/
.macro SAVE_FPU, reg
STR Q0, [\reg, #-0x10]!
STR Q1, [\reg, #-0x10]!
STR Q2, [\reg, #-0x10]!
STR Q3, [\reg, #-0x10]!
STR Q4, [\reg, #-0x10]!
STR Q5, [\reg, #-0x10]!
STR Q6, [\reg, #-0x10]!
STR Q7, [\reg, #-0x10]!
STR Q8, [\reg, #-0x10]!
STR Q9, [\reg, #-0x10]!
STR Q10, [\reg, #-0x10]!
STR Q11, [\reg, #-0x10]!
STR Q12, [\reg, #-0x10]!
STR Q13, [\reg, #-0x10]!
STR Q14, [\reg, #-0x10]!
STR Q15, [\reg, #-0x10]!
.endm
.macro RESTORE_FPU, reg
LDR Q15, [\reg], #0x10
LDR Q14, [\reg], #0x10
LDR Q13, [\reg], #0x10
LDR Q12, [\reg], #0x10
LDR Q11, [\reg], #0x10
LDR Q10, [\reg], #0x10
LDR Q9, [\reg], #0x10
LDR Q8, [\reg], #0x10
LDR Q7, [\reg], #0x10
LDR Q6, [\reg], #0x10
LDR Q5, [\reg], #0x10
LDR Q4, [\reg], #0x10
LDR Q3, [\reg], #0x10
LDR Q2, [\reg], #0x10
LDR Q1, [\reg], #0x10
LDR Q0, [\reg], #0x10
.endm

View File

@ -9,6 +9,7 @@
*/ */
#include "rtconfig.h" #include "rtconfig.h"
#include "asm-generic.h"
#include "asm-fpu.h" #include "asm-fpu.h"
@ -77,6 +78,13 @@ rt_hw_get_gtimer_frq:
MRS X0,CNTFRQ_EL0 MRS X0,CNTFRQ_EL0
RET RET
START_POINT(_thread_start)
blr x19
mov x29, #0
blr x20
b . /* never here */
START_POINT_END(_thread_start)
.macro SAVE_CONTEXT .macro SAVE_CONTEXT
/* Save the entire context. */ /* Save the entire context. */
SAVE_FPU SP SAVE_FPU SP
@ -499,18 +507,18 @@ vector_irq_exit:
// ------------------------------------------------- // -------------------------------------------------
.globl vector_exception START_POINT(vector_exception)
vector_exception:
SAVE_CONTEXT SAVE_CONTEXT
STP X0, X1, [SP, #-0x10]! STP X0, X1, [SP, #-0x10]!
BL rt_hw_trap_exception BL rt_hw_trap_exception
LDP X0, X1, [SP], #0x10 LDP X0, X1, [SP], #0x10
MOV SP, X0 MOV SP, X0
RESTORE_CONTEXT_WITHOUT_MMU_SWITCH RESTORE_CONTEXT_WITHOUT_MMU_SWITCH
START_POINT_END(vector_exception)
.globl vector_serror START_POINT(vector_serror)
vector_serror:
SAVE_CONTEXT SAVE_CONTEXT
STP X0, X1, [SP, #-0x10]! STP X0, X1, [SP, #-0x10]!
BL rt_hw_trap_serror BL rt_hw_trap_serror
b . b .
START_POINT_END(vector_exception)

View File

@ -48,4 +48,5 @@ rt_inline void rt_hw_dsb(void)
__asm__ volatile ("dsb ish":::"memory"); __asm__ volatile ("dsb ish":::"memory");
} }
void _thread_start(void);
#endif /*CPUPORT_H__*/ #endif /*CPUPORT_H__*/

View File

@ -9,6 +9,7 @@
*/ */
#include <board.h> #include <board.h>
#include <rtthread.h> #include <rtthread.h>
#include <cpuport.h>
#include <armv8.h> #include <armv8.h>
@ -64,7 +65,7 @@ rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
*(--stk) = (rt_ubase_t)0; /* Q15 */ *(--stk) = (rt_ubase_t)0; /* Q15 */
*(--stk) = (rt_ubase_t)0; /* Q15 */ *(--stk) = (rt_ubase_t)0; /* Q15 */
*(--stk) = (rt_ubase_t)1; /* X1 */ *(--stk) = (rt_ubase_t)0; /* X1 */
*(--stk) = (rt_ubase_t)parameter; /* X0 */ *(--stk) = (rt_ubase_t)parameter; /* X0 */
*(--stk) = (rt_ubase_t)3; /* X3 */ *(--stk) = (rt_ubase_t)3; /* X3 */
*(--stk) = (rt_ubase_t)2; /* X2 */ *(--stk) = (rt_ubase_t)2; /* X2 */
@ -82,26 +83,26 @@ rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
*(--stk) = (rt_ubase_t)14; /* X14 */ *(--stk) = (rt_ubase_t)14; /* X14 */
*(--stk) = (rt_ubase_t)17; /* X17 */ *(--stk) = (rt_ubase_t)17; /* X17 */
*(--stk) = (rt_ubase_t)16; /* X16 */ *(--stk) = (rt_ubase_t)16; /* X16 */
*(--stk) = (rt_ubase_t)19; /* X19 */ *(--stk) = (rt_ubase_t)tentry; /* X19, 1st param */
*(--stk) = (rt_ubase_t)18; /* X18 */ *(--stk) = (rt_ubase_t)18; /* X18 */
*(--stk) = (rt_ubase_t)21; /* X21 */ *(--stk) = (rt_ubase_t)21; /* X21 */
*(--stk) = (rt_ubase_t)20; /* X20 */ *(--stk) = (rt_ubase_t)texit; /* X20, 2nd param */
*(--stk) = (rt_ubase_t)23; /* X23 */ *(--stk) = (rt_ubase_t)23; /* X23 */
*(--stk) = (rt_ubase_t)22; /* X22 */ *(--stk) = (rt_ubase_t)22; /* X22 */
*(--stk) = (rt_ubase_t)25; /* X25 */ *(--stk) = (rt_ubase_t)25; /* X25 */
*(--stk) = (rt_ubase_t)24; /* X24 */ *(--stk) = (rt_ubase_t)24; /* X24 */
*(--stk) = (rt_ubase_t)27; /* X27 */ *(--stk) = (rt_ubase_t)27; /* X27 */
*(--stk) = (rt_ubase_t)26; /* X26 */ *(--stk) = (rt_ubase_t)26; /* X26 */
*(--stk) = (rt_ubase_t)29; /* X29 */ *(--stk) = (rt_ubase_t)0; /* X29 - addr 0 as AAPCS64 specified */
*(--stk) = (rt_ubase_t)28; /* X28 */ *(--stk) = (rt_ubase_t)28; /* X28 */
*(--stk) = (rt_ubase_t)0; /* FPSR */ *(--stk) = (rt_ubase_t)0; /* FPSR */
*(--stk) = (rt_ubase_t)0; /* FPCR */ *(--stk) = (rt_ubase_t)0; /* FPCR */
*(--stk) = (rt_ubase_t)texit; /* X30 - procedure call link register. */ *(--stk) = (rt_ubase_t)0; /* X30 - procedure call link register. */
*(--stk) = (rt_ubase_t)0; /* sp_el0 */ *(--stk) = (rt_ubase_t)0; /* sp_el0 */
*(--stk) = INITIAL_SPSR_EL1; *(--stk) = INITIAL_SPSR_EL1;
*(--stk) = (rt_ubase_t)tentry; /* Exception return address. */ *(--stk) = (rt_ubase_t)_thread_start; /* Exception return address. */
/* return task's current stack address */ /* return task's current stack address */
return (rt_uint8_t *)stk; return (rt_uint8_t *)stk;

View File

@ -0,0 +1,25 @@
/*
* Copyright (c) 2006-2023 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-03-12 WangXiaoyao the first version
*/
#ifndef __ASM_GENERIC_H__
#define __ASM_GENERIC_H__
#define START_POINT(funcname) \
.type funcname, %function; \
.global funcname; \
funcname: \
.cfi_sections .debug_frame, .eh_frame; \
.cfi_startproc; \
.cfi_undefined lr
#define START_POINT_END(name) \
.cfi_endproc; \
.size name, .-name;
#endif /* __ASM_GENERIC_H__ */

View File

@ -97,4 +97,6 @@ rt_inline void rt_hw_dsb(void)
__asm volatile ("dsb":::"memory"); __asm volatile ("dsb":::"memory");
} }
void _thread_start(void);
#endif /*CPUPORT_H__*/ #endif /*CPUPORT_H__*/

View File

@ -35,7 +35,7 @@ rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
stack_addr += sizeof(rt_uint32_t); stack_addr += sizeof(rt_uint32_t);
stack_addr = (rt_uint8_t *)RT_ALIGN_DOWN((rt_uint32_t)stack_addr, 8); stack_addr = (rt_uint8_t *)RT_ALIGN_DOWN((rt_uint32_t)stack_addr, 8);
stk = (rt_uint32_t *)stack_addr; stk = (rt_uint32_t *)stack_addr;
*(--stk) = (rt_uint32_t)tentry; /* entry point */ *(--stk) = (rt_uint32_t)_thread_start; /* entry point */
*(--stk) = (rt_uint32_t)texit; /* lr */ *(--stk) = (rt_uint32_t)texit; /* lr */
*(--stk) = 0xdeadbeef; /* r12 */ *(--stk) = 0xdeadbeef; /* r12 */
*(--stk) = 0xdeadbeef; /* r11 */ *(--stk) = 0xdeadbeef; /* r11 */
@ -48,8 +48,8 @@ rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
*(--stk) = 0xdeadbeef; /* r4 */ *(--stk) = 0xdeadbeef; /* r4 */
*(--stk) = 0xdeadbeef; /* r3 */ *(--stk) = 0xdeadbeef; /* r3 */
*(--stk) = 0xdeadbeef; /* r2 */ *(--stk) = 0xdeadbeef; /* r2 */
*(--stk) = 0xdeadbeef; /* r1 */ *(--stk) = (rt_uint32_t)tentry; /* r1 : argument 2 for trampoline */
*(--stk) = (rt_uint32_t)parameter; /* r0 : argument */ *(--stk) = (rt_uint32_t)parameter; /* r0 : argument 1 */
/* cpsr */ /* cpsr */
if ((rt_uint32_t)tentry & 0x01) if ((rt_uint32_t)tentry & 0x01)
*(--stk) = SVCMODE | 0x20; /* thumb mode */ *(--stk) = SVCMODE | 0x20; /* thumb mode */

View File

@ -673,6 +673,15 @@ rt_hw_clz:
#define RT_CPUS_NR 1 #define RT_CPUS_NR 1
#endif #endif
#include "asm-generic.h"
START_POINT(_thread_start)
mov r10, lr
blx r1
blx r10
b . /* never here */
START_POINT_END(_thread_start)
.bss .bss
.align 3 /* align to 2~3=8 */ .align 3 /* align to 2~3=8 */
svc_stack_n: svc_stack_n:

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2006-2023 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-03-12 WangXiaoyao the first version
*/
#ifndef __ASM_GENERIC_H__
#define __ASM_GENERIC_H__
/* use to mark a start point where every task start from */
#define START_POINT(funcname) \
.global funcname; \
.type funcname, %function; \
funcname: \
.cfi_sections .debug_frame, .eh_frame; \
.cfi_startproc; \
.cfi_undefined ra
#define START_POINT_END(name) \
.cfi_endproc; \
.size name, .-name;
#endif /* __ASM_GENERIC_H__ */

View File

@ -0,0 +1,26 @@
/*
* Copyright (c) 2006-2023 RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
* 2023-03-12 WangXiaoyao the first version
*/
#ifndef __ASM_GENERIC_H__
#define __ASM_GENERIC_H__
/* use to mark a start point where every task start from */
#define START_POINT(funcname) \
.global funcname; \
.type funcname, %function; \
funcname: \
.cfi_sections .debug_frame, .eh_frame; \
.cfi_startproc; \
.cfi_undefined ra
#define START_POINT_END(name) \
.cfi_endproc; \
.size name, .-name;
#endif /* __ASM_GENERIC_H__ */

View File

@ -10,13 +10,17 @@
#include "cpuport.h" #include "cpuport.h"
#include "stackframe.h" #include "stackframe.h"
#include "asm-generic.h"
.global _rt_thread_entry START_POINT(_rt_thread_entry)
_rt_thread_entry: LOAD ra, (sp) /* thread exit */
LOAD ra, (sp) /* texit */
addi sp, sp, 8 addi sp, sp, 8
LOAD a0, (sp) /* parameter */ LOAD a0, (sp) /* parameter */
addi sp, sp, 8 addi sp, sp, 8
LOAD t0, (sp) /* tentry */ LOAD t0, (sp) /* tentry */
addi sp, sp, 8 addi sp, sp, 8
jr t0 mv s1, ra
jalr t0
jalr s1
j . /* never here */
START_POINT_END(_rt_thread_entry)