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

Subversion Repositories or1k

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

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 33 lampret
 
41 1386 nogj
extern oraddr_t pcprev;
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 1432 nogj
           except, except_name(except), pcprev, ea, cpu_state.pc, pcnext,
79
           cpu_state.pc_delay, runtime.sim.cycles, runtime.cpu.instructions);
80 1386 nogj
 
81
  pcnext = except + (testsprbits (SPR_SR, SPR_SR_EPH) ? 0xf0000000 : 0x00000000);
82
 
83 1442 nogj
  cpu_state.sprs[SPR_EEAR_BASE] =  ea;
84
  cpu_state.sprs[SPR_ESR_BASE] = cpu_state.sprs[SPR_SR];
85
 
86
  cpu_state.sprs[SPR_SR] &= ~SPR_SR_OVE;   /* Disable overflow flag exception. */
87
 
88
  cpu_state.sprs[SPR_SR] |= SPR_SR_SM;    /* SUPV mode */
89
  cpu_state.sprs[SPR_SR] &= ~(SPR_SR_IEE | SPR_SR_TEE);   /* Disable interrupts. */
90
 
91
  /* Address translation is always disabled when starting exception. */
92
  cpu_state.sprs[SPR_SR] &= ~SPR_SR_DME;
93
  cpu_state.sprs[SPR_SR] &= ~SPR_SR_IME;
94
 
95 1386 nogj
  switch(except) {
96
  /* EPCR is irrelevent */
97
  case EXCEPT_RESET:
98
    break;
99
  /* EPCR is loaded with address of instruction that caused the exception */
100
  /* All these exceptions happen during a simulated instruction */
101
  case EXCEPT_BUSERR:
102
  case EXCEPT_DPF:
103
  case EXCEPT_IPF:
104
  case EXCEPT_ALIGN:
105
  case EXCEPT_ILLEGAL:
106
  case EXCEPT_DTLBMISS:
107
  case EXCEPT_ITLBMISS:
108
  case EXCEPT_RANGE:
109
  case EXCEPT_TRAP:
110 1432 nogj
    mtspr(SPR_EPCR_BASE, cpu_state.pc - (cpu_state.delay_insn ? 4 : 0));
111 1386 nogj
    break;
112
  /* EPCR is loaded with address of next not-yet-executed instruction */
113
  case EXCEPT_SYSCALL:
114 1432 nogj
    mtspr(SPR_EPCR_BASE, (cpu_state.pc + 4) - (cpu_state.delay_insn ? 4 : 0));
115 1386 nogj
    break;
116
  /* These exceptions happen AFTER (or before) an instruction has been
117
   * simulated, therefore the pc already points to the *next* instruction */
118
  case EXCEPT_TICK:
119
  case EXCEPT_INT:
120 1432 nogj
    mtspr(SPR_EPCR_BASE, cpu_state.pc - (cpu_state.delay_insn ? 4 : 0));
121 1386 nogj
    /* If we don't update the pc now, then it will only happen *after* the next
122
     * instruction (There would be serious problems if the next instruction just
123
     * happens to be a branch), when it should happen NOW. */
124 1432 nogj
    cpu_state.pc = pcnext;
125 1386 nogj
    pcnext += 4;
126
    break;
127 479 markom
  }
128 693 markom
 
129 1432 nogj
  cpu_state.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.