1/* $NetBSD: bootxx.S,v 1.10 2011/01/06 01:08:48 jakllsch 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 * %edi:%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 push %edi 64 movl $_end, %ecx /* zero bss */ 65 movl $__bss_start, %edi 66 subl %edi, %ecx 67 shr $2, %ecx /* _end and __bss_start are aligned */ 68 xor %eax, %eax 69 rep 70 stosl 71 pop %edi 72 73 movzbl %dl, %edx 74 push %edi /* save args for secondary bootstrap */ 75 push %esi 76 movl %esp, %esi /* address of sector number */ 77 push %edx 78 push %esi /* args for boot1 */ 79 push %edx 80 call _C_LABEL(boot1) /* C code to load /boot */ 81 add $8, %esp 82 call prot_to_real 83 .code16 84 85 test %ax, %ax 86 jnz boot_fail 87 88 pop %edx /* bios disk number */ 89 pop %ebx /* expected partition start sector */ 90 pop %ecx 91 movl $boot_params, %esi 92 orb $X86_BP_FLAGS_LBA64VALID, 4(%esi) 93 lcall $SECONDARY_LOAD_ADDRESS/16, $0 94 95boot_fail: 96 push %ax /* error string from boot1 */ 97 movw errno, %ax 98 aam /* largest errno is < 100 */ 99 addw $('0' << 8) | '0', %ax /* to ascii */ 100 rorw $8, %ax 101 cmpb $'0', %al /* supress leading zero */ 102 jne 10f 103 movb $' ', %al 10410: movw %ax, 12f 105 movw $11f, %si 106 call message /* output boot failed message */ 107 pop %si 108 call message /* and text from boot1 */ 109 jmp loopstop 11011: .ascii "Boot failed (errno " 11112: .asciz "xx): " 112 113ENTRY(_rtt) 114 .code32 115 call prot_to_real 116 .code16 117loopstop: 118 movb 0x86, %ah /* delay for about a second */ 119 movw $16, %cx 120 int $0x15 121 int $0x18 /* might be a boot fail entry */ 1221: sti /* if not loopstop */ 123 hlt 124 jmp 1b 125 126 /* 127 * Vector the fs calls through here so we can support multiple 128 * file system types with one copy of the library code and 129 * multiple copies of this file. 130 */ 131 .global xxfs_open, xxfs_close, xxfs_read, xxfs_stat 132 .code32 133xxfs_open: jmp XXfs_open 134xxfs_close: jmp XXfs_close 135xxfs_read: jmp XXfs_read 136xxfs_stat: jmp XXfs_stat 137