mirror of
https://github.com/NotAShelf/microfetch.git
synced 2026-05-06 07:28:31 +00:00
arch: add powerpc64 support
This commit is contained in:
parent
05fc3d8df9
commit
03e6d1f4cf
5 changed files with 280 additions and 11 deletions
|
|
@ -5,10 +5,11 @@
|
|||
//! What do you mean I wasted two whole hours to make the program only 100µs
|
||||
//! faster?
|
||||
//!
|
||||
//! Supports `x86_64`, `aarch64`, `riscv64`, `loongarch64`, and `s390x`
|
||||
//! architectures.
|
||||
//! Supports `x86_64`, `aarch64`, `riscv64`, `loongarch64`, `s390x`, and
|
||||
//! `powerpc64` architectures.
|
||||
|
||||
#![no_std]
|
||||
#![cfg_attr(target_arch = "powerpc64", feature(asm_experimental_arch))]
|
||||
|
||||
// Ensure we're compiling for a supported architecture.
|
||||
#[cfg(not(any(
|
||||
|
|
@ -16,11 +17,12 @@
|
|||
target_arch = "aarch64",
|
||||
target_arch = "riscv64",
|
||||
target_arch = "loongarch64",
|
||||
target_arch = "s390x"
|
||||
target_arch = "s390x",
|
||||
target_arch = "powerpc64"
|
||||
)))]
|
||||
compile_error!(
|
||||
"Unsupported architecture: only x86_64, aarch64, riscv64, loongarch64, and \
|
||||
s390x are supported"
|
||||
"Unsupported architecture: only x86_64, aarch64, riscv64, loongarch64, \
|
||||
s390x, and powerpc64 are supported"
|
||||
);
|
||||
|
||||
// Per-arch syscall implementations live in their own module files.
|
||||
|
|
@ -39,6 +41,9 @@ mod arch;
|
|||
#[cfg(target_arch = "s390x")]
|
||||
#[path = "s390x.rs"]
|
||||
mod arch;
|
||||
#[cfg(target_arch = "powerpc64")]
|
||||
#[path = "powerpc64.rs"]
|
||||
mod arch;
|
||||
|
||||
/// Copies `n` bytes from `src` to `dest`.
|
||||
///
|
||||
|
|
|
|||
200
crates/asm/src/powerpc64.rs
Normal file
200
crates/asm/src/powerpc64.rs
Normal file
|
|
@ -0,0 +1,200 @@
|
|||
//! Syscall implementations for `powerpc64`.
|
||||
|
||||
use super::{StatfsBuf, SysInfo, UtsNameBuf};
|
||||
|
||||
pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 {
|
||||
unsafe {
|
||||
let ret: i64;
|
||||
core::arch::asm!(
|
||||
"sc",
|
||||
"bns+ 2f",
|
||||
"neg 3, 3",
|
||||
"2:",
|
||||
inlateout("r0") 5i64 => _, // SYS_open
|
||||
inlateout("r3") path => ret,
|
||||
inlateout("r4") flags => _,
|
||||
inlateout("r5") 0i32 => _, // mode
|
||||
out("r6") _, out("r7") _, out("r8") _,
|
||||
out("r9") _, out("r10") _, out("r11") _, out("r12") _,
|
||||
out("cr0") _,
|
||||
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!(
|
||||
"sc",
|
||||
"bns+ 2f",
|
||||
"neg 3, 3",
|
||||
"2:",
|
||||
inlateout("r0") 3i64 => _, // SYS_read
|
||||
inlateout("r3") fd as i64 => ret,
|
||||
inlateout("r4") buf => _,
|
||||
inlateout("r5") count => _,
|
||||
out("r6") _, out("r7") _, out("r8") _,
|
||||
out("r9") _, out("r10") _, out("r11") _, out("r12") _,
|
||||
out("cr0") _,
|
||||
options(nostack)
|
||||
);
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
{
|
||||
ret as isize
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) unsafe fn sys_write(fd: i32, buf: *const u8, count: usize) -> isize {
|
||||
unsafe {
|
||||
let ret: i64;
|
||||
core::arch::asm!(
|
||||
"sc",
|
||||
"bns+ 2f",
|
||||
"neg 3, 3",
|
||||
"2:",
|
||||
inlateout("r0") 4i64 => _, // SYS_write
|
||||
inlateout("r3") fd as i64 => ret,
|
||||
inlateout("r4") buf => _,
|
||||
inlateout("r5") count => _,
|
||||
out("r6") _, out("r7") _, out("r8") _,
|
||||
out("r9") _, out("r10") _, out("r11") _, out("r12") _,
|
||||
out("cr0") _,
|
||||
options(nostack)
|
||||
);
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
{
|
||||
ret as isize
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) unsafe fn sys_close(fd: i32) -> i32 {
|
||||
unsafe {
|
||||
let ret: i64;
|
||||
core::arch::asm!(
|
||||
"sc",
|
||||
"bns+ 2f",
|
||||
"neg 3, 3",
|
||||
"2:",
|
||||
inlateout("r0") 6i64 => _, // SYS_close
|
||||
inlateout("r3") fd as i64 => ret,
|
||||
out("r4") _, out("r5") _, out("r6") _, out("r7") _, out("r8") _,
|
||||
out("r9") _, out("r10") _, out("r11") _, out("r12") _,
|
||||
out("cr0") _,
|
||||
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!(
|
||||
"sc",
|
||||
"bns+ 2f",
|
||||
"neg 3, 3",
|
||||
"2:",
|
||||
inlateout("r0") 122i64 => _, // SYS_uname
|
||||
inlateout("r3") buf => ret,
|
||||
out("r4") _, out("r5") _, out("r6") _, out("r7") _, out("r8") _,
|
||||
out("r9") _, out("r10") _, out("r11") _, out("r12") _,
|
||||
out("cr0") _,
|
||||
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!(
|
||||
"sc",
|
||||
"bns+ 2f",
|
||||
"neg 3, 3",
|
||||
"2:",
|
||||
inlateout("r0") 99i64 => _, // SYS_statfs
|
||||
inlateout("r3") path => ret,
|
||||
inlateout("r4") buf => _,
|
||||
out("r5") _, out("r6") _, out("r7") _, out("r8") _,
|
||||
out("r9") _, out("r10") _, out("r11") _, out("r12") _,
|
||||
out("cr0") _,
|
||||
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!(
|
||||
"sc",
|
||||
"bns+ 2f",
|
||||
"neg 3, 3",
|
||||
"2:",
|
||||
inlateout("r0") 116_i64 => _, // __NR_sysinfo
|
||||
inlateout("r3") info => ret,
|
||||
out("r4") _, out("r5") _, out("r6") _, out("r7") _, out("r8") _,
|
||||
out("r9") _, out("r10") _, out("r11") _, out("r12") _,
|
||||
out("cr0") _,
|
||||
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!(
|
||||
"sc",
|
||||
"bns+ 2f",
|
||||
"neg 3, 3",
|
||||
"2:",
|
||||
inlateout("r0") 223i64 => _, // __NR_sched_getaffinity
|
||||
inlateout("r3") pid as i64 => ret,
|
||||
inlateout("r4") mask_size => _,
|
||||
inlateout("r5") mask => _,
|
||||
out("r6") _, out("r7") _, out("r8") _,
|
||||
out("r9") _, out("r10") _, out("r11") _, out("r12") _,
|
||||
out("cr0") _,
|
||||
options(nostack)
|
||||
);
|
||||
#[allow(clippy::cast_possible_truncation)]
|
||||
{
|
||||
ret as i32
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(super) unsafe fn sys_exit(code: i32) -> ! {
|
||||
unsafe {
|
||||
core::arch::asm!(
|
||||
"li 0, 1", // SYS_exit
|
||||
"sc",
|
||||
in("r3") code,
|
||||
options(noreturn, nostack)
|
||||
);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue