From abb6c10f3a5be99396c303e60d286606ddc72e17 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Fri, 19 Nov 2010 14:06:15 +0100 Subject: Implement memory load/store operations --- memory.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'memory.c') diff --git a/memory.c b/memory.c index 75b041f..553766a 100644 --- a/memory.c +++ b/memory.c @@ -15,10 +15,26 @@ #include "nios2.h" #include "memory.h" -uint8_t memory_get_byte(struct memory *mem, int32_t offset) +uint8_t memory_get_byte(struct memory *mem, int32_t addr) { uint8_t *base = (uint8_t *) mem->base; - return base[offset]; + 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; +} + +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) -- cgit v1.2.3-54-g00ecf