bootxx.S revision 1.1
1/*	$NetBSD: bootxx.S,v 1.1 2003/04/16 22:17:44 dsl Exp $	*/
2
3/*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by David Laight.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
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.
18 * 3. All advertising materials mentioning features or use of this software
19 *    must display the following acknowledgement:
20 *        This product includes software developed by the NetBSD
21 *        Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 *    contributors may be used to endorse or promote products derived
24 *    from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39#include <machine/asm.h>
40#include <sys/disklabel_mbr.h>
41
42/*
43 * Code linked to 0xa00 and copied to sectors 2+ of the netbsd boot
44 * partition by MI /usr/sbin/installboot.
45 * Read into memory by code in pbr.S
46 *
47 * On entry:
48 * 	%dl			BIOS drive number
49 *	%esi			Sector number of netbsd partition
50 *	%cs, %ds, %es, %ss	All zero
51 *	%sp			near 0xfffc
52 */
53	.text
54	.code16
55ENTRY(bootxx)
56	jmp	1f
57	.align	4
58ENTRY(bootxx_magic)
59	.long	X86_BOOT_MAGIC_1	/* checked by installboot & pbr code */
60bootparams:				/* space for patchable variables */
61	.long	1f - bootparams		/* length of this data area */
62#include "boot_params.S"
63	.space	4 * 4			/* some spare */
64
651:	call	gdt_fixup
66
67	calll	real_to_prot
68	.code32
69
70	movl	$_end, %ecx		/* zero bss */
71	movl	$__bss_start, %edi
72	subl	%edi, %ecx
73	shr	$2, %ecx		/* _end and __bss_start are aligned */
74	xor	%eax, %eax
75	rep
76	stosl
77
78	and	$0xff, %edx
79	push	%esi			/* save args for secondary bootstrap */
80	push	%edx
81	push	%esi			/* args for boot1 */
82	push	%edx
83	call	_C_LABEL(boot1)		/* C code to load /boot */
84	add	$8, %esp
85	call	prot_to_real
86	.code16
87
88	test	%ax, %ax
89	jnz	boot_fail
90
91	pop	%edx			/* bios disk number */
92	pop	%ebx			/* expected partition start sector */
93	movl	$bootparams, %esi
94	lcall	$SECONDARY_LOAD_ADDRESS/16, $0
95
96boot_fail:
97	push	%ax
98	movw	$1f, %si
99	call	message
100	pop	%si
101	call	message
102	jmp	loopstop
1031:	.asciz	"Boot failed: "
104
105ENTRY(_rtt)
106	.code32
107	call	prot_to_real
108	.code16
109loopstop:
110	movb	0x86, %ah		/* delay for about a second */
111	movw	$16, %cx
112	int	$0x15
113	int	$0x18			/* might be a boot fail entry */
1141:	sti
115	hlt
116	jmp	1b
117
118	/*
119	 * Vector the fs calls through here so we can support multiple
120	 * file system types with one copy of the library code and
121	 * multiple copies of this file.
122	 */
123	.global	xxfs_open, xxfs_close, xxfs_read, xxfs_stat
124	.code32
125xxfs_open:	jmp	XXfs_open
126xxfs_close:	jmp	XXfs_close
127xxfs_read:	jmp	XXfs_read
128xxfs_stat:	jmp	XXfs_stat
129