authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-06-22 15:29:33+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-07-29 09:50:41+02:00
log290609eff57a9605ff33d3c1662331c45fb80079
treeff4c94187c5bf5c3dd10e47533b91a537a4abd5d
parent0460248900023a7ac1b60e5872ba466ad8cfab5f
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

generate_linux_syscalls: Add riscv32 support.


1 files changed, 67 insertions(+), 0 deletions(-)

tools/generate_linux_syscalls.zig+67
...@@ -296,6 +296,73 @@ pub fn main() !void {...@@ -296,6 +296,73 @@ pub fn main() !void {
296296
297 try writer.writeAll("};\n\n");297 try writer.writeAll("};\n\n");
298 }298 }
299 {
300 try writer.writeAll(
301 \\pub const RiscV32 = enum(usize) {
302 \\ pub const arch_specific_syscall = 244;
303 \\
304 \\
305 );
306
307 const child_args = [_][]const u8{
308 zig_exe,
309 "cc",
310 "-target",
311 "riscv32-linux-gnuilp32",
312 "-E",
313 "-dD",
314 "-P",
315 "-nostdinc",
316 "-Iinclude",
317 "-Iinclude/uapi",
318 "arch/riscv/include/uapi/asm/unistd.h",
319 };
320
321 const child_result = try std.process.Child.run(.{
322 .allocator = allocator,
323 .argv = &child_args,
324 .cwd = linux_path,
325 .cwd_dir = linux_dir,
326 });
327 if (child_result.stderr.len > 0) std.debug.print("{s}\n", .{child_result.stderr});
328
329 const defines = switch (child_result.term) {
330 .Exited => |code| if (code == 0) child_result.stdout else {
331 std.debug.print("zig cc exited with code {d}\n", .{code});
332 std.process.exit(1);
333 },
334 else => {
335 std.debug.print("zig cc crashed\n", .{});
336 std.process.exit(1);
337 },
338 };
339
340 var lines = mem.tokenizeScalar(u8, defines, '\n');
341 loop: while (lines.next()) |line| {
342 var fields = mem.tokenizeAny(u8, line, " \t");
343 const cmd = fields.next() orelse return error.Incomplete;
344 if (!mem.eql(u8, cmd, "#define")) continue;
345 const define = fields.next() orelse return error.Incomplete;
346 const number = fields.next() orelse continue;
347
348 if (!std.ascii.isDigit(number[0])) continue;
349 if (!mem.startsWith(u8, define, "__NR")) continue;
350 const name = mem.trimLeft(u8, mem.trimLeft(u8, define, "__NR3264_"), "__NR_");
351 if (mem.eql(u8, name, "arch_specific_syscall")) continue;
352 if (mem.eql(u8, name, "syscalls")) break :loop;
353
354 const fixed_name = if (stdlib_renames.get(name)) |fixed| fixed else name;
355 try writer.print(" {p} = {s},\n", .{ zig.fmtId(fixed_name), number });
356 }
357
358 try writer.writeAll(
359 \\
360 \\ riscv_flush_icache = arch_specific_syscall + 15,
361 \\ riscv_hwprobe = arch_specific_syscall + 14,
362 \\};
363 \\
364 );
365 }
299 {366 {
300 try writer.writeAll(367 try writer.writeAll(
301 \\pub const RiscV64 = enum(usize) {368 \\pub const RiscV64 = enum(usize) {