From 1767d390fbf3d0c65389de46caf0b6d43ef3b6ad Mon Sep 17 00:00:00 2001 From: Richard Qin Date: Fri, 10 Jul 2026 11:24:56 +0800 Subject: feat: establish bootable new architecture checkpoint Replace the compressed boot path with a relocatable higher-half RISC-V entry, expand memory and SMP support, and add the driver, TTY, VFS, exec, signal, syscall, initramfs, and self-test infrastructure needed for a bootable kernel checkpoint. --- na/fs/vfs_init.cc | 78 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 na/fs/vfs_init.cc (limited to 'na/fs/vfs_init.cc') diff --git a/na/fs/vfs_init.cc b/na/fs/vfs_init.cc new file mode 100644 index 0000000..ec56e88 --- /dev/null +++ b/na/fs/vfs_init.cc @@ -0,0 +1,78 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* Copyright (C) 2026 Richard Qin */ + +/* + * vfs_init.cc — Bootstrap the VFS: mount ramfs root, set global root + * + * Called from kernel_main() after slab_init() and ramfs_init(). + * This is the moral equivalent of Linux's vfs_caches_init() + + * mnt_init() + init_rootfs(). + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* ================================================================== */ +/* vfs_init — mount ramfs as root filesystem */ +/* ================================================================== */ + +/* + * ramfs_mount is called internally via the file_system_type::mount + * callback registered by ramfs_init(). We look it up by name. + */ +extern file_system_type* get_fs_type(const char* name); +extern super_block* alloc_super(file_system_type* type); + +void vfs_init() +{ + /* 1. Look up the ramfs filesystem type */ + file_system_type* ramfs_type = get_fs_type("ramfs"); + if (!ramfs_type || !ramfs_type->mount) { + printk(KERN_ERR "vfs_init: ramfs not registered!\n"); + return; + } + + /* 2. Mount ramfs */ + super_block* sb = ramfs_type->mount(ramfs_type, 0, "ramfs", nullptr); + if (!sb || !sb->s_root) { + printk(KERN_ERR "vfs_init: failed to mount ramfs!\n"); + return; + } + + /* 3. Set global root */ + g_root_dentry = sb->s_root; + g_root_mnt = nullptr; /* TODO: allocate a proper vfsmount when mount.cc lands */ + + dget(g_root_dentry); /* Hold a reference for the global root */ + + printk(KERN_INFO "[vfs] root filesystem mounted (ramfs)\n"); + + /* 4. Set up VFS state for the current (BSP idle) task, + * which will be inherited by all subsequently created tasks. */ + TaskControlBlock* bsp = current_task(); + if (bsp) { + if (!bsp->files) { + bsp->files = alloc_files_struct(); + } + if (!bsp->fs) { + bsp->fs = alloc_fs_struct(); + if (bsp->fs) { + bsp->fs->root.de = g_root_dentry; + bsp->fs->root.mnt = g_root_mnt; + bsp->fs->pwd.de = g_root_dentry; + bsp->fs->pwd.mnt = g_root_mnt; + dget(g_root_dentry); /* root ref */ + dget(g_root_dentry); /* pwd ref */ + } + } + printk(KERN_INFO "[vfs] BSP task VFS context initialized\n"); + } +} -- cgit v1.2.3