From 84f0ab322d4b056191fd09d8fbc792ba1e045453 Mon Sep 17 00:00:00 2001 From: bbbradsmith Date: Sat, 6 May 2023 13:54:28 -0400 Subject: [PATCH] sim65: cycles does not increment 1 at a time, so some small overhead is needed in range check --- src/sim65/main.c | 11 ++++++++--- test/asm/val/Makefile | 2 +- test/standard/Makefile | 2 +- test/val/Makefile | 2 +- 4 files changed, 11 insertions(+), 6 deletions(-) diff --git a/src/sim65/main.c b/src/sim65/main.c index 27299168e..d92d52ef6 100644 --- a/src/sim65/main.c +++ b/src/sim65/main.c @@ -64,6 +64,12 @@ const char* ProgramFile; /* exit simulator after MaxCycles Cycles */ unsigned long MaxCycles; +/* maximum number of cycles that can be tested, +** requires overhead for longest possible instruction, +** which should be 7, using 16 for safety. +*/ +#define MAXCYCLES_LIMIT (ULONG_MAX-16) + /* Header signature 'sim65' */ static const unsigned char HeaderSignature[] = { 0x73, 0x69, 0x6D, 0x36, 0x35 @@ -73,7 +79,6 @@ static const unsigned char HeaderSignature[] = { static const unsigned char HeaderVersion = 2; - /*****************************************************************************/ /* Code */ /*****************************************************************************/ @@ -142,8 +147,8 @@ static void OptQuitXIns (const char* Opt attribute ((unused)), { MaxCycles = strtoul(Arg, NULL, 0); /* Guard against overflow. */ - if (MaxCycles == ULONG_MAX && errno == ERANGE) { - Error("'-x parameter out of range. Max: %lu",ULONG_MAX); + if (MaxCycles >= MAXCYCLES_LIMIT) { + Error("'-x parameter out of range. Max: %lu",MAXCYCLES_LIMIT); } } diff --git a/test/asm/val/Makefile b/test/asm/val/Makefile index 49b6d5290..09a6b91bc 100644 --- a/test/asm/val/Makefile +++ b/test/asm/val/Makefile @@ -23,7 +23,7 @@ ifdef QUIET endif # sim65 can support 64-bit cycle counts on some platforms, but not all. This must fit in 32-bit. -SIM65FLAGS = -x 4294967295 +SIM65FLAGS = -x 4000000000 CA65 := $(if $(wildcard ../../../bin/ca65*),..$S..$S..$Sbin$Sca65,ca65) LD65 := $(if $(wildcard ../../../bin/ld65*),..$S..$S..$Sbin$Sld65,ld65) diff --git a/test/standard/Makefile b/test/standard/Makefile index 9993ba699..40299c1bf 100644 --- a/test/standard/Makefile +++ b/test/standard/Makefile @@ -23,7 +23,7 @@ ifdef QUIET endif # sim65 can support 64-bit cycle counts on some platforms, but not all. This must fit in 32-bit. -SIM65FLAGS = -x 4294967295 -c +SIM65FLAGS = -x 4000000000 -c CC65 := $(if $(wildcard ../../bin/cc65*),..$S..$Sbin$Scc65,cc65) CA65 := $(if $(wildcard ../../bin/ca65*),..$S..$Sbin$Sca65,ca65) diff --git a/test/val/Makefile b/test/val/Makefile index 8820e535a..158967f9e 100644 --- a/test/val/Makefile +++ b/test/val/Makefile @@ -25,7 +25,7 @@ ifdef QUIET endif # sim65 can support 64-bit cycle counts on some platforms, but not all. This must fit in 32-bit. -SIM65FLAGS = -x 4294967295 -c +SIM65FLAGS = -x 4000000000 -c CC65 := $(if $(wildcard ../../bin/cc65*),..$S..$Sbin$Scc65,cc65) CA65 := $(if $(wildcard ../../bin/ca65*),..$S..$Sbin$Sca65,ca65)