|  | @@ -341,6 +341,7 @@ zero_bytes:
 | 
		
	
		
			
			| 341 | 341 |   * Returns:
 | 
		
	
		
			
			| 342 | 342 |   *   %esi : next source physical address
 | 
		
	
		
			
			| 343 | 343 |   *   %edi : next destination physical address
 | 
		
	
		
			
			|  | 344 | + *   CF : as returned by memcpy()-like function
 | 
		
	
		
			
			| 344 | 345 |   * Corrupts:
 | 
		
	
		
			
			| 345 | 346 |   *   None
 | 
		
	
		
			
			| 346 | 347 |   ****************************************************************************
 | 
		
	
	
		
			
			|  | @@ -356,6 +357,7 @@ process_bytes:
 | 
		
	
		
			
			| 356 | 357 |  	pushl	%ebp
 | 
		
	
		
			
			| 357 | 358 |  
 | 
		
	
		
			
			| 358 | 359 |  	/* Construct GDT on stack (since .prefix may not be writable) */
 | 
		
	
		
			
			|  | 360 | +	.equ	GDT_LEN, 0x20
 | 
		
	
		
			
			| 359 | 361 |  	.equ	PM_DS, 0x18	/* Flat data segment */
 | 
		
	
		
			
			| 360 | 362 |  	pushl	$0x00cf9300
 | 
		
	
		
			
			| 361 | 363 |  	pushl	$0x0000ffff
 | 
		
	
	
		
			
			|  | @@ -369,7 +371,7 @@ process_bytes:
 | 
		
	
		
			
			| 369 | 371 |  	pushw	$0xffff
 | 
		
	
		
			
			| 370 | 372 |  	pushl	$0		/* Base and length */
 | 
		
	
		
			
			| 371 | 373 |  	pushw	%ss
 | 
		
	
		
			
			| 372 |  | -	pushw	$0x1f
 | 
		
	
		
			
			|  | 374 | +	pushw	$( GDT_LEN - 1 )
 | 
		
	
		
			
			| 373 | 375 |  	movzwl	%sp, %ebp
 | 
		
	
		
			
			| 374 | 376 |  	shll	$4, 0x02(%bp)
 | 
		
	
		
			
			| 375 | 377 |  	addl	%ebp, 0x02(%bp)
 | 
		
	
	
		
			
			|  | @@ -407,7 +409,9 @@ process_bytes:
 | 
		
	
		
			
			| 407 | 409 |  
 | 
		
	
		
			
			| 408 | 410 |  	/* Return to (flat) real mode */
 | 
		
	
		
			
			| 409 | 411 |  	movl	%cr0, %eax
 | 
		
	
		
			
			|  | 412 | +	pushfw
 | 
		
	
		
			
			| 410 | 413 |  	andb	$0!CR0_PE, %al
 | 
		
	
		
			
			|  | 414 | +	popfw
 | 
		
	
		
			
			| 411 | 415 |  	movl	%eax, %cr0
 | 
		
	
		
			
			| 412 | 416 |  	lret
 | 
		
	
		
			
			| 413 | 417 |  2:	/* lret will ljmp to here */
 | 
		
	
	
		
			
			|  | @@ -433,7 +437,7 @@ process_bytes:
 | 
		
	
		
			
			| 433 | 437 |  
 | 
		
	
		
			
			| 434 | 438 |  	/* Restore GDT */
 | 
		
	
		
			
			| 435 | 439 |  	data32 lgdt -8(%bp)
 | 
		
	
		
			
			| 436 |  | -	addw	$( 8 /* saved GDT */ + ( PM_DS + 8 ) /* GDT on stack */ ), %sp
 | 
		
	
		
			
			|  | 440 | +	leaw	GDT_LEN(%bp), %sp
 | 
		
	
		
			
			| 437 | 441 |  
 | 
		
	
		
			
			| 438 | 442 |  	/* Restore registers and return */
 | 
		
	
		
			
			| 439 | 443 |  	popl	%ebp
 | 
		
	
	
		
			
			|  | @@ -461,6 +465,7 @@ process_bytes:
 | 
		
	
		
			
			| 461 | 465 |  	call	*%bx
 | 
		
	
		
			
			| 462 | 466 |  
 | 
		
	
		
			
			| 463 | 467 |  	/* Convert %ds:esi and %es:edi back to physical addresses */
 | 
		
	
		
			
			|  | 468 | +	pushfw
 | 
		
	
		
			
			| 464 | 469 |  	xorl	%eax, %eax
 | 
		
	
		
			
			| 465 | 470 |  	movw    %ds, %ax
 | 
		
	
		
			
			| 466 | 471 |  	shll	$4, %eax
 | 
		
	
	
		
			
			|  | @@ -469,6 +474,7 @@ process_bytes:
 | 
		
	
		
			
			| 469 | 474 |  	movw    %es, %ax
 | 
		
	
		
			
			| 470 | 475 |  	shll	$4, %eax
 | 
		
	
		
			
			| 471 | 476 |  	addl	%eax, %edi
 | 
		
	
		
			
			|  | 477 | +	popfw
 | 
		
	
		
			
			| 472 | 478 |  
 | 
		
	
		
			
			| 473 | 479 |  	/* Restore registers and return */
 | 
		
	
		
			
			| 474 | 480 |  	popw	%es
 | 
		
	
	
		
			
			|  | @@ -493,6 +499,7 @@ process_bytes:
 | 
		
	
		
			
			| 493 | 499 |   * Returns:
 | 
		
	
		
			
			| 494 | 500 |   *   %esi : next source physical address (will be a multiple of 16)
 | 
		
	
		
			
			| 495 | 501 |   *   %edi : next destination physical address (will be a multiple of 16)
 | 
		
	
		
			
			|  | 502 | + *   CF set on failure
 | 
		
	
		
			
			| 496 | 503 |   * Corrupts:
 | 
		
	
		
			
			| 497 | 504 |   *   none
 | 
		
	
		
			
			| 498 | 505 |   ****************************************************************************
 | 
		
	
	
		
			
			|  | @@ -511,6 +518,7 @@ install_block:
 | 
		
	
		
			
			| 511 | 518 |  	movw	$copy_bytes, %bx
 | 
		
	
		
			
			| 512 | 519 |  #endif
 | 
		
	
		
			
			| 513 | 520 |  	call	process_bytes
 | 
		
	
		
			
			|  | 521 | +	jc	99f
 | 
		
	
		
			
			| 514 | 522 |  
 | 
		
	
		
			
			| 515 | 523 |  	/* Zero .bss portion */
 | 
		
	
		
			
			| 516 | 524 |  	negl	%ecx
 | 
		
	
	
		
			
			|  | @@ -522,9 +530,9 @@ install_block:
 | 
		
	
		
			
			| 522 | 530 |  	addl	$0xf, %esi
 | 
		
	
		
			
			| 523 | 531 |  	andl	$~0xf, %esi
 | 
		
	
		
			
			| 524 | 532 |  	addl	$0xf, %edi
 | 
		
	
		
			
			| 525 |  | -	andl	$~0xf, %edi
 | 
		
	
		
			
			|  | 533 | +	andl	$~0xf, %edi /* Will also clear CF */
 | 
		
	
		
			
			| 526 | 534 |  
 | 
		
	
		
			
			| 527 |  | -	/* Restore registers and return */
 | 
		
	
		
			
			|  | 535 | +99:	/* Restore registers and return */
 | 
		
	
		
			
			| 528 | 536 |  	popw	%bx
 | 
		
	
		
			
			| 529 | 537 |  	popl	%ecx
 | 
		
	
		
			
			| 530 | 538 |  	ret
 | 
		
	
	
		
			
			|  | @@ -730,6 +738,7 @@ install_prealloc:
 | 
		
	
		
			
			| 730 | 738 |  	movl	$_text16_early_filesz, %ecx
 | 
		
	
		
			
			| 731 | 739 |  	movl	$_text16_early_memsz, %edx
 | 
		
	
		
			
			| 732 | 740 |  	call	install_block		/* .text16.early */
 | 
		
	
		
			
			|  | 741 | +	jc	install_block_death
 | 
		
	
		
			
			| 733 | 742 |  	popl	%ecx			/* Calculate offset to next block */
 | 
		
	
		
			
			| 734 | 743 |  	subl	%esi, %ecx
 | 
		
	
		
			
			| 735 | 744 |  	negl	%ecx
 | 
		
	
	
		
			
			|  | @@ -748,17 +757,8 @@ install_prealloc:
 | 
		
	
		
			
			| 748 | 757 |  	pushw	$access_highmem
 | 
		
	
		
			
			| 749 | 758 |  	lret
 | 
		
	
		
			
			| 750 | 759 |  1:	/* Die if we could not access high memory */
 | 
		
	
		
			
			| 751 |  | -	jnc	3f
 | 
		
	
		
			
			| 752 |  | -	movw	$a20_death_message, %si
 | 
		
	
		
			
			| 753 |  | -	xorw	%di, %di
 | 
		
	
		
			
			| 754 |  | -	call	print_message
 | 
		
	
		
			
			| 755 |  | -2:	jmp	2b
 | 
		
	
		
			
			| 756 |  | -	.section ".prefix.data.a20_death_message", "aw", @progbits
 | 
		
	
		
			
			| 757 |  | -a20_death_message:
 | 
		
	
		
			
			| 758 |  | -	.asciz	"\nHigh memory inaccessible - cannot continue\n"
 | 
		
	
		
			
			| 759 |  | -	.size	a20_death_message, . - a20_death_message
 | 
		
	
		
			
			| 760 |  | -	.previous
 | 
		
	
		
			
			| 761 |  | -3:
 | 
		
	
		
			
			|  | 760 | +	jc	access_highmem_death
 | 
		
	
		
			
			|  | 761 | +
 | 
		
	
		
			
			| 762 | 762 |  #endif
 | 
		
	
		
			
			| 763 | 763 |  
 | 
		
	
		
			
			| 764 | 764 |  	/* Open payload (which may not yet be in memory) */
 | 
		
	
	
		
			
			|  | @@ -769,25 +769,7 @@ a20_death_message:
 | 
		
	
		
			
			| 769 | 769 |  	pushw	$open_payload
 | 
		
	
		
			
			| 770 | 770 |  	lret
 | 
		
	
		
			
			| 771 | 771 |  1:	/* Die if we could not access the payload */
 | 
		
	
		
			
			| 772 |  | -	jnc	3f
 | 
		
	
		
			
			| 773 |  | -	xorw	%di, %di
 | 
		
	
		
			
			| 774 |  | -	movl	%esi, %eax
 | 
		
	
		
			
			| 775 |  | -	call	print_hex_dword
 | 
		
	
		
			
			| 776 |  | -	call	print_space
 | 
		
	
		
			
			| 777 |  | -	movl	%ecx, %eax
 | 
		
	
		
			
			| 778 |  | -	call	print_hex_dword
 | 
		
	
		
			
			| 779 |  | -	movw	$payload_death_message, %si
 | 
		
	
		
			
			| 780 |  | -	call	print_message
 | 
		
	
		
			
			| 781 |  | -2:	/* Halt system */
 | 
		
	
		
			
			| 782 |  | -	cli
 | 
		
	
		
			
			| 783 |  | -	hlt
 | 
		
	
		
			
			| 784 |  | -	jmp	2b
 | 
		
	
		
			
			| 785 |  | -	.section ".prefix.data.payload_death_message", "aw", @progbits
 | 
		
	
		
			
			| 786 |  | -payload_death_message:
 | 
		
	
		
			
			| 787 |  | -	.asciz	"\nPayload inaccessible - cannot continue\n"
 | 
		
	
		
			
			| 788 |  | -	.size	payload_death_message, . - payload_death_message
 | 
		
	
		
			
			| 789 |  | -	.previous
 | 
		
	
		
			
			| 790 |  | -3:
 | 
		
	
		
			
			|  | 772 | +	jc	open_payload_death
 | 
		
	
		
			
			| 791 | 773 |  
 | 
		
	
		
			
			| 792 | 774 |  	/* Calculate physical address of payload (i.e. first source) */
 | 
		
	
		
			
			| 793 | 775 |  	testl	%esi, %esi
 | 
		
	
	
		
			
			|  | @@ -801,12 +783,14 @@ payload_death_message:
 | 
		
	
		
			
			| 801 | 783 |  	movl	$_text16_late_filesz, %ecx
 | 
		
	
		
			
			| 802 | 784 |  	movl	$_text16_late_memsz, %edx
 | 
		
	
		
			
			| 803 | 785 |  	call	install_block		/* .text16.late */
 | 
		
	
		
			
			|  | 786 | +	jc	install_block_death
 | 
		
	
		
			
			| 804 | 787 |  	progress "  .data16\n"
 | 
		
	
		
			
			| 805 | 788 |  	movzwl	%bx, %edi
 | 
		
	
		
			
			| 806 | 789 |  	shll	$4, %edi
 | 
		
	
		
			
			| 807 | 790 |  	movl	$_data16_filesz, %ecx
 | 
		
	
		
			
			| 808 | 791 |  	movl	$_data16_filesz, %edx	/* do not zero our temporary stack */
 | 
		
	
		
			
			| 809 | 792 |  	call	install_block		/* .data16 */
 | 
		
	
		
			
			|  | 793 | +	jc	install_block_death
 | 
		
	
		
			
			| 810 | 794 |  
 | 
		
	
		
			
			| 811 | 795 |  	/* Set up %ds for access to .data16 */
 | 
		
	
		
			
			| 812 | 796 |  	movw	%bx, %ds
 | 
		
	
	
		
			
			|  | @@ -846,6 +830,7 @@ payload_death_message:
 | 
		
	
		
			
			| 846 | 830 |  	movl	$_textdata_filesz, %ecx
 | 
		
	
		
			
			| 847 | 831 |  	movl	$_textdata_memsz, %edx
 | 
		
	
		
			
			| 848 | 832 |  	call	install_block
 | 
		
	
		
			
			|  | 833 | +	jc	install_block_death
 | 
		
	
		
			
			| 849 | 834 |  	popl	%edi
 | 
		
	
		
			
			| 850 | 835 |  
 | 
		
	
		
			
			| 851 | 836 |  #endif /* KEEP_IT_REAL */
 | 
		
	
	
		
			
			|  | @@ -960,6 +945,52 @@ close_payload:
 | 
		
	
		
			
			| 960 | 945 |  	.size	open_payload, . - open_payload
 | 
		
	
		
			
			| 961 | 946 |  	.size	close_payload, . - close_payload
 | 
		
	
		
			
			| 962 | 947 |  
 | 
		
	
		
			
			|  | 948 | +	/* Report installation failure */
 | 
		
	
		
			
			|  | 949 | +	.section ".prefix.install_death", "ax", @progbits
 | 
		
	
		
			
			|  | 950 | +install_death:
 | 
		
	
		
			
			|  | 951 | +	pushw	%cs
 | 
		
	
		
			
			|  | 952 | +	popw	%ds
 | 
		
	
		
			
			|  | 953 | +	xorw	%di, %di
 | 
		
	
		
			
			|  | 954 | +	call	print_hex_dword
 | 
		
	
		
			
			|  | 955 | +	call	print_space
 | 
		
	
		
			
			|  | 956 | +	movl	%esi, %eax
 | 
		
	
		
			
			|  | 957 | +	call	print_hex_dword
 | 
		
	
		
			
			|  | 958 | +	call	print_space
 | 
		
	
		
			
			|  | 959 | +	movl	%ecx, %eax
 | 
		
	
		
			
			|  | 960 | +	call	print_hex_dword
 | 
		
	
		
			
			|  | 961 | +	movw	$install_death_message, %si
 | 
		
	
		
			
			|  | 962 | +	call	print_message
 | 
		
	
		
			
			|  | 963 | +2:	/* Halt system */
 | 
		
	
		
			
			|  | 964 | +	cli
 | 
		
	
		
			
			|  | 965 | +	hlt
 | 
		
	
		
			
			|  | 966 | +	jmp	2b
 | 
		
	
		
			
			|  | 967 | +	.size	install_death, . - install_death
 | 
		
	
		
			
			|  | 968 | +	.section ".prefix.data.install_death_message", "aw", @progbits
 | 
		
	
		
			
			|  | 969 | +install_death_message:
 | 
		
	
		
			
			|  | 970 | +	.asciz	"\nInstallation failed - cannot continue\n"
 | 
		
	
		
			
			|  | 971 | +	.size	install_death_message, . - install_death_message
 | 
		
	
		
			
			|  | 972 | +
 | 
		
	
		
			
			|  | 973 | +	/* Report failure to access high memory */
 | 
		
	
		
			
			|  | 974 | +	.section ".prefix.install_block_death", "ax", @progbits
 | 
		
	
		
			
			|  | 975 | +install_block_death:
 | 
		
	
		
			
			|  | 976 | +	movl	$0x1b101b10, %eax
 | 
		
	
		
			
			|  | 977 | +	jmp	install_death
 | 
		
	
		
			
			|  | 978 | +	.size	install_block_death, . - install_block_death
 | 
		
	
		
			
			|  | 979 | +
 | 
		
	
		
			
			|  | 980 | +	/* Report failure to access high memory */
 | 
		
	
		
			
			|  | 981 | +	.section ".prefix.access_highmem_death", "ax", @progbits
 | 
		
	
		
			
			|  | 982 | +access_highmem_death:
 | 
		
	
		
			
			|  | 983 | +	movl	$0x0a200a20, %eax
 | 
		
	
		
			
			|  | 984 | +	jmp	install_death
 | 
		
	
		
			
			|  | 985 | +	.size	access_highmem_death, . - access_highmem_death
 | 
		
	
		
			
			|  | 986 | +
 | 
		
	
		
			
			|  | 987 | +	/* Report failure to open payload */
 | 
		
	
		
			
			|  | 988 | +	.section ".prefix.open_payload_death", "ax", @progbits
 | 
		
	
		
			
			|  | 989 | +open_payload_death:
 | 
		
	
		
			
			|  | 990 | +	xorl	%eax, %eax
 | 
		
	
		
			
			|  | 991 | +	jmp	install_death
 | 
		
	
		
			
			|  | 992 | +	.size	open_payload_death, . - open_payload_death
 | 
		
	
		
			
			|  | 993 | +
 | 
		
	
		
			
			| 963 | 994 |  /****************************************************************************
 | 
		
	
		
			
			| 964 | 995 |   * uninstall
 | 
		
	
		
			
			| 965 | 996 |   *
 |