OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [sim/] [except.c] - Blame information for rev 275

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 8 hellwig
/*
2
 * except.c -- exception handling
3
 */
4
 
5
 
6
#include <stdio.h>
7
#include <stdlib.h>
8
#include <string.h>
9
#include <setjmp.h>
10
 
11
#include "error.h"
12
#include "except.h"
13
 
14
 
15
#define MAX_ENV_NEST_DEPTH      10
16
 
17
 
18
static jmp_buf *environments[MAX_ENV_NEST_DEPTH];
19
static int currentEnvironment = -1;
20
 
21
 
22
void throwException(int exception) {
23
  if (currentEnvironment < 0) {
24
    error("exception %d thrown while no environment active", exception);
25
  }
26
  longjmp(*environments[currentEnvironment], exception);
27
}
28
 
29
 
30
void pushEnvironment(jmp_buf *environment) {
31
  if (currentEnvironment == MAX_ENV_NEST_DEPTH - 1) {
32
    error("too many environments active");
33
  }
34
  currentEnvironment++;
35
  environments[currentEnvironment] = environment;
36
}
37
 
38
 
39
void popEnvironment(void) {
40
  if (currentEnvironment < 0) {
41
    error("cannot pop environment - none active");
42
  }
43
  currentEnvironment--;
44
}
45 275 hellwig
 
46
 
47
static char *cause[32] = {
48
  /*  0 */  "serial line 0 xmt interrupt",
49
  /*  1 */  "serial line 0 rcv interrupt",
50
  /*  2 */  "serial line 1 xmt interrupt",
51
  /*  3 */  "serial line 1 rcv interrupt",
52
  /*  4 */  "keyboard interrupt",
53
  /*  5 */  "unknown interrupt",
54
  /*  6 */  "unknown interrupt",
55
  /*  7 */  "unknown interrupt",
56
  /*  8 */  "disk interrupt",
57
  /*  9 */  "unknown interrupt",
58
  /* 10 */  "unknown interrupt",
59
  /* 11 */  "unknown interrupt",
60
  /* 12 */  "unknown interrupt",
61
  /* 13 */  "unknown interrupt",
62
  /* 14 */  "timer 0 interrupt",
63
  /* 15 */  "timer 1 interrupt",
64
  /* 16 */  "bus timeout exception",
65
  /* 17 */  "illegal instruction exception",
66
  /* 18 */  "privileged instruction exception",
67
  /* 19 */  "divide instruction exception",
68
  /* 20 */  "trap instruction exception",
69
  /* 21 */  "TLB miss exception",
70
  /* 22 */  "TLB write exception",
71
  /* 23 */  "TLB invalid exception",
72
  /* 24 */  "illegal address exception",
73
  /* 25 */  "privileged address exception",
74
  /* 26 */  "unknown exception",
75
  /* 27 */  "unknown exception",
76
  /* 28 */  "unknown exception",
77
  /* 29 */  "unknown exception",
78
  /* 30 */  "unknown exception",
79
  /* 31 */  "unknown exception"
80
};
81
 
82
 
83
char *exceptionToString(int exception) {
84
  if (exception < 0 ||
85
      exception >= sizeof(cause)/sizeof(cause[0])) {
86
    error("exception number out of bounds");
87
  }
88
  return cause[exception];
89
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.