Skip to content

Commit 35683dd

Browse files
committed
Start using the memory map GRUB gave us to determine how much RAM we can use. (We're still hardcoding a lot of RAM at the beginning though.)
1 parent 041bbef commit 35683dd

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

MyOS_1/paging.h

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,32 @@ inline void Paging_Enable(multiboot_info *multibootInfo)
126126

127127
// TEMPTEMP: put page directories between 16 - 20 megs
128128
nextPageDirectory = FOUR_MEGABYTES * 4;
129+
130+
// Walk through the mem map grub gave us
131+
// TODO: Assert that grub gave us a memory map
132+
// TODO: Don't assume we have memory at the beginning of RAM
133+
// TODO: Use all the entries we get from GRUB
134+
multiboot_mmap_entry *entry = (multiboot_mmap_entry *)multibootInfo->mmap_addr;
135+
136+
// examine each mmap entry
137+
for (uint32_t offset = 0; offset <= multibootInfo->mmap_length && entry->size; offset += entry->size + 4)
138+
{
139+
if (entry->type == MULTIBOOT_MEMORY_AVAILABLE)
140+
{
141+
// If the next page of memory we're assuming we can use resides here
142+
if (pagingNextAvailableMemory >= entry->addr && pagingNextAvailableMemory < (entry->addr + entry->len))
143+
{
144+
// determine how many pages we really have available
145+
uint64_t addrEnd = entry->addr + entry->len;
146+
uint64_t bytesAvailable = addrEnd - pagingNextAvailableMemory;
147+
paging4MPagesAvailable = bytesAvailable / FOUR_MEGABYTES;
148+
return;
149+
}
150+
}
151+
152+
// advance pointer to next entry
153+
entry = (multiboot_mmap_entry*)((uint32_t)entry + entry->size + 4);
154+
}
129155
}
130156

131157
bool Paging_Print_Page_Table(PAGE_DIRECTORY_ENTRY *thePageDir);

Release/MyOS_1.dll

0 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)