Subversion Repositories shark

Rev

Rev 38 | Rev 445 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
38 pj 1
/*
2
 * Project: S.Ha.R.K.
3
 *
4
 * Coordinators:
5
 *   Giorgio Buttazzo    <giorgio@sssup.it>
6
 *   Paolo Gai           <pj@gandalf.sssup.it>
7
 *
8
 * Authors     :
9
 *   Paolo Gai           <pj@gandalf.sssup.it>
10
 *   (see the web pages for full authors list)
11
 *
12
 * ReTiS Lab (Scuola Superiore S.Anna - Pisa - Italy)
13
 *
14
 * http://www.sssup.it
15
 * http://retis.sssup.it
16
 * http://shark.sssup.it
17
 */
18
 
19
/**
20
 ------------
157 pj 21
 CVS :        $Id: exchand.c,v 1.2 2003-05-01 19:40:52 pj Exp $
38 pj 22
 
23
 File:        $File$
157 pj 24
 Revision:    $Revision: 1.2 $
25
 Last update: $Date: 2003-05-01 19:40:52 $
38 pj 26
 ------------
27
**/
28
 
29
/*
157 pj 30
 * Copyright (C) 2000-2003 Paolo Gai
38 pj 31
 *
32
 * This program is free software; you can redistribute it and/or modify
33
 * it under the terms of the GNU General Public License as published by
34
 * the Free Software Foundation; either version 2 of the License, or
35
 * (at your option) any later version.
36
 *
37
 * This program is distributed in the hope that it will be useful,
38
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
39
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
40
 * GNU General Public License for more details.
41
 *
42
 * You should have received a copy of the GNU General Public License
43
 * along with this program; if not, write to the Free Software
44
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
45
 *
46
 */
47
 
48
#include <kernel/kern.h>
49
 
50
static int             myflag;
51
static siginfo_t       myinfo;
52
static struct timespec mytime;
53
 
54
static void thehandler(int signo, siginfo_t *info, void *extra);
55
static void theend(void *arg);
56
 
157 pj 57
const char *const _sys_exclist[] = {
58
  "not used",
59
  "not used",
60
  "invalid kill of a task with a shadow pointer set",          /* 2 */
61
  "cleanup push: no more cleanups handlers",
62
  "invalid operation for a task",
63
  "not used",
64
  "no more OSLib events posted (see oslib/kl/event.c)",
65
  "deadline miss",
66
  "wcet violation",
67
  "task activated at a wrong time (too early?)",
68
  "mutex owner killed",                                        /* 10 */
69
  "SRP: invalid lock",
70
  "Dummy task: invalid operation",
71
  "Sporadic Server: invalid replenishment",
72
  "ARP: table full",
73
  "Netbuff: init",
74
  "Netbuff: get",
75
  "Netbuff: already free",
76
  "Netbuff: release",
77
  "UDP: Bad checksum"
78
};
79
 
80
static char shutdown_message_buffer[500];
81
static int myflag_shutdown = 0;
82
 
38 pj 83
/*
84
   This exception handler should be good for text applications that do NOT
85
   use graphics
86
*/
87
int set_default_exception_handler(void)
88
{
89
  struct sigaction action;
90
 
91
  myflag = 0;
92
 
93
  sys_atrunlevel(theend, NULL, RUNLEVEL_AFTER_EXIT);
94
 
95
  /* Init the standard S.Ha.R.K. exception handler */
96
  action.sa_flags = SA_SIGINFO;            /* Set the signal action */
97
  action.sa_sigaction = thehandler;
98
  action.sa_handler = 0;
99
  sigfillset(&action.sa_mask); /* we block all the other signals... */
100
 
101
  return sigaction(SIGHEXC, &action, NULL); /* set the signal */
102
}
103
 
157 pj 104
int sys_shutdown_message(char *fmt,...)
105
{
106
  va_list parms;
107
  int result = -1;
108
 
109
  if (!myflag_shutdown) {
110
    myflag_shutdown = 1;
111
    va_start(parms,fmt);
112
    result = vsprintf(shutdown_message_buffer,fmt,parms);
113
    va_end(parms);
114
  }
115
 
116
  return(result);
117
}
118
 
38 pj 119
static void thehandler(int signo, siginfo_t *info, void *extra)
120
{
121
  if (!myflag) {
122
    myflag = 1;
123
    myinfo = *info;
124
    sys_gettime(&mytime),
125
 
126
    sys_abort(AHEXC);
127
  }
128
}
129
 
130
static void theend(void *arg)
131
{
132
  if (myflag) {
157 pj 133
    cprintf("S.Ha.R.K. Exception raised!!!\n");
134
    cprintf("Time (s:ns)     :%ld:%ld\n", mytime.tv_sec, mytime.tv_nsec);
135
    cprintf("Exception number:%d (%s)\n", myinfo.si_value.sival_int,
136
            _sys_exclist[myinfo.si_value.sival_int]);
137
    cprintf("PID             :%d (%s)\n", myinfo.si_task,
138
            proc_table[myinfo.si_task].name);
139
    cprintf("Avail time      : %d\n", proc_table[myinfo.si_task].avail_time);
38 pj 140
  }
157 pj 141
  if (myflag_shutdown) {
142
    cprintf("\nShutdown message:\n%s\n", shutdown_message_buffer);
143
  }
144
 
38 pj 145
}
146
 
147
 
148