bootxx.S revision 1.7
11.7Sdsl/* $NetBSD: bootxx.S,v 1.7 2004/08/23 06:50:21 dsl Exp $ */ 21.1Sdsl 31.1Sdsl/*- 41.1Sdsl * Copyright (c) 2003 The NetBSD Foundation, Inc. 51.1Sdsl * All rights reserved. 61.1Sdsl * 71.1Sdsl * This code is derived from software contributed to The NetBSD Foundation 81.1Sdsl * by David Laight. 91.1Sdsl * 101.1Sdsl * Redistribution and use in source and binary forms, with or without 111.1Sdsl * modification, are permitted provided that the following conditions 121.1Sdsl * are met: 131.1Sdsl * 1. Redistributions of source code must retain the above copyright 141.1Sdsl * notice, this list of conditions and the following disclaimer. 151.1Sdsl * 2. Redistributions in binary form must reproduce the above copyright 161.1Sdsl * notice, this list of conditions and the following disclaimer in the 171.1Sdsl * documentation and/or other materials provided with the distribution. 181.1Sdsl * 3. All advertising materials mentioning features or use of this software 191.1Sdsl * must display the following acknowledgement: 201.1Sdsl * This product includes software developed by the NetBSD 211.1Sdsl * Foundation, Inc. and its contributors. 221.1Sdsl * 4. Neither the name of The NetBSD Foundation nor the names of its 231.1Sdsl * contributors may be used to endorse or promote products derived 241.1Sdsl * from this software without specific prior written permission. 251.1Sdsl * 261.1Sdsl * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 271.1Sdsl * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 281.1Sdsl * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 291.1Sdsl * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 301.1Sdsl * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 311.1Sdsl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 321.1Sdsl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 331.1Sdsl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 341.1Sdsl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 351.1Sdsl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 361.1Sdsl * POSSIBILITY OF SUCH DAMAGE. 371.1Sdsl */ 381.1Sdsl 391.1Sdsl#include <machine/asm.h> 401.2Slukem#include <sys/bootblock.h> 411.1Sdsl 421.1Sdsl/* 431.1Sdsl * Code linked to 0xa00 and copied to sectors 2+ of the netbsd boot 441.1Sdsl * partition by MI /usr/sbin/installboot. 451.1Sdsl * Read into memory by code in pbr.S 461.1Sdsl * 471.1Sdsl * On entry: 481.1Sdsl * %dl BIOS drive number 491.1Sdsl * %esi Sector number of netbsd partition 501.1Sdsl * %cs, %ds, %es, %ss All zero 511.1Sdsl * %sp near 0xfffc 521.1Sdsl */ 531.1Sdsl .text 541.1Sdsl .code16 551.1SdslENTRY(bootxx) 561.1Sdsl jmp 1f 571.3Sdsl .balign 4 581.1SdslENTRY(bootxx_magic) 591.1Sdsl .long X86_BOOT_MAGIC_1 /* checked by installboot & pbr code */ 601.6Sjunyoungboot_params: /* space for patchable variables */ 611.6Sjunyoung .long 1f - boot_params /* length of this data area */ 621.3Sdsl#include <boot_params.S> 631.7Sdsl . = bootxx + 0x80 /* Space for patching unknown params */ 641.1Sdsl 651.1Sdsl1: call gdt_fixup 661.1Sdsl 671.1Sdsl calll real_to_prot 681.1Sdsl .code32 691.1Sdsl 701.1Sdsl movl $_end, %ecx /* zero bss */ 711.1Sdsl movl $__bss_start, %edi 721.1Sdsl subl %edi, %ecx 731.1Sdsl shr $2, %ecx /* _end and __bss_start are aligned */ 741.1Sdsl xor %eax, %eax 751.1Sdsl rep 761.1Sdsl stosl 771.1Sdsl 781.1Sdsl and $0xff, %edx 791.1Sdsl push %esi /* save args for secondary bootstrap */ 801.5Sdsl movl %esp, %esi /* address of sector number */ 811.1Sdsl push %edx 821.1Sdsl push %esi /* args for boot1 */ 831.1Sdsl push %edx 841.1Sdsl call _C_LABEL(boot1) /* C code to load /boot */ 851.1Sdsl add $8, %esp 861.1Sdsl call prot_to_real 871.1Sdsl .code16 881.1Sdsl 891.1Sdsl test %ax, %ax 901.1Sdsl jnz boot_fail 911.1Sdsl 921.1Sdsl pop %edx /* bios disk number */ 931.1Sdsl pop %ebx /* expected partition start sector */ 941.6Sjunyoung movl $boot_params, %esi 951.1Sdsl lcall $SECONDARY_LOAD_ADDRESS/16, $0 961.1Sdsl 971.1Sdslboot_fail: 981.4Sdsl push %ax /* error string from boot1 */ 991.4Sdsl movw errno, %ax 1001.4Sdsl aam /* largest errno is < 100 */ 1011.4Sdsl addw $('0' << 8) | '0', %ax /* to ascii */ 1021.4Sdsl rorw $8, %ax 1031.4Sdsl cmpb $'0', %al /* supress leading zero */ 1041.4Sdsl jne 10f 1051.4Sdsl movb $' ', %al 1061.4Sdsl10: movw %ax, 12f 1071.4Sdsl movw $11f, %si 1081.4Sdsl call message /* output boot failed message */ 1091.1Sdsl pop %si 1101.4Sdsl call message /* and text from boot1 */ 1111.1Sdsl jmp loopstop 1121.4Sdsl11: .ascii "Boot failed (errno " 1131.4Sdsl12: .asciz "xx): " 1141.1Sdsl 1151.1SdslENTRY(_rtt) 1161.1Sdsl .code32 1171.1Sdsl call prot_to_real 1181.1Sdsl .code16 1191.1Sdslloopstop: 1201.1Sdsl movb 0x86, %ah /* delay for about a second */ 1211.1Sdsl movw $16, %cx 1221.1Sdsl int $0x15 1231.1Sdsl int $0x18 /* might be a boot fail entry */ 1241.4Sdsl1: sti /* if not loopstop */ 1251.1Sdsl hlt 1261.1Sdsl jmp 1b 1271.1Sdsl 1281.1Sdsl /* 1291.1Sdsl * Vector the fs calls through here so we can support multiple 1301.1Sdsl * file system types with one copy of the library code and 1311.1Sdsl * multiple copies of this file. 1321.1Sdsl */ 1331.1Sdsl .global xxfs_open, xxfs_close, xxfs_read, xxfs_stat 1341.1Sdsl .code32 1351.1Sdslxxfs_open: jmp XXfs_open 1361.1Sdslxxfs_close: jmp XXfs_close 1371.1Sdslxxfs_read: jmp XXfs_read 1381.1Sdslxxfs_stat: jmp XXfs_stat 139