Memory detection in protected mode?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
alaroldai
Posts: 19
Joined: Sat May 07, 2011 6:34 am

Memory detection in protected mode?

Post by alaroldai »

Hey there, I'm at the awkward point where although I understand memory allocation principles (free-list, best/first-fit algorithms etc), I'm trying to work out how to implement it without accidentally writing into some memory-mapped device's I/O port. So detecting a memory map for the machine would seem like a good idea. However, quoting the wiki:
One of the most vital pieces of information that an OS needs in order to initialize itself is a map of the available RAM on a machine. Fundamentally, the best way (and really the only way) an OS can get that information is by using the BIOS.
and
Unfortunately, in Protected mode, almost all BIOS functions become unavailable
Does this mean that there is no reliable way to get a map of the available RAM from Protected Mode?
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: Memory detection in protected mode?

Post by bluemoon »

If you choose to get memory map from BIOS, you should do it in real mode (in early stage of boot process), or if you use things like GRUB it will do it for you.
However, I'm not sure on UEFI, which may support protected mode/long mode interfaces.
Cognition
Member
Member
Posts: 191
Joined: Tue Apr 15, 2008 6:37 pm
Location: Gotham, Batmanistan

Re: Memory detection in protected mode?

Post by Cognition »

It means you need to retrieve a memory map before entering protected mode on a BIOS based system. Usually the memory map is retrieved by the bootloader and passed to the kernel in some fashion. The bootloader itself should also parse the memory map to make sure it can load the kernel in the first place.
Reserved for OEM use.
Antti
Member
Member
Posts: 923
Joined: Thu Jul 05, 2012 5:12 am
Location: Finland

Re: Memory detection in protected mode?

Post by Antti »

bluemoon wrote:I'm not sure on UEFI, which may support protected mode/long mode interfaces
It supports only protected mode / long mode interfaces. Most of the services are available as Boot Services. It means that you cannot use them after control is transferred to your OS. There are also Runtime Services.

When it comes to the memory detection, it is a Boot Service. The OS loader (UEFI program) must handle it.
Post Reply