File tree Expand file tree Collapse file tree 4 files changed +32
-53
lines changed Expand file tree Collapse file tree 4 files changed +32
-53
lines changed Original file line number Diff line number Diff line change @@ -22,28 +22,15 @@ pub fn pmap_bss_end() -> u64 {
22
22
return ___BSS_END__ as u64 ;
23
23
}
24
24
25
- pub struct Mem ;
26
- pub struct VAddr ( u64 ) ;
27
- #[ derive( Debug ) ]
28
- pub struct Range {
29
- pub addr : u64 ,
30
- pub len : u64 ,
31
- }
32
-
33
25
pub fn roundup_4k ( addr : u64 ) -> u64 {
34
- return ( addr + 0x1000 ) & 0xffff_ffff_ffff_0000 ;
26
+ return ( addr + 0xfff ) & ! 0xfff ;
35
27
}
36
28
37
29
pub fn rounddown_4k ( addr : u64 ) -> u64 {
38
- return addr & 0xffff_ffff_ffff_0000 ;
39
- }
40
-
41
- impl Range {
42
- pub fn contains ( & self , addr : u64 ) -> bool {
43
- return self . addr <= addr && addr < self . addr + self . len ;
44
- }
30
+ return addr & !0xfff ;
45
31
}
46
32
33
+ pub struct Mem ;
47
34
impl Mem {
48
35
// units
49
36
pub const K : u64 = 1024 ;
@@ -70,18 +57,6 @@ impl Mem {
70
57
pub const PHY_BM_SIZE : u64 = Mem :: PHY_PAGES >> 3 ;
71
58
}
72
59
73
- impl VAddr {
74
- pub fn roundup_4k ( & self ) {
75
- todo ! ( )
76
- }
77
- pub fn rounddown_4k ( & self ) {
78
- todo ! ( )
79
- }
80
- pub fn page_number ( & self ) -> u64 {
81
- self . 0 >> Mem :: PAGE_SHIFT
82
- }
83
- }
84
-
85
60
// PHY_TOP 128M
86
61
// ~ free frames
87
62
// PMA::bitmap + PHY_BM_SIZE
Original file line number Diff line number Diff line change 1
- use crate :: defs:: Range ;
1
+ // use crate::defs::Range;
2
2
use crate :: io:: * ;
3
3
use core:: fmt;
4
4
use core:: mem:: size_of;
5
+ use core:: ops:: Range ;
5
6
use lazy_static:: lazy_static;
6
7
// provide functions to parse information provided by grub multiboot
7
8
// see docs/multiboot.txt
@@ -58,11 +59,11 @@ impl MultibootMmap {
58
59
pub const MTYPE_RAM_NVS : u32 = 4 ;
59
60
/// defective RAM
60
61
pub const MTYPE_RAM_DEFECT : u32 = 5 ;
61
- pub fn get_range ( & self ) -> Range {
62
- return Range {
63
- addr : self . addr ,
64
- len : self . len ,
65
- } ;
62
+ pub fn get_range ( & self ) -> Range < u64 > {
63
+ Range {
64
+ start : self . addr ,
65
+ end : self . addr + self . len ,
66
+ }
66
67
}
67
68
pub fn get_end ( & self ) -> u64 {
68
69
return self . addr + self . len ;
Original file line number Diff line number Diff line change 1
1
use crate :: defs:: * ;
2
2
use crate :: io:: * ;
3
3
use crate :: machine:: multiboot;
4
+ use core:: ops:: Range ;
4
5
pub mod pma;
5
6
6
7
use lazy_static:: lazy_static;
@@ -32,20 +33,21 @@ pub fn init() {
32
33
continue ;
33
34
}
34
35
// TODO early break if the array is already full
35
- if mblock. get_range ( ) . contains ( pmap_kernel_end ( ) ) {
36
- let r = Range {
37
- addr : pmap_kernel_end ( ) ,
38
- len : mblock. get_end ( ) - pmap_kernel_end ( ) ,
39
- } ;
40
- inserted += GLOBAL_PMA . lock ( ) . insert_range ( r) ;
41
- } else {
42
- inserted += GLOBAL_PMA . lock ( ) . insert_range ( mblock. get_range ( ) ) ;
36
+ let mut r = mblock. get_range ( ) ;
37
+ if mblock. get_range ( ) . contains ( & pmap_kernel_end ( ) ) {
38
+ r. start = pmap_kernel_end ( ) ;
43
39
}
44
- println ! (
45
- "pma init: {:#X}KiB free memory, {:#X} pages inserted from block {:#X?}" ,
46
- inserted * 0x4 ,
47
- inserted,
48
- mblock,
49
- ) ;
40
+ inserted += GLOBAL_PMA . lock ( ) . insert_range ( & r) ;
50
41
}
42
+
43
+ println ! (
44
+ "pma init: kernel mapped at {:#X} - {:#X}" ,
45
+ pmap_kernel_start( ) ,
46
+ pmap_kernel_end( )
47
+ ) ;
48
+ println ! (
49
+ "pma init: {:#X}KiB free memory, {:#X} pages" ,
50
+ inserted * 0x4 ,
51
+ inserted,
52
+ ) ;
51
53
}
Original file line number Diff line number Diff line change 1
1
use crate :: defs:: * ;
2
2
use crate :: io:: * ;
3
3
use crate :: machine:: multiboot:: MultibootMmap ;
4
+ use core:: ops:: Range ;
4
5
use core:: slice;
5
6
6
7
extern "C" {
@@ -51,18 +52,18 @@ impl PageStackAllocator {
51
52
Some ( self . page_stack [ self . head ] )
52
53
}
53
54
54
- /// 4k page only
55
- pub fn insert_range ( & mut self , r : Range ) -> u64 {
55
+ /// 4k page only?
56
+ pub fn insert_range ( & mut self , r : & Range < u64 > ) -> u64 {
57
+ // r.contains(&1);
56
58
let mut inserted = 0 ;
57
- let mut page = roundup_4k ( r. addr ) ;
59
+ let mut page = roundup_4k ( r. start ) ;
58
60
loop {
59
- if !r. contains ( page) {
61
+ if !r. contains ( & page) {
60
62
break ;
61
63
}
62
64
if !self . free_page ( page) {
63
65
break ;
64
66
} else {
65
- println ! ( "inserted: {:#X}" , page) ;
66
67
inserted += 1 ;
67
68
}
68
69
page += 0x1000 ;
You can’t perform that action at this time.
0 commit comments