From 700ac6719de330f47badc13fd3d0e861b17bd85c Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Thu, 5 Jan 2023 15:09:55 -1000 Subject: [PATCH] SCP: Assure only 5 UNIT fields can be initialized beyond the UDATA macro The simh v3 UNIT structure only provided UNIT fields wait, u3, u4, u5 and u6 available for static initialization beyond what is provided by the UDATA macro. This change assures that here as well. If a simulator developer needs to initialize UNIT fields beyond what is available here and via the UDATA macro, then explicit code usually in the DEVICE reset routine should be used to initialize those fields. Fix the CDC1700 simulator which statically initialized additional UNIT fields. --- CDC1700/cdc1700_cd.c | 52 ++++++++++++++++++++++++-------------------- CDC1700/cdc1700_dp.c | 10 ++++----- sim_defs.h | 20 ++++++++++++----- 3 files changed, 46 insertions(+), 36 deletions(-) diff --git a/CDC1700/cdc1700_cd.c b/CDC1700/cdc1700_cd.c index c30ae960..d50869d1 100644 --- a/CDC1700/cdc1700_cd.c +++ b/CDC1700/cdc1700_cd.c @@ -325,30 +325,14 @@ IO_DEVICE CDdev = IODEV(NULL, "1733-2", 1733, 3, 0xFF, 0, */ UNIT cd_unit[] = { - { UDATA(&cd_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_856_4, CD856_4_SIZE), - 0, 0, 0, 0, 0, &CDunits[0], &cd_unit[1] - }, - { UDATA(&cd_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_856_4, CD856_4_SIZE), - 0, 0, 0, 0, 0, &CDunits[0], &cd_unit[0] - }, - { UDATA(&cd_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_856_4, CD856_4_SIZE), - 0, 0, 0, 0, 0, &CDunits[1], &cd_unit[3] - }, - { UDATA(&cd_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_856_4, CD856_4_SIZE), - 0, 0, 0, 0, 0, &CDunits[1], &cd_unit[2] - }, - { UDATA(&cd_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_856_4, CD856_4_SIZE), - 0, 0, 0, 0, 0, &CDunits[2], &cd_unit[5] - }, - { UDATA(&cd_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_856_4, CD856_4_SIZE), - 0, 0, 0, 0, 0, &CDunits[2], &cd_unit[4] - }, - { UDATA(&cd_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_856_4, CD856_4_SIZE), - 0, 0, 0, 0, 0, &CDunits[3], &cd_unit[7] - }, - { UDATA(&cd_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_856_4, CD856_4_SIZE), - 0, 0, 0, 0, 0, &CDunits[3], &cd_unit[6] - } + { UDATA(&cd_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_856_4, CD856_4_SIZE)}, + { UDATA(&cd_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_856_4, CD856_4_SIZE)}, + { UDATA(&cd_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_856_4, CD856_4_SIZE)}, + { UDATA(&cd_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_856_4, CD856_4_SIZE)}, + { UDATA(&cd_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_856_4, CD856_4_SIZE)}, + { UDATA(&cd_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_856_4, CD856_4_SIZE)}, + { UDATA(&cd_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_856_4, CD856_4_SIZE)}, + { UDATA(&cd_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_856_4, CD856_4_SIZE)} }; REG cd_reg[] = { @@ -1058,7 +1042,27 @@ static t_stat CDreset(DEVICE *dptr) t_stat cd_reset(DEVICE *dptr) { t_stat r = SCPE_OK; + static t_bool Initialized = FALSE; + if (!Initialized) { /* Initialize additional UNIT state not done by UDATA macro */ + Initialized = TRUE; + cd_unit[0].up7 = &CDunits[0]; + cd_unit[0].up8 = &cd_unit[1]; + cd_unit[1].up7 = &CDunits[0]; + cd_unit[1].up8 = &cd_unit[0]; + cd_unit[2].up7 = &CDunits[1]; + cd_unit[2].up8 = &cd_unit[3]; + cd_unit[3].up7 = &CDunits[1]; + cd_unit[3].up8 = &cd_unit[2]; + cd_unit[4].up7 = &CDunits[2]; + cd_unit[4].up8 = &cd_unit[5]; + cd_unit[5].up7 = &CDunits[2]; + cd_unit[5].up8 = &cd_unit[4]; + cd_unit[6].up7 = &CDunits[3]; + cd_unit[6].up8 = &cd_unit[7]; + cd_unit[7].up7 = &CDunits[3]; + cd_unit[7].up8 = &cd_unit[6]; + } if (IOFWinitialized) if ((dptr->flags & DEV_DIS) == 0) if ((r = checkReset(dptr, CDdev.iod_equip) == SCPE_OK)) { diff --git a/CDC1700/cdc1700_dp.c b/CDC1700/cdc1700_dp.c index 1e0aa491..face232c 100644 --- a/CDC1700/cdc1700_dp.c +++ b/CDC1700/cdc1700_dp.c @@ -249,12 +249,8 @@ IO_DEVICE DPdev = IODEV(NULL, "1738-B", 1738, 3, 0xFF, 0, */ UNIT dp_unit[] = { - { UDATA(&dp_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_854, DP854_SIZE), - 0, 0, 0, 0, 0, &DPunits[0] - }, - { UDATA(&dp_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_854, DP854_SIZE), - 0, 0, 0, 0, 0, &DPunits[1] - }, + { UDATA(&dp_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_854, DP854_SIZE)}, + { UDATA(&dp_svc, UNIT_FIX+UNIT_ATTABLE+UNIT_DISABLE+UNIT_854, DP854_SIZE)}, }; REG dp_reg[] = { @@ -812,6 +808,8 @@ t_stat dp_reset(DEVICE *dptr) { t_stat r; + dp_unit[0].up7 = &DPunits[0]; + dp_unit[1].up7 = &DPunits[1]; if (IOFWinitialized) if ((dptr->flags & DEV_DIS) == 0) if ((r = checkReset(dptr, DPdev.iod_equip)) != SCPE_OK) diff --git a/sim_defs.h b/sim_defs.h index cec4d543..0b48e3f8 100644 --- a/sim_defs.h +++ b/sim_defs.h @@ -594,11 +594,6 @@ struct UNIT { void (*io_flush)(UNIT *up); /* io flush routine */ uint32 iostarttime; /* I/O start time */ int32 buf; /* buffer */ - int32 wait; /* wait */ - int32 u3; /* device specific */ - int32 u4; /* device specific */ - int32 u5; /* device specific */ - int32 u6; /* device specific */ void *up7; /* device specific */ void *up8; /* device specific */ uint16 us9; /* device specific */ @@ -631,6 +626,14 @@ struct UNIT { double a_due_gtime; /* due time (in instructions) for timer event */ double a_usec_delay; /* time delay for timer event */ #endif + /* Everything above here in the UNIT structure is within the scope of the UDATA + macro initializer, if a simulator developer wants to initialize any of these + values, they must be done by explicit code usually in a device reset routine */ + int32 wait; /* wait */ + int32 u3; /* device specific */ + int32 u4; /* device specific */ + int32 u5; /* device specific */ + int32 u6; /* device specific */ }; /* Unit flags */ @@ -911,7 +914,12 @@ struct MEMFILE { */ -#define UDATA(act,fl,cap) NULL,act,NULL,NULL,NULL,NULL,0,0,(fl),0,(cap),0,NULL,0,0 +#ifdef SIM_ASYNCH_IO +#define UDATA(act,fl,cap) NULL,act,NULL,NULL,NULL,NULL,0,0,(fl),0,(cap),0,NULL,0,0,NULL,NULL,0,0,NULL,NULL,NULL,0,0,0,NULL,0,NULL,NULL,0,NULL,\ + NULL,NULL,NULL,0,NULL,0,0,0,0,0 +#else +#define UDATA(act,fl,cap) NULL,act,NULL,NULL,NULL,NULL,0,0,(fl),0,(cap),0,NULL,0,0,NULL,NULL,0,0,NULL,NULL,NULL,0,0,0,NULL,0,NULL,NULL,0,NULL +#endif /* Register initialization macros.