authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2025-10-30 01:41:32+01:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-10-30 01:41:32+01:00
log767f28d7a631cc0e235dc3f6bbd260395a911010
tree3d334693ac465b9728c2590bd69bc5de7a817435
parent09aa4add2a00454077b5421204acf5e96b6d51cf
parentef4f6e6c0578288144760437231620efbdb1edd6
signaturebadge-check Signed by PGP key B5690EEEBB952194

Merge pull request #25733 from GasInfinity-Forks/x86_16-cpu_context

* fix: add `i86` cpu in `update_cpu_features` * feat: add `x86_16` debug `cpu_context`

3 files changed, 51 insertions(+), 1 deletions(-)

lib/std/Target/x86.zig+3-1
......@@ -3084,7 +3084,9 @@ pub const cpu = struct {
30843084 pub const @"i86": CpuModel = .{
30853085 .name = "i86",
30863086 .llvm_name = null,
3087 .features = featureSet(&[_]Feature{}),
3087 .features = featureSet(&[_]Feature{
3088 .@"16bit_mode",
3089 }),
30883090 };
30893091 pub const @"i386": CpuModel = .{
30903092 .name = "i386",
lib/std/debug/cpu_context.zig+41
......@@ -19,6 +19,7 @@ else switch (native_arch) {
1919 .riscv32, .riscv32be, .riscv64, .riscv64be => Riscv,
2020 .ve => Ve,
2121 .s390x => S390x,
22 .x86_16 => X86_16,
2223 .x86 => X86,
2324 .x86_64 => X86_64,
2425 else => noreturn,
......@@ -1350,6 +1351,46 @@ const Ve = extern struct {
13501351 }
13511352};
13521353
1354const X86_16 = struct {
1355 pub const Register = enum {
1356 // zig fmt: off
1357 sp, bp, ss,
1358 ip, cs,
1359 // zig fmt: on
1360 };
1361
1362 regs: std.enums.EnumArray(Register, u16),
1363
1364 pub inline fn current() X86_16 {
1365 var ctx: X86_16 = undefined;
1366 asm volatile (
1367 \\ movw %%sp, 0x00(%%di)
1368 \\ movw %%bp, 0x02(%%di)
1369 \\ movw %%ss, 0x04(%%di)
1370 \\ pushw %%cs
1371 \\ call 1f
1372 \\1:
1373 \\ popw 0x06(%%di)
1374 \\ popw 0x08(%%di)
1375 :
1376 : [gprs] "{di}" (&ctx.regs.values),
1377 : .{ .memory = true });
1378 return ctx;
1379 }
1380
1381 // NOTE: There doesn't seem to be any standard for DWARF x86-16 so we'll just reuse the ones for x86.
1382 pub fn dwarfRegisterBytes(ctx: *X86_16, register_num: u16) DwarfRegisterError![]u8 {
1383 switch (register_num) {
1384 4 => return @ptrCast(ctx.regs.getPtr(.sp)),
1385 5 => return @ptrCast(ctx.regs.getPtr(.bp)),
1386 6 => return @ptrCast(ctx.regs.getPtr(.ip)),
1387 41 => return @ptrCast(ctx.regs.getPtr(.cs)),
1388 42 => return @ptrCast(ctx.regs.getPtr(.ss)),
1389 else => return error.InvalidRegister,
1390 }
1391 }
1392};
1393
13531394const X86 = struct {
13541395 /// The first 8 registers here intentionally match the order of registers in the x86 instruction
13551396 /// encoding. This order is inherited by the PUSHA instruction and the DWARF register mappings,
tools/update_cpu_features.zig+7
......@@ -1563,6 +1563,13 @@ const targets = [_]ArchTarget{
15631563 .deps = &.{},
15641564 },
15651565 },
1566 .extra_cpus = &.{
1567 .{
1568 .llvm_name = null,
1569 .zig_name = "i86",
1570 .features = &.{"16bit_mode"},
1571 },
1572 },
15661573 .omit_cpus = &.{
15671574 // LLVM defines a bunch of dumb aliases with foreach loops in X86.td.
15681575 "pentium_mmx",