Add stpcpy() and implement version/derivative queries
[syslinux.git] / bootsect.inc
blob7e8f416de7769287179d48c443dba47ec0c5d6fb
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.
11 ;; -----------------------------------------------------------------------
14 ;; bootsect.inc
16 ;; Load a boot sector (or other bootstrap program.)
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.
24 ; Load a boot sector
26 is_bootsector:
27 %if IS_SYSLINUX || IS_MDSLINUX
28                 ; Transfer zero bytes
29                 mov byte [CopySuper],0
30                 jmp short load_bootsec
32 is_bss_sector:
33                 ; Transfer the superblock
34                 mov byte [CopySuper],superblock_len
35 %endif
36 load_bootsec:
37                 mov edi, 100000h
38                 mov [trackbuf+4],edi    ; Copy from this address
39                 push edi                ; Save load address
40                 xor dx,dx               ; No padding
41                 mov bx,abort_check      ; Don't print dots, but allow abort
42                 call load_high
44                 sub edi,100000h
45                 mov [trackbuf+8],edi    ; Save length
47                 mov eax,7C00h           ; Entry point
48                 mov [trackbuf],eax      ; Copy to this address
49                 mov [EntryPoint],eax    ; Jump to this address when done
51 %if IS_SYSLINUX || IS_MDSLINUX
52                 movzx ecx,byte [CopySuper]
53                 jcxz .not_bss
55                 ; For a BSS boot sector we have to patch.
56                 mov esi,superblock
57                 mov edi,100000h+(superblock-bootsec)
58                 call bcopy
60 .not_bss:
61 %endif
63                 xor edx,edx
64                 xor esi,esi
65 %if IS_SYSLINUX || IS_MDSLINUX || IS_EXTLINUX
66                 ; Restore original FDC table
67                 mov eax,[OrigFDCTabPtr]
68                 mov [fdctab],eax
70                 mov dl,[DriveNumber]
71                 mov si,PartInfo         ; Partition info buffer
72                 mov di,800h-18          ; Put partition info here
73                 push di
74                 mov cx,8                ; 16 bytes
75                 xor ax,ax
76                 rep movsw
77                 pop si                  ; DS:SI points to partition info
78 %elif IS_ISOLINUX
79                 mov dl,[DriveNumber]
80 %elif IS_PXELINUX
81                 mov byte [KeepPXE],1    ; Chainloading another NBP
82                 call reset_pxe
83 %endif
84                 xor bx,bx
87 ; replace_bootstrap for the special case where we have exactly one
88 ; descriptor, and it's the first entry in the trackbuf
91 replace_bootstrap_one:
92                 push word 1                     ; Length of descriptor list
93                 push word trackbuf              ; Address of descriptor list
94                 ; Fall through
97 ; Entrypoint for "shut down and replace bootstrap" -- also invoked by
98 ; the COMBOOT API.  This routine expects two words on the stack:
99 ; address of the copy list (versus DS) and count.  Additionally,
100 ; the values of ESI and EDX are passed on to the new bootstrap;
101 ; the value of BX becomes the new DS.
103 replace_bootstrap:
104                 ;
105                 ; Prepare for shutting down
106                 ;
107                 call vgaclearmode
108                 call cleanup_hardware
110                 ;
111                 ; Set up initial stack frame (not used by PXE if keeppxe is
112                 ; set - we use the PXE stack then.)
113                 ; AFTER THIS POINT ONLY .earlybss IS AVAILABLE, NOT .bss
114                 ;
115                 xor ax,ax
116                 mov ds,ax
117                 mov es,ax
119 %if IS_PXELINUX
120                 test byte [KeepPXE],01h
121                 jz .stdstack
122                 les di,[InitStack]      ; Reset stack to PXE original
123                 jmp .stackok
124 %endif
125 .stdstack:
126                 mov di,7C00h-44
127                 push di
128                 mov cx,22               ; 44 bytes
129                 rep stosw
130                 pop di
131 .stackok:
133                 mov [es:di+28],edx      ; New EDX
134                 mov [es:di+12],esi      ; New ESI
135                 mov [es:di+6],bx        ; New DS
137 %if IS_PXELINUX == 0
138                 ; DON'T DO THIS FOR PXELINUX...
139                 ; For PXE, ES:BX -> PXENV+, and this would corrupt
140                 ; that use.
142                 ; Restore ES:DI -> $PnP (if we were ourselves called
143                 ; that way...)
144                 mov ax,[OrigESDI]
145                 mov bx,[OrigESDI+2]
147                 mov [es:di+8],ax        ; New DI
148                 mov [es:di+4],bx        ; New ES
149 %endif
150                 pop bx                  ; Copy from...
151                 pop ax                  ; Copy list count
153                 cli
154                 mov cx,es
155                 mov ss,cx
156                 movzx esp,di
158                 jmp shuffle_and_boot