@@ -104,8 +104,7 @@ void OS::start(uint32_t boot_magic, uint32_t boot_addr)
104104 // Print a fancy header
105105 CAPTION (" #include<os> // Literally" );
106106
107- void * esp = get_cpu_esp ();
108- MYINFO (" Stack: %p" , esp);
107+ MYINFO (" Stack: %p" , get_cpu_esp ());
109108 MYINFO (" Boot magic: 0x%x, addr: 0x%x" , boot_magic, boot_addr);
110109
111110 // / STATMAN ///
@@ -130,7 +129,7 @@ void OS::start(uint32_t boot_magic, uint32_t boot_addr)
130129
131130 OS::legacy_boot ();
132131 }
133- Expects (OS::memory_end_ != 0 );
132+ assert (OS::memory_end_ != 0 );
134133 // Give the rest of physical memory to heap
135134 OS::heap_max_ = OS::memory_end_;
136135
@@ -149,13 +148,13 @@ void OS::start(uint32_t boot_magic, uint32_t boot_addr)
149148 memmap.assign_range ({(uintptr_t )&_LOAD_START_, (uintptr_t )&_end - 1 ,
150149 " ELF" , " Your service binary including OS" });
151150
152- Expects (::heap_begin and heap_max_);
151+ assert (::heap_begin != 0x0 and OS:: heap_max_ != 0x0 );
153152 // @note for security we don't want to expose this
154153 memmap.assign_range ({(uintptr_t )&_end, ::heap_begin - 1 ,
155154 " Pre-heap" , " Heap randomization area" });
156155
157156 uintptr_t span_max = std::numeric_limits<std::ptrdiff_t >::max ();
158- uintptr_t heap_range_max_ = std::min (span_max, heap_max_);
157+ uintptr_t heap_range_max_ = std::min (span_max, OS:: heap_max_- 1 );
159158
160159 MYINFO (" Assigning heap" );
161160 memmap.assign_range ({::heap_begin, heap_range_max_,
@@ -196,14 +195,17 @@ void OS::legacy_boot()
196195{
197196 // Fetch CMOS memory info (unfortunately this is maximally 10^16 kb)
198197 auto mem = hw::CMOS::meminfo ();
199- // uintptr_t low_memory_size = mem.base.total * 1024;
200- INFO2 (" * Low memory: %i Kib" , mem.base .total );
201-
202- uintptr_t high_memory_size = mem.extended .total * 1024 ;
203- INFO2 (" * High memory (from cmos): %i Kib" , mem.extended .total );
198+ if (OS::memory_end_ == 0 )
199+ {
200+ // uintptr_t low_memory_size = mem.base.total * 1024;
201+ INFO2 (" * Low memory: %i Kib" , mem.base .total );
202+
203+ uintptr_t high_memory_size = mem.extended .total * 1024 ;
204+ INFO2 (" * High memory (from cmos): %i Kib" , mem.extended .total );
205+ OS::memory_end_ = 0x100000 + high_memory_size;
206+ }
204207
205208 auto & memmap = memory_map ();
206-
207209 // No guarantees without multiboot, but we assume standard memory layout
208210 memmap.assign_range ({0x0009FC00 , 0x0009FFFF ,
209211 " EBDA" , " Extended BIOS data area" });
@@ -214,11 +216,12 @@ void OS::legacy_boot()
214216 uintptr_t addr_max = std::numeric_limits<std::size_t >::max ();
215217 uintptr_t span_max = std::numeric_limits<std::ptrdiff_t >::max ();
216218
217- uintptr_t unavail_start = 0x100000 + high_memory_size ;
219+ uintptr_t unavail_start = OS::memory_end_ ;
218220 size_t interval = std::min (span_max, addr_max - unavail_start) - 1 ;
219221 uintptr_t unavail_end = unavail_start + interval;
220222
221- while (unavail_end < addr_max){
223+ while (unavail_end < addr_max)
224+ {
222225 INFO2 (" * Unavailable memory: 0x%" PRIxPTR" - 0x%" PRIxPTR, unavail_start, unavail_end);
223226 memmap.assign_range ({unavail_start, unavail_end,
224227 " N/A" , " Reserved / outside physical range" });
0 commit comments