#include <sys/param.h>
#include <sys/systm.h>
#include <sys/buf.h>
#include <sys/reboot.h>
#include <sys/conf.h>
#include <sys/device.h>
#include <sys/disklabel.h>
#include <sys/kernel.h>
#include <uvm/uvm.h>
#include <machine/asm_macro.h>
#include <machine/autoconf.h>
#include <machine/cpu.h>
#include <machine/vmparam.h>
#include <scsi/scsi_all.h>
#include <scsi/scsiconf.h>
#include <dev/cons.h>
void dumpconf(void);
void get_autoboot_device(void);
int cold = 1;
dev_t bootdev;
struct device *bootdv;
void
cpu_configure()
{
softintr_init();
if (config_rootfound("mainbus", "mainbus") == 0)
panic("no mainbus found");
set_vbr(kernel_vbr);
pmap_unmap_firmware();
cold = 0;
set_psr(get_psr() & ~PSR_IND);
spl0();
}
void
diskconf(void)
{
printf("boot device: %s\n",
(bootdv) ? bootdv->dv_xname : "<unknown>");
setroot(bootdv, 0, RB_USERREQ);
dumpconf();
}
struct autoboot_t {
char cont[16];
int targ;
int part;
} autoboot;
void
get_autoboot_device(void)
{
char *value, c;
int i, len, part;
extern char *nvram_by_symbol(char *);
if ((bootdev & B_MAGICMASK) == B_DEVMAGIC) {
#ifdef DEBUG
printf("bootdev = 0x%08x (t:%d, a:%d, c:%d, u:%d, p:%d)\n",
bootdev, B_TYPE(bootdev), B_ADAPTOR(bootdev),
B_CONTROLLER(bootdev), B_UNIT(bootdev),
B_PARTITION(bootdev));
#endif
switch (B_TYPE(bootdev)) {
case 0:
snprintf(autoboot.cont, sizeof(autoboot.cont),
"spc%d", B_CONTROLLER(bootdev));
break;
#if 0
case 1:
snprintf(autoboot.cont, sizeof(autoboot.cont),
"le%d", B_CONTROLLER(bootdev));
break;
#endif
default:
goto use_nvram_info;
}
autoboot.targ = B_UNIT(bootdev);
autoboot.part = B_PARTITION(bootdev);
return;
}
use_nvram_info:
printf("%s: no bootdev information, use NVRAM setting\n", __func__);
strlcpy(autoboot.cont, "spc0", sizeof(autoboot.cont));
value = nvram_by_symbol("boot_unit");
if (value != NULL) {
len = strlen(value);
if (len == 1) {
c = value[0];
} else if (len == 2 && value[0] == '1') {
strlcpy(autoboot.cont, "spc1", sizeof(autoboot.cont));
c = value[1];
} else
c = -1;
if ((c >= '0') && (c <= '6'))
autoboot.targ = 6 - (c - '0');
}
value = nvram_by_symbol("boot_partition");
if (value != NULL) {
len = strlen(value);
part = 0;
for (i = 0; i < len; i++)
part = part * 10 + (value[i] - '0');
autoboot.part = part;
}
}
void
device_register(struct device *dev, void *aux)
{
if (strcmp("sd", dev->dv_cfdata->cf_driver->cd_name) == 0 ||
strcmp("cd", dev->dv_cfdata->cf_driver->cd_name) == 0) {
struct scsi_attach_args *sa = aux;
struct device *spcsc;
spcsc = dev->dv_parent->dv_parent;
if (strcmp(spcsc->dv_xname, autoboot.cont) == 0 &&
sa->sa_sc_link->target == autoboot.targ &&
sa->sa_sc_link->lun == 0) {
bootdv = dev;
return;
}
}
}
const struct nam2blk nam2blk[] = {
{ "sd", 4 },
{ "cd", 6 },
{ "rd", 7 },
{ "vnd", 8 },
{ "wd", 9 },
{ NULL, -1 }
};