aboutsummaryrefslogtreecommitdiffstats
path: root/bootsect.inc
blob: b114c4eba92173a4c07ed0ccd4e1a0c70fd109c2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
;; $Id$
;; -----------------------------------------------------------------------
;;   
;;   Copyright 1994-2002 H. Peter Anvin - All Rights Reserved
;;
;;   This program is free software; you can redistribute it and/or modify
;;   it under the terms of the GNU General Public License as published by
;;   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
;;   Bostom MA 02111-1307, USA; either version 2 of the License, or
;;   (at your option) any later version; incorporated herein by reference.
;;
;; -----------------------------------------------------------------------

;;
;; bootsect.inc
;; 
;; Load a boot sector (or other bootstrap program.)
;;
;; Unlike previous versions of this software, this doesn't require that
;; the length is 512 bytes.  This allows PXE bootstraps and WinNT
;; "CD boot sectors" to be invoked.
;;

;
; Load a boot sector
;
is_bootsector:
%if IS_SYSLINUX
		; Transfer zero bytes
		xor cx,cx
		jmp short load_bootsec
is_bss_sector:
		; Transfer the superblock
		mov cx,superblock_len
load_bootsec:
		push cx
%endif
		xchg dx,ax
		shr eax,16
		xchg dx,ax		; Now EAX = file length
		mov edi, 100000h
		call load_high
		call crlf

%if IS_SYSLINUX
		pop cx
%endif

		sub edi,100000h
		push edi		; Save length

%if IS_SYSLINUX
		jcxz .not_bss

		; For a BSS boot sector we have to patch.
		mov esi,superblock
		mov edi,100000h+(superblock-bootsec)
		movzx ecx,cx
		call bcopy

.not_bss:
%endif
;
; Prepare for shutting down
;
		call vgaclearmode
		xor edx,edx
		xor eax,eax
%if IS_SYSLINUX
		mov dl,[bsDriveNumber]

		mov si,PartInfo
		mov di,800h-18		; Put partition info here
		push di
		mov cx,8		; 16 bytes
		rep movsw
		pop si			; DS:SI points to partition info
%elif IS_ISOLINUX
		mov dl,[DriveNo]
%elif IS_PXELINUX
		; Close the UDP stack so the PXE stack is in a known state for
		; the new NBP
		call reset_pxe
%endif

		pop ecx			; Byte count to copy

		cli
%if IS_PXELINUX
		lss sp,[Stack]		; Reset stack to PXE original
		pop es
%else
		xor ebx,ebx
		mov ds,bx
		mov es,bx
		mov esp,7C00h
		pushad
		pushfd
		push bx	; ds
		push bx ; es
		push bx ; fs
		push bx	; gs
%endif

		mov esi,100000h		; Copy from...
		mov edi,7C00h		; Copy to...

		jmp bcopy_over_self

%if IS_SYSLINUX = 0
is_bss_sector:
		mov si,err_bssimage
		call cwritestr
		jmp enter_command
%endif