94 lines
2.5 KiB
Rust
94 lines
2.5 KiB
Rust
#![no_std]
|
|
#![no_main]
|
|
#![feature(bench_black_box)]
|
|
|
|
extern crate alloc;
|
|
|
|
use bootloader::{entry_point, BootInfo};
|
|
use core::{panic::PanicInfo, hint::black_box};
|
|
use os::{println, proc::{PROCESSES, ProcessControlBlock, Registers}};
|
|
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) -> ! {
|
|
without_interrupts(|| os::init(bootinfo));
|
|
|
|
println!("creating procs...");
|
|
|
|
// or else interrupts are disabled in the new processes
|
|
let rflags = registers::rflags::read_raw();
|
|
|
|
// without_interrupts for the PROCESSES lock
|
|
without_interrupts(|| {
|
|
let mut procs = PROCESSES.lock();
|
|
|
|
static mut PROC_1_STACK: [u8; 4096] = [0; 4096];
|
|
|
|
let stack_frame = InterruptStackFrameValue {
|
|
instruction_pointer: VirtAddr::new(proc1 as u64),
|
|
code_segment: CS::get_reg().0 as u64,
|
|
cpu_flags: rflags,
|
|
stack_pointer: VirtAddr::new(unsafe { &PROC_1_STACK } as *const _ as u64) + 1024usize,
|
|
stack_segment: SS::get_reg().0 as u64,
|
|
};
|
|
|
|
let registers = Registers::default();
|
|
|
|
procs[1].write(ProcessControlBlock { stack_frame, registers });
|
|
|
|
static mut PROC_2_STACK: [u8; 4096] = [0; 4096];
|
|
|
|
let stack_frame = InterruptStackFrameValue {
|
|
instruction_pointer: VirtAddr::new(proc2 as u64),
|
|
code_segment: CS::get_reg().0 as u64,
|
|
cpu_flags: rflags,
|
|
stack_pointer: VirtAddr::new(unsafe { &PROC_2_STACK } as *const _ as u64) + 1024usize,
|
|
stack_segment: SS::get_reg().0 as u64,
|
|
};
|
|
|
|
let registers = Registers::default();
|
|
|
|
procs[2].write(ProcessControlBlock { stack_frame, registers });
|
|
|
|
procs[0].next = 1;
|
|
procs[0].prev = 2;
|
|
|
|
procs[1].next = 2;
|
|
procs[1].prev = 0;
|
|
|
|
procs[2].next = 0;
|
|
procs[2].prev = 1;
|
|
});
|
|
|
|
loop {
|
|
println!("Hi from main proc!");
|
|
for i in 0..200000 { black_box(i); }
|
|
}
|
|
|
|
loop {
|
|
hlt();
|
|
}
|
|
}
|
|
|
|
#[allow(named_asm_labels)]
|
|
extern "C" fn proc1() -> ! {
|
|
loop {
|
|
println!("Hi from proc 1!");
|
|
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..200000 { black_box(i); }
|
|
}
|
|
}
|
|
|
|
#[panic_handler]
|
|
fn panic(info: &PanicInfo) -> ! {
|
|
println!("{}", info);
|
|
loop {
|
|
hlt();
|
|
}
|
|
} |