harec

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit f637476ca9a6b10b59cb64ad2bd275f904fddaea
parent 4cad49c2584ddea18817a133e02739242891a77e
Author: Drew DeVault <sir@cmpwn.com>
Date:   Sun,  7 Feb 2021 08:29:05 -0500

all: port to aarch64

Diffstat:
Art/+linux/start+aarch64.s | 8++++++++
Rrt/+linux/start.s -> rt/+linux/start+x86_64.s | 0
Art/+linux/syscall+aarch64.s | 105+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Art/+linux/syscallno+aarch64.ha | 291++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mrt/+linux/syscalls.ha | 7++++---
Mrt/compile.ha | 2+-
Mrt/configure | 11++++++-----
7 files changed, 415 insertions(+), 9 deletions(-)

diff --git a/rt/+linux/start+aarch64.s b/rt/+linux/start+aarch64.s @@ -0,0 +1,8 @@ +.text +.global _start +_start: + mov x29, #0 + mov x30, #0 + mov x0, sp + add sp, x0, #-16 + b rt.start_ha diff --git a/rt/+linux/start.s b/rt/+linux/start+x86_64.s diff --git a/rt/+linux/syscall+aarch64.s b/rt/+linux/syscall+aarch64.s @@ -0,0 +1,105 @@ +.text +.global rt.syscall0 +rt.syscall0: + sub sp, sp, #16 + str x0, [sp, 8] + ldr x8, [sp, 8] + svc 0 + add sp, sp, 16 + ret + +.global rt.syscall1 +rt.syscall1: + sub sp, sp, #16 + str x0, [sp, 8] + str x1, [sp] + ldr x8, [sp, 8] + ldr x0, [sp] + svc 0 + add sp, sp, 16 + ret + +.global rt.syscall2 +rt.syscall2: + sub sp, sp, #32 + str x0, [sp, 24] + str x1, [sp, 16] + str x2, [sp, 8] + ldr x8, [sp, 24] + ldr x0, [sp, 16] + ldr x1, [sp, 8] + svc 0 + add sp, sp, 32 + ret + +.global rt.syscall3 +rt.syscall3: + sub sp, sp, #32 + str x0, [sp, 24] + str x1, [sp, 16] + str x2, [sp, 8] + str x3, [sp] + ldr x8, [sp, 24] + ldr x0, [sp, 16] + ldr x1, [sp, 8] + ldr x2, [sp] + svc 0 + add sp, sp, 32 + ret + +.global rt.syscall4 +rt.syscall4: + sub sp, sp, #48 + str x0, [sp, 40] + str x1, [sp, 32] + str x2, [sp, 24] + str x3, [sp, 16] + str x4, [sp, 8] + ldr x8, [sp, 40] + ldr x0, [sp, 32] + ldr x1, [sp, 24] + ldr x2, [sp, 16] + ldr x3, [sp, 8] + svc 0 + add sp, sp, 48 + ret + +.global rt.syscall5 +rt.syscall5: + sub sp, sp, #48 + str x0, [sp, 40] + str x1, [sp, 32] + str x2, [sp, 24] + str x3, [sp, 16] + str x4, [sp, 8] + str x5, [sp] + ldr x8, [sp, 40] + ldr x0, [sp, 32] + ldr x1, [sp, 24] + ldr x2, [sp, 16] + ldr x3, [sp, 8] + ldr x4, [sp] + svc 0 + add sp, sp, 48 + ret + +.global rt.syscall6 +rt.syscall6: + sub sp, sp, #64 + str x0, [sp, 56] + str x1, [sp, 48] + str x2, [sp, 40] + str x3, [sp, 32] + str x4, [sp, 24] + str x5, [sp, 16] + str x6, [sp, 8] + ldr x8, [sp, 56] + ldr x0, [sp, 48] + ldr x1, [sp, 40] + ldr x2, [sp, 32] + ldr x3, [sp, 24] + ldr x4, [sp, 16] + ldr x5, [sp, 8] + svc 0 + add sp, sp, 64 + ret diff --git a/rt/+linux/syscallno+aarch64.ha b/rt/+linux/syscallno+aarch64.ha @@ -0,0 +1,291 @@ +export def SYS_io_setup: u64 = 0u64; +export def SYS_io_destroy: u64 = 1u64; +export def SYS_io_submit: u64 = 2u64; +export def SYS_io_cancel: u64 = 3u64; +export def SYS_io_getevents: u64 = 4u64; +export def SYS_setxattr: u64 = 5u64; +export def SYS_lsetxattr: u64 = 6u64; +export def SYS_fsetxattr: u64 = 7u64; +export def SYS_getxattr: u64 = 8u64; +export def SYS_lgetxattr: u64 = 9u64; +export def SYS_fgetxattr: u64 = 10u64; +export def SYS_listxattr: u64 = 11u64; +export def SYS_llistxattr: u64 = 12u64; +export def SYS_flistxattr: u64 = 13u64; +export def SYS_removexattr: u64 = 14u64; +export def SYS_lremovexattr: u64 = 15u64; +export def SYS_fremovexattr: u64 = 16u64; +export def SYS_getcwd: u64 = 17u64; +export def SYS_lookup_dcookie: u64 = 18u64; +export def SYS_eventfd2: u64 = 19u64; +export def SYS_epoll_create1: u64 = 20u64; +export def SYS_epoll_ctl: u64 = 21u64; +export def SYS_epoll_pwait: u64 = 22u64; +export def SYS_dup: u64 = 23u64; +export def SYS_dup3: u64 = 24u64; +export def SYS_fcntl: u64 = 25u64; +export def SYS_inotify_init1: u64 = 26u64; +export def SYS_inotify_add_watch: u64 = 27u64; +export def SYS_inotify_rm_watch: u64 = 28u64; +export def SYS_ioctl: u64 = 29u64; +export def SYS_ioprio_set: u64 = 30u64; +export def SYS_ioprio_get: u64 = 31u64; +export def SYS_flock: u64 = 32u64; +export def SYS_mknodat: u64 = 33u64; +export def SYS_mkdirat: u64 = 34u64; +export def SYS_unlinkat: u64 = 35u64; +export def SYS_symlinkat: u64 = 36u64; +export def SYS_linkat: u64 = 37u64; +export def SYS_renameat: u64 = 38u64; +export def SYS_umount2: u64 = 39u64; +export def SYS_mount: u64 = 40u64; +export def SYS_pivot_root: u64 = 41u64; +export def SYS_nfsservctl: u64 = 42u64; +export def SYS_statfs: u64 = 43u64; +export def SYS_fstatfs: u64 = 44u64; +export def SYS_truncate: u64 = 45u64; +export def SYS_ftruncate: u64 = 46u64; +export def SYS_fallocate: u64 = 47u64; +export def SYS_faccessat: u64 = 48u64; +export def SYS_chdir: u64 = 49u64; +export def SYS_fchdir: u64 = 50u64; +export def SYS_chroot: u64 = 51u64; +export def SYS_fchmod: u64 = 52u64; +export def SYS_fchmodat: u64 = 53u64; +export def SYS_fchownat: u64 = 54u64; +export def SYS_fchown: u64 = 55u64; +export def SYS_openat: u64 = 56u64; +export def SYS_close: u64 = 57u64; +export def SYS_vhangup: u64 = 58u64; +export def SYS_pipe2: u64 = 59u64; +export def SYS_quotactl: u64 = 60u64; +export def SYS_getdents64: u64 = 61u64; +export def SYS_lseek: u64 = 62u64; +export def SYS_read: u64 = 63u64; +export def SYS_write: u64 = 64u64; +export def SYS_readv: u64 = 65u64; +export def SYS_writev: u64 = 66u64; +export def SYS_pread64: u64 = 67u64; +export def SYS_pwrite64: u64 = 68u64; +export def SYS_preadv: u64 = 69u64; +export def SYS_pwritev: u64 = 70u64; +export def SYS_sendfile: u64 = 71u64; +export def SYS_pselect6: u64 = 72u64; +export def SYS_ppoll: u64 = 73u64; +export def SYS_signalfd4: u64 = 74u64; +export def SYS_vmsplice: u64 = 75u64; +export def SYS_splice: u64 = 76u64; +export def SYS_tee: u64 = 77u64; +export def SYS_readlinkat: u64 = 78u64; +export def SYS_newfstatat: u64 = 79u64; +export def SYS_fstat: u64 = 80u64; +export def SYS_sync: u64 = 81u64; +export def SYS_fsync: u64 = 82u64; +export def SYS_fdatasync: u64 = 83u64; +export def SYS_sync_file_range: u64 = 84u64; +export def SYS_timerfd_create: u64 = 85u64; +export def SYS_timerfd_settime: u64 = 86u64; +export def SYS_timerfd_gettime: u64 = 87u64; +export def SYS_utimensat: u64 = 88u64; +export def SYS_acct: u64 = 89u64; +export def SYS_capget: u64 = 90u64; +export def SYS_capset: u64 = 91u64; +export def SYS_personality: u64 = 92u64; +export def SYS_exit: u64 = 93u64; +export def SYS_exit_group: u64 = 94u64; +export def SYS_waitid: u64 = 95u64; +export def SYS_set_tid_address: u64 = 96u64; +export def SYS_unshare: u64 = 97u64; +export def SYS_futex: u64 = 98u64; +export def SYS_set_robust_list: u64 = 99u64; +export def SYS_get_robust_list: u64 = 100u64; +export def SYS_nanosleep: u64 = 101u64; +export def SYS_getitimer: u64 = 102u64; +export def SYS_setitimer: u64 = 103u64; +export def SYS_kexec_load: u64 = 104u64; +export def SYS_init_module: u64 = 105u64; +export def SYS_delete_module: u64 = 106u64; +export def SYS_timer_create: u64 = 107u64; +export def SYS_timer_gettime: u64 = 108u64; +export def SYS_timer_getoverrun: u64 = 109u64; +export def SYS_timer_settime: u64 = 110u64; +export def SYS_timer_delete: u64 = 111u64; +export def SYS_clock_settime: u64 = 112u64; +export def SYS_clock_gettime: u64 = 113u64; +export def SYS_clock_getres: u64 = 114u64; +export def SYS_clock_nanosleep: u64 = 115u64; +export def SYS_syslog: u64 = 116u64; +export def SYS_ptrace: u64 = 117u64; +export def SYS_sched_setparam: u64 = 118u64; +export def SYS_sched_setscheduler: u64 = 119u64; +export def SYS_sched_getscheduler: u64 = 120u64; +export def SYS_sched_getparam: u64 = 121u64; +export def SYS_sched_setaffinity: u64 = 122u64; +export def SYS_sched_getaffinity: u64 = 123u64; +export def SYS_sched_yield: u64 = 124u64; +export def SYS_sched_get_priority_max: u64 = 125u64; +export def SYS_sched_get_priority_min: u64 = 126u64; +export def SYS_sched_rr_get_interval: u64 = 127u64; +export def SYS_restart_syscall: u64 = 128u64; +export def SYS_kill: u64 = 129u64; +export def SYS_tkill: u64 = 130u64; +export def SYS_tgkill: u64 = 131u64; +export def SYS_sigaltstack: u64 = 132u64; +export def SYS_rt_sigsuspend: u64 = 133u64; +export def SYS_rt_sigaction: u64 = 134u64; +export def SYS_rt_sigprocmask: u64 = 135u64; +export def SYS_rt_sigpending: u64 = 136u64; +export def SYS_rt_sigtimedwait: u64 = 137u64; +export def SYS_rt_sigqueueinfo: u64 = 138u64; +export def SYS_rt_sigreturn: u64 = 139u64; +export def SYS_setpriority: u64 = 140u64; +export def SYS_getpriority: u64 = 141u64; +export def SYS_reboot: u64 = 142u64; +export def SYS_setregid: u64 = 143u64; +export def SYS_setgid: u64 = 144u64; +export def SYS_setreuid: u64 = 145u64; +export def SYS_setuid: u64 = 146u64; +export def SYS_setresuid: u64 = 147u64; +export def SYS_getresuid: u64 = 148u64; +export def SYS_setresgid: u64 = 149u64; +export def SYS_getresgid: u64 = 150u64; +export def SYS_setfsuid: u64 = 151u64; +export def SYS_setfsgid: u64 = 152u64; +export def SYS_times: u64 = 153u64; +export def SYS_setpgid: u64 = 154u64; +export def SYS_getpgid: u64 = 155u64; +export def SYS_getsid: u64 = 156u64; +export def SYS_setsid: u64 = 157u64; +export def SYS_getgroups: u64 = 158u64; +export def SYS_setgroups: u64 = 159u64; +export def SYS_uname: u64 = 160u64; +export def SYS_sethostname: u64 = 161u64; +export def SYS_setdomainname: u64 = 162u64; +export def SYS_getrlimit: u64 = 163u64; +export def SYS_setrlimit: u64 = 164u64; +export def SYS_getrusage: u64 = 165u64; +export def SYS_umask: u64 = 166u64; +export def SYS_prctl: u64 = 167u64; +export def SYS_getcpu: u64 = 168u64; +export def SYS_gettimeofday: u64 = 169u64; +export def SYS_settimeofday: u64 = 170u64; +export def SYS_adjtimex: u64 = 171u64; +export def SYS_getpid: u64 = 172u64; +export def SYS_getppid: u64 = 173u64; +export def SYS_getuid: u64 = 174u64; +export def SYS_geteuid: u64 = 175u64; +export def SYS_getgid: u64 = 176u64; +export def SYS_getegid: u64 = 177u64; +export def SYS_gettid: u64 = 178u64; +export def SYS_sysinfo: u64 = 179u64; +export def SYS_mq_open: u64 = 180u64; +export def SYS_mq_unlink: u64 = 181u64; +export def SYS_mq_timedsend: u64 = 182u64; +export def SYS_mq_timedreceive: u64 = 183u64; +export def SYS_mq_notify: u64 = 184u64; +export def SYS_mq_getsetattr: u64 = 185u64; +export def SYS_msgget: u64 = 186u64; +export def SYS_msgctl: u64 = 187u64; +export def SYS_msgrcv: u64 = 188u64; +export def SYS_msgsnd: u64 = 189u64; +export def SYS_semget: u64 = 190u64; +export def SYS_semctl: u64 = 191u64; +export def SYS_semtimedop: u64 = 192u64; +export def SYS_semop: u64 = 193u64; +export def SYS_shmget: u64 = 194u64; +export def SYS_shmctl: u64 = 195u64; +export def SYS_shmat: u64 = 196u64; +export def SYS_shmdt: u64 = 197u64; +export def SYS_socket: u64 = 198u64; +export def SYS_socketpair: u64 = 199u64; +export def SYS_bind: u64 = 200u64; +export def SYS_listen: u64 = 201u64; +export def SYS_accept: u64 = 202u64; +export def SYS_connect: u64 = 203u64; +export def SYS_getsockname: u64 = 204u64; +export def SYS_getpeername: u64 = 205u64; +export def SYS_sendto: u64 = 206u64; +export def SYS_recvfrom: u64 = 207u64; +export def SYS_setsockopt: u64 = 208u64; +export def SYS_getsockopt: u64 = 209u64; +export def SYS_shutdown: u64 = 210u64; +export def SYS_sendmsg: u64 = 211u64; +export def SYS_recvmsg: u64 = 212u64; +export def SYS_readahead: u64 = 213u64; +export def SYS_brk: u64 = 214u64; +export def SYS_munmap: u64 = 215u64; +export def SYS_mremap: u64 = 216u64; +export def SYS_add_key: u64 = 217u64; +export def SYS_request_key: u64 = 218u64; +export def SYS_keyctl: u64 = 219u64; +export def SYS_clone: u64 = 220u64; +export def SYS_execve: u64 = 221u64; +export def SYS_mmap: u64 = 222u64; +export def SYS_fadvise64: u64 = 223u64; +export def SYS_swapon: u64 = 224u64; +export def SYS_swapoff: u64 = 225u64; +export def SYS_mprotect: u64 = 226u64; +export def SYS_msync: u64 = 227u64; +export def SYS_mlock: u64 = 228u64; +export def SYS_munlock: u64 = 229u64; +export def SYS_mlockall: u64 = 230u64; +export def SYS_munlockall: u64 = 231u64; +export def SYS_mincore: u64 = 232u64; +export def SYS_madvise: u64 = 233u64; +export def SYS_remap_file_pages: u64 = 234u64; +export def SYS_mbind: u64 = 235u64; +export def SYS_get_mempolicy: u64 = 236u64; +export def SYS_set_mempolicy: u64 = 237u64; +export def SYS_migrate_pages: u64 = 238u64; +export def SYS_move_pages: u64 = 239u64; +export def SYS_rt_tgsigqueueinfo: u64 = 240u64; +export def SYS_perf_event_open: u64 = 241u64; +export def SYS_accept4: u64 = 242u64; +export def SYS_recvmmsg: u64 = 243u64; +export def SYS_wait4: u64 = 260u64; +export def SYS_prlimit64: u64 = 261u64; +export def SYS_fanotify_init: u64 = 262u64; +export def SYS_fanotify_mark: u64 = 263u64; +export def SYS_name_to_handle_at: u64 = 264u64; +export def SYS_open_by_handle_at: u64 = 265u64; +export def SYS_clock_adjtime: u64 = 266u64; +export def SYS_syncfs: u64 = 267u64; +export def SYS_setns: u64 = 268u64; +export def SYS_sendmmsg: u64 = 269u64; +export def SYS_process_vm_readv: u64 = 270u64; +export def SYS_process_vm_writev: u64 = 271u64; +export def SYS_kcmp: u64 = 272u64; +export def SYS_finit_module: u64 = 273u64; +export def SYS_sched_setattr: u64 = 274u64; +export def SYS_sched_getattr: u64 = 275u64; +export def SYS_renameat2: u64 = 276u64; +export def SYS_seccomp: u64 = 277u64; +export def SYS_getrandom: u64 = 278u64; +export def SYS_memfd_create: u64 = 279u64; +export def SYS_bpf: u64 = 280u64; +export def SYS_execveat: u64 = 281u64; +export def SYS_userfaultfd: u64 = 282u64; +export def SYS_membarrier: u64 = 283u64; +export def SYS_mlock2: u64 = 284u64; +export def SYS_copy_file_range: u64 = 285u64; +export def SYS_preadv2: u64 = 286u64; +export def SYS_pwritev2: u64 = 287u64; +export def SYS_pkey_mprotect: u64 = 288u64; +export def SYS_pkey_alloc: u64 = 289u64; +export def SYS_pkey_free: u64 = 290u64; +export def SYS_statx: u64 = 291u64; +export def SYS_io_pgetevents: u64 = 292u64; +export def SYS_rseq: u64 = 293u64; +export def SYS_kexec_file_load: u64 = 294u64; +export def SYS_pidfd_send_signal: u64 = 424u64; +export def SYS_io_uring_setup: u64 = 425u64; +export def SYS_io_uring_enter: u64 = 426u64; +export def SYS_io_uring_register: u64 = 427u64; +export def SYS_open_tree: u64 = 428u64; +export def SYS_move_mount: u64 = 429u64; +export def SYS_fsopen: u64 = 430u64; +export def SYS_fsconfig: u64 = 431u64; +export def SYS_fsmount: u64 = 432u64; +export def SYS_fspick: u64 = 433u64; +export def SYS_pidfd_open: u64 = 434u64; +export def SYS_clone3: u64 = 435u64; diff --git a/rt/+linux/syscalls.ha b/rt/+linux/syscalls.ha @@ -11,14 +11,14 @@ export fn write(fd: int, buf: *const void, count: size) size = export fn close(fd: int) int = syscall1(SYS_close, fd: u64): int; -export fn dup2(old: int, new: int) int = - syscall2(SYS_dup2, old: u64, new: u64): int; +export fn dup3(old: int, new: int, flags: int) int = + syscall3(SYS_dup3, old: u64, new: u64, flags: u64): int; export fn getpid() int = syscall0(SYS_getpid): int; export @noreturn fn exit(status: int) void = syscall1(SYS_exit, status: u64); -export fn fork() int = syscall0(SYS_fork): int; +export fn fork() int = syscall2(SYS_clone, SIGCHLD: u64, 0u64): int; export fn execve( path: *const char, @@ -104,3 +104,4 @@ export fn mprotect(addr: *void, length: size, prot: uint) int = syscall3(SYS_mprotect, addr: uintptr: u64, length: u64, prot: u64): int; export def SIGABRT: int = 6; +export def SIGCHLD: int = 17; diff --git a/rt/compile.ha b/rt/compile.ha @@ -7,7 +7,7 @@ export fn compile(src: const str) int = { const child = fork(); if (child == 0) { close(pipefd[1]); - dup2(pipefd[0], 0); + dup3(pipefd[0], 0, 0); close(1); close(2); diff --git a/rt/configure b/rt/configure @@ -2,22 +2,23 @@ all="$all rt" rt() { + arch=$(uname -m) case $(uname) in Linux) - rtstart=rt/+linux/start.o + rtstart=rt/+linux/start+$arch.o cat <<-EOF - rtstart=rt/+linux/start.o + rtstart=rt/+linux/start+$arch.o libhart_srcs=\ rt/+linux/errno.ha \ rt/+linux/segmalloc.ha \ - rt/+linux/syscallno+x86_64.ha \ + rt/+linux/syscallno+$arch.ha \ rt/+linux/syscalls.ha libhart_objs=\ - rt/+linux/syscall+x86_64.o + rt/+linux/syscall+$arch.o - rt: libhart.a rt/+linux/start.o + rt: libhart.a rt/+linux/start+$arch.o EOF ;; *)