1 ;; -----------------------------------------------------------------------
3 ;; Copyright 1994-2009 H. Peter Anvin - All Rights Reserved
4 ;; Copyright 2009-2012 Intel Corporation; author: H. Peter Anvin
6 ;; This program is free software; you can redistribute it and/or modify
7 ;; it under the terms of the GNU General Public License as published by
8 ;; the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 ;; Boston MA 02111-1307, USA; either version 2 of the License, or
10 ;; (at your option) any later version; incorporated herein by reference.
12 ;; -----------------------------------------------------------------------
17 ;; Load a boot sector (or other bootstrap program.)
19 ;; Unlike previous versions of this software, this doesn't require that
20 ;; the length is 512 bytes. This allows PXE bootstraps and WinNT
21 ;; "CD boot sectors" to be invoked.
31 jmp short load_bootsec
34 ; Transfer the superblock
36 push word superblock_len_fat16
39 mov edi,free_high_memory
40 mov [trackbuf+4],edi ; Copy from this address
41 mov eax,0xA0000 ; Maximum load
42 xor dx,dx ; No padding
43 mov bx,abort_check ; Don't print dots, but allow abort
46 sub edi,free_high_memory
47 mov [trackbuf+8],edi ; Save length
52 mov eax,7C00h ; Entry point
53 mov [trackbuf],eax ; Copy to this address
59 ; For a BSS boot sector we have to patch.
61 mov edi,free_high_memory+(superblock-bootsec)
64 push eax ; Save entry point
68 %if IS_SYSLINUX || IS_EXTLINUX
69 ; Restore original FDC table
70 mov eax,[OrigFDCTabPtr]
74 mov si,PartInfo ; Partition info buffer
75 mov di,800h-18 ; Put partition info here
80 pop si ; DS:SI points to partition info
86 mov byte [KeepPXE],03h ; Chainloading + keep PXE
89 ; Put restore DS, EDX and ESI to the true initial values
96 ; replace_bootstrap for the special case where we have exactly one
97 ; descriptor, based in low memory. We will generate a second descriptor
98 ; to clear remaining FBM.
101 replace_bootstrap_one:
102 mov eax,[trackbuf] ; Base address
103 add eax,[trackbuf+8] ; Length
104 movzx ecx,word [BIOS_fbm]
105 shl ecx,10 ; Free Base Memory
107 mov [trackbuf+12],eax
108 or dword [trackbuf+16],-1 ; Zero memory
109 mov [trackbuf+20],ecx
110 push word 2 ; Length of descriptor list
114 ; Entrypoint for "shut down and replace bootstrap" -- also invoked by
115 ; the COMBOOT API. This routine expects the entry point (CS, IP) and the
116 ; count of the descriptor sequence on the stack; the shuffle
117 ; descriptors start at the first byte of the trackbuf.
119 ; The registers EDX and ESI are passed on to the called program,
120 ; and BX is passed on as DS.
124 ; Prepare for shutting down
129 ; We jump here when loading a kernel image, so that we don't reset
130 ; the screen mode in "quiet" mode
132 replace_bootstrap_noclearmode:
133 call cleanup_hardware
136 ; Set up initial stack frame (not used by PXE if keeppxe is
137 ; set - we use the PXE stack then.)
146 les di,[InitStack] ; Reset stack to PXE original
150 ; StackBuf is guaranteed to have 44 bytes free immediately
151 ; above it, and it will not interfere with our existing stack.
159 mov [es:di+28],edx ; New EDX
160 mov [es:di+12],esi ; New ESI
161 mov [es:di+6],bx ; New DS
164 ; DON'T DO THIS FOR PXELINUX...
165 ; For PXE, ES:BX -> PXENV+, and this would corrupt
168 ; Restore ES:DI -> $PnP (if we were ourselves called
173 mov [es:di+8],ax ; New DI
174 mov [es:di+4],bx ; New ES
176 pop ax ; descriptor list entries count
186 push di ; length of list
187 add di,bx ; DI <- end of list
189 ; Terminating entry...
190 lea eax,[replace_stub] ; Entrypoint
193 xor ax,ax ; EAX[31:16] == 0 already
199 mov si,__replacestub_lma
200 mov cx,__replacestub_dwords
203 ; ECX <- final list length
205 pop cx ; original length in bytes
206 add cx, 12 ; + termination entry size
208 pop word [replace_stub.ss]
209 pop word [replace_stub.esp]
210 pop dword [replace_stub.csip]
213 mov ss,[replace_stub.ss]
214 mov esp,[replace_stub.esp]
219 jmp shuffle_and_boot_raw
221 ; This stub gets run after the shuffle. It is copied
222 ; below 0x7c00 in order to properly handle the case
223 ; of bootstrap replacement.
232 mov esp,strict dword 0
246 mov si,err_bs_too_big
250 err_bs_too_big db "Too large for a bootstrap (need LINUX instead of KERNEL?)"