From 8db4c483d5e3941c9352ab5caa0808b391adfbfb Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 18 Nov 2010 14:03:58 +0100 Subject: Add memory handling module --- memory.c | 35 +++++++++++++++++++++++++++++++++++ memory.h | 27 +++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 memory.c create mode 100644 memory.h diff --git a/memory.c b/memory.c new file mode 100644 index 0000000..75b041f --- /dev/null +++ b/memory.c @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2010 Tobias Klauser + * + * 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 +#include + +#include "nios2sim-ng.h" +#include "nios2.h" +#include "memory.h" + +uint8_t memory_get_byte(struct memory *mem, int32_t offset) +{ + uint8_t *base = (uint8_t *) mem->base; + return base[offset]; +} + +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"); + } +} diff --git a/memory.h b/memory.h new file mode 100644 index 0000000..e5bd073 --- /dev/null +++ b/memory.h @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2010 Tobias Klauser + * + * 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. + */ + +#ifndef _MEMORY_H_ +#define _MEMORY_H_ + +struct memory { + uint32_t *base; + size_t size; + + uint32_t image_base; +}; + +#define IMAGE_BASE_UNINITIALIZED UINT32_MAX + +extern uint8_t memory_get_byte(struct memory *mem, int32_t offset); + +extern void memory_dump(struct memory *mem, uint32_t offset, size_t count); + +#endif /* _MEMORY_H_ */ -- cgit v1.2.3-54-g00ecf it.cgi/linux/net-next.git/commit/include/uapi/asm-generic/types.h?h=nds-private-remove&id=70ad35067c99dd6fb1fefbabf11dd53806f1978c'>commitdiff
AgeCommit message (Expand)AuthorFilesLines