Browse Source

[PXE] Improve PnP/BBS detection

Use BBS installation check to see if we need to hook INT19 even on a PnP
BIOS.

Verify that $PnP signature is paragraph-aligned; bochs/qemu BIOS provides
a dummy $PnP signature with no valid entry point, and deliberately
unaligns the signature to indicate that it is not properly valid.

Print message if INT19 is hooked.

Attempt to use PMM even if BBS check failed.
tags/v0.9.4
Michael Brown 16 years ago
parent
commit
9c86a39551
1 changed files with 49 additions and 19 deletions
  1. 49
    19
      src/arch/i386/prefix/romprefix.S

+ 49
- 19
src/arch/i386/prefix/romprefix.S View File

9
 #define PNP_SIGNATURE ( '$' + ( 'P' << 8 ) + ( 'n' << 16 ) + ( 'P' << 24 ) )
9
 #define PNP_SIGNATURE ( '$' + ( 'P' << 8 ) + ( 'n' << 16 ) + ( 'P' << 24 ) )
10
 #define PMM_SIGNATURE ( '$' + ( 'P' << 8 ) + ( 'M' << 16 ) + ( 'M' << 24 ) )
10
 #define PMM_SIGNATURE ( '$' + ( 'P' << 8 ) + ( 'M' << 16 ) + ( 'M' << 24 ) )
11
 #define STACK_MAGIC ( 'L' + ( 'R' << 8 ) + ( 'E' << 16 ) + ( 'T' << 24 ) )
11
 #define STACK_MAGIC ( 'L' + ( 'R' << 8 ) + ( 'E' << 16 ) + ( 'T' << 24 ) )
12
+#define PNP_GET_BBS_VERSION 0x60
12
 
13
 
13
 	.text
14
 	.text
14
 	.code16
15
 	.code16
123
 	movw	$init_message, %si
124
 	movw	$init_message, %si
124
 	call	print_message
125
 	call	print_message
125
 	/* Check for PnP BIOS */
126
 	/* Check for PnP BIOS */
127
+	testw	$0x0f, %di	/* PnP signature must be aligned - bochs    */
128
+	jnz	hook_int19	/* uses unalignment to indicate 'fake' PnP. */
126
 	cmpl	$PNP_SIGNATURE, %es:0(%di)
129
 	cmpl	$PNP_SIGNATURE, %es:0(%di)
127
-	je	ispnp
128
-notpnp:	/* Not PnP: hook INT19 */
130
+	jne	hook_int19
131
+	/* Is PnP: print PnP message */
132
+	movw	$init_message_pnp, %si
133
+	call	print_message
134
+	xchgw	%bx, %bx
135
+	/* Check for BBS */
136
+	pushw	%es:0x1b(%di)	/* Real-mode data segment */
137
+	pushw	%ds		/* &(bbs_version) */
138
+	pushw	$bbs_version
139
+	pushw	$PNP_GET_BBS_VERSION
140
+	lcall	*%es:0xd(%di)
141
+	addw	$16, %sp
142
+	testw	%ax, %ax
143
+	jne	hook_int19
144
+	movw	$init_message_bbs, %si
145
+	call	print_message
146
+	jmp	hook_bbs
147
+	/* Not BBS-compliant - must hook INT 19 */
148
+hook_int19:
149
+	movw	$init_message_int19, %si
150
+	call	print_message
129
 	xorw	%ax, %ax
151
 	xorw	%ax, %ax
130
 	movw	%ax, %es
152
 	movw	%ax, %es
131
 	pushw	%cs
153
 	pushw	%cs
132
 	pushw	$int19_entry
154
 	pushw	$int19_entry
133
 	popl	%es:( 0x19 * 4 )
155
 	popl	%es:( 0x19 * 4 )
134
-	jmp	99f
135
-ispnp:	/* Is PnP: print PnP message */
136
-	movw	$init_message_pnp, %si
137
-	call	print_message
156
+hook_bbs:
138
 	/* Check for PMM */
157
 	/* Check for PMM */
139
 	movw	$( 0xe000 - 1 ), %di
158
 	movw	$( 0xe000 - 1 ), %di
140
 pmm_scan:
159
 pmm_scan:
141
 	incw	%di
160
 	incw	%di
142
-	jz	99f
161
+	jz	no_pmm
143
 	movw	%di, %es
162
 	movw	%di, %es
144
 	cmpl	$PMM_SIGNATURE, %es:0
163
 	cmpl	$PMM_SIGNATURE, %es:0
145
 	jne	pmm_scan
164
 	jne	pmm_scan
158
 	pushl	$0xffffffff	/* No handle */
177
 	pushl	$0xffffffff	/* No handle */
159
 	pushl	$( 0x00200000 / 16 ) /* 2MB in paragraphs */
178
 	pushl	$( 0x00200000 / 16 ) /* 2MB in paragraphs */
160
 	pushw	$0x0000		/* pmmAllocate */
179
 	pushw	$0x0000		/* pmmAllocate */
161
-	lcall	%es:*(7)
180
+	lcall	*%es:7
162
 	addw	$12, %sp
181
 	addw	$12, %sp
163
 	testw	%dx, %dx	/* %ax==0 even on success, since align=2MB */
182
 	testw	%dx, %dx	/* %ax==0 even on success, since align=2MB */
164
 	jnz	gotpmm
183
 	jnz	gotpmm
165
 	movw	$init_message_pmm_failed, %si
184
 	movw	$init_message_pmm_failed, %si
166
 	call	print_message
185
 	call	print_message
167
-	jmp	99f
186
+	jmp	no_pmm
168
 gotpmm:	/* PMM allocation succeeded: copy ROM to PMM block */
187
 gotpmm:	/* PMM allocation succeeded: copy ROM to PMM block */
169
 	pushal			/* PMM presence implies 1kB stack */
188
 	pushal			/* PMM presence implies 1kB stack */
170
 	movw	%ax, %es	/* %ax=0 already - see above */
189
 	movw	%ax, %es	/* %ax=0 already - see above */
188
 	loop	1b
207
 	loop	1b
189
 	subb	%bl, checksum
208
 	subb	%bl, checksum
190
 	popal
209
 	popal
191
-99:
210
+no_pmm:
192
 	/* Print CRLF to terminate messages */
211
 	/* Print CRLF to terminate messages */
193
-	movw	$init_message_crlf, %si
194
-	call	print_message
212
+	movw	$'\n', %ax
213
+	call	print_character
195
 	/* Restore registers */
214
 	/* Restore registers */
196
 	popw	%es
215
 	popw	%es
197
 	popw	%ds
216
 	popw	%ds
202
 	.size init, . - init
221
 	.size init, . - init
203
 
222
 
204
 init_message:
223
 init_message:
205
-	.asciz	"gPXE (http://etherboot.org)"
224
+	.asciz	"gPXE (http://etherboot.org) -"
206
 	.size	init_message, . - init_message
225
 	.size	init_message, . - init_message
207
 init_message_pnp:
226
 init_message_pnp:
208
-	.asciz	" - PnP BIOS detected"
227
+	.asciz	" PnP"
209
 	.size init_message_pnp, . - init_message_pnp
228
 	.size init_message_pnp, . - init_message_pnp
229
+init_message_bbs:
230
+	.asciz	" BBS"
231
+	.size init_message_bbs, . - init_message_bbs
210
 init_message_pmm:
232
 init_message_pmm:
211
-	.asciz	", using PMM"
233
+	.asciz	" PMM"
212
 	.size init_message_pmm, . - init_message_pmm
234
 	.size init_message_pmm, . - init_message_pmm
213
 init_message_pmm_failed:
235
 init_message_pmm_failed:
214
-	.asciz	" (failed)"
236
+	.asciz	"(failed)"
215
 	.size init_message_pmm_failed, . - init_message_pmm_failed
237
 	.size init_message_pmm_failed, . - init_message_pmm_failed
216
-init_message_crlf:
217
-	.asciz	"\n"
218
-	.size	init_message_crlf, . - init_message_crlf
238
+init_message_int19:
239
+	.asciz	" INT19"
240
+	.size init_message_int19, . - init_message_int19
219
 
241
 
220
 /* ROM image location
242
 /* ROM image location
221
  *
243
  *
224
 image_source:
246
 image_source:
225
 	.long	0
247
 	.long	0
226
 	.size	image_source, . - image_source
248
 	.size	image_source, . - image_source
249
+
227
 /* Temporary decompression area
250
 /* Temporary decompression area
228
  *
251
  *
229
  * May be either at HIGHMEM_LOADPOINT, or within PMM-allocated block.
252
  * May be either at HIGHMEM_LOADPOINT, or within PMM-allocated block.
232
 	.long	HIGHMEM_LOADPOINT
255
 	.long	HIGHMEM_LOADPOINT
233
 	.size	decompress_to, . - decompress_to
256
 	.size	decompress_to, . - decompress_to
234
 
257
 
258
+/* BBS version
259
+ *
260
+ * Filled in by BBS BIOS.  We ignore the value.
261
+ */
262
+bbs_version:
263
+	.word	0
264
+
235
 /* Boot Execution Vector entry point
265
 /* Boot Execution Vector entry point
236
  *
266
  *
237
  * Called by the PnP BIOS when it wants to boot us.
267
  * Called by the PnP BIOS when it wants to boot us.

Loading…
Cancel
Save