1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/xlat/x86/amd64abi.h Sun Jul 05 13:52:50 2009 +1000
1.7 + * Provides the implementation for the AMD64 ABI (eg prologue, epilogue, and
1.8 + * calling conventions)
1.10 + * Copyright (c) 2007 Nathan Keynes.
1.12 + * This program is free software; you can redistribute it and/or modify
1.13 + * it under the terms of the GNU General Public License as published by
1.14 + * the Free Software Foundation; either version 2 of the License, or
1.15 + * (at your option) any later version.
1.17 + * This program is distributed in the hope that it will be useful,
1.18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.20 + * GNU General Public License for more details.
1.23 +#define REG_ARG1 REG_RDI
1.24 +#define REG_ARG2 REG_RSI
1.25 +#define REG_ARG3 REG_RDX
1.26 +#define REG_RESULT1 REG_RAX
1.27 +#define MAX_REG_ARG 3 /* There's more, but we don't use more than 3 here anyway */
1.29 +static inline void decode_address( uintptr_t base, int addr_reg )
1.31 + MOVL_r32_r32( addr_reg, REG_ECX );
1.32 + SHRL_imm_r32( 12, REG_ECX );
1.33 + MOVP_immptr_rptr( base, REG_RDI );
1.34 + MOVP_sib_rptr( 3, REG_RCX, REG_RDI, 0, REG_RCX );
1.38 + * Note: clobbers ECX to make the indirect call - this isn't usually
1.39 + * a problem since the callee will generally clobber it anyway.
1.42 +static inline void CALL_ptr( void *ptr )
1.44 + MOVP_immptr_rptr( (uintptr_t)ptr, REG_ECX );
1.45 + CALL_r32(REG_ECX);
1.48 +static inline void CALL1_ptr_r32( void *ptr, int arg1 )
1.50 + if( arg1 != REG_ARG1 ) {
1.51 + MOVQ_r64_r64( arg1, REG_ARG1 );
1.56 +static inline void CALL1_r32disp_r32( int preg, uint32_t disp, int arg1 )
1.58 + if( arg1 != REG_ARG1 ) {
1.59 + MOVQ_r64_r64( arg1, REG_ARG1 );
1.61 + CALL_r32disp(preg, disp);
1.64 +static inline void CALL2_ptr_r32_r32( void *ptr, int arg1, int arg2 )
1.66 + if( arg2 != REG_ARG2 ) {
1.67 + MOVQ_r64_r64( arg2, REG_ARG2 );
1.69 + if( arg1 != REG_ARG1 ) {
1.70 + MOVQ_r64_r64( arg1, REG_ARG1 );
1.75 +static inline void CALL2_r32disp_r32_r32( int preg, uint32_t disp, int arg1, int arg2 )
1.77 + if( arg2 != REG_ARG2 ) {
1.78 + MOVQ_r64_r64( arg2, REG_ARG2 );
1.80 + if( arg1 != REG_ARG1 ) {
1.81 + MOVQ_r64_r64( arg1, REG_ARG1 );
1.83 + CALL_r32disp(preg, disp);
1.86 +static inline void CALL3_r32disp_r32_r32_r32( int preg, uint32_t disp, int arg1, int arg2, int arg3 )
1.88 + if( arg3 != REG_ARG3 ) {
1.89 + MOVQ_r64_r64( arg3, REG_ARG3 );
1.91 + if( arg2 != REG_ARG2 ) {
1.92 + MOVQ_r64_r64( arg2, REG_ARG2 );
1.94 + if( arg1 != REG_ARG1 ) {
1.95 + MOVQ_r64_r64( arg1, REG_ARG1 );
1.97 + CALL_r32disp(preg, disp);
1.101 + * Emit the 'start of block' assembly. Sets up the stack frame and save
1.102 + * SI/DI as required
1.104 +static inline void enter_block( )
1.106 + PUSH_r32(REG_RBP);
1.107 + SUBQ_imms_r64( 16, REG_RSP );
1.110 +static inline void exit_block( )
1.112 + ADDQ_imms_r64( 16, REG_RSP );
1.113 + POP_r32(REG_RBP);