OpenCores
URL https://opencores.org/ocsvn/eco32/eco32/trunk

Subversion Repositories eco32

[/] [eco32/] [trunk/] [monitor/] [monitor/] [common/] [command.c] - Blame information for rev 200

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 59 hellwig
/*
2
 * command.c -- command interpreter
3
 */
4
 
5
 
6
#include "common.h"
7
#include "stdarg.h"
8
#include "romlib.h"
9
#include "getline.h"
10
#include "command.h"
11
#include "asm.h"
12
#include "disasm.h"
13
#include "load.h"
14
#include "boot.h"
15
#include "cpu.h"
16
#include "mmu.h"
17
#include "start.h"
18
 
19
 
20
#define MAX_TOKENS      10
21
 
22
 
23
typedef struct {
24
  char *name;
25
  void (*hlpProc)(void);
26
  void (*cmdProc)(char *tokens[], int n);
27
} Command;
28
 
29
extern Command commands[];
30
extern int numCommands;
31
 
32
 
33
static void help(void) {
34
  printf("valid commands are:\n");
35
  printf("  help    get help\n");
36
  printf("  +       add and subtract\n");
37
  printf("  a       assemble\n");
38
  printf("  u       unassemble\n");
39
  printf("  b       set/reset breakpoint\n");
40
  printf("  c       continue from breakpoint\n");
41
  printf("  s       single-step\n");
42
  printf("  #       show/set PC\n");
43
  printf("  p       show/set PSW\n");
44
  printf("  r       show/set register\n");
45
  printf("  d       dump memory\n");
46
  printf("  mw      show/set memory word\n");
47
  printf("  mh      show/set memory halfword\n");
48
  printf("  mb      show/set memory byte\n");
49
  printf("  t       show/set TLB contents\n");
50
  printf("  load    load from serial line\n");
51
  printf("  boot    bootstrap from disk\n");
52
  printf("type 'help <cmd>' to get help for <cmd>\n");
53
}
54
 
55
 
56
static void help00(void) {
57
  printf("  help              show a list of commands\n");
58
  printf("  help <cmd>        show help for <cmd>\n");
59
}
60
 
61
 
62
static void help01(void) {
63
  printf("  +  <num1> <num2>  add and subtract <num1> and <num2>\n");
64
}
65
 
66
 
67
static void help02(void) {
68
  printf("  a                 assemble starting at PC\n");
69
  printf("  a  <addr>         assemble starting at <addr>\n");
70
}
71
 
72
 
73
static void help03(void) {
74
  printf("  u                 unassemble 16 instrs starting at PC\n");
75
  printf("  u  <addr>         unassemble 16 instrs starting at <addr>\n");
76
  printf("  u  <addr> <cnt>   unassemble <cnt> instrs starting at <addr>\n");
77
}
78
 
79
 
80
static void help04(void) {
81
  printf("  b                 reset break\n");
82
  printf("  b  <addr>         set break at <addr>\n");
83
}
84
 
85
 
86
static void help05(void) {
87
  printf("  c                 continue execution\n");
88
  printf("  c  <cnt>          continue execution <cnt> times\n");
89
}
90
 
91
 
92
static void help06(void) {
93
  printf("  s                 single-step one instruction\n");
94
  printf("  s  <cnt>          single-step <cnt> instructions\n");
95
}
96
 
97
 
98
static void help07(void) {
99
  printf("  #                 show PC\n");
100
  printf("  #  <addr>         set PC to <addr>\n");
101
}
102
 
103
 
104
static void help08(void) {
105
  printf("  p                 show PSW\n");
106
  printf("  p  <data>         set PSW to <data>\n");
107
}
108
 
109
 
110
static void help09(void) {
111
  printf("  r                 show all registers\n");
112
  printf("  r  <reg>          show register <reg>\n");
113
  printf("  r  <reg> <data>   set register <reg> to <data>\n");
114
}
115
 
116
 
117
static void help10(void) {
118
  printf("  d                 dump 256 bytes starting at PC\n");
119
  printf("  d  <addr>         dump 256 bytes starting at <addr>\n");
120
  printf("  d  <addr> <cnt>   dump <cnt> bytes starting at <addr>\n");
121
}
122
 
123
 
124
static void help11(void) {
125
  printf("  mw                show memory word at PC\n");
126
  printf("  mw <addr>         show memory word at <addr>\n");
127
  printf("  mw <addr> <data>  set memory word at <addr> to <data>\n");
128
}
129
 
130
 
131
static void help12(void) {
132
  printf("  mh                show memory halfword at PC\n");
133
  printf("  mh <addr>         show memory halfword at <addr>\n");
134
  printf("  mh <addr> <data>  set memory halfword at <addr> to <data>\n");
135
}
136
 
137
 
138
static void help13(void) {
139
  printf("  mb                show memory byte at PC\n");
140
  printf("  mb <addr>         show memory byte at <addr>\n");
141
  printf("  mb <addr> <data>  set memory byte at <addr> to <data>\n");
142
}
143
 
144
 
145
static void help14(void) {
146
  printf("  t                 show TLB contents\n");
147
  printf("  t  <i>            show TLB contents at <i>\n");
148
  printf("  t  <i> p <data>   set TLB contents at <i> to page <data>\n");
149
  printf("  t  <i> f <data>   set TLB contents at <i> to frame <data>\n");
150
}
151
 
152
 
153
static void help15(void) {
154
  printf("  load <n>          load an S-record file from serial line <n>\n");
155
}
156
 
157
 
158
static void help16(void) {
159 200 hellwig
  printf("  boot <n>          load and start first sector of disk <n>\n");
160
  printf("  boot <n> *        load first sector of disk <n>, do not start\n");
161 59 hellwig
}
162
 
163
 
164
static Bool getHexNumber(char *str, Word *valptr) {
165
  char *end;
166
 
167
  *valptr = strtoul(str, &end, 16);
168
  return *end == '\0';
169
}
170
 
171
 
172
static Bool getDecNumber(char *str, int *valptr) {
173
  char *end;
174
 
175
  *valptr = strtoul(str, &end, 10);
176
  return *end == '\0';
177
}
178
 
179
 
180
static void showPC(void) {
181
  Word pc, psw;
182
  Word instr;
183
 
184
  pc = cpuGetPC();
185
  psw = cpuGetPSW();
186
  instr = mmuReadWord(pc);
187
  printf("PC   %08X     [PC]   %08X   %s\n",
188
         pc, instr, disasm(instr, pc));
189
}
190
 
191
 
192
static void showBreak(void) {
193
  Word brk;
194
 
195
  brk = cpuGetBreak();
196
  printf("brk  ");
197
  if (cpuTestBreak()) {
198
    printf("%08X", brk);
199
  } else {
200
    printf("--------");
201
  }
202
  printf("\n");
203
}
204
 
205
 
206
static void showPSW(void) {
207
  Word psw;
208
  int i;
209
 
210
  psw = cpuGetPSW();
211
  printf("     xxxx  V  UPO  IPO  IACK   MASK\n");
212
  printf("PSW  ");
213
  for (i = 31; i >= 0; i--) {
214
    if (i == 27 || i == 26 || i == 23 || i == 20 || i == 15) {
215
      printf("  ");
216
    }
217
    printf("%c", psw & (1 << i) ? '1' : '0');
218
  }
219
  printf("\n");
220
}
221
 
222
 
223
static void doHelp(char *tokens[], int n) {
224
  int i;
225
 
226
  if (n == 1) {
227
    help();
228
  } else if (n == 2) {
229
    for (i = 0; i < numCommands; i++) {
230
      if (strcmp(commands[i].name, tokens[1]) == 0) {
231
        (*commands[i].hlpProc)();
232
        return;
233
      }
234
    }
235
    printf("no help available for '%s', sorry\n", tokens[1]);
236
  } else {
237
    help00();
238
  }
239
}
240
 
241
 
242
static void doArith(char *tokens[], int n) {
243
  Word num1, num2, num3, num4;
244
 
245
  if (n == 3) {
246
    if (!getHexNumber(tokens[1], &num1)) {
247
      printf("illegal first number\n");
248
      return;
249
    }
250
    if (!getHexNumber(tokens[2], &num2)) {
251
      printf("illegal second number\n");
252
      return;
253
    }
254
    num3 = num1 + num2;
255
    num4 = num1 - num2;
256
    printf("add = %08X, sub = %08X\n", num3, num4);
257
  } else {
258
    help01();
259
  }
260
}
261
 
262
 
263
static void doAssemble(char *tokens[], int n) {
264
  Word addr;
265
  Word psw;
266
  char prompt[30];
267
  char *line;
268
  char *msg;
269
  Word instr;
270
 
271
  if (n == 1) {
272
    addr = cpuGetPC();
273
  } else if (n == 2) {
274
    if (!getHexNumber(tokens[1], &addr)) {
275
      printf("illegal address\n");
276
      return;
277
    }
278
  } else {
279
    help02();
280
    return;
281
  }
282
  addr &= ~0x00000003;
283
  psw = cpuGetPSW();
284
  while (1) {
285
    sprintf(prompt, "ASM # %08X: ", addr);
286
    line = getLine(prompt);
287
    if (*line == '\0' || *line == '\n') {
288
      break;
289
    }
290
    addHist(line);
291
    msg = asmInstr(line, addr, &instr);
292
    if (msg != NULL) {
293
      printf("%s\n", msg);
294
    } else {
295
      mmuWriteWord(addr, instr);
296
      addr += 4;
297
    }
298
  }
299
}
300
 
301
 
302
static void doUnassemble(char *tokens[], int n) {
303
  Word addr, count;
304
  Word psw;
305
  int i;
306
  Word instr;
307
 
308
  if (n == 1) {
309
    addr = cpuGetPC();
310
    count = 16;
311
  } else if (n == 2) {
312
    if (!getHexNumber(tokens[1], &addr)) {
313
      printf("illegal address\n");
314
      return;
315
    }
316
    count = 16;
317
  } else if (n == 3) {
318
    if (!getHexNumber(tokens[1], &addr)) {
319
      printf("illegal address\n");
320
      return;
321
    }
322
    if (!getHexNumber(tokens[2], &count)) {
323
      printf("illegal count\n");
324
      return;
325
    }
326
    if (count == 0) {
327
      return;
328
    }
329
  } else {
330
    help03();
331
    return;
332
  }
333
  addr &= ~0x00000003;
334
  psw = cpuGetPSW();
335
  for (i = 0; i < count; i++) {
336
    instr = mmuReadWord(addr);
337
    printf("%08X:  %08X    %s\n",
338
            addr, instr, disasm(instr, addr));
339
    if (addr + 4 < addr) {
340
      /* wrap-around */
341
      break;
342
    }
343
    addr += 4;
344
  }
345
}
346
 
347
 
348
static void doBreak(char *tokens[], int n) {
349
  Word addr;
350
 
351
  if (n == 1) {
352
    cpuResetBreak();
353
    showBreak();
354
  } else if (n == 2) {
355
    if (!getHexNumber(tokens[1], &addr)) {
356
      printf("illegal address\n");
357
      return;
358
    }
359
    addr &= ~0x00000003;
360
    cpuSetBreak(addr);
361
    showBreak();
362
  } else {
363
    help04();
364
  }
365
}
366
 
367
 
368
static void doContinue(char *tokens[], int n) {
369
  Word count, i;
370
  Word addr;
371
 
372
  if (n == 1) {
373
    count = 1;
374
  } else if (n == 2) {
375
    if (!getHexNumber(tokens[1], &count) || count == 0) {
376
      printf("illegal count\n");
377
      return;
378
    }
379
  } else {
380
    help05();
381
    return;
382
  }
383
  for (i = 0; i < count; i++) {
384
    cpuRun();
385
  }
386
  addr = cpuGetPC();
387
  printf("break at %08X\n", addr);
388
  showPC();
389
}
390
 
391
 
392
static void doStep(char *tokens[], int n) {
393
  Word count, i;
394
 
395
  if (n == 1) {
396
    count = 1;
397
  } else if (n == 2) {
398
    if (!getHexNumber(tokens[1], &count) || count == 0) {
399
      printf("illegal count\n");
400
      return;
401
    }
402
  } else {
403
    help06();
404
    return;
405
  }
406
  for (i = 0; i < count; i++) {
407
    cpuStep();
408
  }
409
  showPC();
410
}
411
 
412
 
413
static void doPC(char *tokens[], int n) {
414
  Word addr;
415
 
416
  if (n == 1) {
417
    showPC();
418
  } else if (n == 2) {
419
    if (!getHexNumber(tokens[1], &addr)) {
420
      printf("illegal address\n");
421
      return;
422
    }
423
    addr &= ~0x00000003;
424
    cpuSetPC(addr);
425
    showPC();
426
  } else {
427
    help07();
428
  }
429
}
430
 
431
 
432
static void explainPSW(Word data) {
433
  int i;
434
 
435
  printf("interrupt vector                   : %s (%s)\n",
436
         data & PSW_V ? "on " : "off",
437
         data & PSW_V ? "RAM" : "ROM");
438
  printf("current user mode                  : %s (%s)\n",
439
         data & PSW_UM ? "on " : "off",
440
         data & PSW_UM ? "user" : "kernel");
441
  printf("previous user mode                 : %s (%s)\n",
442
         data & PSW_PUM ? "on " : "off",
443
         data & PSW_PUM ? "user" : "kernel");
444
  printf("old user mode                      : %s (%s)\n",
445
         data & PSW_OUM ? "on " : "off",
446
         data & PSW_OUM ? "user" : "kernel");
447
  printf("current interrupt enable           : %s (%s)\n",
448
         data & PSW_IE ? "on " : "off",
449
         data & PSW_IE ? "enabled" : "disabled");
450
  printf("previous interrupt enable          : %s (%s)\n",
451
         data & PSW_PIE ? "on " : "off",
452
         data & PSW_PIE ? "enabled" : "disabled");
453
  printf("old interrupt enable               : %s (%s)\n",
454
         data & PSW_OIE ? "on " : "off",
455
         data & PSW_OIE ? "enabled" : "disabled");
456
  printf("last interrupt acknowledged        : %02X  (%s)\n",
457
         (data & PSW_PRIO_MASK) >> 16,
458
         exceptionToString((data & PSW_PRIO_MASK) >> 16));
459
  for (i = 15; i >= 0; i--) {
460
    printf("%-35s: %s (%s)\n",
461
           exceptionToString(i),
462
           data & (1 << i) ? "on " : "off",
463
           data & (1 << i) ? "enabled" : "disabled");
464
  }
465
}
466
 
467
 
468
static void doPSW(char *tokens[], int n) {
469
  Word data;
470
 
471
  if (n == 1) {
472
    data = cpuGetPSW();
473
    showPSW();
474
    explainPSW(data);
475
  } else if (n == 2) {
476
    if (!getHexNumber(tokens[1], &data)) {
477
      printf("illegal data\n");
478
      return;
479
    }
480
    data &= 0x0FFFFFFF;
481
    cpuSetPSW(data);
482
    showPSW();
483
    explainPSW(data);
484
  } else {
485
    help08();
486
  }
487
}
488
 
489
 
490
static void doRegister(char *tokens[], int n) {
491
  int i, j;
492
  int reg;
493
  Word data;
494
 
495
  if (n == 1) {
496
    for (i = 0; i < 8; i++) {
497
      for (j = 0; j < 4; j++) {
498
        reg = 8 * j + i;
499
        data = cpuGetReg(reg);
500
        printf("$%-2d  %08X     ", reg, data);
501
      }
502
      printf("\n");
503
    }
504
    showPSW();
505
    showBreak();
506
    showPC();
507
  } else if (n == 2) {
508
    if (!getDecNumber(tokens[1], &reg) || reg < 0 || reg >= 32) {
509
      printf("illegal register number\n");
510
      return;
511
    }
512
    data = cpuGetReg(reg);
513
    printf("$%-2d  %08X\n", reg, data);
514
  } else if (n == 3) {
515
    if (!getDecNumber(tokens[1], &reg) || reg < 0 || reg >= 32) {
516
      printf("illegal register number\n");
517
      return;
518
    }
519
    if (!getHexNumber(tokens[2], &data)) {
520
      printf("illegal data\n");
521
      return;
522
    }
523
    cpuSetReg(reg, data);
524
  } else {
525
    help09();
526
  }
527
}
528
 
529
 
530
static void doDump(char *tokens[], int n) {
531
  Word addr, count;
532
  Word psw;
533
  Word lo, hi, curr;
534
  int lines, i, j;
535
  Word tmp;
536
  Byte c;
537
 
538
  if (n == 1) {
539
    addr = cpuGetPC();
540
    count = 16 * 16;
541
  } else if (n == 2) {
542
    if (!getHexNumber(tokens[1], &addr)) {
543
      printf("illegal address\n");
544
      return;
545
    }
546
    count = 16 * 16;
547
  } else if (n == 3) {
548
    if (!getHexNumber(tokens[1], &addr)) {
549
      printf("illegal address\n");
550
      return;
551
    }
552
    if (!getHexNumber(tokens[2], &count)) {
553
      printf("illegal count\n");
554
      return;
555
    }
556
    if (count == 0) {
557
      return;
558
    }
559
  } else {
560
    help10();
561
    return;
562
  }
563
  psw = cpuGetPSW();
564
  lo = addr & ~0x0000000F;
565
  hi = addr + count - 1;
566
  if (hi < lo) {
567
    /* wrap-around */
568
    hi = 0xFFFFFFFF;
569
  }
570
  lines = (hi - lo + 16) >> 4;
571
  curr = lo;
572
  for (i = 0; i < lines; i++) {
573
    printf("%08X:  ", curr);
574
    for (j = 0; j < 16; j++) {
575
      tmp = curr + j;
576
      if (tmp < addr || tmp > hi) {
577
        printf("  ");
578
      } else {
579
        c = mmuReadByte(tmp);
580
        printf("%02X", c);
581
      }
582
      printf(" ");
583
    }
584
    printf("  ");
585
    for (j = 0; j < 16; j++) {
586
      tmp = curr + j;
587
      if (tmp < addr || tmp > hi) {
588
        printf(" ");
589
      } else {
590
        c = mmuReadByte(tmp);
591
        if (c >= 32 && c <= 126) {
592
          printf("%c", c);
593
        } else {
594
          printf(".");
595
        }
596
      }
597
    }
598
    printf("\n");
599
    curr += 16;
600
  }
601
}
602
 
603
 
604
static void doMemoryWord(char *tokens[], int n) {
605
  Word psw;
606
  Word addr;
607
  Word data;
608
  Word tmpData;
609
 
610
  psw = cpuGetPSW();
611
  if (n == 1) {
612
    addr = cpuGetPC();
613
    data = mmuReadWord(addr);
614
    printf("%08X:  %08X\n", addr, data);
615
  } else if (n == 2) {
616
    if (!getHexNumber(tokens[1], &addr)) {
617
      printf("illegal address\n");
618
      return;
619
    }
620
    data = mmuReadWord(addr);
621
    printf("%08X:  %08X\n", addr, data);
622
  } else if (n == 3) {
623
    if (!getHexNumber(tokens[1], &addr)) {
624
      printf("illegal address\n");
625
      return;
626
    }
627
    if (!getHexNumber(tokens[2], &tmpData)) {
628
      printf("illegal data\n");
629
      return;
630
    }
631
    data = tmpData;
632
    mmuWriteWord(addr, data);
633
  } else {
634
    help11();
635
  }
636
}
637
 
638
 
639
static void doMemoryHalf(char *tokens[], int n) {
640
  Word psw;
641
  Word addr;
642
  Half data;
643
  Word tmpData;
644
 
645
  psw = cpuGetPSW();
646
  if (n == 1) {
647
    addr = cpuGetPC();
648
    data = mmuReadHalf(addr);
649
    printf("%08X:  %04X\n", addr, data);
650
  } else if (n == 2) {
651
    if (!getHexNumber(tokens[1], &addr)) {
652
      printf("illegal address\n");
653
      return;
654
    }
655
    data = mmuReadHalf(addr);
656
    printf("%08X:  %04X\n", addr, data);
657
  } else if (n == 3) {
658
    if (!getHexNumber(tokens[1], &addr)) {
659
      printf("illegal address\n");
660
      return;
661
    }
662
    if (!getHexNumber(tokens[2], &tmpData)) {
663
      printf("illegal data\n");
664
      return;
665
    }
666
    data = (Half) tmpData;
667
    mmuWriteHalf(addr, data);
668
  } else {
669
    help12();
670
  }
671
}
672
 
673
 
674
static void doMemoryByte(char *tokens[], int n) {
675
  Word psw;
676
  Word addr;
677
  Byte data;
678
  Word tmpData;
679
 
680
  psw = cpuGetPSW();
681
  if (n == 1) {
682
    addr = cpuGetPC();
683
    data = mmuReadByte(addr);
684
    printf("%08X:  %02X\n", addr, data);
685
  } else if (n == 2) {
686
    if (!getHexNumber(tokens[1], &addr)) {
687
      printf("illegal address\n");
688
      return;
689
    }
690
    data = mmuReadByte(addr);
691
    printf("%08X:  %02X\n", addr, data);
692
  } else if (n == 3) {
693
    if (!getHexNumber(tokens[1], &addr)) {
694
      printf("illegal address\n");
695
      return;
696
    }
697
    if (!getHexNumber(tokens[2], &tmpData)) {
698
      printf("illegal data\n");
699
      return;
700
    }
701
    data = (Byte) tmpData;
702
    mmuWriteByte(addr, data);
703
  } else {
704
    help13();
705
  }
706
}
707
 
708
 
709
static void doTLB(char *tokens[], int n) {
710 180 hellwig
  static char *mmuAccsWidth[4] = { "byte", "half", "word", "????" };
711 59 hellwig
  int index;
712
  TLB_Entry tlbEntry;
713 180 hellwig
  Word mmuAccs;
714 59 hellwig
  Word data;
715
 
716
  if (n == 1) {
717
    for (index = 0; index < TLB_SIZE; index++) {
718
      tlbEntry = mmuGetTLB(index);
719
      printf("TLB[%02d]    page  %08X    frame  %08X  %c  %c\n",
720
             index, tlbEntry.page, tlbEntry.frame,
721
             tlbEntry.write ? 'w' : '-',
722
             tlbEntry.valid ? 'v' : '-');
723
    }
724 180 hellwig
    printf("Index   (1)  %08X\n", mmuGetIndex());
725
    printf("EntryHi (2)  %08X\n", mmuGetEntryHi());
726
    printf("EntryLo (3)  %08X\n", mmuGetEntryLo());
727
    printf("BadAddr (4)  %08X\n", mmuGetBadAddr());
728
    mmuAccs = mmuGetBadAccs();
729
    printf("BadAccs (5)  %08X (%s %s)\n",
730
           mmuAccs,
731
           (mmuAccs & MMU_ACCS_WRITE) ? "write" : "read",
732
           mmuAccsWidth[mmuAccs & 0x03]);
733 59 hellwig
  } else if (n == 2) {
734
    if (!getDecNumber(tokens[1], &index) || index < 0 || index >= TLB_SIZE) {
735
      printf("illegal TLB index\n");
736
      return;
737
    }
738
    tlbEntry = mmuGetTLB(index);
739
    printf("TLB[%02d]    page  %08X    frame  %08X  %c  %c\n",
740
           index, tlbEntry.page, tlbEntry.frame,
741
           tlbEntry.write ? 'w' : '-',
742
           tlbEntry.valid ? 'v' : '-');
743
  } else if (n == 3) {
744
    help14();
745
  } else if (n == 4) {
746
    if (!getDecNumber(tokens[1], &index) || index < 0 || index >= TLB_SIZE) {
747
      printf("illegal TLB index\n");
748
      return;
749
    }
750
    if (!getHexNumber(tokens[3], &data)) {
751
      printf("illegal data\n");
752
      return;
753
    }
754
    tlbEntry = mmuGetTLB(index);
755
    if (strcmp(tokens[2], "p") == 0) {
756
      tlbEntry.page = data & PAGE_MASK;
757
    } else
758
    if (strcmp(tokens[2], "f") == 0) {
759
      tlbEntry.frame = data & PAGE_MASK;
760
      tlbEntry.write = data & TLB_WRITE ? true : false;
761
      tlbEntry.valid = data & TLB_VALID ? true : false;
762
    } else {
763
      printf("TLB selector is not one of 'p' or 'f'\n");
764
      return;
765
    }
766
    mmuSetTLB(index, tlbEntry);
767
    printf("TLB[%02d]    page  %08X    frame  %08X  %c  %c\n",
768
           index, tlbEntry.page, tlbEntry.frame,
769
           tlbEntry.write ? 'w' : '-',
770
           tlbEntry.valid ? 'v' : '-');
771
  } else {
772
    help14();
773
  }
774
}
775
 
776
 
777
static void doLoad(char *tokens[], int n) {
778
  int serno;
779
 
780
  if (n == 2) {
781
    if (!getDecNumber(tokens[1], &serno) || serno < 0 || serno > 1) {
782
      printf("illegal serial line number\n");
783
      return;
784
    }
785
    load(serno);
786
  } else {
787
    help15();
788
  }
789
}
790
 
791
 
792
static void doBoot(char *tokens[], int n) {
793
  int dskno;
794
 
795
  if (n == 2) {
796
    if (!getDecNumber(tokens[1], &dskno) || dskno < 0 || dskno > 1) {
797
      printf("illegal disk number\n");
798
      return;
799
    }
800 200 hellwig
    boot(dskno, true);
801
  } else if (n == 3) {
802
    if (!getDecNumber(tokens[1], &dskno) || dskno < 0 || dskno > 1) {
803
      printf("illegal disk number\n");
804
      return;
805
    }
806
    if (strcmp(tokens[2], "*") != 0) {
807
      help16();
808
      return;
809
    }
810
    boot(dskno, false);
811 59 hellwig
  } else {
812
    help16();
813
  }
814
}
815
 
816
 
817
Command commands[] = {
818
  { "help", help00, doHelp       },
819
  { "+",    help01, doArith      },
820
  { "a",    help02, doAssemble   },
821
  { "u",    help03, doUnassemble },
822
  { "b",    help04, doBreak      },
823
  { "c",    help05, doContinue   },
824
  { "s",    help06, doStep       },
825
  { "#",    help07, doPC         },
826
  { "p",    help08, doPSW        },
827
  { "r",    help09, doRegister   },
828
  { "d",    help10, doDump       },
829
  { "mw",   help11, doMemoryWord },
830
  { "mh",   help12, doMemoryHalf },
831
  { "mb",   help13, doMemoryByte },
832
  { "t",    help14, doTLB        },
833
  { "load", help15, doLoad       },
834
  { "boot", help16, doBoot       },
835
};
836
 
837
int numCommands = sizeof(commands) / sizeof(commands[0]);
838
 
839
 
840
static void doCommand(char *line) {
841
  char *tokens[MAX_TOKENS];
842
  int n;
843
  char *p;
844
  int i;
845
 
846
  n = 0;
847
  p = strtok(line, " \t\n");
848
  while (p != NULL) {
849
    if (n == MAX_TOKENS) {
850
      printf("too many tokens on line\n");
851
      return;
852
    }
853
    tokens[n++] = p;
854
    p = strtok(NULL, " \t\n");
855
  }
856
  if (n == 0) {
857
    return;
858
  }
859
  for (i = 0; i < numCommands; i++) {
860
    if (strcmp(commands[i].name, tokens[0]) == 0) {
861
      (*commands[i].cmdProc)(tokens, n);
862
      return;
863
    }
864
  }
865
  help();
866
}
867
 
868
 
869
static char *article(char firstLetterOfNoun) {
870
  switch (firstLetterOfNoun) {
871
    case 'a':
872
    case 'e':
873
    case 'i':
874
    case 'o':
875
    case 'u':
876
      return "An";
877
    default:
878
      return "A";
879
  }
880
}
881
 
882
 
883
static void interactiveException(int exception) {
884
  char *what;
885
 
886
  what = exceptionToString(exception);
887
  printf("\n");
888
  printf("NOTE: %s %s occurred while executing the command.\n",
889
         article(*what), what);
890
  printf("      This event will not alter the state of the CPU.\n");
891
}
892
 
893
 
894
void execCommand(char *line) {
895
  MonitorState commandState;
896
 
897
  if (saveState(&commandState)) {
898
    /* initialization */
899
    monitorReturn = &commandState;
900
    doCommand(line);
901
  } else {
902
    /* an exception was thrown */
903
    interactiveException((userContext.psw & PSW_PRIO_MASK) >> 16);
904
  }
905
  monitorReturn = NULL;
906
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.