this repo has no description
1
fork

Configure Feed

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

Merge pull request #760 from Balint66/master

Adding some basic functionality to sysctl_machdep

authored by

Ariel Abreu and committed by
GitHub
c68ff619 2321fac6

+206 -3
+206 -3
src/kernel/emulation/linux/misc/sysctl_machdep.c
··· 1 1 #include "sysctl_machdep.h" 2 + #include "simple.h" 2 3 #include <sys/errno.h> 4 + #include <alloca.h> 5 + 6 + extern char *strncpy(char *dest, const char *src, __SIZE_TYPE__ n); 3 7 4 8 enum { 5 9 _MACHDEP_CPU = 1000, 6 10 }; 7 11 8 12 enum { 9 - _CPU_BRAND_STRING = 1000, 13 + _CPU_VENDOR = 1000, 14 + _CPU_MAX_BASIC, 15 + _CPU_FAMILY, 16 + _CPU_MODEL, 17 + _CPU_STEPPING, 18 + _CPU_BRAND_STRING, 19 + _CPU_FEATURES, 10 20 }; 11 21 22 + static sysctl_handler(handle_vendor); 23 + static sysctl_handler(handle_max_basic); 24 + static sysctl_handler(handle_family); 25 + static sysctl_handler(handle_model); 26 + static sysctl_handler(handle_stepping); 12 27 static sysctl_handler(handle_brand_string); 28 + static sysctl_handler(handle_features); 13 29 14 30 const struct known_sysctl sysctls_machdep_cpu[] = { 15 - { .oid = _CPU_BRAND_STRING, .type = CTLTYPE_STRING, .exttype = "S", .name = "brand_string", .handler = handle_brand_string }, 31 + { .oid = _CPU_MAX_BASIC, .type = CTLTYPE_INT, .exttype = "I", .name = "max_basic", .handler = handle_max_basic }, 32 + { .oid = _CPU_VENDOR, .type = CTLTYPE_STRING, .exttype = "S", .name = "vendor", .handler = handle_vendor }, 33 + { .oid = _CPU_FAMILY, .type = CTLTYPE_INT, .exttype = "I", .name = "family", .handler = handle_family }, 34 + { .oid = _CPU_MODEL, .type = CTLTYPE_INT, .exttype = "I", .name = "model", .handler = handle_model }, 35 + { .oid = _CPU_STEPPING, .type = CTLTYPE_INT, .exttype = "I", .name = "stepping", .handler = handle_stepping }, 36 + { .oid = _CPU_BRAND_STRING, .type = CTLTYPE_STRING, .exttype = "S", .name = "vendor", .handler = handle_brand_string }, 37 + { .oid = _CPU_FEATURES, .type = CTLTYPE_STRING, .exttype = "S", .name = "features", .handler = handle_features }, 16 38 { .oid = -1 } 17 39 }; 18 40 ··· 28 50 : "0" (level)) 29 51 #endif 30 52 31 - sysctl_handler(handle_brand_string) 53 + #ifndef setup 54 + #define setup(value)\ 55 + unsigned int level = 0; \ 56 + unsigned int eax = value; \ 57 + unsigned int ebx; \ 58 + unsigned int edx; \ 59 + unsigned int ecx 60 + #endif 61 + 62 + 63 + static inline void copyout_int(int value, char* to_copy, size_t* to_copy_length) 64 + { 65 + char tmp[64]; 66 + __simple_sprintf(tmp, "%d", value); 67 + copyout_string(tmp, to_copy, to_copy_length); 68 + } 69 + 70 + 71 + sysctl_handler(handle_vendor) 32 72 { 33 73 unsigned int level = 0; 34 74 unsigned int eax = 0; ··· 51 91 return 0; 52 92 } 53 93 94 + sysctl_handler(handle_max_basic) 95 + { 96 + setup(0); 97 + 98 + 99 + __cpuid(level, eax, ebx, ecx, edx); 100 + 101 + copyout_int(eax, (char*)old,oldlen); 102 + 103 + return 0; 104 + } 105 + 106 + sysctl_handler(handle_family) 107 + { 108 + setup(1); 109 + 110 + __cpuid(level, eax, ebx, ecx, edx); 111 + 112 + eax = eax >> 7; 113 + eax &= 15; 114 + 115 + copyout_int(eax, old, oldlen); 116 + 117 + return 0; 118 + } 119 + 120 + sysctl_handler(handle_model) 121 + { 122 + setup(1); 123 + 124 + __cpuid(level, eax, ebx, ecx, edx); 125 + 126 + eax = eax >> 3; 127 + eax &= 15; 128 + 129 + copyout_int(eax,(char*)old, oldlen); 130 + 131 + return 0; 132 + } 133 + 134 + sysctl_handler(handle_stepping) 135 + { 136 + setup(1); 137 + 138 + __cpuid(level, eax, ebx, ecx, edx); 139 + 140 + eax &= 15; 141 + 142 + copyout_int(eax,(char*)old, oldlen); 143 + 144 + return 0; 145 + } 146 + 147 + sysctl_handler(handle_brand_string) 148 + { 149 + setup(0x80000000); 150 + 151 + __cpuid(level,eax,ebx, ecx, edx); 152 + 153 + if (eax < 0x80000004) // the information is not implemented 154 + return 2; 155 + 156 + 157 + 158 + union 159 + { 160 + unsigned int brand[12]; 161 + char name[49]; 162 + } v; 163 + 164 + for (int i = 1; i < 4; i++) 165 + { 166 + eax = 0x80000000+i; 167 + __cpuid(level, eax, ebx, ecx, edx); 168 + v.brand[0x0+(i-1)*4] = eax; 169 + v.brand[0x1+(i-1)*4] = ebx; 170 + v.brand[0x2+(i-1)*4] = ecx; 171 + v.brand[0x3+(i-1)*4] = edx; 172 + } 173 + 174 + v.name[48] = 0; 175 + copyout_string(v.name, (char*) old, oldlen); 176 + 177 + return 0; 178 + } 179 + 180 + sysctl_handler(handle_features) 181 + { 182 + 183 + setup(1); 184 + 185 + static const char features[][7] = {"FPU","VME", "DE", "PSE", "TSC", "MSR", "PAE", "MCE", "CX8", "APIC", "","SEP","MTRR","PGE", 186 + "MCA", "CMOV", "PAT", "PSE-36", "PSN", "CLFSH", "", "DS", "ACPI", "MMX", "FXSR", "SSE", "SSE2", "SS", 187 + "HTT", "TM","IA64","PBE"}; 188 + 189 + __cpuid(0,eax,ebx,ecx,edx); 190 + int current_length = 0; 191 + 192 + if (old != NULL) 193 + { 194 + 195 + char *outsr = (char*)old; 196 + 197 + for (int i = 0; i < 32; i++) 198 + { 199 + if (i == 10 || i == 20) 200 + continue; 201 + 202 + if ( (edx & (1<<i)) && current_length < *oldlen) 203 + { 204 + if (current_length) 205 + { 206 + outsr[current_length] = ' '; 207 + 208 + current_length++; 209 + } 210 + if (current_length < *oldlen) 211 + { 212 + int len = __simple_strlen(features[i]); 213 + 214 + strncpy(outsr + current_length, features[i], 215 + *oldlen - current_length); 216 + 217 + current_length += len; 218 + } 219 + } 220 + } 221 + 222 + if (current_length < *oldlen) 223 + { 224 + outsr[current_length] = '\0'; 225 + } 226 + 227 + } 228 + else 229 + { 230 + 231 + for (int i = 0; i < 32; i++) 232 + { 233 + 234 + if (i == 10 || i == 20) 235 + continue; 236 + 237 + if (edx & (1<<i)) 238 + { 239 + if (current_length != 0) 240 + current_length++; 241 + 242 + current_length += __simple_strlen(features[i]); 243 + } 244 + 245 + } 246 + 247 + if (oldlen) 248 + *oldlen = current_length; 249 + 250 + } 251 + 252 + 253 + 254 + return 0; 255 + 256 + }