bootxx.S revision 1.8
1/* $NetBSD: bootxx.S,v 1.8 2005/12/11 12:17:48 christos 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 */ 60boot_params: /* space for patchable variables */ 61 .long 1f - boot_params /* length of this data area */ 62#include <boot_params.S> 63 . = bootxx + 0x80 /* Space for patching unknown params */ 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 movl %esp, %esi /* address of sector number */ 81 push %edx 82 push %esi /* args for boot1 */ 83 push %edx 84 call _C_LABEL(boot1) /* C code to load /boot */ 85 add $8, %esp 86 call prot_to_real 87 .code16 88 89 test %ax, %ax 90 jnz boot_fail 91 92 pop %edx /* bios disk number */ 93 pop %ebx /* expected partition start sector */ 94 movl $boot_params, %esi 95 lcall $SECONDARY_LOAD_ADDRESS/16, $0 96 97boot_fail: 98 push %ax /* error string from boot1 */ 99 movw errno, %ax 100 aam /* largest errno is < 100 */ 101 addw $('0' << 8) | '0', %ax /* to ascii */ 102 rorw $8, %ax 103 cmpb $'0', %al /* supress leading zero */ 104 jne 10f 105 movb $' ', %al 10610: movw %ax, 12f 107 movw $11f, %si 108 call message /* output boot failed message */ 109 pop %si 110 call message /* and text from boot1 */ 111 jmp loopstop 11211: .ascii "Boot failed (errno " 11312: .asciz "xx): " 114 115ENTRY(_rtt) 116 .code32 117 call prot_to_real 118 .code16 119loopstop: 120 movb 0x86, %ah /* delay for about a second */ 121 movw $16, %cx 122 int $0x15 123 int $0x18 /* might be a boot fail entry */ 1241: sti /* if not loopstop */ 125 hlt 126 jmp 1b 127 128 /* 129 * Vector the fs calls through here so we can support multiple 130 * file system types with one copy of the library code and 131 * multiple copies of this file. 132 */ 133 .global xxfs_open, xxfs_close, xxfs_read, xxfs_stat 134 .code32 135xxfs_open: jmp XXfs_open 136xxfs_close: jmp XXfs_close 137xxfs_read: jmp XXfs_read 138xxfs_stat: jmp XXfs_stat 139