I am doing a small project to use the standard C library for Linux for ARM on bare metal (without OS). I use qemu-system-arm as a runtime platform and GDB for debugging. I wrote a small system call handler to handle the SVC calls that the C library creates, but I am confused by the fact that my raw syscall function cannot go through the stack back to the caller, even if the SVC handler can. Handler Code:
SVC_Handler:
srsfd sp!,
cpsid i,
push {r4-r12, lr}
__in_syscall:
cmp r7,
blhs Unhandled_SVC
adr r8, SVC_Table
str r7, SysCall
ldr r7, [r8, r7, lsl
blx r7
goback:
pop {r4-r12, lr}
rfeia sp!
SysCall:
.word 0
Unhandled_SVC:
stmfd sp!, {r12, lr}
push {r2-r5}
mov r3, r1
mov r2, r0
ldr r1, SysCall
ldr r0, stringPtr
bl printf
add sp,
mov r0,
ldmfd sp!, {r12, pc}
If I set a breakpoint in __in_syscall, I see that the stack frame is fine. If I enter Unhandled_SVC either through a branch or indirectly using a pointer to SVC_Table, GDB gets confused by showing the stack frame, even if the program runs correctly.
What am I missing?
ELLCC .