bootxx.S revision 1.4
1/* $NetBSD: bootxx.S,v 1.4 2004/02/28 23:01:55 dsl Exp $ */ 2 3/*- 4 * Copyright (c) 2003 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by David Laight. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 3. All advertising materials mentioning features or use of this software 19 * must display the following acknowledgement: 20 * This product includes software developed by the NetBSD 21 * Foundation, Inc. and its contributors. 22 * 4. Neither the name of The NetBSD Foundation nor the names of its 23 * contributors may be used to endorse or promote products derived 24 * from this software without specific prior written permission. 25 * 26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 36 * POSSIBILITY OF SUCH DAMAGE. 37 */ 38 39#include <machine/asm.h> 40#include <sys/bootblock.h> 41 42/* 43 * Code linked to 0xa00 and copied to sectors 2+ of the netbsd boot 44 * partition by MI /usr/sbin/installboot. 45 * Read into memory by code in pbr.S 46 * 47 * On entry: 48 * %dl BIOS drive number 49 * %esi Sector number of netbsd partition 50 * %cs, %ds, %es, %ss All zero 51 * %sp near 0xfffc 52 */ 53 .text 54 .code16 55ENTRY(bootxx) 56 jmp 1f 57 .balign 4 58ENTRY(bootxx_magic) 59 .long X86_BOOT_MAGIC_1 /* checked by installboot & pbr code */ 60bootparams: /* space for patchable variables */ 61 .long 1f - bootparams /* length of this data area */ 62#include <boot_params.S> 63 .space 4 * 4 /* some spare */ 64 651: call gdt_fixup 66 67 calll real_to_prot 68 .code32 69 70 movl $_end, %ecx /* zero bss */ 71 movl $__bss_start, %edi 72 subl %edi, %ecx 73 shr $2, %ecx /* _end and __bss_start are aligned */ 74 xor %eax, %eax 75 rep 76 stosl 77 78 and $0xff, %edx 79 push %esi /* save args for secondary bootstrap */ 80 push %edx 81 push %esi /* args for boot1 */ 82 push %edx 83 call _C_LABEL(boot1) /* C code to load /boot */ 84 add $8, %esp 85 call prot_to_real 86 .code16 87 88 test %ax, %ax 89 jnz boot_fail 90 91 pop %edx /* bios disk number */ 92 pop %ebx /* expected partition start sector */ 93 movl $bootparams, %esi 94 lcall $SECONDARY_LOAD_ADDRESS/16, $0 95 96boot_fail: 97 push %ax /* error string from boot1 */ 98 movw errno, %ax 99 aam /* largest errno is < 100 */ 100 addw $('0' << 8) | '0', %ax /* to ascii */ 101 rorw $8, %ax 102 cmpb $'0', %al /* supress leading zero */ 103 jne 10f 104 movb $' ', %al 10510: movw %ax, 12f 106 movw $11f, %si 107 call message /* output boot failed message */ 108 pop %si 109 call message /* and text from boot1 */ 110 jmp loopstop 11111: .ascii "Boot failed (errno " 11212: .asciz "xx): " 113 114ENTRY(_rtt) 115 .code32 116 call prot_to_real 117 .code16 118loopstop: 119 movb 0x86, %ah /* delay for about a second */ 120 movw $16, %cx 121 int $0x15 122 int $0x18 /* might be a boot fail entry */ 1231: sti /* if not loopstop */ 124 hlt 125 jmp 1b 126 127 /* 128 * Vector the fs calls through here so we can support multiple 129 * file system types with one copy of the library code and 130 * multiple copies of this file. 131 */ 132 .global xxfs_open, xxfs_close, xxfs_read, xxfs_stat 133 .code32 134xxfs_open: jmp XXfs_open 135xxfs_close: jmp XXfs_close 136xxfs_read: jmp XXfs_read 137xxfs_stat: jmp XXfs_stat 138