1/* $NetBSD: bootxx.S,v 1.9 2008/04/28 20:23:25 martin 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 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32#include <machine/asm.h> 33#include <sys/bootblock.h> 34 35/* 36 * Code linked to 0xa00 and copied to sectors 2+ of the netbsd boot 37 * partition by MI /usr/sbin/installboot. 38 * Read into memory by code in pbr.S 39 * 40 * On entry: 41 * %dl BIOS drive number 42 * %esi Sector number of netbsd partition 43 * %cs, %ds, %es, %ss All zero 44 * %sp near 0xfffc 45 */ 46 .text 47 .code16 48ENTRY(bootxx) 49 jmp 1f 50 .balign 4 51ENTRY(bootxx_magic) 52 .long X86_BOOT_MAGIC_1 /* checked by installboot & pbr code */ 53boot_params: /* space for patchable variables */ 54 .long 1f - boot_params /* length of this data area */ 55#include <boot_params.S> 56 . = bootxx + 0x80 /* Space for patching unknown params */ 57 581: call gdt_fixup 59 60 calll real_to_prot 61 .code32 62 63 movl $_end, %ecx /* zero bss */ 64 movl $__bss_start, %edi 65 subl %edi, %ecx 66 shr $2, %ecx /* _end and __bss_start are aligned */ 67 xor %eax, %eax 68 rep 69 stosl 70 71 and $0xff, %edx 72 push %esi /* save args for secondary bootstrap */ 73 movl %esp, %esi /* address of sector number */ 74 push %edx 75 push %esi /* args for boot1 */ 76 push %edx 77 call _C_LABEL(boot1) /* C code to load /boot */ 78 add $8, %esp 79 call prot_to_real 80 .code16 81 82 test %ax, %ax 83 jnz boot_fail 84 85 pop %edx /* bios disk number */ 86 pop %ebx /* expected partition start sector */ 87 movl $boot_params, %esi 88 lcall $SECONDARY_LOAD_ADDRESS/16, $0 89 90boot_fail: 91 push %ax /* error string from boot1 */ 92 movw errno, %ax 93 aam /* largest errno is < 100 */ 94 addw $('0' << 8) | '0', %ax /* to ascii */ 95 rorw $8, %ax 96 cmpb $'0', %al /* supress leading zero */ 97 jne 10f 98 movb $' ', %al 9910: movw %ax, 12f 100 movw $11f, %si 101 call message /* output boot failed message */ 102 pop %si 103 call message /* and text from boot1 */ 104 jmp loopstop 10511: .ascii "Boot failed (errno " 10612: .asciz "xx): " 107 108ENTRY(_rtt) 109 .code32 110 call prot_to_real 111 .code16 112loopstop: 113 movb 0x86, %ah /* delay for about a second */ 114 movw $16, %cx 115 int $0x15 116 int $0x18 /* might be a boot fail entry */ 1171: sti /* if not loopstop */ 118 hlt 119 jmp 1b 120 121 /* 122 * Vector the fs calls through here so we can support multiple 123 * file system types with one copy of the library code and 124 * multiple copies of this file. 125 */ 126 .global xxfs_open, xxfs_close, xxfs_read, xxfs_stat 127 .code32 128xxfs_open: jmp XXfs_open 129xxfs_close: jmp XXfs_close 130xxfs_read: jmp XXfs_read 131xxfs_stat: jmp XXfs_stat 132