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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_62/] [or1ksim/] [cpu/] [or1k/] [except.c] - Blame information for rev 572

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

powered by: WebSVN 2.1.0

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