sparc: 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. Register g7 is
used to point to the thread data. Thread data is accessed with negative
offsets from g7.

Signed-off-by: Martin Åberg <martin.aberg@gaisler.com>
This commit is contained in:
Martin Åberg 2020-10-27 12:31:41 +01:00 committed by Andrew Boie
commit feae3249b2
5 changed files with 28 additions and 0 deletions

View file

@ -45,6 +45,7 @@ config SPARC
select BIG_ENDIAN
select ATOMIC_OPERATIONS_BUILTIN if SPARC_CASA
select ATOMIC_OPERATIONS_C if !SPARC_CASA
select ARCH_HAS_THREAD_LOCAL_STORAGE
help
SPARC architecture

View file

@ -17,3 +17,4 @@ zephyr_library_sources(
)
zephyr_library_sources_ifdef(CONFIG_IRQ_OFFLOAD irq_offload.c)
zephyr_library_sources_ifdef(CONFIG_THREAD_LOCAL_STORAGE tls.c)

View file

@ -118,6 +118,9 @@ SECTION_FUNC(TEXT, z_sparc_context_switch)
/* restore output registers */
ldd [%o0 + _thread_offset_to_o6], %o6
#ifdef CONFIG_THREAD_LOCAL_STORAGE
ld [%o0 + _thread_offset_to_tls], %g7
#endif
ld [%o0 + _thread_offset_to_psr], %g1 /* %g1 = new thread psr */

22
arch/sparc/core/tls.c Normal file
View file

@ -0,0 +1,22 @@
/*
* Copyright (c) 2019-2020 Cobham Gaisler AB
*
* 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)
{
new_thread->tls = POINTER_TO_UINT(stack_ptr);
stack_ptr -= z_tls_data_size();
z_tls_copy(stack_ptr);
return z_tls_data_size();
}

View file

@ -42,6 +42,7 @@ SECTIONS
_image_text_end = .;
#include <linker/common-rom.ld>
#include <linker/thread-local-storage.ld>
SECTION_PROLOGUE(_RODATA_SECTION_NAME,,)
{