Subversion Repositories Kolibri OS

Rev

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