Use MIPS N32 abi in all user programs

Signed-off-by: Harry Chen <i@harrychen.xyz>
master
Harry Chen 6 years ago
parent a460c5b327
commit c730e9c8da

@ -34,6 +34,7 @@ elseif (${ARCH} STREQUAL riscv64)
set(CMAKE_C_FLAGS "-march=rv64imafdc -mabi=lp64d -mcmodel=medany")
elseif (${ARCH} STREQUAL aarch64)
elseif (${ARCH} STREQUAL mipsel)
set(PREFIX ${ARCH}-linux-musln32-)
else ()
message("Unsupported arch: ${ARCH}")
endif ()

@ -2798,15 +2798,17 @@ static volatile int go;
static void *_locker(void *v)
{
while (go != 1)
while (go != 1) {
#if defined(__x86_64__)
asm volatile("pause\n":::"memory");
#elif defined(__aarch64__)
asm volatile("yield\n":::"memory");
#elif defined(__mips__) || defined(__riscv32__) || defined(__riscv64__)
asm volatile("nop\n":::"memory");
#else
#warning Yield instruction is not implemented
{}
#endif
}
pthread_mutex_t *m = (pthread_mutex_t *)v;
int i;
@ -2921,15 +2923,17 @@ static void _condtest(const int nt)
go = 0;
if (pthread_create(&t[i], NULL, _condsleep, &args[i]))
errx(-1, "pthread_ create");
while (go == 0)
while (go == 0) {
#if defined(__x86_64__)
asm volatile("pause\n":::"memory");
#elif defined(__aarch64__)
asm volatile("yield\n":::"memory");
#elif defined(__mips__) || defined(__riscv32__) || defined(__riscv64__)
asm volatile("nop\n":::"memory");
#else
#warning Yield instruction is not implemented
{}
#endif
}
}
for (i = 0; i < nt; i++)

@ -3,11 +3,17 @@ iperf3_tarball := iperf3-$(iperf3_version).tar.gz
iperf3_tarball_path := src/$(iperf3_tarball)
build_dir := build/$(arch)
iperf3_dir := $(build_dir)/iperf-$(iperf3_version)
cc := $(arch)-linux-musl-gcc
strip := $(arch)-linux-musl-strip
prefix := $(arch)-linux-musl-
bin_unstripped := build/$(arch)/iperf3_unstripped
bin := build/$(arch)/iperf3
ifeq ($(arch), mipsel)
prefix := mipsel-linux-musln32-
endif
cc := $(prefix)gcc
strip := $(prefix)strip
$(iperf3_tarball_path):
wget https://github.com/esnet/iperf/archive/$(iperf3_version).tar.gz -O $(iperf3_tarball_path)

@ -3,11 +3,17 @@ nginx_tarball := nginx-$(nginx_version).tar.gz
nginx_tarball_path := src/nginx-$(nginx_version).tar.gz
build_dir := build/$(arch)
nginx_dir := $(build_dir)/nginx-$(nginx_version)
cc := $(arch)-linux-musl-gcc
strip := $(arch)-linux-musl-strip
prefix := $(arch)-linux-musl-
bin_unstripped := build/$(arch)/nginx_unstripped
bin := build/$(arch)/nginx
ifeq ($(arch), mipsel)
prefix := mipsel-linux-musln32-
endif
cc := $(prefix)gcc
strip := $(prefix)strip
$(nginx_tarball_path):
wget https://nginx.org/download/$(nginx_tarball) -O $(nginx_tarball_path)

@ -3,13 +3,19 @@ redis_tarball := redis-$(redis_version).tar.gz
redis_tarball_path := src/redis-$(redis_version).tar.gz
build_dir := build/$(arch)
redis_dir := $(build_dir)/redis-$(redis_version)
cc := $(arch)-linux-musl-gcc
strip := $(arch)-linux-musl-strip
prefix := $(arch)-linux-musl-
bin_server_unstripped := build/$(arch)/redis-server-unstripped
bin_server := build/$(arch)/redis-server
bin_cli_unstripped := build/$(arch)/redis-cli-unstripped
bin_cli := build/$(arch)/redis-cli
ifeq ($(arch), mipsel)
prefix := mipsel-linux-musln32-
endif
cc := $(prefix)gcc
strip := $(prefix)strip
# $ARCH is also used in redis internal Makefile, avoid clashing
undefine ARCH

@ -4,7 +4,8 @@ use alloc::string::String;
#[inline(always)]
fn sys_call(syscall_id: SyscallId, arg0: usize, arg1: usize, arg2: usize, arg3: usize, arg4: usize, arg5: usize) -> i32 {
let id = syscall_id as usize;
let ret: i32;
let mut ret: i32;
let mut failed: i32 = 0;
unsafe {
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
@ -32,11 +33,18 @@ fn sys_call(syscall_id: SyscallId, arg0: usize, arg1: usize, arg2: usize, arg3:
: "memory"
: "volatile");
#[cfg(target_arch = "mips")]
{
asm!("syscall"
: "={v0}" (ret)
: "{t0}" (id), "{a0}" (arg0), "{a1}" (arg1), "{a2}" (arg2), "{a3}" (arg3), "{s0}" (arg4), "{s1}" (arg5)
// v0 for syscall id
: "={$2}" (ret), "={$7}" (failed)
// v0, a0, a1, a2, a3, a4, a5
: "{$2}" (id), "{$4}" (arg0), "{$5}" (arg1), "{$6}" (arg2), "{$7}" (arg3), "{$8}" (arg4), "{$9}" (arg5)
: "memory"
: "volatile");
if failed != 0 {
ret = - ret;
}
}
}
ret
}

@ -36,7 +36,7 @@ elseif (${ARCH} STREQUAL aarch64)
endif ()
set(CMAKE_C_FLAGS "-mgeneral-regs-only")
elseif (${ARCH} STREQUAL mipsel)
set(PREFIX mipsel-linux-musl-)
set(PREFIX ${ARCH}-linux-musln32-)
else()
message("Unsupported arch: ${ARCH}")
endif ()

@ -65,6 +65,22 @@ syscall(int num, ...) {
"m" (a[4])
: "cc", "memory"
);
#elif defined(__mips__)
// mips n32 abi
register long a0 __asm__("$4") = a[0];
register long a1 __asm__("$5") = a[1];
register long a2 __asm__("$6") = a[2];
register long a3 __asm__("$7") = a[3];
register long a4 __asm__("$8") = a[4];
register long a5 __asm__("$9") = a[5];
register long v0 __asm__("$2");
__asm__ __volatile__ (
"addu $2,$0,%2 ; syscall"
: "=&r"(v0), "=r"(a3)
: "ir"(num), "0"(v0), "1"(a3), "r"(a0), "r"(a1), "r"(a2), "r"(a3), "r"(a4), "r"(a5)
: "$1", "$3", "$10", "$11", "$12", "$13",
"$14", "$15", "$24", "$25", "hi", "lo", "memory");
ret = a3 ? -v0 : v0;
#endif
return ret;
}

Loading…
Cancel
Save