Revision 235f86ef hw/loader.c

b/hw/loader.c
708 708
    return NULL;
709 709
}
710 710

  
711
int rom_copy(uint8_t *dest, target_phys_addr_t addr, size_t size)
712
{
713
    target_phys_addr_t end = addr + size;
714
    uint8_t *s, *d = dest;
715
    size_t l = 0;
716
    Rom *rom;
717

  
718
    QTAILQ_FOREACH(rom, &roms, next) {
719
        if (rom->max)
720
            continue;
721
        if (rom->min > addr)
722
            continue;
723
        if (rom->min + rom->romsize < addr)
724
            continue;
725
        if (rom->min > end)
726
            break;
727
        if (!rom->data)
728
            continue;
729

  
730
        d = dest + (rom->min - addr);
731
        s = rom->data;
732
        l = rom->romsize;
733

  
734
        if (rom->min < addr) {
735
            d = dest;
736
            s += (addr - rom->min);
737
            l -= (addr - rom->min);
738
        }
739
        if ((d + l) > (dest + size)) {
740
            l = dest - d;
741
        }
742

  
743
        memcpy(d, s, l);
744
    }
745

  
746
    return (d + l) - dest;
747
}
748

  
711 749
void *rom_ptr(target_phys_addr_t addr)
712 750
{
713 751
    Rom *rom;

Also available in: Unified diff