Skip to content

Version 0.3.5 #50

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jan 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
#![cfg_attr(feature = "deny-warnings", deny(missing_docs))]
#![cfg_attr(not(feature = "deny-warnings"), warn(missing_docs))]

#![deny(missing_debug_implementations)]

#[cfg(test)]
Expand All @@ -18,10 +17,10 @@ extern crate std;

#[macro_use]
extern crate bitflags;
extern crate array_init;
extern crate bit_field;
extern crate os_bootinfo;
extern crate usize_conversions;
extern crate array_init;

/// Provides the non-standard-width integer types `u2`–`u63`.
///
Expand Down
19 changes: 18 additions & 1 deletion src/registers/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ bitflags! {
}
}

/// Contains the Page Fault Linear Address (PFLA).
///
/// When page fault occurs, the CPU sets this register to the accessed address.
#[derive(Debug)]
pub struct Cr2;

/// Contains the physical address of the level 4 page table.
#[derive(Debug)]
pub struct Cr3;
Expand All @@ -57,7 +63,7 @@ bitflags! {
mod x86_64 {
use super::*;
use structures::paging::PhysFrame;
use PhysAddr;
use {PhysAddr, VirtAddr};

impl Cr0 {
/// Read the current set of CR0 flags.
Expand Down Expand Up @@ -108,6 +114,17 @@ mod x86_64 {
}
}

impl Cr2 {
/// Read the current page fault linear address from the CR3 register.
pub fn read() -> VirtAddr {
let value: u64;
unsafe {
asm!("mov %cr2, $0" : "=r" (value));
}
VirtAddr::new(value)
}
}

impl Cr3 {
/// Read the current P4 table address from the CR3 register.
pub fn read() -> (PhysFrame, Cr3Flags) {
Expand Down
1 change: 1 addition & 0 deletions src/structures/idt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ impl fmt::Debug for ExceptionStackFrame {

bitflags! {
/// Describes an page fault error code.
#[repr(transparent)]
pub struct PageFaultErrorCode: u64 {
/// If this flag is set, the page fault was caused by a page-protection violation,
/// else the page fault was caused by a not-present page.
Expand Down
4 changes: 1 addition & 3 deletions src/structures/paging/page_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,7 @@ pub struct PageTableEntry {
impl PageTableEntry {
/// Creates an unused page table entry.
pub fn new() -> Self {
PageTableEntry {
entry: 0,
}
PageTableEntry { entry: 0 }
}

/// Returns whether this entry is zero.
Expand Down