Rev 8978 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2288 | clevermous | 1 | |
2 | |||
3 | |||
8965 | Boppan | 4 | ; @param proc Callee name |
5 | ; @param arg Arguments to pass |
||
6 | macro stdcall proc,[arg] |
||
7 | { common |
||
2288 | clevermous | 8 | if ~ arg eq |
9 | reverse |
||
10 | pushd arg |
||
11 | common |
||
12 | end if |
||
13 | call proc } |
||
14 | |||
15 | |||
8969 | Boppan | 16 | ; @param proc Callee name |
17 | ; @param arg Arguments to pass |
||
18 | macro invoke proc,[arg] |
||
19 | { common |
||
2288 | clevermous | 20 | if ~ arg eq |
21 | reverse |
||
22 | pushd arg |
||
23 | common |
||
24 | end if |
||
25 | call [proc] } |
||
26 | |||
27 | |||
8970 | Boppan | 28 | ; @param proc Callee name |
29 | ; @param arg Arguments to pass |
||
30 | macro ccall proc,[arg] |
||
31 | { common |
||
2288 | clevermous | 32 | size@ccall = 0 |
33 | if ~ arg eq |
||
34 | reverse |
||
35 | pushd arg |
||
36 | size@ccall = size@ccall+4 |
||
37 | common |
||
38 | end if |
||
39 | call proc |
||
40 | if size@ccall |
||
41 | add esp, size@ccall |
||
42 | end if } |
||
43 | |||
44 | |||
8971 | Boppan | 45 | ; @param proc Callee name |
46 | ; @param arg Arguments to pass |
||
47 | macro cinvoke proc,[arg] |
||
48 | { common |
||
2288 | clevermous | 49 | size@ccall = 0 |
50 | if ~ arg eq |
||
51 | reverse |
||
52 | pushd arg |
||
53 | size@ccall = size@ccall+4 |
||
54 | common |
||
55 | end if |
||
56 | call [proc] |
||
57 | if size@ccall |
||
58 | add esp, size@ccall |
||
59 | end if } |
||
60 | |||
61 | |||
8972 | Boppan | 62 | ; Calling convention for the procedure may be defined before parameter |
63 | ; list using `stdcall` or `c` word like this:\n |
||
64 | ; `proc name stdcall, param0, param1`\n |
||
65 | ; List of registers used in the procedure may be specified before |
||
66 | ; parameter list using `uses` word like this:\n |
||
67 | ; `proc name uses eax ebx ecx, param0, param1`\n |
||
68 | ; If you need to specify both calling convention and used registers |
||
69 | ; put calling convention first and then `uses` statement like this:\n |
||
70 | ; `proc name stdcall uses ebx ecx edx, param0, param1`\n |
||
8979 | Boppan | 71 | ; The defined procedure should be ended using `endp` macro. |
72 | ; @param args Name of the procedure and a comma-separated argument list. |
||
8972 | Boppan | 73 | ; Type of any parameter may be specified by semicolon after its |
74 | ; name like this:\n |
||
75 | ; `proc name param0:dword, param1:qword`. |
||
76 | macro proc [args] |
||
77 | { common |
||
2288 | clevermous | 78 | match name params, args> |
79 | \{ define@proc name, |
||
80 | |||
81 | |||
82 | |||
83 | |||
8978 | Boppan | 84 | macro prologuedef procname,flag,parmbytes,localbytes,reglist |
2288 | clevermous | 85 | { local loc |
7294 | dunkaist | 86 | loc = (localbytes+3) and (not 3) |
87 | parmbase@proc equ ebp+8 |
||
88 | localbase@proc equ ebp-loc |
||
89 | if parmbytes | localbytes |
||
90 | push ebp |
||
2288 | clevermous | 91 | mov ebp, esp |
92 | if localbytes |
||
93 | sub esp, loc |
||
7294 | dunkaist | 94 | end if |
2288 | clevermous | 95 | end if |
96 | irps reg, reglist \{ push reg \} } |
||
97 | |||
98 | |||
99 | |||
100 | |||
8978 | Boppan | 101 | macro epiloguedef procname,flag,parmbytes,localbytes,reglist |
2288 | clevermous | 102 | { irps reg, reglist \{ reverse pop reg \} |
103 | if parmbytes | localbytes |
||
104 | leave |
||
105 | end if |
||
106 | if flag and 10000b |
||
7294 | dunkaist | 107 | retn |
2288 | clevermous | 108 | else |
109 | retn parmbytes |
||
110 | end if } |
||
111 | |||
112 | |||
7294 | dunkaist | 113 | |
114 | |||
8978 | Boppan | 115 | macro define@proc name,statement |
2288 | clevermous | 116 | { local params,flag,regs,parmbytes,localbytes,current |
117 | if used name |
||
118 | name: |
||
119 | match =stdcall args, statement \{ params equ args |
||
120 | flag = 11b \} |
||
121 | match =stdcall, statement \{ params equ |
||
122 | flag = 11b \} |
||
123 | match =c args, statement \{ params equ args |
||
124 | flag = 10001b \} |
||
125 | match =c, statement \{ params equ |
||
126 | flag = 10001b \} |
||
127 | match =params, params \{ params equ statement |
||
128 | flag = 0 \} |
||
129 | match =uses reglist=,args, params \{ regs equ reglist |
||
130 | params equ args \} |
||
131 | match =regs =uses reglist, regs params \{ regs equ reglist |
||
132 | params equ \} |
||
133 | match =regs, regs \{ regs equ \} |
||
134 | match prologue:reglist, prologue@proc: |
||
7294 | dunkaist | 135 | virtual at parmbase@proc |
136 | match =,args, params \{ defargs@proc args \} |
||
2288 | clevermous | 137 | match =args@proc args, args@proc params \{ defargs@proc args \} |
138 | parmbytes = $-(parmbase@proc) |
||
7294 | dunkaist | 139 | end virtual |
2288 | clevermous | 140 | name # % = parmbytes/4 |
141 | all@vars equ |
||
142 | current = 0 |
||
143 | macro locals |
||
144 | \{ virtual at localbase@proc+current |
||
7294 | dunkaist | 145 | macro label def \\{ match . type,def> \\\{ deflocal@proc .,label, |
146 | struc db [val] \\{ \common deflocal@proc .,db,val \\} |
||
2288 | clevermous | 147 | struc du [val] \\{ \common deflocal@proc .,du,val \\} |
7294 | dunkaist | 148 | struc dw [val] \\{ \common deflocal@proc .,dw,val \\} |
2288 | clevermous | 149 | struc dp [val] \\{ \common deflocal@proc .,dp,val \\} |
150 | struc dd [val] \\{ \common deflocal@proc .,dd,val \\} |
||
151 | struc dt [val] \\{ \common deflocal@proc .,dt,val \\} |
||
152 | struc dq [val] \\{ \common deflocal@proc .,dq,val \\} |
||
153 | struc rb cnt \\{ deflocal@proc .,rb cnt, \\} |
||
154 | struc rw cnt \\{ deflocal@proc .,rw cnt, \\} |
||
155 | struc rp cnt \\{ deflocal@proc .,rp cnt, \\} |
||
156 | struc rd cnt \\{ deflocal@proc .,rd cnt, \\} |
||
157 | struc rt cnt \\{ deflocal@proc .,rt cnt, \\} |
||
158 | struc rq cnt \\{ deflocal@proc .,rq cnt, \\} \} |
||
159 | macro endl |
||
160 | \{ purge label |
||
161 | restruc db,du,dw,dp,dd,dt,dq |
||
7294 | dunkaist | 162 | restruc rb,rw,rp,rd,rt,rq |
2288 | clevermous | 163 | current = $-(localbase@proc) |
7294 | dunkaist | 164 | end virtual \} |
2288 | clevermous | 165 | macro ret operand |
166 | \{ match any, operand \\{ retn operand \\} |
||
167 | match , operand \\{ match epilogue:reglist, epilogue@proc: |
||
7294 | dunkaist | 168 | macro finish@proc |
169 | \{ localbytes = current |
||
170 | match close:reglist, close@proc: |
||
171 | end if \} } |
||
172 | |||
2288 | clevermous | 173 | |
8978 | Boppan | 174 | macro defargs@proc [arg] |
2288 | clevermous | 175 | { common |
176 | if ~ arg eq |
||
177 | forward |
||
178 | local ..arg,current@arg |
||
179 | match argname:type, arg |
||
180 | \{ current@arg equ argname |
||
181 | label ..arg type |
||
182 | argname equ ..arg |
||
183 | if dqword eq type |
||
184 | dd ?,?,?,? |
||
185 | else if tbyte eq type |
||
186 | dd ?,?,? |
||
187 | else if qword eq type | pword eq type |
||
188 | dd ?,? |
||
189 | else |
||
190 | dd ? |
||
191 | end if \} |
||
192 | match =current@arg,current@arg |
||
193 | \{ current@arg equ arg |
||
194 | arg equ ..arg |
||
195 | ..arg dd ? \} |
||
196 | common |
||
197 | args@proc equ current@arg |
||
198 | forward |
||
199 | restore current@arg |
||
200 | common |
||
201 | end if } |
||
202 | |||
203 | |||
8978 | Boppan | 204 | macro deflocal@proc name,def,[val] { name def val } |
7294 | dunkaist | 205 | |
206 | |||
8978 | Boppan | 207 | macro deflocal@proc name,def,[val] |
2288 | clevermous | 208 | { common |
209 | match vars, all@vars \{ all@vars equ all@vars, \} |
||
210 | all@vars equ all@vars name |
||
211 | forward |
||
212 | local ..var,..tmp |
||
213 | ..var def val |
||
214 | match =?, val \{ ..tmp equ \} |
||
215 | match any =?, val \{ ..tmp equ \} |
||
7294 | dunkaist | 216 | match any (=?), val \{ ..tmp equ \} |
217 | match =label, def \{ ..tmp equ \} |
||
218 | match tmp : value, ..tmp : val |
||
2288 | clevermous | 219 | \{ tmp: end virtual |
220 | initlocal@proc ..var,def value |
||
221 | virtual at tmp\} |
||
222 | common |
||
223 | match first rest, ..var, \{ name equ first \} } |
||
224 | |||
225 | |||
7294 | dunkaist | 226 | |
227 | |||
8978 | Boppan | 228 | macro initlocal@proc name,def |
2288 | clevermous | 229 | { virtual at name |
230 | def |
||
231 | size@initlocal = $ - name |
||
232 | end virtual |
||
233 | position@initlocal = 0 |
||
234 | while size@initlocal > position@initlocal |
||
235 | virtual at name |
||
236 | def |
||
237 | if size@initlocal - position@initlocal < 2 |
||
238 | current@initlocal = 1 |
||
239 | load byte@initlocal byte from name+position@initlocal |
||
240 | else if size@initlocal - position@initlocal < 4 |
||
241 | current@initlocal = 2 |
||
242 | load word@initlocal word from name+position@initlocal |
||
243 | else |
||
244 | current@initlocal = 4 |
||
245 | load dword@initlocal dword from name+position@initlocal |
||
246 | end if |
||
247 | end virtual |
||
248 | if current@initlocal = 1 |
||
249 | mov byte [name+position@initlocal], byte@initlocal |
||
250 | else if current@initlocal = 2 |
||
251 | mov word [name+position@initlocal], word@initlocal |
||
252 | else |
||
253 | mov dword [name+position@initlocal], dword@initlocal |
||
254 | end if |
||
255 | position@initlocal = position@initlocal + current@initlocal |
||
256 | end while } |
||
257 | |||
258 | |||
8979 | Boppan | 259 | macro endp |
2288 | clevermous | 260 | { purge ret,locals,endl |
261 | finish@proc |
||
262 | purge finish@proc |
||
263 | restore regs@proc |
||
264 | match all,args@proc \{ restore all \} |
||
265 | restore args@proc |
||
266 | match all,all@vars \{ restore all \} } |
||
267 | |||
268 | |||
269 | { common |
||
270 | locals |
||
271 | forward done@local equ |
||
272 | match varname[count]:vartype, var |
||
273 | \{ match =BYTE, vartype \\{ varname rb count |
||
274 | restore done@local \\} |
||
275 | match =WORD, vartype \\{ varname rw count |
||
276 | restore done@local \\} |
||
277 | match =DWORD, vartype \\{ varname rd count |
||
278 | restore done@local \\} |
||
279 | match =PWORD, vartype \\{ varname rp count |
||
280 | restore done@local \\} |
||
281 | match =QWORD, vartype \\{ varname rq count |
||
282 | restore done@local \\} |
||
283 | match =TBYTE, vartype \\{ varname rt count |
||
284 | restore done@local \\} |
||
285 | match =DQWORD, vartype \\{ label varname dqword |
||
286 | rq count+count |
||
287 | restore done@local \\} |
||
288 | match , done@local \\{ virtual |
||
289 | varname vartype |
||
290 | end virtual |
||
291 | rb count*sizeof.\#vartype |
||
292 | restore done@local \\} \} |
||
293 | match :varname:vartype, done@local:var |
||
294 | \{ match =BYTE, vartype \\{ varname db ? |
||
295 | restore done@local \\} |
||
296 | match =WORD, vartype \\{ varname dw ? |
||
297 | restore done@local \\} |
||
298 | match =DWORD, vartype \\{ varname dd ? |
||
299 | restore done@local \\} |
||
300 | match =PWORD, vartype \\{ varname dp ? |
||
301 | restore done@local \\} |
||
302 | match =QWORD, vartype \\{ varname dq ? |
||
303 | restore done@local \\} |
||
304 | match =TBYTE, vartype \\{ varname dt ? |
||
305 | restore done@local \\} |
||
306 | match =DQWORD, vartype \\{ label varname dqword |
||
307 | dq ?,? |
||
308 | restore done@local \\} |
||
309 | match , done@local \\{ varname vartype |
||
310 | restore done@local \\} \} |
||
311 | match ,done@local |
||
312 | \{ var |
||
313 | restore done@local \} |
||
314 | common |
||
315 | endl }>> |
||
316 |