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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel-0-3-0-rc3/] [or1ksim/] [cpu/] [or1k/] [except.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 33 lampret
/* except.c -- Simulation of OR1K exceptions
2 1748 jeremybenn
 
3 33 lampret
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
4 1748 jeremybenn
   Copyright (C) 2008 Embecosm Limited
5 33 lampret
 
6 1748 jeremybenn
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
7 33 lampret
 
8 1748 jeremybenn
   This file is part of Or1ksim, the OpenRISC 1000 Architectural Simulator.
9 33 lampret
 
10 1748 jeremybenn
   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 33 lampret
 
15 1748 jeremybenn
   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 33 lampret
 
20 1748 jeremybenn
   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 33 lampret
 
23 1748 jeremybenn
/* This program is commented throughout in a fashion suitable for processing
24
   with Doxygen. */
25
 
26
 
27
/* Autoconf and/or portability configuration */
28 1350 nogj
#include "config.h"
29
 
30 1748 jeremybenn
/* Package includes */
31 33 lampret
#include "except.h"
32 344 markom
#include "sim-config.h"
33 1748 jeremybenn
#include "arch.h"
34
#include "debug.h"
35
#include "spr-defs.h"
36 1350 nogj
#include "execute.h"
37 1748 jeremybenn
#include "debug-unit.h"
38 33 lampret
 
39 1452 nogj
#if DYNAMIC_EXECUTION
40
#include "sched.h"
41 1751 jeremybenn
#include "op-support.h"
42 1452 nogj
#endif
43
 
44 1751 jeremybenn
extern void op_join_mem_cycles(void);
45 82 lampret
 
46 1748 jeremybenn
 
47 1751 jeremybenn
 
48 1386 nogj
int except_pending = 0;
49 139 chris
 
50 479 markom
/* Asserts OR1K exception. */
51 1751 jeremybenn
/* WARNING: Don't expect except_handle to return.  Sometimes it _may_ return at
52 1473 nogj
 * other times it may not. */
53 1748 jeremybenn
void
54
except_handle (oraddr_t except, oraddr_t ea)
55 33 lampret
{
56 1452 nogj
  oraddr_t except_vector;
57
 
58 1748 jeremybenn
  if (debug_ignore_exception (except))
59 1386 nogj
    return;
60 139 chris
 
61 1452 nogj
#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 1386 nogj
  except_pending = 1;
66 1452 nogj
#endif
67 51 lampret
 
68 1748 jeremybenn
  except_vector =
69
    except + (cpu_state.sprs[SPR_SR] & SPR_SR_EPH ? 0xf0000000 : 0x00000000);
70 1386 nogj
 
71 1452 nogj
#if !(DYNAMIC_EXECUTION)
72
  pcnext = except_vector;
73
#endif
74
 
75 1748 jeremybenn
  cpu_state.sprs[SPR_EEAR_BASE] = ea;
76 1442 nogj
  cpu_state.sprs[SPR_ESR_BASE] = cpu_state.sprs[SPR_SR];
77
 
78 1748 jeremybenn
  cpu_state.sprs[SPR_SR] &= ~SPR_SR_OVE;        /* Disable overflow flag exception. */
79 1442 nogj
 
80 1748 jeremybenn
  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 1442 nogj
 
83
  /* Address translation is always disabled when starting exception. */
84
  cpu_state.sprs[SPR_SR] &= ~SPR_SR_DME;
85
 
86 1452 nogj
#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 1748 jeremybenn
  if (scheduler.job_queue->time <= 0)
92
    do_scheduler ();
93 1452 nogj
#endif
94
 
95 1748 jeremybenn
  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 1452 nogj
#if DYNAMIC_EXECUTION
105 1748 jeremybenn
      op_join_mem_cycles ();
106 1686 nogj
#endif
107 1748 jeremybenn
      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 1452 nogj
#if DYNAMIC_EXECUTION
117 1748 jeremybenn
      /* 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 1452 nogj
#endif
122 1748 jeremybenn
      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 1452 nogj
#if !(DYNAMIC_EXECUTION)
137 1748 jeremybenn
      /* 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 1452 nogj
#endif
143 1748 jeremybenn
      break;
144
    }
145 693 markom
 
146 1452 nogj
  /* 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 1481 nogj
   * exist and thus cpu_state.delay_insn would stick in the exception handler
154 1452 nogj
   * causeing grief if the first instruction of the exception handler is also in
155
   * the delay slot of the previous instruction */
156 1432 nogj
  cpu_state.delay_insn = 0;
157 1452 nogj
 
158
#if DYNAMIC_EXECUTION
159 1748 jeremybenn
  do_jump (except_vector);
160 1452 nogj
#endif
161 33 lampret
}

powered by: WebSVN 2.1.0

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