This commit was generated by cvs2svn to track changes on a CVS vendor
[unix-history] / sys / i386 / boot / boot2.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:35:26 rpd
fe139ecb 27 * $Id: boot2.S,v 1.2 1993/10/16 19:11:33 rgrimes Exp $
a27f4645
RM
28 */
29
30#include "asm.h"
31
32/* Conventional GDT indexes. */
33#define BOOT_CS_INDEX 3
34#define BOOT_CS16_INDEX 5
35#define BOOT_DS_INDEX 4
36#define DB_CS_INDEX 14
37#define DB_CS16_INDEX 15
38#define DB_DS_INDEX 16
39#define GDT_INDEX 17
40
41/* Vector numbers. */
42#define BREAKPOINT_VECTOR 3
43#define DEBUG_VECTOR 1
44
45/*
46 * boot2() -- second stage boot
47 */
48
49.globl EXT(ouraddr)
50
51ENTRY(boot2)
52 data32
53 subl %eax, %eax
54 mov %cs, %ax
55 mov %ax, %ds
56 mov %ax, %es
57 data32
58 shll $4, %eax
59 addr32
60 data32
61 movl %eax, EXT(ouraddr)
62
63 /* fix up GDT entries for bootstrap */
64#define FIXUP(gdt_index) \
65 addr32; \
66 movl %eax, EXT(Gdt)+(8*gdt_index)+2; /* actually movw %ax */ \
67 addr32; \
68 movb %bl, EXT(Gdt)+(8*gdt_index)+4
69
70 data32
71 shld $16, %eax, %ebx
72 FIXUP(BOOT_CS_INDEX)
73 FIXUP(BOOT_CS16_INDEX)
74 FIXUP(BOOT_DS_INDEX)
75
76 /* fix up GDT entry for GDT, and GDT and IDT pointers */
77 data32
78 movl %eax, %ecx
79 data32
80 addl $ EXT(Gdt), %eax
81 data32
82 shld $16, %eax, %ebx
83 FIXUP(GDT_INDEX)
84 addr32
85 data32
86 movl %eax, EXT(Gdtr)+2
87 data32
88 addl $ EXT(Idt), %ecx
89 addr32
90 data32
91 movl %ecx, EXT(Idtr_prot)+2
92
93 /* %es = vector table segment for a while */
94 push %es
95 data32
96 subl %eax, %eax
97 mov %ax, %es
98
99 /* fix up GDT entries for bdb */
100 data32
101 movl $4*DEBUG_VECTOR, %esi
102 addr32
103 movl %es: 2(%esi), %eax /* actually movw to %ax */
104 data32
105 shll $4, %eax
106 data32
107 shld $16, %eax, %ebx
108 FIXUP(DB_CS_INDEX)
109 FIXUP(DB_CS16_INDEX)
110 FIXUP(DB_DS_INDEX)
111
112 /* Fetch entry points of bdb's protected mode trap handlers. These
113 * are stored at 2 before the corresponding entry points for real mode.
114 */
115 data32
116 subl %ebx, %ebx
117 addr32
118 movl %es: (%esi), %ebx /* actually movw to %bx */
119 data32
120 subl %ecx, %ecx
121 addr32
122 movl %es: 4*(BREAKPOINT_VECTOR-DEBUG_VECTOR)(%esi), %ecx
123 /* actually movw to %cx */
124
125 /* %es = bdb segment for a while */
126 data32
127 shrl $4, %eax
128 mov %ax, %es
129
130 /* fix up IDT entries for bdb */
fe139ecb
RG
131 subl $2, %ebx
132 movl %es: (%ebx), %eax /* actually movw to %ax */
a27f4645
RM
133 addr32
134 movl %eax, EXT(Idt)+8*DEBUG_VECTOR /* actually movw %ax */
fe139ecb
RG
135 subl $2, %ecx
136 movl %es: (%ecx), %eax /* actually movw to %ax */
a27f4645
RM
137 addr32
138 movl %eax, EXT(Idt)+8*BREAKPOINT_VECTOR /* actually movw %ax */
139
140 /* finished with groping in real mode segments */
141 pop %es
142
143 /* change to protected mode */
144 data32
145 call EXT(real_to_prot)
146
147 /* clear the bss */
148 movl $ EXT(edata), %edi /* no EXT(_edata) - krufty ld */
149 movl $ EXT(end), %ecx /* or EXT(_end) */
150 subl %edi, %ecx
151 subb %al, %al
152 rep
153 stosb
154
155 movzbl %dl, %edx /* discard head (%dh) and random high bits */
156 pushl %edx
157 call EXT(boot)
158oops:
159 hlt
160 jmp oops
161
162 .data
163 .align 2
164#if 0 /* XXX this would give losing "_ouraddr :". Better declared in C */
165EXT(ouraddr):
166#else
167_ouraddr:
168#endif
169 .long 0