feat(sched): implement preemptive time-slicing multitasking via PIT 8254 timer ISR (Vector 32)

This commit is contained in:
RarDog
2026-09-02 16:54:19 +03:00
parent 448b0e710e
commit e7a0d2e6b1
6 changed files with 248 additions and 74 deletions
+14 -14
View File
@@ -17,6 +17,7 @@ use sched::SCHEDULER;
core::arch::global_asm!(include_str!("../asm/context.S"));
core::arch::global_asm!(include_str!("../asm/syscall_entry.S"));
core::arch::global_asm!(include_str!("../asm/ring3_enter.S"));
core::arch::global_asm!(include_str!("../asm/timer_isr.S"));
#[no_mangle]
pub extern "C" fn _start() -> ! {
@@ -60,21 +61,18 @@ pub extern "C" fn _start() -> ! {
mm::init(memmap_resp);
}
// 6. Initialize IPC & Capability System
// 6. Initialize Preemptive Hardware Timer (PIT 8254 @ 100 Hz)
kprintln!("[BOOT] Configuring PIT 8254 timer for Preemptive Multi-Tasking...");
unsafe {
drivers::timer::init(100);
}
// 7. Initialize IPC & Capability System
ipc::init();
// 7. Initialize Scheduler
// 8. Initialize Scheduler
sched::init();
// 8. Self-Test Fast-Path IPC Ping
kprintln!("[TEST] Executing Kernel Fast-Path IPC Self-Test...");
let (status, resp_op, val) = ipc::fastpath::handle_fastpath_call(
ipc::fastpath::CAP_KERNEL_CONTROL,
ipc::fastpath::IPC_OP_PING,
42, 0, 0, 0
);
kprintln!("[TEST] IPC Fast-Path Ping Result: status={}, opcode={:#x}, val={}", status, resp_op, val);
// 9. Inspect and Load Initial Userspace Processes
unsafe {
let mod_resp = MODULE_REQUEST.response;
@@ -102,7 +100,7 @@ pub extern "C" fn _start() -> ! {
proc.pml4_paddr,
proc.kernel_stack_top,
);
kprintln!("[BOOT] Registered Thread '{}' with TID {:?}", name, tid);
kprintln!("[BOOT] Registered Preemptible Thread '{}' with TID {:?}", name, tid);
}
Err(err) => {
kprintln!("[ERROR] Failed to load module [{}]: {}", i, err);
@@ -110,8 +108,10 @@ pub extern "C" fn _start() -> ! {
}
}
kprintln!("[BOOT] Starting Multi-Tasking & IPC Rendezvous...");
kprintln!("[BOOT] Enabling Interrupts & Starting Preemptive Scheduler...");
kprintln!("-------------------------------------------------------");
// Pick first ready thread and switch to it with interrupts enabled
(*sched_ptr).schedule();
} else {
kprintln!("[BOOT] No userspace modules detected. Staying in Ring 0 idle loop.");
@@ -122,7 +122,7 @@ pub extern "C" fn _start() -> ! {
loop {
unsafe {
core::arch::asm!("hlt");
core::arch::asm!("sti; hlt");
}
}
}