Skip to content

Commit 70206af

Browse files
authored
Merge pull request #25640 from alexrp/std-target-more-arches
`std.Target`: add tags and info for alpha, hppa, microblaze, sh + some bonus commits
2 parents e5fcc81 + 07d764d commit 70206af

25 files changed

+1318
-284
lines changed

lib/std/Target.zig

Lines changed: 375 additions & 151 deletions
Large diffs are not rendered by default.

lib/std/Thread.zig

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1235,6 +1235,18 @@ const LinuxThreadImpl = struct {
12351235
: [ptr] "r" (@intFromPtr(self.mapped.ptr)),
12361236
[len] "r" (self.mapped.len),
12371237
: .{ .memory = true }),
1238+
.alpha => asm volatile (
1239+
\\ ldi $0, 73 # SYS_munmap
1240+
\\ mov %[ptr], $16
1241+
\\ mov %[len], $17
1242+
\\ callsys
1243+
\\ ldi $0, 1 # SYS_exit
1244+
\\ ldi $16, 0
1245+
\\ callsys
1246+
:
1247+
: [ptr] "r" (@intFromPtr(self.mapped.ptr)),
1248+
[len] "r" (self.mapped.len),
1249+
: .{ .memory = true }),
12381250
.hexagon => asm volatile (
12391251
\\ r6 = #215 // SYS_munmap
12401252
\\ r0 = %[ptr]
@@ -1247,6 +1259,42 @@ const LinuxThreadImpl = struct {
12471259
: [ptr] "r" (@intFromPtr(self.mapped.ptr)),
12481260
[len] "r" (self.mapped.len),
12491261
: .{ .memory = true }),
1262+
.hppa => asm volatile (
1263+
\\ ldi 91, %%r20 /* SYS_munmap */
1264+
\\ copy %[ptr], %%r26
1265+
\\ copy %[len], %%r25
1266+
\\ ble 0x100(%%sr2, %%r0)
1267+
\\ ldi 1, %%r20 /* SYS_exit */
1268+
\\ ldi 0, %%r26
1269+
\\ ble 0x100(%%sr2, %%r0)
1270+
:
1271+
: [ptr] "r" (@intFromPtr(self.mapped.ptr)),
1272+
[len] "r" (self.mapped.len),
1273+
: .{ .memory = true }),
1274+
.m68k => asm volatile (
1275+
\\ move.l #91, %%d0 // SYS_munmap
1276+
\\ move.l %[ptr], %%d1
1277+
\\ move.l %[len], %%d2
1278+
\\ trap #0
1279+
\\ move.l #1, %%d0 // SYS_exit
1280+
\\ move.l #0, %%d1
1281+
\\ trap #0
1282+
:
1283+
: [ptr] "r" (@intFromPtr(self.mapped.ptr)),
1284+
[len] "r" (self.mapped.len),
1285+
: .{ .memory = true }),
1286+
.microblaze, .microblazeel => asm volatile (
1287+
\\ ori r12, r0, 91 # SYS_munmap
1288+
\\ ori r5, %[ptr], 0
1289+
\\ ori r6, %[len], 0
1290+
\\ brki r14, 0x8
1291+
\\ ori r12, r0, 1 # SYS_exit
1292+
\\ or r5, r0, r0
1293+
\\ brki r14, 0x8
1294+
:
1295+
: [ptr] "r" (@intFromPtr(self.mapped.ptr)),
1296+
[len] "r" (self.mapped.len),
1297+
: .{ .memory = true }),
12501298
// We set `sp` to the address of the current function as a workaround for a Linux
12511299
// kernel bug that caused syscalls to return EFAULT if the stack pointer is invalid.
12521300
// The bug was introduced in 46e12c07b3b9603c60fc1d421ff18618241cb081 and fixed in
@@ -1335,6 +1383,28 @@ const LinuxThreadImpl = struct {
13351383
: [ptr] "r" (@intFromPtr(self.mapped.ptr)),
13361384
[len] "r" (self.mapped.len),
13371385
: .{ .memory = true }),
1386+
.sh, .sheb => asm volatile (
1387+
\\ mov #91, r3 ! SYS_munmap
1388+
\\ mov %[ptr], r4
1389+
\\ mov %[len], r5
1390+
\\ trapa #31
1391+
\\ or r0, r0
1392+
\\ or r0, r0
1393+
\\ or r0, r0
1394+
\\ or r0, r0
1395+
\\ or r0, r0
1396+
\\ mov #1, r3 ! SYS_exit
1397+
\\ mov #0, r4
1398+
\\ trapa #31
1399+
\\ or r0, r0
1400+
\\ or r0, r0
1401+
\\ or r0, r0
1402+
\\ or r0, r0
1403+
\\ or r0, r0
1404+
:
1405+
: [ptr] "r" (@intFromPtr(self.mapped.ptr)),
1406+
[len] "r" (self.mapped.len),
1407+
: .{ .memory = true }),
13381408
.sparc => asm volatile (
13391409
\\ # See sparc64 comments below.
13401410
\\ 1:

lib/std/atomic.zig

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,7 @@ pub fn cacheLineForCpu(cpu: std.Target.Cpu) u16 {
419419
.aarch64,
420420
.aarch64_be,
421421
.arc,
422+
.arceb,
422423
.powerpc64,
423424
.powerpc64le,
424425
=> 128,
@@ -432,20 +433,29 @@ pub fn cacheLineForCpu(cpu: std.Target.Cpu) u16 {
432433
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_mipsle.go#L7
433434
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_mips64x.go#L9
434435
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/sparc/include/asm/cache.h#L14
436+
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/microblaze/include/asm/cache.h#L15
437+
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/sh/include/cpu-sh4/cpu/cache.h#L10
435438
.arm,
436439
.armeb,
437440
.thumb,
438441
.thumbeb,
442+
.microblaze,
443+
.microblazeel,
439444
.mips,
440445
.mipsel,
441446
.mips64,
442447
.mips64el,
448+
.sh,
449+
.sheb,
443450
.sparc,
444451
.sparc64,
445452
=> 32,
446453

447454
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/m68k/include/asm/cache.h#L10
448455
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/openrisc/include/asm/cache.h#L24
456+
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/parisc/include/asm/cache.h#L16
457+
.hppa,
458+
.hppa64,
449459
.m68k,
450460
.or1k,
451461
=> 16,
@@ -468,6 +478,7 @@ pub fn cacheLineForCpu(cpu: std.Target.Cpu) u16 {
468478
// - https://github.com/golang/go/blob/19e923182e590ae6568c2c714f20f32512aeb3e3/src/internal/cpu/cpu_riscv64.go#L7
469479
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/xtensa/variants/csp/include/variant/core.h#L209
470480
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/csky/Kconfig#L183
481+
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/alpha/include/asm/cache.h#L11
471482
// - https://www.xmos.com/download/The-XMOS-XS3-Architecture.pdf
472483
else => 64,
473484
};

lib/std/builtin.zig

Lines changed: 85 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,7 @@ pub const CallingConvention = union(enum(u8)) {
204204

205205
// Calling conventions for the `x86_64` architecture.
206206
x86_64_sysv: CommonOptions,
207+
x86_64_x32: CommonOptions,
207208
x86_64_win: CommonOptions,
208209
x86_64_regcall_v3_sysv: CommonOptions,
209210
x86_64_regcall_v4_win: CommonOptions,
@@ -229,6 +230,9 @@ pub const CallingConvention = union(enum(u8)) {
229230
aarch64_vfabi: CommonOptions,
230231
aarch64_vfabi_sve: CommonOptions,
231232

233+
/// The standard `alpha` calling convention.
234+
alpha_osf: CommonOptions,
235+
232236
// Calling convetions for the `arm`, `armeb`, `thumb`, and `thumbeb` architectures.
233237
/// ARM Architecture Procedure Call Standard
234238
arm_aapcs: CommonOptions,
@@ -275,7 +279,7 @@ pub const CallingConvention = union(enum(u8)) {
275279
/// The standard `wasm32` and `wasm64` calling convention, as specified in the WebAssembly Tool Conventions.
276280
wasm_mvp: CommonOptions,
277281

278-
/// The standard `arc` calling convention.
282+
/// The standard `arc`/`arceb` calling convention.
279283
arc_sysv: CommonOptions,
280284
arc_interrupt: ArcInterruptOptions,
281285

@@ -296,6 +300,12 @@ pub const CallingConvention = union(enum(u8)) {
296300
hexagon_sysv: CommonOptions,
297301
hexagon_sysv_hvx: CommonOptions,
298302

303+
/// The standard `hppa` calling convention.
304+
hppa_elf: CommonOptions,
305+
306+
/// The standard `hppa64` calling convention.
307+
hppa64_elf: CommonOptions,
308+
299309
/// The standard `lanai` calling convention.
300310
lanai_sysv: CommonOptions,
301311

@@ -311,8 +321,13 @@ pub const CallingConvention = union(enum(u8)) {
311321
m68k_rtd: CommonOptions,
312322
m68k_interrupt: CommonOptions,
313323

324+
/// The standard `microblaze`/`microblazeel` calling convention.
325+
microblaze_std: CommonOptions,
326+
microblaze_interrupt: MicroblazeInterruptOptions,
327+
314328
/// The standard `msp430` calling convention.
315329
msp430_eabi: CommonOptions,
330+
msp430_interrupt: CommonOptions,
316331

317332
/// The standard `or1k` calling convention.
318333
or1k_sysv: CommonOptions,
@@ -324,14 +339,19 @@ pub const CallingConvention = union(enum(u8)) {
324339
s390x_sysv: CommonOptions,
325340
s390x_sysv_vx: CommonOptions,
326341

342+
// Calling conventions for the `sh`/`sheb` architecture.
343+
sh_gnu: CommonOptions,
344+
sh_renesas: CommonOptions,
345+
sh_interrupt: ShInterruptOptions,
346+
327347
/// The standard `ve` calling convention.
328348
ve_sysv: CommonOptions,
329349

330350
// Calling conventions for the `xcore` architecture.
331351
xcore_xs1: CommonOptions,
332352
xcore_xs2: CommonOptions,
333353

334-
// Calling conventions for the `xtensa` architecture.
354+
// Calling conventions for the `xtensa`/`xtensaeb` architecture.
335355
xtensa_call0: CommonOptions,
336356
xtensa_windowed: CommonOptions,
337357

@@ -403,6 +423,25 @@ pub const CallingConvention = union(enum(u8)) {
403423
};
404424
};
405425

426+
/// Options for the `microblaze_interrupt` calling convention.
427+
pub const MicroblazeInterruptOptions = struct {
428+
/// The boundary the stack is aligned to when the function is called.
429+
/// `null` means the default for this calling convention.
430+
incoming_stack_alignment: ?u64 = null,
431+
type: InterruptType = .regular,
432+
433+
pub const InterruptType = enum(u2) {
434+
/// User exception; return with `rtsd`.
435+
user,
436+
/// Regular interrupt; return with `rtid`.
437+
regular,
438+
/// Fast interrupt; return with `rtid`.
439+
fast,
440+
/// Software breakpoint; return with `rtbd`.
441+
breakpoint,
442+
};
443+
};
444+
406445
/// Options for the `mips_interrupt` and `mips64_interrupt` calling conventions.
407446
pub const MipsInterruptOptions = struct {
408447
/// The boundary the stack is aligned to when the function is called.
@@ -438,6 +477,25 @@ pub const CallingConvention = union(enum(u8)) {
438477
};
439478
};
440479

480+
/// Options for the `sh_interrupt` calling convention.
481+
pub const ShInterruptOptions = struct {
482+
/// The boundary the stack is aligned to when the function is called.
483+
/// `null` means the default for this calling convention.
484+
incoming_stack_alignment: ?u64 = null,
485+
save: SaveBehavior = .full,
486+
487+
pub const SaveBehavior = enum(u3) {
488+
/// Save only fpscr (if applicable).
489+
fpscr,
490+
/// Save only high-numbered registers, i.e. r0 through r7 are *not* saved.
491+
high,
492+
/// Save all registers normally.
493+
full,
494+
/// Save all registers using the CPU's fast register bank.
495+
bank,
496+
};
497+
};
498+
441499
/// Returns the array of `std.Target.Cpu.Arch` to which this `CallingConvention` applies.
442500
/// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`.
443501
pub fn archs(cc: CallingConvention) []const std.Target.Cpu.Arch {
@@ -459,21 +517,6 @@ pub const CallingConvention = union(enum(u8)) {
459517
/// This data structure is used by the Zig language code generation and
460518
/// therefore must be kept in sync with the compiler implementation.
461519
pub const AddressSpace = enum(u5) {
462-
/// The places where a user can specify an address space attribute
463-
pub const Context = enum {
464-
/// A function is specified to be placed in a certain address space.
465-
function,
466-
/// A (global) variable is specified to be placed in a certain address space.
467-
/// In contrast to .constant, these values (and thus the address space they will be
468-
/// placed in) are required to be mutable.
469-
variable,
470-
/// A (global) constant value is specified to be placed in a certain address space.
471-
/// In contrast to .variable, values placed in this address space are not required to be mutable.
472-
constant,
473-
/// A pointer is ascripted to point into a certain address space.
474-
pointer,
475-
};
476-
477520
// CPU address spaces.
478521
generic,
479522
gs,
@@ -858,6 +901,13 @@ pub const VaListAarch64 = extern struct {
858901
__vr_offs: c_int,
859902
};
860903

904+
/// This data structure is used by the Zig language code generation and
905+
/// therefore must be kept in sync with the compiler implementation.
906+
pub const VaListAlpha = extern struct {
907+
__base: *anyopaque,
908+
__offset: c_int,
909+
};
910+
861911
/// This data structure is used by the Zig language code generation and
862912
/// therefore must be kept in sync with the compiler implementation.
863913
pub const VaListArm = extern struct {
@@ -891,6 +941,16 @@ pub const VaListS390x = extern struct {
891941
__overflow_area_pointer: *anyopaque,
892942
};
893943

944+
/// This data structure is used by the Zig language code generation and
945+
/// therefore must be kept in sync with the compiler implementation.
946+
pub const VaListSh = extern struct {
947+
__va_next_o: *anyopaque,
948+
__va_next_o_limit: *anyopaque,
949+
__va_next_fp: *anyopaque,
950+
__va_next_fp_limit: *anyopaque,
951+
__va_next_stack: *anyopaque,
952+
};
953+
894954
/// This data structure is used by the Zig language code generation and
895955
/// therefore must be kept in sync with the compiler implementation.
896956
pub const VaListX86_64 = extern struct {
@@ -920,14 +980,19 @@ pub const VaList = switch (builtin.cpu.arch) {
920980
.x86,
921981
=> *u8,
922982
.arc,
983+
.arceb,
923984
.avr,
924985
.bpfel,
925986
.bpfeb,
926987
.csky,
988+
.hppa,
989+
.hppa64,
927990
.lanai,
928991
.loongarch32,
929992
.loongarch64,
930993
.m68k,
994+
.microblaze,
995+
.microblazeel,
931996
.mips,
932997
.mipsel,
933998
.mips64,
@@ -952,21 +1017,23 @@ pub const VaList = switch (builtin.cpu.arch) {
9521017
.stage2_llvm => @compileError("disabled due to miscompilations"),
9531018
},
9541019
},
1020+
.alpha => VaListAlpha,
9551021
.arm, .armeb, .thumb, .thumbeb => VaListArm,
9561022
.hexagon => if (builtin.target.abi.isMusl()) VaListHexagon else *u8,
9571023
.powerpc, .powerpcle => switch (builtin.os.tag) {
9581024
.aix => *u8,
9591025
else => VaListPowerPc,
9601026
},
9611027
.s390x => VaListS390x,
1028+
.sh, .sheb => VaListSh, // This is wrong for `sh_renesas`: https://github.com/ziglang/zig/issues/24692#issuecomment-3150779829
9621029
.x86_64 => switch (builtin.os.tag) {
9631030
.uefi, .windows => switch (builtin.zig_backend) {
9641031
else => *u8,
9651032
.stage2_llvm => @compileError("disabled due to miscompilations"),
9661033
},
9671034
else => VaListX86_64,
9681035
},
969-
.xtensa => VaListXtensa,
1036+
.xtensa, .xtensaeb => VaListXtensa,
9701037
else => @compileError("VaList not supported for this target yet"),
9711038
};
9721039

0 commit comments

Comments
 (0)