Commit | Line | Data |
---|---|---|
15637ed4 RG |
1 | /* |
2 | * Ported to boot 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 | |
3 | * | |
4 | * Mach Operating System | |
5 | * Copyright (c) 1992, 1991 Carnegie Mellon University | |
6 | * All Rights Reserved. | |
7 | * | |
8 | * Permission to use, copy, modify and distribute this software and its | |
9 | * documentation is hereby granted, provided that both the copyright | |
10 | * notice and this permission notice appear in all copies of the | |
11 | * software, derivative works or modified versions, and any portions | |
12 | * thereof, and that both notices appear in supporting documentation. | |
13 | * | |
14 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
15 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
16 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
17 | * | |
18 | * Carnegie Mellon requests users of this software to return to | |
19 | * | |
20 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
21 | * School of Computer Science | |
22 | * Carnegie Mellon University | |
23 | * Pittsburgh PA 15213-3890 | |
24 | * | |
25 | * any improvements or extensions that they make and grant Carnegie Mellon | |
26 | * the rights to redistribute these changes. | |
27 | */ | |
28 | ||
29 | /* | |
30 | * HISTORY | |
31 | * $Log: start.s,v $ | |
32 | * Revision 2.2 92/04/04 11:36:29 rpd | |
33 | * Fix Intel Copyright as per B. Davies authorization. | |
34 | * [92/04/03 rvb] | |
35 | * Need to zero dh on hd path; at least for an adaptec card. | |
36 | * [92/01/14 rvb] | |
37 | * | |
38 | * From 2.5 boot: | |
39 | * Flush digit printing. | |
40 | * Fuse floppy and hd boot by using Int 21 to tell | |
41 | * boot type (slightly dubious since Int 21 is DOS | |
42 | * not BIOS) | |
43 | * [92/03/30 mg32] | |
44 | * | |
45 | * Revision 2.2 91/04/02 14:42:04 mbj | |
46 | * Fix the BIG boot bug. We had missed a necessary data | |
47 | * before a xor that was clearing a register used later | |
48 | * as an index register. | |
49 | * [91/03/01 rvb] | |
50 | * Remember floppy type for swapgeneric | |
51 | * Add Intel copyright | |
52 | * [90/02/09 rvb] | |
53 | * | |
54 | */ | |
55 | ||
56 | ||
57 | /* | |
58 | Copyright 1988, 1989, 1990, 1991, 1992 | |
59 | by Intel Corporation, Santa Clara, California. | |
60 | ||
61 | All Rights Reserved | |
62 | ||
63 | Permission to use, copy, modify, and distribute this software and | |
64 | its documentation for any purpose and without fee is hereby | |
65 | granted, provided that the above copyright notice appears in all | |
66 | copies and that both the copyright notice and this permission notice | |
67 | appear in supporting documentation, and that the name of Intel | |
68 | not be used in advertising or publicity pertaining to distribution | |
69 | of the software without specific, written prior permission. | |
70 | ||
71 | INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE | |
72 | INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, | |
73 | IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR | |
74 | CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM | |
75 | LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, | |
76 | NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION | |
77 | WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
78 | */ | |
79 | #include "asm.h" | |
80 | ||
81 | .file "start.s" | |
82 | ||
83 | BOOTSEG = 0x9000 # boot will be loaded at 640k-64k | |
84 | BOOTSTACK = 0xe000 # boot stack | |
85 | SIGNATURE = 0xaa55 | |
86 | LOADSZ = 14 # size of unix boot | |
87 | PARTSTART = 0x1be # starting address of partition table | |
88 | NUMPART = 4 # number of partitions in partition table | |
89 | PARTSZ = 16 # each partition table entry is 16 bytes | |
90 | BSDPART = 0xA5 # value of boot_ind, means bootable partition | |
91 | BOOTABLE = 0x80 # value of boot_ind, means bootable partition | |
92 | ||
93 | .text | |
94 | ||
95 | ENTRY(boot1) | |
96 | ||
97 | # boot1 is loaded at 0x0:0x7c00 | |
98 | # ljmp to the next instruction to set up %cs | |
99 | data32 | |
100 | ljmp $0x7c0, $start | |
101 | ||
102 | start: | |
103 | # set up %ds | |
104 | mov %cs, %ax | |
105 | mov %ax, %ds | |
106 | ||
107 | ||
108 | # set up %ss and %esp | |
109 | data32 | |
110 | mov $BOOTSEG, %eax | |
111 | mov %ax, %ss | |
112 | data32 | |
113 | mov $BOOTSTACK, %esp | |
114 | ||
115 | /*** set up %es, (where we will load boot2 to) ***/ | |
116 | mov %ax, %es | |
117 | ||
118 | #ifdef DEBUG | |
119 | data32 | |
120 | mov $one, %esi | |
121 | data32 | |
122 | call message | |
123 | #endif | |
124 | # get the boot drive id | |
125 | movb $0x33, %ah | |
126 | movb $0x05, %al | |
127 | int $0x21 | |
128 | ||
129 | cmpb $0x80, %dl | |
130 | data32 | |
131 | jge hd | |
132 | ||
133 | fd: | |
134 | # reset the disk system | |
135 | #ifdef DEBUG | |
136 | data32 | |
137 | mov $two, %esi | |
138 | data32 | |
139 | call message | |
140 | #endif | |
141 | movb $0x0, %ah | |
142 | int $0x13 | |
143 | data32 | |
144 | mov $0x0001, %ecx # cyl 0, sector 1 | |
145 | data32 | |
146 | #ifdef DEBUG | |
147 | data32 | |
148 | mov $three, %esi | |
149 | data32 | |
150 | call message | |
151 | #endif | |
152 | jmp load | |
153 | ||
154 | hd: /**** load sector 0 into the BOOTSEG ****/ | |
155 | #ifdef DEBUG | |
156 | data32 | |
157 | mov $four, %esi | |
158 | data32 | |
159 | call message | |
160 | #endif | |
161 | data32 | |
162 | mov $0x0201, %eax | |
163 | xor %ebx, %ebx # %bx = 0 | |
164 | data32 | |
165 | mov $0x0001, %ecx | |
166 | #ifdef DEBUG | |
167 | data32 | |
168 | mov $five, %esi | |
169 | data32 | |
170 | call message | |
171 | #endif | |
172 | data32 | |
173 | andl $0xff, %edx | |
174 | /*mov $0x0080, %edx*/ | |
175 | int $0x13 | |
176 | data32 | |
177 | jb read_error | |
178 | ||
179 | /***# find the bootable partition *****/ | |
180 | data32 | |
181 | mov $PARTSTART, %ebx | |
182 | data32 | |
183 | mov $NUMPART, %ecx | |
184 | again: | |
185 | addr16 | |
186 | movb %es:4(%ebx), %al | |
187 | cmpb $BSDPART, %al | |
188 | data32 | |
189 | je found | |
190 | data32 | |
191 | add $PARTSZ, %ebx | |
192 | data32 | |
193 | loop again | |
194 | data32 | |
195 | mov $enoboot, %esi | |
196 | data32 | |
197 | jmp err_stop | |
198 | ||
199 | ||
200 | /* | |
201 | # BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory | |
202 | # Call with %ah = 0x2 | |
203 | # %al = number of sectors | |
204 | # %ch = cylinder | |
205 | # %cl = sector | |
206 | # %dh = head | |
207 | # %dl = drive (0x80 for hard disk, 0x0 for floppy disk) | |
208 | # %es:%bx = segment:offset of buffer | |
209 | # Return: | |
210 | # %al = 0x0 on success; err code on failure | |
211 | */ | |
212 | ||
213 | found: | |
214 | addr16 | |
215 | movb %es:1(%ebx), %dh /* head */ | |
216 | addr16 | |
217 | xor %ecx, %ecx | |
218 | addr16 | |
219 | movw %es:2(%ebx), %ecx /*sect,cyl (+ 2 bytes junk in top word )*/ | |
220 | ||
221 | load: | |
222 | movb $0x2, %ah /* function 2 */ | |
223 | movb $LOADSZ, %al /* number of blocks */ | |
224 | xor %ebx, %ebx /* %bx = 0, put it at 0 in the BOOTSEG */ | |
225 | int $0x13 | |
226 | data32 | |
227 | jb read_error | |
228 | ||
229 | # ljmp to the second stage boot loader (boot2). | |
230 | # After ljmp, %cs is BOOTSEG and boot1 (512 bytes) will be used | |
231 | # as an internal buffer "intbuf". | |
232 | ||
233 | #ifdef DEBUG | |
234 | data32 | |
235 | mov $six, %esi | |
236 | data32 | |
237 | call message | |
238 | #endif | |
239 | data32 | |
240 | ljmp $BOOTSEG, $EXT(boot2) | |
241 | ||
242 | # | |
243 | # read_error | |
244 | # | |
245 | ||
246 | read_error: | |
247 | ||
248 | data32 | |
249 | mov $eread, %esi | |
250 | err_stop: | |
251 | data32 | |
252 | call message | |
253 | data32 | |
254 | jmp stop | |
255 | ||
256 | # | |
257 | # message: write the error message in %ds:%esi to console | |
258 | # | |
259 | ||
260 | message: | |
261 | # Use BIOS "int 10H Function 0Eh" to write character in teletype mode | |
262 | # %ah = 0xe %al = character | |
263 | # %bh = page %bl = foreground color (graphics modes) | |
264 | ||
265 | data32 | |
266 | push %eax | |
267 | data32 | |
268 | push %ebx | |
269 | data32 | |
270 | mov $0x0001, %ebx | |
271 | cld | |
272 | ||
273 | nextb: | |
274 | lodsb # load a byte into %al | |
275 | cmpb $0x0, %al | |
276 | data32 | |
277 | je done | |
278 | movb $0xe, %ah | |
279 | int $0x10 # display a byte | |
280 | data32 | |
281 | jmp nextb | |
282 | done: | |
283 | data32 | |
284 | pop %ebx | |
285 | data32 | |
286 | pop %eax | |
287 | data32 | |
288 | ret | |
289 | ||
290 | stop: hlt | |
291 | data32 | |
292 | jmp stop # halt doesnt actually halt forever | |
293 | ||
294 | /* error messages */ | |
295 | ||
296 | #ifdef DEBUG | |
297 | one: String "1\r\n\0" | |
298 | two: String "2\r\n\0" | |
299 | three: String "3\r\n\0" | |
300 | four: String "4\r\n\0" | |
301 | five: String "5\r\n\0" | |
302 | six: String "6\r\n\0" | |
303 | seven: String "7\r\n\0" | |
304 | #endif DEBUG | |
305 | eread: String "Read error\r\n\0" | |
306 | enoboot: String "No bootable partition\r\n\0" | |
307 | endofcode: | |
308 | /* throw in a partition in case we are block0 as well */ | |
309 | /* flag,head,sec,cyl,typ,ehead,esect,ecyl,start,len */ | |
310 | . = EXT(boot1) + PARTSTART | |
311 | .byte 0x0,0,0,0,0,0,0,0 | |
312 | .long 0,0 | |
313 | .byte 0x0,0,0,0,0,0,0,0 | |
314 | .long 0,0 | |
315 | .byte 0x0,0,0,0,0,0,0,0 | |
316 | .long 0,0 | |
317 | .byte BOOTABLE,0,1,0,BSDPART,255,255,255 | |
318 | .long 0,50000 | |
319 | /* the last 2 bytes in the sector 0 contain the signature */ | |
320 | . = EXT(boot1) + 0x1fe | |
321 | .value SIGNATURE | |
322 | ENTRY(disklabel) | |
323 | . = EXT(boot1) + 0x400 |