From 0ddc618b1d60ef6729326aa4e45b8280fcf51775 Mon Sep 17 00:00:00 2001 From: Freya Murphy Date: Wed, 16 Apr 2025 16:51:25 -0400 Subject: fmt --- kernel/cpu/cpu.c | 130 ++++++++++++++++++++++++++++--------------------------- 1 file changed, 67 insertions(+), 63 deletions(-) (limited to 'kernel/cpu') 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"); } - -- cgit v1.2.3-freya