hp merge changes -- too numerous to mention here; see ChangeLog and
[deliverable/binutils-gdb.git] / gdb / v850ice.c
CommitLineData
6c310da8
SG
1/* ICE interface for the NEC V850 for GDB, the GNU debugger.
2 Copyright 1996, Free Software Foundation, Inc.
3
4This file is part of GDB.
5
6This program is free software; you can redistribute it and/or modify
4ef1f467 7it under the terms of the GNU General Public License as published by
6c310da8
SG
8the Free Software Foundation; either version 2 of the License, or
9(at your option) any later version.
10
11This program is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with this program; if not, write to the Free Software
18Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
19
20#include "defs.h"
21#include "gdb_string.h"
6c310da8 22#include "frame.h"
e3ca310c 23#include "symtab.h"
6c310da8 24#include "inferior.h"
e3ca310c 25#include "breakpoint.h"
6c310da8
SG
26#include "symfile.h"
27#include "target.h"
6c310da8 28#include "objfiles.h"
e3ca310c
KS
29#include "gdbcore.h"
30#include "value.h"
31#include "command.h"
32
33#include <tcl.h>
34#include <tk.h>
35#include <windows.h>
36#include <winuser.h> /* for WM_USER */
37
38extern unsigned long int strtoul(const char *nptr, char **endptr,
39 int base);
40
41/* Local data definitions */
42struct MessageIO
43{
44 int size; /* length of input or output in bytes */
45 char * buf; /* buffer having the input/output information */
46};
47
48/* Prototypes for functions located in other files */
49extern void break_command PARAMS ((char *, int));
50
51extern void stepi_command PARAMS ((char *, int));
52
53extern void nexti_command PARAMS ((char *, int));
54
55extern void continue_command PARAMS ((char *, int));
56
57extern HINSTANCE Tk_GetHINSTANCE PARAMS ((void));
6c310da8 58
4ce8d0e9
KS
59extern void (*ui_loop_hook) PARAMS ((int));
60
6c310da8 61/* Prototypes for local functions */
e3ca310c
KS
62static int init_hidden_window PARAMS ((void));
63
64static LRESULT CALLBACK v850ice_wndproc PARAMS ((HWND, UINT, WPARAM, LPARAM));
6c310da8
SG
65
66static void v850ice_files_info PARAMS ((struct target_ops *ignore));
67
68static int v850ice_xfer_memory PARAMS ((CORE_ADDR memaddr, char *myaddr,
69 int len, int should_write,
70 struct target_ops *target));
71
72static void v850ice_prepare_to_store PARAMS ((void));
73
74static void v850ice_fetch_registers PARAMS ((int regno));
75
76static void v850ice_resume PARAMS ((int pid, int step,
77 enum target_signal siggnal));
78
79static void v850ice_open PARAMS ((char *name, int from_tty));
80
81static void v850ice_close PARAMS ((int quitting));
82
67205639
KS
83static void v850ice_stop PARAMS ((void));
84
6c310da8
SG
85static void v850ice_store_registers PARAMS ((int regno));
86
87static void v850ice_mourn PARAMS ((void));
88
89static int v850ice_wait PARAMS ((int pid, struct target_waitstatus *status));
90
91static void v850ice_kill PARAMS ((void));
92
93static void v850ice_detach PARAMS ((char *args, int from_tty));
94
95static int v850ice_insert_breakpoint PARAMS ((CORE_ADDR, char *));
96
97static int v850ice_remove_breakpoint PARAMS ((CORE_ADDR, char *));
98
e3ca310c 99static void v850ice_command PARAMS ((char *, int));
6c310da8 100
e3ca310c 101static int ice_disassemble PARAMS ((unsigned long, int, char *));
c719b714 102
e3ca310c 103static int ice_lookup_addr PARAMS ((unsigned long *, char *, char *));
6c310da8 104
e3ca310c
KS
105static int ice_lookup_symbol PARAMS ((unsigned long, char *));
106
107static void ice_SimulateDisassemble PARAMS ((char *, int));
108
109static void ice_SimulateAddrLookup PARAMS ((char *, int));
110
111static void ice_Simulate_SymLookup PARAMS ((char *, int));
112
113static void ice_fputs PARAMS ((const char *, GDB_FILE *));
114
115static int ice_file PARAMS ((char *));
116
117static int ice_cont PARAMS ((char *));
118
119static int ice_stepi PARAMS ((char *));
120
121static int ice_nexti PARAMS ((char *));
122
123static void togdb_force_update PARAMS ((void));
124
4ce8d0e9
KS
125static void view_source PARAMS ((CORE_ADDR));
126
badb1b51
KS
127static void do_gdb (char *, char *, int);
128
129
e3ca310c
KS
130/* Globals */
131static HWND hidden_hwnd; /* HWND for messages */
132
133long (__stdcall *ExeAppReq) PARAMS ((char *, long, char *, struct MessageIO *));
134
135long (__stdcall *RegisterClient) PARAMS ((HWND));
136
137long (__stdcall *UnregisterClient) PARAMS ((void));
138
139extern Tcl_Interp *gdbtk_interp;
140
141/* Globals local to this file only */
142static int ice_open = 0; /* Is ICE open? */
143
144static char * v850_CB_Result; /* special char array for saving 'callback' results */
145
146static int SimulateCallback; /* simulate a callback event */
147
148#define MAX_BLOCK_SIZE 64*1024 /* Cannot transfer memory in blocks bigger
149 than this */
150/* MDI/ICE Message IDs */
151#define GSINGLESTEP 0x200 /* single-step target */
152#define GRESUME 0x201 /* resume target */
153#define GREADREG 0x202 /* read a register */
154#define GWRITEREG 0x203 /* write a register */
155#define GWRITEBLOCK 0x204 /* write a block of memory */
156#define GREADBLOCK 0x205 /* read a block of memory */
157#define GSETBREAK 0x206 /* set a breakpoint */
158#define GREMOVEBREAK 0x207 /* remove a breakpoint */
159#define GHALT 0x208 /* ??? */
160#define GCHECKSTATUS 0x209 /* check status of ICE */
161#define GMDIREPLY 0x210 /* Reply for previous query - NOT USED */
162#define GDOWNLOAD 0x211 /* something for MDI */
163#define GCOMMAND 0x212 /* execute command in ice */
164#define GLOADFILENAME 0x213 /* retrieve load filename */
165#define GWRITEMEM 0x214 /* write word, half-word, or byte */
166
167/* GCHECKSTATUS return codes: */
168#define ICE_Idle 0x00
169#define ICE_Breakpoint 0x01 /* hit a breakpoint */
170#define ICE_Stepped 0x02 /* have stepped */
171#define ICE_Exception 0x03 /* have exception */
172#define ICE_Halted 0x04 /* hit a user halt */
173#define ICE_Exited 0x05 /* called exit */
174#define ICE_Terminated 0x06 /* user terminated */
175#define ICE_Running 0x07
176#define ICE_Unknown 0x99
177
178/* Windows messages */
179#define WM_STATE_CHANGE WM_USER+101
180#define WM_SYM_TO_ADDR WM_USER+102
181#define WM_ADDR_TO_SYM WM_USER+103
182#define WM_DISASSEMBLY WM_USER+104
4ce8d0e9 183#define WM_SOURCE WM_USER+105
e3ca310c
KS
184
185/* STATE_CHANGE codes */
186#define STATE_CHANGE_REGS 1 /* Register(s) changed */
187#define STATE_CHANGE_LOAD 2 /* HW reset */
188#define STATE_CHANGE_RESET 3 /* Load new file */
189#define STATE_CHANGE_CONT 4 /* Run target */
190#define STATE_CHANGE_STOP 5 /* Stop target */
191#define STATE_CHANGE_STEPI 6 /* Stepi target */
192#define STATE_CHANGE_NEXTI 7 /* Nexti target */
193
194static struct target_ops v850ice_ops; /* Forward decl */
195
196/* This function creates a hidden window */
197static int
198init_hidden_window ()
264b9de0 199{
e3ca310c
KS
200 WNDCLASS class;
201
202 if (hidden_hwnd != NULL)
203 return TCL_OK;
204
205 class.style = 0;
206 class.cbClsExtra = 0;
207 class.cbWndExtra = 0;
208 class.hInstance = Tk_GetHINSTANCE();
209 class.hbrBackground = NULL;
210 class.lpszMenuName = NULL;
211 class.lpszClassName = "gdbtk_v850ice";
212 class.lpfnWndProc = v850ice_wndproc;
213 class.hIcon = NULL;
214 class.hCursor = NULL;
215
216 if (! RegisterClass (&class))
217 return TCL_ERROR;
218
219 hidden_hwnd = CreateWindow ("gdbtk_v850ice", "gdbtk_v850ice", WS_TILED,
220 0, 0, 0, 0, NULL, NULL, class.hInstance,
221 NULL);
222 if (hidden_hwnd == NULL)
223 {
224 char buf[200];
225 DWORD err;
226
227 err = GetLastError ();
228 FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
229 0, buf, 200, NULL);
230 printf_unfiltered ("Could not create window: %s", buf);
231 return TCL_ERROR;
232 }
233
234 return TCL_OK;
235}
236
237/*
238 This function is installed as the message handler for the hidden window
239 which QBox will use to communicate with gdbtk. It recognize and acts
240 on the following messages:
241
242 WM_SYM_TO_ADDR \
243 WM_ADDR_TO_SYM | Not implemented at NEC's request
244 WM_DISASSEMBLY /
245 WM_STATE_CHANGE - tells us that a state change has occured in the ICE
246*/
247static LRESULT CALLBACK
248v850ice_wndproc (hwnd, message, wParam, lParam)
249 HWND hwnd;
250 UINT message;
251 WPARAM wParam;
252 LPARAM lParam;
253{
254 LRESULT result = FALSE;
255
256 switch (message)
257 {
258 case WM_SYM_TO_ADDR:
259 MessageBox (0, "Symbol resolution\nNot implemented", "GDB", MB_OK);
260 break;
261 case WM_ADDR_TO_SYM:
262 MessageBox (0, "Address resolution\nNot implemented", "GDB", MB_OK);
263 break;
4ce8d0e9
KS
264 case WM_SOURCE:
265 view_source ((CORE_ADDR) lParam);
266 break;
e3ca310c
KS
267 case WM_STATE_CHANGE:
268 switch (wParam)
269 {
270 case STATE_CHANGE_LOAD:
271 {
272 struct MessageIO iob;
273 char buf[128];
274
275 iob.buf = buf;
276 iob.size = 128;
277
278 /* Load in a new file... Need filename */
279 ExeAppReq ("GDB", GLOADFILENAME, NULL, &iob);
280 if (!catch_errors (ice_file, iob.buf, "", RETURN_MASK_ALL))
281 printf_unfiltered ("load errored\n");
282 }
283 break;
284 case STATE_CHANGE_RESET:
285 registers_changed ();
286 flush_cached_frames ();
287 togdb_force_update ();
288 result = TRUE;
289 break;
290 case STATE_CHANGE_REGS:
291 registers_changed ();
292 togdb_force_update ();
293 result = TRUE;
294 break;
295 case STATE_CHANGE_CONT:
296 if (!catch_errors (ice_cont, NULL, "", RETURN_MASK_ALL))
297 printf_unfiltered ("continue errored\n");
298 result = TRUE;
299 break;
300 case STATE_CHANGE_STEPI:
301 if (!catch_errors (ice_stepi, (PTR)(int) lParam, "",
302 RETURN_MASK_ALL))
303 printf_unfiltered ("stepi errored\n");
304 result = TRUE;
305 break;
306 case STATE_CHANGE_NEXTI:
307 if (!catch_errors (ice_nexti, (PTR)(int) lParam, "",
308 RETURN_MASK_ALL))
309 printf_unfiltered ("nexti errored\n");
310 result = TRUE;
311 break;
312 }
313 }
264b9de0 314
e3ca310c
KS
315 if (result == FALSE)
316 return DefWindowProc (hwnd, message, wParam, lParam);
317
318 return FALSE;
319}
6c310da8
SG
320
321/* Code for opening a connection to the ICE. */
322
323static void
324v850ice_open (name, from_tty)
325 char *name;
326 int from_tty;
327{
e3ca310c 328 HINSTANCE handle;
6c310da8
SG
329
330 if (name)
331 error ("Too many arguments.");
332
333 target_preopen (from_tty);
334
335 unpush_target (&v850ice_ops);
336
337 if (from_tty)
338 puts_filtered ("V850ice debugging\n");
339
340 push_target (&v850ice_ops); /* Switch to using v850ice target now */
341
342 target_terminal_init ();
343
e3ca310c
KS
344 /* Initialize everything necessary to facilitate communication
345 between QBox, gdbtk, and the DLLs which control the ICE */
346 if (ExeAppReq == NULL)
347 {
348 handle = LoadLibrary ("necmsg.dll");
349 if (handle == NULL)
350 error ("Cannot load necmsg.dll");
351
352 ExeAppReq = (long (*) PARAMS ((char *, long, char *, struct MessageIO *)))
353 GetProcAddress (handle, "ExeAppReq");
354 RegisterClient = (long (*) PARAMS ((HWND)))
355 GetProcAddress (handle, "RegisterClient");
356 UnregisterClient = (long (*) PARAMS ((void)))
357 GetProcAddress (handle, "UnregisterClient");
358
359 if (ExeAppReq == NULL || RegisterClient == NULL || UnregisterClient == NULL)
360 error ("Could not find requisite functions in necmsg.dll.");
361
362 if (init_hidden_window () != TCL_OK)
363 error ("could not initialize message handling");
364 }
365
366 /* Tell the DLL we are here */
367 RegisterClient (hidden_hwnd);
368
369 ice_open = 1;
370
6c310da8
SG
371 /* Without this, some commands which require an active target (such as kill)
372 won't work. This variable serves (at least) double duty as both the pid
373 of the target process (if it has such), and as a flag indicating that a
374 target is active. These functions should be split out into seperate
375 variables, especially since GDB will someday have a notion of debugging
376 several processes. */
6c310da8
SG
377 inferior_pid = 42000;
378
e3ca310c
KS
379 start_remote ();
380 return;
6c310da8
SG
381}
382
383/* Clean up connection to a remote debugger. */
384
385/* ARGSUSED */
386static void
387v850ice_close (quitting)
388 int quitting;
389{
6c310da8
SG
390 if (ice_open)
391 {
264b9de0 392 UnregisterClient ();
e3ca310c
KS
393 ice_open = 0;
394 inferior_pid = 0;
6c310da8
SG
395 }
396}
397
67205639
KS
398/* Stop the process on the ice. */
399static void
400v850ice_stop ()
401{
402 /* This is silly, but it works... */
403 v850ice_command ("stop", 0);
404}
405
6c310da8
SG
406static void
407v850ice_detach (args, from_tty)
408 char *args;
409 int from_tty;
410{
411 if (args)
412 error ("Argument given to \"detach\" when remotely debugging.");
413
414 pop_target ();
415 if (from_tty)
416 puts_filtered ("Ending v850ice debugging.\n");
417}
418
419/* Tell the remote machine to resume. */
420
421static void
422v850ice_resume (pid, step, siggnal)
423 int pid, step;
424 enum target_signal siggnal;
425{
e3ca310c
KS
426 long retval;
427 char buf[256];
428 struct MessageIO iob;
429
430 iob.size = 0;
431 iob.buf = buf;
6c310da8
SG
432
433 if (step)
e3ca310c 434 retval = ExeAppReq ("GDB", GSINGLESTEP, "step", &iob);
6c310da8 435 else
e3ca310c 436 retval = ExeAppReq ("GDB", GRESUME, "run", &iob);
6c310da8
SG
437
438 if (retval)
264b9de0 439 error ("ExeAppReq (step = %d) returned %d", step, retval);
6c310da8
SG
440}
441
442/* Wait until the remote machine stops, then return,
443 storing status in STATUS just as `wait' would.
444 Returns "pid" (though it's not clear what, if anything, that
445 means in the case of this target). */
446
447static int
448v850ice_wait (pid, status)
449 int pid;
450 struct target_waitstatus *status;
451{
264b9de0 452 long v850_status;
e3ca310c
KS
453 char buf[256];
454 struct MessageIO iob;
455 int done = 0;
4ce8d0e9
KS
456 int count = 0;
457
e3ca310c
KS
458 iob.size = 0;
459 iob.buf = buf;
460
461 do
462 {
4ce8d0e9
KS
463 if (count++ % 100000)
464 {
465 ui_loop_hook (-2);
466 count = 0;
467 }
468
e3ca310c
KS
469 v850_status = ExeAppReq ("GDB", GCHECKSTATUS, NULL, &iob);
470
471 switch (v850_status)
472 {
473 case ICE_Idle:
474 case ICE_Breakpoint:
475 case ICE_Stepped:
476 case ICE_Halted:
477 status->kind = TARGET_WAITKIND_STOPPED;
478 status->value.sig = TARGET_SIGNAL_TRAP;
479 done = 1;
480 break;
481 case ICE_Exception:
482 status->kind = TARGET_WAITKIND_SIGNALLED;
483 status->value.sig = TARGET_SIGNAL_SEGV;
484 done = 1;
485 break;
486 case ICE_Exited:
487 status->kind = TARGET_WAITKIND_EXITED;
488 status->value.integer = 0;
489 done = 1;
490 break;
491 case ICE_Terminated:
492 status->kind = TARGET_WAITKIND_SIGNALLED;
493 status->value.sig = TARGET_SIGNAL_KILL;
494 done = 1;
495 break;
496 default:
497 break;
498 }
499 }
500 while (!done);
501
6c310da8
SG
502 return inferior_pid;
503}
504
505static int
506convert_register (regno, buf)
507 int regno;
508 char *buf;
509{
510 if (regno <= 31)
511 sprintf (buf, "r%d", regno);
d70a61e7
AC
512 else if (REGISTER_NAME (regno)[0] == 's'
513 && REGISTER_NAME (regno)[1] == 'r')
6c310da8
SG
514 return 0;
515 else
d70a61e7 516 sprintf (buf, "%s", REGISTER_NAME (regno));
6c310da8
SG
517
518 return 1;
519}
520
521/* Read the remote registers into the block REGS. */
522/* Note that the ICE returns register contents as ascii hex strings. We have
523 to convert that to an unsigned long, and then call store_unsigned_integer to
524 convert it to target byte-order if necessary. */
525
526static void
527v850ice_fetch_registers (regno)
528 int regno;
529{
530 long retval;
531 char cmd[100];
532 char val[100];
264b9de0 533 struct MessageIO iob;
6c310da8
SG
534 unsigned long regval;
535 char *p;
536
537 if (regno == -1)
538 {
539 for (regno = 0; regno < NUM_REGS; regno++)
e3ca310c 540 v850ice_fetch_registers (regno);
6c310da8
SG
541 return;
542 }
543
544 strcpy (cmd, "reg ");
545 if (!convert_register (regno, &cmd[4]))
546 return;
547
264b9de0
SG
548 iob.size = sizeof val;
549 iob.buf = val;
e3ca310c 550 retval = ExeAppReq ("GDB", GREADREG, cmd, &iob);
6c310da8 551 if (retval)
e3ca310c 552 error ("1: ExeAppReq returned %d: cmd = %s", retval, cmd);
6c310da8 553
e3ca310c 554 regval = strtoul (val, NULL, 16);
6c310da8
SG
555 if (regval == 0 && p == val)
556 error ("v850ice_fetch_registers (%d): bad value from ICE: %s.",
e3ca310c 557 regno, val);
6c310da8
SG
558
559 store_unsigned_integer (val, REGISTER_RAW_SIZE (regno), regval);
560 supply_register (regno, val);
561}
562
563/* Store register REGNO, or all registers if REGNO == -1, from the contents
564 of REGISTERS. */
565
566static void
567v850ice_store_registers (regno)
568 int regno;
569{
570 long retval;
571 char cmd[100];
6c310da8 572 unsigned long regval;
e3ca310c
KS
573 char buf[256];
574 struct MessageIO iob;
575 iob.size = 0;
576 iob.buf = buf;
6c310da8
SG
577
578 if (regno == -1)
579 {
580 for (regno = 0; regno < NUM_REGS; regno++)
581 v850ice_store_registers (regno);
582 return;
583 }
584
585 regval = extract_unsigned_integer (&registers[REGISTER_BYTE (regno)],
e3ca310c 586 REGISTER_RAW_SIZE (regno));
6c310da8
SG
587 strcpy (cmd, "reg ");
588 if (!convert_register (regno, &cmd[4]))
589 return;
590 sprintf (cmd + strlen (cmd), "=0x%x", regval);
591
e3ca310c 592 retval = ExeAppReq ("GDB", GWRITEREG, cmd, &iob);
6c310da8 593 if (retval)
e3ca310c 594 error ("2: ExeAppReq returned %d: cmd = %s", retval, cmd);
6c310da8
SG
595}
596
597/* Prepare to store registers. Nothing to do here, since the ICE can write one
598 register at a time. */
599
600static void
601v850ice_prepare_to_store ()
602{
603}
604
605/* Read or write LEN bytes from inferior memory at MEMADDR, transferring
606 to or from debugger address MYADDR. Write to inferior if SHOULD_WRITE is
e3ca310c 607 nonzero. Returns length of data written or read; 0 for error.
6c310da8 608
e3ca310c
KS
609 We can only read/write MAX_BLOCK_SIZE bytes at a time, though, or the DLL
610 dies */
6c310da8
SG
611/* ARGSUSED */
612static int
613v850ice_xfer_memory (memaddr, myaddr, len, should_write, target)
614 CORE_ADDR memaddr;
615 char *myaddr;
616 int len;
617 int should_write;
618 struct target_ops *target; /* ignored */
619{
620 long retval;
621 char cmd[100];
264b9de0 622 struct MessageIO iob;
e3ca310c 623 int sent;
6c310da8
SG
624
625 if (should_write)
626 {
e3ca310c
KS
627 if (len == 4 || len == 2 || len == 1)
628 {
629 long value = 0;
630 char buf[256];
631 char c;
632
633 iob.size = 0;
634 iob.buf = buf;
635
636 sent = 0;
637 switch (len)
638 {
639 case 4:
640 c = 'w';
641 value |= (long) (myaddr[3] << 24) & 0xff000000;
642 value |= (long) (myaddr[2] << 16) & 0x00ff0000;
643 value |= (long) (myaddr[1] << 8) & 0x0000ff00;
644 value |= (long) myaddr[0] & 0x000000ff;
645 case 2:
646 c = 'h';
647 value |= (long) myaddr[1] << 8 & 0xff00;
648 value |= (long) myaddr[0] & 0x00ff;
649 break;
650 case 1:
651 c = 'b';
652 value |= (long) myaddr[0] & 0xff;
653 break;
654 }
655
656 sprintf (cmd, "memory %c c 0x%x=0x%x", c, (int) memaddr, value);
657 retval = ExeAppReq ("GDB", GWRITEMEM, cmd, &iob);
658 if (retval == 0)
659 sent = len;
660 }
661 else
662 {
663 sent = 0;
664 do
665 {
666 iob.size = len > MAX_BLOCK_SIZE ? MAX_BLOCK_SIZE : len;
667 iob.buf = myaddr;
668 sprintf (cmd, "memory b c 0x%x=0x00 l=%d", (int)memaddr, iob.size);
669 retval = ExeAppReq ("GDB", GWRITEBLOCK, cmd, &iob);
670 if (retval != 0)
671 break;
672 len -= iob.size;
673 memaddr += iob.size;
674 myaddr += iob.size;
675 sent += iob.size;
676 }
677 while (len > 0);
678 }
6c310da8
SG
679 }
680 else
681 {
682 unsigned char *tmp;
e3ca310c 683 unsigned char *t;
6c310da8 684 int i;
e3ca310c 685
6c310da8 686 tmp = alloca (len + 100);
e3ca310c 687 t = tmp;
6c310da8 688 memset (tmp + len, 0xff, 100);
6c310da8 689
e3ca310c
KS
690 sent = 0;
691 do
692 {
693 iob.size = len > MAX_BLOCK_SIZE ? MAX_BLOCK_SIZE : len;
694 iob.buf = tmp;
695 sprintf (cmd, "memory b 0x%x l=%d", (int)memaddr, iob.size);
696 retval = ExeAppReq ("GDB", GREADBLOCK, cmd, &iob);
697 if (retval != 0)
698 break;
699 len -= iob.size;
700 memaddr += iob.size;
701 sent += iob.size;
702 tmp += iob.size;
703 }
704 while (len > 0);
705
706 if (retval == 0)
707 {
708 for (i = 0; i < 100; i++)
709 {
710 if (t[sent + i] != 0xff)
711 {
712 warning ("GREADBLOCK trashed bytes after transfer area.");
713 break;
714 }
715 }
716 memcpy (myaddr, t, sent);
717 }
718 }
719
720 if (retval != 0)
721 error ("3: ExeAppReq returned %d: cmd = %s", retval, cmd);
722
723 return sent;
6c310da8
SG
724}
725
726static void
727v850ice_files_info (ignore)
728 struct target_ops *ignore;
729{
730 puts_filtered ("Debugging a target via the NEC V850 ICE.\n");
731}
732
733static int
734v850ice_insert_breakpoint (addr, contents_cache)
735 CORE_ADDR addr;
736 char *contents_cache;
737{
738 long retval;
739 char cmd[100];
e3ca310c
KS
740 char buf[256];
741 struct MessageIO iob;
6c310da8 742
e3ca310c
KS
743 iob.size = 0;
744 iob.buf = buf;
6c310da8
SG
745 sprintf (cmd, "%d, ", addr);
746
e3ca310c 747 retval = ExeAppReq ("GDB", GSETBREAK, cmd, &iob);
6c310da8 748 if (retval)
e3ca310c 749 error ("ExeAppReq (GSETBREAK) returned %d: cmd = %s", retval, cmd);
6c310da8
SG
750
751 return 0;
752}
753
754static int
755v850ice_remove_breakpoint (addr, contents_cache)
756 CORE_ADDR addr;
757 char *contents_cache;
758{
759 long retval;
760 char cmd[100];
e3ca310c
KS
761 char buf[256];
762 struct MessageIO iob;
763
764 iob.size = 0;
765 iob.buf = buf;
6c310da8
SG
766
767 sprintf (cmd, "%d, ", addr);
768
e3ca310c 769 retval = ExeAppReq ("GDB", GREMOVEBREAK, cmd, &iob);
6c310da8 770 if (retval)
e3ca310c 771 error ("ExeAppReq (GREMOVEBREAK) returned %d: cmd = %s", retval, cmd);
6c310da8
SG
772
773 return 0;
774}
775
776static void
777v850ice_kill ()
778{
779 target_mourn_inferior ();
e3ca310c 780 inferior_pid = 0;
6c310da8
SG
781}
782
783static void
784v850ice_mourn ()
785{
786}
787
e3ca310c
KS
788static void
789v850ice_load (filename, from_tty)
790 char * filename;
791 int from_tty;
792{
793 struct MessageIO iob;
794 char buf[256];
795
796 iob.size = 0;
797 iob.buf = buf;
798 generic_load(filename, from_tty);
67205639 799 ExeAppReq ("GDB", GDOWNLOAD, filename, &iob);
e3ca310c
KS
800}
801
802static int
803ice_file (arg)
804 char *arg;
805{
806 char *s;
807
808 target_detach (NULL, 0);
809 pop_target ();
810
811 printf_unfiltered ("\n");
812
813 s = arg;
814 while (*s != '\0')
815 {
816 if (*s == '\\')
817 *s = '/';
818 s++;
819 }
820
821 /* Safegaurd against confusing the breakpoint routines... */
822 delete_command(NULL, 0);
823
824 /* Must supress from_tty, otherwise we could start asking if the
825 user really wants to load a new symbol table, etc... */
826 printf_unfiltered ("Reading symbols from %s...", arg);
827 exec_file_command (arg, 0);
828 symbol_file_command (arg, 0);
829 printf_unfiltered ("done\n");
830
831 /* exec_file_command will kill our target, so reinstall the ICE as
832 the target. */
833 v850ice_open (NULL, 0);
6c310da8 834
e3ca310c
KS
835 togdb_force_update ();
836 return 1;
837}
838
839static int
840ice_cont (c)
841 char *c;
842{
67205639 843 printf_filtered ("continue (ice)");
4ce8d0e9 844 ReplyMessage ((LRESULT) 1);
67205639 845 Tcl_Eval (gdbtk_interp, "gdb_immediate continue");
e3ca310c
KS
846 return 1;
847}
848
badb1b51
KS
849static void
850do_gdb (cmd, str, count)
851 char *cmd;
852 char *str;
853 int count;
854{
855
856 ReplyMessage ((LRESULT) 1);
857
858 while (count--)
859 {
860 printf_unfiltered (str);
861 Tcl_Eval (gdbtk_interp, cmd);
862 }
863}
864
865
e3ca310c
KS
866static int
867ice_stepi (c)
868 char *c;
869{
e3ca310c
KS
870 int count = (int) c;
871
badb1b51 872 do_gdb ("gdb_immediate stepi", "stepi (ice)\n", count);
e3ca310c
KS
873 return 1;
874}
875
876static int
877ice_nexti (c)
878 char *c;
879{
e3ca310c
KS
880 int count = (int) c;
881
badb1b51 882 do_gdb ("gdb_immediate nexti", "nexti (ice)\n", count);
e3ca310c
KS
883 return 1;
884}
885
886static void
887v850ice_command (arg, from_tty)
888 char *arg;
889 int from_tty;
890{
891 struct MessageIO iob;
892 char buf[256];
893
894 iob.buf = buf;
895 iob.size = 0;
896 ExeAppReq ("GDB", GCOMMAND, arg, &iob);
897}
898
899static void
900togdb_force_update (void)
901{
902 Tcl_Eval (gdbtk_interp, "gdbtk_update");
903}
904
4ce8d0e9
KS
905static void
906view_source (addr)
907 CORE_ADDR addr;
908{
909 char c[256];
910
badb1b51 911 sprintf (c, "set src [lindex [manage find src] 0]\n$src location BROWSE [gdb_loc *0x%x]", addr);
4ce8d0e9
KS
912 Tcl_Eval (gdbtk_interp, c);
913}
914
e3ca310c 915/* Define the target subroutine names */
c719b714
JM
916
917static void init_850ice_ops(void)
918{
919 v850ice_ops.to_shortname = "ice";
920 v850ice_ops.to_longname = "NEC V850 ICE interface";
921 v850ice_ops.to_doc = "Debug a system controlled by a NEC 850 ICE.";
922 v850ice_ops.to_open = v850ice_open;
923 v850ice_ops.to_close = v850ice_close;
4ef1f467
DT
924 v850ice_ops.to_attach = NULL;
925 v850ice_ops.to_post_attach = NULL;
926 v850ice_ops.to_require_attach = NULL;
927 v850ice_ops.to_detach = v850ice_detach;
928 v850ice_ops.to_require_detach = NULL;
c719b714 929 v850ice_ops.to_resume = v850ice_resume;
4ef1f467
DT
930 v850ice_ops.to_wait = v850ice_wait;
931 v850ice_ops.to_post_wait = NULL;
c719b714
JM
932 v850ice_ops.to_fetch_registers = v850ice_fetch_registers;
933 v850ice_ops.to_store_registers = v850ice_store_registers;
934 v850ice_ops.to_prepare_to_store = v850ice_prepare_to_store;
935 v850ice_ops.to_xfer_memory = v850ice_xfer_memory;
936 v850ice_ops.to_files_info = v850ice_files_info;
937 v850ice_ops.to_insert_breakpoint = v850ice_insert_breakpoint;
938 v850ice_ops.to_remove_breakpoint = v850ice_remove_breakpoint;
939 v850ice_ops.to_terminal_init = NULL;
940 v850ice_ops.to_terminal_inferior = NULL;
941 v850ice_ops.to_terminal_ours_for_output = NULL;
942 v850ice_ops.to_terminal_ours = NULL;
943 v850ice_ops.to_terminal_info = NULL;
944 v850ice_ops.to_kill = v850ice_kill;
e3ca310c 945 v850ice_ops.to_load = v850ice_load;
c719b714 946 v850ice_ops.to_lookup_symbol = NULL;
4ef1f467 947 v850ice_ops.to_create_inferior = NULL;
c719b714
JM
948 v850ice_ops.to_mourn_inferior = v850ice_mourn;
949 v850ice_ops.to_can_run = 0;
950 v850ice_ops.to_notice_signals = 0;
951 v850ice_ops.to_thread_alive = NULL;
67205639 952 v850ice_ops.to_stop = v850ice_stop;
4ef1f467
DT
953 v850ice_ops.to_pid_to_exec_file = NULL;
954 v850ice_ops.to_core_file_to_sym_file = NULL;
c719b714
JM
955 v850ice_ops.to_stratum = process_stratum;
956 v850ice_ops.DONT_USE = NULL;
957 v850ice_ops.to_has_all_memory = 1;
958 v850ice_ops.to_has_memory = 1;
959 v850ice_ops.to_has_stack = 1;
960 v850ice_ops.to_has_registers = 1;
961 v850ice_ops.to_has_execution = 1;
962 v850ice_ops.to_sections = NULL;
963 v850ice_ops.to_sections_end = NULL;
964 v850ice_ops.to_magic = OPS_MAGIC ;
965}
6c310da8
SG
966
967void
968_initialize_v850ice ()
969{
e3ca310c 970 init_850ice_ops ();
6c310da8 971 add_target (&v850ice_ops);
e3ca310c
KS
972
973 add_com ("ice", class_obscure, v850ice_command,
974 "Send command to ICE");
6c310da8 975}
This page took 0.167388 seconds and 4 git commands to generate.