Page 1 of 1

BIOS INT 0x15 0xe820 Memory detection causes triple fault

Posted: Fri Mar 20, 2015 2:56 pm
by mikazo
Hi everyone,

I started implementing my own OS a couple days ago and this is my first post on the forum!

I've been stuck most of those days trying to get the INT 0x15 0xe820 memory detection working, as described on the Detecting Memory (x86) wiki page of osdev.org.

I'm using basically the same assembly code as is listed on the page, but no matter what I try, I seem to get a triple fault in both qemu and VirtualBox.

In case it makes any difference, here is the exact code I've been using. I commented out the 'int 0x15' instruction and the machine doesn't triple fault, so I know it's something to do with how I'm calling the interrupt function. I call the following code from C code in a separate file. I left the rest of the assembly code out because I have it commented out for now, until I can get at least one interrupt call to work.

After much Googling, I can't seem to figure out what I'm doing wrong! Any help would be appreciated.

Code: Select all

.text
detectMemory:
    mov ebx, 0x100
    mov es, ebx
    xor edi, edi
    xor ebx, ebx        # ebx must be 0 to start
    xor ebp, ebp      # keep an entry count in ebp
    mov edx, 0x534D4150    # Place "SMAP" into edx
    mov eax, 0xe820
    mov dword ptr [es:[di] + 20], 1   # force a valid ACPI 3.X entry
    mov ecx, 24     # ask for 24 bytes
    int 0x15   # TRIPLE FAULT!

Re: BIOS INT 0x15 0xe820 Memory detection causes triple faul

Posted: Fri Mar 20, 2015 3:02 pm
by iansjack
And how are you running the C code? Are you sure that it is running in real mode?

Re: BIOS INT 0x15 0xe820 Memory detection causes triple faul

Posted: Fri Mar 20, 2015 3:10 pm
by mikazo
I was just about to edit my original post when I saw your reply. I am running in real mode, as I have not implemented any switch to protected mode. The rest of my OS is basically what is described on the Bare Bones wiki page. My OS really doesn't do anything else yet. The first things it does are print some text and then try to detect memory as described above.

Re: BIOS INT 0x15 0xe820 Memory detection causes triple faul

Posted: Fri Mar 20, 2015 3:13 pm
by iansjack
The Bare Bones tutorial runs in protected mode. That explains your triple fault.

Re: BIOS INT 0x15 0xe820 Memory detection causes triple faul

Posted: Fri Mar 20, 2015 3:26 pm
by mikazo
I read the Bare Bones page more closely and didn't see anything about real mode or protected mode. (EDIT: oops, yes it does mention starting in protected mode.)

I did see that it mentioned looking at the GNU Multiboot Machine State documentation. So I looked that up (https://www.gnu.org/software/grub/manua ... state.html) and saw the following:
‘GDTR’
Even though the segment registers are set up as described above, the ‘GDTR’ may be invalid, so the OS image must not load any segment registers (even just reloading the same values!) until it sets up its own ‘GDT’.

‘IDTR’
The OS image must leave interrupts disabled until it sets up its own IDT.
Does this mean that I need to set up a GDT and IDT before I can call the e820 function?

Re: BIOS INT 0x15 0xe820 Memory detection causes triple faul

Posted: Fri Mar 20, 2015 3:36 pm
by madanra
No; you have to be in real mode. If you're using GRUB, it provides a memory map, so you don't need to use the BIOS to get it.

Re: BIOS INT 0x15 0xe820 Memory detection causes triple faul

Posted: Fri Mar 20, 2015 3:40 pm
by iansjack
mikazo wrote:Does this mean that I need to set up a GDT and IDT before I can call the e820 function?
You cannot call any BIOS functions from protected mode. (Not quite true, but near enough for your purposes.)

Forget the BIOS; we're not in real mode any more, Toto.

Re: BIOS INT 0x15 0xe820 Memory detection causes triple faul

Posted: Fri Mar 20, 2015 3:50 pm
by bace
mikazo wrote:

Code: Select all

    mov ebx, 0x100
    mov es, ebx
That's a pretty good sign you're in protected mode. Do you really know the x86 architecture well enough to write an OS for it?

Re: BIOS INT 0x15 0xe820 Memory detection causes triple faul

Posted: Fri Mar 20, 2015 3:59 pm
by iansjack
*** Deleted ***

Re: BIOS INT 0x15 0xe820 Memory detection causes triple faul

Posted: Fri Mar 20, 2015 4:01 pm
by bace
Whoops!
Just tried it. Almost got there in time to edit it :lol: