1 dnl AMD64 calling conventions checking.
3 dnl Copyright 2000, 2003, 2004, 2006, 2007 Free Software Foundation, Inc.
5 dnl This file is part of the GNU MP Library.
7 dnl The GNU MP Library is free software; you can redistribute it and/or
8 dnl modify it under the terms of the GNU Lesser General Public License as
9 dnl published by the Free Software Foundation; either version 3 of the
10 dnl License, or (at your option) any later version.
12 dnl The GNU MP Library is distributed in the hope that it will be useful,
13 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
14 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 dnl Lesser General Public License for more details.
17 dnl You should have received a copy of the GNU Lesser General Public License
18 dnl along with the GNU MP Library. If not, see http://www.gnu.org/licenses/.
21 include(`../config.m4')
24 C void x86_fldcw (unsigned short cw);
26 C Execute an fldcw, setting the x87 control word to cw.
35 C unsigned short x86_fstcw (void);
37 C Execute an fstcw, returning the current x87 control word.
47 dnl Instrumented profiling won't come out quite right below, since we don't
48 dnl do an actual "ret". There's only a few instructions here, so there's
49 dnl no great need to get them separately accounted, just let them get
50 dnl attributed to the caller.
52 ifelse(WANT_PROFILING,instrument,
53 `define(`WANT_PROFILING',no)')
56 C int calling_conventions (...);
58 C The global variable "calling_conventions_function" is the function to
59 C call, with the arguments as passed here.
61 C Perhaps the finit should be done only if the tags word isn't clear, but
62 C nothing uses the rounding mode or anything at the moment.
64 define(`WANT_RBX', eval(8*0)($1))
65 define(`WANT_RBP', eval(8*1)($1))
66 define(`WANT_R12', eval(8*2)($1))
67 define(`WANT_R13', eval(8*3)($1))
68 define(`WANT_R14', eval(8*4)($1))
69 define(`WANT_R15', eval(8*5)($1))
71 define(`JUNK_RAX', eval(8*6)($1))
72 define(`JUNK_R10', eval(8*7)($1))
73 define(`JUNK_R11', eval(8*8)($1))
75 define(`SAVE_RBX', eval(8*9)($1))
76 define(`SAVE_RBP', eval(8*10)($1))
77 define(`SAVE_R12', eval(8*11)($1))
78 define(`SAVE_R13', eval(8*12)($1))
79 define(`SAVE_R14', eval(8*13)($1))
80 define(`SAVE_R15', eval(8*14)($1))
82 define(`RETADDR', eval(8*15)($1))
84 define(`RBX', eval(8*16)($1))
85 define(`RBP', eval(8*17)($1))
86 define(`R12', eval(8*18)($1))
87 define(`R13', eval(8*19)($1))
88 define(`R14', eval(8*20)($1))
89 define(`R15', eval(8*21)($1))
90 define(`RFLAGS', eval(8*22)($1))
99 PROLOGUE(calling_conventions)
101 movq G(calling_conventions_values)@GOTPCREL(%rip), %rdi
104 movq %rax, RETADDR(%rdi)
106 leaq L(return)(%rip), %rax
109 movq %rbx, SAVE_RBX(%rdi)
110 movq %rbp, SAVE_RBP(%rdi)
111 movq %r12, SAVE_R12(%rdi)
112 movq %r13, SAVE_R13(%rdi)
113 movq %r14, SAVE_R14(%rdi)
114 movq %r15, SAVE_R15(%rdi)
116 C values we expect to see unchanged, as per amd64check.c
117 movq WANT_RBX(%rdi), %rbx
118 movq WANT_RBP(%rdi), %rbp
119 movq WANT_R12(%rdi), %r12
120 movq WANT_R13(%rdi), %r13
121 movq WANT_R14(%rdi), %r14
122 movq WANT_R15(%rdi), %r15
124 C Try to provoke a problem by starting with junk in the registers,
125 C especially %rax which will be the return value.
127 C ENHANCE-ME: If we knew how many of the parameter registers were
128 C actually being used we could put junk in the rest. Maybe we could
129 C get try.c to communicate this to us.
130 C movq JUNK_RAX(%rdi), %rax C overwritten below anyway
131 movq JUNK_R10(%rdi), %r10
132 movq JUNK_R11(%rdi), %r11
134 movq G(calling_conventions_function)@GOTPCREL(%rip), %rax
139 movq G(calling_conventions_values)@GOTPCREL(%rip), %rdi
150 movq %rbx, RFLAGS(%rdi)
152 movq G(calling_conventions_fenv)@GOTPCREL(%rip), %rbx
156 movq SAVE_RBX(%rdi), %rbx
157 movq SAVE_RBP(%rdi), %rbp
158 movq SAVE_R12(%rdi), %r12
159 movq SAVE_R13(%rdi), %r13
160 movq SAVE_R14(%rdi), %r14
161 movq SAVE_R15(%rdi), %r15