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