load from disk with int 0x13

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
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

load from disk with int 0x13

Post by sancho1980 »

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: Select all

  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???
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: load from disk with int 0x13

Post by qw »

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

Re: load from disk with int 0x13

Post by sancho1980 »

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??
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: load from disk with int 0x13

Post by qw »

sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

Re: load from disk with int 0x13

Post by sancho1980 »

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?
User avatar
kmtdk
Member
Member
Posts: 263
Joined: Sat May 17, 2008 4:05 am
Location: Cyperspace, Denmark
Contact:

Re: load from disk with int 0x13

Post by kmtdk »

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: Select all

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.
User avatar
bewing
Member
Member
Posts: 1401
Joined: Wed Feb 07, 2007 1:45 pm
Location: Eugene, OR, US

Re: load from disk with int 0x13

Post by bewing »

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?
User avatar
qw
Member
Member
Posts: 792
Joined: Mon Jan 26, 2009 2:48 am

Re: load from disk with int 0x13

Post by qw »

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.
sancho1980
Member
Member
Posts: 199
Joined: Fri Jul 13, 2007 6:37 am
Location: Stuttgart/Germany
Contact:

Re: load from disk with int 0x13

Post by sancho1980 »

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: Select all

void doIrq()
{
  doSomething();
}
Suppose this works, I recently added another function call in there like

Code: Select all

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.,..
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: load from disk with int 0x13

Post by gerryg400 »

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