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 133

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
 
28
extern int cont_run;
29
extern struct iqueue_entry iqueue[20];
30
extern unsigned long pc;
31 82 lampret
extern unsigned long pcnext;
32 123 markom
extern unsigned long pc_phy;
33 51 lampret
extern struct iqueue_entry iqueue[];
34 33 lampret
 
35 82 lampret
extern int delay_insn;
36 123 markom
int cycle_delay = 0;  /* Added by CZ 27/05/01 */
37 82 lampret
 
38 33 lampret
/* Handle OR1K exceptions. */
39
void except_handle(int except, unsigned long ea)
40
{
41 43 lampret
        unsigned long pc_saved;
42 51 lampret
 
43
        printf("Exception 0x%x (%s): ", except, EXCEPT_NAME(except));
44
        printf("Iqueue[0].insn_addr: 0x%x  Eff ADDR: 0x%x\n",  iqueue[0].insn_addr, ea);
45 82 lampret
        printf("  pc: 0x%x  pcnext: 0x%x\n",  pc, pcnext);
46 64 lampret
 
47 33 lampret
#if ONLY_VIRTUAL_MACHINE
48 51 lampret
        printf("WARNING: No exception processing while ONLY_VIRTUAL_MACHINE is defined.\n");
49
        cont_run = 0;
50 33 lampret
#else
51 51 lampret
 
52 82 lampret
        if (delay_insn) {
53
                printf(" INFO: Exception during execution of delay slot insn.\n");
54
                pc -= 4;
55
        }
56
#if 0
57
        if ((pcnext != (pc + 4)) && (except != EXCEPT_ITLBMISS)) {      /* Always execute delay slot insn */
58
                printf("XXXXXXXXXXXXXX\n");
59 77 lampret
                fetch();                                                /* before starting with exception */
60
                decode(&iqueue[0]);                                      /* (itlbmiss is special case) */
61 51 lampret
                execute();
62
        }
63 82 lampret
#endif
64 64 lampret
 
65 33 lampret
        if (!(mfspr(SPR_SR) & SPR_SR_EXR)) {
66 51 lampret
                printf("ABORT: Exception occured while exception detection was disabled.\n");
67 33 lampret
                cont_run = 0;
68
                return;
69
        }
70 123 markom
 
71 64 lampret
        pc_saved = pc & ~0x3;
72 51 lampret
        mtspr(SPR_EPCR_BASE, pc_saved);
73 33 lampret
        mtspr(SPR_EEAR_BASE, ea);
74 64 lampret
        mtspr(SPR_ESR_BASE, mfspr(SPR_SR));
75
 
76
        /* Address translation is always disabled when starting exception. */
77
        mtspr(SPR_SR, mfspr(SPR_SR) & ~(SPR_SR_DME));
78
        mtspr(SPR_SR, mfspr(SPR_SR) & ~(SPR_SR_IME));
79
 
80 33 lampret
        mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_SUPV);     /* SUPV mode */
81 51 lampret
        mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_EXR);     /* Disable except. */
82 33 lampret
        pc = (unsigned long)except;
83 123 markom
 
84
        /* MM: We do pc update after the execute (in the simulator), so we
85
           decrease it by 4 so that next instruction points to first exception
86
           instruction. */
87
        if (except == EXCEPT_SYSCALL)
88
          pc -= 4;
89
        pcnext = pc+4;
90
 
91
        /* Added by CZ 27/05/01 */
92
        pc_phy = pc;
93 133 markom
        cycle_delay = 7;  /* An exception stalls the CPU 7 clock cycles */
94 33 lampret
#endif
95
}

powered by: WebSVN 2.1.0

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