Home | History | Annotate | Line # | Download | only in boot
biosboot.S revision 1.1.2.4
      1  1.1.2.4  skrll /*	$NetBSD: biosboot.S,v 1.1.2.4 2004/09/21 13:17:10 skrll Exp $	*/
      2      1.1    dsl 
      3      1.1    dsl /*-
      4      1.1    dsl  * Copyright (c) 2003 The NetBSD Foundation, Inc.
      5      1.1    dsl  * All rights reserved.
      6      1.1    dsl  *
      7      1.1    dsl  * This code is derived from software contributed to The NetBSD Foundation
      8      1.1    dsl  * by David Laight.
      9      1.1    dsl  *
     10      1.1    dsl  * Redistribution and use in source and binary forms, with or without
     11      1.1    dsl  * modification, are permitted provided that the following conditions
     12      1.1    dsl  * are met:
     13      1.1    dsl  * 1. Redistributions of source code must retain the above copyright
     14      1.1    dsl  *    notice, this list of conditions and the following disclaimer.
     15      1.1    dsl  * 2. Redistributions in binary form must reproduce the above copyright
     16      1.1    dsl  *    notice, this list of conditions and the following disclaimer in the
     17      1.1    dsl  *    documentation and/or other materials provided with the distribution.
     18      1.1    dsl  * 3. All advertising materials mentioning features or use of this software
     19      1.1    dsl  *    must display the following acknowledgement:
     20      1.1    dsl  *        This product includes software developed by the NetBSD
     21      1.1    dsl  *        Foundation, Inc. and its contributors.
     22      1.1    dsl  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.1    dsl  *    contributors may be used to endorse or promote products derived
     24      1.1    dsl  *    from this software without specific prior written permission.
     25      1.1    dsl  *
     26      1.1    dsl  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.1    dsl  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.1    dsl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.1    dsl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.1    dsl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.1    dsl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.1    dsl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.1    dsl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.1    dsl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.1    dsl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.1    dsl  * POSSIBILITY OF SUCH DAMAGE.
     37      1.1    dsl  */
     38      1.1    dsl 
     39      1.1    dsl #include <machine/asm.h>
     40  1.1.2.1  skrll #include <sys/bootblock.h>
     41      1.1    dsl 
     42      1.1    dsl /*
     43      1.1    dsl  * Code linked to 0x1000:0 and (usually) read from /boot by bootxx code
     44      1.1    dsl  *
     45      1.1    dsl  * On entry:
     46      1.1    dsl  * 	%dl			BIOS drive number
     47      1.1    dsl  *	%ebx			Sector number of netbsd partition
     48      1.1    dsl  *	%ds:%esi		Boot parameter block (patched by installboot)
     49      1.1    dsl  *	%cs			0x1000
     50      1.1    dsl  *	%ds, %es, %ss		All zero
     51      1.1    dsl  *	%sp			near 0xfffc
     52      1.1    dsl  */
     53      1.1    dsl 
     54      1.1    dsl 	.text
     55      1.1    dsl 	.code16
     56      1.1    dsl ENTRY(boot_start)
     57      1.1    dsl 	jmp	boot_start_1
     58  1.1.2.1  skrll 	.balign	4
     59      1.1    dsl ENTRY(boot_magic)
     60      1.1    dsl 	.long	X86_BOOT_MAGIC_2	/* checked for by bootxx code */
     61      1.1    dsl ENTRY(boot_params)
     62      1.1    dsl 	.long	boot_start_1 - boot_params
     63  1.1.2.1  skrll #include <boot_params.S>
     64      1.1    dsl 	. = boot_start + 0x80		/* space for patchable variables */
     65      1.1    dsl boot_start_1:
     66      1.1    dsl 
     67      1.1    dsl #if 0
     68      1.1    dsl 	/* Allow for boot_start not being %cs:0 */
     69      1.1    dsl 	call	2f
     70      1.1    dsl 2:	pop	%cx
     71      1.1    dsl 	sub	$2b, %cx		/* %ax is offset */
     72      1.1    dsl 	test	$0xf, %cx		/* check code seg aligned */
     73      1.1    dsl 	jz	3f
     74      1.1    dsl 	lret				/* not playing if not */
     75      1.1    dsl 3:	mov	%cs, %ax
     76      1.1    dsl 	shr	$4, %cx
     77      1.1    dsl 	add	%cx, %ax		/* segment staring at boot_start */
     78      1.1    dsl 	push	%ax
     79      1.1    dsl 	push	$4f
     80      1.1    dsl 	lret
     81      1.1    dsl 4:
     82      1.1    dsl #endif
     83      1.1    dsl 
     84      1.1    dsl 	mov	%cs, %ax
     85      1.1    dsl 	mov	%ax, %es
     86      1.1    dsl 
     87  1.1.2.2  skrll 	/* Grab boot_params patched into bootxx by installboot */
     88      1.1    dsl 	cmpl	$X86_BOOT_MAGIC_1,-4(%si)	/* sanity check ptr */
     89      1.1    dsl 	jne	2f
     90      1.1    dsl 	mov	$boot_params, %di
     91      1.1    dsl 	movl	(%si),%ecx
     92      1.1    dsl 	cmp	$boot_start_1 - boot_params, %cx
     93      1.1    dsl 	jbe	1f
     94      1.1    dsl 	mov	$boot_start_1 - boot_params, %cx
     95      1.1    dsl 1:	cld
     96      1.1    dsl 	rep
     97      1.1    dsl 	movsb
     98      1.1    dsl 2:
     99      1.1    dsl 
    100      1.1    dsl 	mov	%ax, %ds
    101      1.1    dsl 	movl	$_end, %eax		/* top of bss */
    102      1.1    dsl 	shr	$4, %eax		/* as a segment */
    103      1.1    dsl 	add	$0x1001, %ax		/* and + 64k */
    104      1.1    dsl 	mov	%ax, %ss		/* for stack */
    105      1.1    dsl 	mov	$0xfffc, %sp		/* %sp at top of it */
    106      1.1    dsl 
    107      1.1    dsl 	call	gdt_fixup
    108      1.1    dsl 
    109      1.1    dsl 	calll	real_to_prot
    110      1.1    dsl 	.code32
    111      1.1    dsl 
    112      1.1    dsl 	movl	$_end, %ecx		/* zero bss */
    113      1.1    dsl 	movl	$__bss_start, %edi
    114      1.1    dsl 	subl	%edi, %ecx
    115      1.1    dsl 	shr	$2, %ecx		/* _end and __bss_start are aligned */
    116      1.1    dsl 	xor	%eax, %eax
    117      1.1    dsl 	rep
    118      1.1    dsl 	stosl
    119      1.1    dsl 
    120      1.1    dsl 	and	$0xff, %edx
    121      1.1    dsl 	push	%ebx			/* first sector of bios partition */
    122      1.1    dsl 	push	%edx			/* bios disk */
    123      1.1    dsl 	call	_C_LABEL(boot2)		/* C bootstrap code */
    124      1.1    dsl 	add	$8, %esp
    125      1.1    dsl 	call	prot_to_real
    126      1.1    dsl 	.code16
    127      1.1    dsl 
    128      1.1    dsl boot_fail:
    129      1.1    dsl 	push	%ax
    130      1.1    dsl 	movw	$1f, %si
    131      1.1    dsl 	call	message
    132      1.1    dsl 	pop	%si
    133      1.1    dsl 	call	message
    134      1.1    dsl 	jmp	loopstop
    135      1.1    dsl 1:	.asciz	"Boot2 failed: "
    136      1.1    dsl 
    137      1.1    dsl ENTRY(_rtt)
    138      1.1    dsl 	.code32
    139      1.1    dsl 	call	prot_to_real
    140      1.1    dsl 	.code16
    141      1.1    dsl loopstop:
    142      1.1    dsl 	movb	0x86, %ah		/* delay for about a second */
    143      1.1    dsl 	movw	$16, %cx
    144      1.1    dsl 	int	$0x15
    145      1.1    dsl 	int	$0x18			/* might be a boot fail entry */
    146      1.1    dsl 1:	sti
    147      1.1    dsl 	hlt
    148      1.1    dsl 	jmp	1b
    149