|
;; $Id: bootsect.inc,v 1.1 2007-09-01 22:44:04 niro Exp $ |
|
1 |
;; ----------------------------------------------------------------------- |
;; ----------------------------------------------------------------------- |
2 |
;; |
;; |
3 |
;; Copyright 1994-2005 H. Peter Anvin - All Rights Reserved |
;; Copyright 1994-2009 H. Peter Anvin - All Rights Reserved |
4 |
|
;; Copyright 2009 Intel Corporation; author: H. Peter Anvin |
5 |
;; |
;; |
6 |
;; This program is free software; you can redistribute it and/or modify |
;; 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 |
;; it under the terms of the GNU General Public License as published by |
13 |
|
|
14 |
;; |
;; |
15 |
;; bootsect.inc |
;; bootsect.inc |
16 |
;; |
;; |
17 |
;; Load a boot sector (or other bootstrap program.) |
;; Load a boot sector (or other bootstrap program.) |
18 |
;; |
;; |
19 |
;; Unlike previous versions of this software, this doesn't require that |
;; Unlike previous versions of this software, this doesn't require that |
25 |
; Load a boot sector |
; Load a boot sector |
26 |
; |
; |
27 |
is_bootsector: |
is_bootsector: |
28 |
%if IS_SYSLINUX || IS_MDSLINUX |
%if IS_SYSLINUX |
29 |
; Transfer zero bytes |
; Transfer zero bytes |
30 |
mov byte [CopySuper],0 |
push word 0 |
31 |
jmp short load_bootsec |
jmp short load_bootsec |
32 |
|
|
33 |
is_bss_sector: |
is_bss_sector: |
34 |
; Transfer the superblock |
; Transfer the superblock |
35 |
mov byte [CopySuper],superblock_len |
SuperSize equ $+1 |
36 |
|
push word superblock_len_fat16 |
37 |
%endif |
%endif |
38 |
load_bootsec: |
load_bootsec: |
39 |
xchg dx,ax |
mov edi,100000h |
|
shl eax,16 |
|
|
xchg dx,ax ; Now EAX = file length |
|
|
mov edi, 100000h |
|
40 |
mov [trackbuf+4],edi ; Copy from this address |
mov [trackbuf+4],edi ; Copy from this address |
|
push edi ; Save load address |
|
41 |
xor dx,dx ; No padding |
xor dx,dx ; No padding |
42 |
|
mov bx,abort_check ; Don't print dots, but allow abort |
43 |
call load_high |
call load_high |
|
call crlf |
|
44 |
|
|
45 |
sub edi,100000h |
sub edi,100000h |
46 |
mov [trackbuf+8],edi ; Save length |
mov [trackbuf+8],edi ; Save length |
47 |
|
|
48 |
mov eax,7C00h ; Entry point |
mov eax,7C00h ; Entry point |
49 |
mov [trackbuf],eax ; Copy to this address |
mov [trackbuf],eax ; Copy to this address |
|
mov [EntryPoint],eax ; Jump to this address when done |
|
50 |
|
|
51 |
%if IS_SYSLINUX || IS_MDSLINUX |
%if IS_SYSLINUX |
52 |
movzx ecx,byte [CopySuper] |
xor ecx,ecx |
53 |
jcxz .not_bss |
pop cx |
54 |
|
|
55 |
; For a BSS boot sector we have to patch. |
; For a BSS boot sector we have to patch. |
56 |
mov esi,superblock |
mov esi,superblock |
57 |
mov edi,100000h+(superblock-bootsec) |
mov edi,100000h+(superblock-bootsec) |
58 |
call bcopy |
call bcopy |
|
|
|
|
.not_bss: |
|
59 |
%endif |
%endif |
60 |
|
push eax ; Save entry point |
61 |
|
|
62 |
xor edx,edx |
xor edx,edx |
63 |
xor esi,esi |
xor esi,esi |
64 |
%if IS_SYSLINUX || IS_MDSLINUX || IS_EXTLINUX |
%if IS_SYSLINUX || IS_EXTLINUX |
65 |
; Restore original FDC table |
; Restore original FDC table |
66 |
mov eax,[OrigFDCTabPtr] |
mov eax,[OrigFDCTabPtr] |
67 |
mov [fdctab],eax |
mov [fdctab],eax |
74 |
xor ax,ax |
xor ax,ax |
75 |
rep movsw |
rep movsw |
76 |
pop si ; DS:SI points to partition info |
pop si ; DS:SI points to partition info |
77 |
|
xor bx,bx |
78 |
%elif IS_ISOLINUX |
%elif IS_ISOLINUX |
79 |
mov dl,[DriveNo] |
mov dl,[DriveNumber] |
80 |
|
xor bx,bx |
81 |
%elif IS_PXELINUX |
%elif IS_PXELINUX |
82 |
mov byte [KeepPXE],1 ; Chainloading another NBP |
mov byte [KeepPXE],03h ; Chainloading + keep PXE |
83 |
call reset_pxe |
call reset_pxe |
84 |
|
lfs si,[InitStack] |
85 |
|
; Put restore DS, EDX and ESI to the true initial values |
86 |
|
mov bx,[fs:si+6] |
87 |
|
mov edx,[fs:si+28] |
88 |
|
mov esi,[fs:si+12] |
89 |
%endif |
%endif |
|
xor bx,bx |
|
90 |
|
|
91 |
; |
; |
92 |
; replace_bootstrap for the special case where we have exactly one |
; replace_bootstrap for the special case where we have exactly one |
93 |
; descriptor, and it's the first entry in the trackbuf |
; descriptor, based in low memory. We will generate a second descriptor |
94 |
|
; to clear remaining FBM. |
95 |
; |
; |
96 |
|
|
97 |
replace_bootstrap_one: |
replace_bootstrap_one: |
98 |
push word trackbuf ; Address of descriptor list |
mov eax,[trackbuf] ; Base address |
99 |
push word 1 ; Length of descriptor list |
add eax,[trackbuf+8] ; Length |
100 |
|
movzx ecx,word [BIOS_fbm] |
101 |
|
shl ecx,10 ; Free Base Memory |
102 |
|
sub ecx,eax |
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 |
107 |
; Fall through |
; Fall through |
108 |
|
|
109 |
; |
; |
110 |
; Entrypoint for "shut down and replace bootstrap" -- also invoked by |
; Entrypoint for "shut down and replace bootstrap" -- also invoked by |
111 |
; the COMBOOT API. This routine expects two words on the stack: |
; the COMBOOT API. This routine expects the entry point (CS, IP) and the |
112 |
; address of the copy list (versus DS) and count. Additionally, |
; count of the descriptor sequence on the stack; the shuffle |
113 |
; the values of ESI and EDX are passed on to the new bootstrap; |
; descriptors start at the first byte of the trackbuf. |
114 |
; the value of BX becomes the new DS. |
; |
115 |
; |
; The registers EDX and ESI are passed on to the called program, |
116 |
|
; and BX is passed on as DS. |
117 |
|
; |
118 |
replace_bootstrap: |
replace_bootstrap: |
119 |
; |
; |
120 |
; Prepare for shutting down |
; Prepare for shutting down |
121 |
; |
; |
122 |
call vgaclearmode |
call vgaclearmode |
123 |
|
|
124 |
|
; |
125 |
|
; We jump here when loading a kernel image, so that we don't reset |
126 |
|
; the screen mode in "quiet" mode |
127 |
|
; |
128 |
|
replace_bootstrap_noclearmode: |
129 |
|
call cleanup_hardware |
130 |
|
|
131 |
; |
; |
132 |
; Set up initial stack frame (not used by PXE if keeppxe is |
; Set up initial stack frame (not used by PXE if keeppxe is |
133 |
; set - we use the PXE stack then.) |
; set - we use the PXE stack then.) |
|
; AFTER THIS POINT ONLY .earlybss IS AVAILABLE, NOT .bss |
|
134 |
; |
; |
135 |
xor ax,ax |
xor ax,ax |
136 |
mov ds,ax |
mov ds,ax |
137 |
mov es,ax |
mov es,ax |
138 |
|
|
139 |
%if IS_PXELINUX |
%if IS_PXELINUX |
140 |
test byte [KeepPXE],01h |
cmp byte [KeepPXE],0 |
141 |
jz .stdstack |
je .stdstack |
142 |
les di,[InitStack] ; Reset stack to PXE original |
les di,[InitStack] ; Reset stack to PXE original |
143 |
jmp .stackok |
jmp .stackok |
144 |
%endif |
%endif |
150 |
pop di |
pop di |
151 |
.stackok: |
.stackok: |
152 |
|
|
153 |
mov [es:di+28],edx |
mov [es:di+28],edx ; New EDX |
154 |
mov [es:di+12],esi |
mov [es:di+12],esi ; New ESI |
155 |
mov [es:di+6],bx |
mov [es:di+6],bx ; New DS |
156 |
|
|
157 |
|
%if IS_PXELINUX == 0 |
158 |
|
; DON'T DO THIS FOR PXELINUX... |
159 |
|
; For PXE, ES:BX -> PXENV+, and this would corrupt |
160 |
|
; that use. |
161 |
|
|
162 |
|
; Restore ES:DI -> $PnP (if we were ourselves called |
163 |
|
; that way...) |
164 |
|
mov ax,[OrigESDI] |
165 |
|
mov bx,[OrigESDI+2] |
166 |
|
|
167 |
|
mov [es:di+8],ax ; New DI |
168 |
|
mov [es:di+4],bx ; New ES |
169 |
|
%endif |
170 |
|
pop ax ; List length |
171 |
|
|
172 |
|
push di |
173 |
|
push es |
174 |
|
|
175 |
|
push ds |
176 |
|
pop es |
177 |
|
|
178 |
|
mov ebx,trackbuf |
179 |
|
imul di,ax,12 |
180 |
|
add di,bx ; DI <- end of list |
181 |
|
push di |
182 |
|
|
183 |
|
; Terminating entry... |
184 |
|
lea eax,[replace_stub] ; Entrypoint |
185 |
|
push ax |
186 |
|
stosd |
187 |
|
xor ax,ax ; EAX[31:16] == 0 already |
188 |
|
stosd ; 16-bit mode |
189 |
|
stosd ; End of list |
190 |
|
|
191 |
pop ax ; Copy list count |
; Copy the stub |
192 |
pop bx ; Copy from... |
pop di |
193 |
|
mov si,__replacestub_lma |
194 |
|
mov cx,__replacestub_dwords |
195 |
|
rep movsd |
196 |
|
|
197 |
|
xor ecx,ecx |
198 |
|
pop cx ; ECX <- length of list |
199 |
|
|
200 |
|
pop word [replace_stub.ss] |
201 |
|
pop word [replace_stub.esp] |
202 |
|
pop dword [replace_stub.csip] |
203 |
|
|
204 |
cli |
cli |
205 |
mov cx,es |
mov ss,[replace_stub.ss] |
206 |
mov ss,cx |
mov esp,[replace_stub.esp] |
207 |
movzx esp,di |
|
208 |
|
mov edi,trackbuf |
209 |
jmp shuffle_and_boot |
mov esi,edi |
210 |
|
|
211 |
%if IS_SYSLINUX || IS_MDSLINUX |
jmp shuffle_and_boot_raw |
212 |
; Nothing |
|
213 |
%else |
; This stub gets run after the shuffle. It is copied |
214 |
is_bss_sector: |
; below 0x7c00 in order to properly handle the case |
215 |
mov si,err_bssimage |
; of bootstrap replacement. |
216 |
call cwritestr |
section .replacestub |
217 |
jmp enter_command |
replace_stub: |
218 |
%endif |
mov cr0,eax |
219 |
|
jmp 0:.next |
220 |
|
.next: |
221 |
|
mov ax,strict word 0 |
222 |
|
.ss equ $-2 |
223 |
|
mov ss,ax |
224 |
|
mov esp,strict dword 0 |
225 |
|
.esp equ $-4 |
226 |
|
pop gs |
227 |
|
pop fs |
228 |
|
pop es |
229 |
|
pop ds |
230 |
|
popad |
231 |
|
popfd |
232 |
|
jmp 0:0 |
233 |
|
.csip equ $-4 |
234 |
|
|
235 |
|
section .text |