authorgravatar for leon@makase.roLeon Lombar <leon@makase.ro> 2026-06-18 14:18:47+02:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-06-19 04:22:55+02:00
log84f84267c72b12d4562d53df33e3c0121c7e5cee
tree66b3241a814e73c2abaed7dd185275a062940802
parentd5446652fa22db2e771be9af6ab755e8b199b5c9

std.Target: add PSX

Adds target info for the PSX. Builds fine with the following: ```zig const target = b.resolveTargetQuery(.{ .os_tag = .psx, .cpu_arch = .mipsel, }); ``` the only "problem" being that it spits out an error from LLVM even though generating an object file succeeds: ```sh ❯ zig build install └─ install generated to main.o └─ compile obj obj Debug mipsel-psx failure error: warning: MIPS-I support is experimental ```

9 files changed, 63 insertions(+), 4 deletions(-)

lib/std/Build/Configuration.zig+3
......@@ -2591,6 +2591,7 @@ pub const TargetQuery = struct {
25912591 uefi,
25922592 @"3ds",
25932593 wiiu,
2594 psx,
25942595 ps3,
25952596 ps4,
25962597 ps5,
......@@ -2640,6 +2641,7 @@ pub const TargetQuery = struct {
26402641 .uefi => .uefi,
26412642 .@"3ds" => .@"3ds",
26422643 .wiiu => .wiiu,
2644 .psx => .psx,
26432645 .ps3 => .ps3,
26442646 .ps4 => .ps4,
26452647 .ps5 => .ps5,
......@@ -2689,6 +2691,7 @@ pub const TargetQuery = struct {
26892691 .uefi => .uefi,
26902692 .@"3ds" => .@"3ds",
26912693 .wiiu => .wiiu,
2694 .psx => .psx,
26922695 .ps3 => .ps3,
26932696 .ps4 => .ps4,
26942697 .ps5 => .ps5,
lib/std/Target.zig+15-1
......@@ -51,6 +51,7 @@ pub const Os = struct {
5151 @"3ds",
5252 wiiu,
5353
54 psx,
5455 ps3,
5556 ps4,
5657 ps5,
......@@ -166,6 +167,7 @@ pub const Os = struct {
166167 .plan9,
167168 .serenity,
168169
170 .psx,
169171 .ps3,
170172 .ps4,
171173 .ps5,
......@@ -402,6 +404,7 @@ pub const Os = struct {
402404 .plan9,
403405 .serenity,
404406
407 .psx,
405408 .ps3,
406409 .ps4,
407410 .ps5,
......@@ -949,6 +952,7 @@ pub const Abi = enum {
949952 .uefi => .msvc,
950953 .@"3ds" => .eabihf,
951954 .wiiu => .eabihf,
955 .psx => .eabi,
952956 .psp => .eabihf,
953957 .vita => .eabihf,
954958 .wasi, .emscripten => .musl,
......@@ -2098,6 +2102,7 @@ pub const Cpu = struct {
20982102 .m68k => &m68k.cpu.M68030,
20992103 .mips => &mips.cpu.mips32r2,
21002104 .mipsel => switch (os.tag) {
2105 .psx => &mips.cpu.r3000a,
21012106 .psp => &mips.cpu.allegrex,
21022107 else => &mips.cpu.mips32r2,
21032108 },
......@@ -2290,11 +2295,12 @@ pub fn requiresLibC(target: *const Target) bool {
22902295 .freestanding,
22912296 .fuchsia,
22922297 .managarm,
2293 .ps3,
22942298 .rtems,
22952299 .cuda,
22962300 .nvcl,
22972301 .amdhsa,
2302 .psx,
2303 .ps3,
22982304 .ps4,
22992305 .ps5,
23002306 .psp,
......@@ -2475,6 +2481,7 @@ pub const DynamicLinker = struct {
24752481 .opengl,
24762482 .vulkan,
24772483
2484 .psx,
24782485 .ps3,
24792486 .ps4,
24802487 .ps5,
......@@ -2886,6 +2893,7 @@ pub const DynamicLinker = struct {
28862893 .@"3ds",
28872894 .wiiu,
28882895
2896 .psx,
28892897 .psp,
28902898 .vita,
28912899
......@@ -3445,6 +3453,12 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) u16 {
34453453 .longlong, .ulonglong, .double, .longdouble => return 64,
34463454 },
34473455
3456 .psx => switch (c_type) {
3457 .char => return 8,
3458 .short, .ushort => return 16,
3459 .int, .uint, .long, .ulong, .float => return 32,
3460 .longlong, .ulonglong, .double, .longdouble => return 64,
3461 },
34483462 .ps4, .ps5 => switch (c_type) {
34493463 .char => return 8,
34503464 .short, .ushort => return 16,
lib/std/Target/mips.zig+9
......@@ -587,4 +587,13 @@ pub const cpu = struct {
587587 .p5600,
588588 }),
589589 };
590 pub const r3000a: CpuModel = .{
591 .name = "r3000a",
592 .llvm_name = null,
593 .features = featureSet(&[_]Feature{
594 .mips1,
595 .notraps,
596 .soft_float,
597 }),
598 };
590599};
lib/std/debug.zig+10-1
......@@ -507,7 +507,16 @@ pub fn defaultPanic(msg: []const u8, first_trace_addr: ?usize) noreturn {
507507 if (use_trap_panic) @trap();
508508
509509 switch (builtin.os.tag) {
510 .freestanding, .other, .@"3ds", .wiiu, .psp, .vita => {
510 .freestanding,
511 .other,
512
513 .@"3ds",
514 .wiiu,
515
516 .psx,
517 .psp,
518 .vita,
519 => {
511520 @trap();
512521 },
513522 .uefi => {
lib/std/start.zig+13-1
......@@ -70,7 +70,19 @@ comptime {
7070 // case it's not required to provide an entrypoint such as main.
7171 if (!@hasDecl(root, start_sym_name) and @hasDecl(root, "main")) @export(&wasm_freestanding_start, .{ .name = start_sym_name });
7272 } else switch (native_os) {
73 .other, .freestanding, .@"3ds", .wiiu, .psp, .vita, .vulkan, .opengl, .opencl => {},
73 .other,
74 .freestanding,
75 .vulkan,
76 .opengl,
77 .opencl,
78
79 .@"3ds",
80 .wiiu,
81
82 .psx,
83 .psp,
84 .vita,
85 => {},
7486 else => if (!@hasDecl(root, start_sym_name)) @export(&_start, .{ .name = start_sym_name }),
7587 }
7688 }
src/Compilation.zig+1
......@@ -6354,6 +6354,7 @@ fn addCommonCCArgs(
63546354 // Homebrew targets without LLVM support; use communities's preferred macros.
63556355 .@"3ds" => try argv.append("-D__3DS__"),
63566356 .wiiu => try argv.append("-D__WIIU__"),
6357 .psx => try argv.append("-D__psx__"),
63576358 .psp => try argv.append("-D__PSP__"),
63586359 .vita => try argv.append("-D__vita__"),
63596360 else => {},
src/codegen/llvm.zig+2-1
......@@ -243,9 +243,10 @@ pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8
243243 .opengl,
244244 .other,
245245 .plan9,
246 .psx,
246247 .psp,
247 .tios,
248248 .vita,
249 .tios,
249250 .wiiu,
250251 => "unknown",
251252 };
test/llvm_targets.zig+1
......@@ -154,6 +154,7 @@ const targets = [_]std.Target.Query{
154154 .{ .cpu_arch = .mipsel, .os_tag = .linux, .abi = .musleabihf },
155155 .{ .cpu_arch = .mipsel, .os_tag = .netbsd, .abi = .eabi },
156156 .{ .cpu_arch = .mipsel, .os_tag = .netbsd, .abi = .eabihf },
157 .{ .cpu_arch = .mipsel, .os_tag = .psx, .abi = .eabi },
157158 .{ .cpu_arch = .mipsel, .os_tag = .psp, .abi = .eabihf },
158159 .{ .cpu_arch = .mipsel, .os_tag = .rtems, .abi = .eabi },
159160 .{ .cpu_arch = .mipsel, .os_tag = .rtems, .abi = .eabihf },
tools/update_cpu_features.zig+9
......@@ -1358,6 +1358,15 @@ const targets = [_]ArchTarget{
13581358 },
13591359 },
13601360 .extra_cpus = &.{
1361 .{
1362 .llvm_name = null,
1363 .zig_name = "r3000a",
1364 .features = &.{
1365 "mips1",
1366 "soft_float",
1367 "notraps",
1368 },
1369 },
13611370 .{
13621371 .llvm_name = null,
13631372 .zig_name = "allegrex",