diff options
| author | David Rubin <daviru007@icloud.com> | 2024-03-25 05:30:12 -0700 |
|---|---|---|
| committer | David Rubin <daviru007@icloud.com> | 2024-05-11 02:17:11 -0700 |
| commit | 685f8282180016ac8d82ecf2fe7facc1a2d6b9f7 (patch) | |
| tree | 620d40ac62344a8e0bf97274b60d28ed7daa0da7 /lib/std | |
| parent | b28c966e332623dc43b1481b34016d18ce3262fa (diff) | |
| download | zig-685f8282180016ac8d82ecf2fe7facc1a2d6b9f7.tar.gz zig-685f8282180016ac8d82ecf2fe7facc1a2d6b9f7.zip | |
riscv: add a custom panic function
this provides a much better indication of when we are having a controlled panic with an error message
or when we are actually segfaulting, as before the `trap` as causing a segfault.
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/builtin.zig | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/lib/std/builtin.zig b/lib/std/builtin.zig index 3fb9494305..1d26c3e0c1 100644 --- a/lib/std/builtin.zig +++ b/lib/std/builtin.zig @@ -767,13 +767,31 @@ pub fn default_panic(msg: []const u8, error_return_trace: ?*StackTrace, ret_addr builtin.zig_backend == .stage2_x86 or (builtin.zig_backend == .stage2_x86_64 and (builtin.target.ofmt != .elf and builtin.target.ofmt != .macho)) or builtin.zig_backend == .stage2_sparc64 or - builtin.zig_backend == .stage2_spirv64 or - builtin.zig_backend == .stage2_riscv64) + builtin.zig_backend == .stage2_spirv64) { while (true) { @breakpoint(); } } + + if (builtin.zig_backend == .stage2_riscv64) { + asm volatile ("ecall" + : + : [number] "{a7}" (64), + [arg1] "{a0}" (1), + [arg2] "{a1}" (@intFromPtr("panicking!\n")), + [arg3] "{a2}" ("panicking!\n".len), + : "rcx", "r11", "memory" + ); + asm volatile ("ecall" + : + : [number] "{a7}" (94), + [arg1] "{a0}" (127), + : "rcx", "r11", "memory" + ); + unreachable; + } + switch (builtin.os.tag) { .freestanding => { while (true) { |
