Message ID | 1257962966-22902-3-git-send-email-agraf@suse.de |
---|---|
State | New |
Headers | show |
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 <agraf@suse.de> > --- > 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
On 11.11.2009, at 22:57, Anthony Liguori wrote: > 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 <agraf@suse.de> >> --- >> 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. Ok, will rename in v2. Alex
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); void *rom_ptr(target_phys_addr_t addr); void do_info_roms(Monitor *mon);
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> --- hw/loader.c | 38 ++++++++++++++++++++++++++++++++++++++ hw/loader.h | 1 + 2 files changed, 39 insertions(+), 0 deletions(-)