Home | History | Annotate | Line # | Download | only in boot
biosboot.S revision 1.6.14.1
      1  1.6.14.1       jym /*	$NetBSD: biosboot.S,v 1.6.14.1 2011/01/10 00:37:32 jym 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.6.14.1       jym  *	%ecx:%ebx		Sector number of NetBSD partition
     41  1.6.14.1       jym  *	%ds:%si			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.6.14.1       jym 	movl	%ecx, %ebp		/* move LBA out of the way */
     81  1.6.14.1       jym 
     82       1.4  junyoung 	/* Grab boot_params patched into bootxx by installboot */
     83       1.1       dsl 	cmpl	$X86_BOOT_MAGIC_1,-4(%si)	/* sanity check ptr */
     84       1.1       dsl 	jne	2f
     85       1.1       dsl 	mov	$boot_params, %di
     86       1.1       dsl 	movl	(%si),%ecx
     87       1.1       dsl 	cmp	$boot_start_1 - boot_params, %cx
     88       1.1       dsl 	jbe	1f
     89       1.1       dsl 	mov	$boot_start_1 - boot_params, %cx
     90       1.1       dsl 1:	cld
     91       1.1       dsl 	rep
     92       1.1       dsl 	movsb
     93       1.1       dsl 2:
     94       1.1       dsl 
     95       1.1       dsl 	mov	%ax, %ds
     96       1.1       dsl 	movl	$_end, %eax		/* top of bss */
     97       1.1       dsl 	shr	$4, %eax		/* as a segment */
     98       1.1       dsl 	add	$0x1001, %ax		/* and + 64k */
     99       1.1       dsl 	mov	%ax, %ss		/* for stack */
    100       1.1       dsl 	mov	$0xfffc, %sp		/* %sp at top of it */
    101       1.1       dsl 
    102       1.1       dsl 	call	gdt_fixup
    103       1.1       dsl 
    104       1.1       dsl 	calll	real_to_prot
    105       1.1       dsl 	.code32
    106       1.1       dsl 
    107       1.1       dsl 	movl	$_end, %ecx		/* zero bss */
    108       1.1       dsl 	movl	$__bss_start, %edi
    109       1.1       dsl 	subl	%edi, %ecx
    110       1.1       dsl 	shr	$2, %ecx		/* _end and __bss_start are aligned */
    111       1.1       dsl 	xor	%eax, %eax
    112       1.1       dsl 	rep
    113       1.1       dsl 	stosl
    114       1.1       dsl 
    115  1.6.14.1       jym 	testb	$X86_BP_FLAGS_LBA64VALID, boot_params+4
    116  1.6.14.1       jym 	jnz	1f
    117  1.6.14.1       jym 	xorl	%ebp, %ebp		/* high part of LBA is not valid */
    118  1.6.14.1       jym 1:
    119  1.6.14.1       jym 
    120  1.6.14.1       jym 	movzbl	%dl, %edx
    121  1.6.14.1       jym 	push	%ebp			/* high 32 bits of first sector */
    122       1.1       dsl 	push	%ebx			/* first sector of bios partition */
    123       1.1       dsl 	push	%edx			/* bios disk */
    124       1.1       dsl 	call	_C_LABEL(boot2)		/* C bootstrap code */
    125  1.6.14.1       jym 	addl	$12, %esp
    126       1.1       dsl 	call	prot_to_real
    127       1.1       dsl 	.code16
    128       1.1       dsl 
    129       1.1       dsl boot_fail:
    130       1.1       dsl 	push	%ax
    131       1.1       dsl 	movw	$1f, %si
    132       1.1       dsl 	call	message
    133       1.1       dsl 	pop	%si
    134       1.1       dsl 	call	message
    135       1.1       dsl 	jmp	loopstop
    136       1.1       dsl 1:	.asciz	"Boot2 failed: "
    137       1.1       dsl 
    138       1.1       dsl ENTRY(_rtt)
    139       1.1       dsl 	.code32
    140       1.1       dsl 	call	prot_to_real
    141       1.1       dsl 	.code16
    142       1.1       dsl loopstop:
    143  1.6.14.1       jym 	movb	$0x86, %ah		/* delay for about a second */
    144       1.1       dsl 	movw	$16, %cx
    145       1.1       dsl 	int	$0x15
    146       1.1       dsl 	int	$0x18			/* might be a boot fail entry */
    147       1.1       dsl 1:	sti
    148       1.1       dsl 	hlt
    149       1.1       dsl 	jmp	1b
    150