#include <sys/param.h>
#include <sys/systm.h>
#include <sys/proc.h>
#include <sys/user.h>
#include <sys/reboot.h>
#include <sys/device.h>
#include <sys/hibernate.h>
#include <sys/disklabel.h>
#include <net/if.h>
#include <net/if_types.h>
#include <netinet/in.h>
#include <netinet/if_ether.h>
#include <uvm/uvm_extern.h>
#include <machine/gdt.h>
#include <machine/biosvar.h>
#include "ioapic.h"
#include "acpi.h"
#if NIOAPIC > 0
#include <machine/i82093var.h>
#endif
#ifdef MULTIPROCESSOR
#include <machine/mpbiosvar.h>
#endif
extern dev_t bootdev;
extern struct timeout viac3_rnd_tmo;
extern int viac3_rnd_present;
void viac3_rnd(void *);
extern struct timeout rdrand_tmo;
extern int has_rdrand;
extern int has_rdseed;
void rdrand(void *);
#ifdef CRYPTO
void viac3_crypto_setup(void);
extern int i386_has_xcrypt;
#endif
void
unmap_startup(void)
{
extern int kernel_text[], endboot[];
vaddr_t p = (vaddr_t)kernel_text;
do {
pmap_kremove(p, PAGE_SIZE);
p += PAGE_SIZE;
} while (p < (vaddr_t)endboot);
}
void
cpu_configure(void)
{
gdt_init();
i386_proc0_tss_init();
pmap_bootstrap_pae();
#if defined(MULTIPROCESSOR) || \
(NACPI > 0 && !defined(SMALL_KERNEL))
pmap_prealloc_lowmem_ptp();
#endif
#ifdef MULTIPROCESSOR
pmap_kenter_pa((vaddr_t)MP_TRAMPOLINE,
(paddr_t)MP_TRAMPOLINE,
PROT_READ | PROT_WRITE | PROT_EXEC);
pmap_kenter_pa((vaddr_t)MP_TRAMP_DATA,
(paddr_t)MP_TRAMP_DATA,
PROT_READ | PROT_WRITE);
#endif
if (config_rootfound("mainbus", NULL) == NULL)
panic("cpu_configure: mainbus not configured");
#if NIOAPIC > 0
ioapic_enable();
#endif
proc0.p_addr->u_pcb.pcb_cr0 = rcr0();
unmap_startup();
#ifdef MULTIPROCESSOR
cpu_init_idle_pcbs();
#endif
spl0();
cold = 0;
if (viac3_rnd_present) {
timeout_set(&viac3_rnd_tmo, viac3_rnd, &viac3_rnd_tmo);
viac3_rnd(&viac3_rnd_tmo);
}
if (has_rdrand || has_rdseed) {
timeout_set(&rdrand_tmo, rdrand, &rdrand_tmo);
rdrand(&rdrand_tmo);
}
#ifdef CRYPTO
if (i386_has_xcrypt)
viac3_crypto_setup();
#endif
}
void
device_register(struct device *dev, void *aux)
{
}
void
diskconf(void)
{
int majdev, unit, part = 0;
struct device *bootdv = NULL;
dev_t tmpdev;
char buf[128];
extern bios_bootmac_t *bios_bootmac;
dkcsumattach();
if ((bootdev & B_MAGICMASK) == (u_int)B_DEVMAGIC) {
majdev = B_TYPE(bootdev);
unit = B_UNIT(bootdev);
part = B_PARTITION(bootdev);
snprintf(buf, sizeof buf, "%s%d%c", findblkname(majdev),
unit, DL_PARTNUM2NAME(part));
bootdv = parsedisk(buf, strlen(buf), part, &tmpdev);
}
if (bios_bootmac) {
struct ifnet *ifp;
TAILQ_FOREACH(ifp, &ifnetlist, if_list) {
if (ifp->if_type == IFT_ETHER &&
memcmp(bios_bootmac->mac,
((struct arpcom *)ifp)->ac_enaddr,
ETHER_ADDR_LEN) == 0)
break;
}
if (ifp) {
printf("PXE boot MAC address %s, interface %s\n",
ether_sprintf(bios_bootmac->mac), ifp->if_xname);
#if defined(NFSCLIENT)
bootdv = parsedisk(ifp->if_xname, strlen(ifp->if_xname),
0, &tmpdev);
part = 0;
#endif
} else
printf("PXE boot MAC address %s, interface %s\n",
ether_sprintf(bios_bootmac->mac), "unknown");
}
setroot(bootdv, part, RB_USERREQ);
dumpconf();
#ifdef HIBERNATE
hibernate_resume();
#endif
}
const struct nam2blk nam2blk[] = {
{ "wd", 0 },
{ "fd", 2 },
{ "sd", 4 },
{ "cd", 6 },
{ "vnd", 14 },
{ "rd", 17 },
{ NULL, -1 }
};