arch/at91sam3x8e: use r0 for syscall number

This commit is contained in:
Felix Kopp 2021-01-05 15:30:36 +01:00
parent ef25cd9fbb
commit 8252f14b6b
No known key found for this signature in database
GPG key ID: C478BA0A85F75728
9 changed files with 44 additions and 39 deletions

View file

@ -9,29 +9,32 @@
#include <errno.h>
#include <stddef.h>
#include <unistd.h>
void arch_syscall(void *sp)
void arch_enter(void *sp)
{
struct reg_snapshot *regs = sp;
enum syscall sc_num = arch_syscall_num(regs);
int (*handler)(sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
sysarg_t arg4, sysarg_t arg5, sysarg_t arg6);
int (*handler)(sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4);
int sc_ret;
if (sc_num == SYSCALL_WRITE)
*(uint32_t *)0x400E1030U = 1 << 27;
if (sc_num > NSYSCALLS) {
arch_syscall_set_rval(regs, -EINVAL);
return;
}
handler = syscall_table[sc_num];
handler = sys_table[sc_num];
if (handler == NULL) {
arch_syscall_set_rval(regs, -EINVAL);
return;
}
/* TODO: not every syscall uses the max amount of parameters (duh) */
sc_ret = handler(arch_syscall_arg1(regs), arch_syscall_arg2(regs), arch_syscall_arg3(regs),
arch_syscall_arg4(regs), arch_syscall_arg5(regs), arch_syscall_arg6(regs));
sc_ret = handler(arch_syscall_arg1(regs), arch_syscall_arg2(regs),
arch_syscall_arg3(regs), arch_syscall_arg4(regs));
arch_syscall_set_rval(regs, sc_ret);
}

View file

@ -6,7 +6,7 @@
.text
.extern arch_syscall
.extern arch_enter
.thumb_func
.global irq_svc
@ -41,7 +41,7 @@ irq_svc:
push {r3-r7} /* r8-r11, lr */
mov r0, sp
bl arch_syscall /* arch_syscall(sp); */
bl arch_enter /* arch_enter(sp); */
pop {r3-r7} /* r8-r11, lr */
mov lr, r7

View file

@ -1,26 +1,20 @@
/* SPDX-License-Identifier: BSD-3-Clause */
/* See the end of this file for copyright, licensing, and warranty information. */
/*
* This is a collection of system calls that are exported to userspace.
* The Ardix syscall ABI for parameter passing is aligned with the AAPCS, making
* these wrappers extremely simple because all parameters are already in the
* correct registers.
*/
.syntax unified
.thumb
/* these syscalls are only there to be exported to userspace */
/* this is only invoked from user space, obviously */
.section .text.shared
.thumb_func
.global pwrite
.type pwrite, %function
pwrite:
.global syscall
.type syscall, %function
/* int syscall(int number, int arg1, int arg2, int arg3, int arg4); */
syscall:
svc #1
bx lr
.size pwrite, .-pwrite
.size syscall, .-syscall
/*
* Copyright (c) 2020 Felix Kopp <sandtler@sandtler.club>

View file

@ -54,15 +54,13 @@ struct reg_snapshot {
struct reg_hw_snapshot hw;
};
#define arch_syscall_num(reg_snap) ( ((uint8_t *)((reg_snap)->hw.lr))[1] )
#define arch_syscall_arg1(reg_snap) ((reg_snap)->hw.r0)
#define arch_syscall_arg2(reg_snap) ((reg_snap)->hw.r1)
#define arch_syscall_arg3(reg_snap) ((reg_snap)->hw.r2)
#define arch_syscall_arg4(reg_snap) ((reg_snap)->hw.r3)
#define arch_syscall_arg5(reg_snap) ((reg_snap)->sw.r8)
#define arch_syscall_arg6(reg_snap) ((reg_snap)->sw.r9)
#define arch_syscall_num(reg_snap) ((reg_snap)->hw.r0)
#define arch_syscall_arg1(reg_snap) ((reg_snap)->hw.r1)
#define arch_syscall_arg2(reg_snap) ((reg_snap)->hw.r2)
#define arch_syscall_arg3(reg_snap) ((reg_snap)->hw.r3)
#define arch_syscall_arg4(reg_snap) ((reg_snap)->hw.r12)
#define arch_syscall_set_rval(reg_snap, val) ((reg_snap)->hw.r0 = (uint32_t)(val));
#define arch_syscall_set_rval(reg_snap, val) ((reg_snap)->hw.r0 = (val));
/*
* Real-time Timer (RTT)

View file

@ -12,7 +12,7 @@
*
* @param sp: The current stack pointer.
*/
void arch_syscall(void *sp);
void arch_enter(void *sp);
/*
* Copyright (c) 2020 Felix Kopp <sandtler@sandtler.club>

View file

@ -16,9 +16,12 @@ enum syscall {
NSYSCALLS
};
/** Perform an indirect system call. */
int syscall(enum syscall number, sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4);
/** The table of system call handlers, indexed by syscall number. */
extern const int (*syscall_table[NSYSCALLS])(sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
sysarg_t arg4, sysarg_t arg5, sysarg_t arg6);
extern const int (*sys_table[NSYSCALLS])(sysarg_t arg1, sysarg_t arg2,
sysarg_t arg3, sysarg_t arg4);
/* catchall handler that returns -ENOSYS */
int sys_stub(void);

View file

@ -5,14 +5,13 @@
#include <toolchain.h>
#define syscall_entry(number, func) \
[number] (int (*)(sysarg_t, sysarg_t, sysarg_t, sysarg_t, sysarg_t, sysarg_t))(func)
#define sys_table_entry(number, func) \
[number] (int (*)(sysarg_t, sysarg_t, sysarg_t, sysarg_t))(func)
__rodata
const int (*syscall_table[NSYSCALLS])(sysarg_t arg1, sysarg_t arg2, sysarg_t arg3,
sysarg_t arg4, sysarg_t arg5, sysarg_t arg6) = {
syscall_entry(SYSCALL_READ, &sys_stub),
syscall_entry(SYSCALL_WRITE, &sys_write),
const int (*sys_table[NSYSCALLS])(sysarg_t arg1, sysarg_t arg2, sysarg_t arg3, sysarg_t arg4) = {
sys_table_entry(SYSCALL_READ, &sys_stub),
sys_table_entry(SYSCALL_WRITE, &sys_write),
};
int sys_stub(void)

View file

@ -29,4 +29,5 @@ ARDIX_SOURCES += \
$(ARDIX_LIB_PWD)/ctype.c \
$(ARDIX_LIB_PWD)/list.c \
$(ARDIX_LIB_PWD)/malloc.c \
$(ARDIX_LIB_PWD)/string.c
$(ARDIX_LIB_PWD)/string.c \
$(ARDIX_LIB_PWD)/unistd.c

View file

@ -8,9 +8,16 @@
#include <toolchain.h>
#include <unistd.h>
__shared ssize_t pwrite(int fildes, const void *buf, size_t nbyte, off_t offset)
{
return syscall(SYSCALL_WRITE, (sysarg_t)fildes, (sysarg_t)buf, (sysarg_t)nbyte,
(sysarg_t)offset);
}
__shared ssize_t write(int fildes, const void *buf, size_t nbyte)
{
return pwrite(fildes, buf, nbyte, 0);
return syscall(SYSCALL_WRITE, (sysarg_t)fildes, (sysarg_t)buf, (sysarg_t)nbyte,
(sysarg_t)0);
}
/*