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

Subversion Repositories scarm

[/] [scarm/] [trunk/] [src/] [scRAM.cpp] - Blame information for rev 10

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 zhong
///////////////////////////////////////////////////////////////////////////////
2
// This program is free software; you can redistribute it and/or
3
// modify it under the terms of the GNU General Public License
4
// as published by the Free Software Foundation; either version 2
5
// of the License, or (at your option) any later version.
6
//
7
// This program is distributed in the hope that it will be useful,
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10
// GNU General Public License for more details.
11
//
12
// You should have received a copy of the GNU General Public License
13
// along with this program; if not, write to the Free Software
14
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
15
//////////////////////////////////////////////////////////////////////
16
 
17
///////////////////////////////////////////////////////////////////              
18
//          
19
//  Original Author: Allen Tao Zhong,
20
//  University of Electronic Science and Technology in China
21
//  email: zhong@opencores.org
22
//  info   This is a SystemC ARM model,
23
// scRAM.cpp: implementation of the scRAM class.
24
//
25
//////////////////////////////////////////////////////////////////////
26
#include "scRAM.h"
27
#include  "global.h"
28
//#define DEBUG
29
//////////////////////////////////////////////////////////////////////
30
// Construction/Destruction
31
//////////////////////////////////////////////////////////////////////
32
 
33
 
34
scRAM::~scRAM()
35
{
36
 
37
}
38
 
39
 
40
 
41
bool scRAM::load_program(char * file_name)
42
{
43
                FILE * program=NULL;
44
        uint32_t data;
45
          program = fopen(file_name, "rb");
46
                        if(program!=NULL)
47
                        {
48
                if( fseek(program, 0, SEEK_SET) != 0)
49
                                {
50
                                    cout<<"seek error"<<endl;
51
                                }else
52
                                {
53
                 //for
54
                                 int i=0;
55
#if defined(DEBUG)
56
        //cout<<"loading program..."<<endl;
57
#endif                          
58
                                 while( !feof( program) )
59
                                 {
60
                                        fread(&data,sizeof(uint32_t),1,program);
61
 
62
                                          if( ferror( program ) )      {
63
                                                 perror( "Read error" );
64
                                                 break;
65
                                          }
66
 
67
                                        //fseek(program,4,SEEK_CUR);
68
                                        //cout<<hex<<data<<endl;
69
                                        m_data[i]=data;
70
                                        i++;
71
                                        if(i>=SIZE_OF_MEM){
72
                                                cout<<"The memory is full."<<endl;
73
                                                break;}
74
 
75
                                 }
76
                        m_data[i]=0x12345678;
77
                                }
78
 
79
                             cout<<"ram swi"<<endl;
80
uint32_t addr=0xec0;
81
           addr=addr/4;
82
           m_data[addr]=0x40000000;
83
addr=0xec4;
84
           addr=addr/4;
85
           m_data[addr]=0x70000000;
86
addr=0xec8;
87
           addr=addr/4;
88
           m_data[addr]=0x80000000;
89
addr=0xecc;
90
           addr=addr/4;
91
           m_data[addr]=0x70000000;
92
                                fclose(program);
93
                        }else{
94
                          cout<<"can not find file."<<endl;
95
                cout<<"  usage : scARM <file name> <args...>"<<endl;
96
                cout<<"  file name : a program to execute"<<endl;
97
                cout<<"  Note:Program should be plain bianery format."<<endl;
98
                cout<<"  args : arguments to the file"<<endl;
99
                          sc_stop();
100
                        }
101
 
102
  return true;
103
}
104
 
105
void scRAM::dump(uint32_t addr)
106
{
107
   cout<<hex<<addr<<":"<<m_data[addr]<<endl;
108
}
109
void scRAM::entry()
110
{
111
 
112
           uint32_t addr=A;
113
           addr=addr/4;
114
 
115
          if(addr>SIZE_OF_MEM)
116
      {
117
                  cout<<"read access out of mem in scRAM"<<endl;
118
                  //sc_stop();
119
          }else
120
          {
121
                        if(m_rw==0){
122
 
123
                          D=m_data[addr];
124
         //cout<<"read ram "<<hex<<A<<":"<<(m_data[addr])<<endl;    
125
                        }
126
                        else {
127
      // cout<<"write ram "<<hex<<A<<":"<<D<<endl;
128
                          m_data[addr]=D;
129
                         m_rw=0;
130
                        }
131
          }
132
 
133
 
134
}
135
void scRAM::rw()
136
{
137
  m_rw=1;
138
}
139
scRAM::scRAM(sc_module_name name_):sc_module(name_)
140
        {
141
       m_rw=0;
142
          // SC_METHOD(interrupt);
143
          // sensitive_pos<<clock;
144
           SC_SLAVE(rw,nRW);
145
           SC_SLAVE(entry,A);
146
 
147
 
148
        };
149
 
150
void scRAM::interrupt()
151
{
152
  if(g_interrupt==1)
153
  {
154
     cout<<"ram swi"<<endl;
155
uint32_t addr=0xec0;
156
           addr=addr/4;
157
           m_data[addr]=0x40000000;
158
addr=0xec4;
159
           addr=addr/4;
160
           m_data[addr]=0x70000000;
161
addr=0xec8;
162
           addr=addr/4;
163
           m_data[addr]=0x80000000;
164
addr=0xecc;
165
           addr=addr/4;
166
           m_data[addr]=0x70000000;
167
  }
168
}

powered by: WebSVN 2.1.0

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