Page 1 of 1

BIOS interrupts just make my system crash...

Posted: Sat May 02, 2015 1:59 am
by shervingav
Hi all,

i am trying to read the memory map using "int 15h" but every time that the int instruction is being executed, my OS crashes.
can anyone help me with this?
the crashing always happens when i use the int instruction in real mode before setting the IDT.
for example:

Code: Select all

_start: ;this is the point where my code starts executing
    mov esp, _temp_stack  ;setup temp stack
    jmp detect_ram ;Get mem map ----->CRASH<-----
    cli
    extern install ;the function for setting up GDT, IDT, Pmode, ... 
    call install
ret

extern mmap ;the data structure for ram entries
extern ent_cnt ;the number of entries
global detect_ram
detect_ram:
    xor ebx, ebx
    xor bp, bp
    mov edx, 0x534D4150
    mov eax, 0xe820
    mov ecx, 24
    mov di, [mmap]
    mov [es:di + 20], dword 1
    int 15h ; ------------------------------> THE SYSTEM CRASHES HERE
    jc short .failed
    mov edx, 0x0534D4150
    cmp eax, edx
    jne short .failed
    test ebx, ebx
    je short .failed
    jmp short .jmpin
.e820lp:
	mov eax, 0xe820
	mov [es:di + 20], dword 1
	mov ecx, 24
	int 15h
	jc short .e820f
	mov edx, 0x0534D4150
.jmpin:
	jcxz .skipent
	cmp cl, 20
	jbe short .notext
	test byte [es:di + 20], 1
	je short .skipent
.notext:
	mov ecx, [es:di + 8]
	or ecx, [es:di + 12]
	jz .skipent
	inc bp
	add di, 24
.skipent:
	test ebx, ebx
	jne short .e820lp
.e820f:
	mov [ent_cnt], bp
	clc
	ret
.failed:
	stc
	ret

This is my code and it crashes everytime!

Re: BIOS interrupts just make my system crash...

Posted: Sat May 02, 2015 2:31 am
by Octocontrabass

Re: BIOS interrupts just make my system crash...

Posted: Sat May 02, 2015 2:49 am
by shervingav
The link you provided didnt help but thanks.

Re: BIOS interrupts just make my system crash...

Posted: Sat May 02, 2015 3:14 am
by Combuster
If you are actually in real mode like you claim you are, then there certainly are a few items in the bootloader article that apply. But by the looks of your code, everything but the int 0x15 code is written like it's not meant to be executed in real mode, but protected mode instead, and it's very likely you made a fundamental design error this way. For that reason I can't point out any single line as a bug because any line qualifies for requiring a rewrite depending on the reasoning you put behind it.

The solution to your problem can go two ways: either you rewrite this to run completely in protected mode, and as a consequence of that you're far too late to get your own memory map and you should be grabbing the one from GRUB instead. Otherwise, you rewrite it for real mode properly, drop any use of a separate linker, any C code you have attached, and write a proper (2-stage) bootloader with the proper 16-bit registers by hand.



P.S. Saying things like "It crashes" or "it didn't help" are very unspecific and unhelpful responses. In the future you'll have to elaborate on them because people are unlikely to spend another post asking "what crashes in what way, what do you see exactly?" and "why didn't it help?"

Re: BIOS interrupts just make my system crash...

Posted: Sat May 02, 2015 3:20 am
by shervingav
How can i get memory map from grub??
Combuster wrote: P.S. Saying things like "It crashes" or "it didn't help" are very unspecific and unhelpful responses. In the future you'll have to elaborate on them because people are unlikely to spend another post asking "what crashes in what way, what do you see exactly?" and "why didn't it help?"
Your right, ill try to explain more.

Re: BIOS interrupts just make my system crash...

Posted: Sat May 02, 2015 3:26 am
by Combuster

Re: BIOS interrupts just make my system crash...

Posted: Sat May 02, 2015 3:46 am
by shervingav
Thanks.

Re: BIOS interrupts just make my system crash...

Posted: Sat May 02, 2015 10:04 am
by TightCoderEx
Everything in your code is legitimate real mode code and there is nothing to suggest otherwise.

It is not a good idea to alter stack pointer without disabling interrupts.

The only thing I would question is the contents of ES:DI that is the pointer to E820 map, so doing a register dump
just before "int 15h" would be the best way to determine if everything is as it should be.

I've tested the snippet from detect_ram in BOCH's and it returns the same as my version.

Re: BIOS interrupts just make my system crash...

Posted: Sat May 02, 2015 12:58 pm
by iansjack
No-one seems to have asked an obvious question yet. How are you running this code? Are you using a custom bootloader that you haven't shown us (in which case the answer is likely to be there) or are you using GRUB (in which case the answer is obvious). In other words, I suspect that the error is in code that you haven't shown us.