base-hw: Core main-thread as Main member

Let the Core main-thread object be a member of the one Kernel::Main object
instead of having it as global static variable.

Ref #4217
This commit is contained in:
Martin Stein 2021-07-12 16:10:08 +02:00 committed by Norman Feske
parent 2b89cd66cb
commit b247def09a
7 changed files with 21 additions and 22 deletions

View File

@ -12,6 +12,9 @@
* under the terms of the GNU Affero General Public License version 3.
*/
/* base includes */
#include <util/reconstructible.h>
/* base-hw Core includes */
#include <kernel/cpu.h>
#include <kernel/lock.h>
@ -37,8 +40,9 @@ class Kernel::Main
static Main *_instance;
Lock _data_lock { };
Cpu_pool _cpu_pool { };
Lock _data_lock { };
Cpu_pool _cpu_pool { };
Genode::Constructible<Core_main_thread> _core_main_thread { };
void _handle_kernel_entry();
};
@ -122,7 +126,12 @@ void Kernel::main_initialize_and_handle_kernel_entry()
Genode::log("");
Genode::log("kernel initialized");
Core_main_thread::initialize_instance(Main::_instance->_cpu_pool);
Main::_instance->_core_main_thread.construct(
Main::_instance->_cpu_pool);
boot_info.core_main_thread_utcb =
(addr_t)Main::_instance->_core_main_thread->utcb();
kernel_ready = true;
} else {
/* secondary cpus spin until the kernel is initialized */

View File

@ -898,13 +898,3 @@ Core_main_thread::Core_main_thread(Cpu_pool &cpu_pool)
Thread::_pd = &core_pd();
_become_active();
}
Core_main_thread *Core_main_thread::_instance;
void Core_main_thread::initialize_instance(Cpu_pool &cpu_pool)
{
static Core_main_thread instance { cpu_pool };
_instance = &instance;
}

View File

@ -438,17 +438,9 @@ class Kernel::Thread : private Kernel::Object, public Cpu_job, private Timeout
*/
class Kernel::Core_main_thread : public Core_object<Kernel::Thread>
{
private:
static Core_main_thread *_instance;
public:
Core_main_thread(Cpu_pool &cpu_pool);
static void initialize_instance(Cpu_pool &cpu_pool);
static Thread &instance() { return *_instance; };
};
#endif /* _CORE__KERNEL__THREAD_H_ */

View File

@ -63,6 +63,11 @@ Hw::Page_table::Allocator & Platform::core_page_table_allocator()
}
addr_t Platform::core_main_thread_phys_utcb()
{
return core_phys_addr(_boot_info().core_main_thread_utcb);
}
void Platform::_init_io_mem_alloc()
{
/* add entire adress space minus the RAM memory regions */

View File

@ -143,6 +143,8 @@ class Genode::Platform : public Genode::Platform_generic
* by core's local capability space.
*/
size_t max_caps() const override { return Kernel::Pd::max_cap_ids; }
static addr_t core_main_thread_phys_utcb();
};
#endif /* _CORE__PLATFORM_H_ */

View File

@ -93,7 +93,7 @@ void Thread::_init_platform_thread(size_t, Type type)
}
/* remap initial main-thread UTCB according to stack-area spec */
Genode::map_local(Platform::core_phys_addr((addr_t)Kernel::Core_main_thread::instance().utcb()),
Genode::map_local(Platform::core_main_thread_phys_utcb(),
(addr_t)&_stack->utcb(),
max(sizeof(Native_utcb) / get_page_size(), (size_t)1));

View File

@ -27,6 +27,7 @@ struct Hw::Boot_info
addr_t const table;
addr_t const table_allocator;
addr_t core_main_thread_utcb { 0 };
Mapping_pool const elf_mappings;
Kernel_irqs kernel_irqs { };
Mapping const boot_modules;