bootxx.S revision 1.3
11.3Sdsl/*	$NetBSD: bootxx.S,v 1.3 2003/10/09 10:29:39 dsl Exp $	*/
21.1Sdsl
31.1Sdsl/*-
41.1Sdsl * Copyright (c) 2003 The NetBSD Foundation, Inc.
51.1Sdsl * All rights reserved.
61.1Sdsl *
71.1Sdsl * This code is derived from software contributed to The NetBSD Foundation
81.1Sdsl * by David Laight.
91.1Sdsl *
101.1Sdsl * Redistribution and use in source and binary forms, with or without
111.1Sdsl * modification, are permitted provided that the following conditions
121.1Sdsl * are met:
131.1Sdsl * 1. Redistributions of source code must retain the above copyright
141.1Sdsl *    notice, this list of conditions and the following disclaimer.
151.1Sdsl * 2. Redistributions in binary form must reproduce the above copyright
161.1Sdsl *    notice, this list of conditions and the following disclaimer in the
171.1Sdsl *    documentation and/or other materials provided with the distribution.
181.1Sdsl * 3. All advertising materials mentioning features or use of this software
191.1Sdsl *    must display the following acknowledgement:
201.1Sdsl *        This product includes software developed by the NetBSD
211.1Sdsl *        Foundation, Inc. and its contributors.
221.1Sdsl * 4. Neither the name of The NetBSD Foundation nor the names of its
231.1Sdsl *    contributors may be used to endorse or promote products derived
241.1Sdsl *    from this software without specific prior written permission.
251.1Sdsl *
261.1Sdsl * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
271.1Sdsl * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
281.1Sdsl * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
291.1Sdsl * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
301.1Sdsl * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
311.1Sdsl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
321.1Sdsl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
331.1Sdsl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
341.1Sdsl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
351.1Sdsl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
361.1Sdsl * POSSIBILITY OF SUCH DAMAGE.
371.1Sdsl */
381.1Sdsl
391.1Sdsl#include <machine/asm.h>
401.2Slukem#include <sys/bootblock.h>
411.1Sdsl
421.1Sdsl/*
431.1Sdsl * Code linked to 0xa00 and copied to sectors 2+ of the netbsd boot
441.1Sdsl * partition by MI /usr/sbin/installboot.
451.1Sdsl * Read into memory by code in pbr.S
461.1Sdsl *
471.1Sdsl * On entry:
481.1Sdsl * 	%dl			BIOS drive number
491.1Sdsl *	%esi			Sector number of netbsd partition
501.1Sdsl *	%cs, %ds, %es, %ss	All zero
511.1Sdsl *	%sp			near 0xfffc
521.1Sdsl */
531.1Sdsl	.text
541.1Sdsl	.code16
551.1SdslENTRY(bootxx)
561.1Sdsl	jmp	1f
571.3Sdsl	.balign	4
581.1SdslENTRY(bootxx_magic)
591.1Sdsl	.long	X86_BOOT_MAGIC_1	/* checked by installboot & pbr code */
601.1Sdslbootparams:				/* space for patchable variables */
611.1Sdsl	.long	1f - bootparams		/* length of this data area */
621.3Sdsl#include <boot_params.S>
631.1Sdsl	.space	4 * 4			/* some spare */
641.1Sdsl
651.1Sdsl1:	call	gdt_fixup
661.1Sdsl
671.1Sdsl	calll	real_to_prot
681.1Sdsl	.code32
691.1Sdsl
701.1Sdsl	movl	$_end, %ecx		/* zero bss */
711.1Sdsl	movl	$__bss_start, %edi
721.1Sdsl	subl	%edi, %ecx
731.1Sdsl	shr	$2, %ecx		/* _end and __bss_start are aligned */
741.1Sdsl	xor	%eax, %eax
751.1Sdsl	rep
761.1Sdsl	stosl
771.1Sdsl
781.1Sdsl	and	$0xff, %edx
791.1Sdsl	push	%esi			/* save args for secondary bootstrap */
801.1Sdsl	push	%edx
811.1Sdsl	push	%esi			/* args for boot1 */
821.1Sdsl	push	%edx
831.1Sdsl	call	_C_LABEL(boot1)		/* C code to load /boot */
841.1Sdsl	add	$8, %esp
851.1Sdsl	call	prot_to_real
861.1Sdsl	.code16
871.1Sdsl
881.1Sdsl	test	%ax, %ax
891.1Sdsl	jnz	boot_fail
901.1Sdsl
911.1Sdsl	pop	%edx			/* bios disk number */
921.1Sdsl	pop	%ebx			/* expected partition start sector */
931.1Sdsl	movl	$bootparams, %esi
941.1Sdsl	lcall	$SECONDARY_LOAD_ADDRESS/16, $0
951.1Sdsl
961.1Sdslboot_fail:
971.1Sdsl	push	%ax
981.1Sdsl	movw	$1f, %si
991.1Sdsl	call	message
1001.1Sdsl	pop	%si
1011.1Sdsl	call	message
1021.1Sdsl	jmp	loopstop
1031.1Sdsl1:	.asciz	"Boot failed: "
1041.1Sdsl
1051.1SdslENTRY(_rtt)
1061.1Sdsl	.code32
1071.1Sdsl	call	prot_to_real
1081.1Sdsl	.code16
1091.1Sdslloopstop:
1101.1Sdsl	movb	0x86, %ah		/* delay for about a second */
1111.1Sdsl	movw	$16, %cx
1121.1Sdsl	int	$0x15
1131.1Sdsl	int	$0x18			/* might be a boot fail entry */
1141.1Sdsl1:	sti
1151.1Sdsl	hlt
1161.1Sdsl	jmp	1b
1171.1Sdsl
1181.1Sdsl	/*
1191.1Sdsl	 * Vector the fs calls through here so we can support multiple
1201.1Sdsl	 * file system types with one copy of the library code and
1211.1Sdsl	 * multiple copies of this file.
1221.1Sdsl	 */
1231.1Sdsl	.global	xxfs_open, xxfs_close, xxfs_read, xxfs_stat
1241.1Sdsl	.code32
1251.1Sdslxxfs_open:	jmp	XXfs_open
1261.1Sdslxxfs_close:	jmp	XXfs_close
1271.1Sdslxxfs_read:	jmp	XXfs_read
1281.1Sdslxxfs_stat:	jmp	XXfs_stat
129