@@ -18,7 +18,7 @@ unsafe extern "C" {
18
18
}
19
19
20
20
fn base_addr ( ) -> usize {
21
- 0xffff_8000_0000_0000
21
+ KZERO
22
22
}
23
23
24
24
fn eboottext_addr ( ) -> usize {
@@ -93,25 +93,23 @@ pub fn total_kernel_range() -> PhysRange {
93
93
PhysRange ( from_virt_to_physaddr ( base_addr ( ) ) ..from_virt_to_physaddr ( end_addr ( ) ) )
94
94
}
95
95
96
- // TODO Meh, this is only valid if it's been mapped as an offset - should probably remove
97
- pub const fn physaddr_as_virt ( pa : PhysAddr ) -> usize {
98
- ( pa. addr ( ) as usize ) . wrapping_add ( KZERO )
96
+ /// Transform the physical address to a virtual address, under the assumption that
97
+ /// the virtual address is the physical address offset from KZERO.
98
+ pub const fn physaddr_as_ptr_mut_offset_from_kzero < T > ( pa : PhysAddr ) -> * mut T {
99
+ ( pa. addr ( ) as usize ) . wrapping_add ( KZERO ) as * mut T
99
100
}
100
101
101
- // TODO remove?
102
- pub const fn physaddr_as_ptr_mut < T > ( pa : PhysAddr ) -> * mut T {
103
- physaddr_as_virt ( pa) as * mut T
104
- }
105
-
106
- // TODO remove?
107
- pub const fn from_virt_to_physaddr ( va : usize ) -> PhysAddr {
102
+ /// Given a virtual address, return the physical address. Makes a massive assumption
103
+ /// that the code is mapped offset to KZERO, so should be used with extreme care.
104
+ pub fn from_virt_to_physaddr ( va : usize ) -> PhysAddr {
105
+ debug_assert ! ( va >= KZERO , "from_virt_to_physaddr: va {} must be >= KZERO ({})" , va, KZERO ) ;
108
106
PhysAddr :: new ( ( va - KZERO ) as u64 )
109
107
}
110
108
111
109
/// Given an address, return the physical address. Makes a massive assumption
112
110
/// that the code is mapped offset to KZERO, so should be used with extreme care.
113
111
pub fn from_ptr_to_physaddr_offset_from_kzero < T > ( a : * const T ) -> PhysAddr {
114
- PhysAddr :: new ( ( a. addr ( ) - KZERO ) as u64 )
112
+ from_virt_to_physaddr ( a. addr ( ) )
115
113
}
116
114
117
115
pub fn early_pages_range ( ) -> PhysRange {
0 commit comments