lconf.c 5.71 KB
/* -----------------------------------------------------------------------------
 *  Copyright (C) 2020 daiteq s.r.o.                     http://www.daiteq.com
 *
 *  This program is distributed WITHOUT ANY WARRANTY; without even
 *  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
 *  PURPOSE.
 *
 * -----------------------------------------------------------------------------
 *  Filename    : sysregs.c
 *  Authors     : Martin Danek
 *  Description : system register definitions
 *  Release     :
 *  Version     : 1.0
 *  Date        : 14.6.2020
 * -----------------------------------------------------------------------------
 */


#include <stdint.h>
#include "leon-myuart.h"
#include "lconf.h"


void get_lconf(lconf_type *lconf) {
  unsigned config;

  config = (unsigned)cpu_reg_read(LCONF_BASE);

  lconf->ahbstaten = (config&LCONF_AHBSTATEN);
  lconf->wdogen = (config&LCONF_WDOGEN);
  lconf->multiplier = (config&LCONF_MULTIPLIER);
  lconf->divider = (config&LCONF_DIVIDER);
  lconf->macen = (config&LCONF_MACEN);
  lconf->sdramen = (config&LCONF_SDRAMEN);
  lconf->dsu = (config&LCONF_DSU);
  lconf->men = (config&LCONF_MEN);
  //
  lconf->dline_bits = (config&LCONF_DLINE_BITS) >> 10;
  lconf->dset_bits = (config&LCONF_DSIZE) >> 12;
  lconf->iline_bits = (config&LCONF_ILINE_BITS) >> 15;
  lconf->iset_bits = (config&LCONF_ISIZE) >> 17;
  lconf->nwindows = (config&LCONF_NWINDOWS) >> 20;
  lconf->watchpoints = (config&LCONF_WATCHPOINTS) >> 26;
  lconf->fpu = (config&LCONF_FPU_MSK) >> 4;
  lconf->pci = (config&LCONF_PCI_MSK) >> 2;
  lconf->wproten = (config&LCONF_WPROTEN_MSK);
}


void get_lconf_fpu(lconf_fpu_type *lconf_fpu) {
  unsigned config;

  config = (unsigned)cpu_reg_read(LCONF_FPU_BASE);

  lconf_fpu->fdiv = (config&LCONF_FPU_DIV);
  lconf_fpu->fsqrt = (config&LCONF_FPU_SQRT);
  lconf_fpu->packed = (config&LCONF_FPU_PACKED);
  lconf_fpu->dual = (config&LCONF_FPU_DUAL);
  //
  lconf_fpu->exp_hi = (config&LCONF_FPU_EXPH_BITS) >> 4;
  lconf_fpu->trsig_hi = (config&LCONF_FPU_TRSIGH_BITS) >> 8;
  lconf_fpu->exp_lo = (config&LCONF_FPU_EXPL_BITS) >> 14;
  lconf_fpu->trsig_lo = (config&LCONF_FPU_TRSIGL_BITS) >> 18;
}


void get_lconf_swar(lconf_swar_type *lconf_swar) {
  unsigned config;

  config = (unsigned)cpu_reg_read(LCONF_SWAR_BASE);

  lconf_swar->correl = (config&LCONF_SWAR_CORREL);
  lconf_swar->demod = (config&LCONF_SWAR_DEMOD);
  lconf_swar->sincos = (config&LCONF_SWAR_SINCOS);
  lconf_swar->audio = (config&LCONF_SWAR_AUDIO);
  lconf_swar->video = (config&LCONF_SWAR_VIDEO);
  lconf_swar->alu = (config&LCONF_SWAR_ALU);
  lconf_swar->acc = (config&LCONF_SWAR_ACC);
  //
  lconf_swar->lanes = (config&LCONF_SWAR_LANES) >> 16;
  lconf_swar->swidth = (config&LCONF_SWAR_SWIDTH) >> 21;
  lconf_swar->awidth = (config&LCONF_SWAR_AWIDTH) >> 26;
}

void report_lconf(lconf_type *lconf) {
  NL;
  m_print("LEON CONFIGURATION");NL;
  m_print("------------------");NL;
  if (lconf->ahbstaten)   { m_print("  AHBSTATEN");NL; }
  if (lconf->wdogen)      { m_print("  WDOGEN");NL; }
  if (lconf->multiplier)  { m_print("  MULTIPLIER");NL; }
  if (lconf->divider)     { m_print("  DIVIDER");NL; }
  if (lconf->macen)       { m_print("  MACEN");NL; }
  if (lconf->sdramen)     { m_print("  SDRAMEN");NL; }
  if (lconf->dsu)         { m_print("  DSU");NL; }
  if (lconf->men)         { m_print("  MEN");NL; }
  m_print("  DLINE BITS:     ");i_print(lconf->dline_bits);NL;
  m_print("  DSET SIZE [KB]: ");i_print(1<<lconf->dset_bits);NL;
  m_print("  ILINE BITS:     ");i_print(lconf->iline_bits);NL;
  m_print("  ISET SIZE [KB]: ");i_print(1<<lconf->iset_bits);NL;
  m_print("  NWINDOWS:       ");i_print(lconf->nwindows+1);NL;
  m_print("  WATCHPOINTS:    ");i_print(lconf->watchpoints);NL;
  m_print("  FPU:            ");
  switch (lconf->fpu) {
    case 0: m_print("NONE"); break;
    case 1: m_print("MEIKO/DAIFPU"); break;
    case 2: m_print("GRFPU"); break;
    default: m_print("DAIFPU");break;
  }
  NL;
  m_print("  PCI:            ");
  switch (lconf->pci) {
    case 0: m_print("NONE"); break;
    case 1: m_print("INSILICON"); break;
    case 2: m_print("ESA"); break;
    default: m_print("OTHER");break;
  }
  NL;
  m_print("  WPROTEN:        ");i_print(lconf->wproten);NL;
  m_print("");NL;NL;
}

void report_lconf_fpu(lconf_fpu_type *lconf_fpu) {
  m_print("DAIFPU");NL;
  m_print("------");NL;
  if (lconf_fpu->fdiv)   { m_print("  FDIV");NL; }
  if (lconf_fpu->fsqrt)  { m_print("  FSQRT");NL; }
  if (lconf_fpu->packed) { m_print("  PACKED");NL; }
  if (lconf_fpu->dual)   { m_print("  DUAL");NL; }
  m_print("  PREC1 EXP BITS:   ");i_print(lconf_fpu->exp_hi);NL;
  m_print("  PREC1 TRSIG BITS: ");i_print(lconf_fpu->trsig_hi);NL;
  if (lconf_fpu->dual) {
    m_print("  PREC2 EXP BITS:   ");i_print(lconf_fpu->exp_lo);NL;
    m_print("  PREC2 TRSIG BITS: ");i_print(lconf_fpu->trsig_lo);NL;
  }
  m_print("");NL;
}

void report_lconf_swar(lconf_swar_type *lconf_swar) {
  if ((lconf_swar->correl)||
      (lconf_swar->demod)||
      (lconf_swar->audio)||
      (lconf_swar->video)||
      (lconf_swar->alu)) {
    m_print("SWAR UNIT");NL;
    m_print("---------");NL;
    if (lconf_swar->correl)   { m_print("  CORREL");NL; }
    if (lconf_swar->demod)    { m_print("  DEMOD");NL; }
    if (lconf_swar->sincos)   { m_print("  SINCOS");NL; }
    if (lconf_swar->audio)    { m_print("  AUDIO");NL; }
    if (lconf_swar->video)    { m_print("  VIDEO");NL; }
    if (lconf_swar->alu)      { m_print("  ALU");NL; }
    if (lconf_swar->acc)      { m_print("  ACC");NL; }
    m_print("  LANES:       ");i_print(lconf_swar->lanes);NL;
    m_print("  SWIDTH:      ");i_print(lconf_swar->swidth);NL;
    m_print("  AWIDTH:      ");i_print(lconf_swar->awidth);NL;
  }
  else {
    m_print("SWAR UNIT DISABLED");NL;
    m_print("------------------");NL;
  }
  m_print("");NL;
}