Add logo by Abi Rasheed
[profile/ivi/syslinux.git] / core / bootsect.inc
1 ;; -----------------------------------------------------------------------
2 ;;
3 ;;   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
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.
11 ;;
12 ;; -----------------------------------------------------------------------
13
14 ;;
15 ;; bootsect.inc
16 ;;
17 ;; Load a boot sector (or other bootstrap program.)
18 ;;
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.
22 ;;
23
24 ;
25 ; Load a boot sector
26 ;
27 is_bootsector:
28 %if IS_SYSLINUX
29                 ; Transfer zero bytes
30                 push word 0
31                 jmp short load_bootsec
32
33 is_bss_sector:
34                 ; Transfer the superblock
35 SuperSize       equ $+1
36                 push word superblock_len_fat16
37 %endif
38 load_bootsec:
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
43                 call load_high
44
45                 sub edi,free_high_memory
46                 mov [trackbuf+8],edi    ; Save length
47
48                 mov eax,7C00h           ; Entry point
49                 mov [trackbuf],eax      ; Copy to this address
50
51 %if IS_SYSLINUX
52                 xor ecx,ecx
53                 pop cx
54
55                 ; For a BSS boot sector we have to patch.
56                 mov esi,superblock
57                 mov edi,free_high_memory+(superblock-bootsec)
58                 call bcopy
59 %endif
60                 push eax                ; Save entry point
61
62                 xor edx,edx
63                 xor esi,esi
64 %if IS_SYSLINUX || IS_EXTLINUX
65                 ; Restore original FDC table
66                 mov eax,[OrigFDCTabPtr]
67                 mov [fdctab],eax
68
69                 mov dl,[DriveNumber]
70                 mov si,PartInfo         ; Partition info buffer
71                 mov di,800h-18          ; Put partition info here
72                 push di
73                 mov cx,8                ; 16 bytes
74                 xor ax,ax
75                 rep movsw
76                 pop si                  ; DS:SI points to partition info
77                 xor bx,bx
78 %elif IS_ISOLINUX
79                 mov dl,[DriveNumber]
80                 xor bx,bx
81 %elif IS_PXELINUX
82                 mov byte [KeepPXE],03h  ; Chainloading + keep PXE
83                 pm_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
90
91 ;
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.
95 ;
96
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
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
108
109 ;
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.
114 ;
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:
119                 ;
120                 ; Prepare for shutting down
121                 ;
122                 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
133                 ; set - we use the PXE stack then.)
134                 ;
135                 xor ax,ax
136                 mov ds,ax
137                 mov es,ax
138
139 %if IS_PXELINUX
140                 cmp byte [KeepPXE],0
141                 je .stdstack
142                 les di,[InitStack]      ; Reset stack to PXE original
143                 jmp .stackok
144 %endif
145 .stdstack:
146                 ; StackBuf is guaranteed to have 44 bytes free immediately
147                 ; above it, and it will not interfere with our existing stack.
148                 mov di,StackBuf
149                 push di
150                 mov cx,22               ; 44 bytes
151                 rep stosw
152                 pop di
153 .stackok:
154
155                 mov [es:di+28],edx      ; New EDX
156                 mov [es:di+12],esi      ; New ESI
157                 mov [es:di+6],bx        ; New DS
158
159 %if IS_PXELINUX == 0
160                 ; DON'T DO THIS FOR PXELINUX...
161                 ; For PXE, ES:BX -> PXENV+, and this would corrupt
162                 ; that use.
163
164                 ; Restore ES:DI -> $PnP (if we were ourselves called
165                 ; that way...)
166                 mov ax,[OrigESDI]
167                 mov bx,[OrigESDI+2]
168
169                 mov [es:di+8],ax        ; New DI
170                 mov [es:di+4],bx        ; New ES
171 %endif
172                 pop ax                  ; descriptor list entries count
173
174                 push di
175                 push es
176
177                 push ds
178                 pop es
179
180                 mov ebx,trackbuf
181                 imul di,ax,12
182                 push di                 ; length of list
183                 add di,bx               ; DI <- end of list
184
185                 ; Terminating entry...
186                 lea eax,[replace_stub]  ; Entrypoint
187                 push ax
188                 stosd
189                 xor ax,ax               ; EAX[31:16] == 0 already
190                 stosd                   ; 16-bit mode
191                 stosd                   ; End of list
192
193                 ; Copy the stub
194                 pop di
195                 mov si,__replacestub_lma
196                 mov cx,__replacestub_dwords
197                 rep movsd
198
199                 ; ECX <- final list length
200                 xor ecx,ecx
201                 pop cx                  ; original length in bytes
202                 add cx, 12              ; + termination entry size
203
204                 pop word [replace_stub.ss]
205                 pop word [replace_stub.esp]
206                 pop dword [replace_stub.csip]
207
208                 cli
209                 mov ss,[replace_stub.ss]
210                 mov esp,[replace_stub.esp]
211
212                 mov edi,trackbuf
213                 mov esi,edi
214
215                 jmp shuffle_and_boot_raw
216
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.
220                 section .replacestub
221 replace_stub:
222                 mov cr0,eax
223                 jmp 0:.next
224 .next:
225                 mov ax,strict word 0
226 .ss             equ $-2
227                 mov ss,ax
228                 mov esp,strict dword 0
229 .esp            equ $-4
230                 pop gs
231                 pop fs
232                 pop es
233                 pop ds
234                 popad
235                 popfd
236                 jmp 0:0
237 .csip           equ $-4
238
239                 section .text16