source: rtems/testsuites/validation/tc-score-isr.c @ a9862623

Last change on this file since a9862623 was a9862623, checked in by Sebastian Huber <sebastian.huber@…>, on 09/21/23 at 12:54:01

validation: Check stack of interrupted context

Check the stack of the interrupted context during the multitasking
start.

Update #4955.

  • Property mode set to 100644
File size: 6.6 KB
Line 
1/* SPDX-License-Identifier: BSD-2-Clause */
2
3/**
4 * @file
5 *
6 * @ingroup ScoreIsrValIsr
7 */
8
9/*
10 * Copyright (C) 2023 embedded brains GmbH & Co. KG
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 *    notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 *    notice, this list of conditions and the following disclaimer in the
19 *    documentation and/or other materials provided with the distribution.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 * POSSIBILITY OF SUCH DAMAGE.
32 */
33
34/*
35 * This file is part of the RTEMS quality process and was automatically
36 * generated.  If you find something that needs to be fixed or
37 * worded better please post a report or patch to an RTEMS mailing list
38 * or raise a bug report:
39 *
40 * https://www.rtems.org/bugs.html
41 *
42 * For information on updating and regenerating please refer to the How-To
43 * section in the Software Requirements Engineering chapter of the
44 * RTEMS Software Engineering manual.  The manual is provided as a part of
45 * a release.  For development sources please refer to the online
46 * documentation at:
47 *
48 * https://docs.rtems.org
49 */
50
51#ifdef HAVE_CONFIG_H
52#include "config.h"
53#endif
54
55#include <rtems.h>
56#include <rtems/sysinit.h>
57#include <rtems/score/percpu.h>
58#include <rtems/score/thread.h>
59
60#include "tx-support.h"
61
62#include <rtems/test.h>
63
64/**
65 * @defgroup ScoreIsrValIsr spec:/score/isr/val/isr
66 *
67 * @ingroup TestsuitesValidationIntr
68 *
69 * @brief Tests general interrupt support behaviour.
70 *
71 * This test case performs the following actions:
72 *
73 * - Submit an ISR request during system initialization.  Check the stack of
74 *   the interrupted context while the ISR request is serviced.  Store the
75 *   result of the check in interrupted_stack_at_multitasking_start_is_valid.
76 *
77 *   - Check that stack of the interrupted context was valid when an interrupt
78 *     was serviced during the multitasking start.
79 *
80 * @{
81 */
82
83static uintptr_t interrupted_stack_at_multitasking_start;
84
85static bool interrupted_stack_at_multitasking_start_is_valid;
86
87#if defined(__aarch64__)
88void __real_bsp_interrupt_dispatch( void );
89
90void __wrap_bsp_interrupt_dispatch( void );
91
92void __wrap_bsp_interrupt_dispatch( void )
93{
94  if ( interrupted_stack_at_multitasking_start == 0 ) {
95    uintptr_t             sp;
96    rtems_interrupt_level level;
97
98    rtems_interrupt_local_disable( level );
99    __asm__ volatile (
100      "msr spsel, #1\n"
101      "mov %0, sp\n"
102      "msr spsel, #0"
103      : "=r" ( sp )
104    );
105    rtems_interrupt_local_enable( level );
106
107    interrupted_stack_at_multitasking_start = sp;
108  }
109
110  __real_bsp_interrupt_dispatch();
111}
112#endif
113
114#if defined(ARM_MULTILIB_ARCH_V4)
115void __real_bsp_interrupt_dispatch( void );
116
117void __wrap_bsp_interrupt_dispatch( void );
118
119void __wrap_bsp_interrupt_dispatch( void )
120{
121  register uintptr_t sp __asm__( "9" );
122
123  if ( interrupted_stack_at_multitasking_start == 0 ) {
124    interrupted_stack_at_multitasking_start = sp;
125  }
126
127  __real_bsp_interrupt_dispatch();
128}
129#endif
130
131#if defined(__riscv)
132void __real__RISCV_Interrupt_dispatch(
133  uintptr_t        mcause,
134  Per_CPU_Control *cpu_self
135);
136
137void __wrap__RISCV_Interrupt_dispatch(
138  uintptr_t        mcause,
139  Per_CPU_Control *cpu_self
140);
141
142void __wrap__RISCV_Interrupt_dispatch(
143  uintptr_t        mcause,
144  Per_CPU_Control *cpu_self
145)
146{
147  register uintptr_t sp __asm__( "s1" );
148
149  if ( interrupted_stack_at_multitasking_start == 0 ) {
150    interrupted_stack_at_multitasking_start = sp;
151  }
152
153  __real__RISCV_Interrupt_dispatch( mcause, cpu_self );
154}
155#endif
156
157#if defined(__sparc__)
158void __real__SPARC_Interrupt_dispatch( uint32_t irq );
159
160static RTEMS_USED void InterruptDispatch( uint32_t irq, uintptr_t sp )
161{
162  if ( interrupted_stack_at_multitasking_start == 0 ) {
163    interrupted_stack_at_multitasking_start = sp;
164  }
165
166  __real__SPARC_Interrupt_dispatch( irq );
167}
168
169__asm__ (
170  "\t.section\t\".text\"\n"
171  "\t.align\t4\n"
172  "\t.globl\t__wrap__SPARC_Interrupt_dispatch\n"
173  "\t.type\t__wrap__SPARC_Interrupt_dispatch, #function\n"
174  "__wrap__SPARC_Interrupt_dispatch:\n"
175  "\tmov\t%fp, %o1\n"
176  "\tor\t%o7, %g0, %g1\n"
177  "\tcall\tInterruptDispatch, 0\n"
178  "\t or\t%g1, %g0, %o7\n"
179  "\t.previous\n"
180);
181#endif
182
183static void ISRHandler( void *arg )
184{
185  uintptr_t begin;
186  uintptr_t end;
187
188  (void) arg;
189
190#if defined(RTEMS_SMP)
191  Per_CPU_Control *cpu_self;
192
193  cpu_self = _Per_CPU_Get();
194  begin = (uintptr_t) &cpu_self->Interrupt_frame;
195  end = begin + sizeof( cpu_self->Interrupt_frame );
196#else
197  Thread_Control *executing;
198
199  executing = GetExecuting();
200  begin = (uintptr_t) executing->Start.Initial_stack.area;
201  end = begin + executing->Start.Initial_stack.size;
202#endif
203
204  interrupted_stack_at_multitasking_start_is_valid =
205    ( begin <= interrupted_stack_at_multitasking_start &&
206      interrupted_stack_at_multitasking_start < end );
207}
208
209static CallWithinISRRequest isr_request = {
210  .handler = ISRHandler
211};
212
213static void SubmitISRRequest( void )
214{
215  CallWithinISRSubmit( &isr_request );
216}
217
218RTEMS_SYSINIT_ITEM(
219  SubmitISRRequest,
220  RTEMS_SYSINIT_DEVICE_DRIVERS,
221  RTEMS_SYSINIT_ORDER_LAST
222);
223
224/**
225 * @brief Submit an ISR request during system initialization.  Check the stack
226 *   of the interrupted context while the ISR request is serviced.  Store the
227 *   result of the check in interrupted_stack_at_multitasking_start_is_valid.
228 */
229static void ScoreIsrValIsr_Action_0( void )
230{
231  /*
232   * The actions are performed during system initialization and the
233   * multitasking start.
234   */
235
236  /*
237   * Check that stack of the interrupted context was valid when an interrupt
238   * was serviced during the multitasking start.
239   */
240  T_true( interrupted_stack_at_multitasking_start_is_valid );
241}
242
243/**
244 * @fn void T_case_body_ScoreIsrValIsr( void )
245 */
246T_TEST_CASE( ScoreIsrValIsr )
247{
248  ScoreIsrValIsr_Action_0();
249}
250
251/** @} */
Note: See TracBrowser for help on using the repository browser.