Index: uspace/lib/c/arch/riscv64/Makefile.inc
===================================================================
--- uspace/lib/c/arch/riscv64/Makefile.inc	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/Makefile.inc	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,42 @@
+#
+# Copyright (c) 2016 Martin Decky
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+ARCH_SOURCES = \
+	arch/$(UARCH)/src/entry.c \
+	arch/$(UARCH)/src/entryjmp.c \
+	arch/$(UARCH)/src/thread_entry.c \
+	arch/$(UARCH)/src/fibril.c \
+	arch/$(UARCH)/src/tls.c \
+	arch/$(UARCH)/src/syscall.c \
+	arch/$(UARCH)/src/stacktrace.c
+
+ARCH_AUTOGENS_AG = \
+	arch/$(UARCH)/include/libarch/istate_struct.ag \
+	arch/$(UARCH)/include/libarch/fibril_context.ag
+
+.PRECIOUS: arch/$(UARCH)/src/entry.o
Index: uspace/lib/c/arch/riscv64/_link.ld.in
===================================================================
--- uspace/lib/c/arch/riscv64/_link.ld.in	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/_link.ld.in	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,80 @@
+STARTUP(LIBC_PATH/arch/UARCH/src/entry.o)
+ENTRY(__entry)
+
+PHDRS {
+#ifdef LOADER
+	interp PT_INTERP;
+	text PT_LOAD FILEHDR PHDRS FLAGS(5);
+#else
+	text PT_LOAD FLAGS(5);
+#endif
+	data PT_LOAD FLAGS(6);
+	debug PT_NOTE;
+}
+
+SECTIONS {
+#ifdef LOADER
+	. = 0x70001000 + SIZEOF_HEADERS;
+#else
+	. = 0x1000 + SIZEOF_HEADERS;
+#endif
+	
+	.text : {
+		*(.text .text.*);
+		*(.rodata .rodata.*);
+		*(.srodata .srodata.*);
+	} :text
+	
+#ifdef LOADER
+	.interp : {
+		*(.interp);
+	} :interp :text
+#endif
+	
+	. = . + 0x1000;
+	
+	.data : {
+		*(.data);
+		*(.sdata);
+		*(.data.rel*);
+	} :data
+	
+	.tdata : {
+		_tdata_start = .;
+		*(.tdata);
+		*(.gnu.linkonce.tb.*);
+		_tdata_end = .;
+		_tbss_start = .;
+		*(.tbss);
+		_tbss_end = .;
+	} :data
+	
+	_tls_alignment = ALIGNOF(.tdata);
+	
+	.sbss : {
+		*(.scommon);
+		*(.sbss);
+	}
+	
+	.bss : {
+		*(COMMON);
+		*(.bss);
+	} :data
+	
+#ifdef CONFIG_LINE_DEBUG
+	.comment 0 : { *(.comment); } :debug
+	.debug_abbrev 0 : { *(.debug_abbrev); } :debug
+	.debug_aranges 0 : { *(.debug_aranges); } :debug
+	.debug_info 0 : { *(.debug_info); } :debug
+	.debug_line 0 : { *(.debug_line); } :debug
+	.debug_loc 0 : { *(.debug_loc); } :debug
+	.debug_pubnames 0 : { *(.debug_pubnames); } :debug
+	.debug_pubtypes 0 : { *(.debug_pubtypes); } :debug
+	.debug_ranges 0 : { *(.debug_ranges); } :debug
+	.debug_str 0 : { *(.debug_str); } :debug
+#endif
+	
+	/DISCARD/ : {
+		*(*);
+	}
+}
Index: uspace/lib/c/arch/riscv64/include/libarch/atomic.h
===================================================================
--- uspace/lib/c/arch/riscv64/include/libarch/atomic.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/include/libarch/atomic.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,103 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libcriscv64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_riscv64_ATOMIC_H_
+#define LIBC_riscv64_ATOMIC_H_
+
+#include <stdbool.h>
+
+#define LIBC_ARCH_ATOMIC_H_
+#define CAS
+
+#include <atomicdflt.h>
+
+// FIXME
+
+static inline bool cas(atomic_t *val, atomic_count_t ov, atomic_count_t nv)
+{
+	if (val->count == ov) {
+		val->count = nv;
+		return true;
+	}
+	
+	return false;
+}
+
+static inline void atomic_inc(atomic_t *val)
+{
+	/* On real hardware the increment has to be done
+	   as an atomic action. */
+	
+	val->count++;
+}
+
+static inline void atomic_dec(atomic_t *val)
+{
+	/* On real hardware the decrement has to be done
+	   as an atomic action. */
+	
+	val->count++;
+}
+
+static inline atomic_count_t atomic_postinc(atomic_t *val)
+{
+	/* On real hardware both the storing of the previous
+	   value and the increment have to be done as a single
+	   atomic action. */
+	
+	atomic_count_t prev = val->count;
+	
+	val->count++;
+	return prev;
+}
+
+static inline atomic_count_t atomic_postdec(atomic_t *val)
+{
+	/* On real hardware both the storing of the previous
+	   value and the decrement have to be done as a single
+	   atomic action. */
+	
+	atomic_count_t prev = val->count;
+	
+	val->count--;
+	return prev;
+}
+
+#define atomic_preinc(val) (atomic_postinc(val) + 1)
+#define atomic_predec(val) (atomic_postdec(val) - 1)
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/riscv64/include/libarch/barrier.h
===================================================================
--- uspace/lib/c/arch/riscv64/include/libarch/barrier.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/include/libarch/barrier.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,1 @@
+../../../../../../../kernel/arch/riscv64/include/arch/barrier.h
Index: uspace/lib/c/arch/riscv64/include/libarch/ddi.h
===================================================================
--- uspace/lib/c/arch/riscv64/include/libarch/ddi.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/include/libarch/ddi.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,68 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @file
+ */
+
+#ifndef LIBC_riscv64_DDI_H_
+#define LIBC_riscv64_DDI_H_
+
+#include <sys/types.h>
+#include <libarch/types.h>
+
+static inline void arch_pio_write_8(ioport8_t *port, uint8_t v)
+{
+	*port = v;
+}
+
+static inline void arch_pio_write_16(ioport16_t *port, uint16_t v)
+{
+	*port = v;
+}
+
+static inline void arch_pio_write_32(ioport32_t *port, uint32_t v)
+{
+	*port = v;
+}
+
+static inline uint8_t arch_pio_read_8(const ioport8_t *port)
+{
+	return *port;
+}
+
+static inline uint16_t arch_pio_read_16(const ioport16_t *port)
+{
+	return *port;
+}
+
+static inline uint32_t arch_pio_read_32(const ioport32_t *port)
+{
+	return *port;
+}
+
+#endif
Index: uspace/lib/c/arch/riscv64/include/libarch/elf.h
===================================================================
--- uspace/lib/c/arch/riscv64/include/libarch/elf.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/include/libarch/elf.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,1 @@
+../../../../../../../kernel/arch/riscv64/include/arch/elf.h
Index: uspace/lib/c/arch/riscv64/include/libarch/elf_linux.h
===================================================================
--- uspace/lib/c/arch/riscv64/include/libarch/elf_linux.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/include/libarch/elf_linux.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,53 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libcriscv64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_riscv64_ELF_LINUX_H_
+#define LBIC_riscv64_ELF_LINUX_H_
+
+#include <libarch/istate.h>
+#include <sys/types.h>
+
+typedef struct {
+} elf_regs_t;
+
+static inline void istate_to_elf_regs(istate_t *istate, elf_regs_t *elf_regs)
+{
+	(void) istate;
+	(void) elf_regs;
+}
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/riscv64/include/libarch/entry.h
===================================================================
--- uspace/lib/c/arch/riscv64/include/libarch/entry.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/include/libarch/entry.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/**
+ * @file
+ */
+
+#ifndef LIBC_riscv64_ENTRY_H_
+#define LIBC_riscv64_ENTRY_H_
+
+extern void __entry(void);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/riscv64/include/libarch/faddr.h
===================================================================
--- uspace/lib/c/arch/riscv64/include/libarch/faddr.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/include/libarch/faddr.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libriscv64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_riscv64_FADDR_H_
+#define LIBC_riscv64_FADDR_H_
+
+#include <libarch/types.h>
+
+#define FADDR(fptr)  ((uintptr_t) (fptr))
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/riscv64/include/libarch/fibril.h
===================================================================
--- uspace/lib/c/arch/riscv64/include/libarch/fibril.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/include/libarch/fibril.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,70 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libcriscv64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_riscv64_FIBRIL_H_
+#define LIBC_riscv64_FIBRIL_H_
+
+#include <sys/types.h>
+
+#define SP_DELTA  0
+
+#define context_set(ctx, _pc, stack, size, ptls) \
+	do { \
+		(ctx)->pc = (uintptr_t) (_pc); \
+		(ctx)->sp = ((uintptr_t) (stack)) + (size) - SP_DELTA; \
+		(ctx)->fp = 0; \
+		(ctx)->tls = ((uintptr_t) (ptls)) + sizeof(tcb_t); \
+	} while (0)
+
+/*
+ * This stores the registers which need to be
+ * preserved across function calls.
+ */
+typedef struct {
+	uintptr_t sp;
+	uintptr_t fp;
+	uintptr_t pc;
+	uintptr_t tls;
+} context_t;
+
+static inline uintptr_t context_get_fp(context_t *ctx)
+{
+	/* This function returns the frame pointer. */
+	return ctx->fp;
+}
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/riscv64/include/libarch/fibril_context.ag
===================================================================
--- uspace/lib/c/arch/riscv64/include/libarch/fibril_context.ag	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/include/libarch/fibril_context.ag	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,179 @@
+#
+# Copyright (c) 2016 Martin Decky
+# All rights reserved.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions
+# are met:
+#
+# - Redistributions of source code must retain the above copyright
+#   notice, this list of conditions and the following disclaimer.
+# - Redistributions in binary form must reproduce the above copyright
+#   notice, this list of conditions and the following disclaimer in the
+#   documentation and/or other materials provided with the distribution.
+# - The name of the author may not be used to endorse or promote products
+#   derived from this software without specific prior written permission.
+#
+# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+#
+
+{
+        name : context,
+
+        includes : [
+                {
+                        include : <sys/types.h>
+                }
+        ],
+
+        members : [
+                #
+                # There is a room for optimization (we can store just those
+                # registers that must be preserved during ABI function call).
+                #
+
+                {
+                        name : sp,
+                        type : uint64_t
+                },
+                {
+                        name : pc,
+                        type : uint64_t
+                },
+
+                {
+                        name : zero,
+                        type : uint64_t
+                },
+                {
+                        name : ra,
+                        type : uint64_t
+                },
+
+                {
+                        name : x3,
+                        type : uint64_t
+                },
+                {
+                        name : x4,
+                        type : uint64_t
+                },
+                {
+                        name : x5,
+                        type : uint64_t
+                },
+                {
+                        name : x6,
+                        type : uint64_t
+                },
+                {
+                        name : x7,
+                        type : uint64_t
+                },
+                {
+                        name : x8,
+                        type : uint64_t
+                },
+                {
+                        name : x9,
+                        type : uint64_t
+                },
+                {
+                        name : x10,
+                        type : uint64_t
+                },
+                {
+                        name : x11,
+                        type : uint64_t
+                },
+                {
+                        name : x12,
+                        type : uint64_t
+                },
+                {
+                        name : x13,
+                        type : uint64_t
+                },
+                {
+                        name : x14,
+                        type : uint64_t
+                },
+                {
+                        name : x15,
+                        type : uint64_t
+                },
+                {
+                        name : x16,
+                        type : uint64_t
+                },
+                {
+                        name : x17,
+                        type : uint64_t
+                },
+                {
+                        name : x18,
+                        type : uint64_t
+                },
+                {
+                        name : x19,
+                        type : uint64_t
+                },
+                {
+                        name : x20,
+                        type : uint64_t
+                },
+                {
+                        name : x21,
+                        type : uint64_t
+                },
+                {
+                        name : x22,
+                        type : uint64_t
+                },
+                {
+                        name : x23,
+                        type : uint64_t
+                },
+                {
+                        name : x24,
+                        type : uint64_t
+                },
+                {
+                        name : x25,
+                        type : uint64_t
+                },
+                {
+                        name : x26,
+                        type : uint64_t
+                },
+                {
+                        name : x27,
+                        type : uint64_t
+                },
+                {
+                        name : x28,
+                        type : uint64_t
+                },
+                {
+                        name : x29,
+                        type : uint64_t
+                },
+                {
+                        name : x30,
+                        type : uint64_t
+                },
+                {
+                        name : x31,
+                        type : uint64_t
+                }
+        ]
+}
Index: uspace/lib/c/arch/riscv64/include/libarch/inttypes.h
===================================================================
--- uspace/lib/c/arch/riscv64/include/libarch/inttypes.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/include/libarch/inttypes.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,44 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libcriscv64
+ * @{
+ */
+
+#ifndef LIBC_riscv64_INTTYPES_H_
+#define LIBC_riscv64_INTTYPES_H_
+
+#define PRIdn  PRId64  /**< Format for native_t. */
+#define PRIun  PRIu64  /**< Format for sysarg_t. */
+#define PRIxn  PRIx64  /**< Format for hexadecimal sysarg_t. */
+#define PRIua  PRIu64  /**< Format for atomic_count_t. */
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/riscv64/include/libarch/istate.h
===================================================================
--- uspace/lib/c/arch/riscv64/include/libarch/istate.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/include/libarch/istate.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,1 @@
+../../../../../../../kernel/arch/riscv64/include/arch/istate.h
Index: uspace/lib/c/arch/riscv64/include/libarch/istate_struct.ag
===================================================================
--- uspace/lib/c/arch/riscv64/include/libarch/istate_struct.ag	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/include/libarch/istate_struct.ag	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,1 @@
+../../../../../../../kernel/arch/riscv64/include/arch/istate_struct.ag
Index: uspace/lib/c/arch/riscv64/include/libarch/stddef.h
===================================================================
--- uspace/lib/c/arch/riscv64/include/libarch/stddef.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/include/libarch/stddef.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libcabs32
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_abs32_STDDEF_H_
+#define LIBC_abs32_STDDEF_H_
+
+#include <libarch/common.h>
+
+typedef uint64_t size_t;
+typedef int64_t ptrdiff_t;
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/riscv64/include/libarch/stdint.h
===================================================================
--- uspace/lib/c/arch/riscv64/include/libarch/stdint.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/include/libarch/stdint.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libcabs32
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_abs32_STDINT_H_
+#define LIBC_abs32_STDINT_H_
+
+#include <libarch/common.h>
+
+#define SIZE_MAX UINT64_MAX
+
+#define UINTPTR_MAX UINT64_MAX
+typedef uint64_t uintptr_t;
+
+#define INTPTR_MIN INT64_MIN
+#define INTPTR_MAX INT64_MAX
+typedef int64_t intptr_t;
+
+#define UINTMAX_MAX UINT64_MAX
+typedef uint64_t uintmax_t;
+
+#define INTMAX_MAX INT64_MAX
+typedef int64_t intmax_t;
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/riscv64/include/libarch/syscall.h
===================================================================
--- uspace/lib/c/arch/riscv64/include/libarch/syscall.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/include/libarch/syscall.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libc
+ * @{
+ */
+/**
+ * @file
+ */
+
+#ifndef LIBC_riscv64_SYSCALL_H_
+#define LIBC_riscv64_SYSCALL_H_
+
+#include <sys/types.h>
+#include <abi/syscall.h>
+
+#define __syscall0  __syscall
+#define __syscall1  __syscall
+#define __syscall2  __syscall
+#define __syscall3  __syscall
+#define __syscall4  __syscall
+#define __syscall5  __syscall
+#define __syscall6  __syscall
+
+extern sysarg_t __syscall(const sysarg_t, const sysarg_t, const sysarg_t,
+    const sysarg_t, const sysarg_t, const sysarg_t, const syscall_t);
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/riscv64/include/libarch/thread.h
===================================================================
--- uspace/lib/c/arch/riscv64/include/libarch/thread.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/include/libarch/thread.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libcriscv64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_riscv64_THREAD_H_
+#define LIBC_riscv64_THREAD_H_
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/riscv64/include/libarch/tls.h
===================================================================
--- uspace/lib/c/arch/riscv64/include/libarch/tls.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/include/libarch/tls.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,60 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libcriscv64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_riscv64_TLS_H_
+#define LIBC_riscv64_TLS_H_
+
+#define CONFIG_TLS_VARIANT_2
+
+#include <libc.h>
+#include <unistd.h>
+
+typedef struct {
+	void *self;
+	void *fibril_data;
+} tcb_t;
+
+static inline void __tcb_set(tcb_t *tcb)
+{
+}
+
+static inline tcb_t *__tcb_get(void)
+{
+	return NULL;
+}
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/riscv64/include/libarch/types.h
===================================================================
--- uspace/lib/c/arch/riscv64/include/libarch/types.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/include/libarch/types.h	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,58 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup libcriscv64
+ * @{
+ */
+/** @file
+ */
+
+#ifndef LIBC_riscv64_TYPES_H_
+#define LIBC_riscv64_TYPES_H_
+
+#include <libarch/common.h>
+#include <libarch/stddef.h>
+#include <libarch/stdint.h>
+
+#define __64_BITS__
+
+#define SSIZE_MIN  INT64_MIN
+#define SSIZE_MAX  INT64_MAX
+
+typedef uint64_t sysarg_t;
+typedef int64_t native_t;
+
+typedef int64_t ssize_t;
+
+typedef uint64_t atomic_count_t;
+typedef int64_t atomic_signed_t;
+
+#endif
+
+/** @}
+ */
Index: uspace/lib/c/arch/riscv64/src/entry.c
===================================================================
--- uspace/lib/c/arch/riscv64/src/entry.c	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/src/entry.c	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,42 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @file
+ */
+
+#include <unistd.h>
+#include <libarch/entry.h>
+#include "../../../generic/private/libc.h"
+
+void __entry(void)
+{
+	__main(NULL);
+}
+
+/** @}
+ */
Index: uspace/lib/c/arch/riscv64/src/entryjmp.c
===================================================================
--- uspace/lib/c/arch/riscv64/src/entryjmp.c	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/src/entryjmp.c	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @file
+ */
+
+#include <stdbool.h>
+#include <entry_point.h>
+
+/** Jump to program entry point. */
+void entry_point_jmp(void *entry_point, void *pcb)
+{
+	while (true);
+}
+
+/**
+ * @}
+ */
Index: uspace/lib/c/arch/riscv64/src/fibril.c
===================================================================
--- uspace/lib/c/arch/riscv64/src/fibril.c	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/src/fibril.c	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @file
+ */
+
+#include <fibril.h>
+#include <stdbool.h>
+
+int context_save(context_t *ctx)
+{
+	return 1;
+}
+
+void context_restore(context_t *ctx)
+{
+	while (true);
+}
+
+/** @}
+ */
Index: uspace/lib/c/arch/riscv64/src/stacktrace.c
===================================================================
--- uspace/lib/c/arch/riscv64/src/stacktrace.c	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/src/stacktrace.c	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,67 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @file
+ */
+
+#include <sys/types.h>
+#include <unistd.h>
+#include <stdbool.h>
+#include <stacktrace.h>
+
+bool stacktrace_fp_valid(stacktrace_t *st, uintptr_t fp)
+{
+	return true;
+}
+
+int stacktrace_fp_prev(stacktrace_t *st, uintptr_t fp, uintptr_t *prev)
+{
+	return 0;
+}
+
+int stacktrace_ra_get(stacktrace_t *st, uintptr_t fp, uintptr_t *ra)
+{
+	return 0;
+}
+
+void stacktrace_prepare(void)
+{
+}
+
+uintptr_t stacktrace_fp_get(void)
+{
+	return (uintptr_t) NULL;
+}
+
+uintptr_t stacktrace_pc_get(void)
+{
+	return (uintptr_t) NULL;
+}
+
+/** @}
+ */
Index: uspace/lib/c/arch/riscv64/src/syscall.c
===================================================================
--- uspace/lib/c/arch/riscv64/src/syscall.c	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/src/syscall.c	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @file
+ */
+
+#include <sys/types.h>
+#include <libarch/syscall.h>
+
+sysarg_t __syscall(const sysarg_t p1, const sysarg_t p2,
+    const sysarg_t p3, const sysarg_t p4, const sysarg_t p5, const sysarg_t p6,
+    const syscall_t id)
+{
+	return 0;
+}
+
+/** @}
+ */
Index: uspace/lib/c/arch/riscv64/src/thread_entry.c
===================================================================
--- uspace/lib/c/arch/riscv64/src/thread_entry.c	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/src/thread_entry.c	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,41 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @file
+ */
+
+#include <unistd.h>
+#include "../../../generic/private/thread.h"
+
+void __thread_entry(void)
+{
+	__thread_main(NULL);
+}
+
+/** @}
+ */
Index: uspace/lib/c/arch/riscv64/src/tls.c
===================================================================
--- uspace/lib/c/arch/riscv64/src/tls.c	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
+++ uspace/lib/c/arch/riscv64/src/tls.c	(revision 2c2d54a73f8d98a509aa5049bb9ef840b9bb186c)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2016 Martin Decky
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @file
+ */
+
+#include <tls.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+tcb_t *tls_alloc_arch(void **data, size_t size)
+{
+	return tls_alloc_variant_2(data, size);
+}
+
+void tls_free_arch(tcb_t *tcb, size_t size)
+{
+	tls_free_variant_2(tcb, size);
+}
+
+/** @}
+ */
