1 /* $NetBSD: biosboot.S,v 1.8 2011/01/05 23:13:01 jakllsch Exp $ */
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <machine/asm.h>
33 #include <sys/bootblock.h>
36 * Code linked to 0x1000:0 and (usually) read from /boot by bootxx code
39 * %dl BIOS drive number
40 * %ecx:%ebx Sector number of NetBSD partition
41 * %ds:%si Boot parameter block (patched by installboot)
43 * %ds, %es, %ss All zero
53 .long X86_BOOT_MAGIC_2 /* checked for by bootxx code */
55 .long boot_start_1 - boot_params
56 #include <boot_params.S>
57 . = boot_start + 0x80 /* space for patchable variables */
61 /* Allow for boot_start not being %cs:0 */
64 sub $2b, %cx /* %ax is offset */
65 test $0xf, %cx /* check code seg aligned */
67 lret /* not playing if not */
70 add %cx, %ax /* segment staring at boot_start */
80 movl %ecx, %ebp /* move LBA out of the way */
82 /* Grab boot_params patched into bootxx by installboot */
83 cmpl $X86_BOOT_MAGIC_1,-4(%si) /* sanity check ptr */
87 cmp $boot_start_1 - boot_params, %cx
89 mov $boot_start_1 - boot_params, %cx
96 movl $_end, %eax /* top of bss */
97 shr $4, %eax /* as a segment */
98 add $0x1001, %ax /* and + 64k */
99 mov %ax, %ss /* for stack */
100 mov $0xfffc, %sp /* %sp at top of it */
107 movl $_end, %ecx /* zero bss */
108 movl $__bss_start, %edi
110 shr $2, %ecx /* _end and __bss_start are aligned */
115 testb $X86_BP_FLAGS_LBA64VALID, boot_params+4
117 xorl %ebp, %ebp /* high part of LBA is not valid */
121 push %ebp /* high 32 bits of first sector */
122 push %ebx /* first sector of bios partition */
123 push %edx /* bios disk */
124 call _C_LABEL(boot2) /* C bootstrap code */
136 1: .asciz "Boot2 failed: "
143 movb $0x86, %ah /* delay for about a second */
146 int $0x18 /* might be a boot fail entry */