All of lore.kernel.org
 help / color / mirror / Atom feed
From: Harald Krapfenbauer <krapfenbauer@ict.tuwien.ac.at>
To: "linux-mips@linux-mips.org" <linux-mips@linux-mips.org>
Subject: function call on MIPS (newbie question)
Date: Tue, 24 Jun 2008 12:18:37 +0200	[thread overview]
Message-ID: <4860C9FD.60103@ict.tuwien.ac.at> (raw)

Hi!

I'm a newbie to the MIPS architecture and I want to port some program to
MIPS.
I must call a function within the .text segment with 2 simple
parameters. So I figured out the following code which
*) loads arg1 into register $4
*) loads arg2 into register $5
*) loads the address into $15
*) executes a jalr
*) breaks afterwards


	*((guint32 *)(code)) = ((method_argument1 >> 16) & 0xffff) |
0x3c040000;    /* arg 1 upper half word */
	*((guint32 *)(code+4)) = (method_argument1 & 0xffff) | 0x24040000;
     /* arg 1 lower half word */
	*((guint32 *)(code+8)) = ((method_argument2 >> 16) & 0xffff) |
0x3c050000;  /* arg 2 upper half word */
	*((guint32 *)(code+12)) = (method_argument2 & 0xffff) | 0x24050000;
     /* arg 2 lower half word */
	*((guint32 *)(code+16)) = ((method_address >> 16) & 0xffff) |
0x3c0f0000;   /* address upper half word */
	*((guint32 *)(code+20)) = (method_address & 0xffff) | 0x240f0000;
     /* address lower half word */
	*((guint32 *)(code+24)) = 0x01e0f809;
     /* jalr */
	*((guint32 *)(code+28)) = 0x0;
     /* branch delay slot */
	*((guint32 *)(code+32)) = 0x0d;
     /* breakpoint */



The code is written to the stack, the SP and the PC are then set to the
beginning of the code on the stack.

Something must be going wrong because after the program stops again, the
PC is 0xffffcb38 (The method address is 0x53cb38) and my program
receives signal 10.

Did I miss something or is my code wrong?
Any help appreciated!

Best regards,
Harald Krapfenbauer

             reply	other threads:[~2008-06-24 10:18 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-06-24 10:18 Harald Krapfenbauer [this message]
2008-06-24 17:45 ` function call on MIPS (newbie question) David VomLehn
2008-06-24 17:48 ` Chris Dearman
2008-06-27 10:00   ` Harald Krapfenbauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4860C9FD.60103@ict.tuwien.ac.at \
    --to=krapfenbauer@ict.tuwien.ac.at \
    --cc=linux-mips@linux-mips.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.