From 078883fda32b56f3798cff2808ab659b66055318 Mon Sep 17 00:00:00 2001 From: Christian Prochaska Date: Tue, 20 May 2014 22:52:56 +0200 Subject: [PATCH] base: interface for D- and I-cache synchronization On ARM, when machine instructions get written into the data cache (for example by a JIT compiler), one needs to make sure that the instructions get written out to memory and read from memory into the instruction cache before they get executed. This functionality is usually provided by a kernel syscall and this patch adds a generic interface for Genode applications to use it. Fixes #1153. --- repos/base-codezero/lib/mk/base.mk | 1 + repos/base-fiasco/lib/mk/base.mk | 1 + repos/base-foc/lib/mk/base.mk | 1 + repos/base-foc/src/base/cpu/cache.cc | 23 ++++++++++++++++++ repos/base-hw/lib/mk/base.mk | 1 + repos/base-hw/src/base/cpu/cache.cc | 21 ++++++++++++++++ repos/base-linux/lib/mk/arm/base.mk | 9 +++++++ repos/base-linux/lib/mk/x86/base.mk | 9 +++++++ repos/base-linux/src/base/cpu/arm/cache.cc | 21 ++++++++++++++++ repos/base-nova/lib/mk/base.mk | 1 + repos/base-okl4/lib/mk/base.mk | 1 + repos/base-pistachio/lib/mk/base.mk | 1 + repos/base/include/cpu/cache.h | 28 ++++++++++++++++++++++ repos/base/src/base/cpu/cache.cc | 21 ++++++++++++++++ 14 files changed, 139 insertions(+) create mode 100644 repos/base-foc/src/base/cpu/cache.cc create mode 100644 repos/base-hw/src/base/cpu/cache.cc create mode 100644 repos/base-linux/lib/mk/arm/base.mk create mode 100644 repos/base-linux/lib/mk/x86/base.mk create mode 100644 repos/base-linux/src/base/cpu/arm/cache.cc create mode 100644 repos/base/include/cpu/cache.h create mode 100644 repos/base/src/base/cpu/cache.cc diff --git a/repos/base-codezero/lib/mk/base.mk b/repos/base-codezero/lib/mk/base.mk index 1cd54b3fc..7aea3ba22 100644 --- a/repos/base-codezero/lib/mk/base.mk +++ b/repos/base-codezero/lib/mk/base.mk @@ -1,4 +1,5 @@ SRC_CC += console/log_console.cc +SRC_CC += cpu/cache.cc SRC_CC += env/env.cc env/context_area.cc env/reinitialize.cc SRC_CC += thread/thread_start.cc diff --git a/repos/base-fiasco/lib/mk/base.mk b/repos/base-fiasco/lib/mk/base.mk index c364cd313..2ea9bfcab 100644 --- a/repos/base-fiasco/lib/mk/base.mk +++ b/repos/base-fiasco/lib/mk/base.mk @@ -7,6 +7,7 @@ LIBS += base-common SRC_CC += console/log_console.cc +SRC_CC += cpu/cache.cc SRC_CC += env/env.cc env/context_area.cc env/reinitialize.cc SRC_CC += thread/thread_start.cc diff --git a/repos/base-foc/lib/mk/base.mk b/repos/base-foc/lib/mk/base.mk index 93c6c060d..44aa19f3e 100644 --- a/repos/base-foc/lib/mk/base.mk +++ b/repos/base-foc/lib/mk/base.mk @@ -7,6 +7,7 @@ LIBS += base-common SRC_CC += console/log_console.cc +SRC_CC += cpu/cache.cc SRC_CC += env/env.cc env/context_area.cc env/reinitialize.cc \ env/cap_map_remove.cc env/cap_alloc.cc SRC_CC += thread/thread_start.cc diff --git a/repos/base-foc/src/base/cpu/cache.cc b/repos/base-foc/src/base/cpu/cache.cc new file mode 100644 index 000000000..0cbbc5812 --- /dev/null +++ b/repos/base-foc/src/base/cpu/cache.cc @@ -0,0 +1,23 @@ +/* + * \brief Implementation of the cache operations + * \author Christian Prochaska + * \date 2014-05-13 + */ + +/* + * Copyright (C) 2014 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. + */ + +namespace Fiasco { +#include +} + +#include + +void Genode::cache_coherent(Genode::addr_t addr, Genode::size_t size) +{ + Fiasco::l4_cache_coherent(addr, addr + size); +} diff --git a/repos/base-hw/lib/mk/base.mk b/repos/base-hw/lib/mk/base.mk index 45094c478..bd1d7242a 100644 --- a/repos/base-hw/lib/mk/base.mk +++ b/repos/base-hw/lib/mk/base.mk @@ -7,6 +7,7 @@ LIBS += base-common startup SRC_CC += console/log_console.cc +SRC_CC += cpu/cache.cc SRC_CC += env/env.cc env/context_area.cc env/reinitialize.cc SRC_CC += thread/thread.cc thread_support.cc diff --git a/repos/base-hw/src/base/cpu/cache.cc b/repos/base-hw/src/base/cpu/cache.cc new file mode 100644 index 000000000..a3fa969ea --- /dev/null +++ b/repos/base-hw/src/base/cpu/cache.cc @@ -0,0 +1,21 @@ +/* + * \brief Implementation of the cache operations + * \author Christian Prochaska + * \date 2014-05-13 + */ + +/* + * Copyright (C) 2014 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. + */ + +#include + +#include + +void Genode::cache_coherent(Genode::addr_t addr, Genode::size_t size) +{ + Kernel::update_instr_region(addr, size); +} diff --git a/repos/base-linux/lib/mk/arm/base.mk b/repos/base-linux/lib/mk/arm/base.mk new file mode 100644 index 000000000..c8020257b --- /dev/null +++ b/repos/base-linux/lib/mk/arm/base.mk @@ -0,0 +1,9 @@ +# +# \brief ARM-specific base lib parts that are not used by hybrid applications +# \author Christian Prochaska +# \date 2014-05-14 +# + +SRC_CC += cpu/arm/cache.cc + +include $(REP_DIR)/lib/mk/base.mk diff --git a/repos/base-linux/lib/mk/x86/base.mk b/repos/base-linux/lib/mk/x86/base.mk new file mode 100644 index 000000000..3dbbc67cd --- /dev/null +++ b/repos/base-linux/lib/mk/x86/base.mk @@ -0,0 +1,9 @@ +# +# \brief x86-specific base lib parts that are not used by hybrid applications +# \author Christian Prochaska +# \date 2014-05-14 +# + +SRC_CC += cpu/cache.cc + +include $(REP_DIR)/lib/mk/base.mk diff --git a/repos/base-linux/src/base/cpu/arm/cache.cc b/repos/base-linux/src/base/cpu/arm/cache.cc new file mode 100644 index 000000000..828ae1afe --- /dev/null +++ b/repos/base-linux/src/base/cpu/arm/cache.cc @@ -0,0 +1,21 @@ +/* + * \brief Implementation of the cache operations + * \author Christian Prochaska + * \date 2014-05-13 + */ + +/* + * Copyright (C) 2014 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. + */ + +#include + +#include + +void Genode::cache_coherent(Genode::addr_t addr, Genode::size_t size) +{ + lx_syscall(__ARM_NR_cacheflush, addr, addr + size, 0); +} diff --git a/repos/base-nova/lib/mk/base.mk b/repos/base-nova/lib/mk/base.mk index a59981a15..0b1ce6a00 100644 --- a/repos/base-nova/lib/mk/base.mk +++ b/repos/base-nova/lib/mk/base.mk @@ -7,6 +7,7 @@ LIBS += base-common SRC_CC += console/log_console.cc +SRC_CC += cpu/cache.cc SRC_CC += env/env.cc env/context_area.cc env/reinitialize.cc SRC_CC += thread/thread_nova.cc diff --git a/repos/base-okl4/lib/mk/base.mk b/repos/base-okl4/lib/mk/base.mk index 2adc078d4..91ace8320 100644 --- a/repos/base-okl4/lib/mk/base.mk +++ b/repos/base-okl4/lib/mk/base.mk @@ -1,4 +1,5 @@ SRC_CC += console/log_console.cc +SRC_CC += cpu/cache.cc SRC_CC += env/env.cc env/context_area.cc env/reinitialize.cc SRC_CC += thread/thread_start.cc diff --git a/repos/base-pistachio/lib/mk/base.mk b/repos/base-pistachio/lib/mk/base.mk index c364cd313..2ea9bfcab 100644 --- a/repos/base-pistachio/lib/mk/base.mk +++ b/repos/base-pistachio/lib/mk/base.mk @@ -7,6 +7,7 @@ LIBS += base-common SRC_CC += console/log_console.cc +SRC_CC += cpu/cache.cc SRC_CC += env/env.cc env/context_area.cc env/reinitialize.cc SRC_CC += thread/thread_start.cc diff --git a/repos/base/include/cpu/cache.h b/repos/base/include/cpu/cache.h new file mode 100644 index 000000000..fdf24cb3d --- /dev/null +++ b/repos/base/include/cpu/cache.h @@ -0,0 +1,28 @@ +/* + * \brief Cache operations + * \author Christian Prochaska + * \date 2014-05-13 + */ + +/* + * Copyright (C) 2014 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. + */ + +#ifndef _INCLUDE__CPU__CACHE_H_ +#define _INCLUDE__CPU__CACHE_H_ + +#include + +namespace Genode { + + /* + * Make D-Cache and I-Cache coherent + */ + void cache_coherent(Genode::addr_t addr, Genode::size_t size); + +} + +#endif /* _INCLUDE__CPU__CACHE_H_ */ diff --git a/repos/base/src/base/cpu/cache.cc b/repos/base/src/base/cpu/cache.cc new file mode 100644 index 000000000..7d4950ae7 --- /dev/null +++ b/repos/base/src/base/cpu/cache.cc @@ -0,0 +1,21 @@ +/* + * \brief Implementation of the cache operations + * \author Christian Prochaska + * \date 2014-05-13 + */ + +/* + * Copyright (C) 2014 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. + */ + +#include + +/* + * This function needs to be implemented only for base platforms with ARM + * support right now, so the default implementation does nothing. + */ +void cache_coherent(Genode::addr_t, Genode::size_t) { } +