Mercurial > pub > dyncall > dyncall
annotate portasm/portasm-x64.S @ 542:a73a5cd50c19
- fix passing aggregate-by-val on x64/sysv: subaggr classification for
aggr *arrays* was wrong (was problematic when there ware exactly 2 8bytes to
be classified, potentially be passed via registers)
author | Tassilo Philipp |
---|---|
date | Mon, 02 May 2022 15:32:41 +0200 |
parents | 71c884e610f0 |
children | 6a8aac9b2bcf |
rev | line source |
---|---|
0 | 1 /* |
2 | |
3 Package: dyncall | |
4 Library: portasm | |
165
572aff021627
- file name/layout cleanup, removed "-att" from x64 .S filenames, as unnecessary and also misleading
cslag
parents:
0
diff
changeset
|
5 File: portasm/portasm-x64.S |
0 | 6 Description: Portable Assembler Macros for X64 |
7 License: | |
8 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
9 Copyright (c) 2007-2022 Daniel Adler <dadler@uni-goettingen.de>, |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
10 Tassilo Philipp <tphilipp@potion-studios.com> |
0 | 11 |
12 Permission to use, copy, modify, and distribute this software for any | |
13 purpose with or without fee is hereby granted, provided that the above | |
14 copyright notice and this permission notice appear in all copies. | |
15 | |
16 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
17 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
18 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
19 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
20 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
21 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
22 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
23 | |
24 */ | |
25 | |
26 | |
27 | |
28 /* Common macros. */ | |
29 #define XCONCAT(A,B) A##B | |
30 #if defined(GEN_MASM) | |
31 /* MASM syntax. */ | |
32 .CODE | |
33 # define BEGIN_ASM | |
34 # define END_ASM END | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
35 # define CSYM(X) X |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
36 # define GLOBAL(X) X PROC |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
37 # define GLOBAL_FRAME(X) X PROC FRAME |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
38 # define BEGIN_PROC(X) OPTION PROLOGUE:NONE, EPILOGUE:NONE |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
39 # define FRAME_BEGIN_PROC(X) OPTION EPILOGUE:NONE |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
40 # define FRAME_SET(OFFSET, X) .setframe X, OFFSET |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
41 # define FRAME_PUSH_REG(X) .pushreg X |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
42 # define FRAME_ENDPROLOG() .endprolog |
0 | 43 # define END_PROC(X) X ENDP |
44 # define PUSH(R) push R | |
45 # define POP(R) pop R | |
46 # define MOV(S,D) mov D,S | |
47 # define MOVB(S,D) mov D,S | |
48 # define MOVL(S,D) mov D,S | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
49 # define MOVZXQ(S,D) movzx D,S |
0 | 50 # define ADDL(S,D) add D,S |
51 # define ANDL(S,D) and D,S | |
52 # define SUBL(S,D) sub D,S | |
53 # define SHRL(S,D) shr D,S | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
54 # define SHLQ(S,D) shl D,S |
0 | 55 # define ADD(S,D) add D,S |
56 # define AND(S,D) and D,S | |
57 # define SUB(S,D) sub D,S | |
58 # define SHR(S,D) shr D,S | |
59 # define MOVD(S,D) movd D,S | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
60 # define XOR(S,D) xor D,S |
0 | 61 # define RET() ret |
62 # define CALL_DWORD(R,OFF) call DWORD(R,OFF) | |
63 # define REP(X) rep X | |
64 # define MOVSB movsb | |
65 # define MOVSW movsw | |
66 # define MOVSD(S,D) movsd D,S | |
67 # define MOVSDX(S,D) movsdx D,S | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
68 # define BYTE(R) byte ptr [R] |
0 | 69 # define DWORD(R,OFF) dword ptr [R+OFF] |
70 # define QWORD(R,OFF) qword ptr [R+OFF] | |
71 # define LIT(X) X | |
72 # define INT(X) int X | |
73 # define HEX(X) XCONCAT(X,h) | |
74 # define CALL(X) call X | |
75 # define CALL_REG(X) call X | |
76 # define LEA(S,D) lea D,S | |
77 # define SET(K,V) K = V | |
78 # define JE(X) je X | |
79 # define JNE(X) jne X | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
80 # define JMP(X) jmp X |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
81 # define CMPL(A,B) cmp B,A |
0 | 82 # define LOCAL(X) X |
166
d5705f226298
- added portasm support for adding .section .note.GNU-stack "hints" marking generated .o files from assembly files as not needing an executable stack
cslag
parents:
165
diff
changeset
|
83 /* @@@ check if masm support wanted/needed */ |
d5705f226298
- added portasm support for adding .section .note.GNU-stack "hints" marking generated .o files from assembly files as not needing an executable stack
cslag
parents:
165
diff
changeset
|
84 # define SECTION_NOTE_NXSTACK |
0 | 85 #else |
86 /* GNU/SunPro Assembler AT&T Syntax */ | |
87 .text | |
88 # define BEGIN_ASM | |
89 # define END_ASM | |
168
2bce7629f541
- "tag" also non-linux assembly files with .note.GNU-stack, to mark .o files generated from manual assembly code as not needing an executable stack (still only for x* archs)
cslag
parents:
166
diff
changeset
|
90 # include "../autovar/autovar_ABI.h" |
0 | 91 # if defined (OS_Darwin) |
92 # define CSYM(X) _##X | |
93 # else | |
94 # define CSYM(X) X | |
95 # endif | |
96 # define RAX %rax | |
97 # define RBX %rbx | |
98 # define RCX %rcx | |
99 # define RDX %rdx | |
100 # define RSI %rsi | |
101 # define RDI %rdi | |
102 # define RBP %rbp | |
103 # define RSP %rsp | |
104 # define R8 %r8 | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
105 # define R8D %r8d |
0 | 106 # define R9 %r9 |
107 # define R10 %r10 | |
108 # define R11 %r11 | |
109 # define R12 %r12 | |
110 # define R13 %r13 | |
111 # define R14 %r14 | |
112 # define R15 %r15 | |
113 # define XMM0 %xmm0 | |
114 # define XMM1 %xmm1 | |
115 # define XMM2 %xmm2 | |
116 # define XMM3 %xmm3 | |
117 # define XMM4 %xmm4 | |
118 # define XMM5 %xmm5 | |
119 # define XMM6 %xmm6 | |
120 # define XMM7 %xmm7 | |
121 # define AL %al | |
122 # define AH %ah | |
123 # define BL %bl | |
124 # define BH %bh | |
125 # define CL %cl | |
126 # define CH %ch | |
127 # define DL %dl | |
128 # define DH %dh | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
129 # define GLOBAL(X) .globl CSYM(X) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
130 # define GLOBAL_FRAME(X) .globl CSYM(X) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
131 # define BEGIN_PROC(X) CSYM(X): |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
132 # define FRAME_BEGIN_PROC(X) CSYM(X): |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
133 # define FRAME_SET(OFFSET, X) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
134 # define FRAME_PUSH_REG(X) |
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
135 # define FRAME_ENDPROLOG() |
0 | 136 # define END_PROC(X) |
137 # define PUSH(R) pushq R | |
138 # define POP(R) popq R | |
139 # define MOV(S,D) movq S,D | |
140 # define MOVB(S,D) movb S,D | |
141 # define MOVL(S,D) movl S,D | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
142 # define MOVZXQ(S,D) movzbq S,D |
0 | 143 # define ADDL(S,D) addl S,D |
144 # define ANDL(S,D) andl S,D | |
145 # define SUBL(S,D) subl S,D | |
146 # define SHRL(S,D) shrl S,D | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
147 # define SHLQ(S,D) shlq S,D |
0 | 148 # define ADD(S,D) addq S,D |
149 # define AND(S,D) andq S,D | |
150 # define SUB(S,D) subq S,D | |
151 # define SHR(S,D) shrq S,D | |
152 # define MOVD(S,D) movd S,D | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
153 # define XOR(S,D) xorq S,D |
0 | 154 # define RET() ret |
155 # define CALL_DWORD(R,OFF) call *DWORD(R,OFF) | |
156 # define REP(X) rep X | |
157 # define MOVSB movsb | |
158 # define MOVSW movsw | |
159 # define MOVSD(S,D) movsd S,D | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
160 # define BYTE(R) (R) |
0 | 161 # define DWORD(R,OFF) OFF(R) |
162 # define QWORD(R,OFF) OFF(R) | |
163 # define LIT(X) $X | |
164 # define INT(X) int X | |
165 # define HEX(X) XCONCAT(0x,X) | |
166 # define CALL(X) call X | |
167 # define CALL_REG(X) call *X | |
168 # define LEA(A,B) lea A,B | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
169 # define CMPL(A,B) cmpl A,B |
0 | 170 # define JE(X) je X |
171 # define JNE(X) jne X | |
533
71c884e610f0
- integration of patches from Raphael Luba, Thekla, Inc.:
Tassilo Philipp
parents:
281
diff
changeset
|
172 # define JMP(X) jmp X |
0 | 173 # define FLDS(X) flds X |
174 # define FLDL(X) fldl X | |
249
91db39538e78
- replaced `.set' directives used to set symbol values in assembly files with (seemingly) more portable `=' syntax (e.g. older versions of Sun's `as' don't handle `.set')
Tassilo Philipp
parents:
182
diff
changeset
|
175 /* not available on some platforms, e.g. old solaris, so use K=V syntax # define SET(K,V) .set K,V */ |
91db39538e78
- replaced `.set' directives used to set symbol values in assembly files with (seemingly) more portable `=' syntax (e.g. older versions of Sun's `as' don't handle `.set')
Tassilo Philipp
parents:
182
diff
changeset
|
176 # define SET(K,V) K = V |
0 | 177 # define LOCAL(X) .X |
178 #endif | |
179 |