Skip to content
This repository was archived by the owner on Sep 27, 2024. It is now read-only.

Commit ce6bc1b

Browse files
rootbeerRossComputerGuy
authored andcommitted
lib/std: support riscv64
Borrow the ucontext layout from Go (probably reasonable?) and fix up some missing imports for shared structures. I can compile a glibc-linked hello.zig with: zig build-exe hello.zig -lc -target riscv64-linux-gnu.2.38 -mcpu=generic_rv64 or a native Zig binary with: zig build-exe hello.zig -target riscv64-linux -mcpu=generic_rv64 But the resulting binary segfaults immediately in my (perhaps broken) qemu setup. I've no experience in riscv64, so this maybe be broken in subtle ways, but perhaps its a useful point for someone with the right hardware to make more progress. Builds on ziglang#18803
1 parent 9d418fb commit ce6bc1b

File tree

2 files changed

+56
-1
lines changed

2 files changed

+56
-1
lines changed

lib/std/debug.zig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ pub fn dumpCurrentStackTrace(start_addr: ?usize) void {
194194

195195
pub const have_ucontext = @hasDecl(os.system, "ucontext_t") and
196196
(builtin.os.tag != .linux or switch (builtin.cpu.arch) {
197-
.mips, .mipsel, .mips64, .mips64el, .riscv64 => false,
197+
.mips, .mipsel, .mips64, .mips64el => false,
198198
else => true,
199199
});
200200

lib/std/os/linux/riscv64.zig

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ const pid_t = std.os.linux.pid_t;
99
const sockaddr = linux.sockaddr;
1010
const socklen_t = linux.socklen_t;
1111
const timespec = std.os.linux.timespec;
12+
const stack_t = linux.stack_t;
13+
const sigset_t = linux.sigset_t;
1214

1315
pub fn syscall0(number: SYS) usize {
1416
return asm volatile ("ecall"
@@ -223,3 +225,56 @@ pub const Stat = extern struct {
223225
pub const Elf_Symndx = u32;
224226

225227
pub const VDSO = struct {};
228+
229+
pub const userregs_t = extern struct {
230+
pc: u64,
231+
ra: u64,
232+
sp: u64,
233+
gp: u64,
234+
tp: u64,
235+
t0: u64,
236+
t1: u64,
237+
t2: u64,
238+
s0: u64,
239+
s1: u64,
240+
a0: u64,
241+
a1: u64,
242+
a2: u64,
243+
a3: u64,
244+
a4: u64,
245+
a5: u64,
246+
a6: u64,
247+
a7: u64,
248+
s2: u64,
249+
s3: u64,
250+
s4: u64,
251+
s5: u64,
252+
s6: u64,
253+
s7: u64,
254+
s8: u64,
255+
s9: u64,
256+
s10: u64,
257+
s11: u64,
258+
t3: u64,
259+
t4: u64,
260+
t5: u64,
261+
t6: u64,
262+
};
263+
264+
pub const fpregs_t = extern struct {
265+
f: [528]u8,
266+
};
267+
268+
pub const mcontext_t = extern struct {
269+
userregs: userregs_t,
270+
fpregs: fpregs_t,
271+
};
272+
273+
pub const ucontext_t = extern struct {
274+
flags: u64,
275+
link: ?*ucontext_t,
276+
stack: stack_t,
277+
sigmask: sigset_t,
278+
reserved: [8]u8 = undefined,
279+
mcontext: mcontext_t,
280+
};

0 commit comments

Comments
 (0)