From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1N8LC2-0000HI-VF for qemu-devel@nongnu.org; Wed, 11 Nov 2009 16:57:35 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1N8LBy-0000Dh-Pw for qemu-devel@nongnu.org; Wed, 11 Nov 2009 16:57:34 -0500 Received: from [199.232.76.173] (port=54638 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1N8LBy-0000DS-B6 for qemu-devel@nongnu.org; Wed, 11 Nov 2009 16:57:30 -0500 Received: from mail-yx0-f188.google.com ([209.85.210.188]:38784) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1N8LBy-0003KM-12 for qemu-devel@nongnu.org; Wed, 11 Nov 2009 16:57:30 -0500 Received: by yxe26 with SMTP id 26so1379262yxe.4 for ; Wed, 11 Nov 2009 13:57:29 -0800 (PST) Message-ID: <4AFB3347.4080606@codemonkey.ws> Date: Wed, 11 Nov 2009 15:57:27 -0600 From: Anthony Liguori MIME-Version: 1.0 References: <1257962966-22902-1-git-send-email-agraf@suse.de> <1257962966-22902-3-git-send-email-agraf@suse.de> In-Reply-To: <1257962966-22902-3-git-send-email-agraf@suse.de> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH 2/6] Introduce copy_rom List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Alexander Graf Cc: glommer@redhat.com, qemu-devel@nongnu.org, avi@redhat.com Alexander Graf wrote: > We have several rom helpers currently, but none of them can get us > code that spans several roms into a pointer. > > This patch introduces a function that copies over rom contents. > > Signed-off-by: Alexander Graf > --- > hw/loader.c | 38 ++++++++++++++++++++++++++++++++++++++ > hw/loader.h | 1 + > 2 files changed, 39 insertions(+), 0 deletions(-) > > diff --git a/hw/loader.c b/hw/loader.c > index 9153b38..cab53c1 100644 > --- a/hw/loader.c > +++ b/hw/loader.c > @@ -701,6 +701,44 @@ static Rom *find_rom(target_phys_addr_t addr) > return NULL; > } > > +int copy_rom(uint8_t *dest, target_phys_addr_t addr, size_t size) > +{ > + target_phys_addr_t end = addr + size; > + uint8_t *s, *d = dest; > + size_t l = 0; > + Rom *rom; > + > + QTAILQ_FOREACH(rom, &roms, next) { > + if (rom->max) > + continue; > + if (rom->min > addr) > + continue; > + if (rom->min + rom->romsize < addr) > + continue; > + if (rom->min > end) > + break; > + if (!rom->data) > + continue; > + > + d = dest + (rom->min - addr); > + s = rom->data; > + l = rom->romsize; > + > + if (rom->min < addr) { > + d = dest; > + s += (addr - rom->min); > + l -= (addr - rom->min); > + } > + if ((d + l) > (dest + size)) { > + l = dest - d; > + } > + > + memcpy(d, s, l); > + } > + > + return (d + l) - dest; > +} > + > void *rom_ptr(target_phys_addr_t addr) > { > Rom *rom; > diff --git a/hw/loader.h b/hw/loader.h > index 67dae57..6cfb03a 100644 > --- a/hw/loader.h > +++ b/hw/loader.h > @@ -24,6 +24,7 @@ int rom_add_file(const char *file, > int rom_add_blob(const char *name, const void *blob, size_t len, > target_phys_addr_t min, target_phys_addr_t max, int align); > int rom_load_all(void); > +int copy_rom(uint8_t *dest, target_phys_addr_t addr, size_t size); > rom_copy() would have fit better. Regards, Anthony Liguori