diff --git a/biscuit/CMakeLists.txt b/biscuit/CMakeLists.txt index 30a518d..a95a3b2 100644 --- a/biscuit/CMakeLists.txt +++ b/biscuit/CMakeLists.txt @@ -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 () diff --git a/biscuit/c/usertests.c b/biscuit/c/usertests.c index 9faceca..42c7a47 100644 --- a/biscuit/c/usertests.c +++ b/biscuit/c/usertests.c @@ -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++) diff --git a/iperf3/Makefile b/iperf3/Makefile index 15f34d3..1b6b0b2 100644 --- a/iperf3/Makefile +++ b/iperf3/Makefile @@ -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) diff --git a/nginx/Makefile b/nginx/Makefile index efe57d9..de22b74 100644 --- a/nginx/Makefile +++ b/nginx/Makefile @@ -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) diff --git a/redis/Makefile b/redis/Makefile index dd82ade..c25e3d2 100644 --- a/redis/Makefile +++ b/redis/Makefile @@ -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 diff --git a/rust/src/syscall.rs b/rust/src/syscall.rs index 94f4387..9e012b7 100644 --- a/rust/src/syscall.rs +++ b/rust/src/syscall.rs @@ -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 } diff --git a/ucore/CMakeLists.txt b/ucore/CMakeLists.txt index 3cdce4a..6c53058 100644 --- a/ucore/CMakeLists.txt +++ b/ucore/CMakeLists.txt @@ -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 () diff --git a/ucore/src/ulibs/syscall.c b/ucore/src/ulibs/syscall.c index bddd1ed..59aa563 100644 --- a/ucore/src/ulibs/syscall.c +++ b/ucore/src/ulibs/syscall.c @@ -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; }