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 64

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
extern unsigned long pctemp;
32 51 lampret
extern struct iqueue_entry iqueue[];
33 33 lampret
 
34
/* Handle OR1K exceptions. */
35
void except_handle(int except, unsigned long ea)
36
{
37 43 lampret
        unsigned long pc_saved;
38 51 lampret
 
39
        printf("Exception 0x%x (%s): ", except, EXCEPT_NAME(except));
40
        printf("Iqueue[0].insn_addr: 0x%x  Eff ADDR: 0x%x\n",  iqueue[0].insn_addr, ea);
41
        printf("  pctemp: 0x%x  pc: 0x%x\n",  pctemp, pc);
42 64 lampret
 
43 33 lampret
#if ONLY_VIRTUAL_MACHINE
44 51 lampret
        printf("WARNING: No exception processing while ONLY_VIRTUAL_MACHINE is defined.\n");
45
        cont_run = 0;
46 33 lampret
#else
47 51 lampret
 
48
        if (pctemp != (pc + 4)) {       /* Always execute delay slot insn */
49
                fetch();                /* before starting with exception.*/
50
                decode(&iqueue[0]);
51
                execute();
52
        }
53 64 lampret
 
54 33 lampret
        if (!(mfspr(SPR_SR) & SPR_SR_EXR)) {
55 51 lampret
                printf("ABORT: Exception occured while exception detection was disabled.\n");
56 33 lampret
                cont_run = 0;
57
                return;
58
        }
59 51 lampret
 
60 64 lampret
        pc_saved = pc & ~0x3;
61 51 lampret
        mtspr(SPR_EPCR_BASE, pc_saved);
62 33 lampret
        mtspr(SPR_EEAR_BASE, ea);
63 64 lampret
        mtspr(SPR_ESR_BASE, mfspr(SPR_SR));
64
 
65
        /* Address translation is always disabled when starting exception. */
66
        mtspr(SPR_SR, mfspr(SPR_SR) & ~(SPR_SR_DME));
67
        mtspr(SPR_SR, mfspr(SPR_SR) & ~(SPR_SR_IME));
68
 
69 33 lampret
        mtspr(SPR_SR, mfspr(SPR_SR) | SPR_SR_SUPV);     /* SUPV mode */
70 51 lampret
        mtspr(SPR_SR, mfspr(SPR_SR) & ~SPR_SR_EXR);     /* Disable except. */
71 33 lampret
        pc = (unsigned long)except;
72
        pctemp = (unsigned long)except;
73
#endif
74
}

powered by: WebSVN 2.1.0

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