commit 84f84267c72b12d4562d53df33e3c0121c7e5cee (tree)
parent d5446652fa22db2e771be9af6ab755e8b199b5c9
Author: Leon Lombar <leon@makase.ro>
Date: Thu, 18 Jun 2026 14:18:47 +0200
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
```
Diffstat:
9 files changed, 63 insertions(+), 4 deletions(-)
diff --git a/lib/std/Build/Configuration.zig b/lib/std/Build/Configuration.zig
@@ -2591,6 +2591,7 @@ pub const TargetQuery = struct {
uefi,
@"3ds",
wiiu,
+ psx,
ps3,
ps4,
ps5,
@@ -2640,6 +2641,7 @@ pub const TargetQuery = struct {
.uefi => .uefi,
.@"3ds" => .@"3ds",
.wiiu => .wiiu,
+ .psx => .psx,
.ps3 => .ps3,
.ps4 => .ps4,
.ps5 => .ps5,
@@ -2689,6 +2691,7 @@ pub const TargetQuery = struct {
.uefi => .uefi,
.@"3ds" => .@"3ds",
.wiiu => .wiiu,
+ .psx => .psx,
.ps3 => .ps3,
.ps4 => .ps4,
.ps5 => .ps5,
diff --git a/lib/std/Target.zig b/lib/std/Target.zig
@@ -51,6 +51,7 @@ pub const Os = struct {
@"3ds",
wiiu,
+ psx,
ps3,
ps4,
ps5,
@@ -166,6 +167,7 @@ pub const Os = struct {
.plan9,
.serenity,
+ .psx,
.ps3,
.ps4,
.ps5,
@@ -402,6 +404,7 @@ pub const Os = struct {
.plan9,
.serenity,
+ .psx,
.ps3,
.ps4,
.ps5,
@@ -949,6 +952,7 @@ pub const Abi = enum {
.uefi => .msvc,
.@"3ds" => .eabihf,
.wiiu => .eabihf,
+ .psx => .eabi,
.psp => .eabihf,
.vita => .eabihf,
.wasi, .emscripten => .musl,
@@ -2098,6 +2102,7 @@ pub const Cpu = struct {
.m68k => &m68k.cpu.M68030,
.mips => &mips.cpu.mips32r2,
.mipsel => switch (os.tag) {
+ .psx => &mips.cpu.r3000a,
.psp => &mips.cpu.allegrex,
else => &mips.cpu.mips32r2,
},
@@ -2290,11 +2295,12 @@ pub fn requiresLibC(target: *const Target) bool {
.freestanding,
.fuchsia,
.managarm,
- .ps3,
.rtems,
.cuda,
.nvcl,
.amdhsa,
+ .psx,
+ .ps3,
.ps4,
.ps5,
.psp,
@@ -2475,6 +2481,7 @@ pub const DynamicLinker = struct {
.opengl,
.vulkan,
+ .psx,
.ps3,
.ps4,
.ps5,
@@ -2886,6 +2893,7 @@ pub const DynamicLinker = struct {
.@"3ds",
.wiiu,
+ .psx,
.psp,
.vita,
@@ -3445,6 +3453,12 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) u16 {
.longlong, .ulonglong, .double, .longdouble => return 64,
},
+ .psx => switch (c_type) {
+ .char => return 8,
+ .short, .ushort => return 16,
+ .int, .uint, .long, .ulong, .float => return 32,
+ .longlong, .ulonglong, .double, .longdouble => return 64,
+ },
.ps4, .ps5 => switch (c_type) {
.char => return 8,
.short, .ushort => return 16,
diff --git a/lib/std/Target/mips.zig b/lib/std/Target/mips.zig
@@ -587,4 +587,13 @@ pub const cpu = struct {
.p5600,
}),
};
+ pub const r3000a: CpuModel = .{
+ .name = "r3000a",
+ .llvm_name = null,
+ .features = featureSet(&[_]Feature{
+ .mips1,
+ .notraps,
+ .soft_float,
+ }),
+ };
};
diff --git a/lib/std/debug.zig b/lib/std/debug.zig
@@ -507,7 +507,16 @@ pub fn defaultPanic(msg: []const u8, first_trace_addr: ?usize) noreturn {
if (use_trap_panic) @trap();
switch (builtin.os.tag) {
- .freestanding, .other, .@"3ds", .wiiu, .psp, .vita => {
+ .freestanding,
+ .other,
+
+ .@"3ds",
+ .wiiu,
+
+ .psx,
+ .psp,
+ .vita,
+ => {
@trap();
},
.uefi => {
diff --git a/lib/std/start.zig b/lib/std/start.zig
@@ -70,7 +70,19 @@ comptime {
// case it's not required to provide an entrypoint such as main.
if (!@hasDecl(root, start_sym_name) and @hasDecl(root, "main")) @export(&wasm_freestanding_start, .{ .name = start_sym_name });
} else switch (native_os) {
- .other, .freestanding, .@"3ds", .wiiu, .psp, .vita, .vulkan, .opengl, .opencl => {},
+ .other,
+ .freestanding,
+ .vulkan,
+ .opengl,
+ .opencl,
+
+ .@"3ds",
+ .wiiu,
+
+ .psx,
+ .psp,
+ .vita,
+ => {},
else => if (!@hasDecl(root, start_sym_name)) @export(&_start, .{ .name = start_sym_name }),
}
}
diff --git a/src/Compilation.zig b/src/Compilation.zig
@@ -6354,6 +6354,7 @@ fn addCommonCCArgs(
// Homebrew targets without LLVM support; use communities's preferred macros.
.@"3ds" => try argv.append("-D__3DS__"),
.wiiu => try argv.append("-D__WIIU__"),
+ .psx => try argv.append("-D__psx__"),
.psp => try argv.append("-D__PSP__"),
.vita => try argv.append("-D__vita__"),
else => {},
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig
@@ -243,9 +243,10 @@ pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8
.opengl,
.other,
.plan9,
+ .psx,
.psp,
- .tios,
.vita,
+ .tios,
.wiiu,
=> "unknown",
};
diff --git a/test/llvm_targets.zig b/test/llvm_targets.zig
@@ -154,6 +154,7 @@ const targets = [_]std.Target.Query{
.{ .cpu_arch = .mipsel, .os_tag = .linux, .abi = .musleabihf },
.{ .cpu_arch = .mipsel, .os_tag = .netbsd, .abi = .eabi },
.{ .cpu_arch = .mipsel, .os_tag = .netbsd, .abi = .eabihf },
+ .{ .cpu_arch = .mipsel, .os_tag = .psx, .abi = .eabi },
.{ .cpu_arch = .mipsel, .os_tag = .psp, .abi = .eabihf },
.{ .cpu_arch = .mipsel, .os_tag = .rtems, .abi = .eabi },
.{ .cpu_arch = .mipsel, .os_tag = .rtems, .abi = .eabihf },
diff --git a/tools/update_cpu_features.zig b/tools/update_cpu_features.zig
@@ -1360,6 +1360,15 @@ const targets = [_]ArchTarget{
.extra_cpus = &.{
.{
.llvm_name = null,
+ .zig_name = "r3000a",
+ .features = &.{
+ "mips1",
+ "soft_float",
+ "notraps",
+ },
+ },
+ .{
+ .llvm_name = null,
.zig_name = "allegrex",
.features = &.{ "mips2", "single_float", "notraps" },
},