Page 1 of 1

problem reading more than 1 track

Posted: Wed Apr 04, 2012 9:07 am
by assembler01
First I need to tell you that my bootloader does'nt search for my kernel but instead loads sectors from the SECOND sector (end of bootloader) where my kernel is included in the code with a incbin "kernel.asm".
Anyway, my bootloader loads 1 track (18 sectors in fat12) but my kernel recently expanded to be more than 1 track in size so I needed to make the bootloader load more tracks:

Code: Select all

read:
  pusha
  mov ah,2 ; read
  mov al,18 ; 1 track at a time
  mov ch,0 ; start at track 0
  mov cl,2 ; start sector 2 = end of bootloader and start of kernel
  mov dh,0 ; head 0
  mov dl,byte[bootdev] ; boot device passed to us from BIOS st startup
  mov bx,0x2000 ; load segment
  mov es,bx
  mov bx,0

.do:
  int 0x13 ; read
  jc .error ; if error ...
  mov cl,0 ; all other reads start from sector 0
  inc ch ; next track
  cmp ch,3 ; read 3 tracks just to be safe
  jne .do

.done:
  mov ax,0x07c0 ; set es back to 0x07c0
  mov es,ax
  popa
  ret

.error:
  mov si,.msg
  call printerr ; print error message in red
  jmp error ; reboot

.msg: db 10,13,'Disk read error!!!',10,13,0
But when I booted it up it seemd like if it only loaded 1 track still becaous the things at the end of the kernel didn't work.

Re: problem reading more than 1 track

Posted: Wed Apr 04, 2012 9:27 am
by JAAman
one problem... tracks don't ever start with sector 0

you are loading the second track starting with sector 0 -- but sector 0 is a special flag in CHS format to indicate an invalid CHS set... so any correctly written BIOS will return a fail and not load any sectors at all

Re: problem reading more than 1 track

Posted: Wed Apr 04, 2012 9:40 am
by assembler01
But the bios does not return an error code. If not 0 then what sector should I start to read from?

Re: problem reading more than 1 track

Posted: Thu Apr 05, 2012 2:47 am
by Yoda
Sector count for CHS mode starts from 1.

Re: problem reading more than 1 track

Posted: Thu Apr 05, 2012 8:58 am
by JAAman
assembler01 wrote:But the bios does not return an error code. If not 0 then what sector should I start to read from?
thing is, you are doing it correctly in the first track (by starting at sector #2, instead of #1, to skip the boot sector), but then incorrectly in the second track


sector numbers always begin with #1, so the first sector on the track would be sector #1, second would be #2, third would be #3, etc...

so in CHS your addresses would be:
0/0/1 -- boot sector
0/0/2 -- first sector of your loaded code
0/0/3
...
0/1/1 -- first sector of second track
0/0/2
...
1/0/1 -- first sector of second cyl (track numHeads+1)
1/0/2
...

like that -- just remember, there is never a sector #0 when using CHS format

the BIOS should be setting carry flag to indicate error, but it might not, as there are no sectors to load, it did complete correctly... thus no error