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") set(CMAKE_C_FLAGS "-march=rv64imafdc -mabi=lp64d -mcmodel=medany")
elseif (${ARCH} STREQUAL aarch64) elseif (${ARCH} STREQUAL aarch64)
elseif (${ARCH} STREQUAL mipsel) elseif (${ARCH} STREQUAL mipsel)
set(PREFIX ${ARCH}-linux-musln32-)
else () else ()
message("Unsupported arch: ${ARCH}") message("Unsupported arch: ${ARCH}")
endif () endif ()

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

@ -3,11 +3,17 @@ iperf3_tarball := iperf3-$(iperf3_version).tar.gz
iperf3_tarball_path := src/$(iperf3_tarball) iperf3_tarball_path := src/$(iperf3_tarball)
build_dir := build/$(arch) build_dir := build/$(arch)
iperf3_dir := $(build_dir)/iperf-$(iperf3_version) iperf3_dir := $(build_dir)/iperf-$(iperf3_version)
cc := $(arch)-linux-musl-gcc prefix := $(arch)-linux-musl-
strip := $(arch)-linux-musl-strip
bin_unstripped := build/$(arch)/iperf3_unstripped bin_unstripped := build/$(arch)/iperf3_unstripped
bin := build/$(arch)/iperf3 bin := build/$(arch)/iperf3
ifeq ($(arch), mipsel)
prefix := mipsel-linux-musln32-
endif
cc := $(prefix)gcc
strip := $(prefix)strip
$(iperf3_tarball_path): $(iperf3_tarball_path):
wget https://github.com/esnet/iperf/archive/$(iperf3_version).tar.gz -O $(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 nginx_tarball_path := src/nginx-$(nginx_version).tar.gz
build_dir := build/$(arch) build_dir := build/$(arch)
nginx_dir := $(build_dir)/nginx-$(nginx_version) nginx_dir := $(build_dir)/nginx-$(nginx_version)
cc := $(arch)-linux-musl-gcc prefix := $(arch)-linux-musl-
strip := $(arch)-linux-musl-strip
bin_unstripped := build/$(arch)/nginx_unstripped bin_unstripped := build/$(arch)/nginx_unstripped
bin := build/$(arch)/nginx bin := build/$(arch)/nginx
ifeq ($(arch), mipsel)
prefix := mipsel-linux-musln32-
endif
cc := $(prefix)gcc
strip := $(prefix)strip
$(nginx_tarball_path): $(nginx_tarball_path):
wget https://nginx.org/download/$(nginx_tarball) -O $(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 redis_tarball_path := src/redis-$(redis_version).tar.gz
build_dir := build/$(arch) build_dir := build/$(arch)
redis_dir := $(build_dir)/redis-$(redis_version) redis_dir := $(build_dir)/redis-$(redis_version)
cc := $(arch)-linux-musl-gcc prefix := $(arch)-linux-musl-
strip := $(arch)-linux-musl-strip
bin_server_unstripped := build/$(arch)/redis-server-unstripped bin_server_unstripped := build/$(arch)/redis-server-unstripped
bin_server := build/$(arch)/redis-server bin_server := build/$(arch)/redis-server
bin_cli_unstripped := build/$(arch)/redis-cli-unstripped bin_cli_unstripped := build/$(arch)/redis-cli-unstripped
bin_cli := build/$(arch)/redis-cli 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 # $ARCH is also used in redis internal Makefile, avoid clashing
undefine ARCH undefine ARCH

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

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

@ -65,6 +65,22 @@ syscall(int num, ...) {
"m" (a[4]) "m" (a[4])
: "cc", "memory" : "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 #endif
return ret; return ret;
} }

Loading…
Cancel
Save