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