X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/4452a7af2eac33dbad800bcc91f2399d62c18f53..3e170ce000f1506b7b5d2c5c7faec85ceabb573d:/osfmk/i386/startup64.c diff --git a/osfmk/i386/startup64.c b/osfmk/i386/startup64.c index 29d21fac8..ddf892451 100644 --- a/osfmk/i386/startup64.c +++ b/osfmk/i386/startup64.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2006 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2006-2012 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -34,7 +34,6 @@ #include #include -#include #include #include @@ -57,7 +56,6 @@ #include #include #include -#include #include #include @@ -66,129 +64,13 @@ #include -void -cpu_IA32e_enable(cpu_data_t *cdp) -{ - uint32_t cr0 = get_cr0(); - uint64_t efer = rdmsr64(MSR_IA32_EFER); - - assert(!ml_get_interrupts_enabled()); - - postcode(CPU_IA32_ENABLE_ENTRY); - - /* Turn paging off - works because we're identity mapped */ - set_cr0(cr0 & ~CR0_PG); - - /* pop in new top level phys pg addr */ - set_cr3((vm_offset_t) kernel64_cr3); - - wrmsr64(MSR_IA32_EFER, efer | MSR_IA32_EFER_LME); /* set mode */ - - /* Turn paging on */ - set_cr0(cr0 | CR0_PG); - - /* this call is required to re-activate paging */ - kprintf("cpu_IA32e_enable(%p)\n", cdp); - - if ((rdmsr64(MSR_IA32_EFER) & MSR_IA32_EFER_LMA) == 0) - panic("cpu_IA32e_enable() MSR_IA32_EFER_LMA not asserted"); - - cdp->cpu_kernel_cr3 = kernel64_cr3; - - postcode(CPU_IA32_ENABLE_EXIT); -} - -void -cpu_IA32e_disable(cpu_data_t *cdp) -{ - uint32_t cr0 = get_cr0(); - uint64_t efer = rdmsr64(MSR_IA32_EFER); - - assert(!ml_get_interrupts_enabled()); - - postcode(CPU_IA32_DISABLE_ENTRY); - - if ((rdmsr64(MSR_IA32_EFER) & MSR_IA32_EFER_LMA) == 0) - panic("cpu_IA32e_disable() MSR_IA32_EFER_LMA clear on entry"); - - /* Turn paging off - works because we're identity mapped */ - set_cr0(cr0 & ~CR0_PG); - - /* pop in legacy top level phys pg addr */ - set_cr3((vm_offset_t) lo_kernel_cr3); - - wrmsr64(MSR_IA32_EFER, efer & ~MSR_IA32_EFER_LME); /* reset mode */ - - /* Turn paging on */ - set_cr0(cr0 | CR0_PG); - - /* this call is required to re-activate paging */ - kprintf("cpu_IA32e_disable(%p)\n", cdp); - - if ((rdmsr64(MSR_IA32_EFER) & MSR_IA32_EFER_LMA) != 0) - panic("cpu_IA32e_disable() MSR_IA32_EFER_LMA not cleared"); - - cdp->cpu_kernel_cr3 = 0ULL; - - postcode(CPU_IA32_DISABLE_EXIT); -} - -void -fix_desc64(void *descp, int count) -{ - struct fake_descriptor64 *fakep; - union { - struct real_gate64 gate; - struct real_descriptor64 desc; - } real; - int i; - - fakep = (struct fake_descriptor64 *) descp; - - for (i = 0; i < count; i++, fakep++) { - /* - * Construct the real decriptor locally. - */ - - bzero((void *) &real, sizeof(real)); - - switch (fakep->access & ACC_TYPE) { - case 0: - break; - case ACC_CALL_GATE: - case ACC_INTR_GATE: - case ACC_TRAP_GATE: - real.gate.offset_low16 = fakep->offset[0] & 0xFFFF; - real.gate.selector16 = fakep->lim_or_seg & 0xFFFF; - real.gate.IST = fakep->size_or_IST & 0x7; - real.gate.access8 = fakep->access; - real.gate.offset_high16 = (fakep->offset[0]>>16)&0xFFFF; - real.gate.offset_top32 = (uint32_t)fakep->offset[1]; - break; - default: /* Otherwise */ - real.desc.limit_low16 = fakep->lim_or_seg & 0xFFFF; - real.desc.base_low16 = fakep->offset[0] & 0xFFFF; - real.desc.base_med8 = (fakep->offset[0] >> 16) & 0xFF; - real.desc.access8 = fakep->access; - real.desc.limit_high4 = (fakep->lim_or_seg >> 16) & 0xFF; - real.desc.granularity4 = fakep->size_or_IST; - real.desc.base_high8 = (fakep->offset[0] >> 24) & 0xFF; - real.desc.base_top32 = (uint32_t) fakep->offset[1]; - } - - /* - * Now copy back over the fake structure. - */ - bcopy((void *) &real, (void *) fakep, sizeof(real)); - } -} - #if DEBUG +extern void dump_regs64(void); extern void dump_gdt(void *); extern void dump_ldt(void *); extern void dump_idt(void *); extern void dump_tss(void *); -extern void dump_frame32(x86_saved_state_compat32_t *scp); +extern void dump_frame32(x86_saved_state32_t *sp); extern void dump_frame64(x86_saved_state64_t *sp); extern void dump_frame(x86_saved_state_t *sp); @@ -196,7 +78,7 @@ void dump_frame(x86_saved_state_t *sp) { if (is_saved_state32(sp)) - dump_frame32((x86_saved_state_compat32_t *) sp); + dump_frame32(&sp->ss_32); else if (is_saved_state64(sp)) dump_frame64(&sp->ss_64); else @@ -204,44 +86,36 @@ dump_frame(x86_saved_state_t *sp) } void -dump_frame32(x86_saved_state_compat32_t *scp) +dump_frame32(x86_saved_state32_t *sp) { unsigned int i; - uint32_t *ip = (uint32_t *) scp; + uint32_t *ip = (uint32_t *) sp; - kprintf("dump_frame32(0x%08x):\n", scp); + kprintf("dump_frame32(%p):\n", sp); for (i = 0; - i < sizeof(x86_saved_state_compat32_t)/sizeof(uint32_t); + i < sizeof(x86_saved_state32_t)/sizeof(uint32_t); i++, ip++) - kprintf("0x%08x: 0x%08x\n", ip, *ip); - - kprintf("scp->isf64.err: 0x%016llx\n", scp->isf64.err); - kprintf("scp->isf64.rip: 0x%016llx\n", scp->isf64.rip); - kprintf("scp->isf64.cs: 0x%016llx\n", scp->isf64.cs); - kprintf("scp->isf64.rflags: 0x%016llx\n", scp->isf64.rflags); - kprintf("scp->isf64.rsp: 0x%016llx\n", scp->isf64.rsp); - kprintf("scp->isf64.ss: 0x%016llx\n", scp->isf64.ss); - - kprintf("scp->iss32.tag: 0x%08x\n", scp->iss32.tag); - kprintf("scp->iss32.state.gs: 0x%08x\n", scp->iss32.state.gs); - kprintf("scp->iss32.state.fs: 0x%08x\n", scp->iss32.state.fs); - kprintf("scp->iss32.state.es: 0x%08x\n", scp->iss32.state.es); - kprintf("scp->iss32.state.ds: 0x%08x\n", scp->iss32.state.ds); - kprintf("scp->iss32.state.edi: 0x%08x\n", scp->iss32.state.edi); - kprintf("scp->iss32.state.esi: 0x%08x\n", scp->iss32.state.esi); - kprintf("scp->iss32.state.ebp: 0x%08x\n", scp->iss32.state.ebp); - kprintf("scp->iss32.state.cr2: 0x%08x\n", scp->iss32.state.cr2); - kprintf("scp->iss32.state.ebx: 0x%08x\n", scp->iss32.state.ebx); - kprintf("scp->iss32.state.edx: 0x%08x\n", scp->iss32.state.edx); - kprintf("scp->iss32.state.ecx: 0x%08x\n", scp->iss32.state.ecx); - kprintf("scp->iss32.state.eax: 0x%08x\n", scp->iss32.state.eax); - kprintf("scp->iss32.state.trapno: 0x%08x\n", scp->iss32.state.eax); - kprintf("scp->iss32.state.eip: 0x%08x\n", scp->iss32.state.eip); - kprintf("scp->iss32.state.cs: 0x%08x\n", scp->iss32.state.cs); - kprintf("scp->iss32.state.efl: 0x%08x\n", scp->iss32.state.efl); - kprintf("scp->iss32.state.uesp: 0x%08x\n", scp->iss32.state.uesp); - kprintf("scp->iss32.state.ss: 0x%08x\n", scp->iss32.state.ss); + kprintf("%p: 0x%08x\n", ip, *ip); + + kprintf("sp->gs: 0x%08x\n", sp->gs); + kprintf("sp->fs: 0x%08x\n", sp->fs); + kprintf("sp->es: 0x%08x\n", sp->es); + kprintf("sp->ds: 0x%08x\n", sp->ds); + kprintf("sp->edi: 0x%08x\n", sp->edi); + kprintf("sp->esi: 0x%08x\n", sp->esi); + kprintf("sp->ebp: 0x%08x\n", sp->ebp); + kprintf("sp->cr2: 0x%08x\n", sp->cr2); + kprintf("sp->ebx: 0x%08x\n", sp->ebx); + kprintf("sp->edx: 0x%08x\n", sp->edx); + kprintf("sp->ecx: 0x%08x\n", sp->ecx); + kprintf("sp->eax: 0x%08x\n", sp->eax); + kprintf("sp->trapno: 0x%08x\n", sp->eax); + kprintf("sp->eip: 0x%08x\n", sp->eip); + kprintf("sp->cs: 0x%08x\n", sp->cs); + kprintf("sp->efl: 0x%08x\n", sp->efl); + kprintf("sp->uesp: 0x%08x\n", sp->uesp); + kprintf("sp->ss: 0x%08x\n", sp->ss); postcode(0x99); } @@ -257,10 +131,10 @@ dump_frame64(x86_saved_state64_t *sp) for (i = 0; i < sizeof(x86_saved_state64_t)/sizeof(uint64_t); i++, ip++) - kprintf("0x%08x: 0x%016x\n", ip, *ip); + kprintf("%p: 0x%016llx\n", ip, *ip); kprintf("sp->isf.trapno: 0x%08x\n", sp->isf.trapno); - kprintf("sp->isf.trapfn: 0x%08x\n", sp->isf.trapfn); + kprintf("sp->isf.trapfn: 0x%016llx\n", sp->isf.trapfn); kprintf("sp->isf.err: 0x%016llx\n", sp->isf.err); kprintf("sp->isf.rip: 0x%016llx\n", sp->isf.rip); kprintf("sp->isf.cs: 0x%016llx\n", sp->isf.cs); @@ -280,9 +154,6 @@ dump_frame64(x86_saved_state64_t *sp) kprintf("sp->r14: 0x%016llx\n", sp->r14); kprintf("sp->r15: 0x%016llx\n", sp->r15); kprintf("sp->cr2: 0x%016llx\n", sp->cr2); - kprintf("sp->v_arg8: 0x%016llx\n", sp->v_arg8); - kprintf("sp->v_arg7: 0x%016llx\n", sp->v_arg7); - kprintf("sp->v_arg6: 0x%016llx\n", sp->v_arg6); kprintf("sp->r9: 0x%016llx\n", sp->r9); kprintf("sp->r8: 0x%016llx\n", sp->r8); kprintf("sp->r10: 0x%016llx\n", sp->r10); @@ -299,7 +170,7 @@ dump_gdt(void *gdtp) unsigned int i; uint32_t *ip = (uint32_t *) gdtp; - kprintf("GDT:\n", ip); + kprintf("GDT:\n"); for (i = 0; i < GDTSZ; i++, ip += 2) { kprintf("%p: 0x%08x\n", ip+0, *(ip+0)); kprintf("%p: 0x%08x\n", ip+1, *(ip+1)); @@ -312,7 +183,7 @@ dump_ldt(void *ldtp) unsigned int i; uint32_t *ip = (uint32_t *) ldtp; - kprintf("LDT:\n", ip); + kprintf("LDT:\n"); for (i = 0; i < LDTSZ_MIN; i++, ip += 2) { kprintf("%p: 0x%08x\n", ip+0, *(ip+0)); kprintf("%p: 0x%08x\n", ip+1, *(ip+1)); @@ -325,7 +196,7 @@ dump_idt(void *idtp) unsigned int i; uint32_t *ip = (uint32_t *) idtp; - kprintf("IDT64:\n", ip); + kprintf("IDT64:\n"); for (i = 0; i < 16; i++, ip += 4) { kprintf("%p: 0x%08x\n", ip+0, *(ip+0)); kprintf("%p: 0x%08x\n", ip+1, *(ip+1)); @@ -340,9 +211,52 @@ dump_tss(void *tssp) unsigned int i; uint32_t *ip = (uint32_t *) tssp; - kprintf("TSS64:\n", ip); + kprintf("TSS64:\n"); for (i = 0; i < sizeof(master_ktss64)/sizeof(uint32_t); i++, ip++) { kprintf("%p: 0x%08x\n", ip+0, *(ip+0)); } } + +void dump_regs64(void) +{ + +#define SNAP_REG(reg) \ + uint64_t reg; \ + __asm__ volatile("mov %%" #reg ", %0" : "=m" (reg)) + +#define KPRINT_REG(reg) \ + kprintf("%3s: %p\n", #reg, (void *) reg) + + SNAP_REG(rsp); + SNAP_REG(rbp); + SNAP_REG(rax); + SNAP_REG(rbx); + SNAP_REG(rcx); + SNAP_REG(rdx); + SNAP_REG(rsi); + SNAP_REG(rdi); + SNAP_REG(r8); + SNAP_REG(r9); + SNAP_REG(r10); + SNAP_REG(r11); + SNAP_REG(r12); + SNAP_REG(r13); + SNAP_REG(r14); + + KPRINT_REG(rsp); + KPRINT_REG(rbp); + KPRINT_REG(rax); + KPRINT_REG(rbx); + KPRINT_REG(rcx); + KPRINT_REG(rdx); + KPRINT_REG(rsi); + KPRINT_REG(rdi); + KPRINT_REG(r8); + KPRINT_REG(r9); + KPRINT_REG(r10); + KPRINT_REG(r11); + KPRINT_REG(r12); + KPRINT_REG(r13); + KPRINT_REG(r14); +} #endif /* DEBUG */