+static void v850ice_command (char *, int);
+
+static int ice_disassemble (unsigned long, int, char *);
+
+static int ice_lookup_addr (unsigned long *, char *, char *);
+
+static int ice_lookup_symbol (unsigned long, char *);
+
+static void ice_SimulateDisassemble (char *, int);
+
+static void ice_SimulateAddrLookup (char *, int);
+
+static void ice_Simulate_SymLookup (char *, int);
+
+static void ice_fputs (const char *, struct ui_file *);
+
+static int ice_file (char *);
+
+static int ice_cont (char *);
+
+static int ice_stepi (char *);
+
+static int ice_nexti (char *);
+
+static void togdb_force_update (void);
+
+static void view_source (CORE_ADDR);
+
+static void do_gdb (char *, char *, void (*func) (char *, int), int);
+
+
+/* Globals */
+static HWND hidden_hwnd; /* HWND for messages */
+
+long (__stdcall * ExeAppReq) (char *, long, char *, struct MessageIO *);
+
+long (__stdcall * RegisterClient) (HWND);
+
+long (__stdcall * UnregisterClient) (void);
+
+extern Tcl_Interp *gdbtk_interp;
+
+/* Globals local to this file only */
+static int ice_open = 0; /* Is ICE open? */
+
+static char *v850_CB_Result; /* special char array for saving 'callback' results */
+
+static int SimulateCallback; /* simulate a callback event */
+
+#define MAX_BLOCK_SIZE 64*1024 /* Cannot transfer memory in blocks bigger
+ than this */
+/* MDI/ICE Message IDs */
+#define GSINGLESTEP 0x200 /* single-step target */
+#define GRESUME 0x201 /* resume target */
+#define GREADREG 0x202 /* read a register */
+#define GWRITEREG 0x203 /* write a register */
+#define GWRITEBLOCK 0x204 /* write a block of memory */
+#define GREADBLOCK 0x205 /* read a block of memory */
+#define GSETBREAK 0x206 /* set a breakpoint */
+#define GREMOVEBREAK 0x207 /* remove a breakpoint */
+#define GHALT 0x208 /* ??? */
+#define GCHECKSTATUS 0x209 /* check status of ICE */
+#define GMDIREPLY 0x210 /* Reply for previous query - NOT USED */
+#define GDOWNLOAD 0x211 /* something for MDI */
+#define GCOMMAND 0x212 /* execute command in ice */
+#define GLOADFILENAME 0x213 /* retrieve load filename */
+#define GWRITEMEM 0x214 /* write word, half-word, or byte */
+
+/* GCHECKSTATUS return codes: */
+#define ICE_Idle 0x00
+#define ICE_Breakpoint 0x01 /* hit a breakpoint */
+#define ICE_Stepped 0x02 /* have stepped */
+#define ICE_Exception 0x03 /* have exception */
+#define ICE_Halted 0x04 /* hit a user halt */
+#define ICE_Exited 0x05 /* called exit */
+#define ICE_Terminated 0x06 /* user terminated */
+#define ICE_Running 0x07
+#define ICE_Unknown 0x99
+
+/* Windows messages */
+#define WM_STATE_CHANGE WM_USER+101
+#define WM_SYM_TO_ADDR WM_USER+102
+#define WM_ADDR_TO_SYM WM_USER+103
+#define WM_DISASSEMBLY WM_USER+104
+#define WM_SOURCE WM_USER+105
+
+/* STATE_CHANGE codes */
+#define STATE_CHANGE_REGS 1 /* Register(s) changed */
+#define STATE_CHANGE_LOAD 2 /* HW reset */
+#define STATE_CHANGE_RESET 3 /* Load new file */
+#define STATE_CHANGE_CONT 4 /* Run target */
+#define STATE_CHANGE_STOP 5 /* Stop target */
+#define STATE_CHANGE_STEPI 6 /* Stepi target */
+#define STATE_CHANGE_NEXTI 7 /* Nexti target */
+
+static struct target_ops v850ice_ops; /* Forward decl */
+
+/* This function creates a hidden window */
+static int
+init_hidden_window (void)
+{
+ WNDCLASS class;
+
+ if (hidden_hwnd != NULL)
+ return 1;
+
+ class.style = 0;
+ class.cbClsExtra = 0;
+ class.cbWndExtra = 0;
+ class.hInstance = GetModuleHandle (0);
+ class.hbrBackground = NULL;
+ class.lpszMenuName = NULL;
+ class.lpszClassName = "gdb_v850ice";
+ class.lpfnWndProc = v850ice_wndproc;
+ class.hIcon = NULL;
+ class.hCursor = NULL;
+
+ if (!RegisterClass (&class))
+ return 0;
+
+ hidden_hwnd = CreateWindow ("gdb_v850ice", "gdb_v850ice", WS_TILED,
+ 0, 0, 0, 0, NULL, NULL, class.hInstance,
+ NULL);
+ if (hidden_hwnd == NULL)
+ {
+ char buf[200];
+ DWORD err;
+
+ err = GetLastError ();
+ FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
+ 0, buf, 200, NULL);
+ printf_unfiltered ("Could not create window: %s", buf);
+ return 0;
+ }
+
+ return 1;
+}
+
+/*
+ This function is installed as the message handler for the hidden window
+ which QBox will use to communicate with gdb. It recognize and acts
+ on the following messages:
+
+ WM_SYM_TO_ADDR \
+ WM_ADDR_TO_SYM | Not implemented at NEC's request
+ WM_DISASSEMBLY /
+ WM_STATE_CHANGE - tells us that a state change has occured in the ICE
+ */
+static LRESULT CALLBACK
+v850ice_wndproc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)