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

Subversion Repositories or1k

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

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

Line No. Rev Author Line
1 33 lampret
/* except.c -- Simulation of OR1K exceptions
2
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
3
 
4
This file is part of OpenRISC 1000 Architectural Simulator.
5
 
6
This program is free software; you can redistribute it and/or modify
7
it under the terms of the GNU General Public License as published by
8
the Free Software Foundation; either version 2 of the License, or
9
(at your option) any later version.
10
 
11
This program is distributed in the hope that it will be useful,
12
but WITHOUT ANY WARRANTY; without even the implied warranty of
13
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
GNU General Public License for more details.
15
 
16
You should have received a copy of the GNU General Public License
17
along with this program; if not, write to the Free Software
18
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
19
 
20
#include <stdlib.h>
21
#include <stdio.h>
22
#include <string.h>
23
 
24 1350 nogj
#include "config.h"
25
 
26
#ifdef HAVE_INTTYPES_H
27
#include <inttypes.h>
28
#endif
29
 
30
#include "port.h"
31
#include "arch.h"
32 33 lampret
#include "abstract.h"
33
#include "except.h"
34 344 markom
#include "sim-config.h"
35 1308 phoenix
#include "debug_unit.h"
36 1432 nogj
#include "opcode/or32.h"
37
#include "spr_defs.h"
38 1350 nogj
#include "execute.h"
39 1432 nogj
#include "sprs.h"
40 1510 nogj
#include "debug.h"
41 33 lampret
 
42 1452 nogj
#if DYNAMIC_EXECUTION
43
#include "sched.h"
44
#include "op_support.h"
45
#endif
46
 
47 1510 nogj
DEFAULT_DEBUG_CHANNEL(except);
48 82 lampret
 
49 1386 nogj
int except_pending = 0;
50 139 chris
 
51 1386 nogj
static const char *except_names[] = {
52
 NULL,
53
 "Reset",
54
 "Bus Error",
55
 "Data Page Fault",
56
 "Insn Page Fault",
57
 "Tick timer",
58
 "Alignment",
59
 "Illegal instruction",
60
 "Interrupt",
61
 "Data TLB Miss",
62
 "Insn TLB Miss",
63
 "Range",
64
 "System Call",
65 1585 phoenix
 "Floating Point",
66 1386 nogj
 "Trap" };
67
 
68 1452 nogj
const char *except_name(oraddr_t except)
69 139 chris
{
70 1386 nogj
  return except_names[except >> 8];
71 139 chris
}
72
 
73 479 markom
/* Asserts OR1K exception. */
74 1473 nogj
/* WARNING: Don't excpect except_handle to return.  Sometimes it _may_ return at
75
 * other times it may not. */
76 1350 nogj
void except_handle(oraddr_t except, oraddr_t ea)
77 33 lampret
{
78 1452 nogj
  oraddr_t except_vector;
79
 
80 1386 nogj
  if(debug_ignore_exception (except))
81
    return;
82 139 chris
 
83 1452 nogj
#if !(DYNAMIC_EXECUTION)
84
  /* In the dynamic recompiler, this function never returns, so this is not
85
   * needed.  Ofcourse we could set it anyway, but then all code that checks
86
   * this variable would break, since it is never reset */
87 1386 nogj
  except_pending = 1;
88 1452 nogj
#endif
89 51 lampret
 
90 1510 nogj
  TRACE("Exception 0x%"PRIxADDR" (%s) at 0x%"PRIxADDR", EA: 0x%"PRIxADDR
91
        ", cycles %lld, #%lld\n",
92
        except, except_name(except), cpu_state.pc, ea, runtime.sim.cycles,
93
        runtime.cpu.instructions);
94 1386 nogj
 
95 1506 nogj
  except_vector = except + (cpu_state.sprs[SPR_SR] & SPR_SR_EPH ? 0xf0000000 : 0x00000000);
96 1386 nogj
 
97 1452 nogj
#if !(DYNAMIC_EXECUTION)
98
  pcnext = except_vector;
99
#endif
100
 
101 1442 nogj
  cpu_state.sprs[SPR_EEAR_BASE] =  ea;
102
  cpu_state.sprs[SPR_ESR_BASE] = cpu_state.sprs[SPR_SR];
103
 
104
  cpu_state.sprs[SPR_SR] &= ~SPR_SR_OVE;   /* Disable overflow flag exception. */
105
 
106
  cpu_state.sprs[SPR_SR] |= SPR_SR_SM;    /* SUPV mode */
107
  cpu_state.sprs[SPR_SR] &= ~(SPR_SR_IEE | SPR_SR_TEE);   /* Disable interrupts. */
108
 
109
  /* Address translation is always disabled when starting exception. */
110
  cpu_state.sprs[SPR_SR] &= ~SPR_SR_DME;
111
 
112 1452 nogj
#if DYNAMIC_EXECUTION
113
  /* If we were called from do_scheduler and there were more jobs scheduled to
114
   * run after this, they won't run unless the following call is made since this
115
   * function never returns.  (If we weren't called from do_scheduler, then the
116
   * job at the head of the queue will still have some time remaining) */
117
  if(scheduler.job_queue->time <= 0)
118
    do_scheduler();
119
#endif
120
 
121 1386 nogj
  switch(except) {
122
  /* EPCR is irrelevent */
123
  case EXCEPT_RESET:
124
    break;
125
  /* EPCR is loaded with address of instruction that caused the exception */
126 1452 nogj
  case EXCEPT_ITLBMISS:
127
  case EXCEPT_IPF:
128 1686 nogj
    cpu_state.sprs[SPR_EPCR_BASE] = ea - (cpu_state.delay_insn ? 4 : 0);
129 1452 nogj
#if DYNAMIC_EXECUTION
130 1686 nogj
    op_join_mem_cycles();
131
#endif
132 1481 nogj
    break;
133 1386 nogj
  case EXCEPT_BUSERR:
134
  case EXCEPT_DPF:
135
  case EXCEPT_ALIGN:
136
  case EXCEPT_ILLEGAL:
137
  case EXCEPT_DTLBMISS:
138
  case EXCEPT_RANGE:
139
  case EXCEPT_TRAP:
140 1686 nogj
    /* All these exceptions happen during a simulated instruction */
141 1452 nogj
#if DYNAMIC_EXECUTION
142
    /* Since these exceptions happen during a simulated instruction and this
143
     * function jumps out to the exception vector the scheduler would never have
144
     * a chance to run, therefore run it now */
145 1686 nogj
    run_sched_out_of_line();
146 1452 nogj
#endif
147 1508 nogj
    cpu_state.sprs[SPR_EPCR_BASE] = cpu_state.pc - (cpu_state.delay_insn ? 4 : 0);
148 1386 nogj
    break;
149
  /* EPCR is loaded with address of next not-yet-executed instruction */
150
  case EXCEPT_SYSCALL:
151 1508 nogj
    cpu_state.sprs[SPR_EPCR_BASE] = (cpu_state.pc + 4) - (cpu_state.delay_insn ? 4 : 0);
152 1386 nogj
    break;
153
  /* These exceptions happen AFTER (or before) an instruction has been
154
   * simulated, therefore the pc already points to the *next* instruction */
155
  case EXCEPT_TICK:
156
  case EXCEPT_INT:
157 1508 nogj
    cpu_state.sprs[SPR_EPCR_BASE] = cpu_state.pc - (cpu_state.delay_insn ? 4 : 0);
158 1452 nogj
#if !(DYNAMIC_EXECUTION)
159 1386 nogj
    /* If we don't update the pc now, then it will only happen *after* the next
160
     * instruction (There would be serious problems if the next instruction just
161
     * happens to be a branch), when it should happen NOW. */
162 1432 nogj
    cpu_state.pc = pcnext;
163 1386 nogj
    pcnext += 4;
164 1452 nogj
#endif
165 1386 nogj
    break;
166 479 markom
  }
167 693 markom
 
168 1452 nogj
  /* Address trnaslation is here because run_sched_out_of_line calls
169
   * eval_insn_direct which checks out the immu for the address translation but
170
   * if it would be disabled above then there would be not much point... */
171
  cpu_state.sprs[SPR_SR] &= ~SPR_SR_IME;
172
 
173
  /* Complex/simple execution strictly don't need this because of the
174
   * next_delay_insn thingy but in the dynamic execution modell that doesn't
175 1481 nogj
   * exist and thus cpu_state.delay_insn would stick in the exception handler
176 1452 nogj
   * causeing grief if the first instruction of the exception handler is also in
177
   * the delay slot of the previous instruction */
178 1432 nogj
  cpu_state.delay_insn = 0;
179 1452 nogj
 
180
#if DYNAMIC_EXECUTION
181 1692 nogj
  do_jump(except_vector);
182 1452 nogj
#endif
183 33 lampret
}

powered by: WebSVN 2.1.0

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