From patchwork Tue Aug 16 09:05:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Rolnik X-Patchwork-Id: 9282935 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id A0B41607FD for ; Tue, 16 Aug 2016 09:06:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 90DFE28B70 for ; Tue, 16 Aug 2016 09:06:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 85B9928B99; Tue, 16 Aug 2016 09:06:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id ECA4A28B70 for ; Tue, 16 Aug 2016 09:06:18 +0000 (UTC) Received: from localhost ([::1]:40824 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bZaKA-0001LQ-3H for patchwork-qemu-devel@patchwork.kernel.org; Tue, 16 Aug 2016 05:06:18 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57364) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bZaJU-0001Es-Tt for qemu-devel@nongnu.org; Tue, 16 Aug 2016 05:05:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bZaJP-0006Cc-AE for qemu-devel@nongnu.org; Tue, 16 Aug 2016 05:05:35 -0400 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]:33273) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bZaJO-0006CW-Vu for qemu-devel@nongnu.org; Tue, 16 Aug 2016 05:05:31 -0400 Received: by mail-wm0-x242.google.com with SMTP id o80so15289291wme.0 for ; Tue, 16 Aug 2016 02:05:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=r8MzJ3OsyYvJCUPA9Mf0inA3GdFNtUN1X07UBmDxNsM=; b=0zpZ5uOI90EBnjjts2+OzuC8P1QgvCDv+uTS3ysIy1Rr+l+2YU7ugvxuoB8X93HyMf /luMI+2FDmdWIvJS9dpAWpTSlJ/ic4DKELB9rKhyQDRx+H+/s0drKnR3Amha1ao1ncto k7g+tYLFzEQbplB0avvIYpTvA+b6+P20mTLnKjusy19MjGcvHZOrPm8W2/HDbyunND1E OfaquL2HoA3D+oPuDh2HXl/IAX4gcI9fmk7LMl1y/L6U4iS10MAlmC0hnhguwH5cQMqj szli3G9UXVYCIFrxiRdd3kUv/tuiFw/neLgpkWmA/6uhaC1+K0JLnzNuN/+t7+mzB+99 U4yA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=r8MzJ3OsyYvJCUPA9Mf0inA3GdFNtUN1X07UBmDxNsM=; b=bX8T3k+g/jEkjj1AvqKDR5r1rPCMaYN2SaMZ1XjDOEPhSD/+8O0IamiomI+YZXbaDL 4DoCNsMhvjpN2SIv8PaUXfwwp5XtvZKCoF9R1yiXnXc66QKNJQnDgMdNoHMNdg+vBciH FBqN87W6aC1/tltEZSPxr/FeBL/4MJnqdGLgpVVcBbmr7xXAl9+QytXdMEOAWBwAb1Zn 0JtdS9FzY/5bLTLpyBk3+15EMmrT4WYbxkLU90zXfvjd54iNiz76hqqSaIDtiksMioVa lFbs64mU8tuqDmld9OcDB70gSoc4dODIcJ3pFgHvFIMDEsyMoet2lZfTnoq7s20Zz3l2 Ge9A== X-Gm-Message-State: AEkooutSUSvwnbHnNsOjhUeXm9p0FSk185XFUZqV6xz8+AS0shYx1WN2GPskU6s8Nx9h+g== X-Received: by 10.28.169.203 with SMTP id s194mr20697738wme.95.1471338330237; Tue, 16 Aug 2016 02:05:30 -0700 (PDT) Received: from a0999b0126e1.ant.amazon.com ([37.46.41.212]) by smtp.gmail.com with ESMTPSA id p4sm25618237wjq.27.2016.08.16.02.05.28 (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 16 Aug 2016 02:05:29 -0700 (PDT) From: Michael Rolnik To: qemu-devel@nongnu.org Date: Tue, 16 Aug 2016 12:05:14 +0300 Message-Id: <1471338320-8523-4-git-send-email-mrolnik@gmail.com> X-Mailer: git-send-email 2.4.9 (Apple Git-60) In-Reply-To: <1471338320-8523-1-git-send-email-mrolnik@gmail.com> References: <1471338320-8523-1-git-send-email-mrolnik@gmail.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2a00:1450:400c:c09::242 Subject: [Qemu-devel] [PATCH v15 3/9] target-avr: adding a sample AVR board X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: peter.maydell@linaro.org, Michael Rolnik , rth@twiddle.net Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Michael Rolnik --- 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 S: Maintained F: target-avr/ +F: hw/avr/ CRIS M: Edgar E. Iglesias 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 +# +# + +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 + * + */ + +/* + * 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) +