memory
This commit is contained in:
parent
3222bcbfe2
commit
4574150d2b
|
@ -10,6 +10,11 @@ crate-type = ["staticlib"]
|
|||
spin = "0.9.1"
|
||||
x86_64 = "0.14.10"
|
||||
rlibc = "1.0"
|
||||
multiboot2 = { version = "0.14.0", optional = true }
|
||||
[dependencies.lazy_static]
|
||||
version = "1.4.0"
|
||||
features = ["spin_no_std"]
|
||||
features = ["spin_no_std"]
|
||||
|
||||
[features]
|
||||
default = ["f_multiboot2"]
|
||||
f_multiboot2 = ["dep:multiboot2"]
|
14
Makefile
14
Makefile
|
@ -11,7 +11,7 @@ assembly_source_files := $(wildcard arch/$(arch)/*.asm)
|
|||
assembly_object_files := $(patsubst arch/$(arch)/%.asm, \
|
||||
build/arch/$(arch)/%.o, $(assembly_source_files))
|
||||
|
||||
.PHONY: all clean run iso
|
||||
.PHONY: all clean run iso quick_invalidate
|
||||
|
||||
all: $(final) $(iso)
|
||||
|
||||
|
@ -24,6 +24,11 @@ run: $(final) $(iso)
|
|||
-chardev stdio,id=char0,mux=on,logfile=serial.log,signal=off \
|
||||
-serial chardev:char0 -mon chardev=char0
|
||||
|
||||
quick_invalidate:
|
||||
@echo "quick invalidation"
|
||||
@rm -rf build/arch/$(arch)
|
||||
@rm -rf $(kernel)
|
||||
|
||||
iso: $(iso)
|
||||
|
||||
$(iso): $(final) $(grub_cfg)
|
||||
|
@ -43,9 +48,4 @@ $(kernel):
|
|||
|
||||
build/arch/$(arch)/%.o: arch/$(arch)/%.asm
|
||||
@mkdir -p $(shell dirname $@)
|
||||
@nasm -felf64 $< -o $@
|
||||
|
||||
quick_invalidate:
|
||||
@echo "quick invalidation"
|
||||
@rm -rf build/arch/$(arch)
|
||||
@rm -rf $(kernel)
|
||||
@nasm -felf64 $< -o $@
|
|
@ -8,6 +8,7 @@ bits 32
|
|||
|
||||
start:
|
||||
mov esp, stack_top
|
||||
mov edi, ebx
|
||||
|
||||
call check_multiboot
|
||||
call check_cpuid
|
||||
|
@ -147,7 +148,7 @@ p3_table:
|
|||
p2_table:
|
||||
resb 4096
|
||||
stack_bottom:
|
||||
resb 64
|
||||
resb 4096 * 4 ;; 16 KiB
|
||||
stack_top:
|
||||
|
||||
section .rodata
|
||||
|
|
|
@ -11,3 +11,11 @@ BdsDxe: starting Boot0001 "UEFI QEMU DVD-ROM QM00003 " from PciRoot(0x0)/Pci(0x1
|
|||
|
||||
welcome to wukkOS!
|
||||
(c) 2022 Real Microsoft, LLC
|
||||
initialising memory maps...[OK]
|
||||
memory map:
|
||||
0 - a0000 : Available
|
||||
100000 - 800000 : Available
|
||||
808000 - 80b000 : Available
|
||||
80c000 - 810000 : Available
|
||||
900000 - 78ef000 : Available
|
||||
7bff000 - 7f58000 : Available
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
use alloc::vec::Vec;
|
||||
use crate::KernelArgs;
|
||||
|
||||
#[cfg(feature = "f_multiboot2")]
|
||||
pub mod multiboot2;
|
||||
|
||||
pub enum MemoryType {
|
||||
Available,
|
||||
Reserved,
|
||||
AcpiReclaimable,
|
||||
Nvs,
|
||||
BadMemory,
|
||||
Kernel,
|
||||
Bootloader,
|
||||
Unknown(u32)
|
||||
}
|
||||
|
||||
pub struct MemoryArea {
|
||||
pub start: usize,
|
||||
pub end: usize,
|
||||
pub area_type: MemoryType,
|
||||
}
|
||||
|
||||
pub trait KernelInfo {
|
||||
fn init_from_kernel_args(&mut self, args: KernelArgs);
|
||||
fn get_memory_areas(&self) -> Vec<MemoryArea>;
|
||||
}
|
|
@ -0,0 +1,41 @@
|
|||
extern crate multiboot2;
|
||||
|
||||
use alloc::vec;
|
||||
use alloc::vec::Vec;
|
||||
use multiboot2::{BootInformation, load, MemoryAreaType};
|
||||
use crate::boot::{KernelInfo, MemoryArea, MemoryType};
|
||||
use crate::KernelArgs;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Multiboot2Bootloader {
|
||||
pub boot_info: Option<BootInformation>,
|
||||
}
|
||||
|
||||
impl KernelInfo for Multiboot2Bootloader {
|
||||
fn init_from_kernel_args(&mut self, args: KernelArgs) {
|
||||
let boot_info = unsafe {
|
||||
load(args.multiboot_information_address)
|
||||
}.expect("invalid kernel args!");
|
||||
self.boot_info = Some(boot_info);
|
||||
}
|
||||
|
||||
fn get_memory_areas(&self) -> Vec<MemoryArea> {
|
||||
let mut memory_areas = vec![];
|
||||
let boot_info = self.boot_info.as_ref().unwrap();
|
||||
let memory_map_tag = boot_info.memory_map_tag().expect("memory map tag required but not found!");
|
||||
for area in memory_map_tag.memory_areas() {
|
||||
memory_areas.push(MemoryArea {
|
||||
start: area.start_address() as usize,
|
||||
end: area.end_address() as usize,
|
||||
area_type: match area.typ() {
|
||||
MemoryAreaType::Available => MemoryType::Available,
|
||||
MemoryAreaType::Reserved => MemoryType::Reserved,
|
||||
MemoryAreaType::AcpiAvailable => MemoryType::AcpiReclaimable,
|
||||
MemoryAreaType::ReservedHibernate => MemoryType::Reserved,
|
||||
MemoryAreaType::Defective => MemoryType::BadMemory,
|
||||
}
|
||||
})
|
||||
}
|
||||
memory_areas
|
||||
}
|
||||
}
|
58
src/lib.rs
58
src/lib.rs
|
@ -1,9 +1,12 @@
|
|||
#![feature(abi_x86_interrupt)]
|
||||
#![feature(default_alloc_error_handler)]
|
||||
#![feature(panic_info_message)]
|
||||
#![no_std]
|
||||
#![no_main]
|
||||
|
||||
use alloc::boxed::Box;
|
||||
use alloc::format;
|
||||
use alloc::string::ToString;
|
||||
use alloc::sync::Arc;
|
||||
use allocator::*;
|
||||
|
||||
|
@ -17,6 +20,7 @@ use core::ops::Deref;
|
|||
use lazy_static::lazy_static;
|
||||
use core::panic::PanicInfo;
|
||||
use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame};
|
||||
use crate::boot::KernelInfo;
|
||||
use crate::internals::WhyDoTheyCallItOvenWhenYouOfInTheColdFoodOfOutHotEatTheFood::*;
|
||||
use crate::serial::{Port, potential_serial_ports, terminal_helpers, terminal::ST};
|
||||
|
||||
|
@ -24,6 +28,8 @@ mod font;
|
|||
mod serial;
|
||||
mod internals;
|
||||
mod allocator;
|
||||
mod security;
|
||||
mod boot;
|
||||
|
||||
lazy_static! {
|
||||
static ref IDT: InterruptDescriptorTable = {
|
||||
|
@ -38,10 +44,33 @@ const RAINBOW : [Colour; 6] = [Colour{r:255,g:0,b:0}, Colour{r:255,g:127,b:0}, C
|
|||
|
||||
|
||||
#[panic_handler]
|
||||
fn panic(_info: &PanicInfo) -> ! { loop {} }
|
||||
fn panic(info: &PanicInfo) -> ! {
|
||||
ST.logln("---KERNEL FUCKY WUKKY UWU (panic)---");
|
||||
ST.logln(if let Some(s) = info.payload().downcast_ref::<&str>() {
|
||||
format!("panic payload: {s:?}")
|
||||
} else {
|
||||
format!("no panic payload")
|
||||
}.as_str());
|
||||
ST.logln(if let Some(msg) = info.message() {
|
||||
format!("panic msg: {}", msg.as_str().unwrap_or("no message"))
|
||||
} else {
|
||||
"no message".to_string()
|
||||
}.as_str());
|
||||
ST.logln(if let Some(location) = info.location() {
|
||||
format!("location: file {} line {}", location.file(), location.line())
|
||||
} else {
|
||||
"no location".to_string()
|
||||
}.as_str());
|
||||
loop {}
|
||||
}
|
||||
|
||||
pub struct KernelArgs {
|
||||
#[cfg(feature = "f_multiboot2")]
|
||||
multiboot_information_address: usize
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern fn kernel_main() -> ! {
|
||||
pub extern fn kernel_main(args: KernelArgs) -> ! {
|
||||
// initialise serial
|
||||
let mut serial_ports = serial::init_serial();
|
||||
let mut console_port = None;
|
||||
|
@ -56,11 +85,36 @@ pub extern fn kernel_main() -> ! {
|
|||
ST.init_from_port(*port);
|
||||
}
|
||||
|
||||
let kern_info: Box<dyn boot::KernelInfo> = {
|
||||
#[cfg(feature = "f_multiboot2")]
|
||||
{
|
||||
let mut kern_info = boot::multiboot2::Multiboot2Bootloader::default();
|
||||
kern_info.init_from_kernel_args(args);
|
||||
Box::new(kern_info)
|
||||
}
|
||||
};
|
||||
|
||||
ST.logln("");
|
||||
ST.logln("");
|
||||
ST.logln("");
|
||||
ST.logln("welcome to wukkOS!");
|
||||
ST.logln("(c) 2022 Real Microsoft, LLC");
|
||||
ST.log("initialising memory maps...");
|
||||
let mem_areas = kern_info.get_memory_areas();
|
||||
ST.logln("[OK]");
|
||||
ST.logln("memory map:");
|
||||
for area in mem_areas {
|
||||
ST.logln(format!("{:x} - {:x} : {}", area.start, area.end, match area.area_type {
|
||||
boot::MemoryType::Available => "Available",
|
||||
boot::MemoryType::Reserved => "Reserved",
|
||||
boot::MemoryType::AcpiReclaimable => "ACPI Reclaimable",
|
||||
boot::MemoryType::Nvs => "NVS",
|
||||
boot::MemoryType::BadMemory => "Bad Memory",
|
||||
boot::MemoryType::Kernel => "Kernel",
|
||||
boot::MemoryType::Bootloader => "Bootloader",
|
||||
boot::MemoryType::Unknown(_) => "Unknown"
|
||||
}).as_str());
|
||||
}
|
||||
|
||||
loop {}
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
pub mod stack_smashing_protection;
|
|
@ -0,0 +1,8 @@
|
|||
pub const STACK_CHK_GUARD: usize = usize::MAX;
|
||||
|
||||
pub const STACK_CHK_PTR: *const usize = &STACK_CHK_GUARD;
|
||||
|
||||
pub extern "C" fn __stack_chk_fail() -> ! {
|
||||
panic!("stack fucking or uh smashing detected!");
|
||||
loop {}
|
||||
}
|
Loading…
Reference in New Issue