summaryrefslogtreecommitdiff
path: root/csim
diff options
context:
space:
mode:
authorAlex AUVOLAT <alex.auvolat@ens.fr>2014-01-02 22:30:11 +0100
committerAlex AUVOLAT <alex.auvolat@ens.fr>2014-01-02 22:30:11 +0100
commit85bc61cb7fa8f4b9af78064cb65fbad49a109d5f (patch)
tree5116b1c423864f3cde8f1002b7a4dabb62e88fff /csim
parent4e1aaf316457f4d4f045fd3ebe500cd70f6bafcc (diff)
downloadSystDigit-Projet-85bc61cb7fa8f4b9af78064cb65fbad49a109d5f.tar.gz
SystDigit-Projet-85bc61cb7fa8f4b9af78064cb65fbad49a109d5f.zip
Started CPU implementation.
Diffstat (limited to 'csim')
-rw-r--r--csim/load.c10
-rw-r--r--csim/sim.c4
-rw-r--r--csim/sim.h2
3 files changed, 9 insertions, 7 deletions
diff --git a/csim/load.c b/csim/load.c
index 4e7583a..bb77a0e 100644
--- a/csim/load.c
+++ b/csim/load.c
@@ -20,13 +20,15 @@ void add_rom(const char *prefix, FILE *file) {
rom->prefix = prefix;
// Load ROM file
- fscanf(file, "%d %d\n", &(rom->addr_size), &(rom->word_size));
- rom->data = malloc(pow2(rom->addr_size) * sizeof(t_value));
+ fscanf(file, "%d %d\n", &(rom->words_defined), &(rom->word_size));
+ rom->data = malloc(rom->words_defined * sizeof(t_value));
- for (i = 0; i < pow2(rom->addr_size); i++) {
+ for (i = 0; i < rom->words_defined; i++) {
fscanf(file, " ");
if (fscanf(file, "/%lu", &(rom->data[i]))) {
// ok, value is read
+ } else if (fscanf(file, "x%x", &(rom->data[i]))) {
+ // ok, value is read
} else {
rom->data[i] = read_bool(file, NULL);
}
@@ -124,7 +126,7 @@ t_program *load_dumb_netlist (FILE *stream) {
// find corresponding ROM
for (r = roms; r != NULL; r = r->next) {
if (is_prefix(r->prefix, p->vars[p->eqs[i].dest_var].name)) {
- if (r->addr_size == as && r->word_size == ws) {
+ if (r->word_size == ws) {
p->eqs[i].Rom.rom = r;
break;
} else {
diff --git a/csim/sim.c b/csim/sim.c
index e3d61da..04cad15 100644
--- a/csim/sim.c
+++ b/csim/sim.c
@@ -121,8 +121,8 @@ void machine_step(t_machine *m) {
}
break;
case C_ROM:
- if (p->eqs[i].Rom.rom != NULL) {
- a = m->var_values[p->eqs[i].Rom.read_addr];
+ a = m->var_values[p->eqs[i].Rom.read_addr];
+ if (p->eqs[i].Rom.rom != NULL && a < p->eqs[i].Rom.rom->words_defined) {
v = p->eqs[i].Rom.rom->data[a];
} else {
v = 0;
diff --git a/csim/sim.h b/csim/sim.h
index c331fa5..0265f53 100644
--- a/csim/sim.h
+++ b/csim/sim.h
@@ -26,7 +26,7 @@
typedef unsigned long long int t_value;
typedef struct _s_rom {
- int addr_size, word_size;
+ int word_size, words_defined;
t_value *data;
const char *prefix;
struct _s_rom *next;