Skip to content

Commit

Permalink
hw/core/loader.c: Track last-seen ROM in rom_check_and_register_reset()
Browse files Browse the repository at this point in the history
In rom_check_and_register_reset() we detect overlaps by looking at
whether the ROM blob we're currently examining is in the same address
space and starts before the previous ROM blob ends.  (This works
because the ROM list is kept sorted in order by AddressSpace and then
by address.)

Instead of keeping the AddressSpace and last address of the previous ROM
blob in local variables, just keep a pointer to it.

This will allow us to print more useful information when we do detect
an overlap.

Signed-off-by: Peter Maydell <[email protected]>
Reviewed-by: Richard Henderson <[email protected]>
Message-id: [email protected]
  • Loading branch information
pm215 committed Dec 15, 2020
1 parent 05bcbcf commit 5b1de52
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions hw/core/loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -1166,28 +1166,35 @@ static void rom_reset(void *unused)
}
}

/* Return true if two consecutive ROMs in the ROM list overlap */
static bool roms_overlap(Rom *last_rom, Rom *this_rom)
{
if (!last_rom) {
return false;
}
return last_rom->as == this_rom->as &&
last_rom->addr + last_rom->romsize > this_rom->addr;
}

int rom_check_and_register_reset(void)
{
hwaddr addr = 0;
MemoryRegionSection section;
Rom *rom;
AddressSpace *as = NULL;
Rom *rom, *last_rom = NULL;

QTAILQ_FOREACH(rom, &roms, next) {
if (rom->fw_file) {
continue;
}
if (!rom->mr) {
if ((addr > rom->addr) && (as == rom->as)) {
if (roms_overlap(last_rom, rom)) {
fprintf(stderr, "rom: requested regions overlap "
"(rom %s. free=0x" TARGET_FMT_plx
", addr=0x" TARGET_FMT_plx ")\n",
rom->name, addr, rom->addr);
rom->name, last_rom->addr + last_rom->romsize,
rom->addr);
return -1;
}
addr = rom->addr;
addr += rom->romsize;
as = rom->as;
last_rom = rom;
}
section = memory_region_find(rom->mr ? rom->mr : get_system_memory(),
rom->addr, 1);
Expand Down

0 comments on commit 5b1de52

Please sign in to comment.