Detecting Memory (x86): Difference between revisions

Jump to navigation Jump to search
m
Bot: Replace deprecated source tag with syntaxhighlight
[unchecked revision][unchecked revision]
m (Bot: Replace deprecated source tag with syntaxhighlight)
m (Bot: Replace deprecated source tag with syntaxhighlight)
Line 237:
 
Usage:
<sourcesyntaxhighlight lang="c">
unsigned short total;
unsigned char lowmem, highmem;
Line 248:
total = lowmem | highmem << 8;
return total;
</syntaxhighlight>
</source>
 
====E820h====
Line 311:
Taking this into account, our example code would look like the following. Note that if you prefer a version that does not require the multiboot.h header downloaded from the link above, there is a version listed in the code examples section of this article.
 
<sourcesyntaxhighlight lang="c">
 
 
Line 348:
}
}
</syntaxhighlight>
</source>
 
'''WARNING:''' If you downloaded the multiboot header from gnu.org (linked above) you probably got a version which defines the base address and length fields as one 64-bit unsigned integer each, rather than two 32-bit unsigned integers each. [https://forum.osdev.org/viewtopic.php?t=30318 This may cause gcc to pack the structure incorrectly] which can lead to nonsensical values when you try to read it.
Line 453:
Declare the appropriate structure, get the pointer to the first instance, grab whatever address and length information you want, and finally skip to the next memory map instance by adding size+sizeof(mmap->size) to the pointer, because mmap->size does not take itself into account and because GRUB treating base_addr_low as offset 0 in the structure. You must also use mmap_length to make sure you don't overshoot the entire buffer.
 
<sourcesyntaxhighlight lang="c">
typedef struct multiboot_memory_map {
unsigned int size;
Line 475:
...
}
</syntaxhighlight>
</source>
 
===Getting an E820 Memory Map===
Line 534:
 
Sample in C (assuming we are in a bootloader environment, real mode, DS and CS = 0000):
<sourcesyntaxhighlight lang="c">
// running in real mode may require:
__asm__(".code16gcc\n");
Line 592:
}
}
</syntaxhighlight>
</source>
 
===Getting an UEFI Memory Map===
<sourcesyntaxhighlight lang="c">
EFI_STATUS Status;
EFI_MEMORY_DESCRIPTOR *EfiMemoryMap;
Line 641:
EfiEntry = NEXT_MEMORY_DESCRIPTOR (EfiEntry, EfiDescriptorSize);
} while((UINT8*)EfiEntry < (UINT8*)EfiMemoryMap + EfiMemoryMapSize);
</syntaxhighlight>
</source>
 
===Manual Probing in C===
Line 649:
* the assembly language manual probing code that follows this example is better
 
<sourcesyntaxhighlight lang="c">
/*
* void count_memory (void)
Line 724:
outb(0xA1, irq2);
}
</syntaxhighlight>
</source>
 
===Manual Probing in ASM===
Cookies help us deliver our services. By using our services, you agree to our use of cookies.

Navigation menu