Page 1 of 1

memory map from bios

Posted: Thu Jun 02, 2011 5:03 am
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

Re: memory map from bios

Posted: Thu Jun 02, 2011 5:59 am
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?

Re: memory map from bios

Posted: Thu Jun 02, 2011 8:34 am
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

Re: memory map from bios

Posted: Thu Jun 02, 2011 4:35 pm
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;


Re: memory map from bios

Posted: Fri Jun 03, 2011 5:09 am
by Bietje
Aaah! Great, thank you! I will try to work that out now.

Re: memory map from bios

Posted: Fri Jun 03, 2011 6:58 am
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?

Re: memory map from bios

Posted: Fri Jun 03, 2011 7:09 am
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