-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscp.c
5468 lines (4842 loc) · 194 KB
/
scp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* scp.c: simulator control program
Copyright (c) 1993-2022, Robert M Supnik
Permission is hereby granted, free of charge, to any person obtaining a
copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation
the rights to use, copy, modify, merge, publish, distribute, sublicense,
and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
ROBERT M SUPNIK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Except as contained in this notice, the name of Robert M Supnik shall not be
used in advertising or otherwise to promote the sale, use or other dealings
in this Software without prior written authorization from Robert M Supnik.
06-Mar-22 RMS Removed UNIT_RAW support
21-Oct-21 RMS Fixed bug in byte deposits if aincr > 1
20=Sep-21 RMS Fixed bug in nested DO recognition (per Mark Pizzolato)
15-Apr-21 RMS Changed RUN to store new PC value both before RESET
(former behavior) and after (per Mark Pizzolato)
18-Mar-21 JDB Revised "attach_unit" and "detach_unit" for pipe support
Modified tests to allow UNIT_RO without UNIT_ROABLE
16-Feb-21 JDB Rewrote get_rval, put_rval to support arrays of structures
01-Feb-21 JDB Added casts for down-conversions
25-Jan-21 JDB REG "size" field now determines access size
REG "maxval" field now determines maximum allowed value
30-Nov-20 RMS Fixed RUN problem if CPU reset clears PC (Mark Pizzolato)
09-Nov-20 RMS Added hack for sim_card multiple attach (Mark Pizzolato)
23-Oct-20 JDB Added tmxr_post_logs calls to flush and close log files
04-Jun-20 JDB Call of "sim_vm_init" is now conditional on USE_VM_INIT
28-May-20 RMS Flush stdout after prompting (Mark Pizzolato)
23-Mar-20 RMS Added SET <dev|unit> APPEND command
13-Feb-20 RMS Spelled out CONTINUE in command table (Dave Bryan)
09-Jan-20 JDB Added "sim_vm_unit_name" extension hook
26-Oct-19 RMS Removed commented out MTAB_VAL code
09-Oct-19 JDB Corrected "sim_ref_type" use for RESTORE and DETACH ALL
19-Jul-19 JDB Added "sim_get_radix" extension hook
13-Apr-19 JDB Added extension hooks
Added "sim_prog_name" and "sim_ref_type" global variables
Added global routine declarations
12-Apr-19 JDB Permit quoted action lists in "sim_brk_getact"
Propagate -V through DO command levels
Use DO command replacement consistently
Add memory checking to the ASSERT command
26-Mar-18 RMS Modified DETACH for static use of UNIT_RO (Mark Pizzolato)
19-Mar-18 RMS Removed redundant declarations
06-Mar-18 RMS Moved switch routine declaration to scp.h
Removed get_ipaddr
06-Dec-17 JDB Prevent a disabled unit from being attached
10-Mar-17 MP Fixed "noise" bugs (COVERITY)
08-Mar-16 RMS Added shutdown flag for detach_all
28-Mar-15 RMS Added sim_printf from GitHub master (Mark Pizzolato)
28-Dec-14 JDB [4.0] Moved sim_load and sim_emax declarations to scp.h
14-Dec-14 JDB [4.0] Added sim_activate_time
[4.0] Changed sim_is_active to return t_bool
10-Nov-14 JDB Added ATTACH -N
02-Jul-14 JDB [4.0] Added sim_error_text
01-Mar-13 JDB Fixed SHOW RADIX, etc. for a device that has no modifiers
Modified SET and SHOW invalid entry messages for consistency
Correct fprintf parameter errors reported by clang
26-Feb-13 JDB Moved EX_* and SSH_* constants to scp.h
24-Feb-13 JDB Added REG_VMAD check in fprint_stopped_gen for VM address call
Added SIM_SW_STOP to examine call in fprint_stopped_gen
05-Feb-13 JDB Added sim_vm_fprint_stopped for VM-specific stop messages
Modified ex_reg and dep_reg to pass VM-specific register flags
08-May-12 RMS Fixed memory leaks in save/restore (Peter Schorn)
20-Mar-12 MP Fixes to "SHOW <x> SHOW" commands
06-Jan-12 JDB Fixed "SHOW DEVICE" with only one enabled unit (Dave Bryan)
13-Jan-11 MP Added "SHOW SHOW" and "SHOW <dev> SHOW" commands
05-Jan-11 RMS Fixed bug in deposit stride for numeric input (John Dundas)
23-Dec-10 RMS Clarified some help messages (Mark Pizzolato)
08-Nov-10 RMS Fixed handling of DO with no arguments (Dave Bryan)
22-May-10 RMS Added *nix READLINE support (Mark Pizzolato)
08-Feb-09 RMS Fixed warnings in help printouts
29-Dec-08 RMS Fixed implementation of MTAB_NC
24-Nov-08 RMS Revised RESTORE unit logic for consistency
05-Sep-08 JDB "detach_all" ignores error status returns if shutting down
17-Aug-08 RMS Revert RUN/BOOT to standard, rather than powerup, reset
25-Jul-08 JDB DO cmd missing params now default to null string
29-Jun-08 JDB DO cmd sub_args now allows "\\" to specify literal backslash
31-Mar-08 RMS Fixed bug in local/global register search (Mark Pizzolato)
Fixed bug in restore of RO units (Mark Pizzolato)
06-Feb-08 RMS Added SET/SHO/NO BR with default argument
18-Jul-07 RMS Modified match_ext for VMS ext;version support
28-Apr-07 RMS Modified sim_instr invocation to call sim_rtcn_init_all
Fixed bug in get_sim_opt
Fixed bug in restoration with changed memory size
08-Mar-07 JDB Fixed breakpoint actions in DO command file processing
30-Jan-07 RMS Fixed bugs in get_ipaddr
17-Oct-06 RMS Added idle support
04-Oct-06 JDB DO cmd failure now echoes cmd unless -q
14-Jul-06 RMS Added sim_activate_abs
02-Jun-06 JDB Fixed do_cmd to exit nested files on assertion failure
Added -E switch to do_cmd to exit on any error
14-Feb-06 RMS Upgraded save file format to V3.5
18-Jan-06 RMS Added fprint_stopped_gen
Added breakpoint spaces
Fixed unaligned register access (Doug Carman)
22-Sep-05 RMS Fixed declarations (Sterling Garwood)
30-Aug-05 RMS Revised to trim trailing spaces on file names
25-Aug-05 RMS Added variable default device support
23-Aug-05 RMS Added Linux line history support
16-Aug-05 RMS Fixed C++ declaration and cast problems
01-May-05 RMS Revised syntax for SET DEBUG (Dave Bryan)
22-Mar-05 JDB Modified DO command to allow ten-level nesting
18-Mar-05 RMS Moved DETACH tests into detach_unit (Dave Bryan)
Revised interface to fprint_sym, fparse_sym
07-Feb-05 RMS Added ASSERT command (Dave Bryan)
02-Feb-05 RMS Fixed bug in global register search
26-Dec-04 RMS Qualified SAVE examine, RESTORE deposit with SIM_SW_REST
10-Nov-04 JDB Fixed logging of errors from cmds in "do" file
05-Nov-04 RMS Moved SET/SHOW DEBUG under CONSOLE hierarchy
Renamed unit OFFLINE/ONLINE to DISABLED/ENABLED (Dave Bryan)
Revised to flush output files after simulation stop (Dave Bryan)
15-Oct-04 RMS Fixed HELP to suppress duplicate descriptions
27-Sep-04 RMS Fixed comma-separation options in set (David Bryan)
09-Sep-04 RMS Added -p option for RESET
13-Aug-04 RMS Qualified RESTORE detach with SIM_SW_REST
17-Jul-04 RMS Added ECHO command (Dave Bryan)
12-Jul-04 RMS Fixed problem ATTACHing to read only files
(John Dundas)
28-May-04 RMS Added SET/SHOW CONSOLE
14-Feb-04 RMS Updated SAVE/RESTORE (V3.2)
RMS Added debug print routines (Dave Hittner)
RMS Added sim_vm_parse_addr and sim_vm_fprint_addr
RMS Added REG_VMAD support
RMS Split out libraries
RMS Moved logging function to SCP
RMS Exposed step counter interface(s)
RMS Fixed double logging of SHOW BREAK (Mark Pizzolato)
RMS Fixed implementation of REG_VMIO
RMS Added SET/SHOW DEBUG, SET/SHOW <device> DEBUG,
SHOW <device> MODIFIERS, SHOW <device> RADIX
RMS Changed sim_fsize to take uptr argument
29-Dec-03 RMS Added Telnet console output stall support
01-Nov-03 RMS Cleaned up implicit detach on attach/restore
Fixed bug in command line read while logging (Mark Pizzolato)
01-Sep-03 RMS Fixed end-of-file problem in dep, idep
Fixed error on trailing spaces in dep, idep
15-Jul-03 RMS Removed unnecessary test in reset_all
15-Jun-03 RMS Added register flag REG_VMIO
25-Apr-03 RMS Added extended address support (V3.0)
Fixed bug in SAVE (Peter Schorn)
Added u5, u6 fields
Added logical name support
03-Mar-03 RMS Added sim_fsize
27-Feb-03 RMS Fixed bug in multiword deposits to files
08-Feb-03 RMS Changed sim_os_sleep to void, match_ext to char*
Added multiple actions, .ini file support
Added multiple switch evaluations per line
07-Feb-03 RMS Added VMS support for ! (Mark Pizzolato)
01-Feb-03 RMS Added breakpoint table extension, actions
14-Jan-03 RMS Added missing function prototypes
10-Jan-03 RMS Added attach/restore flag, dynamic memory size support,
case sensitive SET options
22-Dec-02 RMS Added ! (OS command) feature (Mark Pizzolato)
17-Dec-02 RMS Added get_ipaddr
02-Dec-02 RMS Added EValuate command
16-Nov-02 RMS Fixed bug in register name match algorithm
13-Oct-02 RMS Fixed Borland compiler warnings (Hans Pufal)
05-Oct-02 RMS Fixed bugs in set_logon, ssh_break (David Hittner)
Added support for fixed buffer devices
Added support for Telnet console, removed VT support
Added help <command>
Added VMS file optimizations (Robert Alan Byer)
Added quiet mode, DO with parameters, GUI interface,
extensible commands (Brian Knittel)
Added device enable/disable commands
14-Jul-02 RMS Fixed exit bug in do, added -v switch (Brian Knittel)
17-May-02 RMS Fixed bug in fxread/fxwrite error usage (found by
Norm Lastovic)
02-May-02 RMS Added VT emulation interface, changed {NO}LOG to SET {NO}LOG
22-Apr-02 RMS Fixed laptop sleep problem in clock calibration, added
magtape record length error (Jonathan Engdahl)
26-Feb-02 RMS Fixed initialization bugs in do_cmd, get_aval
(Brian Knittel)
10-Feb-02 RMS Fixed problem in clock calibration
06-Jan-02 RMS Moved device enable/disable to simulators
30-Dec-01 RMS Generalized timer packaged, added circular arrays
19-Dec-01 RMS Fixed DO command bug (John Dundas)
07-Dec-01 RMS Implemented breakpoint package
05-Dec-01 RMS Fixed bug in universal register logic
03-Dec-01 RMS Added read-only units, extended SET/SHOW, universal registers
24-Nov-01 RMS Added unit-based registers
16-Nov-01 RMS Added DO command
28-Oct-01 RMS Added relative range addressing
08-Oct-01 RMS Added SHOW VERSION
30-Sep-01 RMS Relaxed attach test in BOOT
27-Sep-01 RMS Added queue count routine, fixed typo in ex/mod
17-Sep-01 RMS Removed multiple console support
07-Sep-01 RMS Removed conditional externs on function prototypes
Added special modifier print
31-Aug-01 RMS Changed int64 to t_int64 for Windoze (V2.7)
18-Jul-01 RMS Minor changes for Macintosh port
12-Jun-01 RMS Fixed bug in big-endian I/O (Dave Conroy)
27-May-01 RMS Added multiple console support
16-May-01 RMS Added logging
15-May-01 RMS Added features from Tim Litt
12-May-01 RMS Fixed missing return in disable_cmd
25-Mar-01 RMS Added ENABLE/DISABLE
14-Mar-01 RMS Revised LOAD/DUMP interface (again)
05-Mar-01 RMS Added clock calibration support
05-Feb-01 RMS Fixed bug, DETACH buffered unit with hwmark = 0
04-Feb-01 RMS Fixed bug, RESTORE not using device's attach routine
21-Jan-01 RMS Added relative time
22-Dec-00 RMS Fixed find_device for devices ending in numbers
08-Dec-00 RMS V2.5a changes
30-Oct-00 RMS Added output file option to examine
11-Jul-99 RMS V2.5 changes
13-Apr-99 RMS Fixed handling of 32b addresses
04-Oct-98 RMS V2.4 changes
20-Aug-98 RMS Added radix commands
05-Jun-98 RMS Fixed bug in ^D handling for UNIX
10-Apr-98 RMS Added switches to all commands
26-Oct-97 RMS Added search capability
25-Jan-97 RMS Revised data types
23-Jan-97 RMS Added bi-endian I/O
06-Sep-96 RMS Fixed bug in variable length IEXAMINE
16-Jun-96 RMS Changed interface to parse/print_sym
06-Apr-96 RMS Added error checking in reset all
07-Jan-96 RMS Added register buffers in save/restore
11-Dec-95 RMS Fixed ordering bug in save/restore
22-May-95 RMS Added symbolic input
13-Apr-95 RMS Added symbolic printouts
*/
/* Macros and data structures */
#include "sim_defs.h"
#include "sim_tmxr.h"
#include <signal.h>
#include <ctype.h>
#include <sys/stat.h>
#if defined(SIM_HAVE_DLOPEN) /* Dynamic Readline support */
#include <dlfcn.h>
#endif
/* Search definitions */
#define SCH_OR 0 /* search logicals */
#define SCH_AND 1
#define SCH_XOR 2
#define SCH_E 0 /* search booleans */
#define SCH_N 1
#define SCH_G 2
#define SCH_L 3
#define SCH_EE 4
#define SCH_NE 5
#define SCH_GE 6
#define SCH_LE 7
#define DO_NEST_LVL 10 /* DO cmd nesting level */
#define SRBSIZ 1024 /* save/restore buffer */
#define SIM_BRK_INILNT 4096 /* bpt tbl length */
#define SIM_BRK_ALLTYP 0xFFFFFFFF
#define UPDATE_SIM_TIME(x) sim_time = sim_time + (x - sim_interval); \
sim_rtime = sim_rtime + ((uint32) (x - sim_interval)); \
x = sim_interval
#define SZ_D(dp) (size_map[((dp)->dwidth + CHAR_BIT - 1) / CHAR_BIT])
#if defined (USE_INT64)
#define SZ_LOAD(sz,v,mb,j) \
if (sz == sizeof (uint8)) v = *(((uint8 *) mb) + ((uint32) j)); \
else if (sz == sizeof (uint16)) v = *(((uint16 *) mb) + ((uint32) j)); \
else if (sz == sizeof (uint32)) v = *(((uint32 *) mb) + ((uint32) j)); \
else v = *(((t_uint64 *) mb) + ((uint32) j));
#define SZ_STORE(sz,v,mb,j) \
if (sz == sizeof (uint8)) *(((uint8 *) mb) + j) = (uint8) v; \
else if (sz == sizeof (uint16)) *(((uint16 *) mb) + ((uint32) j)) = (uint16) v; \
else if (sz == sizeof (uint32)) *(((uint32 *) mb) + ((uint32) j)) = (uint32) v; \
else *(((t_uint64 *) mb) + ((uint32) j)) = v;
#else
#define SZ_LOAD(sz,v,mb,j) \
if (sz == sizeof (uint8)) v = *(((uint8 *) mb) + ((uint32) j)); \
else if (sz == sizeof (uint16)) v = *(((uint16 *) mb) + ((uint32) j)); \
else v = *(((uint32 *) mb) + ((uint32) j));
#define SZ_STORE(sz,v,mb,j) \
if (sz == sizeof (uint8)) *(((uint8 *) mb) + ((uint32) j)) = (uint8) v; \
else if (sz == sizeof (uint16)) *(((uint16 *) mb) + ((uint32) j)) = (uint16) v; \
else *(((uint32 *) mb) + ((uint32) j)) = v;
#endif
#define GET_SWITCHES(cp) \
if ((cp = get_sim_sw (cp)) == NULL) return SCPE_INVSW
#define GET_RADIX(val,dft) \
val = sim_get_radix (NULL, sim_switches, dft);
/* The per-simulator pointers can be overrriden by a VM init routine */
char* (*sim_vm_read) (char *ptr, int32 size, FILE *stream) = NULL;
void (*sim_vm_post) (t_bool from_scp) = NULL;
CTAB *sim_vm_cmd = NULL;
void (*sim_vm_fprint_addr) (FILE *st, DEVICE *dptr, t_addr addr) = NULL;
t_addr (*sim_vm_parse_addr) (DEVICE *dptr, char *cptr, char **tptr) = NULL;
t_bool (*sim_vm_fprint_stopped) (FILE *st, t_stat reason) = NULL;
t_bool (*sim_vm_is_subroutine_call) (t_addr **ret_addrs) = NULL;
/* Prototypes */
/* Set and show command processors */
t_stat set_dev_radix (DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat set_dev_enbdis (DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat set_dev_debug (DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat set_dev_unit_append (DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat set_unit_enbdis (DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat ssh_break (FILE *st, char *cptr, int32 flg);
t_stat show_cmd_fi (FILE *ofile, int32 flag, char *cptr);
t_stat show_config (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat show_queue (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat show_time (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat show_mod_names (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat show_show_commands (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat show_log_names (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat show_dev_radix (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat show_dev_debug (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat show_dev_logicals (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat show_dev_modifiers (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat show_dev_show_commands (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat show_version (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat show_break (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag, char *cptr);
t_stat show_device (FILE *st, DEVICE *dptr, int32 flag);
t_stat show_unit (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flag);
t_stat show_all_mods (FILE *st, DEVICE *dptr, UNIT *uptr, int32 flg);
t_stat show_one_mod (FILE *st, DEVICE *dptr, UNIT *uptr, MTAB *mptr, char *cptr, int32 flag);
t_stat sim_check_console (int32 sec);
t_stat sim_save (FILE *sfile);
t_stat sim_rest (FILE *rfile);
/* Breakpoint package */
t_stat sim_brk_init (void);
t_stat sim_brk_set (t_addr loc, int32 sw, int32 ncnt, char *act);
t_stat sim_brk_clr (t_addr loc, int32 sw);
t_stat sim_brk_clrall (int32 sw);
t_stat sim_brk_show (FILE *st, t_addr loc, int32 sw);
t_stat sim_brk_showall (FILE *st, int32 sw);
char *sim_brk_getact (char *buf, int32 size);
void sim_brk_clract (void);
void sim_brk_npc (uint32 cnt);
BRKTAB *sim_brk_new (t_addr loc);
/* Commands support routines */
SCHTAB *get_search (char *cptr, int32 radix, SCHTAB *schptr);
int32 test_search (t_value val, SCHTAB *schptr);
char *get_glyph_gen (char *iptr, char *optr, char mchar, t_bool uc);
int32 get_switches (char *cptr);
t_stat get_aval (t_addr addr, DEVICE *dptr, UNIT *uptr);
t_value get_rval (REG *rptr, uint32 idx);
void put_rval (REG *rptr, uint32 idx, t_value val);
void fprint_help (FILE *st);
void fprint_stopped (FILE *st, t_stat r);
void fprint_capac (FILE *st, DEVICE *dptr, UNIT *uptr);
char *read_line (char *ptr, int32 size, FILE *stream);
char *read_line_p (char *prompt, char *ptr, int32 size, FILE *stream);
REG *find_reg_glob (char *ptr, char **optr, DEVICE **gdptr);
/* Forward references */
t_stat scp_attach_unit (DEVICE *dptr, UNIT *uptr, char *cptr);
t_stat scp_detach_unit (DEVICE *dptr, UNIT *uptr);
t_bool qdisable (DEVICE *dptr);
t_stat attach_err (UNIT *uptr, t_stat stat);
t_stat detach_all (int32 start_device, t_bool shutdown);
t_stat assign_device (DEVICE *dptr, char *cptr);
t_stat deassign_device (DEVICE *dptr);
t_stat ssh_break_one (FILE *st, int32 flg, t_addr lo, int32 cnt, char *aptr);
t_stat run_boot_prep (void);
t_stat exdep_reg_loop (FILE *ofile, SCHTAB *schptr, int32 flag, char *cptr,
REG *lowr, REG *highr, uint32 lows, uint32 highs);
t_stat ex_reg (FILE *ofile, t_value val, int32 flag, REG *rptr, uint32 idx);
t_stat dep_reg (int32 flag, char *cptr, REG *rptr, uint32 idx);
t_stat exdep_addr_loop (FILE *ofile, SCHTAB *schptr, int32 flag, char *cptr,
t_addr low, t_addr high, DEVICE *dptr, UNIT *uptr);
t_stat ex_addr (FILE *ofile, int32 flag, t_addr addr, DEVICE *dptr,
UNIT *uptr, int32 dfltinc);
t_stat dep_addr (int32 flag, char *cptr, t_addr addr, DEVICE *dptr,
UNIT *uptr, int32 dfltinc);
t_stat step_svc (UNIT *ptr);
void sub_args_local (char *instr, char *tmpbuf, int32 maxstr, char *do_arg[]);
int32 get_radix_local (const char *cptr, int32 switches, int32 default_radix);
/* Extension interface */
char *sim_vm_release;
void (*sub_args) (char *iptr, char *optr, int32 len, char *args []) = sub_args_local;
int32 (*sim_get_radix) (const char *cptr, int32 switches, int32 default_radix) = get_radix_local;
char * (*sim_vm_unit_name) (const UNIT *uptr) = NULL;
/* Global data */
DEVICE *sim_dflt_dev = NULL;
UNIT *sim_clock_queue = NULL;
int32 sim_interval = 0;
int32 sim_switches = 0;
FILE *sim_ofile = NULL;
SCHTAB *sim_schptr = FALSE;
DEVICE *sim_dfdev = NULL;
UNIT *sim_dfunit = NULL;
int32 sim_opt_out = 0;
int32 sim_is_running = 0;
uint32 sim_brk_summ = 0;
uint32 sim_brk_types = 0;
uint32 sim_brk_dflt = 0;
char *sim_brk_act = NULL;
BRKTAB *sim_brk_tab = NULL;
int32 sim_brk_ent = 0;
int32 sim_brk_lnt = 0;
int32 sim_brk_ins = 0;
t_bool sim_brk_pend[SIM_BKPT_N_SPC] = { FALSE };
t_addr sim_brk_ploc[SIM_BKPT_N_SPC] = { 0 };
int32 sim_quiet = 0;
int32 sim_step = 0;
static double sim_time;
static uint32 sim_rtime;
static int32 noqueue_time;
volatile int32 stop_cpu = 0;
t_value *sim_eval = NULL;
FILE *sim_log = NULL; /* log file */
FILE *sim_deb = NULL; /* debug file */
static SCHTAB sim_stab;
char *sim_prog_name; /* pointer to the executable name */
uint32 sim_ref_type = REF_NONE; /* reference type */
static UNIT sim_step_unit = { UDATA (&step_svc, 0, 0) };
#if defined USE_INT64
static const char *sim_si64 = "64b data";
#else
static const char *sim_si64 = "32b data";
#endif
#if defined USE_ADDR64
static const char *sim_sa64 = "64b addresses";
#else
static const char *sim_sa64 = "32b addresses";
#endif
#if defined (USE_NETWORK) || defined (USE_SHARED)
const char *eth_capabilities(void);
#else
#define eth_capabilities() "no Ethernet"
#endif
/* Tables and strings */
const char save_vercur[] = "V3.5";
const char save_ver32[] = "V3.2";
const char save_ver30[] = "V3.0";
const char *scp_error_messages[] = {
"Address space exceeded",
"Unit not attached",
"I/O error",
"Checksum error",
"Format error",
"Unit not attachable",
"File open error",
"Memory exhausted",
"Invalid argument",
"Step expired",
"Unknown command",
"Read only argument",
"Command not completed",
"Simulation stopped",
"Goodbye",
"Console input I/O error",
"Console output I/O error",
"End of file",
"Relocation error",
"No settable parameters",
"Unit already attached",
"Hardware timer error",
"SIGINT handler setup error",
"Console terminal setup error",
"Subscript out of range",
"Command not allowed",
"Unit disabled",
"Read only operation not allowed",
"Invalid switch",
"Missing value",
"Too few arguments",
"Too many arguments",
"Non-existent device",
"Non-existent unit",
"Non-existent register",
"Non-existent parameter",
"Nested DO command limit exceeded",
"Internal error",
"Invalid magtape record length",
"Console Telnet connection lost",
"Console Telnet connection timed out",
"Console Telnet output stall",
"Assertion failed"
};
const size_t size_map[] = { sizeof (int8),
sizeof (int8), sizeof (int16), sizeof (int32), sizeof (int32)
#if defined (USE_INT64)
, sizeof (t_int64), sizeof (t_int64), sizeof (t_int64), sizeof (t_int64)
#endif
};
const t_value width_mask[] = { 0,
0x1, 0x3, 0x7, 0xF,
0x1F, 0x3F, 0x7F, 0xFF,
0x1FF, 0x3FF, 0x7FF, 0xFFF,
0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF,
0x1FFFF, 0x3FFFF, 0x7FFFF, 0xFFFFF,
0x1FFFFF, 0x3FFFFF, 0x7FFFFF, 0xFFFFFF,
0x1FFFFFF, 0x3FFFFFF, 0x7FFFFFF, 0xFFFFFFF,
0x1FFFFFFF, 0x3FFFFFFF, 0x7FFFFFFF, 0xFFFFFFFF
#if defined (USE_INT64)
, 0x1FFFFFFFF, 0x3FFFFFFFF, 0x7FFFFFFFF, 0xFFFFFFFFF,
0x1FFFFFFFFF, 0x3FFFFFFFFF, 0x7FFFFFFFFF, 0xFFFFFFFFFF,
0x1FFFFFFFFFF, 0x3FFFFFFFFFF, 0x7FFFFFFFFFF, 0xFFFFFFFFFFF,
0x1FFFFFFFFFFF, 0x3FFFFFFFFFFF, 0x7FFFFFFFFFFF, 0xFFFFFFFFFFFF,
0x1FFFFFFFFFFFF, 0x3FFFFFFFFFFFF, 0x7FFFFFFFFFFFF, 0xFFFFFFFFFFFFF,
0x1FFFFFFFFFFFFF, 0x3FFFFFFFFFFFFF, 0x7FFFFFFFFFFFFF, 0xFFFFFFFFFFFFFF,
0x1FFFFFFFFFFFFFF, 0x3FFFFFFFFFFFFFF,
0x7FFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFF,
0x1FFFFFFFFFFFFFFF, 0x3FFFFFFFFFFFFFFF,
0x7FFFFFFFFFFFFFFF, 0xFFFFFFFFFFFFFFFF
#endif
};
static CTAB cmd_table[] = {
{ "RESET", &reset_cmd, 0,
"r{eset} {ALL|<device>} reset simulator\n" },
{ "EXAMINE", &exdep_cmd, EX_E,
"e{xamine} <list> examine memory or registers\n" },
{ "IEXAMINE", &exdep_cmd, EX_E+EX_I,
"ie{xamine} <list> interactive examine memory or registers\n" },
{ "DEPOSIT", &exdep_cmd, EX_D,
"d{eposit} <list> <val> deposit in memory or registers\n" },
{ "IDEPOSIT", &exdep_cmd, EX_D+EX_I,
"id{eposit} <list> interactive deposit in memory or registers\n" },
{ "EVALUATE", &eval_cmd, 0,
"ev{aluate} <expr> evaluate symbolic expression\n" },
{ "RUN", &run_cmd, RU_RUN,
"ru{n} {new PC} reset and start simulation\n" },
{ "GO", &run_cmd, RU_GO,
"go {new PC} start simulation\n" },
{ "STEP", &run_cmd, RU_STEP,
"s{tep} {n} simulate n instructions\n" },
{ "CONTINUE", &run_cmd, RU_CONT,
"c{ont} continue simulation\n" },
{ "BOOT", &run_cmd, RU_BOOT,
"b{oot} <unit> bootstrap unit\n" },
{ "BREAK", &brk_cmd, SSH_ST,
"br{eak} <list> set breakpoints\n" },
{ "NOBREAK", &brk_cmd, SSH_CL,
"nobr{eak} <list> clear breakpoints\n" },
{ "ATTACH", &attach_cmd, 0,
"at{tach} <unit> <file> attach file to simulated unit\n" },
{ "DETACH", &detach_cmd, 0,
"det{ach} <unit> detach file from simulated unit\n" },
{ "ASSIGN", &assign_cmd, 0,
"as{sign} <device> <name> assign logical name for device\n" },
{ "DEASSIGN", &deassign_cmd, 0,
"dea{ssign} <device> deassign logical name for device\n" },
{ "SAVE", &save_cmd, 0,
"sa{ve} <file> save simulator to file\n" },
{ "RESTORE", &restore_cmd, 0,
"rest{ore}|ge{t} <file> restore simulator from file\n" },
{ "GET", &restore_cmd, 0, NULL },
{ "LOAD", &load_cmd, 0,
"l{oad} <file> {<args>} load binary file\n" },
{ "DUMP", &load_cmd, 1,
"du(mp) <file> {<args>} dump binary file\n" },
{ "EXIT", &exit_cmd, 0,
"exi{t}|q{uit}|by{e} exit from simulation\n" },
{ "QUIT", &exit_cmd, 0, NULL },
{ "BYE", &exit_cmd, 0, NULL },
{ "SET", &set_cmd, 0,
"set console arg{,arg...} set console options\n"
"set break <list> set breakpoints\n"
"set nobreak <list> clear breakpoints\n"
"set throttle x{M|K|%%} set simulation rate\n"
"set nothrottle set simulation rate to maximum\n"
"set <dev> OCT|DEC|HEX set device display radix\n"
"set <dev> ENABLED enable device\n"
"set <dev> DISABLED disable device\n"
"set <dev> DEBUG{=arg} set device debug flags\n"
"set <dev> NODEBUG={arg} clear device debug flags\n"
"set <dev> APPEND set first unit's position for appending\n"
"set <dev> arg{,arg...} set device parameters (see show modifiers)\n"
"set <unit> ENABLED enable unit\n"
"set <unit> DISABLED disable unit\n"
"set <unit> APPEND set unit's position for appending\n"
"set <unit> arg{,arg...} set unit parameters (see show modifiers)\n"
},
{ "SHOW", &show_cmd, 0,
"sh{ow} br{eak} <list> show breakpoints\n"
"sh{ow} con{figuration} show configuration\n"
"sh{ow} cons{ole} {arg} show console options\n"
"sh{ow} dev{ices} show devices\n"
"sh{ow} m{odifiers} show modifiers for all devices\n"
"sh{ow} s{how} show SHOW commands for all devices\n"
"sh{ow} n{ames} show logical names\n"
"sh{ow} q{ueue} show event queue\n"
"sh{ow} ti{me} show simulated time\n"
"sh{ow} th{rottle} show simulation rate\n"
"sh{ow} ve{rsion} show simulator version\n"
"sh{ow} <dev> RADIX show device display radix\n"
"sh{ow} <dev> DEBUG show device debug flags\n"
"sh{ow} <dev> MODIFIERS show device modifiers\n"
"sh{ow} <dev> NAMES show device logical name\n"
"sh{ow} <dev> SHOW show device SHOW commands\n"
"sh{ow} <dev> {arg,...} show device parameters\n"
"sh{ow} <unit> {arg,...} show unit parameters\n" },
{ "DO", &do_cmd, 1,
"do <file> {arg,arg...} process command file\n" },
{ "ECHO", &echo_cmd, 0,
"echo <string> display <string>\n" },
{ "ASSERT", &assert_cmd, 0,
"assert {<dev>} <cond> test simulator state against condition\n" },
{ "HELP", &help_cmd, 0,
"h{elp} type this message\n"
"h{elp} <command> type help for command\n" },
{ "!", &spawn_cmd, 0,
"! execute local command interpreter\n"
"! <command> execute local host command\n" },
{ NULL, NULL, 0 }
};
/* SET command tables */
static CTAB set_glob_tab[] = {
{ "CONSOLE", &sim_set_console, 0 },
{ "BREAK", &brk_cmd, SSH_ST },
{ "NOBREAK", &brk_cmd, SSH_CL },
{ "TELNET", &sim_set_telnet, 0 }, /* deprecated */
{ "NOTELNET", &sim_set_notelnet, 0 }, /* deprecated */
{ "LOG", &sim_set_logon, 0 }, /* deprecated */
{ "NOLOG", &sim_set_logoff, 0 }, /* deprecated */
{ "DEBUG", &sim_set_debon, 0 }, /* deprecated */
{ "NODEBUG", &sim_set_deboff, 0 }, /* deprecated */
{ "THROTTLE", &sim_set_throt, 1 },
{ "NOTHROTTLE", &sim_set_throt, 0 },
{ NULL, NULL, 0 }
};
static C1TAB set_dev_tab[] = {
{ "OCTAL", &set_dev_radix, 8 },
{ "DECIMAL", &set_dev_radix, 10 },
{ "HEX", &set_dev_radix, 16 },
{ "ENABLED", &set_dev_enbdis, 1 },
{ "DISABLED", &set_dev_enbdis, 0 },
{ "APPEND", &set_dev_unit_append, 0 },
{ "DEBUG", &set_dev_debug, 1 },
{ "NODEBUG", &set_dev_debug, 0 },
{ NULL, NULL, 0 }
};
static C1TAB set_unit_tab[] = {
{ "ENABLED", &set_unit_enbdis, 1 },
{ "DISABLED", &set_unit_enbdis, 0 },
{ "APPEND", &set_dev_unit_append, 0 },
{ NULL, NULL, 0 }
};
/* SHOW command tables */
static SHTAB show_glob_tab[] = {
{ "CONFIGURATION", &show_config, 0 },
{ "DEVICES", &show_config, 1 },
{ "QUEUE", &show_queue, 0 },
{ "TIME", &show_time, 0 },
{ "MODIFIERS", &show_mod_names, 0 },
{ "NAMES", &show_log_names, 0 },
{ "SHOW", &show_show_commands, 0 },
{ "VERSION", &show_version, 1 },
{ "CONSOLE", &sim_show_console, 0 },
{ "BREAK", &show_break, 0 },
{ "LOG", &sim_show_log, 0 }, /* deprecated */
{ "TELNET", &sim_show_telnet, 0 }, /* deprecated */
{ "DEBUG", &sim_show_debug, 0 }, /* deprecated */
{ "THROTTLE", &sim_show_throt, 0 },
{ "CLOCKS", &sim_show_timers, 0 },
{ NULL, NULL, 0 }
};
static SHTAB show_dev_tab[] = {
{ "RADIX", &show_dev_radix, 0 },
{ "DEBUG", &show_dev_debug, 0 },
{ "MODIFIERS", &show_dev_modifiers, 1 }, /* 1 = return error if no mods */
{ "NAMES", &show_dev_logicals, 0 },
{ "SHOW", &show_dev_show_commands, 0 },
{ NULL, NULL, 0 }
};
static SHTAB show_unit_tab[] = {
{ NULL, NULL, 0 }
};
/* Main command loop */
int main (int argc, char *argv[])
{
char cbuf[CBUFSIZE], gbuf[CBUFSIZE], *cptr, *cmdargs[10] = { NULL };
int32 i, sw;
t_bool lookswitch;
t_stat stat;
CTAB *cmdp;
#if defined (__MWERKS__) && defined (macintosh)
argc = ccommand (&argv);
#endif
*cbuf = 0; /* init arg buffer */
sim_switches = 0; /* init switches */
lookswitch = TRUE;
sim_prog_name = cmdargs [0] = argv [0]; /* save a pointer to the program name */
for (i = 1; i < argc; i++) { /* loop thru args */
if (argv[i] == NULL) /* paranoia */
continue;
else /* if not null */
cmdargs[i] = argv[i]; /* then set the corresponding argument pointer */
if ((*argv[i] == '-') && lookswitch) { /* switch? */
if ((sw = get_switches (argv[i])) < 0) {
fprintf (stderr, "Invalid switch %s\n", argv[i]);
return 0;
}
sim_switches = sim_switches | sw;
}
else {
if ((strlen (argv[i]) + strlen (cbuf) + 1) >= CBUFSIZE) {
fprintf (stderr, "Argument string too long\n");
return 0;
}
if (*cbuf) /* concat args */
strcat (cbuf, " ");
strcat (cbuf, argv[i]);
lookswitch = FALSE; /* no more switches */
}
} /* end for */
sim_quiet = sim_switches & SWMASK ('Q'); /* -q means quiet */
sim_init_sock (); /* init socket capabilities */
#if defined (USE_VM_INIT)
(*sim_vm_init)(); /* call once only */
#endif
sim_finit(); /* init fio package */
stop_cpu = 0;
sim_interval = 0;
sim_time = sim_rtime = 0;
noqueue_time = 0;
sim_clock_queue = NULL;
sim_is_running = 0;
sim_log = NULL;
if (sim_emax <= 0)
sim_emax = 1;
sim_timer_init ();
if ((stat = sim_ttinit ()) != SCPE_OK) {
fprintf (stderr, "Fatal terminal initialization error\n%s\n",
scp_error_messages[stat - SCPE_BASE]);
return 0;
}
if ((sim_eval = (t_value *) calloc (sim_emax, sizeof (t_value))) == NULL) {
fprintf (stderr, "Unable to allocate examine buffer\n");
return 0;
};
if ((stat = reset_all_p (0)) != SCPE_OK) {
fprintf (stderr, "Fatal simulator initialization error\n%s\n",
scp_error_messages[stat - SCPE_BASE]);
return 0;
}
if ((stat = sim_brk_init ()) != SCPE_OK) {
fprintf (stderr, "Fatal breakpoint table initialization error\n%s\n",
scp_error_messages[stat - SCPE_BASE]);
return 0;
}
if (!sim_quiet) {
printf ("\n");
show_version (stdout, NULL, NULL, 0, NULL);
}
if (sim_dflt_dev == NULL) /* if no default */
sim_dflt_dev = sim_devices[0];
if (*cbuf) /* cmd file arg? */
stat = find_cmd ("DO")->action (0, cbuf); /* proc cmd file */
else if (*argv[0]) { /* sim name arg? */
char nbuf[PATH_MAX + 7], *np; /* "path.ini" */
nbuf[0] = '"'; /* starting " */
strncpy (nbuf + 1, argv[0], PATH_MAX + 1); /* copy sim name */
if (np = match_ext (nbuf, "EXE")) /* remove .exe */
*np = 0;
strcat (nbuf, ".ini\""); /* add .ini" */
stat = find_cmd ("DO")->action (-1, nbuf); /* proc cmd file */
}
while (stat != SCPE_EXIT) { /* in case exit */
if (cptr = sim_brk_getact (cbuf, CBUFSIZE)) /* pending action? */
printf ("sim> %s\n", cptr); /* echo */
else if (sim_vm_read != NULL) { /* sim routine? */
printf ("sim> "); /* prompt */
cptr = (*sim_vm_read) (cbuf, CBUFSIZE, stdin);
}
else cptr = read_line_p ("sim> ", cbuf, CBUFSIZE, stdin);/* read with prompt*/
if (cptr == NULL) /* ignore EOF */
continue;
if (*cptr == 0) /* ignore blank */
continue;
sub_args (cbuf, gbuf, CBUFSIZE, cmdargs); /* substitute arguments */
if (sim_log) /* log cmd */
fprintf (sim_log, "sim> %s\n", cptr);
cptr = get_glyph (cptr, gbuf, 0); /* get command glyph */
sim_switches = 0; /* init switches */
if (cmdp = find_cmd (gbuf)) /* lookup command */
stat = cmdp->action (cmdp->arg, cptr); /* if found, exec */
else stat = SCPE_UNK;
if (stat >= SCPE_BASE) /* error? */
sim_printf ("%s\n", scp_error_messages[stat - SCPE_BASE]);
if (sim_vm_post != NULL)
(*sim_vm_post) (TRUE);
} /* end while */
detach_all (0, TRUE); /* close device files */
tmxr_post_logs (TRUE); /* close all mux log files */
sim_set_deboff (0, NULL); /* close debug */
sim_set_logoff (0, NULL); /* close log */
sim_set_notelnet (0, NULL); /* close Telnet */
sim_ttclose (); /* close console */
return 0;
}
/* Find command routine */
CTAB *find_cmd (char *gbuf)
{
CTAB *cmdp = NULL;
if (sim_vm_cmd) /* try ext commands */
cmdp = find_ctab (sim_vm_cmd, gbuf);
if (cmdp == NULL) /* try regular cmds */
cmdp = find_ctab (cmd_table, gbuf);
return cmdp;
}
/* Exit command */
t_stat exit_cmd (int32 flag, char *cptr)
{
return SCPE_EXIT;
}
/* Help command */
void fprint_help (FILE *st)
{
CTAB *cmdp;
for (cmdp = sim_vm_cmd; cmdp && (cmdp->name != NULL); cmdp++) {
if (cmdp->help)
fputs (cmdp->help, st);
}
for (cmdp = cmd_table; cmdp && (cmdp->name != NULL); cmdp++) {
if (cmdp->help && (!sim_vm_cmd || !find_ctab (sim_vm_cmd, cmdp->name)))
fputs (cmdp->help, st);
}
return;
}
t_stat help_cmd (int32 flag, char *cptr)
{
char gbuf[CBUFSIZE];
CTAB *cmdp;
GET_SWITCHES (cptr);
if (*cptr) {
cptr = get_glyph (cptr, gbuf, 0);
if (*cptr)
return SCPE_2MARG;
if (cmdp = find_cmd (gbuf))
sim_printf ("%s", cmdp->help);
else return SCPE_ARG;
}
else {
fprint_help (stdout);
if (sim_log)
fprint_help (sim_log);
}
return SCPE_OK;
}
/* Spawn command */
t_stat spawn_cmd (int32 flag, char *cptr)
{
if ((cptr == NULL) || (strlen (cptr) == 0))
cptr = getenv("SHELL");
if ((cptr == NULL) || (strlen (cptr) == 0))
cptr = getenv("ComSpec");
#if defined (VMS)
if ((cptr == NULL) || (strlen (cptr) == 0))
cptr = "SPAWN/INPUT=SYS$COMMAND:";
#endif
fflush(stdout); /* flush stdout */
if (sim_log) /* flush log if enabled */
fflush (sim_log);
system (cptr);
#if defined (VMS)
printf ("\n");
#endif
return SCPE_OK;
}
/* Echo command */
t_stat echo_cmd (int32 flag, char *cptr)
{
sim_printf ("%s\n", cptr);
return SCPE_OK;
}
/* Do command
Syntax: DO {-E} {-V} <filename> {<arguments>...}
-E causes all command errors to be fatal; without it, only EXIT and ASSERT
failure will stop a command file.
-V causes commands to be echoed before execution.
Note that SCPE_STEP ("Step expired") is considered a note and not an error
and so does not abort command execution when using -E.
Inputs:
flag = caller and nesting level indicator
fcptr = filename and optional arguments, space-separated
Outputs:
status = error status
The "flag" input value indicates the source of the call, as follows:
-1 = initialization file (no error if not found)
0 = command line file
1 = "DO" command
>1 = nested "DO" command
Implementation notes:
1. The "SWMASK ('V')" flag is 010000000, so we use that as an upper bit flag
to propagate echo status to sub-DOs. This does not interfere with the
level count in the lower bits of the "flag" parameter.
*/
#define SCPE_DOFAILED 0040000 /* fail in DO, not subproc */
t_stat do_cmd (int32 flag, char *fcptr)
{
char *cptr, cbuf[CBUFSIZE], gbuf[CBUFSIZE], *c, quote, *do_arg[10];
FILE *fpin;
CTAB *cmdp;
int32 echo, nargs, errabort;
t_bool interactive, isdo, staying;
t_stat stat;
char *ocptr;
stat = SCPE_OK;
staying = TRUE;
interactive = (flag > 0); /* issued interactively? */
if (interactive) { /* get switches */
GET_SWITCHES (fcptr);
}
echo = sim_switches & SWMASK ('V'); /* -v means echo */
errabort = sim_switches & SWMASK ('E'); /* -e means abort on error */
if (flag >= 0) /* if this is not the initialization file */
echo = echo | flag & ~0377; /* then propagate the echo flag to the current level */
c = fcptr;
for (nargs = 0; nargs < 10; ) { /* extract arguments */
while (isspace (*c)) /* skip blanks */
c++;
if (*c == 0) /* all done? */
do_arg [nargs++] = NULL; /* null argument */
else {
if (*c == '\'' || *c == '"') /* quoted string? */
quote = *c++;
else quote = 0;
do_arg[nargs++] = c; /* save start */
while (*c && (quote ? (*c != quote) : !isspace (*c)))
c++;
if (*c) /* term at quote/spc */
*c++ = 0;
}