2 * Mach Operating System
3 * Copyright (c) 1992, 1991 Carnegie Mellon University
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.
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.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
26 * from: Mach, Revision 2.2 92/04/04 11:36:29 rpd
31 Copyright 1988, 1989, 1990, 1991, 1992
32 by Intel Corporation, Santa Clara, California.
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.
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.
53 * Ported to PC-9801 by Yoshio Kimura
61 LOADSZ= 8192 /* size of unix boot */
63 NAMEBLOCKMAGIC= 0xfadefeed /* value of magicnumebr for block2 */
66 * This DEBUGMSG(msg) macro may be useful for debugging. Its use is
67 * restricted to this file since it only works in real mode.
69 #define DEBUGMSG(msg) \
90 /* set up %ss and %esp */
94 * make a little room on the stack for
95 * us to save the default bootstring we might find..
96 * effectively, we push the bootstring.
98 mov $BOOTSTACK-64, %esp
100 /* set up %es, (where we will load boot2 to) */
110 /* set up graphic screen */
117 mov $0x0a00, %eax /* 80 x 25 mode */
120 movb $0x0c, %ah /* text on */
123 /* cursor home and on */
134 /* transfer PC-9801 system common area to 0xa1000 */
142 /* transfer EPSON machine type to 0xa1200 */
147 and $0x00ffffff, %eax
148 mov %eax, %es: (0x1624)
155 /* bootstrap passes */
178 mov %cs: (boot_cyl), %ecx /* actualy %cx in real mode */
185 * BIOS call "INT 0x1B Function 0xn6" to read sectors from disk into memory
186 * Call with %ah = 0xd6(for floppy disk) or 0x06(for hard disk)
189 * %ch = sector size(for floppy) or cylinder(for hard)
193 * %es:%bp = segment:offset of buffer
195 * %ah = 0x0 on success; err code on failure
201 * Load the second sector and see if it is a boot instruction block.
202 * If it is then scan the contents for the first valid string and copy it to
203 * the location of the default boot string.. then zero it out.
204 * Finally write the block back to disk with the zero'd out entry..
205 * I hate writing at this stage but we need this to be persistant.
206 * If the boot fails, then the next boot will get the next string.
207 * /etc/rc will regenerate a complete block2 iff the boot succeeds.
209 * Format of block 2 is:
210 * [NAMEBLOCKMAGIC] <--0xdeafc0de
212 * [bootstring]NULL <---e.g. 0:wd(0,a)/kernel.experimental
213 * [bootstring]NULL <---e.g. 0:wd(0,a)/kernel.old
215 * [bootstring]NULL <---e.g. 0:wd(0,f)/kernel
220 * save things we might smash
221 * (that are not smashed immedatly after us anyway.)
224 push %ecx /* preserve 'cyl,sector ' */
228 * Load the second sector
229 * BIOS call "INT 0x13 Function 0x2" to read sectors from disk into memory
230 * Call with %ah = 0x2
231 * %al = number of sectors
235 * %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
236 * %es:%bx = segment:offset of buffer
238 * %al = 0x0 on success; err code on failure
241 movl $0x0201, %eax /function 2 (read) 1 sector */
242 xor %ebx, %ebx /* %bx = 0 */ /* buffer address (ES:0) */
244 movl $0x0002, %ecx /* sector 2, cylinder 0 */
246 andl $0x00ff, %edx /* head 0, drive N */
251 * confirm that it is one for us
254 xorl %ebx, %ebx /* magic number at start of buffer */
257 movl %es:(%ebx), %eax
259 cmpl $NAMEBLOCKMAGIC, %eax
261 jne notours /* not ours so return to caller */
263 * scan for a bootstring
264 * Skip the magic number, and scan till we find a non-null,
267 incl %ebx /* quicker and smaller */
273 movb %es:(%ebx), %al /* load the next byte */
274 testb %al, %al /* and if it is null */
275 data32 /* keep scanning (past deleted entries) */
277 incb %al /* now look for -1 */
279 jz notours /* if we reach the 0xFF then we have finished */
282 * save our settings.. we need them twice..
287 * copy it to the default string location
288 * which is just above the stack for 64 bytes.
291 movl $BOOTSTACK-64, %ecx /* 64 bytes at the top of the stack */
294 movb %es:(%ebx), %al /* get the next byte in */
296 movb %al, %es:(%ecx) /* and transfer it to the name buffer */
297 incl %ebx /* get on with the next byte */
298 incl %ecx /* get on with the next byte */
299 testb %al, %al /* if it was 0 then quit this */
301 jnz nxtbyte /* and looop if more to do */
304 * restore the saved settings and
305 * zero it out so next time we don't try it again
308 pop %ebx /* get back our starting location */
309 #ifdef NAMEBLOCK_WRITEBACK
312 movb %es:(%ebx), %al /* get the byte */
314 movb $0, %es:(%ebx) /* zero it out */
316 incl %ebx /* point to the next byte */
317 testb %al, %al /* check if we have finished.. */
321 * Write the second sector back
322 * Load the second sector
323 * BIOS call "INT 0x13 Function 0x3" to write sectors from memory to disk
324 * Call with %ah = 0x3
325 * %al = number of sectors
329 * %dl = drive (0x80 for hard disk, 0x0 for floppy disk)
330 * %es:%bx = segment:offset of buffer
332 * %al = 0x0 on success; err code on failure
335 movl $0x0301, %eax /* write 1 sector */
336 xor %ebx, %ebx /* buffer is at offset 0 */
338 movl $0x0002, %ecx /* block 2 */
340 andl $0xff, %edx /* head 0 */
347 #endif /* NAMEBLOCK_WRITEBACK */
349 * return to the main-line
359 xor %bp, %bp /* %bp = 0, put it at 0 in the BOOTSEG */
364 * ljmp to the second stage boot loader (boot2).
365 * After ljmp, %cs is BOOTSEG and boot1 (512 bytes) will be used
366 * as an internal buffer "intbuf".
371 ljmp $BOOTSEG, $ EXT(boot2)
384 * message: write the error message in %ds:%esi to console
407 lodsb /* load a byte into %al */
414 movb %bl, %es:0x2000(%di)
440 jmp stop /* halt doesnt actually halt forever */
454 #ifdef NAMEBLOCK_WRITEBACK
455 ewrite: String "Write error\r\n\0"
456 #endif /* NAMEBLOCK_WRITEBACK */
457 eread: String "Read error\r\n\0"
458 enoboot: String "No bootable partition\r\n\0"
461 . = EXT(start) + 0x1be
463 /* Partition table */
466 .byte 0x80, 0x00, 0x01, 0x00
467 .byte 0xa5, 0xff, 0xff, 0xff
468 .byte 0x00, 0x00, 0x00, 0x00
469 .byte 0x50, 0xc3, 0x00, 0x00
471 /* the last 2 bytes in the sector 0 contain the signature */
475 . = EXT(start) + 0x400