2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_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 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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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>
37 #include <ppc/proc_reg.h>
39 #include <ppc/misc_protos.h>
41 #include <ppc/pmap_internals.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>
49 #include <mach-o/mach_header.h>
52 /* External references */
54 extern unsigned int intstack
[]; /* declared in start.s */
55 extern unsigned int intstack_top_ss
; /* declared in start.s */
57 extern unsigned int gdbstackptr
; /* declared in start.s */
58 extern unsigned int gdbstack_top_ss
; /* declared in start.s */
59 #endif /* MACH_KGDB */
61 /* Stuff declared in kern/bootstrap.c which we may need to initialise */
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
;
71 /* Trap handling function prototypes */
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 */
82 struct ppc_thread_state boot_task_thread_state
;
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
;
92 unsigned int avail_remaining
= 0;
93 vm_offset_t first_avail
;
101 extern struct mach_header _mh_execute_header
;
111 vm_offset_t end
, etext
, edata
;
117 void ppc_vm_init(unsigned int memory_size
, boot_args
*args
)
119 unsigned int htabmask
;
122 int boot_task_end_offset
;
125 #endif /* NCPUS > 1 */
127 printf("mem_size = %d M\n",memory_size
/ (1024 * 1024));
130 /* Now retrieve addresses for end, edata, and etext
131 * from MACH-O headers.
135 etext
= (vm_offset_t
) sectTEXTB
+ sectSizeTEXT
;
136 edata
= (vm_offset_t
) sectDATAB
+ sectSizeDATA
;
140 /* Stitch valid memory regions together - they may be contiguous
141 * even though they're not already glued together
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.
150 /* Initialise the pmap system, using space above `first_avail'*/
153 free_regions
[free_regions_count
].start
=
154 round_page((unsigned int)&_ExceptionVectorsEnd
-
155 (unsigned int)&_ExceptionVectorsStart
);
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
162 free_regions
[free_regions_count
].start
= round_page((unsigned int)&_ExceptionVectorsEnd
) + 4096;
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
171 /* For PowerMac, first_avail is set to above the bootstrap task.
172 * TODO NMGS - different screen modes - might free mem?
175 first_avail
= round_page(args
->first_avail
);
178 /* map in the exception vectors */
180 * map the kernel text, data and bss. Don't forget other regions too
182 for (i
= 0; i
< args
->kern_info
.region_count
; i
++) {
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
);
194 #endif /* MACH_KDB */
197 /* Skip the VECTORS segment */
198 if (args
->kern_info
.regions
[i
].addr
== 0)
202 boot_region_count
= args
->task_info
.region_count
;
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 */
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");
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
);
232 /* Count the size of mapped space */
233 boot_size
+= args
->task_info
.regions
[i
].size
;
235 /* There may be an overlapping physical page
236 * mapped to two different virtual addresses
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
;
243 printf("WARNING - bootstrap overlaps regions\n");
247 boot_task_end_offset
=
248 args
->task_info
.regions
[i
].offset
+
249 args
->task_info
.regions
[i
].size
;
253 if (boot_region_count
) {
255 /* Add a new region to the bootstrap task for it's stack */
256 args
->task_info
.regions
[boot_region_count
].addr
=
258 args
->task_info
.regions
[boot_region_count
].size
=
260 args
->task_info
.regions
[boot_region_count
].mapped
= FALSE
;
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
);
271 boot_thread_state_flavor
= PPC_THREAD_STATE
;
272 boot_thread_state_count
= PPC_THREAD_STATE_COUNT
;
274 (thread_state_t
)&boot_task_thread_state
;