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

Subversion Repositories or1k

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

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

powered by: WebSVN 2.1.0

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