wok rev 538

Etherboot: can boot with grub too
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Apr 10 21:55:02 2008 +0000 (2008-04-10)
parents 38edb0e5bd67
children 47e6882f05da
files etherboot/receipt etherboot/stuff/etherboot-prefix.u
line diff
     1.1 --- a/etherboot/receipt	Thu Apr 10 19:43:50 2008 +0000
     1.2 +++ b/etherboot/receipt	Thu Apr 10 21:55:02 2008 +0000
     1.3 @@ -14,7 +14,8 @@
     1.4  {
     1.5  	cd $src/src
     1.6  	patch -p2 < ../../stuff/etherboot-net.u
     1.7 -	make bin/etherboot-net.zdsk
     1.8 +	patch -p2 < ../../stuff/etherboot-prefix.u
     1.9 +	make bin/etherboot-net.zlilo
    1.10  }
    1.11  
    1.12  
    1.13 @@ -22,7 +23,7 @@
    1.14  genpkg_rules()
    1.15  {
    1.16  	mkdir -p $fs/usr/share/boot
    1.17 -	cp $src/src/bin/etherboot-net.zdsk $fs/usr/share/boot/etherboot
    1.18 +	cp $src/src/bin/etherboot-net.zlilo $fs/usr/share/boot/etherboot
    1.19  }
    1.20  
    1.21  # Pre and post install commands for Tazpkg.
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/etherboot/stuff/etherboot-prefix.u	Thu Apr 10 21:55:02 2008 +0000
     2.3 @@ -0,0 +1,426 @@
     2.4 +--- etherboot-5.4.3/src/arch/i386/prefix/liloprefix.S
     2.5 ++++ etherboot-5.4.3/src/arch/i386/prefix/liloprefix.S
     2.6 +@@ -1,92 +1,361 @@
     2.7 +-/*
     2.8 +-	Copyright (C) 2000, Entity Cyber, Inc.
     2.9 +-
    2.10 +-	Authors: Gary Byers (gb@thinguin.org)
    2.11 +-		 Marty Connor (mdc@thinguin.org)
    2.12 +-
    2.13 +-	This software may be used and distributed according to the terms
    2.14 +-	of the GNU Public License (GPL), incorporated herein by reference.
    2.15 +-
    2.16 +-	Description:	
    2.17 +-
    2.18 +-	This is just a little bit of code and data that can get prepended
    2.19 +-	to an Etherboot ROM image in order to allow LILO to load the
    2.20 +-	result as if it were a Linux kernel image.
    2.21 +-
    2.22 +-	A real Linux kernel image consists of a one-sector boot loader
    2.23 +-	(to load the image from a floppy disk), followed a few sectors
    2.24 +-	of setup code, followed by the kernel code itself.  There's
    2.25 +-	a table in the first sector (starting at offset 497) that indicates
    2.26 +-	how many sectors of setup code follow the first sector and which
    2.27 +-	contains some other parameters that aren't interesting in this
    2.28 +-	case.
    2.29 +-
    2.30 +-	When LILO loads the sectors that comprise a kernel image, it doesn't
    2.31 +-	execute the code in the first sector (since that code would try to
    2.32 +-	load the image from a floppy disk.)  The code in the first sector
    2.33 +-	below doesn't expect to get executed (and prints an error message
    2.34 +-	if it ever -is- executed.)  LILO's only interested in knowing the
    2.35 +-	number of setup sectors advertised in the table (at offset 497 in
    2.36 +-	the first sector.)
    2.37 +-
    2.38 +-	Etherboot doesn't require much in the way of setup code.
    2.39 +-	Historically, the Linux kernel required at least 4 sectors of
    2.40 +-	setup code.  Current versions of LILO look at the byte at
    2.41 +-	offset 497 in the first sector to indicate how many sectors
    2.42 +-	of setup code are contained in the image.
    2.43 +-
    2.44 +-*/
    2.45 ++/* NOTE: this boot sector contains instructions that need at least an 80186.
    2.46 ++ * Yes, as86 has a bug somewhere in the valid instruction set checks.
    2.47 ++ *
    2.48 ++ * SYS_SIZE is the number of clicks (16 bytes) to be loaded.  For Etherboot
    2.49 ++ * purposes, we need to load everything but the boot sector itself, i.e. 32
    2.50 ++ * clicks less than the size of the entire (verbatim) image.  The image size
    2.51 ++ * is practically limited only by the available base memory size.
    2.52 ++ */
    2.53 ++.globl	SYSSIZE
    2.54 ++.equ	SYSSIZE, _verbatim_size_pgh - 32
    2.55 ++
    2.56 ++/*	floppyload.S Copyright (C) 1991, 1992 Linus Torvalds
    2.57 ++ *	modified by Drew Eckhardt
    2.58 ++ *	modified by Bruce Evans (bde)
    2.59 ++ *
    2.60 ++ * floppyprefix.S is loaded at 0x0000:0x7c00 by the bios-startup routines.
    2.61 ++ *
    2.62 ++ * It then loads the system at SYSSEG<<4, using BIOS interrupts.
    2.63 ++ *
    2.64 ++ * The loader has been made as simple as possible, and continuous read errors
    2.65 ++ * will result in a unbreakable loop. Reboot by hand. It loads pretty fast by
    2.66 ++ * getting whole tracks at a time whenever possible.
    2.67 ++ */
    2.68 + 
    2.69 + #define	SETUPSECS 4		/* Minimal nr of setup-sectors */
    2.70 + #define PREFIXSIZE ((SETUPSECS+1)*512)
    2.71 + #define PREFIXPGH (PREFIXSIZE / 16 )
    2.72 +-#define	BOOTSEG  0x07C0		/* original address of boot-sector */
    2.73 + #define	INITSEG  0x9000		/* we move boot here - out of the way */
    2.74 + #define	SETUPSEG 0x9020		/* setup starts here */
    2.75 +-#define SYSSEG   0x1000		/* system loaded at 0x10000 (65536). */
    2.76 + 
    2.77 +-	.text
    2.78 +-	.code16
    2.79 +-	.arch i386
    2.80 +-	.org	0
    2.81 +-	.section ".prefix", "ax", @progbits
    2.82 + 	.globl	_prefix
    2.83 + _prefix:
    2.84 ++.equ	BOOTSEG, 0x07C0			/* original address of boot-sector */
    2.85 + 
    2.86 +-/* 
    2.87 +-	This is a minimal boot sector.	If anyone tries to execute it (e.g., if
    2.88 +-	a .lilo file is dd'ed to a floppy), print an error message. 
    2.89 +-*/
    2.90 ++.equ	SYSSEG, 0x1000			/* system loaded at SYSSEG<<4 */
    2.91 + 
    2.92 +-bootsector: 
    2.93 +-	jmp	$BOOTSEG, $go - _prefix	/* reload cs:ip to match relocation addr */
    2.94 ++	.org	0
    2.95 ++	.arch i386
    2.96 ++	.text
    2.97 ++	.section ".prefix", "ax", @progbits
    2.98 ++	.code16
    2.99 ++
   2.100 ++	jmp	$BOOTSEG, $go		/* reload cs:ip to match relocation addr */
   2.101 + go: 
   2.102 +-	movw	$0x2000, %di		/*  0x2000 is arbitrary value >= length
   2.103 +-					    of bootsect + room for stack */
   2.104 ++	movw	$0x2000-12, %di		/* 0x2000 is arbitrary value >= length */
   2.105 ++					/* of bootsect + room for stack + 12 for */
   2.106 ++					/* saved disk parm block */
   2.107 + 
   2.108 + 	movw	$BOOTSEG, %ax
   2.109 + 	movw	%ax,%ds
   2.110 + 	movw	%ax,%es
   2.111 +-
   2.112 +-	cli
   2.113 +-	movw	%ax, %ss		/* put stack at BOOTSEG:0x2000. */
   2.114 ++	movw	%ax,%ss			/* put stack at initial position */
   2.115 + 	movw	%di,%sp
   2.116 +-	sti
   2.117 + 
   2.118 +-	movw	$why_end-why, %cx
   2.119 +-	movw	$why - _prefix, %si
   2.120 ++/* Many BIOS's default disk parameter tables will not recognize multi-sector
   2.121 ++ * reads beyond the maximum sector number specified in the default diskette
   2.122 ++ * parameter tables - this may mean 7 sectors in some cases.
   2.123 ++ *
   2.124 ++ * Since single sector reads are slow and out of the question, we must take care
   2.125 ++ * of this by creating new parameter tables (for the first disk) in RAM.  We
   2.126 ++ * will set the maximum sector count to 36 - the most we will encounter on an
   2.127 ++ * ED 2.88.  High doesn't hurt.	Low does.
   2.128 ++ *
   2.129 ++ * Segments are as follows: ds=es=ss=cs - BOOTSEG
   2.130 ++ */
   2.131 ++
   2.132 ++	xorw	%cx,%cx
   2.133 ++	movw	%cx,%es			/* access segment 0 */
   2.134 ++	movw	$0x78, %bx		/* 0:bx is parameter table address */
   2.135 ++	pushw	%ds			/* save ds */
   2.136 ++/* 0:bx is parameter table address */
   2.137 ++	ldsw	%es:(%bx),%si		/* loads ds and si */
   2.138 ++
   2.139 ++	movw	%ax,%es			/* ax is BOOTSECT (loaded above) */
   2.140 ++	movb	$6, %cl			/* copy 12 bytes */
   2.141 ++	cld
   2.142 ++	pushw	%di			/* keep a copy for later */
   2.143 ++	rep
   2.144 ++	movsw				/* ds:si is source, es:di is dest */
   2.145 ++	popw	%di
   2.146 ++
   2.147 ++	movb	$36,%es:4(%di)
   2.148 ++
   2.149 ++	movw	%cx,%ds			/* access segment 0 */
   2.150 ++	xchgw	%di,(%bx)
   2.151 ++	movw	%es,%si
   2.152 ++	xchgw	%si,2(%bx)
   2.153 ++	popw	%ds			/* restore ds */
   2.154 ++	movw	%di, dpoff		/* save old parameters */
   2.155 ++	movw	%si, dpseg		/* to restore just before finishing */
   2.156 ++	pushw	%ds
   2.157 ++	popw	%es			/* reload es */
   2.158 ++
   2.159 ++/* Note that es is already set up.  Also cx is 0 from rep movsw above. */
   2.160 ++
   2.161 ++	xorb	%ah,%ah			/* reset FDC */
   2.162 ++	xorb	%dl,%dl
   2.163 ++	int	$0x13
   2.164 ++
   2.165 ++/* Get disk drive parameters, specifically number of sectors/track.
   2.166 ++ *
   2.167 ++ * It seems that there is no BIOS call to get the number of sectors.  Guess
   2.168 ++ * 36 sectors if sector 36 can be read, 18 sectors if sector 18 can be read,
   2.169 ++ * 15 if sector 15 can be read.	Otherwise guess 9.
   2.170 ++ */
   2.171 ++
   2.172 ++	movw	$disksizes, %si		/* table of sizes to try */
   2.173 ++
   2.174 ++probe_loop: 
   2.175 ++	lodsb
   2.176 ++	cbtw				/* extend to word */
   2.177 ++	movw	%ax, sectors
   2.178 ++	cmpw	$disksizes+4, %si
   2.179 ++	jae	got_sectors		/* if all else fails, try 9 */
   2.180 ++	xchgw	%cx,%ax			/* cx = track and sector */
   2.181 ++	xorw	%dx,%dx			/* drive 0, head 0 */
   2.182 ++	movw	$0x0200, %bx		/* address after boot sector */
   2.183 ++					/*   (512 bytes from origin, es = cs) */
   2.184 ++	movw	$0x0201, %ax		/* service 2, 1 sector */
   2.185 ++	int	$0x13
   2.186 ++	jc	probe_loop		/* try next value */
   2.187 ++
   2.188 ++got_sectors: 
   2.189 ++	movw	$msg1end-msg1, %cx
   2.190 ++	movw	$msg1, %si
   2.191 ++	call	print_str
   2.192 ++
   2.193 ++/* ok, we've written the Loading... message, now we want to load the system */
   2.194 ++
   2.195 ++	pushw	%es			/* = ds */
   2.196 ++	movw	$SYSSEG, %ax
   2.197 ++	movw	%ax,%es			/* segment of SYSSEG<<4 */
   2.198 ++	pushw	%es
   2.199 ++	call	read_it
   2.200 ++
   2.201 ++/* This turns off the floppy drive motor, so that we enter the kernel in a
   2.202 ++ * known state, and don't have to worry about it later.
   2.203 ++ */
   2.204 ++	movw	$0x3f2, %dx
   2.205 ++	xorb	%al,%al
   2.206 ++	outb	%al,%dx
   2.207 ++
   2.208 ++	call	print_nl
   2.209 ++	pop	%es			/* = SYSSEG */
   2.210 ++	pop	%es			/* balance push/pop es */
   2.211 ++sigok: 
   2.212 ++
   2.213 ++/* Restore original disk parameters */
   2.214 ++	movw	$0x78, %bx
   2.215 ++	movw	dpoff, %di
   2.216 ++	movw	dpseg, %si
   2.217 ++	xorw	%ax,%ax
   2.218 ++	movw	%ax,%ds
   2.219 ++	movw	%di,(%bx)
   2.220 ++	movw	%si,2(%bx)
   2.221 ++
   2.222 ++/* after that (everything loaded), we call to the .ROM file loaded. */
   2.223 ++
   2.224 ++	pushl	$0		/* No parameters to preserve for exit path */
   2.225 ++	pushw	$0		/* Use prefix exit path mechanism */
   2.226 ++	ljmp	$SYSSEG, $_start
   2.227 ++
   2.228 ++/* This routine loads the system at address SYSSEG<<4, making sure no 64kB
   2.229 ++ * boundaries are crossed. We try to load it as fast as possible, loading whole
   2.230 ++ * tracks whenever we can.
   2.231 ++ *
   2.232 ++ * in:	es - starting address segment (normally SYSSEG)
   2.233 ++ */
   2.234 ++read_it: 
   2.235 ++	movw	$0,sread		/* read whole image incl boot sector */
   2.236 ++	movw	%es,%ax
   2.237 ++	testw	$0x0fff, %ax
   2.238 ++die:	jne	die			/* es must be at 64kB boundary */
   2.239 ++	xorw	%bx,%bx			/* bx is starting address within segment */
   2.240 ++rp_read: 
   2.241 ++	movw	%es,%ax
   2.242 ++	movw	%bx,%dx
   2.243 ++	movb	$4, %cl
   2.244 ++	shrw	%cl,%dx			/* bx is always divisible by 16 */
   2.245 ++	addw	%dx,%ax
   2.246 ++	cmpw	$SYSSEG+SYSSIZE, %ax	/* have we loaded all yet? */
   2.247 ++	jb	ok1_read
   2.248 ++	ret
   2.249 ++ok1_read: 
   2.250 ++	movw	sectors, %ax
   2.251 ++	subw	sread, %ax
   2.252 ++	movw	%ax,%cx
   2.253 ++	shlw	$9, %cx
   2.254 ++	addw	%bx,%cx
   2.255 ++	jnc	ok2_read
   2.256 ++	je	ok2_read
   2.257 ++	xorw	%ax,%ax
   2.258 ++	subw	%bx,%ax
   2.259 ++	shrw	$9, %ax
   2.260 ++ok2_read: 
   2.261 ++	call	read_track
   2.262 ++	movw	%ax,%cx
   2.263 ++	addw	sread, %ax
   2.264 ++	cmpw	sectors, %ax
   2.265 ++	jne	ok3_read
   2.266 ++	movw	$1, %ax
   2.267 ++	subw	head, %ax
   2.268 ++	jne	ok4_read
   2.269 ++	incw	track
   2.270 ++ok4_read: 
   2.271 ++	movw	%ax, head
   2.272 ++	xorw	%ax,%ax
   2.273 ++ok3_read: 
   2.274 ++	movw	%ax, sread
   2.275 ++	shlw	$9, %cx
   2.276 ++	addw	%cx,%bx
   2.277 ++	jnc	rp_read
   2.278 ++	movw	%es,%ax
   2.279 ++	addb	$0x10, %ah
   2.280 ++	movw	%ax,%es
   2.281 ++	xorw	%bx,%bx
   2.282 ++	jmp	rp_read
   2.283 ++
   2.284 ++read_track: 
   2.285 ++	pusha
   2.286 ++	pushw	%ax
   2.287 ++	pushw	%bx
   2.288 ++	pushw	%bp			/* just in case the BIOS is buggy */
   2.289 ++	movw	$0x0e2e, %ax		/* 0x2e = . */
   2.290 ++	movw	$0x0007, %bx
   2.291 ++	int	$0x10
   2.292 ++	popw	%bp
   2.293 ++	popw	%bx
   2.294 ++	popw	%ax
   2.295 ++
   2.296 ++	movw	track, %dx
   2.297 ++	movw	sread, %cx
   2.298 ++	incw	%cx
   2.299 ++	movb	%dl,%ch
   2.300 ++	movw	head, %dx
   2.301 ++	movb	%dl,%dh
   2.302 ++	andw	$0x0100, %dx
   2.303 ++	movb	$2, %ah
   2.304 ++
   2.305 ++	pushw	%dx			/* save for error dump */
   2.306 ++	pushw	%cx
   2.307 ++	pushw	%bx
   2.308 ++	pushw	%ax
   2.309 ++
   2.310 ++	int	$0x13
   2.311 ++	jc	bad_rt
   2.312 ++	addw	$8, %sp
   2.313 ++	popa
   2.314 ++	ret
   2.315 ++
   2.316 ++bad_rt: pushw	%ax			/* save error code */
   2.317 ++	call	print_all		/* ah = error, al = read */
   2.318 ++
   2.319 ++	xorb	%ah,%ah
   2.320 ++	xorb	%dl,%dl
   2.321 ++	int	$0x13
   2.322 ++
   2.323 ++	addw	$10, %sp
   2.324 ++	popa
   2.325 ++	jmp	read_track
   2.326 ++
   2.327 ++/* print_all is for debugging purposes.	It will print out all of the registers.
   2.328 ++ * The assumption is that this is called from a routine, with a stack frame like
   2.329 ++ *	dx
   2.330 ++ *	cx
   2.331 ++ *	bx
   2.332 ++ *	ax
   2.333 ++ *	error
   2.334 ++ *	ret <- sp
   2.335 ++ */
   2.336 ++
   2.337 ++print_all: 
   2.338 ++	call	print_nl		/* nl for readability */
   2.339 ++	movw	$5, %cx			/* error code + 4 registers */
   2.340 ++	movw	%sp,%bp
   2.341 ++
   2.342 ++print_loop: 
   2.343 ++	pushw	%cx			/* save count left */
   2.344 ++
   2.345 ++	cmpb	$5, %cl
   2.346 ++	jae	no_reg			/* see if register name is needed */
   2.347 + 
   2.348 + 	movw	$0x0007, %bx		/* page 0, attribute 7 (normal) */
   2.349 ++	movw	$0xe05+0x41-1, %ax
   2.350 ++	subb	%cl,%al
   2.351 ++	int	$0x10
   2.352 ++
   2.353 ++	movb	$0x58, %al		/* 'X' */
   2.354 ++	int	$0x10
   2.355 ++
   2.356 ++	movb	$0x3A, %al		/* ':' */
   2.357 ++	int	$0x10
   2.358 ++
   2.359 ++no_reg: 
   2.360 ++	addw	$2, %bp			/* next register */
   2.361 ++	call	print_hex		/* print it */
   2.362 ++	movb	$0x20, %al		/* print a space */
   2.363 ++	int	$0x10
   2.364 ++	popw	%cx
   2.365 ++	loop	print_loop
   2.366 ++	call	print_nl		/* nl for readability */
   2.367 ++	ret
   2.368 ++
   2.369 ++print_str: 
   2.370 ++	movw	$0x0007, %bx		/* page 0, attribute 7 (normal) */
   2.371 + 	movb	$0x0e, %ah		/* write char, tty mode */
   2.372 + prloop: 
   2.373 + 	lodsb
   2.374 + 	int	$0x10
   2.375 + 	loop	prloop
   2.376 +-freeze: jmp	freeze
   2.377 ++	ret
   2.378 ++
   2.379 ++print_nl: 
   2.380 ++	movw	$0x0007, %bx		/* page 0, attribute 7 (normal) */
   2.381 ++	movw	$0xe0d, %ax		/* CR */
   2.382 ++	int	$0x10
   2.383 ++	movb	$0xa, %al		/* LF */
   2.384 ++	int	$0x10
   2.385 ++	ret
   2.386 ++
   2.387 ++/* print_hex prints the word pointed to by ss:bp in hexadecimal. */
   2.388 ++
   2.389 ++print_hex: 
   2.390 ++	movw	(%bp),%dx		/* load word into dx */
   2.391 ++	movb	$4, %cl
   2.392 ++	movb	$0x0e, %ah		/* write char, tty mode */
   2.393 ++	movw	$0x0007, %bx		/* page 0, attribute 7 (normal) */
   2.394 ++	call	print_digit
   2.395 ++	call	print_digit
   2.396 ++	call	print_digit
   2.397 ++/* fall through */
   2.398 ++print_digit: 
   2.399 ++	rol	%cl,%dx			/* rotate so that lowest 4 bits are used */
   2.400 ++	movb	$0x0f, %al		/* mask for nybble */
   2.401 ++	andb	%dl,%al
   2.402 ++	addb	$0x90, %al		/* convert al to ascii hex (four instructions) */
   2.403 ++	daa
   2.404 ++	adcb	$0x40, %al
   2.405 ++	daa
   2.406 ++	int	$0x10
   2.407 ++	ret
   2.408 ++
   2.409 ++sread:	.word 0				/* sectors read of current track */
   2.410 ++head:	.word 0				/* current head */
   2.411 ++track:	.word 0				/* current track */
   2.412 ++
   2.413 ++sectors: 
   2.414 ++	.word 0
   2.415 ++
   2.416 ++dpseg:	.word 0
   2.417 ++dpoff:	.word 0
   2.418 + 
   2.419 +-why:	.ascii	"This image cannot be loaded from a floppy disk.\r\n"
   2.420 +-why_end: 
   2.421 ++disksizes: 
   2.422 ++	.byte 36,18,15,9
   2.423 + 
   2.424 ++msg1: 
   2.425 ++	.ascii "Loading ROM image"
   2.426 ++msg1end: 
   2.427 + 
   2.428 + 	.org	497
   2.429 + setup_sects: