Talk:Detecting Memory (x86)

From OSDev Wiki
Jump to: navigation, search


Deleting old code

Now that Brendan's manual probing code is here, I'd like to delete the old C manual probing code -- even though "information will be lost".
Bewing 01:26, 22 May 2008 (CDT)

I'd rather not for just that reason :) - Basically you'll be denying everybody that expects to find a sample in C that code. It's not too bad to have a version in both languages really. - Combuster 06:11, 22 May 2008 (CDT)

Updated the low memory snippet

The old low memory detection snippet using INT 0x12; AH = 0x00 assumed that AH would be set to 0x80 or 0x86 when something went wrong, I don't think this can be true as RBIL doesn't state this and as AX itself should contain the size. If somebody doesn't like my assembly style, then he/she's free to change it. If someone doesn't agree with me on the 0x80/0x86 part, then could he/she please explain why.

--Stephanvanschaik 20:32, 19 February 2010 (UTC)


I'm having a bit of a hard time understanding the workings of e820, and I've had problems finding an answer elsewhere on the internet which assumes you already understand this bit. It's pretty clear that e820 is a real-mode only call; however, you need to set register EDX with the appropriate magic number. Whereas all other registers can have their lower 16 bits set fine, the magic number is a 32-bit value, and EDX is not addressable with 16-bit code. How does one run real mode with 32-bit code and addressing? Surgo 19:52, 20 January 2011 (UTC)

You are making the wrong assumption here: you can access all 32-bit GPRs, all 80-bits FPRs, and even the 64 and 128-bit vector registers with 16-bit code in real mode, EDX being no exception. You are even required to use a 32-bit register to enter protected mode as CR0 is 32 bits as well. The only thing real mode forbids is using segment offsets over 64KB for backwards compatibility and even that can be disabled. Your assembler will take care of the rest and insert the correct opcodes for you. - Combuster 22:55, 20 January 2011 (UTC)
Wow, that was a pretty boneheaded mistake. I think misreading some assembler output caused my misconception. Thank you! Surgo 23:05, 20 January 2011 (UTC)

INT 0x12

The RBIL doesn't say this interrupt returns error, and it's impossible, since this function was there since the very first IBM PC computer, so there was no need to set/reset the carry flag. It's not possible for this function not to be supported. In fact, I had trouble with this and it didn't work for me until I removed the error checking. Unsigned 19:15, 22 August 2015 (CDT)

RBIL does say that different functions are invoked for certain values for AX, so you broke the code there. It also states that it might return the value directly from the BDA, which isn't reserved memory and might have changed. A listing in RBIL does not preclude presence in all emulators either. Maybe the more correct way for your code is to clear carry ahead of time (BIOSes are known to be lacking in that), or defer to E820 anyway when int 0x12 fails. - Combuster 02:56, 23 August 2015 (CDT)

Memory via UEFI

Uefi also supports getting the memory map via FI_BOOT_SERVICES->GetMemoryMap. Would be nice to have an example and explanation.

Personal tools