source: soft/giet_vm/giet_kernel/exc_handler.c @ 741

Last change on this file since 741 was 709, checked in by alain, 9 years ago

Major release: Change the task model to implement the POSIX threads API.

  • The shell "exec" and "kill" commands can be used to activate/de-activate the applications.
  • The "pause", "resume", and "context" commands can be used to stop, restart, a single thtead or to display the thread context.

This version has been tested on the following multi-threaded applications,
that have been modified to use the POSIX threads:

  • classif
  • convol
  • transpose
  • gameoflife
  • raycast
  • Property svn:executable set to *
File size: 4.4 KB
Line 
1///////////////////////////////////////////////////////////////////////////////////
2// File     : exc_handler.c
3// Date     : 01/04/2012
4// Author   : alain greiner and joel porquet
5// Copyright (c) UPMC-LIP6
6///////////////////////////////////////////////////////////////////////////////////
7
8#include <exc_handler.h>
9#include <ctx_handler.h>
10#include <sys_handler.h>
11#include <utils.h>
12#include <tty0.h>
13
14///////////////////////////////////////////////////////////////////////////////////
15// Prototypes of exception handlers.
16///////////////////////////////////////////////////////////////////////////////////
17
18static void _cause_ukn();
19static void _cause_adel();
20static void _cause_ades();
21static void _cause_ibe();
22static void _cause_dbe();
23static void _cause_bp();
24static void _cause_ri();
25static void _cause_cpu();
26static void _cause_ovf();
27
28extern void _int_handler();
29extern void _sys_handler();
30
31///////////////////////////////////////////////////////////////////////////////////
32// Initialize the exception vector indexed by the CR XCODE field
33///////////////////////////////////////////////////////////////////////////////////
34
35__attribute__((section(".kdata")))
36const _exc_func_t _cause_vector[16] = 
37{
38    &_int_handler,  /* 0000 : external interrupt */
39    &_cause_ukn,    /* 0001 : undefined exception */
40    &_cause_ukn,    /* 0010 : undefined exception */
41    &_cause_ukn,    /* 0011 : undefined exception */
42    &_cause_adel,   /* 0100 : illegal address read exception */
43    &_cause_ades,   /* 0101 : illegal address write exception */
44    &_cause_ibe,    /* 0110 : instruction bus error exception */
45    &_cause_dbe,    /* 0111 : data bus error exception */
46    &_sys_handler,  /* 1000 : system call */
47    &_cause_bp,     /* 1001 : breakpoint exception */
48    &_cause_ri,     /* 1010 : illegal codop exception */
49    &_cause_cpu,    /* 1011 : illegal coprocessor access */
50    &_cause_ovf,    /* 1100 : arithmetic overflow exception */
51    &_cause_ukn,    /* 1101 : undefined exception */
52    &_cause_ukn,    /* 1110 : undefined exception */
53    &_cause_ukn,    /* 1111 : undefined exception */
54};
55
56///////////////////////////////////////////////
57static void _display_cause( unsigned int type ) 
58{
59    unsigned int gpid       = _get_procid();
60    unsigned int cluster_xy = gpid >> P_WIDTH;
61    unsigned int x          = cluster_xy >> Y_WIDTH;
62    unsigned int y          = cluster_xy & ((1<<Y_WIDTH)-1);
63    unsigned int p          = gpid & ((1<<P_WIDTH)-1);
64    unsigned int trdid      = _get_thread_trdid();
65    unsigned int ltid       = _get_thread_ltid();
66
67    static_scheduler_t*  psched = (static_scheduler_t*)_get_sched();
68
69    const char * mips32_exc_str[] = { "strange unknown cause  ",
70                                      "illegal read address   ",
71                                      "illegal write address  ",
72                                      "inst bus error         ",
73                                      "data bus error         ",
74                                      "breakpoint             ",
75                                      "reserved instruction   ",
76                                      "illegal coproc access  ",
77                                      "arithmetic overflow    " };
78
79    _printf("\n[GIET] Exception for thread %x on processor[%d,%d,%d] at cycle %d\n"
80            " - type      : %s\n"
81            " - EPC       : %x\n"
82            " - BVAR      : %x\n"
83            "...Thread desactivated\n",
84            trdid , x , y , p , _get_proctime(),
85            mips32_exc_str[type], _get_epc(), _get_bvar() );
86
87    // register KILL signal
88    _atomic_or( &psched->context[ltid].slot[CTX_SIGS_ID] , SIGS_MASK_KILL );
89
90    // deschedule calling thread
91    unsigned int save_sr; 
92    _it_disable( &save_sr );
93    _ctx_switch();
94
95}  // end display_cause()
96
97static void _cause_ukn()  { _display_cause(0); }
98static void _cause_adel() { _display_cause(1); }
99static void _cause_ades() { _display_cause(2); }
100static void _cause_ibe()  { _display_cause(3); }
101static void _cause_dbe()  { _display_cause(4); }
102static void _cause_bp()   { _display_cause(5); }
103static void _cause_ri()   { _display_cause(6); }
104static void _cause_cpu()  { _display_cause(7); }
105static void _cause_ovf()  { _display_cause(8); }
106
107// Local Variables:
108// tab-width: 4
109// c-basic-offset: 4
110// c-file-offsets:((innamespace . 0)(inline-open . 0))
111// indent-tabs-mode: nil
112// End:
113// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
114
Note: See TracBrowser for help on using the repository browser.