Upload Tizen:Base source
[external/gmp.git] / tests / x86call.asm
1 dnl  x86 calling conventions checking.
2
3 dnl  Copyright 2000, 2003 Free Software Foundation, Inc.
4 dnl
5 dnl  This file is part of the GNU MP Library.
6 dnl
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.
11 dnl
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.
16 dnl
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/.
19
20
21 include(`../config.m4')
22
23
24 C void x86_fldcw (unsigned short cw);
25 C
26 C Execute an fldcw, setting the x87 control word to cw.
27
28 PROLOGUE(x86_fldcw)
29         fldcw   4(%esp)
30         ret
31 EPILOGUE()
32
33
34 C unsigned short x86_fstcw (void);
35 C
36 C Execute an fstcw, returning the current x87 control word.
37
38 PROLOGUE(x86_fstcw)
39         xorl    %eax, %eax
40         pushl   %eax
41         fstcw   (%esp)
42         popl    %eax
43         ret
44 EPILOGUE()
45
46
47 dnl  Instrumented profiling doesn't come out quite right below, since we
48 dnl  don't do an actual "ret".  There's only a few instructions here, so
49 dnl  there's no great need to get them separately accounted, just let them
50 dnl  get attributed to the caller.
51
52 ifelse(WANT_PROFILING,instrument,
53 `define(`WANT_PROFILING',no)')
54
55
56 C int calling_conventions (...);
57 C
58 C The global variable "calling_conventions_function" is the function to
59 C call, with the arguments as passed here.
60 C
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.
63
64 define(G,
65 m4_assert_numargs(1)
66 `GSYM_PREFIX`'$1')
67
68         .text
69         ALIGN(8)
70 PROLOGUE(calling_conventions)
71         movl    (%esp), %eax
72         movl    %eax, G(calling_conventions_retaddr)
73
74         movl    $L(return), (%esp)
75
76         movl    %ebx, G(calling_conventions_save_ebx)
77         movl    %esi, G(calling_conventions_save_esi)
78         movl    %edi, G(calling_conventions_save_edi)
79         movl    %ebp, G(calling_conventions_save_ebp)
80
81         movl    $0x01234567, %ebx
82         movl    $0x89ABCDEF, %esi
83         movl    $0xFEDCBA98, %edi
84         movl    $0x76543210, %ebp
85
86         C try to provoke a problem by starting with junk in the registers,
87         C especially in %eax and %edx which will be return values
88         movl    $0x70246135, %eax
89         movl    $0x8ACE9BDF, %ecx
90         movl    $0xFDB97531, %edx
91
92         jmp     *G(calling_conventions_function)
93
94 L(return):
95         movl    %ebx, G(calling_conventions_ebx)
96         movl    %esi, G(calling_conventions_esi)
97         movl    %edi, G(calling_conventions_edi)
98         movl    %ebp, G(calling_conventions_ebp)
99
100         pushf
101         popl    %ebx
102         movl    %ebx, G(calling_conventions_eflags)
103
104         fstenv  G(calling_conventions_fenv)
105         finit
106
107         movl    G(calling_conventions_save_ebx), %ebx
108         movl    G(calling_conventions_save_esi), %esi
109         movl    G(calling_conventions_save_edi), %edi
110         movl    G(calling_conventions_save_ebp), %ebp
111
112         jmp     *G(calling_conventions_retaddr)
113
114 EPILOGUE()
115