Add cache_disable to paging
This commit is contained in:
parent
72726e00d5
commit
b54f168f2e
7 changed files with 22 additions and 16 deletions
4
kernel/Cargo.lock
generated
4
kernel/Cargo.lock
generated
|
@ -357,9 +357,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.70"
|
version = "2.0.71"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2f0209b68b3613b093e0ec905354eccaedcfe83b8cb37cbdeae64026c3064c16"
|
checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
|
|
@ -114,7 +114,7 @@ pub fn find_free_virt_range(mut start: u64, end: u64, size: u64) -> u64 {
|
||||||
}
|
}
|
||||||
panic!("No free range found");
|
panic!("No free range found");
|
||||||
}
|
}
|
||||||
fn map(pml4: &mut PageTable, virt: u64, phys: u64, user: bool, write: bool, exec: bool) {
|
fn map(pml4: &mut PageTable, virt: u64, phys: u64, user: bool, write: bool, exec: bool, cache_disable: bool) {
|
||||||
assert!(virt >= 0x1000, "First page shouldn't be mapped");
|
assert!(virt >= 0x1000, "First page shouldn't be mapped");
|
||||||
{
|
{
|
||||||
let mut frames_vec = PHYSICAL_FRAMES.lock();
|
let mut frames_vec = PHYSICAL_FRAMES.lock();
|
||||||
|
@ -132,6 +132,7 @@ fn map(pml4: &mut PageTable, virt: u64, phys: u64, user: bool, write: bool, exec
|
||||||
table.entries_phys[table_i].set_user(user as u64);
|
table.entries_phys[table_i].set_user(user as u64);
|
||||||
table.entries_phys[table_i].set_write(write as u64);
|
table.entries_phys[table_i].set_write(write as u64);
|
||||||
table.entries_phys[table_i].set_execute_disable(!exec as u64);
|
table.entries_phys[table_i].set_execute_disable(!exec as u64);
|
||||||
|
table.entries_phys[table_i].set_cache_disable(cache_disable as u64);
|
||||||
table.entries_phys[table_i].set_present(1);
|
table.entries_phys[table_i].set_present(1);
|
||||||
}
|
}
|
||||||
pub unsafe fn unmap(address: u64) {
|
pub unsafe fn unmap(address: u64) {
|
||||||
|
@ -147,13 +148,13 @@ pub unsafe fn unmap(address: u64) {
|
||||||
None => {}
|
None => {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub unsafe fn map_range(virt_start: u64, phys_start: u64, size: u64, user: bool, write: bool, exec: bool) {
|
pub unsafe fn map_range(virt_start: u64, phys_start: u64, size: u64, user: bool, write: bool, exec: bool, cache_disable: bool) {
|
||||||
assert_eq!(virt_start % 0x1000, 0);
|
assert_eq!(virt_start % 0x1000, 0);
|
||||||
assert_eq!(phys_start % 0x1000, 0);
|
assert_eq!(phys_start % 0x1000, 0);
|
||||||
assert_eq!(size % 0x1000, 0);
|
assert_eq!(size % 0x1000, 0);
|
||||||
let mut current_pml4 = CURRENT_PML4.lock();
|
let mut current_pml4 = CURRENT_PML4.lock();
|
||||||
for i in 0..size / 0x1000 {
|
for i in 0..size / 0x1000 {
|
||||||
map(current_pml4.as_mut().unwrap(), virt_start + i * 0x1000, phys_start + i * 0x1000, user, write, exec);
|
map(current_pml4.as_mut().unwrap(), virt_start + i * 0x1000, phys_start + i * 0x1000, user, write, exec, cache_disable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pub fn setup_paging(loader_struct: &LoaderStruct, phys_start: u64, heap_start: u64) {
|
pub fn setup_paging(loader_struct: &LoaderStruct, phys_start: u64, heap_start: u64) {
|
||||||
|
@ -206,19 +207,19 @@ pub fn setup_paging(loader_struct: &LoaderStruct, phys_start: u64, heap_start: u
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for i in text_start..text_end {
|
for i in text_start..text_end {
|
||||||
map(pml4, i * 0x1000, i * 0x1000 - KERNEL_VIRT_START + phys_start, false, false, true);
|
map(pml4, i * 0x1000, i * 0x1000 - KERNEL_VIRT_START + phys_start, false, false, true, false);
|
||||||
}
|
}
|
||||||
for i in rodata_start..rodata_end {
|
for i in rodata_start..rodata_end {
|
||||||
map(pml4, i * 0x1000, i * 0x1000 - KERNEL_VIRT_START + phys_start, false, false, false);
|
map(pml4, i * 0x1000, i * 0x1000 - KERNEL_VIRT_START + phys_start, false, false, false, false);
|
||||||
}
|
}
|
||||||
for i in data_start..data_end {
|
for i in data_start..data_end {
|
||||||
map(pml4, i * 0x1000, i * 0x1000 - KERNEL_VIRT_START + phys_start, false, true, false);
|
map(pml4, i * 0x1000, i * 0x1000 - KERNEL_VIRT_START + phys_start, false, true, false, false);
|
||||||
}
|
}
|
||||||
for i in bss_start..bss_end {
|
for i in bss_start..bss_end {
|
||||||
map(pml4, i * 0x1000, i * 0x1000 - KERNEL_VIRT_START + phys_start, false, true, false);
|
map(pml4, i * 0x1000, i * 0x1000 - KERNEL_VIRT_START + phys_start, false, true, false, false);
|
||||||
}
|
}
|
||||||
for i in 0..KERNEL_HEAP_INITIAL_SIZE / 0x1000 {
|
for i in 0..KERNEL_HEAP_INITIAL_SIZE / 0x1000 {
|
||||||
map(pml4, KERNEL_HEAP_START + i as u64 * 0x1000, heap_start + i as u64 * 0x1000, false, true, false);
|
map(pml4, KERNEL_HEAP_START + i as u64 * 0x1000, heap_start + i as u64 * 0x1000, false, true, false, false);
|
||||||
let mut heap_map = HEAP_PHYS_MAPPING.lock();
|
let mut heap_map = HEAP_PHYS_MAPPING.lock();
|
||||||
heap_map.push(heap_start + i as u64 * 0x1000);
|
heap_map.push(heap_start + i as u64 * 0x1000);
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,7 +81,7 @@ extern "C" fn AcpiOsMapMemory(phys: ACPI_PHYSICAL_ADDRESS, mut size: ACPI_SIZE)
|
||||||
size = phys_end - phys_start;
|
size = phys_end - phys_start;
|
||||||
let virt_start = find_free_virt_range(KERNEL_MAPPINGS_START, KERNEL_MAPPINGS_END, size);
|
let virt_start = find_free_virt_range(KERNEL_MAPPINGS_START, KERNEL_MAPPINGS_END, size);
|
||||||
unsafe {
|
unsafe {
|
||||||
map_range(virt_start, phys_start, size, false, true, false);
|
map_range(virt_start, phys_start, size, false, true, false, true);
|
||||||
}
|
}
|
||||||
(virt_start + phys_offset) as *mut c_void
|
(virt_start + phys_offset) as *mut c_void
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
use core::arch::asm;
|
use core::arch::asm;
|
||||||
|
|
||||||
pub unsafe fn outb(port: u16, value: u8) {
|
pub unsafe fn outb(port: u16, value: u8) {
|
||||||
asm!("out dx, al", in("al") value, in("dx") port);
|
unsafe {
|
||||||
|
asm!("out dx, al", in("al") value, in("dx") port);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
#![forbid(unsafe_op_in_unsafe_fn)]
|
||||||
|
|
||||||
extern crate alloc;
|
extern crate alloc;
|
||||||
|
|
||||||
|
|
|
@ -30,5 +30,7 @@ pub const KERNEL_HEAP_START: u64 = 0xfffffffe00000000;
|
||||||
pub const KERNEL_HEAP_INITIAL_SIZE: usize = 16 * 1024 * 1024;
|
pub const KERNEL_HEAP_INITIAL_SIZE: usize = 16 * 1024 * 1024;
|
||||||
|
|
||||||
pub unsafe fn load_cr3(cr3: u64) {
|
pub unsafe fn load_cr3(cr3: u64) {
|
||||||
asm!("mov cr3, {}", in(reg) cr3);
|
unsafe {
|
||||||
|
asm!("mov cr3, {}", in(reg) cr3);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
6
loader/Cargo.lock
generated
6
loader/Cargo.lock
generated
|
@ -123,9 +123,9 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "syn"
|
name = "syn"
|
||||||
version = "2.0.70"
|
version = "2.0.71"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "2f0209b68b3613b093e0ec905354eccaedcfe83b8cb37cbdeae64026c3064c16"
|
checksum = "b146dcf730474b4bcd16c311627b31ede9ab149045db4d6088b3becaea046462"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
|
@ -165,7 +165,7 @@ checksum = "4f345e42323c05e41e29e409505f5f8e0df7b5743340215d60344dbd79b729f4"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"proc-macro2",
|
"proc-macro2",
|
||||||
"quote",
|
"quote",
|
||||||
"syn 2.0.70",
|
"syn 2.0.71",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
|
|
Loading…
Add table
Reference in a new issue