filename | src/xlat/x86/amd64abi.h |
changeset | 1146:76c5d1064262 |
prev | 1125:9dd5dee45db9 |
next | 1292:799fdd4f704a |
author | nkeynes |
date | Tue Nov 29 17:11:40 2011 +1000 (12 years ago) |
permissions | -rw-r--r-- |
last change | Add support for block linking when the block target is fixed. Only a small (~3% improvement) so far. |
view | annotate | diff | log | raw |
1 /**
2 * $Id$
3 *
4 * Provides the implementation for the AMD64 ABI (eg prologue, epilogue, and
5 * calling conventions)
6 *
7 * Copyright (c) 2007 Nathan Keynes.
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 */
20 #define REG_ARG1 REG_RDI
21 #define REG_ARG2 REG_RSI
22 #define REG_ARG3 REG_RDX
23 #define REG_RESULT1 REG_RAX
24 #define MAX_REG_ARG 3 /* There's more, but we don't use more than 3 here anyway */
26 static inline void decode_address( uintptr_t base, int addr_reg )
27 {
28 MOVL_r32_r32( addr_reg, REG_ECX );
29 SHRL_imm_r32( 12, REG_ECX );
30 MOVP_immptr_rptr( base, REG_RDI );
31 MOVP_sib_rptr( 3, REG_RCX, REG_RDI, 0, REG_RCX );
32 }
34 /**
35 * Note: clobbers ECX to make the indirect call - this isn't usually
36 * a problem since the callee will generally clobber it anyway.
37 * Size: 12 bytes
38 */
39 static inline void CALL_ptr( void *ptr )
40 {
41 MOVP_immptr_rptr( (uintptr_t)ptr, REG_ECX );
42 CALL_r32(REG_ECX);
43 }
45 #define CALL1_PTR_MIN_SIZE 12
46 static inline void CALL1_ptr_r32( void *ptr, int arg1 )
47 {
48 if( arg1 != REG_ARG1 ) {
49 MOVQ_r64_r64( arg1, REG_ARG1 );
50 }
51 CALL_ptr(ptr);
52 }
54 static inline void CALL1_r32disp_r32( int preg, uint32_t disp, int arg1 )
55 {
56 if( arg1 != REG_ARG1 ) {
57 MOVQ_r64_r64( arg1, REG_ARG1 );
58 }
59 CALL_r32disp(preg, disp);
60 }
62 static inline void CALL2_ptr_r32_r32( void *ptr, int arg1, int arg2 )
63 {
64 if( arg2 != REG_ARG2 ) {
65 MOVQ_r64_r64( arg2, REG_ARG2 );
66 }
67 if( arg1 != REG_ARG1 ) {
68 MOVQ_r64_r64( arg1, REG_ARG1 );
69 }
70 CALL_ptr(ptr);
71 }
73 static inline void CALL2_r32disp_r32_r32( int preg, uint32_t disp, int arg1, int arg2 )
74 {
75 if( arg2 != REG_ARG2 ) {
76 MOVQ_r64_r64( arg2, REG_ARG2 );
77 }
78 if( arg1 != REG_ARG1 ) {
79 MOVQ_r64_r64( arg1, REG_ARG1 );
80 }
81 CALL_r32disp(preg, disp);
82 }
84 static inline void CALL3_r32disp_r32_r32_r32( int preg, uint32_t disp, int arg1, int arg2, int arg3 )
85 {
86 if( arg3 != REG_ARG3 ) {
87 MOVQ_r64_r64( arg3, REG_ARG3 );
88 }
89 if( arg2 != REG_ARG2 ) {
90 MOVQ_r64_r64( arg2, REG_ARG2 );
91 }
92 if( arg1 != REG_ARG1 ) {
93 MOVQ_r64_r64( arg1, REG_ARG1 );
94 }
95 CALL_r32disp(preg, disp);
96 }
98 #define PROLOGUE_SIZE 15
100 /**
101 * Emit the 'start of block' assembly. Sets up the stack frame and save
102 * SI/DI as required
103 */
104 static inline void emit_prologue( )
105 {
106 PUSH_r32(REG_RBP);
107 SUBQ_imms_r64( 16, REG_RSP );
108 MOVP_immptr_rptr( ((uint8_t *)&sh4r) + 128, REG_EBP );
109 }
111 static inline void emit_epilogue( )
112 {
113 ADDQ_imms_r64( 16, REG_RSP );
114 POP_r32(REG_RBP);
115 }
.