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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_47/] [or1ksim/] [cpu/] [or1k/] [except.c] - Blame information for rev 1782

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 82 lampret
extern int delay_insn;
40 1386 nogj
extern oraddr_t pcprev;
41
extern oraddr_t pcdelay;
42 82 lampret
 
43 1386 nogj
int except_pending = 0;
44 139 chris
 
45 1386 nogj
static const char *except_names[] = {
46
 NULL,
47
 "Reset",
48
 "Bus Error",
49
 "Data Page Fault",
50
 "Insn Page Fault",
51
 "Tick timer",
52
 "Alignment",
53
 "Illegal instruction",
54
 "Interrupt",
55
 "Data TLB Miss",
56
 "Insn TLB Miss",
57
 "Range",
58
 "System Call",
59
 "Trap" };
60
 
61
static const char *except_name(oraddr_t except)
62 139 chris
{
63 1386 nogj
  return except_names[except >> 8];
64 139 chris
}
65
 
66 479 markom
/* Asserts OR1K exception. */
67 1350 nogj
void except_handle(oraddr_t except, oraddr_t ea)
68 33 lampret
{
69 1386 nogj
  if(debug_ignore_exception (except))
70
    return;
71 139 chris
 
72 1386 nogj
  except_pending = 1;
73 51 lampret
 
74 1386 nogj
  if (config.sim.verbose)
75
    PRINTF("Exception 0x%"PRIxADDR" (%s) at 0x%"PRIxADDR", EA: 0x%"PRIxADDR
76
           ", ppc: 0x%"PRIxADDR", npc: 0x%"PRIxADDR", dpc: 0x%"PRIxADDR
77
           ", cycles %lld, #%lld\n",
78
           except, except_name(except), pcprev, ea, pc, pcnext, pcdelay,
79
           runtime.sim.cycles, runtime.cpu.instructions);
80
 
81
  pcnext = except + (testsprbits (SPR_SR, SPR_SR_EPH) ? 0xf0000000 : 0x00000000);
82
 
83
  switch(except) {
84
  /* EPCR is irrelevent */
85
  case EXCEPT_RESET:
86
    break;
87
  /* EPCR is loaded with address of instruction that caused the exception */
88
  /* All these exceptions happen during a simulated instruction */
89
  case EXCEPT_BUSERR:
90
  case EXCEPT_DPF:
91
  case EXCEPT_IPF:
92
  case EXCEPT_ALIGN:
93
  case EXCEPT_ILLEGAL:
94
  case EXCEPT_DTLBMISS:
95
  case EXCEPT_ITLBMISS:
96
  case EXCEPT_RANGE:
97
  case EXCEPT_TRAP:
98
    mtspr(SPR_EPCR_BASE, pc - (delay_insn ? 4 : 0));
99
    break;
100
  /* EPCR is loaded with address of next not-yet-executed instruction */
101
  case EXCEPT_SYSCALL:
102
    mtspr(SPR_EPCR_BASE, (pc + 4) - (delay_insn ? 4 : 0));
103
    break;
104
  /* These exceptions happen AFTER (or before) an instruction has been
105
   * simulated, therefore the pc already points to the *next* instruction */
106
  case EXCEPT_TICK:
107
  case EXCEPT_INT:
108
    mtspr(SPR_EPCR_BASE, pc - (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
    pc = pcnext;
113
    pcnext += 4;
114
    break;
115 479 markom
  }
116 693 markom
 
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 599 simons
  mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_SM);     /* SUPV mode */
127
  mtspr(SPR_SR, mfspr(SPR_SR) & ~(SPR_SR_IEE | SPR_SR_TEE));    /* Disable interrupts. */
128 167 markom
 
129 1386 nogj
  delay_insn = 0;
130 33 lampret
}

powered by: WebSVN 2.1.0

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