File tree Expand file tree Collapse file tree 4 files changed +21
-6
lines changed Expand file tree Collapse file tree 4 files changed +21
-6
lines changed Original file line number Diff line number Diff line change 9
9
#![ cfg_attr( feature = "deny-warnings" , deny( warnings) ) ]
10
10
#![ cfg_attr( feature = "deny-warnings" , deny( missing_docs) ) ]
11
11
#![ cfg_attr( not( feature = "deny-warnings" ) , warn( missing_docs) ) ]
12
-
13
12
#![ deny( missing_debug_implementations) ]
14
13
15
14
#[ cfg( test) ]
@@ -18,10 +17,10 @@ extern crate std;
18
17
19
18
#[ macro_use]
20
19
extern crate bitflags;
20
+ extern crate array_init;
21
21
extern crate bit_field;
22
22
extern crate os_bootinfo;
23
23
extern crate usize_conversions;
24
- extern crate array_init;
25
24
26
25
/// Provides the non-standard-width integer types `u2`–`u63`.
27
26
///
Original file line number Diff line number Diff line change @@ -39,6 +39,12 @@ bitflags! {
39
39
}
40
40
}
41
41
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
+
42
48
/// Contains the physical address of the level 4 page table.
43
49
#[ derive( Debug ) ]
44
50
pub struct Cr3 ;
@@ -57,7 +63,7 @@ bitflags! {
57
63
mod x86_64 {
58
64
use super :: * ;
59
65
use structures:: paging:: PhysFrame ;
60
- use PhysAddr ;
66
+ use { PhysAddr , VirtAddr } ;
61
67
62
68
impl Cr0 {
63
69
/// Read the current set of CR0 flags.
@@ -108,6 +114,17 @@ mod x86_64 {
108
114
}
109
115
}
110
116
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
+
111
128
impl Cr3 {
112
129
/// Read the current P4 table address from the CR3 register.
113
130
pub fn read ( ) -> ( PhysFrame , Cr3Flags ) {
Original file line number Diff line number Diff line change @@ -682,6 +682,7 @@ impl fmt::Debug for ExceptionStackFrame {
682
682
683
683
bitflags ! {
684
684
/// Describes an page fault error code.
685
+ #[ repr( transparent) ]
685
686
pub struct PageFaultErrorCode : u64 {
686
687
/// If this flag is set, the page fault was caused by a page-protection violation,
687
688
/// else the page fault was caused by a not-present page.
Original file line number Diff line number Diff line change @@ -27,9 +27,7 @@ pub struct PageTableEntry {
27
27
impl PageTableEntry {
28
28
/// Creates an unused page table entry.
29
29
pub fn new ( ) -> Self {
30
- PageTableEntry {
31
- entry : 0 ,
32
- }
30
+ PageTableEntry { entry : 0 }
33
31
}
34
32
35
33
/// Returns whether this entry is zero.
You can’t perform that action at this time.
0 commit comments