wok-tiny rev 95

linux: add bootloader
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Oct 06 21:04:42 2015 +0200 (2015-10-06)
parents 371673f39e46
children 2c3b4f47fbf5
files linux/receipt linux/stuff/bootloader.S linux/stuff/bundle
line diff
     1.1 --- a/linux/receipt	Fri Oct 02 21:45:05 2015 +0200
     1.2 +++ b/linux/receipt	Tue Oct 06 21:04:42 2015 +0200
     1.3 @@ -36,6 +36,8 @@
     1.4  	cp $WOK/busybox/source/busybox*/.config $src/config-busybox
     1.5  	mkdir $src/slitaz
     1.6  	cp $stuff/list_modules.sh $src/slitaz
     1.7 +	cc -o bootloader.o -Wa,-algms=bootloader.lst -c $stuff/bootloader.S
     1.8 +	objcopy -O binary bootloader.o bootloader.bin
     1.9  
    1.10  	sed -i 's/^config %config/config/' Makefile
    1.11  	cp $stuff/linux-$VERSION-slitaz.config .config
    1.12 @@ -51,9 +53,11 @@
    1.13  {
    1.14  	mkdir $fs/boot
    1.15  	cp -a $src/arch/i386/boot/bzImage $fs/boot/
    1.16 +	dd if=$src/bootloader.bin of=$fs/boot/bzImage conv=notrunc
    1.17  	cp -a $src/System.map $fs/boot/
    1.18  	cp -a $src/.config $fs/boot/config
    1.19  	cp -a $src/config-busybox $fs/boot
    1.20 +	cp -a $stuff/bundle $fs/boot
    1.21  }
    1.22  
    1.23  # Pre and post install commands for Tazpkg.
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/linux/stuff/bootloader.S	Tue Oct 06 21:04:42 2015 +0200
     2.3 @@ -0,0 +1,824 @@
     2.4 +BOOTSEG		= 0x07C0		/* original address of boot-sector */
     2.5 +SYSSEG		= 0x1000		/* historical load address >> 4 */
     2.6 +INITSEG		= 0x9000		/* boot address >> 4 */
     2.7 +SETUPSEG	= 0x9020		/* setup address >> 4 */
     2.8 +ASK_VGA		= -3
     2.9 +
    2.10 +#ifndef SVGA_MODE
    2.11 +#define SVGA_MODE ASK_VGA
    2.12 +#endif
    2.13 +
    2.14 +#ifndef RAMDISK
    2.15 +#define RAMDISK 0
    2.16 +#endif
    2.17 +
    2.18 +#ifndef ROOT_RDONLY
    2.19 +#define ROOT_RDONLY 1
    2.20 +#endif
    2.21 +
    2.22 +/* Assume protocol 2.00+ (kernel >= 1.3.73) */
    2.23 +/* feature set */
    2.24 +#define EXE_SUPPORT		real mode dos .exe file support
    2.25 +// #define EXE_ONLY		remove floppy code
    2.26 +#define EXE_CMDLINE		kernel >= 2.4
    2.27 +// #define FLOPPY_CMDLINE	kernel >= 2.4
    2.28 +// #define OLDCMDLINE		kernel  < 2.4
    2.29 +#define MORETHAN16M		up to 4Gb RAM, not 16Mb
    2.30 +#define KEYBOARDLESS_SUPPORT	scan floppy swap each 5 seconds
    2.31 +// #define FAT12_SUPPORT	will format the floppy free space in FAT 12
    2.32 +// #define REALMODE_NOT_CHECKED	exe crash when started in vm86
    2.33 +// #define SINGLE_FLOPPY	Everytihng fit in a single floppy
    2.34 +// #define EDIT_CMDLINE
    2.35 +// #define MOVE_CMDLINE
    2.36 +#define INITRD_SUPPORT
    2.37 +// #define INITRD_AUTOADDR	Hole in 16Mb..32Mb
    2.38 +// #define MULTI_INITRD		Russian dolls
    2.39 +// #define README_SUPPORT
    2.40 +// #define COUNTER		Show floppy number
    2.41 +#define LABEL "SliTaz"
    2.42 +
    2.43 +	.code16
    2.44 +	.org	0
    2.45 +
    2.46 +bootsect_start:
    2.47 +
    2.48 +cur_initrd_size_ofs	= 494
    2.49 +ramdisk_image_ofs	= 0x218
    2.50 +ramdisk_image	=	bootsect_start+ramdisk_image_ofs
    2.51 +ramdisk_size_ofs	= 0x21C
    2.52 +ramdisk_size	=	bootsect_start+ramdisk_size_ofs
    2.53 +cmd_line_ptr_ofs	= 0x228
    2.54 +cmd_line_ptr	=	bootsect_start+cmd_line_ptr_ofs
    2.55 +setup_sects	=	bootsect_start+497
    2.56 +syssize		=	bootsect_start+500
    2.57 +boot_flag_ofs	= 510
    2.58 +boot_flag	=	bootsect_start+boot_flag_ofs
    2.59 +
    2.60 +
    2.61 +stacktop	= 0x9E00		# in 0x8000 .. 0xA000
    2.62 +zeroed		= 48+10			# gdt + zeroed registers
    2.63 +.macro	INIT_REGS
    2.64 +	movw	$stacktop-zeroed, %di	# stacktop is an arbitrary value >=
    2.65 +					# length of bootsect + length of
    2.66 +					# setup + room for stack;
    2.67 +					# 12 is disk parm size.
    2.68 +	pushw	$INITSEG
    2.69 +	popw	%ss			# %ss contain INITSEG
    2.70 +	movw	%di, %sp		# put stack at INITSEG:stacktop-...
    2.71 +	pushw	%ss
    2.72 +	popw	%es			# %es = %ss = INITSEG
    2.73 +	xorw	%ax, %ax		# %ax = 0
    2.74 +#if defined(EXE_CMDLINE)
    2.75 +	movw	$zeroed+1, %cx		# clear gdt + offset, %ds, limits, cmdline=""
    2.76 +	rep				# don't worry about cld
    2.77 +	stosb				# already done above
    2.78 +	decw	%di
    2.79 +#else
    2.80 +	movw	$zeroed/2, %cx		# clear gdt + offset, %ds, limits
    2.81 +	rep				# don't worry about cld
    2.82 +	stosw				# already done above
    2.83 +#endif
    2.84 +	popw	%bx			# offset = 0
    2.85 +.endm
    2.86 +
    2.87 +#ifdef FAT12_SUPPORT
    2.88 +	jmp	fdstart
    2.89 +	nop
    2.90 +	.ascii	"SLITAZ  "
    2.91 +	.word	512			// 0B: bytes per sector
    2.92 +	.byte	1			// 0D: sectors per cluster
    2.93 +	.word	2880			// 0E: reserved seectors
    2.94 +	.byte	2			// 10: FAT number
    2.95 +	.word	64			// 11: root entries 4x 16
    2.96 +	.word	2880			// 13: total sectors
    2.97 +	.byte	0xF0			// 15: media id (or F9)
    2.98 +#endif
    2.99 +
   2.100 +#ifdef EXE_SUPPORT
   2.101 +#define CODESZ		0x8000
   2.102 +#define EXEADRS(x)	x+0xE0
   2.103 +	decw	%bp			// Magic number: MZ
   2.104 +	popw	%dx
   2.105 +#ifdef EXE_ONLY
   2.106 +	.word	512			// Bytes on last page of file
   2.107 +#else
   2.108 +	jmp	fdstart			// Bytes on last page of file
   2.109 +#endif
   2.110 +	.word	(CODESZ+511)/512	// Pages in file
   2.111 +	.word	0			// Relocations
   2.112 +	.word	2			// Size of header in paragraphs
   2.113 +	.word	4096			// Minimum extra paragraphs needed
   2.114 +	.word	-1			// Maximum extra paragraphs needed
   2.115 +	.word	(CODESZ+15)/16		// Initial (relative) SS value
   2.116 +	.word	stacktop+4		// Initial SP value (+callf)
   2.117 +	.word	0			// Checksum
   2.118 +	.word	EXEADRS(comstart)	// Initial IP value
   2.119 +	.word	0xFFF0			// Initial (relative) CS value
   2.120 +#if defined(EXE_ONLY) || defined(SINGLE_FLOPPY) || defined(COUNTER)
   2.121 +//	.word	0x001C			// File address of relocation table
   2.122 +//	.word	0,0,0			// Overlay number
   2.123 +	.ascii	"(SliTaz)"
   2.124 +#else
   2.125 +swap_floppy:
   2.126 +	.ascii	"Next!"
   2.127 +	.byte	7,13,0			# swap detection needs 13, 0
   2.128 +#endif
   2.129 +#ifdef OLDCMDLINE
   2.130 +# ifdef FLOPPY_CMDLINE
   2.131 +	.word	0			# 0xA33F
   2.132 +	.word	0			# stacktop
   2.133 +# else
   2.134 +	.word	0xA33F
   2.135 +	.word	stacktop
   2.136 +# endif
   2.137 +#endif
   2.138 +#ifndef EXE_ONLY
   2.139 +fdstart:
   2.140 +	pushw	%dx
   2.141 +#endif
   2.142 +#endif
   2.143 + 
   2.144 +LOADSEG		= 0x8000		# 0x1000 multiple, up to 512K zImage
   2.145 +LOADSZ		= 0x10000
   2.146 +
   2.147 +#if defined(EXE_SUPPORT) || defined(EXE_ONLY)
   2.148 +A20BUFFER	= 0x68000		# a20 gate / himem.sys support
   2.149 +#define USEA20BUFFER
   2.150 +#endif
   2.151 + 
   2.152 +#ifndef EXE_ONLY
   2.153 +# bootsect_start:
   2.154 +#ifdef EXE_SUPPORT
   2.155 +	call	initregs
   2.156 +	cwd				# floppy = head = 0
   2.157 +#else
   2.158 +	INIT_REGS
   2.159 +#endif
   2.160 +	popw	%ds			# %ds = 0
   2.161 +	movb	setup_sects+0x7C00, %al	# read bootsector + setup
   2.162 +	incw	%ax			# %ax = setup_sects+bootsect
   2.163 +	popw	%fs			# %fs = 0
   2.164 +
   2.165 +# Many BIOS's default disk parameter tables will not recognize
   2.166 +# multi-sector reads beyond the maximum sector number specified
   2.167 +# in the default diskette parameter tables - this may mean 7
   2.168 +# sectors in some cases.
   2.169 +#
   2.170 +# Since single sector reads are slow and out of the question,
   2.171 +# we must take care of this by creating new parameter tables
   2.172 +# (for the first disk) in RAM.  We can set the maximum sector
   2.173 +# count to 36 - the most we will encounter on an ED 2.88.  
   2.174 +#
   2.175 +# High doesn't hurt.  Low does.  Let's use the max: 63
   2.176 +
   2.177 +	cli
   2.178 +	ldsw	0x78(%bx), %si		# %ds:%bx+0x78 is parameter table address
   2.179 +	popw	%di
   2.180 +	pushw	%es
   2.181 +	pushw	%di
   2.182 +#ifdef	FLOPPY_CMDLINE
   2.183 +	movw	$0, %bp			# patched by installer (7C22)
   2.184 +skipcmdline:
   2.185 +#define cmd_line_ptr	0x22
   2.186 +#endif
   2.187 +	movb	$6, %cl			# copy 12 bytes
   2.188 +	rep				# don't worry about cld
   2.189 +	  movsw				# already done above
   2.190 +	pushw	%ss
   2.191 +	popw	%ds			# now %ds = %es = %ss = INITSEG
   2.192 +	popl	%fs:0x78(%bx)		# update parameter table address
   2.193 +	movb	$63, 0x4-12(%di)	# patch sector count, %di = stacktop
   2.194 +
   2.195 +	xchg	%ax, %di		# sector count
   2.196 +	popw	%ax			# limits = 0
   2.197 +	incw	%cx			# cylinder 0, sector 1, clear Z
   2.198 +	call	read_first_sectors	# read setup
   2.199 +#ifdef	README_SUPPORT
   2.200 +	xorw	%si, %si
   2.201 +	orw	readme, %si
   2.202 +	jz	readmeend
   2.203 +readmeloop:
   2.204 +	call	puts
   2.205 +	jz	readmeend
   2.206 +	call	wait4key
   2.207 +	cmpb	$27, %al
   2.208 +	jne	readmeloop
   2.209 +readmeend:
   2.210 +#endif
   2.211 +#endif
   2.212 +loadsys:
   2.213 +	movw	$0x200,%si
   2.214 +type_of_loader	=	0x10
   2.215 +loadflags	=	0x11
   2.216 +heap_end_ptr	=	0x24
   2.217 +	orw	$0x8020, type_of_loader(%si) # loader type = 0x20 = bootsect-loader
   2.218 +	movb	$(stacktop-0x300)/256, heap_end_ptr+1(%si)
   2.219 +	call	puts_version		# show which kernel we are loading
   2.220 +
   2.221 +#ifdef	FLOPPY_CMDLINE
   2.222 +# The cmdline can be entered and modifed at boot time.
   2.223 +# Only characters before the cursor are passed to the kernel.
   2.224 +
   2.225 +	xorw	%si, %si
   2.226 +	orw	cmd_line_ptr-7(%bx), %si
   2.227 +	jz	nocmdline
   2.228 +#ifdef OLDCMDLINE
   2.229 +	movw	$0xA33F, cmd_line_ptr-2-7(%bx)
   2.230 +#endif
   2.231 +	call	puts
   2.232 +#ifdef	EDIT_CMDLINE
   2.233 +cmdlp:
   2.234 +	movb	$0x20, %al		# clear end of line
   2.235 +cmdlpz:
   2.236 +	call	putc			#  with Space
   2.237 +	subb	$0x18, %al		#   and BackSpace
   2.238 +	jnc	cmdlpz
   2.239 +	decw	%si
   2.240 +cmdget:
   2.241 +#ifdef KEYBOARDLESS_SUPPORT
   2.242 +	call	wait4key
   2.243 +#else
   2.244 +	int	$0x16
   2.245 +#endif
   2.246 +	cbw				# %ah = 0, get keyboard character
   2.247 +	cmpb	$8, %al			# BackSpace ?
   2.248 +	je	cmdbs
   2.249 +	movb	%al, (%si)		# store char
   2.250 +	lodsw				# %si += 2
   2.251 +cmdbs:
   2.252 +	cmpw	%si, cmd_line_ptr-7(%bx)
   2.253 +	je	cmdget
   2.254 +	call	putc
   2.255 +	cmpb	$10, %al		# Enter/linefeed ?
   2.256 +	jne	cmdlp
   2.257 +	movb	%bh,-2(%si)		# set end of string and remove CR
   2.258 +endcmdline:
   2.259 +#endif
   2.260 +#ifdef MOVE_CMDLINE
   2.261 +	pushw	%ss
   2.262 +	popw	%es
   2.263 +	movw	$0x8000, %di
   2.264 +	movw	%di, %si
   2.265 +	xchgw	%si, cmd_line_ptr-7(%bx)
   2.266 +	movb	$0x2, %ch
   2.267 +	rep
   2.268 +	  movsb
   2.269 +#endif
   2.270 +nocmdline:
   2.271 +#endif
   2.272 +
   2.273 +# This routine loads the system at address LOADSEG, making sure
   2.274 +# no 64kB boundaries are crossed. We try to load it as fast as
   2.275 +# possible, loading whole tracks whenever we can.
   2.276 +
   2.277 +.macro	autoaddr base
   2.278 +#ifdef INITRD_AUTOADDR
   2.279 +	movb	$0x88, %ah
   2.280 +	int	$0x15
   2.281 +	//jc	NeedMoreRAM			# error code 80 or 86
   2.282 +	cmpw	$0xB000, %ax			# more than 45M ?
   2.283 +	jb	NeedMoreRAM
   2.284 +	movb	%ch, bootsect_dst_base_hi(%si)	# initramfs @ 32M
   2.285 +	movb	%ch, ramdisk_image_ofs+3-\base
   2.286 +NeedMoreRAM:
   2.287 +#endif
   2.288 +.endm
   2.289 +
   2.290 +bootsect_src_limit	= 16
   2.291 +bootsect_dst_limit	= 24
   2.292 +bootsect_src_base	= 18
   2.293 +bootsect_dst_base	= 26		# bits  0..23
   2.294 +bootsect_dst_base_hi	= 31		# bits 24..31
   2.295 +	popw	%bx			# clear %bx
   2.296 +	movw	%sp, %si		# for bootsect_gdt
   2.297 +init_gdt:
   2.298 +	decw	bootsect_src_limit(%bx,%si)	# max 64Kb
   2.299 +	movw	$0x9300+(LOADSEG/0x1000), bootsect_src_base+2(%bx,%si)
   2.300 +	xorb	$bootsect_dst_limit-bootsect_src_limit, %bl
   2.301 +	jne	init_gdt
   2.302 +#ifdef INITRD_SUPPORT
   2.303 +	movw	$syssize, %bx
   2.304 +	movb	$5, %cl
   2.305 +code32_start	=	0x214
   2.306 +	movw	code32_start+1, %ax		# destination = 0x00100000 or 0x00010000
   2.307 +initrdlp:
   2.308 +	movl	(%bx), %ebx
   2.309 +	decl	%ebx
   2.310 +	shrl	%cl, %ebx
   2.311 +#else
   2.312 +code32_start	=	0x214
   2.313 +	movw	code32_start+1, %ax		# destination = 0x00100000 or 0x00010000
   2.314 +	movl	syssize, %ebx
   2.315 +	decl	%ebx
   2.316 +	shrl	$5, %ebx
   2.317 +#endif
   2.318 +#ifdef MORETHAN16M
   2.319 +	incl	%ebx
   2.320 +#else
   2.321 +	incw	%bx
   2.322 +#endif
   2.323 +#ifdef USEA20BUFFER
   2.324 +	movw	$0x00100000>>8, %di
   2.325 +#endif
   2.326 +syslp:
   2.327 +#ifdef USEA20BUFFER
   2.328 +	cmpw	%ax, %di
   2.329 +	jne	nota20
   2.330 +	xorw	$(0x00100000+A20BUFFER)>>8, %ax
   2.331 +nota20:
   2.332 +#endif
   2.333 +	movw	%ax, bootsect_dst_base+1(%si)
   2.334 +#ifdef MORETHAN16M
   2.335 +	movl	$LOADSZ/512, %edi	# size in sectors
   2.336 +	subl	%edi, %ebx
   2.337 +#else
   2.338 +	movw	$LOADSZ/512, %di	# size in sectors
   2.339 +	subw	%di, %bx
   2.340 +#endif
   2.341 +	pushf
   2.342 +	jnc	not_last
   2.343 +	addw	%bx, %di
   2.344 +not_last:
   2.345 +#ifdef MULTI_INITRD
   2.346 +	pushw	%di
   2.347 +#endif
   2.348 +	pushw	%ax
   2.349 +	pushw	%bx
   2.350 +	pushw	%si
   2.351 +	xorw	%bx,%bx
   2.352 +	pushw	$LOADSEG
   2.353 +	popw	%es
   2.354 +#ifdef EXE_ONLY
   2.355 +	call	read_sectors_dos
   2.356 +#else
   2.357 +patchcall:
   2.358 +	call	read_sectors		# update %bp
   2.359 +#endif
   2.360 +	popw	%si
   2.361 +	popw	%bx
   2.362 +	movw	%es, %cx		# word count = LOADSZ/2 (= LOADSEG)
   2.363 +	movb	$0x87, %ah
   2.364 +	pushw	%ss
   2.365 +	popw	%es			# restore es
   2.366 +	int	$0x15			# max 16M, maybe more...
   2.367 +	popw	%ax
   2.368 +#ifdef MULTI_INITRD
   2.369 +	popw	%di
   2.370 +	shlw	$1,%di			# sectors to pages
   2.371 +	addw	%di, %ax
   2.372 +#ifdef MORETHAN16M
   2.373 +	adcb	%cl, bootsect_dst_base_hi(%si)	# breaks 16M limit ?
   2.374 +#endif
   2.375 +#else
   2.376 +#ifdef MORETHAN16M
   2.377 +	addw	$0x100, %ax		# next dest (ax+=LOADSZ/256)
   2.378 +	adcb	%cl, bootsect_dst_base_hi(%si)	# breaks 16M limit ?
   2.379 +#else
   2.380 +	incb	%ah			# next dest (ax+=LOADSZ/256)
   2.381 +#endif
   2.382 +#endif
   2.383 +#ifdef USEA20BUFFER
   2.384 +	movw	$(LOADSZ+A20BUFFER)>>8, %di
   2.385 +#endif
   2.386 +	popf
   2.387 +	ja	syslp
   2.388 +#ifdef INITRD_SUPPORT
   2.389 +initrdlp2:
   2.390 +#ifdef INITRD_AUTOADDR
   2.391 +	movw	$0x209, %cx
   2.392 +#else
   2.393 +	movb	$9, %cl
   2.394 +#endif
   2.395 +#ifdef MULTI_INITRD
   2.396 +	movw	$cur_initrd_size_ofs, %di
   2.397 +	movw	(%di), %bx
   2.398 +	addw	$4, (%di)
   2.399 +	shrw	%cl, boot_flag_ofs-cur_initrd_size_ofs(%di)
   2.400 +	je	nextInitrd	
   2.401 +	orw	%bx, %bx
   2.402 +	je	bootit			# no initrd
   2.403 +	autoaddr	cur_initrd_size_ofs(%di)
   2.404 +	movw	ramdisk_image+1,%ax
   2.405 +	jmp	initrdlp
   2.406 +nextInitrd:
   2.407 +	pushw	%bx
   2.408 +	movl	-4(%bx), %ebx
   2.409 +	addl	%ebx, ramdisk_size_ofs-cur_initrd_size_ofs(%di)
   2.410 +	movb	$swap_floppy2-0x100, %cs:dpy_swap_floppy-2+0x7C00
   2.411 +	popw	%bx
   2.412 +	cmpb	2(%di), %bl
   2.413 +	jb	initrdlp
   2.414 +#else
   2.415 +	movw	$ramdisk_size, %bx
   2.416 +#ifdef MORETHAN16M
   2.417 +	cmpb	%cl, ramdisk_image+2-ramdisk_size(%bx)
   2.418 +	jb	bootit
   2.419 +	autoaddr	ramdisk_size_ofs(%bx)
   2.420 +	movw	ramdisk_image+1,%ax
   2.421 +	shrw	%cl, boot_flag-ramdisk_size(%bx)
   2.422 +	jne	initrdlp
   2.423 +#else
   2.424 +	movw	ramdisk_image+1,%ax
   2.425 +	cmpw	%ax, bootsect_dst_base+1(%si)
   2.426 +	jb	initrdlp
   2.427 +#endif
   2.428 +#endif
   2.429 +bootit:
   2.430 +#ifdef USEA20BUFFER
   2.431 +#ifdef MORETHAN16M
   2.432 +#ifdef INITRD_SUPPORT
   2.433 +	movb	%al, bootsect_dst_base_hi(%si)		// assume @initrd 64k aligned
   2.434 +	//movb	$0, bootsect_dst_base_hi(%si)
   2.435 +#else
   2.436 +	movb	%cl, bootsect_dst_base_hi(%si)
   2.437 +#endif
   2.438 +#endif
   2.439 +	movb	$0x10, bootsect_dst_base+2(%si)		// assume @initrd 64k aligned
   2.440 +	//movw	$0x1000, bootsect_dst_base+1(%si)		// assume @initrd page aligned
   2.441 +	movw	$A20BUFFER/0x100, bootsect_src_base+1(%si)
   2.442 +	movb	$0x87, %ah
   2.443 +	int	$0x15
   2.444 +#endif
   2.445 +#endif
   2.446 +#ifdef MULTI_INITRD
   2.447 +        jcxz	read_sectorslp
   2.448 +#endif
   2.449 +
   2.450 +# This procedure turns off the floppy drive motor, so
   2.451 +# that we enter the kernel in a known state, and
   2.452 +# don't have to worry about it later.
   2.453 +
   2.454 +kill_motor:
   2.455 +#ifdef USEA20BUFFER
   2.456 +	cwd
   2.457 +#else
   2.458 +	xchgw	%ax, %di		# reset FDC (%di < 128)
   2.459 +#endif
   2.460 +	int	$0x13
   2.461 +
   2.462 +# After that (everything loaded), we jump to the setup-routine
   2.463 +# loaded directly after the bootblock:
   2.464 +# Segments are as follows: %ds = %ss = INITSEG
   2.465 +
   2.466 +	ljmp	$SETUPSEG, $0
   2.467 +
   2.468 +# read_sectors reads %di sectors into %es:0 buffer.
   2.469 +# %es:0 is updated to the next memory location.
   2.470 +# First, sectors are read sector by sector until
   2.471 +# sector per track count is known. Then they are
   2.472 +# read track by track.
   2.473 +# Assume no error on first track.
   2.474 +
   2.475 +#ifndef EXE_ONLY
   2.476 +
   2.477 +#define FLOPPY_CYLINDERS	80	
   2.478 +#define FLOPPY_HEADS		2	
   2.479 +
   2.480 +.macro	putsmsg
   2.481 +#if !defined(SINGLE_FLOPPY) && defined(COUNTER)
   2.482 +	movw	$msgdigit+1-msg, %bx
   2.483 +nextdigit:
   2.484 +	andb	$0xF0, (%bx,%si)
   2.485 +	decw	%bx
   2.486 +	incb	(%bx,%si)
   2.487 +	cmpb	$'9', (%bx,%si)
   2.488 +	ja	nextdigit
   2.489 +#endif
   2.490 +	call	puts
   2.491 +.endm
   2.492 +
   2.493 +check_limits:
   2.494 +	popw	%dx
   2.495 +        cmpb    %al, %cl		# max sector known ?
   2.496 +        ja	next_head		#   no -> store it
   2.497 +	pushaw
   2.498 +        int     $0x13			# reset controler
   2.499 +	stc
   2.500 +	call	putcdot			# print '-'
   2.501 +read_sectorslp:
   2.502 +	popaw
   2.503 +bdendlp:
   2.504 +	pushw	%dx			# some bios break dx...
   2.505 +        pushw   %ax			# limits
   2.506 +	subb	%cl, %al		# sectors remaining in track
   2.507 +	ja	tolastsect
   2.508 +	movb	$1, %al			# 1 sector mini
   2.509 +tolastsect:
   2.510 +	cmpw	%di, %ax
   2.511 +	jb	more1trk
   2.512 +	movw	%di, %ax		# sectors to read
   2.513 +more1trk:
   2.514 +	pushw	%ax			# save context
   2.515 +	movb	$2, %ah			# cmd: read chs
   2.516 +        int     $0x13
   2.517 +	popw	%dx			# save %ax
   2.518 +        popw    %ax			# limits
   2.519 +	jc	check_limits
   2.520 +	xchgw	%ax, %bp
   2.521 +	addw	%dx,%cx			# next sector
   2.522 +	movw	%cx, %gs
   2.523 +	addb	%dl,%bh
   2.524 +	addb	%dl,%bh			# next location
   2.525 +	subw	%dx,%di			# update sector counter
   2.526 +	popw	%dx
   2.527 +	jz	putcdot
   2.528 +read_sectors:
   2.529 +	movw	%gs, %cx
   2.530 +#   al is last sector+1
   2.531 +#   ah is 0
   2.532 +	xchgw	%ax, %bp
   2.533 +        cmpb    %al,%cl			# reach sector limit ?
   2.534 +        jne     bdendlp
   2.535 +next_head:
   2.536 +        movb    %cl,%al
   2.537 +        movb    $1, %cl			# first sector
   2.538 +inc_head:
   2.539 +        xorb    %cl, %dh		# next head
   2.540 +        jne	bdendlp			# reach head limit ?
   2.541 +        incb    %ch			# next cylinder
   2.542 +read_first_sectors:
   2.543 +#ifdef SINGLE_FLOPPY
   2.544 +	jmp	bdendlp
   2.545 +#else
   2.546 +        cmpb    $FLOPPY_CYLINDERS,%ch	# reach cylinder limit ?
   2.547 +        jne	bdendlp
   2.548 +next_floppy:
   2.549 +	movb	$0,%ch			# first cylinder
   2.550 +	pushaw
   2.551 +	movw	$swap_floppy,%si
   2.552 +dpy_swap_floppy:
   2.553 +#ifdef KEYBOARDLESS_SUPPORT
   2.554 +	pushw	%bx
   2.555 +	putsmsg
   2.556 +	popw	%bx
   2.557 +	movw	%si, %bp
   2.558 +waitfloppy:
   2.559 +	call	wait
   2.560 +	jne	waitfloppydone
   2.561 +#ifdef MULTI_INITRD
   2.562 +	decb	(%si)			# max_timeouts	
   2.563 +gobootit:
   2.564 +	//movw	ramdisk_size+2-max_timeouts(%si), %cx
   2.565 +	.byte	0x8B, 0x4C, ramdisk_size+2-max_timeouts
   2.566 +	jz	bootit
   2.567 +#endif
   2.568 +	pushw	%dx			# some bios break dx...
   2.569 +	cbw
   2.570 +	int	$0x13			# reset FDC
   2.571 +	movw	$0x201,%ax
   2.572 +	int	$0x13			# read first sector
   2.573 +	popw	%dx
   2.574 +	rclb	$1,%ah			# floppy changed 06=>0D no error 00
   2.575 +	cmpb	-2(%bp), %ah		# 0D then 00
   2.576 +	jne	waitfloppy		# no => try again
   2.577 +	incw	%bp
   2.578 +	decw	%ax			# was 0001 ?
   2.579 +	jne	waitfloppy
   2.580 +waitfloppydone:
   2.581 +#else
   2.582 +	putsmsg
   2.583 +	cbw				# %ah = 0, get keyboard character
   2.584 +	int	$0x16
   2.585 +#endif
   2.586 +#ifdef MULTI_INITRD
   2.587 +	orb	$0x20, %al
   2.588 +	cmp	$'b', %al
   2.589 +        jz	gobootit
   2.590 +#endif
   2.591 +        jmp	read_sectorslp
   2.592 +#endif
   2.593 +#endif
   2.594 +
   2.595 +#ifdef EXE_SUPPORT
   2.596 +read_sectors_dos:
   2.597 +	xorw	%dx, %dx	// write to %ds:%dx, not %es:%bx
   2.598 +	call	read_sectors_dosz
   2.599 +read_sectors_dosz:
   2.600 +	pushw	%es
   2.601 +	popw	%ds
   2.602 +	movb	$0x3F, %ah	// read
   2.603 +	movw	%di, %cx
   2.604 +	shlw	$8, %cx		// byte count / 2
   2.605 +	movw	%bp, %bx
   2.606 +	int	$0x21
   2.607 +	xchgw	%ax, %dx
   2.608 +	pushw	%ss
   2.609 +	popw	%ds
   2.610 +#endif
   2.611 +
   2.612 +putcdot:
   2.613 +	movb	$'.'+3, %al	// . = success, - = failure
   2.614 +putclf:
   2.615 +	sbbb	$3, %al
   2.616 +putc:
   2.617 +	movb	$0xe, %ah
   2.618 +	movw	$7, %bx			#   one dot each 64k
   2.619 + 	int	$0x10
   2.620 +	cmp	$0xd, %al		# CR ?
   2.621 +	je	putclf
   2.622 +	ret
   2.623 +
   2.624 +#ifdef KEYBOARDLESS_SUPPORT
   2.625 +clock	= 0x46C
   2.626 +wait:
   2.627 +wait4key:
   2.628 +	movw	$clock, %di
   2.629 +#define DELAY 5
   2.630 +	movb	$257-(DELAY*182)/10, %fs:(%di)
   2.631 +waitkbd:
   2.632 +	movw	$0x10D, %ax		# test keyboard, timeout => CR
   2.633 +	cmpb	%fs:(%di),%ah
   2.634 +	je	waitdone
   2.635 +	int	$0x16
   2.636 +	jz	waitkbd
   2.637 +	cbw
   2.638 +	int	$0x16			# eat char
   2.639 +	movw	%di, %fs		# disable timeout
   2.640 +	incw	%di			# clear Z
   2.641 +waitdone:
   2.642 +	ret
   2.643 +#endif
   2.644 +
   2.645 +#ifdef EXE_SUPPORT
   2.646 +comstart:
   2.647 +#ifndef EXE_ONLY
   2.648 +	call	initregs
   2.649 +#else
   2.650 +	INIT_REGS
   2.651 +#endif
   2.652 +	movb	EXEADRS(setup_sects), %al	# read bootsector + setup
   2.653 +	incw	%ax
   2.654 +#ifdef EXE_CMDLINE
   2.655 +	movw	$0x80, %si
   2.656 +	movb	(%si), %cl
   2.657 +	incw	%si
   2.658 +# ifdef OLDCMDLINE
   2.659 +#  ifdef FLOPPY_CMDLINE
   2.660 +	jcxz	nocmdline
   2.661 +	movw	%di, EXEADRS(0x22)
   2.662 +	movw	$0xA33F, 0x7F(%si)
   2.663 +#  endif
   2.664 +# endif
   2.665 +	rep
   2.666 +	  movsb
   2.667 +nocmdline:
   2.668 +	xchgw	%ax, %di
   2.669 +# ifdef HELP
   2.670 +	cmpb	$'?', -1(%si)
   2.671 +	movw	$EXEADRS(0x200), %si
   2.672 +	je	puts_version
   2.673 +#  ifndef REALMODE_NOT_CHECKED
   2.674 +	smsww	%ax
   2.675 +	andb	$1, %al
   2.676 +	jne	puts_version			// real mode only...
   2.677 +#  endif
   2.678 +# endif
   2.679 +#else
   2.680 +	xchgw	%ax, %di
   2.681 +#endif
   2.682 +	movw	0x2C(%bx), %ds	// DOS 3.0+
   2.683 +loop1:
   2.684 +	incw	%bx
   2.685 +	cmpw	%cx, (%bx)
   2.686 +	jne	loop1
   2.687 +	leaw	4(%bx), %dx 	// %ds:%dx filename
   2.688 +#if !defined(REALMODE_NOT_CHECKED) && defined(EXE_CMDLINE) && defined(HELP)
   2.689 +	movb	$0x3D, %ah	// open, access = RO
   2.690 +#else
   2.691 +	movw	$0x3D00, %ax	// open, access = RO
   2.692 +#endif
   2.693 +	int	$0x21
   2.694 +	jc	dosexit
   2.695 +	xchgw	%ax, %bp	// fd
   2.696 +	call	read_sectors_dos	// update %ds
   2.697 +#ifndef EXE_ONLY
   2.698 +	addb	$read_sectors_dos-read_sectors, patchcall+1
   2.699 +#endif
   2.700 +#ifdef EXE_CMDLINE
   2.701 +# ifdef OLDCMDLINE
   2.702 +	movw	$0x202, %bx
   2.703 +	cmpw	%bx, 0x206-0x202(%bx)	# new cmdline for version >= 0x202
   2.704 +	jb	oldcmdline
   2.705 +	movw	$INITSEG/16+stacktop/256, cmd_line_ptr+1-0x202(%bx)
   2.706 +# else
   2.707 +	movw	$INITSEG/16+stacktop/256, cmd_line_ptr+1
   2.708 +# endif
   2.709 +oldcmdline:
   2.710 +#endif
   2.711 +//	ljmp	$INITSEG, $loadsys
   2.712 +	pushw	%ds
   2.713 +	.byte	0x6A, loadsys-bootsect_start
   2.714 +	lretw
   2.715 +#endif
   2.716 +#define kernel_version_offset	0xE
   2.717 +puts_version:
   2.718 +	addw	kernel_version_offset(%si),%si	# starting protocol 2.00, Kernel 1.3.73
   2.719 +puts:
   2.720 +	movb	$0xd, %al		# CR
   2.721 +putcs:
   2.722 +	call	putc
   2.723 +	lodsb
   2.724 +	cmpb	$0, %al			# end of string is any byte <= 0
   2.725 +	jg	putcs
   2.726 +dosexit:
   2.727 +	ret	
   2.728 +
   2.729 +#if !defined(FLOPPY_ONLY) && !defined(EXE_ONLY)
   2.730 +initregs:
   2.731 +	popw	%si
   2.732 +	INIT_REGS
   2.733 +	pushw	%si			# use new stack
   2.734 +	ret
   2.735 +#endif
   2.736 +
   2.737 +
   2.738 +#if !defined(SINGLE_FLOPPY) && !defined(EXE_SUPPORT)
   2.739 +#ifdef MULTI_INITRD
   2.740 +swap_floppy2:
   2.741 +	.ascii	"B or "
   2.742 +#endif
   2.743 +swap_floppy:
   2.744 +#ifdef COUNTER
   2.745 +msg:
   2.746 +	.ascii	"Put disk 00"
   2.747 +msgdigit:
   2.748 +	.ascii	"1, press Enter."
   2.749 +#else
   2.750 +	.ascii	"Next!"
   2.751 +#endif
   2.752 +	.byte	7,13,0			# swap detection needs 13, 0
   2.753 +#ifdef MULTI_INITRD
   2.754 +max_timeouts:
   2.755 +	.byte	20
   2.756 +table:
   2.757 +	.org	cur_initrd_size_ofs
   2.758 +cur_initrd_size:
   2.759 +	.word	table
   2.760 +	.byte	table+4-256
   2.761 +#endif
   2.762 +#endif
   2.763 +#ifdef	README_SUPPORT
   2.764 +	.org	0x1EF
   2.765 +readme:
   2.766 +	.word	0
   2.767 +#endif
   2.768 +#ifdef LABEL
   2.769 +	.ascii LABEL
   2.770 +#endif
   2.771 +	.org	0x1F1
   2.772 +
   2.773 +#ifdef MULTI_INITRD
   2.774 +	.org	0x400
   2.775 +	
   2.776 +	orw	$0x8020, type_of_loader(%si) # loader type = 0x20 = bootsect-loader
   2.777 +	pushal
   2.778 +	
   2.779 +	movw	$10+16, %cx
   2.780 +fillbuf:
   2.781 +	pushw	$0
   2.782 +	loop	fillbuf
   2.783 +	popal			// clear regiters
   2.784 +maploop:
   2.785 +	movw	%sp, %di	// %es = %ss
   2.786 +	movb	$20, %cl
   2.787 +	movw	$0xE820, %ax
   2.788 +	movl	$0x534d4150, %edx
   2.789 +	int	$0x15
   2.790 +	sbbl	%eax, %edx
   2.791 +	jne	mapdone
   2.792 +	decw	16(%di)	
   2.793 +	jne	notram
   2.794 +	addw	8+2(%di), %bp
   2.795 +notram:
   2.796 +	orw	%bx, %bx
   2.797 +	jnz	maploop
   2.798 +mapdone:
   2.799 +	addw	$20, %sp
   2.800 +	shrw	$20-16,%bp
   2.801 +	jnz	mapdone2
   2.802 +	movb	$0x88, %ah
   2.803 +	int	$0x15
   2.804 +	xchgw	%ax, %bp
   2.805 +	shrw	$10, %bp
   2.806 +mapdone2:
   2.807 +	incw	%bp
   2.808 +// %bp : nb Mb	
   2.809 +	call	here
   2.810 +here:
   2.811 +	popw	%di
   2.812 +	movw	$0x1EE, %si
   2.813 +	lodsw
   2.814 +sizeloop:
   2.815 +	scasw			// %di += 2
   2.816 +	addw	$4, %ax
   2.817 +	cmpb	%al, (%si)	
   2.818 +	jbe	sizedone
   2.819 +	cmpw	%bp, sizes-here(%di)
   2.820 +	jbe	sizeloop
   2.821 +	movb	%al, (%si)
   2.822 +sizedone:
   2.823 +	popal
   2.824 +	lret			// need %si
   2.825 +sizes:
   2.826 +
   2.827 +#endif
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/linux/stuff/bundle	Tue Oct 06 21:04:42 2015 +0200
     3.3 @@ -0,0 +1,51 @@
     3.4 +#!/bin/sh
     3.5 +
     3.6 +ddq()
     3.7 +{
     3.8 +	dd "$@" 2> /dev/null
     3.9 +}
    3.10 +
    3.11 +store()
    3.12 +{
    3.13 +	n=$2; for i in $(seq 8 8 32); do
    3.14 +		printf '\\\\x%02X' $(($n & 255))
    3.15 +		n=$(($n >> 8))
    3.16 +	done | xargs echo -en | ddq bs=1 conv=notrunc of="$3" seek=$(($1))
    3.17 +}
    3.18 +
    3.19 +get()
    3.20 +{
    3.21 +	echo $(od -j $(($1)) -N ${3:-4} -t u${3:-4} -An "$2")
    3.22 +}
    3.23 +
    3.24 +end()
    3.25 +{
    3.26 +	echo $(( $(get 0x1F1 "$1" 1)*32 +($(get 0x1F4 "$1") +31 +${2:-1})&-${2:-1} ))
    3.27 +}
    3.28 +
    3.29 +if [ ! -s "$1" ]; then
    3.30 +	cat <<EOT
    3.31 +Usage: $0 kernel [initrd]
    3.32 +EOT
    3.33 +elif [ -s "$2" ]; then
    3.34 +	base_initrd=$(( (($(get 0x1F4 "$1")*33 + 65535)&-65536) + 0x100000 ))
    3.35 +	size_initrd=$(stat -c %s "$2")
    3.36 +	[ $(($base_initrd + $size_initrd)) -gt $((0x1000000)) ] &&
    3.37 +	base_initrd=$((0x01400000))
    3.38 +	printf "initrd @%X %X\n" $base_initrd $size_initrd
    3.39 +	store 0x218 $base_initrd "$1"
    3.40 +	store 0x21C $size_initrd "$1"
    3.41 +	ddq bs=16 seek=$(end "$1" 32) of="$1" if="$2"
    3.42 +	ls -l "$1"
    3.43 +else
    3.44 +	base_initrd=$(get 0x218 "$1")
    3.45 +	size_initrd=$(get 0x21C "$1")
    3.46 +	[ $base_initrd -ne 0 ] &&
    3.47 +	printf "initrd @%X\n" $base_initrd &&
    3.48 +	ddq bs=1 skip=$(($(end "$1" 32) * 16)) count=$size_initrd \
    3.49 +		if="$1" of=initrd && ls -l initrd
    3.50 +	store 0x218 0 "$1"
    3.51 +	store 0x21C 0 "$1"
    3.52 +	ddq bs=16 count=0 seek=$(end "$1") of="$1"
    3.53 +	ls -l "$1"
    3.54 +fi