summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile5
-rw-r--r--device.c46
-rw-r--r--device.h31
-rw-r--r--jtag_uart.c54
-rw-r--r--jtag_uart.h41
-rw-r--r--uart.c41
-rw-r--r--uart.h24
7 files changed, 202 insertions, 40 deletions
diff --git a/Makefile b/Makefile
index a5638ff..40a6460 100644
--- a/Makefile
+++ b/Makefile
@@ -1,9 +1,10 @@
P = nios2sim-ng
VERSION = 0.1
-OBJS = main.o image.o elf.o srec.o nios2.o instruction.o
+OBJS = main.o image.o elf.o srec.o nios2.o memory.o instruction.o simulator.o \
+ device.o uart.o jtag_uart.o
#OBJS += load_image.o nor_flash.o simulator.o simulator.o niosii.o i_type_handler.o j_type_handler.o \
-# r_type_handler.o custom_instr.o io_device.o jtag_uart.o timer.o uart_core.o
+# r_type_handler.o custom_instr.o timer.o
DEFS = -DVERSION="\"$(VERSION)\"" -DDEBUG
diff --git a/device.c b/device.c
new file mode 100644
index 0000000..249d778
--- /dev/null
+++ b/device.c
@@ -0,0 +1,46 @@
+/*
+ * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
+ * Copyright (C) 2010 chysun2000@gmail.com
+ *
+ * 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 "nios2sim-ng.h"
+#include "device.h"
+#include "uart.h"
+#include "jtag_uart.h"
+
+static struct device *devices[] = {
+ &uart_core,
+ &jtag_uart_core,
+};
+#define DEVICES_COUNT ARRAY_SIZE(devices)
+
+int device_init_all(void)
+{
+ unsigned int i;
+ int ret = 0;
+
+ for (i = 0; i < DEVICES_COUNT; i++) {
+ struct device *dev = devices[i];
+
+ if (dev->init == NULL)
+ continue;
+
+ ret = dev->init(dev);
+ if (ret) {
+ err("Failed to initialize device '%s'\n", dev->name);
+ break;
+ }
+
+ vinfo("%s at 0x%08x\n", dev->name, dev->base);
+ }
+
+ return ret;
+}
diff --git a/device.h b/device.h
new file mode 100644
index 0000000..beabe52
--- /dev/null
+++ b/device.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
+ * Copyright (C) 2010 chysun2000@gmail.com
+ *
+ * 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 _DEVICE_H_
+#define _DEVICE_H_
+
+struct device {
+ const char *name;
+
+ uint32_t base;
+ size_t size;
+
+ int (*init)(struct device *dev);
+ bool (*is_dev_addr)(struct device *dev, uint32_t addr);
+ void (*simulate)(struct device *dev);
+
+ /* Private data */
+ void *priv;
+};
+
+extern int device_init_all(void);
+
+#endif /* _DEVICE_H_ */
diff --git a/jtag_uart.c b/jtag_uart.c
index 052c42c..ba0bf5f 100644
--- a/jtag_uart.c
+++ b/jtag_uart.c
@@ -1,28 +1,44 @@
/*
- Nios-sim - one simple NIOSII simulator only for personal interest and fun.
- Copyright (C) 2010 chysun2000@gmail.com
+ * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
+ * Copyright (C) 2010 chysun2000@gmail.com
+ *
+ * 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 "nios2sim-ng.h"
+#include "device.h"
+#include "jtag_uart.h"
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
+static int jtag_uart_init(struct device *dev)
+{
+ return 0;
+}
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+static bool jtag_uart_is_dev_addr(struct device *dev, uint32_t addr)
+{
+ return false;
+}
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
+static void jtag_uart_simulate(struct device *dev)
+{
+}
-#include <stdio.h>
-#include <string.h>
+struct device jtag_uart_core = {
+ .name = "JTAG UART Core",
+ .base = JTAG_UART_BASE,
+ .size = JTAG_UART_SIZE,
-#include "public.h"
-#include "jtag_uart.h"
+ .init = jtag_uart_init,
+ .is_dev_addr = jtag_uart_is_dev_addr,
+ .simulate = jtag_uart_simulate,
+};
+
+#if 0
static struct jtag_uart_priv priv;
static void uart_init(struct io_device * self)
{
@@ -166,4 +182,4 @@ struct io_device jtag_uart_io_device = {
.irq_enable_mask = JTAG_IRQ_MASK
};
-
+#endif
diff --git a/jtag_uart.h b/jtag_uart.h
index d855e39..4328be7 100644
--- a/jtag_uart.h
+++ b/jtag_uart.h
@@ -1,27 +1,28 @@
/*
- Nios-sim - one simple NIOSII simulator only for personal interest and fun.
- Copyright (C) 2010 chysun2000@gmail.com
+ * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
+ * Copyright (C) 2010 chysun2000@gmail.com
+ *
+ * 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.
+ */
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
- (at your option) any later version.
+#ifndef _JTAG_UART_H_
+#define _JTAG_UART_H_
- This program is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
+#include "device.h"
- You should have received a copy of the GNU General Public License along
- with this program; if not, write to the Free Software Foundation, Inc.,
- 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
-*/
+#define JTAG_UART_BASE 0x806810F0
+#define JTAG_UART_SIZE 8
-#ifndef __JTAG_UART_H__
-#define __JTAG_UART_H__
+#define JTAG_UART_DATA_REG 0
+#define JTAG_UART_CTRL_REG 1
-#include "io_device.h"
-#define JTAG_UART_REG_COUNT (2)
+extern struct device jtag_uart_core;
+
+#if 0
#define JTAG_UART_CTRL_REG (0)
#define JTAG_UART_DATA_REG (1)
#define JTAG_UART_BASE_ADDR (0x806810F0)
@@ -53,4 +54,6 @@ struct jtag_uart_priv{
#define ALTERA_JTAGUART_CONTROL_WSPACE_OFST (16)
extern struct io_device jtag_uart_io_device;
-#endif /* __JTAG_UART_H__*/
+#endif
+
+#endif /* _JTAG_UART_H_ */
diff --git a/uart.c b/uart.c
new file mode 100644
index 0000000..f49c1cb
--- /dev/null
+++ b/uart.c
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2010 Tobias Klauser <tklauser@distanz.ch>
+ * Copyright (C) 2010 chysun2000@gmail.com
+ *
+ * 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 "nios2sim-ng.h"
+#include "device.h"
+#include "uart.h"
+
+static int uart_init(struct device *dev)
+{
+ return 0;
+}
+
+static bool uart_is_dev_addr(struct device *dev, uint32_t addr)
+{
+ if (addr >= dev->base && addr < dev->base + dev->size)
+ return true;
+
+ return false;
+}
+
+static void uart_simulate(struct device *dev)
+{
+}
+
+struct device uart_core = {
+ .name = "UART Core",
+ .base = UART_BASE,
+ .size = UART_SIZE,
+
+ .init = uart_init,
+ .is_dev_addr = uart_is_dev_addr,
+ .simulate = uart_simulate,
+};
diff --git a/uart.h b/uart.h
new file mode 100644
index 0000000..4845150
--- /dev/null
+++ b/uart.h
@@ -0,0 +1,24 @@
+/*
+ * 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.
+ */
+
+#ifndef _UART_H_
+#define _UART_H_
+
+#define UART_BASE 0x80681000
+#define UART_SIZE 32
+
+#define UART_RXDATA_REG 0
+#define UART_TXDATA_REG 1
+#define UART_STATUS_REG 2
+#define UART_CONTROL_REG 3
+
+extern struct device uart_core;
+
+#endif /* _UART_H_ */