diff --git a/src/mmu.rs b/src/mmu.rs index 59fe1c0..ffa5434 100644 --- a/src/mmu.rs +++ b/src/mmu.rs @@ -12,6 +12,7 @@ use crate::{ const ID: u16 = 5; const TLB_MAPPING_FLAG_VALID: u32 = 0x800; +const MAPPING_FLAG_EXECUTABLE: u32 = 0x8; const MAPPING_FLAG_USER: u32 = 0x4; const MAPPING_FLAG_WRITABLE: u32 = 0x2; const MAPPING_FLAG_PRESENT: u32 = 0x1; @@ -177,14 +178,17 @@ impl Card for MmuCard { let present_flag = (flags & MAPPING_FLAG_PRESENT) > 0; let wr_flag = (flags & MAPPING_FLAG_WRITABLE) > 0; let user_flag = (flags & MAPPING_FLAG_USER) > 0; + let exec_flag = (flags & MAPPING_FLAG_EXECUTABLE) > 0; let present_flag = if present_flag { "P" } else { "_" }; let wr_flag = if wr_flag { "W" } else { "_" }; let user_flag = if user_flag { "U" } else { "_" }; + let exec_flag = if exec_flag { "X" } else { "_" }; if j == i { println!( - "0x{:0>6x}: 0x{:0>8x} ({}{}{})", + "0x{:0>6x}: 0x{:0>8x} ({}{}{}{})", i << 12, frame, + exec_flag, user_flag, wr_flag, present_flag @@ -193,10 +197,11 @@ impl Card for MmuCard { } else { if range_one_page.unwrap() { println!( - "0x{:0>6x}-0x{:0>6x}: 0x{:0>8x} ({}{}{})", + "0x{:0>6x}-0x{:0>6x}: 0x{:0>8x} ({}{}{}{})", i << 12, j << 12, frame, + exec_flag, user_flag, wr_flag, present_flag @@ -204,11 +209,12 @@ impl Card for MmuCard { } else { let range_len = (j - i) as u32; println!( - "0x{:0>6x}-0x{:0>6x}: 0x{:0>8x}-0x{:0>8x} ({}{}{})", + "0x{:0>6x}-0x{:0>6x}: 0x{:0>8x}-0x{:0>8x} ({}{}{}{})", i << 12, j << 12, frame, frame + (range_len * 0x1000), + exec_flag, user_flag, wr_flag, present_flag @@ -259,14 +265,17 @@ impl Card for MmuCard { let present_flag = (flags & MAPPING_FLAG_PRESENT) > 0; let wr_flag = (flags & MAPPING_FLAG_WRITABLE) > 0; let user_flag = (flags & MAPPING_FLAG_USER) > 0; + let exec_flag = (flags & MAPPING_FLAG_EXECUTABLE) > 0; let present_flag = if present_flag { "P" } else { "_" }; let wr_flag = if wr_flag { "W" } else { "_" }; let user_flag = if user_flag { "U" } else { "_" }; + let exec_flag = if exec_flag { "X" } else { "_" }; if j == i { println!( - "0x{:0>6x}: 0x{:0>8x} ({}{}{})", + "0x{:0>6x}: 0x{:0>8x} ({}{}{}{})", i << 12, frame, + exec_flag, user_flag, wr_flag, present_flag @@ -275,10 +284,11 @@ impl Card for MmuCard { } else { if range_one_page.unwrap() { println!( - "0x{:0>6x}-0x{:0>6x}: 0x{:0>8x} ({}{}{})", + "0x{:0>6x}-0x{:0>6x}: 0x{:0>8x} ({}{}{}{})", i << 12, j << 12, frame, + exec_flag, user_flag, wr_flag, present_flag @@ -286,11 +296,12 @@ impl Card for MmuCard { } else { let range_len = (j - i) as u32; println!( - "0x{:0>6x}-0x{:0>6x}: 0x{:0>8x}-0x{:0>8x} ({}{}{})", + "0x{:0>6x}-0x{:0>6x}: 0x{:0>8x}-0x{:0>8x} ({}{}{}{})", i << 12, j << 12, frame, frame + (range_len * 0x1000), + exec_flag, user_flag, wr_flag, present_flag @@ -368,6 +379,12 @@ impl Mmu for MmuCard { mapping }; if mapping & MAPPING_FLAG_PRESENT > 0 { + if function.is_code() && (mapping & MAPPING_FLAG_EXECUTABLE == 0) { + if print_debug { + println!("Page not executable"); + } + return NullableResult::Err(BusError); + } if !function.is_supervisor() && (mapping & MAPPING_FLAG_USER == 0) { if print_debug { println!("Page not user accessible");