source: rtems/cpukit/score/cpu/arm/cpu.c

Last change on this file was bc910e1, checked in by Sebastian Huber <sebastian.huber@…>, on 03/18/24 at 10:40:18

arm: Move _CPU_ISR_install_vector()

The use of this function is optional. Newer BSPs do not use it.

  • Property mode set to 100644
File size: 5.0 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup RTEMSScoreCPUARM
7 *
8 * @brief This source file contains static assertions to ensure the consistency
9 *   of interfaces used in C and assembler and it contains the ARM-specific
10 *   implementation of _CPU_Initialize(), _CPU_ISR_Get_level(),
11 *   _CPU_ISR_Set_level(), _CPU_Context_Initialize(), and _CPU_Fatal_halt().
12 */
13
14/*
15 *  COPYRIGHT (c) 2000 Canon Research Centre France SA.
16 *  Emmanuel Raguet, mailto:raguet@crf.canon.fr
17 *
18 *  Copyright (c) 2002 Advent Networks, Inc
19 *      Jay Monkman <jmonkman@adventnetworks.com>
20 *
21 *  Copyright (c) 2007 Ray xu <rayx.cn@gmail.com>
22 *
23 *  Copyright (C) 2009, 2017 embedded brains GmbH & Co. KG
24 *
25 * Redistribution and use in source and binary forms, with or without
26 * modification, are permitted provided that the following conditions
27 * are met:
28 * 1. Redistributions of source code must retain the above copyright
29 *    notice, this list of conditions and the following disclaimer.
30 * 2. Redistributions in binary form must reproduce the above copyright
31 *    notice, this list of conditions and the following disclaimer in the
32 *    documentation and/or other materials provided with the distribution.
33 *
34 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
35 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
36 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
37 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
38 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
39 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
40 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
41 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
42 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
43 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
44 * POSSIBILITY OF SUCH DAMAGE.
45 */
46
47#ifdef HAVE_CONFIG_H
48#include "config.h"
49#endif
50
51#include <rtems/score/cpuimpl.h>
52#include <rtems/score/thread.h>
53#include <rtems/score/tls.h>
54
55#ifdef ARM_MULTILIB_VFP
56  RTEMS_STATIC_ASSERT(
57    offsetof( Context_Control, register_d8 ) == ARM_CONTEXT_CONTROL_D8_OFFSET,
58    ARM_CONTEXT_CONTROL_D8_OFFSET
59  );
60#endif
61
62RTEMS_STATIC_ASSERT(
63  offsetof( Context_Control, thread_id )
64    == ARM_CONTEXT_CONTROL_THREAD_ID_OFFSET,
65  ARM_CONTEXT_CONTROL_THREAD_ID_OFFSET
66);
67
68#ifdef ARM_MULTILIB_ARCH_V4
69  RTEMS_STATIC_ASSERT(
70    offsetof( Context_Control, isr_dispatch_disable )
71      == ARM_CONTEXT_CONTROL_ISR_DISPATCH_DISABLE,
72    ARM_CONTEXT_CONTROL_ISR_DISPATCH_DISABLE
73  );
74#endif
75
76#ifdef RTEMS_SMP
77  RTEMS_STATIC_ASSERT(
78    offsetof( Context_Control, is_executing )
79      == ARM_CONTEXT_CONTROL_IS_EXECUTING_OFFSET,
80    ARM_CONTEXT_CONTROL_IS_EXECUTING_OFFSET
81  );
82#endif
83
84RTEMS_STATIC_ASSERT(
85  sizeof( CPU_Exception_frame ) == ARM_EXCEPTION_FRAME_SIZE,
86  ARM_EXCEPTION_FRAME_SIZE
87);
88
89RTEMS_STATIC_ASSERT(
90  sizeof( CPU_Exception_frame ) % CPU_STACK_ALIGNMENT == 0,
91  CPU_Exception_frame_alignment
92);
93
94RTEMS_STATIC_ASSERT(
95  offsetof( CPU_Exception_frame, register_sp )
96    == ARM_EXCEPTION_FRAME_REGISTER_SP_OFFSET,
97  ARM_EXCEPTION_FRAME_REGISTER_SP_OFFSET
98);
99
100RTEMS_STATIC_ASSERT(
101  sizeof( ARM_VFP_context ) == ARM_VFP_CONTEXT_SIZE,
102  ARM_VFP_CONTEXT_SIZE
103);
104
105#ifdef ARM_MULTILIB_ARCH_V4
106
107void _CPU_Context_Initialize(
108  Context_Control *the_context,
109  void *stack_area_begin,
110  size_t stack_area_size,
111  uint32_t new_level,
112  void (*entry_point)( void ),
113  bool is_fp,
114  void *tls_area
115)
116{
117  (void) new_level;
118
119  the_context->register_sp = (uint32_t) stack_area_begin + stack_area_size;
120  the_context->register_lr = (uint32_t) entry_point;
121  the_context->isr_dispatch_disable = 0;
122  the_context->thread_id = (uint32_t) tls_area;
123
124  if ( tls_area != NULL ) {
125    the_context->thread_id = (uint32_t) _TLS_Initialize_area( tls_area );
126  }
127}
128
129void _CPU_ISR_Set_level( uint32_t level )
130{
131  uint32_t arm_switch_reg;
132
133  /* Ignore the level parameter and just enable interrupts */
134  (void) level;
135
136  __asm__ volatile (
137    ARM_SWITCH_TO_ARM
138    "mrs %[arm_switch_reg], cpsr\n"
139    "bic %[arm_switch_reg], #" RTEMS_XSTRING( ARM_PSR_I ) "\n"
140    "msr cpsr, %0\n"
141    ARM_SWITCH_BACK
142    : [arm_switch_reg] "=&r" (arm_switch_reg)
143  );
144}
145
146uint32_t _CPU_ISR_Get_level( void )
147{
148  ARM_SWITCH_REGISTERS;
149  uint32_t level;
150
151  __asm__ volatile (
152    ARM_SWITCH_TO_ARM
153    "mrs %[level], cpsr\n"
154    "and %[level], #" RTEMS_XSTRING( ARM_PSR_I ) "\n"
155    ARM_SWITCH_BACK
156    : [level] "=&r" (level) ARM_SWITCH_ADDITIONAL_OUTPUT
157  );
158
159  return ( level & ARM_PSR_I ) != 0;
160}
161
162void _CPU_Initialize( void )
163{
164  /* Do nothing */
165}
166
167#endif /* ARM_MULTILIB_ARCH_V4 */
168
169void _CPU_Fatal_halt( uint32_t source, CPU_Uint32ptr error )
170{
171  ISR_Level level;
172
173  _CPU_ISR_Disable( level );
174  (void) level;
175
176  __asm__ volatile ("mov r0, %0\n"
177                : "=r" (error)
178                : "0" (error)
179                : "r0" );
180
181  while ( true ) {
182    /* Do nothing */
183  }
184}
Note: See TracBrowser for help on using the repository browser.