riscv/crt0: Use a jal instruction to jump to _ctrap

This ensures that running `b _ctrap; c; bt` inside gdb shows the right
backtrace. If we jump without setting ra gdb gets confused about the
backtrace since we don't have the right cfi directives inside ctrap.
This does not result in any downsides since ra has already been saved.
Previously we had to set a breakpoint just before this jump to get a
correct backtrace, now it's possible to set a breakpoint in _ctrap
instead:

```
Reading symbols from test/test-fopen...
Breakpoint 1 at 0x80000058: file ../../picolibc/picocrt/machine/riscv/crt0.c, line 84.
Remote debugging using :1234
0x0000000000001000 in ?? ()
Continuing.

Breakpoint 1, _ctrap (fault=0x805feee8) at ../../picolibc/picocrt/machine/riscv/crt0.c:84
84              printf("RISCV fault\n");
#0  _ctrap (fault=0x805feee8) at ../../picolibc/picocrt/machine/riscv/crt0.c:84
#1  0x00000000800001c4 in _trap () at ../../picolibc/picocrt/machine/riscv/crt0.c:168
#2  0x00000000800013d0 in fclose (f=0x804008c0) at ../../picolibc/newlib/libc/tinystdio/fclose.c:39
#3  0x0000000080000680 in main () at ../../picolibc/test/test-fopen.c:85
(gdb)
```
This commit is contained in:
Alex Richardson 2023-11-30 14:01:29 -08:00
parent 4a97063282
commit c9977d6f35

View File

@ -161,7 +161,7 @@ _trap(void)
"csrw mstatus, t0\n"
"csrwi fcsr, 0");
#endif
__asm__("j _ctrap");
__asm__("jal _ctrap");
}
#endif