Skip to content

Commit 84a3639

Browse files
anjiahao1xiaoxiang781216
authored andcommitted
arm-m armv7a riscv32 :use cfi in irq asm function, make a debug frame
test code hello_main int main(int argc, FAR char *argv[]) { uint32_t *p = 0xdeedbeff; *p = 0xffffff; printf("%p\n %x\n", p, *p); return 0; } qemu mps3-an547 hello_main : Triggering an exception, and gdb backtrace is: before: (gdb) bt /#0 0x0001168a in systick_getstatus (lower_=0x100010c <g_systick_lower>, status=0x1000a30 <g_intstackalloc+1600>) at /home/ajh/work/vela_system/nuttx/arch/arm/src/armv8-m/arm_systick.c:142 /#1 0x000122f4 in current_usec () at /home/ajh/work/vela_system/nuttx/drivers/timers/arch_timer.c:105 /#2 0x0001234c in udelay_accurate (microseconds=250000) at /home/ajh/work/vela_system/nuttx/drivers/timers/arch_timer.c:115 /apache#3 0x000124bc in up_udelay (microseconds=250000) at /home/ajh/work/vela_system/nuttx/drivers/timers/arch_timer.c:463 /apache#4 0x0001249e in up_mdelay (milliseconds=250) at /home/ajh/work/vela_system/nuttx/drivers/timers/arch_timer.c:446 /apache#5 0x0000920c in reset_board () at /home/ajh/work/vela_system/nuttx/sched/misc/assert.c:830 /apache#6 0x0000937c in _assert (filename=0x393f8 "/arch/arm/src/armv8-m/arm_busfault.c", linenum=113, msg=0x393f0 "panic", regs=0x1008500) at /home/ajh/work/vela_system/nuttx/sched/misc/assert.c:940 /apache#7 0x00000e2c in arm_busfault (irq=3, context=0x1008500, arg=0x0 <up_ndelay>) at /home/ajh/work/vela_system/nuttx/arch/arm/src/armv8-m/arm_busfault.c:113 /apache#8 0x000012d2 in arm_hardfault (irq=3, context=0x1008500, arg=0x0 <up_ndelay>) at /home/ajh/work/vela_system/nuttx/arch/arm/src/armv8-m/arm_hardfault.c:142 /apache#9 0x00008b20 in irq_dispatch (irq=3, context=0x1008500) at /home/ajh/work/vela_system/nuttx/sched/irq/irq_dispatch.c:145 /apache#10 0x0000041a in arm_doirq (irq=3, regs=0x1008500) at /home/ajh/work/vela_system/nuttx/arch/arm/src/armv8-m/arm_doirq.c:103 /apache#11 0x0000034e in exception_common () at /home/ajh/work/vela_system/nuttx/arch/arm/src/armv8-m/arm_exception.S:224 after: (gdb) bt /#0 systick_is_running () at /home/ajh/work/vela_system/nuttx/arch/arm/src/armv8-m/arm_systick.c:106 /#1 0x000125c0 in systick_getstatus (lower_=0x1000114 <g_systick_lower>, status=0x1007a20) at /home/ajh/work/vela_system/nuttx/arch/arm/src/armv8-m/arm_systick.c:141 /#2 0x0001323c in current_usec () at /home/ajh/work/vela_system/nuttx/drivers/timers/arch_timer.c:105 /apache#3 0x00013294 in udelay_accurate (microseconds=250000) at /home/ajh/work/vela_system/nuttx/drivers/timers/arch_timer.c:115 /apache#4 0x00013404 in up_udelay (microseconds=250000) at /home/ajh/work/vela_system/nuttx/drivers/timers/arch_timer.c:463 /apache#5 0x000133e6 in up_mdelay (milliseconds=250) at /home/ajh/work/vela_system/nuttx/drivers/timers/arch_timer.c:446 /apache#6 0x00008c5c in reset_board () at /home/ajh/work/vela_system/nuttx/sched/misc/assert.c:816 /apache#7 0x00008e88 in _assert (filename=0x39408 "/arch/arm/src/armv8-m/arm_busfault.c", linenum=113, msg=0x39400 "panic", regs=0x1007cf0) at /home/ajh/work/vela_system/nuttx/sched/misc/assert.c:915 /apache#8 0x00000ce4 in arm_busfault (irq=3, context=0x1007cf0, arg=0x0 <up_ndelay>) at /home/ajh/work/vela_system/nuttx/arch/arm/src/armv8-m/arm_busfault.c:113 /apache#9 0x0000118a in arm_hardfault (irq=3, context=0x1007cf0, arg=0x0 <up_ndelay>) at /home/ajh/work/vela_system/nuttx/arch/arm/src/armv8-m/arm_hardfault.c:142 /apache#10 0x000086cc in irq_dispatch (irq=3, context=0x1007cf0) at /home/ajh/work/vela_system/nuttx/sched/irq/irq_dispatch.c:145 /apache#11 0x0000041e in arm_doirq (irq=3, regs=0x1007cf0) at /home/ajh/work/vela_system/nuttx/arch/arm/src/armv8-m/arm_doirq.c:99 /apache#12 0x00000360 in exception_common () at /home/ajh/work/vela_system/nuttx/arch/arm/src/armv8-m/arm_exception.S:230 /apache#13 0x00027a8c in hello_main (argc=1, argv=0x1006e20) at /home/ajh/work/vela_system/apps/examples/hello/hello_main.c:39 /apache#14 0x00014968 in nxtask_startup (entrypt=0x27a7d <hello_main>, argc=1, argv=0x1006e20) at /home/ajh/work/vela_system/nuttx/libs/libc/sched/task_startup.c:72 /apache#15 0x0000f450 in nxtask_start () at /home/ajh/work/vela_system/nuttx/sched/task/task_start.c:116 /apache#16 0x00000000 in ?? () (gdb) qemu armv7a nsh, hello_main: before: (gdb) bt /#0 udelay_coarse (microseconds=156000) at /home/ajh/work/vela_system/nuttx/drivers/timers/arch_alarm.c:67 /#1 up_ndelay (nanoseconds=nanoseconds@entry=250000000) at /home/ajh/work/vela_system/nuttx/drivers/timers/arch_alarm.c:431 /#2 0x0060c630 in up_udelay (microseconds=microseconds@entry=250000) at /home/ajh/work/vela_system/nuttx/drivers/timers/arch_alarm.c:416 /apache#3 0x0060c644 in up_mdelay (milliseconds=milliseconds@entry=250) at /home/ajh/work/vela_system/nuttx/drivers/timers/arch_alarm.c:401 /apache#4 0x006056bc in reset_board () at /home/ajh/work/vela_system/nuttx/sched/misc/assert.c:816 /apache#5 _assert (filename=filename@entry=0x63047f "/arch/arm/src/armv7-a/arm_dataabort.c", linenum=linenum@entry=157, msg=msg@entry=0x62f56d "panic", regs=<optimized out>, regs@entry=0x4020af10) at /home/ajh/work/vela_system/nuttx/sched/misc/assert.c:915 /apache#6 0x0060bd74 in arm_dataabort (regs=0x4020af10, dfar=<optimized out>, dfsr=<optimized out>) at /home/ajh/work/vela_system/nuttx/arch/arm/src/armv7-a/arm_dataabort.c:157 /apache#7 0x0060bc04 in arm_vectordata () at /home/ajh/work/vela_system/nuttx/arch/arm/src/armv7-a/arm_vectors.S:438 Backtrace stopped: previous frame identical to this frame (corrupt stack?) (gdb) after: (gdb) bt /#0 udelay_coarse (microseconds=192000) at /home/ajh/work/vela_system/nuttx/drivers/timers/arch_alarm.c:67 /#1 up_ndelay (nanoseconds=nanoseconds@entry=250000000) at /home/ajh/work/vela_system/nuttx/drivers/timers/arch_alarm.c:431 /#2 0x0060c650 in up_udelay (microseconds=microseconds@entry=250000) at /home/ajh/work/vela_system/nuttx/drivers/timers/arch_alarm.c:416 /apache#3 0x0060c664 in up_mdelay (milliseconds=milliseconds@entry=250) at /home/ajh/work/vela_system/nuttx/drivers/timers/arch_alarm.c:401 /apache#4 0x006056bc in reset_board () at /home/ajh/work/vela_system/nuttx/sched/misc/assert.c:816 /apache#5 _assert (filename=filename@entry=0x63047f "/arch/arm/src/armv7-a/arm_dataabort.c", linenum=linenum@entry=157, msg=msg@entry=0x62f56d "panic", regs=<optimized out>, regs@entry=0x4020af10) at /home/ajh/work/vela_system/nuttx/sched/misc/assert.c:915 /apache#6 0x0060bd94 in arm_dataabort (regs=0x4020af10, dfar=<optimized out>, dfsr=<optimized out>) at /home/ajh/work/vela_system/nuttx/arch/arm/src/armv7-a/arm_dataabort.c:157 /apache#7 0x0060bc08 in arm_vectordata () at /home/ajh/work/vela_system/nuttx/arch/arm/src/armv7-a/arm_vectors.S:453 /apache#8 0x00620cd4 in hello_main (argc=4999, argv=0x0) at /home/ajh/work/vela_system/apps/examples/hello/hello_main.c:41 /apache#9 0x0060d320 in nxtask_startup (entrypt=0x620cc4 <hello_main>, argc=1, argv=0x4020a088) at /home/ajh/work/vela_system/nuttx/libs/libc/sched/task_startup.c:72 /apache#10 0x00609b50 in nxtask_start () at /home/ajh/work/vela_system/nuttx/sched/task/task_start.c:116 /apache#11 0x00000000 in ?? () qemu risc-v nsh before: (gdb) bt /#0 udelay_coarse (microseconds=228000, microseconds@entry=891896832) at timers/arch_alarm.c:67 /#1 up_ndelay (nanoseconds=nanoseconds@entry=250000000) at timers/arch_alarm.c:431 /#2 0x8000397e in up_udelay (microseconds=microseconds@entry=250000) at timers/arch_alarm.c:416 /apache#3 0x80003988 in up_mdelay (milliseconds=milliseconds@entry=250) at timers/arch_alarm.c:401 /apache#4 0x80011f1c in reset_board () at misc/assert.c:813 /apache#5 0x80011f7a in _assert (filename=filename@entry=0x0, linenum=linenum@entry=0, msg=msg@entry=0x8002114c "panic", regs=<optimized out>, regs@entry=0x80030704) at misc/assert.c:915 /apache#6 0x80006ad6 in riscv_exception (mcause=<optimized out>, regs=0x80030704, args=<optimized out>) at common/riscv_exception.c:129 /apache#7 0x80000d9e in riscv_doirq (irq=7, regs=<optimized out>) at common/riscv_doirq.c:99 /apache#8 0x80000164 in exception_common () at common/riscv_exception_common.S:210 Backtrace stopped: frame did not save the PC (gdb) after (gdb) bt /#0 0x80003922 in udelay_coarse (microseconds=90000, microseconds@entry=891896832) at timers/arch_alarm.c:67 /#1 up_ndelay (nanoseconds=nanoseconds@entry=250000000) at timers/arch_alarm.c:431 /#2 0x8000397e in up_udelay (microseconds=microseconds@entry=250000) at timers/arch_alarm.c:416 /apache#3 0x80003988 in up_mdelay (milliseconds=milliseconds@entry=250) at timers/arch_alarm.c:401 /apache#4 0x80011f2a in reset_board () at misc/assert.c:816 /apache#5 0x80011f7a in _assert (filename=filename@entry=0x0, linenum=linenum@entry=0, msg=msg@entry=0x8002114c "panic", regs=<optimized out>, regs@entry=0x80030704) at misc/assert.c:915 /apache#6 0x80006ad6 in riscv_exception (mcause=<optimized out>, regs=0x80030704, args=<optimized out>) at common/riscv_exception.c:129 /apache#7 0x80000d9e in riscv_doirq (irq=7, regs=<optimized out>) at common/riscv_doirq.c:99 /apache#8 0x80000166 in exception_common () at common/riscv_exception_common.S:215 /apache#9 0x8001792a in hello_main (argc=<optimized out>, argv=<optimized out>) at hello_main.c:41 /apache#10 0x80004b52 in nxtask_startup (entrypt=0x80030704, argc=1, argv=0x800300e8) at sched/task_startup.c:72 /apache#11 0x80001e72 in nxtask_start () at task/task_start.c:116 /apache#12 0x00000000 in ?? () Backtrace stopped: frame did not save the PC (gdb) Signed-off-by: anjiahao <anjiahao@xiaomi.com>
1 parent e96fb6b commit 84a3639

File tree

5 files changed

+71
-9
lines changed

5 files changed

+71
-9
lines changed

arch/arm/src/armv6-m/arm_exception.S

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@
8585
.syntax unified
8686
.type exception_common, function
8787
exception_common:
88-
88+
.cfi_sections .debug_frame
89+
.cfi_startproc
8990
/* Complete the context save */
9091

9192
/* Get the current stack pointer. The EXC_RETURN value tells us whether
@@ -162,7 +163,11 @@ exception_common:
162163
isb sy
163164
3:
164165
#endif
165-
166+
mov fp, r1
167+
.cfi_def_cfa fp, 0 /* Register in fp, so we just set fp as frame */
168+
.cfi_offset pc, REG_PC * 4
169+
.cfi_offset sp, REG_SP * 4
170+
.cfi_offset lr, REG_LR * 4
166171
bl arm_doirq /* R0=IRQ, R1=register save area on stack */
167172

168173
/* On return from arm_doirq, R0 will hold a pointer to register context
@@ -215,7 +220,7 @@ exception_common:
215220
*/
216221

217222
bx r14 /* And return */
218-
223+
.cfi_endproc
219224
.size exception_common, .-exception_common
220225

221226
/****************************************************************************

arch/arm/src/armv7-a/arm_vectors.S

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,8 @@
173173
.type arm_vectorirq, %function
174174

175175
arm_vectorirq:
176+
.cfi_sections .debug_frame
177+
.cfi_startproc
176178

177179
/* Save the LR and SPSR onto the SYS mode stack before switch. */
178180

@@ -234,6 +236,11 @@ arm_vectorirq:
234236
#endif
235237

236238
bic sp, sp, #7 /* Force 8-byte alignment */
239+
mov fp, r0
240+
.cfi_def_cfa fp, 0 /* Register in fp, so we just set fp as frame */
241+
.cfi_offset pc, REG_PC * 4
242+
.cfi_offset sp, REG_SP * 4
243+
.cfi_offset lr, REG_LR * 4
237244
bl arm_decodeirq /* Call the handler */
238245
mov sp, r4 /* Restore the possibly unaligned stack pointer */
239246

@@ -267,6 +274,7 @@ arm_vectorirq:
267274
.Lirqstacktop:
268275
.word g_intstacktop
269276
#endif
277+
.cfi_endproc
270278
.size arm_vectorirq, . - arm_vectorirq
271279

272280
.align 5
@@ -394,6 +402,8 @@ arm_vectorsvc:
394402
.type arm_vectordata, %function
395403

396404
arm_vectordata:
405+
.cfi_sections .debug_frame
406+
.cfi_startproc
397407

398408
/* Save the LR and SPSR onto the SYS mode stack before switch. */
399409

@@ -437,6 +447,11 @@ arm_vectordata:
437447
mrc CP15_DFSR(r2) /* Get r2=DFSR */
438448
mov r4, sp /* Save the SP in a preserved register */
439449
bic sp, sp, #7 /* Force 8-byte alignment */
450+
mov fp, r0
451+
.cfi_def_cfa fp, 0 /* Register in fp, so we just set fp as frame */
452+
.cfi_offset pc, REG_PC * 4
453+
.cfi_offset sp, REG_SP * 4
454+
.cfi_offset lr, REG_LR * 4
440455
bl arm_dataabort /* Call the handler */
441456
mov sp, r4 /* Restore the possibly unaligned stack pointer */
442457

@@ -465,6 +480,7 @@ arm_vectordata:
465480
/* Restore the CPSR, SYS mode registers and return. */
466481

467482
rfeia r14
483+
.cfi_endproc
468484
.size arm_vectordata, . - arm_vectordata
469485

470486
.align 5
@@ -485,6 +501,8 @@ arm_vectordata:
485501
.type arm_vectorprefetch, %function
486502

487503
arm_vectorprefetch:
504+
.cfi_sections .debug_frame
505+
.cfi_startproc
488506

489507
/* Save the LR and SPSR onto the SYS mode stack before switch. */
490508

@@ -522,6 +540,11 @@ arm_vectorprefetch:
522540
mrc CP15_IFSR(r2) /* Get r2=IFSR */
523541
mov r4, sp /* Save the SP in a preserved register */
524542
bic sp, sp, #7 /* Force 8-byte alignment */
543+
mov fp, r0
544+
.cfi_def_cfa fp, 0 /* Register in fp, so we just set fp as frame */
545+
.cfi_offset pc, REG_PC * 4
546+
.cfi_offset sp, REG_SP * 4
547+
.cfi_offset lr, REG_LR * 4
525548
bl arm_prefetchabort /* Call the handler */
526549
mov sp, r4 /* Restore the possibly unaligned stack pointer */
527550

@@ -550,6 +573,7 @@ arm_vectorprefetch:
550573
/* Restore the CPSR, SYS mode registers and return. */
551574

552575
rfeia r14
576+
.cfi_endproc
553577
.size arm_vectorprefetch, . - arm_vectorprefetch
554578

555579
.align 5
@@ -568,7 +592,8 @@ arm_vectorprefetch:
568592
.type arm_vectorundefinsn, %function
569593

570594
arm_vectorundefinsn:
571-
595+
.cfi_sections .debug_frame
596+
.cfi_startproc
572597
/* Save the LR and SPSR onto the SYS mode stack before switch. */
573598

574599
srsdb sp!, #PSR_MODE_SYS
@@ -602,6 +627,11 @@ arm_vectorundefinsn:
602627
mov r0, sp /* Get r0=xcp */
603628
mov r4, sp /* Save the SP in a preserved register */
604629
bic sp, sp, #7 /* Force 8-byte alignment */
630+
mov fp, r0
631+
.cfi_def_cfa fp, 0 /* Register in fp, so we just set fp as frame */
632+
.cfi_offset pc, REG_PC * 4
633+
.cfi_offset sp, REG_SP * 4
634+
.cfi_offset lr, REG_LR * 4
605635
bl arm_undefinedinsn /* Call the handler */
606636
mov sp, r4 /* Restore the possibly unaligned stack pointer */
607637

@@ -630,6 +660,7 @@ arm_vectorundefinsn:
630660
/* Restore the CPSR, SYS mode registers and return. */
631661

632662
rfeia r14
663+
.cfi_endproc
633664
.size arm_vectorundefinsn, . - arm_vectorundefinsn
634665

635666
.align 5
@@ -650,6 +681,8 @@ arm_vectorundefinsn:
650681
.type arm_vectorfiq, %function
651682

652683
arm_vectorfiq:
684+
.cfi_sections .debug_frame
685+
.cfi_startproc
653686
#if defined(CONFIG_ARCH_TRUSTZONE_SECURE) || defined(CONFIG_ARCH_HIPRI_INTERRUPT)
654687

655688
/* Save the LR and SPSR onto the SYS mode stack before switch. */
@@ -692,6 +725,11 @@ arm_vectorfiq:
692725
#endif
693726

694727
bic sp, sp, #7 /* Force 8-byte alignment */
728+
mov fp, r0
729+
.cfi_def_cfa fp, 0 /* Register in fp, so we just set fp as frame */
730+
.cfi_offset pc, REG_PC * 4
731+
.cfi_offset sp, REG_SP * 4
732+
.cfi_offset lr, REG_LR * 4
695733
bl arm_decodefiq /* Call the handler */
696734
mov sp, r4 /* Restore the possibly unaligned stack pointer */
697735

@@ -731,6 +769,7 @@ arm_vectorfiq:
731769
#else
732770
subs pc, lr, #4
733771
#endif
772+
.cfi_endproc
734773
.size arm_vectorfiq, . - arm_vectorfiq
735774

736775
/****************************************************************************

arch/arm/src/armv7-m/arm_exception.S

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@
121121
.type exception_common, function
122122
#endif
123123
exception_common:
124-
124+
.cfi_sections .debug_frame
125+
.cfi_startproc
125126
mrs r0, ipsr /* R0=exception number */
126127
mrs r12, control /* R12=control */
127128

@@ -199,7 +200,11 @@ exception_common:
199200
mov sp, r2 /* Instantiate the aligned stack */
200201
3:
201202
#endif
202-
203+
mov fp, r1
204+
.cfi_def_cfa r4, 0 /* Register in fp, so we just set fp as frame */
205+
.cfi_offset pc, REG_PC * 4
206+
.cfi_offset sp, REG_SP * 4
207+
.cfi_offset lr, REG_LR * 4
203208
bl arm_doirq /* R0=IRQ, R1=register save (msp) */
204209

205210
/* On return from arm_doirq, R0 will hold a pointer to register context
@@ -235,6 +240,7 @@ exception_common:
235240
*/
236241

237242
bx r14 /* And return */
243+
.cfi_endproc
238244

239245
.size exception_common, .-exception_common
240246

arch/arm/src/armv8-m/arm_exception.S

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@
114114
.thumb_func
115115
.type exception_common, function
116116
exception_common:
117-
117+
.cfi_sections .debug_frame
118+
.cfi_startproc
118119
mrs r12, control /* R12=control */
119120

120121
/* Complete the context save */
@@ -209,7 +210,11 @@ exception_common:
209210
mov sp, r2 /* Instantiate the aligned stack */
210211
3:
211212
#endif
212-
213+
mov fp, r1
214+
.cfi_def_cfa fp, 0 /* Register in fp, so we just set fp as frame */
215+
.cfi_offset pc, REG_PC * 4
216+
.cfi_offset sp, REG_SP * 4
217+
.cfi_offset lr, REG_LR * 4
213218
bl arm_doirq /* R0=IRQ, R1=register save (msp) */
214219

215220
/* On return from arm_doirq, R0 will hold a pointer to register context
@@ -255,7 +260,7 @@ exception_common:
255260
*/
256261

257262
bx r14 /* And return */
258-
263+
.cfi_endproc
259264
.size exception_common, .-exception_common
260265

261266
/****************************************************************************

arch/risc-v/src/common/riscv_exception_common.S

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@
106106
.align 8
107107

108108
exception_common:
109+
.cfi_sections .debug_frame
110+
.cfi_startproc
109111

110112
#ifdef CONFIG_ARCH_KERNEL_STACK
111113
/* Take the kernel stack into use */
@@ -200,6 +202,10 @@ handle_irq:
200202

201203
mv a0, s2 /* exception cause */
202204
mv a1, sp /* context = sp */
205+
mv fp, a1 /* Use fp to debug frame */
206+
.cfi_def_cfa fp, 0 /* Register in fp, so we just set fp as frame */
207+
.cfi_offset x2, 8 /* Toolchain not support macro, is REG_X2 * 4 */
208+
.cfi_offset ra, 0 /* Toolchain not support macro, is REG_EPC * 4 */
203209

204210
#if CONFIG_ARCH_INTERRUPTSTACK > 15
205211

@@ -274,6 +280,7 @@ return_from_exception:
274280
/* Return from exception */
275281

276282
ERET
283+
.cfi_endproc
277284

278285
/****************************************************************************
279286
* Function: riscv_jump_to_user

0 commit comments

Comments
 (0)