]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/mp_slave_boot.s
xnu-792.12.6.tar.gz
[apple/xnu.git] / osfmk / i386 / mp_slave_boot.s
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
5 *
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
14 * agreement.
15 *
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
18 * file.
19 *
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
27 *
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
29 */
30 /*
31 * @OSF_COPYRIGHT@
32 */
33
34 /*
35 * Mach Operating System
36 * Copyright (c) 1991,1990 Carnegie Mellon University
37 * All Rights Reserved.
38 *
39 * Permission to use, copy, modify and distribute this software and its
40 * documentation is hereby granted, provided that both the copyright
41 * notice and this permission notice appear in all copies of the
42 * software, derivative works or modified versions, and any portions
43 * thereof, and that both notices appear in supporting documentation.
44 *
45 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
46 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
47 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
48 *
49 * Carnegie Mellon requests users of this software to return to
50 *
51 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
52 * School of Computer Science
53 * Carnegie Mellon University
54 * Pittsburgh PA 15213-3890
55 *
56 * any improvements or extensions that they make and grant Carnegie Mellon
57 * the rights to redistribute these changes.
58 */
59
60 #include <i386/asm.h>
61 #include <i386/mp_slave_boot.h>
62 #include <i386/postcode.h>
63
64 #define CR0_PE_ON 0x1
65 #define CR0_PE_OFF 0xfffffffe
66
67 .file "slave_boot.s"
68
69 .text
70 .align 12 // Page align for single bcopy_phys()
71
72 #define LJMP(segment,address) \
73 .byte 0xea ;\
74 .long address-EXT(slave_boot_base) ;\
75 .word segment
76
77 #define LGDT(address) \
78 .word 0x010f ;\
79 .byte 0x15 ;\
80 .long address-EXT(slave_boot_base)
81
82 Entry(slave_boot_base)
83 /* code is loaded at 0x0:0x1000 */
84 /* ljmp to the next instruction to set up %cs */
85 data16
86 LJMP(MP_BOOTSEG, EXT(slave_pstart))
87
88 Entry(slave_pstart)
89 /* set up %ds */
90 mov %cs, %ax
91 mov %ax, %ds
92
93 POSTCODE(SLAVE_PSTART_ENTRY);
94
95 /* set up %ss and %esp */
96 data16
97 mov $(MP_BOOTSEG), %eax
98 mov %ax, %ss
99 data16
100 mov $(MP_BOOTSTACK), %esp
101
102 /*set up %es */
103 mov %ax, %es
104
105 /* change to protected mode */
106 data16
107 call EXT(real_to_prot)
108
109 push MP_MACH_START
110 call EXT(startprog)
111
112 /*
113 real_to_prot()
114 transfer from real mode to protected mode.
115 */
116
117 Entry(real_to_prot)
118 /* guarantee that interrupt is disabled when in prot mode */
119 cli
120
121 POSTCODE(REAL_TO_PROT_ENTRY);
122
123 /* load the gdtr */
124 addr16
125 data16
126 LGDT(EXT(gdtr))
127
128 /* load the gdtr */
129 /* set the PE bit of CR0 */
130 mov %cr0, %eax
131
132 data16
133 or $(CR0_PE_ON), %eax
134 mov %eax, %cr0
135
136 /* make intrasegment jump to flush the processor pipeline and */
137 /* reload CS register */
138 data16
139 LJMP(0x08, xprot)
140
141 xprot:
142
143 /* we are in USE32 mode now */
144 /* set up the protective mode segment registers : DS, SS, ES */
145 mov $0x10, %eax
146 movw %ax, %ds
147 movw %ax, %ss
148 movw %ax, %es
149
150 POSTCODE(REAL_TO_PROT_EXIT);
151
152 ret
153
154 /*
155 startprog(phyaddr)
156 start the program on protected mode where phyaddr is the entry point
157 */
158
159 Entry(startprog)
160 push %ebp
161 movl %esp, %ebp
162
163 POSTCODE(STARTPROG_ENTRY);
164
165 movl 0x8(%ebp), %ecx /* entry offset */
166 movl $0x28, %ebx /* segment */
167 push %ebx
168 push %ecx
169
170 /* set up %ds and %es */
171 movl $0x20, %ebx
172 movw %bx, %ds
173 movw %bx, %es
174
175 POSTCODE(STARTPROG_EXIT);
176
177 lret
178
179
180 . = MP_BOOTGDT-MP_BOOT /* GDT location */
181 Entry(Gdt)
182
183 /* Segment Descriptor
184 *
185 * 31 24 19 16 7 0
186 * ------------------------------------------------------------
187 * | | |B| |A| | | |1|0|E|W|A| |
188 * | BASE 31..24 |G|/|0|V| LIMIT |P|DPL| TYPE | BASE 23:16 |
189 * | | |D| |L| 19..16| | |1|1|C|R|A| |
190 * ------------------------------------------------------------
191 * | | |
192 * | BASE 15..0 | LIMIT 15..0 |
193 * | | |
194 * ------------------------------------------------------------
195 */
196 .word 0,0 /* 0x0 : null */
197 .byte 0,0,0,0
198
199 .word 0xffff,MP_BOOT /* 0x8 : boot code */
200 .byte 0,0x9e,0xcf,0
201
202 .word 0xffff,MP_BOOT /* 0x10 : boot data */
203 .byte 0,0x92,0xcf,0
204
205 .word 0xffff,MP_BOOT /* 0x18 : boot code, 16 bits */
206 .byte 0,0x9e,0x0,0
207
208 .word 0xffff,0 /* 0x20 : init data */
209 .byte 0,0x93,0xcf,0
210
211 .word 0xffff,0 /* 0x28 : init code */
212 .byte 0,0x9f,0xcf,0
213
214 Entry(gdtr)
215 .short 48 /* limit (8*6 segs) */
216 .short MP_BOOTGDT /* base low */
217 .short 0 /* base high */
218
219 Entry(slave_boot_end)
220
221
222
223
224
225
226
227
228
229
230
231
232
233