aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile.in2
-rwxr-xr-xconfigure2
-rw-r--r--configure.ac1
-rw-r--r--pk/file.h1
-rw-r--r--pk/handlers.c4
-rw-r--r--pk/pk.mk.in1
-rw-r--r--pk/string.c53
-rw-r--r--pk/syscall.c12
-rw-r--r--pk/syscall.h3
9 files changed, 69 insertions, 10 deletions
diff --git a/Makefile.in b/Makefile.in
index 2e4ab53..0ab3e6c 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -91,7 +91,7 @@ COMPILE := $(CC) -MMD -MP $(CFLAGS) \
# - LIBS : Library flags (eg. -l)
LD := $(CC)
-LDFLAGS := @LDFLAGS@ -nostartfiles -nostdlib $(LDFLAGS)
+LDFLAGS := @LDFLAGS@ -nostartfiles -nostdlib -static $(LDFLAGS)
LIBS := @LIBS@
LINK := $(LD) $(LDFLAGS) -T $(src_dir)/pk/pk.ld
diff --git a/configure b/configure
index be38182..020bef6 100755
--- a/configure
+++ b/configure
@@ -3953,8 +3953,6 @@ fi
CFLAGS="-Wall -Os -std=gnu99 -Wno-unused -Wno-attributes -fno-delete-null-pointer-checks"
-LIBS="-lc -lgcc"
-
{ $as_echo "$as_me:${as_lineno-$LINENO}: adding default configure arg: --host=riscv" >&5
diff --git a/configure.ac b/configure.ac
index 93886cd..31e37e9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -72,7 +72,6 @@ AC_HEADER_STDC
#-------------------------------------------------------------------------
AC_SUBST([CFLAGS], ["-Wall -Os -std=gnu99 -Wno-unused -Wno-attributes -fno-delete-null-pointer-checks"])
-AC_SUBST([LIBS], ["-lc -lgcc"])
AX_DEFAULT_CONFIGURE_ARG([--host=riscv])
diff --git a/pk/file.h b/pk/file.h
index cc7838d..68b68a3 100644
--- a/pk/file.h
+++ b/pk/file.h
@@ -4,6 +4,7 @@
#define _FILE_H
#include <sys/stat.h>
+#include <unistd.h>
#include "atomic.h"
typedef struct file
diff --git a/pk/handlers.c b/pk/handlers.c
index 00bb6de..2d5356a 100644
--- a/pk/handlers.c
+++ b/pk/handlers.c
@@ -112,8 +112,8 @@ void handle_fault_store(trapframe_t* tf)
static void handle_syscall(trapframe_t* tf)
{
- tf->gpr[16] = syscall(tf->gpr[18], tf->gpr[19], tf->gpr[20], tf->gpr[21],
- tf->gpr[22], tf->gpr[23], tf->gpr[16]);
+ tf->gpr[16] = do_syscall(tf->gpr[18], tf->gpr[19], tf->gpr[20], tf->gpr[21],
+ tf->gpr[22], tf->gpr[23], tf->gpr[16]);
tf->epc += 4;
}
diff --git a/pk/pk.mk.in b/pk/pk.mk.in
index 8b6733d..9c105ce 100644
--- a/pk/pk.mk.in
+++ b/pk/pk.mk.in
@@ -24,6 +24,7 @@ pk_c_srcs = \
elf.c \
console.c \
vm.c \
+ string.c \
pk_asm_srcs = \
entry.S \
diff --git a/pk/string.c b/pk/string.c
new file mode 100644
index 0000000..40b62e9
--- /dev/null
+++ b/pk/string.c
@@ -0,0 +1,53 @@
+#include <string.h>
+#include <stdint.h>
+
+void* memcpy(void* dest, const void* src, size_t len)
+{
+ if ((((uintptr_t)dest | (uintptr_t)src | len) & (sizeof(uintptr_t)-1)) == 0) {
+ const uintptr_t* s = src;
+ uintptr_t *d = dest;
+ while (d < (uintptr_t*)(dest + len))
+ *d++ = *s++;
+ } else {
+ const char* s = src;
+ char *d = dest;
+ while (d < (char*)(dest + len))
+ *d++ = *s++;
+ }
+ return dest;
+}
+
+void* memset(void* dest, int byte, size_t len)
+{
+ if ((((uintptr_t)dest | len) & (sizeof(uintptr_t)-1)) == 0) {
+ uintptr_t word = byte & 0xFF;
+ word |= word << 8;
+ word |= word << 16;
+ word |= word << 16 << 16;
+
+ uintptr_t *d = dest;
+ while (d < (uintptr_t*)(dest + len))
+ *d++ = word;
+ } else {
+ char *d = dest;
+ while (d < (char*)(dest + len))
+ *d++ = byte;
+ }
+ return dest;
+}
+
+size_t strlen(const char *s)
+{
+ const char *p = s;
+ while (*p)
+ p++;
+ return p - s;
+}
+
+char* strcpy(char* dest, const char* src)
+{
+ char* d = dest;
+ while ((*d++ = *src++))
+ ;
+ return dest;
+}
diff --git a/pk/syscall.c b/pk/syscall.c
index f9e0664..177d50f 100644
--- a/pk/syscall.c
+++ b/pk/syscall.c
@@ -384,12 +384,17 @@ int sys_getdents(int fd, void* dirbuf, int count)
return 0; //stub
}
-int sys_nosys()
+static int sys_stub_success()
+{
+ return 0;
+}
+
+static int sys_stub_nosys()
{
return -ENOSYS;
}
-long syscall(long a0, long a1, long a2, long a3, long a4, long a5, long n)
+long do_syscall(long a0, long a1, long a2, long a3, long a4, long a5, long n)
{
const static void* syscall_table[] = {
[SYS_exit] = sys_exit,
@@ -430,7 +435,8 @@ long syscall(long a0, long a1, long a2, long a3, long a4, long a5, long n)
[SYS_fcntl] = sys_fcntl,
[SYS_getdents] = sys_getdents,
[SYS_dup] = sys_dup,
- [SYS_readlinkat] = sys_nosys,
+ [SYS_readlinkat] = sys_stub_nosys,
+ [SYS_rt_sigprocmask] = sys_stub_success,
};
if(n >= ARRAY_SIZE(syscall_table) || !syscall_table[n])
diff --git a/pk/syscall.h b/pk/syscall.h
index 79c4eb1..a9fc3c8 100644
--- a/pk/syscall.h
+++ b/pk/syscall.h
@@ -46,12 +46,13 @@
#define SYS_getdents 61
#define SYS_dup 23
#define SYS_readlinkat 78
+#define SYS_rt_sigprocmask 135
#define IS_ERR_VALUE(x) ((unsigned long)(x) >= (unsigned long)-4096)
#define ERR_PTR(x) ((void*)(long)(x))
#define PTR_ERR(x) ((long)(x))
void sys_exit(int code) __attribute__((noreturn));
-long syscall(long a0, long a1, long a2, long a3, long a4, long a5, long n);
+long do_syscall(long a0, long a1, long a2, long a3, long a4, long a5, long n);
#endif