aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/create_process/build.zig26
-rw-r--r--examples/create_process/src/main.zig23
-rw-r--r--examples/create_process/src/main2.zig10
l---------examples/create_process/src/program21
4 files changed, 28 insertions, 32 deletions
diff --git a/examples/create_process/build.zig b/examples/create_process/build.zig
index b358a37..a52bd17 100644
--- a/examples/create_process/build.zig
+++ b/examples/create_process/build.zig
@@ -25,24 +25,24 @@ pub fn build(b: *std.Build) void {
// set a preferred release mode, allowing the user to decide how to optimize.
const optimize = b.standardOptimizeOption(.{});
- const exe = b.addExecutable(.{
- .name = "create_process",
- .root_source_file = b.path("src/main.zig"),
- .target = target,
- .optimize = optimize,
- });
const exe2 = b.addExecutable(.{
.name = "program2",
.root_source_file = b.path("src/main2.zig"),
.target = target,
.optimize = optimize,
});
+ const exe = b.addExecutable(.{
+ .name = "create_process",
+ .root_source_file = b.path("src/main.zig"),
+ .target = target,
+ .optimize = optimize,
+ });
// This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default
// step when running `zig build`).
- b.installArtifact(exe);
b.installArtifact(exe2);
+ b.installArtifact(exe);
// This *creates* a Run step in the build graph, to be executed when another
// step is evaluated that depends on it. The next line below will establish
@@ -69,24 +69,24 @@ pub fn build(b: *std.Build) void {
// Creates a step for unit testing. This only builds the test executable
// but does not run it.
- const exe_unit_tests = b.addTest(.{
- .root_source_file = b.path("src/main.zig"),
+ const exe2_unit_tests = b.addTest(.{
+ .root_source_file = b.path("src/main2.zig"),
.target = target,
.optimize = optimize,
});
- const exe2_unit_tests = b.addTest(.{
- .root_source_file = b.path("src/main2.zig"),
+ const exe_unit_tests = b.addTest(.{
+ .root_source_file = b.path("src/main.zig"),
.target = target,
.optimize = optimize,
});
- const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
const run_exe2_unit_tests = b.addRunArtifact(exe2_unit_tests);
+ const run_exe_unit_tests = b.addRunArtifact(exe_unit_tests);
// Similar to creating the run step earlier, this exposes a `test` step to
// the `zig build --help` menu, providing a way for the user to request
// running the unit tests.
const test_step = b.step("test", "Run unit tests");
- test_step.dependOn(&run_exe_unit_tests.step);
test_step.dependOn(&run_exe2_unit_tests.step);
+ test_step.dependOn(&run_exe_unit_tests.step);
}
diff --git a/examples/create_process/src/main.zig b/examples/create_process/src/main.zig
index 6b31b4f..404aa77 100644
--- a/examples/create_process/src/main.zig
+++ b/examples/create_process/src/main.zig
@@ -2,6 +2,9 @@
//
// SPDX-License-Identifier: AGPL-3.0-or-later
+const program2 = @embedFile("program2");
+var buf: [program2.len]u8 = undefined;
+
export fn _start() void {
main();
}
@@ -9,7 +12,7 @@ export fn _start() void {
pub fn main() void {
const msg = "Hello from program 1";
asm volatile (
- \\ li a7, 100000
+ \\ li a7, 100001
\\ ecall
:
: [ptr] "{a0}" (msg.ptr),
@@ -17,23 +20,19 @@ pub fn main() void {
: "a7"
);
- const path = "/process/create\x00";
- const program = "/userinit/program2\x00";
+ @memcpy(buf[0..], program2);
+
asm volatile (
- \\ li a7, 100001
+ \\ li a7, 100002
\\ ecall
:
- : [path] "{a0}" (path.ptr),
- [program] "{a1}" (program.ptr),
+ : [bytes] "{a0}" (&buf),
+ [len] "{a1}" (buf.len),
: "a7"
);
- const term_path = "/process/self/terminate\x00";
asm volatile (
- \\ li a7, 100001
+ \\ li a7, 100003
\\ ecall
- :
- : [path] "{a0}" (term_path.ptr),
- : "a7", "a1"
- );
+ ::: "a7", "a1");
}
diff --git a/examples/create_process/src/main2.zig b/examples/create_process/src/main2.zig
index 6813d29..e487df9 100644
--- a/examples/create_process/src/main2.zig
+++ b/examples/create_process/src/main2.zig
@@ -9,7 +9,7 @@ export fn _start() void {
pub fn main() void {
const msg = "Hello from program 2";
asm volatile (
- \\ li a7, 100000
+ \\ li a7, 100001
\\ ecall
:
: [ptr] "{a0}" (msg.ptr),
@@ -17,12 +17,8 @@ pub fn main() void {
: "a7"
);
- const term_path = "/process/self/terminate\x00";
asm volatile (
- \\ li a7, 100001
+ \\ li a7, 100003
\\ ecall
- :
- : [path] "{a0}" (term_path.ptr),
- : "a7", "a1"
- );
+ ::: "a7", "a1");
}
diff --git a/examples/create_process/src/program2 b/examples/create_process/src/program2
new file mode 120000
index 0000000..7c00049
--- /dev/null
+++ b/examples/create_process/src/program2
@@ -0,0 +1 @@
+/home/himbeer/zig/srvre/kernel/examples/create_process/zig-out/bin/program2 \ No newline at end of file