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

Subversion Repositories eco32

[/] [eco32/] [trunk/] [sim/] [command.c] - Blame information for rev 296

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

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

powered by: WebSVN 2.1.0

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