source: rtems/cpukit/score/cpu/aarch64/include/rtems/score/cpuimpl.h @ 03e4d1e9

Last change on this file since 03e4d1e9 was 03e4d1e9, checked in by Sebastian Huber <sebastian.huber@…>, on 06/29/22 at 12:37:47

score: Add _CPU_Use_thread_local_storage()

At some point during system initialization, the idle threads are created.
Afterwards, the boot processor basically executes within the context of an idle
thread with thread dispatching disabled. On some architectures, the
thread-local storage area of the associated thread must be set in dedicated
processor registers. Add the new CPU port function to do this:

void _CPU_Use_thread_local_storage( const Context_Control *context )

Close #4672.

  • Property mode set to 100644
File size: 4.1 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSScoreCPU
7 *
8 * @brief CPU Port Implementation API
9 */
10
11/*
12 * Copyright (C) 2020 On-Line Applications Research Corporation (OAR)
13 * Written by Kinsey Moore <kinsey.moore@oarcorp.com>
14 *
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 *    notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 *    notice, this list of conditions and the following disclaimer in the
22 *    documentation and/or other materials provided with the distribution.
23 *
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
28 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
31 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
32 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
33 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
34 * POSSIBILITY OF SUCH DAMAGE.
35 */
36
37#ifndef _RTEMS_SCORE_CPUIMPL_H
38#define _RTEMS_SCORE_CPUIMPL_H
39
40#include <rtems/score/cpu.h>
41
42/**
43 * @defgroup RTEMSScoreCPUAArch64 AArch64
44 *
45 * @ingroup RTEMSScoreCPU
46 *
47 * @brief ARM AArch64 Architecture Support
48 *
49 * @{
50 */
51
52#define CPU_PER_CPU_CONTROL_SIZE 0
53#define CPU_INTERRUPT_FRAME_SIZE 0x2E0
54
55#ifndef ASM
56
57#ifdef __cplusplus
58extern "C" {
59#endif
60
61RTEMS_NO_RETURN void _CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr error );
62
63typedef struct {
64  uint64_t x0;
65  uint64_t register_lr_original;
66  uint64_t register_lr;
67  uint64_t x1;
68  uint64_t x2;
69  uint64_t x3;
70  uint64_t x4;
71  uint64_t x5;
72  uint64_t x6;
73  uint64_t x7;
74  uint64_t x8;
75  uint64_t x9;
76  uint64_t x10;
77  uint64_t x11;
78  uint64_t x12;
79  uint64_t x13;
80  uint64_t x14;
81  uint64_t x15;
82  uint64_t x16;
83  uint64_t x17;
84  uint64_t x18;
85  uint64_t x19;
86  uint64_t x20;
87  uint64_t x21;
88#ifdef AARCH64_MULTILIB_VFP
89  uint128_t q0;
90  uint128_t q1;
91  uint128_t q2;
92  uint128_t q3;
93  uint128_t q4;
94  uint128_t q5;
95  uint128_t q6;
96  uint128_t q7;
97  uint128_t q8;
98  uint128_t q9;
99  uint128_t q10;
100  uint128_t q11;
101  uint128_t q12;
102  uint128_t q13;
103  uint128_t q14;
104  uint128_t q15;
105  uint128_t q16;
106  uint128_t q17;
107  uint128_t q18;
108  uint128_t q19;
109  uint128_t q20;
110  uint128_t q21;
111  uint128_t q22;
112  uint128_t q23;
113  uint128_t q24;
114  uint128_t q25;
115  uint128_t q26;
116  uint128_t q27;
117  uint128_t q28;
118  uint128_t q29;
119  uint128_t q30;
120  uint128_t q31;
121#endif /* AARCH64_MULTILIB_VFP */
122  uint64_t register_elr;
123  uint64_t register_spsr;
124  uint64_t register_fpsr;
125  uint64_t register_fpcr;
126} CPU_Interrupt_frame;
127
128#ifdef RTEMS_SMP
129
130static inline
131struct Per_CPU_Control *_AARCH64_Get_current_per_CPU_control( void )
132{
133  struct Per_CPU_Control *cpu_self;
134  uint64_t value;
135
136  __asm__ volatile (
137    "mrs %0, TPIDR_EL1" : "=&r" ( value ) : : "memory"
138  );
139
140  /* Use EL1 Thread ID Register (TPIDR_EL1) */
141  cpu_self = (struct Per_CPU_Control *)(uintptr_t)value;
142
143  return cpu_self;
144}
145
146#define _CPU_Get_current_per_CPU_control() \
147  _AARCH64_Get_current_per_CPU_control()
148
149#endif /* RTEMS_SMP */
150
151void _CPU_Context_volatile_clobber( uintptr_t pattern );
152
153void _CPU_Context_validate( uintptr_t pattern );
154
155RTEMS_INLINE_ROUTINE void _CPU_Instruction_illegal( void )
156{
157  __asm__ volatile ( ".inst 0x0" );
158}
159
160RTEMS_INLINE_ROUTINE void _CPU_Instruction_no_operation( void )
161{
162  __asm__ volatile ( "nop" );
163}
164
165RTEMS_INLINE_ROUTINE void _CPU_Use_thread_local_storage(
166  const Context_Control *context
167)
168{
169  __asm__ volatile (
170    "msr TPIDR_EL0, %0" : : "r" ( context->thread_id ) : "memory"
171  );
172}
173
174#ifdef __cplusplus
175}
176#endif
177
178#endif /* ASM */
179
180/** @} */
181
182#endif /* _RTEMS_SCORE_CPUIMPL_H */
Note: See TracBrowser for help on using the repository browser.