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

Subversion Repositories eco32

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

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

powered by: WebSVN 2.1.0

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