source: rtems/cpukit/score/cpu/arm/cpu.c @ 5262b9c

Last change on this file since 5262b9c was 5262b9c, checked in by Chris Johns <chrisj@…>, on 06/14/22 at 00:56:34

score/cpu: Silence ARM and AARCH64 GCC 12 false trigger array warning

The false trigger is covered in:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=99578

GCC 11 and 12 has been patched for constant pointer casts above
4K. This code casts a constant pointer within the first 4K
page. As a result the patch disables the warning.

Updates #4662

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