-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added basic paging support for kernel
- Loading branch information
Showing
10 changed files
with
178 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
//! The module holds the data structure for passing nessessary information to kernel. | ||
use i386::{ | ||
driver::mem::e820::E820MemInfo, | ||
driver::disk::ata::pio::ATADiskInfo | ||
driver::disk::ata::pio::ATADiskInfo, mem::paging::Paging | ||
}; | ||
use crate::mem::MEMINFO_MAX; | ||
|
||
/// The module holds the data structure for passing nessessary information to kernel. | ||
|
||
pub struct KernelContext { | ||
pub disk_info: ATADiskInfo, | ||
pub mem_info: E820MemInfo<MEMINFO_MAX> | ||
pub mem_info: E820MemInfo<MEMINFO_MAX>, | ||
pub kernel_paging: &'static dyn Paging | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
use i386::mem::paging::{ | ||
pae::{PDEntry, PDTable, PDPTable, PDPTEntry, PAEPaging}, | ||
PATMemoryType, Paging | ||
}; | ||
|
||
/// kernel occupies 3 2MiB pages, this value can be adjusted accordingly | ||
#[allow(dead_code)] | ||
const KERNEL_PAGENUM: usize = 2; | ||
const MB: u64 = 1 << 20; | ||
|
||
/// 4MB kernel PDT page table entry (directly map virtual address to the same physical address) | ||
static KERNEL_PDT: PDTable = PDTable::with_entries([ | ||
PDEntry::new_page( | ||
true, | ||
false, | ||
PATMemoryType::new(false, false, false), | ||
false, | ||
0 * MB, | ||
false | ||
), | ||
PDEntry::new_page( | ||
true, | ||
false, | ||
PATMemoryType::new(false, false, false), | ||
false, | ||
2 * MB, | ||
false | ||
) | ||
]); | ||
|
||
/// kernel top level page table | ||
static mut KERNEL_PDPT: PDPTable = PDPTable::new(); | ||
|
||
pub static KERNEL_PAGING: PAEPaging = PAEPaging::new(unsafe { &KERNEL_PDPT }); | ||
|
||
pub fn enable_paging() { | ||
unsafe { KERNEL_PDPT.entries[0] = PDPTEntry::new( | ||
PATMemoryType::new(false, false, false), | ||
&KERNEL_PDT as *const PDTable as u64 | ||
)}; | ||
|
||
unsafe { KERNEL_PDPT.entries[1] = PDPTEntry(0xffffffffffffffff); } | ||
KERNEL_PAGING.enable(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.