this repo has no description
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implement brand_string, max_basic, stepping, family, model, features

+149 -20
+149 -20
src/kernel/emulation/linux/misc/sysctl_machdep.c
··· 6 6 }; 7 7 8 8 enum { 9 - _CPU_BRAND_STRING = 1000, 10 - _CPU_MAX_BASIC=999, 9 + _CPU_VENDOR = 1000, 10 + _CPU_MAX_BASIC, 11 + _CPU_FAMILY, 12 + _CPU_MODEL, 13 + _CPU_STEPPING, 14 + _CPU_BRAND_STRING, 15 + _CPU_FEATURES, 11 16 }; 12 17 13 - static sysctl_handler(handle_brand_string); 18 + static sysctl_handler(handle_vendor); 14 19 static sysctl_handler(handle_max_basic); 20 + static sysctl_handler(handle_family); 21 + static sysctl_handler(handle_model); 22 + static sysctl_handler(handle_stepping); 23 + static sysctl_handler(handle_brand_string); 24 + static sysctl_handler(handle_features); 15 25 16 26 const struct known_sysctl sysctls_machdep_cpu[] = { 17 - { .oid = _CPU_BRAND_STRING, .type = CTLTYPE_STRING, .exttype = "S", .name = "brand_string", .handler = handle_brand_string }, 18 - { .oid = _CPU_MAX_BASIC, .type = CTLTYPE_INT, .exttype = "I", .name = "max_basic", .handler = handle_max_basic }, 27 + { .oid = _CPU_MAX_BASIC, .type = CTLTYPE_INT, .exttype = "I", .name = "max_basic", .handler = handle_max_basic }, 28 + { .oid = _CPU_VENDOR, .type = CTLTYPE_STRING, .exttype = "S", .name = "vendor", .handler = handle_vendor }, 29 + { .oid = _CPU_FAMILY, .type = CTLTYPE_INT, .exttype = "I", .name = "family", .handler = handle_family }, 30 + { .oid = _CPU_MODEL, .type = CTLTYPE_INT, .exttype = "I", .name = "model", .handler = handle_model }, 31 + { .oid = _CPU_STEPPING, .type = CTLTYPE_INT, .exttype = "I", .name = "stepping", .handler = handle_stepping }, 32 + { .oid = _CPU_BRAND_STRING, .type = CTLTYPE_STRING, .exttype = "S", .name = "vendor", .handler = handle_brand_string }, 33 + { .oid = _CPU_FEATURES, .type = CTLTYPE_STRING, .exttype = "S", .name = "features", .handler = handle_features }, 19 34 { .oid = -1 } 20 35 }; 21 36 ··· 31 46 : "0" (level)) 32 47 #endif 33 48 34 - sysctl_handler(handle_brand_string) 49 + #ifndef setup 50 + #define setup(value)\ 51 + unsigned int level = 0;\ 52 + unsigned int eax = value;\ 53 + unsigned int ebx;\ 54 + unsigned int edx;\ 55 + unsigned int ecx 56 + 57 + sysctl_handler(handle_vendor) 35 58 { 36 59 unsigned int level = 0; 37 60 unsigned int eax = 0; ··· 56 79 57 80 sysctl_handler(handle_max_basic) 58 81 { 59 - unsigned int level = 0; 60 - unsigned int eax = 0; 61 - union 62 - { 63 - struct 64 - { 65 - unsigned int ebx; 66 - unsigned int edx; 67 - unsigned int ecx; 68 - }; 69 - char name[13]; 70 - } v; 82 + setup(0); 83 + 84 + 85 + __cpuid(level, eax, ebx, ecx, edx); 71 86 72 - __cpuid(level, eax, v.ebx, v.ecx, v.edx); 73 87 74 - 75 88 sprintf(old,"%d",eax); 76 89 77 90 return 0; 78 91 } 79 92 93 + sysctl_handler(handle_family) 94 + { 95 + setup(1); 96 + 97 + __cpuid(level, eax, ebx, ecx, edx); 98 + 99 + eax = eax >> 7; 100 + eax &= 15; 101 + 102 + sprintf(old,"%d",eax); 103 + 104 + return 0; 105 + } 106 + 107 + sysctl_handler(handle_model) 108 + { 109 + setup(1); 110 + 111 + __cpuid(level, eax, ebx, ecx, edx); 112 + 113 + eax = eax >> 3; 114 + eax &= 15; 115 + 116 + sprintf(old,"%d",eax); 117 + 118 + return 0; 119 + } 120 + 121 + sysctl_handler(handle_stepping) 122 + { 123 + setup(1); 124 + 125 + __cpuid(level, eax, ebx, ecx, edx); 126 + 127 + eax &= 15; 128 + 129 + sprintf(old,"%d",eax); 130 + 131 + return 0; 132 + } 133 + 134 + sysctl_handler(handle_brand_string) 135 + { 136 + unsigned int level = 0; 137 + unsigned int eax = 0x80000000; 138 + 139 + unsigned int test[3]; 140 + 141 + __cpuid(level,eax,test, test+1,test+2); 142 + 143 + if(eax < 0x80000004) // the information is not implemented 144 + return 2; 145 + 146 + eax = 0x80000001; 147 + 148 + union 149 + { 150 + unsigned int brand[12]; 151 + char name[49]; 152 + } v; 153 + 154 + __cpuid(level, eax, v.brand+0x1, v.brand+0x2, v.brand+0x3); 155 + v.brand[0x0] = eax; 156 + eax = 0x80000002; 157 + 158 + __cpuid(level, eax, v.brand+0x5, v.brand+0x6, v.brand+0x7); 159 + v.brand[0x4] = eax; 160 + eax = 0x80000003; 161 + 162 + __cpuid(level, eax, v.brand+0x9, v.brand+0xa, v.brand+0xb); 163 + v.brand[0x8] = eax; 164 + 165 + v.name[48] = 0; 166 + copyout_string(v.name, (char*) old, oldlen); 167 + 168 + return 0; 169 + } 170 + sysctl_handler(handle_features) 171 + { 172 + setup(1); 173 + 174 + char *features[] = {"FPU","VME", "DE", "PSE", "TSC", "MSR", "PAE", "MCE", "CX8", "APIC", NULL,"SEP","PGE","MCA", 175 + "CMOV", "PAT", "PSE-36", "PSN", "CLFSH", "DS", "ACPI", "MMX", "FXSR", "SSE", "SSE2", "SS", 176 + "HTT", "TM", NULL, "PBE"}; 177 + 178 + char *out = (char*)(calloc(119, sizeof(char))); //"worst" case: we have all of it plus null termination 179 + 180 + __cpuid(0,eax,ebx,ecx,edx); 181 + 182 + int j = 0; 183 + int size = sizeof(char); 184 + int counter = 0; 185 + 186 + for (int i = 0; i < 32; ++i) 187 + { 188 + if(edx>>i&1) 189 + { 190 + for(j=0;j< sizeof(features[i])/size; j++) 191 + { 192 + out[counter+j] = features[i][j] 193 + } 194 + 195 + counter = counter + j + 1; 196 + 197 + out[counter] = ' '; 198 + 199 + counter += 1; 200 + 201 + } 202 + } 203 + 204 + copyout_string(out,(*char) old, oldlen); 205 + 206 + return 0; 207 + 208 + }