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

Subversion Repositories sxp

[/] [sxp/] [trunk/] [csim/] [reg_file/] [reg_file.cc] - Blame information for rev 59

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 26 samg
#include <iostream.h>
2
#include <stdlib.h>
3
#include <stdio.h>
4
 
5
class reg_file
6
{
7
  public:
8
    reg_file(unsigned number);
9
    void write_reg (unsigned addr, unsigned data, bool data_vld);
10
    unsigned read_reg (unsigned addr);
11
    bool valid_reg (unsigned addr);
12
    void print_regs();
13
    ~reg_file();
14
  protected:
15
    bool *valid;
16
    unsigned *reg;
17
    unsigned num_regs;
18
};
19
 
20
reg_file::reg_file(unsigned number)
21
{
22
  cout << "Begin regfile init, size = " << number << "\n";
23
  num_regs = number;
24
  valid = new bool[number];
25
  reg = new unsigned[number];
26
 
27
  for (unsigned i=0;i<number;i += 1)
28
    valid[i] = false;
29
  cout << "End regfile init\n";
30
  return;
31
}
32
 
33
void reg_file::write_reg (unsigned addr, unsigned data, bool data_vld)
34
{
35
  if(addr >= num_regs) {
36
    cout << "Invalid write address, addr = " << addr << ", max = " << num_regs-1 << ".\n";
37
    // throw an exception
38
    return;
39
  }
40
  else {
41
    valid[addr] = data_vld;
42
    reg[addr] = data;
43
    return;
44
  }
45
}
46
 
47
unsigned reg_file::read_reg (unsigned addr)
48
{
49
  if(addr >= num_regs) {
50
    cout << "Invalid read address, addr = " << addr << ", max = " << num_regs-1 << ".\n";
51
    // throw an exception
52
    return (0);
53
  }
54
  else
55
    if (valid[addr] == false) {
56
      return (0);
57
    }
58
    else
59
      return (reg[addr]);
60
}
61
 
62
bool reg_file::valid_reg (unsigned addr)
63
{
64
  if (addr >= num_regs)
65
    return (false);
66
  else
67
    return (valid[addr]);
68
}
69
 
70
 
71
void reg_file::print_regs()
72
{
73
  for (unsigned i=0;i<num_regs;i += 1) {
74
    printf ("Register %d  = ",i);
75
    if (valid_reg(i))
76
      printf ("%.8x\n",reg[i]);
77
    else
78
      printf ("xxxxxxxx\n");
79
  }
80
  return;
81
}
82
 
83
reg_file::~reg_file()
84
{
85
  delete [] reg;
86
  delete [] valid;
87
}
88
 
89
/*
90
 *  $Id: reg_file.cc,v 1.1 2001-10-29 00:43:05 samg Exp $
91
 *  Program  : reg_file.cc
92
 *  Author   : Sam Gladstone
93
 *  Function : reg file behavioral class for SXP processor
94
 *  $Log: not supported by cvs2svn $
95
 */
96
 

powered by: WebSVN 2.1.0

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