mirror of
https://github.com/RGBCube/serenity
synced 2025-05-16 18:25:06 +00:00
Kernel: List all CPUs in /proc/cpuinfo
This commit is contained in:
parent
fb41d89384
commit
d98edb3171
12 changed files with 229 additions and 64 deletions
|
@ -29,6 +29,7 @@
|
|||
#include <AK/JsonObjectSerializer.h>
|
||||
#include <AK/JsonValue.h>
|
||||
#include <Kernel/Arch/i386/CPU.h>
|
||||
#include <Kernel/Arch/i386/ProcessorInfo.h>
|
||||
#include <Kernel/CommandLine.h>
|
||||
#include <Kernel/Console.h>
|
||||
#include <Kernel/Devices/BlockDevice.h>
|
||||
|
@ -758,63 +759,26 @@ Optional<KBuffer> procfs$df(InodeIdentifier)
|
|||
Optional<KBuffer> procfs$cpuinfo(InodeIdentifier)
|
||||
{
|
||||
KBufferBuilder builder;
|
||||
{
|
||||
CPUID cpuid(0);
|
||||
builder.appendf("cpuid: ");
|
||||
auto emit_u32 = [&](u32 value) {
|
||||
builder.appendf("%c%c%c%c",
|
||||
value & 0xff,
|
||||
(value >> 8) & 0xff,
|
||||
(value >> 16) & 0xff,
|
||||
(value >> 24) & 0xff);
|
||||
};
|
||||
emit_u32(cpuid.ebx());
|
||||
emit_u32(cpuid.edx());
|
||||
emit_u32(cpuid.ecx());
|
||||
builder.appendf("\n");
|
||||
}
|
||||
{
|
||||
CPUID cpuid(1);
|
||||
u32 stepping = cpuid.eax() & 0xf;
|
||||
u32 model = (cpuid.eax() >> 4) & 0xf;
|
||||
u32 family = (cpuid.eax() >> 8) & 0xf;
|
||||
u32 type = (cpuid.eax() >> 12) & 0x3;
|
||||
u32 extended_model = (cpuid.eax() >> 16) & 0xf;
|
||||
u32 extended_family = (cpuid.eax() >> 20) & 0xff;
|
||||
u32 display_model;
|
||||
u32 display_family;
|
||||
if (family == 15) {
|
||||
display_family = family + extended_family;
|
||||
display_model = model + (extended_model << 4);
|
||||
} else if (family == 6) {
|
||||
display_family = family;
|
||||
display_model = model + (extended_model << 4);
|
||||
} else {
|
||||
display_family = family;
|
||||
display_model = model;
|
||||
}
|
||||
builder.appendf("family: %u\n", display_family);
|
||||
builder.appendf("model: %u\n", display_model);
|
||||
builder.appendf("stepping: %u\n", stepping);
|
||||
builder.appendf("type: %u\n", type);
|
||||
}
|
||||
{
|
||||
// FIXME: Check first that this is supported by calling CPUID with eax=0x80000000
|
||||
// and verifying that the returned eax>=0x80000004.
|
||||
alignas(u32) char buffer[48];
|
||||
u32* bufptr = reinterpret_cast<u32*>(buffer);
|
||||
auto copy_brand_string_part_to_buffer = [&](u32 i) {
|
||||
CPUID cpuid(0x80000002 + i);
|
||||
*bufptr++ = cpuid.eax();
|
||||
*bufptr++ = cpuid.ebx();
|
||||
*bufptr++ = cpuid.ecx();
|
||||
*bufptr++ = cpuid.edx();
|
||||
};
|
||||
copy_brand_string_part_to_buffer(0);
|
||||
copy_brand_string_part_to_buffer(1);
|
||||
copy_brand_string_part_to_buffer(2);
|
||||
builder.appendf("brandstr: \"%s\"\n", buffer);
|
||||
}
|
||||
bool first = true;
|
||||
|
||||
Processor::for_each(
|
||||
[&](Processor& proc) -> IterationDecision
|
||||
{
|
||||
if (first)
|
||||
first = false;
|
||||
else
|
||||
builder.append('\n');
|
||||
|
||||
auto& info = proc.info();
|
||||
builder.appendf("processor: %u\n", proc.id());
|
||||
builder.appendf("cpuid: %s\n", info.cpuid().characters());
|
||||
builder.appendf("family: %u\n", info.display_family());
|
||||
builder.appendf("model: %u\n", info.display_model());
|
||||
builder.appendf("stepping: %u\n", info.stepping());
|
||||
builder.appendf("type: %u\n", info.type());
|
||||
builder.appendf("brandstr: \"%s\"\n", info.brandstr().characters());
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
return builder.build();
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue