Minor fixes, use small pages to make it work

This commit is contained in:
Zhang Junyang 2023-07-20 19:40:13 +08:00 committed by Tate, Hongliang Tian
parent d407d85e70
commit e96884b72d
6 changed files with 21 additions and 6 deletions

View File

@ -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

View File

@ -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:

View File

@ -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<IrqCallbackHandle> = Vec::new();
pub fn init() {
heap_allocator::init();
vm::heap_allocator::init();
arch::before_all_init();
logger::init();
vm::init();

View File

@ -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<SpinLock<FrameAllocator>> = Once::new();

View File

@ -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;