ソースを参照

[zbin] Allow decompressor to generate debug output via BIOS console

The 0xe9 debug port exists only on virtual machines.  Provide an
option to print debug output on the BIOS console, to allow for
debugging on real hardware.

Note that this option can be used only if the decompressor is called
in flat real mode; the easiest way to achieve this is to build with
DEBUG=libprefix.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 9年前
コミット
c11306e6ca
1個のファイルの変更50行の追加19行の削除
  1. 50
    19
      src/arch/i386/prefix/unlzma.S

+ 50
- 19
src/arch/i386/prefix/unlzma.S ファイルの表示

@@ -55,25 +55,58 @@ FILE_LICENCE ( GPL2_OR_LATER );
55 55
 #endif /* CODE16 */
56 56
 
57 57
 /****************************************************************************
58
- * Debugging (via 0xe9 debug port)
58
+ * Debugging
59 59
  ****************************************************************************
60
+ *
61
+ * This code will usually run in 16-bit protected mode, in which case
62
+ * only the 0xe9 debug port (present on some virtual machines) can be
63
+ * used.
64
+ *
65
+ * To debug on real hardware, build with DEBUG=libprefix.  This will
66
+ * cause this code to be called in flat real mode, and so DEBUG_INT10
67
+ * may be used.
60 68
  */
61 69
 
62
-#define DEBUG 0
70
+/* Enable debugging via 0xe9 debug port */
71
+#define DEBUG_E9 0
63 72
 
64
-#if DEBUG
65
-	.macro	print_character, char
73
+/* Enable debugging via BIOS INT 10 (works only when in flat real mode) */
74
+#define DEBUG_INT10 0
75
+
76
+#if ( DEBUG_E9 || DEBUG_INT10 )
77
+	.macro	print_character, reg
78
+	pushfl
66 79
 	pushw	%ax
67
-	movb 	$\char, %al
80
+	pushw	%bx
81
+	pushw	%bp
82
+	movb 	\reg, %al
83
+	movw	$0x0007, %bx
84
+	movb	$0x0e, %ah
85
+#if DEBUG_E9
68 86
 	outb	%al, $0xe9
87
+#endif
88
+#if DEBUG_INT10
89
+	cmpb	$('\n'), %al
90
+	jne	L\@
91
+	int	$0x10
92
+	movb	$('\r'), %al
93
+L\@:	int	$0x10
94
+#endif
95
+	popw	%bp
96
+	popw	%bx
69 97
 	popw	%ax
98
+	popfl
70 99
 	.endm
71 100
 
72 101
 	.macro	print_hex_nibble
102
+	pushfl
103
+	pushw	%ax
73 104
 	cmpb	$10, %al
74 105
 	sbb	$0x69, %al
75 106
 	das
76
-	outb	%al, $0xe9
107
+	print_character %al
108
+	popw	%ax
109
+	popfl
77 110
 	.endm
78 111
 
79 112
 	.macro	print_hex_byte, reg
@@ -205,8 +238,6 @@ literal:	.rept	( ( 1 << LZMA_LC ) * 0x300 )
205 238
  * Returns:
206 239
  *   %ds:%esi : compressed input data pointer (possibly updated)
207 240
  *   %eax : current range
208
- * Corrupts:
209
- *   %eax
210 241
  *****************************************************************************
211 242
  */
212 243
 rc_normalise:
@@ -476,7 +507,7 @@ lzma_literal:
476 507
 	/* Store output byte */
477 508
 	ADDR32 stosb
478 509
 	print_hex_byte %al
479
-	print_character ' '
510
+	print_character $(' ')
480 511
 	/* Update LZMA state */
481 512
 	subb	$3, %dl
482 513
 	jns	1f
@@ -562,14 +593,14 @@ lzma_len:
562 593
  *****************************************************************************
563 594
  */
564 595
 match:	/* Update repeated match list */
565
-	print_character '['
596
+	print_character $('[')
566 597
 	movl	$3, %ecx
567 598
 	jmp	1f
568 599
 match_rep:
569
-	print_character '['
570
-	print_character 'R'
600
+	print_character $('[')
601
+	print_character $('R')
571 602
 	print_hex_byte %cl
572
-	print_character '='
603
+	print_character $('=')
573 604
 	movzbl	%cl, %ecx
574 605
 	movl	reps(%ebp,%ecx,4), %eax
575 606
 	jcxz	2f
@@ -582,10 +613,10 @@ match_rep:
582 613
 	/* Get stored match length */
583 614
 	movzwl	len(%ebp), %ecx
584 615
 	print_hex_dword	%eax
585
-	print_character '+'
616
+	print_character $('+')
586 617
 	print_hex_word %cx
587
-	print_character ']'
588
-	print_character ' '
618
+	print_character $(']')
619
+	print_character $(' ')
589 620
 	/* Abort with CF set if match distance is out of range */
590 621
 	movl	out_start(%ebp), %esi
591 622
 	negl	%esi
@@ -872,13 +903,13 @@ decompress:
872 903
 	/* Initialise remaining parameters */
873 904
 	movl	%esi, in_start(%ebp)
874 905
 	movl	%edi, out_start(%ebp)
875
-	print_character '\n'
906
+	print_character $('\n')
876 907
 	ADDR32 lodsb	/* discard initial byte */
877 908
 	print_hex_byte %al
878 909
 	ADDR32 lodsl
879 910
 	bswapl	%eax
880 911
 	print_hex_dword %eax
881
-	print_character '\n'
912
+	print_character $('\n')
882 913
 	movl	%eax, rc_code(%ebp)
883 914
 	decl	rc_range(%ebp)
884 915
 	movl	$STATE_LIT_LIT, %edx
@@ -886,7 +917,7 @@ decompress:
886 917
 	call	lzma_decode
887 918
 	jnc	1b
888 919
 	call	rc_normalise
889
-	print_character '\n'
920
+	print_character $('\n')
890 921
 	/* Undo BCJ filter */
891 922
 	pushl	%esi
892 923
 	movl	out_start(%ebp), %esi

読み込み中…
キャンセル
保存