diff options
author | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2021-12-27 00:00:00 +0000 |
---|---|---|
committer | Igor Pavlov <87184205+ip7z@users.noreply.github.com> | 2022-03-18 15:35:13 +0500 |
commit | f19f813537c7aea1c20749c914e756b54a9c3cf5 (patch) | |
tree | 816ba62ca7c0fa19f2eb46d9e9d6f7dd7c3a744d /Asm/x86/7zAsm.asm | |
parent | 98e06a519b63b81986abe76d28887f6984a7732b (diff) | |
download | 7zip-21.07.tar.gz 7zip-21.07.tar.bz2 7zip-21.07.zip |
'21.07'21.07
Diffstat (limited to 'Asm/x86/7zAsm.asm')
-rw-r--r-- | Asm/x86/7zAsm.asm | 284 |
1 files changed, 284 insertions, 0 deletions
diff --git a/Asm/x86/7zAsm.asm b/Asm/x86/7zAsm.asm new file mode 100644 index 0000000..6275bb7 --- /dev/null +++ b/Asm/x86/7zAsm.asm | |||
@@ -0,0 +1,284 @@ | |||
1 | ; 7zAsm.asm -- ASM macros | ||
2 | ; 2021-12-25 : Igor Pavlov : Public domain | ||
3 | |||
4 | |||
5 | ifdef @wordsize | ||
6 | ; @wordsize is defined only in JWASM and ASMC and is not defined in MASM | ||
7 | ; @wordsize eq 8 for 64-bit x64 | ||
8 | ; @wordsize eq 2 for 32-bit x86 | ||
9 | if @wordsize eq 8 | ||
10 | x64 equ 1 | ||
11 | endif | ||
12 | else | ||
13 | ifdef RAX | ||
14 | x64 equ 1 | ||
15 | endif | ||
16 | endif | ||
17 | |||
18 | |||
19 | ifdef x64 | ||
20 | IS_X64 equ 1 | ||
21 | else | ||
22 | IS_X64 equ 0 | ||
23 | endif | ||
24 | |||
25 | ifdef ABI_LINUX | ||
26 | IS_LINUX equ 1 | ||
27 | else | ||
28 | IS_LINUX equ 0 | ||
29 | endif | ||
30 | |||
31 | ifndef x64 | ||
32 | ; Use ABI_CDECL for x86 (32-bit) only | ||
33 | ; if ABI_CDECL is not defined, we use fastcall abi | ||
34 | ifdef ABI_CDECL | ||
35 | IS_CDECL equ 1 | ||
36 | else | ||
37 | IS_CDECL equ 0 | ||
38 | endif | ||
39 | endif | ||
40 | |||
41 | OPTION PROLOGUE:NONE | ||
42 | OPTION EPILOGUE:NONE | ||
43 | |||
44 | MY_ASM_START macro | ||
45 | ifdef x64 | ||
46 | .code | ||
47 | else | ||
48 | .386 | ||
49 | .model flat | ||
50 | _TEXT$00 SEGMENT PARA PUBLIC 'CODE' | ||
51 | endif | ||
52 | endm | ||
53 | |||
54 | MY_PROC macro name:req, numParams:req | ||
55 | align 16 | ||
56 | proc_numParams = numParams | ||
57 | if (IS_X64 gt 0) | ||
58 | proc_name equ name | ||
59 | elseif (IS_LINUX gt 0) | ||
60 | proc_name equ name | ||
61 | elseif (IS_CDECL gt 0) | ||
62 | proc_name equ @CatStr(_,name) | ||
63 | else | ||
64 | proc_name equ @CatStr(@,name,@, %numParams * 4) | ||
65 | endif | ||
66 | proc_name PROC | ||
67 | endm | ||
68 | |||
69 | MY_ENDP macro | ||
70 | if (IS_X64 gt 0) | ||
71 | ret | ||
72 | elseif (IS_CDECL gt 0) | ||
73 | ret | ||
74 | elseif (proc_numParams LT 3) | ||
75 | ret | ||
76 | else | ||
77 | ret (proc_numParams - 2) * 4 | ||
78 | endif | ||
79 | proc_name ENDP | ||
80 | endm | ||
81 | |||
82 | |||
83 | ifdef x64 | ||
84 | REG_SIZE equ 8 | ||
85 | REG_LOGAR_SIZE equ 3 | ||
86 | else | ||
87 | REG_SIZE equ 4 | ||
88 | REG_LOGAR_SIZE equ 2 | ||
89 | endif | ||
90 | |||
91 | x0 equ EAX | ||
92 | x1 equ ECX | ||
93 | x2 equ EDX | ||
94 | x3 equ EBX | ||
95 | x4 equ ESP | ||
96 | x5 equ EBP | ||
97 | x6 equ ESI | ||
98 | x7 equ EDI | ||
99 | |||
100 | x0_W equ AX | ||
101 | x1_W equ CX | ||
102 | x2_W equ DX | ||
103 | x3_W equ BX | ||
104 | |||
105 | x5_W equ BP | ||
106 | x6_W equ SI | ||
107 | x7_W equ DI | ||
108 | |||
109 | x0_L equ AL | ||
110 | x1_L equ CL | ||
111 | x2_L equ DL | ||
112 | x3_L equ BL | ||
113 | |||
114 | x0_H equ AH | ||
115 | x1_H equ CH | ||
116 | x2_H equ DH | ||
117 | x3_H equ BH | ||
118 | |||
119 | ifdef x64 | ||
120 | x5_L equ BPL | ||
121 | x6_L equ SIL | ||
122 | x7_L equ DIL | ||
123 | |||
124 | r0 equ RAX | ||
125 | r1 equ RCX | ||
126 | r2 equ RDX | ||
127 | r3 equ RBX | ||
128 | r4 equ RSP | ||
129 | r5 equ RBP | ||
130 | r6 equ RSI | ||
131 | r7 equ RDI | ||
132 | x8 equ r8d | ||
133 | x9 equ r9d | ||
134 | x10 equ r10d | ||
135 | x11 equ r11d | ||
136 | x12 equ r12d | ||
137 | x13 equ r13d | ||
138 | x14 equ r14d | ||
139 | x15 equ r15d | ||
140 | else | ||
141 | r0 equ x0 | ||
142 | r1 equ x1 | ||
143 | r2 equ x2 | ||
144 | r3 equ x3 | ||
145 | r4 equ x4 | ||
146 | r5 equ x5 | ||
147 | r6 equ x6 | ||
148 | r7 equ x7 | ||
149 | endif | ||
150 | |||
151 | |||
152 | ifdef x64 | ||
153 | ifdef ABI_LINUX | ||
154 | |||
155 | MY_PUSH_2_REGS macro | ||
156 | push r3 | ||
157 | push r5 | ||
158 | endm | ||
159 | |||
160 | MY_POP_2_REGS macro | ||
161 | pop r5 | ||
162 | pop r3 | ||
163 | endm | ||
164 | |||
165 | endif | ||
166 | endif | ||
167 | |||
168 | |||
169 | MY_PUSH_4_REGS macro | ||
170 | push r3 | ||
171 | push r5 | ||
172 | push r6 | ||
173 | push r7 | ||
174 | endm | ||
175 | |||
176 | MY_POP_4_REGS macro | ||
177 | pop r7 | ||
178 | pop r6 | ||
179 | pop r5 | ||
180 | pop r3 | ||
181 | endm | ||
182 | |||
183 | |||
184 | ; for fastcall and for WIN-x64 | ||
185 | REG_PARAM_0_x equ x1 | ||
186 | REG_PARAM_0 equ r1 | ||
187 | REG_PARAM_1_x equ x2 | ||
188 | REG_PARAM_1 equ r2 | ||
189 | |||
190 | ifndef x64 | ||
191 | ; for x86-fastcall | ||
192 | |||
193 | REG_ABI_PARAM_0_x equ REG_PARAM_0_x | ||
194 | REG_ABI_PARAM_0 equ REG_PARAM_0 | ||
195 | REG_ABI_PARAM_1_x equ REG_PARAM_1_x | ||
196 | REG_ABI_PARAM_1 equ REG_PARAM_1 | ||
197 | |||
198 | else | ||
199 | ; x64 | ||
200 | |||
201 | if (IS_LINUX eq 0) | ||
202 | |||
203 | ; for WIN-x64: | ||
204 | REG_PARAM_2_x equ x8 | ||
205 | REG_PARAM_2 equ r8 | ||
206 | REG_PARAM_3 equ r9 | ||
207 | |||
208 | REG_ABI_PARAM_0_x equ REG_PARAM_0_x | ||
209 | REG_ABI_PARAM_0 equ REG_PARAM_0 | ||
210 | REG_ABI_PARAM_1_x equ REG_PARAM_1_x | ||
211 | REG_ABI_PARAM_1 equ REG_PARAM_1 | ||
212 | REG_ABI_PARAM_2_x equ REG_PARAM_2_x | ||
213 | REG_ABI_PARAM_2 equ REG_PARAM_2 | ||
214 | REG_ABI_PARAM_3 equ REG_PARAM_3 | ||
215 | |||
216 | else | ||
217 | ; for LINUX-x64: | ||
218 | REG_LINUX_PARAM_0_x equ x7 | ||
219 | REG_LINUX_PARAM_0 equ r7 | ||
220 | REG_LINUX_PARAM_1_x equ x6 | ||
221 | REG_LINUX_PARAM_1 equ r6 | ||
222 | REG_LINUX_PARAM_2 equ r2 | ||
223 | REG_LINUX_PARAM_3 equ r1 | ||
224 | REG_LINUX_PARAM_4_x equ x8 | ||
225 | REG_LINUX_PARAM_4 equ r8 | ||
226 | REG_LINUX_PARAM_5 equ r9 | ||
227 | |||
228 | REG_ABI_PARAM_0_x equ REG_LINUX_PARAM_0_x | ||
229 | REG_ABI_PARAM_0 equ REG_LINUX_PARAM_0 | ||
230 | REG_ABI_PARAM_1_x equ REG_LINUX_PARAM_1_x | ||
231 | REG_ABI_PARAM_1 equ REG_LINUX_PARAM_1 | ||
232 | REG_ABI_PARAM_2 equ REG_LINUX_PARAM_2 | ||
233 | REG_ABI_PARAM_3 equ REG_LINUX_PARAM_3 | ||
234 | REG_ABI_PARAM_4_x equ REG_LINUX_PARAM_4_x | ||
235 | REG_ABI_PARAM_4 equ REG_LINUX_PARAM_4 | ||
236 | REG_ABI_PARAM_5 equ REG_LINUX_PARAM_5 | ||
237 | |||
238 | MY_ABI_LINUX_TO_WIN_2 macro | ||
239 | mov r2, r6 | ||
240 | mov r1, r7 | ||
241 | endm | ||
242 | |||
243 | MY_ABI_LINUX_TO_WIN_3 macro | ||
244 | mov r8, r2 | ||
245 | mov r2, r6 | ||
246 | mov r1, r7 | ||
247 | endm | ||
248 | |||
249 | MY_ABI_LINUX_TO_WIN_4 macro | ||
250 | mov r9, r1 | ||
251 | mov r8, r2 | ||
252 | mov r2, r6 | ||
253 | mov r1, r7 | ||
254 | endm | ||
255 | |||
256 | endif ; IS_LINUX | ||
257 | |||
258 | |||
259 | MY_PUSH_PRESERVED_ABI_REGS macro | ||
260 | if (IS_LINUX gt 0) | ||
261 | MY_PUSH_2_REGS | ||
262 | else | ||
263 | MY_PUSH_4_REGS | ||
264 | endif | ||
265 | push r12 | ||
266 | push r13 | ||
267 | push r14 | ||
268 | push r15 | ||
269 | endm | ||
270 | |||
271 | |||
272 | MY_POP_PRESERVED_ABI_REGS macro | ||
273 | pop r15 | ||
274 | pop r14 | ||
275 | pop r13 | ||
276 | pop r12 | ||
277 | if (IS_LINUX gt 0) | ||
278 | MY_POP_2_REGS | ||
279 | else | ||
280 | MY_POP_4_REGS | ||
281 | endif | ||
282 | endm | ||
283 | |||
284 | endif ; x64 | ||