Skip to content

Commit

Permalink
fix warnings and add todo comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Lockna committed Sep 11, 2024
1 parent 3323783 commit eda66cd
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 11 deletions.
4 changes: 2 additions & 2 deletions crates/libxernel/src/sync/spin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::{
};

use crate::{
ipl::{raise_ipl, IPL},
ipl::{raise_ipl, splx, IPL},
on_drop::OnDrop,
};

Expand Down Expand Up @@ -82,7 +82,7 @@ impl<T: ?Sized> Spinlock<T> {

pub fn aquire(&self) -> OnDrop<SpinlockGuard<'_, T>, impl FnOnce()> {
let ipl = raise_ipl(IPL::DPC);
let callback = move || write_cr8(ipl);
let callback = move || splx(ipl);
OnDrop::new(self.lock(), callback)
}

Expand Down
1 change: 1 addition & 0 deletions xernel/kernel/src/arch/amd64/interrupts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ pub fn init() {
handlers[0xE] = IRQHandler::Handler(page_fault_handler);
handlers[0x8] = IRQHandler::Handler(double_fault_handler);
handlers[0xF0] = IRQHandler::Handler(apic_spurious_interrupt);
// TODO: allocate vectors accordingly or manually set all known interrupt handlers here
handlers[0x2f] = IRQHandler::Handler(dispatch_dpcs);
handlers[0xd0] = IRQHandler::Handler(keyboard);
}
Expand Down
1 change: 1 addition & 0 deletions xernel/kernel/src/arch/amd64/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::acpi::hpet;

pub static TSC_TICKS_PER_MS: AtomicU64 = AtomicU64::new(0);

// TODO: Use TSC Deadshot mode for apic
pub fn calibrate_tsc() {
let start: u64 = rdtsc();
hpet::sleep(10_000_000);
Expand Down
2 changes: 2 additions & 0 deletions xernel/kernel/src/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ impl<T> Deref for PerCpu<T> {
}
}

// TODO: Replace RwLock with spinlock to use aquire functionality
// TODO: Create helper methods for cpu struct (add_dpc, add_timer, ...)
#[repr(C, align(8))]
pub struct Cpu {
// NOTE: don't move these variables as we need to access them from assembly
Expand Down
5 changes: 4 additions & 1 deletion xernel/kernel/src/drivers/ps2/keyboard.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use crate::{arch::amd64::{apic::APIC, ports::inb}, sched::context::TrapFrame};
use crate::{
arch::amd64::{apic::APIC, ports::inb},
sched::context::TrapFrame,
};

pub fn keyboard(_: &mut TrapFrame) {
dbg!("keyboard hit");
Expand Down
6 changes: 4 additions & 2 deletions xernel/kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,16 @@ extern "C" fn kernel_main() -> ! {
// FIXME: If used in code, code panics with error "virtual address must be sign extended in bits 48 to 64"
let _user_task = Thread::new_user_thread(process.clone(), VirtAddr::new(0x200000));

let page = FRAME_ALLOCATOR.lock().allocate_frame::<Size2MiB>().unwrap();
let page = FRAME_ALLOCATOR.aquire().allocate_frame::<Size2MiB>().unwrap();

KERNEL_PAGE_MAPPER.lock().map(
KERNEL_PAGE_MAPPER.aquire().map(
page,
Page::from_start_address(VirtAddr::new(0x200000)).unwrap(),
PageTableFlags::WRITABLE | PageTableFlags::USER_ACCESSIBLE | PageTableFlags::PRESENT,
true,
);

// FIXME: If aquire is used probably deadlock
let mut process = process.lock();
let pm = process.get_page_table().as_mut().unwrap();
pm.map(
Expand Down Expand Up @@ -192,6 +193,7 @@ extern "C" fn kernel_main() -> ! {

let kernel_task2 = Thread::kernel_thread_from_fn(task2);

// TODO: use convenience functions
current_cpu().run_queue.write().push_back(Arc::new(main_task));
current_cpu().run_queue.write().push_back(Arc::new(kernel_task));
current_cpu().run_queue.write().push_back(Arc::new(kernel_task2));
Expand Down
4 changes: 2 additions & 2 deletions xernel/kernel/src/sched/context.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
use core::arch::asm;

use crate::arch::amd64::write_cr8;

#[derive(Debug, Clone, Copy, Default)]
#[repr(C)]
pub struct Context {
Expand Down Expand Up @@ -85,6 +83,8 @@ impl TrapFrame {
}
}

// TODO: Maybe rework switching to new thread
// TODO: Move to switch.S since platform dependant
#[naked]
/// Restores the gives TrapFrame and jumps to new RIP via iretq
/// Is used to startup a new thread when it's first executed
Expand Down
7 changes: 3 additions & 4 deletions xernel/kernel/src/timer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ use crate::amd64::interrupts::register_handler;
use crate::amd64::tsc;
use crate::apic::APIC;
use crate::sched::context::TrapFrame;
use libxernel::{
ipl::{get_ipl, IPL},
sync::Once,
};
use libxernel::{ipl::IPL, sync::Once};

static UPTIME: AtomicUsize = AtomicUsize::new(0);
static TIMER_VECTOR: Once<u8> = Once::new();
Expand Down Expand Up @@ -51,6 +48,7 @@ pub fn timer_interrupt_handler(_frame: &mut TrapFrame) {
if let Some(event) = next_event {
APIC.oneshot(*TIMER_VECTOR, &event.deadline);

// TODO: Find a way to clone event
if event.periodic {
//timer_queue.queue_event(event.clone());
}
Expand All @@ -70,5 +68,6 @@ pub fn hardclock(_: ()) {
UPTIME.fetch_add(1, Ordering::SeqCst);
let event = TimerEvent::new(hardclock, (), Duration::from_secs(1), false);

// TODO: use convenience functions
current_cpu().timer_queue.write().enqueue(event);
}

0 comments on commit eda66cd

Please sign in to comment.