From: Michael Rolnik <mrolnik@gmail.com>
To: qemu-devel@nongnu.org
Cc: rth@twiddle.net, peter.maydell@linaro.org,
Michael Rolnik <mrolnik@gmail.com>
Subject: [Qemu-devel] [PATCH v15 3/9] target-avr: adding a sample AVR board
Date: Tue, 16 Aug 2016 12:05:14 +0300 [thread overview]
Message-ID: <1471338320-8523-4-git-send-email-mrolnik@gmail.com> (raw)
In-Reply-To: <1471338320-8523-1-git-send-email-mrolnik@gmail.com>
Signed-off-by: Michael Rolnik <mrolnik@gmail.com>
---
MAINTAINERS | 1 +
hw/avr/Makefile.objs | 21 ++++++++++
hw/avr/sample.c | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 134 insertions(+)
create mode 100644 hw/avr/Makefile.objs
create mode 100644 hw/avr/sample.c
diff --git a/MAINTAINERS b/MAINTAINERS
index c793e90..f38b997 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -114,6 +114,7 @@ AVR
M: Michael Rolnik <mrolnik@gmail.com>
S: Maintained
F: target-avr/
+F: hw/avr/
CRIS
M: Edgar E. Iglesias <edgar.iglesias@gmail.com>
diff --git a/hw/avr/Makefile.objs b/hw/avr/Makefile.objs
new file mode 100644
index 0000000..8f537c9
--- /dev/null
+++ b/hw/avr/Makefile.objs
@@ -0,0 +1,21 @@
+#
+# QEMU AVR CPU
+#
+# Copyright (c) 2016 Michael Rolnik
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, see
+# <http://www.gnu.org/licenses/lgpl-2.1.html>
+#
+
+obj-y += sample.o
diff --git a/hw/avr/sample.c b/hw/avr/sample.c
new file mode 100644
index 0000000..e1cf56c
--- /dev/null
+++ b/hw/avr/sample.c
@@ -0,0 +1,112 @@
+/*
+ * QEMU AVR CPU
+ *
+ * Copyright (c) 2016 Michael Rolnik
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see
+ * <http://www.gnu.org/licenses/lgpl-2.1.html>
+ */
+
+/*
+ * NOTE:
+ * This is not a real AVR board !!! This is an example !!!
+ *
+ * This example can be used to build a real AVR board.
+ *
+ * This example board loads provided binary file into flash memory and
+ * executes it from 0x00000000 address in the code memory space.
+ *
+ * Currently used for AVR CPU validation
+ *
+ */
+
+#include "qemu/osdep.h"
+#include "qapi/error.h"
+#include "qemu-common.h"
+#include "cpu.h"
+#include "hw/hw.h"
+#include "sysemu/sysemu.h"
+#include "sysemu/qtest.h"
+#include "ui/console.h"
+#include "hw/boards.h"
+#include "hw/devices.h"
+#include "hw/loader.h"
+#include "qemu/error-report.h"
+#include "exec/address-spaces.h"
+#include "include/hw/sysbus.h"
+
+#define VIRT_BASE_FLASH 0x00000000
+#define VIRT_BASE_ISRAM 0x00000100
+#define VIRT_BASE_EXMEM 0x00001100
+#define VIRT_BASE_EEPROM 0x00000000
+
+#define SIZE_FLASH 0x00020000
+#define SIZE_ISRAM 0x00001000
+#define SIZE_EXMEM 0x00010000
+#define SIZE_EEPROM 0x00001000
+#define SIZE_IOREG SIZE_REGS
+
+#define PHYS_BASE_FLASH (PHYS_BASE_CODE)
+
+#define PHYS_BASE_ISRAM (PHYS_BASE_DATA)
+#define PHYS_BASE_EXMEM (PHYS_BASE_ISRAM + SIZE_ISRAM)
+#define PHYS_BASE_EEPROM (PHYS_BASE_EXMEM + SIZE_EXMEM)
+
+#define PHYS_BASE_IOREG (PHYS_BASE_REGS + 0x20)
+
+static void sample_init(MachineState *machine)
+{
+ MemoryRegion *address_space_mem;
+ MemoryRegion *ram;
+ MemoryRegion *flash;
+ unsigned ram_size = SIZE_ISRAM + SIZE_EXMEM;
+ AVRCPU *cpu_avr ATTRIBUTE_UNUSED;
+ const char *firmware = NULL;
+ const char *filename;
+
+ address_space_mem = get_system_memory();
+ ram = g_new(MemoryRegion, 1);
+ flash = g_new(MemoryRegion, 1);
+
+ cpu_avr = cpu_avr_init("avr5");
+
+ memory_region_allocate_system_memory(ram, NULL, "avr.ram", ram_size);
+ memory_region_add_subregion(address_space_mem, PHYS_BASE_ISRAM, ram);
+
+ memory_region_init_rom(flash, NULL, "avr.flash", SIZE_FLASH, &error_fatal);
+ memory_region_add_subregion(address_space_mem, PHYS_BASE_FLASH, flash);
+ vmstate_register_ram_global(flash);
+
+ if (machine->firmware) {
+ firmware = machine->firmware;
+ }
+
+ filename = qemu_find_file(QEMU_FILE_TYPE_BIOS, firmware);
+ if (!filename) {
+ error_report("Could not find flash image file '%s'", firmware);
+ exit(1);
+ }
+
+ load_image_targphys(filename, PHYS_BASE_FLASH, SIZE_FLASH);
+}
+
+static void sample_machine_init(MachineClass *mc)
+{
+ mc->desc = "AVR sample/example board";
+ mc->init = sample_init;
+ mc->is_default = 1;
+}
+
+DEFINE_MACHINE("sample", sample_machine_init)
+
--
2.4.9 (Apple Git-60)
next prev parent reply other threads:[~2016-08-16 9:05 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-16 9:05 [Qemu-devel] [PATCH v15 0/9] 8bit AVR cores Michael Rolnik
2016-08-16 9:05 ` [Qemu-devel] [PATCH v15 1/9] target-avr: AVR cores support is added Michael Rolnik
2016-08-16 9:05 ` [Qemu-devel] [PATCH v15 2/9] target-avr: adding AVR CPU features/flavors Michael Rolnik
2016-08-16 9:05 ` Michael Rolnik [this message]
2016-08-16 9:05 ` [Qemu-devel] [PATCH v15 4/9] target-avr: adding instructions encodings Michael Rolnik
2016-08-16 9:05 ` [Qemu-devel] [PATCH v15 5/9] target-avr: adding AVR interrupt handling Michael Rolnik
2016-08-16 9:05 ` [Qemu-devel] [PATCH v15 6/9] target-avr: adding helpers for IN, OUT, SLEEP, WBR & unsupported instructions Michael Rolnik
2016-08-16 9:05 ` [Qemu-devel] [PATCH v15 7/9] target-avr: adding instruction translation Michael Rolnik
2016-08-16 9:05 ` [Qemu-devel] [PATCH v15 8/9] target-avr: instruction decoder generator Michael Rolnik
2016-08-16 9:05 ` [Qemu-devel] [PATCH v15 9/9] target-avr: adding instruction decoder Michael Rolnik
2016-08-16 9:18 ` [Qemu-devel] [PATCH v15 0/9] 8bit AVR cores no-reply
2016-08-16 9:43 ` Peter Maydell
2016-08-16 9:46 ` Fam Zheng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1471338320-8523-4-git-send-email-mrolnik@gmail.com \
--to=mrolnik@gmail.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=rth@twiddle.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).