From 99650e773abf536d6b44f33e2fa4c5e6968592f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20R=C3=B8nne=20Petersen?= Date: Mon, 7 Sep 2026 10:54:51 +0200 Subject: [PATCH] std.zig.system.linux: add m68k CPU model detection --- lib/std/zig/system/linux.zig | 56 ++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/lib/std/zig/system/linux.zig b/lib/std/zig/system/linux.zig index f8055e853bf8255a2af6370f3818812c1504ff15..504d9eb8ba860dc35ffcaa1d9b7d448be033559c 100644 --- a/lib/std/zig/system/linux.zig +++ b/lib/std/zig/system/linux.zig @@ -292,6 +292,61 @@ const csky = struct { } }; +const m68k = struct { + const cpuinfo = struct { + const Impl = struct { + model: ?*const Target.Cpu.Model = null, + + const cpu_names = .{ + .{ "68020", &Target.m68k.cpu.M68020 }, + .{ "68030", &Target.m68k.cpu.M68030 }, + .{ "68040", &Target.m68k.cpu.M68040 }, + .{ "68060", &Target.m68k.cpu.M68060 }, + }; + + fn lineHook(self: *Impl, key: []const u8, value: []const u8) !bool { + if (mem.eql(u8, key, "CPU")) { + inline for (cpu_names) |pair| { + if (mem.eql(u8, value, pair[0])) { + self.model = pair[1]; + break; + } + } + + return false; + } + + return true; + } + + fn finalize(self: *const Impl, arch: Target.Cpu.Arch) ?Target.Cpu { + const model = self.model orelse return null; + return .{ + .arch = arch, + .model = model, + .features = model.features, + }; + } + }; + + const Parser = CpuinfoParser(Impl); + }; + + pub fn detectNativeCpu(io: Io, arch: Target.Cpu.Arch) ?Target.Cpu { + var file = Io.Dir.openFileAbsolute(io, "/proc/cpuinfo", .{}) catch return null; + defer file.close(io); + + var buffer: [4096]u8 = undefined; + var file_reader = file.reader(io, &buffer); + + var cpu = (cpuinfo.Parser.parse(arch, &file_reader.interface) catch null) orelse return null; + + cpu.features.populateDependencies(cpu.arch.allFeaturesList()); + + return cpu; + } +}; + const powerpc = struct { const cpuinfo = struct { const Impl = struct { @@ -818,6 +873,7 @@ pub fn detectNativeCpuAndFeatures(io: Io) ?Target.Cpu { .aarch64, .aarch64_be => aarch64.detectNativeCpuAndFeatures(current_arch), .arm, .armeb, .thumb, .thumbeb => arm.detectNativeCpu(io, current_arch), .csky => csky.detectNativeCpu(io, current_arch), + .m68k => m68k.detectNativeCpu(io, current_arch), .powerpc, .powerpcle, .powerpc64, .powerpc64le => powerpc.detectNativeCpu(io, current_arch), .riscv64, .riscv32 => riscv.detectNativeCpuAndFeatures(io, current_arch), .s390x => s390x.detectNativeCpu(io, current_arch), -- 2.54.0