This commit was generated by cvs2svn to track changes on a CVS vendor
[unix-history] / sys / i386 / boot / start.S
CommitLineData
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 26 * from: Mach, Revision 2.2 92/04/04 11:36:29 rpd
d1531e51 27 * $Id: start.S,v 1.2 1993/10/16 19:11:38 rgrimes Exp $
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
36Permission to use, copy, modify, and distribute this software and
37its documentation for any purpose and without fee is hereby
38granted, provided that the above copyright notice appears in all
39copies and that both the copyright notice and this permission notice
40appear in supporting documentation, and that the name of Intel
41not be used in advertising or publicity pertaining to distribution
42of the software without specific, written prior permission.
43
44INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
45INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS,
46IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR
47CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
48LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT,
49NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
50WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
51*/
52#include "asm.h"
53
54 .file "start.s"
55
56BOOTSEG = 0x9000 # boot will be loaded here (below 640K)
57BOOTSTACK = 0xe000 # boot stack
58SIGNATURE = 0xaa55
59LOADSZ = 15 # size of unix boot
60PARTSTART = 0x1be # starting address of partition table
61NUMPART = 4 # number of partitions in partition table
62PARTSZ = 16 # each partition table entry is 16 bytes
63BSDPART = 0xA5 # value of boot_ind, means bootable partition
64BOOTABLE = 0x80 # value of boot_ind, means bootable partition
65
66 .text
67
68ENTRY(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
74start:
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
101fd:
d1531e51 102 mov $0x0, %dl
a27f4645
RM
103# reset the disk system
104#ifdef DEBUG
105 data32
106 mov $two, %esi
107 data32
108 call message
109#endif
110 movb $0x0, %ah
111 int $0x13
112 data32
113 mov $0x0001, %ecx # cyl 0, sector 1
114 movb $0, %dh # head
115#ifdef DEBUG
116 data32
117 mov $three, %esi
118 data32
119 call message
120#endif
121 data32
122 jmp load
123
124hd: /**** load sector 0 into the BOOTSEG ****/
125#ifdef DEBUG
126 data32
127 mov $four, %esi
128 data32
129 call message
130#endif
131 data32
132 mov $0x0201, %eax
133 xor %ebx, %ebx # %bx = 0
134 data32
135 mov $0x0001, %ecx
136#ifdef DEBUG
137 data32
138 mov $five, %esi
139 data32
140 call message
141#endif
142 data32
143 andl $0xff, %edx
144 /*mov $0x0080, %edx*/
145 int $0x13
146 data32
147 jb read_error
148
149 /***# find the first 386BSD partition *****/
150 data32
151 mov $PARTSTART, %ebx
152 data32
153 mov $NUMPART, %ecx
154again:
155 addr32
156 movb %es:4(%ebx), %al
157 cmpb $BSDPART, %al
158 data32
159 je found
160 data32
161 add $PARTSZ, %ebx
162 data32
163 loop again
164 data32
165 mov $enoboot, %esi
166 data32
167 jmp err_stop
168
169
170/*
171# BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory
172# Call with %ah = 0x2
173# %al = number of sectors
174# %ch = cylinder
175# %cl = sector
176# %dh = head
177# %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
178# %es:%bx = segment:offset of buffer
179# Return:
180# %al = 0x0 on success; err code on failure
181*/
182
183found:
184 addr32
185 movb %es:1(%ebx), %dh /* head */
186 addr32
187 movl %es:2(%ebx), %ecx /*sect, cyl (+ 2 bytes junk in top word) */
188
189load:
190 movb $0x2, %ah /* function 2 */
191 movb $LOADSZ, %al /* number of blocks */
192 xor %ebx, %ebx /* %bx = 0, put it at 0 in the BOOTSEG */
193 int $0x13
194 data32
195 jb read_error
196
197 # ljmp to the second stage boot loader (boot2).
198 # After ljmp, %cs is BOOTSEG and boot1 (512 bytes) will be used
199 # as an internal buffer "intbuf".
200
201#ifdef DEBUG
202 data32
203 mov $six, %esi
204 data32
205 call message
206#endif
207 data32
208 ljmp $BOOTSEG, $ EXT(boot2)
209
210#
211# read_error
212#
213
214read_error:
215 data32
216 mov $eread, %esi
217err_stop:
218 data32
219 call message
220 data32
221 jmp stop
222
223#
224# message: write the error message in %ds:%esi to console
225#
226
227message:
228/*
229 # Use BIOS "int 10H Function 0Eh" to write character in teletype mode
230 # %ah = 0xe %al = character
231 # %bh = page %bl = foreground color (graphics modes)
232*/
233
234 data32
235 push %eax
236 data32
237 push %ebx
238 data32
239 mov $0x0001, %ebx
240 cld
241
242nextb:
243 lodsb # load a byte into %al
244 cmpb $0x0, %al
245 data32
246 je done
247 movb $0xe, %ah
248 int $0x10 # display a byte
249 data32
250 jmp nextb
251done:
252 data32
253 pop %ebx
254 data32
255 pop %eax
256 data32
257 ret
258
259stop: hlt
260 data32
261 jmp stop # halt doesnt actually halt forever
262
263/* error messages */
264
265#ifdef DEBUG
266one: String "1\r\n\0"
267two: String "2\r\n\0"
268three: String "3\r\n\0"
269four: String "4\r\n\0"
270five: String "5\r\n\0"
271six: String "6\r\n\0"
272seven: String "7\r\n\0"
273#endif DEBUG
274eread: String "Read error\r\n\0"
275enoboot: String "No bootable partition\r\n\0"
276endofcode:
277/* throw in a partition in case we are block0 as well */
278/* flag, head, sec, cyl, typ, ehead, esect, ecyl, start, len */
279 . = EXT(boot1) + PARTSTART
280 .byte 0x0,0,0,0,0,0,0,0
281 .long 0,0
282 .byte 0x0,0,0,0,0,0,0,0
283 .long 0,0
284 .byte 0x0,0,0,0,0,0,0,0
285 .long 0,0
286 .byte BOOTABLE,0,1,0,BSDPART,255,255,255
287 .long 0,50000
288/* the last 2 bytes in the sector 0 contain the signature */
289 . = EXT(boot1) + 0x1fe
290 .value SIGNATURE
291ENTRY(disklabel)
292 . = EXT(boot1) + 0x400