xref: /reactos/sdk/lib/ucrt/inc/i386/cruntime.inc (revision b09b5584)
1;***
2;cruntime.inc - multi-model assembly macros for interfacing to HLLs
3;
4;       Copyright (c) Microsoft Corporation.  All rights reserved.
5;
6;Purpose:
7;       This file defines the current memory model being used.
8;
9;*******************************************************************************
10
11;==============================================================================
12;
13;Use the following defines to control processor/segment model
14;
15;   default is -DI86 -Dmem_S
16;
17;==============================================================================
18;
19;The following variables are defined by this file:
20;   cpu                         86, 286, or 386
21;   mmodel                      english name of the memory model, i.e. "Medium"
22;   ISIZE, LSIZE, NSIZE         size of ints, longs, shorts
23;   FLTSIZE, DBLSIZE, LDBLSIZE  size of float, double, long double
24;
25;The following macros allow easy writing of combined 16/32 bit code:
26;
27; 16/32 bit registers:
28;   rax, rbx, rcx, rdx,         expand to native registers (rax = eax or ax)
29;   rsi, rdi, rsp, rbp
30;   CBI                         convert byte to int (al to rax)
31; Numeric type instructions:
32;   IWORD, LWORD, SWORD         data type of int, long, short
33;   DFLOAT, DDOUBLE, DLDOUBLE   define float, double, long double
34;
35;The following utility macros are provided:
36;   codeseg                     define/declare code segment
37;   error <msg>                 stop assembly with message
38;   display <msg>               display a message, unless QUIET defined
39;   _if cond <instruction>      assemble instruction only if cond is TRUE
40;   _ife cond <instruction>     assemble instruction only if cond is FALSE
41;   _ifd symbol <instruction>   assemble instruction only if symbol defined
42;   _ifnd symbol <instruction>  assemble instruction only if symbol not defined
43;
44;   lab  LabelName              assembles to "LabelName:" If DEBUG is defined
45;                               LabelName is made public
46;
47;   JS* (ex. JSE,JSZ,JSB ...)   assemble to "je short","jz short","jb short"
48;
49;   Cmacro look alikes
50;   static* Name, InitialValue, Repeat   defines a static variable of type *
51;   global* Name, InitialValue, Repeat   defines a global variable of type *
52;   label*  Name, {PUBLIC,PASCAL,C}      defines a label of type *
53;
54;==============================================================================
55
56; error <msg>   -    Output message and generate error
57
58error   MACRO   msg
59if2                     ;; only on pass 2 can we generate errors
60        %out    **********************************************************
61        %out    *** E r r o r  --  msg
62        %out    **********************************************************
63        .err
64endif
65        ENDM
66
67; display msg   -    Output message unless QUIET defined
68
69display MACRO   msg
70ifndef QUIET            ;; only when quiet flag not set
71if1                     ;; and on pass 1, then display message
72        %out msg
73endif
74endif
75        ENDM
76
77; One line conditionals:
78;   here we create the capability of writing code lines like
79;
80; _if sizeD   <push ds>   as opposed to    if sizeD
81;                                              push  ds
82;                                          endif
83
84_if     MACRO   cond,text
85    if  cond
86        text
87    endif
88        ENDM
89
90_ife    MACRO   cond,text
91    ife cond
92        text
93    endif
94        ENDM
95
96_ifd    MACRO   cond,text
97    ifdef   cond
98        text
99    endif
100        ENDM
101
102_ifnd   MACRO   cond,text
103    ifndef  cond
104        text
105    endif
106        ENDM
107
108; Process processor arguments
109
110        .686
111
112;  Set memory model
113
114        .model  flat, C
115
116; Define registers:
117; Instead of using the "word" registers directly, we will use a set of
118; text equates.  This will allow you to use the native word size instead of
119; hard coded to 16 bit words.  We also have some instruction equates for
120; instruction with the register type hard coded in.
121
122    rax equ <eax>
123    rbx equ <ebx>
124    rcx equ <ecx>
125    rdx equ <edx>
126    rdi equ <edi>
127    rsi equ <esi>
128    rbp equ <ebp>
129    rsp equ <esp>
130
131    CBI   equ <movsx eax, al>    ; convert byte to int (al to rax)
132
133; The next set of equates deals with the size of SHORTS, INTS, LONGS, and
134; pointers.
135
136    ; parameters and locals
137    IWORD   equ <dword>
138
139    ; sizes for fixing SP, stepping through tables, etc.
140    ISIZE   equ 4
141
142; Float/double definitions
143; (currently the same for 16- and 32-bit segments)
144
145FLTSIZE  equ    4       ; float
146DBLSIZE  equ    8       ; double
147LDBLSIZE equ    10      ; long double
148
149DFLOAT   equ    <dd>
150DDOUBLE  equ    <dq>
151DLDOUBLE equ    <dt>
152
153; codeseg - Define/declare the standard code segment. Maps to the proper
154; form of the .code directive.
155;
156; Input:
157;
158; Output:
159;       .code _TEXT     ; for large code models
160;       .code           ; for small code models
161;       assume  cs:FLAT ; for 386
162;       assume  ds:FLAT ; for 386
163;       assume  es:FLAT ; for 386
164;       assume  ss:FLAT ; for 386
165;
166
167codeseg MACRO
168
169        .code
170
171        assume  ds:FLAT
172        assume  es:FLAT
173        assume  ss:FLAT
174
175        ENDM
176
177; Define named constants for ISA levels.
178
179__ISA_AVAILABLE_X86     equ 0
180__ISA_AVAILABLE_SSE2    equ 1
181__ISA_AVAILABLE_SSE42   equ 2
182__ISA_AVAILABLE_AVX     equ 3
183
184; Define named constants for favor
185
186__FAVOR_ATOM           equ 0
187__FAVOR_ENFSTRG        equ 1
188
189;***************************************************************
190;*
191;*  Debug lab macro
192;*
193;***************************************************************
194
195lab     macro name
196ifdef   DEBUG
197    public  pascal name     ;; define label public for Symdeb
198endif
199name:
200        endm
201
202
203;***************************************************************
204;*
205;*  Conditional jump short macros
206;*
207;***************************************************************
208
209
210        irp     x,<Z,NZ,E,NE,P,PE,AE,BE,G>
211JS&x    equ   <j&x short>
212        endm
213
214
215;***************************************************************
216;*
217;*  Global data definition macros
218;*
219;*  Usage:
220;*      globalI   Name, InitialValue, Repeat
221;*
222;***************************************************************
223
224
225MakeGlobal  macro   suffix, DataType        ;; makes all of the global* macros
226
227global&suffix  macro   name, data, rep
228public  name
229ifb     <rep>
230    _repeat = 1
231else
232    _repeat = (rep)
233endif
234
235name    &DataType  _repeat dup( data )
236        endm
237
238        endm
239
240
241    MakeGlobal  T, dt                   ; globalT
242    MakeGlobal  Q, dq                   ; globalQ
243    MakeGlobal  D, dd                   ; globalD
244    MakeGlobal  W, dw                   ; globalW
245    MakeGlobal  B, db                   ; globalB
246
247;***************************************************************
248;*
249;*  Static data definition macros
250;*
251;*  Usage:
252;*      staticI   Name, InitialValue, Repeat
253;*
254;***************************************************************
255
256
257MakeStatic  macro   suffix, DataType        ;; makes all of the static* macros
258
259static&suffix  macro   name, data, rep
260
261ifdef  DEBUG
262    public  pascal name                     ;; make statics public if DEBUG
263endif
264
265ifb     <rep>
266    _repeat = 1
267else
268    _repeat = (rep)
269endif
270
271name    &DataType  _repeat dup( data )
272        endm
273
274        endm
275
276
277    MakeStatic  T, dt                   ; staticT
278    MakeStatic  Q, dq                   ; staticQ
279    MakeStatic  D, dd                   ; staticD
280    MakeStatic  W, dw                   ; staticW
281    MakeStatic  B, db                   ; staticB
282
283;***************************************************************
284;*
285;*  Label definition macros
286;*
287;*  Usage:
288;*      labelI   Name, {PUBLIC, PASCAL, C}
289;*
290;***************************************************************
291
292__MakePublic    macro   name, option    ;; decides if a label should be
293ifidni  <option>, <PUBLIC>              ;; made public
294    public  name
295elseifidni  <option>, <PASCAL>
296    public  pascal name
297elseifidni  <option>, <C>
298    public  C name
299elseifb  <option>
300    ifdef  DEBUG
301        public  pascal name     ;; make public if DEBUG
302    endif
303endif
304                endm
305
306
307MakeLabel   macro suffix, LabelType     ;; makes all of the label* macros
308
309%@CatStr(<label>,<suffix>)      macro   name, option
310        __MakePublic    <name>,<option>
311name    label   &LabelType
312        endm
313
314        endm
315
316
317        MakeLabel   T, tbyte    ; make labelT
318        MakeLabel   Q, qword    ; make labelQ
319        MakeLabel   D, dword    ; make labelD
320        MakeLabel   W, word     ; make labelW
321        MakeLabel   B, byte     ; make labelB
322
323        MakeLabel   NP, near    ; make labelNP
324