Fix trap handling in PDP-11 CPU, change emu_pdp11 trace output to octal
authorNick Downing <nick@ndcode.org>
Mon, 12 Sep 2022 05:32:23 +0000 (15:32 +1000)
committerNick Downing <nick@ndcode.org>
Mon, 12 Sep 2022 08:29:50 +0000 (18:29 +1000)
emu_pdp11.c
simh

index 5b91393..958c056 100644 (file)
@@ -8,7 +8,9 @@
 #include "simh/PDP11/pdp11_defs.h"
 #include "simh/PDP11/pdp11_cpumod.h"
 #undef fprintf
-extern int32 R[8];             /* working registers */
+extern int32 REGFILE[6][2];    /* R0-R5, two sets */
+extern int32 STACKFILE[4];     /* SP, four modes */
+extern int32 saved_PC;         /* program counter */
 extern int32 PSW;              /* PSW */
 t_stat cpu_reset (DEVICE *dptr);
 #else
@@ -20,7 +22,7 @@ t_stat cpu_reset (DEVICE *dptr);
 #define REG_TRACE 1
 #define MEM_TRACE 1
 
-#define MEM_SIZE 0x8000
+#define MEM_SIZE 0x4000
 #if __BYTE_ORDER == __BIG_ENDIAN
 #define MEM_SIZE_M1 (MEM_SIZE - 1)
 #define MEM_SIZE_M2 (MEM_SIZE - 2)
@@ -94,7 +96,7 @@ int load_ihx(char *name) {
       checksum -= buf[len - 1];
       fprintf(
         stderr,
-        "checksum %02x, should be %02x\n",
+        "checksum %03o, should be %03o\n",
         checksum,
         buf[len - 1]
       );
@@ -182,7 +184,7 @@ int read_byte(void *context, int addr) {
     break;
   default:
     if (addr < 0 || addr >= MEM_SIZE) {
-      fprintf(stderr, "invalid read byte: %04x\n", addr);
+      fprintf(stderr, "invalid read byte: %06o\n", addr);
       data = 0xff;
     }
     else
@@ -190,7 +192,7 @@ int read_byte(void *context, int addr) {
     break;
   }
 #if MEM_TRACE
-  fprintf(stderr, "addr=%04x rd=%02x\n", addr, data);
+  fprintf(stderr, "addr=%06o rd=%03o\n", addr, data);
 #endif
   return data;
 }
@@ -198,7 +200,7 @@ int read_byte(void *context, int addr) {
 int read_word(void *context, int addr) {
   int data;
   if (addr < 0 || addr >= MEM_SIZE || (addr & 1)) {
-    fprintf(stderr, "invalid read word: %04x\n", addr);
+    fprintf(stderr, "invalid read word: %06o\n", addr);
     if (addr & 1)
       exit(EXIT_FAILURE);
     data = 0xffff;
@@ -206,14 +208,14 @@ int read_word(void *context, int addr) {
   else
     data = mem.w[(addr ^ MEM_SIZE_M2) >> 1];
 #if MEM_TRACE
-  fprintf(stderr, "addr=%04x rd=%04x\n", addr, data);
+  fprintf(stderr, "addr=%06o rd=%06o\n", addr, data);
 #endif
   return data;
 }
 
 void write_byte(void *context, int addr, int data) {
 #if MEM_TRACE
-  fprintf(stderr, "addr=%04x wr=%02x\n", addr, data);
+  fprintf(stderr, "addr=%06o wr=%03o\n", addr, data);
 #endif
   switch (addr) {
   case 0xf000:
@@ -233,7 +235,7 @@ void write_byte(void *context, int addr, int data) {
     break;
   default:
     if (addr < 0 || addr >= MEM_SIZE)
-      fprintf(stderr, "invalid write byte: %04x\n", addr);
+      fprintf(stderr, "invalid write byte: %06o\n", addr);
    else
       mem.b[addr ^ MEM_SIZE_M1] = data;
   }
@@ -241,10 +243,10 @@ void write_byte(void *context, int addr, int data) {
 
 void write_word(void *context, int addr, int data) {
 #if MEM_TRACE
-  fprintf(stderr, "addr=%04x wr=%04x\n", addr, data);
+  fprintf(stderr, "addr=%06o wr=%06o\n", addr, data);
 #endif
   if (addr < 0 || addr >= MEM_SIZE || (addr & 1)) {
-    fprintf(stderr, "invalid write word: %04x\n", addr);
+    fprintf(stderr, "invalid write word: %06o\n", addr);
     if (addr & 1)
       exit(EXIT_FAILURE);
   }
@@ -318,7 +320,7 @@ int main(int argc, char **argv) {
     printf("usage: %s image.ihx\n", argv[0]);
     exit(EXIT_FAILURE);
   }
-  load_ihx(argv[1]);
+  int entry_point = load_ihx(argv[1]);
 
 #if 0
   // emulate Tutor firmware for TBI68K
@@ -328,20 +330,21 @@ int main(int argc, char **argv) {
 
 #if ALT_BACKEND
   cpu_reset(NULL);
+  saved_PC = entry_point;
 
   while (true) {
 #if REG_TRACE
     fprintf(
       stderr,
-      "pc=%04x r0=%04x r1=%04x r2=%04x r3=%04x r4=%04x r5=%04x sp=%04x psw=%04x nf=%d zf=%d vf=%d cf=%d\n",
-      R[7],
-      R[0],
-      R[1],
-      R[2],
-      R[3],
-      R[4],
-      R[5],
-      R[6],
+      "pc=%06o r0=%06o r1=%06o r2=%06o r3=%06o r4=%06o r5=%06o sp=%06o psw=%06o nf=%d zf=%d vf=%d cf=%d\n",
+      saved_PC,
+      REGFILE[0][0],
+      REGFILE[1][0],
+      REGFILE[2][0],
+      REGFILE[3][0],
+      REGFILE[4][0],
+      REGFILE[5][0],
+      STACKFILE[MD_KER],
       PSW,
       (PSW >> PSW_V_N) & 1,
       (PSW >> PSW_V_Z) & 1,
@@ -361,7 +364,7 @@ int main(int argc, char **argv) {
 #if REG_TRACE
     fprintf(
       stderr,
-      "pc=%04x a=%02x b=%02x s=%04x x=%04x p=%02x hf=%d if=%d nf=%d zf=%d vf=%d cf=%d\n",
+      "pc=%06o a=%03o b=%03o s=%06o x=%06o p=%03o hf=%d if=%d nf=%d zf=%d vf=%d cf=%d\n",
       cpu.regs.word.pc,
       cpu.regs.byte.a,
       cpu.regs.byte.b,
diff --git a/simh b/simh
index 03da592..215378f 160000 (submodule)
--- a/simh
+++ b/simh
@@ -1 +1 @@
-Subproject commit 03da592c8e74d7815028dfe72ffbcff6b9416b85
+Subproject commit 215378fe6d6e3867a4869c0f56f93c1bb6d7ea1c