env-common.mac revision 08fc4eb537ed24136b05660d0aa038b336516961
; $Id$
;; @file
; Instruction Test Environment - Common Bits.
;
;
; Copyright (C) 2006-2013 Oracle Corporation
;
; This file is part of VirtualBox Open Source Edition (OSE), as
; available from http://www.virtualbox.org. This file is free software;
; you can redistribute it and/or modify it under the terms of the GNU
; General Public License (GPL) 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.
;
%ifndef ___env_common_mac
%define ___env_common_mac
;*******************************************************************************
;* Defined Constants And Macros *
;*******************************************************************************
%ifdef RT_ARCH_AMD64
%define MY_PUSH_FLAGS pushfq
%define MY_POP_FLAGS popfq
%define MY_PUSH_FLAGS_SIZE 8
%macro MY_PUSH_ALL 0
push rbp
mov rbp, rsp
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
pushfq
%endm
%macro MY_POP_ALL 0
popfq
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
%endm
%else
%define MY_PUSH_FLAGS pushfd
%define MY_POP_FLAGS popfd
%define MY_PUSH_FLAGS_SIZE 4
%macro MY_PUSH_ALL 0
push eBP
mov xBP, xSP
push eax
push ebx
push ecx
push edx
push esi
push edi
pushfd
%endm
%macro MY_POP_ALL 0
popfd
pop edi
pop esi
pop edx
pop ecx
pop ebx
pop eax
pop ebp
%endm
%endif
;*******************************************************************************
;* Internal Functions *
;*******************************************************************************
VBINSTST_BEGINCODE
;;
; Report bad register value.
;
; Primary purpose is save all registers and convert from our stack-based to
; the correct calling convention for the environment.
;
; This function will clean up the stack upon return (to save space in the caller).
;
; @param uExpected
; @param uActual
; @param uRegisterNo
;
VBINSTST_BEGINPROC Common_BadValue
MY_PUSH_ALL
mov xAX, xSP ; 16-byte align the stack and reserve space for arguments and stuff.
sub xSP, 40h
and xSP, ~15
mov [xSP + 38h], xAX
%ifdef ASM_CALL64_GCC
mov r8d, [VBINSTST_NAME(g_uVBInsTstSubTestIndicator) wrt rip]
mov rcx, [rbp + 10h] ; expected
mov rdx, [rbp + 18h] ; actual
mov rsi, [rbp + 20h] ; reg#
lea rdi, [.szFmt wrt rip]
VBINSTST_CALL_FN_FAILURE_4
%elifdef ASM_CALL64_MSC
mov r10d, [VBINSTST_NAME(g_uVBInsTstSubTestIndicator) wrt rip]
mov [rsp + 20h], r10
mov r9, [rbp + 10h] ; expected
mov r8, [rbp + 18h] ; actual
mov rdx, [rbp + 20h] ; reg#
lea rcx, [.szFmt wrt rip]
VBINSTST_CALL_FN_FAILURE_4
%elifdef ASM_CALL64_BS2
mov sBX, [VBINSTST_NAME(g_uVBInsTstSubTestIndicator) xWrtRIP]
mov sCX, [xBP + xCB + xCB] ; expected
mov sAX, [xBP + xCB + xCB + sCB*1] ; actual
mov sDX, [xBP + xCB + xCB + sCB*2] ; reg#
lea sSI, [.szFmt xWrtRIP]
mov qword [xSP + xCB + 3*sCB], sBX
mov qword [xSP + xCB + 2*sCB], sCX
mov qword [xSP + xCB + 1*sCB], sAX
mov qword [xSP + xCB], sDX
mov [xSP], sSI
VBINSTST_CALL_FN_FAILURE_4
%else
mov sBX, [VBINSTST_NAME(g_uVBInsTstSubTestIndicator)]
mov sCX, [xBP + xCB + xCB] ; expected
mov sAX, [xBP + xCB + xCB + sCB*1] ; actual
mov sDX, [xBP + xCB + xCB + sCB*2] ; reg#
mov [xSP + xCB + 3*sCB], sBX
mov [xSP + xCB + 2*sCB], sCX
mov [xSP + xCB + 1*sCB], sAX
mov [xSP + xCB], sDX
mov [xSP], RTCCPTR_PRE .szFmt
VBINSTST_CALL_FN_FAILURE_4
%endif
mov xSP, [xSP + 38h]
MY_POP_ALL
ret 3*sCB
%if ARCH_BITS == 64
.szFmt: db 'Bad register 0x%RX32 value 0x%RX64, expected 0x%RX64 (line %RU64)', 13, 0
%else
.szFmt: db 'Bad register 0x%RX32 value 0x%RX32, expected 0x%RX32 (line %RU32)', 13, 0
%endif
VBINSTST_ENDPROC Common_BadValue
;
; Global data variables used by Common_SetupMemReadUxx.
; For address calculation reasons, these must be qword aligned.
;
VBINSTST_BEGINDATA
dd 09d8af498h, 09ab3e5f8h
VBINSTST_GLOBALNAME_EX g_u64Data, data hidden
dq 0
dd 07d7af797h, 096b36562h
VBINSTST_GLOBALNAME_EX g_u32Data, data hidden
dd 0
dd 012305987h
VBINSTST_GLOBALNAME_EX g_u16Data, data hidden
dw 0
dw 05865h
dw 03863h
dw 02679h
VBINSTST_GLOBALNAME_EX g_u8Data, data hidden
db 0
db 90h
dw 0865ah
dd 058daffe2h
VBINSTST_BEGINCODE
;;
; Sets up g_u8Data.
; @param uValue
VBINSTST_BEGINPROC Common_SetupMemReadU8
push sAX
mov ax, [xSP + sCB + xCB]
mov [VBINSTST_NAME(g_u8Data) xWrtRIP], ax
pop sAX
ret sCB
VBINSTST_ENDPROC Common_SetupMemReadU8
;;
; Sets up g_u16Data.
; @param uValue
VBINSTST_BEGINPROC Common_SetupMemReadU16
push sAX
mov ax, [xSP + sCB + xCB]
mov [VBINSTST_NAME(g_u16Data) xWrtRIP], ax
pop sAX
ret sCB
VBINSTST_ENDPROC Common_SetupMemReadU16
;;
; Sets up g_u32Data.
; @param uValue
VBINSTST_BEGINPROC Common_SetupMemReadU32
push sAX
mov eax, [xSP + sCB + xCB]
mov [VBINSTST_NAME(g_u32Data) xWrtRIP], eax
pop sAX
ret sCB
VBINSTST_ENDPROC Common_SetupMemReadU32
;;
; Sets up g_u64Data.
; @param uValue
VBINSTST_BEGINPROC Common_SetupMemReadU64
push sAX
%ifdef RT_ARCH_AMD64
mov rax, [xSP + sCB + xCB]
mov [VBINSTST_NAME(g_u64Data) xWrtRIP], rax
%else
mov eax, [xSP + sCB + xCB]
mov [VBINSTST_NAME(g_u64Data) xWrtRIP], eax
mov eax, [xSP + sCB + xCB + 4]
mov [VBINSTST_NAME(g_u64Data) + 4 xWrtRIP], eax
%endif
pop sAX
ret sCB
VBINSTST_ENDPROC Common_SetupMemReadU64
%endif