1N/A/*
1N/A * GRUB -- GRand Unified Bootloader
1N/A * Copyright (C) 1994-2002 H. Peter Anvin
1N/A * Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc.
1N/A *
1N/A * This program is free software; you can redistribute it and/or modify
1N/A * it under the terms of the GNU General Public License as published by
1N/A * the Free Software Foundation; either version 2 of the License, or
1N/A * (at your option) any later version.
1N/A *
1N/A * This program is distributed in the hope that it will be useful,
1N/A * but WITHOUT ANY WARRANTY; without even the implied warranty of
1N/A * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1N/A * GNU General Public License for more details.
1N/A *
1N/A * You should have received a copy of the GNU General Public License
1N/A * along with this program; if not, write to the Free Software
1N/A * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1N/A *
1N/A */
1N/A
1N/A/*
1N/A Most of this file was originally "isolinux.asm" from SYSLINUX package.
1N/A It has been very heavily modified.
1N/A*/
1N/A
1N/A#define ASM_FILE
1N/A#include "stage1.h"
1N/A#include "shared.h"
1N/A#include "iso9660.h"
1N/A
1N/A#ifndef STAGE1_5
1N/A#include "stage2_size.h"
1N/A#endif
1N/A
1N/A
1N/A /* Absolute addresses
1N/A This makes the assembler generate the address without support
1N/A from the linker. (ELF can't relocate 16-bit addresses!) */
1N/A#define ABS(x) (x-_start+BOOTSEC_LOCATION)
1N/A
1N/A#ifdef STAGE1_5
1N/A# define STAGE_ADDR 0x2000
1N/A#else
1N/A# define STAGE_ADDR 0x8000
1N/A#endif /* STAGE1_5 */
1N/A
1N/A /* Print message string */
1N/A#define MSG(x) mov $ABS(x), %si; call message;
1N/A
1N/A .file "start_eltorito.S"
1N/A
1N/A .text
1N/A
1N/A /* Tell GAS to generate 16-bit instructions so that this code works
1N/A in real mode. */
1N/A .code16
1N/A
1N/A .globl start, _start
1N/A
1N/A/*
1N/A * Primary entry point. Because BIOSes are buggy, we only load the first
1N/A * CD-ROM sector (2K) of the file, so the number one priority is actually
1N/A * loading the rest.
1N/A */
1N/Astart:
1N/A_start:
1N/A cli
1N/A ljmp $0, $ABS(real_start)
1N/A
1N/A . = _start + 8 /* Pad to file offset 8 */
1N/A
1N/A /* This table gets filled in by mkisofs using the
1N/A -boot-info-table option */
1N/Abi_pvd: .long 0xDEADBEEF /* LBA of primary volume descript */
1N/Abi_file: .long 0xDEADBEEF /* LBA of boot file */
1N/Abi_length: .long 0xDEADBEEF /* Length of boot file */
1N/Abi_csum: .long 0xDEADBEEF /* Checksum of boot file */
1N/Abi_reserved: .space (10*4) /* Reserved */
1N/A
1N/Areal_start:
1N/A xor %ax, %ax
1N/A mov %ax, %ss
1N/A mov %ax, %ds
1N/A mov %ax, %es
1N/A mov %ax, %fs
1N/A mov %ax, %gs
1N/A mov $STAGE1_STACKSEG, %sp /* set up the REAL stack */
1N/A sti
1N/A cld
1N/A
1N/A /* save drive reference first thing! */
1N/A mov %dl, ABS(BootDrive)
1N/A
1N/A /* print a notification message on the screen */
1N/A MSG(notification_string)
1N/A
1N/Aload_image:
1N/A /* Set up boot file sector, size, load address */
1N/A mov ABS(bi_length), %eax
1N/A add $(ISO_SECTOR_SIZE-1), %eax
1N/A shr $ISO_SECTOR_BITS, %eax /* dwords->sectors */
1N/A mov %ax, %bp /* boot file sectors */
1N/A mov $(STAGE_ADDR >> 4), %bx
1N/A mov %bx, %es
1N/A xor %bx, %bx
1N/A mov ABS(bi_file), %eax
1N/A call getlinsec
1N/A mov %ds, %ax
1N/A mov %ax, %es
1N/A
1N/A MSG(notification_done)
1N/Abootit:
1N/A /* save the sector number of the second sector in %ebp */
1N/A mov $ABS(firstlist - BOOTSEC_LISTSIZE), %si
1N/A mov (%si), %ebp
1N/A mov ABS(BootDrive), %dl /* this makes sure %dl is our "boot" drive */
1N/A ljmp $0, $(STAGE_ADDR+SECTOR_SIZE) /* jump to main() in asm.S */
1N/A
1N/A/* go here when you need to stop the machine hard after an error condition */
1N/Astop: jmp stop
1N/A
1N/A
1N/A/*
1N/A * Get linear sectors - EBIOS LBA addressing, 2048-byte sectors.
1N/A *
1N/A * Note that we can't always do this as a single request, because at least
1N/A * Phoenix BIOSes has a 127-sector limit. To be on the safe side, stick
1N/A * to 16 sectors (32K) per request.
1N/A *
1N/A * Input:
1N/A * EAX - Linear sector number
1N/A * ES:BX - Target buffer
1N/A * BP - Sector count
1N/A */
1N/Agetlinsec:
1N/A mov $ABS(dapa), %si /* Load up the DAPA */
1N/A mov %bx, 4(%si)
1N/A mov %es, %bx
1N/A mov %bx, 6(%si)
1N/A mov %eax, 8(%si)
1N/A1:
1N/A push %bp
1N/A push %si
1N/A cmp ABS(MaxTransfer), %bp
1N/A jbe 2f
1N/A mov ABS(MaxTransfer), %bp
1N/A2:
1N/A mov %bp, 2(%si)
1N/A mov ABS(BootDrive), %dl
1N/A mov $0x42, %ah /* Extended Read */
1N/A call xint13
1N/A pop %si
1N/A pop %bp
1N/A movzwl 2(%si), %eax /* Sectors we read */
1N/A add %eax, 8(%si) /* Advance sector pointer */
1N/A sub %ax, %bp /* Sectors left */
1N/A shl $(ISO_SECTOR_BITS-4), %ax /* 2048-byte sectors -> segment */
1N/A add %ax, 6(%si) /* Advance buffer pointer */
1N/A
1N/A pushal
1N/A MSG(notification_step)
1N/A popal
1N/A cmp $0, %bp
1N/A ja 1b
1N/A mov 8(%si), %eax /* Return next sector */
1N/A ret
1N/A
1N/A/*
1N/A * INT 13h with retry
1N/A */
1N/Axint13:
1N/A movb $6, ABS(RetryCount)
1N/A.try:
1N/A pushal
1N/A int $0x13
1N/A jc 1f
1N/A add $(8*4), %sp /* Clean up stack */
1N/A ret
1N/A1:
1N/A mov %ah, %dl /* Save error code */
1N/A decb ABS(RetryCount)
1N/A jz .real_error
1N/A mov ABS(RetryCount), %al
1N/A mov ABS(dapa+2), %ah /* Sector transfer count */
1N/A cmp $2, %al /* Only 2 attempts left */
1N/A ja 2f
1N/A mov $1, %ah /* Drop transfer size to 1 */
1N/A jmp .setmaxtr
1N/A2:
1N/A cmp $3, %al
1N/A ja 3f /* First time, just try again */
1N/A shr $1, %ah /* Otherwise, try to reduce */
1N/A adc $0, %ah /* the max transfer size, but not */
1N/A.setmaxtr:
1N/A mov %ah, ABS(MaxTransfer)
1N/A mov %ah, ABS(dapa+2)
1N/A3:
1N/A popal
1N/A jmp .try
1N/A
1N/A.real_error:
1N/A MSG(read_error_string)
1N/A mov %dl, %al
1N/A call printhex2
1N/A popal
1N/A jmp stop
1N/A
1N/A
1N/A
1N/A/*
1N/A * message: write the string pointed to by %si
1N/A *
1N/A * WARNING: trashes %si, %ax, and %bx
1N/A */
1N/A
1N/A /*
1N/A * Use BIOS "int 10H Function 0Eh" to write character in teletype mode
1N/A * %ah = 0xe %al = character
1N/A * %bh = page %bl = foreground color (graphics modes)
1N/A */
1N/A1:
1N/A mov $0x0001, %bx
1N/A mov $0x0E, %ah
1N/A int $0x10 /* display a byte */
1N/A
1N/Amessage:
1N/A lodsb
1N/A or %al, %al
1N/A jne 1b /* if not end of string, jmp to display */
1N/A ret
1N/A
1N/A/*
1N/A * printhex[248]: Write a hex number in (AL, AX, EAX) to the console
1N/A */
1N/Aprinthex2:
1N/A pushal
1N/A rol $24, %eax
1N/A mov $2, %cx
1N/A jmp 1f
1N/Aprinthex4:
1N/A pushal
1N/A rol $16, %eax
1N/A mov $4, %cx
1N/A jmp 1f
1N/Aprinthex8:
1N/A pushal
1N/A mov $8, %cx
1N/A1:
1N/A rol $4, %eax
1N/A push %eax
1N/A and $0x0F, %al
1N/A cmp $10, %al
1N/A jae .high
1N/A.low: add $('0'), %al
1N/A jmp 2f
1N/A.high: add $('A'-10), %al
1N/A2:
1N/A mov $0x0001, %bx
1N/A mov $0x0E, %ah
1N/A int $0x10 /* display a char */
1N/A pop %eax
1N/A loop 1b
1N/A popal
1N/A ret
1N/A
1N/A/**************************************************************************/
1N/A#ifdef STAGE1_5
1N/Anotification_string: .string "Loading stage1.5 "
1N/A#else
1N/Anotification_string: .string "Loading stage2 "
1N/A#endif
1N/A
1N/Anotification_step: .string "."
1N/Anotification_done: .string "\r\n"
1N/A
1N/Aread_error_string: .string "Read error 0x"
1N/A
1N/A/*
1N/A * EBIOS disk address packet
1N/A */
1N/A .align 8
1N/Adapa: .byte 16 /* Packet size */
1N/A .byte 0 /* reserved */
1N/A .word 0 /* +2 Block count */
1N/A .word 0 /* +4 Offset of buffer */
1N/A .word 0 /* +6 Segment of buffer */
1N/A .long 0 /* +8 LBA (LSW) */
1N/A .long 0 /* +C LBA (MSW) */
1N/A
1N/AVARIABLE(BootDrive)
1N/A .byte 0xFF
1N/AVARIABLE(MaxTransfer)
1N/A .word 16 /* Max sectors per transfer (32Kb) */
1N/AVARIABLE(RetryCount)
1N/A .byte 0
1N/A
1N/A
1N/A/*
1N/A * This area is an empty space between the main body of code below which
1N/A * grows up (fixed after compilation, but between releases it may change
1N/A * in size easily), and the lists of sectors to read, which grows down
1N/A * from a fixed top location.
1N/A */
1N/A
1N/A .word 0
1N/A .word 0
1N/A
1N/A . = _start + SECTOR_SIZE - BOOTSEC_LISTSIZE
1N/A
1N/A /* fill the first data listing with the default */
1N/Ablocklist_default_start:/* this is the sector start parameter, in logical
1N/A sectors from the start of the disk, sector 0 */
1N/A .long 0
1N/A
1N/Ablocklist_default_len: /* this is the number of sectors to read */
1N/A#ifdef STAGE1_5
1N/A .word 0
1N/A#else
1N/A .word (STAGE2_SIZE + ISO_SECTOR_SIZE - 1) >> ISO_SECTOR_BITS
1N/A#endif
1N/Ablocklist_default_seg: /* this is the segment of the starting address
1N/A to load the data into */
1N/A .word (STAGE_ADDR + SECTOR_SIZE) >> 4
1N/A
1N/Afirstlist: /* this label has to be after the list data!!! */