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

Last change on this file since 798 was 798, checked in by meunier, 8 years ago
  • Bug fixes in Rosenfeld
  • Property svn:executable set to *
File size: 6.0 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(unsigned int * regs_table);
19static void _cause_adel(unsigned int * regs_table);
20static void _cause_ades(unsigned int * regs_table);
21static void _cause_ibe(unsigned int * regs_table);
22static void _cause_dbe(unsigned int * regs_table);
23static void _cause_bp(unsigned int * regs_table);
24static void _cause_ri(unsigned int * regs_table);
25static void _cause_cpu(unsigned int * regs_table);
26static void _cause_ovf(unsigned int * regs_table);
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, unsigned int * regs_table )
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    _printf("Registers:\n");
88    _printf("CR:   %X\tEPC:  %X\tSR:   %X\tCO_HI %X\tC0_LO  %X\n",
89            regs_table[33], regs_table[32], regs_table[34], regs_table[36], regs_table[35]);
90    _printf("at_1  %X\tv0_2  %X\tv1_3  %X\ta0_4  %X\ta1_5   %X\n",
91            regs_table[1], regs_table[2], regs_table[3], regs_table[4], regs_table[5]);
92    _printf("a2_6  %X\ta3_7  %X\tt0_8  %X\tt1_9  %X\tt2_10  %X\n",
93            regs_table[6], regs_table[7], regs_table[8], regs_table[9], regs_table[10]);
94    _printf("t3_11 %X\tt4_12 %X\tt5_13 %X\tt6_14 %X\tt7_15  %X\n",
95            regs_table[11], regs_table[12], regs_table[13], regs_table[14], regs_table[15]);
96    _printf("s0_16 %X\ts1_17 %X\ts2_18 %X\ts3_19 %X\ts4_20  %X\n",
97            regs_table[16], regs_table[17], regs_table[18], regs_table[19], regs_table[20]);
98    _printf("s5_21 %X\ts6_22 %X\ts7_23 %X\tt8_24 %X\tt9_25  %X\n",
99            regs_table[21], regs_table[22], regs_table[23], regs_table[24], regs_table[25]);
100    _printf("gp_28 %X\tsp_29 %X\tfp_30 %X\tra_31 %X\n\n",
101            regs_table[28], regs_table[29], regs_table[30], regs_table[31]);
102
103
104    // register KILL signal
105    _atomic_or( &psched->context[ltid].slot[CTX_SIGS_ID] , SIGS_MASK_KILL );
106
107    // deschedule calling thread
108    unsigned int save_sr; 
109    _it_disable( &save_sr );
110    _ctx_switch();
111
112}  // end display_cause()
113
114static void _cause_ukn(unsigned int * regs_table)  { _display_cause(0, regs_table); }
115static void _cause_adel(unsigned int * regs_table) { _display_cause(1, regs_table); }
116static void _cause_ades(unsigned int * regs_table) { _display_cause(2, regs_table); }
117static void _cause_ibe(unsigned int * regs_table)  { _display_cause(3, regs_table); }
118static void _cause_dbe(unsigned int * regs_table)  { _display_cause(4, regs_table); }
119static void _cause_bp(unsigned int * regs_table)   { _display_cause(5, regs_table); }
120static void _cause_ri(unsigned int * regs_table)   { _display_cause(6, regs_table); }
121static void _cause_cpu(unsigned int * regs_table)  { _display_cause(7, regs_table); }
122static void _cause_ovf(unsigned int * regs_table)  { _display_cause(8, regs_table); }
123
124// Local Variables:
125// tab-width: 4
126// c-basic-offset: 4
127// c-file-offsets:((innamespace . 0)(inline-open . 0))
128// indent-tabs-mode: nil
129// End:
130// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
131
Note: See TracBrowser for help on using the repository browser.