]> git.saurik.com Git - apple/xnu.git/blame - bsd/dev/ppc/ppc_init.c
xnu-1228.tar.gz
[apple/xnu.git] / bsd / dev / ppc / ppc_init.c
CommitLineData
1c79356b 1/*
5d5c5d0d
A
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
2d21ac55 4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
1c79356b 5 *
2d21ac55
A
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.
8f6c56a5 14 *
2d21ac55
A
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
8f6c56a5
A
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
2d21ac55
A
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.
8f6c56a5 25 *
2d21ac55 26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
1c79356b
A
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 <mach-o/mach_header.h>
50#endif
51
52/* External references */
53
54extern unsigned int intstack[]; /* declared in start.s */
55extern unsigned int intstack_top_ss; /* declared in start.s */
56#if MACH_KGDB
57extern unsigned int gdbstackptr; /* declared in start.s */
58extern 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
63extern vm_offset_t boot_start;
64extern vm_size_t boot_size;
65extern vm_offset_t boot_region_desc;
66extern vm_size_t boot_region_count;
67extern int boot_thread_state_flavor;
68extern thread_state_t boot_thread_state;
69extern unsigned int boot_thread_state_count;
70
71/* Trap handling function prototypes */
72
73extern void thandler(void); /* trap handler */
74extern void ihandler(void); /* interrupt handler */
75extern void shandler(void); /* syscall handler */
76extern void gdbhandler(void); /* debugger handler */
77extern void fpu_switch(void); /* fp handler */
78extern void atomic_switch_trap(void); /* fast path atomic thread switch */
79
80/* definitions */
81
82struct 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 */
89vm_offset_t avail_start;
90vm_offset_t avail_end;
91#endif
92unsigned int avail_remaining = 0;
93vm_offset_t first_avail;
94
95/*
96 * Mach-O Support
97 */
98
99
100#ifdef __MACHO__
101extern struct mach_header _mh_execute_header;
102void *sectTEXTB;
103int sectSizeTEXT;
104void *sectDATAB;
105int sectSizeDATA;
106void *sectOBJCB;
107int sectSizeOBJC;
108void *sectLINKB;
109int sectSizeLINK;
110
111vm_offset_t end, etext, edata;
112#define ETEXT etext
113#endif
114
115
116
117void ppc_vm_init(unsigned int memory_size, boot_args *args)
118{
119 unsigned int htabmask;
120 unsigned int i;
121 vm_offset_t addr;
122 int boot_task_end_offset;
123#if NCPUS > 1
124 const char *cpus;
125#endif /* NCPUS > 1 */
126
127 printf("mem_size = %d M\n",memory_size / (1024 * 1024));
128
129#ifdef __MACHO__
130 /* Now retrieve addresses for end, edata, and etext
131 * from MACH-O headers.
132 */
133
134
135 etext = (vm_offset_t) sectTEXTB + sectSizeTEXT;
136 edata = (vm_offset_t) sectDATAB + sectSizeDATA;
137 end = getlastaddr();
138#endif
139
140 /* Stitch valid memory regions together - they may be contiguous
141 * even though they're not already glued together
142 */
143
144 /* Go through the list of memory regions passed in via the args
145 * and copy valid entries into the pmap_mem_regions table, adding
146 * further calculated entries.
147 */
148
149
150 /* Initialise the pmap system, using space above `first_avail'*/
151
152#ifndef __MACHO__
153 free_regions[free_regions_count].start =
154 round_page((unsigned int)&_ExceptionVectorsEnd -
155 (unsigned int)&_ExceptionVectorsStart);
156#else
157 /* On MACH-O generated kernels, the Exception Vectors
158 * are already mapped and loaded at 0 -- no relocation
159 * or freeing of memory is needed
160 */
161
162 free_regions[free_regions_count].start = round_page((unsigned int)&_ExceptionVectorsEnd) + 4096;
163#endif
164
165 /* If we are on a PDM machine memory at 1M might be used
166 * for video. TODO NMGS call video driver to do this
167 * somehow
168 */
169
170
171 /* For PowerMac, first_avail is set to above the bootstrap task.
172 * TODO NMGS - different screen modes - might free mem?
173 */
174
175 first_avail = round_page(args->first_avail);
176
177
178 /* map in the exception vectors */
179 /*
180 * map the kernel text, data and bss. Don't forget other regions too
181 */
182 for (i = 0; i < args->kern_info.region_count; i++) {
183#if MACH_KDB
184 if (args->kern_info.regions[i].prot == VM_PROT_NONE &&
185 i == args->kern_info.region_count - 1) {
186 /* assume that's the kernel symbol table */
187 kern_sym_start = args->kern_info.regions[i].addr;
188 kern_sym_size = args->kern_info.regions[i].size;
189 printf("kernel symbol table at 0x%x size 0x%x\n",
190 kern_sym_start, kern_sym_size);
191 args->kern_info.regions[i].prot |=
192 (VM_PROT_WRITE|VM_PROT_READ);
193 }
194#endif /* MACH_KDB */
195
196#ifdef __MACHO__
197 /* Skip the VECTORS segment */
198 if (args->kern_info.regions[i].addr == 0)
199 continue;
200#endif
201
202 boot_region_count = args->task_info.region_count;
203 boot_size = 0;
204 boot_task_end_offset = 0;
205 /* Map bootstrap task pages 1-1 so that user_bootstrap can find it */
206 for (i = 0; i < boot_region_count; i++) {
207 if (args->task_info.regions[i].mapped) {
208 /* kernel requires everything page aligned */
209#if DEBUG
210 printf("mapping virt 0x%08x to phys 0x%08x end 0x%x, prot=0x%b\n",
211 ppc_trunc_page(args->task_info.base_addr +
212 args->task_info.regions[i].offset),
213 ppc_trunc_page(args->task_info.base_addr +
214 args->task_info.regions[i].offset),
215 ppc_round_page(args->task_info.base_addr +
216 args->task_info.regions[i].offset +
217 args->task_info.regions[i].size),
218 args->task_info.regions[i].prot,
219 "\x10\1READ\2WRITE\3EXEC");
220#endif /* DEBUG */
221
222 (void)pmap_map(
223 ppc_trunc_page(args->task_info.base_addr +
224 args->task_info.regions[i].offset),
225 ppc_trunc_page(args->task_info.base_addr +
226 args->task_info.regions[i].offset),
227 ppc_round_page(args->task_info.base_addr +
228 args->task_info.regions[i].offset +
229 args->task_info.regions[i].size),
230 args->task_info.regions[i].prot);
231
232 /* Count the size of mapped space */
233 boot_size += args->task_info.regions[i].size;
234
235 /* There may be an overlapping physical page
236 * mapped to two different virtual addresses
237 */
238 if (boot_task_end_offset >
239 args->task_info.regions[i].offset) {
240 boot_size -= boot_task_end_offset -
241 args->task_info.regions[i].offset;
242#if DEBUG
243 printf("WARNING - bootstrap overlaps regions\n");
244#endif /* DEBUG */
245 }
246
247 boot_task_end_offset =
248 args->task_info.regions[i].offset +
249 args->task_info.regions[i].size;
250 }
251 }
252
253 if (boot_region_count) {
254
255 /* Add a new region to the bootstrap task for it's stack */
256 args->task_info.regions[boot_region_count].addr =
257 BOOT_STACK_BASE;
258 args->task_info.regions[boot_region_count].size =
259 BOOT_STACK_SIZE;
260 args->task_info.regions[boot_region_count].mapped = FALSE;
261 boot_region_count++;
262
263 boot_start = args->task_info.base_addr;
264 boot_region_desc = (vm_offset_t) args->task_info.regions;
265 /* TODO NMGS need to put param info onto top of boot stack */
266 boot_task_thread_state.r1 = BOOT_STACK_PTR-0x100;
267 boot_task_thread_state.srr0 = args->task_info.entry;
268 boot_task_thread_state.srr1 =
269 MSR_MARK_SYSCALL(MSR_EXPORT_MASK_SET);
270
271 boot_thread_state_flavor = PPC_THREAD_STATE;
272 boot_thread_state_count = PPC_THREAD_STATE_COUNT;
273 boot_thread_state =
274 (thread_state_t)&boot_task_thread_state;
275 }
276
277
278
279}
280