authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-09-07 10:54:51+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-09-07 12:17:04+02:00
log99650e773abf536d6b44f33e2fa4c5e6968592f1
tree06523aba0c1cc45e44c02b18221a5df94325c5ea
parentc4fec122cd829c3502e47e22b08ed220aaabda0a
signature Signed by SSH key SHA256:7B/LJ7bpR1eX8aCXSr4mtd5M45VMPKcx9zY8e95b5QM

std.zig.system.linux: add m68k CPU model detection


1 files changed, 56 insertions(+), 0 deletions(-)

lib/std/zig/system/linux.zig+56
......@@ -292,6 +292,61 @@ const csky = struct {
292292 }
293293};
294294
295const m68k = struct {
296 const cpuinfo = struct {
297 const Impl = struct {
298 model: ?*const Target.Cpu.Model = null,
299
300 const cpu_names = .{
301 .{ "68020", &Target.m68k.cpu.M68020 },
302 .{ "68030", &Target.m68k.cpu.M68030 },
303 .{ "68040", &Target.m68k.cpu.M68040 },
304 .{ "68060", &Target.m68k.cpu.M68060 },
305 };
306
307 fn lineHook(self: *Impl, key: []const u8, value: []const u8) !bool {
308 if (mem.eql(u8, key, "CPU")) {
309 inline for (cpu_names) |pair| {
310 if (mem.eql(u8, value, pair[0])) {
311 self.model = pair[1];
312 break;
313 }
314 }
315
316 return false;
317 }
318
319 return true;
320 }
321
322 fn finalize(self: *const Impl, arch: Target.Cpu.Arch) ?Target.Cpu {
323 const model = self.model orelse return null;
324 return .{
325 .arch = arch,
326 .model = model,
327 .features = model.features,
328 };
329 }
330 };
331
332 const Parser = CpuinfoParser(Impl);
333 };
334
335 pub fn detectNativeCpu(io: Io, arch: Target.Cpu.Arch) ?Target.Cpu {
336 var file = Io.Dir.openFileAbsolute(io, "/proc/cpuinfo", .{}) catch return null;
337 defer file.close(io);
338
339 var buffer: [4096]u8 = undefined;
340 var file_reader = file.reader(io, &buffer);
341
342 var cpu = (cpuinfo.Parser.parse(arch, &file_reader.interface) catch null) orelse return null;
343
344 cpu.features.populateDependencies(cpu.arch.allFeaturesList());
345
346 return cpu;
347 }
348};
349
295350const powerpc = struct {
296351 const cpuinfo = struct {
297352 const Impl = struct {
......@@ -818,6 +873,7 @@ pub fn detectNativeCpuAndFeatures(io: Io) ?Target.Cpu {
818873 .aarch64, .aarch64_be => aarch64.detectNativeCpuAndFeatures(current_arch),
819874 .arm, .armeb, .thumb, .thumbeb => arm.detectNativeCpu(io, current_arch),
820875 .csky => csky.detectNativeCpu(io, current_arch),
876 .m68k => m68k.detectNativeCpu(io, current_arch),
821877 .powerpc, .powerpcle, .powerpc64, .powerpc64le => powerpc.detectNativeCpu(io, current_arch),
822878 .riscv64, .riscv32 => riscv.detectNativeCpuAndFeatures(io, current_arch),
823879 .s390x => s390x.detectNativeCpu(io, current_arch),