From 17f61323521750ce114db864771bffe74eaa7251 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Tue, 30 Dec 2014 11:57:19 -0800 Subject: [PATCH 1/6] alpha: Compiler suggested cleanups --- alpha/alpha_cpu.c | 12 ++++++------ alpha/alpha_defs.h | 4 ---- alpha/alpha_ev5_cons.c | 2 +- alpha/alpha_ev5_pal.c | 3 ++- alpha/alpha_fpv.c | 2 +- alpha/alpha_sys.c | 3 ++- 6 files changed, 12 insertions(+), 14 deletions(-) diff --git a/alpha/alpha_cpu.c b/alpha/alpha_cpu.c index 6cc6544b..7a6d7c1c 100644 --- a/alpha/alpha_cpu.c +++ b/alpha/alpha_cpu.c @@ -393,7 +393,7 @@ while (reason == 0) { } if (sim_interval <= 0) { /* chk clock queue */ - if (reason = sim_process_event ()) break; + if ((reason = sim_process_event ())) break; intr_summ = pal_eval_intr (1); /* eval interrupts */ } @@ -1433,7 +1433,7 @@ while (reason == 0) { case 0x39: /* MINSW4 */ if (!(arch_mask & AMASK_MVI)) ABORT (EXC_RSVI); - for (i = 0, res = 0; i < 8; i = i++) { + for (i = 0, res = 0; i < 8; i++) { s1 = SEXT_W_Q (R[ra] >> (i << 4)); s2 = SEXT_W_Q (rbv >> (i << 4)); res = res | (((s1 <= s2)? R[ra]: rbv) & word_mask[i]); @@ -1451,7 +1451,7 @@ while (reason == 0) { case 0x3B: /* MINUW4 */ if (!(arch_mask & AMASK_MVI)) ABORT (EXC_RSVI); - for (i = 0, res = 0; i < 8; i = i++) { + for (i = 0, res = 0; i < 8; i++) { s64 = R[ra] & word_mask[i]; t64 = rbv & word_mask[i]; res = res | ((s64 <= t64)? s64: t64); @@ -1469,7 +1469,7 @@ while (reason == 0) { case 0x3D: /* MAXUW4 */ if (!(arch_mask & AMASK_MVI)) ABORT (EXC_RSVI); - for (i = 0, res = 0; i < 8; i = i++) { + for (i = 0, res = 0; i < 8; i++) { s64 = R[ra] & word_mask[i]; t64 = rbv & word_mask[i]; res = res | ((s64 >= t64)? s64: t64); @@ -1487,7 +1487,7 @@ while (reason == 0) { case 0x3F: /* MAXSW4 */ if (!(arch_mask & AMASK_MVI)) ABORT (EXC_RSVI); - for (i = 0, res = 0; i < 8; i = i++) { + for (i = 0, res = 0; i < 8; i++) { s1 = SEXT_W_Q (R[ra] >> (i << 4)); s2 = SEXT_W_Q (rbv >> (i << 4)); res = res | (((s1 >= s2)? R[ra]: rbv) & word_mask[i]); @@ -1834,7 +1834,7 @@ return SCPE_OK; t_stat cpu_show_hist (FILE *st, UNIT *uptr, int32 val, void *desc) { -uint32 k, di, lnt; +int32 k, di, lnt; char *cptr = (char *) desc; t_stat r; InstHistory *h; diff --git a/alpha/alpha_defs.h b/alpha/alpha_defs.h index 6f1ee907..7090bc94 100644 --- a/alpha/alpha_defs.h +++ b/alpha/alpha_defs.h @@ -34,11 +34,7 @@ #include "sim_defs.h" #include -#if defined (__GNUC__) -#define INLINE inline -#else #define INLINE -#endif /* Configuration */ diff --git a/alpha/alpha_ev5_cons.c b/alpha/alpha_ev5_cons.c index fb576705..f7675fb1 100644 --- a/alpha/alpha_ev5_cons.c +++ b/alpha/alpha_ev5_cons.c @@ -133,7 +133,7 @@ if ((dtlb_spage & SPEN_43) && (VPN_GETSP43 (vpn) == 2)) return (va & SP43_MASK); /* 43b superpage? */ if ((dtlb_spage & SPEN_32) && (VPN_GETSP32 (vpn) == 0x1FFE)) return (va & SP32_MASK); /* 32b superpage? */ -if (tlbp = dtlb_lookup (vpn)) /* try TLB */ +if ((tlbp = dtlb_lookup (vpn))) /* try TLB */ return PHYS_ADDR (tlbp->pfn, va); /* found it */ if (ev5_mcsr & MCSR_NT) exc = cons_find_pte_nt (va, &pte64); else exc = cons_find_pte_srm (va, &pte64); diff --git a/alpha/alpha_ev5_pal.c b/alpha/alpha_ev5_pal.c index 4910b0ce..124968e4 100644 --- a/alpha/alpha_ev5_pal.c +++ b/alpha/alpha_ev5_pal.c @@ -904,7 +904,8 @@ t_stat parse_pal_hwre (char *cptr, t_value *inst) { uint32 i, d, val = 0; int32 reg; -char *tptr, gbuf[CBUFSIZE]; +const char *tptr; +char gbuf[CBUFSIZE]; t_stat r; cptr = get_glyph (cptr, gbuf, '/'); diff --git a/alpha/alpha_fpv.c b/alpha/alpha_fpv.c index 67fca723..90513448 100644 --- a/alpha/alpha_fpv.c +++ b/alpha/alpha_fpv.c @@ -209,7 +209,7 @@ t_uint64 vax_cvtif (t_uint64 val, uint32 ir, uint32 dp) UFP a; if (val == 0) return 0; /* 0? return +0 */ -if (val < 0) { /* < 0? */ +if ((val & Q_SIGN) != 0) { /* < 0? */ a.sign = 1; /* set sign */ val = NEG_Q (val); /* |val| */ } diff --git a/alpha/alpha_sys.c b/alpha/alpha_sys.c index 6d84f75a..c3e4c8a4 100644 --- a/alpha/alpha_sys.c +++ b/alpha/alpha_sys.c @@ -716,7 +716,8 @@ t_uint64 bra, df, db; uint32 i, k, lit8, fl; int32 reg; t_stat r; -char *tptr, gbuf[CBUFSIZE]; +const char *tptr; +char gbuf[CBUFSIZE]; if ((r = parse_pal_hwre (cptr, inst)) < 0) return r; /* PAL hardware? */ cptr = get_glyph (cptr, gbuf, 0); /* get opcode */ From 2819ff634e0b2d2a74e69a2c1269d3fc4a89866b Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Tue, 30 Dec 2014 17:49:36 -0800 Subject: [PATCH 2/6] BESM6: FIx makefile conditional logic detecting available SDL components --- makefile | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/makefile b/makefile index 162a954f..9e92b82c 100644 --- a/makefile +++ b/makefile @@ -1175,10 +1175,12 @@ FORMATDISK = ${BESM6D}/formatdisk.c ifeq (,${VIDEO_LDFLAGS}) BESM6_OPT = -I ${BESM6D} -DUSE_INT64 -else ifneq (,$(and $(findstring,SDL2,${VIDEO_LDFLAGS})),$(and($(find_include, SDL2/SDL_ttf),$(find_lib,SDL2_ttf)))) +else ifneq (,$(and $(findstring SDL2,${VIDEO_LDFLAGS}),$(call find_include,SDL2/SDL_ttf),$(call find_lib,SDL2_ttf))) BESM6_OPT = -I ${BESM6D} -DUSE_INT64 ${VIDEO_CCDEFS} ${VIDEO_LDFLAGS} -lSDL2_ttf -else ifneq (,$(and $(find_include, SDL/SDL_ttf),$(find_lib,SDL_ttf))) +else ifneq (,$(and $(call find_include,SDL/SDL_ttf),$(call find_lib,SDL_ttf))) BESM6_OPT = -I ${BESM6D} -DUSE_INT64 ${VIDEO_CCDEFS} ${VIDEO_LDFLAGS} -lSDL_ttf +else + BESM6_OPT = -I ${BESM6D} -DUSE_INT64 endif ### From 76dd31ae027d4216749b070783a6404622def965 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Tue, 30 Dec 2014 17:52:13 -0800 Subject: [PATCH 3/6] BESM6: Compiler suggested cleanups (MSVC). --- BESM6/besm6_arith.c | 2 +- BESM6/besm6_cpu.c | 8 ++++---- BESM6/besm6_mmu.c | 7 ++++--- BESM6/besm6_sys.c | 16 ++++++++-------- BESM6/besm6_tty.c | 4 +++- 5 files changed, 20 insertions(+), 17 deletions(-) diff --git a/BESM6/besm6_arith.c b/BESM6/besm6_arith.c index 016c2c01..082078c3 100644 --- a/BESM6/besm6_arith.c +++ b/BESM6/besm6_arith.c @@ -45,7 +45,7 @@ static alureg_t toalu (t_value val) return ret; } -static int inline is_negative (alureg_t *word) +static int SIM_INLINE is_negative (alureg_t *word) { return (word->mantissa & BIT41) != 0; } diff --git a/BESM6/besm6_cpu.c b/BESM6/besm6_cpu.c index 9da7c6be..f1e6fc31 100644 --- a/BESM6/besm6_cpu.c +++ b/BESM6/besm6_cpu.c @@ -54,9 +54,7 @@ #include #include #include -#include #include -#include #include #include @@ -769,11 +767,12 @@ void check_initial_setup () pult[5] = 1 << 21; GRP |= GRP_PANEL_REQ; } else { + struct tm * d; + /* Яч. ГОД обновляем самостоятельно */ time_t t; t_value date; time(&t); - struct tm * d; d = localtime(&t); ++d->tm_mon; date = (t_value) (d->tm_mday / 10) << 33 | @@ -803,9 +802,10 @@ void check_initial_setup () void cpu_one_inst () { int reg, opcode, addr, nextpc, next_mod; + t_value word; corr_stack = 0; - t_value word = mmu_fetch (PC); + word = mmu_fetch (PC); if (RUU & RUU_RIGHT_INSTR) RK = word; /* get right instruction */ else diff --git a/BESM6/besm6_mmu.c b/BESM6/besm6_mmu.c index 7428cb72..486f4e45 100644 --- a/BESM6/besm6_mmu.c +++ b/BESM6/besm6_mmu.c @@ -139,7 +139,7 @@ t_stat mmu_reset (DEVICE *dptr) { int i; for (i = 0; i < 8; ++i) { - BRZ[i] = BAZ[i] = RP[i] = 0; + BRZ[i] = RP[i] = BAZ[i] = 0; } TABST = 0; OLDEST = 0; @@ -209,12 +209,13 @@ void mmu_protection_check (int addr) void mmu_flush (int idx) { + int waddr = BAZ[idx]; + if (! BAZ[idx]) { /* Был пуст после сброса или выталкивания */ return; } /* Вычисляем физический адрес выталкиваемого БРЗ */ - int waddr = BAZ[idx]; waddr = (waddr > 0100000) ? (waddr - 0100000) : (waddr & 01777) | (TLB[waddr >> 10] << 10); memory[waddr] = BRZ[idx]; @@ -626,7 +627,7 @@ void mmu_setprotection (int idx, t_value val) /* Разряды сумматора, записываемые в регистр защиты - 21-28 */ int mask = 0xff << (idx * 8); val = ((val >> 20) & 0xff) << (idx * 8); - RZ = (RZ & ~mask) | val; + RZ = (uint32)((RZ & ~mask) | val); } void mmu_setcache (int idx, t_value val) diff --git a/BESM6/besm6_sys.c b/BESM6/besm6_sys.c index 01014aa2..86cfe8cb 100644 --- a/BESM6/besm6_sys.c +++ b/BESM6/besm6_sys.c @@ -24,7 +24,6 @@ */ #include "besm6_defs.h" #include -#include const char *opname_short_bemsh [64] = { "зп", "зпм", "рег", "счм", "сл", "вч", "вчоб","вчаб", @@ -188,7 +187,7 @@ t_value ieee_to_besm6 (double d) d = frexp (d, &exponent); /* 0.5 <= d < 1.0 */ d = ldexp (d, 40); - word = d; + word = (t_value)d; if (d - word >= 0.5) word += 1; /* Округление. */ if (exponent < -64) @@ -207,6 +206,7 @@ t_value ieee_to_besm6 (double d) double besm6_to_ieee (t_value word) { double mantissa; + int exponent; /* Убираем свертку */ word &= BITS48; @@ -214,9 +214,9 @@ double besm6_to_ieee (t_value word) /* Сдвигаем так, чтобы знак мантиссы пришелся на знак целого; * таким образом, mantissa равно исходной мантиссе, умноженной на 2**63. */ - mantissa = (t_int64) word << (64 - 48 + 7); + mantissa = (double)(((t_int64) word) << (64 - 48 + 7)); - int exponent = word >> 41; + exponent = word >> 41; /* Порядок смещен вверх на 64, и мантиссу нужно скорректировать */ return ldexp (mantissa, exponent - 64 - 63); @@ -472,7 +472,7 @@ t_stat fprint_sym (FILE *of, t_addr addr, t_value *val, if (sw & SWMASK ('M')) { /* symbolic decode? */ if (sw & SIM_SW_STOP && addr == PC && !(RUU & RUU_RIGHT_INSTR)) fprintf (of, "-> "); - besm6_fprint_cmd (of, cmd >> 24); + besm6_fprint_cmd (of, (uint32)(cmd >> 24)); if (sw & SIM_SW_STOP) /* stop point */ fprintf (of, ", "); else @@ -638,7 +638,7 @@ t_stat besm6_load (FILE *input) case 0: /* EOF */ return SCPE_OK; case ':': /* address */ - addr = word; + addr = (int)word; break; case '=': /* word */ if (addr < 010) @@ -655,7 +655,7 @@ t_stat besm6_load (FILE *input) ++addr; break; case '@': /* start address */ - PC = word; + PC = (uint32)word; break; } if (addr > MEMSIZE) @@ -686,7 +686,7 @@ t_stat besm6_dump (FILE *of, char *fnam) last_addr = addr; if (IS_INSN (word)) { fprintf (of, "к "); - besm6_fprint_cmd (of, word >> 24); + besm6_fprint_cmd (of, (uint32)(word >> 24)); fprintf (of, ", "); besm6_fprint_cmd (of, word & BITS(24)); fprintf (of, "\t\t; %05o - ", addr); diff --git a/BESM6/besm6_tty.c b/BESM6/besm6_tty.c index 14ea236e..ad80ec56 100644 --- a/BESM6/besm6_tty.c +++ b/BESM6/besm6_tty.c @@ -166,6 +166,8 @@ t_stat tty_reset (DEVICE *dptr) /* 19 р ГРП, 300 Гц */ t_stat vt_clk (UNIT * this) { + int num; + /* Телетайпы работают на 10 бод */ static int clk_divider = 1<<29; GRP |= MGRP & BBIT(19); @@ -184,7 +186,7 @@ t_stat vt_clk (UNIT * this) } /* Есть новые сетевые подключения? */ - int num = tmxr_poll_conn (&tty_desc); + num = tmxr_poll_conn (&tty_desc); if (num > 0 && num <= LINES_MAX) { char buf [80]; TMLN *t = &tty_line [num]; From 4381f9acc118d41a71dc9c908b5e43685cfb6ee2 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Tue, 30 Dec 2014 18:46:43 -0800 Subject: [PATCH 4/6] SCP: Added definition of SIM_INLINE when compiling with MSVC, gcc and clang --- sim_defs.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sim_defs.h b/sim_defs.h index b4b81a3d..9c40b7ec 100644 --- a/sim_defs.h +++ b/sim_defs.h @@ -246,7 +246,13 @@ typedef uint32 t_addr; /* Stubs for inlining */ -#define SIM_INLINE +#if defined(_MSC_VER) +#define SIM_INLINE _inline +#elif defined(__GNUC__) +#define SIM_INLINE inline +#else +#define SIM_INLINE +#endif /* System independent definitions */ From 33781be23bad4711bb0294457aaeaff71744dd7e Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Tue, 30 Dec 2014 18:48:42 -0800 Subject: [PATCH 5/6] SCP: Added support fo set a fifo opened with sim_fopen() to be non-blocking. --- sim_fio.c | 25 +++++++++++++++++++++++++ sim_fio.h | 1 + 2 files changed, 26 insertions(+) diff --git a/sim_fio.c b/sim_fio.c index a5819d29..820d0adc 100644 --- a/sim_fio.c +++ b/sim_fio.c @@ -369,10 +369,35 @@ int sim_set_fsize (FILE *fptr, t_addr size) { return _chsize(_fileno(fptr), (long)size); } + +int sim_set_fifo_nonblock (FILE *fptr) +{ +return -1; +} + #else /* !defined(_WIN32) */ #include int sim_set_fsize (FILE *fptr, t_addr size) { return ftruncate(fileno(fptr), (off_t)size); } + +#include +#include + +int sim_set_fifo_nonblock (FILE *fptr) +{ +struct stat stbuf; + +if (!fptr || fstat (fileno(fptr), &stbuf)) + return -1; +#if defined(S_IFIFO) && defined(O_NONBLOCK) +if ((stbuf.st_mode & S_IFIFO)) { + int flags = fcntl(fileno(fptr), F_GETFL, 0); + return fcntl(fileno(fptr), F_SETFL, flags | O_NONBLOCK); + } +#endif +return -1; +} + #endif diff --git a/sim_fio.h b/sim_fio.h index 9089a1f2..65d77612 100644 --- a/sim_fio.h +++ b/sim_fio.h @@ -54,6 +54,7 @@ FILE *sim_fopen (const char *file, const char *mode); int sim_fseek (FILE *st, t_addr offset, int whence); int sim_fseeko (FILE *st, t_offset offset, int whence); int sim_set_fsize (FILE *fptr, t_addr size); +int sim_set_fifo_nonblock (FILE *fptr); size_t sim_fread (void *bptr, size_t size, size_t count, FILE *fptr); size_t sim_fwrite (void *bptr, size_t size, size_t count, FILE *fptr); uint32 sim_fsize (FILE *fptr); From 82d5b01f84ce8a53e7efc668b50a516fefe10e29 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Tue, 30 Dec 2014 18:56:09 -0800 Subject: [PATCH 6/6] BESM6: besm6_punch migrate to use sim_fio API to set a fifo to non-blocking --- BESM6/besm6_punch.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/BESM6/besm6_punch.c b/BESM6/besm6_punch.c index 42906b15..c160bf3b 100644 --- a/BESM6/besm6_punch.c +++ b/BESM6/besm6_punch.c @@ -28,7 +28,6 @@ */ #include "besm6_defs.h" #include -#include t_stat fs_event (UNIT *u); t_stat uvvk_event (UNIT *u); @@ -125,13 +124,7 @@ t_stat fs_attach (UNIT *u, char *cptr) s = attach_unit (u, cptr); if (s != SCPE_OK) return s; - struct stat stbuf; - fstat (fileno(u->fileref), &stbuf); - isfifo[num] = (stbuf.st_mode & S_IFIFO) != 0; - if (isfifo[num]) { - int flags = fcntl(fileno(u->fileref), F_GETFL, 0); - fcntl(fileno(u->fileref), F_SETFL, flags | O_NONBLOCK); - } + isfifo[num] = (0 == sim_set_fifo_nonblock (u->fileref)); ENB_RDY(FS1_READY >> num); return SCPE_OK; }