summaryrefslogtreecommitdiff
path: root/src/init
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2025-07-07 13:22:53 +0200
committerXavier Del Campo Romero <xavi92@disroot.org>2025-07-25 14:16:41 +0200
commit14f60e4fd65c42f126eaee7e09cb4251c167c6ed (patch)
tree313b5e16d7d99cf1518c953e2efe5e5fc920dfbf /src/init
parent48a61c16eaa6dcfc75d00dba302537ce1492db98 (diff)
wiptty
Diffstat (limited to 'src/init')
-rw-r--r--src/init/CMakeLists.txt34
-rw-r--r--src/init/include/init.h27
-rw-r--r--src/init/private_include/init/port.h25
-rw-r--r--src/init/private_include/init/types.h37
-rw-r--r--src/init/ps1/CMakeLists.txt33
-rw-r--r--src/init/ps1/private_include/init/ps1/types.h37
-rw-r--r--src/init/ps1/src/CMakeLists.txt22
-rw-r--r--src/init/ps1/src/boot.c188
-rw-r--r--src/init/ps1/src/globalvars.c21
-rw-r--r--src/init/ps1/src/run.c27
-rw-r--r--src/init/ps1/src/time.c47
-rw-r--r--src/init/src/CMakeLists.txt22
-rw-r--r--src/init/src/boot.c121
-rw-r--r--src/init/src/run.c27
-rw-r--r--src/init/src/vars.c21
-rw-r--r--src/init/src/vfs.c86
16 files changed, 775 insertions, 0 deletions
diff --git a/src/init/CMakeLists.txt b/src/init/CMakeLists.txt
new file mode 100644
index 0000000..5cac77d
--- /dev/null
+++ b/src/init/CMakeLists.txt
@@ -0,0 +1,34 @@
+# wanix, 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(init)
+add_subdirectory(src)
+target_include_directories(init PUBLIC include PRIVATE private_include)
+target_link_libraries(init PRIVATE
+ aio
+ devfs
+ drv
+ io
+ kprintf
+ loop
+ rootfs
+ iso9660
+)
+
+if(PS1_BUILD)
+ add_subdirectory(ps1)
+ target_link_libraries(init PRIVATE init_ps1)
+endif()
diff --git a/src/init/include/init.h b/src/init/include/init.h
new file mode 100644
index 0000000..510245d
--- /dev/null
+++ b/src/init/include/init.h
@@ -0,0 +1,27 @@
+/*
+ * wanix, 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 INIT_H
+#define INIT_H
+
+int init_time(void);
+int init_boot(void);
+int init_vfs(void);
+int init_run(void);
+
+#endif
diff --git a/src/init/private_include/init/port.h b/src/init/private_include/init/port.h
new file mode 100644
index 0000000..f36ae5d
--- /dev/null
+++ b/src/init/private_include/init/port.h
@@ -0,0 +1,25 @@
+/*
+ * wanix, 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 INIT_PORT_H
+#define INIT_PORT_H
+
+int init_port_boot(void);
+int init_port_run(void);
+
+#endif
diff --git a/src/init/private_include/init/types.h b/src/init/private_include/init/types.h
new file mode 100644
index 0000000..f875caf
--- /dev/null
+++ b/src/init/private_include/init/types.h
@@ -0,0 +1,37 @@
+/*
+ * wanix, 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 INIT_TYPES_H
+#define INIT_TYPES_H
+
+#include <aio.h>
+#include <sys/stat.h>
+#include <time.h>
+
+struct init
+{
+ struct aio *aio;
+ struct stat sb;
+ unsigned retries;
+ struct timespec last_retry;
+ int (*next)(struct init *);
+};
+
+extern struct init init_vars;
+
+#endif
diff --git a/src/init/ps1/CMakeLists.txt b/src/init/ps1/CMakeLists.txt
new file mode 100644
index 0000000..2cdc2de
--- /dev/null
+++ b/src/init/ps1/CMakeLists.txt
@@ -0,0 +1,33 @@
+# wanix, 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(init_ps1)
+add_subdirectory(src)
+target_include_directories(init_ps1 PRIVATE private_include)
+target_link_libraries(init_ps1
+ PUBLIC
+ c
+ init
+ PRIVATE
+ aio
+ drv_ps1_bios
+ drv_ps1_rcnt
+ drv_ps1_time
+ iso9660
+ kprintf
+ loop
+ state
+)
diff --git a/src/init/ps1/private_include/init/ps1/types.h b/src/init/ps1/private_include/init/ps1/types.h
new file mode 100644
index 0000000..118f37b
--- /dev/null
+++ b/src/init/ps1/private_include/init/ps1/types.h
@@ -0,0 +1,37 @@
+/*
+ * wanix, 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 INIT_PS1_TYPES_H
+#define INIT_PS1_TYPES_H
+
+#include <aio.h>
+#include <sys/stat.h>
+#include <time.h>
+
+struct init_ps1
+{
+ struct aio *aio;
+ struct stat *sb;
+ unsigned retries;
+ struct timespec last_retry;
+ int (*next)(struct init_ps1 *);
+};
+
+extern struct init_ps1 init_ps1;
+
+#endif
diff --git a/src/init/ps1/src/CMakeLists.txt b/src/init/ps1/src/CMakeLists.txt
new file mode 100644
index 0000000..5a4af14
--- /dev/null
+++ b/src/init/ps1/src/CMakeLists.txt
@@ -0,0 +1,22 @@
+# wanix, 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(init_ps1 PRIVATE
+ boot.c
+ globalvars.c
+ run.c
+ time.c
+)
diff --git a/src/init/ps1/src/boot.c b/src/init/ps1/src/boot.c
new file mode 100644
index 0000000..9b42d47
--- /dev/null
+++ b/src/init/ps1/src/boot.c
@@ -0,0 +1,188 @@
+/*
+ * wanix, 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 <init.h>
+#include <init/ps1/types.h>
+#include <aio.h>
+#include <iso9660.h>
+#include <kprintf.h>
+#include <loop.h>
+#include <sys/stat.h>
+#include <stdlib.h>
+#include <state.h>
+#include <time.h>
+
+struct mount
+{
+ struct aio *aio;
+};
+
+enum {RETRIES = 5};
+
+static int retry(struct init_ps1 *);
+
+static int mount_done(const enum state state, void *const args)
+{
+ struct mount *const m = args;
+
+ loop_rm_aio(m->aio);
+ aio_free(m->aio);
+ free(m);
+
+ if (state)
+ kprintf("Failed to mount ISO9660 filesystem\n");
+ else
+ kprintf("ISO996 filesystem mounted successfully\n");
+
+ return 0;
+}
+
+static int mount_cd(struct init_ps1 *const p)
+{
+ struct aio *aio = NULL;
+ struct mount *const m = malloc(sizeof *m);
+
+ if (!m)
+ goto failure;
+
+ const struct aio_mount fm =
+ {
+ .mount =
+ {
+ .src = "/dev/cd0",
+ .tgt = "/mnt/cdrom",
+ .mode = 0755
+ },
+
+ .type = "iso9660"
+ };
+
+ const struct aio_done d =
+ {
+ .args = m,
+ .f = mount_done
+ };
+
+ if (!(aio = aio_mount(&fm, &d)) || loop_add_aio(aio))
+ goto failure;
+
+ *m = (const struct mount){.aio = aio};
+ p->next = NULL;
+ kprintf("Mounting ISO996 filesystem from %s to %s\n",
+ fm.mount.src, fm.mount.tgt);
+ return 0;
+
+failure:
+ aio_free(aio);
+ free(m);
+ kprintf("Failed to mount ISO996 filesystem from %s to %s\n",
+ fm.mount.src, fm.mount.tgt);
+ return -1;
+}
+
+static int wait_retry(struct init_ps1 *const p)
+{
+ struct timespec ts;
+ const time_t last = p->last_retry.tv_sec, timeout = 5;
+
+ if (clock_gettime(CLOCK_REALTIME, &ts))
+ return -1;
+ else if (ts.tv_sec - last >= timeout)
+ p->next = retry;
+
+ return 0;
+}
+
+static int stat_done(const enum state s, void *const args)
+{
+ int ret = 0;
+ struct init_ps1 *const p = args;
+
+ if (s)
+ {
+ struct timespec ts;
+
+ if (!--p->retries || clock_gettime(CLOCK_REALTIME, &ts))
+ {
+ ret = -1;
+ goto end;
+ }
+
+ p->last_retry = ts;
+ p->next = wait_retry;
+ }
+ else
+ {
+ p->next = mount_cd;
+ kprintf("Successfully initialized CD-ROM (took %u attempts)\n",
+ RETRIES - p->retries + 1);
+ }
+
+end:
+ loop_rm_aio(p->aio);
+ aio_free(p->aio);
+ free(p->sb);
+ return ret;
+}
+
+static int retry(struct init_ps1 *const p)
+{
+ struct aio *aio = NULL;
+ struct stat *const sb = malloc(sizeof *sb);
+
+ if (!sb)
+ goto failure;
+
+ const struct fs_stat s = {.path = "/dev/cd0", .sb = sb};
+ const struct aio_done d = {.f = stat_done, .args = p};
+ const unsigned retries = p->retries;
+
+ if (!(aio = aio_stat(&s, &d)) || loop_add_aio(aio))
+ goto failure;
+
+ *p = (const struct init_ps1)
+ {
+ .aio = aio,
+ .sb = sb,
+ .retries = retries,
+ .last_retry = {.tv_sec = (time_t)-1}
+ };
+
+ kprintf("Initializing CD-ROM to %s (attempt %u)\n", s.path,
+ RETRIES - p->retries + 1);
+ return 0;
+
+failure:
+ free(aio);
+ free(sb);
+ return -1;
+}
+
+int init_port_boot(void)
+{
+ if (iso9660_register())
+ return -1;
+
+ init_ps1 = (const struct init_ps1)
+ {
+ .retries = RETRIES,
+ .next = retry
+ };
+
+ return 0;
+}
diff --git a/src/init/ps1/src/globalvars.c b/src/init/ps1/src/globalvars.c
new file mode 100644
index 0000000..6d4d2aa
--- /dev/null
+++ b/src/init/ps1/src/globalvars.c
@@ -0,0 +1,21 @@
+/*
+ * wanix, 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 <init/ps1/types.h>
+
+struct init_ps1 init_ps1;
diff --git a/src/init/ps1/src/run.c b/src/init/ps1/src/run.c
new file mode 100644
index 0000000..a0d022f
--- /dev/null
+++ b/src/init/ps1/src/run.c
@@ -0,0 +1,27 @@
+/*
+ * wanix, 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 <init.h>
+#include <init/ps1/types.h>
+
+int init_port_run(void)
+{
+ struct init_ps1 *const p = &init_ps1;
+
+ return p->next ? p->next(p) : 0;
+}
diff --git a/src/init/ps1/src/time.c b/src/init/ps1/src/time.c
new file mode 100644
index 0000000..72183c0
--- /dev/null
+++ b/src/init/ps1/src/time.c
@@ -0,0 +1,47 @@
+/*
+ * wanix, 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 <init.h>
+#include <init/ps1/types.h>
+#include <drv/ps1/bios.h>
+#include <drv/ps1/rcnt.h>
+#include <drv/ps1/time.h>
+#include <time.h>
+
+int init_time(void)
+{
+ struct timespec ts;
+ const union drv_ps1_rcnt_cfg cfg =
+ {
+ .bits =
+ {
+ .reset = 1,
+ .repeat = 1,
+ .irq_tgt = 1,
+ .clocksrc = 3
+ }
+ };
+
+ if (clock_getres(CLOCK_REALTIME, &ts))
+ return -1;
+
+ const unsigned fcpu = 33000000;
+ const uint16_t target = (fcpu / 8) / (ts.tv_nsec / 1000);
+
+ return drv_ps1_rcnt_init(DRV_PS1_RCNT2, target, &cfg, drv_ps1_time_tick);
+}
diff --git a/src/init/src/CMakeLists.txt b/src/init/src/CMakeLists.txt
new file mode 100644
index 0000000..fd1c1e7
--- /dev/null
+++ b/src/init/src/CMakeLists.txt
@@ -0,0 +1,22 @@
+# wanix, 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(init PRIVATE
+ boot.c
+ run.c
+ vars.c
+ vfs.c
+)
diff --git a/src/init/src/boot.c b/src/init/src/boot.c
new file mode 100644
index 0000000..98352c2
--- /dev/null
+++ b/src/init/src/boot.c
@@ -0,0 +1,121 @@
+/*
+ * wanix, 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 <init.h>
+#include <init/port.h>
+#include <init/types.h>
+#include <aio.h>
+#include <kprintf.h>
+#include <loop.h>
+#include <stdlib.h>
+#include <time.h>
+
+static int retry(struct init *);
+enum {RETRIES = 5};
+
+static int run(struct init *const init)
+{
+ return init_port_run();
+}
+
+static int init_port(struct init *const init)
+{
+ kprintf("tty initilization successful (took %u attempts)\n",
+ RETRIES - init->retries + 1);
+
+ if (init_port_boot())
+ return -1;
+
+ init->next = run;
+ return 0;
+}
+
+static int wait_retry(struct init *const init)
+{
+ struct timespec ts;
+ const time_t last = init->last_retry.tv_sec, timeout = 5;
+
+ if (clock_gettime(CLOCK_REALTIME, &ts))
+ return -1;
+ else if (ts.tv_sec - last >= timeout)
+ init->next = retry;
+
+ return 0;
+}
+
+static int stat_done(const enum state s, void *const args)
+{
+ int ret = 0;
+ struct init *const init = args;
+
+ if (s)
+ {
+ struct timespec ts;
+
+ if (!--init->retries || clock_gettime(CLOCK_REALTIME, &ts))
+ {
+ ret = -1;
+ goto end;
+ }
+
+ init->last_retry = ts;
+ init->next = wait_retry;
+ }
+ else
+ init->next = init_port;
+
+end:
+ loop_rm_aio(init->aio);
+ aio_free(init->aio);
+ return ret;
+}
+
+static int retry(struct init *const init)
+{
+ struct aio *aio = NULL;
+ const struct fs_stat s = {.path = "/dev/tty", .sb = &init->sb};
+ const struct aio_done d = {.f = stat_done, .args = init};
+ const unsigned retries = init->retries;
+
+ if (!(aio = aio_stat(&s, &d)) || loop_add_aio(aio))
+ goto failure;
+
+ *init = (const struct init)
+ {
+ .aio = aio,
+ .retries = retries,
+ .last_retry = {.tv_sec = (time_t)-1}
+ };
+
+ return 0;
+
+failure:
+ free(aio);
+ return -1;
+}
+
+int init_boot(void)
+{
+ init_vars = (const struct init)
+ {
+ .retries = RETRIES,
+ .next = retry
+ };
+
+ return 0;
+}
diff --git a/src/init/src/run.c b/src/init/src/run.c
new file mode 100644
index 0000000..835efd3
--- /dev/null
+++ b/src/init/src/run.c
@@ -0,0 +1,27 @@
+/*
+ * wanix, 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 <init.h>
+#include <init/types.h>
+
+int init_run(void)
+{
+ struct init *const p = &init_vars;
+
+ return p->next ? p->next(p) : 0;
+}
diff --git a/src/init/src/vars.c b/src/init/src/vars.c
new file mode 100644
index 0000000..ca5ff01
--- /dev/null
+++ b/src/init/src/vars.c
@@ -0,0 +1,21 @@
+/*
+ * wanix, 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 <init/types.h>
+
+struct init init_vars;
diff --git a/src/init/src/vfs.c b/src/init/src/vfs.c
new file mode 100644
index 0000000..cf7dd3d
--- /dev/null
+++ b/src/init/src/vfs.c
@@ -0,0 +1,86 @@
+/*
+ * wanix, 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 <init.h>
+#include <aio.h>
+#include <drv/drv.h>
+#include <io.h>
+#include <devfs.h>
+#include <rootfs.h>
+#include <iso9660.h>
+#include <sys/stat.h>
+#include <stddef.h>
+
+int init_vfs(void)
+{
+ const struct aio_mount m[] =
+ {
+ {
+ .mount =
+ {
+ .tgt = "/",
+ .mode = 0755
+ },
+
+ .type = "rootfs"
+ },
+
+ {
+ .mount =
+ {
+ .tgt = "/dev",
+ .mode = 0755
+ },
+
+ .type = "devfs"
+ }
+ };
+
+ const struct fs_mkdir mk[] =
+ {
+ {
+ .path = "/dev",
+ .mode = 0755
+ },
+
+ {
+ .path = "/mnt",
+ .mode = 0755
+ },
+
+ {
+ .path = "/mnt/cdrom",
+ .mode = 0755
+ }
+ };
+
+ if (rootfs_register()
+ || devfs_register()
+ || io_mount(m))
+ return -1;
+
+ for (size_t i = 0; i < sizeof mk / sizeof *mk; i++)
+ if (io_mkdir(&mk[i]))
+ return -1;
+
+ for (size_t i = 1; i < sizeof m / sizeof *m; i++)
+ if (io_mount(&m[i]))
+ return -1;
+
+ return 0;
+}