2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
27 #include <mach/vm_types.h>
28 #include <mach/vm_param.h>
29 #include <mach/thread_status.h>
30 #include <kern/misc_protos.h>
31 #include <kern/assert.h>
32 #include <kern/cpu_number.h>
34 #include <ppc/proc_reg.h>
36 #include <ppc/misc_protos.h>
38 #include <ppc/pmap_internals.h>
40 #include <ppc/exception.h>
41 #include <ppc/gdb_defs.h>
42 #include <ppc/POWERMAC/video_board.h>
43 #include <ppc/POWERMAC/video_pdm.h>
46 #include <mach-o/mach_header.h>
49 /* External references */
51 extern unsigned int intstack
[]; /* declared in start.s */
52 extern unsigned int intstack_top_ss
; /* declared in start.s */
54 extern unsigned int gdbstackptr
; /* declared in start.s */
55 extern unsigned int gdbstack_top_ss
; /* declared in start.s */
56 #endif /* MACH_KGDB */
58 /* Stuff declared in kern/bootstrap.c which we may need to initialise */
60 extern vm_offset_t boot_start
;
61 extern vm_size_t boot_size
;
62 extern vm_offset_t boot_region_desc
;
63 extern vm_size_t boot_region_count
;
64 extern int boot_thread_state_flavor
;
65 extern thread_state_t boot_thread_state
;
66 extern unsigned int boot_thread_state_count
;
68 /* Trap handling function prototypes */
70 extern void thandler(void); /* trap handler */
71 extern void ihandler(void); /* interrupt handler */
72 extern void shandler(void); /* syscall handler */
73 extern void gdbhandler(void); /* debugger handler */
74 extern void fpu_switch(void); /* fp handler */
75 extern void atomic_switch_trap(void); /* fast path atomic thread switch */
79 struct ppc_thread_state boot_task_thread_state
;
85 #if 1 /* TODO NMGS - vm_map_steal_memory shouldn't use these - remove */
86 vm_offset_t avail_start
;
87 vm_offset_t avail_end
;
89 unsigned int avail_remaining
= 0;
90 vm_offset_t first_avail
;
98 extern struct mach_header _mh_execute_header
;
108 vm_offset_t end
, etext
, edata
;
114 void ppc_vm_init(unsigned int memory_size
, boot_args
*args
)
116 unsigned int htabmask
;
119 int boot_task_end_offset
;
122 #endif /* NCPUS > 1 */
124 printf("mem_size = %d M\n",memory_size
/ (1024 * 1024));
127 /* Now retrieve addresses for end, edata, and etext
128 * from MACH-O headers.
132 etext
= (vm_offset_t
) sectTEXTB
+ sectSizeTEXT
;
133 edata
= (vm_offset_t
) sectDATAB
+ sectSizeDATA
;
137 /* Stitch valid memory regions together - they may be contiguous
138 * even though they're not already glued together
141 /* Go through the list of memory regions passed in via the args
142 * and copy valid entries into the pmap_mem_regions table, adding
143 * further calculated entries.
147 /* Initialise the pmap system, using space above `first_avail'*/
150 free_regions
[free_regions_count
].start
=
151 round_page((unsigned int)&_ExceptionVectorsEnd
-
152 (unsigned int)&_ExceptionVectorsStart
);
154 /* On MACH-O generated kernels, the Exception Vectors
155 * are already mapped and loaded at 0 -- no relocation
156 * or freeing of memory is needed
159 free_regions
[free_regions_count
].start
= round_page((unsigned int)&_ExceptionVectorsEnd
) + 4096;
162 /* If we are on a PDM machine memory at 1M might be used
163 * for video. TODO NMGS call video driver to do this
168 /* For PowerMac, first_avail is set to above the bootstrap task.
169 * TODO NMGS - different screen modes - might free mem?
172 first_avail
= round_page(args
->first_avail
);
175 /* map in the exception vectors */
177 * map the kernel text, data and bss. Don't forget other regions too
179 for (i
= 0; i
< args
->kern_info
.region_count
; i
++) {
181 if (args
->kern_info
.regions
[i
].prot
== VM_PROT_NONE
&&
182 i
== args
->kern_info
.region_count
- 1) {
183 /* assume that's the kernel symbol table */
184 kern_sym_start
= args
->kern_info
.regions
[i
].addr
;
185 kern_sym_size
= args
->kern_info
.regions
[i
].size
;
186 printf("kernel symbol table at 0x%x size 0x%x\n",
187 kern_sym_start
, kern_sym_size
);
188 args
->kern_info
.regions
[i
].prot
|=
189 (VM_PROT_WRITE
|VM_PROT_READ
);
191 #endif /* MACH_KDB */
194 /* Skip the VECTORS segment */
195 if (args
->kern_info
.regions
[i
].addr
== 0)
199 boot_region_count
= args
->task_info
.region_count
;
201 boot_task_end_offset
= 0;
202 /* Map bootstrap task pages 1-1 so that user_bootstrap can find it */
203 for (i
= 0; i
< boot_region_count
; i
++) {
204 if (args
->task_info
.regions
[i
].mapped
) {
205 /* kernel requires everything page aligned */
207 printf("mapping virt 0x%08x to phys 0x%08x end 0x%x, prot=0x%b\n",
208 ppc_trunc_page(args
->task_info
.base_addr
+
209 args
->task_info
.regions
[i
].offset
),
210 ppc_trunc_page(args
->task_info
.base_addr
+
211 args
->task_info
.regions
[i
].offset
),
212 ppc_round_page(args
->task_info
.base_addr
+
213 args
->task_info
.regions
[i
].offset
+
214 args
->task_info
.regions
[i
].size
),
215 args
->task_info
.regions
[i
].prot
,
216 "\x10\1READ\2WRITE\3EXEC");
220 ppc_trunc_page(args
->task_info
.base_addr
+
221 args
->task_info
.regions
[i
].offset
),
222 ppc_trunc_page(args
->task_info
.base_addr
+
223 args
->task_info
.regions
[i
].offset
),
224 ppc_round_page(args
->task_info
.base_addr
+
225 args
->task_info
.regions
[i
].offset
+
226 args
->task_info
.regions
[i
].size
),
227 args
->task_info
.regions
[i
].prot
);
229 /* Count the size of mapped space */
230 boot_size
+= args
->task_info
.regions
[i
].size
;
232 /* There may be an overlapping physical page
233 * mapped to two different virtual addresses
235 if (boot_task_end_offset
>
236 args
->task_info
.regions
[i
].offset
) {
237 boot_size
-= boot_task_end_offset
-
238 args
->task_info
.regions
[i
].offset
;
240 printf("WARNING - bootstrap overlaps regions\n");
244 boot_task_end_offset
=
245 args
->task_info
.regions
[i
].offset
+
246 args
->task_info
.regions
[i
].size
;
250 if (boot_region_count
) {
252 /* Add a new region to the bootstrap task for it's stack */
253 args
->task_info
.regions
[boot_region_count
].addr
=
255 args
->task_info
.regions
[boot_region_count
].size
=
257 args
->task_info
.regions
[boot_region_count
].mapped
= FALSE
;
260 boot_start
= args
->task_info
.base_addr
;
261 boot_region_desc
= (vm_offset_t
) args
->task_info
.regions
;
262 /* TODO NMGS need to put param info onto top of boot stack */
263 boot_task_thread_state
.r1
= BOOT_STACK_PTR
-0x100;
264 boot_task_thread_state
.srr0
= args
->task_info
.entry
;
265 boot_task_thread_state
.srr1
=
266 MSR_MARK_SYSCALL(MSR_EXPORT_MASK_SET
);
268 boot_thread_state_flavor
= PPC_THREAD_STATE
;
269 boot_thread_state_count
= PPC_THREAD_STATE_COUNT
;
271 (thread_state_t
)&boot_task_thread_state
;