ccf5331cc1adb7ade30e70d9e688dd282f39aa8d
[profile/ivi/syslinux.git] / bootsect.inc
1 ;; $Id$
2 ;; -----------------------------------------------------------------------
3 ;;   
4 ;;   Copyright 1994-2002 H. Peter Anvin - All Rights Reserved
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 ;;   Bostom 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                 xor cx,cx
31                 jmp short load_bootsec
32 is_bss_sector:
33                 ; Transfer the superblock
34                 mov cx,superblock_len
35 load_bootsec:
36                 push cx
37 %endif
38                 xchg dx,ax
39                 shr eax,16
40                 xchg dx,ax              ; Now EAX = file length
41                 mov edi, 100000h
42                 call load_high
43                 call crlf
44
45 %if IS_SYSLINUX
46                 pop cx
47 %endif
48
49                 sub edi,100000h
50                 push edi                ; Save length
51
52 %if IS_SYSLINUX
53                 jcxz .not_bss
54
55                 ; For a BSS boot sector we have to patch.
56                 mov esi,superblock
57                 mov edi,100000h+(superblock-bootsec)
58                 movzx ecx,cx
59                 call bcopy
60
61 .not_bss:
62 %endif
63 ;
64 ; Prepare for shutting down
65 ;
66                 call vgaclearmode
67                 xor edx,edx
68                 xor eax,eax
69 %if IS_SYSLINUX
70                 mov dl,[bsDriveNumber]
71
72                 mov si,PartInfo
73                 mov di,800h-18          ; Put partition info here
74                 push di
75                 mov cx,8                ; 16 bytes
76                 rep movsw
77                 pop si                  ; DS:SI points to partition info
78 %elif IS_ISOLINUX
79                 mov dl,[DriveNo]
80 %elif IS_PXELINUX
81                 ; Close the UDP stack so the PXE stack is in a known state for
82                 ; the new NBP
83                 call reset_pxe
84 %endif
85
86                 pop ecx                 ; Byte count to copy
87
88                 cli
89                 xor ebx,ebx
90                 mov ds,bx
91                 mov es,bx
92 %if IS_PXELINUX
93                 lss sp,[InitStack]      ; Reset stack to PXE original
94 %else
95                 mov esp,7C00h
96                 pushad
97                 pushfd
98                 push bx ; ds
99                 push bx ; es
100                 push bx ; fs
101                 push bx ; gs
102 %endif
103
104                 mov esi,100000h         ; Copy from...
105                 mov edi,7C00h           ; Copy to...
106
107                 jmp bcopy_over_self
108
109 %if IS_SYSLINUX = 0
110 is_bss_sector:
111                 mov si,err_bssimage
112                 call cwritestr
113                 jmp enter_command
114 %endif