filename | src/xlat/x86/amd64abi.h |
changeset | 1067:d3c00ffccfcd |
prev | 944:a4e31314bee1 |
prev | 1065:bc1cc0c54917 |
next | 1112:4cac5e474d4c |
author | nkeynes |
date | Sun Jul 05 13:54:48 2009 +1000 (14 years ago) |
permissions | -rw-r--r-- |
last change | No-op merge lxdream-mem to tip to remove head (Long since merged in actuality) |
file | annotate | diff | log | raw |
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +00001.2 +++ b/src/xlat/x86/amd64abi.h Sun Jul 05 13:54:48 2009 +10001.3 @@ -0,0 +1,112 @@1.4 +/**1.5 + * $Id$1.6 + *1.7 + * Provides the implementation for the AMD64 ABI (eg prologue, epilogue, and1.8 + * calling conventions)1.9 + *1.10 + * Copyright (c) 2007 Nathan Keynes.1.11 + *1.12 + * This program is free software; you can redistribute it and/or modify1.13 + * it under the terms of the GNU General Public License as published by1.14 + * the Free Software Foundation; either version 2 of the License, or1.15 + * (at your option) any later version.1.16 + *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 of1.19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the1.20 + * GNU General Public License for more details.1.21 + */1.22 +1.23 +#define REG_ARG1 REG_RDI1.24 +#define REG_ARG2 REG_RSI1.25 +#define REG_ARG3 REG_RDX1.26 +#define REG_RESULT1 REG_RAX1.27 +#define MAX_REG_ARG 3 /* There's more, but we don't use more than 3 here anyway */1.28 +1.29 +static inline void decode_address( uintptr_t base, int addr_reg )1.30 +{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.35 +}1.36 +1.37 +/**1.38 + * Note: clobbers ECX to make the indirect call - this isn't usually1.39 + * a problem since the callee will generally clobber it anyway.1.40 + * Size: 12 bytes1.41 + */1.42 +static inline void CALL_ptr( void *ptr )1.43 +{1.44 + MOVP_immptr_rptr( (uintptr_t)ptr, REG_ECX );1.45 + CALL_r32(REG_ECX);1.46 +}1.47 +1.48 +static inline void CALL1_ptr_r32( void *ptr, int arg1 )1.49 +{1.50 + if( arg1 != REG_ARG1 ) {1.51 + MOVQ_r64_r64( arg1, REG_ARG1 );1.52 + }1.53 + CALL_ptr(ptr);1.54 +}1.55 +1.56 +static inline void CALL1_r32disp_r32( int preg, uint32_t disp, int arg1 )1.57 +{1.58 + if( arg1 != REG_ARG1 ) {1.59 + MOVQ_r64_r64( arg1, REG_ARG1 );1.60 + }1.61 + CALL_r32disp(preg, disp);1.62 +}1.63 +1.64 +static inline void CALL2_ptr_r32_r32( void *ptr, int arg1, int arg2 )1.65 +{1.66 + if( arg2 != REG_ARG2 ) {1.67 + MOVQ_r64_r64( arg2, REG_ARG2 );1.68 + }1.69 + if( arg1 != REG_ARG1 ) {1.70 + MOVQ_r64_r64( arg1, REG_ARG1 );1.71 + }1.72 + CALL_ptr(ptr);1.73 +}1.74 +1.75 +static inline void CALL2_r32disp_r32_r32( int preg, uint32_t disp, int arg1, int arg2 )1.76 +{1.77 + if( arg2 != REG_ARG2 ) {1.78 + MOVQ_r64_r64( arg2, REG_ARG2 );1.79 + }1.80 + if( arg1 != REG_ARG1 ) {1.81 + MOVQ_r64_r64( arg1, REG_ARG1 );1.82 + }1.83 + CALL_r32disp(preg, disp);1.84 +}1.85 +1.86 +static inline void CALL3_r32disp_r32_r32_r32( int preg, uint32_t disp, int arg1, int arg2, int arg3 )1.87 +{1.88 + if( arg3 != REG_ARG3 ) {1.89 + MOVQ_r64_r64( arg3, REG_ARG3 );1.90 + }1.91 + if( arg2 != REG_ARG2 ) {1.92 + MOVQ_r64_r64( arg2, REG_ARG2 );1.93 + }1.94 + if( arg1 != REG_ARG1 ) {1.95 + MOVQ_r64_r64( arg1, REG_ARG1 );1.96 + }1.97 + CALL_r32disp(preg, disp);1.98 +}1.99 +1.100 +/**1.101 + * Emit the 'start of block' assembly. Sets up the stack frame and save1.102 + * SI/DI as required1.103 + */1.104 +static inline void enter_block( )1.105 +{1.106 + PUSH_r32(REG_RBP);1.107 + SUBQ_imms_r64( 16, REG_RSP );1.108 +}1.109 +1.110 +static inline void exit_block( )1.111 +{1.112 + ADDQ_imms_r64( 16, REG_RSP );1.113 + POP_r32(REG_RBP);1.114 + RET();1.115 +}
.