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

Subversion Repositories aemb

[/] [aemb/] [trunk/] [sw/] [iss/] [mem/] [InstMemory.cc] - Blame information for rev 202

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

Line No. Rev Author Line
1 198 sybreon
/*!
2
  AEMB INSTRUCTION SET SIMULATOR
3
  Copyright (C) 2009 Shawn Tan <shawn.tan@aeste.net>
4
 
5
  This program is free software: you can redistribute it and/or modify
6
  it under the terms of the GNU General Public License as published by
7
  the Free Software Foundation, either version 3 of the License, or
8
  (at your option) any later version.
9
 
10
  This program is distributed in the hope that it will be useful, but
11
  WITHOUT ANY WARRANTY; without even the implied warranty of
12
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
  General Public License for more details.
14
 
15
  You should have received a copy of the GNU General Public License
16
  along with this program.  If not, see
17
  <http://www.gnu.org/licenses/>.
18
*/
19
 
20 199 sybreon
#include "InstMemory.hh"
21 198 sybreon
 
22
#include <utility>
23
#include <stdio.h>
24
#include <string.h>
25
#include <stdlib.h>
26
#include <assert.h>
27
 
28
using namespace std;
29
 
30 199 sybreon
namespace aemb
31 198 sybreon
{
32 199 sybreon
 
33
void InstMemory::putInst(const int addr, const int data)
34
{
35 198 sybreon
        int word = addr >> 2; // word align the address
36
        mem.insert(make_pair(word, data));
37
}
38
 
39 199 sybreon
int InstMemory::getInst(const int addr)
40 198 sybreon
{
41
        int word = addr >> 2; // word align the address
42
        assert(!(addr & 0x03)); // check word alignment
43
        map<int,int>::iterator data = mem.find(word);
44
        assert(data != mem.end()); // check if the address is valid     
45
        return data->second;
46
}
47
 
48 199 sybreon
int InstMemory::readVmem()
49 198 sybreon
{
50
        char str[255];
51
        char *tok = NULL;
52
        char *cend = NULL;
53
        long addr, data;
54
 
55
        while (fgets(str, 255, stdin) != NULL) {
56
                switch(str[0]) {
57
                        case '@':
58
                                // extract address
59
                                tok = strtok(str," ");
60
                                cend = tok;
61
                                cend++;
62
                                addr = strtoul(cend, &cend, 16);
63
 
64
                                #ifndef NDEBUG
65
                                printf("\n");
66
                                #endif
67
 
68
                                // extract data
69
                                //tok = strtok(NULL," ");                               
70
                                while ((tok = strtok(NULL, " ")) != NULL) {
71
                                        data = strtoul(tok, &cend, 16);
72
                                        putInst((addr << 2), data);
73
 
74
                                        #ifndef NDEBUG                          
75
                                        printf("\t%X:%.8X", (unsigned int)addr,(unsigned int)data);
76
                                        #endif
77
 
78
                                        ++addr;
79
                                }
80
                        break;
81
 
82
                        default: // ignored line
83
                                //fprintf(stderr,"*** Error parsing VMEM format ***\n");
84
                        break;
85
                }
86
 
87
        }
88
 
89
        #ifndef NDEBUG
90
        printf("\nVMEM size: %d",mem.size());
91
        #endif
92
 
93
        return mem.size();
94
}
95
 
96 199 sybreon
void InstMemory::dumpMem()
97 198 sybreon
{
98
        map<int,int>::iterator iter;
99
 
100
        for (iter = mem.begin(); iter != mem.end(); ++iter) {
101
                #ifndef NDEBUG
102
                printf("\n%X : %.8X",iter->first, iter->second);
103
                #endif
104
        }
105
 
106
}
107
 
108 199 sybreon
InstMemory::InstMemory()
109 198 sybreon
{
110
}
111
 
112 199 sybreon
InstMemory::~InstMemory()
113 198 sybreon
{
114
}
115 199 sybreon
 
116
}

powered by: WebSVN 2.1.0

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