Fix userspace tag and tagof functions for riscv
Use the x86 style tag functions for userspace runtime.
@@ -96,20 +96,15 @@ __bswap64(u64 _x)
#define le64toh(x) (x)
#endif
-#ifndef KERNEL
-#define VA_TAG_BASE 0
-#define VA_TAG_OFFSET USER_VA_TAG_OFFSET
-#define VA_TAG_WIDTH USER_VA_TAG_WIDTH
-#else
+typedef void *value;
+typedef u8 value_tag;
+
+#ifdef KERNEL
#define KMEM_BASE 0xffff800000000000ull
#define USER_LIMIT 0x0000800000000000ull /* 4-level page tables -> 48-bit addresses */
#define VA_TAG_BASE KMEM_BASE
#define VA_TAG_OFFSET 38
#define VA_TAG_WIDTH 8
-#endif
-
-typedef void *value;
-typedef u8 value_tag;
static inline __attribute__((always_inline)) value tag(void *v, value_tag t) {
return pointer_from_u64(VA_TAG_BASE | (((u64)t) << VA_TAG_OFFSET) |
@@ -120,6 +115,21 @@ static inline __attribute__((always_inline)) value_tag tagof(value v) {
return (u64_from_pointer(v) >> VA_TAG_OFFSET) & ((1ull << VA_TAG_WIDTH) - 1);
}
+#else
+
+static inline void *tag(void *v, u8 tval)
+{
+ *((u8 *)v-1) = tval;
+ return v;
+}
+
+static inline u8 tagof(void *v)
+{
+ return *((u8 *)v-1);
+}
+
+#endif
+
typedef struct spinlock {
word w;
} *spinlock;
