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