Page 1 of 1

load from disk with int 0x13

Posted: Mon May 31, 2010 3:17 pm
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???

Re: load from disk with int 0x13

Posted: Mon May 31, 2010 4:16 pm
by qw
Look what happens when "loop_load" returns. Also, the LBA to CHS translation is funny.

Re: load from disk with int 0x13

Posted: Tue Jun 01, 2010 12:16 am
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??

Re: load from disk with int 0x13

Posted: Tue Jun 01, 2010 3:29 am
by qw

Re: load from disk with int 0x13

Posted: Tue Jun 01, 2010 4:27 pm
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?

Re: load from disk with int 0x13

Posted: Tue Jun 01, 2010 5:56 pm
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

Re: load from disk with int 0x13

Posted: Tue Jun 01, 2010 6:54 pm
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?

Re: load from disk with int 0x13

Posted: Wed Jun 02, 2010 1:01 am
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.

Re: load from disk with int 0x13

Posted: Wed Jun 02, 2010 4:27 am
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.,..

Re: load from disk with int 0x13

Posted: Wed Jun 02, 2010 4:49 am
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 ;-)