BIOS INT 0x15 0xe820 Memory detection causes triple fault

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
mikazo
Posts: 3
Joined: Fri Mar 20, 2015 2:50 pm

BIOS INT 0x15 0xe820 Memory detection causes triple fault

Post 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!
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post by iansjack »

And how are you running the C code? Are you sure that it is running in real mode?
mikazo
Posts: 3
Joined: Fri Mar 20, 2015 2:50 pm

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

Post 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.
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post by iansjack »

The Bare Bones tutorial runs in protected mode. That explains your triple fault.
mikazo
Posts: 3
Joined: Fri Mar 20, 2015 2:50 pm

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

Post 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?
madanra
Member
Member
Posts: 149
Joined: Mon Sep 07, 2009 12:01 pm

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

Post 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.
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post 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.
User avatar
bace
Member
Member
Posts: 34
Joined: Fri Jan 16, 2015 10:41 am
Location: United Kingdom

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

Post 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?
"for example, turning off the system’s power through the movement of a large red switch" - the Advanced Configuration and Power Interface Specification
User avatar
iansjack
Member
Member
Posts: 4707
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

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

Post by iansjack »

*** Deleted ***
Last edited by iansjack on Fri Mar 20, 2015 4:03 pm, edited 1 time in total.
User avatar
bace
Member
Member
Posts: 34
Joined: Fri Jan 16, 2015 10:41 am
Location: United Kingdom

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

Post by bace »

Whoops!
Just tried it. Almost got there in time to edit it :lol:
"for example, turning off the system’s power through the movement of a large red switch" - the Advanced Configuration and Power Interface Specification
Post Reply