1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
|
;@file
; This file contains macros supporting 64 bit assembly
;
;@copyright
; Copyright (c) 1999 - 2012 Intel Corporation. All rights reserved
; This software and associated documentation (if any) is furnished
; under a license and may only be used or copied in accordance
; with the terms of the license. Except as permitted by such
; license, no part of this software or documentation may be
; reproduced, stored in a retrieval system, or transmitted in any
; form or by any means without the express written consent of
; Intel Corporation.
;
; This file contains an 'Intel Peripheral Driver' and uniquely
; identified as "Intel Reference Module" and is
; licensed for Intel CPUs and chipsets under the terms of your
; license agreement with Intel or your vendor. This file may
; be modified by the user, subject to additional terms of the
; license agreement
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; Macro: _movq
;
; Input: rxx - general perpose 64 bit register
; mmx - MMX register
;
; Output: None
;
; Registers:
;
; Description: Performs "movq rxx, mmx" and "movq mmx, rxx" operations
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
_movq MACRO toReg:REQ, frReg:REQ
LOCAL gReg, mReg, op
db 48h ; ; REX.W prefix
IFIDNI <toReg>, <rax>
gReg = 00h
op = 7Eh
ELSEIFIDNI <toReg>, <rcx>
gReg = 01h
op = 7Eh
ELSEIFIDNI <toReg>, <rdx>
gReg = 02h
op = 7Eh
ELSEIFIDNI <toReg>, <rbx>
gReg = 03h
op = 7Eh
ELSEIFIDNI <toReg>, <rsp>
gReg = 04h
op = 7Eh
ELSEIFIDNI <toReg>, <rbp>
gReg = 05h
op = 7Eh
ELSEIFIDNI <toReg>, <rsi>
gReg = 06h
op = 7Eh
ELSEIFIDNI <toReg>, <rdi>
gReg = 07h
op = 7Eh
ELSEIFIDNI <toReg>, <mm0>
mReg = 0C0h + 0 * 08h
op = 6Eh
ELSEIFIDNI <toReg>, <mm1>
mReg = 0C0h + 1 * 08h
op = 6Eh
ELSEIFIDNI <toReg>, <mm2>
mReg = 0C0h + 2 * 08h
op = 6Eh
ELSEIFIDNI <toReg>, <mm3>
mReg = 0C0h + 3 * 08h
op = 6Eh
ELSEIFIDNI <toReg>, <mm4>
mReg = 0C0h + 4 * 08h
op = 6Eh
ELSEIFIDNI <toReg>, <mm5>
mReg = 0C0h + 5 * 08h
op = 6Eh
ELSEIFIDNI <toReg>, <mm6>
mReg = 0C0h + 6 * 08h
op = 6Eh
ELSEIFIDNI <toReg>, <mm7>
mReg = 0C0h + 7 * 08h
op = 6Eh
ENDIF
;; If op = 7E format movq rxx, mmx
IFIDNI <frReg>, <rax>
gReg = 00h
IF op EQ 7Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <rcx>
gReg = 01h
IF op EQ 7Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <rdx>
gReg = 02h
IF op EQ 7Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <rbx>
gReg = 03h
IF op EQ 7Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <rsp>
gReg = 04h
IF op EQ 7Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <rbp>
gReg = 05h
IF op EQ 7Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <rsi>
gReg = 06h
IF op EQ 7Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <rdi>
gReg = 07h
IF op EQ 7Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <mm0>
mReg = 0C0h + 0 * 08h
IF op EQ 6Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <mm1>
mReg = 0C0h + 1 * 08h
IF op EQ 6Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <mm2>
mReg = 0C0h + 2 * 08h
IF op EQ 6Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <mm3>
mReg = 0C0h + 3 * 08h
IF op EQ 6Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <mm4>
mReg = 0C0h + 4 * 08h
IF op EQ 6Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <mm5>
mReg = 0C0h + 5 * 08h
IF op EQ 6Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <mm6>
mReg = 0C0h + 6 * 08h
IF op EQ 6Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <mm7>
mReg = 0C0h + 7 * 08h
IF op EQ 6Eh
.ERR
ENDIF
ENDIF
db 0Fh, op, gReg + mReg
ENDM
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; Macro: _movd
;
; Input: exx - general perpose 32 bit register
; mmx - MMX register
;
; Output: None
;
; Registers:
;
; Description: Performs "movd exx, mmx" and "movd mmx, exx" operations
; coded to perform in compatibility or protected mode but
; assembled by ml64
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
_movd MACRO toReg:REQ, frReg:REQ
LOCAL gReg, mReg, op
IFIDNI <toReg>, <eax>
gReg = 00h
op = 7Eh
ELSEIFIDNI <toReg>, <ecx>
gReg = 01h
op = 7Eh
ELSEIFIDNI <toReg>, <edx>
gReg = 02h
op = 7Eh
ELSEIFIDNI <toReg>, <ebx>
gReg = 03h
op = 7Eh
ELSEIFIDNI <toReg>, <esp>
gReg = 04h
op = 7Eh
ELSEIFIDNI <toReg>, <ebp>
gReg = 05h
op = 7Eh
ELSEIFIDNI <toReg>, <esi>
gReg = 06h
op = 7Eh
ELSEIFIDNI <toReg>, <edi>
gReg = 07h
op = 7Eh
ELSEIFIDNI <toReg>, <mm0>
mReg = 0C0h + 0 * 08h
op = 6Eh
ELSEIFIDNI <toReg>, <mm1>
mReg = 0C0h + 1 * 08h
op = 6Eh
ELSEIFIDNI <toReg>, <mm2>
mReg = 0C0h + 2 * 08h
op = 6Eh
ELSEIFIDNI <toReg>, <mm3>
mReg = 0C0h + 3 * 08h
op = 6Eh
ELSEIFIDNI <toReg>, <mm4>
mReg = 0C0h + 4 * 08h
op = 6Eh
ELSEIFIDNI <toReg>, <mm5>
mReg = 0C0h + 5 * 08h
op = 6Eh
ELSEIFIDNI <toReg>, <mm6>
mReg = 0C0h + 6 * 08h
op = 6Eh
ELSEIFIDNI <toReg>, <mm7>
mReg = 0C0h + 7 * 08h
op = 6Eh
ENDIF
;; If op = 7E format movq exx, mmx
IFIDNI <frReg>, <eax>
gReg = 00h
IF op EQ 7Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <ecx>
gReg = 01h
IF op EQ 7Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <edx>
gReg = 02h
IF op EQ 7Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <ebx>
gReg = 03h
IF op EQ 7Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <esp>
gReg = 04h
IF op EQ 7Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <ebp>
gReg = 05h
IF op EQ 7Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <esi>
gReg = 06h
IF op EQ 7Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <edi>
gReg = 07h
IF op EQ 7Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <mm0>
mReg = 0C0h + 0 * 08h
IF op EQ 6Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <mm1>
mReg = 0C0h + 1 * 08h
IF op EQ 6Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <mm2>
mReg = 0C0h + 2 * 08h
IF op EQ 6Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <mm3>
mReg = 0C0h + 3 * 08h
IF op EQ 6Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <mm4>
mReg = 0C0h + 4 * 08h
IF op EQ 6Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <mm5>
mReg = 0C0h + 5 * 08h
IF op EQ 6Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <mm6>
mReg = 0C0h + 6 * 08h
IF op EQ 6Eh
.ERR
ENDIF
ELSEIFIDNI <frReg>, <mm7>
mReg = 0C0h + 7 * 08h
IF op EQ 6Eh
.ERR
ENDIF
ENDIF
db 0Fh, op, gReg + mReg
ENDM
;-----------------------------------------------------------------------------
; 64 bit macros
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; Macro: PUSHA_64
;
; Input: None
;
; Output: None
;
; Registers:
;
; Description: Saves all registers on stack
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
PUSHA_64 MACRO
push rsp
push rbp
push rax
push rbx
push rcx
push rdx
push rsi
push rdi
push r8
push r9
push r10
push r11
push r12
push r13
push r14
push r15
ENDM
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; Macro: POPA_64
;
; Input: None
;
; Output: None
;
; Registers:
;
; Description: Restores all registers from stack
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
POPA_64 MACRO
pop r15
pop r14
pop r13
pop r12
pop r11
pop r10
pop r9
pop r8
pop rdi
pop rsi
pop rdx
pop rcx
pop rbx
pop rax
pop rbp
pop rsp
ENDM
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; Macro: START_FRAME
;
; Input: None
;
; Output: None
;
; Registers:
;
; Description: Starts frame declaration. Creates variable to hold total
; size of all local vars.
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
START_FRAME MACRO
SZ = 0
ENDM
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; Macro: MAKE_LOCAL
;
; Input: ARG - var definition in form Label[Count]:QuolifiedType
;
; Output: None
;
; Registers:
;
; Description: Defines local procedure variable. Adds size of created variable
; to total size of locals.
; size of all local vars.
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
MAKE_LOCAL MACRO ARG:REQ
LOCAL brk, rbrk, clm, lbl, cnt, qtp
brk INSTR <ARG>, <[>
rbrk INSTR <ARG>, <]>
clm INSTR <ARG>, <:>
IF brk GT 0
lbl SUBSTR <ARG>, 1, brk-1
cnt SUBSTR <ARG>, brk+1, rbrk-brk-1
qtp SUBSTR <ARG>, clm+1
LOCAL lbl[cnt]:qtp
ELSE
lbl SUBSTR <ARG>, 1, clm-1
qtp SUBSTR <ARG>, clm+1
LOCAL lbl:qtp
ENDIF
SZ = SZ + sizeof lbl
ENDM
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
; Macro: END_FRAME
;
; Input: None
;
; Output: None
;
; Registers:
;
; Description: Ends frame declaration. Creates stack sufficient to hold
; all declared variables.
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
END_FRAME MACRO
SZ = SZ + 10h ; Margin
enter SZ, 0 ; With spare room on stack
.allocstack SZ
.endprolog
ENDM
SAVED_GDT TEXTEQU <mm0>
SAVED_SS TEXTEQU <mm1>
SAVED_ESP TEXTEQU <mm2>
SAVED_EBP TEXTEQU <mm3>
|