Skip to content

Commit 032fe40

Browse files
authored
Merge pull request #50 from rust-osdev/0.3.5
Version 0.3.5
2 parents acd4bb1 + 4fb35ea commit 032fe40

File tree

4 files changed

+21
-6
lines changed

4 files changed

+21
-6
lines changed

src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
#![cfg_attr(feature = "deny-warnings", deny(warnings))]
1010
#![cfg_attr(feature = "deny-warnings", deny(missing_docs))]
1111
#![cfg_attr(not(feature = "deny-warnings"), warn(missing_docs))]
12-
1312
#![deny(missing_debug_implementations)]
1413

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

1918
#[macro_use]
2019
extern crate bitflags;
20+
extern crate array_init;
2121
extern crate bit_field;
2222
extern crate os_bootinfo;
2323
extern crate usize_conversions;
24-
extern crate array_init;
2524

2625
/// Provides the non-standard-width integer types `u2`–`u63`.
2726
///

src/registers/control.rs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ bitflags! {
3939
}
4040
}
4141

42+
/// Contains the Page Fault Linear Address (PFLA).
43+
///
44+
/// When page fault occurs, the CPU sets this register to the accessed address.
45+
#[derive(Debug)]
46+
pub struct Cr2;
47+
4248
/// Contains the physical address of the level 4 page table.
4349
#[derive(Debug)]
4450
pub struct Cr3;
@@ -57,7 +63,7 @@ bitflags! {
5763
mod x86_64 {
5864
use super::*;
5965
use structures::paging::PhysFrame;
60-
use PhysAddr;
66+
use {PhysAddr, VirtAddr};
6167

6268
impl Cr0 {
6369
/// Read the current set of CR0 flags.
@@ -108,6 +114,17 @@ mod x86_64 {
108114
}
109115
}
110116

117+
impl Cr2 {
118+
/// Read the current page fault linear address from the CR3 register.
119+
pub fn read() -> VirtAddr {
120+
let value: u64;
121+
unsafe {
122+
asm!("mov %cr2, $0" : "=r" (value));
123+
}
124+
VirtAddr::new(value)
125+
}
126+
}
127+
111128
impl Cr3 {
112129
/// Read the current P4 table address from the CR3 register.
113130
pub fn read() -> (PhysFrame, Cr3Flags) {

src/structures/idt.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,7 @@ impl fmt::Debug for ExceptionStackFrame {
682682

683683
bitflags! {
684684
/// Describes an page fault error code.
685+
#[repr(transparent)]
685686
pub struct PageFaultErrorCode: u64 {
686687
/// If this flag is set, the page fault was caused by a page-protection violation,
687688
/// else the page fault was caused by a not-present page.

src/structures/paging/page_table.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ pub struct PageTableEntry {
2727
impl PageTableEntry {
2828
/// Creates an unused page table entry.
2929
pub fn new() -> Self {
30-
PageTableEntry {
31-
entry: 0,
32-
}
30+
PageTableEntry { entry: 0 }
3331
}
3432

3533
/// Returns whether this entry is zero.

0 commit comments

Comments
 (0)