#include <sys/param.h>
#include <sys/systm.h>
#include <sys/buf.h>
#include <sys/disklabel.h>
#include <sys/conf.h>
#include <sys/reboot.h>
#include <sys/device.h>
#include <uvm/uvm_extern.h>
#include <machine/autoconf.h>
#include <machine/rpb.h>
#include <machine/prom.h>
#include <machine/cpuconf.h>
#include <machine/intr.h>
#include <dev/cons.h>
struct device *booted_device;
int booted_partition;
struct bootdev_data *bootdev_data;
char boot_dev[128];
void parse_prom_bootdev(void);
int atoi(char *);
void
unmap_startup(void)
{
extern uint32_t kernel_text[], endboot[];
uint32_t *word = kernel_text;
while (word < endboot)
*word++ = 0x00000000;
}
void
cpu_configure(void)
{
parse_prom_bootdev();
softintr_init();
unmap_startup();
(void)alpha_pal_swpipl(ALPHA_PSL_IPL_HIGH);
if (config_rootfound("mainbus", "mainbus") == NULL)
panic("no mainbus found");
(void)spl0();
hwrpb_restart_setup();
cold = 0;
}
void
diskconf(void)
{
struct device *bootdv;
int bootpartition;
if (booted_device == NULL)
printf("WARNING: can't figure what device matches \"%s\"\n",
boot_dev);
bootdv = booted_device;
bootpartition = booted_partition;
setroot(bootdv, bootpartition, RB_USERREQ);
dumpconf();
}
void
parse_prom_bootdev(void)
{
static struct bootdev_data bd;
char *cp, *scp, *boot_fields[8];
int i, done;
booted_device = NULL;
booted_partition = 0;
bootdev_data = NULL;
bcopy(bootinfo.booted_dev, boot_dev, sizeof bootinfo.booted_dev);
#if 0
printf("parse_prom_bootdev: boot dev = \"%s\"\n", boot_dev);
#endif
i = 0;
scp = cp = boot_dev;
for (done = 0; !done; cp++) {
if (*cp != ' ' && *cp != '\0')
continue;
if (*cp == '\0')
done = 1;
*cp = '\0';
boot_fields[i++] = scp;
scp = cp + 1;
if (i == 8)
done = 1;
}
if (i != 8)
return;
#if 0
printf("i = %d, done = %d\n", i, done);
for (i--; i >= 0; i--)
printf("%d = %s\n", i, boot_fields[i]);
#endif
bd.protocol = boot_fields[0];
bd.bus = atoi(boot_fields[1]);
bd.slot = atoi(boot_fields[2]);
bd.channel = atoi(boot_fields[3]);
bd.remote_address = boot_fields[4];
bd.unit = atoi(boot_fields[5]);
bd.boot_dev_type = atoi(boot_fields[6]);
bd.ctrl_dev_type = boot_fields[7];
#if 0
printf("parsed: proto = %s, bus = %d, slot = %d, channel = %d,\n",
bd.protocol, bd.bus, bd.slot, bd.channel);
printf("\tremote = %s, unit = %d, dev_type = %d, ctrl_type = %s\n",
bd.remote_address, bd.unit, bd.boot_dev_type, bd.ctrl_dev_type);
#endif
bootdev_data = &bd;
}
int
atoi(char *s)
{
int n, neg;
n = 0;
neg = 0;
while (*s == '-') {
s++;
neg = !neg;
}
while (*s != '\0') {
if (*s < '0' || *s > '9')
break;
n = (10 * n) + (*s - '0');
s++;
}
return (neg ? -n : n);
}
void
device_register(struct device *dev, void *aux)
{
if (bootdev_data == NULL) {
return;
}
if (platform.device_register)
(*platform.device_register)(dev, aux);
}
const struct nam2blk nam2blk[] = {
{ "wd", 0 },
{ "cd", 3 },
{ "fd", 4 },
{ "rd", 6 },
{ "sd", 8 },
{ "vnd", 9 },
{ NULL, -1 }
};