Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions components/lwp/arch/aarch64/cortex-a/lwp_gcc.S
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/

#include "rtconfig.h"

#include "asm-generic.h"
#include "asm-fpu.h"

/*********************
Expand Down Expand Up @@ -188,10 +188,9 @@ lwp_exec_user:

/*
* void SVC_Handler(regs);
* since this routine reset the SP, we take it as a start point
*/
.global SVC_Handler
.type SVC_Handler, % function
SVC_Handler:
START_POINT(SVC_Handler)
/* x0 is initial sp */
mov sp, x0

Expand Down Expand Up @@ -220,6 +219,7 @@ SVC_Handler:
blr x30
/* jump explictly, make this code position independant */
b arch_syscall_exit
START_POINT_END(SVC_Handler)

.global arch_syscall_exit
arch_syscall_exit:
Expand Down
4 changes: 3 additions & 1 deletion components/lwp/arch/arm/cortex-a/lwp_gcc.S
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

#include "rtconfig.h"
#include "asm-generic.h"

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

.global arch_syscall_exit
arch_syscall_exit:
Expand Down
5 changes: 3 additions & 2 deletions components/lwp/arch/risc-v/rv64/lwp_gcc.S
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "cpuport.h"
#include "encoding.h"
#include "stackframe.h"
#include "asm-generic.h"

.section .text.lwp

Expand Down Expand Up @@ -269,8 +270,7 @@ arch_fork_exit:
arch_clone_exit:
j arch_syscall_exit

.global syscall_entry
syscall_entry:
START_POINT(syscall_entry)
#ifndef ARCH_USING_NEW_CTX_SWITCH
//swap to thread kernel stack
csrr t0, sstatus
Expand Down Expand Up @@ -319,6 +319,7 @@ copy_context_loop:
OPEN_INTERRUPT
call syscall_handler
j arch_syscall_exit
START_POINT_END(syscall_entry)

.global arch_syscall_exit
arch_syscall_exit:
Expand Down
26 changes: 26 additions & 0 deletions libcpu/aarch64/common/asm-generic.h
Original file line number Diff line number Diff line change
@@ -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__ */
47 changes: 0 additions & 47 deletions libcpu/aarch64/common/asm_fpu.h

This file was deleted.

16 changes: 12 additions & 4 deletions libcpu/aarch64/common/context_gcc.S
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/

#include "rtconfig.h"
#include "asm-generic.h"

#include "asm-fpu.h"

Expand Down Expand Up @@ -77,6 +78,13 @@ rt_hw_get_gtimer_frq:
MRS X0,CNTFRQ_EL0
RET

START_POINT(_thread_start)
blr x19
mov x29, #0
blr x20
b . /* never here */
START_POINT_END(_thread_start)

.macro SAVE_CONTEXT
/* Save the entire context. */
SAVE_FPU SP
Expand Down Expand Up @@ -499,18 +507,18 @@ vector_irq_exit:

// -------------------------------------------------

.globl vector_exception
vector_exception:
START_POINT(vector_exception)
SAVE_CONTEXT
STP X0, X1, [SP, #-0x10]!
BL rt_hw_trap_exception
LDP X0, X1, [SP], #0x10
MOV SP, X0
RESTORE_CONTEXT_WITHOUT_MMU_SWITCH
START_POINT_END(vector_exception)

.globl vector_serror
vector_serror:
START_POINT(vector_serror)
SAVE_CONTEXT
STP X0, X1, [SP, #-0x10]!
BL rt_hw_trap_serror
b .
START_POINT_END(vector_exception)
1 change: 1 addition & 0 deletions libcpu/aarch64/common/cpuport.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ rt_inline void rt_hw_dsb(void)
__asm__ volatile ("dsb ish":::"memory");
}

void _thread_start(void);
#endif /*CPUPORT_H__*/
71 changes: 36 additions & 35 deletions libcpu/aarch64/common/stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*/
#include <board.h>
#include <rtthread.h>
#include <cpuport.h>

#include <armv8.h>

Expand Down Expand Up @@ -64,44 +65,44 @@ 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)1; /* X1 */
*(--stk) = (rt_ubase_t)parameter; /* X0 */
*(--stk) = (rt_ubase_t)3; /* X3 */
*(--stk) = (rt_ubase_t)2; /* X2 */
*(--stk) = (rt_ubase_t)5; /* X5 */
*(--stk) = (rt_ubase_t)4; /* X4 */
*(--stk) = (rt_ubase_t)7; /* X7 */
*(--stk) = (rt_ubase_t)6; /* X6 */
*(--stk) = (rt_ubase_t)9; /* X9 */
*(--stk) = (rt_ubase_t)8; /* X8 */
*(--stk) = (rt_ubase_t)11; /* X11 */
*(--stk) = (rt_ubase_t)10; /* X10 */
*(--stk) = (rt_ubase_t)13; /* X13 */
*(--stk) = (rt_ubase_t)12; /* X12 */
*(--stk) = (rt_ubase_t)15; /* X15 */
*(--stk) = (rt_ubase_t)14; /* X14 */
*(--stk) = (rt_ubase_t)17; /* X17 */
*(--stk) = (rt_ubase_t)16; /* X16 */
*(--stk) = (rt_ubase_t)19; /* X19 */
*(--stk) = (rt_ubase_t)18; /* X18 */
*(--stk) = (rt_ubase_t)21; /* X21 */
*(--stk) = (rt_ubase_t)20; /* X20 */
*(--stk) = (rt_ubase_t)23; /* X23 */
*(--stk) = (rt_ubase_t)22; /* X22 */
*(--stk) = (rt_ubase_t)25; /* X25 */
*(--stk) = (rt_ubase_t)24; /* X24 */
*(--stk) = (rt_ubase_t)27; /* X27 */
*(--stk) = (rt_ubase_t)26; /* X26 */
*(--stk) = (rt_ubase_t)29; /* X29 */
*(--stk) = (rt_ubase_t)28; /* X28 */
*(--stk) = (rt_ubase_t)0; /* FPSR */
*(--stk) = (rt_ubase_t)0; /* FPCR */
*(--stk) = (rt_ubase_t)texit; /* X30 - procedure call link register. */
*(--stk) = (rt_ubase_t)0; /* sp_el0 */
*(--stk) = (rt_ubase_t)0; /* X1 */
*(--stk) = (rt_ubase_t)parameter; /* X0 */
*(--stk) = (rt_ubase_t)3; /* X3 */
*(--stk) = (rt_ubase_t)2; /* X2 */
*(--stk) = (rt_ubase_t)5; /* X5 */
*(--stk) = (rt_ubase_t)4; /* X4 */
*(--stk) = (rt_ubase_t)7; /* X7 */
*(--stk) = (rt_ubase_t)6; /* X6 */
*(--stk) = (rt_ubase_t)9; /* X9 */
*(--stk) = (rt_ubase_t)8; /* X8 */
*(--stk) = (rt_ubase_t)11; /* X11 */
*(--stk) = (rt_ubase_t)10; /* X10 */
*(--stk) = (rt_ubase_t)13; /* X13 */
*(--stk) = (rt_ubase_t)12; /* X12 */
*(--stk) = (rt_ubase_t)15; /* X15 */
*(--stk) = (rt_ubase_t)14; /* X14 */
*(--stk) = (rt_ubase_t)17; /* X17 */
*(--stk) = (rt_ubase_t)16; /* X16 */
*(--stk) = (rt_ubase_t)tentry; /* X19, 1st param */
*(--stk) = (rt_ubase_t)18; /* X18 */
*(--stk) = (rt_ubase_t)21; /* X21 */
*(--stk) = (rt_ubase_t)texit; /* X20, 2nd param */
*(--stk) = (rt_ubase_t)23; /* X23 */
*(--stk) = (rt_ubase_t)22; /* X22 */
*(--stk) = (rt_ubase_t)25; /* X25 */
*(--stk) = (rt_ubase_t)24; /* X24 */
*(--stk) = (rt_ubase_t)27; /* X27 */
*(--stk) = (rt_ubase_t)26; /* X26 */
*(--stk) = (rt_ubase_t)0; /* X29 - addr 0 as AAPCS64 specified */
*(--stk) = (rt_ubase_t)28; /* X28 */
*(--stk) = (rt_ubase_t)0; /* FPSR */
*(--stk) = (rt_ubase_t)0; /* FPCR */
*(--stk) = (rt_ubase_t)0; /* X30 - procedure call link register. */
*(--stk) = (rt_ubase_t)0; /* sp_el0 */

*(--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 (rt_uint8_t *)stk;
Expand Down
25 changes: 25 additions & 0 deletions libcpu/arm/cortex-a/asm-generic.h
Original file line number Diff line number Diff line change
@@ -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__ */
2 changes: 2 additions & 0 deletions libcpu/arm/cortex-a/cpuport.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,6 @@ rt_inline void rt_hw_dsb(void)
__asm volatile ("dsb":::"memory");
}

void _thread_start(void);

#endif /*CPUPORT_H__*/
6 changes: 3 additions & 3 deletions libcpu/arm/cortex-a/stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
stack_addr += sizeof(rt_uint32_t);
stack_addr = (rt_uint8_t *)RT_ALIGN_DOWN((rt_uint32_t)stack_addr, 8);
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) = 0xdeadbeef; /* r12 */
*(--stk) = 0xdeadbeef; /* r11 */
Expand All @@ -48,8 +48,8 @@ rt_uint8_t *rt_hw_stack_init(void *tentry, void *parameter,
*(--stk) = 0xdeadbeef; /* r4 */
*(--stk) = 0xdeadbeef; /* r3 */
*(--stk) = 0xdeadbeef; /* r2 */
*(--stk) = 0xdeadbeef; /* r1 */
*(--stk) = (rt_uint32_t)parameter; /* r0 : argument */
*(--stk) = (rt_uint32_t)tentry; /* r1 : argument 2 for trampoline */
*(--stk) = (rt_uint32_t)parameter; /* r0 : argument 1 */
/* cpsr */
if ((rt_uint32_t)tentry & 0x01)
*(--stk) = SVCMODE | 0x20; /* thumb mode */
Expand Down
9 changes: 9 additions & 0 deletions libcpu/arm/cortex-a/start_gcc.S
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,15 @@ after_enable_mmu_n:
#define RT_CPUS_NR 1
#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
.align 3 /* align to 2~3=8 */
svc_stack_n:
Expand Down
26 changes: 26 additions & 0 deletions libcpu/risc-v/t-head/c906/asm-generic.h
Original file line number Diff line number Diff line change
@@ -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__ */
Loading