diff options
Diffstat (limited to '')
-rw-r--r-- | kernel/cpu/cpu.c | 130 | ||||
-rw-r--r-- | kernel/drivers/acpi.c | 28 | ||||
-rw-r--r-- | kernel/memory/physalloc.c | 6 |
3 files changed, 84 insertions, 80 deletions
diff --git a/kernel/cpu/cpu.c b/kernel/cpu/cpu.c index 3835b68..136a1d8 100644 --- a/kernel/cpu/cpu.c +++ b/kernel/cpu/cpu.c @@ -18,19 +18,19 @@ static inline void sse_init(void) { size_t cr0, cr4; __asm__ volatile("mov %%cr0, %0" : "=r"(cr0)); - cr0 &= ~0x4; // clear coprocessor emulation - cr0 |= 0x2; // set coprocessor monitoring - __asm__ volatile("mov %0, %%cr0" :: "r"(cr0)); + cr0 &= ~0x4; // clear coprocessor emulation + cr0 |= 0x2; // set coprocessor monitoring + __asm__ volatile("mov %0, %%cr0" ::"r"(cr0)); __asm__ volatile("mov %%cr4, %0" : "=r"(cr4)); cr4 |= 1 << 9; // set CR4.OSFXSR cr4 |= 1 << 10; // set CR4.OSXMMEXCPT - __asm__ volatile("mov %0, %%cr4" :: "r"(cr4)); + __asm__ volatile("mov %0, %%cr4" ::"r"(cr4)); } static inline void fxsave_init(void) { static char fxsave_region[512] __attribute__((aligned(16))); - __asm__ volatile("fxsave %0" :: "m"(fxsave_region)); + __asm__ volatile("fxsave %0" ::"m"(fxsave_region)); } static inline void xsave_init(void) @@ -38,23 +38,21 @@ static inline void xsave_init(void) size_t cr4; __asm__ volatile("mov %%cr4, %0" : "=r"(cr4)); cr4 |= 1 << 18; // set CR4.OSXSAVE - __asm__ volatile("mov %0, %%cr4" :: "r"(cr4)); + __asm__ volatile("mov %0, %%cr4" ::"r"(cr4)); } static inline void avx_init(void) { - __asm__ volatile( - "pushq %rax;" - "pushq %rcx;" - "pushq %rdx;" - "xorq %rcx, %rcx;" - "xgetbv;" - "orq $7, %rax;" - "xsetbv;" - "popq %rdx;" - "popq %rcx;" - "popq %rax;" - ); + __asm__ volatile("pushq %rax;" + "pushq %rcx;" + "pushq %rdx;" + "xorq %rcx, %rcx;" + "xgetbv;" + "orq $7, %rax;" + "xsetbv;" + "popq %rdx;" + "popq %rcx;" + "popq %rax;"); } void cpu_init(void) @@ -119,30 +117,37 @@ void cpu_report(void) kputs("\n\n"); } -static inline void cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) +static inline void cpuid(uint32_t leaf, uint32_t *eax, uint32_t *ebx, + uint32_t *ecx, uint32_t *edx) { - __asm__ volatile("cpuid" - : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) - : "0" (leaf)); + __asm__ volatile("cpuid" + : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) + : "0"(leaf)); } -static inline void cpuid_count(uint32_t leaf, uint32_t subleaf, uint32_t *eax, uint32_t *ebx, uint32_t *ecx, uint32_t *edx) +static inline void cpuid_count(uint32_t leaf, uint32_t subleaf, uint32_t *eax, + uint32_t *ebx, uint32_t *ecx, uint32_t *edx) { - __asm__ volatile("cpuid" - : "=a" (*eax), "=b" (*ebx), "=c" (*ecx), "=d" (*edx) - : "0" (leaf), "2" (subleaf)); + __asm__ volatile("cpuid" + : "=a"(*eax), "=b"(*ebx), "=c"(*ecx), "=d"(*edx) + : "0"(leaf), "2"(subleaf)); } void cpu_vendor(char vendor[12]) { uint32_t ignore; - cpuid(0, &ignore, (uint32_t *)(vendor + 0), (uint32_t *)(vendor + 8), (uint32_t *)(vendor + 4)); + cpuid(0, &ignore, (uint32_t *)(vendor + 0), (uint32_t *)(vendor + 8), + (uint32_t *)(vendor + 4)); } -void cpu_name(char name[48]) { - cpuid(0x80000002, (uint32_t *)(name + 0), (uint32_t *)(name + 4), (uint32_t *)(name + 8), (uint32_t *)(name + 12)); - cpuid(0x80000003, (uint32_t *)(name + 16), (uint32_t *)(name + 20), (uint32_t *)(name + 24), (uint32_t *)(name + 28)); - cpuid(0x80000004, (uint32_t *)(name + 32), (uint32_t *)(name + 36), (uint32_t *)(name + 40), (uint32_t *)(name + 44)); +void cpu_name(char name[48]) +{ + cpuid(0x80000002, (uint32_t *)(name + 0), (uint32_t *)(name + 4), + (uint32_t *)(name + 8), (uint32_t *)(name + 12)); + cpuid(0x80000003, (uint32_t *)(name + 16), (uint32_t *)(name + 20), + (uint32_t *)(name + 24), (uint32_t *)(name + 28)); + cpuid(0x80000004, (uint32_t *)(name + 32), (uint32_t *)(name + 36), + (uint32_t *)(name + 40), (uint32_t *)(name + 44)); } void cpu_feats(struct cpu_feat *feats) @@ -156,19 +161,19 @@ void cpu_feats(struct cpu_feat *feats) cpuid(1, &ignore, &ignore, &ecx_1, &edx_1); cpuid_count(7, 0, &ignore, &ebx_7, &ignore, &ignore); - feats->fpu = edx_1 & (1<<0) ? 1 : 0; - feats->mmx = edx_1 & (1<<23) ? 1 : 0; - feats->sse = edx_1 & (1<<25) ? 1 : 0; - feats->sse2 = edx_1 & (1<<26) ? 1 : 0; - feats->sse3 = ecx_1 & (1<<0) ? 1 : 0; - feats->ssse3 = ecx_1 & (1<<9) ? 1 : 0; - feats->sse41 = ecx_1 & (1<<19) ? 1 : 0; - feats->sse42 = ecx_1 & (1<<20) ? 1 : 0; - feats->sse4a = ecx_1 & (1<<6) ? 1 : 0; - feats->avx = ecx_1 & (1<<28) ? 1 : 0; - feats->xsave = ecx_1 & (1<<26) ? 1 : 0; - feats->avx2 = ebx_7 & (1<<5) ? 1 : 0; - feats->avx512 = ebx_7 & (7<<16) ? 1 : 0; + feats->fpu = edx_1 & (1 << 0) ? 1 : 0; + feats->mmx = edx_1 & (1 << 23) ? 1 : 0; + feats->sse = edx_1 & (1 << 25) ? 1 : 0; + feats->sse2 = edx_1 & (1 << 26) ? 1 : 0; + feats->sse3 = ecx_1 & (1 << 0) ? 1 : 0; + feats->ssse3 = ecx_1 & (1 << 9) ? 1 : 0; + feats->sse41 = ecx_1 & (1 << 19) ? 1 : 0; + feats->sse42 = ecx_1 & (1 << 20) ? 1 : 0; + feats->sse4a = ecx_1 & (1 << 6) ? 1 : 0; + feats->avx = ecx_1 & (1 << 28) ? 1 : 0; + feats->xsave = ecx_1 & (1 << 26) ? 1 : 0; + feats->avx2 = ebx_7 & (1 << 5) ? 1 : 0; + feats->avx512 = ebx_7 & (7 << 16) ? 1 : 0; } void cpu_print_regs(struct cpu_regs *regs) @@ -192,42 +197,41 @@ void cpu_print_regs(struct cpu_regs *regs) kprintf("rip: %#016lx (%lu)\n", regs->rip, regs->rip); kprintf("rflags: %#016lx (%lu)\n", regs->rflags, regs->rflags); kputs("rflags: "); - if (regs->rflags & (1<<0)) + if (regs->rflags & (1 << 0)) kputs("CF "); - if (regs->rflags & (1<<2)) + if (regs->rflags & (1 << 2)) kputs("PF "); - if (regs->rflags & (1<<4)) + if (regs->rflags & (1 << 4)) kputs("AF "); - if (regs->rflags & (1<<6)) + if (regs->rflags & (1 << 6)) kputs("ZF "); - if (regs->rflags & (1<<7)) + if (regs->rflags & (1 << 7)) kputs("SF "); - if (regs->rflags & (1<<8)) + if (regs->rflags & (1 << 8)) kputs("TF "); - if (regs->rflags & (1<<9)) + if (regs->rflags & (1 << 9)) kputs("IF "); - if (regs->rflags & (1<<10)) + if (regs->rflags & (1 << 10)) kputs("DF "); - if (regs->rflags & (1<<11)) + if (regs->rflags & (1 << 11)) kputs("OF "); - if (regs->rflags & (3<<12)) + if (regs->rflags & (3 << 12)) kputs("IOPL "); - if (regs->rflags & (1<<14)) + if (regs->rflags & (1 << 14)) kputs("NT "); - if (regs->rflags & (1<<15)) + if (regs->rflags & (1 << 15)) kputs("MD "); - if (regs->rflags & (1<<16)) + if (regs->rflags & (1 << 16)) kputs("RF "); - if (regs->rflags & (1<<17)) + if (regs->rflags & (1 << 17)) kputs("VM "); - if (regs->rflags & (1<<18)) + if (regs->rflags & (1 << 18)) kputs("AC "); - if (regs->rflags & (1<<19)) + if (regs->rflags & (1 << 19)) kputs("VIF "); - if (regs->rflags & (1<<20)) + if (regs->rflags & (1 << 20)) kputs("VIP "); - if (regs->rflags & (1<<21)) + if (regs->rflags & (1 << 21)) kputs("ID "); kputs("\n"); } - diff --git a/kernel/drivers/acpi.c b/kernel/drivers/acpi.c index 41f7ba1..b4b219a 100644 --- a/kernel/drivers/acpi.c +++ b/kernel/drivers/acpi.c @@ -327,29 +327,29 @@ void acpi_report(void) { if (state.version == 0) { kprintf("ACPI 1.0\n"); - kprintf("%.*s: %#016lx\n", 4, (char *) &state.sdt.rsdt->h.signature, - (uintptr_t) state.sdt.rsdt); + kprintf("%.*s: %#016lx\n", 4, (char *)&state.sdt.rsdt->h.signature, + (uintptr_t)state.sdt.rsdt); } else { kprintf("ACPI 2.0\n"); - kprintf("%.*s: %#016lx\n", 4, (char *) &state.sdt.xsdt->h.signature, - (uintptr_t) state.sdt.xsdt); + kprintf("%.*s: %#016lx\n", 4, (char *)&state.sdt.xsdt->h.signature, + (uintptr_t)state.sdt.xsdt); } if (state.fadt) - kprintf("%.*s: %#016lx\n", 4, (char *) &state.fadt->h.signature, - (uintptr_t) state.fadt); + kprintf("%.*s: %#016lx\n", 4, (char *)&state.fadt->h.signature, + (uintptr_t)state.fadt); if (state.dsdt) - kprintf("%.*s: %#016lx\n", 4, (char *) &state.dsdt->h.signature, - (uintptr_t) state.dsdt); + kprintf("%.*s: %#016lx\n", 4, (char *)&state.dsdt->h.signature, + (uintptr_t)state.dsdt); if (state.apic) - kprintf("%.*s: %#016lx\n", 4, (char *) &state.apic->h.signature, - (uintptr_t) state.apic); + kprintf("%.*s: %#016lx\n", 4, (char *)&state.apic->h.signature, + (uintptr_t)state.apic); if (state.hept) - kprintf("%.*s: %#016lx\n", 4, (char *) &state.hept->h.signature, - (uintptr_t) state.hept); + kprintf("%.*s: %#016lx\n", 4, (char *)&state.hept->h.signature, + (uintptr_t)state.hept); if (state.waet) - kprintf("%.*s: %#016lx\n", 4, (char *) &state.waet->h.signature, - (uintptr_t) state.waet); + kprintf("%.*s: %#016lx\n", 4, (char *)&state.waet->h.signature, + (uintptr_t)state.waet); kprintf("\n"); } diff --git a/kernel/memory/physalloc.c b/kernel/memory/physalloc.c index 328502f..676e68e 100644 --- a/kernel/memory/physalloc.c +++ b/kernel/memory/physalloc.c @@ -21,9 +21,9 @@ struct memory_map phys_mmap; struct memory_segment *page_start; static const char *segment_type_str[] = { "Reserved", "Free", - "Reserved", "ACPI Reserved", - "Hibernation", "Defective", - "Unknown" }; + "Reserved", "ACPI Reserved", + "Hibernation", "Defective", + "Unknown" }; static int n_pages(const struct memory_segment *m) { |