aboutsummaryrefslogtreecommitdiff
path: root/pk
diff options
context:
space:
mode:
authorAndrew Waterman <waterman@cs.berkeley.edu>2014-10-26 19:36:28 -0700
committerAndrew Waterman <waterman@cs.berkeley.edu>2014-10-26 19:36:28 -0700
commitfda0d85ae4596262d1da642593676e0f3cf3f0f1 (patch)
tree0725f2bd71cd1bbb7912de74f519a025a4703245 /pk
parent90e64853188620e02a02727ff050e5014cbc2528 (diff)
downloadpk-fda0d85ae4596262d1da642593676e0f3cf3f0f1.zip
pk-fda0d85ae4596262d1da642593676e0f3cf3f0f1.tar.gz
pk-fda0d85ae4596262d1da642593676e0f3cf3f0f1.tar.bz2
Don't rely on the C library
Diffstat (limited to 'pk')
-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
6 files changed, 68 insertions, 6 deletions
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