diff --git a/scp.c b/scp.c index 05e290ff..fec5ca80 100644 --- a/scp.c +++ b/scp.c @@ -311,14 +311,16 @@ else *(((uint32 *) mb) + ((uint32) j)) = v; #endif -#define SIM_DBG_EVENT_NEG 0x01000000 /* negative event dispatch activities */ -#define SIM_DBG_EVENT 0x02000000 /* event dispatch activities */ -#define SIM_DBG_ACTIVATE 0x04000000 /* queue insertion activities */ -#define SIM_DBG_AIO_QUEUE 0x08000000 /* asynch event queue activities */ -#define SIM_DBG_EXP_STACK 0x10000000 /* expression stack activities */ -#define SIM_DBG_EXP_EVAL 0x20000000 /* expression evaluation activities */ -#define SIM_DBG_BRK_ACTION 0x40000000 /* action activities */ -#define SIM_DBG_DO 0x80000000 /* do activities */ +#define SIM_DBG_EVENT_NEG 0x80000000 /* negative event dispatch activities */ +#define SIM_DBG_EVENT 0x40000000 /* event dispatch activities */ +#define SIM_DBG_ACTIVATE 0x20000000 /* queue insertion activities */ +#define SIM_DBG_AIO_QUEUE 0x10000000 /* asynch event queue activities */ +#define SIM_DBG_EXP_STACK 0x08000000 /* expression stack activities */ +#define SIM_DBG_EXP_EVAL 0x04000000 /* expression evaluation activities */ +#define SIM_DBG_BRK_ACTION 0x02000000 /* action activities */ +#define SIM_DBG_DO 0x01000000 /* do activities */ +#define SIM_DBG_SAVE 0x00800000 /* save activities */ +#define SIM_DBG_RESTORE 0x00400000 /* restore activities */ static DEBTAB scp_debug[] = { {"EVENT", SIM_DBG_EVENT, "Event Dispatch Activities"}, @@ -329,6 +331,8 @@ static DEBTAB scp_debug[] = { {"EXPEVAL", SIM_DBG_EXP_EVAL, "Expression Evaluation Activities"}, {"ACTION", SIM_DBG_BRK_ACTION, "If/Breakpoint/Expect Action Activities"}, {"DO", SIM_DBG_DO, "Do Command/Expansion Activities"}, + {"SAVE", SIM_DBG_SAVE, "Save Activities"}, + {"RESTORE", SIM_DBG_RESTORE, "Restore Activities"}, {0} }; @@ -8064,6 +8068,8 @@ REG *rptr; #define WRITE_I(xx) sim_fwrite (&(xx), sizeof (xx), 1, sfile) +sim_debug(SIM_DBG_SAVE, &sim_scp_dev, "sim_save ()\n"); + /* Don't make changes below without also changing save_vercur above */ fprintf (sfile, "%s\n%s\n%s\n%s\n%s\n%.0f\n", @@ -8090,6 +8096,7 @@ for (i = 0; i < (device_count + sim_internal_device_count); i++) {/* loop thru d dptr = sim_internal_devices[i - device_count]; if (dptr->flags & DEV_NOSAVE) continue; + sim_debug (SIM_DBG_SAVE, &sim_scp_dev, "Saving %s\n", dptr->name); fputs (dptr->name, sfile); /* device name */ fputc ('\n', sfile); if (dptr->lname) /* [V3.0] logical name */ @@ -8220,7 +8227,7 @@ char **attnames = NULL; UNIT **attunits = NULL; int32 *attswitches = NULL; int32 attcnt = 0; -void *mbuf; +void *mbuf = NULL; int32 j, blkcnt, limit, unitno, time, flg; uint32 us, depth; t_addr k, high, old_capac; @@ -8237,6 +8244,7 @@ t_bool dont_detach_attach = ((sim_switches & SWMASK ('D')) != 0); t_bool suppress_warning = ((sim_switches & SWMASK ('Q')) != 0); t_bool warned = FALSE; +sim_debug (SIM_DBG_RESTORE, &sim_scp_dev, "sim_rest (force=%d, dont_detach=%d, nowarnings=%d)\n", force_restore, dont_detach_attach, suppress_warning); sim_switches &= ~(SWMASK ('F') | SWMASK ('D') | SWMASK ('Q')); /* remove digested switches */ #define READ_S(xx) if (read_line ((xx), sizeof(xx), rfile) == NULL) { \ r = SCPE_IOERR; \ @@ -8252,6 +8260,7 @@ if (fstat (fileno (rfile), &rstat)) { goto Cleanup_Return; } READ_S (buf); /* [V2.5+] read version */ +sim_debug (SIM_DBG_RESTORE, &sim_scp_dev, "version=%s\n", buf); v40 = v35 = v32 = FALSE; if (strcmp (buf, save_ver40) == 0) /* version 4.0? */ v40 = v35 = v32 = TRUE; @@ -8268,6 +8277,7 @@ if ((strcmp (buf, save_ver40) != 0) && (!sim_quiet) && (!suppress_warning)) { warned = TRUE; } READ_S (buf); /* read sim name */ +sim_debug (SIM_DBG_RESTORE, &sim_scp_dev, "sim_name=%s\n", buf); if (strcmp (buf, sim_savename)) { /* name match? */ sim_printf ("Wrong system type: %s\n", buf); return SCPE_INCOMP; @@ -8326,12 +8336,15 @@ for ( ;; ) { /* device loop */ READ_S (buf); /* read device name */ if (buf[0] == 0) /* last? */ break; + sim_debug (SIM_DBG_RESTORE, &sim_scp_dev, "DEVICE=%s\n", buf); if ((dptr = find_dev (buf)) == NULL) { /* locate device */ sim_printf ("Invalid device name: %s\n", buf); r = SCPE_INCOMP; goto Cleanup_Return; } READ_S (buf); /* [V3.0+] logical name */ + if (buf[0] != '\0') + sim_debug (SIM_DBG_RESTORE, &sim_scp_dev, "logical name=%s\n", buf); deassign_device (dptr); /* delete old name */ if ((buf[0] != 0) && ((r = assign_device (dptr, buf)) != SCPE_OK)) { @@ -8339,6 +8352,7 @@ for ( ;; ) { /* device loop */ goto Cleanup_Return; } READ_I (flg); /* [V2.10+] ctlr flags */ + sim_debug (SIM_DBG_RESTORE, &sim_scp_dev, "DEVICE.flags=%0X\n", flg); if (!v32) flg = ((flg & DEV_UFMASK_31) << (DEV_V_UF - DEV_V_UF_31)) | (flg & ~DEV_UFMASK_31); /* [V3.2+] flags moved */ @@ -8437,36 +8451,34 @@ for ( ;; ) { /* device loop */ sim_printf ("\n"); } sz = SZ_D (dptr); /* allocate buffer */ - if ((mbuf = calloc (SRBSIZ, sz)) == NULL) { + if ((mbuf = realloc (mbuf, SRBSIZ * sz)) == NULL) { r = SCPE_MEM; goto Cleanup_Return; } for (k = 0; k < high; ) { /* loop thru mem */ if (sim_fread (&blkcnt, sizeof (blkcnt), 1, rfile) == 0) {/* block count */ - free (mbuf); r = SCPE_IOERR; goto Cleanup_Return; } if (blkcnt < 0) /* compressed? */ limit = -blkcnt; - else limit = (int32)sim_fread (mbuf, sz, blkcnt, rfile); + else + limit = (int32)sim_fread (mbuf, sz, blkcnt, rfile); if (limit <= 0) { /* invalid or err? */ - free (mbuf); r = SCPE_IOERR; goto Cleanup_Return; } for (j = 0; j < limit; j++, k = k + (dptr->aincr)) { if (blkcnt < 0) /* compressed? */ val = 0; - else SZ_LOAD (sz, val, mbuf, j); /* saved value */ + else + SZ_LOAD (sz, val, mbuf, j); /* saved value */ r = dptr->deposit (val, k, uptr, SIM_SW_REST); if (r != SCPE_OK) { - free (mbuf); goto Cleanup_Return; } } /* end for j */ } /* end for k */ - free (mbuf); /* dealloc buffer */ } /* end if high */ } /* end unit loop */ for ( ;; ) { /* register loop */ @@ -8474,6 +8486,7 @@ for ( ;; ) { /* device loop */ if (buf[0] == 0) /* last? */ break; READ_I (depth); /* [V2.10+] depth */ + sim_debug (SIM_DBG_RESTORE, &sim_scp_dev, "REGISTER=%s, depth=%u\n", buf, depth); if ((rptr = find_reg (buf, NULL, dptr)) == NULL) { sim_printf ("Invalid register name: %s %s\n", sim_dname (dptr), buf); for (us = 0; us < depth; us++) { /* skip values */ @@ -8493,8 +8506,10 @@ for ( ;; ) { /* device loop */ if (val > mask) { /* value ok? */ sim_printf ("Invalid register value: %s %s\n", sim_dname (dptr), buf); } - else if (us < rptr->depth) /* in range? */ - put_rval (rptr, us, val); + else { + if (us < rptr->depth) /* in range? */ + put_rval(rptr, us, val); + } } } /* end register loop */ } /* end device loop */ @@ -8506,6 +8521,7 @@ for (j=0, r = SCPE_OK; jdepth > 1) && (rptr->flags & REG_UNIT)) { #endif } else if ((rptr->depth > 1) && (rptr->flags & REG_STRUCT)) { - ptr = (uint32 *)(((size_t) rptr->loc) + (idx * rptr->str_size)); + ptr = (uint32 *)(((size_t)rptr->loc) + (idx * rptr->str_size)); #if defined (USE_INT64) if (sz <= sizeof (uint32)) *((uint32 *) ptr) = (*((uint32 *) ptr) &