This is the mail archive of the ecos-patches@sources.redhat.com mailing list for the eCos project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

DiskOnChip boot for PC target (preliminary)


 This is a preliminary patch, since the flash layer for DoC devices is still 
in the early stage of testing the physical layer. However RedBoot or an eCos 
application can be booted from DoC.

 You can read more about the patch and DoC and also download the patch from 
<http://www.vsr.si/ecos/patches>

Regards
iz
diff -C2 -N -P -r -x '.*' /ecoscvs/orig/ecos/packages/hal/i386/arch/current/ChangeLog ./hal/i386/arch/current/ChangeLog
*** /ecoscvs/orig/ecos/packages/hal/i386/arch/current/ChangeLog	Fri May 24 01:03:02 2002
--- ./hal/i386/arch/current/ChangeLog	Sun Jul  7 16:37:01 2002
***************
*** 1,2 ****
--- 1,7 ----
+ 2002-07-07  Iztok Zupet <iz@vsr.si>
+ 
+ 	* src/vectors.S: Added CYG_HAL_STARTUP_DISK and CYG_HAL_STARTUP_BIOS
+ 	  in order to init the IDT
+ 
  2002-05-17  Nick Garnett  <nickg@redhat.com>
  
diff -C2 -N -P -r -x '.*' /ecoscvs/orig/ecos/packages/hal/i386/arch/current/src/vectors.S ./hal/i386/arch/current/src/vectors.S
*** /ecoscvs/orig/ecos/packages/hal/i386/arch/current/src/vectors.S	Fri May 24 01:03:07 2002
--- ./hal/i386/arch/current/src/vectors.S	Tue Jul  2 15:27:27 2002
***************
*** 92,96 ****
  	movl	$__interrupt_stack, %esp
  
! #if defined(CYG_HAL_STARTUP_FLOPPY) || defined(CYG_HAL_STARTUP_ROM)
  	# If we are here first, initialize the IDT. RAM startup
  	# configurations can assume that Redboot has already set
--- 92,97 ----
  	movl	$__interrupt_stack, %esp
  
! #if defined(CYG_HAL_STARTUP_FLOPPY) || defined(CYG_HAL_STARTUP_ROM) || \
!     defined(CYG_HAL_STARTUP_DISK) || defined(CYG_HAL_STARTUP_BIOS)
  	# If we are here first, initialize the IDT. RAM startup
  	# configurations can assume that Redboot has already set
diff -C2 -N -P -r -x '.*' /ecoscvs/orig/ecos/packages/hal/i386/pc/current/ChangeLog ./hal/i386/pc/current/ChangeLog
*** /ecoscvs/orig/ecos/packages/hal/i386/pc/current/ChangeLog	Fri May 24 01:03:10 2002
--- ./hal/i386/pc/current/ChangeLog	Sun Jul  7 17:01:15 2002
***************
*** 1,2 ****
--- 1,11 ----
+ 2002-07-07  Iztok Zupet  <iz@vsr.si>
+ 
+ 	* cdl/hal_i386_pc.cdl: 
+ 	Added CYG_HAL_STARTUP_DISK and CYG_HAL_STARTUP_BIOS
+ 	
+ 	* redbootDoC directory with BIOS extension build utility
+ 	added (will have to be moved to devs/flash/DiskOnChip when
+ 	that is done )
+ 
  2002-05-07  Gary Thomas  <gthomas@redhat.com>
  
diff -C2 -N -P -r -x '.*' /ecoscvs/orig/ecos/packages/hal/i386/pc/current/cdl/hal_i386_pc.cdl ./hal/i386/pc/current/cdl/hal_i386_pc.cdl
*** /ecoscvs/orig/ecos/packages/hal/i386/pc/current/cdl/hal_i386_pc.cdl	Fri May 24 01:03:10 2002
--- ./hal/i386/pc/current/cdl/hal_i386_pc.cdl	Fri Jun 28 13:34:22 2002
***************
*** 80,84 ****
          display       "Startup type"
          flavor        data
!         legal_values  {"RAM" "FLOPPY" "ROM"}
          default_value {"RAM"}
  	no_define
--- 80,84 ----
          display       "Startup type"
          flavor        data
!         legal_values  {"RAM" "FLOPPY" "DISK" "BIOS" "ROM"}
          default_value {"RAM"}
  	no_define
***************
*** 91,95 ****
              on PCs with a standard BIOS), or ROM startup (for writing
              straight to a boot ROM/Flash). ROM startup is experimental
!             at this time."
      }
          
--- 91,98 ----
              on PCs with a standard BIOS), or ROM startup (for writing
              straight to a boot ROM/Flash). ROM startup is experimental
!             at this time. DISK and BIOS startup are suitable for booting
! 	    from DiskOnChip. DISK boots from a normal C: disk bootable
! 	    partition, while BIOS boots from the DiskOnChip firmware
! 	    (a BIOS extension)"
      }
          
***************
*** 230,234 ****
              display "Build GDB stub loader image"
              default_value 0
!             requires { CYG_HAL_STARTUP == "FLOPPY" }
              requires CYGSEM_HAL_ROM_MONITOR
              requires CYGBLD_BUILD_COMMON_GDB_STUBS
--- 233,237 ----
              display "Build GDB stub loader image"
              default_value 0
!             requires { CYG_HAL_STARTUP == "FLOPPY" || CYG_HAL_STARTUP == "DISK" || CYG_HAL_STARTUP == "BIOS"}
              requires CYGSEM_HAL_ROM_MONITOR
              requires CYGBLD_BUILD_COMMON_GDB_STUBS
***************
*** 289,293 ****
  	
          parent        CYGPKG_HAL_ROM_MONITOR
!         requires      { CYG_HAL_STARTUP == "FLOPPY" || CYG_HAL_STARTUP == "ROM" }
  	requires      { !CYGHWR_HAL_I386_FPU_SWITCH_LAZY }
          description   "
--- 292,296 ----
  	
          parent        CYGPKG_HAL_ROM_MONITOR
!         requires      { CYG_HAL_STARTUP == "FLOPPY" || CYG_HAL_STARTUP == "ROM" || CYG_HAL_STARTUP == "DISK" || CYG_HAL_STARTUP == "BIOS" }
  	requires      { !CYGHWR_HAL_I386_FPU_SWITCH_LAZY }
          description   "
***************
*** 336,347 ****
  
              cdl_option CYGBLD_BUILD_REDBOOT_BIN_FLOPPY {
!                 display       "Build Redboot FLOPPY binary image"
                  active_if     CYGBLD_BUILD_REDBOOT
!                 active_if     { CYG_HAL_STARTUP == "FLOPPY" }
                  calculated    1
                  no_define
                  description "This option enables the conversion of the Redboot 
                               ELF image to a binary image suitable for
!                              copying to a floppy disk."
          
                  make -priority 325 {
--- 339,350 ----
  
              cdl_option CYGBLD_BUILD_REDBOOT_BIN_FLOPPY {
!                 display       "Build Redboot FLOPPY or DISK or BIOS binary image"
                  active_if     CYGBLD_BUILD_REDBOOT
!                 active_if     { CYG_HAL_STARTUP == "FLOPPY" || CYG_HAL_STARTUP == "DISK" || CYG_HAL_STARTUP == "BIOS"}
                  calculated    1
                  no_define
                  description "This option enables the conversion of the Redboot 
                               ELF image to a binary image suitable for
!                              copying to a floppy disk, hard disk or bios extension"
          
                  make -priority 325 {
diff -C2 -N -P -r -x '.*' /ecoscvs/orig/ecos/packages/hal/i386/pc/current/redbootDoC/Makefile ./hal/i386/pc/current/redbootDoC/Makefile
*** /ecoscvs/orig/ecos/packages/hal/i386/pc/current/redbootDoC/Makefile	Thu Jan  1 01:00:00 1970
--- ./hal/i386/pc/current/redbootDoC/Makefile	Sun Jul  7 16:15:07 2002
***************
*** 0 ****
--- 1,66 ----
+ # Default to using RedBoot binary image
+ STAGE2FILE := redboot.img
+ INT:=INT19
+ 
+ MAKEMIL:=DOC_2000
+ ifeq ($(MAKECMDGOALS),mil512)
+ 	DOC_MIL_PAGE:=512
+ 	DOC_MIL_CHECKSUM:=-m
+ 	MAKEMIL=DOC_MIL
+ endif
+ ifeq ($(MAKECMDGOALS),mil256)
+ 	DOC_MIL_PAGE:=256
+ 	DOC_MIL_CHECKSUM:=-m
+ 	MAKEMIL=DOC_MIL
+ endif
+ 
+ 
+ redboot_firmware: doc_stage1 makecsum $(STAGE2FILE) Makefile
+ 	./makecsum $(DOC_MIL_CHECKSUM) doc_stage1 $(STAGE2FILE) redboot_firmware
+ 
+ doc_stage1.exec: doc_stage1.S doc_stage1.h redboot_size.h Makefile
+ 	i386-elf-gcc -O2 -fno-builtin -nostdinc -nostdlib -Wl,-N,-Ttext,0 -D$(MAKEMIL) -D$(INT) -o doc_stage1.exec doc_stage1.S
+ 
+ doc_stage1b-256.o: doc_stage1b.S doc_stage1.h redboot_size.h Makefile
+ 	i386-elf-gcc -o doc_stage1b-256.o -O2 -DPAGE256 -D$(MAKEMIL) -fno-builtin -nostdinc -c doc_stage1b.S
+ 
+ doc_stage1b-512.o: doc_stage1b.S doc_stage1.h redboot_size.h Makefile
+ 	i386-elf-gcc -o doc_stage1b-512.o -O2 -DPAGE512 -D$(MAKEMIL) -fno-builtin -nostdinc -c doc_stage1b.S
+ 
+ doc_stage1.o: doc_stage1.S doc_stage1.h redboot_size.h Makefile
+ 	i386-elf-gcc -O2 -fno-builtin -nostdinc -D$(MAKEMIL) -D$(INT) -c doc_stage1.S
+ 
+ doc_stage1-256.o: doc_stage1.o doc_stage1b-256.o
+ 	i386-elf-ld -N -Ttext 0 -o doc_stage1-256.o doc_stage1.o doc_stage1b-256.o
+ 
+ doc_stage1-512.o: doc_stage1.o doc_stage1b-512.o
+ 	i386-elf-ld -N -Ttext 0 -o doc_stage1-512.o doc_stage1.o doc_stage1b-512.o
+ 
+ doc_stage1-256.bin: doc_stage1-256.o
+ 	i386-elf-objcopy -O binary doc_stage1-256.o doc_stage1-256.bin
+ 
+ doc_stage1-512.bin: doc_stage1-512.o
+ 	i386-elf-objcopy -O binary doc_stage1-512.o doc_stage1-512.bin
+ 
+ doc_stage1: doc_stage1-256.bin doc_stage1-512.bin
+ ifeq ($(MAKEMIL),DOC_MIL)
+ 	cp -f doc_stage1-$(DOC_MIL_PAGE).bin doc_stage1
+ else
+ 	cp -f doc_stage1-256.bin doc_stage1
+ 	dd bs=256 if=doc_stage1-512.bin skip=1 seek=2 count=1 of=doc_stage1
+ endif
+ 
+ redboot_size.h: $(STAGE2FILE)
+ 	-rm -f redboot_size.h
+ 	set dummy `ls -l $(STAGE2FILE)`; \
+ 	echo "#define REDBOOT_SIZE $$6" > redboot_size.h
+ 	
+ 	
+ mil512: redboot_firmware
+ mil256: redboot_firmware
+ 2000:	redboot_firmware
+ int18:	redboot_firmware
+ int19:	redboot_firmware
+ 
+ clean:
+ 	rm -f doc_stage1 *.o *.bin *~ redboot_firmware doc_stage1.exec makecsum redboot_size.h
diff -C2 -N -P -r -x '.*' /ecoscvs/orig/ecos/packages/hal/i386/pc/current/redbootDoC/README ./hal/i386/pc/current/redbootDoC/README
*** /ecoscvs/orig/ecos/packages/hal/i386/pc/current/redbootDoC/README	Thu Jan  1 01:00:00 1970
--- ./hal/i386/pc/current/redbootDoC/README	Sun Jul  7 15:55:11 2002
***************
*** 0 ****
--- 1,51 ----
+ (original by David Woodhouse)
+ 
+ HOW TO GET REDBOOT BOOTING FROM DiskOnChip
+ ---------------------------------------
+ 
+ (0. You'll need the MTD driver modules loaded and the MTD utils built.)
+  1. Build a recent REDBOOT for PC target with DoC patch applied and
+     CYG_HAL_STARTUP_BIOS selected
+  2. Copy the redboot.bin file to this directory/redboot.img.
+  3. Edit the makefile (INT:= [one of: INT18 or INT19] to select beetwen
+     network boot and bootstrap interrupt for boot.
+  3. make [ one of: mil512, mil256, 2000] (Doc Millenium 8Mb is mil512)
+  4. xxxMTD/util/doc_loadbios /dev/mtd0 redboot_firmware
+ 
+ This assumes that the DiskOnChip is the only (or first) memory device
+ for which the driver was loaded - and hence that it's /dev/mtd0
+ 
+ 
+ HOW IT WORKS
+ ------------
+ 
+ The DiskOnChip has a built-in ROM which is recognised as a BIOS extension
+ by the system BIOS. This is called the 'IPL ROM', and it attempts to load 
+ 0x2000 bytes of the next stage, called the 'SPL, from the DiskOnChip.
+ 
+ To make life complex, it doesn't just load the first 0x2000 bytes from the
+ DiskOnChip - it loads half of the first 0x4000 bytes instead. Of each 512-byte
+ block, it loads the first 256 bytes. 
+ This is because of the way that NAND flash blocks are divided into two pages,
+ and presumably it's done to save code space in the IPL ROM.
+ 
+ As it loads the SPL, it performs a checksum. Iff the checksum of the SPL is
+ equal to 0x55, then it will execute the SPL, which it has loaded to the 
+ address 0x2000:0000.
+ 
+ The SPL in turn is responsible for loading the rest of the firmware from the 
+ DiskOnChip. Normally, this steals some memory for itself, and installs an
+ INT 13h (Disk BIOS) handler to emulate disk access.
+ 
+ We change this. Instead of installing an INT 13h handler, we install an
+ INT 18h (network bootstrap) or INT 19 (bootstarp)  handler. This is very small,
+ and is held entirely within the first 256 bytes of the SPL with the code which 
+ installs it. 
+ 
+ The INT (18h-19h) handler, when executed, loads RedBoot from the DiskOnChip
+ to the place where floppy boot would normally load it, and then passes 
+ control to it.
+ 
+ iz
+ 
+ 
diff -C2 -N -P -r -x '.*' /ecoscvs/orig/ecos/packages/hal/i386/pc/current/redbootDoC/doc_stage1.S ./hal/i386/pc/current/redbootDoC/doc_stage1.S
*** /ecoscvs/orig/ecos/packages/hal/i386/pc/current/redbootDoC/doc_stage1.S	Thu Jan  1 01:00:00 1970
--- ./hal/i386/pc/current/redbootDoC/doc_stage1.S	Sun Jul  7 13:04:44 2002
***************
*** 0 ****
--- 1,346 ----
+ ##=============================================================================
+ ##
+ ##      doc_stage1.S
+ ##
+ ##      Stage 1 of RedBoot DoC firmware (BIOS extension)
+ ##
+ ##=============================================================================
+ #####ECOSGPLCOPYRIGHTBEGIN####
+ ## -------------------------------------------
+ ## This file is part of eCos, the Embedded Configurable Operating System.
+ ## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+ ##
+ ## eCos is free software; you can redistribute it and/or modify it under
+ ## the terms of the GNU General Public License as published by the Free
+ ## Software Foundation; either version 2 or (at your option) any later version.
+ ##
+ ## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
+ ## WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ ## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ ## for more details.
+ ##
+ ## You should have received a copy of the GNU General Public License along
+ ## with eCos; if not, write to the Free Software Foundation, Inc.,
+ ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ ##
+ ## As a special exception, if other files instantiate templates or use macros
+ ## or inline functions from this file, or you compile this file and link it
+ ## with other works to produce a work based on this file, this file does not
+ ## by itself cause the resulting work to be covered by the GNU General Public
+ ## License. However the source code for this file must still be made available
+ ## in accordance with section (3) of the GNU General Public License.
+ ##
+ ## This exception does not invalidate any other reasons why a work based on
+ ## this file might be covered by the GNU General Public License.
+ ##
+ ## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
+ ## at http://sources.redhat.com/ecos/ecos-license/
+ ## -------------------------------------------
+ #####ECOSGPLCOPYRIGHTEND####
+ ##=============================================================================
+ #####GRUBGPLCOPYRIGHTBEGIN####
+ ## -------------------------------------------
+ ##  GRUB  --  GRand Unified Bootloader
+ ##  Copyright (C) 2000 Machine Vision Holdings, Inc.
+ ##
+ ##  This program is free software; you can redistribute it and/or modify
+ ##  it under the terms of the GNU General Public License as published by
+ ##  the Free Software Foundation; either version 2 of the License, or
+ ##  (at your option) any later version.
+ ##
+ ##  This program is distributed in the hope that it will be useful,
+ ##  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ ##  GNU General Public License for more details.
+ ##
+ ##  You should have received a copy of the GNU General Public License
+ ##  along with this program; if not, write to the Free Software
+ ##  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ ## -------------------------------------------
+ #####GRUBGPLCOPYRIGHTEND####
+ ##=============================================================================
+ #######DESCRIPTIONBEGIN####
+ ##
+ ## Author(s):   David Woodhouse <dwmv2@infradead.org>, iz
+ ## Contributors:iz
+ ## Date:        2002-07-07
+ ## Purpose:     PC RedBoot boot from DiskOnChip
+ ## Description: This file contains first stage of DoC BIOS extension.
+ ##
+ ##
+ ######DESCRIPTIONEND####
+ ##
+ ##=============================================================================
+ 
+ #include "doc_stage1.h"
+ 	
+ 	.file	"doc_stage1.S"
+ 
+ 	.text
+ 
+ 	/* Tell GAS to generate 16-bit instructions so that this code works
+ 	   in real mode. */
+ 	.code16
+ 
+ .globl _start; _start:
+ 
+ #ifdef DOC_MIL
+ 	/*
+ 	 * _start is in the beginning of DoC Millennium flash memory
+ 	 */
+ 	.byte 0x55, 0xAA	/* BIOS extension signature */
+ 	.byte 0x10		/* BIOS extension size in 512 byte blocks */
+ 	/*
+ 	 * The checksum byte at offset 511 of every copy of IPL is the
+ 	 * complement to 0 of first 511 bytes.  This is because of 2 facts:
+ 	 * a) the sum of bytes in the BIOS extension window is supposed to 
+ 	 *    be 0
+ 	 * b) the whole 8K DoC window is split into 2 aliases of 2 copies
+ 	 *    of 512 byte IPL in the beginning, 4K of zero-filled area and 
+ 	 *    again 2 aliases of 2 copies of 512 byte IPL in the end.
+ 	 */
+ 	/* BIOS will call far _start + 3 */
+ 	.org	3
+ bios_extension_start:
+ 	pushw	%cs
+ #else
+ 	pushw	%ds
+ #endif
+ 
+ 	/*
+ 	 * With DoC 2000, _start is loaded at 0x20000 by the IPL,
+ 	 * and is jumped to with CS:IP 0x2000:0, DS is <DoC segment>.
+ 	 *
+ 	 * With DoC Millennium, the flash memory is mapped to offset 0
+ 	 * of DoC window.  We suppose that BIOS jumps to that offset 
+ 	 * during the ROM extension scan with CS:IP <DoC segment>:3.
+ 	 */
+ 
+ 	
+ 	/* What we need to do is:
+ 	   1. Check the current end-of-memory in the BIOS
+ 	   2. Reduce it by the amount of memory we need for our INT 19h 
+ 	   3. Return, and wait for our INT 19h to be called.
+ 	*/
+ 
+ 	
+ 		/* Find top of memory */
+ 	xorw	%ax, %ax
+ 	movw	%ax, %ds
+ 	movw	0x0413, %ax
+ 
+ 		/* Steal 1K from the top */
+ 	decw	%ax
+ 	movw	%ax,0x0413
+ 
+ 		/* Generate segment address */
+ 	shlw	$6,%ax
+ 	movw	%ax,%es
+ 
+ 		/* Set up our shiny new INT 19h handler */
+ 	movw	%es, (DOC_BIOS_HOOK * 4 + 2)
+ 	movw	$doc_bios_hook, (DOC_BIOS_HOOK * 4)
+ 
+ 		/* Copy ourself into the new segment we've just reserved */
+ 	movw	$0x200, %cx
+ 	cld
+ 	pushw	%cs
+ 	popw	%ds
+ 	xorw	%si,%si
+ 	xorw	%di,%di
+ 	rep
+ 	movsw
+ 
+ 		/* Store the DiskOnChip segment */
+ 	popw	%es:doc_seg
+ 	lret
+ 	
+ doc_bios_hook:
+ 		/* Say hello */
+ 	MSG(doc_bios_hook_execed_string)
+ #ifndef SHOW_INFO
+ 	MSG(eol_string)
+ #endif
+ 
+ 		/* Check where the DiskOnChip is */
+ 	movw	%cs:doc_seg, %ds
+ 
+ 	cld
+ 
+ 		/* Copy it.... */
+ 
+ 		/* Reset DiskOnChip */
+ 	movw	$BXREG, %bx
+ 	movb	$DOC_MODE_CLR_ERR + DOC_MODE_MDWREN + DOC_MODE_NORMAL, BX_DOCControl
+ 	movb	$DOC_MODE_CLR_ERR + DOC_MODE_MDWREN + DOC_MODE_NORMAL, BX_DOCControl
+ 
+ 		/* Set the I/O register */
+ 	movw	$DoC_2k_CDSN_IO, %si
+ 	movb	BX_ChipID, %al
+ 	cmpb	$DOC_ChipID_Doc2k, %al
+ 	je	ioreg_end
+ 	movw	$DoC_Mil_CDSN_IO, %si
+ ioreg_end:
+ 
+ 		/* Flash command:	Reset */
+ 	movb	$NAND_CMD_RESET, %ah
+ 	call	doc_cmd
+ 
+ 
+ 		/********* Display chip ID and segment ***************/
+ #ifdef SHOW_INFO
+ 	pushw	%bx
+ 	pushw	%si
+ 
+ 	pushw	%bx
+ 	call	printspace
+ 	popw	%bx
+ 
+ 	movb	BX_ChipID, %al
+ 	cmpb	$DOC_ChipID_Doc2k, %al
+ 	movw	$(doc_2k_string), %si	
+ 	je	print_id
+ 
+ 	cmpb	$DOC_ChipID_DocMil, %al
+ 	movw	$(doc_mil_string), %si	
+ 	je	print_id
+ 
+ 	call	phbyte
+ 	jmp	print_seg
+ 
+ print_id:
+ 	call	message
+ 
+ print_seg:
+ 	call	printspace
+ 	movw	%ds, %ax
+ 	call	phword
+ 	MSG(eol_string)
+ 	popw	%si
+ 	popw	%bx
+ #endif		/* defined(SHOW_INFO) */
+ 		/*****************************************************/
+ 
+ 		/* 
+ 		   Basically, we know that the DiskOnChip IPL ROM will 
+ 		   load only the first 256 bytes of each 512-byte page
+ 		   from a 512-byte-page device, but it'll load _all_
+ 		   the data from a 256-byte-page device.
+ 		   
+ 		   Therefore, we put the code to handle 256-byte-page
+ 		   devices at offset 0x100, where we know it won't get
+ 		   loaded if we're actually on a 512-byte-page device.
+ 		   We put the code to handle 512-byte-page devices at
+ 		   0x200, in the knowledge that it'll get loaded to 
+ 		   offset 0x100 if it's appropriate.
+ 
+ 		   Now, we don't have to probe the device, we just 
+ 		   jump to the code at 0x100, because we _know_ that 
+ 		   the IPL ROM will have loaded the correct code there.
+ 		   
+ 		   This is SICK. I love it. 
+ 		*/
+ 
+ 	jmp	stage1b
+ 
+ 	/* Routines used by both 256- and 512- byte/page loaders. */
+ 
+                 /* doc_cmd:      Send a command to the flash chip */
+ doc_cmd:
+                 /* Enable CLE line to flash */
+         movb    $CDSN_CTRL_FLASH_IO + CDSN_CTRL_WP + CDSN_CTRL_CLE + CDSN_CTRL_CE, BX_CDSNControl
+                 /* Dummy */
+         incw    BX_ChipID
+                 /* Write the actual command */
+         movb    %ah,BX_SlowIO
+         movb    %ah,(%si)
+                 /* Disable CLE */
+         incw    BX_ChipID
+         movb    $CDSN_CTRL_FLASH_IO + CDSN_CTRL_WP + CDSN_CTRL_CE, BX_CDSNControl
+ 
+                 /* doc_wait:     Wait for the DiskOnChip to be ready */
+ doc_wait:
+         incw    BX_ChipID
+ l38:    
+         testb   $0x80,BX_CDSNControl
+         jz      l38
+         ret
+                 
+ 
+ /*
+  * message: write the string pointed to by %si
+  *
+  *   WARNING: trashes %si, %ax, and %bx
+  */
+ 
+ 	/*
+ 	 * Use BIOS "int 10H Function 0Eh" to write character in teletype mode
+ 	 *	%ah = 0xe	%al = character
+ 	 *	%bh = page	%bl = foreground color (graphics modes)
+ 	 */
+ 1:
+ 	call	printchar
+ message:
+ 	lodsb	%cs:(%si)
+ 	cmpb	$0, %al
+ 	jne	1b	/* if not end of string, jmp to display */
+ 	ret
+ 
+ #ifdef SHOW_INFO
+ 	/* Hex output routines, used at one point in debugging */	
+ phword:
+         pushw   %ax
+         xchgb   %al,%ah
+         call    phbyte
+         movb    %ah,%al
+         call    phbyte
+         popw    %ax
+         ret
+ 
+ phbyte:
+         pushw   %ax
+         movb    %al, %ah
+         shrb    $4,%al
+         call    phnibble
+         movb    %ah, %al
+         call    phnibble
+         popw    %ax
+         ret
+ 
+ phnibble:
+         pushw   %ax
+         andb    $0xf,%al
+         addb    $48,%al
+         cmpb    $57,%al
+         jna     ph1
+         add     $7,%al
+ ph1:    call	printchar
+         popw    %ax
+         ret
+ 
+ printspace:
+ 	mov	$' ', %al
+ printchar:
+ 	movb	$0xe, %ah
+ 	movw	$0x0001, %bx
+ 	int	$0x10
+ 	ret
+ 
+ #endif		/* defined(SHOW_INFO) */
+ 
+ doc_seg:	.word 0
+ 	
+ doc_bios_hook_execed_string:	.string "DoC"
+ doc_2k_string:	.string "2000"
+ doc_mil_string:	.string "Mil"
+ eol_string:	.string "\r\n"
+ 
+ 	.org 0x100
+ stage1b:	
+ 
+ .globl doc_wait
+ .globl doc_cmd
+ .globl message
+ .globl phword
+ .globl phbyte
+ 
diff -C2 -N -P -r -x '.*' /ecoscvs/orig/ecos/packages/hal/i386/pc/current/redbootDoC/doc_stage1.h ./hal/i386/pc/current/redbootDoC/doc_stage1.h
*** /ecoscvs/orig/ecos/packages/hal/i386/pc/current/redbootDoC/doc_stage1.h	Thu Jan  1 01:00:00 1970
--- ./hal/i386/pc/current/redbootDoC/doc_stage1.h	Sun Jul  7 13:21:13 2002
***************
*** 0 ****
--- 1,188 ----
+ ##=============================================================================
+ ##
+ ##      doc_stage1.h
+ ##
+ ##      Stage 1 of RedBoot DoC firmware (BIOS extension)
+ ##
+ ##=============================================================================
+ #####ECOSGPLCOPYRIGHTBEGIN####
+ ## -------------------------------------------
+ ## This file is part of eCos, the Embedded Configurable Operating System.
+ ## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+ ##
+ ## eCos is free software; you can redistribute it and/or modify it under
+ ## the terms of the GNU General Public License as published by the Free
+ ## Software Foundation; either version 2 or (at your option) any later version.
+ ##
+ ## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
+ ## WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ ## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ ## for more details.
+ ##
+ ## You should have received a copy of the GNU General Public License along
+ ## with eCos; if not, write to the Free Software Foundation, Inc.,
+ ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ ##
+ ## As a special exception, if other files instantiate templates or use macros
+ ## or inline functions from this file, or you compile this file and link it
+ ## with other works to produce a work based on this file, this file does not
+ ## by itself cause the resulting work to be covered by the GNU General Public
+ ## License. However the source code for this file must still be made available
+ ## in accordance with section (3) of the GNU General Public License.
+ ##
+ ## This exception does not invalidate any other reasons why a work based on
+ ## this file might be covered by the GNU General Public License.
+ ##
+ ## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
+ ## at http://sources.redhat.com/ecos/ecos-license/
+ ## -------------------------------------------
+ #####ECOSGPLCOPYRIGHTEND####
+ ##=============================================================================
+ #####GRUBGPLCOPYRIGHTBEGIN####
+ ## -------------------------------------------
+ ##  GRUB  --  GRand Unified Bootloader
+ ##  Copyright (C) 2000 Machine Vision Holdings, Inc.
+ ##
+ ##  This program is free software; you can redistribute it and/or modify
+ ##  it under the terms of the GNU General Public License as published by
+ ##  the Free Software Foundation; either version 2 of the License, or
+ ##  (at your option) any later version.
+ ##
+ ##  This program is distributed in the hope that it will be useful,
+ ##  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ ##  GNU General Public License for more details.
+ ##
+ ##  You should have received a copy of the GNU General Public License
+ ##  along with this program; if not, write to the Free Software
+ ##  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ ## -------------------------------------------
+ #####GRUBGPLCOPYRIGHTEND####
+ ##=============================================================================
+ #######DESCRIPTIONBEGIN####
+ ##
+ ## Author(s):   David Woodhouse <dwmv2@infradead.org>, iz
+ ## Contributors:iz
+ ## Date:        2002-07-07
+ ## Purpose:     PC RedBoot boot from DiskOnChip
+ ## Description: This file contains defines for doc_stage1.c DoC BIOS extension.
+ ##
+ ##
+ ######DESCRIPTIONEND####
+ ##
+ ##=============================================================================
+ 
+ 
+ /* SHOW_INFO displays the DiskOnChip ChipID (2000 or Millennium) and
+  * its window segment at the expense of extra code */
+ 
+ #define SHOW_INFO
+ 
+ #define DoC_ChipID 0x1000
+ #define DoC_DOCStatus 0x1001
+ #define DoC_DOCControl 0x1002
+ #define DoC_FloorSelect 0x1003
+ #define DoC_CDSNControl 0x1004
+ #define DoC_CDSNDeviceSelect 0x1005
+ #define DoC_ECCConf 0x1006
+ #define DoC_2k_ECCStatus 0x1007
+ 
+ #define DoC_CDSNSlowIO 0x100d
+ #define DoC_ECCSyndrome0 0x1010
+ #define DoC_ECCSyndrome1 0x1011
+ #define DoC_ECCSyndrome2 0x1012
+ #define DoC_ECCSyndrome3 0x1013
+ #define DoC_ECCSyndrome4 0x1014
+ #define DoC_ECCSyndrome5 0x1015
+ #define DoC_AliasResolution 0x101b
+ #define DoC_ConfigInput 0x101c
+ #define DoC_ReadPipeInit 0x101d
+ #define DoC_WritePipeTerm 0x101e
+ #define DoC_LastDataRead 0x101f
+ #define DoC_NOP 0x1020
+ 
+ #define DoC_Mil_CDSN_IO 0x0800
+ #define DoC_2k_CDSN_IO 0x1800
+ 
+ #define DOC_MODE_RESET 0
+ #define DOC_MODE_NORMAL 1
+ #define DOC_MODE_RESERVED1 2
+ #define DOC_MODE_RESERVED2 3
+ 
+ #define DOC_MODE_MDWREN 4
+ #define DOC_MODE_CLR_ERR 0x80
+ 
+ #define DOC_ChipID_Doc2k 0x20
+ #define DOC_ChipID_DocMil 0x30
+ 
+ #define CDSN_CTRL_FR_B 0x80
+ #define CDSN_CTRL_ECC_IO 0x20
+ #define CDSN_CTRL_FLASH_IO 0x10
+ #define CDSN_CTRL_WP 8
+ #define CDSN_CTRL_ALE 4
+ #define CDSN_CTRL_CLE 2
+ #define CDSN_CTRL_CE 1
+ 
+ 	
+ #define NAND_CMD_READ0 0
+ #define NAND_CMD_READ1 1
+ #define NAND_CMD_RESET 0xff
+ 
+ #include "redboot_size.h"
+ 
+ /*
+  *  defines for the code go here
+  */
+ 
+ /*
+  * Whether we hook to the Bootstrap Loader INT 0x19
+  * or to the Diskless Boot INT 0x18
+  * See 
+  *    http://etherboot.sourceforge.net/doc/html/devman-3.html
+  *    http://www.ctyme.com/intr/rb-2270.htm
+  *    http://www.ctyme.com/intr/rb-2241.htm
+  */
+ #ifdef INT18
+ #define DOC_BIOS_HOOK 0x18
+ #else
+ #define DOC_BIOS_HOOK 0x19
+ #endif
+ 
+ #define LOADLEN (((REDBOOT_SIZE + 0xff) & ~0xff) >> 8)
+ 
+ #ifdef DOC_MIL
+ /*
+  * We place RedBoot at offset 0x400 of DoC Millennium flash memory
+  * to leave room for 2 copies of stage 1 (IPL) at offset 0.  In this way
+  * the Download Engine can load the backup copy of IPL from offset 0x200.
+  */
+ #  define REDBOOTLOADOFS	0x400
+ #else
+ /*
+  * DoC 2000 IPL is stored in ROM.  It will download stage 1 from two 256
+  * byte blocks of flash memory.  The first block is at the start.  The
+  * second block is at offset 0x100 if DoC 2000 page size is 256 bytes.  
+  * If the page size is 512 bytes, the second block gest loaded off 0x200.
+  * RedBoot can be stored at offset 0x300 in both cases.
+  */
+ #  define REDBOOTLOADOFS	0x0300
+ #endif
+ 
+ # define REDBOOTSTART	0x3000
+ 
+ #define REDBOOTLOADSEG	((REDBOOTSTART - REDBOOTLOADOFS) >> 4)
+ 
+ 	/* Some macros to make it obvious what we're accessing */
+ #define BXREG			DoC_CDSNControl
+ 
+ #define BX_ChipID		(DoC_ChipID - BXREG)(%bx)
+ #define BX_DOCControl		(DoC_DOCControl - BXREG)(%bx)
+ 				/* "movb (%bx), %al" takes only 2 bytes */
+ #define BX_CDSNControl		(%bx)
+ #define BX_SlowIO		(DoC_CDSNSlowIO - BXREG)(%bx)
+ #define BX_ReadPipeInit		(DoC_ReadPipeInit - BXREG)(%bx)
+ #define BX_LastDataRead		(DoC_LastDataRead - BXREG)(%bx)
+ 
+ 			/* Print message string */
+ #define MSG(x)	movw $(x), %si; call message
+ 
diff -C2 -N -P -r -x '.*' /ecoscvs/orig/ecos/packages/hal/i386/pc/current/redbootDoC/doc_stage1b.S ./hal/i386/pc/current/redbootDoC/doc_stage1b.S
*** /ecoscvs/orig/ecos/packages/hal/i386/pc/current/redbootDoC/doc_stage1b.S	Thu Jan  1 01:00:00 1970
--- ./hal/i386/pc/current/redbootDoC/doc_stage1b.S	Sun Jul  7 13:29:10 2002
***************
*** 0 ****
--- 1,202 ----
+ ##=============================================================================
+ ##
+ ##      doc_stage1b.S
+ ##
+ ##      Stage 1b of RedBoot DoC firmware (BIOS extension)
+ ##
+ ##=============================================================================
+ #####ECOSGPLCOPYRIGHTBEGIN####
+ ## -------------------------------------------
+ ## This file is part of eCos, the Embedded Configurable Operating System.
+ ## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+ ##
+ ## eCos is free software; you can redistribute it and/or modify it under
+ ## the terms of the GNU General Public License as published by the Free
+ ## Software Foundation; either version 2 or (at your option) any later version.
+ ##
+ ## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
+ ## WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ ## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ ## for more details.
+ ##
+ ## You should have received a copy of the GNU General Public License along
+ ## with eCos; if not, write to the Free Software Foundation, Inc.,
+ ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ ##
+ ## As a special exception, if other files instantiate templates or use macros
+ ## or inline functions from this file, or you compile this file and link it
+ ## with other works to produce a work based on this file, this file does not
+ ## by itself cause the resulting work to be covered by the GNU General Public
+ ## License. However the source code for this file must still be made available
+ ## in accordance with section (3) of the GNU General Public License.
+ ##
+ ## This exception does not invalidate any other reasons why a work based on
+ ## this file might be covered by the GNU General Public License.
+ ##
+ ## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
+ ## at http://sources.redhat.com/ecos/ecos-license/
+ ## -------------------------------------------
+ #####ECOSGPLCOPYRIGHTEND####
+ ##=============================================================================
+ #####GRUBGPLCOPYRIGHTBEGIN####
+ ## -------------------------------------------
+ ##  GRUB  --  GRand Unified Bootloader
+ ##  Copyright (C) 2000 Machine Vision Holdings, Inc.
+ ##
+ ##  This program is free software; you can redistribute it and/or modify
+ ##  it under the terms of the GNU General Public License as published by
+ ##  the Free Software Foundation; either version 2 of the License, or
+ ##  (at your option) any later version.
+ ##
+ ##  This program is distributed in the hope that it will be useful,
+ ##  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ ##  GNU General Public License for more details.
+ ##
+ ##  You should have received a copy of the GNU General Public License
+ ##  along with this program; if not, write to the Free Software
+ ##  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ ## -------------------------------------------
+ #####GRUBGPLCOPYRIGHTEND####
+ ##=============================================================================
+ #######DESCRIPTIONBEGIN####
+ ##
+ ## Author(s):   David Woodhouse <dwmv2@infradead.org>, iz
+ ## Contributors:iz
+ ## Date:        2002-07-07
+ ## Purpose:     PC RedBoot boot from DiskOnChip
+ ## Description: This file contains second stage of DoC BIOS extension.
+ ##
+ ##
+ ######DESCRIPTIONEND####
+ ##
+ ##=============================================================================
+ 
+ #include "doc_stage1.h"
+ 
+ 	.file "doc_stage1b.S"
+ 	.code16
+ 	.text
+ stage1b:
+ 		/* Load %CX with the number of 256-byte blocks to load */	
+ 	movw	$LOADLEN, %cx
+ 
+ 		/* Set up our target address for writing stage2 */
+ 	movw	$REDBOOTLOADSEG, %ax
+ 	movw	%ax, %es
+ 	movw	$REDBOOTLOADOFS, %di
+ 
+ 		/* Stage2 proper starts at offset 0x300 on the flash. We
+ 		   have defined the load address REDBOOTLOADSEG so that
+ 		   we're loading this there.
+ 		*/
+ 
+ #ifdef DOC_MIL_KEEP_IPL
+ 	cmpw	$DoC_2k_CDSN_IO, %si
+ 	je	mil_spec_end3
+ 	/* Keep Millennium's original IPL in the first 1K of flash */
+ 	addw	$0x400, %di
+ mil_spec_end3:
+ #endif
+ 
+ mainloop:
+ 
+ #ifdef PAGE256
+                 /* Send new READ0 command */
+         xorb    %ah, %ah
+ #else	
+ 		/* Send new READ command - is it READ0 or READ1? */
+ 	movw	%di, %ax
+ 	andb	$1,%ah
+ #endif
+ 	call	doc_cmd
+ 
+ 		/* Start of new block. Set address */
+ 	movb	$CDSN_CTRL_FLASH_IO + CDSN_CTRL_WP + CDSN_CTRL_ALE + CDSN_CTRL_CE, BX_CDSNControl
+ 	incw	BX_ChipID
+ 
+ #ifdef PAGE256
+ 		/* We sent bits 0-7, then 8-15, then 16-23 */
+ #else	
+ 		/* We send bits 0-7, then 9-16, then 17-23 */
+ 		/* Yes bit 8 is missing. Read the NAND flash specs */		
+ #endif
+ 	movw	%di,%dx
+ 		/* Bits 0-7 are always zero */
+ 	movb	$0,BX_SlowIO
+ 	movb	$0,(%si)
+ #ifndef PAGE256
+ 			/* Bits 9-16 */
+ 	shrw	$1,%dx
+ 	.byte	0x80, 0xce /* orb adrbit16, %dh */
+ adrbit16:	
+ 	.byte	0
+ #else
+ 			/* Bits 8-15 */
+ #endif
+ 	movb	%dh,BX_SlowIO
+ 	movb	%dh,(%si)
+ #ifdef PAGE256
+ 			/* Bits 16-23 */
+ #else	
+ 			/* Bits 17-24 */
+ #endif
+ 	.byte	0xb2 /* movb adrbytehi, %dl */
+ adrbytehi:
+ 	.byte	0
+ 
+ 	movb	%dl,BX_SlowIO
+ 	movb	%dl,(%si)
+ 
+ 		/* Clear the ALE line to the flash chip */
+ 	movb	$CDSN_CTRL_FLASH_IO + CDSN_CTRL_WP + CDSN_CTRL_CE, BX_CDSNControl
+ 	call	doc_wait
+ 
+ 	pushw	%cx		/* Store the 'blocks remaining' count */
+ 	movw	$0x100, %cx	/* Set up to copy 0x100 bytes */
+ 	cmpw	$DoC_2k_CDSN_IO, %si
+ 	je	mil_spec_end1
+ 	testb	BX_ReadPipeInit, %al /* Millennium should use the */
+ 	decw	%cx		/* LastDataRead register - Pipeline Reads */
+ mil_spec_end1:
+ 
+ readbyte:	
+ 	movsb			/* movb (%si), %al ; stosb would be more */
+ 	decw	%si		/* obvious, but would take an extra byte. */
+ 	loop	readbyte
+ 
+ 	cmpw	$DoC_2k_CDSN_IO, %si
+ 	je	mil_spec_end2
+ 	movb	BX_LastDataRead, %al
+ 	stosb
+ mil_spec_end2:
+ 
+ 	testw	$0xffff, %di	/* Check if we've done a whole 0x10000 bytes */
+ 	jnz	endloop		/* No - continue regardless */
+ 		/* Yes - increase %es */
+ 	movw	%es, %cx
+ 	addb	$0x10, %ch
+ 	movw	%cx, %es
+ 
+ #ifndef PAGE256
+ 	addb	$0x80, %cs:adrbit16	/* Increase bit 16 */
+ 	jnc	endloop			/* Did it overflow? */
+ #endif	
+ 	incb	%cs:adrbytehi		/* If so, increase the high byte too */
+ 
+ endloop:	
+ 	popw	%cx		/* Restore the 'blocks remaining' count */
+ 	loop	mainloop	/* Loop till completely done */
+ good:	
+ 
+ 	MSG(msgjmp)
+ 		/* Run it:	 jmpf 0:3000 */
+ 	.byte	0xea
+ 	.word	REDBOOTSTART,0
+ 
+ msgjmp:		
+ 	.string "Jumping to RedBoot\n\r"
+ 	.org 0xff
+ 	.byte 0 /* checksum */
+ 
+ 
diff -C2 -N -P -r -x '.*' /ecoscvs/orig/ecos/packages/hal/i386/pc/current/redbootDoC/makecsum.c ./hal/i386/pc/current/redbootDoC/makecsum.c
*** /ecoscvs/orig/ecos/packages/hal/i386/pc/current/redbootDoC/makecsum.c	Thu Jan  1 01:00:00 1970
--- ./hal/i386/pc/current/redbootDoC/makecsum.c	Sun Jul  7 15:23:50 2002
***************
*** 0 ****
--- 1,294 ----
+ /*
+ ##
+ ##      mkchecksum.c
+ ##
+ ##      checksumes the BIOS extension
+ ##
+ ##=============================================================================
+ #####ECOSGPLCOPYRIGHTBEGIN####
+ ## -------------------------------------------
+ ## This file is part of eCos, the Embedded Configurable Operating System.
+ ## Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
+ ##
+ ## eCos is free software; you can redistribute it and/or modify it under
+ ## the terms of the GNU General Public License as published by the Free
+ ## Software Foundation; either version 2 or (at your option) any later version.
+ ##
+ ## eCos is distributed in the hope that it will be useful, but WITHOUT ANY
+ ## WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ ## FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ ## for more details.
+ ##
+ ## You should have received a copy of the GNU General Public License along
+ ## with eCos; if not, write to the Free Software Foundation, Inc.,
+ ## 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ ##
+ ## As a special exception, if other files instantiate templates or use macros
+ ## or inline functions from this file, or you compile this file and link it
+ ## with other works to produce a work based on this file, this file does not
+ ## by itself cause the resulting work to be covered by the GNU General Public
+ ## License. However the source code for this file must still be made available
+ ## in accordance with section (3) of the GNU General Public License.
+ ##
+ ## This exception does not invalidate any other reasons why a work based on
+ ## this file might be covered by the GNU General Public License.
+ ##
+ ## Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
+ ## at http://sources.redhat.com/ecos/ecos-license/
+ ## -------------------------------------------
+ #####ECOSGPLCOPYRIGHTEND####
+ ##=============================================================================
+ #####GRUBGPLCOPYRIGHTBEGIN####
+ ## -------------------------------------------
+ ##  GRUB  --  GRand Unified Bootloader
+ ##  Copyright (C) 2000 Machine Vision Holdings, Inc.
+ ##
+ ##  This program is free software; you can redistribute it and/or modify
+ ##  it under the terms of the GNU General Public License as published by
+ ##  the Free Software Foundation; either version 2 of the License, or
+ ##  (at your option) any later version.
+ ##
+ ##  This program is distributed in the hope that it will be useful,
+ ##  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ ##  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ ##  GNU General Public License for more details.
+ ##
+ ##  You should have received a copy of the GNU General Public License
+ ##  along with this program; if not, write to the Free Software
+ ##  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ ## -------------------------------------------
+ #####GRUBGPLCOPYRIGHTEND####
+ ##=============================================================================
+ #######DESCRIPTIONBEGIN####
+ ##
+ ## Author(s):   unknown
+ ## Contributors:
+ ## Date:        2002-07-07
+ ## Purpose:     makes checksum PC RedBoot boot from DiskOnChip
+ ## Description: This file calculates  BIOS extension checksum.
+ ##
+ ##
+ ######DESCRIPTIONEND####
+ ##
+ ##=============================================================================
+ */
+ 
+ #include <stdio.h>
+ #include <sys/types.h>
+ #include <sys/stat.h>
+ #include <fcntl.h>
+ unsigned char buf[16384];
+ 
+ main(int argc, char **argv)
+ {
+ 	int len, i, stubfd, st2fd, outfd, retval = 0;
+ 	unsigned char checksum = 0;
+ 	int isMillennium = 0;
+ 	unsigned char total;
+ 
+ 	memset(buf, 0xff, 16384);
+ 
+ 	if (argc < 4) {
+ 		fprintf(stderr, "Usage: makecsum [-m] <stubfile> <stage2> "
+ 				"<outfile> [checksum]\n");
+ 		exit(1);
+ 	}
+ 
+ 	i = 1;
+ 
+ 	if (!strcmp(argv[i], "-m")) {
+ 		isMillennium = 1;
+ 		i++;
+ 	}
+ 	
+ 	stubfd = open(argv[i++], O_RDONLY);
+ 	if (stubfd < 0) {
+ 		perror("open stub file");
+ 		exit(1);
+ 	}
+ 
+ 	st2fd = open(argv[i++], O_RDONLY);
+ 	if (st2fd < 0) {
+ 		perror("open stage2 file");
+ 		close(stubfd);
+ 		exit(1);
+ 	}
+ 
+ 	outfd = open(argv[i++], O_WRONLY | O_CREAT | O_TRUNC, 0664);
+ 	if (outfd < 0) {
+ 		perror("open output file");
+ 		exit(1);
+ 	}
+ 
+ 	if ((argc >= i + 1) && argv[i][0]) {
+ 		total = strtoul(argv[i++], NULL, 0);
+ 	} else {
+ 		total = isMillennium ? 0x00 : 0x55;
+ 	}
+ 
+ 	if (isMillennium) {
+ 		len =  read(stubfd, buf, 512);
+ 		if (len < 0) {
+ 			perror("read from stub file");
+ 			close(outfd);
+ 			close(st2fd);
+ 			close(stubfd);
+ 			exit(1);
+ 		}
+ 
+ 		if (len > 512) {
+ 			fprintf(stderr, "stub file is too large (>512 bytes)\n");
+ 			close(outfd);
+ 			close(st2fd);
+ 			close(stubfd);
+ 			exit(1);
+ 		}
+ 
+ 		close(stubfd);
+ 
+ 		/* Calculate the DoC Millennium IPL checksum for BIOS */
+ 		buf[511] = 0;
+ 
+ 		i = 0;
+ 		while (i < 511) {
+ 			checksum += buf[i++];
+ 		}
+ 
+ 		/* Set the slack byte to fix the csum */
+ 		buf[511] = total - checksum;
+ 
+ 		/*
+ 		 * Write the original buffer twice.
+ 		 * The second copy will be used by the DoC Millennium
+ 		 * Download Engine in case the ECC check fails on the 
+ 		 * first copy.
+ 		 */
+ 		for (i = 0; i < 2; i++) {
+ 			len = write(outfd, buf, 512);
+ 
+ 			if (len < 0) {
+ 				perror("write output file");
+ 				close(outfd);
+ 				close(st2fd);
+ 				exit(1);
+ 			}
+ 
+ 			if (len < 512) {
+ 				fprintf(stderr, "short write of "
+ 					"output file (%d bytes < 512)\n", len);
+ 				close(outfd);
+ 				close(st2fd);
+ 				exit(1);
+ 			}
+ 		}
+ 	} else {	/* DoC 2000 */
+ 		/* Read the stub loader (stage1) */
+ 
+ 		len =  read(stubfd,buf,769);
+ 		if (len < 0) {
+ 			perror("read from stub file");
+ 			close(outfd);
+ 			close(st2fd);
+ 			close(stubfd);
+ 			exit(1);
+ 		}
+ 
+ 		if (len > 768) {
+ 			fprintf(stderr, "stub file is "
+ 					"too large (>768 bytes)\n");
+ 			close(outfd);
+ 			close(st2fd);
+ 			close(stubfd);
+ 			exit(1);
+ 		}
+ 
+ 		close(stubfd);
+ 
+ 		/* Read enough of the remainder to calculate the csum */
+ 		
+ 		len = read(st2fd, buf+768, 16384-768);
+ 		if (len < 0) {
+ 			perror("read from stage2 file\n");
+ 			close(outfd);
+ 			close(st2fd);
+ 			exit(1);
+ 		}
+ 
+ 
+ 		/* Calculate the csum for 512-byte-page devices */
+ 		buf[767] = 0;
+ 
+ 		i=0;
+ 		while (i<16384) {
+ 			checksum += buf[i];
+ 			i++;
+ 			if ((i >> 8)&1)
+ 				i += 256;
+ 		}
+ 
+ 		/* Set the slack byte to fix the csum */
+ 		buf[767] = total - checksum;
+ 
+ 		/* Calculate the csum for 256-byte-page devices */
+ 		checksum = 0;
+ 
+ 		buf[511] = 0;
+ 
+ 		i=0;
+ 		while (i<8192) {
+ 			checksum += buf[i++];
+ 		}
+ 
+ 		/* Set the slack byte to fix the csum */
+ 		buf[511] = total - checksum;
+ 
+ 
+ 		/* Write the original buffer */
+ 		len = write(outfd, buf, 16384);
+ 
+ 		if (len < 0) {
+ 			perror("write output file");
+ 			close(outfd);
+ 			close(st2fd);
+ 			exit(1);
+ 		}
+ 
+ 		if (len < 16384) {
+ 			fprintf(stderr, "short write of "
+ 				"output file (%d bytes < 16384)\n", len);
+ 			close(outfd);
+ 			close(st2fd);
+ 			exit(1);
+ 		}
+ 	}
+ 
+ 	/* Now chuck out the rest of the stage2 */
+ 
+ 	while (1) {
+ 		len = read(st2fd, buf, 16384);
+ 		if (len < 0) {
+ 			perror("read stage2 file");
+ 			retval = 1;
+ 			break;
+ 		}
+ 		if (len == 0)
+ 			break;
+ 		
+ 		i = write(outfd, buf, len);
+ 		if (i < 0) {
+ 			perror("write output file");
+ 			retval = 1;
+ 			break;
+ 		}
+ 		if (i<len) {
+ 			fprintf(stderr, "short write of "
+ 				"output file (%d bytes < %d)\n", i, len);
+ 			retval = 1;
+ 			break;
+ 		}
+ 	}
+ 		
+ 	close(outfd);
+ 	close(st2fd);
+ 	exit(retval);
+ }
diff -C2 -N -P -r -x '.*' /ecoscvs/orig/ecos/packages/hal/i386/pc/current/redbootDoC/stage1.h ./hal/i386/pc/current/redbootDoC/stage1.h
*** /ecoscvs/orig/ecos/packages/hal/i386/pc/current/redbootDoC/stage1.h	Thu Jan  1 01:00:00 1970
--- ./hal/i386/pc/current/redbootDoC/stage1.h	Wed Sep  6 05:02:39 2000
***************
*** 0 ****
--- 1,80 ----
+ /*
+  *  GRUB  --  GRand Unified Bootloader
+  *  Copyright (C) 1999, 2000   Free Software Foundation, Inc.
+  *
+  *  This program is free software; you can redistribute it and/or modify
+  *  it under the terms of the GNU General Public License as published by
+  *  the Free Software Foundation; either version 2 of the License, or
+  *  (at your option) any later version.
+  *
+  *  This program is distributed in the hope that it will be useful,
+  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  *  GNU General Public License for more details.
+  *
+  *  You should have received a copy of the GNU General Public License
+  *  along with this program; if not, write to the Free Software
+  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+  */
+ 
+ #ifndef STAGE1_HEADER
+ #define STAGE1_HEADER	1
+ 
+ 
+ /* Define the version numbers here, so that Stage 1 can know them.  */
+ #define COMPAT_VERSION_MAJOR	3
+ #define COMPAT_VERSION_MINOR	2
+ #define COMPAT_VERSION		((COMPAT_VERSION_MINOR << 8) \
+ 					| COMPAT_VERSION_MAJOR)
+ 
+ /* The signature for bootloader.  */
+ #define STAGE1_SIGNATURE	0xaa55
+ 
+ /* The offset of the end of BPB (BIOS Parameter Block).  */
+ #define STAGE1_BPBEND		0x3e
+ 
+ /* The offset of the major version.  */
+ #define STAGE1_VER_MAJ_OFFS	0x3e
+ 
+ /* The offset of BOOT_DRIVE.  */
+ #define STAGE1_BOOT_DRIVE	0x40
+ 
+ /* The offset of FORCE_LBA.  */
+ #define STAGE1_FORCE_LBA	0x41
+ 
+ /* The offset of STAGE2_ADDRESS.  */
+ #define STAGE1_STAGE2_ADDRESS	0x42
+ 
+ /* The offset of STAGE2_SECTOR.  */
+ #define STAGE1_STAGE2_SECTOR	0x44
+ 
+ /* The offset of STAGE2_SEGMENT.  */
+ #define STAGE1_STAGE2_SEGMENT	0x48
+ 
+ /* The offset of a magic number used by Windows NT.  */
+ #define STAGE1_WINDOWS_NT_MAGIC	0x1b8
+ 
+ /* The offset of the start of the partition table.  */
+ #define STAGE1_PARTSTART	0x1be
+ 
+ /* The offset of the end of the partition table.  */
+ #define STAGE1_PARTEND		0x1fe
+ 
+ /* The stack segment.  */
+ #define STAGE1_STACKSEG		0x2000
+ 
+ /* The segment of disk buffer. The disk buffer MUST be 32K long and
+    cannot straddle a 64K boundary.  */
+ #define STAGE1_BUFFERSEG	0x7000
+ 
+ /* The address of drive parameters.  */
+ #define STAGE1_DRP_ADDR		0x7f00
+ 
+ /* The size of drive parameters.  */
+ #define STAGE1_DRP_SIZE		0x42
+ 
+ /* The flag for BIOS drive number to designate a hard disk vs. a
+    floppy.  */
+ #define STAGE1_BIOS_HD_FLAG	0x80
+ 
+ #endif /* ! STAGE1_HEADER */
diff -C2 -N -P -r -x '.*' /ecoscvs/orig/ecos/packages/hal/i386/pcmb/current/ChangeLog ./hal/i386/pcmb/current/ChangeLog
*** /ecoscvs/orig/ecos/packages/hal/i386/pcmb/current/ChangeLog	Fri May 24 01:03:14 2002
--- ./hal/i386/pcmb/current/ChangeLog	Sun Jul  7 16:45:02 2002
***************
*** 1,2 ****
--- 1,7 ----
+ 2002-07-07  Iztok Zupet  <iz@vsr.si>
+ 
+ 	* include/pcmb.inc:
+ 	Added DISK and BIOS extension startups.	
+ 
  2002-04-29  Gary Thomas  <gthomas@redhat.com>
  
diff -C2 -N -P -r -x '.*' /ecoscvs/orig/ecos/packages/hal/i386/pcmb/current/include/pcmb.inc ./hal/i386/pcmb/current/include/pcmb.inc
*** /ecoscvs/orig/ecos/packages/hal/i386/pcmb/current/include/pcmb.inc	Fri May 24 01:03:15 2002
--- ./hal/i386/pcmb/current/include/pcmb.inc	Tue Jul  2 15:27:52 2002
***************
*** 44,48 ****
  ##
  ## Author(s):   jskov
! ## Contributors:jskov, pjo, nickg
  ## Date:        1999-01-07
  ## Purpose:     PC platform support
--- 44,48 ----
  ##
  ## Author(s):   jskov
! ## Contributors:jskov, pjo, nickg, iz
  ## Date:        1999-01-07
  ## Purpose:     PC platform support
***************
*** 60,65 ****
  
  #ifndef CYGPKG_HAL_I386_CPU_INIT_DEFINED
! 	
! #ifdef CYG_HAL_STARTUP_FLOPPY
  
  #define CYGPKG_HAL_I386_CPU_INIT_DEFINED
--- 60,66 ----
  
  #ifndef CYGPKG_HAL_I386_CPU_INIT_DEFINED
! 
! #if  defined(CYG_HAL_STARTUP_FLOPPY) || defined(CYG_HAL_STARTUP_DISK) || \
!      defined(CYG_HAL_STARTUP_BIOS)
  
  #define CYGPKG_HAL_I386_CPU_INIT_DEFINED
***************
*** 72,79 ****
  
  	.extern _end
! 
  	sectorsPerTrack = 18
  	bytesPerSector = 512
  	esPerSector = 32	/* = 512/16 */
  
  	cld				/* always count up. */
--- 73,88 ----
  
  	.extern _end
! #ifdef CYG_HAL_STARTUP_FLOPPY
  	sectorsPerTrack = 18
  	bytesPerSector = 512
  	esPerSector = 32	/* = 512/16 */
+ #else
+ #ifdef  CYG_HAL_STARTUP_DISK
+ 	bytesPerSector   = 512
+ 	esPerSector      = 32
+ 	maxHead=(_start-1)		/* safe location for disk parameters */
+ 	secPerTrack =(_start-2)
+ #endif
+ #endif
  
  	cld				/* always count up. */
***************
*** 81,85 ****
  	/* Configure a stack that we can use. */
  	
! 	movl 	$_start, %eax
  	movw 	%ax, %sp
  	shr 	$4, %eax
--- 90,94 ----
  	/* Configure a stack that we can use. */
  	
! 	movl 	$(_start-4), %eax
  	movw 	%ax, %sp
  	shr 	$4, %eax
***************
*** 101,105 ****
--- 110,125 ----
  	shl	$10, %eax
  	pushl	%eax
+ #ifndef CYG_HAL_STARTUP_BIOS
  
+ #ifdef CYG_HAL_STARTUP_DISK
+ 	/* read disk parameters into safe location */
+ 	movb	$0x80,%dl
+ 	movb	$0x08,%ah
+ 	int	$0x13
+ 	jc	_error2
+ 	andb 	$0x3F,%cl	/* sectors per track */
+ 	movb	%cl,%cs:secPerTrack
+ 	movb	%dh,%cs:maxHead
+ #else
  	/* reset floppy */
  	movb $0,%ah
***************
*** 107,111 ****
  	int $0x13
  	jc _error1
! 	
  	/* 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
--- 127,131 ----
  	int $0x13
  	jc _error1
! #endif
  	/* 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
***************
*** 126,131 ****
--- 146,156 ----
  
  	/* initials head/track/sector */
+ #ifdef CYG_HAL_STARTUP_FLOPPY
  	movw	$0,%dx
  	movw	$1,%cx
+ #else
+ 	movw	$0x0180,%dx
+ 	movw	$1,%cx
+ #endif
  
  	movl	$_edata,%edi
***************
*** 134,138 ****
  	
  	jmp	_loadsector
! 
  _nextsector:
  	movw	%es,%ax
--- 159,179 ----
  	
  	jmp	_loadsector
! #ifdef CYG_HAL_STARTUP_DISK
! _nextsector:
! 	movw	%es,%ax
! 	cmpw	%di,%ax
! 	jge	_endload
! 	addw	$esPerSector,%ax
! 	movw	%ax,%es
! 	incb	%cl
!         cmpb	%cs:secPerTrack,%cl 
!         jbe	_loadsector	/* next head ?*/
! 	movb	$1, %cl
!         incb	%dh    
!         cmpb	%cs:maxHead,%dh
!         jbe	_loadsector	/* next track ? */
!         movb	$0, %dh
!         incb	%ch    
! #else
  _nextsector:
  	movw	%es,%ax
***************
*** 150,154 ****
          movb	$0, %dh
          incb	%ch    
! 
  _loadsector:
  
--- 191,195 ----
          movb	$0, %dh
          incb	%ch    
! #endif
  _loadsector:
  
***************
*** 203,208 ****
  	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.  
--- 244,248 ----
  	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.  
***************
*** 216,219 ****
--- 256,260 ----
  1:
  
+ #ifdef CYG_HAL_STARTUP_FLOPPY
  	/* Lets be nice and wait for the diskette drive motor to go off
           * before continuing. */
***************
*** 226,231 ****
  	cmpb	$0, %al
  	jne	2b
! 
  	/* Now we're all loaded up in memory. */
  
  	/* Optionally switch to a high-res video before entering	*/
--- 267,273 ----
  	cmpb	$0, %al
  	jne	2b
! #endif
  	/* Now we're all loaded up in memory. */
+ #endif  // CYG_HAL_STARTUP_BIOS
  
  	/* Optionally switch to a high-res video before entering	*/
***************
*** 389,393 ****
  	.endm /* hal_cpu_init */
  	
! #endif /* CYG_HAL_STARTUP_FLOPPY */
  
  #endif // CYGPKG_HAL_I386_CPU_INIT_DEFINED
--- 431,435 ----
  	.endm /* hal_cpu_init */
  	
! #endif /* CYG_HAL_STARTUP==FLOPPY || CYG_HAL_STARTUP==DISK || CYG_HAL_STARTUP==BIOS */
  
  #endif // CYGPKG_HAL_I386_CPU_INIT_DEFINED

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]