riscv: add support for thread local storage
Adds the necessary bits to initialize TLS in the stack area and sets up CPU registers during context switch. Signed-off-by: Daniel Leung <daniel.leung@intel.com>
This commit is contained in:
parent
388725870f
commit
8a79ce1428
6 changed files with 44 additions and 0 deletions
|
@ -65,6 +65,7 @@ config RISCV
|
||||||
bool
|
bool
|
||||||
select ARCH_IS_SET
|
select ARCH_IS_SET
|
||||||
select HAS_DTS
|
select HAS_DTS
|
||||||
|
select ARCH_HAS_THREAD_LOCAL_STORAGE
|
||||||
imply XIP
|
imply XIP
|
||||||
help
|
help
|
||||||
RISCV architecture
|
RISCV architecture
|
||||||
|
|
|
@ -14,3 +14,4 @@ zephyr_library_sources(
|
||||||
)
|
)
|
||||||
|
|
||||||
zephyr_library_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c)
|
zephyr_library_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c)
|
||||||
|
zephyr_library_sources_ifdef(CONFIG_THREAD_LOCAL_STORAGE tls.c)
|
||||||
|
|
|
@ -30,6 +30,11 @@ void arch_new_thread(struct k_thread *thread, k_thread_stack_t *stack,
|
||||||
stack_init->a1 = (ulong_t)p1;
|
stack_init->a1 = (ulong_t)p1;
|
||||||
stack_init->a2 = (ulong_t)p2;
|
stack_init->a2 = (ulong_t)p2;
|
||||||
stack_init->a3 = (ulong_t)p3;
|
stack_init->a3 = (ulong_t)p3;
|
||||||
|
|
||||||
|
#ifdef CONFIG_THREAD_LOCAL_STORAGE
|
||||||
|
stack_init->tp = (ulong_t)thread->tls;
|
||||||
|
#endif
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Following the RISC-V architecture,
|
* Following the RISC-V architecture,
|
||||||
* the MSTATUS register (used to globally enable/disable interrupt),
|
* the MSTATUS register (used to globally enable/disable interrupt),
|
||||||
|
|
35
arch/riscv/core/tls.c
Normal file
35
arch/riscv/core/tls.c
Normal file
|
@ -0,0 +1,35 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2020 Intel Corporation
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <kernel.h>
|
||||||
|
#include <kernel_structs.h>
|
||||||
|
#include <kernel_internal.h>
|
||||||
|
#include <kernel_tls.h>
|
||||||
|
#include <app_memory/app_memdomain.h>
|
||||||
|
#include <sys/util.h>
|
||||||
|
|
||||||
|
size_t arch_tls_stack_setup(struct k_thread *new_thread, char *stack_ptr)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
* TLS area for RISC-V is simple without any extra
|
||||||
|
* data.
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Since we are populating things backwards,
|
||||||
|
* setup the TLS data/bss area first.
|
||||||
|
*/
|
||||||
|
stack_ptr -= z_tls_data_size();
|
||||||
|
z_tls_copy(stack_ptr);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Set thread TLS pointer which is used in
|
||||||
|
* context switch to point to TLS area.
|
||||||
|
*/
|
||||||
|
new_thread->tls = POINTER_TO_UINT(stack_ptr);
|
||||||
|
|
||||||
|
return z_tls_data_size();
|
||||||
|
}
|
|
@ -111,6 +111,7 @@ SECTIONS
|
||||||
_image_text_end = .;
|
_image_text_end = .;
|
||||||
|
|
||||||
#include <linker/common-rom.ld>
|
#include <linker/common-rom.ld>
|
||||||
|
#include <linker/thread-local-storage.ld>
|
||||||
|
|
||||||
SECTION_PROLOGUE(_RODATA_SECTION_NAME,,)
|
SECTION_PROLOGUE(_RODATA_SECTION_NAME,,)
|
||||||
{
|
{
|
||||||
|
|
|
@ -122,6 +122,7 @@ SECTIONS
|
||||||
_image_rodata_start = .;
|
_image_rodata_start = .;
|
||||||
|
|
||||||
#include <linker/common-rom.ld>
|
#include <linker/common-rom.ld>
|
||||||
|
#include <linker/thread-local-storage.ld>
|
||||||
|
|
||||||
SECTION_PROLOGUE(_RODATA_SECTION_NAME,,)
|
SECTION_PROLOGUE(_RODATA_SECTION_NAME,,)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue