* support for the --sky-debug, sky-debug-file options
authorPatrick Macdonald <patrickm@redhat.com>
Tue, 16 Jun 1998 21:02:33 +0000 (21:02 +0000)
committerPatrick Macdonald <patrickm@redhat.com>
Tue, 16 Jun 1998 21:02:33 +0000 (21:02 +0000)
* support for the --log, --log-file options
* GIF disassembly
* please view ChangeLog.Sky for details

sim/mips/sky-pke.c
sim/mips/sky-pke.h

index 0e5e87949c9407083d3419ddf8217e5f01464ecb..b5c6644edbde14f480cdf97470a78a0b3dc57b8a 100644 (file)
@@ -77,27 +77,29 @@ void pke_fifo_old(struct pke_fifo*, unsigned_4 qwnum);
 
 struct pke_device pke0_device = 
 { 
-  { "pke0", &pke_io_read_buffer, &pke_io_write_buffer }, /* device */
+  { "vif0", &pke_io_read_buffer, &pke_io_write_buffer }, /* device */
   0, 0,        /* ID, flags */
   {},          /* regs */
-  {}, 0,      /* FIFO write buffer */
+  {}, 0,       /* FIFO write buffer */
   { NULL, 0, 0, 0 }, /* FIFO */
-  NULL,           /* FIFO trace file */
+  NULL, NULL,   /* FIFO trace file descriptor and name */
   -1, -1, 0, 0, 0, /* invalid FIFO cache */
-  0, 0            /* pc */
+  0, 0,        /* pc */
+  NULL, NULL   /* disassembly trace file descriptor and name  */
 };
 
 
 struct pke_device pke1_device = 
 { 
-  { "pke1", &pke_io_read_buffer, &pke_io_write_buffer }, /* device */
+  { "vif1", &pke_io_read_buffer, &pke_io_write_buffer }, /* device */
   1, 0,        /* ID, flags */
   {},          /* regs */
   {}, 0,       /* FIFO write buffer */
   { NULL, 0, 0, 0 }, /* FIFO */
-  NULL,           /* FIFO trace file */
+  NULL, NULL,  /* FIFO trace file descriptor and name  */
   -1, -1, 0, 0, 0, /* invalid FIFO cache */
-  0, 0         /* pc */
+  0, 0,        /* pc */
+  NULL, NULL   /* disassembly trace file descriptor and name  */
 };
 
 
@@ -178,23 +180,6 @@ pke_attach(SIM_DESC sd, struct pke_device* me)
                    0 /*modulo*/,
                    NULL,
                    NULL /*buffer*/);
-
-
-  /* attach to trace file if appropriate */
-  {
-    char trace_envvar[80];
-    char* trace_filename = NULL;
-    sprintf(trace_envvar, "VIF%d_TRACE_FILE", me->pke_number);
-    trace_filename = getenv(trace_envvar);
-    if(trace_filename != NULL)
-      {
-       me->fifo_trace_file = fopen(trace_filename, "w");
-       if(me->fifo_trace_file == NULL)
-           perror("VIF FIFO trace error on fopen");
-       else
-         setvbuf(me->fifo_trace_file, NULL, _IOLBF, 0);
-      }
-  }
 }
 
 
@@ -556,7 +541,13 @@ pke_reset(struct pke_device* me)
   /* clear registers, flag, other state */
   memset(me->regs, 0, sizeof(me->regs));
   me->fifo_qw_done = 0;
-  me->flags = 0;
+  if ( me->trace_file != NULL ) 
+    {
+      fclose (me->trace_file);
+      me->trace_file = NULL;
+    }
+  /* Command options will remain alive over the reset.  */
+  me->flags &= PKE_FLAG_TRACE_ON;
 }
 
 
@@ -901,24 +892,29 @@ pke_pc_advance(struct pke_device* me, int num_words)
          
          /* trace the consumption of the FIFO quadword we just skipped over */
          /* fq still points to it */
-         if(me->fifo_trace_file != NULL)
-           {
-             /* assert complete classification */
+         if ( indebug (me->dev.name)) 
+       {
+         if (( me->fifo_trace_file == NULL) &&
+             ( me->fifo_trace_file_name != NULL ))
+           sky_open_file (&me->fifo_trace_file, me->fifo_trace_file_name,
+                         (char *) NULL);
+
+         /* assert complete classification */
              ASSERT(fq->word_class[3] != wc_unknown);
              ASSERT(fq->word_class[2] != wc_unknown);
              ASSERT(fq->word_class[1] != wc_unknown);
              ASSERT(fq->word_class[0] != wc_unknown);
              
              /* print trace record */
-             fprintf(me->fifo_trace_file,
-                     "%d 0x%08x_%08x_%08x_%08x 0x%08x %c%c%c%c\n",
-                     (me->pke_number == 0 ? 0 : 1),
-                     (unsigned) fq->data[3], (unsigned) fq->data[2],
-                     (unsigned) fq->data[1], (unsigned) fq->data[0],
-                     (unsigned) fq->source_address,
-                     fq->word_class[3], fq->word_class[2],
-                     fq->word_class[1], fq->word_class[0]);
-           }
+         fprintf((me->fifo_trace_file != NULL) ? me->fifo_trace_file : stdout,
+                       "%d 0x%08x_%08x_%08x_%08x 0x%08x %c%c%c%c\n",
+                       (me->pke_number == 0 ? 0 : 1),
+                       (unsigned) fq->data[3], (unsigned) fq->data[2],
+                       (unsigned) fq->data[1], (unsigned) fq->data[0],
+                       (unsigned) fq->source_address,
+                       fq->word_class[3], fq->word_class[2],
+                       fq->word_class[1], fq->word_class[0]);
+       }
        } /* next quadword */
     }
 
@@ -2169,3 +2165,51 @@ pke_code_error(struct pke_device* me, unsigned_4 pkecode)
   /* advance over faulty word */
   pke_pc_advance(me, 1);
 }
+
+void
+pke_options(struct pke_device *me, unsigned_4 option, char *option_string)  
+{
+  switch (option) 
+    {
+    case PKE_OPT_DEBUG_NAME:
+      if ( me->fifo_trace_file != NULL ) 
+        {
+          fclose (me->fifo_trace_file);
+          me->fifo_trace_file = NULL;
+        }
+      sky_store_file_name (&me->fifo_trace_file_name, option_string);
+      break;
+
+    case PKE_OPT_TRACE_ON:
+      me->flags |= PKE_FLAG_TRACE_ON;
+      break;
+
+    case PKE_OPT_TRACE_OFF:
+    case PKE_OPT_TRACE_NAME:
+      if ( me->trace_file != NULL ) 
+        {
+          fclose (me->trace_file);
+          me->trace_file = NULL;
+        }
+      
+      if ( option == PKE_OPT_TRACE_OFF ) 
+        me->flags &= ~PKE_FLAG_TRACE_ON;
+      else
+        sky_store_file_name (&me->trace_file_name, option_string);
+      
+      break;
+   
+    case PKE_OPT_CLOSE:
+      if (me->trace_file != NULL) 
+        fclose (me->trace_file);
+      if (me->fifo_trace_file != NULL ) 
+        fclose (me->fifo_trace_file);
+      break;
+
+    default: 
+      ASSERT (0);
+      break;
+    }
+
+  return;
+}
index 9be4f2f2c18ffb86b61cd4af34671229a137b441..89634730b95dfd14486c32b5c8ff7063c4f355ed 100644 (file)
@@ -330,10 +330,11 @@ do { \
        BIT_MASK_SET(((me)->regs[PKE_REG_##reg][0]), \
                    PKE_REG_##reg##_##flag##_B, PKE_REG_##reg##_##flag##_E, \
                    (value)); \
-       if((me)->fifo_trace_file != NULL) \
+       if( indebug (me->dev.name)) \
         { \
-          if(old != (value)) \
-            fprintf((me)->fifo_trace_file, "# Reg %s:%s = 0x%x\n", #reg, #flag, (unsigned)(value)); \
+          if (old != (value)) \
+        fprintf(((me)->fifo_trace_file != NULL) ? (me)->fifo_trace_file : stdout, \
+                 "# Reg %s:%s = 0x%x\n", #reg, #flag, (unsigned)(value)); \
         } \
      } while(0)
 
@@ -402,6 +403,7 @@ struct pke_device
   /* FIFO - private: use only pke_fifo_* routines to access */
   struct pke_fifo fifo;  /* array of FIFO quadword pointers */
   FILE* fifo_trace_file; /* stdio stream open in append mode, or 0 for no trace */
+  char* fifo_trace_file_name; /* user defined debug trace file name  */
 
   /* FIFO cache -- curry last search pke_pcrel_fifo results */
   unsigned_4 last_fifo_pc;
@@ -413,6 +415,11 @@ struct pke_device
   /* PC */
   int fifo_pc;  /* 0 .. (fifo_num_elements-1): quadword index of next instruction */
   int qw_pc;    /* 0 .. 3:                     word index of next instruction */
+
+  /* Disassembly - file name and descriptor  */
+  FILE *trace_file;
+  char *trace_file_name;
+  
 };
 
 extern struct pke_device pke0_device;
@@ -429,7 +436,7 @@ int read_pke_pcx (struct pke_device *device, void *buf);
 #define PKE_FLAG_NONE        0x00
 #define PKE_FLAG_PENDING_PSS 0x01 /* PSS bit written-to; set STAT:PSS after current instruction */
 #define PKE_FLAG_INT_NOLOOP  0x02 /* INT PKEcode received; INT/PIS set; suppress loop after resumption */
-
+#define PKE_FLAG_TRACE_ON    0x04 /* Trace file request from command line  */                                      
 
 /* Kludge alert */
 
@@ -448,19 +455,30 @@ int read_pke_pcx (struct pke_device *device, void *buf);
          memcpy((void*) & value, (unsigned_##size*)(data), size); \
          sim_core_write_aligned_##size(cpu, CIA_GET(cpu), write_map, \
                                       (SIM_ADDR)(addr), value); \
-         if((me)->fifo_trace_file != NULL) \
+         if (indebug (me->dev.name)) \
           { \
             int i; \
             unsigned_##size value_te; \
             value_te = H2T_##size(value); \
-            fprintf((me)->fifo_trace_file, "# Write %2d bytes  to  ", size); \
-            fprintf((me)->fifo_trace_file, "0x%08lx: ", (unsigned long)(addr)); \
+            fprintf(((me)->fifo_trace_file != NULL) ? (me)->fifo_trace_file : stdout, \
+                 "# Write %2d bytes  to  ", size); \
+        fprintf(((me)->fifo_trace_file != NULL) ? (me)->fifo_trace_file : stdout, \
+                  "0x%08lx: ", (unsigned long)(addr)); \
             for(i=0; i<size; i++) \
-              fprintf((me)->fifo_trace_file, " %02x", ((unsigned_1*)(& value_te))[i]); \
-            fprintf((me)->fifo_trace_file, "\n"); \
+          fprintf(((me)->fifo_trace_file != NULL) ? (me)->fifo_trace_file : stdout, \
+                       " %02x", ((unsigned_1*)(& value_te))[i]); \
+          fprintf(((me)->fifo_trace_file != NULL) ? (me)->fifo_trace_file : stdout, \
+                       "\n"); \
           } \
         } while(0)      
 
 
+/* Disassembly file definitions  */
+void pke_options (struct pke_device *device, unsigned_4 option, char *option_string);
+#define PKE_OPT_DEBUG_NAME       1
+#define PKE_OPT_TRACE_ON         2
+#define PKE_OPT_TRACE_OFF        3
+#define PKE_OPT_TRACE_NAME       4
+#define PKE_OPT_CLOSE            5
 
 #endif /* H_PKE_H */