BIOS interrupts just make my system crash...

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
shervingav
Posts: 11
Joined: Sun May 11, 2014 6:19 am
Location: Iran

BIOS interrupts just make my system crash...

Post 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!
"Sometimes it is the people who no one imagines anything of, who do the things that no one can IMAGINE."
_Alan Turing
shervingav
Posts: 11
Joined: Sun May 11, 2014 6:19 am
Location: Iran

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

Post by shervingav »

The link you provided didnt help but thanks.
"Sometimes it is the people who no one imagines anything of, who do the things that no one can IMAGINE."
_Alan Turing
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post 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?"
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
shervingav
Posts: 11
Joined: Sun May 11, 2014 6:19 am
Location: Iran

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

Post 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.
"Sometimes it is the people who no one imagines anything of, who do the things that no one can IMAGINE."
_Alan Turing
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

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

Post by Combuster »

"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
shervingav
Posts: 11
Joined: Sun May 11, 2014 6:19 am
Location: Iran

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

Post by shervingav »

Thanks.
"Sometimes it is the people who no one imagines anything of, who do the things that no one can IMAGINE."
_Alan Turing
User avatar
TightCoderEx
Member
Member
Posts: 90
Joined: Sun Jan 13, 2013 6:24 pm
Location: Grande Prairie AB

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

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

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

Post 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.
Post Reply