VirtualBox

source: vbox/trunk/src/VBox/VMM/VMMAll/EMAllA.asm@ 13148

Last change on this file since 13148 was 12989, checked in by vboxsync, 16 years ago

VMM + VBox/cdefs.h: consolidated all the XYZ*DECLS of the VMM into VMM*DECL. Removed dead DECL and IN_XYZ* macros.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Id
File size: 32.6 KB
Line 
1; $Id: EMAllA.asm 12989 2008-10-06 02:15:39Z vboxsync $
2;; @file
3; EM Assembly Routines.
4;
5
6;
7; Copyright (C) 2006-2007 Sun Microsystems, Inc.
8;
9; This file is part of VirtualBox Open Source Edition (OSE), as
10; available from http://www.virtualbox.org. This file is free software;
11; you can redistribute it and/or modify it under the terms of the GNU
12; General Public License (GPL) as published by the Free Software
13; Foundation, in version 2 as it comes in the "COPYING" file of the
14; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16;
17; Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18; Clara, CA 95054 USA or visit http://www.sun.com if you need
19; additional information or have any questions.
20;
21
22;*******************************************************************************
23;* Header Files *
24;*******************************************************************************
25%include "VBox/asmdefs.mac"
26%include "VBox/err.mac"
27%include "VBox/x86.mac"
28
29;; @def MY_PTR_REG
30; The register we use for value pointers (And,Or,Dec,Inc).
31%ifdef RT_ARCH_AMD64
32 %define MY_PTR_REG rcx
33%else
34 %define MY_PTR_REG ecx
35%endif
36
37;; @def MY_RET_REG
38; The register we return the result in.
39%ifdef RT_ARCH_AMD64
40 %define MY_RET_REG rax
41%else
42 %define MY_RET_REG eax
43%endif
44
45BEGINCODE
46
47
48;;
49; Emulate CMP instruction, CDECL calling conv.
50; VMMDECL(uint32_t) EMEmulateCmp(uint32_t u32Param1, uint64_t u64Param2, size_t cb);
51;
52; @returns EFLAGS after the operation, only arithmetic flags are valid.
53; @param [esp + 04h] rdi rcx Param 1 - First parameter (Dst).
54; @param [esp + 08h] rsi edx Param 2 - Second parameter (Src).
55; @param [esp + 10h] Param 3 - Size of parameters, only 1/2/4/8 (64 bits host only) is valid.
56;
57align 16
58BEGINPROC EMEmulateCmp
59%ifdef RT_ARCH_AMD64
60%ifdef RT_OS_WINDOWS
61 mov rax, r8 ; eax = size of parameters
62%else ; !RT_OS_WINDOWS
63 mov rax, rdx ; rax = size of parameters
64 mov rcx, rdi ; rcx = first parameter
65 mov rdx, rsi ; rdx = second parameter
66%endif ; !RT_OS_WINDOWS
67%else ; !RT_ARCH_AMD64
68 mov eax, [esp + 10h] ; eax = size of parameters
69 mov ecx, [esp + 04h] ; ecx = first parameter
70 mov edx, [esp + 08h] ; edx = second parameter
71%endif
72
73 ; switch on size
74%ifdef RT_ARCH_AMD64
75 cmp al, 8
76 je short .do_qword ; 8 bytes variant
77%endif
78 cmp al, 4
79 je short .do_dword ; 4 bytes variant
80 cmp al, 2
81 je short .do_word ; 2 byte variant
82 cmp al, 1
83 je short .do_byte ; 1 bytes variant
84 int3
85
86 ; workers
87%ifdef RT_ARCH_AMD64
88.do_qword:
89 cmp rcx, rdx ; do 8 bytes CMP
90 jmp short .done
91%endif
92
93.do_dword:
94 cmp ecx, edx ; do 4 bytes CMP
95 jmp short .done
96
97.do_word:
98 cmp cx, dx ; do 2 bytes CMP
99 jmp short .done
100
101.do_byte:
102 cmp cl, dl ; do 1 byte CMP
103
104 ; collect flags and return.
105.done:
106 pushf
107 pop MY_RET_REG
108 retn
109ENDPROC EMEmulateCmp
110
111
112;;
113; Emulate AND instruction, CDECL calling conv.
114; VMMDECL(uint32_t) EMEmulateAnd(void *pvParam1, uint64_t u64Param2, size_t cb);
115;
116; @returns EFLAGS after the operation, only arithmetic flags are valid.
117; @param [esp + 04h] Param 1 - First parameter - pointer to data item.
118; @param [esp + 08h] Param 2 - Second parameter.
119; @param [esp + 10h] Param 3 - Size of parameters, only 1/2/4/8 (64 bits host only) is valid.
120; @uses eax, ecx, edx
121;
122align 16
123BEGINPROC EMEmulateAnd
124%ifdef RT_ARCH_AMD64
125%ifdef RT_OS_WINDOWS
126 mov rax, r8 ; eax = size of parameters
127%else ; !RT_OS_WINDOWS
128 mov rax, rdx ; rax = size of parameters
129 mov rcx, rdi ; rcx = first parameter
130 mov rdx, rsi ; rdx = second parameter
131%endif ; !RT_OS_WINDOWS
132%else ; !RT_ARCH_AMD64
133 mov eax, [esp + 10h] ; eax = size of parameters
134 mov ecx, [esp + 04h] ; ecx = first parameter
135 mov edx, [esp + 08h] ; edx = second parameter
136%endif
137
138 ; switch on size
139%ifdef RT_ARCH_AMD64
140 cmp al, 8
141 je short .do_qword ; 8 bytes variant
142%endif
143 cmp al, 4
144 je short .do_dword ; 4 bytes variant
145 cmp al, 2
146 je short .do_word ; 2 byte variant
147 cmp al, 1
148 je short .do_byte ; 1 bytes variant
149 int3
150
151 ; workers
152%ifdef RT_ARCH_AMD64
153.do_qword:
154 and [MY_PTR_REG], rdx ; do 8 bytes AND
155 jmp short .done
156%endif
157
158.do_dword:
159 and [MY_PTR_REG], edx ; do 4 bytes AND
160 jmp short .done
161
162.do_word:
163 and [MY_PTR_REG], dx ; do 2 bytes AND
164 jmp short .done
165
166.do_byte:
167 and [MY_PTR_REG], dl ; do 1 byte AND
168
169 ; collect flags and return.
170.done:
171 pushf
172 pop MY_RET_REG
173 retn
174ENDPROC EMEmulateAnd
175
176
177;;
178; Emulate OR instruction, CDECL calling conv.
179; VMMDECL(uint32_t) EMEmulateOr(void *pvParam1, uint64_t u64Param2, size_t cb);
180;
181; @returns EFLAGS after the operation, only arithmetic flags are valid.
182; @param [esp + 04h] Param 1 - First parameter - pointer to data item.
183; @param [esp + 08h] Param 2 - Second parameter.
184; @param [esp + 10h] Param 3 - Size of parameters, only 1/2/4/8 (64 bits host only) is valid.
185; @uses eax, ecx, edx
186;
187align 16
188BEGINPROC EMEmulateOr
189%ifdef RT_ARCH_AMD64
190%ifdef RT_OS_WINDOWS
191 mov rax, r8 ; eax = size of parameters
192%else ; !RT_OS_WINDOWS
193 mov rax, rdx ; rax = size of parameters
194 mov rcx, rdi ; rcx = first parameter
195 mov rdx, rsi ; rdx = second parameter
196%endif ; !RT_OS_WINDOWS
197%else ; !RT_ARCH_AMD64
198 mov eax, [esp + 10h] ; eax = size of parameters
199 mov ecx, [esp + 04h] ; ecx = first parameter
200 mov edx, [esp + 08h] ; edx = second parameter
201%endif
202
203 ; switch on size
204%ifdef RT_ARCH_AMD64
205 cmp al, 8
206 je short .do_qword ; 8 bytes variant
207%endif
208 cmp al, 4
209 je short .do_dword ; 4 bytes variant
210 cmp al, 2
211 je short .do_word ; 2 byte variant
212 cmp al, 1
213 je short .do_byte ; 1 bytes variant
214 int3
215
216 ; workers
217%ifdef RT_ARCH_AMD64
218.do_qword:
219 or [MY_PTR_REG], rdx ; do 8 bytes OR
220 jmp short .done
221%endif
222
223.do_dword:
224 or [MY_PTR_REG], edx ; do 4 bytes OR
225 jmp short .done
226
227.do_word:
228 or [MY_PTR_REG], dx ; do 2 bytes OR
229 jmp short .done
230
231.do_byte:
232 or [MY_PTR_REG], dl ; do 1 byte OR
233
234 ; collect flags and return.
235.done:
236 pushf
237 pop MY_RET_REG
238 retn
239ENDPROC EMEmulateOr
240
241
242;;
243; Emulate LOCK OR instruction.
244; VMMDECL(int) EMEmulateLockOr(void *pvParam1, uint64_t u64Param2, size_t cbSize, RTGCUINTREG32 *pf);
245;
246; @returns VINF_SUCCESS on success, VERR_ACCESS_DENIED on \#PF (GC only).
247; @param [esp + 04h] gcc:rdi msc:rcx Param 1 - First parameter - pointer to data item (the real stuff).
248; @param [esp + 08h] gcc:rsi msc:rdx Param 2 - Second parameter- the immediate / register value.
249; @param [esp + 10h] gcc:rdx msc:r8 Param 3 - Size of the operation - 1, 2, 4 or 8 bytes.
250; @param [esp + 14h] gcc:rcx msc:r9 Param 4 - Where to store the eflags on success.
251; only arithmetic flags are valid.
252align 16
253BEGINPROC EMEmulateLockOr
254%ifdef RT_ARCH_AMD64
255%ifdef RT_OS_WINDOWS
256 mov rax, r8 ; eax = size of parameters
257%else ; !RT_OS_WINDOWS
258 mov rax, rdx ; rax = size of parameters
259 mov rcx, rdi ; rcx = first parameter
260 mov rdx, rsi ; rdx = second parameter
261%endif ; !RT_OS_WINDOWS
262%else ; !RT_ARCH_AMD64
263 mov eax, [esp + 10h] ; eax = size of parameters
264 mov ecx, [esp + 04h] ; ecx = first parameter (MY_PTR_REG)
265 mov edx, [esp + 08h] ; edx = second parameter
266%endif
267
268 ; switch on size
269%ifdef RT_ARCH_AMD64
270 cmp al, 8
271 je short .do_qword ; 8 bytes variant
272%endif
273 cmp al, 4
274 je short .do_dword ; 4 bytes variant
275 cmp al, 2
276 je short .do_word ; 2 byte variant
277 cmp al, 1
278 je short .do_byte ; 1 bytes variant
279 int3
280
281 ; workers
282%ifdef RT_ARCH_AMD64
283.do_qword:
284 lock or [MY_PTR_REG], rdx ; do 8 bytes OR
285 jmp short .done
286%endif
287
288.do_dword:
289 lock or [MY_PTR_REG], edx ; do 4 bytes OR
290 jmp short .done
291
292.do_word:
293 lock or [MY_PTR_REG], dx ; do 2 bytes OR
294 jmp short .done
295
296.do_byte:
297 lock or [MY_PTR_REG], dl ; do 1 byte OR
298
299 ; collect flags and return.
300.done:
301 pushf
302%ifdef RT_ARCH_AMD64
303 pop rax
304 %ifdef RT_OS_WINDOWS
305 mov [r9], eax
306 %else ; !RT_OS_WINDOWS
307 mov [rcx], eax
308 %endif ; !RT_OS_WINDOWS
309%else ; !RT_ARCH_AMD64
310 mov eax, [esp + 14h + 4]
311 pop dword [eax]
312%endif
313 mov eax, VINF_SUCCESS
314 retn
315
316%ifdef IN_GC
317; #PF resume point.
318GLOBALNAME EMEmulateLockOr_Error
319 mov eax, VERR_ACCESS_DENIED
320 ret
321%endif
322
323ENDPROC EMEmulateLockOr
324
325
326;;
327; Emulate XOR instruction, CDECL calling conv.
328; VMMDECL(uint32_t) EMEmulateXor(void *pvParam1, uint64_t u64Param2, size_t cb);
329;
330; @returns EFLAGS after the operation, only arithmetic flags are valid.
331; @param [esp + 04h] Param 1 - First parameter - pointer to data item.
332; @param [esp + 08h] Param 2 - Second parameter.
333; @param [esp + 10h] Param 3 - Size of parameters, only 1/2/4/8 (64 bits host only) is valid.
334; @uses eax, ecx, edx
335;
336align 16
337BEGINPROC EMEmulateXor
338%ifdef RT_ARCH_AMD64
339%ifdef RT_OS_WINDOWS
340 mov rax, r8 ; eax = size of parameters
341%else ; !RT_OS_WINDOWS
342 mov rax, rdx ; rax = size of parameters
343 mov rcx, rdi ; rcx = first parameter
344 mov rdx, rsi ; rdx = second parameter
345%endif ; !RT_OS_WINDOWS
346%else ; !RT_ARCH_AMD64
347 mov eax, [esp + 10h] ; eax = size of parameters
348 mov ecx, [esp + 04h] ; ecx = first parameter
349 mov edx, [esp + 08h] ; edx = second parameter
350%endif
351
352 ; switch on size
353%ifdef RT_ARCH_AMD64
354 cmp al, 8
355 je short .do_qword ; 8 bytes variant
356%endif
357 cmp al, 4
358 je short .do_dword ; 4 bytes variant
359 cmp al, 2
360 je short .do_word ; 2 byte variant
361 cmp al, 1
362 je short .do_byte ; 1 bytes variant
363 int3
364
365 ; workers
366%ifdef RT_ARCH_AMD64
367.do_qword:
368 xor [MY_PTR_REG], rdx ; do 8 bytes XOR
369 jmp short .done
370%endif
371
372.do_dword:
373 xor [MY_PTR_REG], edx ; do 4 bytes XOR
374 jmp short .done
375
376.do_word:
377 xor [MY_PTR_REG], dx ; do 2 bytes XOR
378 jmp short .done
379
380.do_byte:
381 xor [MY_PTR_REG], dl ; do 1 byte XOR
382
383 ; collect flags and return.
384.done:
385 pushf
386 pop MY_RET_REG
387 retn
388ENDPROC EMEmulateXor
389
390
391;;
392; Emulate INC instruction, CDECL calling conv.
393; VMMDECL(uint32_t) EMEmulateInc(void *pvParam1, size_t cb);
394;
395; @returns EFLAGS after the operation, only arithmetic flags are valid.
396; @param [esp + 04h] rdi rcx Param 1 - First parameter - pointer to data item.
397; @param [esp + 08h] rsi rdx Param 2 - Size of parameters, only 1/2/4 is valid.
398; @uses eax, ecx, edx
399;
400align 16
401BEGINPROC EMEmulateInc
402%ifdef RT_ARCH_AMD64
403%ifdef RT_OS_WINDOWS
404 mov rax, rdx ; eax = size of parameters
405%else ; !RT_OS_WINDOWS
406 mov rax, rsi ; eax = size of parameters
407 mov rcx, rdi ; rcx = first parameter
408%endif ; !RT_OS_WINDOWS
409%else ; !RT_ARCH_AMD64
410 mov eax, [esp + 08h] ; eax = size of parameters
411 mov ecx, [esp + 04h] ; ecx = first parameter
412%endif
413
414 ; switch on size
415%ifdef RT_ARCH_AMD64
416 cmp al, 8
417 je short .do_qword ; 8 bytes variant
418%endif
419 cmp al, 4
420 je short .do_dword ; 4 bytes variant
421 cmp al, 2
422 je short .do_word ; 2 byte variant
423 cmp al, 1
424 je short .do_byte ; 1 bytes variant
425 int3
426
427 ; workers
428%ifdef RT_ARCH_AMD64
429.do_qword:
430 inc qword [MY_PTR_REG] ; do 8 bytes INC
431 jmp short .done
432%endif
433
434.do_dword:
435 inc dword [MY_PTR_REG] ; do 4 bytes INC
436 jmp short .done
437
438.do_word:
439 inc word [MY_PTR_REG] ; do 2 bytes INC
440 jmp short .done
441
442.do_byte:
443 inc byte [MY_PTR_REG] ; do 1 byte INC
444 jmp short .done
445
446 ; collect flags and return.
447.done:
448 pushf
449 pop MY_RET_REG
450 retn
451ENDPROC EMEmulateInc
452
453
454;;
455; Emulate DEC instruction, CDECL calling conv.
456; VMMDECL(uint32_t) EMEmulateDec(void *pvParam1, size_t cb);
457;
458; @returns EFLAGS after the operation, only arithmetic flags are valid.
459; @param [esp + 04h] Param 1 - First parameter - pointer to data item.
460; @param [esp + 08h] Param 2 - Size of parameters, only 1/2/4 is valid.
461; @uses eax, ecx, edx
462;
463align 16
464BEGINPROC EMEmulateDec
465%ifdef RT_ARCH_AMD64
466%ifdef RT_OS_WINDOWS
467 mov rax, rdx ; eax = size of parameters
468%else ; !RT_OS_WINDOWS
469 mov rax, rsi ; eax = size of parameters
470 mov rcx, rdi ; rcx = first parameter
471%endif ; !RT_OS_WINDOWS
472%else ; !RT_ARCH_AMD64
473 mov eax, [esp + 08h] ; eax = size of parameters
474 mov ecx, [esp + 04h] ; ecx = first parameter
475%endif
476
477 ; switch on size
478%ifdef RT_ARCH_AMD64
479 cmp al, 8
480 je short .do_qword ; 8 bytes variant
481%endif
482 cmp al, 4
483 je short .do_dword ; 4 bytes variant
484 cmp al, 2
485 je short .do_word ; 2 byte variant
486 cmp al, 1
487 je short .do_byte ; 1 bytes variant
488 int3
489
490 ; workers
491%ifdef RT_ARCH_AMD64
492.do_qword:
493 dec qword [MY_PTR_REG] ; do 8 bytes DEC
494 jmp short .done
495%endif
496
497.do_dword:
498 dec dword [MY_PTR_REG] ; do 4 bytes DEC
499 jmp short .done
500
501.do_word:
502 dec word [MY_PTR_REG] ; do 2 bytes DEC
503 jmp short .done
504
505.do_byte:
506 dec byte [MY_PTR_REG] ; do 1 byte DEC
507 jmp short .done
508
509 ; collect flags and return.
510.done:
511 pushf
512 pop MY_RET_REG
513 retn
514ENDPROC EMEmulateDec
515
516
517;;
518; Emulate ADD instruction, CDECL calling conv.
519; VMMDECL(uint32_t) EMEmulateAdd(void *pvParam1, uint64_t u64Param2, size_t cb);
520;
521; @returns EFLAGS after the operation, only arithmetic flags are valid.
522; @param [esp + 04h] Param 1 - First parameter - pointer to data item.
523; @param [esp + 08h] Param 2 - Second parameter.
524; @param [esp + 10h] Param 3 - Size of parameters, only 1/2/4/8 (64 bits host only) is valid.
525; @uses eax, ecx, edx
526;
527align 16
528BEGINPROC EMEmulateAdd
529%ifdef RT_ARCH_AMD64
530%ifdef RT_OS_WINDOWS
531 mov rax, r8 ; eax = size of parameters
532%else ; !RT_OS_WINDOWS
533 mov rax, rdx ; rax = size of parameters
534 mov rcx, rdi ; rcx = first parameter
535 mov rdx, rsi ; rdx = second parameter
536%endif ; !RT_OS_WINDOWS
537%else ; !RT_ARCH_AMD64
538 mov eax, [esp + 10h] ; eax = size of parameters
539 mov ecx, [esp + 04h] ; ecx = first parameter
540 mov edx, [esp + 08h] ; edx = second parameter
541%endif
542
543 ; switch on size
544%ifdef RT_ARCH_AMD64
545 cmp al, 8
546 je short .do_qword ; 8 bytes variant
547%endif
548 cmp al, 4
549 je short .do_dword ; 4 bytes variant
550 cmp al, 2
551 je short .do_word ; 2 byte variant
552 cmp al, 1
553 je short .do_byte ; 1 bytes variant
554 int3
555
556 ; workers
557%ifdef RT_ARCH_AMD64
558.do_qword:
559 add [MY_PTR_REG], rdx ; do 8 bytes ADD
560 jmp short .done
561%endif
562
563.do_dword:
564 add [MY_PTR_REG], edx ; do 4 bytes ADD
565 jmp short .done
566
567.do_word:
568 add [MY_PTR_REG], dx ; do 2 bytes ADD
569 jmp short .done
570
571.do_byte:
572 add [MY_PTR_REG], dl ; do 1 byte ADD
573
574 ; collect flags and return.
575.done:
576 pushf
577 pop MY_RET_REG
578 retn
579ENDPROC EMEmulateAdd
580
581
582;;
583; Emulate ADC instruction, CDECL calling conv.
584; VMMDECL(uint32_t) EMEmulateAdcWithCarrySet(void *pvParam1, uint64_t u64Param2, size_t cb);
585;
586; @returns EFLAGS after the operation, only arithmetic flags are valid.
587; @param [esp + 04h] Param 1 - First parameter - pointer to data item.
588; @param [esp + 08h] Param 2 - Second parameter.
589; @param [esp + 10h] Param 3 - Size of parameters, only 1/2/4/8 (64 bits host only) is valid.
590; @uses eax, ecx, edx
591;
592align 16
593BEGINPROC EMEmulateAdcWithCarrySet
594%ifdef RT_ARCH_AMD64
595%ifdef RT_OS_WINDOWS
596 mov rax, r8 ; eax = size of parameters
597%else ; !RT_OS_WINDOWS
598 mov rax, rdx ; rax = size of parameters
599 mov rcx, rdi ; rcx = first parameter
600 mov rdx, rsi ; rdx = second parameter
601%endif ; !RT_OS_WINDOWS
602%else ; !RT_ARCH_AMD64
603 mov eax, [esp + 10h] ; eax = size of parameters
604 mov ecx, [esp + 04h] ; ecx = first parameter
605 mov edx, [esp + 08h] ; edx = second parameter
606%endif
607
608 ; switch on size
609%ifdef RT_ARCH_AMD64
610 cmp al, 8
611 je short .do_qword ; 8 bytes variant
612%endif
613 cmp al, 4
614 je short .do_dword ; 4 bytes variant
615 cmp al, 2
616 je short .do_word ; 2 byte variant
617 cmp al, 1
618 je short .do_byte ; 1 bytes variant
619 int3
620
621 ; workers
622%ifdef RT_ARCH_AMD64
623.do_qword:
624 stc ; set carry flag
625 adc [MY_PTR_REG], rdx ; do 8 bytes ADC
626 jmp short .done
627%endif
628
629.do_dword:
630 stc ; set carry flag
631 adc [MY_PTR_REG], edx ; do 4 bytes ADC
632 jmp short .done
633
634.do_word:
635 stc ; set carry flag
636 adc [MY_PTR_REG], dx ; do 2 bytes ADC
637 jmp short .done
638
639.do_byte:
640 stc ; set carry flag
641 adc [MY_PTR_REG], dl ; do 1 byte ADC
642
643 ; collect flags and return.
644.done:
645 pushf
646 pop MY_RET_REG
647 retn
648ENDPROC EMEmulateAdcWithCarrySet
649
650
651;;
652; Emulate SUB instruction, CDECL calling conv.
653; VMMDECL(uint32_t) EMEmulateSub(void *pvParam1, uint64_t u64Param2, size_t cb);
654;
655; @returns EFLAGS after the operation, only arithmetic flags are valid.
656; @param [esp + 04h] Param 1 - First parameter - pointer to data item.
657; @param [esp + 08h] Param 2 - Second parameter.
658; @param [esp + 10h] Param 3 - Size of parameters, only 1/2/4/8 (64 bits host only) is valid.
659; @uses eax, ecx, edx
660;
661align 16
662BEGINPROC EMEmulateSub
663%ifdef RT_ARCH_AMD64
664%ifdef RT_OS_WINDOWS
665 mov rax, r8 ; eax = size of parameters
666%else ; !RT_OS_WINDOWS
667 mov rax, rdx ; rax = size of parameters
668 mov rcx, rdi ; rcx = first parameter
669 mov rdx, rsi ; rdx = second parameter
670%endif ; !RT_OS_WINDOWS
671%else ; !RT_ARCH_AMD64
672 mov eax, [esp + 10h] ; eax = size of parameters
673 mov ecx, [esp + 04h] ; ecx = first parameter
674 mov edx, [esp + 08h] ; edx = second parameter
675%endif
676
677 ; switch on size
678%ifdef RT_ARCH_AMD64
679 cmp al, 8
680 je short .do_qword ; 8 bytes variant
681%endif
682 cmp al, 4
683 je short .do_dword ; 4 bytes variant
684 cmp al, 2
685 je short .do_word ; 2 byte variant
686 cmp al, 1
687 je short .do_byte ; 1 bytes variant
688 int3
689
690 ; workers
691%ifdef RT_ARCH_AMD64
692.do_qword:
693 sub [MY_PTR_REG], rdx ; do 8 bytes SUB
694 jmp short .done
695%endif
696
697.do_dword:
698 sub [MY_PTR_REG], edx ; do 4 bytes SUB
699 jmp short .done
700
701.do_word:
702 sub [MY_PTR_REG], dx ; do 2 bytes SUB
703 jmp short .done
704
705.do_byte:
706 sub [MY_PTR_REG], dl ; do 1 byte SUB
707
708 ; collect flags and return.
709.done:
710 pushf
711 pop MY_RET_REG
712 retn
713ENDPROC EMEmulateSub
714
715
716;;
717; Emulate BTR instruction, CDECL calling conv.
718; VMMDECL(uint32_t) EMEmulateBtr(void *pvParam1, uint64_t u64Param2);
719;
720; @returns EFLAGS after the operation, only arithmetic flags are valid.
721; @param [esp + 04h] Param 1 - First parameter - pointer to data item.
722; @param [esp + 08h] Param 2 - Second parameter.
723; @uses eax, ecx, edx
724;
725align 16
726BEGINPROC EMEmulateBtr
727%ifdef RT_ARCH_AMD64
728%ifndef RT_OS_WINDOWS
729 mov rcx, rdi ; rcx = first parameter
730 mov rdx, rsi ; rdx = second parameter
731%endif ; !RT_OS_WINDOWS
732%else ; !RT_ARCH_AMD64
733 mov ecx, [esp + 04h] ; ecx = first parameter
734 mov edx, [esp + 08h] ; edx = second parameter
735%endif
736
737 and edx, 7
738 btr [MY_PTR_REG], edx
739
740 ; collect flags and return.
741 pushf
742 pop MY_RET_REG
743 retn
744ENDPROC EMEmulateBtr
745
746;;
747; Emulate LOCK BTR instruction.
748; VMMDECL(int) EMEmulateLockBtr(void *pvParam1, uint64_t u64Param2, RTGCUINTREG32 *pf);
749;
750; @returns VINF_SUCCESS on success, VERR_ACCESS_DENIED on \#PF (GC only).
751; @param [esp + 04h] gcc:rdi msc:rcx Param 1 - First parameter - pointer to data item (the real stuff).
752; @param [esp + 08h] gcc:rsi msc:rdx Param 2 - Second parameter- the immediate / register value. (really an 8 byte value)
753; @param [esp + 10h] gcc:rdx msc:r8 Param 3 - Where to store the eflags on success.
754;
755align 16
756BEGINPROC EMEmulateLockBtr
757%ifdef RT_ARCH_AMD64
758 %ifdef RT_OS_WINDOWS
759 mov rax, r8 ; rax = third parameter
760 %else ; !RT_OS_WINDOWS
761 mov rcx, rdi ; rcx = first parameter
762 mov rax, rdx ; rax = third parameter
763 mov rdx, rsi ; rdx = second parameter
764 %endif ; !RT_OS_WINDOWS
765%else ; !RT_ARCH_AMD64
766 mov ecx, [esp + 04h] ; ecx = first parameter
767 mov edx, [esp + 08h] ; edx = second parameter
768 mov eax, [esp + 10h] ; eax = third parameter
769%endif
770
771 lock btr [MY_PTR_REG], edx
772
773 ; collect flags and return.
774 pushf
775 pop xDX
776 mov [xAX], edx
777 mov eax, VINF_SUCCESS
778 retn
779
780%ifdef IN_GC
781; #PF resume point.
782GLOBALNAME EMEmulateLockBtr_Error
783 mov eax, VERR_ACCESS_DENIED
784 ret
785%endif
786
787ENDPROC EMEmulateLockBtr
788
789
790;;
791; Emulate BTC instruction, CDECL calling conv.
792; VMMDECL(uint32_t) EMEmulateBtc(void *pvParam1, uint64_t u64Param2);
793;
794; @returns EFLAGS after the operation, only arithmetic flags are valid.
795; @param [esp + 04h] Param 1 - First parameter - pointer to data item.
796; @param [esp + 08h] Param 2 - Second parameter.
797; @uses eax, ecx, edx
798;
799align 16
800BEGINPROC EMEmulateBtc
801%ifdef RT_ARCH_AMD64
802%ifndef RT_OS_WINDOWS
803 mov rcx, rdi ; rcx = first parameter
804 mov rdx, rsi ; rdx = second parameter
805%endif ; !RT_OS_WINDOWS
806%else ; !RT_ARCH_AMD64
807 mov ecx, [esp + 04h] ; ecx = first parameter
808 mov edx, [esp + 08h] ; edx = second parameter
809%endif
810
811 and edx, 7
812 btc [MY_PTR_REG], edx
813
814 ; collect flags and return.
815 pushf
816 pop MY_RET_REG
817 retn
818ENDPROC EMEmulateBtc
819
820
821;;
822; Emulate BTS instruction, CDECL calling conv.
823; VMMDECL(uint32_t) EMEmulateBts(void *pvParam1, uint64_t u64Param2);
824;
825; @returns EFLAGS after the operation, only arithmetic flags are valid.
826; @param [esp + 04h] Param 1 - First parameter - pointer to data item.
827; @param [esp + 08h] Param 2 - Second parameter.
828; @uses eax, ecx, edx
829;
830align 16
831BEGINPROC EMEmulateBts
832%ifdef RT_ARCH_AMD64
833%ifndef RT_OS_WINDOWS
834 mov rcx, rdi ; rcx = first parameter
835 mov rdx, rsi ; rdx = second parameter
836%endif ; !RT_OS_WINDOWS
837%else ; !RT_ARCH_AMD64
838 mov ecx, [esp + 04h] ; ecx = first parameter
839 mov edx, [esp + 08h] ; edx = second parameter
840%endif
841
842 and edx, 7
843 bts [MY_PTR_REG], edx
844
845 ; collect flags and return.
846 pushf
847 pop MY_RET_REG
848 retn
849ENDPROC EMEmulateBts
850
851
852;;
853; Emulate LOCK CMPXCHG instruction, CDECL calling conv.
854; VMMDECL(uint32_t) EMEmulateLockCmpXchg(void *pvParam1, uint64_t *pu64Param2, uint64_t u64Param3, size_t cbSize);
855;
856; @returns EFLAGS after the operation, only arithmetic flags are valid.
857; @param [esp + 04h] gcc:rdi msc:rcx Param 1 - First parameter - pointer to first parameter
858; @param [esp + 08h] gcc:rsi msc:rdx Param 2 - pointer to second parameter (eax)
859; @param [esp + 0ch] gcc:rdx msc:r8 Param 3 - third parameter
860; @param [esp + 14h] gcc:rcx msc:r9 Param 4 - Size of parameters, only 1/2/4/8 is valid
861; @uses eax, ecx, edx
862;
863align 16
864BEGINPROC EMEmulateLockCmpXchg
865 push xBX
866%ifdef RT_ARCH_AMD64
867%ifdef RT_OS_WINDOWS
868 ; rcx contains the first parameter already
869 mov rbx, rdx ; rdx = 2nd parameter
870 mov rdx, r8 ; r8 = 3rd parameter
871 mov rax, r9 ; r9 = size of parameters
872%else
873 mov rax, rcx ; rcx = size of parameters (4th)
874 mov rcx, rdi ; rdi = 1st parameter
875 mov rbx, rsi ; rsi = second parameter
876 ;rdx contains the 3rd parameter already
877%endif ; !RT_OS_WINDOWS
878%else ; !RT_ARCH_AMD64
879 mov ecx, [esp + 04h + 4] ; ecx = first parameter
880 mov ebx, [esp + 08h + 4] ; ebx = 2nd parameter (eax)
881 mov edx, [esp + 0ch + 4] ; edx = third parameter
882 mov eax, [esp + 14h + 4] ; eax = size of parameters
883%endif
884
885%ifdef RT_ARCH_AMD64
886 cmp al, 8
887 je short .do_qword ; 8 bytes variant
888%endif
889 cmp al, 4
890 je short .do_dword ; 4 bytes variant
891 cmp al, 2
892 je short .do_word ; 2 byte variant
893 cmp al, 1
894 je short .do_byte ; 1 bytes variant
895 int3
896
897%ifdef RT_ARCH_AMD64
898.do_qword:
899 ; load 2nd parameter's value
900 mov rax, qword [rbx]
901
902 lock cmpxchg qword [rcx], rdx ; do 8 bytes CMPXCHG
903 mov qword [rbx], rax
904 jmp short .done
905%endif
906
907.do_dword:
908 ; load 2nd parameter's value
909 mov eax, dword [xBX]
910
911 lock cmpxchg dword [xCX], edx ; do 4 bytes CMPXCHG
912 mov dword [xBX], eax
913 jmp short .done
914
915.do_word:
916 ; load 2nd parameter's value
917 mov eax, dword [xBX]
918
919 lock cmpxchg word [xCX], dx ; do 2 bytes CMPXCHG
920 mov word [xBX], ax
921 jmp short .done
922
923.do_byte:
924 ; load 2nd parameter's value
925 mov eax, dword [xBX]
926
927 lock cmpxchg byte [xCX], dl ; do 1 byte CMPXCHG
928 mov byte [xBX], al
929
930.done:
931 ; collect flags and return.
932 pushf
933 pop MY_RET_REG
934
935 pop xBX
936 retn
937ENDPROC EMEmulateLockCmpXchg
938
939
940;;
941; Emulate CMPXCHG instruction, CDECL calling conv.
942; VMMDECL(uint32_t) EMEmulateCmpXchg(void *pvParam1, uint64_t *pu32Param2, uint64_t u32Param3, size_t cbSize);
943;
944; @returns EFLAGS after the operation, only arithmetic flags are valid.
945; @param [esp + 04h] gcc:rdi msc:rcx Param 1 - First parameter - pointer to first parameter
946; @param [esp + 08h] gcc:rsi msc:rdx Param 2 - pointer to second parameter (eax)
947; @param [esp + 0ch] gcc:rdx msc:r8 Param 3 - third parameter
948; @param [esp + 14h] gcc:rcx msc:r9 Param 4 - Size of parameters, only 1/2/4 is valid.
949; @uses eax, ecx, edx
950;
951align 16
952BEGINPROC EMEmulateCmpXchg
953 push xBX
954%ifdef RT_ARCH_AMD64
955%ifdef RT_OS_WINDOWS
956 ; rcx contains the first parameter already
957 mov rbx, rdx ; rdx = 2nd parameter
958 mov rdx, r8 ; r8 = 3rd parameter
959 mov rax, r9 ; r9 = size of parameters
960%else
961 mov rax, rcx ; rcx = size of parameters (4th)
962 mov rcx, rdi ; rdi = 1st parameter
963 mov rbx, rsi ; rsi = second parameter
964 ;rdx contains the 3rd parameter already
965%endif ; !RT_OS_WINDOWS
966%else ; !RT_ARCH_AMD64
967 mov ecx, [esp + 04h + 4] ; ecx = first parameter
968 mov ebx, [esp + 08h + 4] ; ebx = 2nd parameter (eax)
969 mov edx, [esp + 0ch + 4] ; edx = third parameter
970 mov eax, [esp + 14h + 4] ; eax = size of parameters
971%endif
972
973%ifdef RT_ARCH_AMD64
974 cmp al, 8
975 je short .do_qword ; 8 bytes variant
976%endif
977 cmp al, 4
978 je short .do_dword ; 4 bytes variant
979 cmp al, 2
980 je short .do_word ; 2 byte variant
981 cmp al, 1
982 je short .do_byte ; 1 bytes variant
983 int3
984
985%ifdef RT_ARCH_AMD64
986.do_qword:
987 ; load 2nd parameter's value
988 mov rax, qword [rbx]
989
990 cmpxchg qword [rcx], rdx ; do 8 bytes CMPXCHG
991 mov qword [rbx], rax
992 jmp short .done
993%endif
994
995.do_dword:
996 ; load 2nd parameter's value
997 mov eax, dword [xBX]
998
999 cmpxchg dword [xCX], edx ; do 4 bytes CMPXCHG
1000 mov dword [xBX], eax
1001 jmp short .done
1002
1003.do_word:
1004 ; load 2nd parameter's value
1005 mov eax, dword [xBX]
1006
1007 cmpxchg word [xCX], dx ; do 2 bytes CMPXCHG
1008 mov word [xBX], ax
1009 jmp short .done
1010
1011.do_byte:
1012 ; load 2nd parameter's value
1013 mov eax, dword [xBX]
1014
1015 cmpxchg byte [xCX], dl ; do 1 byte CMPXCHG
1016 mov byte [xBX], al
1017
1018.done:
1019 ; collect flags and return.
1020 pushf
1021 pop MY_RET_REG
1022
1023 pop xBX
1024 retn
1025ENDPROC EMEmulateCmpXchg
1026
1027
1028%if 0
1029;; not tested!!
1030
1031;;
1032; Emulate LOCK CMPXCHG8B instruction, CDECL calling conv.
1033; VMMDECL(uint32_t) EMEmulateLockCmpXchg8b(RTHCPTR pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX);
1034;
1035; @returns EFLAGS after the operation, only arithmetic flags are valid.
1036; @param [esp + 04h] Param 1 - First parameter - pointer to first parameter
1037; @param [esp + 08h] Param 2 - Address of the eax register
1038; @param [esp + 0ch] Param 3 - Address of the edx register
1039; @param [esp + 10h] Param 4 - EBX
1040; @param [esp + 14h] Param 5 - ECX
1041; @uses eax, ecx, edx
1042;
1043align 16
1044BEGINPROC EMEmulateLockCmpXchg8b
1045 push ebp
1046 push ebx
1047 mov ebp, [esp + 04h + 8] ; ebp = first parameter
1048 mov eax, [esp + 08h + 8] ; &EAX
1049 mov eax, dword [eax]
1050 mov edx, [esp + 0ch + 8] ; &EDX
1051 mov edx, dword [edx]
1052 mov ebx, [esp + 10h + 8] ; EBX
1053 mov ecx, [esp + 14h + 8] ; ECX
1054
1055 lock cmpxchg8b qword [ebp] ; do CMPXCHG8B
1056 mov ebx, dword [esp + 08h + 8]
1057 mov dword [ebx], eax
1058 mov ebx, dword [esp + 0ch + 8]
1059 mov dword [ebx], edx
1060
1061 ; collect flags and return.
1062 pushf
1063 pop eax
1064
1065 pop ebx
1066 pop ebp
1067 retn
1068
1069ENDPROC EMEmulateLockCmpXchg8b
1070
1071;;
1072; Emulate CMPXCHG8B instruction, CDECL calling conv.
1073; VMMDECL(uint32_t) EMEmulateCmpXchg8b(RTHCPTR pu32Param1, uint32_t *pEAX, uint32_t *pEDX, uint32_t uEBX, uint32_t uECX);
1074;
1075; @returns EFLAGS after the operation, only arithmetic flags are valid.
1076; @param [esp + 04h] Param 1 - First parameter - pointer to first parameter
1077; @param [esp + 08h] Param 2 - Address of the eax register
1078; @param [esp + 0ch] Param 3 - Address of the edx register
1079; @param [esp + 10h] Param 4 - EBX
1080; @param [esp + 14h] Param 5 - ECX
1081; @uses eax, ecx, edx
1082;
1083align 16
1084BEGINPROC EMEmulateCmpXchg8b
1085 push ebp
1086 push ebx
1087 mov ebp, [esp + 04h + 8] ; ebp = first parameter
1088 mov eax, [esp + 08h + 8] ; &EAX
1089 mov eax, dword [eax]
1090 mov edx, [esp + 0ch + 8] ; &EDX
1091 mov edx, dword [edx]
1092 mov ebx, [esp + 10h + 8] ; EBX
1093 mov ecx, [esp + 14h + 8] ; ECX
1094
1095 cmpxchg8b qword [ebp] ; do CMPXCHG8B
1096 mov ebx, dword [esp + 08h + 8]
1097 mov dword [ebx], eax
1098 mov ebx, dword [esp + 0ch + 8]
1099 mov dword [ebx], edx
1100
1101 ; collect flags and return.
1102 pushf
1103 pop eax
1104
1105 pop ebx
1106 pop ebp
1107 retn
1108ENDPROC EMEmulateCmpXchg8b
1109
1110%endif
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette