Changeset View
Changeset View
Standalone View
Standalone View
sys/amd64/amd64/machdep.c
Show First 20 Lines • Show All 1,506 Lines • ▼ Show 20 Lines | |||||
{ | { | ||||
kdb_init(); | kdb_init(); | ||||
#ifdef KDB | #ifdef KDB | ||||
if (boothowto & RB_KDB) | if (boothowto & RB_KDB) | ||||
kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger"); | kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger"); | ||||
#endif | #endif | ||||
} | } | ||||
/* Set up the fast syscall stuff */ | |||||
void | |||||
amd64_conf_fast_syscall(void) | |||||
{ | |||||
uint64_t msr; | |||||
msr = rdmsr(MSR_EFER) | EFER_SCE; | |||||
wrmsr(MSR_EFER, msr); | |||||
wrmsr(MSR_LSTAR, (u_int64_t)IDTVEC(fast_syscall)); | |||||
wrmsr(MSR_CSTAR, (u_int64_t)IDTVEC(fast_syscall32)); | |||||
msr = ((u_int64_t)GSEL(GCODE_SEL, SEL_KPL) << 32) | | |||||
((u_int64_t)GSEL(GUCODE32_SEL, SEL_UPL) << 48); | |||||
wrmsr(MSR_STAR, msr); | |||||
wrmsr(MSR_SF_MASK, PSL_NT | PSL_T | PSL_I | PSL_C | PSL_D | PSL_AC); | |||||
} | |||||
u_int64_t | u_int64_t | ||||
hammer_time(u_int64_t modulep, u_int64_t physfree) | hammer_time(u_int64_t modulep, u_int64_t physfree) | ||||
{ | { | ||||
caddr_t kmdp; | caddr_t kmdp; | ||||
int gsel_tss, x; | int gsel_tss, x; | ||||
struct pcpu *pc; | struct pcpu *pc; | ||||
struct nmi_pcpu *np; | struct nmi_pcpu *np; | ||||
struct xstate_hdr *xhdr; | struct xstate_hdr *xhdr; | ||||
u_int64_t msr; | |||||
char *env; | char *env; | ||||
size_t kstack0_sz; | size_t kstack0_sz; | ||||
int late_console; | int late_console; | ||||
TSRAW(&thread0, TS_ENTER, __func__, NULL); | TSRAW(&thread0, TS_ENTER, __func__, NULL); | ||||
/* | /* | ||||
* This may be done better later if it gets more high level | * This may be done better later if it gets more high level | ||||
* components in it. If so just link td->td_proc here. | * components in it. If so just link td->td_proc here. | ||||
*/ | */ | ||||
proc_linkup0(&proc0, &thread0); | proc_linkup0(&proc0, &thread0); | ||||
kmdp = init_ops.parse_preload_data(modulep); | kmdp = init_ops.parse_preload_data(modulep); | ||||
identify_cpu1(); | identify_cpu1(); | ||||
identify_hypervisor(); | identify_hypervisor(); | ||||
/* link_elf_ireloc(kmdp); */ | |||||
/* Init basic tunables, hz etc */ | /* Init basic tunables, hz etc */ | ||||
init_param1(); | init_param1(); | ||||
thread0.td_kstack = physfree + KERNBASE; | thread0.td_kstack = physfree + KERNBASE; | ||||
thread0.td_kstack_pages = kstack_pages; | thread0.td_kstack_pages = kstack_pages; | ||||
kstack0_sz = thread0.td_kstack_pages * PAGE_SIZE; | kstack0_sz = thread0.td_kstack_pages * PAGE_SIZE; | ||||
bzero((void *)thread0.td_kstack, kstack0_sz); | bzero((void *)thread0.td_kstack, kstack0_sz); | ||||
physfree += kstack0_sz; | physfree += kstack0_sz; | ||||
▲ Show 20 Lines • Show All 109 Lines • ▼ Show 20 Lines | #endif | ||||
common_tss[0].tss_ist2 = (long) np; | common_tss[0].tss_ist2 = (long) np; | ||||
/* Set the IO permission bitmap (empty due to tss seg limit) */ | /* Set the IO permission bitmap (empty due to tss seg limit) */ | ||||
common_tss[0].tss_iobase = sizeof(struct amd64tss) + IOPERM_BITMAP_SIZE; | common_tss[0].tss_iobase = sizeof(struct amd64tss) + IOPERM_BITMAP_SIZE; | ||||
gsel_tss = GSEL(GPROC0_SEL, SEL_KPL); | gsel_tss = GSEL(GPROC0_SEL, SEL_KPL); | ||||
ltr(gsel_tss); | ltr(gsel_tss); | ||||
/* Set up the fast syscall stuff */ | amd64_conf_fast_syscall(); | ||||
msr = rdmsr(MSR_EFER) | EFER_SCE; | |||||
wrmsr(MSR_EFER, msr); | |||||
wrmsr(MSR_LSTAR, (u_int64_t)IDTVEC(fast_syscall)); | |||||
wrmsr(MSR_CSTAR, (u_int64_t)IDTVEC(fast_syscall32)); | |||||
msr = ((u_int64_t)GSEL(GCODE_SEL, SEL_KPL) << 32) | | |||||
((u_int64_t)GSEL(GUCODE32_SEL, SEL_UPL) << 48); | |||||
wrmsr(MSR_STAR, msr); | |||||
wrmsr(MSR_SF_MASK, PSL_NT|PSL_T|PSL_I|PSL_C|PSL_D); | |||||
/* | /* | ||||
* Temporary forge some valid pointer to PCB, for exception | * Temporary forge some valid pointer to PCB, for exception | ||||
* handlers. It is reinitialized properly below after FPU is | * handlers. It is reinitialized properly below after FPU is | ||||
* set up. Also set up td_critnest to short-cut the page | * set up. Also set up td_critnest to short-cut the page | ||||
* fault handler. | * fault handler. | ||||
*/ | */ | ||||
cpu_max_ext_state_size = sizeof(struct savefpu); | cpu_max_ext_state_size = sizeof(struct savefpu); | ||||
thread0.td_pcb = get_pcb_td(&thread0); | thread0.td_pcb = get_pcb_td(&thread0); | ||||
thread0.td_critnest = 1; | thread0.td_critnest = 1; | ||||
/* | /* | ||||
* The console and kdb should be initialized even earlier than here, | * The console and kdb should be initialized even earlier than here, | ||||
* but some console drivers don't work until after getmemsize(). | * but some console drivers don't work until after getmemsize(). | ||||
* Default to late console initialization to support these drivers. | * Default to late console initialization to support these drivers. | ||||
* This loses mainly printf()s in getmemsize() and early debugging. | * This loses mainly printf()s in getmemsize() and early debugging. | ||||
*/ | */ | ||||
late_console = 1; | late_console = 1; | ||||
TUNABLE_INT_FETCH("debug.late_console", &late_console); | TUNABLE_INT_FETCH("debug.late_console", &late_console); | ||||
if (!late_console) { | if (!late_console) { | ||||
cninit(); | cninit(); | ||||
amd64_kdb_init(); | amd64_kdb_init(); | ||||
} | } | ||||
link_elf_ireloc(kmdp); | |||||
getmemsize(kmdp, physfree); | getmemsize(kmdp, physfree); | ||||
init_param2(physmem); | init_param2(physmem); | ||||
/* now running on new page tables, configured,and u/iom is accessible */ | /* now running on new page tables, configured,and u/iom is accessible */ | ||||
if (late_console) | if (late_console) | ||||
cninit(); | cninit(); | ||||
▲ Show 20 Lines • Show All 866 Lines • Show Last 20 Lines |