Index: head/share/man/man4/cloudabi.4 =================================================================== --- head/share/man/man4/cloudabi.4 +++ head/share/man/man4/cloudabi.4 @@ -22,7 +22,7 @@ .\" SUCH DAMAGE. .\" .\" $FreeBSD$ -.Dd July 31, 2015 +.Dd October 22, 2015 .Dt CLOUDABI 4 .Os .Sh NAME @@ -73,7 +73,7 @@ .Fx , the .Nm cloudabi64 -module is only available for amd64. +module is only available for amd64 and arm64. .Pp A full cross compilation toolchain for CloudABI is available in the .Pa devel/cloudabi-toolchain @@ -95,6 +95,9 @@ .Pp cloudlibc on GitHub: .Pa https://github.com/NuxiNL/cloudlibc . +.Pp +The CloudABI Ports Collection on GitHub: +.Pa https://github.com/NuxiNL/cloudabi-ports . .Sh HISTORY CloudABI support first appeared in .Fx 11.0 . Index: head/sys/arm64/cloudabi64/cloudabi64_sysvec.c =================================================================== --- head/sys/arm64/cloudabi64/cloudabi64_sysvec.c +++ head/sys/arm64/cloudabi64/cloudabi64_sysvec.c @@ -0,0 +1,162 @@ +/*- + * Copyright (c) 2015 Nuxi, https://nuxi.nl/ + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#include +__FBSDID("$FreeBSD$"); + +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include + +extern const char *cloudabi64_syscallnames[]; +extern struct sysent cloudabi64_sysent[]; + +static int +cloudabi64_fetch_syscall_args(struct thread *td, struct syscall_args *sa) +{ + struct trapframe *frame = td->td_frame; + int i; + + /* Obtain system call number. */ + sa->code = frame->tf_x[8]; + if (sa->code >= CLOUDABI64_SYS_MAXSYSCALL) + return (ENOSYS); + sa->callp = &cloudabi64_sysent[sa->code]; + + /* Fetch system call arguments. */ + for (i = 0; i < MAXARGS; i++) + sa->args[i] = frame->tf_x[i]; + + /* Default system call return values. */ + td->td_retval[0] = 0; + td->td_retval[1] = frame->tf_x[1]; + return (0); +} + +static void +cloudabi64_set_syscall_retval(struct thread *td, int error) +{ + struct trapframe *frame = td->td_frame; + + switch (error) { + case 0: + /* System call succeeded. */ + frame->tf_x[0] = td->td_retval[0]; + frame->tf_x[1] = td->td_retval[1]; + frame->tf_spsr &= ~PSR_C; + break; + case ERESTART: + /* Restart system call. */ + frame->tf_elr -= 4; + break; + case EJUSTRETURN: + break; + default: + /* System call returned an error. */ + frame->tf_x[0] = cloudabi_convert_errno(error); + frame->tf_spsr |= PSR_C; + break; + } +} + +static void +cloudabi64_schedtail(struct thread *td) +{ + struct trapframe *frame = td->td_frame; + + /* + * Initial register values for processes returning from fork. + * Make sure that we only set these values when forking, not + * when creating a new thread. + */ + if ((td->td_pflags & TDP_FORKING) != 0) { + frame->tf_x[0] = CLOUDABI_PROCESS_CHILD; + frame->tf_x[1] = td->td_tid; + } +} + +void +cloudabi64_thread_setregs(struct thread *td, + const cloudabi64_threadattr_t *attr) +{ + struct trapframe *frame; + stack_t stack; + + /* Perform standard register initialization. */ + stack.ss_sp = (void *)attr->stack; + stack.ss_size = attr->stack_size; + cpu_set_upcall_kse(td, (void *)attr->entry_point, NULL, &stack); + + /* + * Pass in the thread ID of the new thread and the argument + * pointer provided by the parent thread in as arguments to the + * entry point. + */ + frame = td->td_frame; + frame->tf_x[0] = td->td_tid; + frame->tf_x[1] = attr->argument; +} + +static struct sysentvec cloudabi64_elf_sysvec = { + .sv_size = CLOUDABI64_SYS_MAXSYSCALL, + .sv_table = cloudabi64_sysent, + .sv_fixup = cloudabi64_fixup, + .sv_name = "CloudABI ELF64", + .sv_coredump = elf64_coredump, + .sv_pagesize = PAGE_SIZE, + .sv_minuser = VM_MIN_ADDRESS, + .sv_maxuser = VM_MAXUSER_ADDRESS, + .sv_usrstack = USRSTACK, + .sv_stackprot = VM_PROT_READ | VM_PROT_WRITE, + .sv_copyout_strings = cloudabi64_copyout_strings, + .sv_flags = SV_ABI_CLOUDABI | SV_CAPSICUM, + .sv_set_syscall_retval = cloudabi64_set_syscall_retval, + .sv_fetch_syscall_args = cloudabi64_fetch_syscall_args, + .sv_syscallnames = cloudabi64_syscallnames, + .sv_schedtail = cloudabi64_schedtail, +}; + +INIT_SYSENTVEC(elf_sysvec, &cloudabi64_elf_sysvec); + +Elf64_Brandinfo cloudabi64_brand = { + .brand = ELFOSABI_CLOUDABI, + .machine = EM_AARCH64, + .sysvec = &cloudabi64_elf_sysvec, + .compat_3_brand = "CloudABI", +}; Index: head/sys/conf/files.arm64 =================================================================== --- head/sys/conf/files.arm64 +++ head/sys/conf/files.arm64 @@ -53,6 +53,7 @@ arm64/cavium/thunder_pcie.c optional soc_cavm_thunderx pci fdt arm64/cavium/thunder_pcie_pem.c optional soc_cavm_thunderx pci arm64/cavium/thunder_pcie_common.c optional soc_cavm_thunderx pci +arm64/cloudabi64/cloudabi64_sysvec.c optional compat_cloudabi64 crypto/blowfish/bf_enc.c optional crypto | ipsec crypto/des/des_enc.c optional crypto | ipsec | netsmb dev/acpica/acpi_if.m optional acpi Index: head/sys/modules/Makefile =================================================================== --- head/sys/modules/Makefile +++ head/sys/modules/Makefile @@ -633,7 +633,6 @@ .endif .if ${MACHINE_CPUARCH} == "amd64" -_cloudabi64= cloudabi64 _ioat= ioat _ixl= ixl _ixlv= ixlv @@ -749,6 +748,10 @@ .endif .endif +.if ${MACHINE_CPUARCH} == "aarch64" || ${MACHINE_CPUARCH} == "amd64" +_cloudabi64= cloudabi64 +.endif + .endif SUBDIR+=${MODULES_EXTRA}