github.com/goccy/go-jit@v0.0.0-20200514131505-ff78d45cf6af/internal/ccall/include/jit/jit-arch-x86-64.h (about)

     1  /*
     2   * jit-arch-x86.h - Architecture-specific definitions.
     3   *
     4   * Copyright (C) 2008  Southern Storm Software, Pty Ltd.
     5   *
     6   * The libjit library is free software: you can redistribute it and/or
     7   * modify it under the terms of the GNU Lesser General Public License
     8   * as published by the Free Software Foundation, either version 2.1 of
     9   * the License, or (at your option) any later version.
    10   *
    11   * The libjit library is distributed in the hope that it will be useful,
    12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
    13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    14   * Lesser General Public License for more details.
    15   *
    16   * You should have received a copy of the GNU Lesser General Public
    17   * License along with the libjit library.  If not, see
    18   * <http://www.gnu.org/licenses/>.
    19   */
    20  
    21  #ifndef	_JIT_ARCH_X86_64_H
    22  #define	_JIT_ARCH_X86_64_H
    23  
    24  /*
    25   * The frame header structure for X86_64
    26   */
    27  typedef struct _jit_arch_frame _jit_arch_frame_t;
    28  struct _jit_arch_frame
    29  {
    30  	_jit_arch_frame_t *next_frame;
    31  	void *return_address;
    32  };
    33  
    34  /*
    35   * If defined _JIT_ARCH_GET_CURRENT_FRAME() macro assigns the current frame
    36   * pointer to the supplied argument that has to be a void pointer.
    37   */
    38  #if defined(__GNUC__)
    39  #define _JIT_ARCH_GET_CURRENT_FRAME(f)		\
    40  	do {					\
    41  		register void *__f asm("rbp");	\
    42  		f = __f;			\
    43  	} while(0)
    44  #elif defined(_MSC_VER) && defined(_M_IX86)
    45  #define	_JIT_ARCH_GET_CURRENT_FRAME(f)		\
    46  	do {					\
    47  		void *__ptr;			\
    48  		__asm				\
    49  		{				\
    50  			__asm mov qword ptr __ptr, rbp	\
    51  		}				\
    52  		(f) = __ptr;			\
    53  	} while(0)
    54  #else
    55  #undef _JIT_ARCH_GET_CURRENT_FRAME
    56  #endif
    57  
    58  /*
    59   * If defined _JIT_ARCH_GET_NEXT_FRAME() assigns the frame address following
    60   * the frame supplied as second arg to the value supplied as first argument.
    61   */
    62  #define _JIT_ARCH_GET_NEXT_FRAME(n, f)							\
    63  	do {										\
    64  		(n) = (void *)((f) ? ((_jit_arch_frame_t *)(f))->next_frame : 0);	\
    65  	} while(0)
    66  
    67  /*
    68   * If defined _JIT_ARCH_GET_RETURN_ADDRESS() assigns the return address of
    69   * the frame supplied as second arg to the value supplied as first argument.
    70   */
    71  #define _JIT_ARCH_GET_RETURN_ADDRESS(r, f)						\
    72  	do {										\
    73  		(r) = (void *)((f) ? ((_jit_arch_frame_t *)(f))->return_address : 0);	\
    74  	} while(0)
    75  
    76  /*
    77   * If defined _JIT_ARCH_GET_CURRENT_RETURN() assigns the return address of
    78   * the current to the supplied argument.
    79   */
    80  #define _JIT_ARCH_GET_CURRENT_RETURN(r)				\
    81  	do {							\
    82  		void *__frame;					\
    83  		_JIT_ARCH_GET_CURRENT_FRAME(__frame);		\
    84  		_JIT_ARCH_GET_RETURN_ADDRESS((r), __frame);	\
    85  	} while(0)
    86  
    87  #endif /* _JIT_ARCH_X86_64_H */