[PATCH] [MSP430] Fix open syscall not working in simulator
Jozef Lawrynowicz
jozef.l@somniumtech.com
Thu Aug 24 11:06:00 GMT 2017
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
-------------- next part --------------
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
More information about the Binutils
mailing list