1 ;; -----------------------------------------------------------------------
3 ;; Copyright 1994-2009 H. Peter Anvin - All Rights Reserved
4 ;; Copyright 2009 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 xor dx,dx ; No padding
42 mov bx,abort_check ; Don't print dots, but allow abort
45 sub edi,free_high_memory
46 mov [trackbuf+8],edi ; Save length
48 mov eax,7C00h ; Entry point
49 mov [trackbuf],eax ; Copy to this address
55 ; For a BSS boot sector we have to patch.
57 mov edi,free_high_memory+(superblock-bootsec)
60 push eax ; Save entry point
64 %if IS_SYSLINUX || IS_EXTLINUX
65 ; Restore original FDC table
66 mov eax,[OrigFDCTabPtr]
70 mov si,PartInfo ; Partition info buffer
71 mov di,800h-18 ; Put partition info here
76 pop si ; DS:SI points to partition info
82 mov byte [KeepPXE],03h ; Chainloading + keep PXE
85 ; Put restore DS, EDX and ESI to the true initial values
92 ; replace_bootstrap for the special case where we have exactly one
93 ; descriptor, based in low memory. We will generate a second descriptor
94 ; to clear remaining FBM.
97 replace_bootstrap_one:
98 mov eax,[trackbuf] ; Base address
99 add eax,[trackbuf+8] ; Length
100 movzx ecx,word [BIOS_fbm]
101 shl ecx,10 ; Free Base Memory
103 mov [trackbuf+12],eax
104 or dword [trackbuf+16],-1 ; Zero memory
105 mov [trackbuf+20],ecx
106 push word 2 ; Length of descriptor list
110 ; Entrypoint for "shut down and replace bootstrap" -- also invoked by
111 ; the COMBOOT API. This routine expects the entry point (CS, IP) and the
112 ; count of the descriptor sequence on the stack; the shuffle
113 ; descriptors start at the first byte of the trackbuf.
115 ; The registers EDX and ESI are passed on to the called program,
116 ; and BX is passed on as DS.
120 ; Prepare for shutting down
125 ; We jump here when loading a kernel image, so that we don't reset
126 ; the screen mode in "quiet" mode
128 replace_bootstrap_noclearmode:
129 call cleanup_hardware
132 ; Set up initial stack frame (not used by PXE if keeppxe is
133 ; set - we use the PXE stack then.)
142 les di,[InitStack] ; Reset stack to PXE original
146 ; StackBuf is guaranteed to have 44 bytes free immediately
147 ; above it, and it will not interfere with our existing stack.
155 mov [es:di+28],edx ; New EDX
156 mov [es:di+12],esi ; New ESI
157 mov [es:di+6],bx ; New DS
160 ; DON'T DO THIS FOR PXELINUX...
161 ; For PXE, ES:BX -> PXENV+, and this would corrupt
164 ; Restore ES:DI -> $PnP (if we were ourselves called
169 mov [es:di+8],ax ; New DI
170 mov [es:di+4],bx ; New ES
172 pop ax ; descriptor list entries count
182 push di ; length of list
183 add di,bx ; DI <- end of list
185 ; Terminating entry...
186 lea eax,[replace_stub] ; Entrypoint
189 xor ax,ax ; EAX[31:16] == 0 already
195 mov si,__replacestub_lma
196 mov cx,__replacestub_dwords
199 ; ECX <- final list length
201 pop cx ; original length in bytes
202 add cx, 12 ; + termination entry size
204 pop word [replace_stub.ss]
205 pop word [replace_stub.esp]
206 pop dword [replace_stub.csip]
209 mov ss,[replace_stub.ss]
210 mov esp,[replace_stub.esp]
215 jmp shuffle_and_boot_raw
217 ; This stub gets run after the shuffle. It is copied
218 ; below 0x7c00 in order to properly handle the case
219 ; of bootstrap replacement.
228 mov esp,strict dword 0