From patchwork Wed Aug 3 20:06:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alistair Francis X-Patchwork-Id: 655597 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3s4PXs1xzfz9sRZ for ; Thu, 4 Aug 2016 06:18:53 +1000 (AEST) Received: from localhost ([::1]:36518 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bV2cs-0002ff-Vr for incoming@patchwork.ozlabs.org; Wed, 03 Aug 2016 16:18:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:32936) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bV2S8-0000pK-1v for qemu-devel@nongnu.org; Wed, 03 Aug 2016 16:07:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1bV2S3-0001eZ-Qf for qemu-devel@nongnu.org; Wed, 03 Aug 2016 16:07:42 -0400 Received: from mail-bl2nam02on0051.outbound.protection.outlook.com ([104.47.38.51]:56576 helo=NAM02-BL2-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1bV2S3-0001eH-JM for qemu-devel@nongnu.org; Wed, 03 Aug 2016 16:07:39 -0400 Received: from SN1NAM02FT052.eop-nam02.prod.protection.outlook.com (10.152.72.51) by SN1NAM02HT141.eop-nam02.prod.protection.outlook.com (10.152.73.42) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.557.8; Wed, 3 Aug 2016 20:07:33 +0000 Authentication-Results: spf=fail (sender IP is 149.199.60.96) smtp.mailfrom=xilinx.com; redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=xilinx.com; Received-SPF: Fail (protection.outlook.com: domain of xilinx.com does not designate 149.199.60.96 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.60.96; helo=xsj-tvapsmtpgw01; Received: from xsj-tvapsmtpgw01 (149.199.60.96) by SN1NAM02FT052.mail.protection.outlook.com (10.152.72.146) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.567.7 via Frontend Transport; Wed, 3 Aug 2016 20:07:33 +0000 Received: from 172-16-1-203.xilinx.com ([172.16.1.203]:39010 helo=xsj-tvapsmtp02.xilinx.com) by xsj-tvapsmtpgw01 with esmtp (Exim 4.63) (envelope-from ) id 1bV2Rw-00026T-Kn; Wed, 03 Aug 2016 13:07:32 -0700 Received: from [127.0.0.1] (port=35837 helo=tsj-smtp-dlp1.xlnx.xilinx.com) by xsj-tvapsmtp02.xilinx.com with esmtp (Exim 4.63) (envelope-from ) id 1bV2Rw-0000lg-JA; Wed, 03 Aug 2016 13:07:32 -0700 Received: from xsj-tvapsmtp02 (xsj-tvapsmtp02.xilinx.com [172.16.1.203]) by tsj-smtp-dlp1.xlnx.xilinx.com (8.13.8/8.13.1) with ESMTP id u73K0iMZ006732; Wed, 3 Aug 2016 13:00:44 -0700 Received: from [172.19.74.182] (port=45302 helo=xsjalistai50.xilinx.com) by xsj-tvapsmtp02 with esmtp (Exim 4.63) (envelope-from ) id 1bV2Rv-0000ld-Iy; Wed, 03 Aug 2016 13:07:31 -0700 From: Alistair Francis To: , Date: Wed, 3 Aug 2016 13:06:50 -0700 Message-ID: <4d6e70dc122fafbe81d85beb257ce3e0d6479fb1.1470253246.git.alistair.francis@xilinx.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: X-RCIS-Action: ALLOW X-TM-AS-MML: disable X-TM-AS-Product-Ver: IMSS-7.1.0.1679-8.0.0.1202-22490.005 X-TM-AS-Result: No--15.403-7.0-31-10 X-imss-scan-details: No--15.403-7.0-31-10 X-TMASE-MatchedRID: By95iLghmgxYXTxImR5ZvCZm6wdY+F8KM3PBQtDBME+voBtU8+SlKTdS 293fdSg/jbUqhuP4DgFMFBLyjGb4lYrFHTmMFhb3UylSIDEm+Mdzd7C7BtJobtN4wOZZ8JcGDZV LXrOM4unB55sn6soSHGKt8MP+rfhxX79c1SLXpCxIOSHptb5tx8DZw0nL+opS2e73tJcoE9gnVT 2S49OfF0V8edMVEsKhJ9mVAtKoclsvjtMPTTOa8hcanaCAqviGVNyumldWne3fUZT83lbkEKcwf OzvS1WBTpgKTWoi1s3nU7CCEjbK3wa1NXbjqus0wLYk+NSxc5qqxXpq+unGVVrCirnOr0+sU3m+ JXAyVvAAX8fSJuWY0s5KMh5KMcHqvpR6acywKCslcqT+ugT9ENMB70WyBtjHCqIJhrrDy29yzNk fTVuQ1oxiDZnDw/PKAZkt9OWnDd9xVdFZc3w4BEKcYi5Qw/RVoprEeoZHCQKNTnqOMBIJ4Rfb6U ayfK22dKznysZuuFIQUGKV6L3hOZsYswdXk5rLFYJUGv4DL3wcg65CMI4oW1c/CedjlcvkbyI+Q 9zmtRlNVaE2+wxyP2rgmPvtYkbLlwt7DABrvp+eAiCmPx4NwBnUJ0Ek6yhjxEHRux+uk8jpP8tM OyYmaA== X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-HT: Tenant X-Forefront-Antispam-Report: CIP:149.199.60.96; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(1110001)(1109001)(339900001)(189002)(199003)(11100500001)(4326007)(86362001)(77096005)(7846002)(8676002)(50986999)(2950100001)(76176999)(305945005)(356003)(7696003)(9786002)(2906002)(105606002)(81166006)(586003)(19580395003)(118296001)(19580405001)(92566002)(5003940100001)(8936002)(33646002)(48376002)(229853001)(5001770100001)(106466001)(189998001)(47776003)(50466002)(71366001)(87936001)(81156014)(64026002)(85426001)(50226002)(36756003)(41533002)(107986001)(2004002); DIR:OUT; SFP:1101; SCL:1; SRVR:SN1NAM02HT141; H:xsj-tvapsmtpgw01; FPR:; SPF:Fail; PTR:unknown-60-96.xilinx.com; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; SN1NAM02FT052; 1:I+FiR0tOtitNe6gsNeK6hsVMuDJGDPU0OXVXJSk9RcKRzKEN3izjB9QDz4BEcKdXZm9ClrHrKwlVoA5vx50pJ1g8MrRBSZ3Ltk0tLpRa4UVjPsC/lAtB2fu7BJYchRHnA8bAoe76sVAs75eVv+UEHG0KNyHu8niqCDAjVxjOKAJXS5LKK0OgLQPx1S/J29q+yQ8walDjPwlOtylj1Fiq5kqbSFlmj3pn57GUv0u5o60pIWtwawmp4nXc55bW9xGL346lEArQgc1Zh2pXIyqPs3Ud0qYXPbH6vPE3zE9clhGigAxo9K+WP2jhgmo9epsCIwWSxmrk2SvfSjOiS1JKDWPegJXvhNqMBkC/BfA/PqIqXsBl2nkR+RVSrJkTK+xTp4WYNUm9ed3IH5cX3I/dtR8rdTdN8KCh7DxJkuZQlWXLNwTEoMq6FEq0EcKbbhJhLXebcZN5BGP9y9G7CZrItg8aM5Jo/p959Hsy9L8FE8saMR+tFjkoltes10VtzNXXE9PlO7+DnoP+vgGtDYhUszX0yz54tQP7j4WjBsum2w+Ei+Qc5cywfPAm9tZ7kXyTO10fTqOnWmP5KiNsSFAWQm3qI2GzU7YcQEtNVHkszxA= MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 4e840e13-d631-4011-e473-08d3bbd9ce6e X-Microsoft-Exchange-Diagnostics: 1; SN1NAM02HT141; 2:4py43PryC31u1ag9tuyWzNSONRvyt2PnC/ctJssGO9imkvCsT1uOKiPgjI9zut+BOQ6lV7wGgN4G9l3tbos8CrDmgkxowfuyk5inYMnJwvaOGL+s9THAnLzjHOURz05IxInJgaAvYUiX2R4oJO6a/9HpTlXlSD7CITj+9DHjnDKMb+fiaCDCug6CygUcrmyY; 3:Uoz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XFPnTqj7Xne/TCxxBwDjMJzoiRMJsmWYw== X-Microsoft-Exchange-Diagnostics: 1; SN1NAM02HT141; 31:ZdxtGAZkVIcZqsDRGWwtBrXjzNfI0YRk34cxhw15+2gp8cCgzCyfcti7ki10b7PoR68mTN0MUEKjBVDOvnyh1SDCff15kxJb8/GI8wZy2JdulI0WHtOrAG2oqOaGRkTwPUxQuZcLoXOwl+O1shgUQ55Un5d/iXb2uw5Xg7kr5ZMEkc+eiytXY/c6jdhOds0nj7Y0x7LY2Do5+opMzBfHolaLHeGweRyZn5lXDvEe+R4=; 20:sCAeDx0J7hKgEAkhS+mFWq7qkJdEQktOgJitGjMnAB1h+SCUYmR96F8OTMgw2t5KhRf16NoA1ngViV7DODsXSHj9eGRVH2L3fDTRlvM/NDcKZW8Dkcb+e3a48bDByxsEHF5p4ELgQ6bHAsSTQL1bq+iY34VK6F9WaHie4hAADRs1+daehsUq2G14P0ojONxgGSvnZm0Bb12882pWdfmJNNjxnrZRR3ev3U0sHmHqDWCzfAV4bGJyxPkZ0kuJhPR4h6HXCCAJoclN4Kl7FxtAbohh640Y5adbC3MEI+lf2wgw+8RUrzrQSLARVU77GL36Rxf5mGr3C4jEAAqoW6Wd8mBrCPBVhA+W3SjPQdMDcgD5pVWol+7XerEhSoO8LUnCdARWG485kZUhMv5ZP3fLhkFM3RVzuL3gNRsgIvmD1IthsKfgKt+jqCdhOqjwuLgf72IK472xRFkxA0wq9lnJMD+U5RJO5ig/Q2oBLSqilPlhhDtcuWI0R8Pjx8wmB9zO X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(192813158149592)(170618885588394); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040151)(601004)(2401047)(13023025)(13017025)(13024025)(13018025)(8121501046)(13015025)(5005006)(10201501046)(3002001)(6055026); SRVR:SN1NAM02HT141; BCL:0; PCL:0; RULEID:; SRVR:SN1NAM02HT141; X-Microsoft-Exchange-Diagnostics: 1; SN1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NYJQ/IhS11EA1ygdbiuscE2sO6XPSaQtwZholRGs03pUvg=3D?= =?us-ascii?Q?=3D?= X-Microsoft-Exchange-Diagnostics: 1; SN1NAM02HT141; 6:z8higaBFQbIiB1WjI3Ds2DjrAhHQfLcffdk3JTm8H40X5sOX1CiTSlqPGilopmQPpMfRshAelccgq7QgHj4opQ2+/5WwCoJGkQyM7EYmW3SwiyEafiASwyuM82wKwMwkYYreyeLZmbtWJxvdRtnxlGw84sQxx3W2SbgtOEkHTMrGmWM+2h7hl907Zf/a6L76KBgc+YDLOKZaRzL8st0Z6gWT4rkUlLIskBrbasTOAkYFkDamck0hswH2iaUieMy9d1VJEBsLS058xteEUBB5ZNe/w4L8XyvLDPMACmWxsJqlMJIgiwpsPgemKnvMKv5MFU6ltDlla69gC6z6STcdDw==; 5:lngEsfuvQKa/KWGbX8zDukeZLszCYY5e8yDLuv23iszfQZdPXZPaNGyFdjfxLw+3E2pRRdnOTQsNV7A9Eh1C6nB+n2jNvsZ0/O6dp9PvOnvdCZqqF5YJsffoW5wuVK64ggSS5Lx3ygYI71W3Xv37RQ==; 24:/ZapxgjAG69bPcQBgjOy9D56DoYqjnop5QvhtrKZE+dP4g8eJJEgh+OgSSP/GlBPLAOt57C0SL7kexOMYRwJ5zILfyrgPAMqMmr7jUjkMvQ=; 7:+4zviXfitQ2GSkc1Br8UnYkjJ1WEo3YTqXQc217gD8lppTv7spfrx2tG0LrWMgKHfAVifkE7eRTgNwlroP2U3MseMtni0JhVeX0/6Vk3w6enjGgWe8VzNwT1xXFY/b3ch0r+eo8egTj27d3bzIgOL8pH1Iw3Wy37aApJ0D2VwCQfzZurmOc5uEHv0lnwqtxxQyRBosCj9yTKUhQAHW6ITN1D6L1NT8fKVQML3tWBCkru4eIR3olmEBwk4NF9dYqd SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 03 Aug 2016 20:07:33.1293 (UTC) X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.60.96]; Helo=[xsj-tvapsmtpgw01] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN1NAM02HT141 X-detected-operating-system: by eggs.gnu.org: Windows 7 or 8 [fuzzy] X-Received-From: 104.47.38.51 Subject: [Qemu-devel] [PATCH v10 7/8] generic-loader: Add a generic loader 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: cov@codeaurora.org, crosthwaitepeter@gmail.com, pbonzini@redhat.com, armbru@redhat.com, alistair.francis@xilinx.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" Add a generic loader to QEMU which can be used to load images or set memory values. Signed-off-by: Alistair Francis Reviewed-by: Peter Maydell --- V10: - Split out the PC setting and data loading V9: - Fix error messages - Updated some incorrect logic - Add address space loading support for all image types - Explain why the reset is manually registered V8: - Code corrections - Rebase V7: - Rebase V6: - Add error checking V5: - Rebase V4: - Allow the loader to work with every architecture - Move the file to hw/core - Increase the maximum number of CPUs - Make the CPU operations conditional - Convert the cpu option to cpu-num - Require the user to specify endianess V3: - Pass the ram_size to load_image_targphys() V2: - Add maintainers entry - Perform bounds checking - Register and unregister the reset in the realise/unrealise Changes since RFC: - Add BE support MAINTAINERS | 6 ++ hw/core/Makefile.objs | 2 + hw/core/generic-loader.c | 195 +++++++++++++++++++++++++++++++++++++++ include/hw/core/generic-loader.h | 46 +++++++++ 4 files changed, 249 insertions(+) create mode 100644 hw/core/generic-loader.c create mode 100644 include/hw/core/generic-loader.h diff --git a/MAINTAINERS b/MAINTAINERS index 9c88c44..cc34ae0 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -984,6 +984,12 @@ M: Dmitry Fleytman S: Maintained F: hw/net/e1000e* +Generic Loader +M: Alistair Francis +S: Maintained +F: hw/core/generic-loader.c +F: include/hw/core/generic-loader.h + Subsystems ---------- Audio diff --git a/hw/core/Makefile.objs b/hw/core/Makefile.objs index cfd4840..939c94e 100644 --- a/hw/core/Makefile.objs +++ b/hw/core/Makefile.objs @@ -17,3 +17,5 @@ common-obj-$(CONFIG_SOFTMMU) += loader.o common-obj-$(CONFIG_SOFTMMU) += qdev-properties-system.o common-obj-$(CONFIG_SOFTMMU) += register.o common-obj-$(CONFIG_PLATFORM_BUS) += platform-bus.o + +obj-$(CONFIG_SOFTMMU) += generic-loader.o diff --git a/hw/core/generic-loader.c b/hw/core/generic-loader.c new file mode 100644 index 0000000..4ee71cb --- /dev/null +++ b/hw/core/generic-loader.c @@ -0,0 +1,195 @@ +/* + * Generic Loader + * + * Copyright (C) 2014 Li Guang + * Copyright (C) 2016 Xilinx Inc. + * Written by Li Guang + * + * 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. + * + * 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 "qemu/osdep.h" +#include "qom/cpu.h" +#include "hw/sysbus.h" +#include "sysemu/dma.h" +#include "hw/loader.h" +#include "qapi/error.h" +#include "hw/core/generic-loader.h" + +#define CPU_NONE 0xFFFFFFFF + +static void generic_loader_reset(void *opaque) +{ + GenericLoaderState *s = GENERIC_LOADER(opaque); + + if (s->set_pc && s->cpu) { + CPUClass *cc = CPU_GET_CLASS(s->cpu); + cpu_reset(s->cpu); + if (cc) { + cc->set_pc(s->cpu, s->addr); + } + } + + if (s->data_len) { + assert(s->data_len < sizeof(s->data)); + dma_memory_write((s->cpu ? s->cpu : first_cpu)->as, s->addr, &s->data, + s->data_len); + } +} + +static void generic_loader_realize(DeviceState *dev, Error **errp) +{ + GenericLoaderState *s = GENERIC_LOADER(dev); + hwaddr entry; + int big_endian; + int size = 0; + + s->set_pc = false; + + /* Perform some error checking on the user's options */ + if (s->data || s->data_len || s->data_be) { + /* User is loading memory values */ + if (s->file) { + error_setg(errp, "Specifying a file is not supported when loading " + "memory values"); + return; + } else if (s->force_raw) { + error_setg(errp, "Specifying force-raw is not supported when " + "loading memory values"); + return; + } else if (!s->data || !s->data_len) { + error_setg(errp, "Both data and data-len must be specified"); + return; + } else if (s->data_len > 8) { + error_setg(errp, "data-len cannot be greater then 8 bytes"); + return; + } else if (s->data_len > sizeof(s->data)) { + error_setg(errp, "data-len cannot be more then the data size"); + return; + } + } else if (s->file || s->force_raw) { + /* User is loading an image */ + if (s->data || s->data_len || s->data_be) { + error_setg(errp, "data can not be specified when loading an " + "image"); + return; + } + s->set_pc = true; + } else if (s->addr) { + /* User is setting the PC */ + if (s->data || s->data_len || s->data_be) { + error_setg(errp, "data can not be specified when setting a " + "program counter"); + return; + } + s->set_pc = true; + } else { + /* Did the user specify anything? */ + error_setg(errp, "please include valid arguments"); + return; + } + + qemu_register_reset(generic_loader_reset, dev); + + if (s->cpu_num != CPU_NONE) { + s->cpu = qemu_get_cpu(s->cpu_num); + if (!s->cpu) { + error_setg(errp, "Specified boot CPU#%d is nonexistent", + s->cpu_num); + return; + } + } + +#ifdef TARGET_WORDS_BIGENDIAN + big_endian = 1; +#else + big_endian = 0; +#endif + + if (s->file) { + if (!s->force_raw) { + size = load_elf_as(s->file, NULL, NULL, &entry, NULL, NULL, + big_endian, 0, 0, 0, + (s->cpu ? s->cpu : first_cpu)->as); + + if (size < 0) { + size = load_uimage_as(s->file, &entry, NULL, NULL, NULL, NULL, + (s->cpu ? s->cpu : first_cpu)->as); + } + } + + if (size < 0 || s->force_raw) { + /* Default to the maximum size being the machine's ram size */ + size = load_image_targphys_as(s->file, s->addr, ram_size, + (s->cpu ? s->cpu : first_cpu)->as); + } else { + s->addr = entry; + } + + if (size < 0) { + error_setg(errp, "Cannot load specified image %s", s->file); + return; + } + } + + /* Convert the data endiannes */ + if (s->data_be) { + s->data = cpu_to_be64(s->data); + } else { + s->data = cpu_to_le64(s->data); + } +} + +static void generic_loader_unrealize(DeviceState *dev, Error **errp) +{ + qemu_unregister_reset(generic_loader_reset, dev); +} + +static Property generic_loader_props[] = { + DEFINE_PROP_UINT64("addr", GenericLoaderState, addr, 0), + DEFINE_PROP_UINT64("data", GenericLoaderState, data, 0), + DEFINE_PROP_UINT8("data-len", GenericLoaderState, data_len, 0), + DEFINE_PROP_BOOL("data-be", GenericLoaderState, data_be, false), + DEFINE_PROP_UINT32("cpu-num", GenericLoaderState, cpu_num, CPU_NONE), + DEFINE_PROP_BOOL("force-raw", GenericLoaderState, force_raw, false), + DEFINE_PROP_STRING("file", GenericLoaderState, file), + DEFINE_PROP_END_OF_LIST(), +}; + +static void generic_loader_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + /* The reset function is not registered here and is instead registered in + * the realize function to allow this device to be added via the device_add + * command in the QEMU monitor. + * TODO: Improve the device_add functionality to allow resets to be + * connected + */ + dc->realize = generic_loader_realize; + dc->unrealize = generic_loader_unrealize; + dc->props = generic_loader_props; + dc->desc = "Generic Loader"; +} + +static TypeInfo generic_loader_info = { + .name = TYPE_GENERIC_LOADER, + .parent = TYPE_DEVICE, + .instance_size = sizeof(GenericLoaderState), + .class_init = generic_loader_class_init, +}; + +static void generic_loader_register_type(void) +{ + type_register_static(&generic_loader_info); +} + +type_init(generic_loader_register_type) diff --git a/include/hw/core/generic-loader.h b/include/hw/core/generic-loader.h new file mode 100644 index 0000000..dd27c42 --- /dev/null +++ b/include/hw/core/generic-loader.h @@ -0,0 +1,46 @@ +/* + * Generic Loader + * + * Copyright (C) 2014 Li Guang + * Written by Li Guang + * + * 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. + * + * 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. + */ + +#ifndef GENERIC_LOADER_H +#define GENERIC_LOADER_H + +#include "elf.h" + +typedef struct GenericLoaderState { + /* */ + DeviceState parent_obj; + + /* */ + CPUState *cpu; + + uint64_t addr; + uint64_t data; + uint8_t data_len; + uint32_t cpu_num; + + char *file; + + bool force_raw; + bool data_be; + bool set_pc; +} GenericLoaderState; + +#define TYPE_GENERIC_LOADER "loader" +#define GENERIC_LOADER(obj) OBJECT_CHECK(GenericLoaderState, (obj), \ + TYPE_GENERIC_LOADER) + +#endif