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

Subversion Repositories openrisc

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

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
extern void op_join_mem_cycles(void);
40
 
41
 
42
 
43
int except_pending = 0;
44
 
45
/* Asserts OR1K exception. */
46
/* WARNING: Don't expect except_handle to return.  Sometimes it _may_ return at
47
 * other times it may not. */
48
void
49
except_handle (oraddr_t except, oraddr_t ea)
50
{
51
  oraddr_t except_vector;
52
 
53
  if (debug_ignore_exception (except))
54
    return;
55
 
56
  /* In the dynamic recompiler, this function never returns, so this is not
57
   * needed.  Ofcourse we could set it anyway, but then all code that checks
58
   * this variable would break, since it is never reset */
59
  except_pending = 1;
60
 
61
  except_vector =
62
    except + (cpu_state.sprs[SPR_SR] & SPR_SR_EPH ? 0xf0000000 : 0x00000000);
63
 
64
  pcnext = except_vector;
65
 
66
  cpu_state.sprs[SPR_EEAR_BASE] = ea;
67
  cpu_state.sprs[SPR_ESR_BASE] = cpu_state.sprs[SPR_SR];
68
 
69
  cpu_state.sprs[SPR_SR] &= ~SPR_SR_OVE;        /* Disable overflow flag exception. */
70
 
71
  cpu_state.sprs[SPR_SR] |= SPR_SR_SM;  /* SUPV mode */
72
  cpu_state.sprs[SPR_SR] &= ~(SPR_SR_IEE | SPR_SR_TEE); /* Disable interrupts. */
73
 
74
  /* Address translation is always disabled when starting exception. */
75
  cpu_state.sprs[SPR_SR] &= ~SPR_SR_DME;
76
 
77
  switch (except)
78
    {
79
      /* EPCR is irrelevent */
80
    case EXCEPT_RESET:
81
      break;
82
      /* EPCR is loaded with address of instruction that caused the exception */
83
    case EXCEPT_ITLBMISS:
84
    case EXCEPT_IPF:
85
      cpu_state.sprs[SPR_EPCR_BASE] = ea - (cpu_state.delay_insn ? 4 : 0);
86
      break;
87
    case EXCEPT_BUSERR:
88
    case EXCEPT_DPF:
89
    case EXCEPT_ALIGN:
90
    case EXCEPT_ILLEGAL:
91
    case EXCEPT_DTLBMISS:
92
    case EXCEPT_RANGE:
93
    case EXCEPT_TRAP:
94
      /* All these exceptions happen during a simulated instruction */
95
      cpu_state.sprs[SPR_EPCR_BASE] =
96
        cpu_state.pc - (cpu_state.delay_insn ? 4 : 0);
97
      break;
98
      /* EPCR is loaded with address of next not-yet-executed instruction */
99
    case EXCEPT_SYSCALL:
100
      cpu_state.sprs[SPR_EPCR_BASE] =
101
        (cpu_state.pc + 4) - (cpu_state.delay_insn ? 4 : 0);
102
      break;
103
      /* These exceptions happen AFTER (or before) an instruction has been
104
       * simulated, therefore the pc already points to the *next* instruction */
105
    case EXCEPT_TICK:
106
    case EXCEPT_INT:
107
      cpu_state.sprs[SPR_EPCR_BASE] =
108
        cpu_state.pc - (cpu_state.delay_insn ? 4 : 0);
109
      /* If we don't update the pc now, then it will only happen *after* the next
110
       * instruction (There would be serious problems if the next instruction just
111
       * happens to be a branch), when it should happen NOW. */
112
      cpu_state.pc = pcnext;
113
      pcnext += 4;
114
      break;
115
    }
116
 
117
  /* Address trnaslation is here because run_sched_out_of_line calls
118
   * eval_insn_direct which checks out the immu for the address translation but
119
   * if it would be disabled above then there would be not much point... */
120
  cpu_state.sprs[SPR_SR] &= ~SPR_SR_IME;
121
 
122
  /* Complex/simple execution strictly don't need this because of the
123
   * next_delay_insn thingy but in the dynamic execution modell that doesn't
124
   * exist and thus cpu_state.delay_insn would stick in the exception handler
125
   * causeing grief if the first instruction of the exception handler is also in
126
   * the delay slot of the previous instruction */
127
  cpu_state.delay_insn = 0;
128
 
129
}

powered by: WebSVN 2.1.0

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