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

Subversion Repositories eco32

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

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
  int index;
710
  TLB_Entry tlbEntry;
711
  Word data;
712
 
713
  if (n == 1) {
714
    for (index = 0; index < TLB_SIZE; index++) {
715
      tlbEntry = mmuGetTLB(index);
716
      printf("TLB[%02d]    page  %08X    frame  %08X  %c  %c\n",
717
             index, tlbEntry.page, tlbEntry.frame,
718
             tlbEntry.write ? 'w' : '-',
719
             tlbEntry.valid ? 'v' : '-');
720
    }
721
    printf("Index(1)   %08X\n", mmuGetIndex());
722
    printf("EntryHi(2) %08X\n", mmuGetEntryHi());
723
    printf("EntryLo(3) %08X\n", mmuGetEntryLo());
724 84 hellwig
    printf("BadAddr(4) %08X\n", mmuGetBadAddr());
725 59 hellwig
  } else if (n == 2) {
726
    if (!getDecNumber(tokens[1], &index) || index < 0 || index >= TLB_SIZE) {
727
      printf("illegal TLB index\n");
728
      return;
729
    }
730
    tlbEntry = mmuGetTLB(index);
731
    printf("TLB[%02d]    page  %08X    frame  %08X  %c  %c\n",
732
           index, tlbEntry.page, tlbEntry.frame,
733
           tlbEntry.write ? 'w' : '-',
734
           tlbEntry.valid ? 'v' : '-');
735
  } else if (n == 3) {
736
    help14();
737
  } else if (n == 4) {
738
    if (!getDecNumber(tokens[1], &index) || index < 0 || index >= TLB_SIZE) {
739
      printf("illegal TLB index\n");
740
      return;
741
    }
742
    if (!getHexNumber(tokens[3], &data)) {
743
      printf("illegal data\n");
744
      return;
745
    }
746
    tlbEntry = mmuGetTLB(index);
747
    if (strcmp(tokens[2], "p") == 0) {
748
      tlbEntry.page = data & PAGE_MASK;
749
    } else
750
    if (strcmp(tokens[2], "f") == 0) {
751
      tlbEntry.frame = data & PAGE_MASK;
752
      tlbEntry.write = data & TLB_WRITE ? true : false;
753
      tlbEntry.valid = data & TLB_VALID ? true : false;
754
    } else {
755
      printf("TLB selector is not one of 'p' or 'f'\n");
756
      return;
757
    }
758
    mmuSetTLB(index, tlbEntry);
759
    printf("TLB[%02d]    page  %08X    frame  %08X  %c  %c\n",
760
           index, tlbEntry.page, tlbEntry.frame,
761
           tlbEntry.write ? 'w' : '-',
762
           tlbEntry.valid ? 'v' : '-');
763
  } else {
764
    help14();
765
  }
766
}
767
 
768
 
769
static void doLoad(char *tokens[], int n) {
770
  int serno;
771
 
772
  if (n == 2) {
773
    if (!getDecNumber(tokens[1], &serno) || serno < 0 || serno > 1) {
774
      printf("illegal serial line number\n");
775
      return;
776
    }
777
    load(serno);
778
  } else {
779
    help15();
780
  }
781
}
782
 
783
 
784
static void doBoot(char *tokens[], int n) {
785
  int dskno;
786
 
787
  if (n == 2) {
788
    if (!getDecNumber(tokens[1], &dskno) || dskno < 0 || dskno > 1) {
789
      printf("illegal disk number\n");
790
      return;
791
    }
792
    boot(dskno);
793
  } else {
794
    help16();
795
  }
796
}
797
 
798
 
799
Command commands[] = {
800
  { "help", help00, doHelp       },
801
  { "+",    help01, doArith      },
802
  { "a",    help02, doAssemble   },
803
  { "u",    help03, doUnassemble },
804
  { "b",    help04, doBreak      },
805
  { "c",    help05, doContinue   },
806
  { "s",    help06, doStep       },
807
  { "#",    help07, doPC         },
808
  { "p",    help08, doPSW        },
809
  { "r",    help09, doRegister   },
810
  { "d",    help10, doDump       },
811
  { "mw",   help11, doMemoryWord },
812
  { "mh",   help12, doMemoryHalf },
813
  { "mb",   help13, doMemoryByte },
814
  { "t",    help14, doTLB        },
815
  { "load", help15, doLoad       },
816
  { "boot", help16, doBoot       },
817
};
818
 
819
int numCommands = sizeof(commands) / sizeof(commands[0]);
820
 
821
 
822
static void doCommand(char *line) {
823
  char *tokens[MAX_TOKENS];
824
  int n;
825
  char *p;
826
  int i;
827
 
828
  n = 0;
829
  p = strtok(line, " \t\n");
830
  while (p != NULL) {
831
    if (n == MAX_TOKENS) {
832
      printf("too many tokens on line\n");
833
      return;
834
    }
835
    tokens[n++] = p;
836
    p = strtok(NULL, " \t\n");
837
  }
838
  if (n == 0) {
839
    return;
840
  }
841
  for (i = 0; i < numCommands; i++) {
842
    if (strcmp(commands[i].name, tokens[0]) == 0) {
843
      (*commands[i].cmdProc)(tokens, n);
844
      return;
845
    }
846
  }
847
  help();
848
}
849
 
850
 
851
static char *article(char firstLetterOfNoun) {
852
  switch (firstLetterOfNoun) {
853
    case 'a':
854
    case 'e':
855
    case 'i':
856
    case 'o':
857
    case 'u':
858
      return "An";
859
    default:
860
      return "A";
861
  }
862
}
863
 
864
 
865
static void interactiveException(int exception) {
866
  char *what;
867
 
868
  what = exceptionToString(exception);
869
  printf("\n");
870
  printf("NOTE: %s %s occurred while executing the command.\n",
871
         article(*what), what);
872
  printf("      This event will not alter the state of the CPU.\n");
873
}
874
 
875
 
876
void execCommand(char *line) {
877
  MonitorState commandState;
878
 
879
  if (saveState(&commandState)) {
880
    /* initialization */
881
    monitorReturn = &commandState;
882
    doCommand(line);
883
  } else {
884
    /* an exception was thrown */
885
    interactiveException((userContext.psw & PSW_PRIO_MASK) >> 16);
886
  }
887
  monitorReturn = NULL;
888
}

powered by: WebSVN 2.1.0

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