public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] [MSP430] Fix open syscall not working in simulator
@ 2017-08-24 11:06 Jozef Lawrynowicz
  2017-08-29 13:12 ` Nick Clifton
  0 siblings, 1 reply; 2+ messages in thread
From: Jozef Lawrynowicz @ 2017-08-24 11:06 UTC (permalink / raw)
  To: binutils, Nick Clifton

[-- Attachment #1: Type: text/plain, Size: 495 bytes --]

The syscall "open" does not execute correctly in the msp430 simulator.
"open" is a variadic function, so the arguments are passed partly in
registers, and partly on the stack. The other syscalls are regular
functions with arguments that fit in registers.

The attached patch adds proper support for the syscall "open", so it now
executes correctly in the simulator.

If the patch is acceptable, I would appreciate if someone could commit
it for me, as I do not have write access.

Thanks,
Jozef

[-- Attachment #2: 0001-MSP430-Fix-open-syscall-not-working-in-simulator.patch --]
[-- Type: text/plain, Size: 1769 bytes --]

From 64e7bc75fc1bc848d8b8adb62845f9e428c96f5d Mon Sep 17 00:00:00 2001
From: Jozef Lawrynowicz <jozef.l@somniumtech.com>
Date: Tue, 15 Aug 2017 14:38:05 +0000
Subject: [PATCH] MSP430: Fix open syscall not working in simulator

2017-08-XX	Jozef Lawrynowicz	<jozef.l@somniumtech.com>
	
	* sim/msp430/msp430-sim.c (maybe_perform_syscall): Fix passing of arguments
	for variadic syscall "open".
---
 sim/msp430/msp430-sim.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/sim/msp430/msp430-sim.c b/sim/msp430/msp430-sim.c
index 93b47ab..290f689 100644
--- a/sim/msp430/msp430-sim.c
+++ b/sim/msp430/msp430-sim.c
@@ -986,11 +986,26 @@ maybe_perform_syscall (SIM_DESC sd, int call_addr)
   if ((call_addr & ~0x3f) == 0x00180)
     {
       /* Syscall!  */
+      int arg1, arg2, arg3, arg4;
       int syscall_num = call_addr & 0x3f;
-      int arg1 = MSP430_CPU (sd)->state.regs[12];
-      int arg2 = MSP430_CPU (sd)->state.regs[13];
-      int arg3 = MSP430_CPU (sd)->state.regs[14];
-      int arg4 = MSP430_CPU (sd)->state.regs[15];
+
+      /* syscall_num == 2 is used for the variadic function "open". The
+	 arguments are set up differently for variadic functions.
+	 See slaa534.pdf distributed by TI.  */
+      if (syscall_num == 2)
+	{
+	  arg1 = MSP430_CPU (sd)->state.regs[12];
+	  arg2 = mem_get_val (sd, SP, 16);
+	  arg3 = mem_get_val (sd, SP+2, 16);
+	  arg4 = mem_get_val (sd, SP+4, 16);
+	}
+      else
+	{
+	  arg1 = MSP430_CPU (sd)->state.regs[12];
+	  arg2 = MSP430_CPU (sd)->state.regs[13];
+	  arg3 = MSP430_CPU (sd)->state.regs[14];
+	  arg4 = MSP430_CPU (sd)->state.regs[15];
+	}
 
       MSP430_CPU (sd)->state.regs[12] = sim_syscall (MSP430_CPU (sd),
 						     syscall_num, arg1, arg2,
-- 
1.8.3.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] [MSP430] Fix open syscall not working in simulator
  2017-08-24 11:06 [PATCH] [MSP430] Fix open syscall not working in simulator Jozef Lawrynowicz
@ 2017-08-29 13:12 ` Nick Clifton
  0 siblings, 0 replies; 2+ messages in thread
From: Nick Clifton @ 2017-08-29 13:12 UTC (permalink / raw)
  To: Jozef Lawrynowicz, binutils

Hi Jozef,

> The syscall "open" does not execute correctly in the msp430 simulator.
> "open" is a variadic function, so the arguments are passed partly in
> registers, and partly on the stack. The other syscalls are regular
> functions with arguments that fit in registers.

Approved and applied.

Note - for future reference - the simulator is part of GDB not the
binutils, so you need to submit patches to gdb@sourceware.org...

Cheers
  Nick


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-08-29 13:12 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-08-24 11:06 [PATCH] [MSP430] Fix open syscall not working in simulator Jozef Lawrynowicz
2017-08-29 13:12 ` Nick Clifton

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).