|
4 | 4 | #include "system.h"
|
5 | 5 | #include "MemoryManager.h"
|
6 | 6 | #include "StdLib.h"
|
| 7 | +#include "i386.h" |
7 | 8 |
|
8 | 9 | static ProcFileSystem* s_the;
|
9 | 10 |
|
@@ -177,6 +178,71 @@ ByteBuffer procfs$mounts()
|
177 | 178 | return buffer;
|
178 | 179 | }
|
179 | 180 |
|
| 181 | +ByteBuffer procfs$cpuinfo() |
| 182 | +{ |
| 183 | + auto buffer = ByteBuffer::createUninitialized(256); |
| 184 | + char* ptr = (char*)buffer.pointer(); |
| 185 | + { |
| 186 | + CPUID cpuid(0); |
| 187 | + ptr += ksprintf(ptr, "cpuid: "); |
| 188 | + auto emit_dword = [&] (dword value) { |
| 189 | + ptr += ksprintf(ptr, "%c%c%c%c", |
| 190 | + value & 0xff, |
| 191 | + (value >> 8) & 0xff, |
| 192 | + (value >> 16) & 0xff, |
| 193 | + (value >> 24) & 0xff); |
| 194 | + }; |
| 195 | + emit_dword(cpuid.ebx()); |
| 196 | + emit_dword(cpuid.edx()); |
| 197 | + emit_dword(cpuid.ecx()); |
| 198 | + ptr += ksprintf(ptr, "\n"); |
| 199 | + } |
| 200 | + { |
| 201 | + CPUID cpuid(1); |
| 202 | + dword stepping = cpuid.eax() & 0xf; |
| 203 | + dword model = (cpuid.eax() >> 4) & 0xf; |
| 204 | + dword family = (cpuid.eax() >> 8) & 0xf; |
| 205 | + dword type = (cpuid.eax() >> 12) & 0x3; |
| 206 | + dword extended_model = (cpuid.eax() >> 16) & 0xf; |
| 207 | + dword extended_family = (cpuid.eax() >> 20) & 0xff; |
| 208 | + dword display_model; |
| 209 | + dword display_family; |
| 210 | + if (family == 15) { |
| 211 | + display_family = family + extended_family; |
| 212 | + display_model = model + (extended_model << 4); |
| 213 | + } else if (family == 6) { |
| 214 | + display_family = family; |
| 215 | + display_model = model + (extended_model << 4); |
| 216 | + } else { |
| 217 | + display_family = family; |
| 218 | + display_model = model; |
| 219 | + } |
| 220 | + ptr += ksprintf(ptr, "family: %u\n", display_family); |
| 221 | + ptr += ksprintf(ptr, "model: %u\n", display_model); |
| 222 | + ptr += ksprintf(ptr, "stepping: %u\n", stepping); |
| 223 | + ptr += ksprintf(ptr, "type: %u\n", type); |
| 224 | + } |
| 225 | + { |
| 226 | + // FIXME: Check first that this is supported by calling CPUID with eax=0x80000000 |
| 227 | + // and verifying that the returned eax>=0x80000004. |
| 228 | + char buffer[48]; |
| 229 | + dword* bufptr = reinterpret_cast<dword*>(buffer); |
| 230 | + auto copy_brand_string_part_to_buffer = [&] (dword i) { |
| 231 | + CPUID cpuid(0x80000002 + i); |
| 232 | + *bufptr++ = cpuid.eax(); |
| 233 | + *bufptr++ = cpuid.ebx(); |
| 234 | + *bufptr++ = cpuid.ecx(); |
| 235 | + *bufptr++ = cpuid.edx(); |
| 236 | + }; |
| 237 | + copy_brand_string_part_to_buffer(0); |
| 238 | + copy_brand_string_part_to_buffer(1); |
| 239 | + copy_brand_string_part_to_buffer(2); |
| 240 | + ptr += ksprintf(ptr, "brandstr: \"%s\"\n", buffer); |
| 241 | + } |
| 242 | + buffer.trim(ptr - (char*)buffer.pointer()); |
| 243 | + return buffer; |
| 244 | +} |
| 245 | + |
180 | 246 | ByteBuffer procfs$kmalloc()
|
181 | 247 | {
|
182 | 248 | InterruptDisabler disabler;
|
@@ -235,6 +301,7 @@ bool ProcFileSystem::initialize()
|
235 | 301 | addFile(createGeneratedFile("mounts", procfs$mounts));
|
236 | 302 | addFile(createGeneratedFile("kmalloc", procfs$kmalloc));
|
237 | 303 | addFile(createGeneratedFile("summary", procfs$summary));
|
| 304 | + addFile(createGeneratedFile("cpuinfo", procfs$cpuinfo)); |
238 | 305 | return true;
|
239 | 306 | }
|
240 | 307 |
|
|
0 commit comments