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

Subversion Repositories or1k

[/] [or1k/] [tags/] [rel-0-3-0-rc2/] [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 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 102 lampret
 
47
 
48 1715 nogj
/* FIXME: This ugly hack will be removed once the bus architecture gets written
49
 */
50
struct pic pic_state_int = { 1, 1 };
51 1748 jeremybenn
 
52 1715 nogj
struct pic *pic_state = &pic_state_int;
53
 
54 102 lampret
/* Reset. It initializes PIC registers. */
55 1748 jeremybenn
void
56
pic_reset (void)
57 102 lampret
{
58 1748 jeremybenn
  PRINTF ("Resetting PIC.\n");
59 1506 nogj
  cpu_state.sprs[SPR_PICMR] = 0;
60
  cpu_state.sprs[SPR_PICPR] = 0;
61
  cpu_state.sprs[SPR_PICSR] = 0;
62 102 lampret
}
63
 
64 1426 nogj
/* Handles the reporting of an interrupt if it had to be delayed */
65 1748 jeremybenn
static void
66
pic_rep_int (void *dat)
67 102 lampret
{
68 1748 jeremybenn
  if (cpu_state.sprs[SPR_PICSR])
69
    {
70
      except_handle (EXCEPT_INT, cpu_state.sprs[SPR_EEAR_BASE]);
71
    }
72 102 lampret
}
73
 
74 1715 nogj
/* Called whenever interrupts get enabled */
75 1748 jeremybenn
void
76
pic_ints_en (void)
77 1715 nogj
{
78 1748 jeremybenn
  if ((cpu_state.sprs[SPR_PICMR] & cpu_state.sprs[SPR_PICSR]))
79
    SCHED_ADD (pic_rep_int, NULL, 0);
80 1715 nogj
}
81
 
82 102 lampret
/* Asserts interrupt to the PIC. */
83 1715 nogj
/* WARNING: If this is called during a simulated instruction (ie. from a read/
84
 * write mem callback), the interrupt will be delivered after the instruction
85
 * has finished executeing */
86 1748 jeremybenn
void
87
report_interrupt (int line)
88 102 lampret
{
89 1715 nogj
  uint32_t lmask = 1 << line;
90
 
91 1506 nogj
  /* Disable doze and sleep mode */
92
  cpu_state.sprs[SPR_PMR] &= ~(SPR_PMR_DME | SPR_PMR_SME);
93 102 lampret
 
94 1715 nogj
  /* If PIC is disabled, don't set any register, just raise EXCEPT_INT */
95 1748 jeremybenn
  if (!config.pic.enabled)
96
    {
97
      if (cpu_state.sprs[SPR_SR] & SPR_SR_IEE)
98
        except_handle (EXCEPT_INT, cpu_state.sprs[SPR_EEAR_BASE]);
99
      return;
100
    }
101 1608 nogj
 
102 1748 jeremybenn
  if (cpu_state.pic_lines & lmask)
103
    {
104
      /* No edge occured, warn about performance penalty and exit */
105 1751 jeremybenn
      fprintf (stderr, "Warning: Int line %d did not change state\n", line);
106 1748 jeremybenn
      return;
107
    }
108 1715 nogj
 
109
  cpu_state.pic_lines |= lmask;
110
  cpu_state.sprs[SPR_PICSR] |= lmask;
111
 
112
  if ((cpu_state.sprs[SPR_PICMR] & lmask) || line < 2)
113
    if (cpu_state.sprs[SPR_SR] & SPR_SR_IEE)
114 1748 jeremybenn
      SCHED_ADD (pic_rep_int, NULL, 0);
115 102 lampret
}
116 1715 nogj
 
117
/* Clears an int on a pic line */
118 1748 jeremybenn
void
119
clear_interrupt (int line)
120 1715 nogj
{
121
  cpu_state.pic_lines &= ~(1 << line);
122
 
123 1748 jeremybenn
  if (!config.pic.edge_trigger)
124 1715 nogj
    cpu_state.sprs[SPR_PICSR] &= ~(1 << line);
125
}
126
 
127
/*----------------------------------------------------[ PIC configuration ]---*/
128
 
129 1748 jeremybenn
 
130
/*---------------------------------------------------------------------------*/
131
/*!Enable or disable the programmable interrupt controller
132
 
133
   Set the corresponding field in the UPR
134
 
135
   @param[in] val  The value to use
136
   @param[in] dat  The config data structure (not used here)                 */
137
/*---------------------------------------------------------------------------*/
138
static void
139
pic_enabled (union param_val  val,
140
             void            *dat)
141 1715 nogj
{
142 1748 jeremybenn
  if (val.int_val)
143
    {
144
      cpu_state.sprs[SPR_UPR] |= SPR_UPR_PICP;
145
    }
146
  else
147
    {
148
      cpu_state.sprs[SPR_UPR] &= ~SPR_UPR_PICP;
149
    }
150 1715 nogj
 
151 1748 jeremybenn
  config.pic.enabled = val.int_val;
152
 
153
}       /* pic_enabled() */
154
 
155
 
156
/*---------------------------------------------------------------------------*/
157
/*!Enable or disable edge triggering of interrupts
158
 
159
   @param[in] val  The value to use
160
   @param[in] dat  The config data structure (not used here)                 */
161
/*---------------------------------------------------------------------------*/
162
static void
163
pic_edge_trigger (union param_val  val,
164
                  void            *dat)
165 1715 nogj
{
166 1748 jeremybenn
  config.pic.edge_trigger = val.int_val;
167 1715 nogj
 
168 1748 jeremybenn
}       /* pic_edge_trigger() */
169
 
170
 
171
/*---------------------------------------------------------------------------*/
172
/*!Initialize a new interrupt controller configuration
173
 
174
   ALL parameters are set explicitly to default values in init_defconfig()   */
175
/*---------------------------------------------------------------------------*/
176
void
177
reg_pic_sec ()
178 1715 nogj
{
179 1748 jeremybenn
  struct config_section *sec = reg_config_sec ("pic", NULL, NULL);
180 1715 nogj
 
181 1748 jeremybenn
  reg_config_param (sec, "enabled",      paramt_int, pic_enabled);
182
  reg_config_param (sec, "edge_trigger", paramt_int, pic_edge_trigger);
183
 
184
}       /* reg_pic_sec() */

powered by: WebSVN 2.1.0

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