Deleted Added
sdiff udiff text old ( 50477 ) new ( 60821 )
full compact
1#
2# Copyright (c) 1998 Robert Nordier
3# All rights reserved.
4#
5# Redistribution and use in source and binary forms are freely
6# permitted provided that the above copyright notice and this
7# paragraph and the following disclaimer are duplicated in all
8# such forms.
9#
10# This software is provided "AS IS" and without any express or
11# implied warranties, including, without limitation, the implied
12# warranties of merchantability and fitness for a particular
13# purpose.
14#
15
16# $FreeBSD: head/sys/boot/i386/boot2/boot1.S 60821 2000-05-23 12:18:49Z jhb $
17
18 .set MEM_REL,0x700 # Relocation address
19 .set MEM_ARG,0x900 # Arguments
20 .set MEM_ORG,0x7c00 # Origin
21 .set MEM_BUF,0x8c00 # Load area
22 .set MEM_BTX,0x9000 # BTX start
23 .set MEM_JMP,0x9010 # BTX entry point
24 .set MEM_USR,0xa000 # Client start
25
26 .set PRT_OFF,0x1be # Partition offset
27 .set PRT_NUM,0x4 # Partitions
28 .set PRT_BSD,0xa5 # Partition type
29
30 .set SIZ_PAG,0x1000 # Page size
31 .set SIZ_SEC,0x200 # Sector size
32
33 .globl start
34 .globl xread
35 .code16
36
37start: jmp main # Start recognizably
38
39 .org 0x4,0x90
40
41# External read from disk
42
43xread: push %ss # Address
44 pop %ds # data
45xread.1: # Starting
46 pushl $0x0 # absolute
47 push %cx # block
48 push %ax # number
49 push %es # Address of
50 push %bx # transfer buffer
51 xor %ax,%ax # Number of
52 movb %dh,%al # blocks to
53 push %ax # transfer
54 push $0x10 # Size of packet
55 mov %sp,%bp # Packet pointer
56 callw read # Read from disk
57 lea 0x10(%bp),%sp # Clear stack
58 lret # To far caller
59
60# Bootstrap
61
62main: cld # String ops inc
63 xor %cx,%cx # Zero
64 mov %cx,%es # Address
65 mov %cx,%ds # data
66 mov %cx,%ss # Set up
67 mov $start,%sp # stack
68 mov %sp,%si # Source
69 mov $MEM_REL,%di # Destination
70 incb %ch # Word count
71 rep # Copy
72 movsw # code
73 mov $part4,%si # Partition
74 cmpb $0x80,%dl # Hard drive?
75 jb main.4 # No
76 movb $0x1,%dh # Block count
77 callw nread # Read MBR
78 mov $0x1,%cx # Two passes
79main.1: mov $MEM_BUF+PRT_OFF,%si # Partition table
80 movb $0x1,%dh # Partition
81main.2: cmpb $PRT_BSD,0x4(%si) # Our partition type?
82 jne main.3 # No
83 jcxz main.5 # If second pass
84 testb $0x80,(%si) # Active?
85 jnz main.5 # Yes
86main.3: add $0x10,%si # Next entry
87 incb %dh # Partition
88 cmpb $0x1+PRT_NUM,%dh # In table?
89 jb main.2 # Yes
90 dec %cx # Do two
91 jcxz main.1 # passes
92 mov $msg_part,%si # Message
93 jmp error # Error
94main.4: xor %dx,%dx # Partition:drive
95main.5: mov %dx,MEM_ARG # Save args
96 movb $0x10,%dh # Sector count
97 callw nread # Read disk
98 mov $MEM_BTX,%bx # BTX
99 mov 0xa(%bx),%si # Point past
100 add %bx,%si # it
101 mov $MEM_USR+SIZ_PAG,%di # Client page 1
102 mov $MEM_BTX+0xe*SIZ_SEC,%cx # Byte
103 sub %si,%cx # count
104 rep # Relocate
105 movsb # client
106 sub %di,%cx # Byte count
107 xorb %al,%al # Zero
108 rep # assumed
109 stosb # bss
110 callw seta20 # Enable A20
111 jmp start+MEM_JMP-MEM_ORG # Start BTX
112
113# Enable A20
114
115seta20: cli # Disable interrupts
116seta20.1: inb $0x64,%al # Get status
117 testb $0x2,%al # Busy?
118 jnz seta20.1 # Yes
119 movb $0xd1,%al # Command: Write
120 outb %al,$0x64 # output port
121seta20.2: inb $0x64,%al # Get status
122 testb $0x2,%al # Busy?
123 jnz seta20.2 # Yes
124 movb $0xdf,%al # Enable
125 outb %al,$0x60 # A20
126 sti # Enable interrupts
127 retw # To caller
128
129# Local read from disk
130
131nread: mov $MEM_BUF,%bx # Transfer buffer
132 mov 0x8(%si),%ax # Get
133 mov 0xa(%si),%cx # LBA
134 push %cs # Read from
135 callw xread.1 # disk
136 jnc return # If success
137 mov $msg_read,%si # Message
138
139# Error exit
140
141error: callw putstr # Display message
142 mov $prompt,%si # Display
143 callw putstr # prompt
144 xorb %ah,%ah # BIOS: Get
145 int $0x16 # keypress
146 int $0x19 # BIOS: Reboot
147
148# Display string
149
150putstr.0: mov $0x7,%bx # Page:attribute
151 movb $0xe,%ah # BIOS: Display
152 int $0x10 # character
153putstr: lodsb # Get char
154 testb %al,%al # End of string?
155 jne putstr.0 # No
156
157ereturn: movb $0x1,%ah # Invalid
158 stc # argument
159return: retw # To caller
160
161# Read from disk
162
163read: testb $0x80,%cs:MEM_REL+flags-start # LBA support enabled?
164 jz read.1 # No
165 mov $0x55aa,%bx # Magic
166 push %dx # Save
167 movb $0x41,%ah # BIOS: Check
168 int $0x13 # extensions present
169 pop %dx # Restore
170 jc read.1 # If error
171 cmp $0xaa55,%bx # Magic?
172 jne read.1 # No
173 testb $0x1,%cl # Packet interface?
174 jz read.1 # No
175 mov %bp,%si # Disk packet
176 movb $0x42,%ah # BIOS: Extended
177 int $0x13 # read
178 retw # To caller
179
180read.1: push %dx # Save
181 movb $0x8,%ah # BIOS: Get drive
182 int $0x13 # parameters
183 movb %dh,%ch # Max head number
184 pop %dx # Restore
185 jc return # If error
186 andb $0x3f,%cl # Sectors per track
187 jz ereturn # If zero
188 cli # Disable interrupts
189 mov 0x8(%bp),%eax # Get LBA
190 push %dx # Save
191 movzbl %cl,%ebx # Divide by
192 xor %edx,%edx # sectors
193 div %ebx # per track
194 movb %ch,%bl # Max head number
195 movb %dl,%ch # Sector number
196 inc %bx # Divide by
197 xorb %dl,%dl # number
198 div %ebx # of heads
199 movb %dl,%bh # Head number
200 pop %dx # Restore
201 cmpl $0x3ff,%eax # Cylinder number supportable?
202 sti # Enable interrupts
203 ja ereturn # No
204 xchgb %al,%ah # Set up cylinder
205 rorb $0x2,%al # number
206 orb %ch,%al # Merge
207 inc %ax # sector
208 xchg %ax,%cx # number
209 movb %bh,%dh # Head number
210 subb %ah,%al # Sectors this track
211 mov 0x2(%bp),%ah # Blocks to read
212 cmpb %ah,%al # To read
213 jb read.2 # this
214 movb %ah,%al # track
215read.2: mov $0x5,%di # Try count
216read.3: les 0x4(%bp),%bx # Transfer buffer
217 push %ax # Save
218 movb $0x2,%ah # BIOS: Read
219 int $0x13 # from disk
220 pop %bx # Restore
221 jnc read.4 # If success
222 dec %di # Retry?
223 jz read.6 # No
224 xorb %ah,%ah # BIOS: Reset
225 int $0x13 # disk system
226 xchg %bx,%ax # Block count
227 jmp read.3 # Continue
228read.4: movzbw %bl,%ax # Sectors read
229 add %ax,0x8(%bp) # Adjust
230 jnc read.5 # LBA,
231 incw 0xa(%bp) # transfer
232read.5: shlb %bl # buffer
233 add %bl,0x5(%bp) # pointer,
234 sub %al,0x2(%bp) # block count
235 ja read.1 # If not done
236read.6: retw # To caller
237
238# Messages
239
240msg_read: .asciz "Read"
241msg_part: .asciz "Boot"
242
243prompt: .asciz " error\r\n"
244

--- 13 unchanged lines hidden ---