1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
/*
* Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
*
* This file is part of nios2sim-ng.
*
* This file is subject to the terms and conditions of the GNU General Public
* License. See the file "COPYING" in the main directory of this archive
* for more details.
*/
#include <stdio.h>
#include <stdlib.h>
#include "nios2sim-ng.h"
#include "nios2.h"
#include "memory.h"
uint8_t memory_get_byte(struct memory *mem, int32_t addr)
{
uint8_t *base = (uint8_t *) mem->base;
return base[addr - mem->image_base];
}
void memory_set_byte(struct memory *mem, int32_t addr, uint8_t data)
{
uint8_t *base = (uint8_t *) mem->base;
base[addr - mem->image_base] = data;
}
uint16_t memory_get_halfword(struct memory *mem, int32_t addr)
{
return mem->base[(addr - mem->image_base) / 2];
}
void memory_set_halfword(struct memory *mem, int32_t addr, uint16_t data)
{
mem->base[(addr - mem->image_base) / 2] = data;
}
uint32_t memory_get_word(struct memory *mem, int32_t addr)
{
return mem->base[(addr - mem->image_base) / 4];
}
void memory_set_word(struct memory *mem, int32_t addr, uint32_t data)
{
mem->base[(addr - mem->image_base) / 4] = data;
}
void memory_dump(struct memory *mem, uint32_t offset, size_t count)
{
size_t i;
for (i = 0; i < count; i++) {
if ((i + 1) % 4 == 1)
info("%08x: ", (unsigned int) (offset + i));
info(" %08x", mem->base[offset / 4 + i]);
if ((i + 1) % 4 == 0)
info("\n");
}
}
|