Subversion Repositories Kolibri OS

Rev

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