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

Subversion Repositories eco32

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

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

powered by: WebSVN 2.1.0

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