1 #------------------------------------------------------------------------------
\r
3 #* Copyright 2006 - 2007, Intel Corporation
\r
4 #* All rights reserved. This program and the accompanying materials
\r
5 #* are licensed and made available under the terms and conditions of the BSD License
\r
6 #* which accompanies this distribution. The full text of the license may be found at
\r
7 #* http://opensource.org/licenses/bsd-license.php
\r
9 #* THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
\r
10 #* WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
\r
16 #------------------------------------------------------------------------------
\r
18 .equ BLOCK_SIZE, 0x0200
\r
19 .equ BLOCK_MASK, 0x01ff
\r
22 # ****************************************************************************
\r
23 # Code loaded by BIOS at 0x0000:0x7C00
\r
24 # ****************************************************************************
\r
31 # ****************************************************************************
\r
33 # ****************************************************************************
\r
39 leaw %cs:StartString, %si
\r
45 # ****************************************************************************
\r
47 # ****************************************************************************
\r
49 # ****************************************************************************
\r
50 # Initialize segment registers and copy code at 0x0000:0x7c00 to 0x0000:0x0600
\r
51 # ****************************************************************************
\r
52 xorw %ax, %ax # AX = 0x0000
\r
53 movw $0x7c00, %bx # BX = 0x7C00
\r
54 movw $0x600, %bp # BP = 0x0600
\r
55 movw RelocatedStart, %si # SI = Offset(RelocatedStart)
\r
56 movw $0x200, %cx # CX = 0x0200
\r
57 subw %si, %cx # CS = 0x0200 - Offset(RelocatedStart)
\r
58 leaw (%bp,%si,), %di # DI = 0x0600 + Offset(RelocatedStart)
\r
59 leaw (%bx,%si,), %si # BX = 0x7C00 + Offset(RelocatedStart)
\r
60 movw %ax, %ss # SS = 0x0000
\r
61 movw %bx, %sp # SP = 0x7C00
\r
62 movw %ax, %es # ES = 0x0000
\r
63 movw %ax, %ds # DS = 0x0000
\r
64 pushw %ax # PUSH 0x0000
\r
65 pushw %di # PUSH 0x0600 + Offset(RelocatedStart)
\r
66 cld # Clear the direction flag
\r
68 movsb # Copy 0x0200 bytes from 0x7C00 to 0x0600
\r
69 retl # JMP 0x0000:0x0600 + Offset(RelocatedStart)
\r
71 # ****************************************************************************
\r
72 # Code relocated to 0x0000:0x0600
\r
73 # ****************************************************************************
\r
76 # ****************************************************************************
\r
77 # Get Driver Parameters to 0x0000:0x7BFC
\r
78 # ****************************************************************************
\r
80 xorw %ax, %ax # AX = 0
\r
81 movw %ax, %ss # SS = 0
\r
85 movw $0x7c00, %sp # SP = 0x7c00
\r
86 movw %sp, %bp # BP = 0x7c00
\r
88 movb $8, %ah # AH = 8 - Get Drive Parameters Function
\r
89 movb %dl, PhysicalDrive(%bp) # BBS defines that BIOS would pass the booting driver number to the loader through DL
\r
90 int $0x13 # Get Drive Parameters
\r
91 xorw %ax, %ax # AX = 0
\r
92 movb %dh, %al # AL = DH
\r
93 incb %al # MaxHead = AL + 1
\r
94 pushw %ax # 0000:7bfe = MaxHead
\r
95 movb %cl, %al # AL = CL
\r
96 andb $0x3f, %al # MaxSector = AL & 0x3f
\r
97 pushw %ax # 0000:7bfc = MaxSector
\r
99 # ****************************************************************************
\r
100 # Read Target DBR from hard disk to 0x0000:0x7C00
\r
101 # ****************************************************************************
\r
104 movb MbrPartitionIndicator(%bp), %al # AX = MbrPartitionIndex
\r
105 cmpb $0xff, %al # 0xFF means do legacy MBR boot
\r
108 movl $0x0000600, %eax # Assume LegacyMBR is backuped in Sector 6
\r
109 jmp StartReadTo7C00 # EAX = Header/Sector/Tracker/Zero
\r
112 cmpb $4, %al # MbrPartitionIndex should < 4
\r
114 shlw $4, %ax # AX = MBREntrySize * Index
\r
115 addw $0x1be, %ax # AX = MBREntryOffset
\r
116 movw %ax, %di # DI = MBREntryOffset
\r
118 # Here we don't use the C/H/S information provided by Partition table
\r
119 # but calculate C/H/S from LBA ourselves
\r
120 # Ci: Cylinder number
\r
121 # Hi: Header number
\r
122 # Si: Sector number
\r
123 movl %es:8(%bp,%di,), %eax # Start LBA
\r
125 shrl $16, %edx # DX:AX = Start LBA
\r
126 # = Ci * (H * S) + Hi * S + (Si - 1)
\r
128 # Calculate C/H/S according to LBA
\r
130 divw 2(%bp) # AX = Hi + H*Ci
\r
133 pushw %dx # 0000:7bfa = Si <----
\r
134 xorw %dx, %dx # DX:AX = Hi + H*Ci
\r
135 divw 4(%bp) # AX = Ci <----
\r
140 movb (%bp), %cl # Si
\r
141 movb %al, %ch # Ci[0-7]
\r
142 orb %ah, %cl # Ci[8,9]
\r
143 movw $0x7c00, %bx # ES:BX = 0000:7C00h
\r
144 movb $0x2, %ah # Function 02h
\r
145 movb $1, %al # 1 Sector
\r
148 movb PhysicalDrive(%bp), %dl # Drive number
\r
154 # ****************************************************************************
\r
155 # Transfer control to BootSector - Jump to 0x0000:0x7C00
\r
156 # ****************************************************************************
\r
158 pushw %ax # PUSH 0x0000 - Segment
\r
160 pushw %di # PUSH 0x7C00 - Offset
\r
161 retl # JMP 0x0000:0x7C00
\r
163 # ****************************************************************************
\r
165 # ****************************************************************************
\r
173 leaw %cs:ErrorString, %si
\r
186 .byte 'M', 0x0c, 'B', 0x0c, 'R', 0x0c, ' ', 0x0c, 'S', 0x0c, 't', 0x0c, 'a', 0x0c, 'r', 0x0c, 't', 0x0c, '!', 0x0c
\r
188 .byte 'M', 0x0c, 'B', 0x0c, 'R', 0x0c, ' ', 0x0c, 'E', 0x0c, 'r', 0x0c, 'r', 0x0c, ':', 0x0c, '?', 0x0c, '?', 0x0c
\r
190 # ****************************************************************************
\r
191 # A2C - convert Ascii code stored in AH to character stored in AX
\r
192 # ****************************************************************************
\r
212 # ****************************************************************************
\r
213 # PhysicalDrive - Used to indicate which disk to be boot
\r
214 # Can be patched by tool
\r
215 # ****************************************************************************
\r
217 PhysicalDrive: .byte 0x80
\r
219 # ****************************************************************************
\r
220 # MbrPartitionIndicator - Used to indicate which MBR partition to be boot
\r
221 # Can be patched by tool
\r
222 # OxFF means boot to legacy MBR. (LBA OFFSET 6)
\r
223 # ****************************************************************************
\r
225 MbrPartitionIndicator: .byte 0
\r
227 # ****************************************************************************
\r
228 # Unique MBR signature
\r
229 # ****************************************************************************
\r
233 # ****************************************************************************
\r
235 # ****************************************************************************
\r
239 # ****************************************************************************
\r
240 # MBR Entry - To be patched
\r
241 # ****************************************************************************
\r
251 # ****************************************************************************
\r
253 # ****************************************************************************
\r
257 .word 0xaa55 # Boot Sector Signature
\r