diff --git a/src/interrupts.rs b/src/interrupts.rs index fb8f796..20b2931 100644 --- a/src/interrupts.rs +++ b/src/interrupts.rs @@ -125,7 +125,7 @@ unsafe extern "x86-interrupt" fn timer_naked() { } } -const FREQUENCY_DIVIDER: u8 = 15; +const FREQUENCY_DIVIDER: u8 = 5; static mut TIMER_COUNT: u8 = 0; diff --git a/src/main.rs b/src/main.rs index bb30ebe..c9ba14e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,9 +5,9 @@ extern crate alloc; use bootloader::{entry_point, BootInfo}; -use core::{panic::PanicInfo, arch::asm, hint::black_box}; +use core::{panic::PanicInfo, hint::black_box}; use os::{println, proc::{PROCESSES, ProcessControlBlock, Registers}}; -use x86_64::{instructions::{hlt, interrupts::{without_interrupts, self}}, structures::idt::InterruptStackFrameValue, registers::{segmentation::{CS, Segment, SS}, self}, VirtAddr}; +use x86_64::{instructions::{hlt, interrupts::{without_interrupts}}, structures::idt::InterruptStackFrameValue, registers::{segmentation::{CS, Segment, SS}, self}, VirtAddr}; entry_point!(main); fn main(bootinfo: &'static BootInfo) -> ! { @@ -22,7 +22,7 @@ fn main(bootinfo: &'static BootInfo) -> ! { without_interrupts(|| { let mut procs = PROCESSES.lock(); - static mut PROC_1_STACK: [u8; 1024] = [0; 1024]; + static mut PROC_1_STACK: [u8; 4096] = [0; 4096]; let stack_frame = InterruptStackFrameValue { instruction_pointer: VirtAddr::new(proc1 as u64), @@ -36,7 +36,7 @@ fn main(bootinfo: &'static BootInfo) -> ! { procs[1].write(ProcessControlBlock { stack_frame, registers }); - static mut PROC_2_STACK: [u8; 1024] = [0; 1024]; + static mut PROC_2_STACK: [u8; 4096] = [0; 4096]; let stack_frame = InterruptStackFrameValue { instruction_pointer: VirtAddr::new(proc2 as u64), @@ -54,15 +54,15 @@ fn main(bootinfo: &'static BootInfo) -> ! { procs[0].prev = 2; procs[1].next = 2; - procs[1].prev = 2; + procs[1].prev = 0; - procs[2].next = 1; + procs[2].next = 0; procs[2].prev = 1; }); loop { println!("Hi from main proc!"); - for i in 0..500000 { black_box(i); } + for i in 0..200000 { black_box(i); } } loop { @@ -74,14 +74,14 @@ fn main(bootinfo: &'static BootInfo) -> ! { extern "C" fn proc1() -> ! { loop { println!("Hi from proc 1!"); - for i in 0..500000 { black_box(i); } + for i in 0..200000 { black_box(i); } } } extern "C" fn proc2() -> ! { loop { println!("Hi from proc 2, foo bar baz!"); - for i in 0..500000 { black_box(i); } + for i in 0..200000 { black_box(i); } } } diff --git a/src/proc.rs b/src/proc.rs index 984c826..bbe5e34 100644 --- a/src/proc.rs +++ b/src/proc.rs @@ -1,10 +1,10 @@ -use core::{fmt::Debug, mem, hint::black_box}; +use core::{fmt::Debug, mem}; use alloc::boxed::Box; use spin::Mutex; use x86_64::{VirtAddr, structures::{paging::{Page, PageTableFlags}, idt::InterruptStackFrameValue}}; -use crate::{sync::SyncLazy, mem::map_next, lazy_static, assert_canonical, println}; +use crate::{sync::SyncLazy, mem::map_next, lazy_static, assert_canonical}; #[derive(Clone, Copy, Debug)] pub struct ProcessControlBlock { @@ -66,19 +66,13 @@ pub struct ProcListElement { impl ProcListElement { pub fn write(&mut self, pcb: ProcessControlBlock) { - println!("write"); match self.pcb.as_deref_mut() { None => { let addr = Box::leak(Box::new(pcb)); - // with this println, it tries to execute 0x0. without it, it (sometimes) tries to execute PROCESS_LIST_ADDR. - // whatever the case, it happens after 1 println in `fn timer`, before this code is even hit. - // if the line up above ^^^ is inlined, it faults after 2 printlns instead. what in the actual fuck - // println!("addr: {:x}", addr as *mut _ as usize); self.pcb.replace(addr); } Some(v) => { *v = pcb; } } - // println!("end write"); } } @@ -96,37 +90,23 @@ static CURRENT_PROCESS: Mutex = Mutex::new(0); // here i make the assumption that the privilege level is *somewhere* in `InterruptStackFrame` pub fn timer(stack_frame: &mut InterruptStackFrameValue, registers: &mut Registers) { - println!("Hello there from timer interrupt"); - let mut curr_pid = CURRENT_PROCESS.lock(); let mut procs = PROCESSES.lock(); - println!("Hello there from timer interrupt 2"); - // first, save the stack and registers values in the pcb for this pid procs[*curr_pid as usize].write(ProcessControlBlock { stack_frame: *stack_frame, registers: *registers, }); - println!("Hello there from timer interrupt 3"); - // then, choose the next pid let next_pid = procs[*curr_pid as usize].next as u64; *curr_pid = next_pid; let next = procs[next_pid as usize].pcb.as_deref().unwrap(); - println!("Hello there from timer interrupt 4"); - // last, load the stack and registers values from the new pid *stack_frame = next.stack_frame; *registers = next.registers; - - // println!("Next pid: {}", *curr_pid); - // println!("Next stack_frame: {:?}", stack_frame); - // println!("Next registers: {:?}", registers); - - for i in 0..5000000 { black_box(i); } } pub fn init() {