wok diff plop/stuff/bootloader.S @ rev 24936

created recipe for mypaint-brushes
author Hans-G?nter Theisgen
date Thu Apr 14 09:08:33 2022 +0100 (2022-04-14)
parents
children d1f31f5f6401
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/plop/stuff/bootloader.S	Thu Apr 14 09:08:33 2022 +0100
     1.3 @@ -0,0 +1,655 @@
     1.4 +// Image/zImage & tiny bzImage linux kernel boot sector, (C) SliTaz, GPL2.
     1.5 +
     1.6 +SYSSEG		= 0x1000
     1.7 +setup_sects	= 497
     1.8 +syssize		= 500
     1.9 +cmd_line_ptr	= 0x228
    1.10 +
    1.11 +	.text
    1.12 +	.code16
    1.13 +	.org	0
    1.14 +	.globl	_start
    1.15 +_start:
    1.16 +
    1.17 +#define CODESZ 512		/* patched by installer */
    1.18 +
    1.19 +// Default kernel format is 386 Image/zImage
    1.20 +//#define BZIMAGE 0x207		/* setup version ; for bzImage < 512 Kb only */
    1.21 +//#define ELKS			/* 8086/286 linux port */
    1.22 +
    1.23 +/* some extra features */
    1.24 +#define EXE_SUPPORT		real mode dos .exe file support	+208/264
    1.25 +#define  CMDLINE		dos kernel cmdline support	+45
    1.26 +#define  VCPI			VCPI 4.0 support (386+)		+109
    1.27 +#define  SHUTDOWNDOS		shutdown DOS services		+29
    1.28 +
    1.29 +/* some contraints to reduce the code size */
    1.30 +//#define FLOPPY_1440K_ONLY	1.44M floppies support only	-26
    1.31 +#define FLOPPY_HAS_2_SIDES	hardcoded heads count to 2	-15
    1.32 +//#define NO_CMDLINE_SHRINK	remove heading spaces ?		-6-21
    1.33 +//#define  NO_CMDLINE_FILE	remove @cmdline file support ?	-21
    1.34 +//#define NO_DOTS		show progression dots ?		-5
    1.35 +#ifndef BZIMAGE
    1.36 +#define TINY_ZIMAGE		system < 64Kb ?			-11
    1.37 +#define NO_MINSETUP		default setup (dos only) ?	-4
    1.38 +//#define NO_CURSOR_DEFINITION					-8
    1.39 +#endif
    1.40 +
    1.41 +#ifdef ELKS
    1.42 +	.arch	i8086
    1.43 +INITSEG		= 0x0100
    1.44 +SETUPSEG	= 0x0120
    1.45 +#define ONLY8086
    1.46 +#undef BZIMAGE
    1.47 +#undef VCPI
    1.48 +#else
    1.49 +INITSEG		= 0x9000
    1.50 +SETUPSEG	= 0x9020
    1.51 +#endif
    1.52 +
    1.53 +.macro	shlclw cnt,obj
    1.54 +#ifdef ONLY8086
    1.55 +	movb	\cnt,%cl
    1.56 +	shlw	%cl,\obj
    1.57 +#else
    1.58 +	shlw	\cnt,\obj
    1.59 +#endif
    1.60 +.endm
    1.61 +
    1.62 +.macro	shrclw cnt,obj
    1.63 +#ifdef ONLY8086
    1.64 +	movb	\cnt,%cl
    1.65 +	shrw	%cl,\obj
    1.66 +#else
    1.67 +	shrw	\cnt,\obj
    1.68 +#endif
    1.69 +.endm
    1.70 +
    1.71 +#ifdef EXE_SUPPORT
    1.72 +#define EXEADRS(x)	(x+0xE0)
    1.73 +#define FLAT20(x)	(x+16*INITSEG)
    1.74 +
    1.75 +.macro	trace_int19
    1.76 +#ifdef ONLY8086
    1.77 +	xorw	%si, %si
    1.78 +	movw	%si, %ds
    1.79 +	pushw	4+2(%si)
    1.80 +	pushw	4(%si)
    1.81 +	movw	$step19, 4(%si)
    1.82 +	movw	$INITSEG, 4+2(%si)
    1.83 +#else
    1.84 +	pushl	$4
    1.85 +	popw	%si
    1.86 +	popw	%ds
    1.87 +	pushl	(%si)
    1.88 +	movl	$step19+(INITSEG<<16), (%si)
    1.89 +#endif
    1.90 +	pushfw
    1.91 +	popw	%ax
    1.92 +	incb	%ah			# set TF
    1.93 +	pushw	%ax
    1.94 +	popfw
    1.95 +	ljmp	*4*0x19-4(%si)
    1.96 +.endm
    1.97 +
    1.98 +stacktop	= 0x9E00		# in 0x8000 .. 0xA000
    1.99 +	decw	%bp			// Magic number: MZ
   1.100 +	popw	%dx
   1.101 +	jmp	start			// Bytes on last page of file
   1.102 +	.word	(CODESZ+511)/512	// Pages in file			INSTALLER
   1.103 +	.word	0			// Relocations
   1.104 +	.word	(end_header-_start)/16	// Size of header in paragraphs
   1.105 +	.word	4096			// Minimum extra paragraphs needed
   1.106 +	.word	-1			// Maximum extra paragraphs needed
   1.107 +	.word	(CODESZ+15)/16		// Initial (relative) SS value		INSTALLER
   1.108 +	.word	stacktop		// Initial SP value
   1.109 +	.word	0			// Checksum				INSTALLER?
   1.110 +	.word	EXEADRS(comstart)	// Initial IP value
   1.111 +	.word	0xFFF0			// Initial (relative) CS value
   1.112 +//	.word	0x001C			// File address of relocation table
   1.113 +//	.word	0,0,0			// Overlay number
   1.114 +#else
   1.115 +#undef VCPI
   1.116 +#endif
   1.117 +start:
   1.118 +	xorw	%ax, %ax		# %ax = 0
   1.119 +zeroed		= 12			# zeroed registers
   1.120 +	movw	$zeroed/2, %cx		# clear gdt + offset, %ds, limits
   1.121 +stacktop	= 0x9E00		# in 0x8000 .. 0xA000 (+zeroed+12)
   1.122 +#ifdef ONLY8086
   1.123 +	movw	$INITSEG, %bx
   1.124 +#else
   1.125 +	pushw	$INITSEG
   1.126 +#endif
   1.127 +end_header:
   1.128 +	cld				# assume nothing
   1.129 +#if defined(BZIMAGE) && BZIMAGE >= 0x202
   1.130 +	popw	%es			# %es contain INITSEG
   1.131 +	movw	%es, %di
   1.132 +#else
   1.133 +					# cmdline offset at 0x22
   1.134 +	movw	$stacktop, %di		# stacktop is an arbitrary value >=
   1.135 +					# length of bootsect + length of
   1.136 +					# setup + room for stack;
   1.137 +					# 12 is disk parm size.
   1.138 +# ifdef ONLY8086
   1.139 +	pushw	%bx
   1.140 +# endif
   1.141 +	popw	%es			# %es contain INITSEG
   1.142 +#endif
   1.143 +	pushw	%es
   1.144 +	popw	%ss			# %es = %ss = INITSEG
   1.145 +	movw	%di, %sp		# put stack at INITSEG:stacktop-...
   1.146 +#ifdef EXE_SUPPORT
   1.147 +	cwd				# force %dx = 0 (floppy only)
   1.148 +#endif
   1.149 +
   1.150 +# Many BIOS's default disk parameter tables will not recognize
   1.151 +# multi-sector reads beyond the maximum sector number specified
   1.152 +# in the default diskette parameter tables - this may mean 7
   1.153 +# sectors in some cases.
   1.154 +#
   1.155 +# Since single sector reads are slow and out of the question,
   1.156 +# we must take care of this by creating new parameter tables
   1.157 +# (for the first disk) in RAM.  We can set the maximum sector
   1.158 +# count to 36 - the most we will encounter on an ED 2.88.  
   1.159 +#
   1.160 +# High doesn't hurt.  Low does.  Let's use the max: 63
   1.161 +
   1.162 +	rep				# don't worry about cld
   1.163 +	stosw				# already done above
   1.164 +	popw	%bx			# offset = 0
   1.165 +	popw	%ds			# %ds = 0
   1.166 +
   1.167 +	movb	setup_sects+0x7C00, %al	# read bootsector + setup (%ds = 0)
   1.168 +	incw	%ax
   1.169 +
   1.170 +	ldsw	0x78(%bx), %si		# %ds:%bx+0x78 is parameter table address
   1.171 +	pushw	%es
   1.172 +	pushw	%di
   1.173 +	movb	$6, %cl			# copy 12 bytes
   1.174 +	rep				# don't worry about cld
   1.175 +	movsw				# already done above
   1.176 +	movw	%cx, %ds		# %ds = 0
   1.177 +#ifdef ONLY8086
   1.178 +	popw	0x78(%bx)		# update parameter table address
   1.179 +	popw	0x78+2(%bx)
   1.180 +#else
   1.181 +	popl	0x78(%bx)		# update parameter table address
   1.182 +#endif
   1.183 +	pushw	%ss
   1.184 +	popw	%ds			# now %ds = %es = %ss = INITSEG
   1.185 +	movb	$63, 0x4-12(%di)	# patch sector count, %di = stacktop
   1.186 +
   1.187 +	xchg	%ax, %di		# sector count
   1.188 +	popw	%ax			# limits = 0
   1.189 +	incw	%cx			# cylinder 0, sector 1, clear Z
   1.190 +	call	read_first_sectors	# read setup
   1.191 +
   1.192 +# This routine loads the system at address LOADSEG, making sure
   1.193 +# no 64kB boundaries are crossed. We try to load it as fast as
   1.194 +# possible, loading whole tracks whenever we can.
   1.195 +
   1.196 +	movw	syssize, %di
   1.197 +	decw	%di
   1.198 +	shrclw	$9-4, %di
   1.199 +	incw	%di
   1.200 +	movw	$SYSSEG, %cx
   1.201 +#ifdef BZIMAGE
   1.202 +	push	%cx
   1.203 +#endif
   1.204 +	call	read_sectorsCX
   1.205 +
   1.206 +# This procedure turns off the floppy drive motor, so
   1.207 +# that we enter the kernel in a known state, and
   1.208 +# don't have to worry about it later.
   1.209 +
   1.210 +kill_motor:
   1.211 +	xchgw	%ax, %di		# reset FDC (%di < 128)
   1.212 +	int	$0x13
   1.213 +
   1.214 +# After that (everything loaded), we jump to the setup-routine
   1.215 +# loaded directly after the bootblock:
   1.216 +# Segments are as follows: %ds = %ss = INITSEG
   1.217 +
   1.218 +#ifdef BZIMAGE
   1.219 +	popw	%bx
   1.220 +	popw	%si			// SYSSEG:0
   1.221 +movesys:				// %bx = DS, %si
   1.222 +	movw	$16, %ax
   1.223 +	mulw	%bx
   1.224 +	addw	%si, %ax
   1.225 +	adcw	$0x9300, %dx		// %dx:%ax src flat address
   1.226 +	movw	$9, %cx
   1.227 +zero1:
   1.228 +	pushw	$0			// 2E..1E
   1.229 +	loop	zero1
   1.230 +	//pushl	$0x93100000		// 1A: dest
   1.231 +	pushw	$0x9310
   1.232 +	pushw	%cx
   1.233 +	pushw	$-1			// 18
   1.234 +	pushw	%cx			// 16
   1.235 +	pushw	%dx			// src
   1.236 +	pushw	%ax
   1.237 +	pushw	$-1			// 10
   1.238 +	movb	$8, %cl
   1.239 +	movw	%cx, %bx		// will move 8*64 = 512Kb
   1.240 +zero2:
   1.241 +	pushw	$0			// 0E..00
   1.242 +	loop	zero2
   1.243 +	movw	%sp, %si
   1.244 +	pushw	%ss
   1.245 +	popw	%es
   1.246 +	pushw	%es
   1.247 +	popw	%ds
   1.248 +syslp:
   1.249 +	movb	$0x80, %ch	
   1.250 +	movb	$0x87, %ah
   1.251 +	int	$0x15
   1.252 +	incb	0x14(%si)
   1.253 +	incb	0x1C(%si)
   1.254 +	decw	%bx
   1.255 +	jne	syslp
   1.256 +#endif
   1.257 +jmp_setup:
   1.258 +	cli
   1.259 +	ljmp	$SETUPSEG, $0
   1.260 +
   1.261 +#ifdef EXE_SUPPORT
   1.262 +#ifdef SHUTDOWNDOS
   1.263 +doiret:
   1.264 +	iret
   1.265 +step19:
   1.266 +	pushw	%si
   1.267 +	pushw	%ds
   1.268 +	movw	%sp, %si
   1.269 +	ldsw	%ss:4(%si), %si
   1.270 +	cmpw	$0x19CD, (%si)
   1.271 +	popw    %ds
   1.272 +	popw    %si
   1.273 +	jne	doiret
   1.274 +	xorw	%si, %si
   1.275 +	movw	%si, %ds
   1.276 +	pushw	%cs
   1.277 +	popw	%ss
   1.278 +	movw	$stacktop-4-16, %sp
   1.279 +#ifdef ONLY8086
   1.280 +	popw	4(%si)
   1.281 +	popw	4+2(%si)
   1.282 +	popw	%bp
   1.283 +	popw	%di
   1.284 +	popw	%si
   1.285 +	popw	%dx
   1.286 +	popw	%cx
   1.287 +	popw	%bx
   1.288 +	popw	%ax
   1.289 +#else
   1.290 +	popl	4(%si)
   1.291 +	popaw
   1.292 +#endif
   1.293 +#ifdef BZIMAGE
   1.294 +	jmp	movesys
   1.295 +#endif
   1.296 +#endif
   1.297 +#ifndef BZIMAGE
   1.298 +movesys:				// %ax = SYSSEG, %bx = DS, %si
   1.299 +	shrclw	$4, %si
   1.300 +	addw	%si, %bx
   1.301 +#ifdef TINY_ZIMAGE
   1.302 +	movw	$0xFFFF, %cx
   1.303 +	xorw	%si, %si
   1.304 +	xorw	%di, %di
   1.305 +	cmpw	%ax, %bx
   1.306 +	jnc	forward
   1.307 +	decw	%si
   1.308 +	decw	%di
   1.309 +	std
   1.310 +forward:
   1.311 +	movw	%ax, %es
   1.312 +	movw	%bx, %ds
   1.313 +	rep
   1.314 +	  movsb
   1.315 +	cld
   1.316 +#else
   1.317 +	subw	%ax, %bx
   1.318 +	jnc	forward
   1.319 +	movb	$0x90, %ah
   1.320 +	;decw	%ax
   1.321 +forward:
   1.322 +	movw	%ax, %es
   1.323 +	movw	%ax, %di
   1.324 +	addw	%bx, %di
   1.325 +	movw	%di, %ds
   1.326 +	sbbw	%di, %di		// %di = 0 : -1
   1.327 +	cmc				//  C  = 1 :  0
   1.328 +	adcw	%di, %ax
   1.329 +	xorw	%si, %si
   1.330 +	xorw	%di, %di
   1.331 +	movb	$0x10, %cl
   1.332 +	cmpb	%cl, %ah		// move 512k
   1.333 +	rep
   1.334 +	  movsb
   1.335 +	jns	forward
   1.336 +#endif
   1.337 +#ifndef NO_CURSOR_DEFINITION
   1.338 +	movb	$1, %ah
   1.339 +	movb	$0, %bh
   1.340 +	movb	$0x20, %ch	// 0x2000
   1.341 +	int	$0x10
   1.342 +#endif
   1.343 +	pushw	%ss
   1.344 +	popw	%ds
   1.345 +	jmp	jmp_setup
   1.346 +#endif
   1.347 +comstart:
   1.348 +	cld				# assume nothing
   1.349 +#ifdef ONLY8086
   1.350 +	movw	$INITSEG, %ax
   1.351 +	pushw	%ax
   1.352 +#else
   1.353 +	pushw	$INITSEG
   1.354 +#endif
   1.355 +	popw	%es
   1.356 +#ifdef CMDLINE
   1.357 +	movw	%sp, %di
   1.358 +	movw	$0x80, %si
   1.359 +	lodsb
   1.360 +	cbw
   1.361 +	xchgw	%ax, %cx
   1.362 +	jcxz	nocmdline
   1.363 +# if defined(BZIMAGE) && BZIMAGE >= 0x202
   1.364 +	movw	$INITSEG/16+stacktop/256, EXEADRS(cmd_line_ptr+1)
   1.365 +# else
   1.366 +	movw	$0xA33F, 0x7F(%si)
   1.367 +# endif
   1.368 +# ifndef NO_CMDLINE_SHRINK
   1.369 +skipspace:
   1.370 +	lodsb
   1.371 +	cmpb	$0x20, %al
   1.372 +	je	skipspace
   1.373 +#  ifndef NO_CMDLINE_FILE
   1.374 +	movw	%si,%dx
   1.375 +	decw	%si
   1.376 +	subb	$'@',%al
   1.377 +	jne	notafile
   1.378 +	movb	$0x3D,%ah
   1.379 +	int	$0x21
   1.380 +	jc	notafile
   1.381 +	xchgw	%ax,%bx
   1.382 +	//movw	%si,%dx		// ~320 bytes max
   1.383 +	movw	$EXEADRS(notafile)-130,%cx
   1.384 +	movb	$0x3F,%ah
   1.385 +	int	$0x21
   1.386 +	xchgw	%ax,%cx
   1.387 +notafile:
   1.388 +#  else
   1.389 +	decw	%si
   1.390 +#  endif
   1.391 +# endif
   1.392 +	rep
   1.393 +	  movsb
   1.394 +nocmdline:
   1.395 +	orb	EXEADRS(setup_sects), %ch
   1.396 +# ifndef NO_MINSETUP
   1.397 +#  ifndef BZIMAGE
   1.398 +	jnz	setupok
   1.399 +	mov	$4, %ch
   1.400 +setupok:
   1.401 +#  endif
   1.402 +# endif
   1.403 +#else
   1.404 +	movb	EXEADRS(setup_sects), %ch
   1.405 +#endif
   1.406 +	movb	$(512-(end_header-_start))/2, %cl
   1.407 +	movw	$0x100, %si
   1.408 +	movw	$end_header, %di
   1.409 +	rep
   1.410 +	  movsw
   1.411 +	movw	$SYSSEG, %ax
   1.412 +	movw	%ds, %bx
   1.413 +	pushw	%es
   1.414 +	popw	%ss
   1.415 +#ifndef SHUTDOWNDOS
   1.416 +	pushw	%es
   1.417 +	pushw	$movesys
   1.418 +#endif
   1.419 +#ifdef VCPI
   1.420 +	pushaw
   1.421 +	smsww	%ax
   1.422 +	andb	$1, %al
   1.423 +	je	isrm
   1.424 +	movw	$EXEADRS(gdt_vcpi),%si
   1.425 +	movw	$pagebuf-0x90000,%di	// %es = 0x9000
   1.426 +	movl	$pagebuf+3,%es:0x1000(%di)
   1.427 +call_vcpi:
   1.428 +	movb	$0xDE,%ah	// DE01, EBX = getiface(DS:SI, ES:DI)
   1.429 +	int	$0x67
   1.430 +	movl	$FLAT20(sw2pm_params),%esi
   1.431 +	movb	$0x0C,%al	// DE0C switchpm(ESI)
   1.432 +	jmp	call_vcpi
   1.433 +pm_code:
   1.434 +	movl	%cr0,%eax
   1.435 +	andl	$0x7FFFFFFE,%eax
   1.436 +	movl	%eax,%cr0
   1.437 +	movl	%eax,%cr3
   1.438 +isrm:
   1.439 +# ifdef SHUTDOWNDOS
   1.440 +	trace_int19
   1.441 +# else
   1.442 +	lssw	%cs:EXEADRS(saved_ss_sp),%sp	
   1.443 +	popaw
   1.444 +	retf
   1.445 +# endif
   1.446 +#else
   1.447 +# ifdef SHUTDOWNDOS
   1.448 +#  ifdef ONLY8086
   1.449 +	pushw	%ax
   1.450 +	pushw	%bx
   1.451 +	pushw	%cx
   1.452 +	pushw	%dx
   1.453 +	pushw	%si
   1.454 +	pushw	%di
   1.455 +	pushw	%bp
   1.456 +#  else
   1.457 +	pushaw
   1.458 +#  endif
   1.459 +	trace_int19
   1.460 +# endif
   1.461 +	retf
   1.462 +#endif
   1.463 +#endif
   1.464 +
   1.465 +# read_sectors reads %di sectors into %es:0 buffer.
   1.466 +# %es:0 is updated to the next memory location.
   1.467 +# First, sectors are read sector by sector until
   1.468 +# sector per track count is known. Then they are
   1.469 +# read track by track.
   1.470 +# Assume no error on first track.
   1.471 +
   1.472 +#ifdef FLOPPY_1440K_ONLY
   1.473 +#ifndef FLOPPY_HAS_2_SIDES
   1.474 +#define FLOPPY_HAS_2_SIDES	hardcore heads count to 2
   1.475 +#endif
   1.476 +#define FLOPPY_SECTORS		18	/* 18 sectors */
   1.477 +#else
   1.478 +#define FLOPPY_HEADS		2	/* 2 heads minimum */
   1.479 +#endif
   1.480 +
   1.481 +return:
   1.482 +#ifndef NO_DOTS
   1.483 +	movw	$0xE2E,%ax
   1.484 +	int	$0x10
   1.485 +#endif
   1.486 +	ret
   1.487 +
   1.488 +check_limits:
   1.489 +#ifndef FLOPPY_1440K_ONLY
   1.490 +	popw	%dx
   1.491 +        cmpb    %al, %cl		# max sector known ?
   1.492 +        ja	next_head		#   no -> store it
   1.493 +#ifndef FLOPPY_HAS_2_SIDES
   1.494 +#ifdef FLOPPY_HEADS
   1.495 +	cmpb	$FLOPPY_HEADS, %dh	# 2 heads minimum
   1.496 +	jb	check_cylinder
   1.497 +#endif
   1.498 +        cmpb    %ah, %dh		# max head known ?
   1.499 +        ja	next_cylinder		#   no -> store it
   1.500 +check_cylinder:
   1.501 +#endif
   1.502 +	pushw	%ax
   1.503 +	cbw				# %ah = 0
   1.504 +#else
   1.505 +	pushw	%dx
   1.506 +#endif
   1.507 +        int     $0x13			# reset controler
   1.508 +#ifndef FLOPPY_1440K_ONLY
   1.509 +	popw	%ax
   1.510 +	movb	$1, %al			# sector by sector...
   1.511 +#else
   1.512 +	movw	$1, %ax
   1.513 +	jmp	more1trk
   1.514 +#endif
   1.515 +read_sectorslp:
   1.516 +	pushw	%dx			# some bios break dx...
   1.517 +#ifndef FLOPPY_1440K_ONLY
   1.518 +        pushw   %ax			# limits
   1.519 +	subb	%cl, %al		# sectors remaining in track
   1.520 +	ja	tolastsect
   1.521 +	movb	$1, %al			# first track sector by sector
   1.522 +tolastsect:
   1.523 +#else
   1.524 +	movb	$FLOPPY_SECTORS+1, %al
   1.525 +	subb	%cl, %al		# sectors remaining in track
   1.526 +#endif
   1.527 +	cbw
   1.528 +	cmpw	%di, %ax
   1.529 +	jb	more1trk
   1.530 +	movw	%di, %ax		# sectors to read
   1.531 +more1trk:
   1.532 +	pushw	%ax			# save context
   1.533 +	movb	$2, %ah			# cmd: read chs
   1.534 +        int     $0x13
   1.535 +#ifndef FLOPPY_1440K_ONLY
   1.536 +	popw	%dx			# save %ax
   1.537 +        popw    %ax			# limits
   1.538 +#else
   1.539 +	popw	%ax			# restore context
   1.540 +	popw	%dx
   1.541 +#endif
   1.542 +	jc	check_limits
   1.543 +#ifndef FLOPPY_1440K_ONLY
   1.544 +	xchgw	%ax, %bp
   1.545 +	addw	%dx,%cx			# next sector
   1.546 +	movw	%cx, %si
   1.547 +	pushw	%dx
   1.548 +	shlclw	$5, %dx
   1.549 +	movw	%es, %cx
   1.550 +	addw	%dx, %cx
   1.551 +	popw	%dx
   1.552 +	subw	%dx,%di			# update sector counter
   1.553 +	popw	%dx
   1.554 +#else
   1.555 +	addw	%ax,%cx			# next sector
   1.556 +	movw	%cx, %si
   1.557 +	pushw	%ax
   1.558 +	shlclw	$5, %ax
   1.559 +	movw	%es, %cx
   1.560 +	addw	%ax, %cx
   1.561 +	popw	%ax
   1.562 +	subw	%ax,%di			# update sector counter
   1.563 +#endif
   1.564 +read_sectorsCX:
   1.565 +	movw	%cx, %es		# next location
   1.566 +	jz	return
   1.567 +read_sectors:
   1.568 +	movw	%si, %cx
   1.569 +#ifndef FLOPPY_1440K_ONLY
   1.570 +#   al is last sector+1
   1.571 +#   ah is last head+1
   1.572 +	xchgw	%ax, %bp
   1.573 +#endif
   1.574 +#ifndef FLOPPY_1440K_ONLY
   1.575 +        cmpb    %al,%cl			# reach sector limit ?
   1.576 +        jne     bdendlp
   1.577 +next_head:
   1.578 +        movb    %cl,%al
   1.579 +#else
   1.580 +        cmpb    $FLOPPY_SECTORS+1,%cl	# reach sector limit ?
   1.581 +        jne     bdendlp
   1.582 +#endif
   1.583 +        movb    $1,%cl			# first sector
   1.584 +#ifndef FLOPPY_HAS_2_SIDES
   1.585 +        incb    %dh			# next head
   1.586 +        cmpb    %ah, %dh		# reach head limit ?
   1.587 +        jne     bdendlp
   1.588 +next_cylinder:
   1.589 +        movb    %dh,%ah
   1.590 +        movb    $0,%dh			# first head
   1.591 +#else
   1.592 +        xorb    %cl,%dh			# next head
   1.593 +        jne	bdendlp			# reach head limit ?
   1.594 +#endif
   1.595 +# NOTE : support 256 cylinders max
   1.596 +        incb    %ch			# next cylinder
   1.597 +read_first_sectors:
   1.598 +bdendlp:
   1.599 +        jmp	read_sectorslp
   1.600 +
   1.601 +#ifdef VCPI
   1.602 +pagebuf		=	0x98000
   1.603 +tss		=	gdt_abs-40
   1.604 +gdt		=	gdt_abs-32
   1.605 +gdt_null	=	gdt_abs-32
   1.606 +gdt_vcpi	=	gdt_abs-24
   1.607 +gdt_vcpi2	=	gdt_abs-16
   1.608 +gdt_vcpi3	=	gdt_abs-8
   1.609 +gdt_abs:
   1.610 +	.word	0xFFFF
   1.611 +	.long	0x92000000
   1.612 +	.byte	0xCF,0
   1.613 +gdt_code:
   1.614 +	.word	0xFFFF
   1.615 +gdt_code_base:
   1.616 +	.long	0x9A000000+FLAT20(0)
   1.617 +	.byte	0x8F,0
   1.618 +gdt_tss:
   1.619 +	.word	0x00FF
   1.620 +gdt_tss_base:
   1.621 +	.long	0x89000000+FLAT20(tss)
   1.622 +	.byte	0,0
   1.623 +gdtr:
   1.624 +gdt_lim:
   1.625 +	.word	0xFFFF
   1.626 +gdt_base:
   1.627 +	.long	FLAT20(gdt)
   1.628 +sw2pm_params:
   1.629 +sw2pm_cr3:
   1.630 +	.long	pagebuf+0x1000
   1.631 +sw2pm_gdtr_ptr:
   1.632 +	.long	FLAT20(gdtr)
   1.633 +sw2pm_idtr_ptr:
   1.634 +	.long	FLAT20(idtr)
   1.635 +sw2pm_ldtr:
   1.636 +	.word	0
   1.637 +sw2pm_tr:
   1.638 +SEL_TSS		= gdt_tss-gdt_null
   1.639 +	.word	SEL_TSS
   1.640 +sw2pm_jumpaddr:
   1.641 +	.long	pm_code
   1.642 +SEL_CODE	= gdt_code-gdt_null
   1.643 +	.word	SEL_CODE
   1.644 +idtr:
   1.645 +idt_lim:
   1.646 +	.word	0x03FF
   1.647 +idt_base:
   1.648 +	.long	0
   1.649 +# ifndef SHUTDOWNDOS
   1.650 +saved_ss_sp:
   1.651 +	.word	stacktop-4-16-4,INITSEG
   1.652 +# endif
   1.653 +#endif
   1.654 +#ifdef ELKS
   1.655 +	.org	0x1E3
   1.656 +	.byte	13,10,7
   1.657 +	.asciz	"ELKS Boot"
   1.658 +#endif