mboot.S revision 9b79392525856301c6f8962f189c2a32242af618
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2012 OmniTI Computer Consulting, Inc. All rights reserved.
*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/*
* SOLARIS MASTER BOOT:
*
* PURPOSE: loads the primary boot from the active fdisk partition.
* in effect, this routine mimics the functionality of INT 0x19.
*
* resides on the first physical sector of the hard drive media.
* loaded by INT 0x19 (ROM bootstrap loader) at address 0x7C00
* limited to 512 bytes total, including embedded fdisk table.
*
* for compatibility with the ROM BIOS, we contain standard DOS structures:
*
* the fdisk partition table (at offset 0x1BE-0x1FE)
* boot signature bytes (0x55, 0xAA at 0x1FE, 0x1FF)
*
* the above two entities are required in order to be compatible with
* the manner in which the DOS BIOS has always performed its boot operation.
* In the event that our master boot record is inadvertently replaced by
* a standard DOS boot sector, the booting operation will still succeed!
*
* table entry, to compute the start of the active partition; therefore,
* it is geometry independent. This means that the drive could be "built"
* on a system with a disk controller that uses a given disk geometry, but
* would run on any other controller.
*
* SYNOPSIS:
* begins execution at 0:0x7C00
* relocates to 0:0x600 (to get out of the way!)
* reads fdisk table to locate bootable partition
* load boot record from the active fdisk partition at 0x7C00
* verify boot record signature bytes
* error handler - can either reboot, or invoke INT 0x18.
*
* interface from DOS INT 0x19: BootDev in DL
* (this fails sometimes, so we look for a signature to determine whether
* to rely on DL from the floppy boot, or if we should assume 0x80 from
* the BIOS)
*
* interface to partition boot: BootDev in DL
*
*=============================================================================
* Master boot record: resides on first physical sector of device
*/
/*
* This file is written in GNU as syntax using Intel assembler syntax. The
* startup label _start will be executed at address PBOOT_ADDR (0x7C00), but
* the text section must be set at address RELOC_ADDR (0x600). With GNU ld
* this can be done using the "-Ttext 600" option.
*/
#define PBOOT_ADDR 0x7C00
#define RELOC_ADDR 0x600
#define FDISK_START 0x1BE
#define BOOT_SIG 0xAA55
#define N_RETRIES 5
#define FD_NUMPART 4
#define FD_PTESIZE 0x10
#define ACTIVE 0x80
/*
* A convenience macro for declaring a message string (using .ascii directive--
* NOT nul-terminated) surrounded by two labels, which can then be used with
* the SIZEOF() macro to get its length.
*/
/*
* Returns the length of some consecutive bytes. These bytes must be placed
* between two labels. The ending label must be the same as the starting label
* but with a suffix "_end".
*/
.title "Solaris_Master_Boot"
.code16 /* 16-bit mode (real mode) */
.text /* code segment begins here */
_start: /* _start is loaded at PBOOT_ADDR */
cli /* don't bother me now! */
/* prepare to relocate ourselves */
cld /* prepare for relocation */
/* set up segment registers */
/* running at PBOOT_ADDR, jump to RELOC_ADDR-rel addr */
sti /* re-enable interrupts */
/*
* assuming boot device number is in dl has caused problems in the past
* since we still don't absolutely have to rely on it, I've just
* removed the now-pointless code to check for the FACE-CAFE signature
* from mdexec, which doesn't do anything anymore, but left the
* assumption that BootDev is 0x80 and nothing but. If we ever need to
* have BIOS load us from a drive not numbered 0x80, we'll need to
* uncomment the following line; otherwise, the initialized value of
* BootDev, namely 0x80, will be used for disk accesses.
*/
/* mov BootDev, dl */
/* set debug flag based on seeing "both shift down" */
int 0x16
/*
* Search the fdisk table sequentially to find a physical partition
* that is marked as "active" (bootable).
*/
int 0x13
/* Check for LBA BIOS */
int 0x13
/*
* LBA case: form a packet on the stack and call fn 0x42 to read
* packet, backwards (from hi to lo addresses):
* 8-byte LBA
* seg:ofs buffer address
* byte reserved
* byte nblocks
* byte reserved
* packet size in bytes (>= 0x10)
*/
pushd 0 /* hi 32 bits of 64-bit sector number */
int 0x13
lahf /* save flags */
sahf /* restore flags */
int 0x13
/* get BIOS disk parameters */
int 0x13
/* error reading geom; die */
/* calculate sectors per track */
/* calculate sectors per cylinder */
/* calculate cylinder # */
/* dx = sect in cyl (0 - cylsize-1) */
/* ah = 0-rel sect in track */
int 0x13
int 0x13
/* verify boot record signature */
fatal_err: /* land of no return....... */
/*
* bp contains pointer to error message string,
* cx contains string length
*/
int 0x18
/* call with string pointer in es:bp, len in cx */
/* alternate entry for fatal_err */
int 0x10
int 0x10
int 0x16
.byte 0
.word 0
.long PBOOT_ADDR
.byte 0
/*
* For debugging: Here's a representative FDISK table entry
*
* .org 0x1BE
* .byte 0x80,1,1,0,0x82,0xfe,0x7f,4,0x3f,0,0,0,0x86,0xfa,0x3f,0
*/
.org 0x1FE