OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [rtems/] [c/] [src/] [tests/] [sptests/] [spfatal/] [fatal.c] - Blame information for rev 721

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 30 unneback
/*  Fatal Error Test
2
 *
3
 *  NOTE:
4
 *
5
 *  This test actually modifies the Configuration table and restarts
6
 *  the executive.  It is very carefully constructed to do this and
7
 *  uses the Configuration very carefully.
8
 *
9
 *  COPYRIGHT (c) 1989-1999.
10
 *  On-Line Applications Research Corporation (OAR).
11
 *
12
 *  The license and distribution terms for this file may be
13
 *  found in the file LICENSE in this distribution or at
14
 *  http://www.OARcorp.com/rtems/license.html.
15
 *
16
 *  $Id: fatal.c,v 1.2 2001-09-27 12:02:38 chris Exp $
17
 */
18
 
19
#include "system.h"
20
 
21
#include <setjmp.h>
22
 
23
char Workspace[ 64 * 1024 ] CPU_STRUCTURE_ALIGNMENT;
24
 
25
typedef enum {
26
  FATAL_WORKSPACE_OF_ZERO,
27
  FATAL_NULL_WORKSPACE,
28
  FATAL_WORKSPACE_TOO_SMALL,
29
  FATAL_TASK_CREATE,
30
  FATAL_TASK_START
31
}  Fatal_errors_t;
32
 
33
#define FATAL_LAST FATAL_TASK_START
34
 
35
volatile Fatal_errors_t Case_in_switch;
36
 
37
rtems_status_code Expected_Errors[] = {
38
  RTEMS_UNSATISFIED,
39
  RTEMS_INVALID_ADDRESS,
40
  RTEMS_UNSATISFIED,
41
  RTEMS_INVALID_PRIORITY,
42
  RTEMS_TASK_EXITTED
43
};
44
 
45
rtems_status_code Error_Happened[ FATAL_LAST + 1];
46
 
47
jmp_buf Restart_Context;
48
 
49
/*
50
 *  We depend on this being zeroed during initialization.  This
51
 *  occurs automatically because this is part of the BSS.
52
 */
53
 
54
rtems_unsigned32  First_Time_Through;
55
 
56
void Process_case();
57
 
58
rtems_extension Fatal_extension(
59
  rtems_unsigned32 source,
60
  boolean          is_internal,
61
  rtems_unsigned32 error
62
)
63
{
64
  int index;
65
 
66
  Error_Happened[ Case_in_switch ] = error;
67
 
68
  if ( First_Time_Through == 0 ) {
69
    Case_in_switch = FATAL_WORKSPACE_OF_ZERO;
70
    First_Time_Through = 1;
71
    setjmp( Restart_Context );
72
  } else if ( Case_in_switch == FATAL_LAST ) {
73
 
74
    /*
75
     *  Depending on the C library we use, we cannot get the
76
     *  task exitted error so do not check for it.
77
     */
78
 
79
    puts( "*** TEST FATAL ***" );
80
    for ( index=0 ; index< FATAL_LAST ; index++ )
81
      put_error( Error_Happened[ index ], Expected_Errors[ index ] );
82
    puts( "NOT TESTING FATAL ERROR WHEN TASK EXITS -- C LIBRARY CATCHES THIS" );
83
    puts( "*** END OF TEST FATAL ***" );
84
 
85
    /*
86
     *  returns to the default fatal error handler instead of
87
     *  calling rtems_shutdown_executive
88
     */
89
    return;
90
 
91
  } else {
92
 
93
    longjmp( Restart_Context, 1 );
94
  }
95
 
96
  Process_case();
97
}
98
 
99
 
100
 
101
void Process_case()
102
{
103
  switch ( Case_in_switch ) {
104
    case FATAL_WORKSPACE_OF_ZERO:
105
      New_Configuration = rtems_configuration_get_table();
106
      New_Configuration.work_space_start = NULL;
107
      Case_in_switch = FATAL_NULL_WORKSPACE;
108
      break;
109
 
110
    case FATAL_NULL_WORKSPACE:
111
      New_Configuration.work_space_start = Workspace;
112
      New_Configuration.work_space_size  = 256;
113
      Case_in_switch = FATAL_WORKSPACE_TOO_SMALL;
114
      break;
115
 
116
    case FATAL_WORKSPACE_TOO_SMALL:
117
      Initialization_tasks[ 0 ].initial_priority = RTEMS_CURRENT_PRIORITY;
118
      New_Configuration.work_space_size = sizeof( Workspace );
119
      Case_in_switch = FATAL_TASK_CREATE;
120
      break;
121
 
122
    case FATAL_TASK_CREATE:
123
      Initialization_tasks[ 0 ].initial_priority = 1;
124
      Initialization_tasks[ 0 ].entry_point      = NULL;
125
      Case_in_switch = FATAL_TASK_START;
126
      break;
127
 
128
    case FATAL_TASK_START:
129
      /* this extension exits the test */
130
      Initialization_tasks[ 0 ].entry_point = Init;
131
      break;
132
  }
133
  rtems_initialize_executive(
134
    &New_Configuration, rtems_cpu_configuration_get_table() );
135
}
136
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.