|
|
1.1 root 1: /*
2: * Ported to boot 386BSD by Julian Elischer ([email protected]) 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 [email protected]
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
1.1.1.2 ! root 31: * boot2.S,v
! 32: Revision 1.3 1993/07/13 21:51:36 mycroft
! 33: Fix addressing bug in bdb junk.
! 34:
! 35: Revision 1.2 1993/07/11 12:02:22 andrew
! 36: Fixes from bde, including support for loading @ any MB boundary (e.g. a
! 37: kernel linked for 0xfe100000 will load at the 1MB mark) and read-ahead
! 38: buffering to speed booting from floppies. Also works with aha174x
! 39: controllers in enhanced mode.
! 40:
! 41: *
! 42: * 93/07/06 bde
! 43: * Delete LOADMSG define (not used).
! 44: *
! 45: * 93/06/29 bde
! 46: * Use EXT.
! 47: *
! 48: * Initialize GDT and IDT pointers at boot time.
! 49: *
! 50: * Convert (drive | head | junk) to drive arg for boot() (not strictly
! 51: * necessary - boot() only uses drive & 0x80).
1.1 root 52: *
1.1.1.2 ! root 53: * 93/06/28 bde
! 54: * Initialize top bits of %eax for setting _ouraddr. start.s
! 55: * initialized them suitably, but this isn't documented, and the BIOS
! 56: * isn't documented to preserve them.
! 57: *
! 58: * Use addr32 for setting _ouraddr. Without this, there were extra bytes
! 59: * 0, 0 after the store. These decode as "add %al, (%bx,%si)" in 16-bit
! 60: * mode would clobber something (except %al is very likely to be 0 :-).
! 61: *
! 62: * Clear the bss. This may be unnecessary. Some is already cleared in
! 63: * the disk image.
! 64: *
! 65: * Loop if boot() returns.
! 66: *
! 67: Revision 1.1 1993/03/21 18:08:33 cgd
! 68: after 0.2.2 "stable" patches applied
! 69:
1.1 root 70: * Revision 2.2 92/04/04 11:35:26 rpd
71: * From 2.5
72: * [92/03/30 rvb]
73: *
74: * Revision 2.2 91/04/02 14:39:21 mbj
75: * Put into rcs tree
76: * [90/02/09 rvb]
77: *
78: */
79:
80: #include "asm.h"
1.1.1.2 ! root 81:
! 82: /* Conventional GDT indexes. */
! 83: #define BOOT_CS_INDEX 3
! 84: #define BOOT_CS16_INDEX 5
! 85: #define BOOT_DS_INDEX 4
! 86: #define DB_CS_INDEX 14
! 87: #define DB_CS16_INDEX 15
! 88: #define DB_DS_INDEX 16
! 89: #define GDT_INDEX 17
! 90:
! 91: /* Vector numbers. */
! 92: #define BREAKPOINT_VECTOR 3
! 93: #define DEBUG_VECTOR 1
! 94:
1.1 root 95: /*
96: * boot2() -- second stage boot
97: */
98:
1.1.1.2 ! root 99: .globl EXT(ouraddr)
1.1 root 100:
101: ENTRY(boot2)
102: data32
1.1.1.2 ! root 103: subl %eax, %eax
! 104: mov %cs, %ax
! 105: mov %ax, %ds
! 106: mov %ax, %es
1.1 root 107: data32
1.1.1.2 ! root 108: shll $4, %eax
! 109: addr32
1.1 root 110: data32
1.1.1.2 ! root 111: movl %eax, EXT(ouraddr)
! 112:
! 113: /* fix up GDT entries for bootstrap */
! 114: #define FIXUP(gdt_index) \
! 115: addr32; \
! 116: movl %eax, EXT(Gdt)+(8*gdt_index)+2; /* actually movw %ax */ \
! 117: addr32; \
! 118: movb %bl, EXT(Gdt)+(8*gdt_index)+4
! 119:
! 120: data32
! 121: shld $16, %eax, %ebx
! 122: FIXUP(BOOT_CS_INDEX)
! 123: FIXUP(BOOT_CS16_INDEX)
! 124: FIXUP(BOOT_DS_INDEX)
! 125:
! 126: /* fix up GDT entry for GDT, and GDT and IDT pointers */
! 127: data32
! 128: movl %eax, %ecx
! 129: data32
! 130: addl $ EXT(Gdt), %eax
! 131: data32
! 132: shld $16, %eax, %ebx
! 133: FIXUP(GDT_INDEX)
! 134: addr32
! 135: data32
! 136: movl %eax, EXT(Gdtr)+2
! 137: data32
! 138: addl $ EXT(Idt), %ecx
! 139: addr32
! 140: data32
! 141: movl %ecx, EXT(Idtr_prot)+2
! 142:
! 143: /* %es = vector table segment for a while */
! 144: push %es
! 145: data32
! 146: subl %eax, %eax
! 147: mov %ax, %es
! 148:
! 149: /* fix up GDT entries for bdb */
! 150: data32
! 151: movl $4*DEBUG_VECTOR, %esi
! 152: addr32
! 153: movl %es: 2(%esi), %eax /* actually movw to %ax */
! 154: data32
! 155: shll $4, %eax
! 156: data32
! 157: shld $16, %eax, %ebx
! 158: FIXUP(DB_CS_INDEX)
! 159: FIXUP(DB_CS16_INDEX)
! 160: FIXUP(DB_DS_INDEX)
! 161:
! 162: /* Fetch entry points of bdb's protected mode trap handlers. These
! 163: * are stored at 2 before the corresponding entry points for real mode.
! 164: */
! 165: data32
! 166: subl %ebx, %ebx
! 167: addr32
! 168: movl %es: (%esi), %ebx /* actually movw to %bx */
! 169: data32
! 170: subl %ecx, %ecx
! 171: addr32
! 172: movl %es: 4*(BREAKPOINT_VECTOR-DEBUG_VECTOR)(%esi), %ecx
! 173: /* actually movw to %cx */
! 174:
! 175: /* %es = bdb segment for a while */
! 176: data32
! 177: shrl $4, %eax
! 178: mov %ax, %es
! 179:
! 180: /* fix up IDT entries for bdb */
! 181: movl %es: -2(%ebx), %eax /* actually movw to %ax */
! 182: addr32
! 183: movl %eax, EXT(Idt)+8*DEBUG_VECTOR /* actually movw %ax */
! 184: movl %es: -2(%ecx), %eax /* actually movw to %ax */
! 185: addr32
! 186: movl %eax, EXT(Idt)+8*BREAKPOINT_VECTOR /* actually movw %ax */
! 187:
! 188: /* finished with groping in real mode segments */
! 189: pop %es
! 190:
1.1 root 191: /* change to protected mode */
192: data32
1.1.1.2 ! root 193: call EXT(real_to_prot)
! 194:
! 195: /* clear the bss */
! 196: movl $ EXT(edata), %edi /* no EXT(_edata) - krufty ld */
! 197: movl $ EXT(end), %ecx /* or EXT(_end) */
! 198: subl %edi, %ecx
! 199: subb %al, %al
! 200: rep
! 201: stosb
1.1 root 202:
1.1.1.2 ! root 203: movzbl %dl, %edx /* discard head (%dh) and random high bits */
! 204: pushl %edx
! 205: call EXT(boot)
! 206: oops:
! 207: hlt
! 208: jmp oops
1.1 root 209:
210: .data
211: .align 2
1.1.1.2 ! root 212: #if 0 /* XXX this would give losing "_ouraddr :". Better declared in C */
! 213: EXT(ouraddr):
! 214: #else
1.1 root 215: _ouraddr:
1.1.1.2 ! root 216: #endif
1.1 root 217: .long 0
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.