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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel-0-3-0-rc3/] [or1ksim/] [pic/] [pic.c] - Blame information for rev 1748

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 1748 jeremybenn
 
3 102 lampret
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
4 1748 jeremybenn
   Copyright (C) 2008 Embecosm Limited
5
 
6
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
7
 
8
   This file is part of OpenRISC 1000 Architectural Simulator.
9
 
10
   This program is free software; you can redistribute it and/or modify it
11
   under the terms of the GNU General Public License as published by the Free
12
   Software Foundation; either version 3 of the License, or (at your option)
13
   any later version.
14
 
15
   This program is distributed in the hope that it will be useful, but WITHOUT
16
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
17
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
18
   more details.
19
 
20
   You should have received a copy of the GNU General Public License along
21
   with this program.  If not, see <http://www.gnu.org/licenses/>. */
22 102 lampret
 
23 1748 jeremybenn
/* This program is commented throughout in a fashion suitable for processing
24
   with Doxygen. */
25 102 lampret
 
26
 
27 1748 jeremybenn
/* Autoconf and/or portability configuration */
28
#include "config.h"
29
#include "port.h"
30 102 lampret
 
31 1748 jeremybenn
/* System includes */
32 102 lampret
#include <stdlib.h>
33
#include <stdio.h>
34
 
35 1748 jeremybenn
/* Package includes */
36 1350 nogj
#include "arch.h"
37
#include "abstract.h"
38 102 lampret
#include "pic.h"
39 1432 nogj
#include "opcode/or32.h"
40 1748 jeremybenn
#include "spr-defs.h"
41 1432 nogj
#include "execute.h"
42 102 lampret
#include "except.h"
43 167 markom
#include "sprs.h"
44 1506 nogj
#include "sim-config.h"
45 1426 nogj
#include "sched.h"
46 1308 phoenix
#include "debug.h"
47 102 lampret
 
48 1748 jeremybenn
DEFAULT_DEBUG_CHANNEL (pic);
49 102 lampret
 
50 1715 nogj
/* FIXME: This ugly hack will be removed once the bus architecture gets written
51
 */
52
struct pic pic_state_int = { 1, 1 };
53 1748 jeremybenn
 
54 1715 nogj
struct pic *pic_state = &pic_state_int;
55
 
56 102 lampret
/* Reset. It initializes PIC registers. */
57 1748 jeremybenn
void
58
pic_reset (void)
59 102 lampret
{
60 1748 jeremybenn
  PRINTF ("Resetting PIC.\n");
61 1506 nogj
  cpu_state.sprs[SPR_PICMR] = 0;
62
  cpu_state.sprs[SPR_PICPR] = 0;
63
  cpu_state.sprs[SPR_PICSR] = 0;
64 102 lampret
}
65
 
66 1426 nogj
/* Handles the reporting of an interrupt if it had to be delayed */
67 1748 jeremybenn
static void
68
pic_rep_int (void *dat)
69 102 lampret
{
70 1748 jeremybenn
  if (cpu_state.sprs[SPR_PICSR])
71
    {
72
      TRACE ("Delivering interrupt on cycle %lli\n", runtime.sim.cycles);
73
      except_handle (EXCEPT_INT, cpu_state.sprs[SPR_EEAR_BASE]);
74
    }
75 102 lampret
}
76
 
77 1715 nogj
/* Called whenever interrupts get enabled */
78 1748 jeremybenn
void
79
pic_ints_en (void)
80 1715 nogj
{
81 1748 jeremybenn
  if ((cpu_state.sprs[SPR_PICMR] & cpu_state.sprs[SPR_PICSR]))
82
    SCHED_ADD (pic_rep_int, NULL, 0);
83 1715 nogj
}
84
 
85 102 lampret
/* Asserts interrupt to the PIC. */
86 1715 nogj
/* WARNING: If this is called during a simulated instruction (ie. from a read/
87
 * write mem callback), the interrupt will be delivered after the instruction
88
 * has finished executeing */
89 1748 jeremybenn
void
90
report_interrupt (int line)
91 102 lampret
{
92 1715 nogj
  uint32_t lmask = 1 << line;
93
 
94 1506 nogj
  /* Disable doze and sleep mode */
95
  cpu_state.sprs[SPR_PMR] &= ~(SPR_PMR_DME | SPR_PMR_SME);
96 102 lampret
 
97 1748 jeremybenn
  TRACE ("Asserting interrupt %d (%s).\n", line,
98
         (cpu_state.sprs[SPR_PICMR] & lmask) ? "Unmasked" : "Masked");
99 409 markom
 
100 1715 nogj
  /* If PIC is disabled, don't set any register, just raise EXCEPT_INT */
101 1748 jeremybenn
  if (!config.pic.enabled)
102
    {
103
      if (cpu_state.sprs[SPR_SR] & SPR_SR_IEE)
104
        except_handle (EXCEPT_INT, cpu_state.sprs[SPR_EEAR_BASE]);
105
      return;
106
    }
107 1608 nogj
 
108 1748 jeremybenn
  if (cpu_state.pic_lines & lmask)
109
    {
110
      /* No edge occured, warn about performance penalty and exit */
111
      WARN ("Int line %d did not change state\n", line);
112
      return;
113
    }
114 1715 nogj
 
115
  cpu_state.pic_lines |= lmask;
116
  cpu_state.sprs[SPR_PICSR] |= lmask;
117
 
118
  if ((cpu_state.sprs[SPR_PICMR] & lmask) || line < 2)
119
    if (cpu_state.sprs[SPR_SR] & SPR_SR_IEE)
120 1748 jeremybenn
      SCHED_ADD (pic_rep_int, NULL, 0);
121 102 lampret
}
122 1715 nogj
 
123
/* Clears an int on a pic line */
124 1748 jeremybenn
void
125
clear_interrupt (int line)
126 1715 nogj
{
127 1748 jeremybenn
  TRACE ("Clearing interrupt %d\n", line);
128 1715 nogj
  cpu_state.pic_lines &= ~(1 << line);
129
 
130 1748 jeremybenn
  if (!config.pic.edge_trigger)
131 1715 nogj
    cpu_state.sprs[SPR_PICSR] &= ~(1 << line);
132
}
133
 
134
/*----------------------------------------------------[ PIC configuration ]---*/
135
 
136 1748 jeremybenn
 
137
/*---------------------------------------------------------------------------*/
138
/*!Enable or disable the programmable interrupt controller
139
 
140
   Set the corresponding field in the UPR
141
 
142
   @param[in] val  The value to use
143
   @param[in] dat  The config data structure (not used here)                 */
144
/*---------------------------------------------------------------------------*/
145
static void
146
pic_enabled (union param_val  val,
147
             void            *dat)
148 1715 nogj
{
149 1748 jeremybenn
  if (val.int_val)
150
    {
151
      cpu_state.sprs[SPR_UPR] |= SPR_UPR_PICP;
152
    }
153
  else
154
    {
155
      cpu_state.sprs[SPR_UPR] &= ~SPR_UPR_PICP;
156
    }
157 1715 nogj
 
158 1748 jeremybenn
  config.pic.enabled = val.int_val;
159
 
160
}       /* pic_enabled() */
161
 
162
 
163
/*---------------------------------------------------------------------------*/
164
/*!Enable or disable edge triggering of interrupts
165
 
166
   @param[in] val  The value to use
167
   @param[in] dat  The config data structure (not used here)                 */
168
/*---------------------------------------------------------------------------*/
169
static void
170
pic_edge_trigger (union param_val  val,
171
                  void            *dat)
172 1715 nogj
{
173 1748 jeremybenn
  config.pic.edge_trigger = val.int_val;
174 1715 nogj
 
175 1748 jeremybenn
}       /* pic_edge_trigger() */
176
 
177
 
178
/*---------------------------------------------------------------------------*/
179
/*!Initialize a new interrupt controller configuration
180
 
181
   ALL parameters are set explicitly to default values in init_defconfig()   */
182
/*---------------------------------------------------------------------------*/
183
void
184
reg_pic_sec ()
185 1715 nogj
{
186 1748 jeremybenn
  struct config_section *sec = reg_config_sec ("pic", NULL, NULL);
187 1715 nogj
 
188 1748 jeremybenn
  reg_config_param (sec, "enabled",      paramt_int, pic_enabled);
189
  reg_config_param (sec, "edge_trigger", paramt_int, pic_edge_trigger);
190
 
191
}       /* reg_pic_sec() */

powered by: WebSVN 2.1.0

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