Skip to content

Commit

Permalink
fix: fix some bug for boot
Browse files Browse the repository at this point in the history
  • Loading branch information
yfblock committed Aug 10, 2024
1 parent e0671e8 commit 2c57d33
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/components/boot/riscv64.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,12 @@ use crate::components::instruction::Instruction;
use crate::components::pagetable::{PTEFlags, PTE};
use crate::PageTable;

#[repr(align(4096))]
pub(crate) struct PageAlignment([PTE; PageTable::PTE_NUM_IN_PAGE]);

/// TODO: Map the whole memory in the available memory region.
#[link_section = ".data.prepage.entry"]
pub(crate) static mut PAGE_TABLE: [PTE; PageTable::PTE_NUM_IN_PAGE] = {
pub(crate) static mut PAGE_TABLE: PageAlignment = {
let mut arr: [PTE; PageTable::PTE_NUM_IN_PAGE] = [PTE(0); PageTable::PTE_NUM_IN_PAGE];
// 初始化页表信息
// 0x00000000_80000000 -> 0x80000000 (1G)
Expand All @@ -28,7 +31,7 @@ pub(crate) static mut PAGE_TABLE: [PTE; PageTable::PTE_NUM_IN_PAGE] = {
arr[0x104] = PTE::from_addr(0x1_0000_0000, PTEFlags::ADGVRWX);
arr[0x105] = PTE::from_addr(0x1_4000_0000, PTEFlags::ADGVRWX);
arr[0x106] = PTE::from_addr(0x8000_0000, PTEFlags::ADVRWX);
arr
PageAlignment(arr)
};

/// 汇编入口函数
Expand Down Expand Up @@ -215,6 +218,6 @@ pub(crate) extern "C" fn rust_secondary_main(hartid: usize) {

pub fn boot_page_table() -> PageTable {
PageTable(crate::addr::PhysAddr(unsafe {
PAGE_TABLE.as_ptr() as usize & !VIRT_ADDR_START
PAGE_TABLE.0.as_ptr() as usize & !VIRT_ADDR_START
}))
}
11 changes: 10 additions & 1 deletion src/components/boot/x86_64/multiboot.S
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
.endr
.endm

.macro Page1GHugeTable before
.set n, \before * 0x40000000
.rept 512 - \before
.quad n + 0x83
.set n, n + 0x40000000
.endr
.endm

.section .text.entry
.balign 4
.type multiboot_header, STT_OBJECT
Expand Down Expand Up @@ -120,7 +128,8 @@ _boot_mapping_pdpt:
.quad _boot_mapping_pd2 - {offset} + 0x3 # PRESENT | WRITABLE | HUGE_PAGE | paddr(0x4000_0000)
.quad _boot_mapping_pd3 - {offset} + 0x3 # PRESENT | WRITABLE | HUGE_PAGE | paddr(0x8000_0000)
.quad _boot_mapping_pd4 - {offset} + 0x3 # PRESENT | WRITABLE | HUGE_PAGE | paddr(0xc000_0000)
.zero 8 * 508
# .zero 8 * 508
Page1GHugeTable 4

.balign 4096
_boot_mapping_pd:
Expand Down
2 changes: 2 additions & 0 deletions src/components/percpu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ use core::{alloc::Layout, mem::size_of, ptr::copy_nonoverlapping};

use super::pagetable::PAGE_SIZE;

pub use polyhal_macro::def_percpu;

#[repr(align(8))]
struct PerCPUDATA([u8; PAGE_SIZE]);

Expand Down

0 comments on commit 2c57d33

Please sign in to comment.