authorgravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-03-25 00:51:01+01:00
committergravatar for alex@alexrp.comAlex Rønne Petersen <alex@alexrp.com> 2026-03-25 00:51:01+01:00
logb0ab55b8ea82145aba23accdf480efe5632660fd
treead1a50d92ee16c357c40289a3153f3e49b49a1d4
parent558a5c7913434547c55355af0075a9d34db0d4bc
parent164d01c1dc258068c23016ec2110e2b6080b8a2d

Merge pull request 'Add psp os' (#31609) from IridescentRose/zig:psp-os-target into master

Reviewed-on: https://codeberg.org/ziglang/zig/pulls/31609 Reviewed-by: Andrew Kelley <andrew@ziglang.org> Reviewed-by: Alex Rønne Petersen <alex@alexrp.com>

9 files changed, 98 insertions(+), 5 deletions(-)

lib/std/Io/Dir.zig+1-1
......@@ -52,7 +52,7 @@ pub const max_path_bytes = switch (native_os) {
5252/// On WASI, file name components are encoded as valid UTF-8.
5353/// On other platforms, `[]u8` components are an opaque sequence of bytes with no particular encoding.
5454pub const max_name_bytes = switch (native_os) {
55 .linux, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .freebsd, .openbsd, .netbsd, .dragonfly, .illumos, .serenity => std.posix.NAME_MAX,
55 .linux, .driverkit, .ios, .maccatalyst, .macos, .tvos, .visionos, .watchos, .freebsd, .openbsd, .netbsd, .dragonfly, .illumos, .serenity, .psp => std.posix.NAME_MAX,
5656 // Haiku's NAME_MAX includes the null terminator, so subtract one.
5757 .haiku => std.posix.NAME_MAX - 1,
5858 // Each WTF-16LE character may be expanded to 3 WTF-8 bytes.
lib/std/Target.zig+20-2
......@@ -53,6 +53,7 @@ pub const Os = struct {
5353 ps3,
5454 ps4,
5555 ps5,
56 psp,
5657 vita,
5758
5859 emscripten,
......@@ -194,6 +195,7 @@ pub const Os = struct {
194195
195196 .@"3ds",
196197
198 .psp,
197199 .vita,
198200
199201 .wasi,
......@@ -612,6 +614,15 @@ pub const Os = struct {
612614 },
613615 },
614616
617 .psp => .{
618 .semver = .{
619 // https://www.psdevwiki.com/psp/Official_Firmware_(OFW)#1.XX_Kernel
620 // It appears that the kernel started with semver for 1.XX before later changing to MAJ.MINPATCH in later releases (e.g. 3.60, 6.61)
621 .min = .{ .major = 1, .minor = 0, .patch = 3 },
622 .max = .{ .major = 6, .minor = 61, .patch = 0 },
623 },
624 },
625
615626 .vita => .{
616627 .semver = .{
617628 // 1.3 is the first public release
......@@ -919,6 +930,7 @@ pub const Abi = enum {
919930 .tvos,
920931 .visionos,
921932 .watchos,
933 .psp,
922934 .ps3,
923935 .ps4,
924936 .ps5,
......@@ -2023,7 +2035,10 @@ pub const Cpu = struct {
20232035 .lanai => &lanai.cpu.v11, // clang does not have a generic lanai model.
20242036 .loongarch64 => &loongarch.cpu.la64v1_0,
20252037 .m68k => &m68k.cpu.M68000,
2026 .mips, .mipsel => &mips.cpu.mips32r2,
2038 .mips, .mipsel => switch (os.tag) {
2039 .psp => &mips.cpu.allegrex,
2040 else => &mips.cpu.mips32r2,
2041 },
20272042 .mips64, .mips64el => &mips.cpu.mips64r2,
20282043 .msp430 => &msp430.cpu.msp430,
20292044 .nvptx, .nvptx64 => &nvptx.cpu.sm_52,
......@@ -2204,6 +2219,7 @@ pub fn requiresLibC(target: *const Target) bool {
22042219 .amdhsa,
22052220 .ps4,
22062221 .ps5,
2222 .psp,
22072223 .vita,
22082224 .mesa3d,
22092225 .contiki,
......@@ -2379,6 +2395,7 @@ pub const DynamicLinker = struct {
23792395 .ps3,
23802396 .ps4,
23812397 .ps5,
2398 .psp,
23822399 .vita,
23832400 => .none,
23842401 };
......@@ -2783,6 +2800,7 @@ pub const DynamicLinker = struct {
27832800
27842801 .@"3ds",
27852802
2803 .psp,
27862804 .vita,
27872805
27882806 .emscripten,
......@@ -3338,7 +3356,7 @@ pub fn cTypeBitSize(target: *const Target, c_type: CType) u16 {
33383356 .longlong, .ulonglong, .double => return 64,
33393357 .longdouble => return 80,
33403358 },
3341 .vita => switch (c_type) {
3359 .psp, .vita => switch (c_type) {
33423360 .char => return 8,
33433361 .short, .ushort => return 16,
33443362 .int, .uint, .float => return 32,
lib/std/Target/mips.zig+15
......@@ -49,6 +49,7 @@ pub const Feature = enum {
4949 noabicalls,
5050 nomadd4,
5151 nooddspreg,
52 notraps,
5253 p5600,
5354 ptr64,
5455 single_float,
......@@ -353,6 +354,11 @@ pub const all_features = blk: {
353354 .description = "Disable odd numbered single-precision registers",
354355 .dependencies = featureSet(&[_]Feature{}),
355356 };
357 result[@intFromEnum(Feature.notraps)] = .{
358 .llvm_name = null,
359 .description = "Disable trap instructions",
360 .dependencies = featureSet(&[_]Feature{}),
361 };
356362 result[@intFromEnum(Feature.p5600)] = .{
357363 .llvm_name = "p5600",
358364 .description = "The P5600 Processor",
......@@ -419,6 +425,15 @@ pub const all_features = blk: {
419425};
420426
421427pub const cpu = struct {
428 pub const allegrex: CpuModel = .{
429 .name = "allegrex",
430 .llvm_name = null,
431 .features = featureSet(&[_]Feature{
432 .mips2,
433 .notraps,
434 .single_float,
435 }),
436 };
422437 pub const generic: CpuModel = .{
423438 .name = "generic",
424439 .llvm_name = "generic",
lib/std/heap.zig+10
......@@ -805,6 +805,11 @@ const page_size_min_default: ?usize = switch (builtin.os.tag) {
805805 .x86, .x86_64 => 16 << 10,
806806 else => null,
807807 },
808 .psp => switch (builtin.cpu.arch) {
809 // minimum block allocation by testing sceKernel
810 .mips, .mipsel => 1 << 8, // 256
811 else => null,
812 },
808813 // system/lib/libc/musl/arch/emscripten/bits/limits.h
809814 .emscripten => 64 << 10,
810815 .linux => switch (builtin.cpu.arch) {
......@@ -963,6 +968,11 @@ const page_size_max_default: ?usize = switch (builtin.os.tag) {
963968 .x86, .x86_64 => 16 << 10,
964969 else => null,
965970 },
971 .psp => switch (builtin.cpu.arch) {
972 // minimum block allocation by testing sceKernel
973 .mips, .mipsel => 1 << 8, // 256
974 else => null,
975 },
966976 // system/lib/libc/musl/arch/emscripten/bits/limits.h
967977 .emscripten => 64 << 10,
968978 .linux => switch (builtin.cpu.arch) {
lib/std/posix.zig+16
......@@ -38,6 +38,22 @@ pub const system = if (use_libc)
3838else switch (native_os) {
3939 .linux => linux,
4040 .plan9 => std.os.plan9,
41 .psp => struct {
42 pub const fd_t = i32;
43 pub const pid_t = void;
44 pub const pollfd = void;
45 pub const uid_t = void;
46 pub const gid_t = void;
47 pub const mode_t = u32;
48 pub const nlink_t = u32;
49 pub const blksize_t = u32;
50 pub const ino_t = u64;
51 pub const IFNAMESIZE = {};
52 pub const SIG = void;
53
54 // https://github.com/pspdev/newlib/blob/9e0a073634ad73e8e088f2e071c55a9fe5d39709/newlib/libc/sys/psp/sys/dirent.h#L19
55 pub const NAME_MAX = 255;
56 },
4157 else => struct {
4258 pub const pid_t = void;
4359 pub const pollfd = void;
lib/std/start.zig+1-1
......@@ -65,7 +65,7 @@ comptime {
6565 // case it's not required to provide an entrypoint such as main.
6666 if (!@hasDecl(root, start_sym_name) and @hasDecl(root, "main")) @export(&wasm_freestanding_start, .{ .name = start_sym_name });
6767 } else switch (native_os) {
68 .other, .freestanding, .@"3ds", .vita => {},
68 .other, .freestanding, .@"3ds", .psp, .vita => {},
6969 else => if (!@hasDecl(root, start_sym_name)) @export(&_start, .{ .name = start_sym_name }),
7070 }
7171 }
src/Compilation.zig+1
......@@ -6424,6 +6424,7 @@ fn addCommonCCArgs(
64246424 .illumos => try argv.append("__illumos__"),
64256425 // Homebrew targets without LLVM support; use communities's preferred macros.
64266426 .@"3ds" => try argv.append("-D__3DS__"),
6427 .psp => try argv.append("-D__PSP__"),
64276428 .vita => try argv.append("-D__vita__"),
64286429 else => {},
64296430 }
src/codegen/llvm.zig+20-1
......@@ -247,6 +247,7 @@ pub fn targetTriple(allocator: Allocator, target: *const std.Target) ![]const u8
247247 .opengl,
248248 .other,
249249 .plan9,
250 .psp,
250251 .vita,
251252 => "unknown",
252253 };
......@@ -9536,7 +9537,25 @@ pub const FuncGen = struct {
95369537
95379538 fn airTrap(self: *FuncGen, inst: Air.Inst.Index) !void {
95389539 _ = inst;
9539 _ = try self.wip.callIntrinsic(.normal, .none, .trap, &.{}, &.{}, "");
9540 const target = self.ng.object.target;
9541 if ((target.cpu.arch == .mips or target.cpu.arch == .mipsel) and
9542 target.cpu.has(.mips, .notraps))
9543 {
9544 // Emit a MIPS `break` instruction followed by an infinite loop (to fulfill the noreturn)
9545 // since this CPU does not support trap instructions.
9546 const o = self.ng.object;
9547 _ = try self.wip.callAsm(
9548 .none,
9549 try o.builder.fnType(.void, &.{}, .normal),
9550 .{ .sideeffect = true },
9551 try o.builder.string("break\n0:\nj 0b\nnop"),
9552 try o.builder.string("~{memory}"),
9553 &.{},
9554 "",
9555 );
9556 } else {
9557 _ = try self.wip.callIntrinsic(.normal, .none, .trap, &.{}, &.{}, "");
9558 }
95409559 _ = try self.wip.@"unreachable"();
95419560 }
95429561
tools/update_cpu_features.zig+14
......@@ -1299,6 +1299,20 @@ const targets = [_]ArchTarget{
12991299 .name = "Mips",
13001300 .td_name = "Mips",
13011301 },
1302 .extra_features = &.{
1303 .{
1304 .zig_name = "notraps",
1305 .desc = "Disable trap instructions",
1306 .deps = &.{},
1307 },
1308 },
1309 .extra_cpus = &.{
1310 .{
1311 .llvm_name = null,
1312 .zig_name = "allegrex",
1313 .features = &.{ "mips2", "single_float", "notraps" },
1314 },
1315 },
13021316 },
13031317 .{
13041318 .zig_name = "nvptx",