This source file includes following definitions.
- dump_flags
- dps8_strupr
- get_iwb_info
- disassemble
- get_mod_string
- Add36b
- Sub36b
- Add18b
- Sub18b
- Add72b
- Sub72b
- compl36
- compl18
- copyBytes
- copyChars
- putByte
- putChar
- convert_to_word72
- convert_to_word36
- cmp36
- cmp18
- cmp36wl
- cmp72
- strlower
- strmask
- rtrim
- ltrim
- trim
- stripquotes
- cfg_parse
- cfg_parse_done
- strdupesc
- extrASCII36
- extr36
- putASCII36
- put36
- extractASCII36FromBuffer
- extractWord36FromBuffer
- insertASCII36toBuffer
- insertWord36toBuffer
- print_uint128o_r
- print_int128o
- print_uint128_r
- print_int128
- timespec_diff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 #include <stdio.h>
20 #include <string.h>
21 #include <signal.h>
22 #include <ctype.h>
23
24 #include "dps8.h"
25 #include "dps8_sys.h"
26 #include "dps8_iom.h"
27 #include "dps8_cable.h"
28 #include "dps8_cpu.h"
29 #include "dps8_faults.h"
30 #include "dps8_scu.h"
31 #include "dps8_ins.h"
32 #include "dps8_opcodetable.h"
33 #include "dps8_utils.h"
34
35 #define DBG_CTR 1
36
37 #define FREE(p) do \
38 { \
39 free((p)); \
40 (p) = NULL; \
41 } while(0)
42
43
44
45
46
47 char * dump_flags(char * buffer, word18 flags)
48 {
49 (void)sprintf(buffer, "%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
50 flags & I_HEX ? "Hex " : "",
51 flags & I_ABS ? "Abs " : "",
52 flags & I_MIF ? "MIF " : "",
53 flags & I_TRUNC ? "Trunc " : "",
54 flags & I_NBAR ? "~BAR " : "",
55 flags & I_PMASK ? "PMask " : "",
56 flags & I_PERR ? "PErr" : "",
57 flags & I_TALLY ? "Tally " : "",
58 flags & I_OMASK ? "OMASK " : "",
59 flags & I_EUFL ? "EUFL " : "",
60 flags & I_EOFL ? "EOFL " : "",
61 flags & I_OFLOW ? "Ovr " : "",
62 flags & I_CARRY ? "Carry " : "",
63 flags & I_NEG ? "Neg " : "",
64 flags & I_ZERO ? "Zero " : ""
65 );
66 return buffer;
67 }
68
69 static char * dps8_strupr(char *str)
70 {
71 char *s;
72
73 for(s = str; *s; s++)
74 *s = (char) toupper((unsigned char)*s);
75 return str;
76 }
77
78
79
80 static struct opcode_s unimplented = {"(unimplemented)", 0, 0, 0, 0};
81
82 struct opcode_s * get_iwb_info (DCDstruct * i)
83 {
84 struct opcode_s * p = &opcodes10[i->opcode10];
85 return p->mne ? p : &unimplented;
86 }
87
88 char *disassemble(char * result, word36 instruction)
89 {
90 uint32 opcode = GET_OP(instruction);
91 uint32 opcodeX = GET_OPX(instruction);
92 uint32 opcode10 = opcode | (opcodeX ? 01000 : 0);
93 word18 address = GET_ADDR(instruction);
94 word1 a = GET_A(instruction);
95
96 word6 tag = GET_TAG(instruction);
97
98
99 strcpy(result, "???");
100
101
102 if (opcodes10[opcode10].mne)
103 strcpy(result, opcodes10[opcode10].mne);
104
105
106
107 char buff[256];
108
109 if (a)
110 {
111 int n = (address >> 15) & 07;
112 int offset = address & 077777;
113
114 (void)sprintf (buff, " pr%d|%o", n, offset);
115 strcat (result, buff);
116
117 } else {
118 (void)sprintf (buff, " %06o", address);
119 strcat (result, buff);
120 }
121
122 strcpy(buff, "");
123 for(uint n = 0 ; n < 0100 ; n++)
124 if (extMods[n].mod)
125 if(n == tag)
126 {
127 strncpy(buff, extMods[n].mod, sizeof(buff) - 1);
128 buff[sizeof(buff) - 1] = '\0';
129 break;
130 }
131
132 if (strlen(buff))
133 {
134 strcat(result, ",");
135 strcat(result, buff);
136 }
137
138 return dps8_strupr(result);
139 }
140
141
142
143
144
145
146
147
148 char *get_mod_string(char * msg, word6 tag)
149 {
150 strcpy(msg, "none");
151
152 if (tag >= 0100)
153 {
154 (void)sprintf (msg, "getModReg(tag out-of-range %o)", tag);
155 } else {
156 for(uint n = 0 ; n < 0100 ; n++)
157 if (extMods[n].mod)
158 if(n == tag)
159 {
160 strcpy(msg, extMods[n].mod);
161 break;
162 }
163
164 }
165 return msg;
166 }
167
168
169
170
171
172
173 word36 Add36b (cpu_state_t * cpup, word36 op1, word36 op2, word1 carryin, word18 flagsToSet, word18 * flags, bool * ovf)
174 {
175 CPT (cpt2L, 17);
176 sim_debug (DBG_TRACEEXT, & cpu_dev,
177 "Add36b op1 %012"PRIo64" op2 %012"PRIo64" carryin %o flagsToSet %06o flags %06o\n",
178 op1, op2, carryin, flagsToSet, * flags);
179
180
181
182
183 word38 op1e = op1 & MASK36;
184 word38 op2e = op2 & MASK36;
185 word38 ci = carryin ? 1 : 0;
186
187
188 if (op1e & SIGN36)
189 op1e |= BIT37;
190 if (op2e & SIGN36)
191 op2e |= BIT37;
192
193
194 word38 res = op1e + op2e + ci;
195
196
197 bool r37 = res & BIT37 ? true : false;
198 bool r36 = res & SIGN36 ? true : false;
199
200
201 bool r38 = res & BIT38 ? true : false;
202
203
204 * ovf = r37 ^ r36;
205
206
207 bool cry = r38;
208
209
210 res &= MASK36;
211
212 #if defined(PANEL68)
213 if (cry) CPT (cpt2L, 28);
214 if (ovf) CPT (cpt2L, 29);
215 if (!res) CPT (cpt2L, 30);
216 if (res & SIGN36) CPT (cpt2L, 31);
217 #endif
218
219 if (flagsToSet & I_CARRY)
220 {
221 if (cry)
222 SETF (* flags, I_CARRY);
223 else
224 CLRF (* flags, I_CARRY);
225 }
226
227 if (chkOVF (cpup) && (flagsToSet & I_OFLOW))
228 {
229 if (* ovf)
230 SETF (* flags, I_OFLOW);
231 }
232
233 if (flagsToSet & I_ZERO)
234 {
235 if (res)
236 CLRF (* flags, I_ZERO);
237 else
238 SETF (* flags, I_ZERO);
239 }
240
241 if (flagsToSet & I_NEG)
242 {
243 if (res & SIGN36)
244 SETF (* flags, I_NEG);
245 else
246 CLRF (* flags, I_NEG);
247 }
248
249 sim_debug (DBG_TRACEEXT, & cpu_dev, "Add36b res %012"PRIo64" flags %06o ovf %o\n", res, * flags, * ovf);
250 return res;
251 }
252
253 word36 Sub36b (cpu_state_t * cpup, word36 op1, word36 op2, word1 carryin, word18 flagsToSet, word18 * flags, bool * ovf)
254 {
255 CPT (cpt2L, 18);
256
257
258
259
260
261
262
263
264
265 word38 op1e = op1 & MASK36;
266 word38 op2e = op2 & MASK36;
267
268 word38 ci = carryin ? 0 : 1;
269
270
271 if (op1e & SIGN36)
272 op1e |= BIT37;
273 if (op2e & SIGN36)
274 op2e |= BIT37;
275
276
277
278
279 word38 res = (word38) (((word38s) op1e) - ((word38s) op2e) - ((word38) ci));
280
281
282 bool r37 = (res & BIT37) ? true : false;
283 bool r36 = (res & SIGN36) ? true : false;
284
285
286 bool r38 = res & BIT38 ? true : false;
287
288
289 res &= MASK36;
290
291
292 * ovf = r37 ^ r36;
293
294
295 bool cry = r38;
296
297 #if defined(PANEL68)
298 if (cry) CPT (cpt2L, 28);
299 if (ovf) CPT (cpt2L, 29);
300 if (!res) CPT (cpt2L, 30);
301 if (res & SIGN36) CPT (cpt2L, 31);
302 #endif
303
304 if (flagsToSet & I_CARRY)
305 {
306 if (cry)
307 CLRF (* flags, I_CARRY);
308 else
309 SETF (* flags, I_CARRY);
310 }
311
312 if (chkOVF (cpup) && (flagsToSet & I_OFLOW))
313 {
314 if (* ovf)
315 SETF (* flags, I_OFLOW);
316 }
317
318 if (flagsToSet & I_ZERO)
319 {
320 if (res)
321 CLRF (* flags, I_ZERO);
322 else
323 SETF (* flags, I_ZERO);
324 }
325
326 if (flagsToSet & I_NEG)
327 {
328 if (res & SIGN36)
329 SETF (* flags, I_NEG);
330 else
331 CLRF (* flags, I_NEG);
332 }
333
334 return res;
335 }
336
337 word18 Add18b (cpu_state_t * cpup, word18 op1, word18 op2, word1 carryin, word18 flagsToSet, word18 * flags, bool * ovf)
338 {
339 CPT (cpt2L, 19);
340
341
342
343
344 word20 op1e = op1 & MASK18;
345 word20 op2e = op2 & MASK18;
346 word20 ci = carryin ? 1 : 0;
347
348
349 if (op1e & SIGN18)
350 op1e |= BIT19;
351 if (op2e & SIGN18)
352 op2e |= BIT19;
353
354
355 word20 res = op1e + op2e + ci;
356
357
358 bool r19 = (res & BIT19) ? true : false;
359 bool r18 = (res & SIGN18) ? true : false;
360
361
362 bool r20 = res & BIT20 ? true : false;
363
364
365 res &= MASK18;
366
367
368 * ovf = r19 ^ r18;
369
370
371 bool cry = r20;
372
373 #if defined(PANEL68)
374 if (cry) CPT (cpt2L, 28);
375 if (ovf) CPT (cpt2L, 29);
376 if (!res) CPT (cpt2L, 30);
377 if (res & SIGN36) CPT (cpt2L, 31);
378 #endif
379
380 if (flagsToSet & I_CARRY)
381 {
382 if (cry)
383 SETF (* flags, I_CARRY);
384 else
385 CLRF (* flags, I_CARRY);
386 }
387
388 if (chkOVF (cpup) && (flagsToSet & I_OFLOW))
389 {
390 if (* ovf)
391 SETF (* flags, I_OFLOW);
392 }
393
394 if (flagsToSet & I_ZERO)
395 {
396 if (res)
397 CLRF (* flags, I_ZERO);
398 else
399 SETF (* flags, I_ZERO);
400 }
401
402 if (flagsToSet & I_NEG)
403 {
404 if (res & SIGN18)
405 SETF (* flags, I_NEG);
406 else
407 CLRF (* flags, I_NEG);
408 }
409
410 return (word18) res;
411 }
412
413 word18 Sub18b (cpu_state_t * cpup, word18 op1, word18 op2, word1 carryin, word18 flagsToSet, word18 * flags, bool * ovf)
414 {
415 CPT (cpt2L, 20);
416
417
418
419
420
421
422
423
424
425 word20 op1e = op1 & MASK18;
426 word20 op2e = op2 & MASK18;
427
428 word20 ci = carryin ? 0 : 1;
429
430
431 if (op1e & SIGN18)
432 op1e |= BIT19;
433 if (op2e & SIGN18)
434 op2e |= BIT19;
435
436
437
438
439 word20 res = (word20) (((word20s) op1e) - ((word20s) op2e) - ((word20s) ci));
440
441
442 bool r19 = res & BIT19 ? true : false;
443 bool r18 = res & SIGN18 ? true : false;
444
445
446 bool r20 = res & BIT20 ? true : false;
447
448
449 res &= MASK18;
450
451
452 * ovf = r19 ^ r18;
453
454
455 bool cry = r20;
456
457 #if defined(PANEL68)
458 if (cry) CPT (cpt2L, 28);
459 if (ovf) CPT (cpt2L, 29);
460 if (!res) CPT (cpt2L, 30);
461 if (res & SIGN36) CPT (cpt2L, 31);
462 #endif
463
464 if (flagsToSet & I_CARRY)
465 {
466 if (cry)
467 CLRF (* flags, I_CARRY);
468 else
469 SETF (* flags, I_CARRY);
470 }
471
472 if (chkOVF (cpup) && (flagsToSet & I_OFLOW))
473 {
474 if (* ovf)
475 SETF (* flags, I_OFLOW);
476 }
477
478 if (flagsToSet & I_ZERO)
479 {
480 if (res)
481 CLRF (* flags, I_ZERO);
482 else
483 SETF (* flags, I_ZERO);
484 }
485
486 if (flagsToSet & I_NEG)
487 {
488 if (res & SIGN18)
489 SETF (* flags, I_NEG);
490 else
491 CLRF (* flags, I_NEG);
492 }
493
494 return res;
495 }
496
497 word72 Add72b (cpu_state_t * cpup, word72 op1, word72 op2, word1 carryin, word18 flagsToSet, word18 * flags, bool * ovf)
498 {
499 CPT (cpt2L, 21);
500
501
502
503
504 #if defined(NEED_128)
505 word74 op1e = and_128 (op1, MASK72);
506 word74 op2e = and_128 (op2, MASK72);
507 word74 ci = construct_128 (0, carryin ? 1 : 0);
508 #else
509 word74 op1e = op1 & MASK72;
510 word74 op2e = op2 & MASK72;
511 word74 ci = carryin ? 1 : 0;
512 #endif
513
514
515 #if defined(NEED_128)
516 if (isnonzero_128 (and_128 (op1e, SIGN72)))
517 op1e = or_128 (op1e, BIT73);
518 if (isnonzero_128 (and_128 (op2e, SIGN72)))
519 op2e = or_128 (op2e, BIT73);
520 #else
521 if (op1e & SIGN72)
522 op1e |= BIT73;
523 if (op2e & SIGN72)
524 op2e |= BIT73;
525 #endif
526
527
528 #if defined(NEED_128)
529 word74 res = add_128 (op1e, add_128 (op2e, ci));
530 #else
531 word74 res = op1e + op2e + ci;
532 #endif
533
534
535 #if defined(NEED_128)
536 bool r73 = isnonzero_128 (and_128 (res, BIT73));
537 bool r72 = isnonzero_128 (and_128 (res, SIGN72));
538 #else
539 bool r73 = res & BIT73 ? true : false;
540 bool r72 = res & SIGN72 ? true : false;
541 #endif
542
543
544 #if defined(NEED_128)
545 bool r74 = isnonzero_128 (and_128 (res, BIT74));
546 #else
547 bool r74 = res & BIT74 ? true : false;
548 #endif
549
550
551 #if defined(NEED_128)
552 res = and_128 (res, MASK72);
553 #else
554 res &= MASK72;
555 #endif
556
557
558 * ovf = r73 ^ r72;
559
560
561 bool cry = r74;
562
563 #if defined(PANEL68)
564 if (cry) CPT (cpt2L, 28);
565 if (ovf) CPT (cpt2L, 29);
566 if (!res) CPT (cpt2L, 30);
567 if (res & SIGN36) CPT (cpt2L, 31);
568 #endif
569
570 if (flagsToSet & I_CARRY)
571 {
572 if (cry)
573 SETF (* flags, I_CARRY);
574 else
575 CLRF (* flags, I_CARRY);
576 }
577
578 if (chkOVF (cpup) && (flagsToSet & I_OFLOW))
579 {
580 if (* ovf)
581 SETF (* flags, I_OFLOW);
582 }
583
584 if (flagsToSet & I_ZERO)
585 {
586 #if defined(NEED_128)
587 if (isnonzero_128 (res))
588 #else
589 if (res)
590 #endif
591 CLRF (* flags, I_ZERO);
592 else
593 SETF (* flags, I_ZERO);
594 }
595
596 if (flagsToSet & I_NEG)
597 {
598 #if defined(NEED_128)
599 if (isnonzero_128 (and_128 (res, SIGN72)))
600 #else
601 if (res & SIGN72)
602 #endif
603 SETF (* flags, I_NEG);
604 else
605 CLRF (* flags, I_NEG);
606 }
607
608 return res;
609 }
610
611 word72 Sub72b (cpu_state_t * cpup, word72 op1, word72 op2, word1 carryin, word18 flagsToSet, word18 * flags, bool * ovf)
612 {
613 CPT (cpt2L, 22);
614 #if defined(NEED_128)
615 sim_debug (DBG_TRACEEXT, & cpu_dev,
616 "Sub72b op1 %012"PRIo64"%012"PRIo64" op2 %012"PRIo64"%012"PRIo64" carryin %o flagsToSet %06o flags %06o\n",
617 (word36) ((rshift_128 (op1, 36).l) & MASK36),
618 (word36) (op1.l & MASK36),
619 (word36) (rshift_128 (op2, 36).l & MASK36),
620 (word36) (op2.l & MASK36),
621 carryin, flagsToSet, * flags);
622 #else
623 sim_debug (DBG_TRACEEXT, & cpu_dev,
624 "Sub72b op1 %012"PRIo64"%012"PRIo64" op2 %012"PRIo64"%012"PRIo64" carryin %o flagsToSet %06o flags %06o\n",
625 (word36) ((op1 >> 36) & MASK36),
626 (word36) (op1 & MASK36),
627 (word36) ((op2 >> 36) & MASK36),
628 (word36) (op2 & MASK36),
629 carryin, flagsToSet, * flags);
630 #endif
631
632
633
634
635
636
637
638
639
640 #if defined(NEED_128)
641 word74 op1e = and_128 (op1, MASK72);
642 word74 op2e = and_128 (op2, MASK72);
643 #else
644 word74 op1e = op1 & MASK72;
645 word74 op2e = op2 & MASK72;
646 #endif
647
648 #if defined(NEED_128)
649 word74 ci = construct_128 (0, carryin ? 0 : 1);
650 #else
651 word74 ci = carryin ? 0 : 1;
652 #endif
653
654
655 #if defined(NEED_128)
656 if (isnonzero_128 (and_128 (op1e, SIGN72)))
657 op1e = or_128 (op1e, BIT73);
658 if (isnonzero_128 (and_128 (op2e, SIGN72)))
659 op2e = or_128 (op2e, BIT73);
660 #else
661 if (op1e & SIGN72)
662 op1e |= BIT73;
663 if (op2e & SIGN72)
664 op2e |= BIT73;
665 #endif
666
667
668 #if defined(NEED_128)
669 sim_debug (DBG_TRACEEXT, & cpu_dev,
670 "Sub72b op1e %012"PRIo64"%012"PRIo64" op2e %012"PRIo64"%012"PRIo64" carryin %o flagsToSet %06o flags %06o\n",
671 (word36) ((rshift_128 (op1e, 36).l) & MASK36),
672 (word36) (op1e.l & MASK36),
673 (word36) (rshift_128 (op2e, 36).l & MASK36),
674 (word36) (op2e.l & MASK36),
675 carryin, flagsToSet, * flags);
676 #else
677 sim_debug (DBG_TRACEEXT, & cpu_dev,
678 "Sub72b op1e %012"PRIo64"%012"PRIo64" op2e %012"PRIo64"%012"PRIo64" carryin %o flagsToSet %06o flags %06o\n",
679 (word36) ((op1e >> 36) & MASK36),
680 (word36) (op1e & MASK36),
681 (word36) ((op2e >> 36) & MASK36),
682 (word36) (op2e & MASK36),
683 carryin, flagsToSet, * flags);
684 #endif
685 #if defined(NEED_128)
686 word74 res = subtract_128 (subtract_128 (op1e, op2e), ci);
687 #else
688
689
690 word74 res = (word72) (((word72s) op1e) - ((word72s) op2e) - ((word72s) ci));
691 #endif
692 #if defined(NEED_128)
693 sim_debug (DBG_TRACEEXT, & cpu_dev, "Sub72b res %012"PRIo64"%012"PRIo64" flags %06o ovf %o\n",
694 (word36) (rshift_128 (res, 36).l & MASK36), (word36) (res.l & MASK36), * flags, * ovf);
695 #else
696 sim_debug (DBG_TRACEEXT, & cpu_dev, "Sub72b res %012"PRIo64"%012"PRIo64" flags %06o ovf %o\n",
697 (word36) ((res >> 36) & MASK36), (word36) (res & MASK36), * flags, * ovf);
698 #endif
699
700
701 #if defined(NEED_128)
702 bool r73 = isnonzero_128 (and_128 (res, BIT73));
703 bool r72 = isnonzero_128 (and_128 (res, SIGN72));
704 #else
705 bool r73 = res & BIT73 ? true : false;
706 bool r72 = res & SIGN72 ? true : false;
707 #endif
708
709
710 #if defined(NEED_128)
711 bool r74 = isnonzero_128 (and_128 (res, BIT74));
712 #else
713 bool r74 = res & BIT74 ? true : false;
714 #endif
715
716
717 #if defined(NEED_128)
718 res = and_128 (res, MASK72);
719 #else
720 res &= MASK72;
721 #endif
722
723
724 * ovf = r73 ^ r72;
725
726
727 bool cry = r74;
728
729 #if defined(PANEL68)
730 if (cry) CPT (cpt2L, 28);
731 if (ovf) CPT (cpt2L, 29);
732 if (!res) CPT (cpt2L, 30);
733 if (res & SIGN36) CPT (cpt2L, 31);
734 #endif
735
736 if (flagsToSet & I_CARRY)
737 {
738 if (cry)
739 CLRF (* flags, I_CARRY);
740 else
741 SETF (* flags, I_CARRY);
742 }
743
744 if (chkOVF (cpup) && (flagsToSet & I_OFLOW))
745 {
746 if (* ovf)
747 SETF (* flags, I_OFLOW);
748 }
749
750 if (flagsToSet & I_ZERO)
751 {
752 #if defined(NEED_128)
753 if (isnonzero_128 (res))
754 #else
755 if (res)
756 #endif
757 CLRF (* flags, I_ZERO);
758 else
759 SETF (* flags, I_ZERO);
760 }
761
762 if (flagsToSet & I_NEG)
763 {
764 #if defined(NEED_128)
765 if (isnonzero_128 (and_128 (res, SIGN72)))
766 #else
767 if (res & SIGN72)
768 #endif
769 SETF (* flags, I_NEG);
770 else
771 CLRF (* flags, I_NEG);
772 }
773
774 #if defined(NEED_128)
775 sim_debug (DBG_TRACEEXT, & cpu_dev, "Sub72b res %012"PRIo64"%012"PRIo64" flags %06o ovf %o\n",
776 (word36) (rshift_128 (res, 36).l & MASK36), (word36) (res.l & MASK36), * flags, * ovf);
777 #else
778 sim_debug (DBG_TRACEEXT, & cpu_dev, "Sub72b res %012"PRIo64"%012"PRIo64" flags %06o ovf %o\n",
779 (word36) ((res >> 36) & MASK36), (word36) (res & MASK36), * flags, * ovf);
780 #endif
781 return res;
782 }
783
784
785 word36 compl36(cpu_state_t * cpup, word36 op1, word18 *flags, bool * ovf)
786 {
787 CPT (cpt2L, 23);
788
789
790 op1 &= DMASK;
791
792
793
794 word36 res = ((word36) (- ((word36s) op1))) & DMASK;
795
796 * ovf = op1 == MAXNEG;
797
798 #if defined(PANEL68)
799 if (* ovf) CPT (cpt2L, 29);
800 if (!res) CPT (cpt2L, 30);
801 if (res & SIGN36) CPT (cpt2L, 31);
802 #endif
803
804 if (chkOVF (cpup) && * ovf)
805 SETF(*flags, I_OFLOW);
806
807 if (res & SIGN36)
808 SETF(*flags, I_NEG);
809 else
810 CLRF(*flags, I_NEG);
811
812 if (res == 0)
813 SETF(*flags, I_ZERO);
814 else
815 CLRF(*flags, I_ZERO);
816
817 return res;
818 }
819
820
821 word18 compl18(cpu_state_t * cpup, word18 op1, word18 *flags, bool * ovf)
822 {
823 CPT (cpt2L, 24);
824
825
826 op1 &= MASK18;
827
828
829
830 word18 res = ((word18) (- (word18s) op1)) & MASK18;
831
832 * ovf = op1 == MAX18NEG;
833 #if defined(PANEL68)
834 if (* ovf) CPT (cpt2L, 29);
835 if (!res) CPT (cpt2L, 30);
836 if (res & SIGN18) CPT (cpt2L, 31);
837 #endif
838
839 if (chkOVF (cpup) && * ovf)
840 SETF(*flags, I_OFLOW);
841 if (res & SIGN18)
842 SETF(*flags, I_NEG);
843 else
844 CLRF(*flags, I_NEG);
845
846 if (res == 0)
847 SETF(*flags, I_ZERO);
848 else
849 CLRF(*flags, I_ZERO);
850
851 return res;
852 }
853
854 void copyBytes(int posn, word36 src, word36 *dst)
855 {
856 word36 mask = 0;
857
858 if (posn & 8)
859 mask |= 0777000000000LL;
860
861 if (posn & 4)
862 mask |= 0000777000000LL;
863
864 if (posn & 2)
865 mask |= 0000000777000LL;
866
867 if (posn & 1)
868 mask |= 0000000000777LL;
869
870 word36 byteVals = src & mask;
871
872
873 *dst &= ~mask;
874
875
876 *dst |= byteVals;
877 }
878
879 void copyChars(int posn, word36 src, word36 *dst)
880 {
881 word36 mask = 0;
882
883 if (posn & 32)
884 mask |= 0770000000000LL;
885
886 if (posn & 16)
887 mask |= 0007700000000LL;
888
889 if (posn & 8)
890 mask |= 0000077000000LL;
891
892 if (posn & 4)
893 mask |= 0000000770000LL;
894
895 if (posn & 2)
896 mask |= 0000000007700LL;
897
898 if (posn & 1)
899 mask |= 0000000000077LL;
900
901 word36 byteVals = src & mask;
902
903
904 *dst &= ~mask;
905
906
907 *dst |= byteVals;
908 }
909
910
911
912
913 void putByte(word36 *dst, word9 data, int posn)
914 {
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933 putbits36_9 (dst, (uint) posn * 9, data);
934 }
935
936 void putChar(word36 *dst, word6 data, int posn)
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 putbits36_6 (dst, (uint) posn * 6, data);
963 }
964
965 word72 convert_to_word72(word36 even, word36 odd)
966 {
967 #if defined(NEED_128)
968 return or_128 (lshift_128 (construct_128 (0, even), 36), construct_128 (0, odd));
969 #else
970 return ((word72)even << 36) | (word72)odd;
971 #endif
972 }
973
974 void convert_to_word36 (word72 src, word36 *even, word36 *odd)
975 {
976 #if defined(NEED_128)
977 *even = rshift_128 (src, 36).l & DMASK;
978 *odd = src.l & DMASK;
979 #else
980 *even = (word36)(src >> 36) & DMASK;
981 *odd = (word36)src & DMASK;
982 #endif
983 }
984
985 void cmp36(cpu_state_t * cpup, word36 oP1, word36 oP2, word18 *flags)
986 {
987 CPT (cpt2L, 25);
988 L68_ (cpu.ou.cycle |= ou_GOS;)
989 t_int64 op1 = SIGNEXT36_64(oP1 & DMASK);
990 t_int64 op2 = SIGNEXT36_64(oP2 & DMASK);
991
992 word36 sign1 = (word36) op1 & SIGN36;
993 word36 sign2 = (word36) op2 & SIGN36;
994
995 if ((! sign1) && sign2)
996 CLRF (* flags, I_ZERO | I_NEG | I_CARRY);
997
998 else if (sign1 == sign2)
999 {
1000 if (op1 > op2)
1001 {
1002 CPT (cpt2L, 28);
1003 SETF (* flags, I_CARRY);
1004 CLRF (* flags, I_ZERO | I_NEG);
1005 }
1006 else if (op1 == op2)
1007 {
1008 CPT (cpt2L, 28);
1009 CPT (cpt2L, 30);
1010 SETF (* flags, I_ZERO | I_CARRY);
1011 CLRF (* flags, I_NEG);
1012 }
1013 else
1014 {
1015 CPT (cpt2L, 31);
1016 SETF (* flags, I_NEG);
1017 CLRF (* flags, I_ZERO | I_CARRY);
1018 }
1019 }
1020 else
1021 {
1022 CPT (cpt2L, 28);
1023 CPT (cpt2L, 31);
1024 SETF (* flags, I_CARRY | I_NEG);
1025 CLRF (* flags, I_ZERO);
1026 }
1027 }
1028
1029 void cmp18(cpu_state_t * cpup, word18 oP1, word18 oP2, word18 *flags)
1030 {
1031 CPT (cpt2L, 26);
1032 L68_ (cpu.ou.cycle |= ou_GOS;)
1033 int32 op1 = SIGNEXT18_32 (oP1 & MASK18);
1034 int32 op2 = SIGNEXT18_32 (oP2 & MASK18);
1035
1036 word18 sign1 = (word18) op1 & SIGN18;
1037 word18 sign2 = (word18) op2 & SIGN18;
1038
1039 if ((! sign1) && sign2)
1040 CLRF (* flags, I_ZERO | I_NEG | I_CARRY);
1041
1042 else if (sign1 == sign2)
1043 {
1044 if (op1 > op2)
1045 {
1046 CPT (cpt2L, 28);
1047 SETF (* flags, I_CARRY);
1048 CLRF (* flags, I_ZERO | I_NEG);
1049 }
1050 else if (op1 == op2)
1051 {
1052 CPT (cpt2L, 28);
1053 CPT (cpt2L, 30);
1054 SETF (* flags, I_ZERO | I_CARRY);
1055 CLRF (* flags, I_NEG);
1056 }
1057 else
1058 {
1059 CPT (cpt2L, 31);
1060 SETF (* flags, I_NEG);
1061 CLRF (* flags, I_ZERO | I_CARRY);
1062 }
1063 }
1064 else
1065 {
1066 CPT (cpt2L, 28);
1067 CPT (cpt2L, 31);
1068 SETF (* flags, I_CARRY | I_NEG);
1069 CLRF (* flags, I_ZERO);
1070 }
1071 }
1072
1073 void cmp36wl(cpu_state_t * cpup, word36 A, word36 Y, word36 Q, word18 *flags)
1074 {
1075 CPT (cpt2L, 26);
1076
1077
1078
1079
1080 L68_ (cpu.ou.cycle |= ou_GOS;)
1081 t_int64 As = (word36s) SIGNEXT36_64(A & DMASK);
1082 t_int64 Ys = (word36s) SIGNEXT36_64(Y & DMASK);
1083 t_int64 Qs = (word36s) SIGNEXT36_64(Q & DMASK);
1084 bool Z = (As <= Ys && Ys <= Qs) || (As >= Ys && Ys >= Qs);
1085
1086 SCF(Z, *flags, I_ZERO);
1087
1088 if (!(Q & SIGN36) && (Y & SIGN36) && (Qs > Ys))
1089 CLRF(*flags, I_NEG | I_CARRY);
1090 else if (((Q & SIGN36) == (Y & SIGN36)) && (Qs >= Ys))
1091 {
1092 CPT (cpt2L, 28);
1093 SETF(*flags, I_CARRY);
1094 CLRF(*flags, I_NEG);
1095 } else if (((Q & SIGN36) == (Y & SIGN36)) && (Qs < Ys))
1096 {
1097 CPT (cpt2L, 31);
1098 CLRF(*flags, I_CARRY);
1099 SETF(*flags, I_NEG);
1100 } else if ((Q & SIGN36) && !(Y & SIGN36) && (Qs < Ys))
1101 {
1102 CPT (cpt2L, 28);
1103 CPT (cpt2L, 31);
1104 SETF(*flags, I_NEG | I_CARRY);
1105 }
1106 }
1107
1108 void cmp72(cpu_state_t * cpup, word72 op1, word72 op2, word18 *flags)
1109 {
1110 CPT (cpt2L, 27);
1111
1112
1113 L68_ (cpu.ou.cycle |= ou_GOS;)
1114 #if defined(NEED_128)
1115 sim_debug (DBG_TRACEEXT, & cpu_dev, "op1 %016"PRIx64"%016"PRIx64"\n", op1.h, op1.l);
1116 sim_debug (DBG_TRACEEXT, & cpu_dev, "op2 %016"PRIx64"%016"PRIx64"\n", op2.h, op2.l);
1117 int128 op1s = SIGNEXT72_128 (and_128 (op1, MASK72));
1118 int128 op2s = SIGNEXT72_128 (and_128 (op2, MASK72));
1119 sim_debug (DBG_TRACEEXT, & cpu_dev, "op1s %016"PRIx64"%016"PRIx64"\n", op1s.h, op1s.l);
1120 sim_debug (DBG_TRACEEXT, & cpu_dev, "op2s %016"PRIx64"%016"PRIx64"\n", op2s.h, op2s.l);
1121 #else
1122 sim_debug (DBG_TRACEEXT, & cpu_dev, "op1 %016"PRIx64"%016"PRIx64"\n", (uint64_t) (op1>>64), (uint64_t) op1);
1123 sim_debug (DBG_TRACEEXT, & cpu_dev, "op2 %016"PRIx64"%016"PRIx64"\n", (uint64_t) (op2>>64), (uint64_t) op2);
1124 int128 op1s = SIGNEXT72_128 (op1 & MASK72);
1125 int128 op2s = SIGNEXT72_128 (op2 & MASK72);
1126 sim_debug (DBG_TRACEEXT, & cpu_dev, "op1s %016"PRIx64"%016"PRIx64"\n", (uint64_t) (op1s>>64), (uint64_t) op1s);
1127 sim_debug (DBG_TRACEEXT, & cpu_dev, "op2s %016"PRIx64"%016"PRIx64"\n", (uint64_t) (op2s>>64), (uint64_t) op2s);
1128 #endif
1129 #if defined(NEED_128)
1130 if (isgt_s128 (op1s, op2s))
1131 #else
1132 if (op1s > op2s)
1133 #endif
1134 {
1135 #if defined(NEED_128)
1136 if (isnonzero_128 (and_128 (op2, SIGN72)))
1137 #else
1138 if (op2 & SIGN72)
1139 #endif
1140 CLRF (* flags, I_CARRY);
1141 else
1142 {
1143 CPT (cpt2L, 28);
1144 SETF (* flags, I_CARRY);
1145 }
1146 CLRF (* flags, I_ZERO | I_NEG);
1147 }
1148 #if defined(NEED_128)
1149 else if (iseq_128 (cast_128 (op1s), cast_128 (op2s)))
1150 #else
1151 else if (op1s == op2s)
1152 #endif
1153 {
1154 CPT (cpt2L, 28);
1155 CPT (cpt2L, 30);
1156 SETF (* flags, I_CARRY | I_ZERO);
1157 CLRF (* flags, I_NEG);
1158 }
1159 else
1160 {
1161 CPT (cpt2L, 31);
1162 #if defined(NEED_128)
1163 if (isnonzero_128 (and_128 (op1, SIGN72)))
1164 #else
1165 if (op1 & SIGN72)
1166 #endif
1167 {
1168 CPT (cpt2L, 28);
1169 SETF (* flags, I_CARRY);
1170 }
1171 else
1172 CLRF (* flags, I_CARRY);
1173 CLRF (* flags, I_ZERO);
1174 SETF (* flags, I_NEG);
1175 }
1176 }
1177
1178
1179
1180
1181
1182 char * strlower(char *q)
1183 {
1184 char *s = q;
1185
1186 while (*s) {
1187 if (isupper((unsigned char)*s))
1188 *s = (char) tolower(*s);
1189 s++;
1190 }
1191 return q;
1192 }
1193
1194
1195 #define STAR 0
1196 #define NOTSTAR 1
1197 #define RESET 2
1198
1199 int strmask (char * str, char * mask)
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217 {
1218 char * sp, * mp, * reset_string, * reset_mask, * sn;
1219 int state;
1220
1221 sp = str;
1222 mp = mask;
1223
1224 while (1)
1225 {
1226 switch (* mp)
1227 {
1228 case '\0':
1229 return * sp ? false : true;
1230
1231 case '?':
1232 sp ++;
1233 mp ++;
1234 break;
1235
1236 default:
1237 if (* mp == * sp)
1238 {
1239 sp ++;
1240 mp ++;
1241 break;
1242 }
1243 else
1244 {
1245 return false;
1246 }
1247
1248 case '*':
1249 if (* (mp + 1) == '\0')
1250 {
1251 return true;
1252 }
1253 if ((sn = strchr (sp, * (mp + 1))) == NULL)
1254 {
1255 return false;
1256 }
1257
1258
1259
1260 reset_mask = mp;
1261 reset_string = sn + 1;
1262
1263 mp = mp + 2;
1264 sp = sn + 1;
1265 state = NOTSTAR;
1266 while (state == NOTSTAR)
1267 {
1268 switch (* mp)
1269 {
1270 case '\0':
1271 if (* sp == '\0')
1272 return false;
1273 else
1274 state = RESET;
1275 break;
1276 case '?':
1277 sp ++;
1278 mp ++;
1279 break;
1280 default:
1281 if (* mp == * sp)
1282 {
1283 sp ++;
1284 mp ++;
1285 }
1286 else
1287 state = RESET;
1288 break;
1289 case '*':
1290 state = STAR;
1291 break;
1292 }
1293 }
1294
1295 if (state == RESET)
1296 {
1297 sp = reset_string;
1298 mp = reset_mask;
1299 }
1300 break;
1301 }
1302 }
1303 #if defined(SUNLINT) || !defined(__SUNPRO_C) && !defined(__SUNPRO_CC)
1304
1305 return false;
1306 #endif
1307 }
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407 char *rtrim(char *s)
1408 {
1409 if (! s)
1410 return s;
1411 int index;
1412
1413
1414 for (index = (int)strlen(s) - 1; index >= 0 && isspace((unsigned char)s[index]); index--)
1415 {
1416 s[index] = '\0';
1417 }
1418 return(s);
1419 }
1420
1421 char *ltrim(char *s)
1422
1423
1424
1425 {
1426 char *p;
1427 if (s == NULL)
1428 return NULL;
1429
1430
1431 for (p = s; isspace((unsigned char)*p) && *p != '\0'; p++)
1432 ;
1433
1434
1435 memmove(s, p, strlen(p) + 1);
1436 return(s);
1437 }
1438
1439 char *trim(char *s)
1440 {
1441 return ltrim(rtrim(s));
1442 }
1443
1444 char *
1445 stripquotes(char *s)
1446 {
1447 if (! s || ! *s)
1448 return s;
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458 int nLast = (int)strlen(s) - 1;
1459
1460 if (s[0] == '"')
1461 s[0] = ' ';
1462 if (s[nLast] == '"')
1463 s[nLast] = ' ';
1464 return trim(s);
1465 }
1466
1467 #include <ctype.h>
1468
1469
1470
1471
1472 int cfg_parse (const char * tag, const char * cptr, config_list_t * clist, config_state_t * state, int64_t * result)
1473 {
1474 if (! cptr)
1475 return -2;
1476 char * start = NULL;
1477 if (! state -> copy)
1478 {
1479 state -> copy = strdup (cptr);
1480 if (! state->copy)
1481 {
1482 (void)fprintf (stderr, "\rFATAL: Out of memory! Aborting at %s[%s:%d]\r\n",
1483 __func__, __FILE__, __LINE__);
1484 #if defined(USE_BACKTRACE)
1485 # if defined(SIGUSR2)
1486 (void)raise(SIGUSR2);
1487
1488 # endif
1489 #endif
1490 abort();
1491 }
1492 start = state -> copy;
1493 state -> statement_save = NULL;
1494 }
1495
1496 int ret = -2;
1497
1498
1499 char * statement;
1500 statement = strtok_r (start, ";", & state -> statement_save);
1501 start = NULL;
1502 if (! statement)
1503 {
1504 ret = -1;
1505 goto done;
1506 }
1507
1508
1509 char * name_start = statement;
1510 char * name_save = NULL;
1511 char * name;
1512 name = strtok_r (name_start, "=", & name_save);
1513 if (! name)
1514 {
1515 sim_printf ("error: %s: can't parse name\n", tag);
1516 goto done;
1517 }
1518
1519
1520 config_list_t * p = clist;
1521 while (p -> name)
1522 {
1523 if (strcasecmp (name, p -> name) == 0)
1524 break;
1525 p ++;
1526 }
1527 if (! p -> name)
1528 {
1529 sim_printf ("error: %s: don't know name <%s>\n", tag, name);
1530 goto done;
1531 }
1532
1533
1534 char * value;
1535 value = strtok_r (NULL, "", & name_save);
1536 if (! value)
1537 {
1538
1539
1540 if (p -> min > p -> max && ! p -> value_list)
1541 {
1542 return (int) (p - clist);
1543 }
1544 sim_printf ("error: %s: can't parse value\n", tag);
1545 goto done;
1546 }
1547
1548
1549 config_value_list_t * v = p -> value_list;
1550 if (v)
1551 {
1552 while (v -> value_name)
1553 {
1554 if (strcasecmp (value, v -> value_name) == 0)
1555 break;
1556 v ++;
1557 }
1558
1559
1560 if (v -> value_name)
1561 {
1562 * result = v -> value;
1563 return (int) (p - clist);
1564 }
1565 }
1566
1567
1568 if (p -> min > p -> max)
1569 {
1570 sim_printf ("error: %s: can't parse value\n", tag);
1571 goto done;
1572 }
1573
1574 if (strlen (value) == 0)
1575 {
1576 sim_printf ("error: %s: missing value\n", tag);
1577 goto done;
1578 }
1579 char * endptr;
1580 int64_t n = strtoll (value, & endptr, 0);
1581 if (* endptr)
1582 {
1583 sim_printf ("error: %s: can't parse value\n", tag);
1584 goto done;
1585 }
1586
1587
1588 if (n < p -> min || n > p -> max)
1589 {
1590 sim_printf ("error: %s: value out of range\n", tag);
1591 goto done;
1592 }
1593
1594 * result = n;
1595 return (int) (p - clist);
1596
1597 done:
1598 FREE (state -> copy);
1599 state -> copy = NULL;
1600 return ret;
1601 }
1602
1603 void cfg_parse_done (config_state_t * state)
1604 {
1605 if (state -> copy)
1606 FREE (state -> copy);
1607 state -> copy = NULL;
1608 }
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647 char * strdupesc (const char * str)
1648 {
1649 char * buf = strdup (str);
1650 if (!buf)
1651 {
1652 (void)fprintf(stderr, "\rFATAL: Out of memory! Aborting at %s[%s:%d]\r\n",
1653 __func__, __FILE__, __LINE__);
1654 #if defined(USE_BACKTRACE)
1655 # if defined(SIGUSR2)
1656 (void)raise(SIGUSR2);
1657
1658 # endif
1659 #endif
1660 abort();
1661 }
1662 char * p = buf;
1663 while (* p)
1664 {
1665 if (* p != '\\')
1666 {
1667 p ++;
1668 continue;
1669 }
1670 if (p [1] == '\\')
1671 * p = '\\';
1672 else if (p [1] == 'a')
1673 * p = '\001';
1674 else if (p [1] == 'w')
1675 * p = '\\';
1676 else if (p [1] == 'n')
1677 * p = '\n';
1678 else if (p [1] == 't')
1679 * p = '\t';
1680 else if (p [1] == 'f')
1681 * p = '\f';
1682 else if (p [1] == 'r')
1683 * p = '\r';
1684 else if (p [1] == 'e')
1685 * p = '\005';
1686 else if (p [1] == '_')
1687
1688
1689 * p = ' ';
1690 else if (p [1] == 'c')
1691 * p = ',';
1692 else if (p [1] == 's')
1693 * p = ';';
1694 else if (p [1] == 'd')
1695 * p = '$';
1696 else if (p [1] == 'q')
1697 * p = '"';
1698 else if (p [1] == 'z')
1699 * p = '\004';
1700 else if (p [1] == 'k')
1701 * p = '^';
1702 else if (p [1] == 'x')
1703 * p = '\030';
1704 else if (p [1] == 'y')
1705 * p = '\031';
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725 else
1726 {
1727 p ++;
1728 continue;
1729 }
1730 p ++;
1731 memmove (p, p + 1, strlen (p + 1) + 1);
1732 }
1733 return buf;
1734 }
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766 static word36 extrASCII36 (uint8 * bits, uint woffset)
1767 {
1768 uint8 * p = bits + woffset * 4;
1769
1770 uint64 w;
1771 w = ((uint64) p [0]) << 27;
1772 w |= ((uint64) p [1]) << 18;
1773 w |= ((uint64) p [2]) << 9;
1774 w |= ((uint64) p [3]);
1775
1776 return (word36) (w & MASK36);
1777 }
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788 word36 extr36 (uint8 * bits, uint woffset)
1789 {
1790 uint isOdd = woffset % 2;
1791 uint dwoffset = woffset / 2;
1792 uint8 * p = bits + dwoffset * 9;
1793
1794 uint64 w;
1795 if (isOdd)
1796 {
1797 w = (((uint64) p [4]) & 0xf) << 32;
1798 w |= ((uint64) p [5]) << 24;
1799 w |= ((uint64) p [6]) << 16;
1800 w |= ((uint64) p [7]) << 8;
1801 w |= ((uint64) p [8]);
1802 }
1803 else
1804 {
1805 w = ((uint64) p [0]) << 28;
1806 w |= ((uint64) p [1]) << 20;
1807 w |= ((uint64) p [2]) << 12;
1808 w |= ((uint64) p [3]) << 4;
1809 w |= (((uint64) p [4]) >> 4) & 0xf;
1810 }
1811
1812 return (word36) (w & MASK36);
1813 }
1814
1815 static void putASCII36 (word36 val, uint8 * bits, uint woffset)
1816 {
1817 uint8 * p = bits + woffset * 4;
1818 p [0] = (val >> 27) & 0xff;
1819 p [1] = (val >> 18) & 0xff;
1820 p [2] = (val >> 9) & 0xff;
1821 p [3] = (val ) & 0xff;
1822 }
1823
1824 void put36 (word36 val, uint8 * bits, uint woffset)
1825 {
1826 uint isOdd = woffset % 2;
1827 uint dwoffset = woffset / 2;
1828 uint8 * p = bits + dwoffset * 9;
1829
1830 if (isOdd)
1831 {
1832 p [4] &= 0xf0;
1833 p [4] |= (val >> 32) & 0x0f;
1834 p [5] = (val >> 24) & 0xff;
1835 p [6] = (val >> 16) & 0xff;
1836 p [7] = (val >> 8) & 0xff;
1837 p [8] = (val >> 0) & 0xff;
1838
1839
1840
1841
1842
1843 }
1844 else
1845 {
1846 p [0] = (val >> 28) & 0xff;
1847 p [1] = (val >> 20) & 0xff;
1848 p [2] = (val >> 12) & 0xff;
1849 p [3] = (val >> 4) & 0xff;
1850 p [4] &= 0x0f;
1851 p [4] |= (val << 4) & 0xf0;
1852
1853
1854
1855
1856
1857 }
1858
1859 }
1860
1861 int extractASCII36FromBuffer (uint8 * bufp, t_mtrlnt tbc, uint * words_processed, word36 *wordp)
1862 {
1863 uint wp = * words_processed;
1864
1865
1866
1867 uint bytes_processed = wp * 4;
1868 if (bytes_processed >= tbc)
1869 return 1;
1870
1871
1872 * wordp = extrASCII36 (bufp, wp);
1873
1874
1875 (* words_processed) ++;
1876
1877 return 0;
1878 }
1879
1880 int extractWord36FromBuffer (uint8 * bufp, t_mtrlnt tbc, uint * words_processed, word36 *wordp)
1881 {
1882 uint wp = * words_processed;
1883
1884
1885
1886 uint bytes_processed = (wp * 9 + 1) / 2;
1887 if (bytes_processed >= tbc)
1888 return 1;
1889
1890
1891 * wordp = extr36 (bufp, wp);
1892
1893
1894 (* words_processed) ++;
1895
1896 return 0;
1897 }
1898
1899 int insertASCII36toBuffer (uint8 * bufp, t_mtrlnt tbc, uint * words_processed, word36 word)
1900 {
1901 uint wp = * words_processed;
1902
1903
1904
1905 uint bytes_processed = wp * 4;
1906 if (bytes_processed >= tbc)
1907 return 1;
1908
1909
1910 putASCII36 (word, bufp, wp);
1911
1912 (* words_processed) ++;
1913
1914 return 0;
1915 }
1916
1917 int insertWord36toBuffer (uint8 * bufp, t_mtrlnt tbc, uint * words_processed, word36 word)
1918 {
1919 uint wp = * words_processed;
1920
1921
1922
1923 uint bytes_processed = (wp * 9 + 1) / 2;
1924 if (bytes_processed >= tbc)
1925 return 1;
1926
1927
1928 put36 (word, bufp, wp);
1929
1930 (* words_processed) ++;
1931
1932 return 0;
1933 }
1934
1935 #if !defined(NEED_128)
1936 static void print_uint128o_r (uint128 n, char * p)
1937 {
1938 if (n == 0)
1939 return;
1940
1941 print_uint128o_r(n / 8, p);
1942 if (p)
1943 {
1944 char s [2];
1945 s [0] = n % 8 + '0';
1946 s [1] = '\0';
1947 strcat (p, s);
1948 }
1949 else
1950 sim_printf("%c", (int) (n%8+0x30));
1951 }
1952
1953 char * print_int128o (int128 n, char * p)
1954 {
1955 if (n == 0)
1956 {
1957 if (p)
1958 strcat (p, "0");
1959 else
1960 sim_printf ("0");
1961 return p;
1962 }
1963 print_uint128o_r ((uint128) n, p);
1964 return p;
1965 }
1966
1967 static void print_uint128_r (uint128 n, char * p)
1968 {
1969 if (n == 0)
1970 return;
1971
1972 print_uint128_r(n / 10, p);
1973 if (p)
1974 {
1975 char s [2];
1976 s [0] = n % 10 + '0';
1977 s [1] = '\0';
1978 strcat (p, s);
1979 }
1980 else
1981 sim_printf("%c", (int) (n%10+0x30));
1982 }
1983
1984 void print_int128 (int128 n, char * p)
1985 {
1986 if (n == 0)
1987 {
1988 if (p)
1989 strcat (p, "0");
1990 else
1991 sim_printf ("0");
1992 return;
1993 }
1994 if (n < 0)
1995 {
1996 if (p)
1997 strcat (p, "-");
1998 else
1999 sim_printf ("-");
2000 n = -n;
2001 }
2002 print_uint128_r ((uint128) n, p);
2003 }
2004 #endif
2005
2006 void timespec_diff(struct timespec * start, struct timespec * stop,
2007 struct timespec * result)
2008 {
2009 if ((stop->tv_nsec - start->tv_nsec) < 0) {
2010 result->tv_sec = stop->tv_sec - start->tv_sec - 1;
2011 result->tv_nsec = stop->tv_nsec - start->tv_nsec + 1000000000L;
2012 } else {
2013 result->tv_sec = stop->tv_sec - start->tv_sec;
2014 result->tv_nsec = stop->tv_nsec - start->tv_nsec;
2015 }
2016
2017 return;
2018 }
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052