aboutsummaryrefslogtreecommitdiff
path: root/src/drv
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2025-11-12 00:37:26 +0100
committerXavier Del Campo Romero <xavi92@disroot.org>2025-11-16 22:57:45 +0100
commit2ce58c995946f85666e793c4f06efff683e76ae4 (patch)
treefbf2658bb0b0f61dadcf4ca27f997eaded78aae5 /src/drv
parent5ce25ae3b5d8666d373f7d7e336546ce8508c213 (diff)
Diffstat (limited to 'src/drv')
-rw-r--r--src/drv/CMakeLists.txt14
-rw-r--r--src/drv/event/include/drv/event.h14
-rw-r--r--src/drv/null/CMakeLists.txt20
-rw-r--r--src/drv/null/include/drv/null.h28
-rw-r--r--src/drv/null/private_include/drv/null/ops.h31
-rw-r--r--src/drv/null/private_include/drv/null/types.h32
-rw-r--r--src/drv/null/src/CMakeLists.txt23
-rw-r--r--src/drv/null/src/free.c32
-rw-r--r--src/drv/null/src/init.c35
-rw-r--r--src/drv/null/src/read.c30
-rw-r--r--src/drv/null/src/update.c48
-rw-r--r--src/drv/null/src/write.c29
-rw-r--r--src/drv/ps1/cd/private_include/drv/ps1/cd/routines.h8
-rw-r--r--src/drv/ps1/cd/src/read.c4
-rw-r--r--src/drv/ps1/cd/src/write.c4
-rw-r--r--src/drv/ps1/sio/private_include/drv/ps1/sio/ops.h10
-rw-r--r--src/drv/ps1/sio/src/read.c4
-rw-r--r--src/drv/ps1/sio/src/read_nb.c3
-rw-r--r--src/drv/ps1/sio/src/write.c4
-rw-r--r--src/drv/src/tree.c22
-rw-r--r--src/drv/stderr/CMakeLists.txt20
-rw-r--r--src/drv/stderr/include/drv/stderr.h28
-rw-r--r--src/drv/stderr/private_include/drv/stderr/ops.h29
-rw-r--r--src/drv/stderr/private_include/drv/stderr/types.h32
-rw-r--r--src/drv/stderr/src/CMakeLists.txt22
-rw-r--r--src/drv/stderr/src/free.c32
-rw-r--r--src/drv/stderr/src/init.c35
-rw-r--r--src/drv/stderr/src/update.c47
-rw-r--r--src/drv/stderr/src/write.c29
-rw-r--r--src/drv/stdin/CMakeLists.txt20
-rw-r--r--src/drv/stdin/include/drv/stdin.h28
-rw-r--r--src/drv/stdin/private_include/drv/stdin/ops.h29
-rw-r--r--src/drv/stdin/private_include/drv/stdin/types.h32
-rw-r--r--src/drv/stdin/src/CMakeLists.txt22
-rw-r--r--src/drv/stdin/src/free.c32
-rw-r--r--src/drv/stdin/src/init.c35
-rw-r--r--src/drv/stdin/src/read.c30
-rw-r--r--src/drv/stdin/src/update.c47
-rw-r--r--src/drv/stdout/CMakeLists.txt20
-rw-r--r--src/drv/stdout/include/drv/stdout.h28
-rw-r--r--src/drv/stdout/private_include/drv/stdout/ops.h29
-rw-r--r--src/drv/stdout/private_include/drv/stdout/types.h32
-rw-r--r--src/drv/stdout/src/CMakeLists.txt22
-rw-r--r--src/drv/stdout/src/free.c32
-rw-r--r--src/drv/stdout/src/init.c35
-rw-r--r--src/drv/stdout/src/update.c47
-rw-r--r--src/drv/stdout/src/write.c29
-rw-r--r--src/drv/tty/private_include/drv/tty/ops.h4
-rw-r--r--src/drv/tty/src/update.backup.c2
-rw-r--r--src/drv/tty/src/update.c2
-rw-r--r--src/drv/tty/src/write.c6
51 files changed, 1195 insertions, 37 deletions
diff --git a/src/drv/CMakeLists.txt b/src/drv/CMakeLists.txt
index 3306d93..aa21753 100644
--- a/src/drv/CMakeLists.txt
+++ b/src/drv/CMakeLists.txt
@@ -16,10 +16,20 @@
add_library(drv)
add_subdirectory(event)
-add_subdirectory(tty)
+add_subdirectory(null)
add_subdirectory(src)
+add_subdirectory(stderr)
+add_subdirectory(stdin)
+add_subdirectory(stdout)
+add_subdirectory(tty)
target_include_directories(drv PUBLIC include PRIVATE private_include)
-target_link_libraries(drv PUBLIC drv_event PRIVATE drv_tty)
+target_link_libraries(drv PUBLIC drv_event PRIVATE
+ drv_null
+ drv_stderr
+ drv_stdin
+ drv_stdout
+ drv_tty
+)
if(PS1_BUILD)
add_subdirectory(ps1)
diff --git a/src/drv/event/include/drv/event.h b/src/drv/event/include/drv/event.h
index 5707242..acd3659 100644
--- a/src/drv/event/include/drv/event.h
+++ b/src/drv/event/include/drv/event.h
@@ -23,6 +23,8 @@
#include <stdbool.h>
#include <stddef.h>
+struct drv_port;
+
struct drv_event_done
{
int (*f)(int error, void *args);
@@ -31,12 +33,12 @@ struct drv_event_done
struct drv_event_ops
{
- int (*read)(void *buf, size_t n, off_t offset,
- const struct drv_event_done *done, void *args);
- int (*read_nb)(void *buf, size_t n, void *args);
- int (*write)(const void *buf, size_t n, const struct drv_event_done *done,
- void *args);
- void *args;
+ int (*read)(struct drv_port *p, void *buf, size_t n, off_t offset,
+ const struct drv_event_done *done);
+ int (*read_nb)(struct drv_port *p, void *buf, size_t n);
+ int (*write)(struct drv_port *p, const void *buf, size_t n,
+ const struct drv_event_done *done);
+ struct drv_port *p;
};
struct drv_event
diff --git a/src/drv/null/CMakeLists.txt b/src/drv/null/CMakeLists.txt
new file mode 100644
index 0000000..ab09fc2
--- /dev/null
+++ b/src/drv/null/CMakeLists.txt
@@ -0,0 +1,20 @@
+# wnix, a Unix-like operating system for WebAssembly applications.
+# Copyright (C) 2025 Xavier Del Campo Romero
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+add_library(drv_null)
+add_subdirectory(src)
+target_include_directories(drv_null PUBLIC include PRIVATE private_include)
+target_link_libraries(drv_null PUBLIC c PRIVATE drv_event)
diff --git a/src/drv/null/include/drv/null.h b/src/drv/null/include/drv/null.h
new file mode 100644
index 0000000..52ff26f
--- /dev/null
+++ b/src/drv/null/include/drv/null.h
@@ -0,0 +1,28 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DRV_NULL_H
+#define DRV_NULL_H
+
+#include <drv/event.h>
+
+struct drv_port *drv_null_init(const struct drv_event *ev);
+int drv_null_update(struct drv_port *p);
+void drv_null_free(struct drv_port *p);
+
+#endif
diff --git a/src/drv/null/private_include/drv/null/ops.h b/src/drv/null/private_include/drv/null/ops.h
new file mode 100644
index 0000000..cf9d8f2
--- /dev/null
+++ b/src/drv/null/private_include/drv/null/ops.h
@@ -0,0 +1,31 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DRV_NULL_OPS_H
+#define DRV_NULL_OPS_H
+
+#include <drv/event.h>
+#include <drv/null/types.h>
+#include <stddef.h>
+
+int drv_null_read(struct drv_port *p, void *buf, size_t n, off_t offset,
+ const struct drv_event_done *done);
+int drv_null_write(struct drv_port *p, const void *buf, size_t n,
+ const struct drv_event_done *done);
+
+#endif
diff --git a/src/drv/null/private_include/drv/null/types.h b/src/drv/null/private_include/drv/null/types.h
new file mode 100644
index 0000000..1c9266d
--- /dev/null
+++ b/src/drv/null/private_include/drv/null/types.h
@@ -0,0 +1,32 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DRV_NULL_TYPES_H
+#define DRV_NULL_TYPES_H
+
+#include <drv/event.h>
+#include <stdbool.h>
+#include <stddef.h>
+
+struct drv_port
+{
+ bool init;
+ struct drv_event ev;
+};
+
+#endif
diff --git a/src/drv/null/src/CMakeLists.txt b/src/drv/null/src/CMakeLists.txt
new file mode 100644
index 0000000..899cada
--- /dev/null
+++ b/src/drv/null/src/CMakeLists.txt
@@ -0,0 +1,23 @@
+# wnix, a Unix-like operating system for WebAssembly applications.
+# Copyright (C) 2025 Xavier Del Campo Romero
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+target_sources(drv_null PRIVATE
+ free.c
+ init.c
+ read.c
+ update.c
+ write.c
+)
diff --git a/src/drv/null/src/free.c b/src/drv/null/src/free.c
new file mode 100644
index 0000000..1251580
--- /dev/null
+++ b/src/drv/null/src/free.c
@@ -0,0 +1,32 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/null.h>
+#include <drv/null/ops.h>
+#include <drv/null/types.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+void drv_null_free(struct drv_port *const p)
+{
+ if (!p)
+ return;
+
+ free(p);
+}
diff --git a/src/drv/null/src/init.c b/src/drv/null/src/init.c
new file mode 100644
index 0000000..4ed6c39
--- /dev/null
+++ b/src/drv/null/src/init.c
@@ -0,0 +1,35 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/null.h>
+#include <drv/null/ops.h>
+#include <drv/null/types.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+struct drv_port *drv_null_init(const struct drv_event *const ev)
+{
+ struct drv_port *ret = NULL;
+
+ if (!(ret = malloc(sizeof *ret)))
+ return NULL;
+
+ *ret = (const struct drv_port){.ev = *ev};
+ return ret;
+}
diff --git a/src/drv/null/src/read.c b/src/drv/null/src/read.c
new file mode 100644
index 0000000..7dd9820
--- /dev/null
+++ b/src/drv/null/src/read.c
@@ -0,0 +1,30 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/null.h>
+#include <drv/null/types.h>
+#include <drv/null/ops.h>
+#include <stddef.h>
+
+int drv_null_read(struct drv_port *const p, void *const buf, const size_t n,
+ const off_t offset, const struct drv_event_done *const d)
+{
+ /* TODO: how to set EOF? */
+ return 0;
+}
diff --git a/src/drv/null/src/update.c b/src/drv/null/src/update.c
new file mode 100644
index 0000000..cc0b456
--- /dev/null
+++ b/src/drv/null/src/update.c
@@ -0,0 +1,48 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/null.h>
+#include <drv/null/ops.h>
+#include <drv/null/types.h>
+#include <stdbool.h>
+
+static int init(struct drv_port *const p)
+{
+ if (p->init)
+ return 0;
+
+ const struct drv_event *const ev = &p->ev;
+ const struct drv_event_ops ops =
+ {
+ .read = drv_null_read,
+ .write = drv_null_write,
+ .p = p
+ };
+
+ if (ev->status("null", &ops, true, 0666, ev->args))
+ return -1;
+
+ p->init = true;
+ return 0;
+}
+
+int drv_null_update(struct drv_port *const p)
+{
+ return init(p);
+}
diff --git a/src/drv/null/src/write.c b/src/drv/null/src/write.c
new file mode 100644
index 0000000..9ca8b53
--- /dev/null
+++ b/src/drv/null/src/write.c
@@ -0,0 +1,29 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/null.h>
+#include <drv/null/types.h>
+#include <drv/null/ops.h>
+#include <stddef.h>
+
+int drv_null_write(struct drv_port *const p, const void *const buf,
+ const size_t n, const struct drv_event_done *const d)
+{
+ return n;
+}
diff --git a/src/drv/ps1/cd/private_include/drv/ps1/cd/routines.h b/src/drv/ps1/cd/private_include/drv/ps1/cd/routines.h
index 0b756de..9870445 100644
--- a/src/drv/ps1/cd/private_include/drv/ps1/cd/routines.h
+++ b/src/drv/ps1/cd/private_include/drv/ps1/cd/routines.h
@@ -27,10 +27,10 @@
int drv_ps1_cd_send(const struct cmd *cmd);
int drv_ps1_cd_getstat(void);
-int drv_ps1_cd_read(void *buf, size_t n, off_t offset,
- const struct drv_event_done *done, void *args);
-int drv_ps1_cd_write(const void *buf, size_t n,
- const struct drv_event_done *done, void *args);
+int drv_ps1_cd_read(struct drv_port *p, void *buf, size_t n, off_t offset,
+ const struct drv_event_done *done);
+int drv_ps1_cd_write(struct drv_port *p, const void *buf, size_t n,
+ const struct drv_event_done *done);
int drv_ps1_cd_next(void);
struct CdAsyncSeekL drv_ps1_cd_toseekl(unsigned i);
diff --git a/src/drv/ps1/cd/src/read.c b/src/drv/ps1/cd/src/read.c
index d21cbae..f8db3a0 100644
--- a/src/drv/ps1/cd/src/read.c
+++ b/src/drv/ps1/cd/src/read.c
@@ -208,8 +208,8 @@ static int start(void)
return cached_read(p);
}
-int drv_ps1_cd_read(void *const buf, const size_t n, const off_t offset,
- const struct drv_event_done *const done, void *const args)
+int drv_ps1_cd_read(struct drv_port *const pt, void *const buf, const size_t n,
+ const off_t offset, const struct drv_event_done *const done)
{
struct cd_prv *const p = &drv_ps1_cd_prv;
struct cd_req *const r = malloc(sizeof *r);
diff --git a/src/drv/ps1/cd/src/write.c b/src/drv/ps1/cd/src/write.c
index ba47993..a314862 100644
--- a/src/drv/ps1/cd/src/write.c
+++ b/src/drv/ps1/cd/src/write.c
@@ -22,8 +22,8 @@
#include <drv/event.h>
#include <errno.h>
-int drv_ps1_cd_write(const void *const buf, const size_t n,
- const struct drv_event_done *const done, void *const args)
+int drv_ps1_cd_write(struct drv_port *const p, const void *const buf,
+ const size_t n, const struct drv_event_done *const done)
{
/* TODO: write event callback returning EROFS */
errno = EROFS;
diff --git a/src/drv/ps1/sio/private_include/drv/ps1/sio/ops.h b/src/drv/ps1/sio/private_include/drv/ps1/sio/ops.h
index a481fa9..a7e19dd 100644
--- a/src/drv/ps1/sio/private_include/drv/ps1/sio/ops.h
+++ b/src/drv/ps1/sio/private_include/drv/ps1/sio/ops.h
@@ -22,10 +22,10 @@
#include <drv/event.h>
#include <sys/types.h>
-int drv_ps1_sio_read(void *buf, size_t n, off_t offset,
- const struct drv_event_done *done, void *args);
-int drv_ps1_sio_read_nb(void *buf, size_t n, void *args);
-int drv_ps1_sio_write(const void *buf, size_t n,
- const struct drv_event_done *done, void *args);
+int drv_ps1_sio_read(struct drv_port *p, void *buf, size_t n, off_t offset,
+ const struct drv_event_done *done);
+int drv_ps1_sio_read_nb(struct drv_port *p, void *buf, size_t n);
+int drv_ps1_sio_write(struct drv_port *p, const void *buf, size_t n,
+ const struct drv_event_done *done);
#endif
diff --git a/src/drv/ps1/sio/src/read.c b/src/drv/ps1/sio/src/read.c
index e13ad29..63bd29f 100644
--- a/src/drv/ps1/sio/src/read.c
+++ b/src/drv/ps1/sio/src/read.c
@@ -94,8 +94,8 @@ static int load(void)
return 0;
}
-int drv_ps1_sio_read(void *const buf, const size_t n, const off_t offset,
- const struct drv_event_done *const done, void *const args)
+int drv_ps1_sio_read(struct drv_port *const p, void *const buf, const size_t n,
+ const off_t offset, const struct drv_event_done *const done)
{
struct drv_ps1_sio *const s = &drv_ps1_sio;
struct sio_fifo *const f = &s->rx;
diff --git a/src/drv/ps1/sio/src/read_nb.c b/src/drv/ps1/sio/src/read_nb.c
index 755c5cf..9b9c3bf 100644
--- a/src/drv/ps1/sio/src/read_nb.c
+++ b/src/drv/ps1/sio/src/read_nb.c
@@ -55,7 +55,8 @@ static int read_fifo(char *buf, size_t n)
return ret;
}
-int drv_ps1_sio_read_nb(void *const buf, const size_t n, void *const args)
+int drv_ps1_sio_read_nb(struct drv_port *const p, void *const buf,
+ const size_t n)
{
return read_fifo(buf, n);
}
diff --git a/src/drv/ps1/sio/src/write.c b/src/drv/ps1/sio/src/write.c
index 942456f..4f5a702 100644
--- a/src/drv/ps1/sio/src/write.c
+++ b/src/drv/ps1/sio/src/write.c
@@ -86,8 +86,8 @@ static int store(void)
return 0;
}
-int drv_ps1_sio_write(const void *const buf, const size_t n,
- const struct drv_event_done *const done, void *const args)
+int drv_ps1_sio_write(struct drv_port *const p, const void *const buf,
+ const size_t n, const struct drv_event_done *const done)
{
struct drv_ps1_sio *const s = &drv_ps1_sio;
struct sio_fifo *const f = &s->tx;
diff --git a/src/drv/src/tree.c b/src/drv/src/tree.c
index d52df3d..087c38b 100644
--- a/src/drv/src/tree.c
+++ b/src/drv/src/tree.c
@@ -18,6 +18,10 @@
#include <drv/drv.h>
#include <drv/tree.h>
+#include <drv/null.h>
+#include <drv/stderr.h>
+#include <drv/stdin.h>
+#include <drv/stdout.h>
#include <drv/tty.h>
#include <drv/port.h>
#include <stddef.h>
@@ -27,7 +31,11 @@ struct drv_port *(*const drv_tree_init[])(const struct drv_event *) =
#if DRV_PS1
drv_ps1_init,
#endif
- drv_tty_init
+ drv_tty_init,
+ drv_null_init,
+ drv_stderr_init,
+ drv_stdin_init,
+ drv_stdout_init
};
enum {N = sizeof drv_tree_init / sizeof *drv_tree_init};
@@ -37,7 +45,11 @@ int (*const drv_tree_update[N])(struct drv_port *) =
#if DRV_PS1
drv_ps1_update,
#endif
- drv_tty_update
+ drv_tty_update,
+ drv_null_update,
+ drv_stderr_update,
+ drv_stdin_update,
+ drv_stdout_update
};
void (*const drv_tree_free[N])(struct drv_port *) =
@@ -45,7 +57,11 @@ void (*const drv_tree_free[N])(struct drv_port *) =
#if DRV_PS1
drv_ps1_free,
#endif
- drv_tty_free
+ drv_tty_free,
+ drv_null_free,
+ drv_stderr_free,
+ drv_stdin_free,
+ drv_stdout_free
};
const size_t drv_tree_n = N;
diff --git a/src/drv/stderr/CMakeLists.txt b/src/drv/stderr/CMakeLists.txt
new file mode 100644
index 0000000..cb9a07a
--- /dev/null
+++ b/src/drv/stderr/CMakeLists.txt
@@ -0,0 +1,20 @@
+# wnix, a Unix-like operating system for WebAssembly applications.
+# Copyright (C) 2025 Xavier Del Campo Romero
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+add_library(drv_stderr)
+add_subdirectory(src)
+target_include_directories(drv_stderr PUBLIC include PRIVATE private_include)
+target_link_libraries(drv_stderr PUBLIC c PRIVATE drv_event)
diff --git a/src/drv/stderr/include/drv/stderr.h b/src/drv/stderr/include/drv/stderr.h
new file mode 100644
index 0000000..eceff6a
--- /dev/null
+++ b/src/drv/stderr/include/drv/stderr.h
@@ -0,0 +1,28 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DRV_STDERR_H
+#define DRV_STDERR_H
+
+#include <drv/event.h>
+
+struct drv_port *drv_stderr_init(const struct drv_event *ev);
+int drv_stderr_update(struct drv_port *p);
+void drv_stderr_free(struct drv_port *p);
+
+#endif
diff --git a/src/drv/stderr/private_include/drv/stderr/ops.h b/src/drv/stderr/private_include/drv/stderr/ops.h
new file mode 100644
index 0000000..a265b15
--- /dev/null
+++ b/src/drv/stderr/private_include/drv/stderr/ops.h
@@ -0,0 +1,29 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DRV_STDERR_OPS_H
+#define DRV_STDERR_OPS_H
+
+#include <drv/event.h>
+#include <drv/stderr/types.h>
+#include <stddef.h>
+
+int drv_stderr_write(struct drv_port *p, const void *buf, size_t n,
+ const struct drv_event_done *done);
+
+#endif
diff --git a/src/drv/stderr/private_include/drv/stderr/types.h b/src/drv/stderr/private_include/drv/stderr/types.h
new file mode 100644
index 0000000..196568c
--- /dev/null
+++ b/src/drv/stderr/private_include/drv/stderr/types.h
@@ -0,0 +1,32 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DRV_STDERR_TYPES_H
+#define DRV_STDERR_TYPES_H
+
+#include <drv/event.h>
+#include <stdbool.h>
+#include <stddef.h>
+
+struct drv_port
+{
+ bool init;
+ struct drv_event ev;
+};
+
+#endif
diff --git a/src/drv/stderr/src/CMakeLists.txt b/src/drv/stderr/src/CMakeLists.txt
new file mode 100644
index 0000000..fd685c8
--- /dev/null
+++ b/src/drv/stderr/src/CMakeLists.txt
@@ -0,0 +1,22 @@
+# wnix, a Unix-like operating system for WebAssembly applications.
+# Copyright (C) 2025 Xavier Del Campo Romero
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+target_sources(drv_stderr PRIVATE
+ free.c
+ init.c
+ update.c
+ write.c
+)
diff --git a/src/drv/stderr/src/free.c b/src/drv/stderr/src/free.c
new file mode 100644
index 0000000..1793540
--- /dev/null
+++ b/src/drv/stderr/src/free.c
@@ -0,0 +1,32 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/stderr.h>
+#include <drv/stderr/ops.h>
+#include <drv/stderr/types.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+void drv_stderr_free(struct drv_port *const p)
+{
+ if (!p)
+ return;
+
+ free(p);
+}
diff --git a/src/drv/stderr/src/init.c b/src/drv/stderr/src/init.c
new file mode 100644
index 0000000..95797d7
--- /dev/null
+++ b/src/drv/stderr/src/init.c
@@ -0,0 +1,35 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/stderr.h>
+#include <drv/stderr/ops.h>
+#include <drv/stderr/types.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+struct drv_port *drv_stderr_init(const struct drv_event *const ev)
+{
+ struct drv_port *ret = NULL;
+
+ if (!(ret = malloc(sizeof *ret)))
+ return NULL;
+
+ *ret = (const struct drv_port){.ev = *ev};
+ return ret;
+}
diff --git a/src/drv/stderr/src/update.c b/src/drv/stderr/src/update.c
new file mode 100644
index 0000000..24e0cf4
--- /dev/null
+++ b/src/drv/stderr/src/update.c
@@ -0,0 +1,47 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/stderr.h>
+#include <drv/stderr/ops.h>
+#include <drv/stderr/types.h>
+#include <stdbool.h>
+
+static int init(struct drv_port *const p)
+{
+ if (p->init)
+ return 0;
+
+ const struct drv_event *const ev = &p->ev;
+ const struct drv_event_ops ops =
+ {
+ .write = drv_stderr_write,
+ .p = p
+ };
+
+ if (ev->status("stderr", &ops, true, 0666, ev->args))
+ return -1;
+
+ p->init = true;
+ return 0;
+}
+
+int drv_stderr_update(struct drv_port *const p)
+{
+ return init(p);
+}
diff --git a/src/drv/stderr/src/write.c b/src/drv/stderr/src/write.c
new file mode 100644
index 0000000..2f5ccf8
--- /dev/null
+++ b/src/drv/stderr/src/write.c
@@ -0,0 +1,29 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/stderr.h>
+#include <drv/stderr/types.h>
+#include <drv/stderr/ops.h>
+#include <stddef.h>
+
+int drv_stderr_write(struct drv_port *const p, const void *const buf,
+ const size_t n, const struct drv_event_done *const d)
+{
+ return n;
+}
diff --git a/src/drv/stdin/CMakeLists.txt b/src/drv/stdin/CMakeLists.txt
new file mode 100644
index 0000000..8c788a0
--- /dev/null
+++ b/src/drv/stdin/CMakeLists.txt
@@ -0,0 +1,20 @@
+# wnix, a Unix-like operating system for WebAssembly applications.
+# Copyright (C) 2025 Xavier Del Campo Romero
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+add_library(drv_stdin)
+add_subdirectory(src)
+target_include_directories(drv_stdin PUBLIC include PRIVATE private_include)
+target_link_libraries(drv_stdin PUBLIC c PRIVATE drv_event)
diff --git a/src/drv/stdin/include/drv/stdin.h b/src/drv/stdin/include/drv/stdin.h
new file mode 100644
index 0000000..70ec64a
--- /dev/null
+++ b/src/drv/stdin/include/drv/stdin.h
@@ -0,0 +1,28 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DRV_STDIN_H
+#define DRV_STDIN_H
+
+#include <drv/event.h>
+
+struct drv_port *drv_stdin_init(const struct drv_event *ev);
+int drv_stdin_update(struct drv_port *p);
+void drv_stdin_free(struct drv_port *p);
+
+#endif
diff --git a/src/drv/stdin/private_include/drv/stdin/ops.h b/src/drv/stdin/private_include/drv/stdin/ops.h
new file mode 100644
index 0000000..0514172
--- /dev/null
+++ b/src/drv/stdin/private_include/drv/stdin/ops.h
@@ -0,0 +1,29 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DRV_STDIN_OPS_H
+#define DRV_STDIN_OPS_H
+
+#include <drv/event.h>
+#include <drv/stdin/types.h>
+#include <stddef.h>
+
+int drv_stdin_read(struct drv_port *p, void *buf, size_t n, off_t offset,
+ const struct drv_event_done *done);
+
+#endif
diff --git a/src/drv/stdin/private_include/drv/stdin/types.h b/src/drv/stdin/private_include/drv/stdin/types.h
new file mode 100644
index 0000000..62d1c41
--- /dev/null
+++ b/src/drv/stdin/private_include/drv/stdin/types.h
@@ -0,0 +1,32 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DRV_STDIN_TYPES_H
+#define DRV_STDIN_TYPES_H
+
+#include <drv/event.h>
+#include <stdbool.h>
+#include <stddef.h>
+
+struct drv_port
+{
+ bool init;
+ struct drv_event ev;
+};
+
+#endif
diff --git a/src/drv/stdin/src/CMakeLists.txt b/src/drv/stdin/src/CMakeLists.txt
new file mode 100644
index 0000000..0da5cc6
--- /dev/null
+++ b/src/drv/stdin/src/CMakeLists.txt
@@ -0,0 +1,22 @@
+# wnix, a Unix-like operating system for WebAssembly applications.
+# Copyright (C) 2025 Xavier Del Campo Romero
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+target_sources(drv_stdin PRIVATE
+ free.c
+ init.c
+ read.c
+ update.c
+)
diff --git a/src/drv/stdin/src/free.c b/src/drv/stdin/src/free.c
new file mode 100644
index 0000000..0f7d7af
--- /dev/null
+++ b/src/drv/stdin/src/free.c
@@ -0,0 +1,32 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/stdin.h>
+#include <drv/stdin/ops.h>
+#include <drv/stdin/types.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+void drv_stdin_free(struct drv_port *const p)
+{
+ if (!p)
+ return;
+
+ free(p);
+}
diff --git a/src/drv/stdin/src/init.c b/src/drv/stdin/src/init.c
new file mode 100644
index 0000000..c7a2e04
--- /dev/null
+++ b/src/drv/stdin/src/init.c
@@ -0,0 +1,35 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/stdin.h>
+#include <drv/stdin/ops.h>
+#include <drv/stdin/types.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+struct drv_port *drv_stdin_init(const struct drv_event *const ev)
+{
+ struct drv_port *ret = NULL;
+
+ if (!(ret = malloc(sizeof *ret)))
+ return NULL;
+
+ *ret = (const struct drv_port){.ev = *ev};
+ return ret;
+}
diff --git a/src/drv/stdin/src/read.c b/src/drv/stdin/src/read.c
new file mode 100644
index 0000000..a26f7df
--- /dev/null
+++ b/src/drv/stdin/src/read.c
@@ -0,0 +1,30 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/stdin.h>
+#include <drv/stdin/types.h>
+#include <drv/stdin/ops.h>
+#include <stddef.h>
+
+int drv_stdin_read(struct drv_port *const p, void *const buf, const size_t n,
+ const off_t offset, const struct drv_event_done *const d)
+{
+ /* TODO: how to set EOF? */
+ return 0;
+}
diff --git a/src/drv/stdin/src/update.c b/src/drv/stdin/src/update.c
new file mode 100644
index 0000000..cbfebca
--- /dev/null
+++ b/src/drv/stdin/src/update.c
@@ -0,0 +1,47 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/stdin.h>
+#include <drv/stdin/ops.h>
+#include <drv/stdin/types.h>
+#include <stdbool.h>
+
+static int init(struct drv_port *const p)
+{
+ if (p->init)
+ return 0;
+
+ const struct drv_event *const ev = &p->ev;
+ const struct drv_event_ops ops =
+ {
+ .read = drv_stdin_read,
+ .p = p
+ };
+
+ if (ev->status("stdin", &ops, true, 0666, ev->args))
+ return -1;
+
+ p->init = true;
+ return 0;
+}
+
+int drv_stdin_update(struct drv_port *const p)
+{
+ return init(p);
+}
diff --git a/src/drv/stdout/CMakeLists.txt b/src/drv/stdout/CMakeLists.txt
new file mode 100644
index 0000000..58f430a
--- /dev/null
+++ b/src/drv/stdout/CMakeLists.txt
@@ -0,0 +1,20 @@
+# wnix, a Unix-like operating system for WebAssembly applications.
+# Copyright (C) 2025 Xavier Del Campo Romero
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+add_library(drv_stdout)
+add_subdirectory(src)
+target_include_directories(drv_stdout PUBLIC include PRIVATE private_include)
+target_link_libraries(drv_stdout PUBLIC c PRIVATE drv_event)
diff --git a/src/drv/stdout/include/drv/stdout.h b/src/drv/stdout/include/drv/stdout.h
new file mode 100644
index 0000000..0fac80c
--- /dev/null
+++ b/src/drv/stdout/include/drv/stdout.h
@@ -0,0 +1,28 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DRV_STDOUT_H
+#define DRV_STDOUT_H
+
+#include <drv/event.h>
+
+struct drv_port *drv_stdout_init(const struct drv_event *ev);
+int drv_stdout_update(struct drv_port *p);
+void drv_stdout_free(struct drv_port *p);
+
+#endif
diff --git a/src/drv/stdout/private_include/drv/stdout/ops.h b/src/drv/stdout/private_include/drv/stdout/ops.h
new file mode 100644
index 0000000..af848e3
--- /dev/null
+++ b/src/drv/stdout/private_include/drv/stdout/ops.h
@@ -0,0 +1,29 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DRV_STDOUT_OPS_H
+#define DRV_STDOUT_OPS_H
+
+#include <drv/event.h>
+#include <drv/stdout/types.h>
+#include <stddef.h>
+
+int drv_stdout_write(struct drv_port *p, const void *buf, size_t n,
+ const struct drv_event_done *done);
+
+#endif
diff --git a/src/drv/stdout/private_include/drv/stdout/types.h b/src/drv/stdout/private_include/drv/stdout/types.h
new file mode 100644
index 0000000..a39ce64
--- /dev/null
+++ b/src/drv/stdout/private_include/drv/stdout/types.h
@@ -0,0 +1,32 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#ifndef DRV_STDOUT_TYPES_H
+#define DRV_STDOUT_TYPES_H
+
+#include <drv/event.h>
+#include <stdbool.h>
+#include <stddef.h>
+
+struct drv_port
+{
+ bool init;
+ struct drv_event ev;
+};
+
+#endif
diff --git a/src/drv/stdout/src/CMakeLists.txt b/src/drv/stdout/src/CMakeLists.txt
new file mode 100644
index 0000000..490886d
--- /dev/null
+++ b/src/drv/stdout/src/CMakeLists.txt
@@ -0,0 +1,22 @@
+# wnix, a Unix-like operating system for WebAssembly applications.
+# Copyright (C) 2025 Xavier Del Campo Romero
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU Affero General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU Affero General Public License for more details.
+#
+# You should have received a copy of the GNU Affero General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+target_sources(drv_stdout PRIVATE
+ free.c
+ init.c
+ update.c
+ write.c
+)
diff --git a/src/drv/stdout/src/free.c b/src/drv/stdout/src/free.c
new file mode 100644
index 0000000..4b7d733
--- /dev/null
+++ b/src/drv/stdout/src/free.c
@@ -0,0 +1,32 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/stdout.h>
+#include <drv/stdout/ops.h>
+#include <drv/stdout/types.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+void drv_stdout_free(struct drv_port *const p)
+{
+ if (!p)
+ return;
+
+ free(p);
+}
diff --git a/src/drv/stdout/src/init.c b/src/drv/stdout/src/init.c
new file mode 100644
index 0000000..86f566a
--- /dev/null
+++ b/src/drv/stdout/src/init.c
@@ -0,0 +1,35 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/stdout.h>
+#include <drv/stdout/ops.h>
+#include <drv/stdout/types.h>
+#include <stddef.h>
+#include <stdlib.h>
+
+struct drv_port *drv_stdout_init(const struct drv_event *const ev)
+{
+ struct drv_port *ret = NULL;
+
+ if (!(ret = malloc(sizeof *ret)))
+ return NULL;
+
+ *ret = (const struct drv_port){.ev = *ev};
+ return ret;
+}
diff --git a/src/drv/stdout/src/update.c b/src/drv/stdout/src/update.c
new file mode 100644
index 0000000..8b47a52
--- /dev/null
+++ b/src/drv/stdout/src/update.c
@@ -0,0 +1,47 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/stdout.h>
+#include <drv/stdout/ops.h>
+#include <drv/stdout/types.h>
+#include <stdbool.h>
+
+static int init(struct drv_port *const p)
+{
+ if (p->init)
+ return 0;
+
+ const struct drv_event *const ev = &p->ev;
+ const struct drv_event_ops ops =
+ {
+ .write = drv_stdout_write,
+ .p = p
+ };
+
+ if (ev->status("stdout", &ops, true, 0666, ev->args))
+ return -1;
+
+ p->init = true;
+ return 0;
+}
+
+int drv_stdout_update(struct drv_port *const p)
+{
+ return init(p);
+}
diff --git a/src/drv/stdout/src/write.c b/src/drv/stdout/src/write.c
new file mode 100644
index 0000000..06d5980
--- /dev/null
+++ b/src/drv/stdout/src/write.c
@@ -0,0 +1,29 @@
+/*
+ * wnix, a Unix-like operating system for WebAssembly applications.
+ * Copyright (C) 2025 Xavier Del Campo Romero
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <https://www.gnu.org/licenses/>.
+ */
+
+#include <drv/event.h>
+#include <drv/stdout.h>
+#include <drv/stdout/types.h>
+#include <drv/stdout/ops.h>
+#include <stddef.h>
+
+int drv_stdout_write(struct drv_port *const p, const void *const buf,
+ const size_t n, const struct drv_event_done *const d)
+{
+ return n;
+}
diff --git a/src/drv/tty/private_include/drv/tty/ops.h b/src/drv/tty/private_include/drv/tty/ops.h
index b50b00a..ceab56a 100644
--- a/src/drv/tty/private_include/drv/tty/ops.h
+++ b/src/drv/tty/private_include/drv/tty/ops.h
@@ -23,8 +23,8 @@
#include <drv/tty/types.h>
#include <stddef.h>
-int drv_tty_write(const void *buf, size_t n, const struct drv_event_done *done,
- void *args);
+int drv_tty_write(struct drv_port *p, const void *buf, size_t n,
+ const struct drv_event_done *done);
int drv_tty_setdim(struct drv_port *p, unsigned x, unsigned y);
#endif
diff --git a/src/drv/tty/src/update.backup.c b/src/drv/tty/src/update.backup.c
index d072977..07e2a09 100644
--- a/src/drv/tty/src/update.backup.c
+++ b/src/drv/tty/src/update.backup.c
@@ -34,7 +34,7 @@ static int init(struct drv_port *const p)
const struct drv_event_ops ops =
{
.write = drv_tty_write,
- .args = p
+ .p = p
};
if (ev->status("tty", &ops, true, 0666, ev->args))
diff --git a/src/drv/tty/src/update.c b/src/drv/tty/src/update.c
index 7c01678..b5644d0 100644
--- a/src/drv/tty/src/update.c
+++ b/src/drv/tty/src/update.c
@@ -34,7 +34,7 @@ static int init(struct drv_port *const p)
const struct drv_event_ops ops =
{
.write = drv_tty_write,
- .args = p
+ .p = p
};
if (ev->status("tty", &ops, true, 0666, ev->args))
diff --git a/src/drv/tty/src/write.c b/src/drv/tty/src/write.c
index d4a988d..c7b90ed 100644
--- a/src/drv/tty/src/write.c
+++ b/src/drv/tty/src/write.c
@@ -23,11 +23,9 @@
#include <errno.h>
#include <stddef.h>
-int drv_tty_write(const void *const buf, const size_t n,
- const struct drv_event_done *const d, void *const args)
+int drv_tty_write(struct drv_port *const p, const void *const buf,
+ const size_t n, const struct drv_event_done *const d)
{
- struct drv_port *const p = args;
-
for (const char *s = buf; s - (const char *)buf < n; s++)
{
struct row *const r = p->last_row;