mirror of
https://github.com/NotAShelf/microfetch.git
synced 2026-04-27 10:55:20 +00:00
arch: add mips64 support
This commit is contained in:
parent
1b4dcf4a1a
commit
950d9f4d2c
5 changed files with 271 additions and 6 deletions
5
.github/workflows/rust.yml
vendored
5
.github/workflows/rust.yml
vendored
|
|
@ -42,6 +42,11 @@ jobs:
|
||||||
# sparc64 uses experimental asm features
|
# sparc64 uses experimental asm features
|
||||||
- target: sparc64-unknown-linux-gnu
|
- target: sparc64-unknown-linux-gnu
|
||||||
toolchain: nightly
|
toolchain: nightly
|
||||||
|
# mips64 is tier-3 and uses experimental asm features
|
||||||
|
- target: mips64-unknown-linux-gnuabi64
|
||||||
|
toolchain: nightly
|
||||||
|
components: rust-src
|
||||||
|
build_std: true
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: "Checkout"
|
- name: "Checkout"
|
||||||
|
|
|
||||||
|
|
@ -6,11 +6,16 @@
|
||||||
//! faster?
|
//! faster?
|
||||||
//!
|
//!
|
||||||
//! Supports `x86_64`, `aarch64`, `riscv64`, `loongarch64`, `s390x`,
|
//! Supports `x86_64`, `aarch64`, `riscv64`, `loongarch64`, `s390x`,
|
||||||
//! `powerpc64`, `arm` (armv7), `riscv32`, and `sparc64` architectures.
|
//! `powerpc64`, `arm` (armv7), `riscv32`, `sparc64`, and `mips64`
|
||||||
|
//! architectures.
|
||||||
|
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
any(target_arch = "powerpc64", target_arch = "sparc64"),
|
any(
|
||||||
|
target_arch = "powerpc64",
|
||||||
|
target_arch = "sparc64",
|
||||||
|
target_arch = "mips64"
|
||||||
|
),
|
||||||
feature(asm_experimental_arch)
|
feature(asm_experimental_arch)
|
||||||
)]
|
)]
|
||||||
|
|
||||||
|
|
@ -24,11 +29,12 @@
|
||||||
target_arch = "powerpc64",
|
target_arch = "powerpc64",
|
||||||
target_arch = "arm",
|
target_arch = "arm",
|
||||||
target_arch = "riscv32",
|
target_arch = "riscv32",
|
||||||
target_arch = "sparc64"
|
target_arch = "sparc64",
|
||||||
|
target_arch = "mips64"
|
||||||
)))]
|
)))]
|
||||||
compile_error!(
|
compile_error!(
|
||||||
"Unsupported architecture: only x86_64, aarch64, riscv64, loongarch64, \
|
"Unsupported architecture: only x86_64, aarch64, riscv64, loongarch64, \
|
||||||
s390x, powerpc64, arm, riscv32, and sparc64 are supported"
|
s390x, powerpc64, arm, riscv32, sparc64, and mips64 are supported"
|
||||||
);
|
);
|
||||||
|
|
||||||
// Per-arch syscall implementations live in their own module files.
|
// Per-arch syscall implementations live in their own module files.
|
||||||
|
|
@ -59,6 +65,9 @@ mod arch;
|
||||||
#[cfg(target_arch = "sparc64")]
|
#[cfg(target_arch = "sparc64")]
|
||||||
#[path = "sparc64.rs"]
|
#[path = "sparc64.rs"]
|
||||||
mod arch;
|
mod arch;
|
||||||
|
#[cfg(target_arch = "mips64")]
|
||||||
|
#[path = "mips64.rs"]
|
||||||
|
mod arch;
|
||||||
|
|
||||||
/// Copies `n` bytes from `src` to `dest`.
|
/// Copies `n` bytes from `src` to `dest`.
|
||||||
///
|
///
|
||||||
|
|
@ -295,7 +304,8 @@ pub unsafe fn sys_uname(buf: *mut UtsNameBuf) -> i32 {
|
||||||
#[cfg(not(any(
|
#[cfg(not(any(
|
||||||
target_arch = "s390x",
|
target_arch = "s390x",
|
||||||
target_arch = "arm",
|
target_arch = "arm",
|
||||||
target_arch = "riscv32"
|
target_arch = "riscv32",
|
||||||
|
target_arch = "mips64"
|
||||||
)))]
|
)))]
|
||||||
pub struct StatfsBuf {
|
pub struct StatfsBuf {
|
||||||
pub f_type: i64,
|
pub f_type: i64,
|
||||||
|
|
@ -355,6 +365,27 @@ pub struct StatfsBuf {
|
||||||
pub _pad: [u32; 4],
|
pub _pad: [u32; 4],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// mips reorders fields; see
|
||||||
|
/// https://github.com/torvalds/linux/blob/v6.19/arch/mips/include/uapi/asm/statfs.h
|
||||||
|
#[repr(C)]
|
||||||
|
#[cfg(target_arch = "mips64")]
|
||||||
|
pub struct StatfsBuf {
|
||||||
|
pub f_type: i64,
|
||||||
|
pub f_bsize: i64,
|
||||||
|
pub f_frsize: i64,
|
||||||
|
pub f_blocks: u64,
|
||||||
|
pub f_bfree: u64,
|
||||||
|
pub f_files: u64,
|
||||||
|
pub f_ffree: u64,
|
||||||
|
pub f_bavail: u64,
|
||||||
|
pub f_fsid: [i32; 2],
|
||||||
|
pub f_namelen: i64,
|
||||||
|
pub f_flags: i64,
|
||||||
|
|
||||||
|
#[allow(clippy::pub_underscore_fields, reason = "This is not a public API")]
|
||||||
|
pub _pad: [i64; 5],
|
||||||
|
}
|
||||||
|
|
||||||
/// Direct `statfs(2)` syscall
|
/// Direct `statfs(2)` syscall
|
||||||
///
|
///
|
||||||
/// # Returns
|
/// # Returns
|
||||||
|
|
|
||||||
206
crates/asm/src/mips64.rs
Normal file
206
crates/asm/src/mips64.rs
Normal file
|
|
@ -0,0 +1,206 @@
|
||||||
|
//! Syscall implementations for `mips64`.
|
||||||
|
|
||||||
|
use super::{StatfsBuf, SysInfo, UtsNameBuf};
|
||||||
|
|
||||||
|
pub(super) unsafe fn sys_open(path: *const u8, flags: i32) -> i32 {
|
||||||
|
unsafe {
|
||||||
|
let ret: i64;
|
||||||
|
core::arch::asm!(
|
||||||
|
"syscall",
|
||||||
|
"beqz $7, 1f",
|
||||||
|
"nop",
|
||||||
|
"dsubu $2, $0, $2",
|
||||||
|
"1:",
|
||||||
|
inlateout("$2") 5000i64 + 2 => ret, // SYS_open
|
||||||
|
in("$4") path,
|
||||||
|
in("$5") flags,
|
||||||
|
in("$6") 0i32, // mode
|
||||||
|
lateout("$7") _,
|
||||||
|
lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _,
|
||||||
|
lateout("$12") _, lateout("$13") _, lateout("$14") _, lateout("$15") _,
|
||||||
|
lateout("$24") _, lateout("$25") _,
|
||||||
|
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!(
|
||||||
|
"syscall",
|
||||||
|
"beqz $7, 1f",
|
||||||
|
"nop",
|
||||||
|
"dsubu $2, $0, $2",
|
||||||
|
"1:",
|
||||||
|
inlateout("$2") 5000i64 + 0 => ret, // SYS_read
|
||||||
|
in("$4") fd,
|
||||||
|
in("$5") buf,
|
||||||
|
in("$6") count,
|
||||||
|
lateout("$7") _,
|
||||||
|
lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _,
|
||||||
|
lateout("$12") _, lateout("$13") _, lateout("$14") _, lateout("$15") _,
|
||||||
|
lateout("$24") _, lateout("$25") _,
|
||||||
|
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!(
|
||||||
|
"syscall",
|
||||||
|
"beqz $7, 1f",
|
||||||
|
"nop",
|
||||||
|
"dsubu $2, $0, $2",
|
||||||
|
"1:",
|
||||||
|
inlateout("$2") 5000i64 + 1 => ret, // SYS_write
|
||||||
|
in("$4") fd,
|
||||||
|
in("$5") buf,
|
||||||
|
in("$6") count,
|
||||||
|
lateout("$7") _,
|
||||||
|
lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _,
|
||||||
|
lateout("$12") _, lateout("$13") _, lateout("$14") _, lateout("$15") _,
|
||||||
|
lateout("$24") _, lateout("$25") _,
|
||||||
|
options(nostack)
|
||||||
|
);
|
||||||
|
ret as isize
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) unsafe fn sys_close(fd: i32) -> i32 {
|
||||||
|
unsafe {
|
||||||
|
let ret: i64;
|
||||||
|
core::arch::asm!(
|
||||||
|
"syscall",
|
||||||
|
"beqz $7, 1f",
|
||||||
|
"nop",
|
||||||
|
"dsubu $2, $0, $2",
|
||||||
|
"1:",
|
||||||
|
inlateout("$2") 5000i64 + 3 => ret, // SYS_close
|
||||||
|
in("$4") fd,
|
||||||
|
lateout("$7") _,
|
||||||
|
lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _,
|
||||||
|
lateout("$12") _, lateout("$13") _, lateout("$14") _, lateout("$15") _,
|
||||||
|
lateout("$24") _, lateout("$25") _,
|
||||||
|
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!(
|
||||||
|
"syscall",
|
||||||
|
"beqz $7, 1f",
|
||||||
|
"nop",
|
||||||
|
"dsubu $2, $0, $2",
|
||||||
|
"1:",
|
||||||
|
inlateout("$2") 5000i64 + 61 => ret, // SYS_newuname
|
||||||
|
in("$4") buf,
|
||||||
|
lateout("$7") _,
|
||||||
|
lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _,
|
||||||
|
lateout("$12") _, lateout("$13") _, lateout("$14") _, lateout("$15") _,
|
||||||
|
lateout("$24") _, lateout("$25") _,
|
||||||
|
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!(
|
||||||
|
"syscall",
|
||||||
|
"beqz $7, 1f",
|
||||||
|
"nop",
|
||||||
|
"dsubu $2, $0, $2",
|
||||||
|
"1:",
|
||||||
|
inlateout("$2") 5000i64 + 134 => ret, // SYS_statfs
|
||||||
|
in("$4") path,
|
||||||
|
in("$5") buf,
|
||||||
|
lateout("$7") _,
|
||||||
|
lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _,
|
||||||
|
lateout("$12") _, lateout("$13") _, lateout("$14") _, lateout("$15") _,
|
||||||
|
lateout("$24") _, lateout("$25") _,
|
||||||
|
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!(
|
||||||
|
"syscall",
|
||||||
|
"beqz $7, 1f",
|
||||||
|
"nop",
|
||||||
|
"dsubu $2, $0, $2",
|
||||||
|
"1:",
|
||||||
|
inlateout("$2") 5000_i64 + 97 => ret, // SYS_sysinfo
|
||||||
|
in("$4") info,
|
||||||
|
lateout("$7") _,
|
||||||
|
lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _,
|
||||||
|
lateout("$12") _, lateout("$13") _, lateout("$14") _, lateout("$15") _,
|
||||||
|
lateout("$24") _, lateout("$25") _,
|
||||||
|
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!(
|
||||||
|
"syscall",
|
||||||
|
inlateout("$2") 5000i64 + 196 => ret, // __NR_sched_getaffinity
|
||||||
|
in("$4") pid,
|
||||||
|
in("$5") mask_size,
|
||||||
|
in("$6") mask,
|
||||||
|
lateout("$7") _,
|
||||||
|
lateout("$8") _, lateout("$9") _, lateout("$10") _, lateout("$11") _,
|
||||||
|
lateout("$12") _, lateout("$13") _, lateout("$14") _, lateout("$15") _,
|
||||||
|
lateout("$24") _, lateout("$25") _,
|
||||||
|
options(nostack)
|
||||||
|
);
|
||||||
|
#[allow(clippy::cast_possible_truncation)]
|
||||||
|
{
|
||||||
|
ret as i32
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(super) unsafe fn sys_exit(code: i32) -> ! {
|
||||||
|
unsafe {
|
||||||
|
core::arch::asm!(
|
||||||
|
"syscall",
|
||||||
|
in("$2") 5000i64 + 58, // SYS_exit
|
||||||
|
in("$4") code,
|
||||||
|
options(noreturn, nostack)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -190,6 +190,8 @@ fn get_cpu_freq_mhz() -> Option<u32> {
|
||||||
b"cpu MHz static",
|
b"cpu MHz static",
|
||||||
b"CPU MHz",
|
b"CPU MHz",
|
||||||
b"clock",
|
b"clock",
|
||||||
|
// BogoMIPS on MIPS is calibrated to the clock frequency (unlike x86).
|
||||||
|
b"BogoMIPS",
|
||||||
] {
|
] {
|
||||||
if let Some(val) = extract_field(data, key) {
|
if let Some(val) = extract_field(data, key) {
|
||||||
// Parse integer part of the MHz value (e.g. "5200.00" -> 5200)
|
// Parse integer part of the MHz value (e.g. "5200.00" -> 5200)
|
||||||
|
|
@ -270,6 +272,7 @@ fn extract_name(data: &[u8]) -> Option<String> {
|
||||||
b"model name" as &[u8],
|
b"model name" as &[u8],
|
||||||
b"Model Name",
|
b"Model Name",
|
||||||
b"uarch",
|
b"uarch",
|
||||||
|
b"cpu model",
|
||||||
b"isa",
|
b"isa",
|
||||||
b"cpu",
|
b"cpu",
|
||||||
b"machine",
|
b"machine",
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,11 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
#![no_main]
|
#![no_main]
|
||||||
#![cfg_attr(
|
#![cfg_attr(
|
||||||
any(target_arch = "powerpc64", target_arch = "sparc64"),
|
any(
|
||||||
|
target_arch = "powerpc64",
|
||||||
|
target_arch = "sparc64",
|
||||||
|
target_arch = "mips64"
|
||||||
|
),
|
||||||
feature(asm_experimental_arch)
|
feature(asm_experimental_arch)
|
||||||
)]
|
)]
|
||||||
|
|
||||||
|
|
@ -193,6 +197,22 @@ unsafe extern "C" fn _start() {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "mips64")]
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
#[unsafe(naked)]
|
||||||
|
unsafe extern "C" fn _start() {
|
||||||
|
naked_asm!(
|
||||||
|
"move $a0, $sp", // first arg = original sp (argc/argv)
|
||||||
|
"daddiu $sp, $sp, -16",// reserve + keep 16-byte alignment (N64 ABI)
|
||||||
|
"jal {entry_rust}",
|
||||||
|
"nop", // delay slot
|
||||||
|
"move $a0, $v0", // exit code = entry_rust return value
|
||||||
|
"li $v0, 5058", // SYS_exit (5000 + 58)
|
||||||
|
"syscall",
|
||||||
|
entry_rust = sym entry_rust,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Global allocator
|
// Global allocator
|
||||||
#[global_allocator]
|
#[global_allocator]
|
||||||
static ALLOCATOR: BumpAllocator = BumpAllocator::new();
|
static ALLOCATOR: BumpAllocator = BumpAllocator::new();
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue