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

Last change on this file since 802 was 802, checked in by alain, 8 years ago

Improve error message print, to avoisd interleaving.

  • Property svn:executable set to *
File size: 7.6 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    Modify format to have one single printf and avoid interleaving 'AG)
80
81    _printf("\n[GIET] Exception for thread %x on processor[%d,%d,%d] at cycle %d\n"
82            " - type      : %s\n"
83            " - EPC       : %x\n"
84            " - BVAR      : %x\n"
85            "...Thread desactivated\n",
86            trdid , x , y , p , _get_proctime(),
87            mips32_exc_str[type], _get_epc(), _get_bvar() );
88
89    _printf("Registers:\n");
90    _printf("CR:   %X\tEPC:  %X\tSR:   %X\tCO_HI %X\tC0_LO  %X\n",
91            regs_table[33], regs_table[32], regs_table[34], regs_table[36], regs_table[35]);
92    _printf("at_1  %X\tv0_2  %X\tv1_3  %X\ta0_4  %X\ta1_5   %X\n",
93            regs_table[1], regs_table[2], regs_table[3], regs_table[4], regs_table[5]);
94    _printf("a2_6  %X\ta3_7  %X\tt0_8  %X\tt1_9  %X\tt2_10  %X\n",
95            regs_table[6], regs_table[7], regs_table[8], regs_table[9], regs_table[10]);
96    _printf("t3_11 %X\tt4_12 %X\tt5_13 %X\tt6_14 %X\tt7_15  %X\n",
97            regs_table[11], regs_table[12], regs_table[13], regs_table[14], regs_table[15]);
98    _printf("s0_16 %X\ts1_17 %X\ts2_18 %X\ts3_19 %X\ts4_20  %X\n",
99            regs_table[16], regs_table[17], regs_table[18], regs_table[19], regs_table[20]);
100    _printf("s5_21 %X\ts6_22 %X\ts7_23 %X\tt8_24 %X\tt9_25  %X\n",
101            regs_table[21], regs_table[22], regs_table[23], regs_table[24], regs_table[25]);
102    _printf("gp_28 %X\tsp_29 %X\tfp_30 %X\tra_31 %X\n\n",
103            regs_table[28], regs_table[29], regs_table[30], regs_table[31]);
104*/
105    _printf("\n[GIET] Exception for thread %x on processor[%d,%d,%d] at cycle %d\n"
106            "  type : %s\n"
107            "CR    %X\tEPC   %X\tSR    %X\tBVAR  %X\n"
108            "HI    %X\tLO    %X\n"
109            "zero  %X\tat_1  %X\tv0_2  %X\tv1_3  %X\n"
110            "a0_4  %X\ta1_5  %X\ta2_6  %X\ta3_7  %X\n"
111            "t0_8  %X\tt1_9  %X\tt2_10 %X\tt3_11 %X\n"
112            "t4_12 %X\tt5_13 %X\tt6_14 %X\tt7_15 %X\n"
113            "s0_16 %X\ts1_17 %X\ts2_18 %X\ts3_19 %X\n"
114            "s4_20 %X\ts5_21 %X\ts6_22 %X\ts7_23 %X\n"
115            "t8_24 %X\tt9_25 %X\tk0_26 %s\tk1_27 %s\n"
116            "gp_28 %X\tsp_29 %X\tfp_30 %X\tra_31 %X\n",
117            trdid , x , y , p , _get_proctime(),
118            mips32_exc_str[type],
119            regs_table[33] , regs_table[32] , regs_table[34] , regs_table[37],
120            regs_table[36] , regs_table[35] ,
121            0              , regs_table[1]  , regs_table[2]  , regs_table[3] , 
122            regs_table[4]  , regs_table[5]  , regs_table[6]  , regs_table[7] ,
123            regs_table[8]  , regs_table[9]  , regs_table[10] , regs_table[11],
124            regs_table[12] , regs_table[13] , regs_table[14] , regs_table[15],
125            regs_table[16] , regs_table[17] , regs_table[18] , regs_table[19],
126            regs_table[20] , regs_table[21] , regs_table[22] , regs_table[23],
127            regs_table[24] , regs_table[25] , "undefined "   , "undefined "  ,
128            regs_table[28] , regs_table[29] , regs_table[30] , regs_table[31] );
129
130    // register KILL signal
131    _atomic_or( &psched->context[ltid].slot[CTX_SIGS_ID] , SIGS_MASK_KILL );
132
133    // deschedule calling thread
134    unsigned int save_sr; 
135    _it_disable( &save_sr );
136    _ctx_switch();
137
138}  // end display_cause()
139
140static void _cause_ukn(unsigned int * regs_table)  { _display_cause(0, regs_table); }
141static void _cause_adel(unsigned int * regs_table) { _display_cause(1, regs_table); }
142static void _cause_ades(unsigned int * regs_table) { _display_cause(2, regs_table); }
143static void _cause_ibe(unsigned int * regs_table)  { _display_cause(3, regs_table); }
144static void _cause_dbe(unsigned int * regs_table)  { _display_cause(4, regs_table); }
145static void _cause_bp(unsigned int * regs_table)   { _display_cause(5, regs_table); }
146static void _cause_ri(unsigned int * regs_table)   { _display_cause(6, regs_table); }
147static void _cause_cpu(unsigned int * regs_table)  { _display_cause(7, regs_table); }
148static void _cause_ovf(unsigned int * regs_table)  { _display_cause(8, regs_table); }
149
150// Local Variables:
151// tab-width: 4
152// c-basic-offset: 4
153// c-file-offsets:((innamespace . 0)(inline-open . 0))
154// indent-tabs-mode: nil
155// End:
156// vim: filetype=c:expandtab:shiftwidth=4:tabstop=4:softtabstop=4
157
Note: See TracBrowser for help on using the repository browser.