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