Skip to content

Commit

Permalink
Replace allocate_vector
Browse files Browse the repository at this point in the history
  • Loading branch information
Lockna committed Jan 22, 2024
1 parent 235df2d commit deb71b7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 43 deletions.
48 changes: 11 additions & 37 deletions xernel/kernel/src/arch/amd64/interrupts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use ipl::IPL;
use self::ipl::{get_ipl, raise_ipl, set_ipl};

use super::apic::apic_spurious_interrupt;
use libxernel::sync::{Spinlock, SpinlockIRQ};
use libxernel::sync::SpinlockIRQ;

static INTERRUPT_HANDLERS: SpinlockIRQ<[IRQHandler; IDT_ENTRIES]> = SpinlockIRQ::new([IRQHandler::None; IDT_ENTRIES]);

Expand Down Expand Up @@ -78,44 +78,18 @@ pub fn disable() {
}
}

// FIXME: Find solution for multi-core usage
pub fn allocate_vector(ipl: IPL) -> Option<u8> {
static FREE_VECTORS_FOR_IPL: Spinlock<[u8; 16]> = Spinlock::new([
0x0 << 4,
0x1 << 4,
0x2 << 4,
0x3 << 4,
0x4 << 4,
0x5 << 4,
0x6 << 4,
0x7 << 4,
0x8 << 4,
0x9 << 4,
0xA << 4,
0xB << 4,
0xC << 4,
0xD << 4,
0xE << 4,
0xF << 4,
]);

if (ipl as u8) > 15 {
return None;
}

let base_vector = (ipl as u8) << 4;

let mut free_vectors = FREE_VECTORS_FOR_IPL.lock();

let next_free_vector = free_vectors[ipl as usize];

if next_free_vector > base_vector + 15 {
return None;
let starting = core::cmp::max((ipl as u8) << 4, 32);

let handlers = INTERRUPT_HANDLERS.lock();

for i in starting..starting+16 {
if let IRQHandler::None = handlers[i as usize] {
return Some(i);
}
}

free_vectors[ipl as usize] += 1;

Some(next_free_vector)

return None;
}

pub fn register_handler(vector: u8, handler: fn(&mut TrapFrame)) {
Expand Down
4 changes: 1 addition & 3 deletions xernel/kernel/src/dpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,10 @@ use alloc::{boxed::Box, collections::VecDeque};

use crate::{
arch::amd64::interrupts::ipl::{raise_ipl, set_ipl, IPL},
cpu::{current_cpu, PerCpu},
cpu::current_cpu,
sched::scheduler::switch_threads,
};

pub static DPC_VECTOR: PerCpu<u8> = PerCpu::new();

pub trait DpcCall {
fn call(self: Box<Self>);
}
Expand Down
2 changes: 1 addition & 1 deletion xernel/kernel/src/mem/paging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ impl Pagemap {

impl Drop for Pagemap {
fn drop(&mut self) {
todo!("drop pagemap")
//todo!("drop pagemap")
}
}

Expand Down
8 changes: 6 additions & 2 deletions xernel/kernel/src/timer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use core::{
time::Duration,
};

use crate::cpu::current_cpu;
use crate::{cpu::current_cpu, arch::amd64::interrupts::{allocate_vector, ipl::IPL}};

use self::timer_event::TimerEvent;

Expand All @@ -22,7 +22,11 @@ static TIMER_VECTOR: Once<u8> = Once::new();
pub fn init() {
tsc::calibrate_tsc();

TIMER_VECTOR.set_once(0xE0);
if let Some(vec) = allocate_vector(IPL::IPLClock) {
TIMER_VECTOR.set_once(vec);
} else {
panic!("Could not allocate timer vector");
}

register_handler(*TIMER_VECTOR, timer_interrupt_handler);
}
Expand Down

0 comments on commit deb71b7

Please sign in to comment.