diff --git a/build/grub/scripts/build-grub-image.sh b/build/grub/scripts/build-grub-image.sh index 754c16844..1d1770984 100755 --- a/build/grub/scripts/build-grub-image.sh +++ b/build/grub/scripts/build-grub-image.sh @@ -5,7 +5,7 @@ set -eux KERNEL=$1 # Copy the needed files into an ISO image. -mkdir -p target/iso_root +mkdir -p target/iso_root/boot cp $KERNEL target/iso_root/boot/jinux mkdir -p target/iso_root/boot/grub cp build/grub/conf/grub.cfg target/iso_root/boot/grub diff --git a/framework/jinux-frame/src/arch/x86/boot/multiboot2/boot.S b/framework/jinux-frame/src/arch/x86/boot/multiboot2/boot.S index 2977bb4ee..7a5676c8d 100644 --- a/framework/jinux-frame/src/arch/x86/boot/multiboot2/boot.S +++ b/framework/jinux-frame/src/arch/x86/boot/multiboot2/boot.S @@ -152,16 +152,28 @@ PTE_GLOBAL = (1 << 8) // Page Directory: map to low 1 GiB * 4 space lea edi, [boot_pd] - mov eax, PTE_PRESENT | PTE_WRITE | PTE_HUGE | PTE_GLOBAL + lea eax, [boot_pt + (PTE_PRESENT | PTE_WRITE | PTE_GLOBAL)] mov ecx, 512 * 4 // (of entries in PD) * (number of PD) write_pd_entry: mov dword ptr [edi], eax mov dword ptr [edi + 4], 0 - add eax, 0x200000 // 2 MiB + add eax, 0x1000 // 4kiB add edi, 8 loop write_pd_entry + // Page Table: map to low 4 KiB * 1M space + lea edi, [boot_pt] + mov eax, 0x103 // Present, writable, global. + mov ecx, 512 * 512 * 4 // (of entries in PT) * (number of PT) + +write_pt_entry: + mov dword ptr [edi], eax + mov dword ptr [edi + 4], 0 + add eax, 0x1000 // 4KiB + add edi, 8 + loop write_pt_entry + jmp enable_long_mode enable_long_mode: @@ -226,6 +238,8 @@ boot_pd_2g_3g: .skip 4096 boot_pd_3g_4g: .skip 4096 +boot_pt: + .skip 4096 * 512 * 4 boot_page_table_end: boot_stack_bottom: diff --git a/framework/jinux-frame/src/lib.rs b/framework/jinux-frame/src/lib.rs index 5d5c0e642..2ce684b64 100644 --- a/framework/jinux-frame/src/lib.rs +++ b/framework/jinux-frame/src/lib.rs @@ -23,7 +23,6 @@ pub mod bus; pub mod config; pub mod cpu; mod error; -mod heap_allocator; pub mod logger; pub mod io_mem; pub mod prelude; @@ -46,7 +45,7 @@ use trapframe::TrapFrame; static mut IRQ_CALLBACK_LIST: Vec = Vec::new(); pub fn init() { - heap_allocator::init(); + vm::heap_allocator::init(); arch::before_all_init(); logger::init(); vm::init(); diff --git a/framework/jinux-frame/src/vm/frame_allocator.rs b/framework/jinux-frame/src/vm/frame_allocator.rs index 38487a24b..b135062cd 100644 --- a/framework/jinux-frame/src/vm/frame_allocator.rs +++ b/framework/jinux-frame/src/vm/frame_allocator.rs @@ -3,9 +3,10 @@ use buddy_system_allocator::FrameAllocator; use log::info; use spin::Once; +use crate::arch::boot::{MemoryRegion, MemoryRegionType}; use crate::{config::PAGE_SIZE, sync::SpinLock}; -use super::{frame::VmFrameFlags, MemoryRegion, MemoryRegionType, VmFrame}; +use super::{frame::VmFrameFlags, VmFrame}; pub(super) static FRAME_ALLOCATOR: Once> = Once::new(); diff --git a/framework/jinux-frame/src/heap_allocator.rs b/framework/jinux-frame/src/vm/heap_allocator.rs similarity index 100% rename from framework/jinux-frame/src/heap_allocator.rs rename to framework/jinux-frame/src/vm/heap_allocator.rs diff --git a/framework/jinux-frame/src/vm/mod.rs b/framework/jinux-frame/src/vm/mod.rs index f284ab9f1..e44e1357c 100644 --- a/framework/jinux-frame/src/vm/mod.rs +++ b/framework/jinux-frame/src/vm/mod.rs @@ -8,6 +8,7 @@ pub type Paddr = usize; mod frame; mod frame_allocator; +pub(crate) mod heap_allocator; mod io; mod memory_set; mod offset;