Line 25... |
Line 25... |
#include <stdio.h>
|
#include <stdio.h>
|
#include <string.h>
|
#include <string.h>
|
|
|
#include "except.h"
|
#include "except.h"
|
#include "tick.h"
|
#include "tick.h"
|
#include "../cpu/or1k/spr_defs.h"
|
#include "spr_defs.h"
|
#include "pic.h"
|
#include "pic.h"
|
#include "sprs.h"
|
#include "sprs.h"
|
#include "sim-config.h"
|
#include "sim-config.h"
|
|
#include "sched.h"
|
|
|
/* For mode 10 only: timer stops until we write into TTCR. */
|
/* When did the timer start to count */
|
int tt_stopped = 0;
|
int cycles_start = 0;
|
|
|
|
/* TT Count Register */
|
|
unsigned long ttcr;
|
|
|
|
/* TT Mode Register */
|
|
unsigned long ttmr;
|
|
|
|
extern int cycles;
|
|
|
/* Reset. It initializes TTCR register. */
|
/* Reset. It initializes TTCR register. */
|
void tick_reset()
|
void tick_reset()
|
{
|
{
|
if (config.tick.enabled) {
|
|
if (config.sim.verbose)
|
if (config.sim.verbose)
|
printf("Resetting Tick Timer.\n");
|
printf("Resetting Tick Timer.\n");
|
mtspr(SPR_TTCR, 0);
|
mtspr(SPR_TTCR, 0);
|
mtspr(SPR_TTMR, 0);
|
mtspr(SPR_TTMR, 0);
|
tt_stopped = 0;
|
|
} else
|
|
tt_stopped = 1;
|
|
}
|
}
|
|
|
/* Simulation hook. Must be called every clock cycle to simulate tick
|
/* Job handler for tick timer */
|
timer. It does internal functional tick timer simulation. */
|
void tick_job (int param)
|
inline void tick_clock()
|
|
{
|
{
|
unsigned long ttcr;
|
int mode = (ttmr & SPR_TTMR_M) >> 30;
|
unsigned long ttmr;
|
/*debug (7, "tick_job%i, param %i\n", param, mode);*/
|
|
switch (mode) {
|
if (tt_stopped)
|
case 1:
|
return;
|
sprs[SPR_TTCR] = ttcr = 0;
|
|
case 2:
|
ttcr = mfspr(SPR_TTCR);
|
if (ttmr & SPR_TTMR_IE) {
|
ttmr = mfspr(SPR_TTMR);
|
|
|
|
if (!(ttmr & SPR_TTMR_M))
|
|
return;
|
|
|
|
if ((ttcr & SPR_TTCR_PERIOD) == (ttmr & SPR_TTMR_PERIOD)) {
|
|
int mode = (ttmr & SPR_TTMR_M) >> 30; /* CZ 04/09/01 */
|
|
|
|
if (ttmr & SPR_TTMR_IE)
|
|
setsprbits(SPR_TTMR, SPR_TTMR_IP, 1);
|
setsprbits(SPR_TTMR, SPR_TTMR_IP, 1);
|
|
if ((mfspr(SPR_SR) & SPR_SR_TEE) == SPR_SR_TEE)
|
|
except_handle(EXCEPT_TICK, mfspr(SPR_EEAR_BASE));
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
/* Starts the tick timer. This function is called by a write to ttcr spr register */
|
|
void spr_write_ttcr (unsigned long value)
|
|
{
|
|
unsigned mode = (ttmr & SPR_TTMR_M) >> 30;
|
|
/*debug (7, "ttcr = %08x\n", value);*/
|
|
ttcr = value;
|
|
/* Remove previous if it exists */
|
|
SCHED_FIND_REMOVE(tick_job, 0);
|
|
if (mode == 1 || mode == 2) {
|
|
SCHED_ADD(tick_job, 0, cycles + (ttmr & SPR_TTMR_PERIOD) - ttcr);
|
|
cycles_start = cycles - ttcr;
|
|
}
|
|
}
|
|
|
/* Handle the modes properly.. CZ 04/09/01 */
|
void spr_write_ttmr (unsigned long value)
|
switch(mode)
|
|
{
|
{
|
|
/*debug (7, "ttmr = %08x\n", value);*/
|
|
ttmr = value;
|
|
/* Handle the modes properly. */
|
|
switch((ttmr & SPR_TTMR_M) >> 30) {
|
case 0: /* Timer is disabled */
|
case 0: /* Timer is disabled */
|
tt_stopped = 1;
|
|
break;
|
break;
|
case 1: /* Timer should auto restart */
|
case 1: /* Timer should auto restart */
|
ttcr = 0;
|
sprs[SPR_TTCR] = ttcr = 0;
|
mtspr(SPR_TTCR,ttcr);
|
cycles_start = cycles;
|
|
SCHED_FIND_REMOVE(tick_job, 0);
|
|
SCHED_ADD(tick_job, 0, cycles + (ttmr & SPR_TTMR_PERIOD) - ttcr);
|
break;
|
break;
|
case 2: /* Pause the timer */
|
case 2: /* Stop the timer when match */
|
tt_stopped = 1;
|
SCHED_FIND_REMOVE(tick_job, 0);
|
break;
|
break;
|
case 3: /* Timer keeps running */
|
case 3: /* Timer keeps running -- do nothing*/
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
if ((ttmr & SPR_TTMR_IP) && ((mfspr(SPR_SR) & SPR_SR_TEE) == SPR_SR_TEE))
|
unsigned long spr_read_ttcr ()
|
except_handle(EXCEPT_TICK, mfspr(SPR_EEAR_BASE));
|
{
|
|
/*debug (7, "ttcr ---- %08x\n", cycles - cycles_start);*/
|
if (!tt_stopped)
|
return cycles - cycles_start;
|
ttcr++;
|
|
mtspr(SPR_TTCR, ttcr);
|
|
}
|
}
|
|
|
No newline at end of file
|
No newline at end of file
|