floppy loading tracks

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
slacker

floppy loading tracks

Post by slacker »

im trying to load my kernel from a floppy disk into memory but for some reason i am having trouble writing to a certain memory address. my code just hangs when it gets to this mem address. any ideas?

Code: Select all

readtrack7:
mov ax, 0x1fa0
mov es, ax
mov bx,   0x00
mov ah,   0x02
mov al,   18
mov ch,   3
mov cl,   1
mov dh,   1      
mov dl,   0
int 13h
jc readtrack7
User avatar
Brendan
Member
Member
Posts: 8561
Joined: Sat Jan 15, 2005 12:00 am
Location: At his keyboard!
Contact:

Re:floppy loading tracks

Post by Brendan »

Hi,

The BIOS functions usually use 8 bit ISA DMA transfers, which can't cross a 64 Kb boundary. If the DMA tried to do your transfer it'd fill from 0x0001FA00 to 0x0001FFFF with the first 3 sectors. Then it'd wrap around to the start of the 64 Kb area, and fill from 0x00010000 to 0x00011DFF with the remaining 15 sectors.

To avoid this problem the BIOS returns an error instead. In this case the error code (returned in AH when carry is set) would be 0x09 - "DMA across 64 Kb boundary".

To fix it you could split your read into 2 parts:

Code: Select all

readtrack7a:
   mov ax, 0x1fa0
   mov es, ax
   mov bx,   0x00
   mov ah,   0x02
   mov al,   3
   mov ch,   3
   mov cl,   1
   mov dh,   1      
   mov dl,   0
   int 13h
   jc readtrack7a

readtrack7b:
   mov ax, 0x2000
   mov es, ax
   mov bx,   0x00
   mov ah,   0x02
   mov al,   15
   mov ch,   3
   mov cl,   4
   mov dh,   1      
   mov dl,   0
   int 13h
   jc readtrack7b
Although it might be a good idea to handle disk errors properly, for e.g.:

Code: Select all

readdata:
   mov si, 3
.retry:
   pusha
   mov ah, 2
   mov es, di
   mov bx, 0
   mov dl, 0
   int 0x13
   jnc .ok
   sub si, 1
   jb .error
   popa
   jmp .retry
.error:
   printf("Error %d reading boot image\n", AH);
   popa
   jmp abortboot
.ok:
   popa
   ret

abortboot:
   printf("Boot aborted, press control+alt+del to reboot\n");
.die:
   jmp .die
Then you could use:

Code: Select all

   mov di, 0x1fa0
   mov al,   3
   mov ch,   3
   mov cl,   1
   mov dh,   1
   call readdata

   mov di, 0x2000
   mov al,   15
   mov ch,   3
   mov cl,   4
   mov dh,   1
   call readdata

Cheers,

Brendan
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.
Post Reply