]> git.saurik.com Git - apple/xnu.git/blob - bsd/dev/ppc/ppc_init.c
xnu-1504.9.26.tar.gz
[apple/xnu.git] / bsd / dev / ppc / ppc_init.c
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_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 License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
14 *
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
17 *
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
27 */
28
29
30 #include <mach/vm_types.h>
31 #include <mach/vm_param.h>
32 #include <mach/thread_status.h>
33 #include <kern/misc_protos.h>
34 #include <kern/assert.h>
35 #include <kern/cpu_number.h>
36
37 #include <ppc/proc_reg.h>
38 #include <ppc/boot.h>
39 #include <ppc/misc_protos.h>
40 #include <ppc/pmap.h>
41 #include <ppc/pmap_internals.h>
42 #include <ppc/mem.h>
43 #include <ppc/exception.h>
44 #include <ppc/gdb_defs.h>
45 #include <ppc/POWERMAC/video_board.h>
46 #include <ppc/POWERMAC/video_pdm.h>
47
48 #ifdef __MACHO__
49 #include <libkern/kernel_mach_header.h>
50 #endif
51
52 /* External references */
53
54 extern unsigned int intstack[]; /* declared in start.s */
55 extern unsigned int intstack_top_ss; /* declared in start.s */
56 #if MACH_KGDB
57 extern unsigned int gdbstackptr; /* declared in start.s */
58 extern unsigned int gdbstack_top_ss; /* declared in start.s */
59 #endif /* MACH_KGDB */
60
61 /* Stuff declared in kern/bootstrap.c which we may need to initialise */
62
63 extern vm_offset_t boot_start;
64 extern vm_size_t boot_size;
65 extern vm_offset_t boot_region_desc;
66 extern vm_size_t boot_region_count;
67 extern int boot_thread_state_flavor;
68 extern thread_state_t boot_thread_state;
69 extern unsigned int boot_thread_state_count;
70
71 /* Trap handling function prototypes */
72
73 extern void thandler(void); /* trap handler */
74 extern void ihandler(void); /* interrupt handler */
75 extern void shandler(void); /* syscall handler */
76 extern void gdbhandler(void); /* debugger handler */
77 extern void fpu_switch(void); /* fp handler */
78 extern void atomic_switch_trap(void); /* fast path atomic thread switch */
79
80 /* definitions */
81
82 struct ppc_thread_state boot_task_thread_state;
83
84
85
86
87
88 #if 1 /* TODO NMGS - vm_map_steal_memory shouldn't use these - remove */
89 vm_offset_t avail_start;
90 vm_offset_t avail_end;
91 #endif
92 unsigned int avail_remaining = 0;
93 vm_offset_t first_avail;
94
95 /*
96 * Mach-O Support
97 */
98
99
100 #ifdef __MACHO__
101 void *sectTEXTB;
102 unsigned long sectSizeTEXT;
103 void *sectDATAB;
104 unsigned long sectSizeDATA;
105 void *sectOBJCB;
106 unsigned long sectSizeOBJC;
107 void *sectLINKB;
108 unsigned long sectSizeLINK;
109
110 vm_offset_t end, etext, edata;
111 #define ETEXT etext
112 #endif
113
114
115
116 void ppc_vm_init(unsigned int memory_size, boot_args *args)
117 {
118 unsigned int htabmask;
119 unsigned int i;
120 vm_offset_t addr;
121 int boot_task_end_offset;
122
123 printf("mem_size = %d M\n",memory_size / (1024 * 1024));
124
125 #ifdef __MACHO__
126 /* Now retrieve addresses for end, edata, and etext
127 * from MACH-O headers.
128 */
129
130
131 etext = (vm_offset_t) sectTEXTB + sectSizeTEXT;
132 edata = (vm_offset_t) sectDATAB + sectSizeDATA;
133 end = getlastaddr();
134 #endif
135
136 /* Stitch valid memory regions together - they may be contiguous
137 * even though they're not already glued together
138 */
139
140 /* Go through the list of memory regions passed in via the args
141 * and copy valid entries into the pmap_mem_regions table, adding
142 * further calculated entries.
143 */
144
145
146 /* Initialise the pmap system, using space above `first_avail'*/
147
148 #ifndef __MACHO__
149 free_regions[free_regions_count].start =
150 round_page((unsigned int)&_ExceptionVectorsEnd -
151 (unsigned int)&_ExceptionVectorsStart);
152 #else
153 /* On MACH-O generated kernels, the Exception Vectors
154 * are already mapped and loaded at 0 -- no relocation
155 * or freeing of memory is needed
156 */
157
158 free_regions[free_regions_count].start = round_page((unsigned int)&_ExceptionVectorsEnd) + 4096;
159 #endif
160
161 /* If we are on a PDM machine memory at 1M might be used
162 * for video. TODO NMGS call video driver to do this
163 * somehow
164 */
165
166
167 /* For PowerMac, first_avail is set to above the bootstrap task.
168 * TODO NMGS - different screen modes - might free mem?
169 */
170
171 first_avail = round_page(args->first_avail);
172
173
174 /* map in the exception vectors */
175 /*
176 * map the kernel text, data and bss. Don't forget other regions too
177 */
178 for (i = 0; i < args->kern_info.region_count; i++) {
179 #if MACH_KDB
180 if (args->kern_info.regions[i].prot == VM_PROT_NONE &&
181 i == args->kern_info.region_count - 1) {
182 /* assume that's the kernel symbol table */
183 kern_sym_start = args->kern_info.regions[i].addr;
184 kern_sym_size = args->kern_info.regions[i].size;
185 printf("kernel symbol table at 0x%x size 0x%x\n",
186 kern_sym_start, kern_sym_size);
187 args->kern_info.regions[i].prot |=
188 (VM_PROT_WRITE|VM_PROT_READ);
189 }
190 #endif /* MACH_KDB */
191
192 #ifdef __MACHO__
193 /* Skip the VECTORS segment */
194 if (args->kern_info.regions[i].addr == 0)
195 continue;
196 #endif
197
198 boot_region_count = args->task_info.region_count;
199 boot_size = 0;
200 boot_task_end_offset = 0;
201 /* Map bootstrap task pages 1-1 so that user_bootstrap can find it */
202 for (i = 0; i < boot_region_count; i++) {
203 if (args->task_info.regions[i].mapped) {
204 /* kernel requires everything page aligned */
205 #if DEBUG
206 printf("mapping virt 0x%08x to phys 0x%08x end 0x%x, prot=0x%b\n",
207 ppc_trunc_page(args->task_info.base_addr +
208 args->task_info.regions[i].offset),
209 ppc_trunc_page(args->task_info.base_addr +
210 args->task_info.regions[i].offset),
211 ppc_round_page(args->task_info.base_addr +
212 args->task_info.regions[i].offset +
213 args->task_info.regions[i].size),
214 args->task_info.regions[i].prot,
215 "\x10\1READ\2WRITE\3EXEC");
216 #endif /* DEBUG */
217
218 (void)pmap_map(
219 ppc_trunc_page(args->task_info.base_addr +
220 args->task_info.regions[i].offset),
221 ppc_trunc_page(args->task_info.base_addr +
222 args->task_info.regions[i].offset),
223 ppc_round_page(args->task_info.base_addr +
224 args->task_info.regions[i].offset +
225 args->task_info.regions[i].size),
226 args->task_info.regions[i].prot);
227
228 /* Count the size of mapped space */
229 boot_size += args->task_info.regions[i].size;
230
231 /* There may be an overlapping physical page
232 * mapped to two different virtual addresses
233 */
234 if (boot_task_end_offset >
235 args->task_info.regions[i].offset) {
236 boot_size -= boot_task_end_offset -
237 args->task_info.regions[i].offset;
238 #if DEBUG
239 printf("WARNING - bootstrap overlaps regions\n");
240 #endif /* DEBUG */
241 }
242
243 boot_task_end_offset =
244 args->task_info.regions[i].offset +
245 args->task_info.regions[i].size;
246 }
247 }
248
249 if (boot_region_count) {
250
251 /* Add a new region to the bootstrap task for it's stack */
252 args->task_info.regions[boot_region_count].addr =
253 BOOT_STACK_BASE;
254 args->task_info.regions[boot_region_count].size =
255 BOOT_STACK_SIZE;
256 args->task_info.regions[boot_region_count].mapped = FALSE;
257 boot_region_count++;
258
259 boot_start = args->task_info.base_addr;
260 boot_region_desc = (vm_offset_t) args->task_info.regions;
261 /* TODO NMGS need to put param info onto top of boot stack */
262 boot_task_thread_state.r1 = BOOT_STACK_PTR-0x100;
263 boot_task_thread_state.srr0 = args->task_info.entry;
264 boot_task_thread_state.srr1 =
265 MSR_MARK_SYSCALL(MSR_EXPORT_MASK_SET);
266
267 boot_thread_state_flavor = PPC_THREAD_STATE;
268 boot_thread_state_count = PPC_THREAD_STATE_COUNT;
269 boot_thread_state =
270 (thread_state_t)&boot_task_thread_state;
271 }
272
273
274
275 }
276