2 * GRUB -- GRand Unified Bootloader
3 * Copyright (C) 1994-2002 H. Peter Anvin
4 * Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc.
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; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 Most of this file was originally "isolinux.asm" from SYSLINUX package.
24 It has been very heavily modified.
33 #include "stage2_size.h"
38 This makes the assembler generate the address without support
39 from the linker. (ELF can't relocate 16-bit addresses!) */
40 #define ABS(x) (x-_start+BOOTSEC_LOCATION)
43 # define STAGE_ADDR 0x2000
45 # define STAGE_ADDR 0x8000
48 /* Print message string */
49 #define MSG(x) mov $ABS(x), %si; call message;
51 .file "start_eltorito.S"
55 /* Tell GAS to generate 16-bit instructions so that this code works
62 * Primary entry point. Because BIOSes are buggy, we only load the first
63 * CD-ROM sector (2K) of the file, so the number one priority is actually
69 ljmp $0, $ABS(real_start)
71 . = _start + 8 /* Pad to file offset 8 */
73 /* This table gets filled in by mkisofs using the
74 -boot-info-table option */
75 bi_pvd: .long 0xDEADBEEF /* LBA of primary volume descript */
76 bi_file: .long 0xDEADBEEF /* LBA of boot file */
77 bi_length: .long 0xDEADBEEF /* Length of boot file */
78 bi_csum: .long 0xDEADBEEF /* Checksum of boot file */
79 bi_reserved: .space (10*4) /* Reserved */
88 mov $STAGE1_STACKSEG, %sp /* set up the REAL stack */
92 /* save drive reference first thing! */
93 mov %dl, ABS(BootDrive)
95 /* print a notification message on the screen */
96 MSG(notification_string)
99 /* Set up boot file sector, size, load address */
100 mov ABS(bi_length), %eax
101 add $(ISO_SECTOR_SIZE-1), %eax
102 shr $ISO_SECTOR_BITS, %eax /* dwords->sectors */
103 mov %ax, %bp /* boot file sectors */
104 mov $(STAGE_ADDR >> 4), %bx
107 mov ABS(bi_file), %eax
112 MSG(notification_done)
114 /* save the sector number of the second sector in %ebp */
115 mov $ABS(firstlist - BOOTSEC_LISTSIZE), %si
117 mov ABS(BootDrive), %dl /* this makes sure %dl is our "boot" drive */
118 ljmp $0, $(STAGE_ADDR+SECTOR_SIZE) /* jump to main() in asm.S */
120 /* go here when you need to stop the machine hard after an error condition */
125 * Get linear sectors - EBIOS LBA addressing, 2048-byte sectors.
127 * Note that we can't always do this as a single request, because at least
128 * Phoenix BIOSes has a 127-sector limit. To be on the safe side, stick
129 * to 16 sectors (32K) per request.
132 * EAX - Linear sector number
133 * ES:BX - Target buffer
137 mov $ABS(dapa), %si /* Load up the DAPA */
145 cmp ABS(MaxTransfer), %bp
147 mov ABS(MaxTransfer), %bp
150 mov ABS(BootDrive), %dl
151 mov $0x42, %ah /* Extended Read */
155 movzwl 2(%si), %eax /* Sectors we read */
156 add %eax, 8(%si) /* Advance sector pointer */
157 sub %ax, %bp /* Sectors left */
158 shl $(ISO_SECTOR_BITS-4), %ax /* 2048-byte sectors -> segment */
159 add %ax, 6(%si) /* Advance buffer pointer */
162 MSG(notification_step)
166 mov 8(%si), %eax /* Return next sector */
173 movb $6, ABS(RetryCount)
178 add $(8*4), %sp /* Clean up stack */
181 mov %ah, %dl /* Save error code */
184 mov ABS(RetryCount), %al
185 mov ABS(dapa+2), %ah /* Sector transfer count */
186 cmp $2, %al /* Only 2 attempts left */
188 mov $1, %ah /* Drop transfer size to 1 */
192 ja 3f /* First time, just try again */
193 shr $1, %ah /* Otherwise, try to reduce */
194 adc $0, %ah /* the max transfer size, but not */
196 mov %ah, ABS(MaxTransfer)
203 MSG(read_error_string)
212 * message: write the string pointed to by %si
214 * WARNING: trashes %si, %ax, and %bx
218 * Use BIOS "int 10H Function 0Eh" to write character in teletype mode
219 * %ah = 0xe %al = character
220 * %bh = page %bl = foreground color (graphics modes)
225 int $0x10 /* display a byte */
230 jne 1b /* if not end of string, jmp to display */
234 * printhex[248]: Write a hex number in (AL, AX, EAX) to the console
255 .low: add $('0'), %al
257 .high: add $('A'-10), %al
261 int $0x10 /* display a char */
267 /**************************************************************************/
269 notification_string: .string "Loading stage1.5 "
271 notification_string: .string "Loading stage2 "
274 notification_step: .string "."
275 notification_done: .string "\r\n"
277 read_error_string: .string "Read error 0x"
280 * EBIOS disk address packet
283 dapa: .byte 16 /* Packet size */
284 .byte 0 /* reserved */
285 .word 0 /* +2 Block count */
286 .word 0 /* +4 Offset of buffer */
287 .word 0 /* +6 Segment of buffer */
288 .long 0 /* +8 LBA (LSW) */
289 .long 0 /* +C LBA (MSW) */
293 VARIABLE(MaxTransfer)
294 .word 16 /* Max sectors per transfer (32Kb) */
300 * This area is an empty space between the main body of code below which
301 * grows up (fixed after compilation, but between releases it may change
302 * in size easily), and the lists of sectors to read, which grows down
303 * from a fixed top location.
309 . = _start + SECTOR_SIZE - BOOTSEC_LISTSIZE
311 /* fill the first data listing with the default */
312 blocklist_default_start:/* this is the sector start parameter, in logical
313 sectors from the start of the disk, sector 0 */
316 blocklist_default_len: /* this is the number of sectors to read */
320 .word (STAGE2_SIZE + ISO_SECTOR_SIZE - 1) >> ISO_SECTOR_BITS
322 blocklist_default_seg: /* this is the segment of the starting address
323 to load the data into */
324 .word (STAGE_ADDR + SECTOR_SIZE) >> 4
326 firstlist: /* this label has to be after the list data!!! */