Line 38... |
Line 38... |
#include "opcode/or32.h"
|
#include "opcode/or32.h"
|
#include "spr_defs.h"
|
#include "spr_defs.h"
|
#include "execute.h"
|
#include "execute.h"
|
#include "except.h"
|
#include "except.h"
|
#include "sprs.h"
|
#include "sprs.h"
|
|
#include "sim-config.h"
|
#include "sched.h"
|
#include "sched.h"
|
#include "debug.h"
|
#include "debug.h"
|
|
|
DEFAULT_DEBUG_CHANNEL(pic);
|
DEFAULT_DEBUG_CHANNEL(pic);
|
|
|
/* Reset. It initializes PIC registers. */
|
/* Reset. It initializes PIC registers. */
|
void pic_reset()
|
void pic_reset()
|
{
|
{
|
PRINTF("Resetting PIC.\n");
|
PRINTF("Resetting PIC.\n");
|
mtspr(SPR_PICMR, 0);
|
cpu_state.sprs[SPR_PICMR] = 0;
|
mtspr(SPR_PICPR, 0);
|
cpu_state.sprs[SPR_PICPR] = 0;
|
mtspr(SPR_PICSR, 0);
|
cpu_state.sprs[SPR_PICSR] = 0;
|
}
|
}
|
|
|
/* Handles the reporting of an interrupt if it had to be delayed */
|
/* Handles the reporting of an interrupt if it had to be delayed */
|
void pic_clock(void *dat)
|
void pic_clock(void *dat)
|
{
|
{
|
/* Don't do anything if interrupts not currently enabled */
|
/* Don't do anything if interrupts not currently enabled */
|
if(testsprbits (SPR_SR, SPR_SR_IEE)) {
|
if(cpu_state.sprs[SPR_SR] & SPR_SR_IEE) {
|
TRACE("Delivering interrupt on cycle %lli\n", runtime.sim.cycles);
|
TRACE("Delivering interrupt on cycle %lli\n", runtime.sim.cycles);
|
except_handle(EXCEPT_INT, mfspr(SPR_EEAR_BASE));
|
except_handle(EXCEPT_INT, cpu_state.sprs[SPR_EEAR_BASE]);
|
} else if(testsprbits (SPR_PICSR, (int)dat))
|
} else if(cpu_state.sprs[SPR_PICSR] & (1 << (int)dat))
|
/* Reschedule only if the interrupt hasn't been cleared */
|
/* Reschedule only if the interrupt hasn't been cleared */
|
SCHED_ADD(pic_clock, dat, 1);
|
SCHED_ADD(pic_clock, dat, 1);
|
}
|
}
|
|
|
/* WARNING: Don't eaven try and call this function *during* a simulated
|
/* WARNING: Don't eaven try and call this function *during* a simulated
|
Line 72... |
Line 73... |
/* WARNING2: Don't except report_interrupt to return! However, it also _may_
|
/* WARNING2: Don't except report_interrupt to return! However, it also _may_
|
* return. Make sure you handle this case aswell. */
|
* return. Make sure you handle this case aswell. */
|
/* Asserts interrupt to the PIC. */
|
/* Asserts interrupt to the PIC. */
|
void report_interrupt(int line)
|
void report_interrupt(int line)
|
{
|
{
|
setsprbits(SPR_PMR, SPR_PMR_DME, 0); /* Disable doze mode */
|
/* Disable doze and sleep mode */
|
setsprbits(SPR_PMR, SPR_PMR_SME, 0); /* Disable sleep mode */
|
cpu_state.sprs[SPR_PMR] &= ~(SPR_PMR_DME | SPR_PMR_SME);
|
|
|
TRACE("Asserting interrupt %d (%s).\n", line, getsprbit(SPR_PICMR, line) ? "Unmasked" : "Masked");
|
TRACE("Asserting interrupt %d (%s).\n", line,
|
|
(cpu_state.sprs[SPR_PICMR] & (1 << line)) ? "Unmasked" : "Masked");
|
|
|
if (getsprbit(SPR_PICMR, line) || line < 2) {
|
if ((cpu_state.sprs[SPR_PICMR] & (1 << line)) || line < 2) {
|
setsprbit(SPR_PICSR, line, 1);
|
cpu_state.sprs[SPR_PICSR] |= 1 << line;
|
/* Don't do anything if interrupts not currently enabled */
|
/* Don't do anything if interrupts not currently enabled */
|
if (testsprbits (SPR_SR, SPR_SR_IEE)) {
|
if (cpu_state.sprs[SPR_SR] & SPR_SR_IEE) {
|
TRACE("Delivering interrupt on cycle %lli\n", runtime.sim.cycles);
|
TRACE("Delivering interrupt on cycle %lli\n", runtime.sim.cycles);
|
except_handle(EXCEPT_INT, mfspr(SPR_EEAR_BASE));
|
except_handle(EXCEPT_INT, cpu_state.sprs[SPR_EEAR_BASE]);
|
} else
|
} else
|
/* Interrupts not currently enabled, retry next clock cycle */
|
/* Interrupts not currently enabled, retry next clock cycle */
|
SCHED_ADD(pic_clock, (void *)line, 1);
|
SCHED_ADD(pic_clock, (void *)line, 1);
|
}
|
}
|
}
|
}
|