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

Subversion Repositories eco32

[/] [eco32/] [tags/] [eco32-0.22/] [monitor/] [monitor/] [command.c] - Blame information for rev 138

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

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

powered by: WebSVN 2.1.0

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