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