[BACK]Return to x86check.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib / gmp / mpn / tests

Annotation of OpenXM_contrib/gmp/mpn/tests/x86check.c, Revision 1.1.1.1

1.1       maekawa     1: /* x86 calling conventions checking. */
                      2:
                      3: /*
                      4: Copyright (C) 2000 Free Software Foundation, Inc.
                      5:
                      6: This file is part of the GNU MP Library.
                      7:
                      8: The GNU MP Library is free software; you can redistribute it and/or modify
                      9: it under the terms of the GNU Lesser General Public License as published by
                     10: the Free Software Foundation; either version 2.1 of the License, or (at your
                     11: option) any later version.
                     12:
                     13: The GNU MP Library is distributed in the hope that it will be useful, but
                     14: WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
                     15: or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
                     16: License for more details.
                     17:
                     18: You should have received a copy of the GNU Lesser General Public License
                     19: along with the GNU MP Library; see the file COPYING.LIB.  If not, write to
                     20: the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
                     21: MA 02111-1307, USA.
                     22: */
                     23:
                     24: #include <stdio.h>
                     25: #include "gmp.h"
                     26: #include "gmp-impl.h"
                     27: #include "try.h"
                     28:
                     29:
                     30: /* function to call */
                     31: tryfun_t calling_conventions_function;
                     32:
                     33: /* temporaries */
                     34: int  calling_conventions_save_ebx;
                     35: int  calling_conventions_save_esi;
                     36: int  calling_conventions_save_edi;
                     37: int  calling_conventions_save_ebp;
                     38: int  calling_conventions_retaddr;
                     39: int  calling_conventions_retval;
                     40:
                     41: /* values to check */
                     42: struct {
                     43:   unsigned  control;
                     44:   unsigned  status;
                     45:   unsigned  tag;
                     46:   unsigned  other[4];
                     47: } calling_conventions_fenv;
                     48: int  calling_conventions_ebx;
                     49: int  calling_conventions_esi;
                     50: int  calling_conventions_edi;
                     51: int  calling_conventions_ebp;
                     52: int  calling_conventions_eflags;
                     53:
                     54: /* expected values, as per x86call.asm */
                     55: #define VALUE_EBX   0x01234567
                     56: #define VALUE_ESI   0x89ABCDEF
                     57: #define VALUE_EDI   0xFEDCBA98
                     58: #define VALUE_EBP   0x76543210
                     59:
                     60: #define DIR_BIT(eflags)   (((eflags) & (1<<10)) != 0)
                     61:
                     62:
                     63: /* Return 1 if ok, 0 if not */
                     64:
                     65: int
                     66: calling_conventions_check (void)
                     67: {
                     68:   const char  *header = "Violated calling conventions:\n";
                     69:   int  ret = 1;
                     70:
                     71: #define CHECK(callreg, regstr, value)                   \
                     72:   if (callreg != value)                                 \
                     73:     {                                                   \
                     74:       printf ("%s   %s  got 0x%08X want 0x%08X\n",      \
                     75:               header, regstr, callreg, value);          \
                     76:       header = "";                                      \
                     77:       ret = 0;                                          \
                     78:     }
                     79:
                     80:   CHECK (calling_conventions_ebx, "ebx", VALUE_EBX);
                     81:   CHECK (calling_conventions_esi, "esi", VALUE_ESI);
                     82:   CHECK (calling_conventions_edi, "edi", VALUE_EDI);
                     83:   CHECK (calling_conventions_ebp, "ebp", VALUE_EBP);
                     84:
                     85:   if (DIR_BIT (calling_conventions_eflags) != 0)
                     86:     {
                     87:       printf ("%s   eflags dir bit  got %d want 0\n",
                     88:               header, DIR_BIT (calling_conventions_eflags));
                     89:       header = "";
                     90:       ret = 0;
                     91:     }
                     92:
                     93:   if ((calling_conventions_fenv.tag & 0xFFFF) != 0xFFFF)
                     94:     {
                     95:       printf ("%s   fpu tags  got 0x%X want 0xFFFF\n",
                     96:               header, calling_conventions_fenv.tag & 0xFFFF);
                     97:       header = "";
                     98:       ret = 0;
                     99:     }
                    100:
                    101:   return ret;
                    102: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>