Page 1 of 1

VirtualBox int 13h - Critical Error

Posted: Sat Feb 06, 2016 9:06 am
by C00LD0WN
Hey guys,

I'm making my first O.S. mixing C and Assembly. Right now I'm doing my disk.asm file to read a sector from HDD, but when I try to run it on VirtualBox, it just returns a critical error and stops working.

Code: Select all

_readd:
 sti
 ;xor ah,ah
 ;int 13h
 mov ah, 02h
 mov al, 2
 mov ch, 0
 mov dl, 80h
 mov cl, 1
 int 13h
 jc _fail
 ret
 cli
That's my disk.asm

Code: Select all

 extern int _readd();
 
 void kmain()
 {
       int ret = _readd();
       PrintString("Done!");
       readStr();
 }
That's my kernel.c file.

int 13h will return CF if there's an error, AH and AL. Could this be because of that?

Re: VirtualBox int 13h - Critical Error

Posted: Sat Feb 06, 2016 9:18 am
by iansjack
Where are "PrintString()" and "readStr()" defined?
Are you compiling your C code as 16-bit code?
What C compiler are you using?
What is the "critical error" message?
You haven't initialized your segment registers.
You haven't defined a stack.
You are jumping to a label "_fail" that isn't defined.

Re: VirtualBox int 13h - Critical Error

Posted: Sat Feb 06, 2016 9:32 am
by C00LD0WN
PrintString() is defined in my screen.h (working fine, I have tried it)
readStr() is defined in my kb.h (Working fine too)
I'm using gcc. I'm compiling it using a VB machine with ubuntu.
_fail is define, it will just cli and ret

You want me to post here the log file content?

Re: VirtualBox int 13h - Critical Error

Posted: Sat Feb 06, 2016 9:34 am
by iansjack
How are you getting gcc to emit 16-bit, real mode code?
What about your stack?

Re: VirtualBox int 13h - Critical Error

Posted: Sat Feb 06, 2016 9:44 am
by C00LD0WN
I'm not. It is compiling 32-bit. Do I need to use 16-bit?

The command I'm running is:

gcc -m32 -c kernel.c -o kc.o

Can't I use bios interrupts with 32-bit assembly?

If EAX is part of 32 bit assembly and AX is 16-bit assembly wich can use AH and AL registers why can't 32 bit C and assembly run those registers too?

My stack will be ESP register, I'll call the stack through esp.

Re: VirtualBox int 13h - Critical Error

Posted: Sat Feb 06, 2016 9:54 am
by SpyderTL
C00LD0WN wrote:I'm not. It is compiling 32-bit. Do I need to use 16-bit?

The command I'm running is:

gcc -m32 -c kernel.c -o kc.o

Can't I use bios interrupts with 32-bit assembly?
The short answer is, No.

The long answer is Noooooooooooooooooo!

Actually there are a few ways to use the BIOS in 32-bit, but none of them can be implemented in less than a week or two.

Most osdevers just communicate directly with hardware once they switch to 32-bit mode.

Re: VirtualBox int 13h - Critical Error

Posted: Sat Feb 06, 2016 9:57 am
by C00LD0WN
So, I need to compile my kernel.c 16-bit mode?

Re: VirtualBox int 13h - Critical Error

Posted: Sat Feb 06, 2016 12:14 pm
by BrightLight
In protected mode, there are several ways to call the BIOS:
  • Switch back to real mode temporarily to call the BIOS.
  • Set up a v8086 monitor.
  • Use an x86 emulator.
All three of them are very bad choices for disk access. IMHO, these should only be used for VESA graphics modes.
Read this wiki: ATA for more information on ATA. ATA is old actually, but is an easier starting point than AHCI and NVMe.

Re: VirtualBox int 13h - Critical Error

Posted: Sat Feb 06, 2016 12:33 pm
by C00LD0WN
I made it work using the ports referred in this topic