1 /* Remote debugging interface for Zilog Z8000 simulator
2 Copyright 1992 Free Software Foundation, Inc.
3 Contributed by Cygnus Support. Written by Steve Chamberlain
6 This file is part of GDB.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
35 #include "../z8ksim/sim.h"
37 /* External data declarations */
38 extern int stop_soon_quietly
; /* for wait_for_inferior */
40 /* Forward data declarations */
41 extern struct target_ops sim_ops
; /* Forward declaration */
43 /* Forward function declarations */
44 static void sim_fetch_registers ();
45 static void sim_close ();
47 void sim_store_register();
53 sim_write_inferior_memory (memaddr
, myaddr
, len
)
55 unsigned char *myaddr
;
58 return sim_write(memaddr
, myaddr
, len
);
67 for (regno
= 0; regno
< 16; regno
++)
68 store_register(regno
);
72 sim_store_register(regno
,read_register(regno
));
80 sim_kill(arg
,from_tty
)
90 * Download a file specified in 'args', to the sim.
93 sim_load(args
,fromtty
)
101 abfd
= bfd_openr(args
,"coff-z8k");
105 printf_filtered("Unable to open file %s\n", args
);
109 if (bfd_check_format(abfd
, bfd_object
) ==0)
111 printf_filtered("File is not an object file\n");
116 while (s
!= (asection
*)NULL
)
118 if (s
->flags
& SEC_LOAD
)
122 char *buffer
= xmalloc(delta
);
123 printf_filtered("%s\t: 0x%4x .. 0x%4x ",
124 s
->name
, s
->vma
, s
->vma
+ s
->_raw_size
);
125 for (i
= 0; i
< s
->_raw_size
; i
+= delta
)
127 int sub_delta
= delta
;
128 if (sub_delta
> s
->_raw_size
- i
)
129 sub_delta
= s
->_raw_size
- i
;
131 bfd_get_section_contents(abfd
, s
, buffer
, i
, sub_delta
);
132 sim_write_inferior_memory(s
->vma
+ i
, buffer
, sub_delta
);
133 printf_filtered("*");
136 printf_filtered( "\n");
142 sim_set_pc(abfd
->start_address
);
145 /* This is called not only when we first attach, but also when the
146 user types "run" after having attached. */
148 sim_create_inferior (execfile
, args
, env
)
157 error ("Can't pass arguments to remote sim process.");
159 if (execfile
== 0 || exec_bfd
== 0)
160 error ("No exec file specified");
162 entry_pt
= (int) bfd_get_start_address (exec_bfd
);
167 sim_clear_breakpoints();
168 init_wait_for_inferior ();
172 insert_breakpoints (); /* Needed to get correct instruction in cache */
173 proceed(entry_pt
, -1, 0);
179 sim_open (name
, from_tty
)
188 /* Clear any break points */
189 sim_clear_breakpoints();
191 push_target (&sim_ops
);
192 target_fetch_registers(-1);
194 printf_filtered("Connected to the Z8000 Simulator.\n");
197 /* Close out all files and local state before this target loses control. */
205 /* Clear any break points */
206 sim_clear_breakpoints();
208 /* Put this port back into REMOTE mode */
209 sleep(1); /* Let any output make it all the way back */
212 /* Terminate the open connection to the remote debugger.
213 Use this when you want to detach and do something else
216 sim_detach (args
,from_tty
)
220 sim_clear_breakpoints();
222 pop_target(); /* calls sim_close to do the real work */
224 printf_filtered ("Ending remote %s debugging\n", target_shortname
);
228 /* Tell the remote machine to resume. */
231 /* Wait until the remote machine stops, then return,
232 storing status in STATUS just as `wait' would. */
239 *status
= sim_stop_signal();
243 /* Return the name of register number REGNO
244 in the form input and output by sim.
246 Returns a pointer to a static buffer containing the answer. */
251 static char *rn
[NUM_REGS
]= REGISTER_NAMES
;
259 /* Get ready to modify the registers array. On machines which store
260 individual registers, this doesn't need to do anything. On machines
261 which store all the registers in one fell swoop, this makes sure
262 that registers contains all the registers from the program being
266 sim_prepare_to_store ()
268 /* Do nothing, since we can store individual regs */
280 /* Read a word from remote address ADDR and return it.
281 * This goes through the data cache.
284 sim_fetch_word (addr
)
287 /* return dcache_fetch (addr);*/
292 fetch_register(regno
)
297 for (regno
= 0; regno
< 16; regno
++)
298 fetch_register(regno
);
301 char buf
[MAX_REGISTER_RAW_SIZE
];
302 sim_fetch_register(regno
, buf
);
303 supply_register(regno
, buf
);
307 /* Write a word WORD into remote address ADDR.
308 This goes through the data cache. */
311 sim_store_word (addr
, word
)
315 /* dcache_poke (addr, word);*/
319 sim_xfer_inferior_memory(memaddr
, myaddr
, len
, write
, target
)
324 struct target_ops
*target
; /* ignored */
328 sim_write(memaddr
, myaddr
, len
);
333 sim_read(memaddr
, myaddr
, len
);
341 char *file
= "nothing";
343 file
= bfd_get_filename(exec_bfd
);
347 printf_filtered("\tAttached to DOS asynctsr and running program %s\n",file
);
349 printf_filtered("\tAttached to %s at %d baud and running program %s\n",file
);
351 printf_filtered("\ton an H8/300 processor.\n");
354 /* This routine is run as a hook, just before the main command loop is
355 entered. If gdb is configured for the H8, but has not had its
356 target specified yet, this will loop prompting the user to do so.
360 sim_before_main_loop ()
364 extern FILE *instream
;
365 extern jmp_buf to_top_level
;
367 push_target (&sim_ops
);
371 #define MAX_BREAKS 16
372 static int num_brkpts
=0;
374 sim_insert_breakpoint(addr
, save
)
376 char *save
; /* Throw away, let sim save instructions */
381 sim_remove_breakpoint(addr
, save
)
383 char *save
; /* Throw away, let sim save instructions */
388 /* Clear the sims notion of what the break points are */
392 sim_clear_breakpoints();
393 generic_mourn_inferior ();
397 static int rem_resume(a
,b
)
403 /* Define the target subroutine names */
405 struct target_ops sim_ops
=
407 "sim", "Remote SIM monitor",
408 "Use the Z8000 simulator",
410 0, sim_detach
, rem_resume
, sim_wait
, /* attach */
411 fetch_register
, store_register
,
412 sim_prepare_to_store
,
413 sim_xfer_inferior_memory
,
415 0, 0, /* Breakpoints */
416 0, 0, 0, 0, 0, /* Terminal handling */
417 sim_kill
, /* FIXME, kill */
419 0, /* lookup_symbol */
420 sim_create_inferior
, /* create_inferior */
421 sim_mourn
, /* mourn_inferior FIXME */
423 0, /* notice_signals */
424 process_stratum
, 0, /* next */
425 1, 1, 1, 1, 1, /* all mem, mem, stack, regs, exec */
426 0,0, /* Section pointers */
427 OPS_MAGIC
, /* Always the last thing */
435 /***********************************************************************/
438 _initialize_remote_sim ()
440 extern int sim_z8001_mode
;
441 sim_z8001_mode
= z8001_mode
;
442 add_target (&sim_ops
);
This page took 0.038773 seconds and 5 git commands to generate.