|
|
1.1 root 1: ;---------------------------Module-Header------------------------------;
2: ; Module Name: cmacflat.inc
3: ;
4: ; Copyright (c) 1992 Microsoft Corporation
5: ;-----------------------------------------------------------------------;
6: ;-----------------------------------macro-----------------------------------
7: ;
8: ; errnz exp - generate error message if expression isn't zero
9: ;
10: ; The errnz will generate an error message if the expression "exp"
11: ; does not evaluate to zero. This macro is very useful for testing
12: ; relationships between items, labels, and data that was coded into
13: ; an application.
14: ;
15: ; errnz <offset $ - offset label> ;error if not at "label"
16: ; errnz <eofflag and 00000001b> ;eofflag must be bit 0
17: ;
18: ; For expressions involving more than one token, the angle brackets
19: ; must be used.
20: ;
21: ; The macro is only evaluated on pass 2, so forward references may be
22: ; used in the expression.
23: ;---------------------------------------------------------------------------
24:
25: errnz macro x ;;display error if expression is <>0
26: if2
27: if x ;;if expression is non-zero,
28: errnz1 <x>,%(x)
29: endif
30: endif
31: endm
32:
33: errnz1 macro x1,x2
34: = *errnz* x1 = x2
35: .err
36: endm
37:
38:
39: ;-----------------------------------macro-----------------------------------
40: ;
41: ; errn$ label,exp - generate error message if label (exp) <> $
42: ;
43: ; The errnz will generate an error message if the label and "exp"
44: ; does not evaluate to the current value of the location counter.
45: ; This macro is very useful for testing relationships between
46: ; labels and the location counter that was coded into an application.
47: ;
48: ; examples: errn$ label ;error if not at "label"
49: ; errn$ label,+3 ;error if not three bytes from "label"
50: ; errn$ label,-3 ;error if not three bytes past "label"
51: ;
52: ; If no "exp" is given, it is the same as specifying 0
53: ;
54: ; The macro is only evaluated on pass 2, so forward references may be
55: ; used in the expression.
56: ;---------------------------------------------------------------------------
57:
58: errn$ macro l,x ;;error if <$-label1 (exp2)> <>0
59: errnz <offset $ - offset l x>
60: endm
61:
62:
63: ;-----------------------------------macro-----------------------------------
64: ;
65: ; useframe - generate "loc" and arg macros for accessing locals on the frame
66: ;
67: ; usage: useframe name
68: ;
69: ; name: name of the frame to be used
70: ;
71: ; useloc generates text equates which are used for accessing locals and
72: ; parameters on the current frame, based off of EBP.
73: ;
74: ; The locals and parameters are each defined as a structure with the name
75: ; parm_<name> and loc_<name>. What is generated is text equates of the form
76: ;
77: ; parm equ <([ebp + 8])>
78: ; and
79: ; loc equ <([ebp + sizof(loc_name))>
80: ;
81: ; This implies some things of interest:
82: ;
83: ; 1) The calling convention is implied to be that of C. For PASCAL calling
84: ; convention, the parm_ structure must be reordered. This can be
85: ; accomplished by using the create_parm macro which will define the
86: ; structure in the correct order for the calling convention
87: ;
88: ; 2) The loc_name structure should have the most commonly accessed variables
89: ; listed last in the structure so that the end up with the smalled offset,
90: ; and possibly a single byte displacement in the instruction.
91: ;
92: ; 3) A frame which looks like
93: ;
94: ; ---------------------
95: ; | |
96: ; | parameters |
97: ; | |
98: ; --------------------- <--- EBP + 8
99: ; | |
100: ; | ret addr |
101: ; | |
102: ; ---------------------
103: ; | |
104: ; | old EBP |
105: ; | |
106: ; --------------------- <--- EBP
107: ; | |
108: ; | locals |
109: ; | |
110: ; ---------------------
111: ; | |
112: ; | saved regs |
113: ; | |
114: ; ---------------------
115: ;
116: ; Once defined, frame variables can be accessed simply by parm.strucname or
117: ; loc.strucname.
118: ;---------------------------------------------------------------------------
119:
120:
121: useframe macro name
122: ifdef parm_&name
123: parm equ <([ebp + 8])>
124: else
125: parm equ <>
126: endif
127: ifdef loc_&name
128: useframe1 %(((size loc_&name) + 3) and (not 3))
129: else
130: loc equ <>
131: endif
132: endm
133:
134: useframe1 macro size
135: loc equ <([ebp - size])>
136: endm
137:
138:
139:
140: ;-----------------------------------macro-----------------------------------
141: ;
142: ; enterframe - builds the given frame
143: ;
144: ; usage: enterframe name,<save list>
145: ;
146: ; name: name of the frame to generate
147: ; save list: a list of 32 bit registers to be saved upon entry and
148: ; restored upon exit (when leaveframe is encountered)
149: ;
150: ;
151: ; enterframe builds the given frame upon the stack at the point it is
152: ; encountered. What is generated is the following:
153: ;
154: ; enter sizeof(loc_&name);
155: ; push <save list>
156: ;
157: ; Once created, frame variables can be accessed simply by parm.strucname or
158: ; loc.strucname.
159: ;---------------------------------------------------------------------------
160:
161:
162: enterframe macro name,savelist
163: useframe name
164: ?cjFrame = 0
165: ifdef ?PASCALConventions
166: ifdef parm_&name
167: ?cjFrame = size parm_&name
168: endif
169: endif
170: ifdef loc_&name
171: enter (((size loc_&name) + 3) and (not 3)),0
172: else
173: enter 0,0
174: endif
175: ?regpoplist equ <>
176: ifnb <&savelist>
177: irp reg,<&savelist>
178: ifnb <&®>
179: push &®
180: ?regpoplist catstr <&®>,<,>,?regpoplist
181: endif
182: endm
183: endif
184: endm
185:
186:
187:
188: ;-----------------------------------macro-----------------------------------
189: ;
190: ; leaveframe - removes the frame created by enterframe.
191: ;
192: ; usage: leaveframe
193: ;
194: ;
195: ; leaveframe restores saved registers, removes locals from the frame, and
196: ; restores BP, and returns to the caller, optionally popping parameters
197: ; from the stack.
198: ;
199: ; No invalidation of the loc and parm equates is performed.
200: ;---------------------------------------------------------------------------
201:
202:
203: leaveframe macro
204: % irp reg,<?regpoplist>
205: ifnb <®>
206: pop reg
207: endif
208: endm
209: leave
210: ret ?cjFrame
211: endm
212:
213:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.