Problems with E820 Memory Detection
Posted: Thu Jul 14, 2005 11:00 pm
I have spent the last couple of days trying everything I could think of to get memory detection through E820 to work. I have seen the recent thread on memory detection and, although that has helped to get me on the right path, I have run into problems. I have cobbled together some code after looking through various resources, but I cannot get it to work correctly.
Here is my code from inside my bootloader to get the memory map:
I am trying to store the memory map at 0x500 so I can access it from the kernel. From within the kernel, I am parsing the map with this code:
This code doesn't work for me and has only printed out bogus information about the memory. I really am lost and fairly frustrated. I have no idea how to fix this because, to me, it seems correct. Any help and guidance would be greatly appreciated at this point. Thanks for your time.
Here is my code from inside my bootloader to get the memory map:
Code: Select all
xor ax,ax
mov es, ax
mov ds, ax
mov di,0x500
xor ebx,ebx
get_e820:
mov eax,0x0000E820
mov ecx,0x14
mov edx,0x534D4150
int 0x15
jc e820_end
cmp eax,0x534D4150
jne e820_end
add di,20
cmp ebx,0
jne get_e820
e820_end:
Code: Select all
struct e820entry
{
unsigned long baseAddrLow;
unsigned long baseAddrHigh;
unsigned long lengthLow;
unsigned long lengthHigh;
unsigned long type;
} __attribute__((packed));
unsigned long reservedmemory;
unsigned long useablememory;
void getE820Map()
{
unsigned long maplength;
struct e820entry *mem = (struct e820entry *)0x500;
unsigned long a;
puts("\nAddress\tLength\tType\n");
asm volatile("movl %%edi,%0" : "=r" (maplength) );
for(a=0;a<((maplength-0x500)/20);a++)
{
puti(mem[a].baseAddrLow);
putch('\t');
puti(mem[a].lengthLow);
putch('\t');
puti(mem[a].type);
putch('\n');
puti(maplength); /* extra */
putch('\n');
timer_wait(100); /* end extra */
if(mem[a].type==1)
{
useablememory += mem[a].lengthLow;
}
else
{
reservedmemory += mem[a].lengthLow;
}
}
puts("[RAM] Reserved: ");
puti(reservedmemory/1024);
puts("KB Usable: ");
puti(useablememory/1024);
puts("KB Total Memory: ");
puti((reservedmemory+useablememory)/(1024*1024));
puts("MB\n");
}