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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [bootloaders/] [orpmon/] [cmds/] [cpu.c] - Diff between revs 246 and 406

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 246 Rev 406
#include "common.h"
#include "common.h"
#include "support.h"
#include "support.h"
#include "spr-defs.h"
#include "spr-defs.h"
 
 
int ic_enable_cmd (int argc, char *argv[])
int ic_enable_cmd(int argc, char *argv[])
{
{
  unsigned long addr;
        unsigned long addr;
  unsigned long sr;
        unsigned long sr;
 
 
  if (argc) return -1;
        if (argc)
 
                return -1;
  /* Invalidate IC */
  /* Invalidate IC */
  for (addr = 0; addr < 8192; addr += 16)
        for (addr = 0; addr < 8192; addr += 16)
    asm("l.mtspr r0,%0,%1": : "r" (addr), "i" (SPR_ICBIR));
asm("l.mtspr r0,%0,%1": :"r"(addr), "i"(SPR_ICBIR));
 
 
  /* Enable IC */
        /* Enable IC */
  asm("l.mfspr %0,r0,%1": "=r" (sr) : "i" (SPR_SR));
asm("l.mfspr %0,r0,%1": "=r"(sr):"i"(SPR_SR));
  sr |= SPR_SR_ICE;
        sr |= SPR_SR_ICE;
  asm("l.mtspr r0,%0,%1": : "r" (sr), "i" (SPR_SR));
asm("l.mtspr r0,%0,%1": :"r"(sr), "i"(SPR_SR));
  asm("l.nop");
        asm("l.nop");
  asm("l.nop");
        asm("l.nop");
  asm("l.nop");
        asm("l.nop");
  asm("l.nop");
        asm("l.nop");
  return 0;
        return 0;
}
}
 
 
int ic_disable_cmd (int argc, char *argv[])
int ic_disable_cmd(int argc, char *argv[])
{
{
  unsigned long sr;
        unsigned long sr;
 
 
  if (argc) return -1;
        if (argc)
 
                return -1;
  /* Disable IC */
  /* Disable IC */
  asm("l.mfspr %0,r0,%1": "=r" (sr) : "i" (SPR_SR));
asm("l.mfspr %0,r0,%1": "=r"(sr):"i"(SPR_SR));
  sr &= ~SPR_SR_ICE;
        sr &= ~SPR_SR_ICE;
  asm("l.mtspr r0,%0,%1": : "r" (sr), "i" (SPR_SR));
asm("l.mtspr r0,%0,%1": :"r"(sr), "i"(SPR_SR));
  asm("l.nop");
        asm("l.nop");
  asm("l.nop");
        asm("l.nop");
  asm("l.nop");
        asm("l.nop");
  asm("l.nop");
        asm("l.nop");
  return 0;
        return 0;
}
}
 
 
int dc_enable_cmd (int argc, char *argv[])
int dc_enable_cmd(int argc, char *argv[])
{
{
  unsigned long addr;
        unsigned long addr;
  unsigned long sr;
        unsigned long sr;
 
 
  if (argc) return -1;
        if (argc)
 
                return -1;
  /* Invalidate DC */
  /* Invalidate DC */
  for (addr = 0; addr < 8192; addr += 16)
        for (addr = 0; addr < 8192; addr += 16)
    asm("l.mtspr r0,%0,%1": : "r" (addr), "i" (SPR_DCBIR));
asm("l.mtspr r0,%0,%1": :"r"(addr), "i"(SPR_DCBIR));
 
 
  /* Enable DC */
        /* Enable DC */
  asm("l.mfspr %0,r0,%1": "=r" (sr) : "i" (SPR_SR));
asm("l.mfspr %0,r0,%1": "=r"(sr):"i"(SPR_SR));
  sr |= SPR_SR_DCE;
        sr |= SPR_SR_DCE;
  asm("l.mtspr r0,%0,%1": : "r" (sr), "i" (SPR_SR));
asm("l.mtspr r0,%0,%1": :"r"(sr), "i"(SPR_SR));
  asm("l.nop");
        asm("l.nop");
  asm("l.nop");
        asm("l.nop");
  asm("l.nop");
        asm("l.nop");
  asm("l.nop");
        asm("l.nop");
  return 0;
        return 0;
}
}
 
 
int dc_disable_cmd (int argc, char *argv[])
int dc_disable_cmd(int argc, char *argv[])
{
{
 
 
  if (argc) return -1;
        if (argc)
 
                return -1;
 
 
  unsigned long sr = mfspr(SPR_SR);
        unsigned long sr = mfspr(SPR_SR);
 
 
  // If it's enabled and write back is on, we'd better flush it first
        // If it's enabled and write back is on, we'd better flush it first
  // (CWS=1 is write back)
        // (CWS=1 is write back)
 
 
  unsigned long dccfgr = mfspr(SPR_DCCFGR);
        unsigned long dccfgr = mfspr(SPR_DCCFGR);
  int i;
        int i;
  int bs= (dccfgr & SPR_DCCFGR_CBS) ? 32 : 16;
        int bs = (dccfgr & SPR_DCCFGR_CBS) ? 32 : 16;
  int ways = (1 << ((dccfgr & SPR_DCCFGR_NCS) >> 3));
        int ways = (1 << ((dccfgr & SPR_DCCFGR_NCS) >> 3));
  for(i=0;i<ways;i++)
        for (i = 0; i < ways; i++)
      mtspr(SPR_DCBFR, i*bs);
                mtspr(SPR_DCBFR, i * bs);
 
 
  /* Disable DC */
        /* Disable DC */
  sr &= ~SPR_SR_DCE;
        sr &= ~SPR_SR_DCE;
  asm("l.mtspr r0,%0,%1": : "r" (sr), "i" (SPR_SR));
asm("l.mtspr r0,%0,%1": :"r"(sr), "i"(SPR_SR));
  asm("l.nop");
        asm("l.nop");
  asm("l.nop");
        asm("l.nop");
  asm("l.nop");
        asm("l.nop");
  asm("l.nop");
        asm("l.nop");
  return 0;
        return 0;
}
}
 
 
int mfspr_cmd (int argc, char *argv[])
int mfspr_cmd(int argc, char *argv[])
{
{
  unsigned long val, addr;
        unsigned long val, addr;
 
 
  if (argc ==   1) {
        if (argc == 1) {
    addr = strtoul (argv[0], 0, 0);
                addr = strtoul(argv[0], 0, 0);
    /* Read SPR */
                /* Read SPR */
    asm("l.mfspr %0,%1,0": "=r" (val) : "r" (addr));
asm("l.mfspr %0,%1,0": "=r"(val):"r"(addr));
    printf ("\nSPR %04lx: %08lx", addr, val);
    printf ("\nSPR %04lx: %08lx", addr, val);
  } else return -1;
        } else
 
                return -1;
        return 0;
        return 0;
}
}
 
 
int mtspr_cmd (int argc, char *argv[])
int mtspr_cmd(int argc, char *argv[])
{
{
  unsigned long val, addr;
        unsigned long val, addr;
  if (argc == 2) {
        if (argc == 2) {
    addr = strtoul (argv[0], 0, 0);
                addr = strtoul(argv[0], 0, 0);
    val = strtoul (argv[1], 0, 0);
                val = strtoul(argv[1], 0, 0);
    /* Write SPR */
                /* Write SPR */
    asm("l.mtspr %0,%1,0": : "r" (addr), "r" (val));
asm("l.mtspr %0,%1,0": :"r"(addr), "r"(val));
    asm("l.mfspr %0,%1,0": "=r" (val) : "r" (addr));
asm("l.mfspr %0,%1,0": "=r"(val):"r"(addr));
    printf ("\nSPR %04lx: %08lx", addr, val);
    printf ("\nSPR %04lx: %08lx", addr, val);
  } else return -1;
        } else
 
                return -1;
        return 0;
        return 0;
}
}
 
 
void module_cpu_init (void)
void module_cpu_init(void)
{
{
  register_command ("ic_enable", "", "enable instruction cache", ic_enable_cmd);
        register_command("ic_enable", "", "enable instruction cache",
  register_command ("ic_disable", "", "disable instruction cache", ic_disable_cmd);
                         ic_enable_cmd);
 
        register_command("ic_disable", "", "disable instruction cache",
 
                         ic_disable_cmd);
  register_command ("dc_enable", "", "enable data cache", dc_enable_cmd);
  register_command ("dc_enable", "", "enable data cache", dc_enable_cmd);
  register_command ("dc_disable", "", "disable data cache", dc_disable_cmd);
        register_command("dc_disable", "", "disable data cache",
 
                         dc_disable_cmd);
  register_command ("mfspr", "<spr_addr>", "show SPR", mfspr_cmd);
  register_command ("mfspr", "<spr_addr>", "show SPR", mfspr_cmd);
  register_command ("mtspr", "<spr_addr> <value>", "set SPR", mtspr_cmd);
        register_command("mtspr", "<spr_addr> <value>", "set SPR", mtspr_cmd);
}
}
 
 

powered by: WebSVN 2.1.0

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