authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-07-26 05:22:44+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2024-07-30 01:32:47+02:00
logfb249cf3e130c292c639f2357ba3b7f66b2aa1b1
tree21050f72e922f6197b9e7452db1d492ed8ecee00
parentdd78ee43e4aa377650d15be84821f72914fad571
signaturebadge-check Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

generate_linux_syscalls: Add generation code for hexagon.


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

tools/generate_linux_syscalls.zig+54
...@@ -586,6 +586,60 @@ pub fn main() !void {...@@ -586,6 +586,60 @@ pub fn main() !void {
586586
587 try writer.writeAll("};\n\n");587 try writer.writeAll("};\n\n");
588 }588 }
589 {
590 try writer.writeAll("pub const Hexagon = enum(usize) {\n");
591
592 const child_args = [_][]const u8{
593 zig_exe,
594 "cc",
595 "-target",
596 "hexagon-freestanding-none",
597 "-E",
598 "-dD",
599 "-P",
600 "-nostdinc",
601 "-Itools/include",
602 "-Itools/include/uapi",
603 "-D __SYSCALL(nr, nm)=zigsyscall nm nr",
604 "arch/hexagon/include/uapi/asm/unistd.h",
605 };
606
607 const child_result = try std.process.Child.run(.{
608 .allocator = allocator,
609 .argv = &child_args,
610 .cwd = linux_path,
611 .cwd_dir = linux_dir,
612 });
613 if (child_result.stderr.len > 0) std.debug.print("{s}\n", .{child_result.stderr});
614
615 const defines = switch (child_result.term) {
616 .Exited => |code| if (code == 0) child_result.stdout else {
617 std.debug.print("zig cc exited with code {d}\n", .{code});
618 std.process.exit(1);
619 },
620 else => {
621 std.debug.print("zig cc crashed\n", .{});
622 std.process.exit(1);
623 },
624 };
625
626 var lines = mem.tokenizeScalar(u8, defines, '\n');
627 while (lines.next()) |line| {
628 var fields = mem.tokenizeAny(u8, line, " ");
629 const prefix = fields.next() orelse return error.Incomplete;
630
631 if (!mem.eql(u8, prefix, "zigsyscall")) continue;
632
633 const sys_name = fields.next() orelse return error.Incomplete;
634 const value = fields.rest();
635 const name = (getOverridenNameNew(value) orelse sys_name)["sys_".len..];
636 const fixed_name = if (stdlib_renames_new.get(name)) |f| f else if (stdlib_renames.get(name)) |f| f else name;
637
638 try writer.print(" {p} = {s},\n", .{ zig.fmtId(fixed_name), value });
639 }
640
641 try writer.writeAll("};\n\n");
642 }
589643
590 try buf_out.flush();644 try buf_out.flush();
591}645}