source: soft/giet_vm/sys/exc_handler.c @ 158

Last change on this file since 158 was 158, checked in by alain, 12 years ago

Introducing the giet_vm and some example applications

File size: 3.5 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// The exc_handler.c and exc_handler.h files are part of the GIET nano-kernel.
8// They contains the exception handler code.
9///////////////////////////////////////////////////////////////////////////////////
10
11#include <exc_handler.h>
12#include <sys_handler.h>
13#include <drivers.h>
14#include <common.h>
15
16///////////////////////////////////////////////////////////////////////////////////
17// Prototypes of exception handlers.
18///////////////////////////////////////////////////////////////////////////////////
19
20static void _cause_ukn();
21static void _cause_adel();
22static void _cause_ades();
23static void _cause_ibe();
24static void _cause_dbe();
25static void _cause_bp();
26static void _cause_ri();
27static void _cause_cpu();
28static void _cause_ovf();
29
30extern void _int_handler();
31extern void _sys_handler();
32
33///////////////////////////////////////////////////////////////////////////////////
34// Initialize the exception vector according to CR code
35///////////////////////////////////////////////////////////////////////////////////
36const _exc_func_t _cause_vector[16] = {
37    &_int_handler,  /* 0000 : external interrupt */
38    &_cause_ukn,    /* 0001 : undefined exception */
39    &_cause_ukn,    /* 0010 : undefined exception */
40    &_cause_ukn,    /* 0011 : undefined exception */
41    &_cause_adel,   /* 0100 : illegal address read exception */
42    &_cause_ades,   /* 0101 : illegal address write exception */
43    &_cause_ibe,    /* 0110 : instruction bus error exception */
44    &_cause_dbe,    /* 0111 : data bus error exception */
45    &_sys_handler,  /* 1000 : system call */
46    &_cause_bp,     /* 1001 : breakpoint exception */
47    &_cause_ri,     /* 1010 : illegal codop exception */
48    &_cause_cpu,    /* 1011 : illegal coprocessor access */
49    &_cause_ovf,    /* 1100 : arithmetic overflow exception */
50    &_cause_ukn,    /* 1101 : undefined exception */
51    &_cause_ukn,    /* 1110 : undefined exception */
52    &_cause_ukn,    /* 1111 : undefined exception */
53};
54
55static const char *exc_message_causes[] = {
56    "\n\nException : strange unknown cause\n",
57    "\n\nException : illegal read address \n",
58    "\n\nException : illegal write address\n",
59    "\n\nException : inst bus error       \n",
60    "\n\nException : data bus error       \n",
61    "\n\nException : breakpoint           \n",
62    "\n\nException : reserved instruction \n",
63    "\n\nException : illegal coproc access\n"
64    "\n\nException : arithmetic overflow  \n",
65};
66
67static void _cause(unsigned int msg_cause)
68{
69    unsigned int        epc;
70    unsigned int        bar;
71    unsigned int        cause;
72
73    asm volatile("mfc0 %0, $14" : "=r"(epc));
74    asm volatile("mfc0 %0, $8 " : "=r"(bar));
75    asm volatile("mfc0 %0, $13" : "=r"(cause));
76
77    _puts( (char*)(exc_message_causes[msg_cause]) );
78    _puts("\nEPC   = ");
79    _putw( epc );
80    _puts("\nBAR   = ");
81    _putw( bar );
82    _puts("\nCAUSE = ");
83    _putw( cause );
84    _puts("\n");
85
86    _exit();
87}
88
89static void _cause_ukn()  { _cause(0); }
90static void _cause_adel() { _cause(1); }
91static void _cause_ades() { _cause(2); }
92static void _cause_ibe()  { _cause(3); }
93static void _cause_dbe()  { _cause(4); }
94static void _cause_bp()   { _cause(5); }
95static void _cause_ri()   { _cause(6); }
96static void _cause_cpu()  { _cause(7); }
97static void _cause_ovf()  { _cause(8); }
98
Note: See TracBrowser for help on using the repository browser.