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