1 /******************************** -*- C -*- ****************************
2  *
3  *	Platform-independent layer (i386 version)
4  *
5  ***********************************************************************/
6 
7 
8 /***********************************************************************
9  *
10  * Copyright 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
11  * Written by Paolo Bonzini.
12  *
13  * This file is part of GNU lightning.
14  *
15  * GNU lightning is free software; you can redistribute it and/or modify it
16  * under the terms of the GNU Lesser General Public License as published
17  * by the Free Software Foundation; either version 2.1, or (at your option)
18  * any later version.
19  *
20  * GNU lightning is distributed in the hope that it will be useful, but
21  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
22  * or  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
23  * License for more details.
24  *
25  * You should have received a copy of the GNU Lesser General Public License
26  * along with GNU lightning; see the file COPYING.LESSER; if not, write to the
27  * Free Software Foundation, 59 Temple Place - Suite 330, Boston,
28  * MA 02111-1307, USA.
29  *
30  ***********************************************************************/
31 
32 
33 
34 #ifndef __lightning_core_h
35 #define __lightning_core_h
36 
37 #include "core-i386.h"
38 
39 #define JIT_CAN_16 1
40 
41 struct jit_local_state {
42   int	framesize;
43   int	argssize;
44 };
45 
46 #define jit_base_prolog() (PUSHLr(_EBP), MOVLrr(_ESP, _EBP), PUSHLr(_EBX), PUSHLr(_ESI), PUSHLr(_EDI))
47 #define jit_prolog(n) (_jitl.framesize = 8, jit_base_prolog())
48 
49 /* The += allows for stack pollution */
50 
51 #ifdef __APPLE__
52   /* Stack must stay 16-byte aligned: */
53 # define jit_prepare_i(ni)	(((ni & 0x3) \
54                                   ? SUBLir(4 * ((((ni) + 3) & ~(0x3)) - (ni)), JIT_SP) \
55                                   : (void)0), \
56                                  _jitl.argssize += (((ni) + 3) & ~(0x3)))
57 #else
58 # define jit_prepare_i(ni)	(_jitl.argssize += (ni))
59 #endif
60 
61 #define jit_pusharg_i(rs)	PUSHLr(rs)
62 #define jit_finish(sub)        ((void)jit_calli((sub)), ADDLir(sizeof(long) * _jitl.argssize, JIT_SP), _jitl.argssize = 0)
63 #define jit_finishr(reg)	(jit_callr((reg)), ADDLir(sizeof(long) * _jitl.argssize, JIT_SP), _jitl.argssize = 0)
64 
65 #define	jit_arg_c()		((_jitl.framesize += sizeof(int)) - sizeof(int))
66 #define	jit_arg_uc()		((_jitl.framesize += sizeof(int)) - sizeof(int))
67 #define	jit_arg_s()		((_jitl.framesize += sizeof(int)) - sizeof(int))
68 #define	jit_arg_us()		((_jitl.framesize += sizeof(int)) - sizeof(int))
69 #define	jit_arg_i()		((_jitl.framesize += sizeof(int)) - sizeof(int))
70 #define	jit_arg_ui()		((_jitl.framesize += sizeof(int)) - sizeof(int))
71 #define	jit_arg_l()		((_jitl.framesize += sizeof(long)) - sizeof(long))
72 #define	jit_arg_ul()		((_jitl.framesize += sizeof(long)) - sizeof(long))
73 #define	jit_arg_p()		((_jitl.framesize += sizeof(long)) - sizeof(long))
74 
75 #define jit_patch_long_at(jump_pc,v)  (*_PSL((jump_pc) - sizeof(long)) = _jit_SL((jit_insn *)(v) - (jump_pc)))
76 #define jit_patch_at(jump_pc,v)  jit_patch_long_at(jump_pc, v)
77 #define jit_ret() (POPLr(_EDI), POPLr(_ESI), POPLr(_EBX), POPLr(_EBP), RET_())
78 
79 #endif /* __lightning_core_h */
80 
81