From df38140ed666d77cc43087a5c582ee981c9f80fe Mon Sep 17 00:00:00 2001 From: Norman Feske Date: Sun, 7 Feb 2021 18:01:58 +0100 Subject: [PATCH] base-pistachio: coding style --- repos/base-pistachio/src/core/core_log_out.cc | 12 +- .../src/core/include/ipc_pager.h | 317 +++++++------ repos/base-pistachio/src/core/include/kip.h | 4 +- .../src/core/include/map_local.h | 9 +- .../src/core/include/platform.h | 237 +++++----- .../src/core/include/platform_pd.h | 435 +++++++++--------- .../src/core/include/platform_thread.h | 266 +++++------ .../src/core/include/print_l4_thread_id.h | 5 +- .../src/core/include/rpc_cap_factory.h | 1 + repos/base-pistachio/src/core/include/util.h | 8 +- .../src/core/io_mem_session_support.cc | 16 +- .../src/core/irq_session_component.cc | 5 +- repos/base-pistachio/src/core/pager.cc | 14 +- repos/base-pistachio/src/core/pager_object.cc | 7 +- repos/base-pistachio/src/core/platform.cc | 11 +- repos/base-pistachio/src/core/platform_pd.cc | 16 +- .../src/core/platform_thread.cc | 19 +- .../src/core/ram_dataspace_support.cc | 4 + .../src/core/spec/x86/platform_x86.cc | 14 +- .../src/include/base/internal/lock_helper.h | 7 +- .../src/include/base/internal/native_thread.h | 6 +- .../src/include/base/internal/pistachio.h | 32 ++ .../include/base/internal/raw_write_string.h | 4 +- .../include/base/internal/rpc_destination.h | 5 +- repos/base-pistachio/src/lib/base/ipc.cc | 7 +- .../src/lib/base/thread_bootstrap.cc | 13 +- 26 files changed, 725 insertions(+), 749 deletions(-) create mode 100644 repos/base-pistachio/src/include/base/internal/pistachio.h diff --git a/repos/base-pistachio/src/core/core_log_out.cc b/repos/base-pistachio/src/core/core_log_out.cc index 92d22c86a0..80a66f810f 100644 --- a/repos/base-pistachio/src/core/core_log_out.cc +++ b/repos/base-pistachio/src/core/core_log_out.cc @@ -14,9 +14,11 @@ /* core includes */ #include -/* Pistachio includes */ -namespace Pistachio { -#include -} +/* base-internal includes */ +#include -void Genode::Core_log::out(char const c) { Pistachio::L4_KDB_PrintChar(c); } + +void Genode::Core_log::out(char const c) +{ + Pistachio::L4_KDB_PrintChar(c); +} diff --git a/repos/base-pistachio/src/core/include/ipc_pager.h b/repos/base-pistachio/src/core/include/ipc_pager.h index 56553dc68d..4b88daf3ee 100644 --- a/repos/base-pistachio/src/core/include/ipc_pager.h +++ b/repos/base-pistachio/src/core/include/ipc_pager.h @@ -23,168 +23,167 @@ /* core-local includes */ #include -/* Pistachio includes */ -namespace Pistachio { -#include -} +/* base-internal includes */ +#include namespace Genode { - class Mapping - { - private: - - union { - Pistachio::L4_MapItem_t _map_item; - Pistachio::L4_GrantItem_t _grant_item; - }; - - public: - - /** - * Constructor - */ - Mapping(addr_t dst_addr, addr_t src_addr, - Cache_attribute, bool io_mem, - unsigned l2size, - bool rw, bool executable); - - /** - * Construct invalid mapping - */ - Mapping(); - - addr_t _dst_addr() const { return Pistachio::L4_SndBase(_map_item); } - - Pistachio::L4_Fpage_t fpage() const { - return Pistachio::L4_MapItemSndFpage(_map_item); } - - Pistachio::L4_MapItem_t map_item() const { return _map_item; }; - - /** - * Prepare map operation - * - * On Pistachio, we need to map a page locally to be able to map it - * to another address space. - */ - void prepare_map_operation() - { - using namespace Pistachio; - unsigned char volatile *core_local_addr = - (unsigned char volatile *)L4_Address(_map_item.X.snd_fpage); - - if (L4_Rights(_map_item.X.snd_fpage) & L4_Writable) - touch_read_write(core_local_addr); - else - touch_read(core_local_addr); - } - }; - - - /** - * Special paging server class - */ - class Ipc_pager - { - private: - - Pistachio::L4_ThreadId_t _last; /* origin of last fault message */ - Pistachio::L4_Word_t _flags; /* page-fault attributes */ - addr_t _pf_addr; /* page-fault address */ - addr_t _pf_ip; /* instruction pointer of faulter */ - Pistachio::L4_MapItem_t _map_item; /* page-fault answer */ - - protected: - - /** - * Wait for short-message (register) IPC -- pagefault - */ - void _wait(); - - /** - * Send short flex page and - * wait for next short-message (register) IPC -- pagefault - */ - void _reply_and_wait(); - - public: - - /** - * Wait for a new fault received as short message IPC - */ - void wait_for_fault(); - - /** - * Reply current fault and wait for a new one - * - * Send short flex page and wait for next short-message (register) - * IPC -- pagefault - */ - void reply_and_wait_for_fault(); - - /** - * Request instruction pointer of current fault - */ - addr_t fault_ip() { return _pf_ip; } - - /** - * Request fault address of current page fault - */ - addr_t fault_addr() { return _pf_addr & ~3; } - - /** - * Set parameters for next reply - */ - void set_reply_mapping(Mapping m) { _map_item = m.map_item(); } - - /** - * Set destination for next reply - */ - void set_reply_dst(Native_capability pager_object) { - _last.raw = pager_object.local_name(); } - - /** - * Answer call without sending a flex-page mapping - * - * This function is used to acknowledge local calls from one of - * core's region-manager sessions. - */ - void acknowledge_wakeup(); - - /** - * Returns true if the last request was send from a core thread - */ - bool request_from_core() { return true; } - - /** - * Return badge for faulting thread - * - * As L4v4 has no server-defined badges for fault messages, - * we interpret the sender ID as badge. - */ - unsigned long badge() const { return _last.raw; } - - /** - * Return true if last fault was a write fault - */ - bool write_fault() const { return (_flags & 2); } - - /** - * Return true if last fault was a executable fault - */ - bool exec_fault() const { return false; } - - /** - * Return true if last fault was an exception - */ - bool exception() const - { - /* - * Reflection of exceptions is not supported on this platform. - */ - return false; - } - }; + class Mapping; + class Ipc_pager; } + +class Genode::Mapping +{ + private: + + union { + Pistachio::L4_MapItem_t _map_item; + Pistachio::L4_GrantItem_t _grant_item; + }; + + public: + + /** + * Constructor + */ + Mapping(addr_t dst_addr, addr_t src_addr, + Cache_attribute, bool io_mem, + unsigned l2size, + bool rw, bool executable); + + /** + * Construct invalid mapping + */ + Mapping(); + + addr_t _dst_addr() const { return Pistachio::L4_SndBase(_map_item); } + + Pistachio::L4_Fpage_t fpage() const { + return Pistachio::L4_MapItemSndFpage(_map_item); } + + Pistachio::L4_MapItem_t map_item() const { return _map_item; }; + + /** + * Prepare map operation + * + * On Pistachio, we need to map a page locally to be able to map it + * to another address space. + */ + void prepare_map_operation() + { + using namespace Pistachio; + unsigned char volatile *core_local_addr = + (unsigned char volatile *)L4_Address(_map_item.X.snd_fpage); + + if (L4_Rights(_map_item.X.snd_fpage) & L4_Writable) + touch_read_write(core_local_addr); + else + touch_read(core_local_addr); + } +}; + + +class Genode::Ipc_pager +{ + private: + + Pistachio::L4_ThreadId_t _last; /* origin of last fault message */ + Pistachio::L4_Word_t _flags; /* page-fault attributes */ + addr_t _pf_addr; /* page-fault address */ + addr_t _pf_ip; /* instruction pointer of faulter */ + Pistachio::L4_MapItem_t _map_item; /* page-fault answer */ + + protected: + + /** + * Wait for short-message (register) IPC -- pagefault + */ + void _wait(); + + /** + * Send short flex page and + * wait for next short-message (register) IPC -- pagefault + */ + void _reply_and_wait(); + + public: + + /** + * Wait for a new fault received as short message IPC + */ + void wait_for_fault(); + + /** + * Reply current fault and wait for a new one + * + * Send short flex page and wait for next short-message (register) + * IPC -- pagefault + */ + void reply_and_wait_for_fault(); + + /** + * Request instruction pointer of current fault + */ + addr_t fault_ip() { return _pf_ip; } + + /** + * Request fault address of current page fault + */ + addr_t fault_addr() { return _pf_addr & ~3; } + + /** + * Set parameters for next reply + */ + void set_reply_mapping(Mapping m) { _map_item = m.map_item(); } + + /** + * Set destination for next reply + */ + void set_reply_dst(Native_capability pager_object) { + _last.raw = pager_object.local_name(); } + + /** + * Answer call without sending a flex-page mapping + * + * This function is used to acknowledge local calls from one of + * core's region-manager sessions. + */ + void acknowledge_wakeup(); + + /** + * Returns true if the last request was send from a core thread + */ + bool request_from_core() { return true; } + + /** + * Return badge for faulting thread + * + * As L4v4 has no server-defined badges for fault messages, + * we interpret the sender ID as badge. + */ + unsigned long badge() const { return _last.raw; } + + /** + * Return true if last fault was a write fault + */ + bool write_fault() const { return (_flags & 2); } + + /** + * Return true if last fault was a executable fault + */ + bool exec_fault() const { return false; } + + /** + * Return true if last fault was an exception + */ + bool exception() const + { + /* + * Reflection of exceptions is not supported on this platform. + */ + return false; + } +}; + #endif /* _CORE__INCLUDE__IPC_PAGER_H_ */ diff --git a/repos/base-pistachio/src/core/include/kip.h b/repos/base-pistachio/src/core/include/kip.h index ee2feea99a..e3d4bec239 100644 --- a/repos/base-pistachio/src/core/include/kip.h +++ b/repos/base-pistachio/src/core/include/kip.h @@ -14,9 +14,9 @@ #ifndef _CORE__INCLUDE__KIP_H_ #define _CORE__INCLUDE__KIP_H_ +#include + namespace Pistachio { -#include -#include /** * Return a pointer to the kernel info page diff --git a/repos/base-pistachio/src/core/include/map_local.h b/repos/base-pistachio/src/core/include/map_local.h index ef0bb2bdb4..96a6114385 100644 --- a/repos/base-pistachio/src/core/include/map_local.h +++ b/repos/base-pistachio/src/core/include/map_local.h @@ -18,13 +18,8 @@ #include #include -/* Pistachio includes */ -namespace Pistachio { -#include -#include -#include -#include -} +/* base-internal includes */ +#include namespace Genode { diff --git a/repos/base-pistachio/src/core/include/platform.h b/repos/base-pistachio/src/core/include/platform.h index 1edd4c9b19..240038fb2c 100644 --- a/repos/base-pistachio/src/core/include/platform.h +++ b/repos/base-pistachio/src/core/include/platform.h @@ -21,149 +21,148 @@ /* base-internal includes */ #include -/* core-local includes */ -#include "synced_range_allocator.h" -#include "platform_generic.h" -#include "platform_thread.h" -#include "platform_pd.h" +/* core includes */ +#include +#include +#include +#include + +namespace Genode { class Platform; } -namespace Genode { +class Genode::Platform : public Platform_generic +{ + private: - class Platform : public Platform_generic - { - private: + /* + * Shortcut for the type of allocator instances for physical resources + */ + typedef Synced_range_allocator Phys_allocator; - /* - * Shortcut for the type of allocator instances for physical resources - */ - typedef Synced_range_allocator Phys_allocator; + Phys_allocator _ram_alloc; /* RAM allocator */ + Phys_allocator _io_mem_alloc; /* MMIO allocator */ + Phys_allocator _io_port_alloc; /* I/O port allocator */ + Phys_allocator _irq_alloc; /* IRQ allocator */ + Phys_allocator _region_alloc; /* virtual memory allocator for core */ + Rom_fs _rom_fs { }; /* ROM file system */ + Rom_module _kip_rom; /* ROM module for Fiasco KIP */ + addr_t _vm_start = 0; /* begin of virtual memory */ + size_t _vm_size = 0; /* size of virtual memory */ - Phys_allocator _ram_alloc; /* RAM allocator */ - Phys_allocator _io_mem_alloc; /* MMIO allocator */ - Phys_allocator _io_port_alloc; /* I/O port allocator */ - Phys_allocator _irq_alloc; /* IRQ allocator */ - Phys_allocator _region_alloc; /* virtual memory allocator for core */ - Rom_fs _rom_fs { }; /* ROM file system */ - Rom_module _kip_rom; /* ROM module for Fiasco KIP */ - addr_t _vm_start = 0; /* begin of virtual memory */ - size_t _vm_size = 0; /* size of virtual memory */ + /* + * We do not export any boot module loaded before FIRST_ROM. + */ + enum { FIRST_ROM = 3 }; - /* - * We do not export any boot module loaded before FIRST_ROM. - */ - enum { FIRST_ROM = 3 }; + /** + * Setup base resources + * + * - Map and provide KIP as ROM module + * - Initializes region allocator + */ + void _setup_basics(); - /** - * Setup base resources - * - * - Map and provide KIP as ROM module - * - Initializes region allocator - */ - void _setup_basics(); + /** + * Setup preemption flags + */ + void _setup_preemption(); - /** - * Setup preemption flags - */ - void _setup_preemption(); + /** + * Setup RAM, IO_MEM, and region allocators + */ + void _setup_mem_alloc(); - /** - * Setup RAM, IO_MEM, and region allocators - */ - void _setup_mem_alloc(); + /** + * Setup I/O port space allocator + */ + void _setup_io_port_alloc(); - /** - * Setup I/O port space allocator - */ - void _setup_io_port_alloc(); + /** + * Setup IRQ allocator + */ + void _setup_irq_alloc(); - /** - * Setup IRQ allocator - */ - void _setup_irq_alloc(); + /** + * Parse multi-boot information and update ROM database + */ + void _init_rom_modules(); - /** - * Parse multi-boot information and update ROM database - */ - void _init_rom_modules(); + addr_t _rom_module_phys(addr_t virt) { return virt; } - addr_t _rom_module_phys(addr_t virt) { return virt; } - - public: - - /** - * Pager object representing the pager of core namely sigma0 - */ - struct Sigma0 : public Pager_object - { - /** - * Constructor - */ - Sigma0(); - - int pager(Ipc_pager &) override { /* never called */ return -1; } - }; - - /** - * Return singleton instance of Sigma0 pager object - */ - static Sigma0 &sigma0(); - - /** - * Core pager thread that handles core-internal page-faults - */ - struct Core_pager : public Platform_thread, public Pager_object - { - /** - * Constructor - */ - Core_pager(Platform_pd &core_pd); - - int pager(Ipc_pager &) override { /* never called */ return -1; } - }; - - /** - * Return singleton instance of core pager object - */ - Core_pager &core_pager(); + public: + /** + * Pager object representing the pager of core namely sigma0 + */ + struct Sigma0 : public Pager_object + { /** * Constructor */ - Platform(); + Sigma0(); + int pager(Ipc_pager &) override { /* never called */ return -1; } + }; + + /** + * Return singleton instance of Sigma0 pager object + */ + static Sigma0 &sigma0(); + + /** + * Core pager thread that handles core-internal page-faults + */ + struct Core_pager : public Platform_thread, public Pager_object + { /** - * Return singleton instance of core PD object + * Constructor */ - Platform_pd &core_pd(); + Core_pager(Platform_pd &core_pd); + + int pager(Ipc_pager &) override { /* never called */ return -1; } + }; + + /** + * Return singleton instance of core pager object + */ + Core_pager &core_pager(); + + /** + * Constructor + */ + Platform(); + + /** + * Return singleton instance of core PD object + */ + Platform_pd &core_pd(); - /******************************** - ** Generic platform interface ** - ********************************/ + /******************************** + ** Generic platform interface ** + ********************************/ - Range_allocator &core_mem_alloc() override { return _ram_alloc; } - Range_allocator &ram_alloc() override { return _ram_alloc; } - Range_allocator &io_mem_alloc() override { return _io_mem_alloc; } - Range_allocator &io_port_alloc() override { return _io_port_alloc; } - Range_allocator &irq_alloc() override { return _irq_alloc; } - Range_allocator ®ion_alloc() override { return _region_alloc; } - addr_t vm_start() const override { return _vm_start; } - size_t vm_size() const override { return _vm_size; } - Rom_fs &rom_fs() override { return _rom_fs; } - size_t max_caps() const override { return Capability_space::max_caps(); } + Range_allocator &core_mem_alloc() override { return _ram_alloc; } + Range_allocator &ram_alloc() override { return _ram_alloc; } + Range_allocator &io_mem_alloc() override { return _io_mem_alloc; } + Range_allocator &io_port_alloc() override { return _io_port_alloc; } + Range_allocator &irq_alloc() override { return _irq_alloc; } + Range_allocator ®ion_alloc() override { return _region_alloc; } + addr_t vm_start() const override { return _vm_start; } + size_t vm_size() const override { return _vm_size; } + Rom_fs &rom_fs() override { return _rom_fs; } + size_t max_caps() const override { return Capability_space::max_caps(); } - void wait_for_exit() override; + void wait_for_exit() override; - Affinity::Space affinity_space() const override - { - /* - * Ignore topology of CPU nodes, just return a one-dimensional - * affinity space. - */ - return Affinity::Space(L4_NumProcessors(Pistachio::get_kip()), 1); - } - }; -} + Affinity::Space affinity_space() const override + { + /* + * Ignore topology of CPU nodes, just return a one-dimensional + * affinity space. + */ + return Affinity::Space(L4_NumProcessors(Pistachio::get_kip()), 1); + } +}; #endif /* _CORE__INCLUDE__PLATFORM_H_ */ diff --git a/repos/base-pistachio/src/core/include/platform_pd.h b/repos/base-pistachio/src/core/include/platform_pd.h index 94d44cda65..7a2919d0ed 100644 --- a/repos/base-pistachio/src/core/include/platform_pd.h +++ b/repos/base-pistachio/src/core/include/platform_pd.h @@ -14,228 +14,233 @@ #ifndef _CORE__INCLUDE__PLATFORM_PD_H_ #define _CORE__INCLUDE__PLATFORM_PD_H_ +/* Genode includes */ #include + +/* base-internal includes */ +#include + +/* core includes */ #include #include -namespace Pistachio { -#include -} - namespace Genode { class Platform_thread; - class Platform_pd : public Address_space - { - private: - - /* - * Noncopyable - */ - Platform_pd(Platform_pd const &); - Platform_pd &operator = (Platform_pd const &); - - friend class Platform_thread; - - /* - * L4 thread ID has 18 bits for thread number and 14 bits for - * version info. - */ - enum { - PD_BITS = 9, - THREAD_BITS = 7, - VERSION_BITS = 14 - 1, /* preserve 1 bit, see 'make_l4_id' */ - PD_FIRST = 0, - PD_MAX = (1 << PD_BITS) - 1, - THREAD_MAX = (1 << THREAD_BITS) - 1, - VERSION_MAX = (1 << VERSION_BITS) - 1, - PD_INVALID = -1, - }; - - unsigned _pd_id = 0; - unsigned _version = 0; - - Pistachio::L4_ThreadId_t _l4_task_id { }; /* L4 task ID */ - - /** - * Manually construct L4 thread ID from its components - */ - Pistachio::L4_ThreadId_t make_l4_id(unsigned pd_no, - unsigned thread_no, - unsigned version) - { - /* - * We have to make sure that the 6 lower version bits are - * never zero. Otherwise, the kernel won't recognize the - * thread ID as a global ID (i.e., 'L4_ThreadControl' would - * fail during the creation of a new PD). To maintain this - * invariant, we always set the lowest version bit to one. - */ - return Pistachio::L4_GlobalId((pd_no << PD_BITS) | thread_no, - (version << 1) | 1); - } - - - /********************************************** - ** Threads of this protection domain object ** - **********************************************/ - - Platform_thread *_threads[THREAD_MAX]; - - /** - * Initialize thread allocator - */ - void _init_threads(); - - /** - * Thread iteration for one PD - */ - Platform_thread *_next_thread(); - - /** - * Thread allocation - * - * Again a special case for Core thread0. - */ - int _alloc_thread(int thread_id, Platform_thread &thread); - - /** - * Thread deallocation - * - * No special case for Core thread0 here - we just never call it. - */ - void _free_thread(int thread_id); - - - /****************** - ** PD allocator ** - ******************/ - - struct Pd_alloc - { - unsigned reserved : 1; - unsigned free : 1; - unsigned version : VERSION_BITS; - - Pd_alloc(bool r, bool f, unsigned v) - : reserved(r), free(f), version(v) { } - - /* - * Start with version 2 to avoid being mistaken as local or - * interrupt thread ID. - */ - Pd_alloc() : reserved(0), free(0), version(2) { } - }; - - static Pd_alloc *_pds() - { - static Pd_alloc static_pds[PD_MAX]; - return static_pds; - } - - Pistachio::L4_Word_t _kip_ptr = 0; - Pistachio::L4_Word_t _utcb_ptr = 0; - - /** - * Protection-domain creation - * - * The syscall parameter propagates if any L4 kernel function - * should be used. We need the special case for the Core startup. - */ - void _create_pd(bool syscall); - - /** - * Protection domain destruction - * - * No special case for Core here - we just never call it. - */ - void _destroy_pd(); - - /** - * Protection domain allocation - * - * Find free PD and use it. We need the special case for core - * startup. - */ - int _alloc_pd(signed pd_id); - - /** - * Protection domain deallocation - * - * No special case for Core here - we just never call it. - */ - void _free_pd(); - - /** - * Setup KIP and UTCB area - */ - void _setup_address_space(); - - /** - * Return the location of the UTCB for the specified thread - */ - Pistachio::L4_Word_t _utcb_location(unsigned int thread_id); - - - /*************** - ** Debugging ** - ***************/ - - void _debug_log_pds(void); - void _debug_log_threads(void); - - public: - - /** - * Constructors - */ - Platform_pd(bool core); - Platform_pd(Allocator &md_alloc, char const *, - signed pd_id = PD_INVALID, bool create = true); - - /** - * Destructor - */ - ~Platform_pd(); - - /** - * Register quota donation at allocator guard - */ - void upgrade_ram_quota(size_t) { } - - static Pistachio::L4_Word_t _core_utcb_ptr; - static void touch_utcb_space(); - - /** - * Bind thread to protection domain - * - * This function allocates the physical L4 thread ID. - */ - bool bind_thread(Platform_thread &thread); - - int bind_initial_thread(Platform_thread &thread); - - /** - * Unbind thread from protection domain - * - * Free the thread's slot and update thread object. - */ - void unbind_thread(Platform_thread &thread); - - /** - * Assign parent interface to protection domain - */ - void assign_parent(Native_capability) { } - - int pd_id() const { return _pd_id; } - - - /***************************** - ** Address-space interface ** - *****************************/ - - void flush(addr_t, size_t, Core_local_addr) override; - }; + class Platform_pd; } + +class Genode::Platform_pd : public Address_space +{ + private: + + /* + * Noncopyable + */ + Platform_pd(Platform_pd const &); + Platform_pd &operator = (Platform_pd const &); + + friend class Platform_thread; + + /* + * L4 thread ID has 18 bits for thread number and 14 bits for + * version info. + */ + enum { + PD_BITS = 9, + THREAD_BITS = 7, + VERSION_BITS = 14 - 1, /* preserve 1 bit, see 'make_l4_id' */ + PD_FIRST = 0, + PD_MAX = (1 << PD_BITS) - 1, + THREAD_MAX = (1 << THREAD_BITS) - 1, + VERSION_MAX = (1 << VERSION_BITS) - 1, + PD_INVALID = -1, + }; + + unsigned _pd_id = 0; + unsigned _version = 0; + + Pistachio::L4_ThreadId_t _l4_task_id { }; /* L4 task ID */ + + /** + * Manually construct L4 thread ID from its components + */ + Pistachio::L4_ThreadId_t make_l4_id(unsigned pd_no, + unsigned thread_no, + unsigned version) + { + /* + * We have to make sure that the 6 lower version bits are + * never zero. Otherwise, the kernel won't recognize the + * thread ID as a global ID (i.e., 'L4_ThreadControl' would + * fail during the creation of a new PD). To maintain this + * invariant, we always set the lowest version bit to one. + */ + return Pistachio::L4_GlobalId((pd_no << PD_BITS) | thread_no, + (version << 1) | 1); + } + + + /********************************************** + ** Threads of this protection domain object ** + **********************************************/ + + Platform_thread *_threads[THREAD_MAX]; + + /** + * Initialize thread allocator + */ + void _init_threads(); + + /** + * Thread iteration for one PD + */ + Platform_thread *_next_thread(); + + /** + * Thread allocation + * + * Again a special case for Core thread0. + */ + int _alloc_thread(int thread_id, Platform_thread &thread); + + /** + * Thread deallocation + * + * No special case for Core thread0 here - we just never call it. + */ + void _free_thread(int thread_id); + + + /****************** + ** PD allocator ** + ******************/ + + struct Pd_alloc + { + unsigned reserved : 1; + unsigned free : 1; + unsigned version : VERSION_BITS; + + Pd_alloc(bool r, bool f, unsigned v) + : reserved(r), free(f), version(v) { } + + /* + * Start with version 2 to avoid being mistaken as local or + * interrupt thread ID. + */ + Pd_alloc() : reserved(0), free(0), version(2) { } + }; + + static Pd_alloc *_pds() + { + static Pd_alloc static_pds[PD_MAX]; + return static_pds; + } + + Pistachio::L4_Word_t _kip_ptr = 0; + Pistachio::L4_Word_t _utcb_ptr = 0; + + /** + * Protection-domain creation + * + * The syscall parameter propagates if any L4 kernel function + * should be used. We need the special case for the Core startup. + */ + void _create_pd(bool syscall); + + /** + * Protection domain destruction + * + * No special case for Core here - we just never call it. + */ + void _destroy_pd(); + + /** + * Protection domain allocation + * + * Find free PD and use it. We need the special case for core + * startup. + */ + int _alloc_pd(signed pd_id); + + /** + * Protection domain deallocation + * + * No special case for Core here - we just never call it. + */ + void _free_pd(); + + /** + * Setup KIP and UTCB area + */ + void _setup_address_space(); + + /** + * Return the location of the UTCB for the specified thread + */ + Pistachio::L4_Word_t _utcb_location(unsigned int thread_id); + + + /*************** + ** Debugging ** + ***************/ + + void _debug_log_pds(void); + void _debug_log_threads(void); + + public: + + /** + * Constructors + */ + Platform_pd(bool core); + Platform_pd(Allocator &md_alloc, char const *, + signed pd_id = PD_INVALID, bool create = true); + + /** + * Destructor + */ + ~Platform_pd(); + + /** + * Register quota donation at allocator guard + */ + void upgrade_ram_quota(size_t) { } + + static Pistachio::L4_Word_t _core_utcb_ptr; + static void touch_utcb_space(); + + /** + * Bind thread to protection domain + * + * This function allocates the physical L4 thread ID. + */ + bool bind_thread(Platform_thread &thread); + + int bind_initial_thread(Platform_thread &thread); + + /** + * Unbind thread from protection domain + * + * Free the thread's slot and update thread object. + */ + void unbind_thread(Platform_thread &thread); + + /** + * Assign parent interface to protection domain + */ + void assign_parent(Native_capability) { } + + int pd_id() const { return _pd_id; } + + + /***************************** + ** Address-space interface ** + *****************************/ + + void flush(addr_t, size_t, Core_local_addr) override; +}; + #endif /* _CORE__INCLUDE__PLATFORM_PD_H_ */ diff --git a/repos/base-pistachio/src/core/include/platform_thread.h b/repos/base-pistachio/src/core/include/platform_thread.h index e91631ba83..e201b8d941 100644 --- a/repos/base-pistachio/src/core/include/platform_thread.h +++ b/repos/base-pistachio/src/core/include/platform_thread.h @@ -24,9 +24,13 @@ #include #include -/* Pistachio includes */ -namespace Pistachio { -#include +/* base-internal includes */ +#include + +namespace Genode { + + class Platform_pd; + class Platform_thread; } @@ -40,165 +44,163 @@ inline unsigned long convert_native_thread_id_to_badge(Pistachio::L4_ThreadId_t } -namespace Genode { +class Genode::Platform_thread : Interface +{ + private: - class Platform_pd; - class Platform_thread : Interface - { - private: + typedef Pistachio::L4_ThreadId_t L4_ThreadId_t; - typedef Pistachio::L4_ThreadId_t L4_ThreadId_t; + /* + * Noncopyable + */ + Platform_thread(Platform_thread const &); + Platform_thread &operator = (Platform_thread const &); - /* - * Noncopyable - */ - Platform_thread(Platform_thread const &); - Platform_thread &operator = (Platform_thread const &); + typedef String<32> Name; - typedef String<32> Name; + int _thread_id = THREAD_INVALID; + L4_ThreadId_t _l4_thread_id = L4_nilthread; + Name const _name; /* thread name at kernel debugger */ + Platform_pd *_platform_pd = nullptr; + unsigned _priority = 0; + Pager_object *_pager = nullptr; + Affinity::Location _location; - int _thread_id = THREAD_INVALID; - L4_ThreadId_t _l4_thread_id = L4_nilthread; - Name const _name; /* thread name at kernel debugger */ - Platform_pd *_platform_pd = nullptr; - unsigned _priority = 0; - Pager_object *_pager = nullptr; - Affinity::Location _location; + public: - public: + enum { THREAD_INVALID = -1 }; + enum { DEFAULT_PRIORITY = 128 }; - enum { THREAD_INVALID = -1 }; - enum { DEFAULT_PRIORITY = 128 }; + /** + * Constructor + */ + Platform_thread(size_t, char const *name, unsigned priority, + Affinity::Location location, addr_t) + : + _name(name), _priority(priority), _location(location) + { } - /** - * Constructor - */ - Platform_thread(size_t, char const *name, unsigned priority, - Affinity::Location location, addr_t) - : - _name(name), _priority(priority), _location(location) - { } + /** + * Constructor used for core-internal threads + */ + Platform_thread(char const *name) + : _name(name), _location(Affinity::Location()) { } - /** - * Constructor used for core-internal threads - */ - Platform_thread(char const *name) - : _name(name), _location(Affinity::Location()) { } + /** + * Destructor + */ + ~Platform_thread(); - /** - * Destructor - */ - ~Platform_thread(); + /** + * Start thread + * + * \param ip instruction pointer to start at + * \param sp stack pointer to use + * + * \retval 0 successful + * \retval -1 thread could not be started + */ + int start(void *ip, void *sp); - /** - * Start thread - * - * \param ip instruction pointer to start at - * \param sp stack pointer to use - * - * \retval 0 successful - * \retval -1 thread could not be started - */ - int start(void *ip, void *sp); + /** + * Pause this thread + */ + void pause(); - /** - * Pause this thread - */ - void pause(); + /** + * Enable/disable single stepping + */ + void single_step(bool) { } - /** - * Enable/disable single stepping - */ - void single_step(bool) { } + /** + * Resume this thread + */ + void resume(); - /** - * Resume this thread - */ - void resume(); + /** + * This thread is about to be bound + * + * \param thread_id local thread ID + * \param l4_thread_id final L4 thread ID + * \param pd platform pd, thread is bound to + */ + void bind(int thread_id, Pistachio::L4_ThreadId_t l4_thread_id, + Platform_pd &pd); - /** - * This thread is about to be bound - * - * \param thread_id local thread ID - * \param l4_thread_id final L4 thread ID - * \param pd platform pd, thread is bound to - */ - void bind(int thread_id, Pistachio::L4_ThreadId_t l4_thread_id, - Platform_pd &pd); + /** + * Unbind this thread + */ + void unbind(); - /** - * Unbind this thread - */ - void unbind(); + /** + * Override thread state with 's' + * + * \throw Cpu_session::State_access_failed + */ + void state(Thread_state s); - /** - * Override thread state with 's' - * - * \throw Cpu_session::State_access_failed - */ - void state(Thread_state s); - - /** - * Read thread state - */ - Thread_state state(); + /** + * Read thread state + */ + Thread_state state(); - /************************ - ** Accessor functions ** - ************************/ + /************************ + ** Accessor functions ** + ************************/ - /** - * Return/set pager - */ - Pager_object &pager() const - { - if (_pager) - return *_pager; + /** + * Return/set pager + */ + Pager_object &pager() const + { + if (_pager) + return *_pager; - ASSERT_NEVER_CALLED; - } + ASSERT_NEVER_CALLED; + } - void pager(Pager_object &pager) { _pager = &pager; } + void pager(Pager_object &pager) { _pager = &pager; } - /** - * Return identification of thread when faulting - */ - unsigned long pager_object_badge() const { - return convert_native_thread_id_to_badge(_l4_thread_id); } + /** + * Return identification of thread when faulting + */ + unsigned long pager_object_badge() const + { + return convert_native_thread_id_to_badge(_l4_thread_id); + } - /** - * Set the executing CPU for this thread - */ - void affinity(Affinity::Location location); + /** + * Set the executing CPU for this thread + */ + void affinity(Affinity::Location location); - /** - * Request the affinity of this thread - */ - Affinity::Location affinity() const; + /** + * Request the affinity of this thread + */ + Affinity::Location affinity() const; - /** - * Set CPU quota of the thread to 'quota' - */ - void quota(size_t const) { /* not supported*/ } + /** + * Set CPU quota of the thread to 'quota' + */ + void quota(size_t const) { /* not supported*/ } - /** - * Return execution time consumed by the thread - */ - Trace::Execution_time execution_time() const { return { 0, 0 }; } + /** + * Return execution time consumed by the thread + */ + Trace::Execution_time execution_time() const { return { 0, 0 }; } - /********************************** - ** Pistachio-specific Accessors ** - **********************************/ + /********************************** + ** Pistachio-specific Accessors ** + **********************************/ - int thread_id() const { return _thread_id; } - Pistachio::L4_ThreadId_t native_thread_id() const { return _l4_thread_id; } - Name name() const { return _name; } + int thread_id() const { return _thread_id; } + Pistachio::L4_ThreadId_t native_thread_id() const { return _l4_thread_id; } + Name name() const { return _name; } - /* use only for core... */ - void set_l4_thread_id(Pistachio::L4_ThreadId_t id) { _l4_thread_id = id; } - }; -} + /* use only for core... */ + void set_l4_thread_id(Pistachio::L4_ThreadId_t id) { _l4_thread_id = id; } +}; #endif /* _CORE__INCLUDE__PLATFORM_THREAD_H_ */ diff --git a/repos/base-pistachio/src/core/include/print_l4_thread_id.h b/repos/base-pistachio/src/core/include/print_l4_thread_id.h index 7a70e1f36a..625891247d 100644 --- a/repos/base-pistachio/src/core/include/print_l4_thread_id.h +++ b/repos/base-pistachio/src/core/include/print_l4_thread_id.h @@ -16,9 +16,8 @@ #include -namespace Pistachio { -#include -} +/* base-internal includes */ +#include namespace Genode { struct Formatted_tid; } diff --git a/repos/base-pistachio/src/core/include/rpc_cap_factory.h b/repos/base-pistachio/src/core/include/rpc_cap_factory.h index f28c36414d..8514599aaf 100644 --- a/repos/base-pistachio/src/core/include/rpc_cap_factory.h +++ b/repos/base-pistachio/src/core/include/rpc_cap_factory.h @@ -19,6 +19,7 @@ namespace Genode { class Rpc_cap_factory; } + class Genode::Rpc_cap_factory { private: diff --git a/repos/base-pistachio/src/core/include/util.h b/repos/base-pistachio/src/core/include/util.h index 2850c18aaf..7add6722a9 100644 --- a/repos/base-pistachio/src/core/include/util.h +++ b/repos/base-pistachio/src/core/include/util.h @@ -22,18 +22,12 @@ /* base-internal includes */ #include +#include /* core-local includes */ #include #include -/* Pistachio includes */ -namespace Pistachio { -#include -#include -#include -} - namespace Genode { inline void log_event(const char *) { } diff --git a/repos/base-pistachio/src/core/io_mem_session_support.cc b/repos/base-pistachio/src/core/io_mem_session_support.cc index 8f9d1717df..de699922b0 100644 --- a/repos/base-pistachio/src/core/io_mem_session_support.cc +++ b/repos/base-pistachio/src/core/io_mem_session_support.cc @@ -18,12 +18,8 @@ #include #include -/* Pistachio includes */ -namespace Pistachio { -#include -#include -#include -} +/* base-internal includes */ +#include using namespace Genode; @@ -32,7 +28,7 @@ using namespace Genode; * TODO This should take a size parameter and check if the whole * region is "normal" memory. */ -bool is_conventional_memory(addr_t base) +static bool is_conventional_memory(addr_t base) { using namespace Pistachio; L4_KernelInterfacePage_t *kip = get_kip(); @@ -53,9 +49,11 @@ bool is_conventional_memory(addr_t base) void Io_mem_session_component::_unmap_local(addr_t, size_t) { } -static inline bool can_use_super_page(addr_t base, size_t size) { +static inline bool can_use_super_page(addr_t base, size_t size) +{ return (base & (get_super_page_size() - 1)) == 0 - && (size >= get_super_page_size()); } + && (size >= get_super_page_size()); +} addr_t Io_mem_session_component::_map_local(addr_t base, size_t size) diff --git a/repos/base-pistachio/src/core/irq_session_component.cc b/repos/base-pistachio/src/core/irq_session_component.cc index 7db7b970c9..2c77d95fa0 100644 --- a/repos/base-pistachio/src/core/irq_session_component.cc +++ b/repos/base-pistachio/src/core/irq_session_component.cc @@ -19,10 +19,7 @@ #include #include -/* Pistachio includes */ -namespace Pistachio { -#include -} +/* base-internal includes */ using namespace Genode; using namespace Pistachio; diff --git a/repos/base-pistachio/src/core/pager.cc b/repos/base-pistachio/src/core/pager.cc index 507ffe4c99..7da7790f57 100644 --- a/repos/base-pistachio/src/core/pager.cc +++ b/repos/base-pistachio/src/core/pager.cc @@ -18,19 +18,12 @@ /* base-internal includes */ #include #include +#include /* core includes */ #include #include -namespace Pistachio -{ -#include -#include -#include -#include -} - using namespace Genode; using namespace Pistachio; @@ -56,7 +49,10 @@ Mapping::Mapping(addr_t dst_addr, addr_t src_addr, } -Mapping::Mapping() { _map_item = L4_MapItem(L4_Nilpage, 0); } +Mapping::Mapping() +{ + _map_item = L4_MapItem(L4_Nilpage, 0); +} /*************** diff --git a/repos/base-pistachio/src/core/pager_object.cc b/repos/base-pistachio/src/core/pager_object.cc index 0605bda033..37b4ff1d16 100644 --- a/repos/base-pistachio/src/core/pager_object.cc +++ b/repos/base-pistachio/src/core/pager_object.cc @@ -16,12 +16,7 @@ /* base-internal includes */ #include - -/* Pistachio includes */ -namespace Pistachio { -#include -#include -} +#include using namespace Genode; diff --git a/repos/base-pistachio/src/core/platform.cc b/repos/base-pistachio/src/core/platform.cc index d37b17cbb2..3bdd46f083 100644 --- a/repos/base-pistachio/src/core/platform.cc +++ b/repos/base-pistachio/src/core/platform.cc @@ -23,6 +23,7 @@ #include #include #include +#include /* core includes */ #include @@ -35,15 +36,6 @@ #include #include -/* Pistachio includes */ -namespace Pistachio { -#include -#include -#include -#include -#include -} - using namespace Genode; @@ -61,6 +53,7 @@ static Synced_range_allocator &_core_address_ranges() return _core_address_ranges; } + enum { PAGER_STACK_ELEMENTS = 512 }; static unsigned long _core_pager_stack[PAGER_STACK_ELEMENTS]; diff --git a/repos/base-pistachio/src/core/platform_pd.cc b/repos/base-pistachio/src/core/platform_pd.cc index 2200659e38..21e91ea481 100644 --- a/repos/base-pistachio/src/core/platform_pd.cc +++ b/repos/base-pistachio/src/core/platform_pd.cc @@ -17,14 +17,8 @@ #include #include -/* Pistachio includes */ -namespace Pistachio { -#include -#include -#include -#include -#include -} +/* base-internal includes */ +#include using namespace Pistachio; using namespace Genode; @@ -214,7 +208,6 @@ void Platform_pd::unbind_thread(Platform_thread &thread) thread.unbind(); _free_thread(thread_id); - } @@ -278,7 +271,7 @@ void Platform_pd::_setup_address_space() L4_Word_t Platform_pd::_utcb_location(unsigned int thread_id) { - return _utcb_ptr + thread_id*L4_UtcbSize(get_kip()); + return _utcb_ptr + thread_id*L4_UtcbSize(get_kip()); } @@ -348,7 +341,8 @@ Platform_pd::Platform_pd(Allocator &, char const *, signed pd_id, bool create) Platform_pd::~Platform_pd() { /* unbind all threads */ - while (Platform_thread *t = _next_thread()) unbind_thread(*t); + while (Platform_thread *t = _next_thread()) + unbind_thread(*t); _destroy_pd(); _free_pd(); diff --git a/repos/base-pistachio/src/core/platform_thread.cc b/repos/base-pistachio/src/core/platform_thread.cc index b681adba8a..722d0c0001 100644 --- a/repos/base-pistachio/src/core/platform_thread.cc +++ b/repos/base-pistachio/src/core/platform_thread.cc @@ -17,6 +17,7 @@ /* base-internal includes */ #include +#include /* core includes */ #include @@ -24,21 +25,9 @@ #include #include -/* Pistachio includes */ -namespace Pistachio -{ -#include -#include -#include -#include -}; - using namespace Genode; using namespace Pistachio; -static const bool verbose = false; -static const bool verbose2 = true; - void Platform_thread::affinity(Affinity::Location location) { @@ -140,9 +129,9 @@ void Platform_thread::resume() void Platform_thread::bind(int thread_id, L4_ThreadId_t l4_thread_id, Platform_pd &pd) { - _thread_id = thread_id; - _l4_thread_id = l4_thread_id; - _platform_pd = &pd; + _thread_id = thread_id; + _l4_thread_id = l4_thread_id; + _platform_pd = &pd; } diff --git a/repos/base-pistachio/src/core/ram_dataspace_support.cc b/repos/base-pistachio/src/core/ram_dataspace_support.cc index 18e63f332d..843f3e6ec0 100644 --- a/repos/base-pistachio/src/core/ram_dataspace_support.cc +++ b/repos/base-pistachio/src/core/ram_dataspace_support.cc @@ -18,9 +18,13 @@ using namespace Genode; + void Ram_dataspace_factory::_export_ram_ds(Dataspace_component &) { } + + void Ram_dataspace_factory::_revoke_ram_ds(Dataspace_component &) { } + void Ram_dataspace_factory::_clear_ds(Dataspace_component &ds) { memset((void *)ds.phys_addr(), 0, ds.size()); diff --git a/repos/base-pistachio/src/core/spec/x86/platform_x86.cc b/repos/base-pistachio/src/core/spec/x86/platform_x86.cc index 0e4c35f31d..c7ec258f9d 100644 --- a/repos/base-pistachio/src/core/spec/x86/platform_x86.cc +++ b/repos/base-pistachio/src/core/spec/x86/platform_x86.cc @@ -11,19 +11,17 @@ * under the terms of the GNU Affero General Public License version 3. */ +/* base-internal includes */ +#include + /* core-local includes */ #include - -#include "platform.h" -#include "util.h" - -namespace Pistachio { -#include -#include -} +#include +#include using namespace Genode; + void Platform::_setup_io_port_alloc() { /* setup allocator */ diff --git a/repos/base-pistachio/src/include/base/internal/lock_helper.h b/repos/base-pistachio/src/include/base/internal/lock_helper.h index 220a018e3a..d1fa78ed49 100644 --- a/repos/base-pistachio/src/include/base/internal/lock_helper.h +++ b/repos/base-pistachio/src/include/base/internal/lock_helper.h @@ -20,11 +20,8 @@ /* Genode includes */ #include -/* Pistachio includes */ -namespace Pistachio { -#include -#include -} +/* base-internal includes */ +#include extern Pistachio::L4_ThreadId_t main_thread_tid; diff --git a/repos/base-pistachio/src/include/base/internal/native_thread.h b/repos/base-pistachio/src/include/base/internal/native_thread.h index f48571083b..7ad8f52aa5 100644 --- a/repos/base-pistachio/src/include/base/internal/native_thread.h +++ b/repos/base-pistachio/src/include/base/internal/native_thread.h @@ -17,10 +17,8 @@ /* Genode includes */ #include -/* Pistachio includes */ -namespace Pistachio { -#include -} +/* base-internal includes */ +#include namespace Genode { diff --git a/repos/base-pistachio/src/include/base/internal/pistachio.h b/repos/base-pistachio/src/include/base/internal/pistachio.h new file mode 100644 index 0000000000..2b528cb90c --- /dev/null +++ b/repos/base-pistachio/src/include/base/internal/pistachio.h @@ -0,0 +1,32 @@ +/* + * \brief L4ka::Pistachio system-call bindings + * \author Norman Feske + * \date 2021-02-07 + */ + +/* + * Copyright (C) 2021 Genode Labs GmbH + * + * This file is part of the Genode OS framework, which is distributed + * under the terms of the GNU Affero General Public License version 3. + */ + +#ifndef _BASE__INTERNAL__PISTACHIO_H_ +#define _BASE__INTERNAL__PISTACHIO_H_ + +namespace Pistachio { +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +} + +#endif /* _BASE__INTERNAL__PISTACHIO_H_ */ diff --git a/repos/base-pistachio/src/include/base/internal/raw_write_string.h b/repos/base-pistachio/src/include/base/internal/raw_write_string.h index f18d5276e1..0f56a30398 100644 --- a/repos/base-pistachio/src/include/base/internal/raw_write_string.h +++ b/repos/base-pistachio/src/include/base/internal/raw_write_string.h @@ -14,9 +14,7 @@ #ifndef _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_ #define _INCLUDE__BASE__INTERNAL__RAW_WRITE_STRING_H_ -namespace Pistachio { -#include -} +#include namespace Genode { diff --git a/repos/base-pistachio/src/include/base/internal/rpc_destination.h b/repos/base-pistachio/src/include/base/internal/rpc_destination.h index 75eb3392e8..2e0f643bc0 100644 --- a/repos/base-pistachio/src/include/base/internal/rpc_destination.h +++ b/repos/base-pistachio/src/include/base/internal/rpc_destination.h @@ -14,10 +14,7 @@ #ifndef _INCLUDE__BASE__INTERNAL__RPC_DESTINATION_H_ #define _INCLUDE__BASE__INTERNAL__RPC_DESTINATION_H_ -/* Pistachio includes */ -namespace Pistachio { -#include -} +#include namespace Genode { diff --git a/repos/base-pistachio/src/lib/base/ipc.cc b/repos/base-pistachio/src/lib/base/ipc.cc index e8c58d093d..ac04cbea76 100644 --- a/repos/base-pistachio/src/lib/base/ipc.cc +++ b/repos/base-pistachio/src/lib/base/ipc.cc @@ -21,12 +21,7 @@ /* base-internal includes */ #include #include - -/* Pistachio includes */ -namespace Pistachio { -#include -#include -} +#include using namespace Genode; using namespace Pistachio; diff --git a/repos/base-pistachio/src/lib/base/thread_bootstrap.cc b/repos/base-pistachio/src/lib/base/thread_bootstrap.cc index 91bfc66133..9347dc99c4 100644 --- a/repos/base-pistachio/src/lib/base/thread_bootstrap.cc +++ b/repos/base-pistachio/src/lib/base/thread_bootstrap.cc @@ -18,11 +18,7 @@ /* base-internal includes */ #include #include - -/* Pistachio includes */ -namespace Pistachio { - #include -} +#include Pistachio::L4_ThreadId_t main_thread_tid; @@ -51,7 +47,10 @@ void Genode::Thread::_thread_bootstrap() void Genode::Thread::_init_platform_thread(size_t, Type type) { - if (type == NORMAL) { return; } - native_thread().l4id = main_thread_tid; + if (type == NORMAL) + return; + + native_thread().l4id = main_thread_tid; + _thread_cap = main_thread_cap(); }