summaryrefslogtreecommitdiff
path: root/tests/arm32call.asm
blob: 24d073981c502dce9f181dbb6a9ef8f769a7d9db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
dnl  ARM32 calling conventions checking.

dnl  Copyright 2000, 2003, 2004, 2006, 2007, 2010, 2013, 2016 Free Software
dnl  Foundation, Inc.

dnl  This file is part of the GNU MP Library test suite.

dnl  The GNU MP Library test suite is free software; you can redistribute it
dnl  and/or modify it under the terms of the GNU General Public License as
dnl  published by the Free Software Foundation; either version 3 of the
dnl  License, or (at your option) any later version.

dnl  The GNU MP Library test suite is distributed in the hope that it will be
dnl  useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General
dnl  Public License for more details.

dnl  You should have received a copy of the GNU General Public License along
dnl  with the GNU MP Library test suite.  If not, see
dnl  https://www.gnu.org/licenses/.


dnl  The current version of the code attempts to keep the call/return
dnl  prediction stack valid, but matching calls and returns.

include(`../config.m4')


C int calling_conventions (...);
C
C The global variable "calling_conventions_function" is the function to
C call, with the arguments as passed here.

define(`WANT_CALLEE_SAVES',	eval(4*0))
define(`SAVE_CALLEE_SAVES',	eval(4*8))
define(`RETADDR',		eval(4*16))
define(`GOT_CALLEE_SAVES',	eval(4*17))
define(`JUNK_PARAMS',		eval(4*25))

	TEXT
	ALIGN(32)
PROLOGUE(calling_conventions)
	LEA(	r12, calling_conventions_values)

	C Preserve callee-saves registers, including the link register r14
	add	r12, r12, #SAVE_CALLEE_SAVES
	stm	r12, {r4-r11,r14}
	sub	r12, r12, #SAVE_CALLEE_SAVES

	C Put chosen junk into callee-saves registers
	add	r12, r12, #WANT_CALLEE_SAVES
	ldm	r12, {r4-r11}
	sub	r12, r12, #WANT_CALLEE_SAVES

	C No callee-saves registers on arm except r12 and parameter registers
	C

	C Make the actual call
	LEA(	r12, calling_conventions_function)
	ldr	r12, [r12]
	mov	r14, pc
	return	r12

	LEA(	r12, calling_conventions_values)

	C Save callee-saves registers after call
	add	r12, r12, #GOT_CALLEE_SAVES
	stm	r12, {r4-r11}
	sub	r12, r12, #GOT_CALLEE_SAVES

	C Restore callee-saves registers, including the link register r14
	add	r12, r12, #SAVE_CALLEE_SAVES
	ldm	r12, {r4-r11,r14}
	sub	r12, r12, #SAVE_CALLEE_SAVES

	C Overwrite parameter registers.  Note that we overwrite r1, which
	C could hold one half of a 64-bit return value, since we don't use that
	C in GMP.
	add	r12, r12, #JUNK_PARAMS
	ldm	r12, {r1-r3}

	return	r14
EPILOGUE()