Procházet zdrojové kódy

[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 před 9 roky
rodič
revize
c11306e6ca
1 změnil soubory, kde provedl 50 přidání a 19 odebrání
  1. 50
    19
      src/arch/i386/prefix/unlzma.S

+ 50
- 19
src/arch/i386/prefix/unlzma.S Zobrazit soubor

55
 #endif /* CODE16 */
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
 	pushw	%ax
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
 	outb	%al, $0xe9
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
 	popw	%ax
97
 	popw	%ax
98
+	popfl
70
 	.endm
99
 	.endm
71
 
100
 
72
 	.macro	print_hex_nibble
101
 	.macro	print_hex_nibble
102
+	pushfl
103
+	pushw	%ax
73
 	cmpb	$10, %al
104
 	cmpb	$10, %al
74
 	sbb	$0x69, %al
105
 	sbb	$0x69, %al
75
 	das
106
 	das
76
-	outb	%al, $0xe9
107
+	print_character %al
108
+	popw	%ax
109
+	popfl
77
 	.endm
110
 	.endm
78
 
111
 
79
 	.macro	print_hex_byte, reg
112
 	.macro	print_hex_byte, reg
205
  * Returns:
238
  * Returns:
206
  *   %ds:%esi : compressed input data pointer (possibly updated)
239
  *   %ds:%esi : compressed input data pointer (possibly updated)
207
  *   %eax : current range
240
  *   %eax : current range
208
- * Corrupts:
209
- *   %eax
210
  *****************************************************************************
241
  *****************************************************************************
211
  */
242
  */
212
 rc_normalise:
243
 rc_normalise:
476
 	/* Store output byte */
507
 	/* Store output byte */
477
 	ADDR32 stosb
508
 	ADDR32 stosb
478
 	print_hex_byte %al
509
 	print_hex_byte %al
479
-	print_character ' '
510
+	print_character $(' ')
480
 	/* Update LZMA state */
511
 	/* Update LZMA state */
481
 	subb	$3, %dl
512
 	subb	$3, %dl
482
 	jns	1f
513
 	jns	1f
562
  *****************************************************************************
593
  *****************************************************************************
563
  */
594
  */
564
 match:	/* Update repeated match list */
595
 match:	/* Update repeated match list */
565
-	print_character '['
596
+	print_character $('[')
566
 	movl	$3, %ecx
597
 	movl	$3, %ecx
567
 	jmp	1f
598
 	jmp	1f
568
 match_rep:
599
 match_rep:
569
-	print_character '['
570
-	print_character 'R'
600
+	print_character $('[')
601
+	print_character $('R')
571
 	print_hex_byte %cl
602
 	print_hex_byte %cl
572
-	print_character '='
603
+	print_character $('=')
573
 	movzbl	%cl, %ecx
604
 	movzbl	%cl, %ecx
574
 	movl	reps(%ebp,%ecx,4), %eax
605
 	movl	reps(%ebp,%ecx,4), %eax
575
 	jcxz	2f
606
 	jcxz	2f
582
 	/* Get stored match length */
613
 	/* Get stored match length */
583
 	movzwl	len(%ebp), %ecx
614
 	movzwl	len(%ebp), %ecx
584
 	print_hex_dword	%eax
615
 	print_hex_dword	%eax
585
-	print_character '+'
616
+	print_character $('+')
586
 	print_hex_word %cx
617
 	print_hex_word %cx
587
-	print_character ']'
588
-	print_character ' '
618
+	print_character $(']')
619
+	print_character $(' ')
589
 	/* Abort with CF set if match distance is out of range */
620
 	/* Abort with CF set if match distance is out of range */
590
 	movl	out_start(%ebp), %esi
621
 	movl	out_start(%ebp), %esi
591
 	negl	%esi
622
 	negl	%esi
872
 	/* Initialise remaining parameters */
903
 	/* Initialise remaining parameters */
873
 	movl	%esi, in_start(%ebp)
904
 	movl	%esi, in_start(%ebp)
874
 	movl	%edi, out_start(%ebp)
905
 	movl	%edi, out_start(%ebp)
875
-	print_character '\n'
906
+	print_character $('\n')
876
 	ADDR32 lodsb	/* discard initial byte */
907
 	ADDR32 lodsb	/* discard initial byte */
877
 	print_hex_byte %al
908
 	print_hex_byte %al
878
 	ADDR32 lodsl
909
 	ADDR32 lodsl
879
 	bswapl	%eax
910
 	bswapl	%eax
880
 	print_hex_dword %eax
911
 	print_hex_dword %eax
881
-	print_character '\n'
912
+	print_character $('\n')
882
 	movl	%eax, rc_code(%ebp)
913
 	movl	%eax, rc_code(%ebp)
883
 	decl	rc_range(%ebp)
914
 	decl	rc_range(%ebp)
884
 	movl	$STATE_LIT_LIT, %edx
915
 	movl	$STATE_LIT_LIT, %edx
886
 	call	lzma_decode
917
 	call	lzma_decode
887
 	jnc	1b
918
 	jnc	1b
888
 	call	rc_normalise
919
 	call	rc_normalise
889
-	print_character '\n'
920
+	print_character $('\n')
890
 	/* Undo BCJ filter */
921
 	/* Undo BCJ filter */
891
 	pushl	%esi
922
 	pushl	%esi
892
 	movl	out_start(%ebp), %esi
923
 	movl	out_start(%ebp), %esi

Načítá se…
Zrušit
Uložit