Skip to content

Commit

Permalink
x86_64: shuffle bitset functions into a module
Browse files Browse the repository at this point in the history
  • Loading branch information
barzamin committed Mar 12, 2018
1 parent 0eaa572 commit 6f8c4d5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions src/arch/x86_64/memory/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,8 @@ pub fn init(boot_info: &BootInformation) -> MemoryController {
);

// Enable required CPU features
x86_64::enable_nxe_bit(); // Enable NO_EXECUTE pages
x86_64::enable_wrprot_bit(); // Disable writing to non-WRITABLE pages
x86_64::bits::enable_nxe(); // Enable NO_EXECUTE pages
x86_64::bits::enable_wrprot(); // Disable writing to non-WRITABLE pages

let mut active_table = paging::remap_kernel(&mut frame_allocator, boot_info);
info!("paging: remapped kernel");
Expand Down
29 changes: 16 additions & 13 deletions src/arch/x86_64/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,24 @@ pub mod device;
pub mod memory;
pub mod interrupts;

/// Turn on no-execute page protection.
pub fn enable_nxe_bit() {
use x86::registers::msr;

const NXE_BIT: u64 = 1 << 11;
unsafe {
let efer = msr::rdmsr(msr::IA32_EFER);
msr::wrmsr(msr::IA32_EFER, efer | NXE_BIT)
mod bits {
/// Turn on no-execute page protection.
pub fn enable_nxe() {
use x86::registers::msr;

const NXE_BIT: u64 = 1 << 11;
unsafe {
let efer = msr::rdmsr(msr::IA32_EFER);
msr::wrmsr(msr::IA32_EFER, efer | NXE_BIT)
}
}
}

/// Turn on page write-protect enforcement.
pub fn enable_wrprot_bit() {
use x86::registers::control_regs::{Cr0, cr0, cr0_write};
unsafe {
cr0_write(cr0() | Cr0::WRITE_PROTECT);
/// Turn on page write-protect enforcement.
pub fn enable_wrprot() {
use x86::registers::control_regs::{Cr0, cr0, cr0_write};
unsafe {
cr0_write(cr0() | Cr0::WRITE_PROTECT);
}
}
}

0 comments on commit 6f8c4d5

Please sign in to comment.