sys: Refactor GDT initialization, enhance syscall handling, and improve user mode entry

Finally we got usermode working again, It took awhile but we got it done. A few things we did in this commit:

- Simplified GDT entry initialization in gdt.c for kernel and user segments.
- Fixed TSS structure for task switching.
- Implemented cr2 handling in a page fault.
- Enhanced user stack setup in usermode.c to return the correct RSP.
- Improved syscall implementation in syscall.c, including new syscall numbers.
- Updated syscall entry to correctly handle context switching and argument passing.
- Refactored init.c to demonstrate file operations using syscalls.
- Added new syscalls for file operations in syscalls.h.
- Modified VFS to handle leading slashes in paths correctly.

Signed-off-by: kaguya <vpshinomiya@protonmail.com>
This commit is contained in:
kaguya
2026-04-26 02:06:28 -04:00
parent 3b6e68bc16
commit e6e8b1209b
19 changed files with 263 additions and 266 deletions
+9 -3
View File
@@ -3,6 +3,7 @@
#include <arch/x86_64/e9.h>
#include "mp/spinlock.h"
#include "stdio.h"
#include "mm/memory.h"
#include "string.h"
static spinlock_t s_vfs_lock = SPINLOCK_INIT;
@@ -36,8 +37,11 @@ int VFS_RegisterCharDev(const char* path,
fd_t VFS_Open_internal(const char* path)
{
const char* p = path;
if (*p == '/') p++;
for (int i = 0; i < s_num_chardevs; i++) {
if (strcmp(s_chardevs[i].path, path) == 0) {
if (strcmp(s_chardevs[i].path, p) == 0) {
for (int fd = 4; fd < VFS_MAX_FDS; fd++) {
if (!vfs_fd_table[fd].used) {
vfs_fd_table[fd].used = true;
@@ -51,7 +55,9 @@ fd_t VFS_Open_internal(const char* path)
}
}
uint32_t ino = ext2_resolve_path(path);
uint32_t ino = ext2_resolve_path(p);
if (ino == 0)
return -1;
@@ -124,7 +130,7 @@ int VFS_Read(fd_t fd, uint8_t* buf, size_t size)
size = file_size - file->offset;
// naive: read whole file then slice
uint8_t tmp[file_size];
uint8_t* tmp = kmalloc(file_size);
if (!ext2_read_file(&file->ext2.inode, tmp))
return -1;