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

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [or1ksim/] [pic/] [pic.c] - Blame information for rev 30

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

Line No. Rev Author Line
1 19 jeremybenn
/* pic.c -- Simulation of OpenRISC 1000 programmable interrupt controller
2
 
3
   Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
4
   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
 
23
/* This program is commented throughout in a fashion suitable for processing
24
   with Doxygen. */
25
 
26
 
27
/* Autoconf and/or portability configuration */
28
#include "config.h"
29
#include "port.h"
30
 
31
/* System includes */
32
#include <stdlib.h>
33
#include <stdio.h>
34
 
35
/* Package includes */
36
#include "arch.h"
37
#include "abstract.h"
38
#include "pic.h"
39
#include "opcode/or32.h"
40
#include "spr-defs.h"
41
#include "execute.h"
42
#include "except.h"
43
#include "sprs.h"
44
#include "sim-config.h"
45
#include "sched.h"
46
 
47
 
48
/* FIXME: This ugly hack will be removed once the bus architecture gets written
49
 */
50
struct pic pic_state_int = { 1, 1 };
51
 
52
struct pic *pic_state = &pic_state_int;
53
 
54
/* Reset. It initializes PIC registers. */
55
void
56
pic_reset (void)
57
{
58
  PRINTF ("Resetting PIC.\n");
59
  cpu_state.sprs[SPR_PICMR] = 0;
60
  cpu_state.sprs[SPR_PICPR] = 0;
61
  cpu_state.sprs[SPR_PICSR] = 0;
62
}
63
 
64
/* Handles the reporting of an interrupt if it had to be delayed */
65
static void
66
pic_rep_int (void *dat)
67
{
68
  if (cpu_state.sprs[SPR_PICSR])
69
    {
70
      except_handle (EXCEPT_INT, cpu_state.sprs[SPR_EEAR_BASE]);
71
    }
72
}
73
 
74
/* Called whenever interrupts get enabled */
75
void
76
pic_ints_en (void)
77
{
78
  if ((cpu_state.sprs[SPR_PICMR] & cpu_state.sprs[SPR_PICSR]))
79
    SCHED_ADD (pic_rep_int, NULL, 0);
80
}
81
 
82
/* Asserts interrupt to the PIC. */
83
/* 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
void
87
report_interrupt (int line)
88
{
89
  uint32_t lmask = 1 << line;
90
 
91
  /* Disable doze and sleep mode */
92
  cpu_state.sprs[SPR_PMR] &= ~(SPR_PMR_DME | SPR_PMR_SME);
93
 
94
  /* If PIC is disabled, don't set any register, just raise EXCEPT_INT */
95
  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
 
102
  if (cpu_state.pic_lines & lmask)
103
    {
104
      /* No edge occured, warn about performance penalty and exit */
105
      fprintf (stderr, "Warning: Int line %d did not change state\n", line);
106
      return;
107
    }
108
 
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
      SCHED_ADD (pic_rep_int, NULL, 0);
115
}
116
 
117
/* Clears an int on a pic line */
118
void
119
clear_interrupt (int line)
120
{
121
  cpu_state.pic_lines &= ~(1 << line);
122
 
123
  if (!config.pic.edge_trigger)
124
    cpu_state.sprs[SPR_PICSR] &= ~(1 << line);
125
}
126
 
127
/*----------------------------------------------------[ PIC configuration ]---*/
128
 
129
 
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
{
142
  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
 
151
  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
{
166
  config.pic.edge_trigger = val.int_val;
167
 
168
}       /* 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
{
179
  struct config_section *sec = reg_config_sec ("pic", NULL, NULL);
180
 
181
  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.