Skip to content

Commit

Permalink
temp kernel heap & dummy ata
Browse files Browse the repository at this point in the history
  • Loading branch information
wuyukai0403 committed Jan 22, 2025
1 parent f6c8ae4 commit e227a50
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 0 deletions.
17 changes: 17 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions kernel/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ version = "0.0.2-20250105"
edition = "2021"

[dependencies]
good_memory_allocator = "0.1.7"
limine = "0.3.1"
noto-sans-mono-bitmap = "0.3.1"
raw-cpuid = "11.3.0"
Expand Down
5 changes: 5 additions & 0 deletions kernel/src/ata.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
use crate::println;

Check warning on line 1 in kernel/src/ata.rs

View workflow job for this annotation

GitHub Actions / build

unused import: `crate::println`

pub fn init_and_test() {

}
7 changes: 7 additions & 0 deletions kernel/src/int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use crate::{print, println};
use x86_64::structures::idt::HandlerFunc;

Check warning on line 4 in kernel/src/int.rs

View workflow job for this annotation

GitHub Actions / build

unused import: `x86_64::structures::idt::HandlerFunc`
use x86_64::structures::idt::InterruptDescriptorTable;
use x86_64::structures::idt::InterruptStackFrame;
use x86_64::structures::idt::PageFaultErrorCode;
use spin::{Lazy, Mutex};

Check warning on line 8 in kernel/src/int.rs

View workflow job for this annotation

GitHub Actions / build

unused import: `Mutex`

pub static IDT: Lazy<InterruptDescriptorTable> = Lazy::new(|| {
Expand All @@ -12,6 +13,7 @@ pub static IDT: Lazy<InterruptDescriptorTable> = Lazy::new(|| {
temp[33].set_handler_fn(handler2);
temp[34].set_handler_fn(handler3);
temp[36].set_handler_fn(handler4);
temp.page_fault.set_handler_fn(handler5);
temp
});

Expand Down Expand Up @@ -42,3 +44,8 @@ pub extern "x86-interrupt" fn handler4(_: InterruptStackFrame) {
}
crate::apic::local::eoi();
}

pub extern "x86-interrupt" fn handler5(_: InterruptStackFrame, _1: PageFaultErrorCode) {
println!("page fault");
loop{}
}
1 change: 1 addition & 0 deletions kernel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ pub mod cpu;
pub mod int;
pub mod mm;
pub mod pcie;
pub mod ata;
2 changes: 2 additions & 0 deletions kernel/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use DoglinkOS_2nd::cpu::show_cpu_info;
use DoglinkOS_2nd::int::init as init_interrupt;
use DoglinkOS_2nd::mm::init as init_mm;
use DoglinkOS_2nd::pcie::enumrate::doit;
use DoglinkOS_2nd::ata::init_and_test as test_ata;
use DoglinkOS_2nd::println;

#[used]
Expand Down Expand Up @@ -60,6 +61,7 @@ extern "C" fn kmain() -> ! {
init_ioapic(parse_madt());
show_cpu_info();
doit();
test_ata();
hang();
}

Expand Down
13 changes: 13 additions & 0 deletions kernel/src/mm.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,25 @@
use crate::println;
use limine::response::HhdmResponse;
use spin::Mutex;
use good_memory_allocator::SpinLockedAllocator;

#[global_allocator]
static ALLOCATOR: SpinLockedAllocator = SpinLockedAllocator::empty();

#[used]
static mut RESERVED_HEAP: [u8; 8 * 1024 * 1024] = [0; 8 * 1024 * 1024];

pub static offset: Mutex<u64> = Mutex::new(0);

pub fn init(res: &HhdmResponse) {
println!("[INFO] mm: init() called");
unsafe {
println!("[INFO] RESERVED_HEAP is at {:?}", &RESERVED_HEAP as *const u8);
}
*offset.lock() = res.offset();
unsafe {
ALLOCATOR.init(&mut RESERVED_HEAP as *mut u8 as usize, 8 * 1024 * 1024);
}
}

pub fn phys_to_virt(addr: u64) -> u64 {
Expand Down

0 comments on commit e227a50

Please sign in to comment.