bootxx.S revision 1.12
11.12Smlelstv/* $NetBSD: bootxx.S,v 1.12 2022/03/06 18:35:43 mlelstv 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 * 191.1Sdsl * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 201.1Sdsl * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 211.1Sdsl * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 221.1Sdsl * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 231.1Sdsl * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 241.1Sdsl * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 251.1Sdsl * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 261.1Sdsl * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 271.1Sdsl * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 281.1Sdsl * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 291.1Sdsl * POSSIBILITY OF SUCH DAMAGE. 301.1Sdsl */ 311.1Sdsl 321.1Sdsl#include <machine/asm.h> 331.2Slukem#include <sys/bootblock.h> 341.1Sdsl 351.1Sdsl/* 361.1Sdsl * Code linked to 0xa00 and copied to sectors 2+ of the netbsd boot 371.1Sdsl * partition by MI /usr/sbin/installboot. 381.1Sdsl * Read into memory by code in pbr.S 391.1Sdsl * 401.1Sdsl * On entry: 411.1Sdsl * %dl BIOS drive number 421.10Sjakllsch * %edi:%esi Sector number of NetBSD partition 431.1Sdsl * %cs, %ds, %es, %ss All zero 441.1Sdsl * %sp near 0xfffc 451.1Sdsl */ 461.1Sdsl .text 471.1Sdsl .code16 481.1SdslENTRY(bootxx) 491.1Sdsl jmp 1f 501.3Sdsl .balign 4 511.1SdslENTRY(bootxx_magic) 521.1Sdsl .long X86_BOOT_MAGIC_1 /* checked by installboot & pbr code */ 531.6Sjunyoungboot_params: /* space for patchable variables */ 541.6Sjunyoung .long 1f - boot_params /* length of this data area */ 551.3Sdsl#include <boot_params.S> 561.7Sdsl . = bootxx + 0x80 /* Space for patching unknown params */ 571.1Sdsl 581.1Sdsl1: call gdt_fixup 591.1Sdsl 601.1Sdsl calll real_to_prot 611.1Sdsl .code32 621.1Sdsl 631.10Sjakllsch push %edi 641.1Sdsl movl $_end, %ecx /* zero bss */ 651.1Sdsl movl $__bss_start, %edi 661.1Sdsl subl %edi, %ecx 671.1Sdsl shr $2, %ecx /* _end and __bss_start are aligned */ 681.1Sdsl xor %eax, %eax 691.1Sdsl rep 701.1Sdsl stosl 711.10Sjakllsch pop %edi 721.1Sdsl 731.10Sjakllsch movzbl %dl, %edx 741.10Sjakllsch push %edi /* save args for secondary bootstrap */ 751.10Sjakllsch push %esi 761.5Sdsl movl %esp, %esi /* address of sector number */ 771.1Sdsl push %edx 781.1Sdsl push %esi /* args for boot1 */ 791.1Sdsl push %edx 801.1Sdsl call _C_LABEL(boot1) /* C code to load /boot */ 811.1Sdsl add $8, %esp 821.12Smlelstv movw errno, %dx 831.1Sdsl call prot_to_real 841.1Sdsl .code16 851.1Sdsl 861.1Sdsl test %ax, %ax 871.1Sdsl jnz boot_fail 881.1Sdsl 891.1Sdsl pop %edx /* bios disk number */ 901.1Sdsl pop %ebx /* expected partition start sector */ 911.10Sjakllsch pop %ecx 921.6Sjunyoung movl $boot_params, %esi 931.10Sjakllsch orb $X86_BP_FLAGS_LBA64VALID, 4(%esi) 941.1Sdsl lcall $SECONDARY_LOAD_ADDRESS/16, $0 951.1Sdsl 961.1Sdslboot_fail: 971.4Sdsl push %ax /* error string from boot1 */ 981.12Smlelstv movw %dx, %ax 991.4Sdsl aam /* largest errno is < 100 */ 1001.4Sdsl addw $('0' << 8) | '0', %ax /* to ascii */ 1011.4Sdsl rorw $8, %ax 1021.11Smsaitoh cmpb $'0', %al /* suppress leading zero */ 1031.4Sdsl jne 10f 1041.4Sdsl movb $' ', %al 1051.4Sdsl10: movw %ax, 12f 1061.4Sdsl movw $11f, %si 1071.4Sdsl call message /* output boot failed message */ 1081.1Sdsl pop %si 1091.4Sdsl call message /* and text from boot1 */ 1101.1Sdsl jmp loopstop 1111.4Sdsl11: .ascii "Boot failed (errno " 1121.4Sdsl12: .asciz "xx): " 1131.1Sdsl 1141.1SdslENTRY(_rtt) 1151.1Sdsl .code32 1161.1Sdsl call prot_to_real 1171.1Sdsl .code16 1181.1Sdslloopstop: 1191.1Sdsl movb 0x86, %ah /* delay for about a second */ 1201.1Sdsl movw $16, %cx 1211.1Sdsl int $0x15 1221.1Sdsl int $0x18 /* might be a boot fail entry */ 1231.4Sdsl1: sti /* if not loopstop */ 1241.1Sdsl hlt 1251.1Sdsl jmp 1b 1261.1Sdsl 1271.1Sdsl /* 1281.1Sdsl * Vector the fs calls through here so we can support multiple 1291.1Sdsl * file system types with one copy of the library code and 1301.1Sdsl * multiple copies of this file. 1311.1Sdsl */ 1321.1Sdsl .global xxfs_open, xxfs_close, xxfs_read, xxfs_stat 1331.1Sdsl .code32 1341.1Sdslxxfs_open: jmp XXfs_open 1351.1Sdslxxfs_close: jmp XXfs_close 1361.1Sdslxxfs_read: jmp XXfs_read 1371.1Sdslxxfs_stat: jmp XXfs_stat 138