Statistics
| Branch: | Revision:

root / hostregs_helper.h @ 99a0949b

History | View | Annotate | Download (1.8 kB)

1 1057eaa7 pbrook
/*
2 cc5f688d Stefan Weil
 *  Save/restore host registers.
3 1057eaa7 pbrook
 *
4 1057eaa7 pbrook
 *  Copyright (c) 2007 CodeSourcery
5 1057eaa7 pbrook
 *
6 1057eaa7 pbrook
 * This library is free software; you can redistribute it and/or
7 1057eaa7 pbrook
 * modify it under the terms of the GNU Lesser General Public
8 1057eaa7 pbrook
 * License as published by the Free Software Foundation; either
9 1057eaa7 pbrook
 * version 2 of the License, or (at your option) any later version.
10 1057eaa7 pbrook
 *
11 1057eaa7 pbrook
 * This library is distributed in the hope that it will be useful,
12 1057eaa7 pbrook
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 1057eaa7 pbrook
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 1057eaa7 pbrook
 * Lesser General Public License for more details.
15 1057eaa7 pbrook
 *
16 1057eaa7 pbrook
 * You should have received a copy of the GNU Lesser General Public
17 8167ee88 Blue Swirl
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 1057eaa7 pbrook
 */
19 1057eaa7 pbrook
20 54604f74 aurel32
/* The GCC global register variable extension is used to reserve some
21 54604f74 aurel32
   host registers for use by generated code.  However only the core parts of
22 54604f74 aurel32
   the translation engine are compiled with these settings.  We must manually
23 1057eaa7 pbrook
   save/restore these registers when called from regular code.
24 1057eaa7 pbrook
   It is not sufficient to save/restore T0 et. al. as these may be declared
25 1057eaa7 pbrook
   with a datatype smaller than the actual register.  */
26 1057eaa7 pbrook
27 1057eaa7 pbrook
#if defined(DECLARE_HOST_REGS)
28 1057eaa7 pbrook
29 1057eaa7 pbrook
#define DO_REG(REG)                                        \
30 99a0949b malc
    register a_host_reg reg_AREG##REG asm(AREG##REG);        \
31 99a0949b malc
    volatile a_host_reg saved_AREG##REG;
32 1057eaa7 pbrook
33 1057eaa7 pbrook
#elif defined(SAVE_HOST_REGS)
34 1057eaa7 pbrook
35 1057eaa7 pbrook
#define DO_REG(REG)                                        \
36 1057eaa7 pbrook
    __asm__ __volatile__ ("" : "=r" (reg_AREG##REG));        \
37 1057eaa7 pbrook
    saved_AREG##REG = reg_AREG##REG;
38 1057eaa7 pbrook
39 1057eaa7 pbrook
#else
40 1057eaa7 pbrook
41 1057eaa7 pbrook
#define DO_REG(REG)                                     \
42 1057eaa7 pbrook
    reg_AREG##REG = saved_AREG##REG;                        \
43 1057eaa7 pbrook
    __asm__ __volatile__ ("" : : "r" (reg_AREG##REG));
44 1057eaa7 pbrook
45 1057eaa7 pbrook
#endif
46 1057eaa7 pbrook
47 1057eaa7 pbrook
#ifdef AREG0
48 1057eaa7 pbrook
DO_REG(0)
49 1057eaa7 pbrook
#endif
50 1057eaa7 pbrook
51 1057eaa7 pbrook
#ifdef AREG1
52 1057eaa7 pbrook
DO_REG(1)
53 1057eaa7 pbrook
#endif
54 1057eaa7 pbrook
55 1057eaa7 pbrook
#ifdef AREG2
56 1057eaa7 pbrook
DO_REG(2)
57 1057eaa7 pbrook
#endif
58 1057eaa7 pbrook
59 1057eaa7 pbrook
#undef SAVE_HOST_REGS
60 1057eaa7 pbrook
#undef DECLARE_HOST_REGS
61 1057eaa7 pbrook
#undef DO_REG