whoops i ran out of stack space
This commit is contained in:
parent
c68fdd7dd2
commit
ef1f0897ae
|
@ -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;
|
static mut TIMER_COUNT: u8 = 0;
|
||||||
|
|
||||||
|
|
18
src/main.rs
18
src/main.rs
|
@ -5,9 +5,9 @@
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
use bootloader::{entry_point, BootInfo};
|
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 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);
|
entry_point!(main);
|
||||||
fn main(bootinfo: &'static BootInfo) -> ! {
|
fn main(bootinfo: &'static BootInfo) -> ! {
|
||||||
|
@ -22,7 +22,7 @@ fn main(bootinfo: &'static BootInfo) -> ! {
|
||||||
without_interrupts(|| {
|
without_interrupts(|| {
|
||||||
let mut procs = PROCESSES.lock();
|
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 {
|
let stack_frame = InterruptStackFrameValue {
|
||||||
instruction_pointer: VirtAddr::new(proc1 as u64),
|
instruction_pointer: VirtAddr::new(proc1 as u64),
|
||||||
|
@ -36,7 +36,7 @@ fn main(bootinfo: &'static BootInfo) -> ! {
|
||||||
|
|
||||||
procs[1].write(ProcessControlBlock { stack_frame, registers });
|
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 {
|
let stack_frame = InterruptStackFrameValue {
|
||||||
instruction_pointer: VirtAddr::new(proc2 as u64),
|
instruction_pointer: VirtAddr::new(proc2 as u64),
|
||||||
|
@ -54,15 +54,15 @@ fn main(bootinfo: &'static BootInfo) -> ! {
|
||||||
procs[0].prev = 2;
|
procs[0].prev = 2;
|
||||||
|
|
||||||
procs[1].next = 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;
|
procs[2].prev = 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
println!("Hi from main proc!");
|
println!("Hi from main proc!");
|
||||||
for i in 0..500000 { black_box(i); }
|
for i in 0..200000 { black_box(i); }
|
||||||
}
|
}
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@ -74,14 +74,14 @@ fn main(bootinfo: &'static BootInfo) -> ! {
|
||||||
extern "C" fn proc1() -> ! {
|
extern "C" fn proc1() -> ! {
|
||||||
loop {
|
loop {
|
||||||
println!("Hi from proc 1!");
|
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() -> ! {
|
extern "C" fn proc2() -> ! {
|
||||||
loop {
|
loop {
|
||||||
println!("Hi from proc 2, foo bar baz!");
|
println!("Hi from proc 2, foo bar baz!");
|
||||||
for i in 0..500000 { black_box(i); }
|
for i in 0..200000 { black_box(i); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
24
src/proc.rs
24
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 alloc::boxed::Box;
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
use x86_64::{VirtAddr, structures::{paging::{Page, PageTableFlags}, idt::InterruptStackFrameValue}};
|
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)]
|
#[derive(Clone, Copy, Debug)]
|
||||||
pub struct ProcessControlBlock {
|
pub struct ProcessControlBlock {
|
||||||
|
@ -66,19 +66,13 @@ pub struct ProcListElement {
|
||||||
|
|
||||||
impl ProcListElement {
|
impl ProcListElement {
|
||||||
pub fn write(&mut self, pcb: ProcessControlBlock) {
|
pub fn write(&mut self, pcb: ProcessControlBlock) {
|
||||||
println!("write");
|
|
||||||
match self.pcb.as_deref_mut() {
|
match self.pcb.as_deref_mut() {
|
||||||
None => {
|
None => {
|
||||||
let addr = Box::leak(Box::new(pcb));
|
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);
|
self.pcb.replace(addr);
|
||||||
}
|
}
|
||||||
Some(v) => { *v = pcb; }
|
Some(v) => { *v = pcb; }
|
||||||
}
|
}
|
||||||
// println!("end write");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,37 +90,23 @@ static CURRENT_PROCESS: Mutex<u64> = Mutex::new(0);
|
||||||
|
|
||||||
// here i make the assumption that the privilege level is *somewhere* in `InterruptStackFrame`
|
// here i make the assumption that the privilege level is *somewhere* in `InterruptStackFrame`
|
||||||
pub fn timer(stack_frame: &mut InterruptStackFrameValue, registers: &mut Registers) {
|
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 curr_pid = CURRENT_PROCESS.lock();
|
||||||
let mut procs = PROCESSES.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
|
// first, save the stack and registers values in the pcb for this pid
|
||||||
procs[*curr_pid as usize].write(ProcessControlBlock {
|
procs[*curr_pid as usize].write(ProcessControlBlock {
|
||||||
stack_frame: *stack_frame,
|
stack_frame: *stack_frame,
|
||||||
registers: *registers,
|
registers: *registers,
|
||||||
});
|
});
|
||||||
|
|
||||||
println!("Hello there from timer interrupt 3");
|
|
||||||
|
|
||||||
// then, choose the next pid
|
// then, choose the next pid
|
||||||
let next_pid = procs[*curr_pid as usize].next as u64;
|
let next_pid = procs[*curr_pid as usize].next as u64;
|
||||||
*curr_pid = next_pid;
|
*curr_pid = next_pid;
|
||||||
let next = procs[next_pid as usize].pcb.as_deref().unwrap();
|
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
|
// last, load the stack and registers values from the new pid
|
||||||
*stack_frame = next.stack_frame;
|
*stack_frame = next.stack_frame;
|
||||||
*registers = next.registers;
|
*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() {
|
pub fn init() {
|
||||||
|
|
Loading…
Reference in a new issue