1 /* -----------------------------------------------------------------------
3 * Copyright 2007-2009 H. Peter Anvin - All Rights Reserved
4 * Copyright 2009 Intel Corporation; author: H. Peter Anvin
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software and associated documentation
8 * files (the "Software"), to deal in the Software without
9 * restriction, including without limitation the rights to use,
10 * copy, modify, merge, publish, distribute, sublicense, and/or
11 * sell copies of the Software, and to permit persons to whom
12 * the Software is furnished to do so, subject to the following
15 * The above copyright notice and this permission notice shall
16 * be included in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
20 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
22 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
23 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
27 * ----------------------------------------------------------------------- */
30 * Modified MBR code used on an ISO image in hybrid mode.
32 * This doesn't follow the El Torito spec at all -- it is just a stub
33 * loader of a hard-coded offset, but that's good enough to load
42 HYBRID_MAGIC = 0x7078c0fb
43 isolinux_hybrid_signature = 0x7c00+64
44 isolinux_start_hybrid = 0x7c00+64+4
47 /* Important: the top 6 words on the stack are passed to isolinux.bin */
49 partoffset = (stack-8)
53 ebios_flag = (stack-20)
54 secpercyl = (stack-24)
59 /* gas/ld has issues with doing this as absolute addresses... */
60 .section ".bootsec", "a", @nobits
76 /* Check to see if we have a partition table entry */
79 #ifdef PARTITION_SUPPORT
80 andw %si, %si /* %si == 0 -> no partition data */
82 testb $0x7f, (%si) /* Invalid active flag field? */
84 cmpb %cl, 4(%si) /* Partition type zero == invalid? */
86 cmpl $0x58504721, %eax /* !GPT signature in EAX? */
88 cmpb $0xed, 4(%si) /* EFI partition type? */
91 /* We have GPT partition information */
92 movl (32+20)(%si), %ecx
93 movl (36+20)(%si), %ebx
96 /* We have non-GPT partition information */
101 /* We have no partition information */
102 pushl %ebx /* -4: partoffset_hi */
103 pushl %ecx /* -8: partoffset_lo */
104 pushw %es /* -10: es:di -> $PnP header */
105 pushw %di /* -12: es:di -> $PnP header */
111 pushw %dx /* -14: dl -> drive number */
113 /* Copy down to 0:0x600 */
122 /* Check to see if we have EBIOS */
123 pushw %dx /* drive number */
124 movb $0x41, %ah /* %al == 0 already */
133 andw $1,%cx /* Bit 0 = fixed disk subset */
136 /* We have EBIOS; patch in the following code at
137 read_sector_cbios: movb $0x42, %ah ; jmp read_common */
138 movl $0xeb42b4+((read_common-read_sector_cbios-4) << 24), \
143 pushw %cx /* EBIOS flag */
145 /* Get (C)HS geometry */
148 andw $0x3f, %cx /* Sector count */
149 popw %bx /* EBIOS flag */
150 pushw %cx /* -16: Save sectors on the stack */
151 movzbw %dh, %ax /* dh = max head */
152 incw %ax /* From 0-based max to count */
153 pushw %ax /* -18: Save heads on the stack */
154 mulw %cx /* Heads*sectors -> sectors per cylinder */
156 pushw %bx /* -20: EBIOS flag */
158 /* Save sectors/cylinder on the stack */
159 pushw %dx /* -22: High word */
160 pushw %ax /* -24: Low word */
163 * Load sectors. We do this one at a time mostly to avoid
164 * pitfalls and to share code with the stock MBR code.
167 movw $4, %cx /* Sector count */
168 movl (lba_offset), %eax
174 addb $(512 >> 8), %bh
178 * Okay, that actually worked... update the stack pointer
179 * and jump into isolinux.bin...
181 cmpl $HYBRID_MAGIC,(isolinux_hybrid_signature)
185 movw $ebios_flag, %sp
188 * Use a ljmpw here to work around a bug in some unknown version
189 * of gas or ld when it comes to jumping to an absolute symbol...
191 * Look more closely into it if we ever are short on space.
193 ljmpw $0, $isolinux_start_hybrid
197 .ascii "isolinux.bin missing or corrupt.\r\n"
200 * read_sector: read a single sector pointed to by %eax to %es:%bx.
201 * CF is set on error. All registers saved.
206 addl (partoffset), %eax
207 adcl (partoffset+4), %edx
208 pushl %edx /* MSW of LBA */
209 pushl %eax /* LSW of LBA */
210 pushw %es /* Buffer segment */
211 pushw %bx /* Buffer offset */
212 pushw $1 /* Sector count */
213 pushw $16 /* Size of packet */
216 /* This chunk is skipped if we have ebios */
217 /* Do not clobber %eax before this chunk! */
218 /* This also relies on %bx and %edx as set up above. */
228 incw %cx /* Sectors are 1-based */
234 leaw 16(%si), %sp /* Drop DAPA */
240 .ascii "Operating system load error.\r\n"
243 * Print error messages. This is invoked with "call", with the
244 * error message at the return address.
251 movb (BIOS_page), %bh
253 int $0x10 /* May destroy %bp */
254 cmpb $10, %al /* Newline? */
257 int $0x18 /* Boot failure */
262 /* Address of pointer to isolinux.bin */
263 lba_offset = _start+432