3 #include "../port/lib.h"
10 #include "rebootcode.i"
14 #define BOOTARGS (xenstart->cmd_line)
15 #define BOOTARGSLEN (sizeof xenstart->cmd_line)
19 char *confname[MAXCONF];
20 char *confval[MAXCONF];
28 char *cp, *line[MAXCONF], *p, *q;
31 * parse configuration args from dos file plan9.ini
33 cp = BOOTARGS; /* where b.com leaves its config */
34 cp[BOOTARGSLEN-1] = 0;
37 * Strip out '\r', change '\t' -> ' '.
49 n = getfields(cp, line, MAXCONF, 1, "\n");
50 for(i = 0; i < n; i++){
53 cp = strchr(line[i], '=');
57 confname[nconf] = line[i];
73 print("\nPlan 9 (%s)\n", xenstart->magic);
76 // meminit() is not for us
86 if(arch->intrinit) /* launches other processors on an mp */
111 MACHP(0) = (Mach*)CPU0MACH;
112 m->pdb = (ulong*)xenstart->pt_base;
128 memset(m, 0, sizeof(Mach));
134 * For polled uart output at boot, need
135 * a default delay constant. 100000 should
136 * be enough for a while. Cpuidentify will
137 * calculate the real value later.
139 m->loopconst = 100000;
140 m->cpumhz = 1000; // XXX!
142 HYPERVISOR_shared_info = (shared_info_t*)mmumapframe(XENSHARED, (xenstart->shared_info)>>PGSHIFT);
144 // XXX m->shared = &HYPERVISOR_shared_info->vcpu_data[m->machno];
150 char buf[2*KNAMELEN], **sp;
156 snprint(buf, sizeof(buf), "%s %s", arch->id, conffile);
157 ksetenv("terminal", buf, 0);
158 ksetenv("cputype", "386", 0);
160 ksetenv("service", "cpu", 0);
162 ksetenv("service", "terminal", 0);
163 ksetenv("readparts", "1", 0);
164 for(i = 0; i < nconf; i++){
165 if(confname[i][0] != '*')
166 ksetenv(confname[i], confval[i], 0);
167 ksetenv(confname[i], confval[i], 1);
171 kproc("alarm", alarmkproc, 0);
173 sp = (char**)(USTKTOP - sizeof(Tos) - 8 - sizeof(sp[0])*4);
175 strcpy(sp[1] = (char*)&sp[4], "boot");
185 for(i = 0; i < nconf; i++)
186 if(cistrcmp(confname[i], name) == 0)
204 /* convert to name=value\n format */
213 error("kernel configuration too large");
214 memmove(BOOTARGS, p, n);
226 for(i = 0; i < nconf; i++)
227 print("%s=%s\n", confname[i], confval[i]);
229 * all ram above xentop is free, but must be mappable
230 * to virt addrs less than VIRT_START.
232 kpages = PADDR(hypervisor_virt_start)>>PGSHIFT;
233 if(xenstart->nr_pages <= kpages)
234 kpages = xenstart->nr_pages;
236 print("Warning: Plan 9 / Xen limitation - "
237 "using only %lud of %lud available RAM pages\n",
238 kpages, xenstart->nr_pages);
239 xentop = PGROUND(PADDR(xentop));
240 conf.mem[0].npage = kpages - (xentop>>PGSHIFT);
241 conf.mem[0].base = xentop;
243 if(p = getconf("*kernelpercent"))
244 userpcnt = 100 - strtol(p, 0, 0);
249 for(i=0; i<nelem(conf.mem); i++)
250 conf.npage += conf.mem[i].npage;
252 conf.nproc = 100 + ((conf.npage*BY2PG)/MB)*5;
255 if(conf.nproc > 2000)
258 conf.nswap = conf.nproc*80;
264 kpages = conf.npage - (conf.npage*userpcnt)/100;
267 * Hack for the big boys. Only good while physmem < 4GB.
268 * Give the kernel fixed max + enough to allocate the
270 * This is an overestimate as conf.upages < conf.npages.
271 * The patch of nimage is a band-aid, scanning the whole
272 * page list in imagereclaim just takes too long.
274 if(kpages > (64*MB + conf.npage*sizeof(Page))/BY2PG){
275 kpages = (64*MB + conf.npage*sizeof(Page))/BY2PG;
277 kpages += (conf.nproc*KSTACK)/BY2PG;
281 if(conf.npage*BY2PG < 16*MB)
286 kpages = conf.npage - (conf.npage*userpcnt)/100;
289 * Make sure terminals with low memory get at least
290 * 4MB on the first Image chunk allocation.
292 if(conf.npage*BY2PG < 16*MB)
293 imagmem->minarena = 4*1024*1024;
297 * can't go past the end of virtual memory
298 * (ulong)-KZERO is 2^32 - KZERO
300 if(kpages > ((ulong)-KZERO)/BY2PG)
301 kpages = ((ulong)-KZERO)/BY2PG;
303 conf.upages = conf.npage - kpages;
304 conf.ialloc = (kpages/2)*BY2PG;
307 * Guess how much is taken by the large permanent
308 * datastructures. Mntcache and Mntrpc are not accounted for.
311 kpages -= conf.upages*sizeof(Page)
312 + conf.nproc*sizeof(Proc)
313 + conf.nimage*sizeof(Image)
315 + conf.nswppo*sizeof(Page*);
316 mainmem->maxsize = kpages;
319 * give terminals lots of image memory, too; the dynamic
320 * allocation will balance the load properly, hopefully.
321 * be careful with 32-bit overflow.
323 imagmem->maxsize = kpages;
346 * Save the mach dependent part of the process state.
354 * While this processor is in the scheduler, the process could run
355 * on another processor and exit, returning the page tables to
356 * the free list where they could be reallocated and overwritten.
357 * When this processor eventually has to get an entry from the
358 * trashed page tables it will crash.
360 * If there's only one processor, this can't happen.
361 * You might think it would be a win not to do this in that case,
362 * especially on VMware, but it turns out not to matter.
368 reboot(void *entry, void *code, ulong size)
370 void (*f)(ulong, ulong, ulong);
377 /* turn off buffered serial console */
380 /* shutdown devices */
383 /* reboot(0, ...) on Xen causes domU shutdown */
385 HYPERVISOR_shutdown(0);
389 /* setup reboot trampoline function */
390 f = (void*)REBOOTADDR;
391 memmove(f, rebootcode, sizeof(rebootcode));
393 /* off we go - never to return */
394 (*f)(PADDR(entry), PADDR(code), size);