Eliminate global address_size. Replace with function
[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 */
a14ed312 49extern void break_command (char *, int);
6027a0b8 50
a14ed312 51extern void stepi_command (char *, int);
6027a0b8 52
a14ed312 53extern void nexti_command (char *, int);
6027a0b8 54
a14ed312 55extern void continue_command (char *, int);
6027a0b8 56
507f3c78 57extern int (*ui_loop_hook) (int);
6027a0b8
JM
58
59/* Prototypes for local functions */
a14ed312 60static int init_hidden_window (void);
6027a0b8 61
a14ed312 62static LRESULT CALLBACK v850ice_wndproc (HWND, UINT, WPARAM, LPARAM);
6027a0b8 63
a14ed312 64static void v850ice_files_info (struct target_ops *ignore);
6027a0b8 65
a14ed312
KB
66static int v850ice_xfer_memory (CORE_ADDR memaddr, char *myaddr,
67 int len, int should_write,
68 struct target_ops *target);
6027a0b8 69
a14ed312 70static void v850ice_prepare_to_store (void);
6027a0b8 71
a14ed312 72static void v850ice_fetch_registers (int regno);
6027a0b8 73
a14ed312 74static void v850ice_resume (int pid, int step, enum target_signal siggnal);
6027a0b8 75
a14ed312 76static void v850ice_open (char *name, int from_tty);
6027a0b8 77
a14ed312 78static void v850ice_close (int quitting);
6027a0b8 79
a14ed312 80static void v850ice_stop (void);
6027a0b8 81
a14ed312 82static void v850ice_store_registers (int regno);
6027a0b8 83
a14ed312 84static void v850ice_mourn (void);
6027a0b8 85
a14ed312 86static int v850ice_wait (int pid, struct target_waitstatus *status);
6027a0b8 87
a14ed312 88static void v850ice_kill (void);
6027a0b8 89
a14ed312 90static void v850ice_detach (char *args, int from_tty);
6027a0b8 91
a14ed312 92static int v850ice_insert_breakpoint (CORE_ADDR, char *);
6027a0b8 93
a14ed312 94static int v850ice_remove_breakpoint (CORE_ADDR, char *);
6027a0b8 95
a14ed312 96static void v850ice_command (char *, int);
6027a0b8 97
a14ed312 98static int ice_disassemble (unsigned long, int, char *);
6027a0b8 99
a14ed312 100static int ice_lookup_addr (unsigned long *, char *, char *);
6027a0b8 101
a14ed312 102static int ice_lookup_symbol (unsigned long, char *);
6027a0b8 103
a14ed312 104static void ice_SimulateDisassemble (char *, int);
6027a0b8 105
a14ed312 106static void ice_SimulateAddrLookup (char *, int);
6027a0b8 107
a14ed312 108static void ice_Simulate_SymLookup (char *, int);
6027a0b8 109
d9fcf2fb 110static void ice_fputs (const char *, struct ui_file *);
6027a0b8 111
a14ed312 112static int ice_file (char *);
6027a0b8 113
a14ed312 114static int ice_cont (char *);
6027a0b8 115
a14ed312 116static int ice_stepi (char *);
6027a0b8 117
a14ed312 118static int ice_nexti (char *);
6027a0b8 119
a14ed312 120static void togdb_force_update (void);
6027a0b8 121
a14ed312 122static void view_source (CORE_ADDR);
3fc11d3e 123
ac1d1083 124static void do_gdb (char *, char *, void (*func) (char *, int), int);
6027a0b8
JM
125
126
127/* Globals */
c5aa993b 128static HWND hidden_hwnd; /* HWND for messages */
6027a0b8 129
ac1d1083 130long (__stdcall * ExeAppReq) (char *, long, char *, struct MessageIO *);
6027a0b8 131
ac1d1083 132long (__stdcall * RegisterClient) (HWND);
6027a0b8 133
ac1d1083 134long (__stdcall * UnregisterClient) (void);
6027a0b8 135
3fc11d3e 136extern Tcl_Interp *gdbtk_interp;
6027a0b8
JM
137
138/* Globals local to this file only */
c5aa993b 139static int ice_open = 0; /* Is ICE open? */
6027a0b8 140
c5aa993b 141static char *v850_CB_Result; /* special char array for saving 'callback' results */
6027a0b8 142
c5aa993b 143static int SimulateCallback; /* simulate a callback event */
6027a0b8 144
c5aa993b
JM
145#define MAX_BLOCK_SIZE 64*1024 /* Cannot transfer memory in blocks bigger
146 than this */
6027a0b8 147/* MDI/ICE Message IDs */
c5aa993b
JM
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 */
6027a0b8
JM
163
164/* GCHECKSTATUS return codes: */
165#define ICE_Idle 0x00
c5aa993b
JM
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 */
6027a0b8
JM
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
180#define WM_SOURCE WM_USER+105
181
182/* STATE_CHANGE codes */
c5aa993b
JM
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 */
6027a0b8
JM
190
191static struct target_ops v850ice_ops; /* Forward decl */
192
193/* This function creates a hidden window */
194static int
195init_hidden_window ()
196{
197 WNDCLASS class;
198
199 if (hidden_hwnd != NULL)
200 return 1;
201
202 class.style = 0;
203 class.cbClsExtra = 0;
204 class.cbWndExtra = 0;
205 class.hInstance = GetModuleHandle (0);
206 class.hbrBackground = NULL;
207 class.lpszMenuName = NULL;
208 class.lpszClassName = "gdb_v850ice";
209 class.lpfnWndProc = v850ice_wndproc;
210 class.hIcon = NULL;
211 class.hCursor = NULL;
212
c5aa993b 213 if (!RegisterClass (&class))
6027a0b8
JM
214 return 0;
215
216 hidden_hwnd = CreateWindow ("gdb_v850ice", "gdb_v850ice", WS_TILED,
c5aa993b
JM
217 0, 0, 0, 0, NULL, NULL, class.hInstance,
218 NULL);
6027a0b8
JM
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,
c5aa993b 226 0, buf, 200, NULL);
6027a0b8
JM
227 printf_unfiltered ("Could not create window: %s", buf);
228 return 0;
229 }
230
231 return 1;
232}
233
234/*
235 This function is installed as the message handler for the hidden window
236 which QBox will use to communicate with gdb. 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
c5aa993b 243 */
6027a0b8
JM
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;
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
321v850ice_open (name, from_tty)
322 char *name;
323 int from_tty;
324{
325 HINSTANCE handle;
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
341 /* Initialize everything necessary to facilitate communication
342 between QBox, gdb, and the DLLs which control the ICE */
343 if (ExeAppReq == NULL)
344 {
345 handle = LoadLibrary ("necmsg.dll");
346 if (handle == NULL)
c5aa993b 347 error ("Cannot load necmsg.dll");
6027a0b8 348
ac1d1083 349 ExeAppReq = (long (*) (char *, long, char *, struct MessageIO *))
c5aa993b 350 GetProcAddress (handle, "ExeAppReq");
ac1d1083 351 RegisterClient = (long (*) (HWND))
c5aa993b 352 GetProcAddress (handle, "RegisterClient");
ac1d1083 353 UnregisterClient = (long (*) (void))
c5aa993b 354 GetProcAddress (handle, "UnregisterClient");
6027a0b8
JM
355
356 if (ExeAppReq == NULL || RegisterClient == NULL || UnregisterClient == NULL)
c5aa993b 357 error ("Could not find requisite functions in necmsg.dll.");
6027a0b8
JM
358
359 if (!init_hidden_window ())
c5aa993b 360 error ("could not initialize message handling");
6027a0b8
JM
361 }
362
363 /* Tell the DLL we are here */
364 RegisterClient (hidden_hwnd);
365
366 ice_open = 1;
367
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. */
374 inferior_pid = 42000;
375
376 start_remote ();
377 return;
378}
379
380/* Clean up connection to a remote debugger. */
381
382/* ARGSUSED */
383static void
384v850ice_close (quitting)
385 int quitting;
386{
387 if (ice_open)
388 {
389 UnregisterClient ();
390 ice_open = 0;
391 inferior_pid = 0;
392 }
393}
394
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
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{
c5aa993b
JM
423 long retval;
424 char buf[256];
425 struct MessageIO iob;
6027a0b8
JM
426
427 iob.size = 0;
c5aa993b 428 iob.buf = buf;
6027a0b8
JM
429
430 if (step)
431 retval = ExeAppReq ("GDB", GSINGLESTEP, "step", &iob);
432 else
433 retval = ExeAppReq ("GDB", GRESUME, "run", &iob);
434
435 if (retval)
436 error ("ExeAppReq (step = %d) returned %d", step, retval);
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{
449 long v850_status;
450 char buf[256];
c5aa993b 451 struct MessageIO iob;
6027a0b8
JM
452 int done = 0;
453 int count = 0;
454
455 iob.size = 0;
c5aa993b
JM
456 iob.buf = buf;
457
6027a0b8
JM
458 do
459 {
460 if (count++ % 100000)
c5aa993b
JM
461 {
462 ui_loop_hook (0);
6027a0b8 463 count = 0;
c5aa993b 464 }
6027a0b8
JM
465
466 v850_status = ExeAppReq ("GDB", GCHECKSTATUS, NULL, &iob);
467
468 switch (v850_status)
c5aa993b
JM
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 }
6027a0b8
JM
496 }
497 while (!done);
c5aa993b 498
6027a0b8
JM
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 (REGISTER_NAME (regno)[0] == 's'
510 && REGISTER_NAME (regno)[1] == 'r')
511 return 0;
512 else
513 sprintf (buf, "%s", REGISTER_NAME (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];
530 struct MessageIO iob;
531 unsigned long regval;
532 char *p;
533
534 if (regno == -1)
535 {
536 for (regno = 0; regno < NUM_REGS; regno++)
c5aa993b 537 v850ice_fetch_registers (regno);
6027a0b8
JM
538 return;
539 }
540
541 strcpy (cmd, "reg ");
542 if (!convert_register (regno, &cmd[4]))
543 return;
544
545 iob.size = sizeof val;
546 iob.buf = val;
547 retval = ExeAppReq ("GDB", GREADREG, cmd, &iob);
548 if (retval)
549 error ("1: ExeAppReq returned %d: cmd = %s", retval, cmd);
550
551 regval = strtoul (val, NULL, 16);
552 if (regval == 0 && p == val)
553 error ("v850ice_fetch_registers (%d): bad value from ICE: %s.",
c5aa993b 554 regno, val);
6027a0b8
JM
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];
569 unsigned long regval;
570 char buf[256];
571 struct MessageIO iob;
572 iob.size = 0;
573 iob.buf = buf;
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)],
c5aa993b 583 REGISTER_RAW_SIZE (regno));
6027a0b8
JM
584 strcpy (cmd, "reg ");
585 if (!convert_register (regno, &cmd[4]))
586 return;
587 sprintf (cmd + strlen (cmd), "=0x%x", regval);
588
589 retval = ExeAppReq ("GDB", GWRITEREG, cmd, &iob);
590 if (retval)
591 error ("2: ExeAppReq returned %d: cmd = %s", retval, cmd);
592}
593
594/* Prepare to store registers. Nothing to do here, since the ICE can write one
595 register at a time. */
596
c5aa993b 597static void
6027a0b8
JM
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
604 nonzero. Returns length of data written or read; 0 for error.
605
606 We can only read/write MAX_BLOCK_SIZE bytes at a time, though, or the DLL
607 dies */
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;
c5aa993b 615 struct target_ops *target; /* ignored */
6027a0b8
JM
616{
617 long retval;
618 char cmd[100];
619 struct MessageIO iob;
620 int sent;
621
622 if (should_write)
623 {
624 if (len == 4 || len == 2 || len == 1)
c5aa993b
JM
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 break;
643 case 2:
644 c = 'h';
645 value |= (long) ((myaddr[1] << 8) & 0xff00);
646 value |= (long) (myaddr[0] & 0x00ff);
6027a0b8 647 break;
c5aa993b
JM
648 case 1:
649 c = 'b';
650 value |= (long) (myaddr[0] & 0xff);
651 break;
652 }
653
654 sprintf (cmd, "memory %c c 0x%x=0x%x", c, (int) memaddr, value);
655 retval = ExeAppReq ("GDB", GWRITEMEM, cmd, &iob);
656 if (retval == 0)
657 sent = len;
658 }
659 else
660 {
661 sent = 0;
662 do
663 {
664 iob.size = len > MAX_BLOCK_SIZE ? MAX_BLOCK_SIZE : len;
665 iob.buf = myaddr;
666 sprintf (cmd, "memory b c 0x%x=0x00 l=%d", (int) memaddr, iob.size);
667 retval = ExeAppReq ("GDB", GWRITEBLOCK, cmd, &iob);
668 if (retval != 0)
669 break;
670 len -= iob.size;
671 memaddr += iob.size;
672 myaddr += iob.size;
673 sent += iob.size;
674 }
675 while (len > 0);
676 }
6027a0b8
JM
677 }
678 else
679 {
680 unsigned char *tmp;
681 unsigned char *t;
682 int i;
c5aa993b 683
6027a0b8
JM
684 tmp = alloca (len + 100);
685 t = tmp;
686 memset (tmp + len, 0xff, 100);
687
688 sent = 0;
689 do
c5aa993b
JM
690 {
691 iob.size = len > MAX_BLOCK_SIZE ? MAX_BLOCK_SIZE : len;
692 iob.buf = tmp;
693 sprintf (cmd, "memory b 0x%x l=%d", (int) memaddr, iob.size);
694 retval = ExeAppReq ("GDB", GREADBLOCK, cmd, &iob);
695 if (retval != 0)
696 break;
697 len -= iob.size;
698 memaddr += iob.size;
699 sent += iob.size;
700 tmp += iob.size;
701 }
6027a0b8
JM
702 while (len > 0);
703
704 if (retval == 0)
c5aa993b
JM
705 {
706 for (i = 0; i < 100; i++)
707 {
708 if (t[sent + i] != 0xff)
709 {
710 warning ("GREADBLOCK trashed bytes after transfer area.");
711 break;
712 }
713 }
714 memcpy (myaddr, t, sent);
715 }
6027a0b8 716 }
c5aa993b 717
6027a0b8
JM
718 if (retval != 0)
719 error ("3: ExeAppReq returned %d: cmd = %s", retval, cmd);
c5aa993b 720
6027a0b8
JM
721 return sent;
722}
723
724static void
725v850ice_files_info (ignore)
726 struct target_ops *ignore;
727{
728 puts_filtered ("Debugging a target via the NEC V850 ICE.\n");
729}
730
731static int
732v850ice_insert_breakpoint (addr, contents_cache)
733 CORE_ADDR addr;
734 char *contents_cache;
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 sprintf (cmd, "%d, ", addr);
744
745 retval = ExeAppReq ("GDB", GSETBREAK, cmd, &iob);
746 if (retval)
747 error ("ExeAppReq (GSETBREAK) returned %d: cmd = %s", retval, cmd);
748
749 return 0;
750}
751
752static int
753v850ice_remove_breakpoint (addr, contents_cache)
754 CORE_ADDR addr;
755 char *contents_cache;
756{
757 long retval;
758 char cmd[100];
759 char buf[256];
760 struct MessageIO iob;
761
762 iob.size = 0;
c5aa993b 763 iob.buf = buf;
6027a0b8
JM
764
765 sprintf (cmd, "%d, ", addr);
766
767 retval = ExeAppReq ("GDB", GREMOVEBREAK, cmd, &iob);
768 if (retval)
769 error ("ExeAppReq (GREMOVEBREAK) returned %d: cmd = %s", retval, cmd);
770
771 return 0;
772}
773
774static void
775v850ice_kill ()
776{
777 target_mourn_inferior ();
778 inferior_pid = 0;
779}
780
781static void
782v850ice_mourn ()
783{
784}
785
786static void
787v850ice_load (filename, from_tty)
c5aa993b
JM
788 char *filename;
789 int from_tty;
6027a0b8
JM
790{
791 struct MessageIO iob;
792 char buf[256];
793
794 iob.size = 0;
c5aa993b
JM
795 iob.buf = buf;
796 generic_load (filename, from_tty);
6027a0b8
JM
797 ExeAppReq ("GDB", GDOWNLOAD, filename, &iob);
798}
799
800static int
801ice_file (arg)
802 char *arg;
803{
804 char *s;
c5aa993b 805
6027a0b8
JM
806 target_detach (NULL, 0);
807 pop_target ();
808
809 printf_unfiltered ("\n");
810
811 s = arg;
812 while (*s != '\0')
813 {
814 if (*s == '\\')
c5aa993b 815 *s = '/';
6027a0b8
JM
816 s++;
817 }
818
819 /* Safegaurd against confusing the breakpoint routines... */
c5aa993b 820 delete_command (NULL, 0);
6027a0b8
JM
821
822 /* Must supress from_tty, otherwise we could start asking if the
823 user really wants to load a new symbol table, etc... */
824 printf_unfiltered ("Reading symbols from %s...", arg);
825 exec_file_command (arg, 0);
826 symbol_file_command (arg, 0);
827 printf_unfiltered ("done\n");
828
829 /* exec_file_command will kill our target, so reinstall the ICE as
830 the target. */
831 v850ice_open (NULL, 0);
832
833 togdb_force_update ();
834 return 1;
835}
836
837static int
838ice_cont (c)
c5aa993b 839 char *c;
6027a0b8
JM
840{
841 printf_filtered ("continue (ice)\n");
842 ReplyMessage ((LRESULT) 1);
843
3fc11d3e
JM
844 if (gdbtk_interp == NULL)
845 {
6027a0b8 846 continue_command (NULL, 1);
3fc11d3e
JM
847 }
848 else
849 Tcl_Eval (gdbtk_interp, "gdb_immediate continue");
6027a0b8
JM
850
851 return 1;
852}
853
854static void
855do_gdb (cmd, str, func, count)
856 char *cmd;
857 char *str;
507f3c78 858 void (*func) (char *, int);
6027a0b8
JM
859 int count;
860{
861 ReplyMessage ((LRESULT) 1);
862
863 while (count--)
864 {
865 printf_unfiltered (str);
866
3fc11d3e
JM
867 if (gdbtk_interp == NULL)
868 {
6027a0b8 869 func (NULL, 0);
3fc11d3e
JM
870 }
871 else
872 Tcl_Eval (gdbtk_interp, cmd);
6027a0b8
JM
873 }
874}
875
876
877static int
878ice_stepi (c)
c5aa993b 879 char *c;
6027a0b8
JM
880{
881 int count = (int) c;
882
883 do_gdb ("gdb_immediate stepi", "stepi (ice)\n", stepi_command, count);
884 return 1;
885}
886
887static int
888ice_nexti (c)
c5aa993b 889 char *c;
6027a0b8
JM
890{
891 int count = (int) c;
892
893 do_gdb ("gdb_immediate nexti", "nexti (ice)\n", nexti_command, count);
894 return 1;
895}
896
897static void
898v850ice_command (arg, from_tty)
c5aa993b
JM
899 char *arg;
900 int from_tty;
6027a0b8
JM
901{
902 struct MessageIO iob;
903 char buf[256];
904
905 iob.buf = buf;
906 iob.size = 0;
907 ExeAppReq ("GDB", GCOMMAND, arg, &iob);
908}
909
910static void
911togdb_force_update (void)
912{
3fc11d3e
JM
913 if (gdbtk_interp != NULL)
914 Tcl_Eval (gdbtk_interp, "gdbtk_update");
6027a0b8
JM
915}
916
3fc11d3e
JM
917static void
918view_source (addr)
919 CORE_ADDR addr;
920{
921 char c[256];
922
923 if (gdbtk_interp != NULL)
924 {
925 sprintf (c, "catch {set src [lindex [ManagedWin::find SrcWin] 0]\n$src location BROWSE [gdb_loc *0x%x]}", addr);
926 Tcl_Eval (gdbtk_interp, c);
927 }
928}
6027a0b8
JM
929
930/* Define the target subroutine names */
931
c5aa993b
JM
932static void
933init_850ice_ops (void)
6027a0b8 934{
c5aa993b
JM
935 v850ice_ops.to_shortname = "ice";
936 v850ice_ops.to_longname = "NEC V850 ICE interface";
937 v850ice_ops.to_doc = "Debug a system controlled by a NEC 850 ICE.";
938 v850ice_ops.to_open = v850ice_open;
939 v850ice_ops.to_close = v850ice_close;
940 v850ice_ops.to_attach = NULL;
941 v850ice_ops.to_post_attach = NULL;
942 v850ice_ops.to_require_attach = NULL;
943 v850ice_ops.to_detach = v850ice_detach;
944 v850ice_ops.to_require_detach = NULL;
945 v850ice_ops.to_resume = v850ice_resume;
946 v850ice_ops.to_wait = v850ice_wait;
947 v850ice_ops.to_post_wait = NULL;
948 v850ice_ops.to_fetch_registers = v850ice_fetch_registers;
949 v850ice_ops.to_store_registers = v850ice_store_registers;
950 v850ice_ops.to_prepare_to_store = v850ice_prepare_to_store;
951 v850ice_ops.to_xfer_memory = v850ice_xfer_memory;
952 v850ice_ops.to_files_info = v850ice_files_info;
953 v850ice_ops.to_insert_breakpoint = v850ice_insert_breakpoint;
954 v850ice_ops.to_remove_breakpoint = v850ice_remove_breakpoint;
955 v850ice_ops.to_terminal_init = NULL;
956 v850ice_ops.to_terminal_inferior = NULL;
957 v850ice_ops.to_terminal_ours_for_output = NULL;
958 v850ice_ops.to_terminal_ours = NULL;
959 v850ice_ops.to_terminal_info = NULL;
960 v850ice_ops.to_kill = v850ice_kill;
961 v850ice_ops.to_load = v850ice_load;
962 v850ice_ops.to_lookup_symbol = NULL;
963 v850ice_ops.to_create_inferior = NULL;
964 v850ice_ops.to_mourn_inferior = v850ice_mourn;
965 v850ice_ops.to_can_run = 0;
966 v850ice_ops.to_notice_signals = 0;
967 v850ice_ops.to_thread_alive = NULL;
968 v850ice_ops.to_stop = v850ice_stop;
6027a0b8 969 v850ice_ops.to_pid_to_exec_file = NULL;
c5aa993b
JM
970 v850ice_ops.to_core_file_to_sym_file = NULL;
971 v850ice_ops.to_stratum = process_stratum;
972 v850ice_ops.DONT_USE = NULL;
973 v850ice_ops.to_has_all_memory = 1;
974 v850ice_ops.to_has_memory = 1;
975 v850ice_ops.to_has_stack = 1;
976 v850ice_ops.to_has_registers = 1;
977 v850ice_ops.to_has_execution = 1;
978 v850ice_ops.to_sections = NULL;
979 v850ice_ops.to_sections_end = NULL;
980 v850ice_ops.to_magic = OPS_MAGIC;
6027a0b8
JM
981}
982
983void
984_initialize_v850ice ()
985{
986 init_850ice_ops ();
987 add_target (&v850ice_ops);
988
989 add_com ("ice", class_obscure, v850ice_command,
c5aa993b 990 "Send command to ICE");
6027a0b8 991}
This page took 0.106611 seconds and 4 git commands to generate.