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