Thu May 21 13:14:25 1998 John Metzler <jmetzler@cygnus.com>
[deliverable/binutils-gdb.git] / gdb / v850ice.c
index d3e1b194b444abb1abfff77f2c9aa037842b5c20..5e0ca677026f2e2b0ea21ac9e6241078a223fa27 100755 (executable)
@@ -35,6 +35,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
 #include "gdb-stabs.h"
 #include "gdbthread.h"
 #endif
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h> 
 
 /* Prototypes for local functions */
 
@@ -71,11 +73,24 @@ static int v850ice_remove_breakpoint PARAMS ((CORE_ADDR, char *));
 
 static int ice_open = 0;
 
+static struct target_ops v850ice_ops ; 
+
 #ifndef EXPORT
 #define EXPORT __declspec(dllexport)
 #endif
 
-EXPORT long __stdcall ExeAppReq (char *, long, char *, char *);
+struct MessageIO
+{
+  int size;                    /* length of input or output in bytes */
+  char *buf;                   /* buffer having the input/output information */
+};
+
+struct MessageIO null_iob = { 0, NULL };
+
+EXPORT long __stdcall ExeAppReq (char *, long, char *, struct MessageIO *);
+EXPORT long __stdcall RegisterClient (HWND);
+EXPORT long __stdcall UnregisterClient (void);
+EXPORT long __stdcall GdbCallBack (void);
 
 #define        MREADREG          0x0001
 #define        MWRITEREG         0x0002
@@ -125,7 +140,19 @@ EXPORT long __stdcall ExeAppReq (char *, long, char *, char *);
 #define        MRCCMD            0x002E
 #define        MDOWNLOAD         0x0050
 
-extern struct target_ops v850ice_ops;  /* Forward decl */
+#define StatRunning    0
+#define StatExecBreak  1   /* an execution breakpoint has been reached */
+#define StatStepped    2   /* a single step has been completed */
+#define StatException  3   /* the target has stopped due to an exception */
+#define StatHalted     4   /* target has been halted by a user request */
+#define StatExited      5   /* target called exit */
+#define StatTerminated  6   /* target program terminated by a user request */
+#define StatNoProcess   7   /* no process on target and none of the above */
+#define StatNeedInput   8   /* REV: obsolete */
+#define StatNeedDirCmd  9   /* waiting for an entry in the remote window */
+#define StatHardBreak  10  /* hit hardware breakpoint */
+#define StatFailure    11  /* an error occured in the last run/single */
+
 
 /*   "pir", "tkcw", "chcw", "adtre" */
 
@@ -137,7 +164,6 @@ v850ice_open (name, from_tty)
      int from_tty;
 {
   long retval;
-  char retmsg[1000];
 
   if (name)
     error ("Too many arguments.");
@@ -166,12 +192,21 @@ v850ice_open (name, from_tty)
      In particular, if the user quits, be sure to discard it
      (we'd be in an inconsistent state otherwise).  */
 
-  retval = ExeAppReq ("GDB", MINITEXEC, "0", retmsg);
-  ice_open = 1;
+  WinExec ("necsrv", SW_SHOW); /* Start up necsrv */
 
-  start_remote ();
+  retval = RegisterClient (NULL);
+
+  if (retval == 0)
+    {
+      ice_open = 1;
 
-/*  pop_target();*/
+      start_remote ();
+      return;
+    }
+
+  pop_target();
+
+  error ("v850ice_open: MINITEXEC return error: 0x%x", retval);
 }
 
 /* Clean up connection to a remote debugger.  */
@@ -185,10 +220,13 @@ v850ice_close (quitting)
 
   if (ice_open)
     {
-      retval = ExeAppReq ("GDB", MEXITEXEC, NULL, NULL);
+#if 0
+      retval = ExeAppReq ("GDB", MEXITEXEC, NULL, &null_iob);
       if (retval)
        error ("ExeAppReq (MEXITEXEC) returned %d", retval);
+#endif
       ice_open = 0;
+      UnregisterClient ();
     }
 }
 
@@ -213,16 +251,14 @@ v850ice_resume (pid, step, siggnal)
      enum target_signal siggnal;
 {
   long retval;
-  char cmd[100];
-  char val[100];
 
   if (step)
-    retval = ExeAppReq ("GDB", MSINGLESTEP, "step", val);
+    retval = ExeAppReq ("GDB", MSINGLESTEP, "step", &null_iob);
   else
-    retval = ExeAppReq ("GDB", MRESUME, "run", val);
+    retval = ExeAppReq ("GDB", MRESUME, "run", &null_iob);
 
   if (retval)
-    error ("ExeAppReq (step = %d) returned %d: cmd = %s", step, retval, cmd);
+    error ("ExeAppReq (step = %d) returned %d", step, retval);
 }
 
 /* Wait until the remote machine stops, then return,
@@ -235,6 +271,10 @@ v850ice_wait (pid, status)
      int pid;
      struct target_waitstatus *status;
 {
+  long v850_status;
+
+  v850_status = ExeAppReq ("GDB", MCHECKSTATUS, NULL, &null_iob);
+
   status->kind = TARGET_WAITKIND_STOPPED;
   status->value.sig = TARGET_SIGNAL_TRAP;
 
@@ -269,6 +309,7 @@ v850ice_fetch_registers (regno)
   long retval;
   char cmd[100];
   char val[100];
+  struct MessageIO iob;
   unsigned long regval;
   char *p;
 
@@ -283,7 +324,9 @@ v850ice_fetch_registers (regno)
   if (!convert_register (regno, &cmd[4]))
     return;
 
-  retval = ExeAppReq ("GDB", MREADREG, cmd, val);
+  iob.size = sizeof val;
+  iob.buf = val;
+  retval = ExeAppReq ("GDB", MREADREG, cmd, &iob);
   if (retval)
     error ("ExeAppReq returned %d: cmd = %s", retval, cmd);
 
@@ -305,7 +348,6 @@ v850ice_store_registers (regno)
 {
   long retval;
   char cmd[100];
-  char val[100];
   unsigned long regval;
 
   if (regno == -1)
@@ -322,7 +364,7 @@ v850ice_store_registers (regno)
     return;
   sprintf (cmd + strlen (cmd), "=0x%x", regval);
 
-  retval = ExeAppReq ("GDB", MWRITEREG, cmd, val);
+  retval = ExeAppReq ("GDB", MWRITEREG, cmd, &null_iob);
   if (retval)
     error ("ExeAppReq returned %d: cmd = %s", retval, cmd);
 }
@@ -350,15 +392,19 @@ v850ice_xfer_memory (memaddr, myaddr, len, should_write, target)
 {
   long retval;
   char cmd[100];
+  struct MessageIO iob;
+
+  iob.size = len;
+  iob.buf = myaddr;
 
   if (should_write)
     {
 #if 1
       sprintf (cmd, "memory b c 0x%x=0x00 l=%d", (int)memaddr, len);
-      retval = ExeAppReq ("GDB", MWRITEBLOCK, cmd, myaddr);
+      retval = ExeAppReq ("GDB", MWRITEBLOCK, cmd, &iob);
 #else
       sprintf (cmd, "memory b c 0x%x=0x%x", (int)memaddr, *myaddr & 0xff);
-      retval = ExeAppReq ("GDB", MWRITEBLOCK, cmd, myaddr);
+      retval = ExeAppReq ("GDB", MWRITEBLOCK, cmd, &iob);
       return 1;
 #endif
     }
@@ -370,9 +416,13 @@ v850ice_xfer_memory (memaddr, myaddr, len, should_write, target)
       tmp = alloca (len + 100);
       memset (tmp + len, 0xff, 100);
       
+#if 1
       sprintf (cmd, "memory b 0x%x l=%d", (int)memaddr, len);
-      retval = ExeAppReq ("GDB", MREADBLOCK, cmd, tmp);
-
+      retval = ExeAppReq ("GDB", MREADBLOCK, cmd, &iob);
+#else
+      sprintf (cmd, "memory h 0x%x", (int)memaddr);
+      retval = ExeAppReq ("GDB", MREADMEM, cmd, &iob);
+#endif
       for (i = 0; i <  100; i++)
        {
          if (tmp[len + i] != 0xff)
@@ -404,14 +454,13 @@ v850ice_insert_breakpoint (addr, contents_cache)
 {
   long retval;
   char cmd[100];
-  char val[100];
 
   sprintf (cmd, "%d, ", addr);
 
 #if 1
-  retval = ExeAppReq ("GDB", MSETBREAK, cmd, val);
+  retval = ExeAppReq ("GDB", MSETBREAK, cmd, &null_iob);
 #else
-  retval = ExeAppReq ("GDB", MSETHARDBRK, cmd, val);
+  retval = ExeAppReq ("GDB", MSETHARDBRK, cmd, &null_iob);
 #endif
   if (retval)
     error ("ExeAppReq (MSETBREAK) returned %d: cmd = %s", retval, cmd);
@@ -426,14 +475,13 @@ v850ice_remove_breakpoint (addr, contents_cache)
 {
   long retval;
   char cmd[100];
-  char val[100];
 
   sprintf (cmd, "%d, ", addr);
 
 #if 1
-  retval = ExeAppReq ("GDB", MREMOVEBREAK, cmd, val);
+  retval = ExeAppReq ("GDB", MREMOVEBREAK, cmd, &null_iob);
 #else
-  retval = ExeAppReq ("GDB", MREMOVEHARDBRK, cmd, val);
+  retval = ExeAppReq ("GDB", MREMOVEHARDBRK, cmd, &null_iob);
 #endif
   if (retval)
     error ("ExeAppReq (MREMOVEBREAK) returned %d: cmd = %s", retval, cmd);
@@ -454,51 +502,54 @@ v850ice_mourn ()
 
 /* Define the target subroutine names */
 
-struct target_ops v850ice_ops = {
-  "ice",                       /* to_shortname */
-  "NEC V850 ICE interface",    /* to_longname */
-  "Debug a system controlled by a NEC 850 ICE.", /* to_doc */
-  v850ice_open,                        /* to_open */
-  v850ice_close,               /* to_close */
-  NULL,                                /* to_attach */
-  v850ice_detach,              /* to_detach */
-  v850ice_resume,              /* to_resume */
-  v850ice_wait,                        /* to_wait */
-  v850ice_fetch_registers,     /* to_fetch_registers */
-  v850ice_store_registers,     /* to_store_registers */
-  v850ice_prepare_to_store,    /* to_prepare_to_store */
-  v850ice_xfer_memory,         /* to_xfer_memory */
-  v850ice_files_info,          /* to_files_info */
-  v850ice_insert_breakpoint,   /* to_insert_breakpoint */
-  v850ice_remove_breakpoint,   /* to_remove_breakpoint */
-  NULL,                                /* to_terminal_init */
-  NULL,                                /* to_terminal_inferior */
-  NULL,                                /* to_terminal_ours_for_output */
-  NULL,                                /* to_terminal_ours */
-  NULL,                                /* to_terminal_info */
-  v850ice_kill,                        /* to_kill */
-  generic_load,                        /* to_load */
-  NULL,                                /* to_lookup_symbol */
-  NULL,                                /* to_create_inferior */
-  v850ice_mourn,               /* to_mourn_inferior */
-  0,                           /* to_can_run */
-  0,                           /* to_notice_signals */
-  NULL,                                /* to_thread_alive */
-  0,                           /* to_stop */
-  process_stratum,             /* to_stratum */
-  NULL,                                /* to_next */
-  1,                           /* to_has_all_memory */
-  1,                           /* to_has_memory */
-  1,                           /* to_has_stack */
-  1,                           /* to_has_registers */
-  1,                           /* to_has_execution */
-  NULL,                                /* sections */
-  NULL,                                /* sections_end */
-  OPS_MAGIC                    /* to_magic */
-};
+
+static void init_850ice_ops(void)
+{
+  v850ice_ops.to_shortname   =   "ice";                
+  v850ice_ops.to_longname    =   "NEC V850 ICE interface";
+  v850ice_ops.to_doc         =   "Debug a system controlled by a NEC 850 ICE.";
+  v850ice_ops.to_open        =   v850ice_open;         
+  v850ice_ops.to_close       =   v850ice_close;        
+  v850ice_ops.to_attach      =   NULL;         
+  v850ice_ops.to_detach      =   v850ice_detach;       
+  v850ice_ops.to_resume      =   v850ice_resume;       
+  v850ice_ops.to_wait        =   v850ice_wait; 
+  v850ice_ops.to_fetch_registers  =   v850ice_fetch_registers;
+  v850ice_ops.to_store_registers  =   v850ice_store_registers;
+  v850ice_ops.to_prepare_to_store =   v850ice_prepare_to_store;
+  v850ice_ops.to_xfer_memory =   v850ice_xfer_memory;  
+  v850ice_ops.to_files_info  =   v850ice_files_info;   
+  v850ice_ops.to_insert_breakpoint =   v850ice_insert_breakpoint;
+  v850ice_ops.to_remove_breakpoint =   v850ice_remove_breakpoint;
+  v850ice_ops.to_terminal_init    =   NULL;            
+  v850ice_ops.to_terminal_inferior =   NULL;           
+  v850ice_ops.to_terminal_ours_for_output =   NULL;    
+  v850ice_ops.to_terminal_ours   =   NULL;             
+  v850ice_ops.to_terminal_info   =   NULL;             
+  v850ice_ops.to_kill            =   v850ice_kill;             
+  v850ice_ops.to_load            =   generic_load;             
+  v850ice_ops.to_lookup_symbol   =   NULL;             
+  v850ice_ops.to_create_inferior =   NULL;             
+  v850ice_ops.to_mourn_inferior  =   v850ice_mourn;
+  v850ice_ops.to_can_run         =   0;                
+  v850ice_ops.to_notice_signals  =   0;                
+  v850ice_ops.to_thread_alive    =    NULL;    
+  v850ice_ops.to_stop            =   0;                        
+  v850ice_ops.to_stratum         =   process_stratum;  
+  v850ice_ops.DONT_USE           =   NULL;             
+  v850ice_ops.to_has_all_memory  =   1;                
+  v850ice_ops.to_has_memory      =   1;                
+  v850ice_ops.to_has_stack       =   1;                
+  v850ice_ops.to_has_registers   =   1;                
+  v850ice_ops.to_has_execution   =   1;                
+  v850ice_ops.to_sections        =   NULL;             
+  v850ice_ops.to_sections_end    =   NULL;             
+  v850ice_ops.to_magic           =   OPS_MAGIC ;
+}
 
 void
 _initialize_v850ice ()
 {
+  init_850ice_ops() ;
   add_target (&v850ice_ops);
 }
This page took 0.026977 seconds and 4 git commands to generate.