Rev 2288 | Rev 7294 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2288 | Rev 2455 | ||
---|---|---|---|
- | 1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
- | 2 | ;; ;; |
|
- | 3 | ;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; |
|
- | 4 | ;; Distributed under terms of the GNU General Public License ;; |
|
- | 5 | ;; ;; |
|
- | 6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
|
1 | $Revision: 2288 $ |
7 | |
2 | 8 | $Revision: 2455 $ |
|
3 | 9 | ||
4 | ; Macroinstructions for defining and calling procedures |
10 | |
5 | 11 | ; Macroinstructions for defining and calling procedures |
|
6 | macro stdcall proc,[arg] ; directly call STDCALL procedure |
12 | |
7 | { common |
13 | macro stdcall proc,[arg] ; directly call STDCALL procedure |
8 | if ~ arg eq |
14 | { common |
9 | reverse |
15 | if ~ arg eq |
10 | pushd arg |
16 | reverse |
11 | common |
17 | pushd arg |
12 | end if |
18 | common |
13 | call proc } |
19 | end if |
14 | 20 | call proc } |
|
15 | macro invoke proc,[arg] ; indirectly call STDCALL procedure |
21 | |
16 | { common |
22 | macro invoke proc,[arg] ; indirectly call STDCALL procedure |
17 | if ~ arg eq |
23 | { common |
18 | reverse |
24 | if ~ arg eq |
19 | pushd arg |
25 | reverse |
20 | common |
26 | pushd arg |
21 | end if |
27 | common |
22 | call [proc] } |
28 | end if |
23 | 29 | call [proc] } |
|
24 | macro ccall proc,[arg] ; directly call CDECL procedure |
30 | |
25 | { common |
31 | macro ccall proc,[arg] ; directly call CDECL procedure |
26 | size@ccall = 0 |
32 | { common |
27 | if ~ arg eq |
33 | size@ccall = 0 |
28 | reverse |
34 | if ~ arg eq |
29 | pushd arg |
35 | reverse |
30 | size@ccall = size@ccall+4 |
36 | pushd arg |
31 | common |
37 | size@ccall = size@ccall+4 |
32 | end if |
38 | common |
33 | call proc |
39 | end if |
34 | if size@ccall |
40 | call proc |
35 | add esp, size@ccall |
41 | if size@ccall |
36 | end if } |
42 | add esp, size@ccall |
37 | 43 | end if } |
|
38 | macro cinvoke proc,[arg] ; indirectly call CDECL procedure |
44 | |
39 | { common |
45 | macro cinvoke proc,[arg] ; indirectly call CDECL procedure |
40 | size@ccall = 0 |
46 | { common |
41 | if ~ arg eq |
47 | size@ccall = 0 |
42 | reverse |
48 | if ~ arg eq |
43 | pushd arg |
49 | reverse |
44 | size@ccall = size@ccall+4 |
50 | pushd arg |
45 | common |
51 | size@ccall = size@ccall+4 |
46 | end if |
52 | common |
47 | call [proc] |
53 | end if |
48 | if size@ccall |
54 | call [proc] |
49 | add esp, size@ccall |
55 | if size@ccall |
50 | end if } |
56 | add esp, size@ccall |
51 | 57 | end if } |
|
52 | macro proc [args] ; define procedure |
58 | |
53 | { common |
59 | macro proc [args] ; define procedure |
54 | match name params, args> |
60 | { common |
55 | \{ define@proc name, |
61 | match name params, args> |
56 | 62 | \{ define@proc name, |
|
57 | prologue@proc equ prologuedef |
63 | |
58 | 64 | prologue@proc equ prologuedef |
|
59 | macro prologuedef procname,flag,parmbytes,localbytes,reglist |
65 | |
60 | { if parmbytes | localbytes |
66 | macro prologuedef procname,flag,parmbytes,localbytes,reglist |
61 | push ebp |
67 | { if parmbytes | localbytes |
62 | mov ebp, esp |
68 | push ebp |
63 | if localbytes |
69 | mov ebp, esp |
64 | sub esp, localbytes |
70 | if localbytes |
65 | end if |
71 | sub esp, localbytes |
66 | end if |
72 | end if |
67 | irps reg, reglist \{ push reg \} } |
73 | end if |
68 | 74 | irps reg, reglist \{ push reg \} } |
|
69 | epilogue@proc equ epiloguedef |
75 | |
70 | 76 | epilogue@proc equ epiloguedef |
|
71 | macro epiloguedef procname,flag,parmbytes,localbytes,reglist |
77 | |
72 | { irps reg, reglist \{ reverse pop reg \} |
78 | macro epiloguedef procname,flag,parmbytes,localbytes,reglist |
73 | if parmbytes | localbytes |
79 | { irps reg, reglist \{ reverse pop reg \} |
74 | leave |
80 | if parmbytes | localbytes |
75 | end if |
81 | leave |
76 | if (flag and 10000b) | (parmbytes=0) |
82 | end if |
77 | retn |
83 | if (flag and 10000b) | (parmbytes=0) |
78 | else |
84 | retn |
79 | retn parmbytes |
85 | else |
80 | end if } |
86 | retn parmbytes |
81 | 87 | end if } |
|
82 | macro define@proc name,statement |
88 | |
83 | { local params,flag,regs,parmbytes,localbytes,current |
89 | macro define@proc name,statement |
84 | if used name |
90 | { local params,flag,regs,parmbytes,localbytes,current |
85 | name: |
91 | if used name |
86 | match =stdcall args, statement \{ params equ args |
92 | name: |
87 | flag = 11b \} |
93 | match =stdcall args, statement \{ params equ args |
88 | match =stdcall, statement \{ params equ |
94 | flag = 11b \} |
89 | flag = 11b \} |
95 | match =stdcall, statement \{ params equ |
90 | match =c args, statement \{ params equ args |
96 | flag = 11b \} |
91 | flag = 10001b \} |
97 | match =c args, statement \{ params equ args |
92 | match =c, statement \{ params equ |
98 | flag = 10001b \} |
93 | flag = 10001b \} |
99 | match =c, statement \{ params equ |
94 | match =params, params \{ params equ statement |
100 | flag = 10001b \} |
95 | flag = 0 \} |
101 | match =params, params \{ params equ statement |
96 | virtual at ebp+8 |
102 | flag = 0 \} |
97 | match =uses reglist=,args, params \{ regs equ reglist |
103 | virtual at ebp+8 |
98 | params equ args \} |
104 | match =uses reglist=,args, params \{ regs equ reglist |
99 | match =regs =uses reglist, regs params \{ regs equ reglist |
105 | params equ args \} |
100 | params equ \} |
106 | match =regs =uses reglist, regs params \{ regs equ reglist |
101 | match =regs, regs \{ regs equ \} |
107 | params equ \} |
102 | match =,args, params \{ defargs@proc args \} |
108 | match =regs, regs \{ regs equ \} |
103 | match =args@proc args, args@proc params \{ defargs@proc args \} |
109 | match =,args, params \{ defargs@proc args \} |
104 | parmbytes = $ - (ebp+8) |
110 | match =args@proc args, args@proc params \{ defargs@proc args \} |
105 | end virtual |
111 | parmbytes = $ - (ebp+8) |
106 | name # % = parmbytes/4 |
112 | end virtual |
107 | all@vars equ |
113 | name # % = parmbytes/4 |
108 | current = 0 |
114 | all@vars equ |
109 | match prologue:reglist, prologue@proc: |
115 | current = 0 |
110 | macro locals |
116 | match prologue:reglist, prologue@proc: |
111 | \{ virtual at ebp-localbytes+current |
117 | macro locals |
112 | macro label . \\{ deflocal@proc .,:, \\} |
118 | \{ virtual at ebp-localbytes+current |
113 | struc db [val] \\{ \common deflocal@proc .,db,val \\} |
119 | macro label . \\{ deflocal@proc .,:, \\} |
114 | struc dw [val] \\{ \common deflocal@proc .,dw,val \\} |
120 | struc db [val] \\{ \common deflocal@proc .,db,val \\} |
115 | struc dp [val] \\{ \common deflocal@proc .,dp,val \\} |
121 | struc dw [val] \\{ \common deflocal@proc .,dw,val \\} |
116 | struc dd [val] \\{ \common deflocal@proc .,dd,val \\} |
122 | struc dp [val] \\{ \common deflocal@proc .,dp,val \\} |
117 | struc dt [val] \\{ \common deflocal@proc .,dt,val \\} |
123 | struc dd [val] \\{ \common deflocal@proc .,dd,val \\} |
118 | struc dq [val] \\{ \common deflocal@proc .,dq,val \\} |
124 | struc dt [val] \\{ \common deflocal@proc .,dt,val \\} |
119 | struc rb cnt \\{ deflocal@proc .,rb cnt, \\} |
125 | struc dq [val] \\{ \common deflocal@proc .,dq,val \\} |
120 | struc rw cnt \\{ deflocal@proc .,rw cnt, \\} |
126 | struc rb cnt \\{ deflocal@proc .,rb cnt, \\} |
121 | struc rp cnt \\{ deflocal@proc .,rp cnt, \\} |
127 | struc rw cnt \\{ deflocal@proc .,rw cnt, \\} |
122 | struc rd cnt \\{ deflocal@proc .,rd cnt, \\} |
128 | struc rp cnt \\{ deflocal@proc .,rp cnt, \\} |
123 | struc rt cnt \\{ deflocal@proc .,rt cnt, \\} |
129 | struc rd cnt \\{ deflocal@proc .,rd cnt, \\} |
124 | struc rq cnt \\{ deflocal@proc .,rq cnt, \\} \} |
130 | struc rt cnt \\{ deflocal@proc .,rt cnt, \\} |
125 | macro endl |
131 | struc rq cnt \\{ deflocal@proc .,rq cnt, \\} \} |
126 | \{ purge label |
132 | macro endl |
127 | restruc db,dw,dp,dd,dt,dq |
133 | \{ purge label |
128 | restruc rb,rw,rp,rd,rt,rq |
134 | restruc db,dw,dp,dd,dt,dq |
129 | restruc byte,word,dword,pword,tword,qword |
135 | restruc rb,rw,rp,rd,rt,rq |
130 | current = $-(ebp-localbytes) |
136 | restruc byte,word,dword,pword,tword,qword |
131 | end virtual \} |
137 | current = $-(ebp-localbytes) |
132 | macro ret operand |
138 | end virtual \} |
133 | \{ match any, operand \\{ retn operand \\} |
139 | macro ret operand |
134 | match , operand \\{ match epilogue:reglist, epilogue@proc: |
140 | \{ match any, operand \\{ retn operand \\} |
135 | \\\{ epilogue name,flag,parmbytes,localbytes,reglist \\\} \\} \} |
141 | match , operand \\{ match epilogue:reglist, epilogue@proc: |
136 | macro finish@proc \{ localbytes = (((current-1) shr 2)+1) shl 2 |
142 | \\\{ epilogue name,flag,parmbytes,localbytes,reglist \\\} \\} \} |
137 | end if \} } |
143 | macro finish@proc \{ localbytes = (((current-1) shr 2)+1) shl 2 |
138 | 144 | end if \} } |
|
139 | macro defargs@proc [arg] |
145 | |
140 | { common |
146 | macro defargs@proc [arg] |
141 | if ~ arg eq |
147 | { common |
142 | forward |
148 | if ~ arg eq |
143 | local ..arg,current@arg |
149 | forward |
144 | match argname:type, arg |
150 | local ..arg,current@arg |
145 | \{ current@arg equ argname |
151 | match argname:type, arg |
146 | label ..arg type |
152 | \{ current@arg equ argname |
147 | argname equ ..arg |
153 | label ..arg type |
148 | if dqword eq type |
154 | argname equ ..arg |
149 | dd ?,?,?,? |
155 | if dqword eq type |
150 | else if tbyte eq type |
156 | dd ?,?,?,? |
151 | dd ?,?,? |
157 | else if tbyte eq type |
152 | else if qword eq type | pword eq type |
158 | dd ?,?,? |
153 | dd ?,? |
159 | else if qword eq type | pword eq type |
154 | else |
160 | dd ?,? |
155 | dd ? |
161 | else |
156 | end if \} |
162 | dd ? |
157 | match =current@arg,current@arg |
163 | end if \} |
158 | \{ current@arg equ arg |
164 | match =current@arg,current@arg |
159 | arg equ ..arg |
165 | \{ current@arg equ arg |
160 | ..arg dd ? \} |
166 | arg equ ..arg |
161 | common |
167 | ..arg dd ? \} |
162 | args@proc equ current@arg |
168 | common |
163 | forward |
169 | args@proc equ current@arg |
164 | restore current@arg |
170 | forward |
165 | common |
171 | restore current@arg |
166 | end if } |
172 | common |
167 | 173 | end if } |
|
168 | macro deflocal@proc name,def,[val] |
174 | |
169 | { common |
175 | macro deflocal@proc name,def,[val] |
170 | match vars, all@vars \{ all@vars equ all@vars, \} |
176 | { common |
171 | all@vars equ all@vars name |
177 | match vars, all@vars \{ all@vars equ all@vars, \} |
172 | forward |
178 | all@vars equ all@vars name |
173 | local ..var,..tmp |
179 | forward |
174 | ..var def val |
180 | local ..var,..tmp |
175 | match =?, val \{ ..tmp equ \} |
181 | ..var def val |
176 | match any =dup (=?), val \{ ..tmp equ \} |
182 | match =?, val \{ ..tmp equ \} |
177 | match tmp : value, ..tmp : val |
183 | match any =dup (=?), val \{ ..tmp equ \} |
178 | \{ tmp: end virtual |
184 | match tmp : value, ..tmp : val |
179 | initlocal@proc ..var,def value |
185 | \{ tmp: end virtual |
180 | virtual at tmp\} |
186 | initlocal@proc ..var,def value |
181 | common |
187 | virtual at tmp\} |
182 | match first rest, ..var, \{ name equ first \} } |
188 | common |
183 | 189 | match first rest, ..var, \{ name equ first \} } |
|
184 | macro initlocal@proc name,def |
190 | |
185 | { virtual at name |
191 | macro initlocal@proc name,def |
186 | def |
192 | { virtual at name |
187 | size@initlocal = $ - name |
193 | def |
188 | end virtual |
194 | size@initlocal = $ - name |
189 | position@initlocal = 0 |
195 | end virtual |
190 | while size@initlocal > position@initlocal |
196 | position@initlocal = 0 |
191 | virtual at name |
197 | while size@initlocal > position@initlocal |
192 | def |
198 | virtual at name |
193 | if size@initlocal - position@initlocal < 2 |
199 | def |
194 | current@initlocal = 1 |
200 | if size@initlocal - position@initlocal < 2 |
195 | load byte@initlocal byte from name+position@initlocal |
201 | current@initlocal = 1 |
196 | else if size@initlocal - position@initlocal < 4 |
202 | load byte@initlocal byte from name+position@initlocal |
197 | current@initlocal = 2 |
203 | else if size@initlocal - position@initlocal < 4 |
198 | load word@initlocal word from name+position@initlocal |
204 | current@initlocal = 2 |
199 | else |
205 | load word@initlocal word from name+position@initlocal |
200 | current@initlocal = 4 |
206 | else |
201 | load dword@initlocal dword from name+position@initlocal |
207 | current@initlocal = 4 |
202 | end if |
208 | load dword@initlocal dword from name+position@initlocal |
203 | end virtual |
209 | end if |
204 | if current@initlocal = 1 |
210 | end virtual |
205 | mov byte [name+position@initlocal], byte@initlocal |
211 | if current@initlocal = 1 |
206 | else if current@initlocal = 2 |
212 | mov byte [name+position@initlocal], byte@initlocal |
207 | mov word [name+position@initlocal], word@initlocal |
213 | else if current@initlocal = 2 |
208 | else |
214 | mov word [name+position@initlocal], word@initlocal |
209 | mov dword [name+position@initlocal], dword@initlocal |
215 | else |
210 | end if |
216 | mov dword [name+position@initlocal], dword@initlocal |
211 | position@initlocal = position@initlocal + current@initlocal |
217 | end if |
212 | end while } |
218 | position@initlocal = position@initlocal + current@initlocal |
213 | 219 | end while } |
|
214 | macro endp |
220 | |
215 | { purge ret,locals,endl |
221 | macro endp |
216 | finish@proc |
222 | { purge ret,locals,endl |
217 | purge finish@proc |
223 | finish@proc |
218 | restore regs@proc |
224 | purge finish@proc |
219 | match all,args@proc \{ restore all \} |
225 | restore regs@proc |
220 | restore args@proc |
226 | match all,args@proc \{ restore all \} |
221 | match all,all@vars \{ restore all \} } |
227 | restore args@proc |
222 | 228 | match all,all@vars \{ restore all \} } |
|
223 | macro local [var] |
229 | |
224 | { common |
230 | macro local [var] |
225 | locals |
231 | { common |
226 | forward done@local equ |
232 | locals |
227 | match varname[count]:vartype, var |
233 | forward done@local equ |
228 | \{ match =BYTE, vartype \\{ varname rb count |
234 | match varname[count]:vartype, var |
229 | restore done@local \\} |
235 | \{ match =BYTE, vartype \\{ varname rb count |
230 | match =WORD, vartype \\{ varname rw count |
236 | restore done@local \\} |
231 | restore done@local \\} |
237 | match =WORD, vartype \\{ varname rw count |
232 | match =DWORD, vartype \\{ varname rd count |
238 | restore done@local \\} |
233 | restore done@local \\} |
239 | match =DWORD, vartype \\{ varname rd count |
234 | match =PWORD, vartype \\{ varname rp count |
240 | restore done@local \\} |
235 | restore done@local \\} |
241 | match =PWORD, vartype \\{ varname rp count |
236 | match =QWORD, vartype \\{ varname rq count |
242 | restore done@local \\} |
237 | restore done@local \\} |
243 | match =QWORD, vartype \\{ varname rq count |
238 | match =TBYTE, vartype \\{ varname rt count |
244 | restore done@local \\} |
239 | restore done@local \\} |
245 | match =TBYTE, vartype \\{ varname rt count |
240 | match =DQWORD, vartype \\{ label varname dqword |
246 | restore done@local \\} |
241 | rq count+count |
247 | match =DQWORD, vartype \\{ label varname dqword |
242 | restore done@local \\} |
248 | rq count+count |
243 | match , done@local \\{ virtual |
249 | restore done@local \\} |
244 | varname vartype |
250 | match , done@local \\{ virtual |
245 | end virtual |
251 | varname vartype |
246 | rb count*sizeof.\#vartype |
252 | end virtual |
247 | restore done@local \\} \} |
253 | rb count*sizeof.\#vartype |
248 | match :varname:vartype, done@local:var |
254 | restore done@local \\} \} |
249 | \{ match =BYTE, vartype \\{ varname db ? |
255 | match :varname:vartype, done@local:var |
250 | restore done@local \\} |
256 | \{ match =BYTE, vartype \\{ varname db ? |
251 | match =WORD, vartype \\{ varname dw ? |
257 | restore done@local \\} |
252 | restore done@local \\} |
258 | match =WORD, vartype \\{ varname dw ? |
253 | match =DWORD, vartype \\{ varname dd ? |
259 | restore done@local \\} |
254 | restore done@local \\} |
260 | match =DWORD, vartype \\{ varname dd ? |
255 | match =PWORD, vartype \\{ varname dp ? |
261 | restore done@local \\} |
256 | restore done@local \\} |
262 | match =PWORD, vartype \\{ varname dp ? |
257 | match =QWORD, vartype \\{ varname dq ? |
263 | restore done@local \\} |
258 | restore done@local \\} |
264 | match =QWORD, vartype \\{ varname dq ? |
259 | match =TBYTE, vartype \\{ varname dt ? |
265 | restore done@local \\} |
260 | restore done@local \\} |
266 | match =TBYTE, vartype \\{ varname dt ? |
261 | match =DQWORD, vartype \\{ label varname dqword |
267 | restore done@local \\} |
262 | dq ?,? |
268 | match =DQWORD, vartype \\{ label varname dqword |
263 | restore done@local \\} |
269 | dq ?,? |
264 | match , done@local \\{ varname vartype |
270 | restore done@local \\} |
265 | restore done@local \\} \} |
271 | match , done@local \\{ varname vartype |
266 | match ,done@local |
272 | restore done@local \\} \} |
267 | \{ var |
273 | match ,done@local |
268 | restore done@local \} |
274 | \{ var |
269 | common |
275 | restore done@local \} |
270 | endl }>> |
276 | common |
- | 277 | endl }>> |