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 | ||
67205639 KS |
81 | static void v850ice_stop PARAMS ((void)); |
82 | ||
6c310da8 SG |
83 | static void v850ice_store_registers PARAMS ((int regno)); |
84 | ||
85 | static void v850ice_mourn PARAMS ((void)); | |
86 | ||
87 | static int v850ice_wait PARAMS ((int pid, struct target_waitstatus *status)); | |
88 | ||
89 | static void v850ice_kill PARAMS ((void)); | |
90 | ||
91 | static void v850ice_detach PARAMS ((char *args, int from_tty)); | |
92 | ||
93 | static int v850ice_insert_breakpoint PARAMS ((CORE_ADDR, char *)); | |
94 | ||
95 | static int v850ice_remove_breakpoint PARAMS ((CORE_ADDR, char *)); | |
96 | ||
e3ca310c | 97 | static void v850ice_command PARAMS ((char *, int)); |
6c310da8 | 98 | |
e3ca310c | 99 | static int ice_disassemble PARAMS ((unsigned long, int, char *)); |
c719b714 | 100 | |
e3ca310c | 101 | static int ice_lookup_addr PARAMS ((unsigned long *, char *, char *)); |
6c310da8 | 102 | |
e3ca310c KS |
103 | static int ice_lookup_symbol PARAMS ((unsigned long, char *)); |
104 | ||
105 | static void ice_SimulateDisassemble PARAMS ((char *, int)); | |
106 | ||
107 | static void ice_SimulateAddrLookup PARAMS ((char *, int)); | |
108 | ||
109 | static void ice_Simulate_SymLookup PARAMS ((char *, int)); | |
110 | ||
111 | static void ice_fputs PARAMS ((const char *, GDB_FILE *)); | |
112 | ||
113 | static int ice_file PARAMS ((char *)); | |
114 | ||
115 | static int ice_cont PARAMS ((char *)); | |
116 | ||
117 | static int ice_stepi PARAMS ((char *)); | |
118 | ||
119 | static int ice_nexti PARAMS ((char *)); | |
120 | ||
121 | static void togdb_force_update PARAMS ((void)); | |
122 | ||
123 | /* Globals */ | |
124 | static HWND hidden_hwnd; /* HWND for messages */ | |
125 | ||
126 | long (__stdcall *ExeAppReq) PARAMS ((char *, long, char *, struct MessageIO *)); | |
127 | ||
128 | long (__stdcall *RegisterClient) PARAMS ((HWND)); | |
129 | ||
130 | long (__stdcall *UnregisterClient) PARAMS ((void)); | |
131 | ||
132 | extern Tcl_Interp *gdbtk_interp; | |
133 | ||
134 | /* Globals local to this file only */ | |
135 | static int ice_open = 0; /* Is ICE open? */ | |
136 | ||
137 | static char * v850_CB_Result; /* special char array for saving 'callback' results */ | |
138 | ||
139 | static 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 | ||
177 | /* STATE_CHANGE codes */ | |
178 | #define STATE_CHANGE_REGS 1 /* Register(s) changed */ | |
179 | #define STATE_CHANGE_LOAD 2 /* HW reset */ | |
180 | #define STATE_CHANGE_RESET 3 /* Load new file */ | |
181 | #define STATE_CHANGE_CONT 4 /* Run target */ | |
182 | #define STATE_CHANGE_STOP 5 /* Stop target */ | |
183 | #define STATE_CHANGE_STEPI 6 /* Stepi target */ | |
184 | #define STATE_CHANGE_NEXTI 7 /* Nexti target */ | |
185 | ||
186 | static struct target_ops v850ice_ops; /* Forward decl */ | |
187 | ||
188 | /* This function creates a hidden window */ | |
189 | static int | |
190 | init_hidden_window () | |
264b9de0 | 191 | { |
e3ca310c KS |
192 | WNDCLASS class; |
193 | ||
194 | if (hidden_hwnd != NULL) | |
195 | return TCL_OK; | |
196 | ||
197 | class.style = 0; | |
198 | class.cbClsExtra = 0; | |
199 | class.cbWndExtra = 0; | |
200 | class.hInstance = Tk_GetHINSTANCE(); | |
201 | class.hbrBackground = NULL; | |
202 | class.lpszMenuName = NULL; | |
203 | class.lpszClassName = "gdbtk_v850ice"; | |
204 | class.lpfnWndProc = v850ice_wndproc; | |
205 | class.hIcon = NULL; | |
206 | class.hCursor = NULL; | |
207 | ||
208 | if (! RegisterClass (&class)) | |
209 | return TCL_ERROR; | |
210 | ||
211 | hidden_hwnd = CreateWindow ("gdbtk_v850ice", "gdbtk_v850ice", WS_TILED, | |
212 | 0, 0, 0, 0, NULL, NULL, class.hInstance, | |
213 | NULL); | |
214 | if (hidden_hwnd == NULL) | |
215 | { | |
216 | char buf[200]; | |
217 | DWORD err; | |
218 | ||
219 | err = GetLastError (); | |
220 | FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, | |
221 | 0, buf, 200, NULL); | |
222 | printf_unfiltered ("Could not create window: %s", buf); | |
223 | return TCL_ERROR; | |
224 | } | |
225 | ||
226 | return TCL_OK; | |
227 | } | |
228 | ||
229 | /* | |
230 | This function is installed as the message handler for the hidden window | |
231 | which QBox will use to communicate with gdbtk. It recognize and acts | |
232 | on the following messages: | |
233 | ||
234 | WM_SYM_TO_ADDR \ | |
235 | WM_ADDR_TO_SYM | Not implemented at NEC's request | |
236 | WM_DISASSEMBLY / | |
237 | WM_STATE_CHANGE - tells us that a state change has occured in the ICE | |
238 | */ | |
239 | static LRESULT CALLBACK | |
240 | v850ice_wndproc (hwnd, message, wParam, lParam) | |
241 | HWND hwnd; | |
242 | UINT message; | |
243 | WPARAM wParam; | |
244 | LPARAM lParam; | |
245 | { | |
246 | LRESULT result = FALSE; | |
247 | ||
248 | switch (message) | |
249 | { | |
250 | case WM_SYM_TO_ADDR: | |
251 | MessageBox (0, "Symbol resolution\nNot implemented", "GDB", MB_OK); | |
252 | break; | |
253 | case WM_ADDR_TO_SYM: | |
254 | MessageBox (0, "Address resolution\nNot implemented", "GDB", MB_OK); | |
255 | break; | |
256 | case WM_STATE_CHANGE: | |
257 | switch (wParam) | |
258 | { | |
259 | case STATE_CHANGE_LOAD: | |
260 | { | |
261 | struct MessageIO iob; | |
262 | char buf[128]; | |
263 | ||
264 | iob.buf = buf; | |
265 | iob.size = 128; | |
266 | ||
267 | /* Load in a new file... Need filename */ | |
268 | ExeAppReq ("GDB", GLOADFILENAME, NULL, &iob); | |
269 | if (!catch_errors (ice_file, iob.buf, "", RETURN_MASK_ALL)) | |
270 | printf_unfiltered ("load errored\n"); | |
271 | } | |
272 | break; | |
273 | case STATE_CHANGE_RESET: | |
274 | registers_changed (); | |
275 | flush_cached_frames (); | |
276 | togdb_force_update (); | |
277 | result = TRUE; | |
278 | break; | |
279 | case STATE_CHANGE_REGS: | |
280 | registers_changed (); | |
281 | togdb_force_update (); | |
282 | result = TRUE; | |
283 | break; | |
284 | case STATE_CHANGE_CONT: | |
285 | if (!catch_errors (ice_cont, NULL, "", RETURN_MASK_ALL)) | |
286 | printf_unfiltered ("continue errored\n"); | |
287 | result = TRUE; | |
288 | break; | |
289 | case STATE_CHANGE_STEPI: | |
290 | if (!catch_errors (ice_stepi, (PTR)(int) lParam, "", | |
291 | RETURN_MASK_ALL)) | |
292 | printf_unfiltered ("stepi errored\n"); | |
293 | result = TRUE; | |
294 | break; | |
295 | case STATE_CHANGE_NEXTI: | |
296 | if (!catch_errors (ice_nexti, (PTR)(int) lParam, "", | |
297 | RETURN_MASK_ALL)) | |
298 | printf_unfiltered ("nexti errored\n"); | |
299 | result = TRUE; | |
300 | break; | |
301 | } | |
302 | } | |
264b9de0 | 303 | |
e3ca310c KS |
304 | if (result == FALSE) |
305 | return DefWindowProc (hwnd, message, wParam, lParam); | |
306 | ||
307 | return FALSE; | |
308 | } | |
6c310da8 SG |
309 | |
310 | /* Code for opening a connection to the ICE. */ | |
311 | ||
312 | static void | |
313 | v850ice_open (name, from_tty) | |
314 | char *name; | |
315 | int from_tty; | |
316 | { | |
e3ca310c | 317 | HINSTANCE handle; |
6c310da8 SG |
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 | ||
e3ca310c KS |
333 | /* Initialize everything necessary to facilitate communication |
334 | between QBox, gdbtk, and the DLLs which control the ICE */ | |
335 | if (ExeAppReq == NULL) | |
336 | { | |
337 | handle = LoadLibrary ("necmsg.dll"); | |
338 | if (handle == NULL) | |
339 | error ("Cannot load necmsg.dll"); | |
340 | ||
341 | ExeAppReq = (long (*) PARAMS ((char *, long, char *, struct MessageIO *))) | |
342 | GetProcAddress (handle, "ExeAppReq"); | |
343 | RegisterClient = (long (*) PARAMS ((HWND))) | |
344 | GetProcAddress (handle, "RegisterClient"); | |
345 | UnregisterClient = (long (*) PARAMS ((void))) | |
346 | GetProcAddress (handle, "UnregisterClient"); | |
347 | ||
348 | if (ExeAppReq == NULL || RegisterClient == NULL || UnregisterClient == NULL) | |
349 | error ("Could not find requisite functions in necmsg.dll."); | |
350 | ||
351 | if (init_hidden_window () != TCL_OK) | |
352 | error ("could not initialize message handling"); | |
353 | } | |
354 | ||
355 | /* Tell the DLL we are here */ | |
356 | RegisterClient (hidden_hwnd); | |
357 | ||
358 | ice_open = 1; | |
359 | ||
6c310da8 SG |
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. */ | |
6c310da8 SG |
366 | inferior_pid = 42000; |
367 | ||
e3ca310c KS |
368 | start_remote (); |
369 | return; | |
6c310da8 SG |
370 | } |
371 | ||
372 | /* Clean up connection to a remote debugger. */ | |
373 | ||
374 | /* ARGSUSED */ | |
375 | static void | |
376 | v850ice_close (quitting) | |
377 | int quitting; | |
378 | { | |
6c310da8 SG |
379 | if (ice_open) |
380 | { | |
264b9de0 | 381 | UnregisterClient (); |
e3ca310c KS |
382 | ice_open = 0; |
383 | inferior_pid = 0; | |
6c310da8 SG |
384 | } |
385 | } | |
386 | ||
67205639 KS |
387 | /* Stop the process on the ice. */ |
388 | static void | |
389 | v850ice_stop () | |
390 | { | |
391 | /* This is silly, but it works... */ | |
392 | v850ice_command ("stop", 0); | |
393 | } | |
394 | ||
6c310da8 SG |
395 | static void |
396 | v850ice_detach (args, from_tty) | |
397 | char *args; | |
398 | int from_tty; | |
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 | ||
410 | static void | |
411 | v850ice_resume (pid, step, siggnal) | |
412 | int pid, step; | |
413 | enum target_signal siggnal; | |
414 | { | |
e3ca310c KS |
415 | long retval; |
416 | char buf[256]; | |
417 | struct MessageIO iob; | |
418 | ||
419 | iob.size = 0; | |
420 | iob.buf = buf; | |
6c310da8 SG |
421 | |
422 | if (step) | |
e3ca310c | 423 | retval = ExeAppReq ("GDB", GSINGLESTEP, "step", &iob); |
6c310da8 | 424 | else |
e3ca310c | 425 | retval = ExeAppReq ("GDB", GRESUME, "run", &iob); |
6c310da8 SG |
426 | |
427 | if (retval) | |
264b9de0 | 428 | error ("ExeAppReq (step = %d) returned %d", step, retval); |
6c310da8 SG |
429 | } |
430 | ||
431 | /* Wait until the remote machine stops, then return, | |
432 | storing status in STATUS just as `wait' would. | |
433 | Returns "pid" (though it's not clear what, if anything, that | |
434 | means in the case of this target). */ | |
435 | ||
436 | static int | |
437 | v850ice_wait (pid, status) | |
438 | int pid; | |
439 | struct target_waitstatus *status; | |
440 | { | |
264b9de0 | 441 | long v850_status; |
e3ca310c KS |
442 | char buf[256]; |
443 | struct MessageIO iob; | |
444 | int done = 0; | |
445 | iob.size = 0; | |
446 | iob.buf = buf; | |
447 | ||
448 | do | |
449 | { | |
450 | v850_status = ExeAppReq ("GDB", GCHECKSTATUS, NULL, &iob); | |
451 | ||
452 | switch (v850_status) | |
453 | { | |
454 | case ICE_Idle: | |
455 | case ICE_Breakpoint: | |
456 | case ICE_Stepped: | |
457 | case ICE_Halted: | |
458 | status->kind = TARGET_WAITKIND_STOPPED; | |
459 | status->value.sig = TARGET_SIGNAL_TRAP; | |
460 | done = 1; | |
461 | break; | |
462 | case ICE_Exception: | |
463 | status->kind = TARGET_WAITKIND_SIGNALLED; | |
464 | status->value.sig = TARGET_SIGNAL_SEGV; | |
465 | done = 1; | |
466 | break; | |
467 | case ICE_Exited: | |
468 | status->kind = TARGET_WAITKIND_EXITED; | |
469 | status->value.integer = 0; | |
470 | done = 1; | |
471 | break; | |
472 | case ICE_Terminated: | |
473 | status->kind = TARGET_WAITKIND_SIGNALLED; | |
474 | status->value.sig = TARGET_SIGNAL_KILL; | |
475 | done = 1; | |
476 | break; | |
477 | default: | |
478 | break; | |
479 | } | |
480 | } | |
481 | while (!done); | |
482 | ||
6c310da8 SG |
483 | return inferior_pid; |
484 | } | |
485 | ||
486 | static int | |
487 | convert_register (regno, buf) | |
488 | int regno; | |
489 | char *buf; | |
490 | { | |
491 | if (regno <= 31) | |
492 | sprintf (buf, "r%d", regno); | |
493 | else if (reg_names[regno][0] == 's' | |
494 | && reg_names[regno][1] == 'r') | |
495 | return 0; | |
496 | else | |
497 | sprintf (buf, "%s", reg_names[regno]); | |
498 | ||
499 | return 1; | |
500 | } | |
501 | ||
502 | /* Read the remote registers into the block REGS. */ | |
503 | /* Note that the ICE returns register contents as ascii hex strings. We have | |
504 | to convert that to an unsigned long, and then call store_unsigned_integer to | |
505 | convert it to target byte-order if necessary. */ | |
506 | ||
507 | static void | |
508 | v850ice_fetch_registers (regno) | |
509 | int regno; | |
510 | { | |
511 | long retval; | |
512 | char cmd[100]; | |
513 | char val[100]; | |
264b9de0 | 514 | struct MessageIO iob; |
6c310da8 SG |
515 | unsigned long regval; |
516 | char *p; | |
517 | ||
518 | if (regno == -1) | |
519 | { | |
520 | for (regno = 0; regno < NUM_REGS; regno++) | |
e3ca310c | 521 | v850ice_fetch_registers (regno); |
6c310da8 SG |
522 | return; |
523 | } | |
524 | ||
525 | strcpy (cmd, "reg "); | |
526 | if (!convert_register (regno, &cmd[4])) | |
527 | return; | |
528 | ||
264b9de0 SG |
529 | iob.size = sizeof val; |
530 | iob.buf = val; | |
e3ca310c | 531 | retval = ExeAppReq ("GDB", GREADREG, cmd, &iob); |
6c310da8 | 532 | if (retval) |
e3ca310c | 533 | error ("1: ExeAppReq returned %d: cmd = %s", retval, cmd); |
6c310da8 | 534 | |
e3ca310c | 535 | regval = strtoul (val, NULL, 16); |
6c310da8 SG |
536 | if (regval == 0 && p == val) |
537 | error ("v850ice_fetch_registers (%d): bad value from ICE: %s.", | |
e3ca310c | 538 | regno, val); |
6c310da8 SG |
539 | |
540 | store_unsigned_integer (val, REGISTER_RAW_SIZE (regno), regval); | |
541 | supply_register (regno, val); | |
542 | } | |
543 | ||
544 | /* Store register REGNO, or all registers if REGNO == -1, from the contents | |
545 | of REGISTERS. */ | |
546 | ||
547 | static void | |
548 | v850ice_store_registers (regno) | |
549 | int regno; | |
550 | { | |
551 | long retval; | |
552 | char cmd[100]; | |
6c310da8 | 553 | unsigned long regval; |
e3ca310c KS |
554 | char buf[256]; |
555 | struct MessageIO iob; | |
556 | iob.size = 0; | |
557 | iob.buf = buf; | |
6c310da8 SG |
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 (®isters[REGISTER_BYTE (regno)], | |
e3ca310c | 567 | REGISTER_RAW_SIZE (regno)); |
6c310da8 SG |
568 | strcpy (cmd, "reg "); |
569 | if (!convert_register (regno, &cmd[4])) | |
570 | return; | |
571 | sprintf (cmd + strlen (cmd), "=0x%x", regval); | |
572 | ||
e3ca310c | 573 | retval = ExeAppReq ("GDB", GWRITEREG, cmd, &iob); |
6c310da8 | 574 | if (retval) |
e3ca310c | 575 | error ("2: ExeAppReq returned %d: cmd = %s", retval, cmd); |
6c310da8 SG |
576 | } |
577 | ||
578 | /* Prepare to store registers. Nothing to do here, since the ICE can write one | |
579 | register at a time. */ | |
580 | ||
581 | static void | |
582 | v850ice_prepare_to_store () | |
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 | |
e3ca310c | 588 | nonzero. Returns length of data written or read; 0 for error. |
6c310da8 | 589 | |
e3ca310c KS |
590 | We can only read/write MAX_BLOCK_SIZE bytes at a time, though, or the DLL |
591 | dies */ | |
6c310da8 SG |
592 | /* ARGSUSED */ |
593 | static int | |
594 | v850ice_xfer_memory (memaddr, myaddr, len, should_write, target) | |
595 | CORE_ADDR memaddr; | |
596 | char *myaddr; | |
597 | int len; | |
598 | int should_write; | |
599 | struct target_ops *target; /* ignored */ | |
600 | { | |
601 | long retval; | |
602 | char cmd[100]; | |
264b9de0 | 603 | struct MessageIO iob; |
e3ca310c | 604 | int sent; |
6c310da8 SG |
605 | |
606 | if (should_write) | |
607 | { | |
e3ca310c KS |
608 | if (len == 4 || len == 2 || len == 1) |
609 | { | |
610 | long value = 0; | |
611 | char buf[256]; | |
612 | char c; | |
613 | ||
614 | iob.size = 0; | |
615 | iob.buf = buf; | |
616 | ||
617 | sent = 0; | |
618 | switch (len) | |
619 | { | |
620 | case 4: | |
621 | c = 'w'; | |
622 | value |= (long) (myaddr[3] << 24) & 0xff000000; | |
623 | value |= (long) (myaddr[2] << 16) & 0x00ff0000; | |
624 | value |= (long) (myaddr[1] << 8) & 0x0000ff00; | |
625 | value |= (long) myaddr[0] & 0x000000ff; | |
626 | case 2: | |
627 | c = 'h'; | |
628 | value |= (long) myaddr[1] << 8 & 0xff00; | |
629 | value |= (long) myaddr[0] & 0x00ff; | |
630 | break; | |
631 | case 1: | |
632 | c = 'b'; | |
633 | value |= (long) myaddr[0] & 0xff; | |
634 | break; | |
635 | } | |
636 | ||
637 | sprintf (cmd, "memory %c c 0x%x=0x%x", c, (int) memaddr, value); | |
638 | retval = ExeAppReq ("GDB", GWRITEMEM, cmd, &iob); | |
639 | if (retval == 0) | |
640 | sent = len; | |
641 | } | |
642 | else | |
643 | { | |
644 | sent = 0; | |
645 | do | |
646 | { | |
647 | iob.size = len > MAX_BLOCK_SIZE ? MAX_BLOCK_SIZE : len; | |
648 | iob.buf = myaddr; | |
649 | sprintf (cmd, "memory b c 0x%x=0x00 l=%d", (int)memaddr, iob.size); | |
650 | retval = ExeAppReq ("GDB", GWRITEBLOCK, cmd, &iob); | |
651 | if (retval != 0) | |
652 | break; | |
653 | len -= iob.size; | |
654 | memaddr += iob.size; | |
655 | myaddr += iob.size; | |
656 | sent += iob.size; | |
657 | } | |
658 | while (len > 0); | |
659 | } | |
6c310da8 SG |
660 | } |
661 | else | |
662 | { | |
663 | unsigned char *tmp; | |
e3ca310c | 664 | unsigned char *t; |
6c310da8 | 665 | int i; |
e3ca310c | 666 | |
6c310da8 | 667 | tmp = alloca (len + 100); |
e3ca310c | 668 | t = tmp; |
6c310da8 | 669 | memset (tmp + len, 0xff, 100); |
6c310da8 | 670 | |
e3ca310c KS |
671 | sent = 0; |
672 | do | |
673 | { | |
674 | iob.size = len > MAX_BLOCK_SIZE ? MAX_BLOCK_SIZE : len; | |
675 | iob.buf = tmp; | |
676 | sprintf (cmd, "memory b 0x%x l=%d", (int)memaddr, iob.size); | |
677 | retval = ExeAppReq ("GDB", GREADBLOCK, cmd, &iob); | |
678 | if (retval != 0) | |
679 | break; | |
680 | len -= iob.size; | |
681 | memaddr += iob.size; | |
682 | sent += iob.size; | |
683 | tmp += iob.size; | |
684 | } | |
685 | while (len > 0); | |
686 | ||
687 | if (retval == 0) | |
688 | { | |
689 | for (i = 0; i < 100; i++) | |
690 | { | |
691 | if (t[sent + i] != 0xff) | |
692 | { | |
693 | warning ("GREADBLOCK trashed bytes after transfer area."); | |
694 | break; | |
695 | } | |
696 | } | |
697 | memcpy (myaddr, t, sent); | |
698 | } | |
699 | } | |
700 | ||
701 | if (retval != 0) | |
702 | error ("3: ExeAppReq returned %d: cmd = %s", retval, cmd); | |
703 | ||
704 | return sent; | |
6c310da8 SG |
705 | } |
706 | ||
707 | static void | |
708 | v850ice_files_info (ignore) | |
709 | struct target_ops *ignore; | |
710 | { | |
711 | puts_filtered ("Debugging a target via the NEC V850 ICE.\n"); | |
712 | } | |
713 | ||
714 | static int | |
715 | v850ice_insert_breakpoint (addr, contents_cache) | |
716 | CORE_ADDR addr; | |
717 | char *contents_cache; | |
718 | { | |
719 | long retval; | |
720 | char cmd[100]; | |
e3ca310c KS |
721 | char buf[256]; |
722 | struct MessageIO iob; | |
6c310da8 | 723 | |
e3ca310c KS |
724 | iob.size = 0; |
725 | iob.buf = buf; | |
6c310da8 SG |
726 | sprintf (cmd, "%d, ", addr); |
727 | ||
e3ca310c | 728 | retval = ExeAppReq ("GDB", GSETBREAK, cmd, &iob); |
6c310da8 | 729 | if (retval) |
e3ca310c | 730 | error ("ExeAppReq (GSETBREAK) returned %d: cmd = %s", retval, cmd); |
6c310da8 SG |
731 | |
732 | return 0; | |
733 | } | |
734 | ||
735 | static int | |
736 | v850ice_remove_breakpoint (addr, contents_cache) | |
737 | CORE_ADDR addr; | |
738 | char *contents_cache; | |
739 | { | |
740 | long retval; | |
741 | char cmd[100]; | |
e3ca310c KS |
742 | char buf[256]; |
743 | struct MessageIO iob; | |
744 | ||
745 | iob.size = 0; | |
746 | iob.buf = buf; | |
6c310da8 SG |
747 | |
748 | sprintf (cmd, "%d, ", addr); | |
749 | ||
e3ca310c | 750 | retval = ExeAppReq ("GDB", GREMOVEBREAK, cmd, &iob); |
6c310da8 | 751 | if (retval) |
e3ca310c | 752 | error ("ExeAppReq (GREMOVEBREAK) returned %d: cmd = %s", retval, cmd); |
6c310da8 SG |
753 | |
754 | return 0; | |
755 | } | |
756 | ||
757 | static void | |
758 | v850ice_kill () | |
759 | { | |
760 | target_mourn_inferior (); | |
e3ca310c | 761 | inferior_pid = 0; |
6c310da8 SG |
762 | } |
763 | ||
764 | static void | |
765 | v850ice_mourn () | |
766 | { | |
767 | } | |
768 | ||
e3ca310c KS |
769 | static void |
770 | v850ice_load (filename, from_tty) | |
771 | char * filename; | |
772 | int from_tty; | |
773 | { | |
774 | struct MessageIO iob; | |
775 | char buf[256]; | |
776 | ||
777 | iob.size = 0; | |
778 | iob.buf = buf; | |
779 | generic_load(filename, from_tty); | |
67205639 | 780 | ExeAppReq ("GDB", GDOWNLOAD, filename, &iob); |
e3ca310c KS |
781 | } |
782 | ||
783 | static int | |
784 | ice_file (arg) | |
785 | char *arg; | |
786 | { | |
787 | char *s; | |
788 | ||
789 | target_detach (NULL, 0); | |
790 | pop_target (); | |
791 | ||
792 | printf_unfiltered ("\n"); | |
793 | ||
794 | s = arg; | |
795 | while (*s != '\0') | |
796 | { | |
797 | if (*s == '\\') | |
798 | *s = '/'; | |
799 | s++; | |
800 | } | |
801 | ||
802 | /* Safegaurd against confusing the breakpoint routines... */ | |
803 | delete_command(NULL, 0); | |
804 | ||
805 | /* Must supress from_tty, otherwise we could start asking if the | |
806 | user really wants to load a new symbol table, etc... */ | |
807 | printf_unfiltered ("Reading symbols from %s...", arg); | |
808 | exec_file_command (arg, 0); | |
809 | symbol_file_command (arg, 0); | |
810 | printf_unfiltered ("done\n"); | |
811 | ||
812 | /* exec_file_command will kill our target, so reinstall the ICE as | |
813 | the target. */ | |
814 | v850ice_open (NULL, 0); | |
6c310da8 | 815 | |
e3ca310c KS |
816 | togdb_force_update (); |
817 | return 1; | |
818 | } | |
819 | ||
820 | static int | |
821 | ice_cont (c) | |
822 | char *c; | |
823 | { | |
67205639 KS |
824 | printf_filtered ("continue (ice)"); |
825 | Tcl_Eval (gdbtk_interp, "gdb_immediate continue"); | |
e3ca310c KS |
826 | return 1; |
827 | } | |
828 | ||
829 | static int | |
830 | ice_stepi (c) | |
831 | char *c; | |
832 | { | |
67205639 | 833 | char string[50] = "\0"; |
e3ca310c KS |
834 | int count = (int) c; |
835 | ||
67205639 | 836 | sprintf (string, "gdb_immediate stepi %d", count); |
e3ca310c | 837 | printf_unfiltered ("stepi (ice)\n"); |
67205639 | 838 | Tcl_Eval (gdbtk_interp, string); |
e3ca310c | 839 | ReplyMessage ((LRESULT) 1); |
e3ca310c KS |
840 | return 1; |
841 | } | |
842 | ||
843 | static int | |
844 | ice_nexti (c) | |
845 | char *c; | |
846 | { | |
67205639 | 847 | char string[50] = "\0"; |
e3ca310c KS |
848 | int count = (int) c; |
849 | ||
67205639 | 850 | sprintf (string, "gdb_immediate nexti %d", count); |
e3ca310c | 851 | printf_unfiltered ("nexti (ice)\n"); |
67205639 | 852 | Tcl_Eval (gdbtk_interp, string); |
e3ca310c KS |
853 | return 1; |
854 | } | |
855 | ||
856 | static void | |
857 | v850ice_command (arg, from_tty) | |
858 | char *arg; | |
859 | int from_tty; | |
860 | { | |
861 | struct MessageIO iob; | |
862 | char buf[256]; | |
863 | ||
864 | iob.buf = buf; | |
865 | iob.size = 0; | |
866 | ExeAppReq ("GDB", GCOMMAND, arg, &iob); | |
867 | } | |
868 | ||
869 | static void | |
870 | togdb_force_update (void) | |
871 | { | |
872 | Tcl_Eval (gdbtk_interp, "gdbtk_update"); | |
873 | } | |
874 | ||
875 | /* Define the target subroutine names */ | |
c719b714 JM |
876 | |
877 | static void init_850ice_ops(void) | |
878 | { | |
879 | v850ice_ops.to_shortname = "ice"; | |
880 | v850ice_ops.to_longname = "NEC V850 ICE interface"; | |
881 | v850ice_ops.to_doc = "Debug a system controlled by a NEC 850 ICE."; | |
882 | v850ice_ops.to_open = v850ice_open; | |
883 | v850ice_ops.to_close = v850ice_close; | |
884 | v850ice_ops.to_attach = NULL; | |
885 | v850ice_ops.to_detach = v850ice_detach; | |
886 | v850ice_ops.to_resume = v850ice_resume; | |
887 | v850ice_ops.to_wait = v850ice_wait; | |
888 | v850ice_ops.to_fetch_registers = v850ice_fetch_registers; | |
889 | v850ice_ops.to_store_registers = v850ice_store_registers; | |
890 | v850ice_ops.to_prepare_to_store = v850ice_prepare_to_store; | |
891 | v850ice_ops.to_xfer_memory = v850ice_xfer_memory; | |
892 | v850ice_ops.to_files_info = v850ice_files_info; | |
893 | v850ice_ops.to_insert_breakpoint = v850ice_insert_breakpoint; | |
894 | v850ice_ops.to_remove_breakpoint = v850ice_remove_breakpoint; | |
895 | v850ice_ops.to_terminal_init = NULL; | |
896 | v850ice_ops.to_terminal_inferior = NULL; | |
897 | v850ice_ops.to_terminal_ours_for_output = NULL; | |
898 | v850ice_ops.to_terminal_ours = NULL; | |
899 | v850ice_ops.to_terminal_info = NULL; | |
900 | v850ice_ops.to_kill = v850ice_kill; | |
e3ca310c | 901 | v850ice_ops.to_load = v850ice_load; |
c719b714 JM |
902 | v850ice_ops.to_lookup_symbol = NULL; |
903 | v850ice_ops.to_create_inferior = NULL; | |
904 | v850ice_ops.to_mourn_inferior = v850ice_mourn; | |
905 | v850ice_ops.to_can_run = 0; | |
906 | v850ice_ops.to_notice_signals = 0; | |
907 | v850ice_ops.to_thread_alive = NULL; | |
67205639 | 908 | v850ice_ops.to_stop = v850ice_stop; |
c719b714 JM |
909 | v850ice_ops.to_stratum = process_stratum; |
910 | v850ice_ops.DONT_USE = NULL; | |
911 | v850ice_ops.to_has_all_memory = 1; | |
912 | v850ice_ops.to_has_memory = 1; | |
913 | v850ice_ops.to_has_stack = 1; | |
914 | v850ice_ops.to_has_registers = 1; | |
915 | v850ice_ops.to_has_execution = 1; | |
916 | v850ice_ops.to_sections = NULL; | |
917 | v850ice_ops.to_sections_end = NULL; | |
918 | v850ice_ops.to_magic = OPS_MAGIC ; | |
919 | } | |
6c310da8 SG |
920 | |
921 | void | |
922 | _initialize_v850ice () | |
923 | { | |
e3ca310c | 924 | init_850ice_ops (); |
6c310da8 | 925 | add_target (&v850ice_ops); |
e3ca310c KS |
926 | |
927 | add_com ("ice", class_obscure, v850ice_command, | |
928 | "Send command to ICE"); | |
6c310da8 | 929 | } |