|
@@ -1,22 +1,24 @@
|
1
|
|
-#define PXENV_UNDI_SHUTDOWN 0x05
|
2
|
|
-#define PXENV_STOP_UNDI 0x15
|
3
|
|
-#define PXENV_UNLOAD_STACK 0x70
|
|
1
|
+#define PXENV_UNDI_SHUTDOWN 0x0005
|
|
2
|
+#define PXENV_UNDI_GET_NIC_TYPE 0x0012
|
|
3
|
+#define PXENV_STOP_UNDI 0x0015
|
|
4
|
+#define PXENV_UNLOAD_STACK 0x0070
|
4
|
5
|
|
5
|
6
|
#define PXE_STACK_MAGIC 0x57ac /* 'STac' */
|
6
|
7
|
|
7
|
8
|
.text
|
8
|
|
- .code16
|
9
|
9
|
.arch i386
|
10
|
10
|
.org 0
|
11
|
11
|
.section ".prefix", "ax", @progbits
|
|
12
|
+ .section ".prefix.data", "aw", @progbits
|
|
13
|
+ .code16
|
|
14
|
+
|
12
|
15
|
/*****************************************************************************
|
13
|
|
- * Entry point: set cs, ds, bp, print welcome message
|
|
16
|
+ * Entry point: set operating context, print welcome message
|
14
|
17
|
*****************************************************************************
|
15
|
|
- */
|
16
|
|
- jmp $0x7c0, $code_start
|
17
|
|
-10: .asciz "PXE->EB "
|
18
|
|
-code_start:
|
19
|
|
- /* Preserve registers for return to PXE stack */
|
|
18
|
+ */
|
|
19
|
+ .section ".prefix"
|
|
20
|
+ jmp $0x7c0, $1f
|
|
21
|
+1: /* Preserve registers for return to PXE stack */
|
20
|
22
|
pushfl
|
21
|
23
|
pushal
|
22
|
24
|
pushw %gs
|
|
@@ -28,92 +30,110 @@ code_start:
|
28
|
30
|
pushw $PXE_STACK_MAGIC /* PXE stack magic marker */
|
29
|
31
|
/* Set up stack just below 0x7c00 */
|
30
|
32
|
pushw %ss
|
31
|
|
- popw %es
|
32
|
|
- movw %sp, %di
|
|
33
|
+ popw %gs
|
|
34
|
+ movw %sp, %bp /* %gs:%bp points to old PXE stack */
|
33
|
35
|
xorw %ax, %ax
|
34
|
36
|
movw %ax, %ss
|
35
|
37
|
movw $0x7c00, %sp
|
36
|
|
- pushw %es /* Save old PXE stack pointer */
|
37
|
|
- pushw %di
|
|
38
|
+ pushw %gs /* Save old PXE stack pointer */
|
|
39
|
+ pushw %bp
|
38
|
40
|
/* Set up our other segment registers */
|
39
|
41
|
pushw %cs
|
40
|
42
|
popw %ds
|
41
|
43
|
movw $0x40, %ax /* BIOS data segment access */
|
42
|
44
|
movw %ax, %fs
|
|
45
|
+ /* Clear direction flag, for the sake of sanity */
|
|
46
|
+ cld
|
43
|
47
|
/* Print welcome message */
|
44
|
|
- movw $10b, %si
|
|
48
|
+ movw $10f, %si
|
45
|
49
|
call print_message
|
|
50
|
+ .section ".prefix.data"
|
|
51
|
+10: .asciz "PXE->EB:"
|
|
52
|
+ .previous
|
46
|
53
|
|
47
|
54
|
/*****************************************************************************
|
48
|
|
- * Detect type of PXE available (!PXE, PXENV+ or none)
|
|
55
|
+ * Verify PXENV+ structure and record parameters of interest
|
49
|
56
|
*****************************************************************************
|
50
|
57
|
*/
|
51
|
|
-detect_pxe:
|
52
|
|
- les %es:54(%di), %di /* !PXE structure */
|
53
|
|
- cmpl $0x45585021, %es:(%di) /* '!PXE' signature */
|
54
|
|
- je detected_pxe
|
55
|
|
- movw $0x5650, %ax
|
56
|
|
- int $0x1a
|
57
|
|
- cmpw $0x564e, %ax
|
58
|
|
- jne detected_nothing
|
|
58
|
+detect_pxenv:
|
|
59
|
+ /* Signature check */
|
59
|
60
|
cmpl $0x4e455850, %es:(%bx) /* 'PXEN' signature */
|
60
|
|
- jne detected_nothing
|
|
61
|
+ jne 99f
|
61
|
62
|
cmpw $0x2b56, %es:4(%bx) /* 'V+' signature */
|
62
|
|
- je detected_pxenv
|
63
|
|
-
|
64
|
|
-detected_nothing:
|
65
|
|
- movw $10f, %si
|
66
|
|
- call print_message
|
67
|
|
- jmp finished_with_error
|
68
|
|
-10: .asciz "No PXE "
|
69
|
|
-
|
70
|
|
-detected_pxenv: /* es:bx points to PXENV+ structure */
|
|
63
|
+ jne 99f
|
|
64
|
+ /* Record structure address, entry point, and UNDI segments */
|
71
|
65
|
pushw %es
|
72
|
|
- pushw %bx
|
|
66
|
+ popw pxenv_segment
|
|
67
|
+ movw %bx, pxenv_offset
|
|
68
|
+ pushl %es:0x0a(%bx) /* Entry point */
|
|
69
|
+ popl entry_segoff
|
73
|
70
|
pushw %es:0x24(%bx) /* UNDI code segment */
|
74
|
71
|
pushw %es:0x26(%bx) /* UNDI code size */
|
|
72
|
+ popl undi_code_segoff
|
75
|
73
|
pushw %es:0x20(%bx) /* UNDI data segment */
|
76
|
74
|
pushw %es:0x22(%bx) /* UNDI data size */
|
77
|
|
- les %es:0x0a(%bx), %di /* Entry point to %es:%di */
|
|
75
|
+ popl undi_data_segoff
|
|
76
|
+ /* Print "PXENV+ at <address>" */
|
78
|
77
|
movw $10f, %si
|
79
|
|
- jmp pxe_setup_done
|
80
|
|
-10: .asciz "PXENV+ "
|
81
|
|
-
|
82
|
|
-detected_pxe: /* es:di points to !PXE structure */
|
|
78
|
+ call print_message
|
|
79
|
+ movw %bx, %di
|
|
80
|
+ call print_segoff
|
|
81
|
+ movb $',', %al
|
|
82
|
+ call print_character
|
|
83
|
+ .section ".prefix.data"
|
|
84
|
+10: .asciz " PXENV+ at "
|
|
85
|
+ .previous
|
|
86
|
+99:
|
|
87
|
+
|
|
88
|
+/*****************************************************************************
|
|
89
|
+ * Verify !PXE structure and record parameters of interest
|
|
90
|
+ *****************************************************************************
|
|
91
|
+ */
|
|
92
|
+detect_ppxe:
|
|
93
|
+ /* Signature check */
|
|
94
|
+ les %gs:54(%bp), %di /* !PXE structure */
|
|
95
|
+ cmpl $0x45585021, %es:(%di) /* '!PXE' signature */
|
|
96
|
+ jne 99f
|
|
97
|
+ /* Record structure address, entry point, and UNDI segments */
|
83
|
98
|
pushw %es
|
84
|
|
- pushw %di
|
|
99
|
+ popw ppxe_segment
|
|
100
|
+ movw %di, ppxe_offset
|
|
101
|
+ pushl %es:0x10(%di) /* Entry point */
|
|
102
|
+ popl entry_segoff
|
85
|
103
|
pushw %es:0x30(%di) /* UNDI code segment */
|
86
|
104
|
pushw %es:0x36(%di) /* UNDI code size */
|
|
105
|
+ popl undi_code_segoff
|
87
|
106
|
pushw %es:0x28(%di) /* UNDI data segment */
|
88
|
107
|
pushw %es:0x2e(%di) /* UNDI data size */
|
89
|
|
- les %es:0x10(%di), %di /* Entry point to %es:%di */
|
|
108
|
+ popl undi_data_segoff
|
|
109
|
+ /* Print "!PXE at <address>" */
|
90
|
110
|
movw $10f, %si
|
91
|
|
- jmp pxe_setup_done
|
92
|
|
-10: .asciz "!PXE "
|
93
|
|
-
|
94
|
|
-pxe_setup_done:
|
95
|
|
- movw %es, pxe_entry_segment
|
96
|
|
- movw %di, pxe_entry_offset
|
97
|
|
- popw undi_data_size
|
98
|
|
- popw undi_data_segment
|
99
|
|
- popw undi_code_size
|
100
|
|
- popw undi_code_segment
|
101
|
111
|
call print_message
|
102
|
|
- popw %di
|
103
|
|
- popw %es /* Exit with %es:%di containing structure address */
|
|
112
|
+ call print_segoff
|
|
113
|
+ movb $',', %al
|
|
114
|
+ call print_character
|
|
115
|
+ .section ".prefix.data"
|
|
116
|
+10: .asciz " !PXE at "
|
|
117
|
+ .previous
|
|
118
|
+99:
|
104
|
119
|
|
105
|
120
|
/*****************************************************************************
|
106
|
|
- * Print information about located structure
|
|
121
|
+ * Sanity check: we must have an entry point
|
107
|
122
|
*****************************************************************************
|
108
|
123
|
*/
|
109
|
|
-print_structure_information:
|
110
|
|
- call print_segoff /* %es:%di contains address of structure */
|
111
|
|
- les pxe_entry_segoff, %di
|
112
|
|
- call print_segoff
|
113
|
|
- les undi_code_segoff, %di
|
114
|
|
- call print_segoff
|
115
|
|
- les undi_data_segoff, %di
|
116
|
|
- call print_segoff
|
|
124
|
+check_have_stack:
|
|
125
|
+ /* Check for entry point */
|
|
126
|
+ movl entry_segoff, %eax
|
|
127
|
+ testl %eax, %eax
|
|
128
|
+ jnz 99f
|
|
129
|
+ /* No entry point: print message and skip everything else */
|
|
130
|
+ movw $10f, %si
|
|
131
|
+ call print_message
|
|
132
|
+ jmp finished
|
|
133
|
+ .section ".prefix.data"
|
|
134
|
+10: .asciz " No PXE stack found!\n"
|
|
135
|
+ .previous
|
|
136
|
+99:
|
117
|
137
|
|
118
|
138
|
/*****************************************************************************
|
119
|
139
|
* Calculate base memory usage by UNDI
|
|
@@ -138,66 +158,178 @@ find_undi_basemem_usage:
|
138
|
158
|
shrw $6, %cx
|
139
|
159
|
movw %cx, undi_fbms_end
|
140
|
160
|
|
|
161
|
+/*****************************************************************************
|
|
162
|
+ * Print information about detected PXE stack
|
|
163
|
+ *****************************************************************************
|
|
164
|
+ */
|
|
165
|
+print_structure_information:
|
|
166
|
+ /* Print entry point */
|
|
167
|
+ movw $10f, %si
|
|
168
|
+ call print_message
|
|
169
|
+ les entry_segoff, %di
|
|
170
|
+ call print_segoff
|
|
171
|
+ .section ".prefix.data"
|
|
172
|
+10: .asciz " entry point at "
|
|
173
|
+ .previous
|
|
174
|
+ /* Print UNDI code segment */
|
|
175
|
+ movw $10f, %si
|
|
176
|
+ call print_message
|
|
177
|
+ les undi_code_segoff, %di
|
|
178
|
+ call print_segoff
|
|
179
|
+ .section ".prefix.data"
|
|
180
|
+10: .asciz "\n UNDI code segment "
|
|
181
|
+ .previous
|
|
182
|
+ /* Print UNDI data segment */
|
|
183
|
+ movw $10f, %si
|
|
184
|
+ call print_message
|
|
185
|
+ les undi_data_segoff, %di
|
|
186
|
+ call print_segoff
|
|
187
|
+ .section ".prefix.data"
|
|
188
|
+10: .asciz ", data segment "
|
|
189
|
+ .previous
|
|
190
|
+ /* Print UNDI memory usage */
|
|
191
|
+ movw $10f, %si
|
|
192
|
+ call print_message
|
|
193
|
+ movw undi_fbms_start, %ax
|
|
194
|
+ call print_word
|
|
195
|
+ movb $'-', %al
|
|
196
|
+ call print_character
|
|
197
|
+ movw undi_fbms_end, %ax
|
|
198
|
+ call print_word
|
|
199
|
+ movw $20f, %si
|
|
200
|
+ call print_message
|
|
201
|
+ .section ".prefix.data"
|
|
202
|
+10: .asciz " ("
|
|
203
|
+20: .asciz "kB)\n"
|
|
204
|
+ .previous
|
|
205
|
+
|
|
206
|
+/*****************************************************************************
|
|
207
|
+ * Determine physical device
|
|
208
|
+ *****************************************************************************
|
|
209
|
+ */
|
|
210
|
+get_physical_device:
|
|
211
|
+ /* Issue PXENV_UNDI_GET_NIC_TYPE */
|
|
212
|
+ movw $PXENV_UNDI_GET_NIC_TYPE, %bx
|
|
213
|
+ call pxe_call
|
|
214
|
+ jnc 1f
|
|
215
|
+ call print_pxe_error
|
|
216
|
+ jmp no_physical_device
|
|
217
|
+1: /* Determine physical device type */
|
|
218
|
+ movb ( pxe_parameter_structure + 0x02 ), %al
|
|
219
|
+ cmpb $2, %al
|
|
220
|
+ je pci_physical_device
|
|
221
|
+ jmp no_physical_device
|
|
222
|
+
|
|
223
|
+pci_physical_device:
|
|
224
|
+ /* Record PCI bus:dev.fn */
|
|
225
|
+ movw ( pxe_parameter_structure + 0x0b ), %ax
|
|
226
|
+ movw %ax, pci_busdevfn
|
|
227
|
+ movw $10f, %si
|
|
228
|
+ call print_message
|
|
229
|
+ call print_pci_busdevfn
|
|
230
|
+ movb $0x0a, %al
|
|
231
|
+ call print_character
|
|
232
|
+ jmp 99f
|
|
233
|
+ .section ".prefix.data"
|
|
234
|
+10: .asciz " UNDI device is PCI "
|
|
235
|
+ .previous
|
|
236
|
+
|
|
237
|
+no_physical_device:
|
|
238
|
+ /* No device found, or device type not understood */
|
|
239
|
+ movw $10f, %si
|
|
240
|
+ call print_message
|
|
241
|
+ .section ".prefix.data"
|
|
242
|
+10: .asciz " Unable to determine UNDI physical device\n"
|
|
243
|
+ .previous
|
|
244
|
+
|
|
245
|
+99:
|
|
246
|
+
|
141
|
247
|
/*****************************************************************************
|
142
|
248
|
* Leave NIC in a safe state
|
143
|
249
|
*****************************************************************************
|
144
|
250
|
*/
|
145
|
251
|
shutdown_nic:
|
|
252
|
+ /* Issue PXENV_UNDI_SHUTDOWN */
|
146
|
253
|
movw $PXENV_UNDI_SHUTDOWN, %bx
|
147
|
254
|
call pxe_call
|
|
255
|
+ jnc 1f
|
|
256
|
+ call print_pxe_error
|
|
257
|
+1:
|
148
|
258
|
|
149
|
259
|
/*****************************************************************************
|
150
|
260
|
* Unload PXE base code
|
151
|
261
|
*****************************************************************************
|
152
|
262
|
*/
|
153
|
263
|
unload_base_code:
|
|
264
|
+ /* Issue PXENV_UNLOAD_STACK */
|
154
|
265
|
movw $PXENV_UNLOAD_STACK, %bx
|
155
|
266
|
call pxe_call
|
156
|
|
- jnz do_not_free_base_code
|
157
|
|
-free_base_code:
|
|
267
|
+ jnc 1f
|
|
268
|
+ call print_pxe_error
|
|
269
|
+ jmp 99f
|
|
270
|
+1: /* Free base memory used by PXE base code */
|
158
|
271
|
movw %fs:(0x13), %si
|
159
|
272
|
movw undi_fbms_start, %di
|
160
|
273
|
call free_basemem
|
161
|
|
-do_not_free_base_code:
|
|
274
|
+99:
|
162
|
275
|
|
163
|
276
|
/*****************************************************************************
|
164
|
277
|
* Unload UNDI driver
|
165
|
278
|
*****************************************************************************
|
166
|
279
|
*/
|
167
|
280
|
unload_undi:
|
|
281
|
+ /* Issue PXENV_STOP_UNDI */
|
168
|
282
|
movw $PXENV_STOP_UNDI, %bx
|
169
|
283
|
call pxe_call
|
|
284
|
+ jnc 1f
|
|
285
|
+ call print_pxe_error
|
|
286
|
+ jmp 99f
|
|
287
|
+1: /* Free base memory used by UNDI */
|
170
|
288
|
#ifndef PXELOADER_KEEP_UNDI
|
171
|
|
- jnz do_not_free_undi
|
172
|
|
-free_undi:
|
173
|
289
|
movw undi_fbms_start, %si
|
174
|
290
|
movw undi_fbms_end, %di
|
175
|
291
|
call free_basemem
|
176
|
|
-do_not_free_undi:
|
177
|
292
|
#endif /* PXELOADER_KEEP_UNDI */
|
|
293
|
+99:
|
178
|
294
|
|
179
|
295
|
/*****************************************************************************
|
180
|
|
- * Exit point
|
|
296
|
+ * Print remaining free base memory
|
181
|
297
|
*****************************************************************************
|
182
|
|
- */
|
183
|
|
-finished:
|
|
298
|
+ */
|
|
299
|
+print_free_basemem:
|
184
|
300
|
movw $10f, %si
|
185
|
|
- movw pxe_overall_status, %ax
|
186
|
|
- testw %ax, %ax
|
187
|
|
- jz 1f
|
188
|
|
-finished_with_error:
|
|
301
|
+ call print_message
|
|
302
|
+ movw %fs:(0x13), %ax
|
|
303
|
+ call print_word
|
189
|
304
|
movw $20f, %si
|
190
|
|
-1:
|
191
|
305
|
call print_message
|
|
306
|
+ .section ".prefix.data"
|
|
307
|
+10: .asciz " "
|
|
308
|
+20: .asciz "kB free base memory after PXE unload\n"
|
|
309
|
+ .previous
|
|
310
|
+
|
|
311
|
+/*****************************************************************************
|
|
312
|
+ * Exit point
|
|
313
|
+ *****************************************************************************
|
|
314
|
+ */
|
|
315
|
+finished:
|
192
|
316
|
jmp run_etherboot
|
193
|
|
-10: .asciz "ok\n"
|
194
|
|
-20: .asciz "err\n"
|
195
|
317
|
|
196
|
318
|
/*****************************************************************************
|
197
|
|
- * Subroutine: print character in %al (with LF -> LF,CR translation)
|
|
319
|
+ * Subroutine: print character (with LF -> LF,CR translation)
|
|
320
|
+ *
|
|
321
|
+ * Parameters:
|
|
322
|
+ * %al : character to print
|
|
323
|
+ * Returns:
|
|
324
|
+ * Nothing
|
198
|
325
|
*****************************************************************************
|
199
|
326
|
*/
|
200
|
327
|
print_character:
|
|
328
|
+ /* Preserve registers */
|
|
329
|
+ pushw %ax
|
|
330
|
+ pushw %bx
|
|
331
|
+ pushw %bp
|
|
332
|
+ /* Print character */
|
201
|
333
|
movw $0x0007, %bx /* page 0, attribute 7 (normal) */
|
202
|
334
|
movb $0x0e, %ah /* write char, tty mode */
|
203
|
335
|
cmpb $0x0a, %al /* '\n'? */
|
|
@@ -205,122 +337,318 @@ print_character:
|
205
|
337
|
int $0x10
|
206
|
338
|
movb $0x0d, %al
|
207
|
339
|
1: int $0x10
|
|
340
|
+ /* Restore registers and return */
|
|
341
|
+ popw %bp
|
|
342
|
+ popw %bx
|
|
343
|
+ popw %ax
|
208
|
344
|
ret
|
209
|
345
|
|
210
|
346
|
/*****************************************************************************
|
211
|
|
- * Subroutine: print a zero-terminated message starting at %si
|
|
347
|
+ * Subroutine: print a NUL-terminated string
|
|
348
|
+ *
|
|
349
|
+ * Parameters:
|
|
350
|
+ * %ds:%si : string to print
|
|
351
|
+ * Returns:
|
|
352
|
+ * Nothing
|
212
|
353
|
*****************************************************************************
|
213
|
354
|
*/
|
214
|
355
|
print_message:
|
|
356
|
+ /* Preserve registers */
|
|
357
|
+ pushw %ax
|
|
358
|
+ pushw %si
|
|
359
|
+ /* Print string */
|
215
|
360
|
1: lodsb
|
216
|
361
|
testb %al, %al
|
217
|
362
|
je 2f
|
218
|
363
|
call print_character
|
219
|
364
|
jmp 1b
|
220
|
|
-2: ret
|
|
365
|
+2: /* Restore registers and return */
|
|
366
|
+ popw %si
|
|
367
|
+ popw %ax
|
|
368
|
+ ret
|
221
|
369
|
|
222
|
370
|
/*****************************************************************************
|
223
|
|
- * Subroutine: print hex word in %ax
|
|
371
|
+ * Subroutine: print hex digit
|
|
372
|
+ *
|
|
373
|
+ * Parameters:
|
|
374
|
+ * %al (low nibble) : digit to print
|
|
375
|
+ * Returns:
|
|
376
|
+ * Nothing
|
224
|
377
|
*****************************************************************************
|
225
|
378
|
*/
|
226
|
|
-print_hex_word:
|
227
|
|
- movw $4, %cx
|
228
|
|
-1:
|
|
379
|
+print_hex_nibble:
|
|
380
|
+ /* Preserve registers */
|
229
|
381
|
pushw %ax
|
230
|
|
- shrw $12, %ax
|
231
|
|
- /* Courtesy of Norbert Juffa <norbert.juffa@amd.com> */
|
232
|
|
- cmpb $10, %al
|
|
382
|
+ /* Print digit (technique by Norbert Juffa <norbert.juffa@amd.com> */
|
|
383
|
+ andb $0x0f, %al
|
|
384
|
+ cmpb $10, %al
|
233
|
385
|
sbbb $0x69, %al
|
234
|
386
|
das
|
235
|
387
|
call print_character
|
|
388
|
+ /* Restore registers and return */
|
236
|
389
|
popw %ax
|
237
|
|
- shlw $4, %ax
|
238
|
|
- loop 1b
|
|
390
|
+ ret
|
|
391
|
+
|
|
392
|
+/*****************************************************************************
|
|
393
|
+ * Subroutine: print hex byte
|
|
394
|
+ *
|
|
395
|
+ * Parameters:
|
|
396
|
+ * %al : byte to print
|
|
397
|
+ * Returns:
|
|
398
|
+ * Nothing
|
|
399
|
+ *****************************************************************************
|
|
400
|
+ */
|
|
401
|
+print_hex_byte:
|
|
402
|
+ rorb $4, %al
|
|
403
|
+ call print_hex_nibble
|
|
404
|
+ rorb $4, %al
|
|
405
|
+ call print_hex_nibble
|
239
|
406
|
ret
|
240
|
|
-
|
|
407
|
+
|
241
|
408
|
/*****************************************************************************
|
242
|
|
- * Subroutine: print segment:offset address in %es:%di
|
|
409
|
+ * Subroutine: print hex word
|
|
410
|
+ *
|
|
411
|
+ * Parameters:
|
|
412
|
+ * %ax : word to print
|
|
413
|
+ * Returns:
|
|
414
|
+ * Nothing
|
|
415
|
+ *****************************************************************************
|
|
416
|
+ */
|
|
417
|
+print_hex_word:
|
|
418
|
+ xchgb %al, %ah
|
|
419
|
+ call print_hex_byte
|
|
420
|
+ xchgb %al, %ah
|
|
421
|
+ call print_hex_byte
|
|
422
|
+ ret
|
|
423
|
+
|
|
424
|
+/*****************************************************************************
|
|
425
|
+ * Subroutine: print segment:offset address
|
|
426
|
+ *
|
|
427
|
+ * Parameters:
|
|
428
|
+ * %es:%di : segment:offset address to print
|
|
429
|
+ * Returns:
|
|
430
|
+ * Nothing
|
243
|
431
|
*****************************************************************************
|
244
|
432
|
*/
|
245
|
433
|
print_segoff:
|
246
|
|
- pushw %di
|
247
|
|
- pushw %es
|
248
|
|
- popw %ax
|
|
434
|
+ /* Preserve registers */
|
|
435
|
+ pushw %ax
|
|
436
|
+ /* Print "<segment>:offset" */
|
|
437
|
+ movw %es, %ax
|
249
|
438
|
call print_hex_word
|
250
|
|
- movb $0x3a,%al /* ':' */
|
|
439
|
+ movb $':', %al
|
251
|
440
|
call print_character
|
252
|
|
- popw %ax
|
|
441
|
+ movw %di, %ax
|
253
|
442
|
call print_hex_word
|
254
|
|
- movb $0x20, %al /* ' ' */
|
255
|
|
- call print_character
|
|
443
|
+ /* Restore registers and return */
|
|
444
|
+ popw %ax
|
256
|
445
|
ret
|
257
|
446
|
|
258
|
447
|
/*****************************************************************************
|
259
|
|
- * Subroutine: free and zero base memory from %si kB to %di kB
|
|
448
|
+ * Subroutine: print decimal word
|
|
449
|
+ *
|
|
450
|
+ * Parameters:
|
|
451
|
+ * %ax : word to print
|
|
452
|
+ * Returns:
|
|
453
|
+ * Nothing
|
|
454
|
+ *****************************************************************************
|
|
455
|
+ */
|
|
456
|
+print_word:
|
|
457
|
+ /* Preserve registers */
|
|
458
|
+ pushw %ax
|
|
459
|
+ pushw %bx
|
|
460
|
+ pushw %cx
|
|
461
|
+ pushw %dx
|
|
462
|
+ /* Build up digit sequence on stack */
|
|
463
|
+ movw $10, %bx
|
|
464
|
+ xorw %cx, %cx
|
|
465
|
+1: xorw %dx, %dx
|
|
466
|
+ divw %bx, %ax
|
|
467
|
+ pushw %dx
|
|
468
|
+ incw %cx
|
|
469
|
+ testw %ax, %ax
|
|
470
|
+ jnz 1b
|
|
471
|
+ /* Print digit sequence */
|
|
472
|
+1: popw %ax
|
|
473
|
+ call print_hex_nibble
|
|
474
|
+ loop 1b
|
|
475
|
+ /* Restore registers and return */
|
|
476
|
+ popw %dx
|
|
477
|
+ popw %cx
|
|
478
|
+ popw %bx
|
|
479
|
+ popw %ax
|
|
480
|
+ ret
|
|
481
|
+
|
|
482
|
+/*****************************************************************************
|
|
483
|
+ * Subroutine: print PCI bus:dev.fn
|
|
484
|
+ *
|
|
485
|
+ * Parameters:
|
|
486
|
+ * %ax : PCI bus:dev.fn to print
|
|
487
|
+ * Returns:
|
|
488
|
+ * Nothing
|
|
489
|
+ *****************************************************************************
|
|
490
|
+ */
|
|
491
|
+print_pci_busdevfn:
|
|
492
|
+ /* Preserve registers */
|
|
493
|
+ pushw %ax
|
|
494
|
+ /* Print bus */
|
|
495
|
+ xchgb %al, %ah
|
|
496
|
+ call print_hex_byte
|
|
497
|
+ /* Print ":" */
|
|
498
|
+ movb $':', %al
|
|
499
|
+ call print_character
|
|
500
|
+ /* Print device */
|
|
501
|
+ movb %ah, %al
|
|
502
|
+ shrb $3, %al
|
|
503
|
+ call print_hex_byte
|
|
504
|
+ /* Print "." */
|
|
505
|
+ movb $'.', %al
|
|
506
|
+ call print_character
|
|
507
|
+ /* Print function */
|
|
508
|
+ movb %ah, %al
|
|
509
|
+ andb $0x07, %al
|
|
510
|
+ call print_hex_nibble
|
|
511
|
+ /* Restore registers and return */
|
|
512
|
+ popw %ax
|
|
513
|
+ ret
|
|
514
|
+
|
|
515
|
+/*****************************************************************************
|
|
516
|
+ * Subroutine: zero 1kB block of base memory
|
|
517
|
+ *
|
|
518
|
+ * Parameters:
|
|
519
|
+ * %si : block to zero (in kB)
|
|
520
|
+ * Returns:
|
|
521
|
+ * Nothing
|
260
|
522
|
*****************************************************************************
|
261
|
523
|
*/
|
262
|
|
-free_basemem:
|
263
|
|
- movw %fs:(0x13), %ax /* Current FBMS to %ax */
|
264
|
|
- cmpw %ax, %si /* Update FBMS only if "old" value */
|
265
|
|
- jne 1f /* is correct */
|
266
|
|
- movw %di, %fs:(0x13)
|
267
|
|
-1: movw %di, %bx
|
268
|
524
|
zero_kb:
|
269
|
|
- movw %si, %ax /* Zero kB at %si */
|
|
525
|
+ /* Preserve registers */
|
|
526
|
+ pushw %ax
|
|
527
|
+ pushw %cx
|
|
528
|
+ pushw %di
|
|
529
|
+ pushw %es
|
|
530
|
+ /* Zero block */
|
|
531
|
+ movw %si, %ax
|
270
|
532
|
shlw $6, %ax
|
271
|
533
|
movw %ax, %es
|
272
|
|
- xorw %ax, %ax
|
273
|
|
- xorw %di, %di
|
274
|
534
|
movw $0x400, %cx
|
|
535
|
+ xorw %di, %di
|
|
536
|
+ xorw %ax, %ax
|
275
|
537
|
rep stosb
|
276
|
|
- incw %si /* Move to next kB */
|
277
|
|
- cmpw %si, %bx
|
278
|
|
- jne zero_kb /* Loop until done */
|
279
|
|
- movw %fs:(0x13), %ax /* Print free base memory */
|
280
|
|
- call print_hex_word
|
281
|
|
- movb $0x20, %al /* ' ' */
|
282
|
|
- call print_character
|
|
538
|
+ /* Restore registers and return */
|
|
539
|
+ popw %es
|
|
540
|
+ popw %di
|
|
541
|
+ popw %cx
|
|
542
|
+ popw %ax
|
|
543
|
+ ret
|
|
544
|
+
|
|
545
|
+/*****************************************************************************
|
|
546
|
+ * Subroutine: free and zero base memory
|
|
547
|
+ *
|
|
548
|
+ * Parameters:
|
|
549
|
+ * %si : Expected current free base memory counter (in kB)
|
|
550
|
+ * %di : Desired new free base memory counter (in kB)
|
|
551
|
+ * %fs : BIOS data segment (0x40)
|
|
552
|
+ * Returns:
|
|
553
|
+ * %ax : Actual new free base memory counter (in kB)
|
|
554
|
+ *
|
|
555
|
+ * The base memory from %si kB to %di kB is unconditionally zeroed.
|
|
556
|
+ * It will be freed if and only if the expected current free base
|
|
557
|
+ * memory counter (%si) matches the actual current free base memory
|
|
558
|
+ * counter in 0x40:0x13; if this does not match then the memory will
|
|
559
|
+ * be leaked.
|
|
560
|
+ *****************************************************************************
|
|
561
|
+ */
|
|
562
|
+free_basemem:
|
|
563
|
+ /* Zero base memory */
|
|
564
|
+ pushw %si
|
|
565
|
+1: cmpw %si, %di
|
|
566
|
+ je 2f
|
|
567
|
+ call zero_kb
|
|
568
|
+ incw %si
|
|
569
|
+ jmp 1b
|
|
570
|
+2: popw %si
|
|
571
|
+ /* Free base memory */
|
|
572
|
+ movw %fs:(0x13), %ax /* Current FBMS to %ax */
|
|
573
|
+ cmpw %ax, %si /* Update FBMS only if "old" value */
|
|
574
|
+ jne 1f /* is correct */
|
|
575
|
+ movw %di, %ax
|
|
576
|
+1: movw %ax, %fs:(0x13)
|
283
|
577
|
ret
|
284
|
578
|
|
285
|
579
|
/*****************************************************************************
|
286
|
|
- * Make a PXE API call. Works with either !PXE or PXENV+ API.
|
287
|
|
- * Opcode in %bx. pxe_parameter_structure always used.
|
|
580
|
+ * Subroutine: make a PXE API call. Works with either !PXE or PXENV+ API.
|
288
|
581
|
*
|
289
|
|
- * Returns status code (not exit code) in %bx and prints it. Returns
|
290
|
|
- * with zero flag set if status code is zero (PXENV_STATUS_SUCCESS).
|
|
582
|
+ * Parameters:
|
|
583
|
+ * %bx : PXE API call number
|
|
584
|
+ * %ds:pxe_parameter_structure : Parameters for PXE API call
|
|
585
|
+ * Returns:
|
|
586
|
+ * %ax : PXE status code (not exit code)
|
|
587
|
+ * CF set if %ax is non-zero
|
291
|
588
|
*****************************************************************************
|
292
|
589
|
*/
|
293
|
590
|
pxe_call:
|
|
591
|
+ /* Preserve registers */
|
|
592
|
+ pushw %di
|
|
593
|
+ pushw %es
|
294
|
594
|
/* Set up registers for PXENV+ API. %bx already set up */
|
295
|
595
|
pushw %ds
|
296
|
596
|
popw %es
|
297
|
597
|
movw $pxe_parameter_structure, %di
|
298
|
598
|
/* Set up stack for !PXE API */
|
299
|
|
- pushw %cs
|
|
599
|
+ pushw %es
|
300
|
600
|
pushw %di
|
301
|
601
|
pushw %bx
|
302
|
602
|
/* Make the API call */
|
303
|
|
- lcall *pxe_entry_segoff
|
|
603
|
+ lcall *entry_segoff
|
304
|
604
|
/* Reset the stack */
|
305
|
605
|
addw $6, %sp
|
306
|
606
|
movw pxe_parameter_structure, %ax
|
307
|
|
- pushw %ax
|
|
607
|
+ clc
|
|
608
|
+ testw %ax, %ax
|
|
609
|
+ jz 1f
|
|
610
|
+ stc
|
|
611
|
+1: /* Restore registers and return */
|
|
612
|
+ popw %es
|
|
613
|
+ popw %di
|
|
614
|
+ ret
|
|
615
|
+
|
|
616
|
+/*****************************************************************************
|
|
617
|
+ * Subroutine: print PXE API call error message
|
|
618
|
+ *
|
|
619
|
+ * Parameters:
|
|
620
|
+ * %ax : PXE status code
|
|
621
|
+ * %bx : PXE API call number
|
|
622
|
+ * Returns:
|
|
623
|
+ * Nothing
|
|
624
|
+ *****************************************************************************
|
|
625
|
+ */
|
|
626
|
+print_pxe_error:
|
|
627
|
+ pushw %si
|
|
628
|
+ movw $10f, %si
|
|
629
|
+ call print_message
|
|
630
|
+ xchgw %ax, %bx
|
308
|
631
|
call print_hex_word
|
309
|
|
- movw $0x20, %ax /* ' ' */
|
310
|
|
- call print_character
|
311
|
|
- popw %bx
|
312
|
|
- orw %bx, pxe_overall_status
|
313
|
|
- testw %bx, %bx
|
|
632
|
+ movw $20f, %si
|
|
633
|
+ call print_message
|
|
634
|
+ xchgw %ax, %bx
|
|
635
|
+ call print_hex_word
|
|
636
|
+ movw $30f, %si
|
|
637
|
+ call print_message
|
|
638
|
+ popw %si
|
314
|
639
|
ret
|
|
640
|
+ .section ".prefix.data"
|
|
641
|
+10: .asciz " UNDI API call "
|
|
642
|
+20: .asciz " failed: status code "
|
|
643
|
+30: .asciz "\n"
|
|
644
|
+ .previous
|
315
|
645
|
|
316
|
646
|
/*****************************************************************************
|
317
|
647
|
* PXE data structures
|
318
|
648
|
*****************************************************************************
|
319
|
649
|
*/
|
320
|
650
|
|
321
|
|
-pxe_entry_segoff:
|
322
|
|
-pxe_entry_offset: .word 0
|
323
|
|
-pxe_entry_segment: .word 0
|
|
651
|
+pxe_parameter_structure: .fill 20
|
324
|
652
|
|
325
|
653
|
undi_code_segoff:
|
326
|
654
|
undi_code_size: .word 0
|
|
@@ -330,14 +658,30 @@ undi_data_segoff:
|
330
|
658
|
undi_data_size: .word 0
|
331
|
659
|
undi_data_segment: .word 0
|
332
|
660
|
|
|
661
|
+/* The following fields are part of a struct undi_device */
|
|
662
|
+
|
|
663
|
+undi_device:
|
|
664
|
+
|
|
665
|
+pxenv_segoff:
|
|
666
|
+pxenv_offset: .word 0
|
|
667
|
+pxenv_segment: .word 0
|
|
668
|
+
|
|
669
|
+ppxe_segoff:
|
|
670
|
+ppxe_offset: .word 0
|
|
671
|
+ppxe_segment: .word 0
|
|
672
|
+
|
|
673
|
+entry_segoff:
|
|
674
|
+entry_offset: .word 0
|
|
675
|
+entry_segment: .word 0
|
|
676
|
+
|
333
|
677
|
undi_fbms_start: .word 0
|
334
|
678
|
undi_fbms_end: .word 0
|
335
|
679
|
|
336
|
|
-pxe_parameter_structure:
|
337
|
|
- .word 0
|
338
|
|
- .word 0,0,0,0,0
|
|
680
|
+pci_busdevfn: .word 0xffff
|
|
681
|
+isapnp_csn: .word 0xffff
|
|
682
|
+isapnp_read_port: .word 0xffff
|
339
|
683
|
|
340
|
|
-pxe_overall_status: .word 0
|
|
684
|
+ .equ undi_device_size, ( . - undi_device )
|
341
|
685
|
|
342
|
686
|
/*****************************************************************************
|
343
|
687
|
* Run Etherboot main code
|