mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-21 11:13:30 +00:00
Make CloudABI work on i386.
Copy over amd64's cloudabi64_sysvec.c into i386 and tailor it to work. Again, we use a system call convention similar to FreeBSD, except that there is no support for indirect system calls (%eax == 0). Where i386 differs from amd64 is that we have to store thread/process entry arguments on the stack instead of using registers. We also have to put an extra pointer on the stack for TLS (for GSBASE). Place that pointer in the empty slot that is normally used to hold return addresses. That seems to keep the code simple. Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D7590
This commit is contained in:
parent
ded67349a3
commit
8b0a83cce2
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=304615
@ -7,6 +7,18 @@
|
||||
# limitations in config: backslash-newline doesn't work in strings, and
|
||||
# dependency lines other than the first are silently ignored.
|
||||
#
|
||||
cloudabi32_vdso.o optional compat_cloudabi32 \
|
||||
dependency "$S/contrib/cloudabi/cloudabi_vdso_i686.S" \
|
||||
compile-with "${CC} -x assembler-with-cpp -shared -nostdinc -nostdlib -Wl,-T$S/compat/cloudabi/cloudabi_vdso.lds $S/contrib/cloudabi/cloudabi_vdso_i686.S -o ${.TARGET}" \
|
||||
no-obj no-implicit-rule \
|
||||
clean "cloudabi32_vdso.o"
|
||||
#
|
||||
cloudabi32_vdso_blob.o optional compat_cloudabi32 \
|
||||
dependency "cloudabi32_vdso.o" \
|
||||
compile-with "${OBJCOPY} --input-target binary --output-target elf32-i386-freebsd --binary-architecture i386 cloudabi32_vdso.o ${.TARGET}" \
|
||||
no-implicit-rule \
|
||||
clean "cloudabi32_vdso_blob.o"
|
||||
#
|
||||
linux_genassym.o optional compat_linux \
|
||||
dependency "$S/i386/linux/linux_genassym.c" \
|
||||
compile-with "${CC} ${CFLAGS:N-fno-common} -c ${.IMPSRC}" \
|
||||
@ -456,6 +468,7 @@ i386/bios/apm.c optional apm
|
||||
i386/bios/mca_machdep.c optional mca
|
||||
i386/bios/smapi.c optional smapi
|
||||
i386/bios/smapi_bios.S optional smapi
|
||||
i386/cloudabi32/cloudabi32_sysvec.c optional compat_cloudabi32
|
||||
#i386/i386/apic_vector.s optional apic
|
||||
i386/i386/atomic.c standard \
|
||||
compile-with "${CC} -c ${CFLAGS} ${DEFINED_PROF:S/^$/-fomit-frame-pointer/} ${.IMPSRC}"
|
||||
|
477
sys/contrib/cloudabi/cloudabi_vdso_i686.S
Normal file
477
sys/contrib/cloudabi/cloudabi_vdso_i686.S
Normal file
@ -0,0 +1,477 @@
|
||||
// Copyright (c) 2016 Nuxi (https://nuxi.nl/) and contributors.
|
||||
//
|
||||
// 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.
|
||||
//
|
||||
// This file is automatically generated. Do not edit.
|
||||
//
|
||||
// Source: https://github.com/NuxiNL/cloudabi
|
||||
|
||||
#define ENTRY(name) \
|
||||
.text; \
|
||||
.p2align 2, 0x90; \
|
||||
.global name; \
|
||||
.type name, @function; \
|
||||
name:
|
||||
|
||||
#define END(name) .size name, . - name
|
||||
|
||||
ENTRY(cloudabi_sys_clock_res_get)
|
||||
mov $0, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0x8(%esp), %ecx
|
||||
mov %eax, 0(%ecx)
|
||||
mov %edx, 4(%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_clock_res_get)
|
||||
|
||||
ENTRY(cloudabi_sys_clock_time_get)
|
||||
mov $1, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0x10(%esp), %ecx
|
||||
mov %eax, 0(%ecx)
|
||||
mov %edx, 4(%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_clock_time_get)
|
||||
|
||||
ENTRY(cloudabi_sys_condvar_signal)
|
||||
mov $2, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_condvar_signal)
|
||||
|
||||
ENTRY(cloudabi_sys_fd_close)
|
||||
mov $3, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_fd_close)
|
||||
|
||||
ENTRY(cloudabi_sys_fd_create1)
|
||||
mov $4, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0x8(%esp), %ecx
|
||||
mov %eax, (%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_fd_create1)
|
||||
|
||||
ENTRY(cloudabi_sys_fd_create2)
|
||||
mov $5, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0x8(%esp), %ecx
|
||||
mov %eax, (%ecx)
|
||||
mov 0xc(%esp), %ecx
|
||||
mov %edx, (%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_fd_create2)
|
||||
|
||||
ENTRY(cloudabi_sys_fd_datasync)
|
||||
mov $6, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_fd_datasync)
|
||||
|
||||
ENTRY(cloudabi_sys_fd_dup)
|
||||
mov $7, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0x8(%esp), %ecx
|
||||
mov %eax, (%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_fd_dup)
|
||||
|
||||
ENTRY(cloudabi_sys_fd_pread)
|
||||
mov $8, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0x18(%esp), %ecx
|
||||
mov %eax, (%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_fd_pread)
|
||||
|
||||
ENTRY(cloudabi_sys_fd_pwrite)
|
||||
mov $9, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0x18(%esp), %ecx
|
||||
mov %eax, (%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_fd_pwrite)
|
||||
|
||||
ENTRY(cloudabi_sys_fd_read)
|
||||
mov $10, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0x10(%esp), %ecx
|
||||
mov %eax, (%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_fd_read)
|
||||
|
||||
ENTRY(cloudabi_sys_fd_replace)
|
||||
mov $11, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_fd_replace)
|
||||
|
||||
ENTRY(cloudabi_sys_fd_seek)
|
||||
mov $12, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0x14(%esp), %ecx
|
||||
mov %eax, 0(%ecx)
|
||||
mov %edx, 4(%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_fd_seek)
|
||||
|
||||
ENTRY(cloudabi_sys_fd_stat_get)
|
||||
mov $13, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_fd_stat_get)
|
||||
|
||||
ENTRY(cloudabi_sys_fd_stat_put)
|
||||
mov $14, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_fd_stat_put)
|
||||
|
||||
ENTRY(cloudabi_sys_fd_sync)
|
||||
mov $15, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_fd_sync)
|
||||
|
||||
ENTRY(cloudabi_sys_fd_write)
|
||||
mov $16, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0x10(%esp), %ecx
|
||||
mov %eax, (%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_fd_write)
|
||||
|
||||
ENTRY(cloudabi_sys_file_advise)
|
||||
mov $17, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_file_advise)
|
||||
|
||||
ENTRY(cloudabi_sys_file_allocate)
|
||||
mov $18, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_file_allocate)
|
||||
|
||||
ENTRY(cloudabi_sys_file_create)
|
||||
mov $19, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_file_create)
|
||||
|
||||
ENTRY(cloudabi_sys_file_link)
|
||||
mov $20, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_file_link)
|
||||
|
||||
ENTRY(cloudabi_sys_file_open)
|
||||
mov $21, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0x1c(%esp), %ecx
|
||||
mov %eax, (%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_file_open)
|
||||
|
||||
ENTRY(cloudabi_sys_file_readdir)
|
||||
mov $22, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0x18(%esp), %ecx
|
||||
mov %eax, (%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_file_readdir)
|
||||
|
||||
ENTRY(cloudabi_sys_file_readlink)
|
||||
mov $23, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0x18(%esp), %ecx
|
||||
mov %eax, (%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_file_readlink)
|
||||
|
||||
ENTRY(cloudabi_sys_file_rename)
|
||||
mov $24, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_file_rename)
|
||||
|
||||
ENTRY(cloudabi_sys_file_stat_fget)
|
||||
mov $25, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_file_stat_fget)
|
||||
|
||||
ENTRY(cloudabi_sys_file_stat_fput)
|
||||
mov $26, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_file_stat_fput)
|
||||
|
||||
ENTRY(cloudabi_sys_file_stat_get)
|
||||
mov $27, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_file_stat_get)
|
||||
|
||||
ENTRY(cloudabi_sys_file_stat_put)
|
||||
mov $28, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_file_stat_put)
|
||||
|
||||
ENTRY(cloudabi_sys_file_symlink)
|
||||
mov $29, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_file_symlink)
|
||||
|
||||
ENTRY(cloudabi_sys_file_unlink)
|
||||
mov $30, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_file_unlink)
|
||||
|
||||
ENTRY(cloudabi_sys_lock_unlock)
|
||||
mov $31, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_lock_unlock)
|
||||
|
||||
ENTRY(cloudabi_sys_mem_advise)
|
||||
mov $32, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_mem_advise)
|
||||
|
||||
ENTRY(cloudabi_sys_mem_lock)
|
||||
mov $33, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_mem_lock)
|
||||
|
||||
ENTRY(cloudabi_sys_mem_map)
|
||||
mov $34, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0x20(%esp), %ecx
|
||||
mov %eax, (%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_mem_map)
|
||||
|
||||
ENTRY(cloudabi_sys_mem_protect)
|
||||
mov $35, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_mem_protect)
|
||||
|
||||
ENTRY(cloudabi_sys_mem_sync)
|
||||
mov $36, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_mem_sync)
|
||||
|
||||
ENTRY(cloudabi_sys_mem_unlock)
|
||||
mov $37, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_mem_unlock)
|
||||
|
||||
ENTRY(cloudabi_sys_mem_unmap)
|
||||
mov $38, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_mem_unmap)
|
||||
|
||||
ENTRY(cloudabi_sys_poll)
|
||||
mov $39, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0x10(%esp), %ecx
|
||||
mov %eax, (%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_poll)
|
||||
|
||||
ENTRY(cloudabi_sys_poll_fd)
|
||||
mov $40, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0x1c(%esp), %ecx
|
||||
mov %eax, (%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_poll_fd)
|
||||
|
||||
ENTRY(cloudabi_sys_proc_exec)
|
||||
mov $41, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_proc_exec)
|
||||
|
||||
ENTRY(cloudabi_sys_proc_exit)
|
||||
mov $42, %eax
|
||||
int $0x80
|
||||
END(cloudabi_sys_proc_exit)
|
||||
|
||||
ENTRY(cloudabi_sys_proc_fork)
|
||||
mov $43, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0x4(%esp), %ecx
|
||||
mov %eax, (%ecx)
|
||||
mov 0x8(%esp), %ecx
|
||||
mov %edx, (%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_proc_fork)
|
||||
|
||||
ENTRY(cloudabi_sys_proc_raise)
|
||||
mov $44, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_proc_raise)
|
||||
|
||||
ENTRY(cloudabi_sys_random_get)
|
||||
mov $45, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_random_get)
|
||||
|
||||
ENTRY(cloudabi_sys_sock_accept)
|
||||
mov $46, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0xc(%esp), %ecx
|
||||
mov %eax, (%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_sock_accept)
|
||||
|
||||
ENTRY(cloudabi_sys_sock_bind)
|
||||
mov $47, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_sock_bind)
|
||||
|
||||
ENTRY(cloudabi_sys_sock_connect)
|
||||
mov $48, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_sock_connect)
|
||||
|
||||
ENTRY(cloudabi_sys_sock_listen)
|
||||
mov $49, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_sock_listen)
|
||||
|
||||
ENTRY(cloudabi_sys_sock_recv)
|
||||
mov $50, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_sock_recv)
|
||||
|
||||
ENTRY(cloudabi_sys_sock_send)
|
||||
mov $51, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_sock_send)
|
||||
|
||||
ENTRY(cloudabi_sys_sock_shutdown)
|
||||
mov $52, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_sock_shutdown)
|
||||
|
||||
ENTRY(cloudabi_sys_sock_stat_get)
|
||||
mov $53, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_sock_stat_get)
|
||||
|
||||
ENTRY(cloudabi_sys_thread_create)
|
||||
mov $54, %eax
|
||||
int $0x80
|
||||
jc 1f
|
||||
mov 0x8(%esp), %ecx
|
||||
mov %eax, (%ecx)
|
||||
xor %eax, %eax
|
||||
1:
|
||||
ret
|
||||
END(cloudabi_sys_thread_create)
|
||||
|
||||
ENTRY(cloudabi_sys_thread_exit)
|
||||
mov $55, %eax
|
||||
int $0x80
|
||||
END(cloudabi_sys_thread_exit)
|
||||
|
||||
ENTRY(cloudabi_sys_thread_yield)
|
||||
mov $56, %eax
|
||||
int $0x80
|
||||
ret
|
||||
END(cloudabi_sys_thread_yield)
|
204
sys/i386/cloudabi32/cloudabi32_sysvec.c
Normal file
204
sys/i386/cloudabi32/cloudabi32_sysvec.c
Normal file
@ -0,0 +1,204 @@
|
||||
/*-
|
||||
* Copyright (c) 2015-2016 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 <sys/cdefs.h>
|
||||
__FBSDID("$FreeBSD$");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/imgact.h>
|
||||
#include <sys/kernel.h>
|
||||
#include <sys/proc.h>
|
||||
#include <sys/sysent.h>
|
||||
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
|
||||
#include <machine/frame.h>
|
||||
#include <machine/pcb.h>
|
||||
#include <machine/vmparam.h>
|
||||
|
||||
#include <compat/cloudabi/cloudabi_util.h>
|
||||
|
||||
#include <compat/cloudabi32/cloudabi32_syscall.h>
|
||||
#include <compat/cloudabi32/cloudabi32_util.h>
|
||||
|
||||
extern const char *cloudabi32_syscallnames[];
|
||||
extern struct sysent cloudabi32_sysent[];
|
||||
|
||||
static int
|
||||
cloudabi32_fixup_tcb(register_t **stack_base, struct image_params *imgp)
|
||||
{
|
||||
int error;
|
||||
uint32_t args[2];
|
||||
|
||||
/* Place auxiliary vector and TCB on the stack. */
|
||||
error = cloudabi32_fixup(stack_base, imgp);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
/*
|
||||
* On i386, the TCB is referred to by %gs:0. Reuse the empty
|
||||
* space normally used by the return address (args[0]) to store
|
||||
* a single element array, containing a pointer to the TCB. %gs
|
||||
* base will point to this.
|
||||
*
|
||||
* Also let the first argument of the entry point (args[1])
|
||||
* refer to the auxiliary vector, which is stored right after
|
||||
* the TCB.
|
||||
*/
|
||||
args[0] = (uintptr_t)*stack_base;
|
||||
args[1] = (uintptr_t)*stack_base +
|
||||
roundup(sizeof(cloudabi32_tcb_t), sizeof(register_t));
|
||||
*stack_base -= howmany(sizeof(args), sizeof(register_t));
|
||||
return (copyout(args, *stack_base, sizeof(args)));
|
||||
}
|
||||
|
||||
static void
|
||||
cloudabi32_proc_setregs(struct thread *td, struct image_params *imgp,
|
||||
unsigned long stack)
|
||||
{
|
||||
|
||||
exec_setregs(td, imgp, stack);
|
||||
(void)cpu_set_user_tls(td, (void *)stack);
|
||||
}
|
||||
|
||||
static int
|
||||
cloudabi32_fetch_syscall_args(struct thread *td, struct syscall_args *sa)
|
||||
{
|
||||
struct trapframe *frame = td->td_frame;
|
||||
int error;
|
||||
|
||||
/* Obtain system call number. */
|
||||
sa->code = frame->tf_eax;
|
||||
if (sa->code >= CLOUDABI32_SYS_MAXSYSCALL)
|
||||
return (ENOSYS);
|
||||
sa->callp = &cloudabi32_sysent[sa->code];
|
||||
sa->narg = sa->callp->sy_narg;
|
||||
|
||||
/* Fetch system call arguments from the stack. */
|
||||
error = copyin((void *)(frame->tf_esp + 4), sa->args,
|
||||
sa->narg * sizeof(sa->args[0]));
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
/* Default system call return values. */
|
||||
td->td_retval[0] = 0;
|
||||
td->td_retval[1] = frame->tf_edx;
|
||||
return (0);
|
||||
}
|
||||
|
||||
static void
|
||||
cloudabi32_set_syscall_retval(struct thread *td, int error)
|
||||
{
|
||||
struct trapframe *frame = td->td_frame;
|
||||
|
||||
switch (error) {
|
||||
case 0:
|
||||
/* System call succeeded. */
|
||||
frame->tf_eax = td->td_retval[0];
|
||||
frame->tf_edx = td->td_retval[1];
|
||||
frame->tf_eflags &= ~PSL_C;
|
||||
break;
|
||||
case ERESTART:
|
||||
/* Restart system call. */
|
||||
frame->tf_eip -= frame->tf_err;
|
||||
break;
|
||||
case EJUSTRETURN:
|
||||
break;
|
||||
default:
|
||||
/* System call returned an error. */
|
||||
frame->tf_eax = cloudabi_convert_errno(error);
|
||||
frame->tf_eflags |= PSL_C;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
cloudabi32_schedtail(struct thread *td)
|
||||
{
|
||||
struct trapframe *frame = td->td_frame;
|
||||
|
||||
/* Initial register values for processes returning from fork. */
|
||||
frame->tf_eax = CLOUDABI_PROCESS_CHILD;
|
||||
frame->tf_edx = td->td_tid;
|
||||
}
|
||||
|
||||
int
|
||||
cloudabi32_thread_setregs(struct thread *td,
|
||||
const cloudabi32_threadattr_t *attr, uint32_t tcb)
|
||||
{
|
||||
stack_t stack;
|
||||
uint32_t args[3];
|
||||
void *frameptr;
|
||||
int error;
|
||||
|
||||
/* Perform standard register initialization. */
|
||||
stack.ss_sp = (void *)attr->stack;
|
||||
stack.ss_size = attr->stack_size - sizeof(args);
|
||||
cpu_set_upcall(td, (void *)attr->entry_point, NULL, &stack);
|
||||
|
||||
/*
|
||||
* Copy the arguments for the thread entry point onto the stack
|
||||
* (args[1] and args[2]). Similar to process startup, use the
|
||||
* otherwise unused return address (args[0]) for TLS.
|
||||
*/
|
||||
args[0] = tcb;
|
||||
args[1] = td->td_tid;
|
||||
args[2] = attr->argument;
|
||||
frameptr = (void *)td->td_frame->tf_esp;
|
||||
error = copyout(args, frameptr, sizeof(args));
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
return (cpu_set_user_tls(td, frameptr));
|
||||
}
|
||||
|
||||
static struct sysentvec cloudabi32_elf_sysvec = {
|
||||
.sv_size = CLOUDABI32_SYS_MAXSYSCALL,
|
||||
.sv_table = cloudabi32_sysent,
|
||||
.sv_fixup = cloudabi32_fixup_tcb,
|
||||
.sv_name = "CloudABI ELF32",
|
||||
.sv_coredump = elf32_coredump,
|
||||
.sv_pagesize = PAGE_SIZE,
|
||||
.sv_minuser = VM_MIN_ADDRESS,
|
||||
.sv_maxuser = VM_MAXUSER_ADDRESS,
|
||||
.sv_stackprot = VM_PROT_READ | VM_PROT_WRITE,
|
||||
.sv_copyout_strings = cloudabi32_copyout_strings,
|
||||
.sv_setregs = cloudabi32_proc_setregs,
|
||||
.sv_flags = SV_ABI_CLOUDABI | SV_CAPSICUM | SV_IA32 | SV_ILP32,
|
||||
.sv_set_syscall_retval = cloudabi32_set_syscall_retval,
|
||||
.sv_fetch_syscall_args = cloudabi32_fetch_syscall_args,
|
||||
.sv_syscallnames = cloudabi32_syscallnames,
|
||||
.sv_schedtail = cloudabi32_schedtail,
|
||||
};
|
||||
|
||||
INIT_SYSENTVEC(elf_sysvec, &cloudabi32_elf_sysvec);
|
||||
|
||||
Elf32_Brandinfo cloudabi32_brand = {
|
||||
.brand = ELFOSABI_CLOUDABI,
|
||||
.machine = EM_386,
|
||||
.sysvec = &cloudabi32_elf_sysvec,
|
||||
.compat_3_brand = "CloudABI",
|
||||
};
|
@ -973,6 +973,9 @@ options NKPT=31
|
||||
# Emulate spx device for client side of SVR3 local X interface
|
||||
options SPX_HACK
|
||||
|
||||
# Enable 32-bit runtime support for CloudABI binaries.
|
||||
options COMPAT_CLOUDABI32
|
||||
|
||||
# Enable Linux ABI emulation
|
||||
options COMPAT_LINUX
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user