xref: /titanic_44/usr/src/uts/i86pc/os/fakebop.c (revision 62a1b812a0c45c0d4c10ef645dda42bf71080108)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*
30  * This file contains the functionality that mimics the boot operations
31  * on SPARC systems or the old boot.bin/multiboot programs on x86 systems.
32  * The x86 kernel now does everything on its own.
33  */
34 
35 #include <sys/types.h>
36 #include <sys/bootconf.h>
37 #include <sys/bootsvcs.h>
38 #include <sys/bootinfo.h>
39 #include <sys/multiboot.h>
40 #include <sys/bootvfs.h>
41 #include <sys/bootprops.h>
42 #include <sys/varargs.h>
43 #include <sys/param.h>
44 #include <sys/machparam.h>
45 #include <sys/archsystm.h>
46 #include <sys/boot_console.h>
47 #include <sys/cmn_err.h>
48 #include <sys/systm.h>
49 #include <sys/promif.h>
50 #include <sys/archsystm.h>
51 #include <sys/x86_archext.h>
52 #include <sys/kobj.h>
53 #include <sys/privregs.h>
54 #include <sys/sysmacros.h>
55 #include <sys/ctype.h>
56 #include <vm/kboot_mmu.h>
57 #include <vm/hat_pte.h>
58 #include "acpi_fw.h"
59 
60 static int have_console = 0;	/* set once primitive console is initialized */
61 static char *boot_args = "";
62 
63 /*
64  * Debugging macros
65  */
66 static uint_t kbm_debug = 0;
67 #define	DBG_MSG(s)	{ if (kbm_debug) bop_printf(NULL, "%s", s); }
68 #define	DBG(x)		{ if (kbm_debug)			\
69 	bop_printf(NULL, "%s is %" PRIx64 "\n", #x, (uint64_t)(x));	\
70 	}
71 
72 #define	PUT_STRING(s) {				\
73 	char *cp;				\
74 	for (cp = (s); *cp; ++cp)		\
75 		bcons_putchar(*cp);		\
76 	}
77 
78 struct xboot_info *xbootp;	/* boot info from "glue" code in low memory */
79 bootops_t bootop;	/* simple bootops we'll pass on to kernel */
80 struct bsys_mem bm;
81 
82 static uintptr_t next_virt;	/* next available virtual address */
83 static paddr_t next_phys;	/* next available physical address from dboot */
84 static paddr_t high_phys = -(paddr_t)1;	/* last used physical address */
85 
86 /*
87  * buffer for vsnprintf for console I/O
88  */
89 #define	BUFFERSIZE	256
90 static char buffer[BUFFERSIZE];
91 /*
92  * stuff to store/report/manipulate boot property settings.
93  */
94 typedef struct bootprop {
95 	struct bootprop *bp_next;
96 	char *bp_name;
97 	uint_t bp_vlen;
98 	char *bp_value;
99 } bootprop_t;
100 
101 static bootprop_t *bprops = NULL;
102 static char *curr_page = NULL;		/* ptr to avail bprop memory */
103 static int curr_space = 0;		/* amount of memory at curr_page */
104 
105 /*
106  * some allocator statistics
107  */
108 static ulong_t total_bop_alloc_scratch = 0;
109 static ulong_t total_bop_alloc_kernel = 0;
110 
111 static void build_firmware_properties(void);
112 
113 /*
114  * Allocate aligned physical memory at boot time. This allocator allocates
115  * from the highest possible addresses. This avoids exhausting memory that
116  * would be useful for DMA buffers.
117  */
118 paddr_t
119 do_bop_phys_alloc(uint64_t size, uint64_t align)
120 {
121 	paddr_t	pa = 0;
122 	paddr_t	start;
123 	paddr_t	end;
124 	struct memlist	*ml = (struct memlist *)xbootp->bi_phys_install;
125 
126 	/*
127 	 * Be careful if high memory usage is limited in startup.c
128 	 * Since there are holes in the low part of the physical address
129 	 * space we can treat physmem as a pfn (not just a pgcnt) and
130 	 * get a conservative upper limit.
131 	 */
132 	extern pgcnt_t physmem;
133 	if (physmem != 0 && high_phys > pfn_to_pa(physmem))
134 		high_phys = pfn_to_pa(physmem);
135 
136 	/*
137 	 * find the highest available memory in physinstalled
138 	 */
139 	size = P2ROUNDUP(size, align);
140 	for (; ml; ml = ml->next) {
141 		start = ml->address;
142 		end = P2ALIGN(start + ml->size, align);
143 		if (start < next_phys)
144 			start = next_phys;
145 		if (end > high_phys)
146 			end = P2ALIGN(high_phys, align);
147 
148 		if (end <= start)
149 			continue;
150 		if (end - start < size)
151 			continue;
152 
153 		if (end - size > pa)
154 			pa = end - size;
155 	}
156 	if (pa != 0) {
157 		high_phys = pa;
158 		return (pa);
159 	}
160 	panic("do_bop_phys_alloc(0x%" PRIx64 ", 0x%" PRIx64 ") Out of memory\n",
161 	    size, align);
162 	/*NOTREACHED*/
163 }
164 
165 static uintptr_t
166 alloc_vaddr(size_t size, paddr_t align)
167 {
168 	uintptr_t rv;
169 
170 	next_virt = P2ROUNDUP(next_virt, (uintptr_t)align);
171 	rv = (uintptr_t)next_virt;
172 	next_virt += size;
173 	return (rv);
174 }
175 
176 /*
177  * Allocate virtual memory. The size is always rounded up to a multiple
178  * of base pagesize.
179  */
180 
181 /*ARGSUSED*/
182 static caddr_t
183 do_bsys_alloc(bootops_t *bop, caddr_t virthint, size_t size, int align)
184 {
185 	paddr_t a = align;	/* same type as pa for masking */
186 	uint_t pgsize;
187 	paddr_t pa;
188 	uintptr_t va;
189 	ssize_t s;		/* the aligned size */
190 	uint_t level;
191 	uint_t is_kernel = (virthint != 0);
192 
193 	if (a < MMU_PAGESIZE)
194 		a = MMU_PAGESIZE;
195 	else if (!ISP2(a))
196 		prom_panic("do_bsys_alloc() incorrect alignment");
197 	size = P2ROUNDUP(size, MMU_PAGESIZE);
198 
199 	/*
200 	 * Use the next aligned virtual address if we weren't given one.
201 	 */
202 	if (virthint == NULL) {
203 		virthint = (caddr_t)alloc_vaddr(size, a);
204 		total_bop_alloc_scratch += size;
205 	} else {
206 		total_bop_alloc_kernel += size;
207 	}
208 
209 	/*
210 	 * allocate the physical memory
211 	 */
212 	pa = do_bop_phys_alloc(size, a);
213 
214 	/*
215 	 * Add the mappings to the page tables, try large pages first.
216 	 */
217 	va = (uintptr_t)virthint;
218 	s = size;
219 	level = 1;
220 	pgsize = xbootp->bi_use_pae ? TWO_MEG : FOUR_MEG;
221 	if (xbootp->bi_use_largepage && a == pgsize) {
222 		while (IS_P2ALIGNED(pa, pgsize) && IS_P2ALIGNED(va, pgsize) &&
223 		    s >= pgsize) {
224 			kbm_map(va, pa, level, is_kernel);
225 			va += pgsize;
226 			pa += pgsize;
227 			s -= pgsize;
228 		}
229 	}
230 
231 	/*
232 	 * Map remaining pages use small mappings
233 	 */
234 	level = 0;
235 	pgsize = MMU_PAGESIZE;
236 	while (s > 0) {
237 		kbm_map(va, pa, level, is_kernel);
238 		va += pgsize;
239 		pa += pgsize;
240 		s -= pgsize;
241 	}
242 	return (virthint);
243 }
244 
245 /*
246  * Free virtual memory - we'll just ignore these.
247  */
248 /*ARGSUSED*/
249 static void
250 do_bsys_free(bootops_t *bop, caddr_t virt, size_t size)
251 {
252 	bop_printf(NULL, "do_bsys_free(virt=0x%p, size=0x%lx) ignored\n",
253 	    (void *)virt, size);
254 }
255 
256 /*
257  * Old interface
258  */
259 /*ARGSUSED*/
260 static caddr_t
261 do_bsys_ealloc(
262 	bootops_t *bop,
263 	caddr_t virthint,
264 	size_t size,
265 	int align,
266 	int flags)
267 {
268 	prom_panic("unsupported call to BOP_EALLOC()\n");
269 	return (0);
270 }
271 
272 
273 static void
274 bsetprop(char *name, int nlen, void *value, int vlen)
275 {
276 	uint_t size;
277 	uint_t need_size;
278 	bootprop_t *b;
279 
280 	/*
281 	 * align the size to 16 byte boundary
282 	 */
283 	size = sizeof (bootprop_t) + nlen + 1 + vlen;
284 	size = (size + 0xf) & ~0xf;
285 	if (size > curr_space) {
286 		need_size = (size + (MMU_PAGEOFFSET)) & MMU_PAGEMASK;
287 		curr_page = do_bsys_alloc(NULL, 0, need_size, MMU_PAGESIZE);
288 		curr_space = need_size;
289 	}
290 
291 	/*
292 	 * use a bootprop_t at curr_page and link into list
293 	 */
294 	b = (bootprop_t *)curr_page;
295 	curr_page += sizeof (bootprop_t);
296 	curr_space -=  sizeof (bootprop_t);
297 	b->bp_next = bprops;
298 	bprops = b;
299 
300 	/*
301 	 * follow by name and ending zero byte
302 	 */
303 	b->bp_name = curr_page;
304 	bcopy(name, curr_page, nlen);
305 	curr_page += nlen;
306 	*curr_page++ = 0;
307 	curr_space -= nlen + 1;
308 
309 	/*
310 	 * copy in value, but no ending zero byte
311 	 */
312 	b->bp_value = curr_page;
313 	b->bp_vlen = vlen;
314 	if (vlen > 0) {
315 		bcopy(value, curr_page, vlen);
316 		curr_page += vlen;
317 		curr_space -= vlen;
318 	}
319 
320 	/*
321 	 * align new values of curr_page, curr_space
322 	 */
323 	while (curr_space & 0xf) {
324 		++curr_page;
325 		--curr_space;
326 	}
327 }
328 
329 static void
330 bsetprops(char *name, char *value)
331 {
332 	bsetprop(name, strlen(name), value, strlen(value) + 1);
333 }
334 
335 static void
336 bsetprop64(char *name, uint64_t value)
337 {
338 	bsetprop(name, strlen(name), (void *)&value, sizeof (value));
339 }
340 
341 static void
342 bsetpropsi(char *name, int value)
343 {
344 	char prop_val[32];
345 
346 	(void) snprintf(prop_val, sizeof (prop_val), "%d", value);
347 	bsetprops(name, prop_val);
348 }
349 
350 /*
351  * to find the size of the buffer to allocate
352  */
353 /*ARGSUSED*/
354 static int
355 do_bsys_getproplen(bootops_t *bop, char *name)
356 {
357 	bootprop_t *b;
358 
359 	for (b = bprops; b; b = b->bp_next) {
360 		if (strcmp(name, b->bp_name) != 0)
361 			continue;
362 		return (b->bp_vlen);
363 	}
364 	return (-1);
365 }
366 
367 /*
368  * get the value associated with this name
369  */
370 /*ARGSUSED*/
371 static int
372 do_bsys_getprop(bootops_t *bop, char *name, void *value)
373 {
374 	bootprop_t *b;
375 
376 	for (b = bprops; b; b = b->bp_next) {
377 		if (strcmp(name, b->bp_name) != 0)
378 			continue;
379 		bcopy(b->bp_value, value, b->bp_vlen);
380 		return (0);
381 	}
382 	return (-1);
383 }
384 
385 /*
386  * get the name of the next property in succession from the standalone
387  */
388 /*ARGSUSED*/
389 static char *
390 do_bsys_nextprop(bootops_t *bop, char *name)
391 {
392 	bootprop_t *b;
393 
394 	/*
395 	 * A null name is a special signal for the 1st boot property
396 	 */
397 	if (name == NULL || strlen(name) == 0) {
398 		if (bprops == NULL)
399 			return (NULL);
400 		return (bprops->bp_name);
401 	}
402 
403 	for (b = bprops; b; b = b->bp_next) {
404 		if (name != b->bp_name)
405 			continue;
406 		b = b->bp_next;
407 		if (b == NULL)
408 			return (NULL);
409 		return (b->bp_name);
410 	}
411 	return (NULL);
412 }
413 
414 /*
415  * 2nd part of building the table of boot properties. This includes:
416  * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
417  *
418  * lines look like one of:
419  * ^$
420  * ^# comment till end of line
421  * setprop name 'value'
422  * setprop name value
423  * setprop name "value"
424  *
425  * we do single character I/O since this is really just looking at memory
426  */
427 void
428 boot_prop_finish(void)
429 {
430 	int fd;
431 	char *line;
432 	int c;
433 	int bytes_read;
434 	char *name;
435 	int n_len;
436 	char *value;
437 	int v_len;
438 	char *inputdev;	/* these override the comand line if serial ports */
439 	char *outputdev;
440 	char *consoledev;
441 
442 	DBG_MSG("Opening /boot/solaris/bootenv.rc\n");
443 	fd = BRD_OPEN(bfs_ops, "/boot/solaris/bootenv.rc", 0);
444 	DBG(fd);
445 
446 	line = do_bsys_alloc(NULL, NULL, MMU_PAGESIZE, MMU_PAGESIZE);
447 	while (fd >= 0) {
448 
449 		/*
450 		 * get a line
451 		 */
452 		for (c = 0; ; ++c) {
453 			bytes_read = BRD_READ(bfs_ops, fd, line + c, 1);
454 			if (bytes_read == 0) {
455 				if (c == 0)
456 					goto done;
457 				break;
458 			}
459 			if (line[c] == '\n')
460 				break;
461 		}
462 		line[c] = 0;
463 
464 		/*
465 		 * ignore comment lines
466 		 */
467 		c = 0;
468 		while (ISSPACE(line[c]))
469 			++c;
470 		if (line[c] == '#' || line[c] == 0)
471 			continue;
472 
473 		/*
474 		 * must have "setprop " or "setprop\t"
475 		 */
476 		if (strncmp(line + c, "setprop ", 8) != 0 &&
477 		    strncmp(line + c, "setprop\t", 8) != 0)
478 			continue;
479 		c += 8;
480 		while (ISSPACE(line[c]))
481 			++c;
482 		if (line[c] == 0)
483 			continue;
484 
485 		/*
486 		 * gather up the property name
487 		 */
488 		name = line + c;
489 		n_len = 0;
490 		while (line[c] && !ISSPACE(line[c]))
491 			++n_len, ++c;
492 
493 		/*
494 		 * gather up the value, if any
495 		 */
496 		value = "";
497 		v_len = 0;
498 		while (ISSPACE(line[c]))
499 			++c;
500 		if (line[c] != 0) {
501 			value = line + c;
502 			while (line[c] && !ISSPACE(line[c]))
503 				++v_len, ++c;
504 		}
505 
506 		if (v_len >= 2 && value[0] == value[v_len - 1] &&
507 		    (value[0] == '\'' || value[0] == '"')) {
508 			++value;
509 			v_len -= 2;
510 		}
511 		name[n_len] = 0;
512 		if (v_len > 0)
513 			value[v_len] = 0;
514 		else
515 			continue;
516 
517 		/*
518 		 * ignore "boot-file" property, it's now meaningless
519 		 */
520 		if (strcmp(name, "boot-file") == 0)
521 			continue;
522 		if (strcmp(name, "boot-args") == 0 &&
523 		    strlen(boot_args) > 0)
524 			continue;
525 
526 		/*
527 		 * If console was explicitly set on the command line it will
528 		 * override a setting in bootenv.rc
529 		 */
530 		if (strcmp(name, "console") == 0 &&
531 		    do_bsys_getproplen(NULL, "console") > 0)
532 			continue;
533 
534 		bsetprop(name, n_len, value, v_len + 1);
535 	}
536 done:
537 	if (fd >= 0)
538 		BRD_CLOSE(bfs_ops, fd);
539 
540 	/*
541 	 * check to see if we have to override the default value of the console
542 	 */
543 	inputdev = line;
544 	v_len = do_bsys_getproplen(NULL, "input-device");
545 	if (v_len > 0)
546 		(void) do_bsys_getprop(NULL, "input-device", inputdev);
547 	else
548 		v_len = 0;
549 	inputdev[v_len] = 0;
550 
551 	outputdev = inputdev + v_len + 1;
552 	v_len = do_bsys_getproplen(NULL, "output-device");
553 	if (v_len > 0)
554 		(void) do_bsys_getprop(NULL, "output-device", outputdev);
555 	else
556 		v_len = 0;
557 	outputdev[v_len] = 0;
558 
559 	consoledev = outputdev + v_len + 1;
560 	v_len = do_bsys_getproplen(NULL, "console");
561 	if (v_len > 0)
562 		(void) do_bsys_getprop(NULL, "console", consoledev);
563 	else
564 		v_len = 0;
565 	consoledev[v_len] = 0;
566 	bcons_init2(inputdev, outputdev, consoledev);
567 
568 	if (strstr((char *)xbootp->bi_cmdline, "prom_debug") || kbm_debug) {
569 		value = line;
570 		bop_printf(NULL, "\nBoot properties:\n");
571 		name = "";
572 		while ((name = do_bsys_nextprop(NULL, name)) != NULL) {
573 			bop_printf(NULL, "\t0x%p %s = ", (void *)name, name);
574 			(void) do_bsys_getprop(NULL, name, value);
575 			v_len = do_bsys_getproplen(NULL, name);
576 			bop_printf(NULL, "len=%d ", v_len);
577 			value[v_len] = 0;
578 			bop_printf(NULL, "%s\n", value);
579 		}
580 	}
581 }
582 
583 /*
584  * print formatted output
585  */
586 /*PRINTFLIKE2*/
587 /*ARGSUSED*/
588 void
589 bop_printf(bootops_t *bop, char *fmt, ...)
590 {
591 	va_list	ap;
592 
593 	if (have_console == 0)
594 		return;
595 
596 	va_start(ap, fmt);
597 	(void) vsnprintf(buffer, BUFFERSIZE, fmt, ap);
598 	va_end(ap);
599 	PUT_STRING(buffer);
600 }
601 
602 /*
603  * Another panic() variant; this one can be used even earlier during boot than
604  * prom_panic().
605  */
606 /*PRINTFLIKE1*/
607 void
608 bop_panic(char *fmt, ...)
609 {
610 	va_list ap;
611 
612 	va_start(ap, fmt);
613 	bop_printf(NULL, fmt, ap);
614 	va_end(ap);
615 
616 	bop_printf(NULL, "\nPress any key to reboot.\n");
617 	(void) bcons_getchar();
618 	bop_printf(NULL, "Resetting...\n");
619 	reset();
620 }
621 
622 /*
623  * Do a real mode interrupt BIOS call
624  */
625 typedef struct bios_regs {
626 	unsigned short ax, bx, cx, dx, si, di, bp, es, ds;
627 } bios_regs_t;
628 typedef int (*bios_func_t)(int, bios_regs_t *);
629 
630 /*ARGSUSED*/
631 static void
632 do_bsys_doint(bootops_t *bop, int intnum, struct bop_regs *rp)
633 {
634 	static int firsttime = 1;
635 	bios_func_t bios_func = (bios_func_t)(void *)(uintptr_t)0x5000;
636 	bios_regs_t br;
637 
638 	/*
639 	 * The first time we do this, we have to copy the pre-packaged
640 	 * low memory bios call code image into place.
641 	 */
642 	if (firsttime) {
643 		extern char bios_image[];
644 		extern uint32_t bios_size;
645 
646 		bcopy(bios_image, (void *)bios_func, bios_size);
647 		firsttime = 0;
648 	}
649 
650 	br.ax = rp->eax.word.ax;
651 	br.bx = rp->ebx.word.bx;
652 	br.cx = rp->ecx.word.cx;
653 	br.dx = rp->edx.word.dx;
654 	br.bp = rp->ebp.word.bp;
655 	br.si = rp->esi.word.si;
656 	br.di = rp->edi.word.di;
657 	br.ds = rp->ds;
658 	br.es = rp->es;
659 
660 	DBG_MSG("Doing BIOS call...");
661 	rp->eflags = bios_func(intnum, &br);
662 	DBG_MSG("done\n");
663 
664 	rp->eax.word.ax = br.ax;
665 	rp->ebx.word.bx = br.bx;
666 	rp->ecx.word.cx = br.cx;
667 	rp->edx.word.dx = br.dx;
668 	rp->ebp.word.bp = br.bp;
669 	rp->esi.word.si = br.si;
670 	rp->edi.word.di = br.di;
671 	rp->ds = br.ds;
672 	rp->es = br.es;
673 }
674 
675 static struct boot_syscalls bop_sysp = {
676 	bcons_getchar,
677 	bcons_putchar,
678 	bcons_ischar,
679 };
680 
681 static char *whoami;
682 
683 #define	BUFLEN	64
684 
685 static void
686 setup_rarp_props(struct sol_netinfo *sip)
687 {
688 	char buf[BUFLEN];	/* to hold ip/mac addrs */
689 	uint8_t *val;
690 
691 	val = (uint8_t *)&sip->sn_ciaddr;
692 	(void) snprintf(buf, BUFLEN, "%d.%d.%d.%d",
693 	    val[0], val[1], val[2], val[3]);
694 	bsetprops(BP_HOST_IP, buf);
695 
696 	val = (uint8_t *)&sip->sn_siaddr;
697 	(void) snprintf(buf, BUFLEN, "%d.%d.%d.%d",
698 	    val[0], val[1], val[2], val[3]);
699 	bsetprops(BP_SERVER_IP, buf);
700 
701 	if (sip->sn_giaddr != 0) {
702 		val = (uint8_t *)&sip->sn_giaddr;
703 		(void) snprintf(buf, BUFLEN, "%d.%d.%d.%d",
704 		    val[0], val[1], val[2], val[3]);
705 		bsetprops(BP_ROUTER_IP, buf);
706 	}
707 
708 	if (sip->sn_netmask != 0) {
709 		val = (uint8_t *)&sip->sn_netmask;
710 		(void) snprintf(buf, BUFLEN, "%d.%d.%d.%d",
711 		    val[0], val[1], val[2], val[3]);
712 		bsetprops(BP_SUBNET_MASK, buf);
713 	}
714 
715 	if (sip->sn_mactype != 4 || sip->sn_maclen != 6) {
716 		bop_printf(NULL, "unsupported mac type %d, mac len %d\n",
717 		    sip->sn_mactype, sip->sn_maclen);
718 	} else {
719 		val = sip->sn_macaddr;
720 		(void) snprintf(buf, BUFLEN, "%x:%x:%x:%x:%x:%x",
721 		    val[0], val[1], val[2], val[3], val[4], val[5]);
722 		bsetprops(BP_BOOT_MAC, buf);
723 	}
724 }
725 
726 /*
727  * 1st pass at building the table of boot properties. This includes:
728  * - values set on the command line: -B a=x,b=y,c=z ....
729  * - known values we just compute (ie. from xbootp)
730  * - values from /boot/solaris/bootenv.rc (ie. eeprom(1m) values)
731  *
732  * the grub command line looked like:
733  * kernel boot-file [-B prop=value[,prop=value]...] [boot-args]
734  *
735  * whoami is the same as boot-file
736  */
737 static void
738 build_boot_properties(void)
739 {
740 	char *name;
741 	int name_len;
742 	char *value;
743 	int value_len;
744 	static int stdout_val = 0;
745 	struct boot_modules *bm;
746 	char *propbuf;
747 	int quoted = 0;
748 	int boot_arg_len;
749 	uchar_t boot_device;
750 	char str[3];
751 	multiboot_info_t *mbi;
752 	int netboot;
753 	struct sol_netinfo *sip;
754 
755 	/*
756 	 * These have to be done first, so that kobj_mount_root() works
757 	 */
758 	DBG_MSG("Building boot properties\n");
759 	propbuf = do_bsys_alloc(NULL, NULL, MMU_PAGESIZE, 0);
760 	DBG((uintptr_t)propbuf);
761 	if (xbootp->bi_module_cnt > 0) {
762 		bm = xbootp->bi_modules;
763 		bsetprop64("ramdisk_start", (uint64_t)(uintptr_t)bm->bm_addr);
764 		bsetprop64("ramdisk_end", (uint64_t)(uintptr_t)bm->bm_addr +
765 		    bm->bm_size);
766 	}
767 
768 	DBG_MSG("Parsing command line for boot properties\n");
769 	value = xbootp->bi_cmdline;
770 
771 	/*
772 	 * allocate memory to collect boot_args into
773 	 */
774 	boot_arg_len = strlen(xbootp->bi_cmdline) + 1;
775 	boot_args = do_bsys_alloc(NULL, NULL, boot_arg_len, MMU_PAGESIZE);
776 	boot_args[0] = 0;
777 	boot_arg_len = 0;
778 
779 	while (ISSPACE(*value))
780 		++value;
781 	/*
782 	 * value now points at the boot-file
783 	 */
784 	value_len = 0;
785 	while (value[value_len] && !ISSPACE(value[value_len]))
786 		++value_len;
787 	if (value_len > 0) {
788 		whoami = propbuf;
789 		bcopy(value, whoami, value_len);
790 		whoami[value_len] = 0;
791 		bsetprops("boot-file", whoami);
792 		/*
793 		 * strip leading path stuff from whoami, so running from
794 		 * PXE/miniroot makes sense.
795 		 */
796 		if (strstr(whoami, "/platform/") != NULL)
797 			whoami = strstr(whoami, "/platform/");
798 		bsetprops("whoami", whoami);
799 	}
800 
801 	/*
802 	 * Values forcibly set boot propertiex on the command line via -B.
803 	 * Allow use of quotes in values. Other stuff goes on kernel
804 	 * command line.
805 	 */
806 	name = value + value_len;
807 	while (*name != 0) {
808 		/*
809 		 * anything not " -B" is copied to the command line
810 		 */
811 		if (!ISSPACE(name[0]) || name[1] != '-' || name[2] != 'B') {
812 			boot_args[boot_arg_len++] = *name;
813 			boot_args[boot_arg_len] = 0;
814 			++name;
815 			continue;
816 		}
817 
818 		/*
819 		 * skip the " -B" and following white space
820 		 */
821 		name += 3;
822 		while (ISSPACE(*name))
823 			++name;
824 		while (*name && !ISSPACE(*name)) {
825 			value = strstr(name, "=");
826 			if (value == NULL)
827 				break;
828 			name_len = value - name;
829 			++value;
830 			value_len = 0;
831 			quoted = 0;
832 			for (; ; ++value_len) {
833 				if (!value[value_len])
834 					break;
835 
836 				/*
837 				 * is this value quoted?
838 				 */
839 				if (value_len == 0 &&
840 				    (value[0] == '\'' || value[0] == '"')) {
841 					quoted = value[0];
842 					++value_len;
843 				}
844 
845 				/*
846 				 * In the quote accept any character,
847 				 * but look for ending quote.
848 				 */
849 				if (quoted) {
850 					if (value[value_len] == quoted)
851 						quoted = 0;
852 					continue;
853 				}
854 
855 				/*
856 				 * a comma or white space ends the value
857 				 */
858 				if (value[value_len] == ',' ||
859 				    ISSPACE(value[value_len]))
860 					break;
861 			}
862 
863 			if (value_len == 0) {
864 				bsetprop(name, name_len, "true", 5);
865 			} else {
866 				char *v = value;
867 				int l = value_len;
868 				if (v[0] == v[l - 1] &&
869 				    (v[0] == '\'' || v[0] == '"')) {
870 					++v;
871 					l -= 2;
872 				}
873 				bcopy(v, propbuf, l);
874 				propbuf[l] = '\0';
875 				bsetprop(name, name_len, propbuf,
876 				    l + 1);
877 			}
878 			name = value + value_len;
879 			while (*name == ',')
880 				++name;
881 		}
882 	}
883 
884 	/*
885 	 * set boot-args property
886 	 */
887 	bsetprops("boot-args", boot_args);
888 
889 	/*
890 	 * set the BIOS boot device from GRUB
891 	 */
892 	netboot = 0;
893 	mbi = xbootp->bi_mb_info;
894 	if (mbi != NULL && mbi->flags & 0x2) {
895 		boot_device = mbi->boot_device >> 24;
896 		if (boot_device == 0x20)
897 			netboot++;
898 		str[0] = (boot_device >> 4) + '0';
899 		str[1] = (boot_device & 0xf) + '0';
900 		str[2] = 0;
901 		bsetprops("bios-boot-device", str);
902 	} else {
903 		netboot = 1;
904 	}
905 
906 	/*
907 	 * In the netboot case, drives_info is overloaded with the dhcp ack.
908 	 * This is not multiboot compliant and requires special pxegrub!
909 	 */
910 	if (netboot && mbi->drives_length != 0) {
911 		sip = (struct sol_netinfo *)(uintptr_t)mbi->drives_addr;
912 		if (sip->sn_infotype == SN_TYPE_BOOTP)
913 			bsetprop("bootp-response", sizeof ("bootp-response"),
914 			    (void *)(uintptr_t)mbi->drives_addr,
915 			    mbi->drives_length);
916 		else if (sip->sn_infotype == SN_TYPE_BOOTP)
917 			setup_rarp_props(sip);
918 	}
919 	bsetprop("stdout", strlen("stdout"),
920 	    &stdout_val, sizeof (stdout_val));
921 
922 	/*
923 	 * more conjured up values for made up things....
924 	 */
925 	bsetprops("mfg-name", "i86pc");
926 	bsetprops("impl-arch-name", "i86pc");
927 
928 	/*
929 	 * Build firmware-provided system properties
930 	 */
931 	build_firmware_properties();
932 
933 	/*
934 	 * Find out what these are:
935 	 * - cpuid_feature_ecx_include
936 	 * - cpuid_feature_ecx_exclude
937 	 * - cpuid_feature_edx_include
938 	 * - cpuid_feature_edx_exclude
939 	 *
940 	 * Find out what these are in multiboot:
941 	 * - bootp-response
942 	 * - netdev-path
943 	 * - fstype
944 	 */
945 }
946 
947 /*
948  * Install a temporary IDT that lets us catch errors in the boot time code.
949  * We shouldn't get any faults at all while this is installed, so we'll
950  * just generate a traceback and exit.
951  */
952 #ifdef __amd64
953 static const int bcode_sel = B64CODE_SEL;
954 #else
955 static const int bcode_sel = B32CODE_SEL;
956 #endif
957 
958 /*
959  * simple description of a stack frame (args are 32 bit only currently)
960  */
961 typedef struct bop_frame {
962 	struct bop_frame *old_frame;
963 	pc_t retaddr;
964 	long arg[1];
965 } bop_frame_t;
966 
967 void
968 bop_traceback(bop_frame_t *frame)
969 {
970 	pc_t pc;
971 	int cnt;
972 	int a;
973 	char *ksym;
974 	ulong_t off;
975 
976 	bop_printf(NULL, "Stack traceback:\n");
977 	for (cnt = 0; cnt < 30; ++cnt) {	/* up to 30 frames */
978 		pc = frame->retaddr;
979 		if (pc == 0)
980 			break;
981 		ksym = kobj_getsymname(pc, &off);
982 		if (ksym)
983 			bop_printf(NULL, "  %s+%lx", ksym, off);
984 		else
985 			bop_printf(NULL, "  0x%lx", pc);
986 
987 		frame = frame->old_frame;
988 		if (frame == 0) {
989 			bop_printf(NULL, "\n");
990 			break;
991 		}
992 		for (a = 0; a < 6; ++a) {	/* try for 6 args */
993 #if defined(__i386)
994 			if ((void *)&frame->arg[a] == (void *)frame->old_frame)
995 				break;
996 			if (a == 0)
997 				bop_printf(NULL, "(");
998 			else
999 				bop_printf(NULL, ",");
1000 			bop_printf(NULL, "0x%lx", frame->arg[a]);
1001 #endif
1002 		}
1003 		bop_printf(NULL, ")\n");
1004 	}
1005 }
1006 
1007 struct trapframe {
1008 	ulong_t frame_ptr;	/* %[er]bp pushed by our code */
1009 	ulong_t error_code;	/* optional */
1010 	ulong_t inst_ptr;
1011 	ulong_t code_seg;
1012 	ulong_t flags_reg;
1013 #ifdef __amd64
1014 	ulong_t stk_ptr;
1015 	ulong_t stk_seg;
1016 #endif
1017 };
1018 
1019 void
1020 bop_trap(struct trapframe *tf)
1021 {
1022 	bop_frame_t fakeframe;
1023 	static int depth = 0;
1024 
1025 	/*
1026 	 * Check for an infinite loop of traps. Avoid bop_printf() here to
1027 	 * reduce code path and further possibility of failure.
1028 	 */
1029 	if (++depth > 2) {
1030 		PUT_STRING("Nested trap, calling reset()\n");
1031 		reset();
1032 	}
1033 
1034 	/*
1035 	 * adjust the tf for optional error_code by detecting the code selector
1036 	 */
1037 	if (tf->code_seg != bcode_sel)
1038 		tf = (struct trapframe *)((uintptr_t)tf - sizeof (ulong_t));
1039 
1040 	bop_printf(NULL, "Unexpected trap\n");
1041 	bop_printf(NULL, "instruction pointer  0x%lx\n", tf->inst_ptr);
1042 	bop_printf(NULL, "error code, optional 0x%lx\n",
1043 	    tf->error_code & 0xffffffff);
1044 	bop_printf(NULL, "code segment         0x%lx\n", tf->code_seg & 0xffff);
1045 	bop_printf(NULL, "flags register       0x%lx\n", tf->flags_reg);
1046 #ifdef __amd64
1047 	bop_printf(NULL, "return %%rsp         0x%lx\n", tf->stk_ptr);
1048 	bop_printf(NULL, "return %%ss          0x%lx\n", tf->stk_seg & 0xffff);
1049 #endif
1050 	fakeframe.old_frame = (bop_frame_t *)tf->frame_ptr;
1051 	fakeframe.retaddr = (pc_t)tf->inst_ptr;
1052 	bop_printf(NULL, "Attempting stack backtrace:\n");
1053 	bop_traceback(&fakeframe);
1054 	bop_panic("unexpected trap in early boot");
1055 }
1056 
1057 extern void bop_trap_handler(void);
1058 
1059 static gate_desc_t bop_idt[NIDT];
1060 
1061 static desctbr_t bop_idt_info;
1062 
1063 static void
1064 bop_idt_init(void)
1065 {
1066 	int t;
1067 
1068 	bzero(&bop_idt, sizeof (bop_idt));
1069 	for (t = 0; t < NIDT; ++t) {
1070 		set_gatesegd(&bop_idt[t], &bop_trap_handler, bcode_sel,
1071 		    SDT_SYSIGT, SEL_KPL);
1072 	}
1073 	bop_idt_info.dtr_limit = sizeof (bop_idt) - 1;
1074 	bop_idt_info.dtr_base = (uintptr_t)&bop_idt;
1075 	wr_idtr(&bop_idt_info);
1076 }
1077 
1078 /*
1079  * This is where we enter the kernel. It dummies up the boot_ops and
1080  * boot_syscalls vectors and jumps off to _kobj_boot()
1081  */
1082 void
1083 _start(struct xboot_info *xbp)
1084 {
1085 	bootops_t *bops = &bootop;
1086 	extern void _kobj_boot();
1087 
1088 	/*
1089 	 * 1st off - initialize the console for any error messages
1090 	 */
1091 	xbootp = xbp;
1092 	bcons_init((void *)xbootp->bi_cmdline);
1093 	have_console = 1;
1094 
1095 	/*
1096 	 * enable debugging
1097 	 */
1098 	if (strstr((char *)xbootp->bi_cmdline, "kbm_debug"))
1099 		kbm_debug = 1;
1100 
1101 	DBG_MSG("\n\n*** Entered Solaris in _start() cmdline is: ");
1102 	DBG_MSG((char *)xbootp->bi_cmdline);
1103 	DBG_MSG("\n\n\n");
1104 
1105 	/*
1106 	 * Install an IDT to catch early pagefaults (shouldn't have any).
1107 	 * Also needed for kmdb.
1108 	 */
1109 	bop_idt_init();
1110 
1111 	/*
1112 	 * physavail is no longer used by startup
1113 	 */
1114 	bm.physinstalled = xbp->bi_phys_install;
1115 	bm.pcimem = xbp->bi_pcimem;
1116 	bm.physavail = NULL;
1117 
1118 	/*
1119 	 * initialize the boot time allocator
1120 	 */
1121 	next_phys = xbootp->bi_next_paddr;
1122 	DBG(next_phys);
1123 	next_virt = (uintptr_t)xbootp->bi_next_vaddr;
1124 	DBG(next_virt);
1125 	DBG_MSG("Initializing boot time memory management...");
1126 	kbm_init(xbootp);
1127 	DBG_MSG("done\n");
1128 
1129 	/*
1130 	 * Fill in the bootops vector
1131 	 */
1132 	bops->bsys_version = BO_VERSION;
1133 	bops->boot_mem = &bm;
1134 	bops->bsys_alloc = do_bsys_alloc;
1135 	bops->bsys_free = do_bsys_free;
1136 	bops->bsys_getproplen = do_bsys_getproplen;
1137 	bops->bsys_getprop = do_bsys_getprop;
1138 	bops->bsys_nextprop = do_bsys_nextprop;
1139 	bops->bsys_printf = bop_printf;
1140 	bops->bsys_doint = do_bsys_doint;
1141 
1142 	/*
1143 	 * BOP_EALLOC() is no longer needed
1144 	 */
1145 	bops->bsys_ealloc = do_bsys_ealloc;
1146 
1147 	/*
1148 	 *
1149 	 */
1150 	DBG_MSG("Initializing boot properties:\n");
1151 	build_boot_properties();
1152 
1153 	if (strstr((char *)xbootp->bi_cmdline, "prom_debug") || kbm_debug) {
1154 		char *name;
1155 		char *value;
1156 		int len;
1157 
1158 		value = do_bsys_alloc(NULL, NULL, MMU_PAGESIZE, MMU_PAGESIZE);
1159 		bop_printf(NULL, "\nBoot properties:\n");
1160 		name = "";
1161 		while ((name = do_bsys_nextprop(NULL, name)) != NULL) {
1162 			bop_printf(NULL, "\t0x%p %s = ", (void *)name, name);
1163 			(void) do_bsys_getprop(NULL, name, value);
1164 			len = do_bsys_getproplen(NULL, name);
1165 			bop_printf(NULL, "len=%d ", len);
1166 			value[len] = 0;
1167 			bop_printf(NULL, "%s\n", value);
1168 		}
1169 	}
1170 
1171 	/*
1172 	 * jump into krtld...
1173 	 */
1174 	_kobj_boot(&bop_sysp, NULL, bops, NULL);
1175 }
1176 
1177 
1178 /*ARGSUSED*/
1179 static caddr_t
1180 no_more_alloc(bootops_t *bop, caddr_t virthint, size_t size, int align)
1181 {
1182 	panic("Attempt to bsys_alloc() too late\n");
1183 	return (NULL);
1184 }
1185 
1186 /*ARGSUSED*/
1187 static void
1188 no_more_free(bootops_t *bop, caddr_t virt, size_t size)
1189 {
1190 	panic("Attempt to bsys_free() too late\n");
1191 }
1192 
1193 void
1194 bop_no_more_mem(void)
1195 {
1196 	DBG(total_bop_alloc_scratch);
1197 	DBG(total_bop_alloc_kernel);
1198 	bootops->bsys_alloc = no_more_alloc;
1199 	bootops->bsys_free = no_more_free;
1200 }
1201 
1202 
1203 /*
1204  * Set ACPI firmware properties
1205  */
1206 
1207 static caddr_t
1208 vmap_phys(size_t length, paddr_t pa)
1209 {
1210 	paddr_t	start, end;
1211 	caddr_t	va;
1212 	size_t	len, page;
1213 
1214 	start = P2ALIGN(pa, MMU_PAGESIZE);
1215 	end = P2ROUNDUP(pa + length, MMU_PAGESIZE);
1216 	len = end - start;
1217 	va = (caddr_t)alloc_vaddr(len, MMU_PAGESIZE);
1218 	for (page = 0; page < len; page += MMU_PAGESIZE)
1219 		kbm_map((uintptr_t)va + page, start + page, 0, 0);
1220 	return (va + (pa & MMU_PAGEOFFSET));
1221 }
1222 
1223 static uint8_t
1224 checksum_table(uint8_t *tp, size_t len)
1225 {
1226 	uint8_t sum = 0;
1227 
1228 	while (len-- > 0)
1229 		sum += *tp++;
1230 
1231 	return (sum);
1232 }
1233 
1234 static int
1235 valid_rsdp(struct rsdp *rp)
1236 {
1237 
1238 	/* validate the V1.x checksum */
1239 	if (checksum_table((uint8_t *)&rp->v1, sizeof (struct rsdp_v1)) != 0)
1240 		return (0);
1241 
1242 	/* If pre-ACPI 2.0, this is a valid RSDP */
1243 	if (rp->v1.revision < 2)
1244 		return (1);
1245 
1246 	/* validate the V2.x checksum */
1247 	if (checksum_table((uint8_t *)rp, sizeof (struct rsdp)) != 0)
1248 		return (0);
1249 
1250 	return (1);
1251 }
1252 
1253 /*
1254  * Scan memory range for an RSDP;
1255  * see ACPI 3.0 Spec, 5.2.5.1
1256  */
1257 static struct rsdp *
1258 scan_rsdp(paddr_t start, paddr_t end)
1259 {
1260 	size_t len  = end - start + 1;
1261 	caddr_t ptr;
1262 
1263 	ptr = vmap_phys(len, start);
1264 	while (len > 0) {
1265 		if (strncmp(ptr, ACPI_RSDP_SIG, ACPI_RSDP_SIG_LEN) == 0)
1266 			if (valid_rsdp((struct rsdp *)ptr))
1267 				return ((struct rsdp *)ptr);
1268 		ptr += 16;
1269 		len -= 16;
1270 	}
1271 
1272 	return (NULL);
1273 }
1274 
1275 /*
1276  * Refer to ACPI 3.0 Spec, section 5.2.5.1 to understand this function
1277  */
1278 static struct rsdp *
1279 find_rsdp() {
1280 	struct rsdp *rsdp;
1281 	uint16_t *ebda_seg;
1282 	paddr_t  ebda_addr;
1283 
1284 	/*
1285 	 * Get the EBDA segment and scan the first 1K
1286 	 */
1287 	ebda_seg = (uint16_t *)vmap_phys(sizeof (uint16_t), ACPI_EBDA_SEG_ADDR);
1288 	ebda_addr = *ebda_seg << 4;
1289 	rsdp = scan_rsdp(ebda_addr, ebda_addr + ACPI_EBDA_LEN - 1);
1290 	if (rsdp == NULL)
1291 		/* if EBDA doesn't contain RSDP, look in BIOS memory */
1292 		rsdp = scan_rsdp(0xe0000, 0xfffff);
1293 	return (rsdp);
1294 }
1295 
1296 static struct table_header *
1297 map_fw_table(paddr_t table_addr)
1298 {
1299 	struct table_header *tp;
1300 	size_t len = MAX(sizeof (struct table_header), MMU_PAGESIZE);
1301 
1302 	/*
1303 	 * Map at least a page; if the table is larger than this, remap it
1304 	 */
1305 	tp = (struct table_header *)vmap_phys(len, table_addr);
1306 	if (tp->len > len)
1307 		tp = (struct table_header *)vmap_phys(tp->len, table_addr);
1308 	return (tp);
1309 }
1310 
1311 static struct table_header *
1312 find_fw_table(char *signature)
1313 {
1314 	static int revision = 0;
1315 	static struct xsdt *xsdt;
1316 	static int len;
1317 	paddr_t xsdt_addr;
1318 	struct rsdp *rsdp;
1319 	struct table_header *tp;
1320 	paddr_t table_addr;
1321 	int	n;
1322 
1323 	if (strlen(signature) != ACPI_TABLE_SIG_LEN)
1324 		return (NULL);
1325 
1326 	/*
1327 	 * Reading the ACPI 3.0 Spec, section 5.2.5.3 will help
1328 	 * understand this code.  If we haven't already found the RSDT/XSDT,
1329 	 * revision will be 0. Find the RSDP and check the revision
1330 	 * to find out whether to use the RSDT or XSDT.  If revision is
1331 	 * 0 or 1, use the RSDT and set internal revision to 1; if it is 2,
1332 	 * use the XSDT.  If the XSDT address is 0, though, fall back to
1333 	 * revision 1 and use the RSDT.
1334 	 */
1335 	if (revision == 0) {
1336 		if ((rsdp = (struct rsdp *)find_rsdp()) != NULL) {
1337 			revision = rsdp->v1.revision;
1338 			switch (revision) {
1339 			case 2:
1340 				/*
1341 				 * Use the XSDT unless BIOS is buggy and
1342 				 * claims to be rev 2 but has a null XSDT
1343 				 * address
1344 				 */
1345 				xsdt_addr = rsdp->xsdt;
1346 				if (xsdt_addr != 0)
1347 					break;
1348 				/* FALLTHROUGH */
1349 			case 0:
1350 				/* treat RSDP rev 0 as revision 1 internally */
1351 				revision = 1;
1352 				/* FALLTHROUGH */
1353 			case 1:
1354 				/* use the RSDT for rev 0/1 */
1355 				xsdt_addr = rsdp->v1.rsdt;
1356 				break;
1357 			default:
1358 				/* unknown revision */
1359 				revision = 0;
1360 				break;
1361 			}
1362 		}
1363 		if (revision == 0)
1364 			return (NULL);
1365 
1366 		/* cache the XSDT info */
1367 		xsdt = (struct xsdt *)map_fw_table(xsdt_addr);
1368 		len = (xsdt->hdr.len - sizeof (xsdt->hdr)) /
1369 		    ((revision == 1) ? sizeof (uint32_t) : sizeof (uint64_t));
1370 	}
1371 
1372 	/*
1373 	 * Scan the table headers looking for a signature match
1374 	 */
1375 	for (n = 0; n < len; n++) {
1376 		table_addr = (revision == 1) ? xsdt->p.r[n] : xsdt->p.x[n];
1377 		if (table_addr == 0)
1378 			continue;
1379 		tp = map_fw_table(table_addr);
1380 		if (strncmp(tp->sig, signature, ACPI_TABLE_SIG_LEN) == 0) {
1381 			return (tp);
1382 		}
1383 	}
1384 	return (NULL);
1385 }
1386 
1387 static void
1388 process_madt(struct madt *tp)
1389 {
1390 	struct madt_processor *cpu, *end;
1391 	uint32_t cpu_count = 0;
1392 
1393 	/*
1394 	 * User-set boot-ncpus overrides firmware count
1395 	 */
1396 	if (do_bsys_getproplen(NULL, "boot-ncpus") >= 0)
1397 		return;
1398 
1399 	if (tp != NULL) {
1400 		end = (struct madt_processor *)(tp->hdr.len + (uintptr_t)tp);
1401 		cpu = tp->list;
1402 		while (cpu < end) {
1403 			if (cpu->type == MADT_PROCESSOR)
1404 				if (cpu->flags & 1)
1405 					cpu_count++;
1406 
1407 			cpu = (struct madt_processor *)
1408 			    (cpu->len + (uintptr_t)cpu);
1409 		}
1410 		bsetpropsi("boot-ncpus", cpu_count);
1411 	}
1412 
1413 }
1414 
1415 static void
1416 process_srat(struct srat *tp)
1417 {
1418 	struct srat_item *item, *end;
1419 	int i;
1420 	int proc_num, mem_num;
1421 #pragma pack(1)
1422 	struct {
1423 		uint32_t domain;
1424 		uint32_t apic_id;
1425 		uint32_t sapic_id;
1426 	} processor;
1427 	struct {
1428 		uint32_t domain;
1429 		uint64_t addr;
1430 		uint64_t length;
1431 		uint32_t flags;
1432 	} memory;
1433 #pragma pack()
1434 	char prop_name[30];
1435 
1436 	if (tp == NULL)
1437 		return;
1438 
1439 	proc_num = mem_num = 0;
1440 	end = (struct srat_item *)(tp->hdr.len + (uintptr_t)tp);
1441 	item = tp->list;
1442 	while (item < end) {
1443 		switch (item->type) {
1444 		case SRAT_PROCESSOR:
1445 			if (!(item->i.p.flags & SRAT_ENABLED))
1446 				break;
1447 			processor.domain = item->i.p.domain1;
1448 			for (i = 0; i < 3; i++)
1449 				processor.domain +=
1450 				    item->i.p.domain2[i] << ((i + 1) * 8);
1451 			processor.apic_id = item->i.p.apic_id;
1452 			processor.sapic_id = item->i.p.local_sapic_eid;
1453 			(void) snprintf(prop_name, 30, "acpi-srat-processor-%d",
1454 			    proc_num);
1455 			bsetprop(prop_name, strlen(prop_name), &processor,
1456 			    sizeof (processor));
1457 			proc_num++;
1458 			break;
1459 		case SRAT_MEMORY:
1460 			if (!(item->i.m.flags & SRAT_ENABLED))
1461 				break;
1462 			memory.domain = item->i.m.domain;
1463 			memory.addr = item->i.m.base_addr;
1464 			memory.length = item->i.m.len;
1465 			memory.flags = item->i.m.flags;
1466 			(void) snprintf(prop_name, 30, "acpi-srat-memory-%d",
1467 			    mem_num);
1468 			bsetprop(prop_name, strlen(prop_name), &memory,
1469 			    sizeof (memory));
1470 			mem_num++;
1471 			break;
1472 		}
1473 
1474 		item = (struct srat_item *)
1475 		    (item->len + (caddr_t)item);
1476 	}
1477 }
1478 
1479 static void
1480 process_slit(struct slit *tp)
1481 {
1482 
1483 	/*
1484 	 * Check the number of localities; if it's too huge, we just
1485 	 * return and locality enumeration code will handle this later,
1486 	 * if possible.
1487 	 *
1488 	 * Note that the size of the table is the square of the
1489 	 * number of localities; if the number of localities exceeds
1490 	 * UINT16_MAX, the table size may overflow an int when being
1491 	 * passed to bsetprop() below.
1492 	 */
1493 	if (tp->number >= SLIT_LOCALITIES_MAX)
1494 		return;
1495 
1496 	bsetprop(SLIT_NUM_PROPNAME, strlen(SLIT_NUM_PROPNAME), &tp->number,
1497 	    sizeof (tp->number));
1498 	bsetprop(SLIT_PROPNAME, strlen(SLIT_PROPNAME), &tp->entry,
1499 	    tp->number * tp->number);
1500 }
1501 
1502 static void
1503 build_firmware_properties(void)
1504 {
1505 	struct table_header *tp;
1506 
1507 	if (tp = find_fw_table("APIC"))
1508 		process_madt((struct madt *)tp);
1509 
1510 	if (tp = find_fw_table("SRAT"))
1511 		process_srat((struct srat *)tp);
1512 
1513 	if (tp = find_fw_table("SLIT"))
1514 		process_slit((struct slit *)tp);
1515 }
1516 
1517 /*
1518  * fake up a boot property for USB serial console early boot output
1519  */
1520 void *
1521 usbser_init(size_t size)
1522 {
1523 	static char *p = NULL;
1524 
1525 	p = do_bsys_alloc(NULL, NULL, size, MMU_PAGESIZE);
1526 	*p = 0;
1527 	bsetprop("usb-serial-buf", strlen("usb-serial-buf") + 1,
1528 	    &p, sizeof (p));
1529 	return (p);
1530 }
1531