diff --git a/base-codezero/lib/import/import-syscall.mk b/base-codezero/lib/import/import-syscall.mk
new file mode 100644
index 0000000000..d8510e5b17
--- /dev/null
+++ b/base-codezero/lib/import/import-syscall.mk
@@ -0,0 +1 @@
+REP_INC_DIR += include/codezero/dummies
diff --git a/base-codezero/lib/mk/env.mk b/base-codezero/lib/mk/env.mk
new file mode 100644
index 0000000000..f7b38556c0
--- /dev/null
+++ b/base-codezero/lib/mk/env.mk
@@ -0,0 +1,6 @@
+include $(BASE_DIR)/lib/mk/env.mk
+
+SRC_CC += utcb.cc
+
+vpath utcb.cc $(REP_DIR)/src/base/env
+vpath env.cc $(BASE_DIR)/src/base/env
diff --git a/base-codezero/src/base/env/utcb.cc b/base-codezero/src/base/env/utcb.cc
new file mode 100644
index 0000000000..f2fa92a801
--- /dev/null
+++ b/base-codezero/src/base/env/utcb.cc
@@ -0,0 +1,40 @@
+/*
+ * \brief Helper functions UTCB access on Codezero
+ * \author Norman Feske
+ * \date 2012-03-01
+ */
+
+/*
+ * Copyright (C) 2012 Genode Labs GmbH
+ *
+ * This file is part of the Genode OS framework, which is distributed
+ * under the terms of the GNU General Public License version 2.
+ */
+
+/* Genode includes */
+#include
+
+
+/**
+ * Resolve 'Thread_base::myself' when not linking the thread library
+ *
+ * This weak symbol is primarily used by test cases. Most other Genode programs
+ * use the thread library. If the thread library is not used, 'myself' can only
+ * be called by the main thread, for which 'myself' is defined as zero.
+ */
+Genode::Thread_base * __attribute__((weak)) Genode::Thread_base::myself() { return 0; }
+
+
+Genode::Native_utcb *Genode::Thread_base::utcb()
+{
+ /*
+ * If 'utcb' is called on the object returned by 'myself',
+ * the 'this' pointer may be NULL (if the calling thread is
+ * the main thread). Therefore we handle this special case
+ * here.
+ */
+ if (this == 0) return 0;
+
+ return &_context->utcb;
+}
+
diff --git a/base-codezero/src/base/lock/lock_helper.h b/base-codezero/src/base/lock/lock_helper.h
index 5b575559e1..b9b2f50ad4 100644
--- a/base-codezero/src/base/lock/lock_helper.h
+++ b/base-codezero/src/base/lock/lock_helper.h
@@ -22,30 +22,6 @@
#include
-/**
- * Resolve 'Thread_base::myself' when not linking the thread library
- *
- * This weak symbol is primarily used by test cases. Most other Genode programs
- * use the thread library. If the thread library is not used, 'myself' can only
- * be called by the main thread, for which 'myself' is defined as zero.
- */
-Genode::Thread_base * __attribute__((weak)) Genode::Thread_base::myself() { return 0; }
-
-
-Genode::Native_utcb *Genode::Thread_base::utcb()
-{
- /*
- * If 'utcb' is called on the object returned by 'myself',
- * the 'this' pointer may be NULL (if the calling thread is
- * the main thread). Therefore we handle this special case
- * here.
- */
- if (this == 0) return 0;
-
- return &_context->utcb;
-}
-
-
static Codezero::l4_mutex main_running_lock = { -1 };
@@ -61,7 +37,7 @@ static inline bool thread_id_valid(Genode::Native_thread_id tid)
}
-static bool thread_check_stopped_and_restart(Genode::Native_thread_id tid)
+static inline bool thread_check_stopped_and_restart(Genode::Native_thread_id tid)
{
if (!thread_id_valid(tid))
return false;
diff --git a/base-codezero/src/core/target.inc b/base-codezero/src/core/target.inc
index 3557657a29..33faac26a7 100644
--- a/base-codezero/src/core/target.inc
+++ b/base-codezero/src/core/target.inc
@@ -29,7 +29,8 @@ SRC_CC = \
core_rm_session.cc \
core_mem_alloc.cc \
dump_alloc.cc \
- context_area.cc
+ context_area.cc \
+ utcb.cc
INC_DIR = $(REP_DIR)/src/core/include \
$(GEN_CORE_DIR)/include \
@@ -52,4 +53,5 @@ vpath context_area.cc $(GEN_CORE_DIR)
vpath %.cc $(REP_DIR)/src/core
vpath thread_bootstrap.cc $(BASE_DIR)/src/base/thread
vpath thread.cc $(BASE_DIR)/src/base/thread
+vpath utcb.cc $(REP_DIR)/src/base/env
diff --git a/base-fiasco/src/base/lock/lock_helper.h b/base-fiasco/src/base/lock/lock_helper.h
new file mode 100644
index 0000000000..e78731a918
--- /dev/null
+++ b/base-fiasco/src/base/lock/lock_helper.h
@@ -0,0 +1,34 @@
+
+/*
+ * \brief L4/Fiasco-specific helper functions for the Lock implementation
+ * \author Norman Feske
+ * \date 2012-03-01
+ *
+ * L4/Fiasco is the only kernel that does not rely on Genode's generic lock
+ * implementation. The custom implementation contained in 'lock.cc' does not
+ * need 'lock_helper.h'. This file exists for the sole reason to make the
+ * L4/Fiasco version of 'lock_helper' usable from the DDE Kit's spin lock.
+ * Otherwise, we would need to add a special case for L4/Fiasco to the DDE Kit
+ * library.
+ */
+
+/*
+ * Copyright (C) 2009-2012 Genode Labs GmbH
+ *
+ * This file is part of the Genode OS framework, which is distributed
+ * under the terms of the GNU General Public License version 2.
+ */
+
+/* L4/Fiasco includes */
+namespace Fiasco {
+#include
+}
+
+
+/**
+ * Yield CPU time
+ */
+static inline void thread_yield()
+{
+ Fiasco::l4_ipc_sleep(Fiasco::l4_ipc_timeout(0, 0, 500, 0));
+}
diff --git a/base-pistachio/src/base/lock/lock_helper.h b/base-pistachio/src/base/lock/lock_helper.h
index 48f9c922bb..02ae40967c 100644
--- a/base-pistachio/src/base/lock/lock_helper.h
+++ b/base-pistachio/src/base/lock/lock_helper.h
@@ -24,8 +24,8 @@ namespace Pistachio {
}
-bool operator == (Genode::Native_thread_id t1, Genode::Native_thread_id t2) { return t1.raw == t2.raw; }
-bool operator != (Genode::Native_thread_id t1, Genode::Native_thread_id t2) { return t1.raw != t2.raw; }
+static inline bool operator == (Genode::Native_thread_id t1, Genode::Native_thread_id t2) { return t1.raw == t2.raw; }
+static inline bool operator != (Genode::Native_thread_id t1, Genode::Native_thread_id t2) { return t1.raw != t2.raw; }
/**
@@ -43,7 +43,7 @@ static inline void thread_yield() { Pistachio::L4_Yield(); }
*
* \return true if the thread was in blocking state
*/
-static bool thread_check_stopped_and_restart(Genode::Native_thread_id tid)
+static inline bool thread_check_stopped_and_restart(Genode::Native_thread_id tid)
{
using namespace Pistachio;
diff --git a/base/lib/mk/syscall.mk b/base/lib/mk/syscall.mk
new file mode 100644
index 0000000000..055ce220b5
--- /dev/null
+++ b/base/lib/mk/syscall.mk
@@ -0,0 +1,6 @@
+#
+# This file is placeholder to enable generic targets to specify the syscall
+# library at the 'LIBS' declaration, even on platforms where no such library
+# exists. This is done by DDE Kit for reusing the spinlock implementation of
+# the base repository.
+#
diff --git a/os/include/dde_kit/spin_lock.h b/os/include/dde_kit/spin_lock.h
index 945c790d39..543f83a300 100644
--- a/os/include/dde_kit/spin_lock.h
+++ b/os/include/dde_kit/spin_lock.h
@@ -19,6 +19,9 @@
*/
typedef volatile int dde_kit_spin_lock;
+enum { DDE_KIT_SPIN_LOCK_LOCKED, DDE_KIT_SPIN_LOCK_UNLOCKED };
+
+
/**
* Initialize spin lock
*
diff --git a/os/lib/mk/dde_kit.mk b/os/lib/mk/dde_kit.mk
index 94d8025c38..284ddf99ff 100644
--- a/os/lib/mk/dde_kit.mk
+++ b/os/lib/mk/dde_kit.mk
@@ -1,7 +1,17 @@
-SRC_C = lock.cc semaphore.cc panic.cc printf.cc interrupt.cc pgtab.cc \
- memory.cc thread.cc pci_tree.cc pci.cc resources.cc timer.cc \
- dde_kit.cc spin_lock.cc
-LIBS = thread alarm lock
-REP_INC_DIR += src/base/lock
+SRC_C = lock.cc semaphore.cc panic.cc printf.cc interrupt.cc pgtab.cc \
+ memory.cc thread.cc pci_tree.cc pci.cc resources.cc timer.cc \
+ dde_kit.cc spin_lock.cc
+LIBS = thread alarm lock
+
+#
+# Enable 'spin_lock.cc' to reuse the spinlock implementation of the base
+# repository by including the corresponding non-public headers local to
+# 'base-/src'. Because the platform-specific parts of these headers
+# may contain code that invokes system calls, we need to specify the 'syscall'
+# lib as well. This way, the needed include-search directories are supplied to
+# the build system via the respective 'import-syscall.mk' file.
+#
+LIBS += syscall
+REP_INC_DIR += src/base/lock src/platform
vpath % $(REP_DIR)/src/lib/dde_kit
diff --git a/os/src/lib/dde_kit/spin_lock.cc b/os/src/lib/dde_kit/spin_lock.cc
index 9488e61063..52ae164847 100644
--- a/os/src/lib/dde_kit/spin_lock.cc
+++ b/os/src/lib/dde_kit/spin_lock.cc
@@ -15,15 +15,28 @@
#include
#include
-#include
+#include /* included from 'base/src/base/lock/' */
extern "C" {
#include
}
+template struct Static_assert { };
+
+/* specialization for successful static assertion */
+template <> struct Static_assert { static void assert() { } };
+
+
extern "C" void dde_kit_spin_lock_init(dde_kit_spin_lock *spin_lock)
{
+ /*
+ * Check at compile time that the enum values defined for DDE Kit
+ * correspond to those defined in 'base/src/base/lock/spin_lock.h'.
+ */
+ Static_assert<(int)DDE_KIT_SPIN_LOCK_LOCKED == (int)SPINLOCK_LOCKED >::assert();
+ Static_assert<(int)DDE_KIT_SPIN_LOCK_UNLOCKED == (int)SPINLOCK_UNLOCKED>::assert();
+
*spin_lock = SPINLOCK_UNLOCKED;
}