use musl to build biscuit programs for aarch64

master
equation314 6 years ago
parent 06084d9925
commit 10d49723df

@ -47,6 +47,8 @@ install:
sudo apt update;
sudo apt install musl-tools linux-headers-$(uname -r);
elif [ $TRAVIS_OS_NAME = osx ]; then
brew tap altkatz/homebrew-gcc_cross_compilers;
brew install FiloSottile/musl-cross/musl-cross --with-aarch64;
brew tap SergioBenitez/osxct;
brew install aarch64-none-elf;
fi;

@ -29,7 +29,7 @@ if (${ARCH} STREQUAL i386)
endif ()
set(CMAKE_C_FLAGS "-m32 -mno-red-zone")
elseif (${ARCH} STREQUAL x86_64)
set(PREFIX x86_64-linux-musl-)
set(PREFIX x86_64-linux-musl-)
set(CMAKE_C_FLAGS "-m64 -mno-red-zone")
elseif (${ARCH} STREQUAL riscv32)
set(PREFIX riscv64-unknown-elf-)
@ -38,11 +38,7 @@ elseif (${ARCH} STREQUAL riscv64)
set(PREFIX riscv64-unknown-elf-)
set(CMAKE_C_FLAGS "-march=rv64imac -mabi=lp64 -mcmodel=medany")
elseif (${ARCH} STREQUAL aarch64)
if(APPLE)
set(PREFIX aarch64-none-elf-)
else ()
set(PREFIX aarch64-elf-)
endif ()
set(PREFIX aarch64-linux-musl-)
else ()
message("Unsupported arch: ${ARCH}")
endif ()

@ -12,6 +12,10 @@ fn set_tls(tls: usize, pid: usize) {
unsafe {
asm!("mv tp, $0" : : "r"(tls));
}
#[cfg(target_arch = "aarch64")]
unsafe {
asm!("msr tpidr_el0, $0" : : "r"(tls));
}
#[cfg(target_arch = "x86_64")]
unsafe {
static mut DATA: [usize; 1024] = [0; 1024];
@ -27,6 +31,10 @@ fn get_tls() -> usize {
unsafe {
asm!("mv $0, tp" : "=r"(tls) :);
}
#[cfg(target_arch = "aarch64")]
unsafe {
asm!("mrs $0, tpidr_el0" : "=r"(tls) :);
}
#[cfg(target_arch = "x86_64")]
unsafe {
asm!("mov %fs:0, $0" : "=r"(tls) :);

@ -66,7 +66,7 @@ pub fn sys_close(fd: usize) -> i32 {
}
pub fn sys_dup2(fd1: usize, fd2: usize) -> i32 {
sys_call(SyscallId::Dup2, fd1, fd2, 0, 0, 0, 0)
sys_call(SyscallId::Dup3, fd1, fd2, 0, 0, 0, 0)
}
/// Fork the current process. Return the child's PID.
@ -130,7 +130,7 @@ pub fn sys_arch_prctl(code: i32, addr: usize) -> i32 {
sys_call(SyscallId::ArchPrctl, code as usize, addr, 0, 0, 0, 0)
}
#[cfg(not(any(target_arch = "riscv32", target_arch = "riscv64")))]
#[cfg(target_arch = "x86_64")]
#[allow(dead_code)]
enum SyscallId {
Read = 0,
@ -141,7 +141,6 @@ enum SyscallId {
Mmap = 9,
Munmap = 11,
Yield = 24,
Dup2 = 33,
Sleep = 35,
GetPid = 39,
Clone = 56,
@ -150,15 +149,16 @@ enum SyscallId {
Wait = 61,
Kill = 62,
Fsync = 74,
GetDirEntry = 78,
GetCwd = 79,
GetTime = 96,
SetPriority = 141,
ArchPrctl = 158,
GetDirEntry64 = 217,
Openat = 257,
Dup3 = 292,
}
#[cfg(any(target_arch = "riscv32", target_arch = "riscv64"))]
#[cfg(not(target_arch = "x86_64"))]
#[allow(dead_code)]
enum SyscallId {
Read = 63,
@ -170,7 +170,7 @@ enum SyscallId {
Mmap = 222,
Munmap = 215,
Yield = 124,
Dup2 = -1,
Dup3 = 24,
Sleep = 101,
GetPid = 172,
Clone = 220,
@ -179,7 +179,7 @@ enum SyscallId {
Wait = 260,
Kill = 129,
Fsync = 82,
GetDirEntry = -3,
GetDirEntry64 = 61,
GetCwd = 17,
GetTime = 169,
SetPriority = 140,

@ -4,6 +4,8 @@
#define T_SYSCALL 0x80
/* syscall number */
#if defined(__x86_64__) || defined(__i386__)
#define SYS_exit 60
#define SYS_fork 57
#define SYS_wait 61
@ -18,7 +20,7 @@
#define SYS_munmap 11
#define SYS_shmem -1
#define SYS_pgdir -1
#define SYS_open 2
#define SYS_openat 257
#define SYS_close 3
#define SYS_read 0
#define SYS_write 1
@ -26,15 +28,47 @@
#define SYS_fstat 5
#define SYS_fsync 74
#define SYS_getcwd 79
#define SYS_getdirentry 78
#define SYS_dup 33
#define SYS_getdirentry64 217
#define SYS_dup3 292
/* ONLY FOR LAB6 */
#define SYS_set_priority 141
#else
#define SYS_exit 93
#define SYS_fork -1
#define SYS_wait 260
#define SYS_exec 221
#define SYS_clone 220
#define SYS_yield 124
#define SYS_sleep 101
#define SYS_kill 129
#define SYS_gettime 169
#define SYS_getpid 172
#define SYS_mmap 222
#define SYS_munmap 215
#define SYS_shmem -1
#define SYS_pgdir -1
#define SYS_openat 56
#define SYS_close 57
#define SYS_read 63
#define SYS_write 64
#define SYS_seek 62
#define SYS_fstat 80
#define SYS_fsync 82
#define SYS_getcwd 17
#define SYS_getdirentry64 61
#define SYS_dup3 24
/* ONLY FOR LAB6 */
#define SYS_set_priority 140
#endif
/* SYS_fork flags */
#define CLONE_VM 0x00000100 // set if VM shared between processes
#define CLONE_THREAD 0x00000200 // thread group
#define CLONE_FS 0x00000800 // set if shared between processes
#define CLONE_VFORK 0x00004000 // set if the parent wants the child to wake it up on mm_release
/* VFS flags */
// flags for open: choose one of these

@ -76,7 +76,8 @@ sys_exit(int error_code) {
int
sys_fork(void) {
return syscall(SYS_fork);
const int SIGCHILD = 17;
return syscall(SYS_clone, CLONE_VFORK | CLONE_VM | SIGCHILD, 0);
}
int
@ -127,7 +128,8 @@ sys_exec(const char *name, int argc, const char **argv) {
int
sys_open(const char *path, uint32_t open_flags) {
return syscall(SYS_open, path, open_flags);
const int AT_FDCWD = -100;
return syscall(SYS_openat, AT_FDCWD, path, open_flags);
}
int
@ -167,10 +169,10 @@ sys_getcwd(char *buffer, size_t len) {
int
sys_getdirentry(int fd, struct dirent *dirent) {
return syscall(SYS_getdirentry, fd, dirent);
return syscall(SYS_getdirentry64, fd, dirent);
}
int
sys_dup(int fd1, int fd2) {
return syscall(SYS_dup, fd1, fd2);
return syscall(SYS_dup3, fd1, fd2);
}

Loading…
Cancel
Save