boot.s revision 302408
1# Copyright (c) KATO Takenori, 1999, 2000. 2# 3# All rights reserved. Unpublished rights reserved under the copyright 4# laws of Japan. 5# 6# Redistribution and use in source and binary forms, with or without 7# modification, are permitted provided that the following conditions 8# are met: 9# 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer as 12# the first lines of this file unmodified. 13# 2. Redistributions in binary form must reproduce the above copyright 14# notice, this list of conditions and the following disclaimer in the 15# documentation and/or other materials provided with the distribution. 16# 17# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27# 28# $FreeBSD: stable/11/sys/boot/pc98/boot0.5/boot.s 167657 2007-03-17 05:30:03Z kato $ 29# 30 31 .code16 32 33 .text 34 .global boot 35# 36# Read bootstrap program and jump to it. 37# 38boot: 39 # Step 1: Save parameters 40 movw curdevice, %si 41 movb daua(%si), %al 42 movb %al, b_daua 43 shlw %si 44 movw secsize(%si), %ax 45 movw %ax, b_secsize 46 47 movw curpartition, %si 48 movb partnum(%si), %al # %al = real partition number 49 xorb %ah, %ah 50 movw %ax, b_partn # save real parttion number 51 movb $5, %cl 52 shlw %cl, %si # %si = offset to parttable 53 addw $4, %si 54 movb parttable(%si), %al # IPLS 55 movb %al, b_sector 56 incw %si 57 movb parttable(%si), %al # IPLH 58 movb %al, b_head 59 incw %si # IPLC 60 movw parttable(%si), %ax 61 movw %ax, b_cylinder 62 63 # Step 2: Calculate the segment address of the bootstrap routine 64 movw $0x1d00, %ax 65 movw b_secsize, %cx 66 shrw %cx 67 shrw %cx 68 subw %cx, %ax 69 subw $0x100, %ax 70 movw %ax, b_bootseg 71 72 # Step 3: Read bootstrap code 73 movb $6, %ah 74 movb b_daua, %al 75 movw b_secsize, %bx 76 shlw %bx # 2 sectors 77 movw b_cylinder, %cx 78 movb b_head, %dh 79 movb b_sector, %dl 80 movw b_bootseg, %es 81 xorw %bp, %bp 82 int $0x1b 83 jc boot_error 84 85 # Step 4: Set DA/UA into BIOS work area 86 xorw %ax, %ax 87 movw %ax, %es 88 movw $0x584, %bx # DISK_BOOT 89 movb b_daua, %dl 90 call write_biosparam 91 92 call sc_clean 93 # Step 5: Set registers 94 # %ah: 00 95 # %al: DA/UA 96 # %bx: Sector size * 2 97 # %cx: cylinder number of boot partition 98 # %si: pointer to partition table 99 movw b_partn, %ax 100 movb $5, %cl 101 shl %cl, %ax # %ax = partition number * 32 102 addw b_secsize, %ax 103 movw %ax, %si # %si = pointer to partition table 104 movw b_cylinder, %cx # %cx = cylinder 105 movb b_head, %dh # %dh = head 106 movb b_sector, %dl # %dl = sector 107 movw b_bootseg, %es # %es = boot segment 108 movb b_daua, %al # %al = DA/UA 109 movw b_secsize, %bx 110 shlw %bx # %bx = sector size * 2 111 cli 112 movw %cs:iniss, %ss # Restore stack pointer 113 movw %cs:inisp, %sp 114 push %es # Boot segment 115 xorw %bp, %bp 116 push %bp # 0 117 movw %ax, %di # Save %ax 118 xorw %ax, %ax 119 movw %ax, %ds # %ds = 0 120 movw %di, %ax # Restore %ax 121 xorb %ah, %ah # %ah = 0 122 xorw %di, %di # %di = 0 123 sti 124 125 # Jump to bootstrap code 126 lret 127 # NOTREACHED 128 129boot_error: 130 ret 131 132# 133# Try to boot from default partition. 134# 135 .global trydefault 136trydefault: 137 movw ndevice, %cx 138 xorw %si, %si 139trydefault_loop: 140 movw %si, curdevice 141 push %cx 142 push %si 143 call read_ipl 144 pop %si 145 pop %cx 146 cmpb $0x80, defpartflag 147 jne nodefpart 148 # Default partition is defined. 149 push %cx 150 movw npartition, %cx 151srch_part: 152 movw %cx, %bx 153 decw %bx 154 movb defpartnum, %al # %al = real partition number 155 cmpb partnum(%bx), %al 156 jne not_match 157 movw %bx, curpartition # Store partition number 158 call boot 159not_match: 160 loop srch_part 161 pop %cx 162nodefpart: 163 incw %si 164 loop trydefault_loop 165 ret 166 167 .data 168b_daua: .byte 0 # DA/UA 169b_head: .byte 0 # SYSH 170b_sector: .byte 0 # SYSS 171b_cylinder: .word 0 # SYSC 172b_bootseg: .word 0 173b_secsize: .word 0 174b_partn: .word 0 # Real partition number 175