Add RISCV uaccess.h
authorBarret Rhoden <brho@cs.berkeley.edu>
Mon, 16 Nov 2015 21:02:25 +0000 (13:02 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 16 Nov 2015 21:02:25 +0000 (13:02 -0800)
This was written by Davide, but got lost in a rebase involving
6cc759554b02 ("Plugged the exception handling code") on his branch,
which was already c7c7f1ceb352 ("Plugged the exception handling code")
on master.

Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
kern/arch/riscv/uaccess.h [new file with mode: 0644]

diff --git a/kern/arch/riscv/uaccess.h b/kern/arch/riscv/uaccess.h
new file mode 100644 (file)
index 0000000..644ff24
--- /dev/null
@@ -0,0 +1,100 @@
+/* Copyright (c) 2015 Google Inc
+ * Davide Libenzi <dlibenzi@google.com>
+ * See LICENSE for details.
+ *
+ * Part of this code coming from a Linux kernel file:
+ *
+ * linux/arch/x86/include/asm/uaccess.h
+ *
+ * Which, even though missing specific copyright, it is supposed to be
+ * ruled by the overall Linux copyright.
+ */
+
+#pragma once
+
+#include <ros/errno.h>
+#include <compiler.h>
+#include <stdint.h>
+#include <umem.h>
+
+#define ASM_STAC
+#define ASM_CLAC
+#define __m(x) *(x)
+
+struct extable_ip_fixup {
+       uint64_t insn;
+       uint64_t fixup;
+};
+
+#define _ASM_EXTABLE_INIT()                                                                            \
+       asm volatile(                                                                                           \
+       " .pushsection \"__ex_table\",\"a\"\n"                                          \
+       " .balign 16\n"                                                                                         \
+       " .popsection\n"                                                                                        \
+       : :)
+
+#define _ASM_EXTABLE(from, to)                                                                 \
+       " .pushsection \"__ex_table\",\"a\"\n"                                          \
+       " .balign 16\n"                                                                                         \
+       " .quad (" #from ") - .\n"                                                                      \
+       " .quad (" #to ") - .\n"                                                                        \
+       " .popsection\n"
+
+static inline int __put_user(void *dst, const void *src, unsigned int count)
+{
+#warning "The __put_user() API is a stub and should be re-implemented"
+
+       memcpy(dst, src, count);
+
+       return 0;
+}
+
+static inline int copy_to_user(void *dst, const void *src, unsigned int count)
+{
+#warning "The copy_to_user() API is a stub and should be re-implemented"
+
+       int err = 0;
+
+       if (unlikely(!is_user_rwaddr(dst, count))) {
+               err = -EFAULT;
+       } else {
+               err = __put_user(dst, src, count);
+       }
+
+       return err;
+}
+
+static inline int __get_user(void *dst, const void *src, unsigned int count)
+{
+#warning "The __get_user() API is a stub and should be re-implemented"
+
+       memcpy(dst, src, count);
+
+       return 0;
+}
+
+static inline int copy_from_user(void *dst, const void *src,
+                                                                unsigned int count)
+{
+#warning "The copy_from_user() API is a stub and should be re-implemented"
+
+       int err = 0;
+
+       if (unlikely(!is_user_raddr((void *) src, count))) {
+               err = -EFAULT;
+       } else {
+               err = __get_user(dst, src, count);
+       }
+
+       return err;
+}
+
+static inline uintptr_t ex_insn_addr(const struct extable_ip_fixup *x)
+{
+       return (uintptr_t) &x->insn + x->insn;
+}
+
+static inline uintptr_t ex_fixup_addr(const struct extable_ip_fixup *x)
+{
+       return (uintptr_t) &x->fixup + x->fixup;
+}