source: rtems/testsuites/sptests/spfatal30/init.c @ 146adb1

5
Last change on this file since 146adb1 was 146adb1, checked in by Sebastian Huber <sebastian.huber@…>, on 07/17/17 at 05:30:46

sparc: Add lazy floating point switch

The SPARC ABI is a bit special with respect to the floating point context.
The complete floating point context is volatile. Thus, from an ABI point
of view nothing needs to be saved and restored during a context switch.
Instead the floating point context must be saved and restored during
interrupt processing. Historically, the deferred floating point switch was
used for SPARC and the complete floating point context is saved and
restored during a context switch to the new floating point unit owner.
This is a bit dangerous since post-switch actions (e.g. signal handlers)
and context switch extensions may silently corrupt the floating point
context.

The floating point unit is disabled for interrupt handlers. Thus, in case
an interrupt handler uses the floating point unit then this will result in a
trap (INTERNAL_ERROR_ILLEGAL_USE_OF_FLOATING_POINT_UNIT).

In uniprocessor configurations, a lazy floating point context switch is
used. In case an active floating point thread is interrupted (PSR[EF] == 1)
and a thread dispatch is carried out, then this thread is registered as the
floating point owner. When a floating point owner is present during a
context switch, the floating point unit is disabled for the heir thread
(PSR[EF] == 0). The floating point disabled trap checks that the use of the
floating point unit is allowed and saves/restores the floating point context
on demand.

Update #3077.

  • Property mode set to 100644
File size: 1.6 KB
Line 
1/*
2 * Copyright (c) 2017 embedded brains GmbH.  All rights reserved.
3 *
4 *  embedded brains GmbH
5 *  Dornierstr. 4
6 *  82178 Puchheim
7 *  Germany
8 *  <rtems@embedded-brains.de>
9 *
10 * The license and distribution terms for this file may be
11 * found in the file LICENSE in this distribution or at
12 * http://www.rtems.org/license/LICENSE.
13 */
14
15#ifdef HAVE_CONFIG_H
16#include "config.h"
17#endif
18
19#define TESTS_USE_PRINTK
20#include "tmacros.h"
21
22#include <rtems.h>
23
24const char rtems_test_name[] = "SPFATAL 30";
25
26#if (CPU_HARDWARE_FP == TRUE && CPU_ALL_TASKS_ARE_FP == FALSE) \
27  || SPARC_HAS_FPU == 1
28#define EXPECT_ILLEGAL_USE_OF_FLOATING_POINT_UNIT
29#endif
30
31static volatile double f = 1.0;
32
33static void Init(rtems_task_argument arg)
34{
35  TEST_BEGIN();
36
37  f *= 123.456;
38
39#ifdef EXPECT_ILLEGAL_USE_OF_FLOATING_POINT_UNIT
40  rtems_test_assert(0);
41#else
42  TEST_END();
43  rtems_test_exit(0);
44#endif
45}
46
47#ifdef EXPECT_ILLEGAL_USE_OF_FLOATING_POINT_UNIT
48static void fatal_extension(
49  rtems_fatal_source source,
50  bool always_set_to_false,
51  rtems_fatal_code code
52)
53{
54  if (
55    source == INTERNAL_ERROR_CORE
56      && !always_set_to_false
57      && code == INTERNAL_ERROR_ILLEGAL_USE_OF_FLOATING_POINT_UNIT
58  ) {
59    TEST_END();
60  }
61}
62
63#define CONFIGURE_INITIAL_EXTENSIONS \
64  { .fatal = fatal_extension }, \
65  RTEMS_TEST_INITIAL_EXTENSION
66
67#else /* EXPECT_ILLEGAL_USE_OF_FLOATING_POINT_UNIT */
68
69#define CONFIGURE_INITIAL_EXTENSIONS RTEMS_TEST_INITIAL_EXTENSION
70
71#endif /* EXPECT_ILLEGAL_USE_OF_FLOATING_POINT_UNIT */
72
73#define CONFIGURE_APPLICATION_DOES_NOT_NEED_CLOCK_DRIVER
74
75#define CONFIGURE_MAXIMUM_TASKS 1
76
77#define CONFIGURE_RTEMS_INIT_TASKS_TABLE
78
79#define CONFIGURE_INIT
80
81#include <rtems/confdefs.h>
Note: See TracBrowser for help on using the repository browser.