2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
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.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
32 #include <mach/vm_types.h>
33 #include <mach/vm_param.h>
34 #include <mach/thread_status.h>
35 #include <kern/misc_protos.h>
36 #include <kern/assert.h>
37 #include <kern/cpu_number.h>
39 #include <ppc/proc_reg.h>
41 #include <ppc/misc_protos.h>
43 #include <ppc/pmap_internals.h>
45 #include <ppc/exception.h>
46 #include <ppc/gdb_defs.h>
47 #include <ppc/POWERMAC/video_board.h>
48 #include <ppc/POWERMAC/video_pdm.h>
51 #include <mach-o/mach_header.h>
54 /* External references */
56 extern unsigned int intstack
[]; /* declared in start.s */
57 extern unsigned int intstack_top_ss
; /* declared in start.s */
59 extern unsigned int gdbstackptr
; /* declared in start.s */
60 extern unsigned int gdbstack_top_ss
; /* declared in start.s */
61 #endif /* MACH_KGDB */
63 /* Stuff declared in kern/bootstrap.c which we may need to initialise */
65 extern vm_offset_t boot_start
;
66 extern vm_size_t boot_size
;
67 extern vm_offset_t boot_region_desc
;
68 extern vm_size_t boot_region_count
;
69 extern int boot_thread_state_flavor
;
70 extern thread_state_t boot_thread_state
;
71 extern unsigned int boot_thread_state_count
;
73 /* Trap handling function prototypes */
75 extern void thandler(void); /* trap handler */
76 extern void ihandler(void); /* interrupt handler */
77 extern void shandler(void); /* syscall handler */
78 extern void gdbhandler(void); /* debugger handler */
79 extern void fpu_switch(void); /* fp handler */
80 extern void atomic_switch_trap(void); /* fast path atomic thread switch */
84 struct ppc_thread_state boot_task_thread_state
;
90 #if 1 /* TODO NMGS - vm_map_steal_memory shouldn't use these - remove */
91 vm_offset_t avail_start
;
92 vm_offset_t avail_end
;
94 unsigned int avail_remaining
= 0;
95 vm_offset_t first_avail
;
103 extern struct mach_header _mh_execute_header
;
113 vm_offset_t end
, etext
, edata
;
119 void ppc_vm_init(unsigned int memory_size
, boot_args
*args
)
121 unsigned int htabmask
;
124 int boot_task_end_offset
;
127 #endif /* NCPUS > 1 */
129 printf("mem_size = %d M\n",memory_size
/ (1024 * 1024));
132 /* Now retrieve addresses for end, edata, and etext
133 * from MACH-O headers.
137 etext
= (vm_offset_t
) sectTEXTB
+ sectSizeTEXT
;
138 edata
= (vm_offset_t
) sectDATAB
+ sectSizeDATA
;
142 /* Stitch valid memory regions together - they may be contiguous
143 * even though they're not already glued together
146 /* Go through the list of memory regions passed in via the args
147 * and copy valid entries into the pmap_mem_regions table, adding
148 * further calculated entries.
152 /* Initialise the pmap system, using space above `first_avail'*/
155 free_regions
[free_regions_count
].start
=
156 round_page((unsigned int)&_ExceptionVectorsEnd
-
157 (unsigned int)&_ExceptionVectorsStart
);
159 /* On MACH-O generated kernels, the Exception Vectors
160 * are already mapped and loaded at 0 -- no relocation
161 * or freeing of memory is needed
164 free_regions
[free_regions_count
].start
= round_page((unsigned int)&_ExceptionVectorsEnd
) + 4096;
167 /* If we are on a PDM machine memory at 1M might be used
168 * for video. TODO NMGS call video driver to do this
173 /* For PowerMac, first_avail is set to above the bootstrap task.
174 * TODO NMGS - different screen modes - might free mem?
177 first_avail
= round_page(args
->first_avail
);
180 /* map in the exception vectors */
182 * map the kernel text, data and bss. Don't forget other regions too
184 for (i
= 0; i
< args
->kern_info
.region_count
; i
++) {
186 if (args
->kern_info
.regions
[i
].prot
== VM_PROT_NONE
&&
187 i
== args
->kern_info
.region_count
- 1) {
188 /* assume that's the kernel symbol table */
189 kern_sym_start
= args
->kern_info
.regions
[i
].addr
;
190 kern_sym_size
= args
->kern_info
.regions
[i
].size
;
191 printf("kernel symbol table at 0x%x size 0x%x\n",
192 kern_sym_start
, kern_sym_size
);
193 args
->kern_info
.regions
[i
].prot
|=
194 (VM_PROT_WRITE
|VM_PROT_READ
);
196 #endif /* MACH_KDB */
199 /* Skip the VECTORS segment */
200 if (args
->kern_info
.regions
[i
].addr
== 0)
204 boot_region_count
= args
->task_info
.region_count
;
206 boot_task_end_offset
= 0;
207 /* Map bootstrap task pages 1-1 so that user_bootstrap can find it */
208 for (i
= 0; i
< boot_region_count
; i
++) {
209 if (args
->task_info
.regions
[i
].mapped
) {
210 /* kernel requires everything page aligned */
212 printf("mapping virt 0x%08x to phys 0x%08x end 0x%x, prot=0x%b\n",
213 ppc_trunc_page(args
->task_info
.base_addr
+
214 args
->task_info
.regions
[i
].offset
),
215 ppc_trunc_page(args
->task_info
.base_addr
+
216 args
->task_info
.regions
[i
].offset
),
217 ppc_round_page(args
->task_info
.base_addr
+
218 args
->task_info
.regions
[i
].offset
+
219 args
->task_info
.regions
[i
].size
),
220 args
->task_info
.regions
[i
].prot
,
221 "\x10\1READ\2WRITE\3EXEC");
225 ppc_trunc_page(args
->task_info
.base_addr
+
226 args
->task_info
.regions
[i
].offset
),
227 ppc_trunc_page(args
->task_info
.base_addr
+
228 args
->task_info
.regions
[i
].offset
),
229 ppc_round_page(args
->task_info
.base_addr
+
230 args
->task_info
.regions
[i
].offset
+
231 args
->task_info
.regions
[i
].size
),
232 args
->task_info
.regions
[i
].prot
);
234 /* Count the size of mapped space */
235 boot_size
+= args
->task_info
.regions
[i
].size
;
237 /* There may be an overlapping physical page
238 * mapped to two different virtual addresses
240 if (boot_task_end_offset
>
241 args
->task_info
.regions
[i
].offset
) {
242 boot_size
-= boot_task_end_offset
-
243 args
->task_info
.regions
[i
].offset
;
245 printf("WARNING - bootstrap overlaps regions\n");
249 boot_task_end_offset
=
250 args
->task_info
.regions
[i
].offset
+
251 args
->task_info
.regions
[i
].size
;
255 if (boot_region_count
) {
257 /* Add a new region to the bootstrap task for it's stack */
258 args
->task_info
.regions
[boot_region_count
].addr
=
260 args
->task_info
.regions
[boot_region_count
].size
=
262 args
->task_info
.regions
[boot_region_count
].mapped
= FALSE
;
265 boot_start
= args
->task_info
.base_addr
;
266 boot_region_desc
= (vm_offset_t
) args
->task_info
.regions
;
267 /* TODO NMGS need to put param info onto top of boot stack */
268 boot_task_thread_state
.r1
= BOOT_STACK_PTR
-0x100;
269 boot_task_thread_state
.srr0
= args
->task_info
.entry
;
270 boot_task_thread_state
.srr1
=
271 MSR_MARK_SYSCALL(MSR_EXPORT_MASK_SET
);
273 boot_thread_state_flavor
= PPC_THREAD_STATE
;
274 boot_thread_state_count
= PPC_THREAD_STATE_COUNT
;
276 (thread_state_t
)&boot_task_thread_state
;