@@ -10,6 +10,7 @@ use bootloader::{
1010} ;
1111use core:: {
1212 arch:: { asm, global_asm} ,
13+ cmp,
1314 panic:: PanicInfo ,
1415 slice,
1516} ;
@@ -78,16 +79,23 @@ fn bootloader_main(
7879 use bootloader:: binary:: {
7980 bios:: memory_descriptor:: E820MemoryRegion , legacy_memory_region:: LegacyFrameAllocator ,
8081 } ;
82+ const GIGABYTE : u64 = 4096 * 512 * 512 ;
8183
8284 let e820_memory_map = {
8385 let ptr = usize_from ( memory_map_addr. as_u64 ( ) ) as * const E820MemoryRegion ;
8486 unsafe { slice:: from_raw_parts ( ptr, usize_from ( memory_map_entry_count) ) }
8587 } ;
86- let max_phys_addr = e820_memory_map
87- . iter ( )
88- . map ( |r| r. start_addr + r. len )
89- . max ( )
90- . expect ( "no physical memory regions found" ) ;
88+ let max_phys_addr = {
89+ let max = e820_memory_map
90+ . iter ( )
91+ . map ( |r| r. start_addr + r. len )
92+ . max ( )
93+ . expect ( "no physical memory regions found" ) ;
94+ // Don't consider addresses > 4GiB when determining the maximum physical
95+ // address for the bootloader, as we are in protected mode and cannot
96+ // address more than 4 GiB of memory anyway.
97+ cmp:: min ( max, 4 * GIGABYTE )
98+ } ;
9199
92100 let mut frame_allocator = {
93101 let kernel_end = PhysFrame :: containing_address ( kernel_start + kernel_size - 1u64 ) ;
@@ -106,7 +114,7 @@ fn bootloader_main(
106114 // identity-map remaining physical memory (first gigabyte is already identity-mapped)
107115 {
108116 let start_frame: PhysFrame < Size2MiB > =
109- PhysFrame :: containing_address ( PhysAddr :: new ( 4096 * 512 * 512 ) ) ;
117+ PhysFrame :: containing_address ( PhysAddr :: new ( GIGABYTE ) ) ;
110118 let end_frame = PhysFrame :: containing_address ( PhysAddr :: new ( max_phys_addr - 1 ) ) ;
111119 for frame in PhysFrame :: range_inclusive ( start_frame, end_frame) {
112120 unsafe {
0 commit comments