progress in irqs
This commit is contained in:
parent
82bccd373c
commit
46f4837cc7
37
Cargo.lock
generated
37
Cargo.lock
generated
@ -2,12 +2,25 @@
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "bit_field"
|
||||
version = "0.10.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61"
|
||||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.8.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8f68f53c83ab957f72c32642f3868eec03eb974d1fb82e453128456482613d36"
|
||||
|
||||
[[package]]
|
||||
name = "mxrox"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"no-std-compat 0.4.1",
|
||||
"stable-vec",
|
||||
"x86_64",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@ -22,6 +35,12 @@ version = "0.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b93853da6d84c2e3c7d730d6473e8817692dd89be387eb01b94d7f108ecb5b8c"
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.19"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4"
|
||||
|
||||
[[package]]
|
||||
name = "stable-vec"
|
||||
version = "0.4.1"
|
||||
@ -30,3 +49,21 @@ checksum = "d1dff32a2ce087283bec878419027cebd888760d8760b2941ad0843531dc9ec8"
|
||||
dependencies = [
|
||||
"no-std-compat 0.2.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "volatile"
|
||||
version = "0.4.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "442887c63f2c839b346c192d047a7c87e73d0689c9157b00b53dcc27dd5ea793"
|
||||
|
||||
[[package]]
|
||||
name = "x86_64"
|
||||
version = "0.15.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0f042214de98141e9c8706e8192b73f56494087cc55ebec28ce10f26c5c364ae"
|
||||
dependencies = [
|
||||
"bit_field",
|
||||
"bitflags",
|
||||
"rustversion",
|
||||
"volatile",
|
||||
]
|
||||
|
@ -9,6 +9,7 @@ edition = "2021"
|
||||
[dependencies]
|
||||
stable-vec = "0.4.1"
|
||||
no-std-compat = {version = "0.4.1", features = ["alloc"]}
|
||||
x86_64 = {version = "0.15.2", features = ["instructions"]}
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
|
@ -30,6 +30,7 @@ Internet resources where I found most information about OS dev
|
||||
- https://gitea.bedohswe.eu.org/bedohswe/bootsector_tictactoe/
|
||||
- https://wiki.osdev.org/PS/2
|
||||
- https://os.phil-opp.com/
|
||||
- https://wiki.osdev.org/Interrupts_Tutorial
|
||||
|
||||
### Contributing
|
||||
|
||||
|
68
src/kernel/irq.rs
Normal file
68
src/kernel/irq.rs
Normal file
@ -0,0 +1,68 @@
|
||||
use core::ptr::write_volatile;
|
||||
use core::arch::asm;
|
||||
|
||||
const APIC_BASE: *mut u32 = 0xFEE00000 as *mut u32;
|
||||
|
||||
const APIC_EOI: *mut u32 = unsafe { APIC_BASE.add(0x0B0) };
|
||||
const APIC_SVR: *mut u32 = unsafe { APIC_BASE.add(0x0F0) };
|
||||
|
||||
#[repr(C, packed)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct IdtEntry {
|
||||
offset_low: u16,
|
||||
selector: u16,
|
||||
ist: u8,
|
||||
type_attr: u8,
|
||||
offset_middle: u16
|
||||
}
|
||||
|
||||
pub const IDT_SIZE: usize = 256;
|
||||
|
||||
#[repr(C)]
|
||||
pub struct Idt {
|
||||
entries: [IdtEntry; IDT_SIZE],
|
||||
}
|
||||
|
||||
static mut IDT: Idt = Idt {
|
||||
entries: [IdtEntry {
|
||||
offset_low: 0,
|
||||
selector: 0,
|
||||
ist: 0,
|
||||
type_attr: 0,
|
||||
offset_middle: 0,
|
||||
}; IDT_SIZE],
|
||||
};
|
||||
|
||||
fn register_idt(handler: u32) {
|
||||
unsafe {
|
||||
let entry = &mut IDT.entries[32];
|
||||
|
||||
entry.offset_low = handler as u16;
|
||||
entry.selector = 0x08;
|
||||
entry.ist = 0;
|
||||
entry.type_attr = 0x8E;
|
||||
entry.offset_middle = (handler >> 16) as u16;
|
||||
}
|
||||
}
|
||||
|
||||
unsafe fn load_idt() {
|
||||
asm!("lidt [{}]", "sti", in(reg) &IDT as *const _);
|
||||
}
|
||||
|
||||
unsafe fn enable_apic() {
|
||||
let sv_reg = APIC_SVR as *mut u32;
|
||||
let mut value = 0x100 | 0x1;
|
||||
write_volatile(sv_reg, value);
|
||||
}
|
||||
|
||||
unsafe fn send_eoi() {
|
||||
let eoi_reg = APIC_EOI as *mut u32;
|
||||
write_volatile(eoi_reg, 0);
|
||||
}
|
||||
|
||||
pub fn init_apic() {
|
||||
unsafe {
|
||||
load_idt();
|
||||
enable_apic();
|
||||
}
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
use irq::init_apic;
|
||||
use heap::init_heap;
|
||||
use ps2::read_ps2_status;
|
||||
use ps2::init_ps2;
|
||||
use vga::{
|
||||
fill_with_color,
|
||||
put_string,
|
||||
@ -8,11 +9,10 @@ use vga::{
|
||||
VGA_COLOR_LIGHT_MAGENTA,
|
||||
VGA_COLOR_RED
|
||||
};
|
||||
use no_std_compat::string::ToString;
|
||||
|
||||
mod vga;
|
||||
mod ps2;
|
||||
mod acpi;
|
||||
mod irq;
|
||||
mod thread;
|
||||
mod heap;
|
||||
mod util;
|
||||
@ -24,15 +24,10 @@ pub fn show_error(message: &str) {
|
||||
|
||||
pub fn init_kernel() {
|
||||
init_heap(16400, 16384);
|
||||
init_ps2();
|
||||
init_apic();
|
||||
|
||||
fill_with_color(VGA_COLOR_BLACK);
|
||||
|
||||
loop {
|
||||
put_string(
|
||||
0, 0,
|
||||
&format!("ps/2 status: 0x{:x}", read_ps2_status()),
|
||||
VGA_COLOR_BLACK,
|
||||
VGA_COLOR_LIGHT_MAGENTA
|
||||
);
|
||||
}
|
||||
loop {}
|
||||
}
|
@ -1,7 +1,5 @@
|
||||
use core::ptr::{read_volatile, write_volatile};
|
||||
|
||||
use no_std_compat::vec::Vec;
|
||||
|
||||
const DATA_PORT: *mut u8 = 0x60 as *mut u8;
|
||||
const STATUS_PORT: *mut u8 = 0x64 as *mut u8;
|
||||
|
||||
@ -17,11 +15,11 @@ fn send_ps2_command(command: u8) {
|
||||
unsafe { write_volatile(STATUS_PORT, command) }
|
||||
}
|
||||
|
||||
pub fn read_ps2_status() -> u8 {
|
||||
fn read_ps2_status() -> u8 {
|
||||
unsafe { read_volatile(STATUS_PORT) }
|
||||
}
|
||||
|
||||
/// returns device type bytes
|
||||
fn init_ps2_controller() -> Vec<u8> {
|
||||
pub fn init_ps2() {
|
||||
|
||||
todo!()
|
||||
}
|
@ -1 +0,0 @@
|
||||
use core::str;
|
@ -4,6 +4,8 @@
|
||||
#![feature(lang_items)]
|
||||
#![feature(alloc_error_handler)]
|
||||
#![feature(rustc_private)]
|
||||
#![feature(abi_x86_interrupt)]
|
||||
|
||||
|
||||
#[lang = "eh_personality"]
|
||||
extern "C" fn eh_personality() {}
|
||||
@ -20,12 +22,13 @@ extern crate alloc;
|
||||
#[inline(never)]
|
||||
#[panic_handler]
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
show_error(info.message().as_str().unwrap_or("mxrox death"));
|
||||
show_error(info.message().as_str().unwrap_or("Unknown Error"));
|
||||
loop {}
|
||||
}
|
||||
|
||||
#[alloc_error_handler]
|
||||
fn oom(_layout: core::alloc::Layout) -> ! {
|
||||
show_error("Out Of Memory");
|
||||
loop {}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user