| ... | ... | @@ -232,6 +232,66 @@ const arm = struct { |
| 232 | 232 | } |
| 233 | 233 | }; |
| 234 | 234 | |
| 235 | const csky = struct { |
| 236 | const cpuinfo = struct { |
| 237 | const Impl = struct { |
| 238 | model: ?*const Target.Cpu.Model = null, |
| 239 | |
| 240 | const cpu_names = .{ |
| 241 | .{ "ck807", &Target.csky.cpu.ck807 }, |
| 242 | .{ "ck807f", &Target.csky.cpu.ck807f }, |
| 243 | .{ "ck810", &Target.csky.cpu.ck810 }, |
| 244 | .{ "ck810f", &Target.csky.cpu.ck810f }, |
| 245 | .{ "ck810t", &Target.csky.cpu.ck810t }, |
| 246 | .{ "ck810ft", &Target.csky.cpu.ck810ft }, |
| 247 | .{ "ck860", &Target.csky.cpu.ck860 }, |
| 248 | .{ "ck860f", &Target.csky.cpu.ck860f }, |
| 249 | .{ "ck860fv", &Target.csky.cpu.ck860fv }, |
| 250 | }; |
| 251 | |
| 252 | fn lineHook(self: *Impl, key: []const u8, value: []const u8) !bool { |
| 253 | if (mem.eql(u8, key, "C-SKY CPU model")) { |
| 254 | inline for (cpu_names) |pair| { |
| 255 | if (mem.eql(u8, value, pair[0])) { |
| 256 | self.model = pair[1]; |
| 257 | break; |
| 258 | } |
| 259 | } |
| 260 | |
| 261 | return false; |
| 262 | } |
| 263 | |
| 264 | return true; |
| 265 | } |
| 266 | |
| 267 | fn finalize(self: *const Impl, arch: Target.Cpu.Arch) ?Target.Cpu { |
| 268 | const model = self.model orelse return null; |
| 269 | return .{ |
| 270 | .arch = arch, |
| 271 | .model = model, |
| 272 | .features = model.features, |
| 273 | }; |
| 274 | } |
| 275 | }; |
| 276 | |
| 277 | const Parser = CpuinfoParser(Impl); |
| 278 | }; |
| 279 | |
| 280 | pub fn detectNativeCpu(io: Io, arch: Target.Cpu.Arch) ?Target.Cpu { |
| 281 | var file = Io.Dir.openFileAbsolute(io, "/proc/cpuinfo", .{}) catch return null; |
| 282 | defer file.close(io); |
| 283 | |
| 284 | var buffer: [4096]u8 = undefined; |
| 285 | var file_reader = file.reader(io, &buffer); |
| 286 | |
| 287 | var cpu = (cpuinfo.Parser.parse(arch, &file_reader.interface) catch null) orelse return null; |
| 288 | |
| 289 | cpu.features.populateDependencies(cpu.arch.allFeaturesList()); |
| 290 | |
| 291 | return cpu; |
| 292 | } |
| 293 | }; |
| 294 | |
| 235 | 295 | const powerpc = struct { |
| 236 | 296 | const cpuinfo = struct { |
| 237 | 297 | const Impl = struct { |
| ... | ... | @@ -757,6 +817,7 @@ pub fn detectNativeCpuAndFeatures(io: Io) ?Target.Cpu { |
| 757 | 817 | return switch (current_arch) { |
| 758 | 818 | .aarch64, .aarch64_be => aarch64.detectNativeCpuAndFeatures(current_arch), |
| 759 | 819 | .arm, .armeb, .thumb, .thumbeb => arm.detectNativeCpu(io, current_arch), |
| 820 | .csky => csky.detectNativeCpu(io, current_arch), |
| 760 | 821 | .powerpc, .powerpcle, .powerpc64, .powerpc64le => powerpc.detectNativeCpu(io, current_arch), |
| 761 | 822 | .riscv64, .riscv32 => riscv.detectNativeCpuAndFeatures(io, current_arch), |
| 762 | 823 | .s390x => s390x.detectNativeCpu(io, current_arch), |