/* * \brief Core-internal utilities * \author Martin Stein * \date 2012-01-02 */ /* * Copyright (C) 2012-2013 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 _UTIL_H_ #define _UTIL_H_ /* Genode includes */ #include #include namespace Genode { enum { ACTIVITY_TABLE_ON_FAULTS = 0, MIN_PAGE_SIZE_LOG2 = 12, }; /** * Identification that core threads use to get access to their metadata */ typedef addr_t Core_thread_id; /** * Allows core threads to get their core-thread ID via their stack pointer */ enum { CORE_STACK_ALIGNM_LOG2 = 15 }; /** * Get the the minimal supported page-size log 2 */ constexpr size_t get_page_size_log2() { return MIN_PAGE_SIZE_LOG2; } /** * Get the the minimal supported page-size */ constexpr size_t get_page_size() { return 1 << get_page_size_log2(); } /** * Get the base mask for the minimal supported page-size */ constexpr addr_t get_page_mask() { return ~(get_page_size() - 1); } /** * Round down to the minimal page-size alignment */ inline addr_t trunc_page(addr_t addr) { return addr & get_page_mask(); } /** * Round up to the minimal page-size alignment */ inline addr_t round_page(addr_t addr) { return trunc_page(addr + get_page_size() - 1); } /** * Return an address rounded down to a specific alignment * * \param addr original address * \param alignm_log2 log2 of the required alignment */ inline addr_t trunc(addr_t const addr, addr_t const alignm_log2) { return (addr >> alignm_log2) << alignm_log2; } /** * Return wether a pointer fullfills an alignment * * \param p pointer * \param alignm_log2 log2 of the required alignment */ inline bool aligned(void * const p, addr_t const alignm_log2) { return (addr_t)p == trunc((addr_t)p, alignm_log2); } /** * Round up to a specific alignment */ inline addr_t round(addr_t const addr, unsigned const alignm_log2) { return trunc(addr + (1<