acpi
This commit is contained in:
12
nel_os_bootloader/Cargo.lock
generated
12
nel_os_bootloader/Cargo.lock
generated
@ -2,6 +2,17 @@
|
|||||||
# It is not intended for manual editing.
|
# It is not intended for manual editing.
|
||||||
version = 4
|
version = 4
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "acpi"
|
||||||
|
version = "5.2.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "94476c7ef97af4c4d998b3f422c1b01d5211aad57c80ed200baf148d1f1efab6"
|
||||||
|
dependencies = [
|
||||||
|
"bit_field",
|
||||||
|
"bitflags 2.9.1",
|
||||||
|
"log",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "bit_field"
|
name = "bit_field"
|
||||||
version = "0.10.2"
|
version = "0.10.2"
|
||||||
@ -47,6 +58,7 @@ checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
|||||||
name = "nel_os_bootloader"
|
name = "nel_os_bootloader"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"acpi",
|
||||||
"goblin",
|
"goblin",
|
||||||
"log",
|
"log",
|
||||||
"nel_os_common",
|
"nel_os_common",
|
||||||
|
@ -9,3 +9,4 @@ log = "0.4.27"
|
|||||||
uefi = { version = "0.35.0", features = ["logger", "panic_handler", "alloc"] }
|
uefi = { version = "0.35.0", features = ["logger", "panic_handler", "alloc"] }
|
||||||
x86 = "0.52.0"
|
x86 = "0.52.0"
|
||||||
nel_os_common = { path = "../nel_os_common" }
|
nel_os_common = { path = "../nel_os_common" }
|
||||||
|
acpi = "5.2.0"
|
||||||
|
@ -14,4 +14,5 @@ qemu-system-x86_64 -enable-kvm \
|
|||||||
-cdrom nel_os.iso \
|
-cdrom nel_os.iso \
|
||||||
-boot d \
|
-boot d \
|
||||||
-cpu host \
|
-cpu host \
|
||||||
|
-smp 1 \
|
||||||
-s
|
-s
|
||||||
|
26
nel_os_kernel/src/acpi.rs
Normal file
26
nel_os_kernel/src/acpi.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
use core::ptr::NonNull;
|
||||||
|
|
||||||
|
use acpi::{AcpiHandler, PhysicalMapping};
|
||||||
|
|
||||||
|
#[derive(Clone)]
|
||||||
|
pub struct KernelAcpiHandler;
|
||||||
|
|
||||||
|
impl AcpiHandler for KernelAcpiHandler {
|
||||||
|
unsafe fn map_physical_region<T>(
|
||||||
|
&self,
|
||||||
|
physical_address: usize,
|
||||||
|
size: usize,
|
||||||
|
) -> acpi::PhysicalMapping<Self, T> {
|
||||||
|
unsafe {
|
||||||
|
PhysicalMapping::new(
|
||||||
|
physical_address,
|
||||||
|
NonNull::new(physical_address as *mut _).unwrap(),
|
||||||
|
size,
|
||||||
|
size,
|
||||||
|
self.clone(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn unmap_physical_region<T>(_region: &acpi::PhysicalMapping<Self, T>) {}
|
||||||
|
}
|
@ -1,4 +1,5 @@
|
|||||||
use ab_glyph::{Font, FontRef, ScaleFont};
|
use ab_glyph::{Font, FontRef, ScaleFont};
|
||||||
|
use alloc::vec::Vec;
|
||||||
use lazy_static::lazy_static;
|
use lazy_static::lazy_static;
|
||||||
use nel_os_common::gop::{FrameBuffer as RawFrameBuffer, PixelFormat as RawPixelFormat};
|
use nel_os_common::gop::{FrameBuffer as RawFrameBuffer, PixelFormat as RawPixelFormat};
|
||||||
use spin::Mutex;
|
use spin::Mutex;
|
||||||
@ -22,14 +23,20 @@ pub struct FrameBuffer {
|
|||||||
|
|
||||||
pub pixel_format: PixelFormat,
|
pub pixel_format: PixelFormat,
|
||||||
|
|
||||||
|
pub background_color: (u8, u8, u8),
|
||||||
|
|
||||||
pub text_cursor: (usize, usize),
|
pub text_cursor: (usize, usize),
|
||||||
|
|
||||||
|
pub text_buffer: Vec<Vec<char>>,
|
||||||
|
pub textscreen_width: usize,
|
||||||
|
pub textscreen_height: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
unsafe impl Send for FrameBuffer {}
|
unsafe impl Send for FrameBuffer {}
|
||||||
unsafe impl Sync for FrameBuffer {}
|
unsafe impl Sync for FrameBuffer {}
|
||||||
|
|
||||||
impl FrameBuffer {
|
impl FrameBuffer {
|
||||||
pub fn from_raw_buffer(raw_buffer: &RawFrameBuffer) -> Self {
|
pub fn from_raw_buffer(raw_buffer: &RawFrameBuffer, background_color: (u8, u8, u8)) -> Self {
|
||||||
Self {
|
Self {
|
||||||
frame_buffer: raw_buffer.frame_buffer,
|
frame_buffer: raw_buffer.frame_buffer,
|
||||||
width: raw_buffer.width,
|
width: raw_buffer.width,
|
||||||
@ -40,7 +47,11 @@ impl FrameBuffer {
|
|||||||
RawPixelFormat::Rgb => PixelFormat::Rgb,
|
RawPixelFormat::Rgb => PixelFormat::Rgb,
|
||||||
RawPixelFormat::Bgr => PixelFormat::Bgr,
|
RawPixelFormat::Bgr => PixelFormat::Bgr,
|
||||||
},
|
},
|
||||||
|
background_color,
|
||||||
text_cursor: (0, 0),
|
text_cursor: (0, 0),
|
||||||
|
text_buffer: Vec::new(),
|
||||||
|
textscreen_width: raw_buffer.width / 8,
|
||||||
|
textscreen_height: raw_buffer.height / 14,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -76,39 +87,47 @@ impl FrameBuffer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_text(&mut self, text: &str) {
|
pub fn clear(&self) {
|
||||||
let (mut x, mut y) = self.text_cursor;
|
let (r, g, b) = self.background_color;
|
||||||
|
for y in 0..self.height {
|
||||||
for c in text.chars() {
|
for x in 0..self.width {
|
||||||
if c == '\n' {
|
self.draw_pixel(r, g, b, x, y);
|
||||||
x = 0;
|
|
||||||
y += 14;
|
|
||||||
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
self.draw_char(c, x, y);
|
|
||||||
x += 8;
|
|
||||||
if x + 8 > self.width {
|
|
||||||
x = 0;
|
|
||||||
y += 14;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
self.text_cursor = (x, y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn print_char(&mut self, c: char) {
|
pub fn update_textscreen(&mut self) {
|
||||||
let (x, y) = self.text_cursor;
|
self.clear();
|
||||||
|
for (y, line) in self.text_buffer.iter().enumerate() {
|
||||||
self.draw_char(c, x, y);
|
let mut x = 0;
|
||||||
self.text_cursor.0 += 8;
|
for &c in line {
|
||||||
if self.text_cursor.0 >= self.width {
|
self.draw_char(c, x, y * 14);
|
||||||
self.text_cursor.0 = 0;
|
x += 8;
|
||||||
self.text_cursor.1 += 14;
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn add_text_line(&mut self, text: &str) {
|
||||||
|
if self.text_buffer.len() >= self.textscreen_height {
|
||||||
|
self.text_buffer.remove(0);
|
||||||
|
}
|
||||||
|
self.text_buffer.push(text.chars().collect());
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clear_text(&mut self) {
|
||||||
|
self.text_cursor = (0, 0);
|
||||||
|
self.text_buffer.clear();
|
||||||
|
self.clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn print_text(&mut self, text: &str) {
|
||||||
|
let lines = text.lines();
|
||||||
|
for line in lines {
|
||||||
|
self.add_text_line(line);
|
||||||
|
}
|
||||||
|
self.update_textscreen();
|
||||||
|
}
|
||||||
|
|
||||||
pub fn draw_char(&self, c: char, x: usize, y: usize) {
|
pub fn draw_char(&self, c: char, x: usize, y: usize) {
|
||||||
let font = FontRef::try_from_slice(FONT).unwrap();
|
let font = FontRef::try_from_slice(FONT).unwrap();
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
|
pub mod acpi;
|
||||||
pub mod constant;
|
pub mod constant;
|
||||||
pub mod cpuid;
|
pub mod cpuid;
|
||||||
pub mod graphics;
|
pub mod graphics;
|
||||||
@ -16,9 +17,11 @@ use core::arch::asm;
|
|||||||
use core::panic::PanicInfo;
|
use core::panic::PanicInfo;
|
||||||
use core::ptr::addr_of;
|
use core::ptr::addr_of;
|
||||||
|
|
||||||
|
use ::acpi::AcpiTables;
|
||||||
use x86_64::{registers::control::Cr3, structures::paging::OffsetPageTable, VirtAddr};
|
use x86_64::{registers::control::Cr3, structures::paging::OffsetPageTable, VirtAddr};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
acpi::KernelAcpiHandler,
|
||||||
constant::{KERNEL_STACK_SIZE, PKG_VERSION},
|
constant::{KERNEL_STACK_SIZE, PKG_VERSION},
|
||||||
graphics::{FrameBuffer, FRAME_BUFFER},
|
graphics::{FrameBuffer, FRAME_BUFFER},
|
||||||
memory::{allocator, memory::BitmapMemoryTable, paging},
|
memory::{allocator, memory::BitmapMemoryTable, paging},
|
||||||
@ -112,13 +115,8 @@ pub extern "sysv64" fn main(boot_info: &nel_os_common::BootInfo) {
|
|||||||
|
|
||||||
allocator::init_heap(&mut mapper, &mut bitmap_table).unwrap();
|
allocator::init_heap(&mut mapper, &mut bitmap_table).unwrap();
|
||||||
|
|
||||||
let frame_buffer = FrameBuffer::from_raw_buffer(&boot_info.frame_buffer);
|
let frame_buffer = FrameBuffer::from_raw_buffer(&boot_info.frame_buffer, (64, 64, 64));
|
||||||
|
frame_buffer.clear();
|
||||||
for x in 0..frame_buffer.width {
|
|
||||||
for y in 0..frame_buffer.height {
|
|
||||||
frame_buffer.draw_pixel(64, 64, 64, x, y);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
FRAME_BUFFER.lock().replace(frame_buffer);
|
FRAME_BUFFER.lock().replace(frame_buffer);
|
||||||
|
|
||||||
@ -141,11 +139,13 @@ pub extern "sysv64" fn main(boot_info: &nel_os_common::BootInfo) {
|
|||||||
usable_frame as f64 * 4. / 1024. / 1024.
|
usable_frame as f64 * 4. / 1024. / 1024.
|
||||||
);
|
);
|
||||||
|
|
||||||
x86_64::instructions::interrupts::int3();
|
info!("RSDP: {:#x}", boot_info.rsdp);
|
||||||
|
|
||||||
unsafe {
|
let acpi_tables =
|
||||||
*(0xffdeadbeaf as *mut u8) = 0x43;
|
unsafe { AcpiTables::from_rsdp(KernelAcpiHandler, boot_info.rsdp as usize) }.unwrap();
|
||||||
}
|
let platform_info = acpi_tables.platform_info().unwrap();
|
||||||
|
let processor_info = platform_info.processor_info;
|
||||||
|
info!("Processor info: {:#x?}", processor_info);
|
||||||
|
|
||||||
hlt_loop();
|
hlt_loop();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user