; Copyright (C) 2006 InnoTek Systemberatung GmbH
; This file is part of VirtualBox Open Source Edition (OSE), as
; you can redistribute it
and/or modify it under the terms of the GNU
; General Public License as published by the Free Software Foundation,
; in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
; distribution. VirtualBox OSE is distributed in the hope that it will
; be useful, but WITHOUT ANY WARRANTY of any kind.
; If you received this file as part of a commercial VirtualBox
; distribution, then only the terms of your commercial VirtualBox
; license agreement apply instead of the previous paragraph.
;*******************************************************************************
;*******************************************************************************
; The register we use for value pointers (And,Or,Dec,Inc).
; The register we return the result in.
; Emulate CMP instruction, CDECL calling conv.
; EMDECL(uint32_t) EMEmulateCmp(uint32_t u32Param1, uint32_t u32Param2, size_t cb);
; @returns EFLAGS after the operation, only arithmetic flags is valid.
; @param [esp + 04h] rdi rcx Param 1 - First parameter (Dst).
; @param [esp + 08h] rsi edx Param 2 - Second parameter (Src).
; @param [esp + 0ch] rdx r8 Param 3 - Size of parameters, only 1/2/4 is valid.
mov rax, r8 ; eax = size of parameters
mov rax, rdx ; rax = size of parameters
mov rcx, rdi ; rcx = first parameter
mov rdx, rsi ; rdx = second parameter
mov eax, [esp + 0ch] ; eax = size of parameters
mov ecx, [esp + 04h] ; ecx = first parameter
mov edx, [esp + 08h] ; edx = second parameter
je short .do_qword ; 8 bytes variant
je short .do_dword ; 4 bytes variant
je short .do_word ; 2 byte variant
je short .do_byte ; 1 bytes variant
cmp rcx, rdx ; do 8 bytes CMP
cmp ecx, edx ; do 4 bytes CMP
cmp cx, dx ; do 2 bytes CMP
cmp cl, dl ; do 1 byte CMP
; collect flags and return.
; Emulate AND instruction, CDECL calling conv.
; EMDECL(uint32_t) EMEmulateAnd(uint32_t *pu32Param1, uint32_t u32Param2, size_t cb);
; @returns EFLAGS after the operation, only arithmetic flags is valid.
; @param [esp + 04h] Param 1 - First parameter - pointer to data item.
; @param [esp + 08h] Param 2 - Second parameter.
; @param [esp + 0ch] Param 3 - Size of parameters, only 1/2/4 is valid.
mov rax, r8 ; eax = size of parameters
mov rax, rdx ; rax = size of parameters
mov rcx, rdi ; rcx = first parameter
mov rdx, rsi ; rdx = second parameter
mov eax, [esp + 0ch] ; eax = size of parameters
mov ecx, [esp + 04h] ; ecx = first parameter
mov edx, [esp + 08h] ; edx = second parameter
je short .do_qword ; 8 bytes variant
je short .do_dword ; 4 bytes variant
je short .do_word ; 2 byte variant
je short .do_byte ; 1 bytes variant
and [MY_PTR_REG], rdx ; do 8 bytes AND
and [MY_PTR_REG], edx ; do 4 bytes AND
and [MY_PTR_REG], dx ; do 2 bytes AND
and [MY_PTR_REG], dl ; do 1 byte AND
; collect flags and return.
; Emulate OR instruction, CDECL calling conv.
; EMDECL(uint32_t) EMEmulateOr(uint32_t *pu32Param1, uint32_t u32Param2, size_t cb);
; @returns EFLAGS after the operation, only arithmetic flags is valid.
; @param [esp + 04h] Param 1 - First parameter - pointer to data item.
; @param [esp + 08h] Param 2 - Second parameter.
; @param [esp + 0ch] Param 3 - Size of parameters, only 1/2/4 is valid.
mov rax, r8 ; eax = size of parameters
mov rax, rdx ; rax = size of parameters
mov rcx, rdi ; rcx = first parameter
mov rdx, rsi ; rdx = second parameter
mov eax, [esp + 0ch] ; eax = size of parameters
mov ecx, [esp + 04h] ; ecx = first parameter
mov edx, [esp + 08h] ; edx = second parameter
je short .do_qword ; 8 bytes variant
je short .do_dword ; 4 bytes variant
je short .do_word ; 2 byte variant
je short .do_byte ; 1 bytes variant
or [MY_PTR_REG], rdx ; do 8 bytes OR
or [MY_PTR_REG], edx ; do 4 bytes OR
or [MY_PTR_REG], dx ; do 2 bytes OR
or [MY_PTR_REG], dl ; do 1 byte OR
; collect flags and return.
; Emulate XOR instruction, CDECL calling conv.
; EMDECL(uint32_t) EMEmulateXor(uint32_t *pu32Param1, uint32_t u32Param2, size_t cb);
; @returns EFLAGS after the operation, only arithmetic flags is valid.
; @param [esp + 04h] Param 1 - First parameter - pointer to data item.
; @param [esp + 08h] Param 2 - Second parameter.
; @param [esp + 0ch] Param 3 - Size of parameters, only 1/2/4 is valid.
mov rax, r8 ; eax = size of parameters
mov rax, rdx ; rax = size of parameters
mov rcx, rdi ; rcx = first parameter
mov rdx, rsi ; rdx = second parameter
mov eax, [esp + 0ch] ; eax = size of parameters
mov ecx, [esp + 04h] ; ecx = first parameter
mov edx, [esp + 08h] ; edx = second parameter
je short .do_qword ; 8 bytes variant
je short .do_dword ; 4 bytes variant
je short .do_word ; 2 byte variant
je short .do_byte ; 1 bytes variant
xor [MY_PTR_REG], rdx ; do 8 bytes XOR
xor [MY_PTR_REG], edx ; do 4 bytes XOR
xor [MY_PTR_REG], dx ; do 2 bytes XOR
xor [MY_PTR_REG], dl ; do 1 byte XOR
; collect flags and return.
; Emulate INC instruction, CDECL calling conv.
; EMDECL(uint32_t) EMEmulateInc(uint32_t *pu32Param1, size_t cb);
; @returns EFLAGS after the operation, only arithmetic flags are valid.
; @param [esp + 04h] rdi rcx Param 1 - First parameter - pointer to data item.
; @param [esp + 08h] rsi rdx Param 2 - Size of parameters, only 1/2/4 is valid.
mov rax, rdx ; eax = size of parameters
mov rax, rsi ; eax = size of parameters
mov rcx, rdi ; rcx = first parameter
mov eax, [esp + 08h] ; eax = size of parameters
mov ecx, [esp + 04h] ; ecx = first parameter
je short .do_qword ; 8 bytes variant
je short .do_dword ; 4 bytes variant
je short .do_word ; 2 byte variant
je short .do_byte ; 1 bytes variant
inc qword [MY_PTR_REG] ; do 8 bytes INC
inc dword [MY_PTR_REG] ; do 4 bytes INC
inc word [MY_PTR_REG] ; do 2 bytes INC
inc byte [MY_PTR_REG] ; do 1 byte INC
; collect flags and return.
; Emulate DEC instruction, CDECL calling conv.
; EMDECL(uint32_t) EMEmulateDec(uint32_t *pu32Param1, size_t cb);
; @returns EFLAGS after the operation, only arithmetic flags are valid.
; @param [esp + 04h] Param 1 - First parameter - pointer to data item.
; @param [esp + 08h] Param 2 - Size of parameters, only 1/2/4 is valid.
mov rax, rdx ; eax = size of parameters
mov rax, rsi ; eax = size of parameters
mov rcx, rdi ; rcx = first parameter
mov eax, [esp + 08h] ; eax = size of parameters
mov ecx, [esp + 04h] ; ecx = first parameter
je short .do_qword ; 8 bytes variant
je short .do_dword ; 4 bytes variant
je short .do_word ; 2 byte variant
je short .do_byte ; 1 bytes variant
dec qword [MY_PTR_REG] ; do 8 bytes DEC
dec dword [MY_PTR_REG] ; do 4 bytes DEC
dec word [MY_PTR_REG] ; do 2 bytes DEC
dec byte [MY_PTR_REG] ; do 1 byte DEC
; collect flags and return.
; Emulate ADD instruction, CDECL calling conv.
; EMDECL(uint32_t) EMEmulateAdd(uint32_t *pu32Param1, uint32_t u32Param2, size_t cb);
; @returns EFLAGS after the operation, only arithmetic flags is valid.
; @param [esp + 04h] Param 1 - First parameter - pointer to data item.
; @param [esp + 08h] Param 2 - Second parameter.
; @param [esp + 0ch] Param 3 - Size of parameters, only 1/2/4 is valid.
mov rax, r8 ; eax = size of parameters
mov rax, rdx ; rax = size of parameters
mov rcx, rdi ; rcx = first parameter
mov rdx, rsi ; rdx = second parameter
mov eax, [esp + 0ch] ; eax = size of parameters
mov ecx, [esp + 04h] ; ecx = first parameter
mov edx, [esp + 08h] ; edx = second parameter
je short .do_qword ; 8 bytes variant
je short .do_dword ; 4 bytes variant
je short .do_word ; 2 byte variant
je short .do_byte ; 1 bytes variant
add [MY_PTR_REG], rdx ; do 8 bytes ADD
add [MY_PTR_REG], edx ; do 4 bytes ADD
add [MY_PTR_REG], dx ; do 2 bytes ADD
add [MY_PTR_REG], dl ; do 1 byte ADD
; collect flags and return.
; Emulate ADC instruction, CDECL calling conv.
; EMDECL(uint32_t) EMEmulateAdcWithCarrySet(uint32_t *pu32Param1, uint32_t u32Param2, size_t cb);
; @returns EFLAGS after the operation, only arithmetic flags is valid.
; @param [esp + 04h] Param 1 - First parameter - pointer to data item.
; @param [esp + 08h] Param 2 - Second parameter.
; @param [esp + 0ch] Param 3 - Size of parameters, only 1/2/4 is valid.
BEGINPROC EMEmulateAdcWithCarrySet
mov rax, r8 ; eax = size of parameters
mov rax, rdx ; rax = size of parameters
mov rcx, rdi ; rcx = first parameter
mov rdx, rsi ; rdx = second parameter
mov eax, [esp + 0ch] ; eax = size of parameters
mov ecx, [esp + 04h] ; ecx = first parameter
mov edx, [esp + 08h] ; edx = second parameter
je short .do_qword ; 8 bytes variant
je short .do_dword ; 4 bytes variant
je short .do_word ; 2 byte variant
je short .do_byte ; 1 bytes variant
adc [MY_PTR_REG], rdx ; do 8 bytes ADC
adc [MY_PTR_REG], edx ; do 4 bytes ADC
adc [MY_PTR_REG], dx ; do 2 bytes ADC
adc [MY_PTR_REG], dl ; do 1 byte ADC
; collect flags and return.
ENDPROC EMEmulateAdcWithCarrySet
; Emulate SUB instruction, CDECL calling conv.
; EMDECL(uint32_t) EMEmulateSub(uint32_t *pu32Param1, uint32_t u32Param2, size_t cb);
; @returns EFLAGS after the operation, only arithmetic flags is valid.
; @param [esp + 04h] Param 1 - First parameter - pointer to data item.
; @param [esp + 08h] Param 2 - Second parameter.
; @param [esp + 0ch] Param 3 - Size of parameters, only 1/2/4 is valid.
mov rax, r8 ; eax = size of parameters
mov rax, rdx ; rax = size of parameters
mov rcx, rdi ; rcx = first parameter
mov rdx, rsi ; rdx = second parameter
mov eax, [esp + 0ch] ; eax = size of parameters
mov ecx, [esp + 04h] ; ecx = first parameter
mov edx, [esp + 08h] ; edx = second parameter
je short .do_qword ; 8 bytes variant
je short .do_dword ; 4 bytes variant
je short .do_word ; 2 byte variant
je short .do_byte ; 1 bytes variant
sub [MY_PTR_REG], rdx ; do 8 bytes SUB
sub [MY_PTR_REG], edx ; do 4 bytes SUB
sub [MY_PTR_REG], dx ; do 2 bytes SUB
sub [MY_PTR_REG], dl ; do 1 byte SUB
; collect flags and return.
; Emulate BTR instruction, CDECL calling conv.
; EMDECL(uint32_t) EMEmulateBtr(uint32_t *pu32Param1, uint32_t u32Param2);
; @returns EFLAGS after the operation, only arithmetic flags is valid.
; @param [esp + 04h] Param 1 - First parameter - pointer to data item.
; @param [esp + 08h] Param 2 - Second parameter.
mov rcx, rdi ; rcx = first parameter
mov rdx, rsi ; rdx = second parameter
mov ecx, [esp + 04h] ; ecx = first parameter
mov edx, [esp + 08h] ; edx = second parameter
; collect flags and return.