Index: platform.inc =================================================================== RCS file: /cvs/ecos/ecos/packages/hal/i386/pc/current/include/platform.inc,v retrieving revision 1.2 diff -u -w -b -B -r1.2 platform.inc --- platform.inc 2000/08/25 17:33:01 1.2 +++ platform.inc 2000/11/02 04:57:40 @@ -65,8 +65,7 @@ sectorsPerTrack = 18 bytesPerSector = 512 - bytesPerTrack = sectorsPerTrack * bytesPerSector - dptLength = 3 /* words. */ + esPerSector = 32 /* = 512/16 */ cld /* always count up. */ @@ -93,35 +92,62 @@ shl $10, %eax pushl %eax - - /* Read the rest of the image to _start. This code works by reading a track - at a time... + /* reset floppy */ + movb $0,%ah + movb $0,%dl + int $0x13 + jc _error + + /* Read the rest of the image to _start. This code works by reading + only one sector at a time to avoid "buffer cross 64k boundary" fatal + problem... This is slow but should work in almost all situations. + _start should be aligned on a 512 bytes boundary to be sure. */ - - movl $_edata, %eax - movl $_start, %ebx /* Our destination address. */ - subl %ebx, %eax /* Number of bytes in the image. */ - movl $1, %ecx /* Track/sector to read from (starts at 1). */ - -0: - cmpl $0, %eax - jle 1f - - pushl %eax /* Save the number of bytes we want. */ - pushl %ebx /* Save our current address. */ - pushl %ecx /* Save our disk location. */ - - /* Read in a track with head 0. */ - movl %ebx, %eax /* Put our address into ES:BX. */ - shr $4, %eax + /* destination pointer es:bx */ + /* With correct alignement, bx should be 0 and es should be a multiple of 32 + if not it may cause the "buffer cross 64k boundary" problem (cf above) + */ + movl $_start,%eax + movw %ax,%bx + andw $0xF,%bx + shrl $4,%eax movw %ax, %es - andl $0xF, %ebx - movw $0, %dx /* Disk 0, head 0 */ - movb $0x02, %ah - movb $sectorsPerTrack, %al /* Read the entire track. */ + + /* initials head/track/sector */ + movw $0,%dx + movw $1,%cx + + xorl %edi,%edi + jmp _loadsector + +_nextsector: + addw $esPerSector, %di /* advance buffer pointer */ + shll $4,%edi + cmpl $_edata,%edi + jg _endload /* next sector ? */ + shrl $4,%edi + movw %di,%es + incb %cl + cmpb $sectorsPerTrack, %cl + jbe _loadsector /* next head ?*/ movb $1, %cl - int $0x13 /* CX points to our track/sector. */ + incb %dh + cmpb $1, %dh + je _loadsector /* next track ? */ + movb $0, %dh + incb %ch + +_loadsector: + + pushw %es + movw $0x0201, %ax + int $0x13 + popw %di + jc _error + + movw $(0x0E*256+'.'), %ax /* print a dot */ + int $0x10 /* So go ahead and resume execution at the real starting address. This only serves to move us quickly to the real starting location; and has @@ -129,52 +155,13 @@ reading the first track, then we limit ourselves to reading images of 30k bytes max before overwriting ourselves at 0x7C00. */ - - ljmp $0, $2f - hlt - .align 4 -2: - - popl %ecx - popl %ebx - popl %eax - - /* Add our length to the address. */ - addl $bytesPerTrack, %ebx - subl $bytesPerTrack, %eax - - /* Maybe read in a track with head 1. */ - cmpl $0, %eax - jle 1f - - pushl %eax /* Save the number of bytes we want. */ - pushl %ebx /* Save our current address. */ - pushl %ecx - - movl %ebx, %eax /* Put our address into ES:BX. */ - shr $4, %eax - movw %ax, %es - andl $0xF, %ebx - movw $0x0100, %dx /* Disk 0, head 1 */ - movb $0x02, %ah - movb $sectorsPerTrack, %al /* Read the entire track. */ - movb $1, %cl - int $0x13 /* CX points to our track/sector. */ + ljmp $0,$_nextsector - popl %ecx - popl %ebx - popl %eax - - /* Add our length to the address. */ - addl $bytesPerTrack, %ebx - subl $bytesPerTrack, %eax - - /* Move to the next track. */ - addb $0x1, %ch - - jmp 0b - +_error: /* halt on error */ + cli + hlt + jmp _start /* Write the 0x55/0xAA signature at the end of the first block. Without this signature the BIOS won't consider this block to be bootable. @@ -183,8 +170,8 @@ . = _start + 510 .byte 0x55 .byte 0xAA - +_endload: 1: /* Lets be nice and wait for the diskette drive motor to go off before continuing. */