Home | History | Annotate | Line # | Download | only in boot
biosboot.S revision 1.5.78.1
      1  1.5.78.1      yamt /*	$NetBSD: biosboot.S,v 1.5.78.1 2008/05/16 02:22:38 yamt 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  *
     19       1.1       dsl  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     20       1.1       dsl  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     21       1.1       dsl  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     22       1.1       dsl  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     23       1.1       dsl  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     24       1.1       dsl  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     25       1.1       dsl  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     26       1.1       dsl  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     27       1.1       dsl  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     28       1.1       dsl  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     29       1.1       dsl  * POSSIBILITY OF SUCH DAMAGE.
     30       1.1       dsl  */
     31       1.1       dsl 
     32       1.1       dsl #include <machine/asm.h>
     33       1.2     lukem #include <sys/bootblock.h>
     34       1.1       dsl 
     35       1.1       dsl /*
     36       1.1       dsl  * Code linked to 0x1000:0 and (usually) read from /boot by bootxx code
     37       1.1       dsl  *
     38       1.1       dsl  * On entry:
     39       1.1       dsl  * 	%dl			BIOS drive number
     40       1.1       dsl  *	%ebx			Sector number of netbsd partition
     41       1.1       dsl  *	%ds:%esi		Boot parameter block (patched by installboot)
     42       1.1       dsl  *	%cs			0x1000
     43       1.1       dsl  *	%ds, %es, %ss		All zero
     44       1.1       dsl  *	%sp			near 0xfffc
     45       1.1       dsl  */
     46       1.1       dsl 
     47       1.1       dsl 	.text
     48       1.1       dsl 	.code16
     49       1.1       dsl ENTRY(boot_start)
     50       1.1       dsl 	jmp	boot_start_1
     51       1.3       dsl 	.balign	4
     52       1.1       dsl ENTRY(boot_magic)
     53       1.1       dsl 	.long	X86_BOOT_MAGIC_2	/* checked for by bootxx code */
     54       1.1       dsl ENTRY(boot_params)
     55       1.1       dsl 	.long	boot_start_1 - boot_params
     56       1.3       dsl #include <boot_params.S>
     57       1.1       dsl 	. = boot_start + 0x80		/* space for patchable variables */
     58       1.1       dsl boot_start_1:
     59       1.1       dsl 
     60       1.1       dsl #if 0
     61       1.1       dsl 	/* Allow for boot_start not being %cs:0 */
     62       1.1       dsl 	call	2f
     63       1.1       dsl 2:	pop	%cx
     64       1.1       dsl 	sub	$2b, %cx		/* %ax is offset */
     65       1.1       dsl 	test	$0xf, %cx		/* check code seg aligned */
     66       1.1       dsl 	jz	3f
     67       1.1       dsl 	lret				/* not playing if not */
     68       1.1       dsl 3:	mov	%cs, %ax
     69       1.1       dsl 	shr	$4, %cx
     70       1.1       dsl 	add	%cx, %ax		/* segment staring at boot_start */
     71       1.1       dsl 	push	%ax
     72       1.1       dsl 	push	$4f
     73       1.1       dsl 	lret
     74       1.1       dsl 4:
     75       1.1       dsl #endif
     76       1.1       dsl 
     77       1.1       dsl 	mov	%cs, %ax
     78       1.1       dsl 	mov	%ax, %es
     79       1.1       dsl 
     80       1.4  junyoung 	/* Grab boot_params patched into bootxx by installboot */
     81       1.1       dsl 	cmpl	$X86_BOOT_MAGIC_1,-4(%si)	/* sanity check ptr */
     82       1.1       dsl 	jne	2f
     83       1.1       dsl 	mov	$boot_params, %di
     84       1.1       dsl 	movl	(%si),%ecx
     85       1.1       dsl 	cmp	$boot_start_1 - boot_params, %cx
     86       1.1       dsl 	jbe	1f
     87       1.1       dsl 	mov	$boot_start_1 - boot_params, %cx
     88       1.1       dsl 1:	cld
     89       1.1       dsl 	rep
     90       1.1       dsl 	movsb
     91       1.1       dsl 2:
     92       1.1       dsl 
     93       1.1       dsl 	mov	%ax, %ds
     94       1.1       dsl 	movl	$_end, %eax		/* top of bss */
     95       1.1       dsl 	shr	$4, %eax		/* as a segment */
     96       1.1       dsl 	add	$0x1001, %ax		/* and + 64k */
     97       1.1       dsl 	mov	%ax, %ss		/* for stack */
     98       1.1       dsl 	mov	$0xfffc, %sp		/* %sp at top of it */
     99       1.1       dsl 
    100       1.1       dsl 	call	gdt_fixup
    101       1.1       dsl 
    102       1.1       dsl 	calll	real_to_prot
    103       1.1       dsl 	.code32
    104       1.1       dsl 
    105       1.1       dsl 	movl	$_end, %ecx		/* zero bss */
    106       1.1       dsl 	movl	$__bss_start, %edi
    107       1.1       dsl 	subl	%edi, %ecx
    108       1.1       dsl 	shr	$2, %ecx		/* _end and __bss_start are aligned */
    109       1.1       dsl 	xor	%eax, %eax
    110       1.1       dsl 	rep
    111       1.1       dsl 	stosl
    112       1.1       dsl 
    113       1.1       dsl 	and	$0xff, %edx
    114       1.1       dsl 	push	%ebx			/* first sector of bios partition */
    115       1.1       dsl 	push	%edx			/* bios disk */
    116       1.1       dsl 	call	_C_LABEL(boot2)		/* C bootstrap code */
    117       1.1       dsl 	add	$8, %esp
    118       1.1       dsl 	call	prot_to_real
    119       1.1       dsl 	.code16
    120       1.1       dsl 
    121       1.1       dsl boot_fail:
    122       1.1       dsl 	push	%ax
    123       1.1       dsl 	movw	$1f, %si
    124       1.1       dsl 	call	message
    125       1.1       dsl 	pop	%si
    126       1.1       dsl 	call	message
    127       1.1       dsl 	jmp	loopstop
    128       1.1       dsl 1:	.asciz	"Boot2 failed: "
    129       1.1       dsl 
    130       1.1       dsl ENTRY(_rtt)
    131       1.1       dsl 	.code32
    132       1.1       dsl 	call	prot_to_real
    133       1.1       dsl 	.code16
    134       1.1       dsl loopstop:
    135       1.1       dsl 	movb	0x86, %ah		/* delay for about a second */
    136       1.1       dsl 	movw	$16, %cx
    137       1.1       dsl 	int	$0x15
    138       1.1       dsl 	int	$0x18			/* might be a boot fail entry */
    139       1.1       dsl 1:	sti
    140       1.1       dsl 	hlt
    141       1.1       dsl 	jmp	1b
    142