authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-02 14:49:28-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-03-02 14:49:28-07:00
log68c00122b10a7364c52a59f56761942525498ce8
treef745d592d9270f0e5f4898d0355318fc73f88e81
parent939f334221ad34618ceb59bc42ce9ef366a54bf9

x86: detect and set 16bit_mode and 32bit_mode CPU features


1 files changed, 27 insertions(+), 5 deletions(-)

lib/std/zig/system.zig+27-5
...@@ -326,11 +326,33 @@ pub const NativeTargetInfo = struct {...@@ -326,11 +326,33 @@ pub const NativeTargetInfo = struct {
326 cpu_detection_unimplemented = true;326 cpu_detection_unimplemented = true;
327 break :backup_cpu_detection Target.Cpu.baseline(cpu_arch);327 break :backup_cpu_detection Target.Cpu.baseline(cpu_arch);
328 };328 };
329 cross_target.updateCpuFeatures(&cpu.features);329 var result = try detectAbiAndDynamicLinker(allocator, cpu, os, cross_target);
330330 // For x86, we need to populate some CPU feature flags depending on architecture
331 var target = try detectAbiAndDynamicLinker(allocator, cpu, os, cross_target);331 // and mode:
332 target.cpu_detection_unimplemented = cpu_detection_unimplemented;332 // * 16bit_mode => if the abi is code16
333 return target;333 // * 32bit_mode => if the arch is i386
334 // However, the "mode" flags can be used as overrides, so if the user explicitly
335 // sets one of them, that takes precedence.
336 switch (cpu_arch) {
337 .i386 => {
338 if (!std.Target.x86.featureSetHasAny(cross_target.cpu_features_add, .{
339 .@"16bit_mode", .@"32bit_mode",
340 })) {
341 switch (result.target.abi) {
342 .code16 => result.target.cpu.features.addFeature(
343 @enumToInt(std.Target.x86.Feature.@"16bit_mode"),
344 ),
345 else => result.target.cpu.features.addFeature(
346 @enumToInt(std.Target.x86.Feature.@"32bit_mode"),
347 ),
348 }
349 }
350 },
351 else => {},
352 }
353 cross_target.updateCpuFeatures(&result.target.cpu.features);
354 result.cpu_detection_unimplemented = cpu_detection_unimplemented;
355 return result;
334 }356 }
335357
336 /// First we attempt to use the executable's own binary. If it is dynamically358 /// First we attempt to use the executable's own binary. If it is dynamically