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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [cpu/] [or1k/] [except.c] - Blame information for rev 346

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 19 jeremybenn
/* except.c -- Simulation of OR1K exceptions
2
 
3
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
4
   Copyright (C) 2008 Embecosm Limited
5
 
6
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
7
 
8
   This file is part of Or1ksim, the OpenRISC 1000 Architectural Simulator.
9
 
10
   This program is free software; you can redistribute it and/or modify it
11
   under the terms of the GNU General Public License as published by the Free
12
   Software Foundation; either version 3 of the License, or (at your option)
13
   any later version.
14
 
15
   This program is distributed in the hope that it will be useful, but WITHOUT
16
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
18
   more details.
19
 
20
   You should have received a copy of the GNU General Public License along
21
   with this program.  If not, see <http://www.gnu.org/licenses/>.  */
22
 
23
/* This program is commented throughout in a fashion suitable for processing
24
   with Doxygen. */
25
 
26
 
27
/* Autoconf and/or portability configuration */
28
#include "config.h"
29
 
30
/* Package includes */
31
#include "except.h"
32
#include "sim-config.h"
33
#include "arch.h"
34
#include "debug.h"
35
#include "spr-defs.h"
36
#include "execute.h"
37
#include "debug-unit.h"
38
 
39
#if DYNAMIC_EXECUTION
40
#include "sched.h"
41
#include "op-support.h"
42
#endif
43
 
44
extern void op_join_mem_cycles(void);
45
 
46
 
47
 
48
int except_pending = 0;
49
 
50
/* Asserts OR1K exception. */
51
/* WARNING: Don't expect except_handle to return.  Sometimes it _may_ return at
52
 * other times it may not. */
53
void
54
except_handle (oraddr_t except, oraddr_t ea)
55
{
56
  oraddr_t except_vector;
57
 
58
  if (debug_ignore_exception (except))
59
    return;
60
 
61
#if !(DYNAMIC_EXECUTION)
62
  /* In the dynamic recompiler, this function never returns, so this is not
63
   * needed.  Ofcourse we could set it anyway, but then all code that checks
64
   * this variable would break, since it is never reset */
65
  except_pending = 1;
66
#endif
67
 
68
  except_vector =
69
    except + (cpu_state.sprs[SPR_SR] & SPR_SR_EPH ? 0xf0000000 : 0x00000000);
70
 
71
#if !(DYNAMIC_EXECUTION)
72
  pcnext = except_vector;
73
#endif
74
 
75
  cpu_state.sprs[SPR_EEAR_BASE] = ea;
76
  cpu_state.sprs[SPR_ESR_BASE] = cpu_state.sprs[SPR_SR];
77
 
78
  cpu_state.sprs[SPR_SR] &= ~SPR_SR_OVE;        /* Disable overflow flag exception. */
79
 
80
  cpu_state.sprs[SPR_SR] |= SPR_SR_SM;  /* SUPV mode */
81
  cpu_state.sprs[SPR_SR] &= ~(SPR_SR_IEE | SPR_SR_TEE); /* Disable interrupts. */
82
 
83
  /* Address translation is always disabled when starting exception. */
84
  cpu_state.sprs[SPR_SR] &= ~SPR_SR_DME;
85
 
86
#if DYNAMIC_EXECUTION
87
  /* If we were called from do_scheduler and there were more jobs scheduled to
88
   * run after this, they won't run unless the following call is made since this
89
   * function never returns.  (If we weren't called from do_scheduler, then the
90
   * job at the head of the queue will still have some time remaining) */
91
  if (scheduler.job_queue->time <= 0)
92
    do_scheduler ();
93
#endif
94
 
95
  switch (except)
96
    {
97
      /* EPCR is irrelevent */
98
    case EXCEPT_RESET:
99
      break;
100
      /* EPCR is loaded with address of instruction that caused the exception */
101
    case EXCEPT_ITLBMISS:
102
    case EXCEPT_IPF:
103
      cpu_state.sprs[SPR_EPCR_BASE] = ea - (cpu_state.delay_insn ? 4 : 0);
104
#if DYNAMIC_EXECUTION
105
      op_join_mem_cycles ();
106
#endif
107
      break;
108
    case EXCEPT_BUSERR:
109
    case EXCEPT_DPF:
110
    case EXCEPT_ALIGN:
111
    case EXCEPT_ILLEGAL:
112
    case EXCEPT_DTLBMISS:
113
    case EXCEPT_RANGE:
114
    case EXCEPT_TRAP:
115
      /* All these exceptions happen during a simulated instruction */
116
#if DYNAMIC_EXECUTION
117
      /* Since these exceptions happen during a simulated instruction and this
118
       * function jumps out to the exception vector the scheduler would never have
119
       * a chance to run, therefore run it now */
120
      run_sched_out_of_line ();
121
#endif
122
      cpu_state.sprs[SPR_EPCR_BASE] =
123
        cpu_state.pc - (cpu_state.delay_insn ? 4 : 0);
124
      break;
125
      /* EPCR is loaded with address of next not-yet-executed instruction */
126
    case EXCEPT_SYSCALL:
127
      cpu_state.sprs[SPR_EPCR_BASE] =
128
        (cpu_state.pc + 4) - (cpu_state.delay_insn ? 4 : 0);
129
      break;
130
      /* These exceptions happen AFTER (or before) an instruction has been
131
       * simulated, therefore the pc already points to the *next* instruction */
132
    case EXCEPT_TICK:
133
    case EXCEPT_INT:
134
      cpu_state.sprs[SPR_EPCR_BASE] =
135
        cpu_state.pc - (cpu_state.delay_insn ? 4 : 0);
136
#if !(DYNAMIC_EXECUTION)
137
      /* If we don't update the pc now, then it will only happen *after* the next
138
       * instruction (There would be serious problems if the next instruction just
139
       * happens to be a branch), when it should happen NOW. */
140
      cpu_state.pc = pcnext;
141
      pcnext += 4;
142
#endif
143
      break;
144
    }
145
 
146
  /* Address trnaslation is here because run_sched_out_of_line calls
147
   * eval_insn_direct which checks out the immu for the address translation but
148
   * if it would be disabled above then there would be not much point... */
149
  cpu_state.sprs[SPR_SR] &= ~SPR_SR_IME;
150
 
151
  /* Complex/simple execution strictly don't need this because of the
152
   * next_delay_insn thingy but in the dynamic execution modell that doesn't
153
   * exist and thus cpu_state.delay_insn would stick in the exception handler
154
   * causeing grief if the first instruction of the exception handler is also in
155
   * the delay slot of the previous instruction */
156
  cpu_state.delay_insn = 0;
157
 
158
#if DYNAMIC_EXECUTION
159
  do_jump (except_vector);
160
#endif
161
}

powered by: WebSVN 2.1.0

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