2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
25 #include <mach/vm_types.h>
26 #include <mach/vm_param.h>
27 #include <mach/thread_status.h>
28 #include <kern/misc_protos.h>
29 #include <kern/assert.h>
30 #include <kern/cpu_number.h>
32 #include <ppc/proc_reg.h>
34 #include <ppc/misc_protos.h>
36 #include <ppc/pmap_internals.h>
38 #include <ppc/exception.h>
39 #include <ppc/gdb_defs.h>
40 #include <ppc/POWERMAC/video_board.h>
41 #include <ppc/POWERMAC/video_pdm.h>
44 #include <mach-o/mach_header.h>
47 /* External references */
49 extern unsigned int intstack
[]; /* declared in start.s */
50 extern unsigned int intstack_top_ss
; /* declared in start.s */
52 extern unsigned int gdbstackptr
; /* declared in start.s */
53 extern unsigned int gdbstack_top_ss
; /* declared in start.s */
54 #endif /* MACH_KGDB */
56 /* Stuff declared in kern/bootstrap.c which we may need to initialise */
58 extern vm_offset_t boot_start
;
59 extern vm_size_t boot_size
;
60 extern vm_offset_t boot_region_desc
;
61 extern vm_size_t boot_region_count
;
62 extern int boot_thread_state_flavor
;
63 extern thread_state_t boot_thread_state
;
64 extern unsigned int boot_thread_state_count
;
66 /* Trap handling function prototypes */
68 extern void thandler(void); /* trap handler */
69 extern void ihandler(void); /* interrupt handler */
70 extern void shandler(void); /* syscall handler */
71 extern void gdbhandler(void); /* debugger handler */
72 extern void fpu_switch(void); /* fp handler */
73 extern void atomic_switch_trap(void); /* fast path atomic thread switch */
77 struct ppc_thread_state boot_task_thread_state
;
83 #if 1 /* TODO NMGS - vm_map_steal_memory shouldn't use these - remove */
84 vm_offset_t avail_start
;
85 vm_offset_t avail_end
;
87 unsigned int avail_remaining
= 0;
88 vm_offset_t first_avail
;
96 extern struct mach_header _mh_execute_header
;
106 vm_offset_t end
, etext
, edata
;
112 void ppc_vm_init(unsigned int memory_size
, boot_args
*args
)
114 unsigned int htabmask
;
117 int boot_task_end_offset
;
120 #endif /* NCPUS > 1 */
122 printf("mem_size = %d M\n",memory_size
/ (1024 * 1024));
125 /* Now retrieve addresses for end, edata, and etext
126 * from MACH-O headers.
130 etext
= (vm_offset_t
) sectTEXTB
+ sectSizeTEXT
;
131 edata
= (vm_offset_t
) sectDATAB
+ sectSizeDATA
;
135 /* Stitch valid memory regions together - they may be contiguous
136 * even though they're not already glued together
139 /* Go through the list of memory regions passed in via the args
140 * and copy valid entries into the pmap_mem_regions table, adding
141 * further calculated entries.
145 /* Initialise the pmap system, using space above `first_avail'*/
148 free_regions
[free_regions_count
].start
=
149 round_page((unsigned int)&_ExceptionVectorsEnd
-
150 (unsigned int)&_ExceptionVectorsStart
);
152 /* On MACH-O generated kernels, the Exception Vectors
153 * are already mapped and loaded at 0 -- no relocation
154 * or freeing of memory is needed
157 free_regions
[free_regions_count
].start
= round_page((unsigned int)&_ExceptionVectorsEnd
) + 4096;
160 /* If we are on a PDM machine memory at 1M might be used
161 * for video. TODO NMGS call video driver to do this
166 /* For PowerMac, first_avail is set to above the bootstrap task.
167 * TODO NMGS - different screen modes - might free mem?
170 first_avail
= round_page(args
->first_avail
);
173 /* map in the exception vectors */
175 * map the kernel text, data and bss. Don't forget other regions too
177 for (i
= 0; i
< args
->kern_info
.region_count
; i
++) {
179 if (args
->kern_info
.regions
[i
].prot
== VM_PROT_NONE
&&
180 i
== args
->kern_info
.region_count
- 1) {
181 /* assume that's the kernel symbol table */
182 kern_sym_start
= args
->kern_info
.regions
[i
].addr
;
183 kern_sym_size
= args
->kern_info
.regions
[i
].size
;
184 printf("kernel symbol table at 0x%x size 0x%x\n",
185 kern_sym_start
, kern_sym_size
);
186 args
->kern_info
.regions
[i
].prot
|=
187 (VM_PROT_WRITE
|VM_PROT_READ
);
189 #endif /* MACH_KDB */
192 /* Skip the VECTORS segment */
193 if (args
->kern_info
.regions
[i
].addr
== 0)
197 boot_region_count
= args
->task_info
.region_count
;
199 boot_task_end_offset
= 0;
200 /* Map bootstrap task pages 1-1 so that user_bootstrap can find it */
201 for (i
= 0; i
< boot_region_count
; i
++) {
202 if (args
->task_info
.regions
[i
].mapped
) {
203 /* kernel requires everything page aligned */
205 printf("mapping virt 0x%08x to phys 0x%08x end 0x%x, prot=0x%b\n",
206 ppc_trunc_page(args
->task_info
.base_addr
+
207 args
->task_info
.regions
[i
].offset
),
208 ppc_trunc_page(args
->task_info
.base_addr
+
209 args
->task_info
.regions
[i
].offset
),
210 ppc_round_page(args
->task_info
.base_addr
+
211 args
->task_info
.regions
[i
].offset
+
212 args
->task_info
.regions
[i
].size
),
213 args
->task_info
.regions
[i
].prot
,
214 "\x10\1READ\2WRITE\3EXEC");
218 ppc_trunc_page(args
->task_info
.base_addr
+
219 args
->task_info
.regions
[i
].offset
),
220 ppc_trunc_page(args
->task_info
.base_addr
+
221 args
->task_info
.regions
[i
].offset
),
222 ppc_round_page(args
->task_info
.base_addr
+
223 args
->task_info
.regions
[i
].offset
+
224 args
->task_info
.regions
[i
].size
),
225 args
->task_info
.regions
[i
].prot
);
227 /* Count the size of mapped space */
228 boot_size
+= args
->task_info
.regions
[i
].size
;
230 /* There may be an overlapping physical page
231 * mapped to two different virtual addresses
233 if (boot_task_end_offset
>
234 args
->task_info
.regions
[i
].offset
) {
235 boot_size
-= boot_task_end_offset
-
236 args
->task_info
.regions
[i
].offset
;
238 printf("WARNING - bootstrap overlaps regions\n");
242 boot_task_end_offset
=
243 args
->task_info
.regions
[i
].offset
+
244 args
->task_info
.regions
[i
].size
;
248 if (boot_region_count
) {
250 /* Add a new region to the bootstrap task for it's stack */
251 args
->task_info
.regions
[boot_region_count
].addr
=
253 args
->task_info
.regions
[boot_region_count
].size
=
255 args
->task_info
.regions
[boot_region_count
].mapped
= FALSE
;
258 boot_start
= args
->task_info
.base_addr
;
259 boot_region_desc
= (vm_offset_t
) args
->task_info
.regions
;
260 /* TODO NMGS need to put param info onto top of boot stack */
261 boot_task_thread_state
.r1
= BOOT_STACK_PTR
-0x100;
262 boot_task_thread_state
.srr0
= args
->task_info
.entry
;
263 boot_task_thread_state
.srr1
=
264 MSR_MARK_SYSCALL(MSR_EXPORT_MASK_SET
);
266 boot_thread_state_flavor
= PPC_THREAD_STATE
;
267 boot_thread_state_count
= PPC_THREAD_STATE_COUNT
;
269 (thread_state_t
)&boot_task_thread_state
;