diff --git a/.gitignore b/.gitignore index 17bb528..bb571f8 100644 --- a/.gitignore +++ b/.gitignore @@ -37,3 +37,4 @@ Cargo.lock /boot.o /build/ /OVMF-pure-efi.fd +/isodir \ No newline at end of file diff --git a/Cargo.toml b/Cargo.toml index a3e9061..06f8013 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,15 +3,12 @@ name = "wukkOS" version = "0.1.0" edition = "2021" -[lib] -crate-type = ["staticlib"] - [dependencies] spin = "0.9.1" x86_64 = "0.14.10" x86 = "0.52.0" rlibc = "1.0" -multiboot2 = { version = "0.14.0", optional = true } +limine = { version = "0.1.9", optional = true } acpi = { version = "4.1.1", optional = true } linked_list_allocator = { version = "0.9.0", optional = true } [dependencies.lazy_static] @@ -19,7 +16,7 @@ version = "1.4.0" features = ["spin_no_std"] [features] -default = ["f_multiboot2", "f_ll_alloc", "f_debug_verbose"] +default = ["f_limine", "f_ll_alloc", "f_debug_verbose"] f_debug_verbose = [] -f_multiboot2 = ["dep:multiboot2", "dep:acpi"] +f_limine = ["dep:limine", "dep:acpi"] f_ll_alloc = ["dep:linked_list_allocator"] \ No newline at end of file diff --git a/Makefile b/Makefile index 5a53afc..6e17c0e 100644 --- a/Makefile +++ b/Makefile @@ -1,16 +1,14 @@ arch ?= x86_64 -kernel := target/$(arch)-custom/debug/libwukkOS.a +kernel := target/$(arch)-custom/debug/wukkOS iso := build/arch/$(arch)/wukkOS.iso target ?= $(arch)-custom final := build/arch/$(arch)/wukkOS.bin efi_bios := build/arch/$(arch)/OVMF-pure-efi.fd -gcc := x86_64-elf-gcc -ld := x86_64-elf-ld -# set grub-mkrescue to either $GRUB_MKRESCUE or /usr/bin/grub-mkrescue -grub-mkrescue ?= $(shell which grub-mkrescue) +gcc ?= gcc +ld ?= ld linker_script := arch/$(arch)/linker.ld -grub_cfg := arch/$(arch)/grub.cfg +bootloader_cfg := arch/$(arch)/limine.cfg assembly_source_files := $(wildcard arch/$(arch)/*.asm) assembly_object_files := $(patsubst arch/$(arch)/%.asm, \ build/arch/$(arch)/%.o, $(assembly_source_files)) @@ -26,7 +24,7 @@ clean: @rm -rf build run: $(final) $(iso) - @qemu-system-$(arch) -bios $(efi_bios) -cdrom $(iso) \ + @qemu-system-$(arch) -bios $(efi_bios) -cdrom $(iso) -d int -D qemulog.log \ -chardev stdio,id=char0,mux=on,logfile=serial.log,signal=off \ -serial chardev:char0 -mon chardev=char0 -m 512M @@ -39,18 +37,26 @@ iso: $(iso) $(iso): $(final) $(grub_cfg) @cp OVMF-pure-efi.fd build/arch/$(arch)/OVMF-pure-efi.fd # TODO! remove this, it's only for testing and i don't think we can distribute it - @mkdir -p isodir/boot/grub + @mkdir -p isodir/boot @cp $(final) isodir/boot/wukkOS.bin - @cp $(grub_cfg) isodir/boot/grub/grub.cfg - @$(grub-mkrescue) -o $(iso) isodir + @cp $(bootloader_cfg) isodir/boot/limine.cfg + @cp byob/limine.sys byob/limine-cd.bin byob/limine-cd-efi.bin isodir/boot/ + @xorriso -as mkisofs -b boot/limine-cd.bin \ + -no-emul-boot -boot-load-size 4 -boot-info-table \ + --efi-boot boot/limine-cd-efi.bin \ + -efi-boot-part --efi-boot-image --protective-msdos-label \ + isodir -o $(iso) @rm -rf isodir + @byob/limine-deploy $(iso) $(final): $(kernel) $(linker_script) $(assembly_object_files) - @$(ld) -n -T $(linker_script) -o $(final) $(assembly_object_files) $(kernel) \ - --gc-sections -z noexecstack + @mkdir -p $(shell dirname $@) + @cp $(kernel) $(final) + #@$(ld) -n -T $(linker_script) -o $(final) $(kernel) \ + # --gc-sections $(kernel): - @RUST_TARGET_PATH=$(shell pwd) xargo build --target $(target) -Zbuild-std=core,alloc --features "f_multiboot2" + @RUST_TARGET_PATH=$(shell pwd) xargo build --target $(target) -Zbuild-std=core,alloc --features "f_limine" build/arch/$(arch)/%.o: arch/$(arch)/%.asm @mkdir -p $(shell dirname $@) diff --git a/arch/x86_64/boot.asm b/arch/x86_64/boot.asm deleted file mode 100644 index bb20481..0000000 --- a/arch/x86_64/boot.asm +++ /dev/null @@ -1,161 +0,0 @@ -global start -extern long_mode_start - -section .text -bits 32 - -;; basic boilerplate stuff from blog_os, expect to be changed - -start: - mov esp, stack_top - mov edi, ebx - - call check_multiboot - call check_cpuid - call check_long_mode - - call setup_page_tables - call enable_paging - - lgdt [gdt64.pointer] - - jmp gdt64.code:long_mode_start - - hlt -check_multiboot: - cmp eax, 0x36d76289 - jne .no_multiboot - ret -.no_multiboot: - mov al, "0" - jmp error -check_cpuid: - ; Check if CPUID is supported by attempting to flip the ID bit (bit 21) - ; in the FLAGS register. If we can flip it, CPUID is available. - - ; Copy FLAGS in to EAX via stack - pushfd - pop eax - - ; Copy to ECX as well for comparing later on - mov ecx, eax - - ; Flip the ID bit - xor eax, 1 << 21 - - ; Copy EAX to FLAGS via the stack - push eax - popfd - - ; Copy FLAGS back to EAX (with the flipped bit if CPUID is supported) - pushfd - pop eax - - ; Restore FLAGS from the old version stored in ECX (i.e. flipping the - ; ID bit back if it was ever flipped). - push ecx - popfd - - ; Compare EAX and ECX. If they are equal then that means the bit - ; wasn't flipped, and CPUID isn't supported. - cmp eax, ecx - je .no_cpuid - ret -.no_cpuid: - mov al, "1" - jmp error -check_long_mode: - ; test if extended processor info in available - mov eax, 0x80000000 ; implicit argument for cpuid - cpuid ; get highest supported argument - cmp eax, 0x80000001 ; it needs to be at least 0x80000001 - jb .no_long_mode ; if it's less, the CPU is too old for long mode - - ; use extended info to test if long mode is available - mov eax, 0x80000001 ; argument for extended processor info - cpuid ; returns various feature bits in ecx and edx - test edx, 1 << 29 ; test if the LM-bit is set in the D-register - jz .no_long_mode ; If it's not set, there is no long mode - ret -.no_long_mode: - mov al, "2" - jmp error -setup_page_tables: - ; map first P4 entry to P3 table - mov eax, p3_table - or eax, 0b11 ; present + writable - mov [p4_table], eax - - ; map first P3 entry to P2 table - mov eax, p2_table - or eax, 0b11 ; present + writable - mov [p3_table], eax - - ; map each P2 entry to a huge 2MiB page - mov ecx, 0 ; counter variable - -.map_p2_table: - ; map ecx-th P2 entry to a huge page that starts at address 2MiB*ecx - mov eax, 0x200000 ; 2MiB - mul ecx ; start address of ecx-th page - or eax, 0b10000011 ; present + writable + huge - mov [p2_table + ecx * 8], eax ; map ecx-th entry - - inc ecx ; increase counter - cmp ecx, 512 ; if counter == 512, the whole P2 table is mapped - jne .map_p2_table ; else map the next entry - - ret - -enable_paging: - ; load P4 to cr3 register (cpu uses this to access the P4 table) - mov eax, p4_table - mov cr3, eax - - ; enable PAE-flag in cr4 (Physical Address Extension) - mov eax, cr4 - or eax, 1 << 5 - mov cr4, eax - - ; set the long mode bit in the EFER MSR (model specific register) - mov ecx, 0xC0000080 - rdmsr - or eax, 1 << 8 - wrmsr - - ; enable paging in the cr0 register - mov eax, cr0 - or eax, 1 << 31 - mov cr0, eax - - ret - -; Prints `ERR: ` and the given error code to screen and hangs. -; parameter: error code (in ascii) in al -error: - mov dword [0xb8000], 0x4f524f45 - mov dword [0xb8004], 0x4f3a4f52 - mov dword [0xb8008], 0x4f204f20 - mov byte [0xb800a], al - hlt - -section .bss -align 4096 -p4_table: - resb 4096 -p3_table: - resb 4096 -p2_table: - resb 4096 -stack_bottom: - resb 4096 * 4 ;; 16 KiB -stack_top: - -section .rodata -gdt64: - dq 0 ; zero entry -.code: equ $ - gdt64 ; new - dq (1<<43) | (1<<44) | (1<<47) | (1<<53) ; code segment -.pointer: - dw $ - gdt64 - 1 - dq gdt64 \ No newline at end of file diff --git a/arch/x86_64/grub.cfg b/arch/x86_64/grub.cfg deleted file mode 100644 index a1b062b..0000000 --- a/arch/x86_64/grub.cfg +++ /dev/null @@ -1,7 +0,0 @@ -set timeout=0 -set default=0 - -menuentry "wukkOS basic kernel" { - multiboot2 /boot/wukkOS.bin - boot -} \ No newline at end of file diff --git a/arch/x86_64/limine.cfg b/arch/x86_64/limine.cfg new file mode 100644 index 0000000..2af48f4 --- /dev/null +++ b/arch/x86_64/limine.cfg @@ -0,0 +1,5 @@ +TIMEOUT=0 + +:wukkOS + PROTOCOL=limine + KERNEL_PATH=boot:///boot/wukkOS.bin \ No newline at end of file diff --git a/arch/x86_64/linker.ld b/arch/x86_64/linker.ld index 72e7d29..459344d 100644 --- a/arch/x86_64/linker.ld +++ b/arch/x86_64/linker.ld @@ -1,26 +1,48 @@ -ENTRY(start) +/* Tell the linker that we want an x86_64 ELF64 output file */ +OUTPUT_FORMAT(elf64-x86-64) +OUTPUT_ARCH(i386:x86-64) -SECTIONS { - . = 1M; +/* We want the symbol `x86_64_barebones_main` to be our entry point */ +ENTRY(kernel_main) - .boot : - { - /* ensure that the multiboot header is at the beginning */ - KEEP(*(.multiboot_header)) - } +/* Define the program headers we want so the bootloader gives us the right */ +/* MMU permissions */ +PHDRS +{ + null PT_NULL FLAGS(0) ; /* Null segment */ + text PT_LOAD FLAGS((1 << 0) | (1 << 2)) ; /* Execute + Read */ + rodata PT_LOAD FLAGS((1 << 2)) ; /* Read only */ + data PT_LOAD FLAGS((1 << 1) | (1 << 2)) ; /* Write + Read */ +} - .text : - { +SECTIONS +{ + /* We wanna be placed in the topmost 2GiB of the address space, for optimisations */ + /* and because that is what the Limine spec mandates. */ + /* Any address in this region will do, but often 0xffffffff80000000 is chosen as */ + /* that is the beginning of the region. */ + . = 0xffffffff80000000; + + .text : { *(.text .text.*) - } + } :text - .rodata : - { + /* Move to the next memory page for .rodata */ + . += CONSTANT(MAXPAGESIZE); + + .rodata : { *(.rodata .rodata.*) - } + } :rodata - .data.rel.ro : - { - *(.data.rel.ro.local*) *(.data.rel.ro .data.rel.ro.*) - } + /* Move to the next memory page for .data */ + . += CONSTANT(MAXPAGESIZE); + + .data : { + *(.data .data.*) + } :data + + .bss : { + *(COMMON) + *(.bss .bss.*) + } :data } \ No newline at end of file diff --git a/arch/x86_64/longmodestart.asm b/arch/x86_64/longmodestart.asm deleted file mode 100644 index 9c2dc04..0000000 --- a/arch/x86_64/longmodestart.asm +++ /dev/null @@ -1,17 +0,0 @@ -global long_mode_start -extern kernel_main - -section .text -bits 64 -long_mode_start: - mov ax, 0x00 - mov ss, ax - mov ds, ax - mov es, ax - mov fs, ax - mov gs, ax - - extern kernel_main - call kernel_main - - hlt \ No newline at end of file diff --git a/arch/x86_64/multiboot_header.asm b/arch/x86_64/multiboot_header.asm deleted file mode 100644 index e855dfe..0000000 --- a/arch/x86_64/multiboot_header.asm +++ /dev/null @@ -1,16 +0,0 @@ -section .multiboot_header -header_start: - align 4 - ; multiboot 2 magic - dd 0xe85250d6 - dd 0x00000000 - dd header_end - header_start - ; checksum - dd 0x100000000 - (0xe85250d6 + 0x00000000 + (header_end - header_start)) - - ; required end tag - dw 0 ; type - dw 0 ; flags - dd 8 ; size - -header_end: \ No newline at end of file diff --git a/byob/.gitignore b/byob/.gitignore new file mode 100644 index 0000000..c219351 --- /dev/null +++ b/byob/.gitignore @@ -0,0 +1,5 @@ +# limine binaries +limine.sys +limine-cd.bin +limine-cd-efi.bin +limine-deploy \ No newline at end of file diff --git a/byob/README.md b/byob/README.md new file mode 100644 index 0000000..5d33010 --- /dev/null +++ b/byob/README.md @@ -0,0 +1,9 @@ +# bring your own bootloader! +wukkOS is currently reliant on limine, and it is also currently required for you to +provide your own binaries for it. those binaries should be placed in this directory, +and the Makefile will copy them into the iso. +currently the binaries are: +- limine.sys +- limine-cd.bin +- limine-cd-efi.bin +- limine-deploy (should be for your current system) \ No newline at end of file diff --git a/serial.log b/serial.log index 38a858c..9129c8d 100644 --- a/serial.log +++ b/serial.log @@ -1,10 +1,6 @@ -[=3hBdsDxe: loading Boot0001 "UEFI QEMU DVD-ROM QM00003 " from PciRoot(0x0)/Pci(0x1,0x1)/Ata(Secondary,Master,0x0) +[=3h[=3h[=3h[=3hBdsDxe: loading Boot0001 "UEFI QEMU DVD-ROM QM00003 " from PciRoot(0x0)/Pci(0x1,0x1)/Ata(Secondary,Master,0x0) BdsDxe: starting Boot0001 "UEFI QEMU DVD-ROM QM00003 " from PciRoot(0x0)/Pci(0x1,0x1)/Ata(Secondary,Master,0x0) - Booting `wukkOS basic kernel' - - WARNING: no console will be available to OS - error: no suitable video mode found. - using serial port 0 as console +using serial port 0 as console debug: setup GDT debug: GDT loaded debug: CS set @@ -20,44 +16,3 @@ initialising mapper...[OK] initialising frame allocator...[OK] initialising heap...[OK] testing heap...[OK] -checking for apic compatibility...[OK] -initialising apic...[debug] read_phys_memory32: addr fffe0000 not mapped -[debug] allocated frame: PhysFrame[4KiB](0x1c000) -[debug] mapped page: Page[4KiB](0xfffe0000) -[debug] map_to_result: Ok(MapperFlush(Page[4KiB](0xfffe0000))) -[debug] xapic id: 0 -[debug] xapic version: 0 -[OK] -setting up apic interrupts...[debug] acpi tag: RsdpV1Tag { typ: AcpiV1, size: 28, signature: [82, 83, 68, 32, 80, 84, 82, 32], checksum: 172, oem_id: [66, 79, 67, 72, 83, 32], revision: 0, rsdt_address: 532140032 } -[debug] rsdt: 532140032 -[debug] read_phys_memory32: addr 1fb7d000 not mapped -[WARN] failed to unmap page -[debug] read_phys_memory32: addr 1fb7d000 not mapped -[debug] read_phys_memory32: addr 1fb7a000 not mapped -[WARN] failed to unmap page -[debug] read_phys_memory32: addr 1fb7a000 not mapped -[debug] read_phys_memory32: addr 1fb7b000 not mapped -[WARN] failed to unmap page -[WARN] failed to unmap page -[debug] read_phys_memory32: addr 1fb79000 not mapped -[WARN] failed to unmap page -[debug] read_phys_memory32: addr 1fb78000 not mapped -[WARN] failed to unmap page -[debug] read_phys_memory32: addr 1fb77000 not mapped -[WARN] failed to unmap page -[debug] read_phys_memory32: addr 1fb76000 not mapped -[WARN] failed to unmap page -[WARN] failed to unmap page -[debug] loaded rsdt -[debug] read_phys_memory32: addr 1fb7a000 not mapped -[debug] read_phys_memory32: addr 1fb79000 not mapped -[WARN] failed to unmap page -[WARN] failed to unmap page -[debug] ioapic addr: fec00000 -[debug] ioapicaddr: 0xfec00000 -[debug] read_phys_memory32: addr fec00000 not mapped -[debug] allocated frame: PhysFrame[4KiB](0x1f000) -[debug] mapped page: Page[4KiB](0xfec00000) -[debug] map_to_result: Ok(MapperFlush(Page[4KiB](0xfec00000))) -[debug] ioapic supported interrupts: 1 -[OK] diff --git a/src/boot/mod.rs b/src/boot/mod.rs index 2ee2989..ed79a07 100644 --- a/src/boot/mod.rs +++ b/src/boot/mod.rs @@ -2,21 +2,15 @@ use alloc::sync::Arc; use core::marker::PhantomData; use core::ptr::NonNull; use acpi::{AcpiHandler, InterruptModel, PhysicalMapping}; -use crate::{debug, KernelArgs, println}; +use limine::LimineTerminalResponse; +use crate::{debug, println, TERMINAL_REQUEST}; #[cfg(feature = "f_multiboot2")] use multiboot2::{load, MemoryMapTag, BootInformation}; use x86_64::structures::paging::{FrameAllocator, Mapper, OffsetPageTable, Page, Translate}; use x86_64::VirtAddr; use crate::memory::{BootInfoFrameAllocator, FRAME_ALLOC, MEM_MAPPER, PageSize, read_phys_memory32}; - -pub struct KernelInfo { - kernel_start: u64, - kernel_end: u64, - safe_mem_start: u64, - #[cfg(feature = "f_multiboot2")] - boot_info: BootInformation, -} +use crate::serial::terminal::ST; #[derive(Clone)] struct Handler; @@ -54,73 +48,24 @@ impl AcpiHandler for Handler { } } -impl KernelInfo { - pub fn init_from_kernel_args(args: KernelArgs) -> Self { - #[cfg(feature = "f_multiboot2")] - { - let boot_info = unsafe { load(args.multiboot_information_address) }.expect("failed to load multiboot2 information"); - let elf_sections = boot_info.elf_sections_tag().expect("no elf sections tag"); - let kernel_start = elf_sections.sections().map(|s| s.start_address()).min().unwrap(); - let kernel_end = elf_sections.sections().map(|s| s.end_address()).max().unwrap(); - // get end of multiboot for safe memory - let safe_mem_start = boot_info.start_address() + boot_info.total_size(); - let kernel_info = KernelInfo { - kernel_start, - kernel_end, - safe_mem_start: safe_mem_start as u64, - boot_info, - }; - kernel_info - } - } +pub struct LimineWriter; - #[cfg(feature = "f_multiboot2")] - pub fn get_memory_tag(&self) -> &MemoryMapTag { - let mm_tag = self.boot_info.memory_map_tag().expect("no memory map tag").clone(); - mm_tag - } - - #[cfg(feature = "f_multiboot2")] - pub fn memory_areas(&self) -> impl Iterator { - let mm_tag = self.boot_info.memory_map_tag().expect("ERR NO MEM MAP TAG!"); - mm_tag.all_memory_areas() - } - - pub fn is_safe_memory(&self, addr: u64) -> bool { - addr >= self.safe_mem_start && addr >= self.kernel_end - } - - pub fn safe_memory_start(&self) -> u64 { - self.safe_mem_start - } - - pub fn acpi_get_ioapic_addr(&self) -> u32 { - #[cfg(feature = "f_multiboot2")] - { - let acpi_tag = self.boot_info.rsdp_v1_tag().expect("no acpi tag"); - debug!("acpi tag: {:?}", acpi_tag); - let rsdp = acpi_tag; - let rsdp = unsafe { &*rsdp }; - let rsdt = rsdp.rsdt_address(); - debug!("rsdt: {:?}", rsdt); - let rsdt = unsafe { - acpi::AcpiTables::from_rsdt( - Handler, 0, - rsdt) - .expect("failed to get acpi tables") - }; - debug!("loaded rsdt"); - let platform_info = rsdt.platform_info().expect("failed to get platform info"); - let interrupt_model = platform_info.interrupt_model; - if let InterruptModel::Apic(apic) = interrupt_model { - let ioapics = apic.io_apics; - let ioapic = ioapics.first().expect("no ioapics"); - let ioapic_addr = ioapic.address; - debug!("ioapic addr: {:x}", ioapic_addr); - ioapic_addr +impl core::fmt::Write for LimineWriter { + fn write_str(&mut self, s: &str) -> core::fmt::Result { + static mut CACHED: Option<&'static LimineTerminalResponse> = None; + unsafe { + if let Some(writer) = CACHED { + let terminal = &writer.terminals()[0]; + writer.write().unwrap()(terminal, s); } else { - panic!("no ioapic"); + let response = TERMINAL_REQUEST.get_response().get().unwrap(); + let terminal = &response.terminals()[0]; + let writer = response.write().unwrap(); + writer(terminal, s); + + CACHED = Some(response); } } + Ok(()) } } \ No newline at end of file diff --git a/src/internals/cpu.rs b/src/internals/cpu.rs index 5d42b2d..dd5dba1 100644 --- a/src/internals/cpu.rs +++ b/src/internals/cpu.rs @@ -3,7 +3,7 @@ use x86::apic::{xapic::XAPIC, ioapic::IoApic, ApicControl}; use x86_64::PhysAddr; use x86_64::structures::idt::InterruptStackFrame; use x86_64::structures::paging::PhysFrame; -use crate::{debug, KERN_INFO, print, println}; +use crate::{debug, print, println}; use crate::memory::{BootInfoFrameAllocator, read_phys_memory32, write_phys_memory32}; use crate::serial::{command, read}; diff --git a/src/macros/mod.rs b/src/macros/mod.rs index 11c85f3..9314c60 100644 --- a/src/macros/mod.rs +++ b/src/macros/mod.rs @@ -1,4 +1,6 @@ use core::fmt; +use limine::LimineTerminalResponse; +use crate::boot::LimineWriter; use crate::serial::terminal::ST; #[macro_export] @@ -21,6 +23,9 @@ macro_rules! debug { pub fn _print(args: fmt::Arguments) { use core::fmt::Write; ST.writer.lock().write_fmt(args).unwrap(); + + let mut limine_writer = LimineWriter; + limine_writer.write_fmt(args).unwrap(); } #[doc(hidden)] @@ -31,5 +36,10 @@ pub fn _debug(args: fmt::Arguments) { ST.log("[debug] "); ST.writer.lock().write_fmt(args).unwrap(); ST.logln(""); + + let mut limine_writer = LimineWriter; + limine_writer.write_str("[debug] ").unwrap(); + limine_writer.write_fmt(args).unwrap(); + limine_writer.write_str("\n").unwrap(); } } \ No newline at end of file diff --git a/src/lib.rs b/src/main.rs similarity index 93% rename from src/lib.rs rename to src/main.rs index 3a813e6..16d049f 100644 --- a/src/lib.rs +++ b/src/main.rs @@ -16,7 +16,7 @@ use alloc::vec; use core::arch::asm; use lazy_static::lazy_static; use core::panic::PanicInfo; -use multiboot2::MemoryAreaType; +use limine::{LimineBootInfoRequest, LimineMemmapRequest, LimineTerminalRequest}; use spin::Mutex; use x86_64::structures::idt::{InterruptDescriptorTable, InterruptStackFrame}; use x86_64::structures::gdt::{GlobalDescriptorTable, Descriptor}; @@ -24,7 +24,6 @@ use x86_64::structures::tss::TaskStateSegment; use x86_64::{PhysAddr, VirtAddr}; use x86_64::registers::segmentation::{CS, Segment, SS}; use x86_64::structures::paging::Translate; -use crate::boot::KernelInfo; use crate::internals::WhyDoTheyCallItOvenWhenYouOfInTheColdFoodOfOutHotEatTheFood::*; use crate::memory::{FRAME_ALLOC, MEM_MAPPER}; use crate::serial::terminal::ST; @@ -37,8 +36,12 @@ mod boot; mod memory; mod macros; +static BOOTLOADER_INFO: LimineBootInfoRequest = LimineBootInfoRequest::new(0); +static TERMINAL_REQUEST: LimineTerminalRequest = LimineTerminalRequest::new(0); +static MEM_MAP: LimineMemmapRequest = LimineMemmapRequest::new(0); + lazy_static! { - pub static ref KERN_INFO: Mutex> = Mutex::new(None); + //pub static ref KERN_INFO: Mutex> = Mutex::new(None); static ref GDT: Mutex = { let mut gdt = GlobalDescriptorTable::new(); Mutex::new(gdt) @@ -82,14 +85,10 @@ fn panic(info: &PanicInfo) -> ! { loop {} } -#[repr(C)] -pub struct KernelArgs { - #[cfg(feature = "f_multiboot2")] - multiboot_information_address: usize -} - #[no_mangle] -pub extern fn kernel_main(args: KernelArgs) -> ! { +pub extern "C" fn kernel_main() -> ! { + debug!("entry point"); + // initialise serial let mut serial_ports = serial::init_serial(); let mut console_port = None; @@ -165,7 +164,6 @@ pub extern fn kernel_main(args: KernelArgs) -> ! { println!(); println!("welcome to wukkOS!"); println!("(c) 2022 Real Microsoft, LLC"); - KERN_INFO.lock().replace(KernelInfo::init_from_kernel_args(args)); // memory stuff { @@ -194,7 +192,7 @@ pub extern fn kernel_main(args: KernelArgs) -> ! { } // apic stuff - { + /*{ print!("checking for apic compatibility..."); let apic_compatible = unsafe { internals::cpu::check_apic_compat() }; if apic_compatible { @@ -213,7 +211,7 @@ pub extern fn kernel_main(args: KernelArgs) -> ! { println!("[OK]"); // enable interrupts x86_64::instructions::interrupts::enable(); - } + }*/ loop { } diff --git a/src/memory/mod.rs b/src/memory/mod.rs index 7bead8e..70c9ca5 100644 --- a/src/memory/mod.rs +++ b/src/memory/mod.rs @@ -46,18 +46,14 @@ unsafe fn active_level_4_table(phys_mem_offset: VirtAddr) -> &'static mut PageTa unsafe { &mut *page_table_ptr } // unsafe } -#[cfg(feature = "f_multiboot2")] -use multiboot2::{MemoryMapTag, BootInformation}; use spin::Mutex; -use crate::boot::KernelInfo; -use crate::{debug, KERN_INFO, print, println}; +use crate::{debug, MEM_MAP, print, println}; pub struct BootInfoFrameAllocator { next: usize, } impl BootInfoFrameAllocator { - #[cfg(feature = "f_multiboot2")] pub unsafe fn init() -> Self { Self { next: 0, @@ -67,15 +63,13 @@ impl BootInfoFrameAllocator { unsafe impl FrameAllocator for BootInfoFrameAllocator { fn allocate_frame(&mut self) -> Option { - #[cfg(feature = "f_multiboot2")] { - let mut kern_lock = KERN_INFO.lock(); - let mut kern_info = kern_lock.as_mut().unwrap(); - let mut usable_frames = kern_info - .memory_areas(); - let mut usable_frames = usable_frames + #[cfg(feature = "f_limine")] { + let mmap = MEM_MAP.get_response().get().expect("failed to get memory map") + .memmap(); + let mut usable_frames = mmap.iter() .map(|area| { - let frame_addr = area.start_address(); - let frame_end = area.end_address(); + let frame_addr = area.base; + let frame_end = area.base + area.len; let frame_size = frame_end - frame_addr; let num_frames = frame_size / 4096; let start_frame = PhysFrame::containing_address(PhysAddr::new(frame_addr)); @@ -85,9 +79,6 @@ unsafe impl FrameAllocator for BootInfoFrameAllocator { let frame = usable_frames.nth(self.next).clone(); self.next += 1; - // ensure unlock - unsafe { KERN_INFO.force_unlock() }; - frame } } diff --git a/x86_64-custom.json b/x86_64-custom.json index 346fefd..33ca2b2 100644 --- a/x86_64-custom.json +++ b/x86_64-custom.json @@ -9,7 +9,14 @@ "executables": true, "linker-flavor": "ld.lld", "linker": "rust-lld", - "panic-strategy": "abort", "disable-redzone": true, - "features": "-mmx,-sse,+soft-float" + "panic-strategy": "abort", + "features": "-mmx,-sse,+soft-float", + "code-model": "kernel", + "pre-link-args": { + "ld.lld": [ + "--gc-sections", + "--script=arch/x86_64/linker.ld" + ] + } } \ No newline at end of file