comparison portasm/portasm-x64.S @ 533:71c884e610f0

- integration of patches from Raphael Luba, Thekla, Inc.: * integration of aggregate-by-value (struct, union) support patch for x64 (win and sysv) * windows/x64 asm additions to specify how stack unwinds (help for debuggers, exception handling, etc.) * see Changelog for details - new calling convention modes for thiscalls (platform agnostic, was specific before) * new signature character for platform agnostic thiscalls ('*' / DC_SIGCHAR_CC_THISCALL) - dcCallF(), dcVCallF(), dcArgF() and dcVArgF(): * added support for aggregates-by-value (wasn't part of patch) * change that those functions don't implicitly call dcReset() anymore, which was unflexible (breaking change) - added macros to feature test implementation for aggregate-by-value and syscall support - changed libdyncall_s.lib and libdyncallback_s.lib order in callback test makefiles, as some toolchains are picky about order - doc: * man page updates to describe aggregate interface * manual overview changes to highlight platforms with aggregate-by-value support - test/plain: replaced tests w/ old/stale sctruct interface with new aggregate one
author Tassilo Philipp
date Thu, 21 Apr 2022 13:35:47 +0200
parents f5577f6bf97a
children 6a8aac9b2bcf
comparison
equal deleted inserted replaced
532:d4bf63ab9164 533:71c884e610f0
4 Library: portasm 4 Library: portasm
5 File: portasm/portasm-x64.S 5 File: portasm/portasm-x64.S
6 Description: Portable Assembler Macros for X64 6 Description: Portable Assembler Macros for X64
7 License: 7 License:
8 8
9 Copyright (c) 2011-2018 Daniel Adler <dadler@uni-goettingen.de> 9 Copyright (c) 2007-2022 Daniel Adler <dadler@uni-goettingen.de>,
10 Tassilo Philipp <tphilipp@potion-studios.com>
10 11
11 Permission to use, copy, modify, and distribute this software for any 12 Permission to use, copy, modify, and distribute this software for any
12 purpose with or without fee is hereby granted, provided that the above 13 purpose with or without fee is hereby granted, provided that the above
13 copyright notice and this permission notice appear in all copies. 14 copyright notice and this permission notice appear in all copies.
14 15
29 #if defined(GEN_MASM) 30 #if defined(GEN_MASM)
30 /* MASM syntax. */ 31 /* MASM syntax. */
31 .CODE 32 .CODE
32 # define BEGIN_ASM 33 # define BEGIN_ASM
33 # define END_ASM END 34 # define END_ASM END
34 # define GLOBAL(X) X PROC 35 # define CSYM(X) X
35 # define BEGIN_PROC(X) OPTION PROLOGUE:NONE, EPILOGUE:NONE 36 # define GLOBAL(X) X PROC
37 # define GLOBAL_FRAME(X) X PROC FRAME
38 # define BEGIN_PROC(X) OPTION PROLOGUE:NONE, EPILOGUE:NONE
39 # define FRAME_BEGIN_PROC(X) OPTION EPILOGUE:NONE
40 # define FRAME_SET(OFFSET, X) .setframe X, OFFSET
41 # define FRAME_PUSH_REG(X) .pushreg X
42 # define FRAME_ENDPROLOG() .endprolog
36 # define END_PROC(X) X ENDP 43 # define END_PROC(X) X ENDP
37 # define PUSH(R) push R 44 # define PUSH(R) push R
38 # define POP(R) pop R 45 # define POP(R) pop R
39 # define MOV(S,D) mov D,S 46 # define MOV(S,D) mov D,S
40 # define MOVB(S,D) mov D,S 47 # define MOVB(S,D) mov D,S
41 # define MOVL(S,D) mov D,S 48 # define MOVL(S,D) mov D,S
49 # define MOVZXQ(S,D) movzx D,S
42 # define ADDL(S,D) add D,S 50 # define ADDL(S,D) add D,S
43 # define ANDL(S,D) and D,S 51 # define ANDL(S,D) and D,S
44 # define SUBL(S,D) sub D,S 52 # define SUBL(S,D) sub D,S
45 # define SHRL(S,D) shr D,S 53 # define SHRL(S,D) shr D,S
46 # define MOVQ(S,D) movq D,S 54 # define SHLQ(S,D) shl D,S
47 # define ADD(S,D) add D,S 55 # define ADD(S,D) add D,S
48 # define AND(S,D) and D,S 56 # define AND(S,D) and D,S
49 # define SUB(S,D) sub D,S 57 # define SUB(S,D) sub D,S
50 # define SHR(S,D) shr D,S 58 # define SHR(S,D) shr D,S
51 # define MOVD(S,D) movd D,S 59 # define MOVD(S,D) movd D,S
60 # define XOR(S,D) xor D,S
52 # define RET() ret 61 # define RET() ret
53 # define CALL_DWORD(R,OFF) call DWORD(R,OFF) 62 # define CALL_DWORD(R,OFF) call DWORD(R,OFF)
54 # define REP(X) rep X 63 # define REP(X) rep X
55 # define MOVSB movsb 64 # define MOVSB movsb
56 # define MOVSW movsw 65 # define MOVSW movsw
57 # define MOVSD(S,D) movsd D,S 66 # define MOVSD(S,D) movsd D,S
58 # define MOVSDX(S,D) movsdx D,S 67 # define MOVSDX(S,D) movsdx D,S
68 # define BYTE(R) byte ptr [R]
59 # define DWORD(R,OFF) dword ptr [R+OFF] 69 # define DWORD(R,OFF) dword ptr [R+OFF]
60 # define QWORD(R,OFF) qword ptr [R+OFF] 70 # define QWORD(R,OFF) qword ptr [R+OFF]
61 # define LIT(X) X 71 # define LIT(X) X
62 # define INT(X) int X 72 # define INT(X) int X
63 # define HEX(X) XCONCAT(X,h) 73 # define HEX(X) XCONCAT(X,h)
65 # define CALL_REG(X) call X 75 # define CALL_REG(X) call X
66 # define LEA(S,D) lea D,S 76 # define LEA(S,D) lea D,S
67 # define SET(K,V) K = V 77 # define SET(K,V) K = V
68 # define JE(X) je X 78 # define JE(X) je X
69 # define JNE(X) jne X 79 # define JNE(X) jne X
70 # define CMP(A,B) cmp B,A 80 # define JMP(X) jmp X
81 # define CMPL(A,B) cmp B,A
71 # define LOCAL(X) X 82 # define LOCAL(X) X
72 /* @@@ check if masm support wanted/needed */ 83 /* @@@ check if masm support wanted/needed */
73 # define SECTION_NOTE_NXSTACK 84 # define SECTION_NOTE_NXSTACK
74 #else 85 #else
75 /* GNU/SunPro Assembler AT&T Syntax */ 86 /* GNU/SunPro Assembler AT&T Syntax */
89 # define RSI %rsi 100 # define RSI %rsi
90 # define RDI %rdi 101 # define RDI %rdi
91 # define RBP %rbp 102 # define RBP %rbp
92 # define RSP %rsp 103 # define RSP %rsp
93 # define R8 %r8 104 # define R8 %r8
105 # define R8D %r8d
94 # define R9 %r9 106 # define R9 %r9
95 # define R10 %r10 107 # define R10 %r10
96 # define R11 %r11 108 # define R11 %r11
97 # define R12 %r12 109 # define R12 %r12
98 # define R13 %r13 110 # define R13 %r13
112 # define BH %bh 124 # define BH %bh
113 # define CL %cl 125 # define CL %cl
114 # define CH %ch 126 # define CH %ch
115 # define DL %dl 127 # define DL %dl
116 # define DH %dh 128 # define DH %dh
117 # define GLOBAL(X) .globl CSYM(X) 129 # define GLOBAL(X) .globl CSYM(X)
118 # define BEGIN_PROC(X) CSYM(X): 130 # define GLOBAL_FRAME(X) .globl CSYM(X)
131 # define BEGIN_PROC(X) CSYM(X):
132 # define FRAME_BEGIN_PROC(X) CSYM(X):
133 # define FRAME_SET(OFFSET, X)
134 # define FRAME_PUSH_REG(X)
135 # define FRAME_ENDPROLOG()
119 # define END_PROC(X) 136 # define END_PROC(X)
120 # define PUSH(R) pushq R 137 # define PUSH(R) pushq R
121 # define POP(R) popq R 138 # define POP(R) popq R
122 # define MOV(S,D) movq S,D 139 # define MOV(S,D) movq S,D
123 # define MOVB(S,D) movb S,D 140 # define MOVB(S,D) movb S,D
124 # define MOVL(S,D) movl S,D 141 # define MOVL(S,D) movl S,D
142 # define MOVZXQ(S,D) movzbq S,D
125 # define ADDL(S,D) addl S,D 143 # define ADDL(S,D) addl S,D
126 # define ANDL(S,D) andl S,D 144 # define ANDL(S,D) andl S,D
127 # define SUBL(S,D) subl S,D 145 # define SUBL(S,D) subl S,D
128 # define SHRL(S,D) shrl S,D 146 # define SHRL(S,D) shrl S,D
129 # define MOVQ(S,D) movq S,D 147 # define SHLQ(S,D) shlq S,D
130 # define ADD(S,D) addq S,D 148 # define ADD(S,D) addq S,D
131 # define AND(S,D) andq S,D 149 # define AND(S,D) andq S,D
132 # define SUB(S,D) subq S,D 150 # define SUB(S,D) subq S,D
133 # define SHR(S,D) shrq S,D 151 # define SHR(S,D) shrq S,D
134 # define MOVD(S,D) movd S,D 152 # define MOVD(S,D) movd S,D
153 # define XOR(S,D) xorq S,D
135 # define RET() ret 154 # define RET() ret
136 # define CALL_DWORD(R,OFF) call *DWORD(R,OFF) 155 # define CALL_DWORD(R,OFF) call *DWORD(R,OFF)
137 # define REP(X) rep X 156 # define REP(X) rep X
138 # define MOVSB movsb 157 # define MOVSB movsb
139 # define MOVSW movsw 158 # define MOVSW movsw
140 # define MOVSD(S,D) movsd S,D 159 # define MOVSD(S,D) movsd S,D
160 # define BYTE(R) (R)
141 # define DWORD(R,OFF) OFF(R) 161 # define DWORD(R,OFF) OFF(R)
142 # define QWORD(R,OFF) OFF(R) 162 # define QWORD(R,OFF) OFF(R)
143 # define LIT(X) $X 163 # define LIT(X) $X
144 # define INT(X) int X 164 # define INT(X) int X
145 # define HEX(X) XCONCAT(0x,X) 165 # define HEX(X) XCONCAT(0x,X)
146 # define CALL(X) call X 166 # define CALL(X) call X
147 # define CALL_REG(X) call *X 167 # define CALL_REG(X) call *X
148 # define LEA(A,B) lea A,B 168 # define LEA(A,B) lea A,B
149 # define CMP(A,B) cmp A,B 169 # define CMPL(A,B) cmpl A,B
150 # define CMPB(A,B) cmpb A,B
151 # define JE(X) je X 170 # define JE(X) je X
152 # define JNE(X) jne X 171 # define JNE(X) jne X
172 # define JMP(X) jmp X
153 # define FLDS(X) flds X 173 # define FLDS(X) flds X
154 # define FLDL(X) fldl X 174 # define FLDL(X) fldl X
155 /* not available on some platforms, e.g. old solaris, so use K=V syntax # define SET(K,V) .set K,V */ 175 /* not available on some platforms, e.g. old solaris, so use K=V syntax # define SET(K,V) .set K,V */
156 # define SET(K,V) K = V 176 # define SET(K,V) K = V
157 # define LOCAL(X) .X 177 # define LOCAL(X) .X