authorgravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2021-10-17 11:45:14-04:00
committergravatar for jacoblevgw@gmail.comJacob G-W <jacoblevgw@gmail.com> 2021-11-09 07:08:27-05:00
log73be14027d91641d59058c24ceb82c7ef46c2796
tree1a01a35fe7e33b0fc55f1601a01123a34e85e0c7
parentfe314e60bbb2861484241a81d3d6185dbb60d1e8

plan9: more syscalls


2 files changed, 69 insertions(+), 15 deletions(-)

lib/std/os/plan9.zig+23-1
...@@ -64,6 +64,28 @@ pub fn pwrite(fd: usize, buf: [*]const u8, count: usize, offset: usize) usize {...@@ -64,6 +64,28 @@ pub fn pwrite(fd: usize, buf: [*]const u8, count: usize, offset: usize) usize {
64 return syscall_bits.syscall4(.PWRITE, fd, @ptrToInt(buf), count, offset);64 return syscall_bits.syscall4(.PWRITE, fd, @ptrToInt(buf), count, offset);
65}65}
6666
67pub fn open(path: [*:0]const u8, omode: OpenMode) usize {
68 return syscall_bits.syscall2(.OPEN, @ptrToInt(path), @enumToInt(omode));
69}
70
71pub fn create(path: [*:0]const u8, omode: OpenMode, perms: usize) usize {
72 return syscall_bits.syscall3(.CREATE, @ptrToInt(path), @enumToInt(omode), perms);
73}
74
67pub fn exits(status: ?[*:0]const u8) void {75pub fn exits(status: ?[*:0]const u8) void {
68 syscall_bits.syscall1(.EXITS, if (status) |s| @ptrToInt(s) else 0);76 _ = syscall_bits.syscall1(.EXITS, if (status) |s| @ptrToInt(s) else 0);
69}77}
78
79pub fn close(fd: usize) usize {
80 return syscall_bits.syscall1(.CLOSE, fd);
81}
82pub const OpenMode = enum(usize) {
83 OREAD = 0, //* open for read
84 OWRITE = 1, //* write
85 ORDWR = 2, //* read and write
86 OEXEC = 3, //* execute, == read but check execute permission
87 OTRUNC = 16, //* or'ed in (except for exec), truncate file first
88 OCEXEC = 32, //* or'ed in (per file descriptor), close on exec
89 ORCLOSE = 64, //* or'ed in, remove on close
90 OEXCL = 0x1000, //* or'ed in, exclusive create
91};
lib/std/os/plan9/x86_64.zig+46-14
...@@ -1,11 +1,21 @@...@@ -1,11 +1,21 @@
1const plan9 = @import("../plan9.zig");1const plan9 = @import("../plan9.zig");
2// TODO get ret from inline asm
3// TODO better inline asm2// TODO better inline asm
43
5pub fn syscall4(sys: plan9.SYS, arg0: usize, arg1: usize, arg2: usize, arg3: usize) usize {4pub fn syscall1(sys: plan9.SYS, arg0: usize) usize {
5 return asm volatile (
6 \\push %%r8
7 \\push $0
8 \\syscall
9 \\pop %%r11
10 \\pop %%r11
11 : [ret] "={rax}" (-> usize),
12 : [syscall_number] "{rbp}" (@enumToInt(sys)),
13 [arg0] "{r8}" (arg0),
14 : "rcx", "rax", "rbp", "r11", "memory"
15 );
16}
17pub fn syscall2(sys: plan9.SYS, arg0: usize, arg1: usize) usize {
6 return asm volatile (18 return asm volatile (
7 \\push %%r11
8 \\push %%r10
9 \\push %%r919 \\push %%r9
10 \\push %%r820 \\push %%r8
11 \\push $021 \\push $0
...@@ -13,29 +23,51 @@ pub fn syscall4(sys: plan9.SYS, arg0: usize, arg1: usize, arg2: usize, arg3: usi...@@ -13,29 +23,51 @@ pub fn syscall4(sys: plan9.SYS, arg0: usize, arg1: usize, arg2: usize, arg3: usi
13 \\pop %%r1123 \\pop %%r11
14 \\pop %%r1124 \\pop %%r11
15 \\pop %%r1125 \\pop %%r11
26 : [ret] "={rax}" (-> usize),
27 : [arg0] "{r8}" (arg0),
28 [arg1] "{r9}" (arg1),
29 [syscall_number] "{rbp}" (@enumToInt(sys)),
30 : "rcx", "rax", "rbp", "r11", "memory"
31 );
32}
33pub fn syscall3(sys: plan9.SYS, arg0: usize, arg1: usize, arg2: usize) usize {
34 return asm volatile (
35 \\push %%r10
36 \\push %%r9
37 \\push %%r8
38 \\push $0
39 \\syscall
40 \\pop %%r11
41 \\pop %%r11
16 \\pop %%r1142 \\pop %%r11
17 \\pop %%r1143 \\pop %%r11
18 : [ret] "={rax}" (-> usize),44 : [ret] "={rax}" (-> usize),
19 // :
20 : [arg0] "{r8}" (arg0),45 : [arg0] "{r8}" (arg0),
21 [arg1] "{r9}" (arg1),46 [arg1] "{r9}" (arg1),
22 [arg2] "{r10}" (arg2),47 [arg2] "{r10}" (arg2),
23 [arg2] "{r11}" (arg3),
24 [syscall_number] "{rbp}" (@enumToInt(sys)),48 [syscall_number] "{rbp}" (@enumToInt(sys)),
25 : "rcx", "rbp", "r11", "memory"49 : "rcx", "rax", "rbp", "r11", "memory"
26 );50 );
27}51}
28pub fn syscall1(sys: plan9.SYS, arg0: usize) void {52pub fn syscall4(sys: plan9.SYS, arg0: usize, arg1: usize, arg2: usize, arg3: usize) usize {
29 _ = sys;53 return asm volatile (
30 asm volatile (54 \\push %%r11
55 \\push %%r10
56 \\push %%r9
31 \\push %%r857 \\push %%r8
32 \\push $058 \\push $0
33 \\syscall59 \\syscall
34 \\pop %%r1160 \\pop %%r11
35 \\pop %%r1161 \\pop %%r11
36 :62 \\pop %%r11
37 : [syscall_number] "{rbp}" (@enumToInt(sys)),63 \\pop %%r11
38 [arg0] "{r8}" (arg0),64 \\pop %%r11
39 : "rcx", "rbp", "r11", "memory"65 : [ret] "={rax}" (-> usize),
66 : [arg0] "{r8}" (arg0),
67 [arg1] "{r9}" (arg1),
68 [arg2] "{r10}" (arg2),
69 [arg2] "{r11}" (arg3),
70 [syscall_number] "{rbp}" (@enumToInt(sys)),
71 : "rcx", "rax", "rbp", "r11", "memory"
40 );72 );
41}73}