1 ;------------------------------------------------------------------------------
3 ;* Copyright 2006 - 2007, Intel Corporation
4 ;* All rights reserved. This program and the accompanying materials
5 ;* are licensed and made available under the terms and conditions of the BSD License
6 ;* which accompanies this distribution. The full text of the license may be found at
7 ;* http://opensource.org/licenses/bsd-license.php
9 ;* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
10 ;* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 ;------------------------------------------------------------------------------
28 ; ****************************************************************************
29 ; Code loaded by BIOS at 0x0000:0x7C00
30 ; ****************************************************************************
35 ; ****************************************************************************
37 ; ****************************************************************************
43 lea si, cs:[StartString]
48 ; ****************************************************************************
50 ; ****************************************************************************
52 ; ****************************************************************************
53 ; Initialize segment registers and copy code at 0x0000:0x7c00 to 0x0000:0x0600
54 ; ****************************************************************************
55 xor ax, ax ; AX = 0x0000
56 mov bx, 07c00h ; BX = 0x7C00
57 mov bp, 0600h ; BP = 0x0600
58 mov si, OFFSET RelocatedStart ; SI = Offset(RelocatedStart)
59 mov cx, 0200h ; CX = 0x0200
60 sub cx, si ; CS = 0x0200 - Offset(RelocatedStart)
61 lea di, [bp+si] ; DI = 0x0600 + Offset(RelocatedStart)
62 lea si, [bx+si] ; BX = 0x7C00 + Offset(RelocatedStart)
63 mov ss, ax ; SS = 0x0000
64 mov sp, bx ; SP = 0x7C00
65 mov es,ax ; ES = 0x0000
66 mov ds,ax ; DS = 0x0000
68 push di ; PUSH 0x0600 + Offset(RelocatedStart)
69 cld ; Clear the direction flag
70 rep movsb ; Copy 0x0200 bytes from 0x7C00 to 0x0600
71 retf ; JMP 0x0000:0x0600 + Offset(RelocatedStart)
73 ; ****************************************************************************
74 ; Code relocated to 0x0000:0x0600
75 ; ****************************************************************************
78 ; ****************************************************************************
79 ; Get Driver Parameters to 0x0000:0x7BFC
80 ; ****************************************************************************
86 mov sp,07c00h ; sp = 0x7c00
87 mov bp,sp ; bp = 0x7c00
89 mov ah,8 ; ah = 8 - Get Drive Parameters Function
90 mov byte ptr [bp+PhysicalDrive],dl ; BBS defines that BIOS would pass the booting driver number to the loader through DL
91 int 13h ; Get Drive Parameters
94 inc al ; MaxHead = al + 1
95 push ax ; 0000:7bfe = MaxHead
97 and al,03fh ; MaxSector = al & 0x3f
98 push ax ; 0000:7bfc = MaxSector
100 ; ****************************************************************************
101 ; Read GPT Header from hard disk to 0x0000:0x0800
102 ; ****************************************************************************
104 mov es, ax ; Read to 0x0000:0x0800
105 mov di, 0800h ; Read to 0x0000:0x0800
106 mov eax, 1 ; Read LBA #1
107 mov edx, 0 ; Read LBA #1
108 mov bx, 1 ; Read 1 Block
113 ; ****************************************************************************
114 ; Read Target GPT Entry from hard disk to 0x0000:0x0A00
115 ; ****************************************************************************
116 cmp dword ptr es:[di], 020494645h ; Check for "EFI "
118 cmp dword ptr es:[di + 4], 054524150h ; Check for "PART"
120 cmp dword ptr es:[di + 8], 000010000h ; Check Revision - 0x10000
123 mov eax, dword ptr es:[di + 84] ; EAX = SizeOfPartitionEntry
124 mul byte ptr [bp+GptPartitionIndicator] ; EAX = SizeOfPartitionEntry * GptPartitionIndicator
125 mov edx, eax ; EDX = SizeOfPartitionEntry * GptPartitionIndicator
126 shr eax, BLOCK_SHIFT ; EAX = (SizeOfPartitionEntry * GptPartitionIndicator) / BLOCK_SIZE
127 and edx, BLOCK_MASK ; EDX = Targer PartitionEntryLBA Offset
128 ; = (SizeOfPartitionEntry * GptPartitionIndicator) % BLOCK_SIZE
130 mov ecx, dword ptr es:[di + 72] ; ECX = PartitionEntryLBA (Low)
131 mov ebx, dword ptr es:[di + 76] ; EBX = PartitionEntryLBA (High)
132 add eax, ecx ; EAX = Target PartitionEntryLBA (Low)
133 ; = (PartitionEntryLBA +
134 ; (SizeOfPartitionEntry * GptPartitionIndicator) / BLOCK_SIZE)
135 adc edx, ebx ; EDX = Target PartitionEntryLBA (High)
137 mov di, 0A00h ; Read to 0x0000:0x0A00
138 mov bx, 1 ; Read 1 Block
143 ; ****************************************************************************
144 ; Read Target DBR from hard disk to 0x0000:0x7C00
145 ; ****************************************************************************
146 pop edx ; EDX = (SizeOfPartitionEntry * GptPartitionIndicator) % BLOCK_SIZE
147 add di, dx ; DI = Targer PartitionEntryLBA Offset
148 cmp dword ptr es:[di], 0C12A7328h ; Check for EFI System Partition "C12A7328-F81F-11d2-BA4B-00A0C93EC93B"
150 cmp dword ptr es:[di + 4], 011d2F81Fh ;
152 cmp dword ptr es:[di + 8], 0A0004BBAh ;
154 cmp dword ptr es:[di + 0ch], 03BC93EC9h ;
157 mov eax, dword ptr es:[di + 32] ; EAX = StartingLBA (Low)
158 mov edx, dword ptr es:[di + 36] ; EDX = StartingLBA (High)
159 mov di, 07C00h ; Read to 0x0000:0x7C00
160 mov bx, 1 ; Read 1 Block
163 ; ****************************************************************************
164 ; Transfer control to BootSector - Jump to 0x0000:0x7C00
165 ; ****************************************************************************
167 push ax ; PUSH 0x0000
169 push di ; PUSH 0x7C00
170 retf ; JMP 0x0000:0x7C00
172 ; ****************************************************************************
173 ; ReadBlocks - Reads a set of blocks from a block device
175 ; EDX:EAX = Start LBA
176 ; BX = Number of Blocks to Read (must < 127)
177 ; ES:DI = Buffer to store sectors read from disk
178 ; ****************************************************************************
180 ; si = DiskAddressPacket
187 mov bp, 0600h ; bp = 0x600
188 lea si, [bp + OFFSET AddressPacket] ; DS:SI = Disk Address Packet
189 mov BYTE PTR ds:[si+2],bl ; 02 = Number Of Block transfered
190 mov WORD PTR ds:[si+4],di ; 04 = Transfer Buffer Offset
191 mov WORD PTR ds:[si+6],es ; 06 = Transfer Buffer Segment
192 mov DWORD PTR ds:[si+8],eax ; 08 = Starting LBA (Low)
193 mov DWORD PTR ds:[si+0ch],edx ; 0C = Starting LBA (High)
194 mov ah, 42h ; ah = Function 42
195 mov dl,byte ptr [bp+PhysicalDrive] ; dl = Drive Number
202 ; ****************************************************************************
203 ; Address Packet used by ReadBlocks
204 ; ****************************************************************************
206 db 10h ; Size of address packet
207 db 00h ; Reserved. Must be 0
208 db 01h ; Read blocks at a time (To be fixed each times)
209 db 00h ; Reserved. Must be 0
210 dw 0000h ; Destination Address offset (To be fixed each times)
211 dw 0000h ; Destination Address segment (To be fixed each times)
213 dd 0h, 0h ; Start LBA (To be fixed each times)
216 ; ****************************************************************************
218 ; ****************************************************************************
225 lea si, cs:[ErrorString]
233 db 'G', 0ch, 'P', 0ch, 'T', 0ch, ' ', 0ch, 'S', 0ch, 't', 0ch, 'a', 0ch, 'r', 0ch, 't', 0ch, '!', 0ch
235 db 'G', 0ch, 'P', 0ch, 'T', 0ch, ' ', 0ch, 'E', 0ch, 'r', 0ch, 'r', 0ch, 'o', 0ch, 'r', 0ch, '!', 0ch
237 ; ****************************************************************************
238 ; PhysicalDrive - Used to indicate which disk to be boot
239 ; Can be patched by tool
240 ; ****************************************************************************
244 ; ****************************************************************************
245 ; GptPartitionIndicator - Used to indicate which GPT partition to be boot
246 ; Can be patched by tool
247 ; ****************************************************************************
249 GptPartitionIndicator db 0
251 ; ****************************************************************************
252 ; Unique MBR signature
253 ; ****************************************************************************
257 ; ****************************************************************************
259 ; ****************************************************************************
263 ; ****************************************************************************
264 ; PMBR Entry - Can be patched by tool
265 ; ****************************************************************************
267 db 0 ; Boot Indicator
268 db 0ffh ; Start Header
269 db 0ffh ; Start Sector
270 db 0ffh ; Start Track
276 dd 0FFFFFFFFh ; End LBA
285 ; ****************************************************************************
287 ; ****************************************************************************
291 dw 0aa55h ; Boot Sector Signature