Skip to content

Commit

Permalink
Check ROM file contents for sanity and error out if system would be u…
Browse files Browse the repository at this point in the history
…nbootable
  • Loading branch information
Spritetm committed Jul 8, 2024
1 parent 831e54a commit d75a83c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions emu.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ Copyright (c) 2024 Sprite_tm <[email protected]>
log_printf(LOG_SRC_EMU, msg_level, format_and_args)
#define EMU_LOG_DEBUG(format_and_args...) EMU_LOG(LOG_DEBUG, format_and_args)
#define EMU_LOG_INFO( format_and_args...) EMU_LOG(LOG_INFO, format_and_args)
#define EMU_LOG_ERROR( format_and_args...) EMU_LOG(LOG_ERR, format_and_args)

typedef struct mem_range_t mem_range_t;

Expand Down Expand Up @@ -259,6 +260,18 @@ void setup_rom(const char *name, const char *filename) {
EMU_LOG_INFO("Loaded ROM '%s' into section '%s' at addr %x\n", filename, name, m->offset);
}

static int is_rom_sane(const char *name) {
mem_range_t *m=find_range_by_name(name);
uint32_t boot_vect=m->read32(m->obj, 4);
//boot vector needs to be aligned to even bytes
if (boot_vect&1) return 0;
//boot vector needs to point to a sane address
if (boot_vect<8) return 0;
if (boot_vect>0x810000) return 0;
//Seems OK.
return 1;
}

//Set up a range for an UART.
uart_t *setup_uart(const char *name, int is_console) {
mem_range_t *m=find_range_by_name(name);
Expand Down Expand Up @@ -934,6 +947,16 @@ void emu_start(emu_cfg_t *cfg) {
setup_mbus("MBUSMEM", "MBUSIO");
rtc_t *rtc=setup_rtc("RTC");

//Note: if you get these messages, are you sure you downloaded the ROMs via the *RAW* link in Github and
//not just threw the URL from your browser into wget or curl?
if (!is_rom_sane("U15")) {
EMU_LOG_ERROR("U15 ROM image does not look like a valid boot ROM! Emulator might not boot properly.\n");
}
if (!is_rom_sane("U17")) {
EMU_LOG_ERROR("U17 ROM image does not look like a valid boot ROM! Emulator cannot boot, exiting.\n");
exit(1);
}

void *cpuctx[2];
cpuctx[0]=calloc(m68k_context_size(), 1); //dma cpu
cpuctx[1]=calloc(m68k_context_size(), 1); //job cpu
Expand Down

0 comments on commit d75a83c

Please sign in to comment.