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.
This commit is contained in:
David Rubin 2024-03-25 05:30:12 -07:00
parent b28c966e33
commit 685f828218
2 changed files with 21 additions and 3 deletions

View File

@ -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) {

View File

@ -526,7 +526,7 @@ pub fn backendSupportsFeature(
feature: Feature,
) bool {
return switch (feature) {
.panic_fn => ofmt == .c or use_llvm or cpu_arch == .x86_64,
.panic_fn => ofmt == .c or use_llvm or cpu_arch == .x86_64 or cpu_arch == .riscv64,
.panic_unwrap_error => ofmt == .c or use_llvm,
.safety_check_formatted => ofmt == .c or use_llvm,
.error_return_trace => use_llvm,