v0.5.3: syscalls, minilibc.
- fix(gs): was a nightmare. now its solved. Both MSR_GS_BASE and MSR_KERNEL_GS_BASE are now initialized to , preventing null GS_BASE when interrupt occurs during the first kernel task run - chore(syscall.asm): stability improvements. User RSP is now saved via kernel stack instead of global g_cpu, preventing stack theft when task switch occurs during a syscall - feat(interrupts): all irq and isr handlers now conditionally perform swapgs based on the CS selector (checkin if comfing from ring 3) - upgrade(scheduler): big update: 1) added TASK_BLOCKED state from process sync; 2) syncronized PID and Task ID to fix wakeup logic; 3) implemented sched_block and sched_exit() for proper wait/exit syscalls
This commit is contained in:
@@ -3,10 +3,11 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#define MSR_EFER 0xC0000080
|
||||
#define MSR_STAR 0xC0000081
|
||||
#define MSR_LSTAR 0xC0000082
|
||||
#define MSR_FMASK 0xC0000084
|
||||
#define MSR_EFER 0xC0000080
|
||||
#define MSR_STAR 0xC0000081
|
||||
#define MSR_LSTAR 0xC0000082
|
||||
#define MSR_FMASK 0xC0000084
|
||||
#define MSR_GS_BASE 0xC0000101
|
||||
#define MSR_KERNEL_GS_BASE 0xC0000102
|
||||
|
||||
#define EFER_SCE 0x01 // System Call Enable
|
||||
@@ -17,6 +18,7 @@ typedef enum {
|
||||
SYS_MEM,
|
||||
SYS_WRITE,
|
||||
SYS_READ,
|
||||
SYS_WAIT,
|
||||
} syscalls;
|
||||
|
||||
void syscall_init();
|
||||
@@ -7,6 +7,9 @@
|
||||
typedef enum process_state {
|
||||
DEAD,
|
||||
RUNNING,
|
||||
READY,
|
||||
BLOCKED,
|
||||
SLEEPING,
|
||||
} process_state;
|
||||
|
||||
typedef struct process {
|
||||
@@ -27,9 +30,13 @@ typedef struct task {
|
||||
process_state task_state; // reusing process_state cuz wn
|
||||
u64 kernel_stack_top;
|
||||
process* proc;
|
||||
i32 waiting_on_pid;
|
||||
} task;
|
||||
|
||||
void sched_init();
|
||||
task* sched_spawn(void(*entry)(), process* owner, bool is_user, u64 fixed_user_stack);
|
||||
u64 sched_next(u64 curr_rsp);
|
||||
void yield(u64 ticks);
|
||||
void yield(u64 ticks);
|
||||
void sched_block(u32 pid);
|
||||
void sched_wakeup(u32 pid);
|
||||
void sched_exit(); // suicide
|
||||
@@ -7,4 +7,4 @@
|
||||
void timer_init(u32 freq);
|
||||
u64 timer_handler(Registers *regs);
|
||||
void sleep(u64 ms);
|
||||
u64 get_uptime();
|
||||
u64 get_uptime();
|
||||
@@ -6,4 +6,5 @@
|
||||
#include <types.h>
|
||||
|
||||
u64 sys_exit(i32 code);
|
||||
u64 sys_spawn(const char* path);
|
||||
u64 sys_spawn(const char* path);
|
||||
u64 sys_wait(u64 pid);
|
||||
Reference in New Issue
Block a user