OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 24, 2024 6:44 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: load from disk with int 0x13
PostPosted: Mon May 31, 2010 3:17 pm 
Offline
Member
Member

Joined: Fri Jul 13, 2007 6:37 am
Posts: 199
Location: Stuttgart/Germany
i have written a routine to load my "kernel" into memory, but i think it has a flaw, because the bigger the kernel grows, the more often i get strange crashes at very unexpected moments plus i used the bochs debugging tools and found out that sometimes when i think a certain function is being called, very strange instructions pop up
could someone have a look at my load routine and tell me if theres anything conceptually wrong with it

suppose i want to load N sectors, starting from LBA sector S on floppy into memory location L, then i would do something like this:
Code:
  mov ax, L/010h
  mov es, ax
  mov bx, 0
  mov si, N
  mov cx, S
  mov dh, 0
  call loop_load

loop_load:
  cmp si, 0h
  je end_loop_load
  call loadSector
  dec si
  inc cl
  mov ax, es
  add ax, SECTOR_SIZE/10h ; SECTOR_SIZE defined as 512
  mov es, ax
  jmp loop_load
end_loop_load:
  ret

align 2
loadSector:
  cmp cl, MAXSECTOR + 1 ; MAXSECTOR defined as 18
  jne do_load_sector
  mov cl, MINSECTOR ; MINSECTOR defined as 1
  inc dh
  cmp dh, MAXHEAD + 1 ; MAXHEAD defined as 1
  jne do_load_sector
  mov dh, MINHEAD ; MINHEAD defined as 1
  inc ch
do_load_sector:
  mov ah, 02h
  mov al, 1
  int 13h
  jc lderr
  ret


any thing wrong with this???

_________________
www.com-eu-nication.eu


Top
 Profile  
 
 Post subject: Re: load from disk with int 0x13
PostPosted: Mon May 31, 2010 4:16 pm 
Offline
Member
Member
User avatar

Joined: Mon Jan 26, 2009 2:48 am
Posts: 792
Look what happens when "loop_load" returns. Also, the LBA to CHS translation is funny.


Top
 Profile  
 
 Post subject: Re: load from disk with int 0x13
PostPosted: Tue Jun 01, 2010 12:16 am 
Offline
Member
Member

Joined: Fri Jul 13, 2007 6:37 am
Posts: 199
Location: Stuttgart/Germany
Hobbes wrote:
Look what happens when "loop_load" returns. Also, the LBA to CHS translation is funny.


Funny or wrong?
Id call it dummy safe..
So no clue??

_________________
www.com-eu-nication.eu


Top
 Profile  
 
 Post subject: Re: load from disk with int 0x13
PostPosted: Tue Jun 01, 2010 3:29 am 
Offline
Member
Member
User avatar

Joined: Mon Jan 26, 2009 2:48 am
Posts: 792
http://en.wikipedia.org/wiki/Logical_block_addressing#Conversion_between_CHS_to_LBA


Top
 Profile  
 
 Post subject: Re: load from disk with int 0x13
PostPosted: Tue Jun 01, 2010 4:27 pm 
Offline
Member
Member

Joined: Fri Jul 13, 2007 6:37 am
Posts: 199
Location: Stuttgart/Germany
Hobbes wrote:


im not sure what youre trying to say with that link
ive looked at it over and over again, and i still cant find any mistake in my loading routine
so i understand you cant find anything obvious either?

_________________
www.com-eu-nication.eu


Top
 Profile  
 
 Post subject: Re: load from disk with int 0x13
PostPosted: Tue Jun 01, 2010 5:56 pm 
Offline
Member
Member
User avatar

Joined: Sat May 17, 2008 4:05 am
Posts: 263
Location: Cyperspace, Denmark
Hi
well, fist thing i see is that you not specifi DL, so check if DL is the drive number.
and are you sure you understand 16 bit adressing fully ?? ; because when you change es with 512, it results in 5120 , (ES:BX)
so instead change bx.
and after int 0x13
use AH, as it contains useful data, and some times the carry gets set, even if there were no problems ( my exprierence), use this:
Code:
int 0x13
cmp ah,0x00
jnz lderr
ret


you can read more on the int 13 here : http://www.ctyme.com/intr/rb-0607.htm

_________________
well, what to say, to much to do in too little space.
when it goes up hill, increase work, when it goes straight, test yourself but when going down, slow down.


Top
 Profile  
 
 Post subject: Re: load from disk with int 0x13
PostPosted: Tue Jun 01, 2010 6:54 pm 
Offline
Member
Member
User avatar

Joined: Wed Feb 07, 2007 1:45 pm
Posts: 1401
Location: Eugene, OR, US
The only thing that I see is if your starting value of 'S' (your "lba") is > 18, then you will get lots of funny data. Are you absolutely sure that your "kernel" starts on cylinder 0, head 0 of the floppy disk?


Top
 Profile  
 
 Post subject: Re: load from disk with int 0x13
PostPosted: Wed Jun 02, 2010 1:01 am 
Offline
Member
Member
User avatar

Joined: Mon Jan 26, 2009 2:48 am
Posts: 792
sancho1980 wrote:
im not sure what youre trying to say with that link
ive looked at it over and over again, and i still cant find any mistake in my loading routine
so i understand you cant find anything obvious either?
You confused me by calling the value of S an LBA. It is not an LBA that you are loading into CX. You are loading a CHS address into DH and CX. Now I know that, "loadSector" looks correct, except that MINHEAD should be 0.


Top
 Profile  
 
 Post subject: Re: load from disk with int 0x13
PostPosted: Wed Jun 02, 2010 4:27 am 
Offline
Member
Member

Joined: Fri Jul 13, 2007 6:37 am
Posts: 199
Location: Stuttgart/Germany
bewing wrote:
The only thing that I see is if your starting value of 'S' (your "lba") is > 18, then you will get lots of funny data. Are you absolutely sure that your "kernel" starts on cylinder 0, head 0 of the floppy disk?


It's not that my kernel doesnt work at all
It's got quite a bit of functionality, and is already over 60k big
But, for example, my generic routine that handles hardware interrupts would look like this

Code:
void doIrq()
{
  doSomething();
}


Suppose this works, I recently added another function call in there like

Code:
void doIrq()
{
  doSomething();
  int a = 3;
  if (a == 2) callMe();
}


This new function callMe() didnt have ANY parameters, doesnt do anything except return straight away and as the example shows has no chance to get called (at that point in time)
But still, it makes my system crash. Everything works fine if I remove this...

So this made me guess/suspect it's gfot something to do with the size of the kernel and how its loaded maybe.,..

_________________
www.com-eu-nication.eu


Top
 Profile  
 
 Post subject: Re: load from disk with int 0x13
PostPosted: Wed Jun 02, 2010 4:49 am 
Offline
Member
Member

Joined: Thu Mar 25, 2010 11:26 pm
Posts: 1801
Location: Melbourne, Australia
Quote:
i have written a routine to load my "kernel" into memory, but i think it has a flaw, because...

When you put the word kernel inside quotation marks it sounds like your kernel is not yet fully featured ;-)

_________________
If a trainstation is where trains stop, what is a workstation ?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 10 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Majestic-12 [Bot] and 207 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group