Subversion Repositories shark

Rev

Rev 445 | Rev 564 | 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
 ------------
503 giacomo 21
 CVS :        $Id: exchand.c,v 1.4 2004-03-10 16:42:51 giacomo Exp $
38 pj 22
 
23
 File:        $File$
503 giacomo 24
 Revision:    $Revision: 1.4 $
25
 Last update: $Date: 2004-03-10 16:42:51 $
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>
445 giacomo 49
#include <stdlib.h>
50
#include <tracer.h>
38 pj 51
 
52
static int             myflag;
53
static siginfo_t       myinfo;
54
static struct timespec mytime;
55
 
56
static void thehandler(int signo, siginfo_t *info, void *extra);
57
static void theend(void *arg);
58
 
157 pj 59
const char *const _sys_exclist[] = {
60
  "not used",
61
  "not used",
62
  "invalid kill of a task with a shadow pointer set",          /* 2 */
63
  "cleanup push: no more cleanups handlers",
64
  "invalid operation for a task",
65
  "not used",
66
  "no more OSLib events posted (see oslib/kl/event.c)",
67
  "deadline miss",
68
  "wcet violation",
69
  "task activated at a wrong time (too early?)",
70
  "mutex owner killed",                                        /* 10 */
71
  "SRP: invalid lock",
72
  "Dummy task: invalid operation",
73
  "Sporadic Server: invalid replenishment",
74
  "ARP: table full",
75
  "Netbuff: init",
76
  "Netbuff: get",
77
  "Netbuff: already free",
78
  "Netbuff: release",
79
  "UDP: Bad checksum"
80
};
81
 
82
static char shutdown_message_buffer[500];
83
static int myflag_shutdown = 0;
84
 
38 pj 85
/*
86
   This exception handler should be good for text applications that do NOT
87
   use graphics
88
*/
89
int set_default_exception_handler(void)
90
{
91
  struct sigaction action;
92
 
93
  myflag = 0;
94
 
95
  sys_atrunlevel(theend, NULL, RUNLEVEL_AFTER_EXIT);
96
 
97
  /* Init the standard S.Ha.R.K. exception handler */
98
  action.sa_flags = SA_SIGINFO;            /* Set the signal action */
99
  action.sa_sigaction = thehandler;
100
  action.sa_handler = 0;
101
  sigfillset(&action.sa_mask); /* we block all the other signals... */
102
 
103
  return sigaction(SIGHEXC, &action, NULL); /* set the signal */
104
}
105
 
157 pj 106
int sys_shutdown_message(char *fmt,...)
107
{
108
  va_list parms;
109
  int result = -1;
110
 
111
  if (!myflag_shutdown) {
112
    myflag_shutdown = 1;
113
    va_start(parms,fmt);
114
    result = vsprintf(shutdown_message_buffer,fmt,parms);
115
    va_end(parms);
116
  }
117
 
118
  return(result);
119
}
120
 
38 pj 121
static void thehandler(int signo, siginfo_t *info, void *extra)
122
{
123
  if (!myflag) {
124
    myflag = 1;
125
    myinfo = *info;
126
    sys_gettime(&mytime),
127
 
128
    sys_abort(AHEXC);
129
  }
130
}
131
 
132
static void theend(void *arg)
133
{
445 giacomo 134
 
38 pj 135
  if (myflag) {
157 pj 136
    cprintf("S.Ha.R.K. Exception raised!!!\n");
137
    cprintf("Time (s:ns)     :%ld:%ld\n", mytime.tv_sec, mytime.tv_nsec);
138
    cprintf("Exception number:%d (%s)\n", myinfo.si_value.sival_int,
139
	    _sys_exclist[myinfo.si_value.sival_int]);
140
    cprintf("PID             :%d (%s)\n", myinfo.si_task,
141
	    proc_table[myinfo.si_task].name);
142
    cprintf("Avail time      : %d\n", proc_table[myinfo.si_task].avail_time);
445 giacomo 143
 
38 pj 144
  }
157 pj 145
  if (myflag_shutdown) {
146
    cprintf("\nShutdown message:\n%s\n", shutdown_message_buffer);
147
  }
148
 
38 pj 149
}
150
 
151
 
152