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

Subversion Repositories or1k

[/] [or1k/] [branches/] [stable_0_2_x/] [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 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 1506 nogj
#include "sim-config.h"
44 1426 nogj
#include "sched.h"
45 1308 phoenix
#include "debug.h"
46 102 lampret
 
47 1426 nogj
DEFAULT_DEBUG_CHANNEL(pic);
48 102 lampret
 
49
/* Reset. It initializes PIC registers. */
50
void pic_reset()
51
{
52 997 markom
  PRINTF("Resetting PIC.\n");
53 1506 nogj
  cpu_state.sprs[SPR_PICMR] = 0;
54
  cpu_state.sprs[SPR_PICPR] = 0;
55
  cpu_state.sprs[SPR_PICSR] = 0;
56 102 lampret
}
57
 
58 1426 nogj
/* Handles the reporting of an interrupt if it had to be delayed */
59
void pic_clock(void *dat)
60 102 lampret
{
61 1387 nogj
  /* Don't do anything if interrupts not currently enabled */
62 1506 nogj
  if(cpu_state.sprs[SPR_SR] & SPR_SR_IEE) {
63 1496 nogj
    TRACE("Delivering interrupt on cycle %lli\n", runtime.sim.cycles);
64 1506 nogj
    except_handle(EXCEPT_INT, cpu_state.sprs[SPR_EEAR_BASE]);
65 1608 nogj
  } else if(cpu_state.sprs[SPR_PICSR] & cpu_state.sprs[SPR_PICMR])
66 1496 nogj
    /* Reschedule only if the interrupt hasn't been cleared */
67 1608 nogj
    sched_next_insn(pic_clock, NULL);
68 102 lampret
}
69
 
70 1387 nogj
/* WARNING: Don't eaven try and call this function *during* a simulated
71
 * instruction!! (as in during a read_mem or write_mem callback).  except_handle
72
 * assumes that this is the case, it breaks otherwise. */
73 1473 nogj
/* WARNING2: Don't except report_interrupt to return!  However, it also _may_
74
 * return.  Make sure you handle this case aswell. */
75 102 lampret
/* Asserts interrupt to the PIC. */
76
void report_interrupt(int line)
77
{
78 1506 nogj
  /* Disable doze and sleep mode */
79
  cpu_state.sprs[SPR_PMR] &= ~(SPR_PMR_DME | SPR_PMR_SME);
80 102 lampret
 
81 1506 nogj
  TRACE("Asserting interrupt %d (%s).\n", line,
82
        (cpu_state.sprs[SPR_PICMR] & (1 << line)) ? "Unmasked" : "Masked");
83 409 markom
 
84 1608 nogj
  SCHED_FIND_REMOVE(pic_clock, NULL);
85
 
86 1506 nogj
  if ((cpu_state.sprs[SPR_PICMR] & (1 << line)) || line < 2) {
87
    cpu_state.sprs[SPR_PICSR] |= 1 << line;
88 1387 nogj
    /* Don't do anything if interrupts not currently enabled */
89 1506 nogj
    if (cpu_state.sprs[SPR_SR] & SPR_SR_IEE) {
90 1478 nogj
      TRACE("Delivering interrupt on cycle %lli\n", runtime.sim.cycles);
91 1506 nogj
      except_handle(EXCEPT_INT, cpu_state.sprs[SPR_EEAR_BASE]);
92 1608 nogj
      return;
93
    }
94 1387 nogj
  }
95 1608 nogj
 
96
  if(cpu_state.sprs[SPR_PICMR] & cpu_state.sprs[SPR_PICSR])
97
    /* Interrupts not currently enabled, retry next clock cycle */
98
    sched_next_insn(pic_clock, NULL);
99 102 lampret
}

powered by: WebSVN 2.1.0

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