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