2 * Copyright (c) 1998 Michael Smith <msmith@freebsd.org>
3 * Copyright (c) 1998 Doug Rabson <dfr@freebsd.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $FreeBSD: src/sys/boot/alpha/common/main.c,v 1.11.2.2 2001/03/04 05:14:50 obrien Exp $
28 * $DragonFly: src/sys/boot/alpha/common/Attic/main.c,v 1.2 2003/06/17 04:28:16 dillon Exp $
35 #include <sys/param.h>
36 #include <machine/rpb.h>
37 #include <machine/prom.h>
38 #include "bootstrap.h"
39 #include "libalpha/libalpha.h"
41 extern char bootprog_name[], bootprog_rev[], bootprog_date[], bootprog_maker[];
43 struct alpha_devdesc currdev; /* our current device */
44 struct arch_switch archsw; /* MI/MD interface boundary */
47 extern void OSFpal(void);
48 extern void halt(void);
53 struct rpb *hwrpb = (struct rpb *)HWRPB_ADDR;
55 struct mddt_cluster *memc;
57 unsigned long total = 0;
59 mddtp = (struct mddt *)(((caddr_t)hwrpb) + hwrpb->rpb_memdat_off);
60 for (i = 0; i < mddtp->mddt_cluster_cnt; i++) {
61 memc = &mddtp->mddt_clusters[i];
62 total += memc->mddt_pg_cnt << PAGE_SHIFT;
67 /* #define XTRA_PAGES 32 */
73 struct rpb *hwrpb = (struct rpb *)HWRPB_ADDR;
75 struct mddt_cluster *memc = 0;
77 unsigned long startpfn;
82 * Find the last usable memory cluster and add some of its pages
83 * to our address space. The 256k allowed by the firmware isn't quite
84 * adequate for our needs.
86 mddtp = (struct mddt *)(((caddr_t)hwrpb) + hwrpb->rpb_memdat_off);
87 for (i = mddtp->mddt_cluster_cnt - 1; i >= 0; i--) {
88 memc = &mddtp->mddt_clusters[i];
89 if (!(memc->mddt_usage & (MDDT_NONVOLATILE | MDDT_PALCODE)))
94 * We want to extend the heap from 256k up to XTRA_PAGES more pages.
95 * We take pages from the end of the last usable memory region,
96 * taking care to avoid the memory used by the kernel's message
97 * buffer. We allow 4 pages for the message buffer.
99 startpfn = memc->mddt_pfn + memc->mddt_pg_cnt - 4 - XTRA_PAGES;
100 startva = 0x20040000;
101 startpte = 0x40000000
102 + (((startva >> 23) & 0x3ff) << PAGE_SHIFT)
103 + (((startva >> 13) & 0x3ff) << 3);
105 for (i = 0; i < XTRA_PAGES; i++) {
107 pte = ((startpfn + i) << 32) | 0x1101;
108 *(u_int64_t *) (startpte + 8 * i) = pte;
119 * Initialise the heap as early as possible. Once this is done,
120 * alloc() is usable. The stack is buried inside us, so this is
123 setheap((void *)end, (void *)(0x20040000 + XTRA_PAGES * 8192));
127 * If this is the two stage disk loader, add the memory used by
128 * the first stage to the heap.
130 free_region((void *)PRIMARY_LOAD_ADDRESS,
131 (void *)SECONDARY_LOAD_ADDRESS);
135 * XXX Chicken-and-egg problem; we want to have console output
136 * early, but some console attributes may depend on reading from
137 * eg. the boot device, which we can't do yet. We can use
138 * printf() etc. once this is done.
142 /* switch to OSF pal code. */
146 * Initialise the block cache
148 bcache_init(32, 512); /* 16k XXX tune this */
151 * March through the device switch probing for things.
153 for (i = 0; devsw[i] != NULL; i++)
154 if (devsw[i]->dv_init != NULL)
155 (devsw[i]->dv_init)();
158 printf("%s, Revision %s\n", bootprog_name, bootprog_rev);
159 printf("(%s, %s)\n", bootprog_maker, bootprog_date);
160 printf("Memory: %ld k\n", memsize() / 1024);
162 /* We're booting from an SRM disk, try to spiff this */
163 currdev.d_dev = devsw[0]; /* XXX presumes that biosdisk is first in devsw */
164 currdev.d_type = currdev.d_dev->dv_type;
165 currdev.d_kind.srmdisk.unit = 0;
166 currdev.d_kind.srmdisk.slice = -1; /* XXX should be able to detect this, default to autoprobe */
167 currdev.d_kind.srmdisk.partition = 0; /* default to 'a' */
169 /* Create alpha-specific variables */
170 prom_getenv(PROM_E_BOOTED_FILE, bootfile, sizeof(bootfile));
172 setenv("bootfile", bootfile, 1);
173 env_setenv("currdev", EV_VOLATILE, alpha_fmtdev(&currdev), alpha_setcurrdev, env_nounset);
174 env_setenv("loaddev", EV_VOLATILE, alpha_fmtdev(&currdev), env_noset, env_nounset);
175 setenv("LINES", "24", 1); /* optional */
177 archsw.arch_autoload = alpha_autoload;
178 archsw.arch_getdev = alpha_getdev;
179 archsw.arch_copyin = alpha_copyin;
180 archsw.arch_copyout = alpha_copyout;
181 archsw.arch_readin = alpha_readin;
184 * SRM firmware takes *ages* to open the disk device. We hold it
185 * open until the closeall() when we exec the kernel. Note that
186 * we must close it eventually since otherwise the firmware leaves
187 * the ncr hardware in a broken state (at least it does on my EB164).
189 open("/boot", O_RDONLY);
191 interact(); /* doesn't return */
196 COMMAND_SET(reboot, "reboot", "reboot the system", command_reboot);
199 command_reboot(int argc, char *argv[])
202 printf("Rebooting...\n");
205 /* Note: we shouldn't get to this point! */
206 panic("Reboot failed!");
210 COMMAND_SET(halt, "halt", "halt the system", command_halt);
213 command_halt(int argc, char *argv[])
215 halt(); /* never returns */
221 COMMAND_SET(stack, "stack", "show stack usage", command_stack);
224 command_stack(int argc, char *argv[])
228 for (cp = &stackbase; cp < &stacktop; cp++)
232 printf("%d bytes of stack used\n", &stacktop - cp);
238 COMMAND_SET(heap, "heap", "show heap usage", command_heap);
241 command_heap(int argc, char *argv[])
243 printf("heap base at %p, top at %p, used %ld\n", end, sbrk(0), sbrk(0) - end);