1
0
mirror of https://github.com/cc65/cc65.git synced 2024-06-15 17:30:06 +00:00

sim65: cycles does not increment 1 at a time, so some small overhead is needed in range check

This commit is contained in:
bbbradsmith 2023-05-06 13:54:28 -04:00
parent c03d00bc80
commit 84f0ab322d
4 changed files with 11 additions and 6 deletions

View File

@ -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);
}
}

View File

@ -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)

View File

@ -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)

View File

@ -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)