/*- * Copyright (c) 2005 Jung-uk Kim * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. */ #include #include static __inline void do_cpuid(u_int ax, u_int *p) { __asm __volatile("cpuid" : "=a" (p[0]), "=b" (p[1]), "=c" (p[2]), "=d" (p[3]) : "0" (ax)); } static __inline void cpuid_count(u_int ax, u_int cx, u_int *p) { __asm __volatile("cpuid" : "=a" (p[0]), "=b" (p[1]), "=c" (p[2]), "=d" (p[3]) : "0" (ax), "c" (cx)); } int main(void) { u_int regs[4]; u_int cpuhigh, exthigh; u_int i, j; int vendor; do_cpuid(0, regs); cpuhigh = regs[0]; /* Match vendor strings */ if (regs[1] == 0x756e6547 && regs[2] == 0x6c65746e && regs[3] == 0x49656e69) vendor = 1; else if (regs[1] == 0x68747541 && regs[2] == 0x444d4163 && regs[3] == 0x69746e65) vendor = 2; else vendor = 0; #if 0 switch(vendor) { case 1: printf(" CPU Vendor: Intel\n\n"); break; case 2: printf(" CPU Vendor: AMD\n\n"); break; } #endif printf("CPUID function %%eax %%ebx %%ecx %%edx\n"); printf("--------------------------------------------------\n"); for (i = 0; i <= cpuhigh; i++) { if (vendor != 1 || i != 4) { do_cpuid(i, regs); printf(" %8xh %08x %08x %08x %08x\n", i & 0xffff, regs[0], regs[1], regs[2], regs[3]); } else { /* Deterministic Cache Parameters Leaf */ for (j = 0; j < 32; j++) { cpuid_count(i, j, regs); if ((regs[0] & 0x1f) == 0) break; printf(" %8xh[%02x] %08x %08x %08x %08x\n", i & 0xffff, j, regs[0], regs[1], regs[2], regs[3]); } } } exthigh = 0; do_cpuid(0x80000000, regs); if (regs[0] >= 0x80000000) exthigh = regs[0]; for (i = 0x80000000; i <= exthigh; i++) { do_cpuid(i, regs); printf("%04x_%04xh %08x %08x %08x %08x\n", (i >> 16) & 0xffff, i & 0xffff, regs[0], regs[1], regs[2], regs[3]); } return (0); }