Compare commits
2 Commits
477781c3f5
...
1bd0c60b93
Author | SHA1 | Date | |
---|---|---|---|
1bd0c60b93 | |||
f569497776 |
@ -14,6 +14,7 @@ lzma-rs = { git = "https://github.com/glaeqen/lzma-no-std-rs/", version = "0.2.0
|
||||
once_cell = { version = "1.20.3", default-features = false, features = ["alloc", "critical-section"] }
|
||||
spin = "0.10.0"
|
||||
talc = "4.4.2"
|
||||
x86_64 = "0.15.2"
|
||||
|
||||
[target.'cfg(target_arch = "x86_64")'.dependencies]
|
||||
x86_64 = "0.15.2"
|
||||
|
@ -2,10 +2,8 @@ use x86_64::structures::gdt::{Descriptor, GlobalDescriptorTable};
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use super::asm::*;
|
||||
|
||||
use crate::log::{LOGGER, LogLevel};
|
||||
use crate::{format, log_trace};
|
||||
use crate::{critical_section, format, log_trace};
|
||||
|
||||
lazy_static! {
|
||||
pub static ref GDT: GlobalDescriptorTable = {
|
||||
@ -15,16 +13,13 @@ lazy_static! {
|
||||
};
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub fn setup_gdt() {
|
||||
unsafe {
|
||||
interrupt_disable();
|
||||
}
|
||||
GDT.load();
|
||||
log_trace!(
|
||||
"GDT: Setting up global descriptor table at 0x{:x}",
|
||||
core::ptr::addr_of!(GDT) as usize
|
||||
);
|
||||
unsafe {
|
||||
interrupt_enable();
|
||||
}
|
||||
critical_section!({
|
||||
GDT.load();
|
||||
log_trace!(
|
||||
"GDT: Setting up global descriptor table at 0x{:x}",
|
||||
core::ptr::addr_of!(GDT) as usize
|
||||
);
|
||||
});
|
||||
}
|
||||
|
19
src/kernel/arch/x86_64/interrupts.rs
Normal file
19
src/kernel/arch/x86_64/interrupts.rs
Normal file
@ -0,0 +1,19 @@
|
||||
// Copyright (c) 2025 shibedrill
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use x86_64::structures::idt::*;
|
||||
|
||||
use crate::format;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref IDT: InterruptDescriptorTable = {
|
||||
let mut idt = InterruptDescriptorTable::new();
|
||||
idt.double_fault.set_handler_fn(double_fault);
|
||||
idt
|
||||
};
|
||||
}
|
||||
|
||||
extern "x86-interrupt" fn double_fault(info: InterruptStackFrame, _: u64) -> ! {
|
||||
crate::interrupt::double_fault(&format!("{info:#?}"));
|
||||
}
|
@ -4,4 +4,5 @@
|
||||
pub mod acpi;
|
||||
pub mod asm;
|
||||
pub mod gdt;
|
||||
pub mod interrupts;
|
||||
pub mod serial;
|
||||
|
@ -1,6 +1,9 @@
|
||||
// Copyright (c) 2025 shibedrill
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
pub mod modules;
|
||||
pub mod params;
|
||||
|
||||
use limine::{BaseRevision, request::*};
|
||||
|
||||
#[used]
|
15
src/kernel/boot/modules.rs
Normal file
15
src/kernel/boot/modules.rs
Normal file
@ -0,0 +1,15 @@
|
||||
// Copyright (c) 2025 shibedrill
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
use limine::response::ModuleResponse;
|
||||
|
||||
use crate::boot::MODULE_REQUEST;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref MODULE_RESPONSE: &'static ModuleResponse = MODULE_REQUEST
|
||||
.get_response()
|
||||
.expect("Bootloader did not return kernel modules");
|
||||
}
|
||||
|
||||
// TODO: make initramfs a lazy static somehow?
|
@ -1,12 +1,12 @@
|
||||
// Copyright (c) 2025 shibedrill
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
use crate::boot::FILE_REQUEST;
|
||||
use crate::memory::alloc;
|
||||
use alloc::string::String;
|
||||
use alloc::vec::Vec;
|
||||
use lazy_static::lazy_static;
|
||||
use limine::response::ExecutableFileResponse;
|
||||
use crate::boot::FILE_REQUEST;
|
||||
|
||||
lazy_static! {
|
||||
pub static ref EXECUTABLE_FILE_RESPONSE: &'static ExecutableFileResponse = FILE_REQUEST
|
@ -1,3 +1,6 @@
|
||||
// Copyright (c) 2025 shibedrill
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
use crate::format;
|
||||
use crate::log::LogLevel;
|
||||
use crate::memory::alloc::string::String;
|
||||
|
@ -1,3 +1,6 @@
|
||||
// Copyright (c) 2025 shibedrill
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
use fdt::*;
|
||||
use lazy_static::lazy_static;
|
||||
use limine::response::{DeviceTreeBlobResponse, RsdpResponse};
|
||||
@ -8,12 +11,24 @@ use crate::{format, log_info, log_trace, log_warning};
|
||||
|
||||
lazy_static! {
|
||||
pub static ref DTB: Option<&'static DeviceTreeBlobResponse> = match DTB_REQUEST.get_response() {
|
||||
Some(resp) => { log_info!("Device: Got DTB pointer"); Some(resp) },
|
||||
None => { log_warning!("Device: Did not get DTB pointer"); None },
|
||||
Some(resp) => {
|
||||
log_info!("Device: Got DTB pointer");
|
||||
Some(resp)
|
||||
}
|
||||
None => {
|
||||
log_warning!("Device: Did not get DTB pointer");
|
||||
None
|
||||
}
|
||||
};
|
||||
pub static ref RSDP: Option<&'static RsdpResponse> = match RSDP_REQUEST.get_response() {
|
||||
Some(resp) => { log_info!("Device: Got RSDP pointer"); Some(resp) },
|
||||
None => { log_warning!("Device: Did not get RSDP pointer, ACPI unavailable"); None },
|
||||
Some(resp) => {
|
||||
log_info!("Device: Got RSDP pointer");
|
||||
Some(resp)
|
||||
}
|
||||
None => {
|
||||
log_warning!("Device: Did not get RSDP pointer, ACPI unavailable");
|
||||
None
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
4
src/kernel/interrupt/mod.rs
Normal file
4
src/kernel/interrupt/mod.rs
Normal file
@ -0,0 +1,4 @@
|
||||
|
||||
pub fn double_fault(info: &str) -> ! {
|
||||
panic!("Double fault: {}", info);
|
||||
}
|
@ -3,27 +3,26 @@
|
||||
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
#![feature(cfg_match)]
|
||||
#![feature(allocator_api)]
|
||||
#![feature(abi_x86_interrupt)]
|
||||
|
||||
mod arch;
|
||||
mod boot;
|
||||
mod constants;
|
||||
mod device;
|
||||
mod interrupt;
|
||||
#[macro_use]
|
||||
mod log;
|
||||
mod memory;
|
||||
mod panic;
|
||||
mod params;
|
||||
mod process;
|
||||
mod resources;
|
||||
#[macro_use]
|
||||
mod util;
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use arch::x86_64::gdt;
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use arch::x86_64::serial::Serialport;
|
||||
|
||||
use boot::*;
|
||||
use boot::{modules::*, params, *};
|
||||
use constants::*;
|
||||
use log::*;
|
||||
use memory::alloc::{format, string::*, vec};
|
||||
@ -97,16 +96,9 @@ unsafe extern "C" fn main() -> ! {
|
||||
}
|
||||
}
|
||||
|
||||
let module_response = MODULE_REQUEST
|
||||
.get_response()
|
||||
.expect("Bootloader did not return kernel modules");
|
||||
log_info!(
|
||||
"Boot: {} kernel modules found",
|
||||
module_response.modules().len()
|
||||
);
|
||||
if !module_response.modules().is_empty() {
|
||||
if !MODULE_RESPONSE.modules().is_empty() {
|
||||
let mut log_msg: String = String::from("Boot: Kernel modules list:\n");
|
||||
for module in module_response.modules() {
|
||||
for module in MODULE_RESPONSE.modules() {
|
||||
log_msg.push_str(&format!(
|
||||
"\t\t{}",
|
||||
String::from_utf8_lossy(module.path().to_bytes())
|
||||
@ -126,7 +118,7 @@ unsafe extern "C" fn main() -> ! {
|
||||
log_trace!("Boot: initramfs path requested: {irfs_path}");
|
||||
let _initramfs = {
|
||||
let mut result: Option<&File> = None;
|
||||
for file in module_response.modules() {
|
||||
for file in MODULE_RESPONSE.modules() {
|
||||
if file.path().to_string_lossy() == irfs_path {
|
||||
result = Some(file);
|
||||
log_info!("Boot: initramfs found");
|
||||
@ -137,7 +129,9 @@ unsafe extern "C" fn main() -> ! {
|
||||
.expect("initramfs not found in modules list");
|
||||
|
||||
// Panic if this is absent. It's needed to set up the GDT and paging
|
||||
let mmap_response = MEMMAP_REQUEST.get_response().expect("Bootloader did not supply memory map");
|
||||
let mmap_response = MEMMAP_REQUEST
|
||||
.get_response()
|
||||
.expect("Bootloader did not supply memory map");
|
||||
log_info!("Boot: Memory map received");
|
||||
if !mmap_response.entries().is_empty() {
|
||||
let mut log_msg: String = String::from("Boot: Memory map:");
|
||||
@ -199,8 +193,15 @@ unsafe extern "C" fn main() -> ! {
|
||||
panic!("Memory map contains no entries");
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
gdt::setup_gdt();
|
||||
//#[cfg(target_arch = "x86_64")]
|
||||
//gdt::setup_gdt();
|
||||
|
||||
arch::x86_64::interrupts::IDT.load();
|
||||
unsafe {
|
||||
*(0xdeadbeef as *mut u8) = 42;
|
||||
};
|
||||
|
||||
panic!("Bailing");
|
||||
|
||||
#[allow(unreachable_code)]
|
||||
loop {
|
||||
|
@ -13,7 +13,7 @@ pub fn panic(info: &PanicInfo) -> ! {
|
||||
log_critical!(
|
||||
"Panic in {}: {}",
|
||||
info.location().unwrap(),
|
||||
info.message().as_str().unwrap_or("missing panic message"),
|
||||
info.message()
|
||||
);
|
||||
loop {
|
||||
unsafe {
|
||||
|
@ -1,3 +1,6 @@
|
||||
// Copyright (c) 2025 shibedrill
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#![allow(unused_imports, dead_code)]
|
||||
|
||||
use enumflags2::{BitFlags, bitflags, make_bitflags};
|
||||
|
@ -1,2 +0,0 @@
|
||||
// Copyright (c) 2025 shibedrill
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
9
src/kernel/util.rs
Normal file
9
src/kernel/util.rs
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! critical_section {
|
||||
($b:block) => {
|
||||
unsafe { $crate::arch::asm::interrupt_disable(); }
|
||||
$b
|
||||
unsafe { $crate::arch::asm::interrupt_enable(); }
|
||||
};
|
||||
}
|
Loading…
Reference in New Issue
Block a user