filename | src/xlat/x86/amd64abi.h |
changeset | 1125:9dd5dee45db9 |
prev | 1112:4cac5e474d4c |
next | 1146:76c5d1064262 |
author | nkeynes |
date | Mon Sep 13 10:13:42 2010 +1000 (13 years ago) |
permissions | -rw-r--r-- |
last change | Implement shadow-execution 'core' to run translator + interpreter side by side (for testing) |
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 static inline void CALL1_ptr_r32( void *ptr, int arg1 )
46 {
47 if( arg1 != REG_ARG1 ) {
48 MOVQ_r64_r64( arg1, REG_ARG1 );
49 }
50 CALL_ptr(ptr);
51 }
53 static inline void CALL1_r32disp_r32( int preg, uint32_t disp, int arg1 )
54 {
55 if( arg1 != REG_ARG1 ) {
56 MOVQ_r64_r64( arg1, REG_ARG1 );
57 }
58 CALL_r32disp(preg, disp);
59 }
61 static inline void CALL2_ptr_r32_r32( void *ptr, int arg1, int arg2 )
62 {
63 if( arg2 != REG_ARG2 ) {
64 MOVQ_r64_r64( arg2, REG_ARG2 );
65 }
66 if( arg1 != REG_ARG1 ) {
67 MOVQ_r64_r64( arg1, REG_ARG1 );
68 }
69 CALL_ptr(ptr);
70 }
72 static inline void CALL2_r32disp_r32_r32( int preg, uint32_t disp, int arg1, int arg2 )
73 {
74 if( arg2 != REG_ARG2 ) {
75 MOVQ_r64_r64( arg2, REG_ARG2 );
76 }
77 if( arg1 != REG_ARG1 ) {
78 MOVQ_r64_r64( arg1, REG_ARG1 );
79 }
80 CALL_r32disp(preg, disp);
81 }
83 static inline void CALL3_r32disp_r32_r32_r32( int preg, uint32_t disp, int arg1, int arg2, int arg3 )
84 {
85 if( arg3 != REG_ARG3 ) {
86 MOVQ_r64_r64( arg3, REG_ARG3 );
87 }
88 if( arg2 != REG_ARG2 ) {
89 MOVQ_r64_r64( arg2, REG_ARG2 );
90 }
91 if( arg1 != REG_ARG1 ) {
92 MOVQ_r64_r64( arg1, REG_ARG1 );
93 }
94 CALL_r32disp(preg, disp);
95 }
97 #define PROLOGUE_SIZE 15
99 /**
100 * Emit the 'start of block' assembly. Sets up the stack frame and save
101 * SI/DI as required
102 */
103 static inline void emit_prologue( )
104 {
105 PUSH_r32(REG_RBP);
106 SUBQ_imms_r64( 16, REG_RSP );
107 MOVP_immptr_rptr( ((uint8_t *)&sh4r) + 128, REG_EBP );
108 }
110 static inline void emit_epilogue( )
111 {
112 ADDQ_imms_r64( 16, REG_RSP );
113 POP_r32(REG_RBP);
114 }
.