From 58506fe0240ff2902e9fb740cab6df80e1436baa Mon Sep 17 00:00:00 2001 From: Michel Pollet Date: Fri, 6 Apr 2012 18:25:10 +0100 Subject: [PATCH] core: Increased the number of possible IOs Also added a sanity check Signed-off-by: Michel Pollet --- simavr/sim/sim_avr.h | 2 +- simavr/sim/sim_io.c | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/simavr/sim/sim_avr.h b/simavr/sim/sim_avr.h index 6c0fc03..bcc5898 100644 --- a/simavr/sim/sim_avr.h +++ b/simavr/sim/sim_avr.h @@ -53,7 +53,7 @@ enum { R_SREG = 32+0x3f, // maximum number of IO registers, on normal AVRs - MAX_IOs = 256 - 32, // minus 32 GP registers + MAX_IOs = 256, // Bigger AVRs need more than 256-32 (mega1280) }; #define AVR_DATA_TO_IO(v) ((v) - 32) diff --git a/simavr/sim/sim_io.c b/simavr/sim/sim_io.c index 2fa455b..7edb786 100644 --- a/simavr/sim/sim_io.c +++ b/simavr/sim/sim_io.c @@ -99,6 +99,12 @@ avr_register_io_write( { avr_io_addr_t a = AVR_DATA_TO_IO(addr); + if (a >= MAX_IOs) { + fprintf(stderr, + "Error: avr_register_io_write(): IO address 0x%04x out of range (max 0x%04x).\n", + a, MAX_IOs); + abort(); + } /* * Verifying that some other piece of code is not installed to watch write * on this address. If there is, this code installs a "dispatcher" callback -- 2.39.5