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:
+28
-4
@@ -1,5 +1,7 @@
|
||||
#include "../include/syscalls.h"
|
||||
|
||||
#define STDOUT 1
|
||||
|
||||
unsigned strlen(const char* str)
|
||||
{
|
||||
unsigned len = 0;
|
||||
@@ -8,15 +10,37 @@ unsigned strlen(const char* str)
|
||||
++len;
|
||||
++str;
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
void main()
|
||||
{
|
||||
syscall(1, 'A', 0, 0);
|
||||
syscall(1, 'B', 0, 0);
|
||||
syscall(1, 'C', 0, 0);
|
||||
const char* path = "/qwerty.txt";
|
||||
const char* msg = "Suki Suki Daisuki Kekkon Shiyo, my honey!";
|
||||
|
||||
char buf[128];
|
||||
|
||||
// ── open file ─────────────────────────────
|
||||
long fd = syscall(SYS_OPEN, (long)path, 0, 0);
|
||||
|
||||
// ── write message ─────────────────────────
|
||||
syscall(SYS_WRITE, fd, (long)msg, strlen(msg));
|
||||
|
||||
// ── close ────────────────────────────────
|
||||
syscall(SYS_CLOSE, fd, 0, 0);
|
||||
|
||||
// ── reopen ───────────────────────────────
|
||||
fd = syscall(SYS_OPEN, (long)path, 0, 0);
|
||||
|
||||
// ── read into buffer ─────────────────────
|
||||
long n = syscall(SYS_READ, fd, (long)buf, sizeof(buf));
|
||||
|
||||
// ── close ────────────────────────────────
|
||||
syscall(SYS_CLOSE, fd, 0, 0);
|
||||
|
||||
// ── print buffer to stdout ───────────────
|
||||
syscall(SYS_WRITE, STDOUT, (long)buf, n);
|
||||
|
||||
// ── done ────────────────────────────────
|
||||
while (1);
|
||||
}
|
||||
Reference in New Issue
Block a user