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