Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
e8d060e
std.Target: update lists of omitted LLVM tags
alexrp Oct 19, 2025
362a44a
std.Target: better Abi.default() behavior for arc and xtensa
alexrp Oct 19, 2025
0e15b2a
std.Target: handle some more cases in toCoffMachine()
alexrp Oct 19, 2025
a7f085f
std.Target: fix cCallingConvention() to pick mips64_n32 for muslabin32
alexrp Oct 19, 2025
022dcbc
std.Target.DynamicLinker: recognize standard hexagon-linux-musl path
alexrp Oct 19, 2025
ae789fa
test: enable dynamic hexagon-linux-musl with -Dtest-extra-targets
alexrp Oct 19, 2025
cd56b06
Zcu: simplify atomicPtrAlignment()
alexrp Oct 19, 2025
862e674
std.Target: remove bogus hosted avr/msp430 prongs in cTypeBitSize()
alexrp Oct 19, 2025
45b80f2
std.Target: fix cTypePreferredAlignment() for arc
alexrp Oct 19, 2025
dda05b2
std.Target: fix cMaxIntAlignment() for a few architectures
alexrp Oct 19, 2025
3e2daa5
std.Target: add arceb and xtensaeb Cpu.Arch tags
alexrp Oct 19, 2025
c55e83e
std.Target: xtensa defaults to windowed ABI
alexrp Oct 21, 2025
ee72f06
std.Target: add tags and info for alpha, hppa, microblaze, sh
alexrp Oct 20, 2025
a144194
std.Target: add stackGrowth() function
alexrp Oct 20, 2025
beb507a
std.builtin: add CallingConvention.x86_64_x32
alexrp Oct 19, 2025
abf40ca
std.builtin: add CallingConvention.msp430_interrupt
alexrp Oct 20, 2025
4fa453c
std.builtin: add CallingConvention.microblaze_interrupt
alexrp Oct 20, 2025
af1d777
std.builtin: add CallingConvention.sh_interrupt
alexrp Oct 20, 2025
340d6ce
std.builtin: move AddressSpace.Context to std.Target.AddressSpaceContext
alexrp Oct 20, 2025
252e1fd
std.start: add alpha support
alexrp Oct 23, 2025
c792ebf
std.start: add microblaze support
alexrp Oct 23, 2025
4193ea8
std.start: add sh support
alexrp Oct 23, 2025
fc48f8a
std.pie: add alpha support
alexrp Oct 21, 2025
fb2c029
std.pie: add microblaze support
alexrp Oct 23, 2025
2b54437
std.pie: add sh support
alexrp Oct 21, 2025
9fde442
std.os.linux.tls: add alpha support
alexrp Oct 21, 2025
5e92126
std.os.linux.tls: add microblaze support
alexrp Oct 21, 2025
aff557e
std.os.linux.tls: add sh support
alexrp Oct 21, 2025
f723d69
std.os.linux.tls: add hppa support
alexrp Oct 21, 2025
3d1b781
std.Thread: implement freeAndExit() for m68k-linux
alexrp Oct 20, 2025
de87c85
std.Thread: implement freeAndExit() for alpha-linux
alexrp Oct 21, 2025
f6c06d7
std.Thread: implement freeAndExit() for hppa-linux
alexrp Oct 21, 2025
3777d3c
std.Thread: implement freeAndExit() for microblaze-linux
alexrp Oct 21, 2025
493889d
std.Thread: implement freeAndExit() for sh-linux
alexrp Oct 21, 2025
3c5502e
std.atomic: define cache line size for alpha, hppa, microblaze, sh
alexrp Oct 20, 2025
7eda0b5
std.heap: define page size for alpha, hppa, microblaze, sh on Linux
alexrp Oct 20, 2025
a03b924
std.heap: define page size for alpha, hppa, sh on OpenBSD
alexrp Oct 23, 2025
23b2990
std.heap: define page size for hppa, sh on NetBSD
alexrp Oct 23, 2025
d99cf50
std.debug.cpu_context: add signal_ucontext_t for alpha, hppa, microbl…
alexrp Oct 23, 2025
a689c38
std.debug: FP unwinding is impossible on alpha, microblaze, sh
alexrp Oct 20, 2025
c13355a
std.debug: fix FP unwind progress check for stackGrowth() == .up targets
alexrp Oct 20, 2025
d8cb8b7
std.debug: fix FP unwinding for hppa/hppa64
alexrp Oct 20, 2025
07d764d
std.zig.system: handle alpha, hppa, microblaze, sh in getExternalExec…
alexrp Oct 20, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
526 changes: 375 additions & 151 deletions lib/std/Target.zig

Large diffs are not rendered by default.

70 changes: 70 additions & 0 deletions lib/std/Thread.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1235,6 +1235,18 @@ const LinuxThreadImpl = struct {
: [ptr] "r" (@intFromPtr(self.mapped.ptr)),
[len] "r" (self.mapped.len),
: .{ .memory = true }),
.alpha => asm volatile (
\\ ldi $0, 73 # SYS_munmap
\\ mov %[ptr], $16
\\ mov %[len], $17
\\ callsys
\\ ldi $0, 1 # SYS_exit
\\ ldi $16, 0
\\ callsys
:
: [ptr] "r" (@intFromPtr(self.mapped.ptr)),
[len] "r" (self.mapped.len),
: .{ .memory = true }),
.hexagon => asm volatile (
\\ r6 = #215 // SYS_munmap
\\ r0 = %[ptr]
Expand All @@ -1247,6 +1259,42 @@ const LinuxThreadImpl = struct {
: [ptr] "r" (@intFromPtr(self.mapped.ptr)),
[len] "r" (self.mapped.len),
: .{ .memory = true }),
.hppa => asm volatile (
\\ ldi 91, %%r20 /* SYS_munmap */
\\ copy %[ptr], %%r26
\\ copy %[len], %%r25
\\ ble 0x100(%%sr2, %%r0)
\\ ldi 1, %%r20 /* SYS_exit */
\\ ldi 0, %%r26
\\ ble 0x100(%%sr2, %%r0)
:
: [ptr] "r" (@intFromPtr(self.mapped.ptr)),
[len] "r" (self.mapped.len),
: .{ .memory = true }),
.m68k => asm volatile (
\\ move.l #91, %%d0 // SYS_munmap
\\ move.l %[ptr], %%d1
\\ move.l %[len], %%d2
\\ trap #0
\\ move.l #1, %%d0 // SYS_exit
\\ move.l #0, %%d1
\\ trap #0
:
: [ptr] "r" (@intFromPtr(self.mapped.ptr)),
[len] "r" (self.mapped.len),
: .{ .memory = true }),
.microblaze, .microblazeel => asm volatile (
\\ ori r12, r0, 91 # SYS_munmap
\\ ori r5, %[ptr], 0
\\ ori r6, %[len], 0
\\ brki r14, 0x8
\\ ori r12, r0, 1 # SYS_exit
\\ or r5, r0, r0
\\ brki r14, 0x8
:
: [ptr] "r" (@intFromPtr(self.mapped.ptr)),
[len] "r" (self.mapped.len),
: .{ .memory = true }),
// We set `sp` to the address of the current function as a workaround for a Linux
// kernel bug that caused syscalls to return EFAULT if the stack pointer is invalid.
// The bug was introduced in 46e12c07b3b9603c60fc1d421ff18618241cb081 and fixed in
Expand Down Expand Up @@ -1335,6 +1383,28 @@ const LinuxThreadImpl = struct {
: [ptr] "r" (@intFromPtr(self.mapped.ptr)),
[len] "r" (self.mapped.len),
: .{ .memory = true }),
.sh, .sheb => asm volatile (
\\ mov #91, r3 ! SYS_munmap
\\ mov %[ptr], r4
\\ mov %[len], r5
\\ trapa #31
\\ or r0, r0
\\ or r0, r0
\\ or r0, r0
\\ or r0, r0
\\ or r0, r0
\\ mov #1, r3 ! SYS_exit
\\ mov #0, r4
\\ trapa #31
\\ or r0, r0
\\ or r0, r0
\\ or r0, r0
\\ or r0, r0
\\ or r0, r0
:
: [ptr] "r" (@intFromPtr(self.mapped.ptr)),
[len] "r" (self.mapped.len),
: .{ .memory = true }),
.sparc => asm volatile (
\\ # See sparc64 comments below.
\\ 1:
Expand Down
11 changes: 11 additions & 0 deletions lib/std/atomic.zig
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ pub fn cacheLineForCpu(cpu: std.Target.Cpu) u16 {
.aarch64,
.aarch64_be,
.arc,
.arceb,
.powerpc64,
.powerpc64le,
=> 128,
Expand All @@ -432,20 +433,29 @@ pub fn cacheLineForCpu(cpu: std.Target.Cpu) u16 {
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_mipsle.go#L7
// - https://github.com/golang/go/blob/3dd58676054223962cd915bb0934d1f9f489d4d2/src/internal/cpu/cpu_mips64x.go#L9
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/sparc/include/asm/cache.h#L14
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/microblaze/include/asm/cache.h#L15
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/sh/include/cpu-sh4/cpu/cache.h#L10
.arm,
.armeb,
.thumb,
.thumbeb,
.microblaze,
.microblazeel,
.mips,
.mipsel,
.mips64,
.mips64el,
.sh,
.sheb,
.sparc,
.sparc64,
=> 32,

// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/m68k/include/asm/cache.h#L10
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/openrisc/include/asm/cache.h#L24
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/parisc/include/asm/cache.h#L16
.hppa,
.hppa64,
.m68k,
.or1k,
=> 16,
Expand All @@ -468,6 +478,7 @@ pub fn cacheLineForCpu(cpu: std.Target.Cpu) u16 {
// - https://github.com/golang/go/blob/19e923182e590ae6568c2c714f20f32512aeb3e3/src/internal/cpu/cpu_riscv64.go#L7
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/xtensa/variants/csp/include/variant/core.h#L209
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/csky/Kconfig#L183
// - https://github.com/torvalds/linux/blob/3a7e02c040b130b5545e4b115aada7bacd80a2b6/arch/alpha/include/asm/cache.h#L11
// - https://www.xmos.com/download/The-XMOS-XS3-Architecture.pdf
else => 64,
};
Expand Down
103 changes: 85 additions & 18 deletions lib/std/builtin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ pub const CallingConvention = union(enum(u8)) {

// Calling conventions for the `x86_64` architecture.
x86_64_sysv: CommonOptions,
x86_64_x32: CommonOptions,
x86_64_win: CommonOptions,
x86_64_regcall_v3_sysv: CommonOptions,
x86_64_regcall_v4_win: CommonOptions,
Expand All @@ -229,6 +230,9 @@ pub const CallingConvention = union(enum(u8)) {
aarch64_vfabi: CommonOptions,
aarch64_vfabi_sve: CommonOptions,

/// The standard `alpha` calling convention.
alpha_osf: CommonOptions,

// Calling convetions for the `arm`, `armeb`, `thumb`, and `thumbeb` architectures.
/// ARM Architecture Procedure Call Standard
arm_aapcs: CommonOptions,
Expand Down Expand Up @@ -275,7 +279,7 @@ pub const CallingConvention = union(enum(u8)) {
/// The standard `wasm32` and `wasm64` calling convention, as specified in the WebAssembly Tool Conventions.
wasm_mvp: CommonOptions,

/// The standard `arc` calling convention.
/// The standard `arc`/`arceb` calling convention.
arc_sysv: CommonOptions,
arc_interrupt: ArcInterruptOptions,

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

/// The standard `hppa` calling convention.
hppa_elf: CommonOptions,

/// The standard `hppa64` calling convention.
hppa64_elf: CommonOptions,

/// The standard `lanai` calling convention.
lanai_sysv: CommonOptions,

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

/// The standard `microblaze`/`microblazeel` calling convention.
microblaze_std: CommonOptions,
microblaze_interrupt: MicroblazeInterruptOptions,

/// The standard `msp430` calling convention.
msp430_eabi: CommonOptions,
msp430_interrupt: CommonOptions,

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

// Calling conventions for the `sh`/`sheb` architecture.
sh_gnu: CommonOptions,
sh_renesas: CommonOptions,
sh_interrupt: ShInterruptOptions,

/// The standard `ve` calling convention.
ve_sysv: CommonOptions,

// Calling conventions for the `xcore` architecture.
xcore_xs1: CommonOptions,
xcore_xs2: CommonOptions,

// Calling conventions for the `xtensa` architecture.
// Calling conventions for the `xtensa`/`xtensaeb` architecture.
xtensa_call0: CommonOptions,
xtensa_windowed: CommonOptions,

Expand Down Expand Up @@ -403,6 +423,25 @@ pub const CallingConvention = union(enum(u8)) {
};
};

/// Options for the `microblaze_interrupt` calling convention.
pub const MicroblazeInterruptOptions = struct {
/// The boundary the stack is aligned to when the function is called.
/// `null` means the default for this calling convention.
incoming_stack_alignment: ?u64 = null,
type: InterruptType = .regular,

pub const InterruptType = enum(u2) {
/// User exception; return with `rtsd`.
user,
/// Regular interrupt; return with `rtid`.
regular,
/// Fast interrupt; return with `rtid`.
fast,
/// Software breakpoint; return with `rtbd`.
breakpoint,
};
};

/// Options for the `mips_interrupt` and `mips64_interrupt` calling conventions.
pub const MipsInterruptOptions = struct {
/// The boundary the stack is aligned to when the function is called.
Expand Down Expand Up @@ -438,6 +477,25 @@ pub const CallingConvention = union(enum(u8)) {
};
};

/// Options for the `sh_interrupt` calling convention.
pub const ShInterruptOptions = struct {
/// The boundary the stack is aligned to when the function is called.
/// `null` means the default for this calling convention.
incoming_stack_alignment: ?u64 = null,
save: SaveBehavior = .full,

pub const SaveBehavior = enum(u3) {
/// Save only fpscr (if applicable).
fpscr,
/// Save only high-numbered registers, i.e. r0 through r7 are *not* saved.
high,
/// Save all registers normally.
full,
/// Save all registers using the CPU's fast register bank.
bank,
};
};

/// Returns the array of `std.Target.Cpu.Arch` to which this `CallingConvention` applies.
/// Asserts that `cc` is not `.auto`, `.@"async"`, `.naked`, or `.@"inline"`.
pub fn archs(cc: CallingConvention) []const std.Target.Cpu.Arch {
Expand All @@ -459,21 +517,6 @@ pub const CallingConvention = union(enum(u8)) {
/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const AddressSpace = enum(u5) {
/// The places where a user can specify an address space attribute
pub const Context = enum {
/// A function is specified to be placed in a certain address space.
function,
/// A (global) variable is specified to be placed in a certain address space.
/// In contrast to .constant, these values (and thus the address space they will be
/// placed in) are required to be mutable.
variable,
/// A (global) constant value is specified to be placed in a certain address space.
/// In contrast to .variable, values placed in this address space are not required to be mutable.
constant,
/// A pointer is ascripted to point into a certain address space.
pointer,
};

// CPU address spaces.
generic,
gs,
Expand Down Expand Up @@ -858,6 +901,13 @@ pub const VaListAarch64 = extern struct {
__vr_offs: c_int,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const VaListAlpha = extern struct {
__base: *anyopaque,
__offset: c_int,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const VaListArm = extern struct {
Expand Down Expand Up @@ -891,6 +941,16 @@ pub const VaListS390x = extern struct {
__overflow_area_pointer: *anyopaque,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const VaListSh = extern struct {
__va_next_o: *anyopaque,
__va_next_o_limit: *anyopaque,
__va_next_fp: *anyopaque,
__va_next_fp_limit: *anyopaque,
__va_next_stack: *anyopaque,
};

/// This data structure is used by the Zig language code generation and
/// therefore must be kept in sync with the compiler implementation.
pub const VaListX86_64 = extern struct {
Expand Down Expand Up @@ -920,14 +980,19 @@ pub const VaList = switch (builtin.cpu.arch) {
.x86,
=> *u8,
.arc,
.arceb,
.avr,
.bpfel,
.bpfeb,
.csky,
.hppa,
.hppa64,
.lanai,
.loongarch32,
.loongarch64,
.m68k,
.microblaze,
.microblazeel,
.mips,
.mipsel,
.mips64,
Expand All @@ -952,21 +1017,23 @@ pub const VaList = switch (builtin.cpu.arch) {
.stage2_llvm => @compileError("disabled due to miscompilations"),
},
},
.alpha => VaListAlpha,
.arm, .armeb, .thumb, .thumbeb => VaListArm,
.hexagon => if (builtin.target.abi.isMusl()) VaListHexagon else *u8,
.powerpc, .powerpcle => switch (builtin.os.tag) {
.aix => *u8,
else => VaListPowerPc,
},
.s390x => VaListS390x,
.sh, .sheb => VaListSh, // This is wrong for `sh_renesas`: https://github.com/ziglang/zig/issues/24692#issuecomment-3150779829
.x86_64 => switch (builtin.os.tag) {
.uefi, .windows => switch (builtin.zig_backend) {
else => *u8,
.stage2_llvm => @compileError("disabled due to miscompilations"),
},
else => VaListX86_64,
},
.xtensa => VaListXtensa,
.xtensa, .xtensaeb => VaListXtensa,
else => @compileError("VaList not supported for this target yet"),
};

Expand Down
Loading
Loading