simple menu: The use of realloc() requires indirect pointers
[profile/ivi/syslinux.git] / bootsect.inc
1 ;; -----------------------------------------------------------------------
2 ;;
3 ;;   Copyright 1994-2008 H. Peter Anvin - All Rights Reserved
4 ;;
5 ;;   This program is free software; you can redistribute it and/or modify
6 ;;   it under the terms of the GNU General Public License as published by
7 ;;   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 ;;   Boston MA 02111-1307, USA; either version 2 of the License, or
9 ;;   (at your option) any later version; incorporated herein by reference.
10 ;;
11 ;; -----------------------------------------------------------------------
12
13 ;;
14 ;; bootsect.inc
15 ;;
16 ;; Load a boot sector (or other bootstrap program.)
17 ;;
18 ;; Unlike previous versions of this software, this doesn't require that
19 ;; the length is 512 bytes.  This allows PXE bootstraps and WinNT
20 ;; "CD boot sectors" to be invoked.
21 ;;
22
23 ;
24 ; Load a boot sector
25 ;
26 is_bootsector:
27 %if IS_SYSLINUX || IS_MDSLINUX
28                 ; Transfer zero bytes
29                 mov byte [CopySuper],0
30                 jmp short load_bootsec
31
32 is_bss_sector:
33                 ; Transfer the superblock
34                 mov byte [CopySuper],superblock_len
35 %endif
36 load_bootsec:
37                 xchg dx,ax
38                 shl eax,16
39                 xchg dx,ax              ; Now EAX = file length
40                 mov edi, 100000h
41                 mov [trackbuf+4],edi    ; Copy from this address
42                 push edi                ; Save load address
43                 xor dx,dx               ; No padding
44                 mov bx,abort_check      ; Don't print dots, but allow abort
45                 call load_high
46
47                 sub edi,100000h
48                 mov [trackbuf+8],edi    ; Save length
49
50                 mov eax,7C00h           ; Entry point
51                 mov [trackbuf],eax      ; Copy to this address
52                 mov [EntryPoint],eax    ; Jump to this address when done
53
54 %if IS_SYSLINUX || IS_MDSLINUX
55                 movzx ecx,byte [CopySuper]
56                 jcxz .not_bss
57
58                 ; For a BSS boot sector we have to patch.
59                 mov esi,superblock
60                 mov edi,100000h+(superblock-bootsec)
61                 call bcopy
62
63 .not_bss:
64 %endif
65
66                 xor edx,edx
67                 xor esi,esi
68 %if IS_SYSLINUX || IS_MDSLINUX || IS_EXTLINUX
69                 ; Restore original FDC table
70                 mov eax,[OrigFDCTabPtr]
71                 mov [fdctab],eax
72
73                 mov dl,[DriveNumber]
74                 mov si,PartInfo         ; Partition info buffer
75                 mov di,800h-18          ; Put partition info here
76                 push di
77                 mov cx,8                ; 16 bytes
78                 xor ax,ax
79                 rep movsw
80                 pop si                  ; DS:SI points to partition info
81 %elif IS_ISOLINUX
82                 mov dl,[DriveNumber]
83 %elif IS_PXELINUX
84                 mov byte [KeepPXE],1    ; Chainloading another NBP
85                 call reset_pxe
86 %endif
87                 xor bx,bx
88
89 ;
90 ; replace_bootstrap for the special case where we have exactly one
91 ; descriptor, and it's the first entry in the trackbuf
92 ;
93
94 replace_bootstrap_one:
95                 push word 1                     ; Length of descriptor list
96                 push word trackbuf              ; Address of descriptor list
97                 ; Fall through
98
99 ;
100 ; Entrypoint for "shut down and replace bootstrap" -- also invoked by
101 ; the COMBOOT API.  This routine expects two words on the stack:
102 ; address of the copy list (versus DS) and count.  Additionally,
103 ; the values of ESI and EDX are passed on to the new bootstrap;
104 ; the value of BX becomes the new DS.
105 ;
106 replace_bootstrap:
107                 ;
108                 ; Prepare for shutting down
109                 ;
110                 call vgaclearmode
111                 call cleanup_hardware
112
113                 ;
114                 ; Set up initial stack frame (not used by PXE if keeppxe is
115                 ; set - we use the PXE stack then.)
116                 ; AFTER THIS POINT ONLY .earlybss IS AVAILABLE, NOT .bss
117                 ;
118                 xor ax,ax
119                 mov ds,ax
120                 mov es,ax
121
122 %if IS_PXELINUX
123                 test byte [KeepPXE],01h
124                 jz .stdstack
125                 les di,[InitStack]      ; Reset stack to PXE original
126                 jmp .stackok
127 %endif
128 .stdstack:
129                 mov di,7C00h-44
130                 push di
131                 mov cx,22               ; 44 bytes
132                 rep stosw
133                 pop di
134 .stackok:
135
136                 mov [es:di+28],edx      ; New EDX
137                 mov [es:di+12],esi      ; New ESI
138                 mov [es:di+6],bx        ; New DS
139
140 %if IS_PXELINUX == 0
141                 ; DON'T DO THIS FOR PXELINUX...
142                 ; For PXE, ES:BX -> PXENV+, and this would corrupt
143                 ; that use.
144
145                 ; Restore ES:DI -> $PnP (if we were ourselves called
146                 ; that way...)
147                 mov ax,[OrigESDI]
148                 mov bx,[OrigESDI+2]
149
150                 mov [es:di+8],ax        ; New DI
151                 mov [es:di+4],bx        ; New ES
152 %endif
153                 pop bx                  ; Copy from...
154                 pop ax                  ; Copy list count
155
156                 cli
157                 mov cx,es
158                 mov ss,cx
159                 movzx esp,di
160
161                 jmp shuffle_and_boot