1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
// SPDX-FileCopyrightText: 2024 Himbeer <himbeer@disroot.org>
//
// SPDX-License-Identifier: AGPL-3.0-or-later
const Result = extern struct {
value: usize,
status: usize,
};
export fn _start() void {
main();
}
pub fn main() void {
const s1 = "Hello";
asm volatile (
\\ li a7, 100000
\\ ecall
:
: [s] "{a0}" (s1.ptr),
[n] "{a1}" (s1.len),
: "a7"
);
const path = "/foo\x00";
asm volatile (
\\ li a7, 100003
\\ li a2, 0
\\ ecall
:
: [path] "{a0}" (path.ptr),
[readFn] "{a1}" (&read),
: "a7", "a2"
);
const s2 = "Stream resource provided";
asm volatile (
\\ li a7, 100000
\\ ecall
:
: [s] "{a0}" (s2.ptr),
[n] "{a1}" (s2.len),
: "a7"
);
const handle = asm volatile (
\\ li a7, 100001
\\ ecall
: [handle] "={a0}" (-> usize),
: [path] "{a0}" (path.ptr),
: "a7", "a1"
);
const s3 = "Resource opened";
asm volatile (
\\ li a7, 100000
\\ ecall
:
: [s] "{a0}" (s3.ptr),
[n] "{a1}" (s3.len),
: "a7"
);
var buf: [8]u8 = undefined;
asm volatile (
\\ li a7, 100009
\\ ecall
:
: [handle] "{a0}" (handle),
[buffer] "{a1}" (&buf),
[len] "{a2}" (buf.len),
);
const s4 = "Bytes read";
asm volatile (
\\ li a7, 100000
\\ ecall
:
: [s] "{a0}" (s4.ptr),
[n] "{a1}" (s4.len),
: "a7"
);
}
pub fn read(buffer: []u8) Result {
for (buffer, 0..) |_, i| {
buffer[i] = 0;
}
return .{
.value = buffer.len,
.status = 0,
};
}
|