memory map from bios

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
Bietje
Member
Member
Posts: 100
Joined: Wed Apr 20, 2011 6:57 am

memory map from bios

Post by Bietje »

Hi,

At the moment I use bios interrupt 0x15/0xe820 to get a nice memory map for multiboot compatibility. But what if that interrupt fails..? Then I should use bios int 0x12 icw 0x15/0x801.. But how am I going to make a nice multiboot structure of the bunch information those interrupts returned?

-- Bietje
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: memory map from bios

Post by bluemoon »

Think about your range of target audience before adding support to legacy machines.
According to the wiki for the E820 function:
This function is available on all PCs built since 2002, and on most existing PCs before then. It is the only BIOS function that can detect memory areas above 4G. It is meant to be the ultimate memory detection BIOS function.
IMO if that fail, it is totally acceptable to just panic.
If you want to try other method anyway, take a look at http://wiki.osdev.org/Detecting_Memory_(x86)
Bietje wrote:But how am I going to make a nice multiboot structure of the bunch information those interrupts returned?
What so difficult to put information into a data structure?
Bietje
Member
Member
Posts: 100
Joined: Wed Apr 20, 2011 6:57 am

Re: memory map from bios

Post by Bietje »

bluemoon wrote:
Bietje wrote:But how am I going to make a nice multiboot structure of the bunch information those interrupts returned?
What so difficult to put information into a data structure?
Nothing. But maby I worded my question wrong.. I don't really understand what the exact output is of 0x15/0xe801.
This function has been around since about 1994, so all systems from after then up to now should have this function. It is built to handle the 15M memory hole, but stops at the next hole / memory mapped device / reserved area above that. That is, it is only designed to handle contiguous memory above 16M.
Typical Output:
AX = CX = extended memory between 1M and 16M, in K (max 3C00h = 15MB)
BX = DX = extended memory above 16M, in 64K blocks
What I understand is that it returns a number representing the extended (??) memory between 1m and 16m and the extended (??) memory above 16m.

So my problem was how do I fill an entry/more entries with just that information?
Entry struct:

Code: Select all

mm_entry:
  dd 0    ; size
  dq 0    ; base address
  dq 0    ; length
  dd 0    ; type
Bietje
User avatar
bluemoon
Member
Member
Posts: 1761
Joined: Wed Dec 01, 2010 3:41 am
Location: Hong Kong

Re: memory map from bios

Post by bluemoon »

An entry made with INT12 & E801 may look like this:

Code: Select all

Low = INT12 to detect low memory
Mid = extended memory between 1M and 16M
High = extended memory above 16M

Base Address       | Length             | Type
0x0000000000000000 | Low | Free Memory (1)
Low | 1M - Low | Reserved Memory
0x0000000000100000 | Mid  | Free Memory between 1M and 16M
0x0000000001000000 | High | Free Memory above 16M

Translate into your structure:
entry[0].size = 20;  // I guess size means the field size return by E820?
entry[0].base = 0;
entry[0].length = Low;
entry[0].type = kFree;

entry[1].size = 20;
entry[1].base = Low;
entry[1].length = 1M - Low;
entry[1].type = kReserved;

entry[2].size = 20;
entry[2].base = 1M;
entry[2].length = Mid;
entry[2].type = kFree;

entry[3].size = 20;
entry[3].base = 16M;
entry[3].length = High;
entry[3].type = kFree;

Bietje
Member
Member
Posts: 100
Joined: Wed Apr 20, 2011 6:57 am

Re: memory map from bios

Post by Bietje »

Aaah! Great, thank you! I will try to work that out now.
Bietje
Member
Member
Posts: 100
Joined: Wed Apr 20, 2011 6:57 am

Re: memory map from bios

Post by Bietje »

Is the type field just an integer?
  • Type 1: Usable (normal) RAM
    Type 2: Reserved - unusable
    Type 3: ACPI reclaimable memory
    Type 4: ACPI NVS memory
    Type 5: Area containing bad memory
Where a 1 represents type 1, 2 type 2, etc.. Or is it a bit more complicated?
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re: memory map from bios

Post by Brendan »

Hi,
Bietje wrote:Is the type field just an integer?
I'd consider it a 32-bit unsigned integer or a "uint32_t" (not an "int" or a "long" or a "short" or a "size_t" or....).


Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply