[v2] sim: msp430: set initial PC to ELF entry if available

Message ID 1394509106-27143-1-git-send-email-vapier@gentoo.org
State Committed
Headers

Commit Message

Mike Frysinger March 11, 2014, 3:38 a.m. UTC
  If we want to run a simple ELF, it makes more sense to start at the
ELF's entry point instead of requiring the magic reset vector always
be set up.  This matches better what other sims do.

2014-03-08  Mike Frysinger  <vapier@gentoo.org>

	* msp430-sim.c (sim_create_inferior): Set new_pc to the result of
	bfd_get_start_address when abfd is not NULL and new_pc is zero.
---
v2
	- use the ELF entry only when the reset vector is not set up.

 sim/msp430/msp430-sim.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
  

Comments

DJ Delorie March 11, 2014, 3:44 a.m. UTC | #1
Assuming that memory-region ram is initialized to zero (I think it is
based on reading the common/ code), this is fine.  Thanks!
  
Mike Frysinger March 11, 2014, 3:57 a.m. UTC | #2
On Mon 10 Mar 2014 23:44:31 DJ Delorie wrote:
> Assuming that memory-region ram is initialized to zero (I think it is
> based on reading the common/ code), this is fine.  Thanks!

the default fill value is 0.  it can be changed by memory-fill, but no sim 
does that.  a user could change this with command line flags, but i guess 
you'd get what you pay for at that point :).
-mike
  
DJ Delorie March 11, 2014, 4:12 a.m. UTC | #3
> a user could change this with command line flags, but i guess you'd
> get what you pay for at that point :).

+1 on that :-)
  

Patch

diff --git a/sim/msp430/msp430-sim.c b/sim/msp430/msp430-sim.c
index c3fa4a9..2a648f5 100644
--- a/sim/msp430/msp430-sim.c
+++ b/sim/msp430/msp430-sim.c
@@ -249,9 +249,14 @@  sim_create_inferior (SIM_DESC sd,
   int c;
   int new_pc;
 
+  /* Set the PC to the default reset vector if available.  */
   c = sim_core_read_buffer (sd, MSP430_CPU (sd), read_map, resetv, 0xfffe, 2);
-
   new_pc = resetv[0] + 256 * resetv[1];
+
+  /* If the reset vector isn't initialized, then use the ELF entry.  */
+  if (abfd != NULL && !new_pc)
+    new_pc = bfd_get_start_address (abfd);
+
   sim_pc_set (MSP430_CPU (sd), new_pc);
   msp430_pc_store (MSP430_CPU (sd), new_pc);