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

Subversion Repositories or1k

[/] [or1k/] [tags/] [nog_patch_61/] [or1ksim/] [pic/] [pic.c] - Blame information for rev 1780

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

powered by: WebSVN 2.1.0

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