Subversion Repositories shark

Rev

Rev 157 | Rev 503 | 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
 ------------
445 giacomo 21
 CVS :        $Id: exchand.c,v 1.3 2004-02-10 17:50:03 giacomo Exp $
38 pj 22
 
23
 File:        $File$
445 giacomo 24
 Revision:    $Revision: 1.3 $
25
 Last update: $Date: 2004-02-10 17:50:03 $
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
 
445 giacomo 132
 
133
extern void *StartTracerBuffer; // Buffer Start 0
134
extern void *EndTracerBuffer; // Buffer End 4
135
extern void *LastBeforeEndTracerBuffer; //8
136
extern void *CurrentTracerBuffer; //The Actual Write Point For The Next Event 12
137
extern void *FirstTracerBuffer; //The First Valid Event 16
138
 
139
 
140
extern int TracerActive; //20
141
extern int TracerOutputType; //24
142
extern unsigned long long TracerEventsRecorded; //28
143
extern unsigned int TracerEventsPresent; //36
144
 
38 pj 145
static void theend(void *arg)
146
{
445 giacomo 147
 
148
  #ifdef __NEW_TRACER__
149
 
150
    void *save_tracer_pointer;
151
 
152
  #endif
153
 
38 pj 154
  if (myflag) {
157 pj 155
    cprintf("S.Ha.R.K. Exception raised!!!\n");
156
    cprintf("Time (s:ns)     :%ld:%ld\n", mytime.tv_sec, mytime.tv_nsec);
157
    cprintf("Exception number:%d (%s)\n", myinfo.si_value.sival_int,
158
	    _sys_exclist[myinfo.si_value.sival_int]);
159
    cprintf("PID             :%d (%s)\n", myinfo.si_task,
160
	    proc_table[myinfo.si_task].name);
161
    cprintf("Avail time      : %d\n", proc_table[myinfo.si_task].avail_time);
445 giacomo 162
 
163
    #ifdef __NEW_TRACER__
164
 
165
      save_tracer_pointer = malloc(48);
166
 
167
      *(void **)(save_tracer_pointer) = StartTracerBuffer; // Buffer Start 0
168
      *(void **)(save_tracer_pointer+4) = EndTracerBuffer; // Buffer End 4
169
      *(void **)(save_tracer_pointer+8) = LastBeforeEndTracerBuffer; //8
170
      *(void **)(save_tracer_pointer+12) = CurrentTracerBuffer; //The Actual Write Point For The Next Event 12
171
      *(void **)(save_tracer_pointer+16) = FirstTracerBuffer; //The First Valid Event 16
172
 
173
      *(int *)(save_tracer_pointer+20) = 0; //20
174
 
175
      *(int *)(save_tracer_pointer+24) = TRACER_UDP_OUTPUT; //24
176
      *(unsigned long long *)(save_tracer_pointer+28) = TracerEventsRecorded; //28
177
      *(unsigned int *)(save_tracer_pointer+36) = TracerEventsPresent; //36
178
 
179
      cprintf("Dumper Magic Number = %u\n",(int)save_tracer_pointer);
180
 
181
    #endif
182
 
38 pj 183
  }
157 pj 184
  if (myflag_shutdown) {
185
    cprintf("\nShutdown message:\n%s\n", shutdown_message_buffer);
186
  }
187
 
38 pj 188
}
189
 
190
 
191