1 /* At entry, the processor is in 16 bit real mode and the code is being
2 * executed from an address it was not linked to. Code must be pic and
3 * 32 bit sensitive until things are fixed up.
5 * Also be very careful as the stack is at the rear end of the interrupt
6 * table so using a noticeable amount of stack space is a no-no.
9 /* Define DELAYED_INT when NO_DELAYED_INT is not defined.
10 * This allows positive tests instead of tests that contain
11 * double negatives, and become confusing.
13 #ifndef NO_DELAYED_INT
17 /* We need some unique magic ID, if we defer startup thru the INT18H or INT19H
18 * handler. This way, we can check if we have already been installed.
24 /* Hook into INT18H or INT19H handler */
31 #define BOOT_INT_VEC BOOT_INT*4
32 #define SCRATCHVEC 0x300
34 /* Prefix exit codes. We store these on the stack so that we will
35 * know how to return control to the BIOS when Etherboot exits.
37 #define EXIT_VIA_LRET 0x0
38 #define EXIT_VIA_INT_18 0x1
39 #define EXIT_VIA_BOOT_INT 0x2
45 .section ".prefix", "ax", @progbits
47 .word 0xAA55 /* BIOS extension signature */
48 size: .byte 0 /* number of 512 byte blocks */
49 /* = number of 256 word blocks */
50 /* filled in by makerom program */
51 jmp over /* skip over checksum */
52 .byte 0 /* checksum */
53 jmp legacyentry /* alternate entry point +6 */
54 /* used by mknbi-rom */
62 .word UNDIROMID - _prefix
63 #endif /* PXE_EXPORT */
71 .word 0x0000 /* vendor ID, filled in by makerom */
72 .word 0x0000 /* device ID, filled in by makerom */
73 .word 0x0000 /* pointer to vital product data */
74 .word 0x0018 /* PCI data structure length */
75 .byte 0x00 /* PCI data structure revision */
76 .byte 0x02 /* Device Base Type code */
77 .byte 0x00 /* Device Sub-Type code */
78 .byte 0x00 /* Device Interface Type code */
79 .word 0x0000 /* Image length same as offset 02h */
80 .word 0x0001 /* revision level of code/data */
81 .byte 0x00 /* code type */
82 .byte 0x80 /* indicator (last PCI data structure) */
83 .word 0x0000 /* reserved */
87 .byte 0x01 /* structure revision */
88 .byte 0x02 /* length (in 16 byte increments) */
89 .word 0x0000 /* offset of next header */
90 .byte 0x00 /* Reserved */
91 .byte 0x00 /* checksum filled by makerom */
92 .long 0x00000000 /* Device identifier */
93 .word mfgstr - _prefix
94 .word 0x0 /* pointer to product name */
95 /* filled by makerom */
96 .byte 0x02 /* Device Base Type code */
97 .byte 0x00 /* Device Sub-Type code */
98 .byte 0x00 /* Device Interface Type code */
99 .byte 0x14 /* device indicator */
100 .word 0x0000 /* boot connection vector */
101 .word 0x0000 /* disconnect vector */
102 .word pnpentry - _prefix
103 .word 0x0000 /* reserved */
104 .word 0x0000 /* static resource information vector */
108 .byte UNDIROMID_end - UNDIROMID /* length of structure */
109 .byte 0 /* Checksum */
110 .byte 0 /* Structure revision */
111 .byte 0,1,2 /* PXE version 2.1.0 */
112 .word UNDILoader - _prefix /* Offset to loader routine */
113 .word _real_mode_stack_size /* Stack segment size */
114 .word _real_mode_stack_size /* Data segment size */
115 .word _pxe_stack_size /* Code segment size */
118 /* The code segment contains our pxe_stack_t plus the PXE and
119 * RM callback interfaces. We don't actually use a data
120 * segment, but we put a nonzero value here to avoid confusing
121 * things. 16k of stack space should be enough.
123 * When we claim our own memory, we fill out the data segment
124 * with the address and size of the real-mode stack, so that
125 * NBPs will free that area of memory for us. When the UNDI
126 * loader is used to initialise us, we will never need a
127 * real-mode stack because we will only ever be called via the
128 * PXE API, hence our stack is already in base memory.
130 .equ UNDICodeSize, _pxe_stack_size
131 .equ UNDIDataSize, _real_mode_stack_size
132 .equ UNDIStackSize, _real_mode_stack_size
134 #endif /* PXE_EXPORT */
136 #endif /* PCI_PNP_HEADER */
139 * Explicitly specify DI is wrt ES to avoid problems with some BIOSes
140 * Discovered by Eric Biederman
141 * In addition, some BIOSes don't point DI to the string $PnP so
142 * we need another #define to take care of that.
145 #ifdef DEBUG_ROMPREFIX
148 /* Omit this test for ISA cards anyway */
149 #ifdef PCI_PNP_HEADER
150 /* Accept old name too for backward compatibility */
151 #if !defined(BBS_BUT_NOT_PNP_COMPLIANT) && !defined(PNP_BUT_NOT_BBS_COMPLIANT)
152 cmpw $'$'+'P'*256,%es:0(%di)
154 cmpw $'n'+'P'*256,%es:2(%di)
156 #endif /* BBS_BUT_NOT_PNP_COMPLIANT */
159 #endif /* PCI_PNP_HEADER */
161 #ifdef DEBUG_ROMPREFIX
168 movw %ax,%ds /* access first 64kB segment */
169 movw SCRATCHVEC+4, %ax /* check if already installed */
170 cmpw $MAGIC, %ax /* check magic word */
172 movw BOOT_INT_VEC, %ax /* hook into INT18H or INT19H */
174 movw BOOT_INT_VEC+2, %ax
175 movw %ax, SCRATCHVEC+2
176 movw $start_int - _prefix, %ax
177 movw %ax, BOOT_INT_VEC
179 movw %ax, BOOT_INT_VEC+2
180 movw $MAGIC, %ax /* set magic word */
181 movw %ax, SCRATCHVEC+4
182 #ifdef DEBUG_ROMPREFIX
191 start_int: /* clobber magic id, so that we will */
192 #ifdef DEBUG_ROMPREFIX
195 xorw %ax,%ax /* not inadvertendly end up in an */
196 movw %ax,%ds /* endless loop */
197 movw %ax, SCRATCHVEC+4
198 movw SCRATCHVEC+2, %ax /* restore original INT19h handler */
199 movw %ax, BOOT_INT_VEC+2
201 movw %ax, BOOT_INT_VEC
202 pushl %eax /* padding */
203 pushw $EXIT_VIA_BOOT_INT
205 #endif /* DELAYED_INT */
211 #ifdef DEBUG_ROMPREFIX
212 call print_legacyentry
219 #ifdef PCI_PNP_HEADER
221 #ifdef DEBUG_ROMPREFIX
224 pushl %eax /* padding */
225 pushw $EXIT_VIA_INT_18
227 #endif /* PCI_PNP_HEADER */
231 /* Store ROM segment and size on stack */
235 movzbw %cs:(size-_prefix), %ax
236 shlw $9, %ax /* 512-byte blocks */
238 /* Relocate to free base memory, switch stacks */
239 pushw $12 /* Preserve exit code & far ret addr */
241 /* We are now running in RAM */
242 popw %ax /* padding */
245 popw %ds:(_prefix_rom+2) /* ROM size */
246 popw %ds:(_prefix_rom+0) /* ROM segment */
247 popw %ds /* Original %ds */
248 popw %ax /* Original %ax */
249 pushw %ax /* 4-byte alignment */
250 pushl $8 /* Preserve exit code & far ret addr */
251 pushw $0 /* Set null return address */
255 .section ".text16", "ax", @progbits
257 popw %ax /* padding */
258 popw %ax /* %ax = exit code */
259 cmpw $EXIT_VIA_LRET, %ax
263 1: addw $4, %sp /* Strip padding */
264 cmpw $EXIT_VIA_BOOT_INT, %ax
266 /* Exit via int BOOT_INT */
267 int $BOOT_INT /* Try original vector */
268 2: /* Exit via int $0x18 */
269 int $0x18 /* As per BIOS Boot Spec, next dev */
275 /* UNDI loader needs to be rewritten to use new mechanism */
280 #define PXENV_UNDI_LOADER 0x104d
284 /* Loader API is different to the usual PXE API; there is no
285 * opcode on the stack. We arrange the stack to look like a
286 * normal PXE API call; this makes the Etherboot internals
287 * cleaner and avoids adding an extra API type just for the
291 movw %sp, %ax /* Store original %ss:sp */
294 pushl %eax /* Space for loader structure ptr */
297 movw 16(%bp), %ax /* Copy loader structure ptr */
302 pushw $PXENV_UNDI_LOADER /* PXE 'opcode' */
303 pushl %eax /* dummy return address */
304 /* Stack now looks like a normal PXE API call */
305 /* Store ROM segment and size on stack */
308 movzbw %cs:(size-_prefix), %ax
309 shlw $9, %ax /* 512-byte blocks */
311 /* Unpack Etherboot into temporarily claimed base memory */
312 pushw $20 /* Dummy ret, PXE params, orig ss:sp */
314 popw %ax /* discard */
315 popw %cs:(_prefix_rom+2) /* ROM size */
316 popw %cs:(_prefix_rom+0) /* ROM segment */
317 popw %ax /* Original %ax */
318 /* Inhibit automatic deallocation of base memory */
319 movl $0, %cs:_prefix_image_basemem
320 /* Make PXE API call to Etherboot */
321 pushl $0x201 /* PXE API version */
322 /* Need to USE_INTERNAL_STACK, since we will call relocate() */
323 pushl $(EB_OPCODE_PXE|EB_USE_INTERNAL_STACK) /* PXE API call type */
325 addw $18, %sp /* discard */
326 popw %bx /* Restore original %ss:sp */
331 lret $2 /* Skip our PXE 'opcode' */
332 #endif /* PXE_EXPORT */
336 #ifdef DEBUG_ROMPREFIX
341 movw $1f-_prefix, %si
345 1: .asciz "ROM detected\r\n"
349 movw $1f-_prefix, %si
353 1: .asciz "booting\r\n"
357 movw $1f-_prefix, %si
361 1: .asciz ": Non-PnP BIOS detected!\r\n"
365 movw $1f-_prefix, %si
369 1: .asciz "ROM using legacy boot mechanism\r\n"
373 movw $1f-_prefix, %si
377 1: .ascii "hooked boot via INT"
386 movw $1f-_prefix, %si
390 1: .asciz "booting via hooked interrupt\r\n"
398 movw $1f-_prefix, %si
405 1: .asciz "Etherboot "
411 movw $0x0007, %bx /* page 0, attribute 7 (normal) */
412 movb $0x0e, %ah /* write char, tty mode */