arch: add sparc64 support

This commit is contained in:
Amaan Qureshi 2026-04-17 02:31:53 -04:00
commit 1b4dcf4a1a
No known key found for this signature in database
5 changed files with 245 additions and 5 deletions

View file

@ -6,10 +6,13 @@
//! faster?
//!
//! Supports `x86_64`, `aarch64`, `riscv64`, `loongarch64`, `s390x`,
//! `powerpc64`, `arm` (armv7), and `riscv32` architectures.
//! `powerpc64`, `arm` (armv7), `riscv32`, and `sparc64` architectures.
#![no_std]
#![cfg_attr(target_arch = "powerpc64", feature(asm_experimental_arch))]
#![cfg_attr(
any(target_arch = "powerpc64", target_arch = "sparc64"),
feature(asm_experimental_arch)
)]
// Ensure we're compiling for a supported architecture.
#[cfg(not(any(
@ -20,11 +23,12 @@
target_arch = "s390x",
target_arch = "powerpc64",
target_arch = "arm",
target_arch = "riscv32"
target_arch = "riscv32",
target_arch = "sparc64"
)))]
compile_error!(
"Unsupported architecture: only x86_64, aarch64, riscv64, loongarch64, \
s390x, powerpc64, arm, and riscv32 are supported"
s390x, powerpc64, arm, riscv32, and sparc64 are supported"
);
// Per-arch syscall implementations live in their own module files.
@ -52,6 +56,9 @@ mod arch;
#[cfg(target_arch = "riscv32")]
#[path = "riscv32.rs"]
mod arch;
#[cfg(target_arch = "sparc64")]
#[path = "sparc64.rs"]
mod arch;
/// Copies `n` bytes from `src` to `dest`.
///

179
crates/asm/src/sparc64.rs Normal file
View file

@ -0,0 +1,179 @@
//! Syscall implementations for `sparc64`.
use super::{StatfsBuf, SysInfo, UtsNameBuf};
pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 {
unsafe {
let ret: i64;
core::arch::asm!(
"mov {nr}, %g1",
"t 0x6d",
"bcs,a %xcc, 1f",
"sub %g0, %o0, %o0",
"1:",
nr = in(reg) 5i64, // SYS_open
inlateout("o0") path => ret,
in("o1") flags,
in("o2") 0i32, // mode
options(nostack)
);
#[allow(clippy::cast_possible_truncation)]
{
ret as i32
}
}
}
pub(super) unsafe fn sys_read(fd: i32, buf: *mut u8, count: usize) -> isize {
unsafe {
let ret: i64;
core::arch::asm!(
"mov {nr}, %g1",
"t 0x6d",
"bcs,a %xcc, 1f",
"sub %g0, %o0, %o0",
"1:",
nr = in(reg) 3i64, // SYS_read
inlateout("o0") fd as i64 => ret,
in("o1") buf,
in("o2") count,
options(nostack)
);
ret as isize
}
}
pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize {
unsafe {
let ret: i64;
core::arch::asm!(
"mov {nr}, %g1",
"t 0x6d",
"bcs,a %xcc, 1f",
"sub %g0, %o0, %o0",
"1:",
nr = in(reg) 4i64, // SYS_write
inlateout("o0") fd as i64 => ret,
in("o1") buf,
in("o2") count,
options(nostack)
);
ret as isize
}
}
pub(super) unsafe fn sys_close(fd: i32) -> i32 {
unsafe {
let ret: i64;
core::arch::asm!(
"mov {nr}, %g1",
"t 0x6d",
"bcs,a %xcc, 1f",
"sub %g0, %o0, %o0",
"1:",
nr = in(reg) 6i64, // SYS_close
inlateout("o0") fd as i64 => ret,
options(nostack)
);
#[allow(clippy::cast_possible_truncation)]
{
ret as i32
}
}
}
pub(super) unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 {
unsafe {
let ret: i64;
core::arch::asm!(
"mov {nr}, %g1",
"t 0x6d",
"bcs,a %xcc, 1f",
"sub %g0, %o0, %o0",
"1:",
nr = in(reg) 189i64, // SYS_newuname
inlateout("o0") buf => ret,
options(nostack)
);
#[allow(clippy::cast_possible_truncation)]
{
ret as i32
}
}
}
pub(super) unsafe fn sys_statfs(path: *const u8, buf: *mut StatfsBuf) -> i32 {
unsafe {
let ret: i64;
core::arch::asm!(
"mov {nr}, %g1",
"t 0x6d",
"bcs,a %xcc, 1f",
"sub %g0, %o0, %o0",
"1:",
nr = in(reg) 157i64, // SYS_statfs
inlateout("o0") path => ret,
in("o1") buf,
options(nostack)
);
#[allow(clippy::cast_possible_truncation)]
{
ret as i32
}
}
}
pub(super) unsafe fn sys_sysinfo(info: *mut SysInfo) -> i64 {
unsafe {
let ret: i64;
core::arch::asm!(
"mov {nr}, %g1",
"t 0x6d",
"bcs,a %xcc, 1f",
"sub %g0, %o0, %o0",
"1:",
nr = in(reg) 214_i64, // __NR_sysinfo
inlateout("o0") info => ret,
options(nostack)
);
ret
}
}
pub(super) unsafe fn sys_sched_getaffinity(
pid: i32,
mask_size: usize,
mask: *mut u8,
) -> i32 {
unsafe {
let ret: i64;
core::arch::asm!(
"mov {nr}, %g1",
"t 0x6d",
"bcs,a %xcc, 1f",
"sub %g0, %o0, %o0",
"1:",
nr = in(reg) 260i64, // __NR_sched_getaffinity
inlateout("o0") pid as i64 => ret,
in("o1") mask_size,
in("o2") mask,
options(nostack)
);
#[allow(clippy::cast_possible_truncation)]
{
ret as i32
}
}
}
pub(super) unsafe fn sys_exit(code: i32) -> ! {
unsafe {
core::arch::asm!(
"mov {nr}, %g1",
"t 0x6d",
nr = in(reg) 1i64, // SYS_exit
in("o0") code,
options(noreturn, nostack)
);
}
}