]>
Commit | Line | Data |
---|---|---|
55e303ae A |
1 | /* |
2 | * Copyright (c) 2003 Apple Computer, Inc. All rights reserved. | |
3 | * | |
4 | * @APPLE_LICENSE_HEADER_START@ | |
5 | * | |
e5568f75 A |
6 | * The contents of this file constitute Original Code as defined in and |
7 | * are subject to the Apple Public Source License Version 1.1 (the | |
8 | * "License"). You may not use this file except in compliance with the | |
9 | * License. Please obtain a copy of the License at | |
10 | * http://www.apple.com/publicsource and read it before using this file. | |
11 | * | |
12 | * This Original Code and all software distributed under the License are | |
13 | * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
55e303ae A |
14 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
15 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
e5568f75 A |
16 | * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the |
17 | * License for the specific language governing rights and limitations | |
18 | * under the License. | |
55e303ae A |
19 | * |
20 | * @APPLE_LICENSE_HEADER_END@ | |
21 | */ | |
22 | /* | |
23 | * @OSF_COPYRIGHT@ | |
24 | */ | |
25 | /* | |
26 | * Mach Operating System | |
27 | * Copyright (c) 1991,1990,1989, 1988 Carnegie Mellon University | |
28 | * All Rights Reserved. | |
29 | * | |
30 | * Permission to use, copy, modify and distribute this software and its | |
31 | * documentation is hereby granted, provided that both the copyright | |
32 | * notice and this permission notice appear in all copies of the | |
33 | * software, derivative works or modified versions, and any portions | |
34 | * thereof, and that both notices appear in supporting documentation. | |
35 | * | |
36 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
37 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
38 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
39 | * | |
40 | * Carnegie Mellon requests users of this software to return to | |
41 | * | |
42 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
43 | * School of Computer Science | |
44 | * Carnegie Mellon University | |
45 | * Pittsburgh PA 15213-3890 | |
46 | * | |
47 | * any improvements or extensions that they make and grant Carnegie Mellon | |
48 | * the rights to redistribute these changes. | |
49 | */ | |
50 | ||
51 | #include <cpus.h> | |
52 | #include <platforms.h> | |
53 | #include <mach_kdb.h> | |
54 | #include <himem.h> | |
55 | #include <fast_idle.h> | |
56 | ||
57 | #include <mach/i386/vm_param.h> | |
58 | ||
59 | #include <string.h> | |
60 | #include <mach/vm_param.h> | |
61 | #include <mach/vm_prot.h> | |
62 | #include <mach/machine.h> | |
63 | #include <mach/time_value.h> | |
64 | #include <kern/etap_macros.h> | |
65 | #include <kern/spl.h> | |
66 | #include <kern/assert.h> | |
67 | #include <kern/debug.h> | |
68 | #include <kern/misc_protos.h> | |
69 | #include <kern/cpu_data.h> | |
70 | #include <kern/processor.h> | |
71 | #include <vm/vm_page.h> | |
72 | #include <vm/pmap.h> | |
73 | #include <vm/vm_kern.h> | |
74 | #include <i386/pmap.h> | |
75 | #include <i386/ipl.h> | |
76 | #include <i386/pio.h> | |
77 | #include <i386/misc_protos.h> | |
78 | #include <i386/mp_slave_boot.h> | |
79 | #ifdef __MACHO__ | |
80 | #include <mach/boot_info.h> | |
81 | #include <mach/thread_status.h> | |
82 | #endif | |
83 | ||
84 | vm_size_t mem_size = 0; | |
85 | vm_offset_t first_addr = 0; /* set by start.s - keep out of bss */ | |
86 | vm_offset_t first_avail = 0;/* first after page tables */ | |
87 | vm_offset_t last_addr; | |
88 | ||
89 | uint64_t max_mem; | |
90 | uint64_t sane_size; | |
91 | ||
92 | vm_offset_t avail_start, avail_end; | |
93 | vm_offset_t virtual_avail, virtual_end; | |
94 | vm_offset_t hole_start, hole_end; | |
95 | vm_offset_t avail_next; | |
96 | unsigned int avail_remaining; | |
97 | ||
98 | /* parameters passed from bootstrap loader */ | |
99 | int cnvmem = 0; /* must be in .data section */ | |
100 | int extmem = 0; | |
101 | ||
102 | #ifndef __MACHO__ | |
103 | extern char edata, end; | |
104 | #endif | |
105 | ||
106 | #ifdef __MACHO__ | |
107 | #include <mach-o/loader.h> | |
108 | vm_offset_t edata, etext, end; | |
109 | ||
110 | extern struct mach_header _mh_execute_header; | |
111 | void *sectTEXTB; int sectSizeTEXT; | |
112 | void *sectDATAB; int sectSizeDATA; | |
113 | void *sectOBJCB; int sectSizeOBJC; | |
114 | void *sectLINKB; int sectSizeLINK; | |
115 | void *sectPRELINKB; int sectSizePRELINK; | |
116 | ||
117 | #endif | |
118 | ||
119 | /* | |
120 | * Basic VM initialization. | |
121 | */ | |
122 | void | |
123 | i386_vm_init(unsigned int maxmem, KernelBootArgs_t *args) | |
124 | { | |
125 | int i,j; /* Standard index vars. */ | |
126 | vm_size_t bios_hole_size; | |
127 | ||
128 | #ifdef __MACHO__ | |
129 | /* Now retrieve addresses for end, edata, and etext | |
130 | * from MACH-O headers. | |
131 | */ | |
132 | ||
133 | sectTEXTB = (void *) getsegdatafromheader( | |
134 | &_mh_execute_header, "__TEXT", §SizeTEXT); | |
135 | sectDATAB = (void *) getsegdatafromheader( | |
136 | &_mh_execute_header, "__DATA", §SizeDATA); | |
137 | sectOBJCB = (void *) getsegdatafromheader( | |
138 | &_mh_execute_header, "__OBJC", §SizeOBJC); | |
139 | sectLINKB = (void *) getsegdatafromheader( | |
140 | &_mh_execute_header, "__LINKEDIT", §SizeLINK); | |
141 | sectPRELINKB = (void *) getsegdatafromheader( | |
142 | &_mh_execute_header, "__PRELINK", §SizePRELINK); | |
143 | ||
144 | etext = (vm_offset_t) sectTEXTB + sectSizeTEXT; | |
145 | edata = (vm_offset_t) sectDATAB + sectSizeDATA; | |
146 | #endif | |
147 | #ifndef __MACHO__ | |
148 | /* | |
149 | * Zero the BSS. | |
150 | */ | |
151 | ||
152 | bzero((char *)&edata,(unsigned)(&end - &edata)); | |
153 | #endif | |
154 | ||
155 | /* Now copy over various boot args bits.. */ | |
156 | cnvmem = args->convmem; | |
157 | extmem = args->extmem; | |
158 | ||
159 | /* | |
160 | * Initialize the pic prior to any possible call to an spl. | |
161 | */ | |
162 | ||
163 | set_cpu_model(); | |
164 | vm_set_page_size(); | |
165 | ||
166 | /* | |
167 | * Initialize the Event Trace Analysis Package | |
168 | * Static Phase: 1 of 2 | |
169 | */ | |
170 | etap_init_phase1(); | |
171 | ||
172 | /* | |
173 | * Compute the memory size. | |
174 | */ | |
175 | ||
176 | #if NCPUS > 1 | |
177 | /* First two pages are used to boot the other cpus. */ | |
178 | /* TODO - reclaim pages after all cpus have booted */ | |
179 | ||
180 | first_addr = MP_FIRST_ADDR; | |
181 | #else | |
182 | first_addr = 0x1000; | |
183 | #endif | |
184 | ||
185 | /* BIOS leaves data in low memory */ | |
186 | last_addr = 1024*1024 + extmem*1024; | |
187 | ||
188 | /* extended memory starts at 1MB */ | |
189 | ||
190 | bios_hole_size = 1024*1024 - trunc_page((vm_offset_t)(1024 * cnvmem)); | |
191 | ||
192 | /* | |
193 | * Initialize for pmap_free_pages and pmap_next_page. | |
194 | * These guys should be page-aligned. | |
195 | */ | |
196 | ||
197 | hole_start = trunc_page((vm_offset_t)(1024 * cnvmem)); | |
198 | hole_end = round_page((vm_offset_t)first_avail); | |
199 | ||
200 | /* | |
201 | * compute mem_size | |
202 | */ | |
203 | ||
204 | /* | |
205 | * We're currently limited to 512 MB max physical memory. | |
206 | */ | |
207 | #define M (1024*1024) | |
208 | #define MAXMEM (512*M) | |
209 | if ((maxmem == 0) && (last_addr - bios_hole_size > MAXMEM)) { | |
210 | printf("Physical memory %d MB, "\ | |
211 | "maximum usable memory limited to %d MB\n", | |
212 | (last_addr - bios_hole_size)/M, MAXMEM/M); | |
213 | maxmem = MAXMEM; | |
214 | } | |
215 | ||
216 | if (maxmem != 0) { | |
217 | if (maxmem < (last_addr) - bios_hole_size) | |
218 | last_addr = maxmem + bios_hole_size; | |
219 | } | |
220 | ||
221 | first_addr = round_page(first_addr); | |
222 | last_addr = trunc_page(last_addr); | |
223 | mem_size = last_addr - bios_hole_size; | |
224 | ||
225 | max_mem = (uint64_t)mem_size; | |
226 | sane_size = max_mem; | |
227 | ||
228 | avail_start = first_addr; | |
229 | avail_end = last_addr; | |
230 | avail_next = avail_start; | |
231 | ||
232 | #if NCPUS > 1 | |
233 | interrupt_stack_alloc(); | |
234 | #endif /* NCPUS > 1 */ | |
235 | ||
236 | /* | |
237 | * Initialize kernel physical map. | |
238 | * Kernel virtual address starts at VM_KERNEL_MIN_ADDRESS. | |
239 | */ | |
240 | pmap_bootstrap(0); | |
241 | ||
242 | avail_remaining = atop((avail_end - avail_start) - | |
243 | (hole_end - hole_start)); | |
244 | } | |
245 | ||
246 | unsigned int | |
247 | pmap_free_pages(void) | |
248 | { | |
249 | return avail_remaining; | |
250 | } | |
251 | ||
252 | boolean_t | |
253 | pmap_next_page( | |
254 | ppnum_t *pn) | |
255 | { | |
256 | if (avail_next == avail_end) | |
257 | return FALSE; | |
258 | ||
259 | /* skip the hole */ | |
260 | ||
261 | if (avail_next == hole_start) | |
262 | avail_next = hole_end; | |
263 | ||
264 | *pn = (ppnum_t)i386_btop(avail_next); | |
265 | avail_next += PAGE_SIZE; | |
266 | avail_remaining--; | |
267 | ||
268 | return TRUE; | |
269 | } | |
270 | ||
271 | boolean_t | |
272 | pmap_valid_page( | |
273 | vm_offset_t x) | |
274 | { | |
275 | return ((avail_start <= x) && (x < avail_end)); | |
276 | } |