public inbox for ecos-discuss@sourceware.org
 help / color / mirror / Atom feed
From: Fabrice Gautier <Fabrice_Gautier@sdesigns.com>
To: "Ecos-List (E-mail)" <ecos-discuss@sourceware.cygnus.com>
Subject: [ECOS] i386 flopy load problem.
Date: Wed, 01 Nov 2000 21:10:00 -0000	[thread overview]
Message-ID: <5AF611D83988D4118ACF00E0B10400540557FB@mr-intranet.sdesigns.net> (raw)

[-- Attachment #1: Type: text/plain, Size: 669 bytes --]

Hi,

The current code for loading from the floppy won't work in many case. It
will be subject to what i call the "buffer cross 64k boundary problem": The
bios function can't handle a buffer that cross a 64k boundary (This is also
refered as "DMA access across 64k boundary" in some docs)

The current code load track by track, and so there is a good chance to cross
a 64K boundary during a track load, if the image size is big enough.

The only way to avoid the problem is to load one sector at a time, and to
align _start on 512 bytes. This is slower but who cares?

Attached is a patch against platform.S

Regards,

-- 
Fabrice Gautier
fabrice_gautier@sdesigns.com 


[-- Attachment #2: load.patch --]
[-- Type: text/x-diff, Size: 4183 bytes --]

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. */

             reply	other threads:[~2000-11-01 21:10 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2000-11-01 21:10 Fabrice Gautier [this message]
2000-11-02  9:21 ` Jonathan Larmour
2000-11-02 20:09 Fabrice Gautier
2000-11-02 22:01 Rolf Manderscheid
2000-11-02 22:13 ` Jonathan Larmour
2000-11-03 10:54 Fabrice Gautier
2000-11-16  9:13 Leandro Vieira
2000-11-16  9:29 ` Robert Swindells
2000-11-16 13:18 ` Robert Swindells
     [not found] <200011162118.NAA18216@cygnus.com>
2000-11-17  3:48 ` Bart Veer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5AF611D83988D4118ACF00E0B10400540557FB@mr-intranet.sdesigns.net \
    --to=fabrice_gautier@sdesigns.com \
    --cc=ecos-discuss@sourceware.cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).