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

Subversion Repositories or1k

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

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 102 lampret
/* pic.c -- Simulation of OpenRISC 1000 programmable interrupt controller
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
/* This is functional simulation of OpenRISC 1000 architectural
21
   programmable interrupt controller.
22
*/
23
 
24
#include <stdlib.h>
25
#include <stdio.h>
26
#include <string.h>
27
 
28 1350 nogj
#include "config.h"
29
 
30
#ifdef HAVE_INTTYPES_H
31
#include <inttypes.h>
32
#endif
33
 
34
#include "port.h"
35
#include "arch.h"
36
#include "abstract.h"
37 102 lampret
#include "pic.h"
38
#include "spr_defs.h"
39
#include "except.h"
40 167 markom
#include "sprs.h"
41 1308 phoenix
#include "debug.h"
42 1387 nogj
#include "sched.h"
43 102 lampret
 
44
extern int cont_run;
45
 
46
/* Reset. It initializes PIC registers. */
47
void pic_reset()
48
{
49 997 markom
  PRINTF("Resetting PIC.\n");
50 409 markom
  mtspr(SPR_PICMR, 0);
51
  mtspr(SPR_PICPR, 0);
52
  mtspr(SPR_PICSR, 0);
53 102 lampret
}
54
 
55 1387 nogj
/* Simulation hook.  Called when interrupts are masked. */
56
void pic_clock(int i)
57 102 lampret
{
58 1387 nogj
  /* Don't do anything if interrupts not currently enabled */
59
  if(testsprbits (SPR_SR, SPR_SR_IEE))
60 611 simons
    except_handle(EXCEPT_INT, mfspr(SPR_EEAR_BASE));
61 1387 nogj
  else
62
    SCHED_ADD(pic_clock, 0, 1);
63 102 lampret
}
64
 
65 1387 nogj
/* WARNING: Don't eaven try and call this function *during* a simulated
66
 * instruction!! (as in during a read_mem or write_mem callback).  except_handle
67
 * assumes that this is the case, it breaks otherwise. */
68 102 lampret
/* Asserts interrupt to the PIC. */
69
void report_interrupt(int line)
70
{
71 409 markom
  setsprbits(SPR_PMR, SPR_PMR_DME, 0); /* Disable doze mode */
72
  setsprbits(SPR_PMR, SPR_PMR_SME, 0); /* Disable sleep mode */
73 102 lampret
 
74 1308 phoenix
  debug(4, "Asserting interrupt %d (%s).\n", line, getsprbit(SPR_PICMR, line) ? "Unmasked" : "Masked");
75 409 markom
 
76 1387 nogj
  if (getsprbit(SPR_PICMR, line) || line < 2) {
77 1308 phoenix
    setsprbit(SPR_PICSR, line, 1);
78 1387 nogj
    /* Don't do anything if interrupts not currently enabled */
79
    if (testsprbits (SPR_SR, SPR_SR_IEE))
80
      except_handle(EXCEPT_INT, mfspr(SPR_EEAR_BASE));
81
    else
82
      /* Interrupts not currently enabled, retry next clock cycle */
83
      SCHED_ADD(pic_clock, 0, runtime.sim.cycles + 1);
84
  }
85 102 lampret
}

powered by: WebSVN 2.1.0

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