env-common.mac revision f372af8e6ee2a011213b11cc69f4a29530ff7ce5
44568d2972696810da90828aef56e24dac466c06slive; $Id$
44568d2972696810da90828aef56e24dac466c06slive;; @file
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd; Instruction Test Environment - Common Bits.
d209ecb5fe6393098ebb1f1afeea3648b1bf89eafielding;
d209ecb5fe6393098ebb1f1afeea3648b1bf89eafielding
d209ecb5fe6393098ebb1f1afeea3648b1bf89eafielding;
d209ecb5fe6393098ebb1f1afeea3648b1bf89eafielding; Copyright (C) 2006-2013 Oracle Corporation
d209ecb5fe6393098ebb1f1afeea3648b1bf89eafielding;
d209ecb5fe6393098ebb1f1afeea3648b1bf89eafielding; This file is part of VirtualBox Open Source Edition (OSE), as
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd; available from http://www.virtualbox.org. This file is free software;
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd; you can redistribute it and/or modify it under the terms of the GNU
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd; General Public License (GPL) as published by the Free Software
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd; Foundation, in version 2 as it comes in the "COPYING" file of the
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd; VirtualBox OSE distribution. VirtualBox OSE is distributed in the
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd; hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd;
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd%ifndef ___env_common_mac
bfb214f8ec1b83a124e7a8caa495e3e8f19e9c75nd%define ___env_common_mac
8a72c24379e10c3f3d0dfe352bf15e45ee65c179nd
8a72c24379e10c3f3d0dfe352bf15e45ee65c179nd
44568d2972696810da90828aef56e24dac466c06slive;*******************************************************************************
3c56725151a46fef84ce376d709b5339da28e10fnd;* Defined Constants And Macros *
44568d2972696810da90828aef56e24dac466c06slive;*******************************************************************************
5fa8671cb225dacefd0b5dde0d9876bbb30862d8slive%ifdef RT_ARCH_AMD64
44568d2972696810da90828aef56e24dac466c06slive %define MY_PUSH_FLAGS pushfq
f1110149b5b6c28ecc39d1958d98ad9cfa8e41f3nd %define MY_POP_FLAGS popfq
f1110149b5b6c28ecc39d1958d98ad9cfa8e41f3nd %define MY_PUSH_FLAGS_SIZE 8
2e809a50cd648587cde45e41c8a3b3c9f48bd3cand
44568d2972696810da90828aef56e24dac466c06slive %macro MY_PUSH_ALL 0
5fa8671cb225dacefd0b5dde0d9876bbb30862d8slive push rbp
5fa8671cb225dacefd0b5dde0d9876bbb30862d8slive mov rbp, rsp
44568d2972696810da90828aef56e24dac466c06slive push rax
44568d2972696810da90828aef56e24dac466c06slive push rbx
44568d2972696810da90828aef56e24dac466c06slive push rcx
44568d2972696810da90828aef56e24dac466c06slive push rdx
44568d2972696810da90828aef56e24dac466c06slive push rsi
3c56725151a46fef84ce376d709b5339da28e10fnd push rdi
3c56725151a46fef84ce376d709b5339da28e10fnd push r8
44568d2972696810da90828aef56e24dac466c06slive push r9
44568d2972696810da90828aef56e24dac466c06slive push r10
44568d2972696810da90828aef56e24dac466c06slive push r11
44568d2972696810da90828aef56e24dac466c06slive push r12
44568d2972696810da90828aef56e24dac466c06slive push r13
44568d2972696810da90828aef56e24dac466c06slive push r14
44568d2972696810da90828aef56e24dac466c06slive push r15
44568d2972696810da90828aef56e24dac466c06slive pushfq
44568d2972696810da90828aef56e24dac466c06slive %endm
44568d2972696810da90828aef56e24dac466c06slive %macro MY_POP_ALL 0
44568d2972696810da90828aef56e24dac466c06slive popfq
44568d2972696810da90828aef56e24dac466c06slive pop r15
44568d2972696810da90828aef56e24dac466c06slive pop r14
8afa28f4910ded087330b035046ad6874e968f08rpluem pop r13
44568d2972696810da90828aef56e24dac466c06slive pop r12
44568d2972696810da90828aef56e24dac466c06slive pop r11
44568d2972696810da90828aef56e24dac466c06slive pop r10
44568d2972696810da90828aef56e24dac466c06slive pop r9
44568d2972696810da90828aef56e24dac466c06slive pop r8
44568d2972696810da90828aef56e24dac466c06slive pop rdi
44568d2972696810da90828aef56e24dac466c06slive pop rsi
44568d2972696810da90828aef56e24dac466c06slive pop rdx
44568d2972696810da90828aef56e24dac466c06slive pop rcx
3ab930ddc61b821f2e4b6582624258aac782cc84patrikj pop rbx
f32e3f62baf7948fee690b8f319e435370e79443nd pop rax
3ab930ddc61b821f2e4b6582624258aac782cc84patrikj pop rbp
2e809a50cd648587cde45e41c8a3b3c9f48bd3cand %endm
2e809a50cd648587cde45e41c8a3b3c9f48bd3cand
3ab930ddc61b821f2e4b6582624258aac782cc84patrikj%else
f32e3f62baf7948fee690b8f319e435370e79443nd %define MY_PUSH_FLAGS pushfd
f2e55f27f49e34dcd7a066d1486a623a02a93ec7erikabele %define MY_POP_FLAGS popfd
2e809a50cd648587cde45e41c8a3b3c9f48bd3cand %define MY_PUSH_FLAGS_SIZE 4
2e809a50cd648587cde45e41c8a3b3c9f48bd3cand
d1b2e36420ade1a362f0410de47143e0a1c63964slive %macro MY_PUSH_ALL 0
f32e3f62baf7948fee690b8f319e435370e79443nd push eBP
2e809a50cd648587cde45e41c8a3b3c9f48bd3cand mov xBP, xSP
2e809a50cd648587cde45e41c8a3b3c9f48bd3cand push eax
fc56d0d97412cd0421430f3e415c9b19be97e101nd 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 *
;*******************************************************************************
;;
; Report bad register value.
;
; Primary purpose is save all registers and convert from our stack-based to
; the correct calling convention for the environment.
;
; @param uExpected
; @param uActual
; @param uRegisterNo
;
VBINSTST_BEGINPROC Common_BadValue
MY_PUSH_ALL
%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
sub rsp, 28h
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
add rsp, 28h
%else
mov sBX, [VBINSTST_NAME(g_uVBInsTstSubTestIndicator)]
mov sCX, [xBP + 4 + xCB] ; expected
mov sAX, [xBP + 4 + xCB + 4] ; actual
mov sDX, [xBP + 4 + xCB + 8] ; reg#
push sBX
push sCX
push sAX
push sDX
push .szFmt
VBINSTST_CALL_FN_FAILURE_4
add esp, 4*sCB + xCB
%endif
MY_POP_ALL
ret
%if ARCH_BITS == 64
.szFmt: db 'Bad register %#llx value %#018llx, expected %#018llx (line %llu)', 0
%else
.szFmt: db 'Bad register %lx value %#010lx, expected %#010lx (line %lu)', 0
%endif
VBINSTST_ENDPROC Common_BadValue
;
; Global data variables used by Common_SetupMemReadUxx.
;
BEGINDATA
VBINSTST_GLOBALNAME_EX g_u64Data, data hidden
dq 0
VBINSTST_GLOBALNAME_EX g_u32Data, data hidden
dd 0
VBINSTST_GLOBALNAME_EX g_u16Data, data hidden
dw 0
VBINSTST_GLOBALNAME_EX g_u8Data, data hidden
db 0
db 90h
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