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

Subversion Repositories sardmips

[/] [sardmips/] [branches/] [avendor/] [source/] [memory/] [memory2.h] - Blame information for rev 18

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 igorloi
#ifndef _MEMORY2_H
2
#define _MEMORY2_H
3
 
4
#include <systemc.h>
5
#include <iomanip.h>
6
#include <stdio.h>
7
#include <unistd.h>
8
#include <stdlib.h>
9
#include <string.h>
10
#include <sys/types.h>
11
#include <sys/stat.h>
12
#include <fcntl.h>
13
#include "../constants/elf.h"
14
#include "../constants/constants.h"
15
#include "../constants/config.h"
16
 
17
SC_MODULE(memory2)
18
{
19
  sc_in<bool> in_clk;
20
  sc_in<bool> reset;
21
 
22
  sc_in<sc_logic>       memreq;
23
  sc_in<sc_logic>       memrw;
24
  sc_in<sc_lv<2> >      membs;
25
  sc_in<sc_uint<32> >   memaddr;
26
  // sc_inout_rv<32>    memdata;
27
  sc_in<sc_lv<32> >     memdatawrite;
28
  sc_out<sc_lv<32> >    memdataread;
29
  // sc_out<sc_logic>   memhold;
30
 
31
  // Segnali per la gestioe delle eccezioni 
32
  sc_out<sc_logic>      addrl;          //indirizzo disallineato in lettura
33
  sc_out<sc_logic>      addrs;          //indirizzo disallineato in scrittura
34
  sc_out<sc_logic>      page_fault;     //indirizzo mancante
35
 
36
 
37
  unsigned int x[MEMSIZE]; // Lower part of kuseg (starting at 0x0000_0000)
38
  char *memoryname;
39
  unsigned int pc;
40
 
41
  void mread();
42
  void mwrite();
43
 
44
  void page_fault_analyzer();
45
  void check_load_aligned();
46
  void check_store_aligned();
47
 
48
 
49
#ifdef _CC_MEMDUMP_
50
  int memcontents;
51
#endif
52
 
53
  typedef memory2 SC_CURRENT_USER_MODULE;
54
  memory2(sc_module_name name, char *contents_file)
55
    {
56
      unsigned int i = 0;
57
      unsigned int line;
58
      unsigned int codepos = 0;
59
      //unsigned int datasegstart = 0;
60
      unsigned char *buf;
61
      unsigned char *code;
62
      //char main[4];
63
#ifdef _CC_MEMDUMP_
64
      unsigned int ci = 0x00000000;
65
 
66
      // Create blank memory file filled with 0's
67
      memcontents = open("mem.bin", O_CREAT | O_RDWR, 0666);
68
      for (i = 0; i < (MEMSIZE/4); i++)
69
        write(memcontents, &ci, 4);
70
      close(memcontents);
71
#endif
72
 
73
 
74
 
75
      FILE *fid = fopen(contents_file, "r");
76
      buf = (unsigned char*)malloc(32768);
77
      int size = fread(buf, 1, 32768, fid);
78
      code = (unsigned char*)malloc(MEMSIZE);
79
 
80
 
81
          memcpy(code,buf,size);
82
          codepos = size;
83
 
84
      i = 0;
85
      while (i < codepos)
86
        {
87
          line  = code[i];
88
          line += (code[i+1]<<8);
89
          line += (code[i+2]<<16);
90
          line += (code[i+3]<<24);
91
 
92
          x[i>>2] = line;
93
          i += 4;
94
        }
95
 
96
        SC_METHOD(mread);
97
        sensitive << reset;
98
       sensitive_neg << in_clk;
99
 
100
 
101
        SC_METHOD(mwrite);
102
        sensitive << reset;
103
        sensitive_neg << in_clk;
104
 
105
        SC_METHOD(page_fault_analyzer);
106
        sensitive << memaddr << memreq << memrw << membs;
107
 
108
        SC_METHOD(check_load_aligned);
109
        sensitive << memaddr << memreq << memrw << membs;
110
 
111
        SC_METHOD(check_store_aligned);
112
        sensitive << memaddr << memreq << memrw << membs;
113
     }
114
};
115
 
116
#endif

powered by: WebSVN 2.1.0

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