diff options
author | Alexander Graf <agraf@suse.de> | 2009-11-12 21:53:11 +0100 |
---|---|---|
committer | Anthony Liguori <aliguori@us.ibm.com> | 2009-11-17 10:38:57 -0600 |
commit | 235f86ef01470391925e7edec71638b41ffa5537 (patch) | |
tree | 6608c1ed7a492d09ab58569dd0aa9c473826de66 /hw/loader.c | |
parent | ff06108b182b83e4c42c89f1724a30217ad7c073 (diff) |
Introduce rom_copy
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 <agraf@suse.de>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'hw/loader.c')
-rw-r--r-- | hw/loader.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/hw/loader.c b/hw/loader.c index 7f9fc2157a..2d7a2c4954 100644 --- a/hw/loader.c +++ b/hw/loader.c @@ -708,6 +708,44 @@ static Rom *find_rom(target_phys_addr_t addr) return NULL; } +int rom_copy(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; |