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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_52/] [or1ksim/] [pic/] [pic.c] - Blame information for rev 1765

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 1426 nogj
#include "sched.h"
42 1308 phoenix
#include "debug.h"
43 102 lampret
 
44
extern int cont_run;
45 1426 nogj
DEFAULT_DEBUG_CHANNEL(pic);
46 102 lampret
 
47
/* Reset. It initializes PIC registers. */
48
void pic_reset()
49
{
50 997 markom
  PRINTF("Resetting PIC.\n");
51 409 markom
  mtspr(SPR_PICMR, 0);
52
  mtspr(SPR_PICPR, 0);
53
  mtspr(SPR_PICSR, 0);
54 102 lampret
}
55
 
56 1426 nogj
/* Handles the reporting of an interrupt if it had to be delayed */
57
void pic_clock(void *dat)
58 102 lampret
{
59 1387 nogj
  /* Don't do anything if interrupts not currently enabled */
60
  if(testsprbits (SPR_SR, SPR_SR_IEE))
61 611 simons
    except_handle(EXCEPT_INT, mfspr(SPR_EEAR_BASE));
62 1387 nogj
  else
63 1426 nogj
    SCHED_ADD(pic_clock, NULL, 1);
64 102 lampret
}
65
 
66 1387 nogj
/* WARNING: Don't eaven try and call this function *during* a simulated
67
 * instruction!! (as in during a read_mem or write_mem callback).  except_handle
68
 * assumes that this is the case, it breaks otherwise. */
69 102 lampret
/* Asserts interrupt to the PIC. */
70
void report_interrupt(int line)
71
{
72 409 markom
  setsprbits(SPR_PMR, SPR_PMR_DME, 0); /* Disable doze mode */
73
  setsprbits(SPR_PMR, SPR_PMR_SME, 0); /* Disable sleep mode */
74 102 lampret
 
75 1426 nogj
  TRACE("Asserting interrupt %d (%s).\n", line, getsprbit(SPR_PICMR, line) ? "Unmasked" : "Masked");
76 409 markom
 
77 1387 nogj
  if (getsprbit(SPR_PICMR, line) || line < 2) {
78 1308 phoenix
    setsprbit(SPR_PICSR, line, 1);
79 1387 nogj
    /* Don't do anything if interrupts not currently enabled */
80 1426 nogj
    if (testsprbits (SPR_SR, SPR_SR_IEE)) {
81 1387 nogj
      except_handle(EXCEPT_INT, mfspr(SPR_EEAR_BASE));
82 1426 nogj
      TRACE("Delivering interrupt on cycle %lli\n", runtime.sim.cycles);
83
    } else
84 1387 nogj
      /* Interrupts not currently enabled, retry next clock cycle */
85 1426 nogj
      SCHED_ADD(pic_clock, NULL, 1);
86 1387 nogj
  }
87 102 lampret
}

powered by: WebSVN 2.1.0

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