VirtualBox int 13h - Critical Error

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
C00LD0WN
Posts: 5
Joined: Sat Feb 06, 2016 8:47 am

VirtualBox int 13h - Critical Error

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

Re: VirtualBox int 13h - Critical Error

Post 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.
C00LD0WN
Posts: 5
Joined: Sat Feb 06, 2016 8:47 am

Re: VirtualBox int 13h - Critical Error

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

Re: VirtualBox int 13h - Critical Error

Post by iansjack »

How are you getting gcc to emit 16-bit, real mode code?
What about your stack?
C00LD0WN
Posts: 5
Joined: Sat Feb 06, 2016 8:47 am

Re: VirtualBox int 13h - Critical Error

Post 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.
User avatar
SpyderTL
Member
Member
Posts: 1074
Joined: Sun Sep 19, 2010 10:05 pm

Re: VirtualBox int 13h - Critical Error

Post 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.
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott
C00LD0WN
Posts: 5
Joined: Sat Feb 06, 2016 8:47 am

Re: VirtualBox int 13h - Critical Error

Post by C00LD0WN »

So, I need to compile my kernel.c 16-bit mode?
User avatar
BrightLight
Member
Member
Posts: 901
Joined: Sat Dec 27, 2014 9:11 am
Location: Maadi, Cairo, Egypt
Contact:

Re: VirtualBox int 13h - Critical Error

Post 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.
You know your OS is advanced when you stop using the Intel programming guide as a reference.
C00LD0WN
Posts: 5
Joined: Sat Feb 06, 2016 8:47 am

Re: VirtualBox int 13h - Critical Error

Post by C00LD0WN »

I made it work using the ports referred in this topic
Post Reply