1 #include "inc.h" 2 #include "../../kernel/arch/i386/include/archconst.h" 3 4 #ifndef CONFIG_MAX_CPUS 5 #define CONFIG_MAX_CPUS 1 6 #endif 7 8 static const char * x86_flag[] = { 9 "fpu", 10 "vme", 11 "de", 12 "pse", 13 "tsc", 14 "msr", 15 "pae", 16 "mce", 17 "cx8", 18 "apic", 19 "", 20 "sep", 21 "mtrr", 22 "pge", 23 "mca", 24 "cmov", 25 "pat", 26 "pse36", 27 "psn", 28 "clfsh", 29 "", 30 "dts", 31 "acpi", 32 "mmx", 33 "fxsr", 34 "sse", 35 "sse2", 36 "ss", 37 "ht", 38 "tm", 39 "", 40 "pbe", 41 "pni", 42 "", 43 "", 44 "monitor", 45 "ds_cpl", 46 "vmx", 47 "smx", 48 "est", 49 "tm2", 50 "ssse3", 51 "cid", 52 "", 53 "", 54 "cx16", 55 "xtpr", 56 "pdcm", 57 "", 58 "", 59 "dca", 60 "sse4_1", 61 "sse4_2", 62 "x2apic", 63 "movbe", 64 "popcnt", 65 "", 66 "", 67 "xsave", 68 "osxsave", 69 "", 70 "", 71 "", 72 "", 73 }; 74 75 static void print_cpu_flags(u32_t * flags) 76 { 77 int i, j; 78 79 for (i = 0; i < 2; i++) { 80 for (j = 0; j < 32; j++) { 81 if (flags[i] & (1 << j) && 82 x86_flag[i * 32 + j][0]) 83 buf_printf("%s ", x86_flag[i * 32 + j]); 84 } 85 } 86 buf_printf("\n"); 87 } 88 89 static void print_cpu(struct cpu_info * cpu_info, unsigned id) 90 { 91 buf_printf("%-16s: %d\n", "processor", id); 92 93 #if defined(__i386__) 94 switch (cpu_info->vendor) { 95 case CPU_VENDOR_INTEL: 96 buf_printf("%-16s: %s\n", "vendor_id", "GenuineIntel"); 97 buf_printf("%-16s: %s\n", "model name", "Intel"); 98 break; 99 case CPU_VENDOR_AMD: 100 buf_printf("%-16s: %s\n", "vendor_id", "AuthenticAMD"); 101 buf_printf("%-16s: %s\n", "model name", "AMD"); 102 break; 103 default: 104 buf_printf("%-16: %s\n", "vendor_id", "unknown"); 105 } 106 107 buf_printf("%-16s: %d\n", "cpu family", cpu_info->family); 108 buf_printf("%-16s: %d\n", "model", cpu_info->model); 109 buf_printf("%-16s: %d\n", "stepping", cpu_info->stepping); 110 buf_printf("%-16s: %d\n", "cpu MHz", cpu_info->freq); 111 buf_printf("%-16s: ", "flags"); 112 print_cpu_flags(cpu_info->flags); 113 buf_printf("\n"); 114 #endif 115 } 116 117 void root_cpuinfo(void) 118 { 119 struct cpu_info cpu_info[CONFIG_MAX_CPUS]; 120 struct machine machine; 121 unsigned c; 122 123 if (sys_getmachine(&machine)) { 124 printf("PROCFS: cannot get machine\n"); 125 return; 126 } 127 if (sys_getcpuinfo(&cpu_info)) { 128 printf("PROCFS: cannot get cpu info\n"); 129 return; 130 } 131 132 for (c = 0; c < machine.processors_count; c++) 133 print_cpu(&cpu_info[c], c); 134 } 135