bootxx.S revision 1.11
11.11Smsaitoh/*	$NetBSD: bootxx.S,v 1.11 2019/07/11 03:49:51 msaitoh 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 *
191.1Sdsl * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
201.1Sdsl * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
211.1Sdsl * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
221.1Sdsl * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
231.1Sdsl * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
241.1Sdsl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
251.1Sdsl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
261.1Sdsl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
271.1Sdsl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
281.1Sdsl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
291.1Sdsl * POSSIBILITY OF SUCH DAMAGE.
301.1Sdsl */
311.1Sdsl
321.1Sdsl#include <machine/asm.h>
331.2Slukem#include <sys/bootblock.h>
341.1Sdsl
351.1Sdsl/*
361.1Sdsl * Code linked to 0xa00 and copied to sectors 2+ of the netbsd boot
371.1Sdsl * partition by MI /usr/sbin/installboot.
381.1Sdsl * Read into memory by code in pbr.S
391.1Sdsl *
401.1Sdsl * On entry:
411.1Sdsl * 	%dl			BIOS drive number
421.10Sjakllsch *	%edi:%esi		Sector number of NetBSD partition
431.1Sdsl *	%cs, %ds, %es, %ss	All zero
441.1Sdsl *	%sp			near 0xfffc
451.1Sdsl */
461.1Sdsl	.text
471.1Sdsl	.code16
481.1SdslENTRY(bootxx)
491.1Sdsl	jmp	1f
501.3Sdsl	.balign	4
511.1SdslENTRY(bootxx_magic)
521.1Sdsl	.long	X86_BOOT_MAGIC_1	/* checked by installboot & pbr code */
531.6Sjunyoungboot_params:				/* space for patchable variables */
541.6Sjunyoung	.long	1f - boot_params	/* length of this data area */
551.3Sdsl#include <boot_params.S>
561.7Sdsl	. = bootxx + 0x80		/* Space for patching unknown params */
571.1Sdsl
581.1Sdsl1:	call	gdt_fixup
591.1Sdsl
601.1Sdsl	calll	real_to_prot
611.1Sdsl	.code32
621.1Sdsl
631.10Sjakllsch	push	%edi
641.1Sdsl	movl	$_end, %ecx		/* zero bss */
651.1Sdsl	movl	$__bss_start, %edi
661.1Sdsl	subl	%edi, %ecx
671.1Sdsl	shr	$2, %ecx		/* _end and __bss_start are aligned */
681.1Sdsl	xor	%eax, %eax
691.1Sdsl	rep
701.1Sdsl	stosl
711.10Sjakllsch	pop	%edi
721.1Sdsl
731.10Sjakllsch	movzbl	%dl, %edx
741.10Sjakllsch	push	%edi			/* save args for secondary bootstrap */
751.10Sjakllsch	push	%esi
761.5Sdsl	movl	%esp, %esi		/* address of sector number */
771.1Sdsl	push	%edx
781.1Sdsl	push	%esi			/* args for boot1 */
791.1Sdsl	push	%edx
801.1Sdsl	call	_C_LABEL(boot1)		/* C code to load /boot */
811.1Sdsl	add	$8, %esp
821.1Sdsl	call	prot_to_real
831.1Sdsl	.code16
841.1Sdsl
851.1Sdsl	test	%ax, %ax
861.1Sdsl	jnz	boot_fail
871.1Sdsl
881.1Sdsl	pop	%edx			/* bios disk number */
891.1Sdsl	pop	%ebx			/* expected partition start sector */
901.10Sjakllsch	pop	%ecx
911.6Sjunyoung	movl	$boot_params, %esi
921.10Sjakllsch	orb	$X86_BP_FLAGS_LBA64VALID, 4(%esi)
931.1Sdsl	lcall	$SECONDARY_LOAD_ADDRESS/16, $0
941.1Sdsl
951.1Sdslboot_fail:
961.4Sdsl	push	%ax			/* error string from boot1 */
971.4Sdsl	movw	errno, %ax
981.4Sdsl	aam				/* largest errno is < 100 */
991.4Sdsl	addw	$('0' << 8) | '0', %ax	/* to ascii */
1001.4Sdsl	rorw	$8, %ax
1011.11Smsaitoh	cmpb	$'0', %al		/* suppress leading zero */
1021.4Sdsl	jne	10f
1031.4Sdsl	movb	$' ', %al
1041.4Sdsl10:	movw	%ax, 12f
1051.4Sdsl	movw	$11f, %si
1061.4Sdsl	call	message			/* output boot failed message */
1071.1Sdsl	pop	%si
1081.4Sdsl	call	message			/* and text from boot1 */
1091.1Sdsl	jmp	loopstop
1101.4Sdsl11:	.ascii	"Boot failed (errno "
1111.4Sdsl12:	.asciz	"xx): "
1121.1Sdsl
1131.1SdslENTRY(_rtt)
1141.1Sdsl	.code32
1151.1Sdsl	call	prot_to_real
1161.1Sdsl	.code16
1171.1Sdslloopstop:
1181.1Sdsl	movb	0x86, %ah		/* delay for about a second */
1191.1Sdsl	movw	$16, %cx
1201.1Sdsl	int	$0x15
1211.1Sdsl	int	$0x18			/* might be a boot fail entry */
1221.4Sdsl1:	sti				/* if not loopstop */
1231.1Sdsl	hlt
1241.1Sdsl	jmp	1b
1251.1Sdsl
1261.1Sdsl	/*
1271.1Sdsl	 * Vector the fs calls through here so we can support multiple
1281.1Sdsl	 * file system types with one copy of the library code and
1291.1Sdsl	 * multiple copies of this file.
1301.1Sdsl	 */
1311.1Sdsl	.global	xxfs_open, xxfs_close, xxfs_read, xxfs_stat
1321.1Sdsl	.code32
1331.1Sdslxxfs_open:	jmp	XXfs_open
1341.1Sdslxxfs_close:	jmp	XXfs_close
1351.1Sdslxxfs_read:	jmp	XXfs_read
1361.1Sdslxxfs_stat:	jmp	XXfs_stat
137