Linux MIPS Architecture development
 help / color / mirror / Atom feed
From: Ralf Baechle <ralf@linux-mips.org>
To: Harald Krapfenbauer <krapfenbauer@ict.tuwien.ac.at>
Cc: "linux-mips@linux-mips.org" <linux-mips@linux-mips.org>
Subject: Re: 64-bit values on 32-bit machine
Date: Tue, 8 Jul 2008 16:14:30 +0100	[thread overview]
Message-ID: <20080708151429.GA31147@linux-mips.org> (raw)
In-Reply-To: <487334AD.70100@ict.tuwien.ac.at>

On Tue, Jul 08, 2008 at 11:34:37AM +0200, Harald Krapfenbauer wrote:

> I want to know how 64-bit values are passed on a little-endian 32-bit
> MIPS machine on function calls.
> 
> If there is one 64-bit argument to a function, it is passed in registers
> a0-a1 I think, but does a0 contain the lower 4 bytes or the upper 4?
> 
> Similarly, if there are several arguments so that a 64-bit argument is
> passed on the stack: Do the lower 4 bytes go to the lower address or to
> the higher?

Give a man a fish and he's got to eat for one day.  Teach a man how to
fish and he's got food for a life ;-)

I suggest to find out about such ABI details you write a small test program
in C, compile that to assembler code using the -S option and check the
generated .s file.  For example:

$ cat c.c
extern foo(unsigned long long a1, unsigned long long a2,
           unsigned long long a3);

void bar(void)
{
	foo(1UL, 2UL, 3UL);
}
$ mips-linux-gcc -fno-pic -mno-abicalls -O2 -S c.c
	.file	1 "c.c"
	.section .mdebug.abi32
	.previous
	.gnu_attribute 4, 1
	.text
	.align	2
	.globl	bar
	.ent	bar
	.type	bar, @function
bar:
	.set	nomips16
	.frame	$sp,32,$31		# vars= 0, regs= 1/0, args= 24, gp= 0
	.mask	0x80000000,-4
	.fmask	0x00000000,0
	.set	noreorder
	.set	nomacro
	
	addiu	$sp,$sp,-32
	li	$3,3			# 0x3
	move	$2,$0
	li	$5,1			# 0x1
	move	$4,$0
	li	$7,2			# 0x2
	move	$6,$0
	sw	$31,28($sp)
	sw	$3,20($sp)
	jal	foo
	sw	$2,16($sp)

	lw	$31,28($sp)
	nop
	j	$31
	addiu	$sp,$sp,32

	.set	macro
	.set	reorder
	.end	bar
	.ident	"GCC: (GNU) 4.3.0"
$

mips-linux-gcc is the big endian compiler.  Repeat for little endian:

$ mipsel-linux-gcc -fno-pic -mno-abicalls -O2 -S c.c
	.file	1 "c.c"
	.section .mdebug.abi32
	.previous
	.gnu_attribute 4, 1
	.text
	.align	2
	.globl	bar
	.ent	bar
	.type	bar, @function
bar:
	.set	nomips16
	.frame	$sp,32,$31		# vars= 0, regs= 1/0, args= 24, gp= 0
	.mask	0x80000000,-4
	.fmask	0x00000000,0
	.set	noreorder
	.set	nomacro
	
	addiu	$sp,$sp,-32
	li	$2,3			# 0x3
	move	$3,$0
	li	$4,1			# 0x1
	move	$5,$0
	li	$6,2			# 0x2
	move	$7,$0
	sw	$31,28($sp)
	sw	$2,16($sp)
	jal	foo
	sw	$3,20($sp)

	lw	$31,28($sp)
	nop
	j	$31
	addiu	$sp,$sp,32

	.set	macro
	.set	reorder
	.end	bar
	.ident	"GCC: (GNU) 4.3.0"
$

Ignore the "-fno-pic -mno-abicalls" options; they disable the PIC code
generation which on MIPS is default and is making the generated code well
harder to read.

You will notice that big endian compiler uses register pairs $4/$5 rsp.
$6/$6 in the order high / low half and the little endian compiler does it
in the reverse order; similar for the memory order for stack arguments.

  Ralf

      reply	other threads:[~2008-07-08 15:16 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-07-08  9:34 64-bit values on 32-bit machine Harald Krapfenbauer
2008-07-08 15:14 ` Ralf Baechle [this message]

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=20080708151429.GA31147@linux-mips.org \
    --to=ralf@linux-mips.org \
    --cc=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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox