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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_1_x/] [or1ksim/] [cpu/] [or1k/] [except.c] - Blame information for rev 1768

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
#include "sprs.h"
35 344 markom
#include "sim-config.h"
36 1308 phoenix
#include "debug_unit.h"
37 1350 nogj
#include "execute.h"
38 33 lampret
 
39
extern int cont_run;
40
extern struct iqueue_entry iqueue[20];
41 123 markom
extern unsigned long pc_phy;
42 51 lampret
extern struct iqueue_entry iqueue[];
43 33 lampret
 
44 82 lampret
extern int delay_insn;
45
 
46 437 simons
struct _pending pending;
47 139 chris
 
48 479 markom
/* Discards all pending exceptions */
49
void clear_pending_exception()
50 139 chris
{
51 479 markom
  pending.valid = 0;
52
  pending.type = 0;
53
  pending.address = 0;
54
  pending.saved = 0;
55 139 chris
}
56
 
57 479 markom
/* Asserts OR1K exception. */
58 1350 nogj
void except_handle(oraddr_t except, oraddr_t ea)
59 33 lampret
{
60 479 markom
  if(debug_ignore_exception (except)) {
61
    clear_pending_exception ();
62
  } else {
63
    pending.valid = 1;
64
    pending.type = except;
65
    pending.address = ea;
66
    if (delay_insn)
67
      pending.saved = pc - 4;
68
    else
69
      pending.saved = pc;
70 1350 nogj
    if (config.sim.verbose)
71
      PRINTF("Exception 0x%"PRIxADDR" (%s) at 0x%"PRIxADDR", EA: 0x%"PRIxADDR
72
             ", ppc: 0x%"PRIxADDR", npc: 0x%"PRIxADDR", cycles %lld, #%lld\n",
73
             except, EXCEPT_NAME(except), iqueue[0].insn_addr, ea, pc, pcnext,
74
             runtime.sim.cycles, runtime.cpu.instructions);
75 479 markom
  }
76 139 chris
}
77
 
78 479 markom
/* Actually handles exception */
79 1350 nogj
void except_handle_backend (oraddr_t except, oraddr_t ea, oraddr_t pc_saved)
80 139 chris
{
81 33 lampret
#if ONLY_VIRTUAL_MACHINE
82 479 markom
  fprintf(stderr, "WARNING: No exception processing while ONLY_VIRTUAL_MACHINE is defined.\n");
83
  cont_run = 0;
84 33 lampret
#else
85 51 lampret
 
86 479 markom
  if (delay_insn) {
87 997 markom
    if (config.sim.verbose) PRINTF("INFO: Exception during execution of delay slot insn.\n");
88 479 markom
    pc -= 4;
89
  }
90 693 markom
 
91 1350 nogj
  pc_saved = pc & ~ADDR_C(0x3);
92 458 simons
  if (except == EXCEPT_ILLEGAL)
93 556 markom
    mtspr(SPR_EPCR_BASE, pending.saved);
94 458 simons
  else if (except == EXCEPT_ALIGN)
95
    mtspr(SPR_EPCR_BASE, pending.saved);
96
  else if (except == EXCEPT_DTLBMISS)
97
    mtspr(SPR_EPCR_BASE, pending.saved);
98
  else if (except == EXCEPT_DPF)
99
    mtspr(SPR_EPCR_BASE, pending.saved);
100
  else if (except == EXCEPT_BUSERR)
101
    mtspr(SPR_EPCR_BASE, pending.saved);
102
  else if (except == EXCEPT_TRAP)
103
    mtspr(SPR_EPCR_BASE, pending.saved);
104
  else if (except == EXCEPT_RANGE)
105
    mtspr(SPR_EPCR_BASE, pending.saved);
106 572 simons
  else if (except == EXCEPT_ITLBMISS)
107
    mtspr(SPR_EPCR_BASE, pending.saved);
108
  else if (except == EXCEPT_IPF)
109
    mtspr(SPR_EPCR_BASE, pending.saved);
110 458 simons
  else
111 479 markom
    mtspr(SPR_EPCR_BASE, pc_saved);
112 458 simons
 
113 479 markom
  mtspr(SPR_EEAR_BASE, ea);
114
  mtspr(SPR_ESR_BASE, mfspr(SPR_SR));
115 64 lampret
 
116 479 markom
  /* Address translation is always disabled when starting exception. */
117
  mtspr(SPR_SR, mfspr(SPR_SR) & ~(SPR_SR_DME));
118
  mtspr(SPR_SR, mfspr(SPR_SR) & ~(SPR_SR_IME));
119 64 lampret
 
120 479 markom
  mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_OVE);   /* Disable overflow flag exception. */
121 458 simons
 
122 599 simons
  mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_SM);     /* SUPV mode */
123
  mtspr(SPR_SR, mfspr(SPR_SR) & ~(SPR_SR_IEE | SPR_SR_TEE));    /* Disable interrupts. */
124 167 markom
 
125 479 markom
  clear_pending_exception ();
126 458 simons
 
127 599 simons
  pc = (unsigned long)except + (testsprbits (SPR_SR, SPR_SR_EPH) ? 0xf0000000 : 0x00000000);
128 556 markom
 
129 479 markom
  /* This has been removed. All exceptions (not just SYSCALL) suffer
130
     from the same problem. The solution is to continue just like
131
     the pipeline would, and issue the exception on the next
132
     clock cycle. We assume now that this function is being called
133
     ->BEFORE<- the instruction fetch and after the previous update
134
     which always yields the correct behavior. This has the added
135
     advantage that a debugger can prevent an exception from
136
     taking place by resetting the pc. */
137 139 chris
#if 0
138 479 markom
  /* MM: We do pc update after the execute (in the simulator), so we
139
     decrease it by 4 so that next instruction points to first exception
140
     instruction.  Do NOT comment this out. */
141
  if (except == EXCEPT_SYSCALL)
142
    pc -= 4;
143 139 chris
#endif
144 479 markom
  pcnext = pc + 4;
145 123 markom
 
146 479 markom
  /* Added by CZ 27/05/01 */
147
  pc_phy = pc;      /* An exception always turns off the MMU, so
148
           pc is always pc_phy */
149 139 chris
 
150 556 markom
#endif /* !ONLY_VIRUAL_MACHINE */
151 33 lampret
}

powered by: WebSVN 2.1.0

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