/* sprs.c -- Simulation of OR1K special-purpose registers
|
/* sprs.c -- Simulation of OR1K special-purpose registers
|
Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
|
Copyright (C) 1999 Damjan Lampret, lampret@opencores.org
|
|
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
This file is part of OpenRISC 1000 Architectural Simulator.
|
|
|
This program is free software; you can redistribute it and/or modify
|
This program is free software; you can redistribute it and/or modify
|
it under the terms of the GNU General Public License as published by
|
it under the terms of the GNU General Public License as published by
|
the Free Software Foundation; either version 2 of the License, or
|
the Free Software Foundation; either version 2 of the License, or
|
(at your option) any later version.
|
(at your option) any later version.
|
|
|
This program is distributed in the hope that it will be useful,
|
This program is distributed in the hope that it will be useful,
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
GNU General Public License for more details.
|
GNU General Public License for more details.
|
|
|
You should have received a copy of the GNU General Public License
|
You should have received a copy of the GNU General Public License
|
along with this program; if not, write to the Free Software
|
along with this program; if not, write to the Free Software
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
|
|
#include <stdlib.h>
|
#include <stdlib.h>
|
#include <stdio.h>
|
#include <stdio.h>
|
#include <string.h>
|
#include <string.h>
|
#include <errno.h>
|
#include <errno.h>
|
|
|
#include "arch.h"
|
#include "arch.h"
|
#include "sprs.h"
|
#include "sprs.h"
|
#include "abstract.h"
|
#include "abstract.h"
|
#include "sim-config.h"
|
#include "sim-config.h"
|
|
|
extern int flag;
|
extern int flag;
|
|
|
sprword sprs[MAX_SPRS];
|
sprword sprs[MAX_SPRS];
|
|
|
int audio_cnt = 0;
|
int audio_cnt = 0;
|
|
|
static FILE *fo = 0;
|
static FILE *fo = 0;
|
/* Set a specific SPR with a value. */
|
/* Set a specific SPR with a value. */
|
inline void
|
inline void
|
mtspr(const int regno, const sprword value)
|
mtspr(const int regno, const sprword value)
|
{
|
{
|
regno %= MAX_SPRS;
|
regno %= MAX_SPRS;
|
sprs[regno] = value;
|
sprs[regno] = value;
|
|
|
/* MM: Register hooks. */
|
/* MM: Register hooks. */
|
switch (regno) {
|
switch (regno) {
|
case SPR_TTCR:
|
case SPR_TTCR:
|
spr_write_ttcr (value);
|
spr_write_ttcr (value);
|
break;
|
break;
|
case SPR_TTMR:
|
case SPR_TTMR:
|
spr_write_ttmr (value);
|
spr_write_ttmr (value);
|
break;
|
break;
|
case SPR_SR:
|
case SPR_SR:
|
/* Set internal flag also */
|
/* Set internal flag also */
|
if(value & SPR_SR_F) flag = 1;
|
if(value & SPR_SR_F) flag = 1;
|
else flag = 0;
|
else flag = 0;
|
sprs[regno] |= SPR_SR_FO;
|
sprs[regno] |= SPR_SR_FO;
|
break;
|
break;
|
case SPR_NPC:
|
case SPR_NPC:
|
{
|
{
|
extern unsigned long pc;
|
extern unsigned long pc;
|
extern unsigned long pcnext;
|
extern unsigned long pcnext;
|
extern int delay_insn;
|
extern int delay_insn;
|
extern unsigned long pcdelay;
|
extern unsigned long pcdelay;
|
|
|
clear_pending_exception ();
|
clear_pending_exception ();
|
|
|
/* The debugger has redirected us to a new address */
|
/* The debugger has redirected us to a new address */
|
/* This is usually done to reissue an instruction
|
/* This is usually done to reissue an instruction
|
which just caused a breakpoint exception. */
|
which just caused a breakpoint exception. */
|
pc = value;
|
pc = value;
|
|
|
if(!value && config.sim.verbose)
|
if(!value && config.sim.verbose)
|
PRINTF("WARNING: PC just set to 0!\n");
|
PRINTF("WARNING: PC just set to 0!\n");
|
|
|
/* Clear any pending delay slot jumps also */
|
/* Clear any pending delay slot jumps also */
|
delay_insn = 0;
|
delay_insn = 0;
|
pcnext = value + 4;
|
pcnext = value + 4;
|
}
|
}
|
break;
|
break;
|
case 0xFFFD:
|
case 0xFFFD:
|
fo = fopen ("audiosim.pcm", "wb+");
|
fo = fopen ("audiosim.pcm", "wb+");
|
if (!fo) PRINTF("Cannot open audiosim.pcm\n");
|
if (!fo) PRINTF("Cannot open audiosim.pcm\n");
|
PRINTF("Audio opened.\n");
|
PRINTF("Audio opened.\n");
|
break;
|
break;
|
case 0xFFFE:
|
case 0xFFFE:
|
if (!fo) PRINTF("audiosim.pcm not opened\n");
|
if (!fo) PRINTF("audiosim.pcm not opened\n");
|
fputc (value & 0xFF, fo);
|
fputc (value & 0xFF, fo);
|
if ((audio_cnt % 1024) == 0)
|
if ((audio_cnt % 1024) == 0)
|
PRINTF("%i\n", audio_cnt);
|
PRINTF("%i\n", audio_cnt);
|
audio_cnt++;
|
audio_cnt++;
|
break;
|
break;
|
case 0xFFFF:
|
case 0xFFFF:
|
fclose(fo);
|
fclose(fo);
|
PRINTF("Audio closed.\n");
|
PRINTF("Audio closed.\n");
|
runtime.sim.cont_run = 0;
|
runtime.sim.cont_run = 0;
|
break;
|
break;
|
case SPR_PMR:
|
case SPR_PMR:
|
/* PMR[SDF] and PMR[DCGE] are ignored completely. */
|
/* PMR[SDF] and PMR[DCGE] are ignored completely. */
|
if (value & SPR_PMR_SUME) {
|
if (value & SPR_PMR_SUME) {
|
PRINTF ("SUSPEND: PMR[SUME] bit was set.\n");
|
PRINTF ("SUSPEND: PMR[SUME] bit was set.\n");
|
runtime.sim.cont_run = 0;
|
runtime.sim.cont_run = 0;
|
}
|
}
|
break;
|
break;
|
default:
|
default:
|
/* Mask reseved bits in DTLBMR and DTLBMR registers */
|
/* Mask reseved bits in DTLBMR and DTLBMR registers */
|
if ( (regno >= SPR_DTLBMR_BASE(0)) && (regno < SPR_DTLBTR_LAST(3))) {
|
if ( (regno >= SPR_DTLBMR_BASE(0)) && (regno < SPR_DTLBTR_LAST(3))) {
|
if((regno & 0xff) < 0x80)
|
if((regno & 0xff) < 0x80)
|
sprs[regno] = ((value / (config.dmmu.pagesize * config.dmmu.nsets)) *
|
sprs[regno] = ((value / config.dmmu.pagesize) * config.dmmu.pagesize) |
|
config.dmmu.pagesize * config.dmmu.nsets) |
|
|
(value & (SPR_DTLBMR_V | SPR_DTLBMR_PL1 | SPR_DTLBMR_CID | SPR_DTLBMR_LRU));
|
(value & (SPR_DTLBMR_V | SPR_DTLBMR_PL1 | SPR_DTLBMR_CID | SPR_DTLBMR_LRU));
|
else
|
else
|
sprs[regno] = ((value / config.dmmu.pagesize) * config.dmmu.pagesize) |
|
sprs[regno] = ((value / config.dmmu.pagesize) * config.dmmu.pagesize) |
|
(value & (SPR_DTLBTR_CC | SPR_DTLBTR_CI | SPR_DTLBTR_WBC | SPR_DTLBTR_WOM |
|
(value & (SPR_DTLBTR_CC | SPR_DTLBTR_CI | SPR_DTLBTR_WBC | SPR_DTLBTR_WOM |
|
SPR_DTLBTR_A | SPR_DTLBTR_D | SPR_DTLBTR_URE | SPR_DTLBTR_UWE | SPR_DTLBTR_SRE |
|
SPR_DTLBTR_A | SPR_DTLBTR_D | SPR_DTLBTR_URE | SPR_DTLBTR_UWE | SPR_DTLBTR_SRE |
|
SPR_DTLBTR_SWE));
|
SPR_DTLBTR_SWE));
|
}
|
}
|
|
|
/* Mask reseved bits in ITLBMR and ITLBMR registers */
|
/* Mask reseved bits in ITLBMR and ITLBMR registers */
|
if ( (regno >= SPR_ITLBMR_BASE(0)) && (regno < SPR_ITLBTR_LAST(3))) {
|
if ( (regno >= SPR_ITLBMR_BASE(0)) && (regno < SPR_ITLBTR_LAST(3))) {
|
if((regno & 0xff) < 0x80)
|
if((regno & 0xff) < 0x80)
|
sprs[regno] = ((value / (config.immu.pagesize * config.immu.nsets)) *
|
sprs[regno] = ((value / config.immu.pagesize) * config.immu.pagesize) |
|
config.immu.pagesize * config.immu.nsets) |
|
|
(value & (SPR_ITLBMR_V | SPR_ITLBMR_PL1 | SPR_ITLBMR_CID | SPR_ITLBMR_LRU));
|
(value & (SPR_ITLBMR_V | SPR_ITLBMR_PL1 | SPR_ITLBMR_CID | SPR_ITLBMR_LRU));
|
else
|
else
|
sprs[regno] = ((value / config.immu.pagesize) * config.immu.pagesize) |
|
sprs[regno] = ((value / config.immu.pagesize) * config.immu.pagesize) |
|
(value & (SPR_ITLBTR_CC | SPR_ITLBTR_CI | SPR_ITLBTR_WBC | SPR_ITLBTR_WOM |
|
(value & (SPR_ITLBTR_CC | SPR_ITLBTR_CI | SPR_ITLBTR_WBC | SPR_ITLBTR_WOM |
|
SPR_ITLBTR_A | SPR_ITLBTR_D | SPR_ITLBTR_SXE | SPR_ITLBTR_UXE));
|
SPR_ITLBTR_A | SPR_ITLBTR_D | SPR_ITLBTR_SXE | SPR_ITLBTR_UXE));
|
}
|
}
|
/* Links to GPRS */
|
/* Links to GPRS */
|
if(regno >= 0x0400 && regno < 0x0420) {
|
if(regno >= 0x0400 && regno < 0x0420) {
|
extern unsigned long reg[32];
|
extern unsigned long reg[32];
|
reg[regno - 0x0400] = value;
|
reg[regno - 0x0400] = value;
|
}
|
}
|
break;
|
break;
|
}
|
}
|
}
|
}
|
|
|
/* Show status of important SPRs. */
|
/* Show status of important SPRs. */
|
void sprs_status()
|
void sprs_status()
|
{
|
{
|
PRINTF("VR : 0x%.8x UPR : 0x%.8x\n", mfspr(SPR_VR), mfspr(SPR_UPR));
|
PRINTF("VR : 0x%.8x UPR : 0x%.8x\n", mfspr(SPR_VR), mfspr(SPR_UPR));
|
PRINTF("SR : 0x%.8x\n", mfspr(SPR_SR));
|
PRINTF("SR : 0x%.8x\n", mfspr(SPR_SR));
|
PRINTF("MACLO: 0x%.8x MACHI: 0x%.8x\n", mfspr(SPR_MACLO), mfspr(SPR_MACHI));
|
PRINTF("MACLO: 0x%.8x MACHI: 0x%.8x\n", mfspr(SPR_MACLO), mfspr(SPR_MACHI));
|
PRINTF("EPCR0: 0x%.8x EPCR1: 0x%.8x\n", mfspr(SPR_EPCR_BASE), mfspr(SPR_EPCR_BASE+1));
|
PRINTF("EPCR0: 0x%.8x EPCR1: 0x%.8x\n", mfspr(SPR_EPCR_BASE), mfspr(SPR_EPCR_BASE+1));
|
PRINTF("EEAR0: 0x%.8x EEAR1: 0x%.8x\n", mfspr(SPR_EEAR_BASE), mfspr(SPR_EEAR_BASE+1));
|
PRINTF("EEAR0: 0x%.8x EEAR1: 0x%.8x\n", mfspr(SPR_EEAR_BASE), mfspr(SPR_EEAR_BASE+1));
|
PRINTF("ESR0 : 0x%.8x ESR1 : 0x%.8x\n", mfspr(SPR_ESR_BASE), mfspr(SPR_ESR_BASE+1));
|
PRINTF("ESR0 : 0x%.8x ESR1 : 0x%.8x\n", mfspr(SPR_ESR_BASE), mfspr(SPR_ESR_BASE+1));
|
PRINTF("TTMR : 0x%.8x TTCR : 0x%.8x\n", mfspr(SPR_TTMR), mfspr(SPR_TTCR));
|
PRINTF("TTMR : 0x%.8x TTCR : 0x%.8x\n", mfspr(SPR_TTMR), mfspr(SPR_TTCR));
|
PRINTF("PICMR: 0x%.8x PICSR: 0x%.8x\n", mfspr(SPR_PICMR), mfspr(SPR_PICSR));
|
PRINTF("PICMR: 0x%.8x PICSR: 0x%.8x\n", mfspr(SPR_PICMR), mfspr(SPR_PICSR));
|
PRINTF("PPC: 0x%.8x NPC : 0x%.8x\n", mfspr(SPR_PPC), mfspr(SPR_NPC));
|
PRINTF("PPC: 0x%.8x NPC : 0x%.8x\n", mfspr(SPR_PPC), mfspr(SPR_NPC));
|
}
|
}
|
|
|