blob: 242afc20bed386c9c96511c8b1245bb8d1928f52 [file] [log] [blame]
/* **********************************************************
* Copyright (c) 2013 Google, Inc. All rights reserved.
* Copyright (c) 2007-2010 VMware, Inc. All rights reserved.
* **********************************************************/
/*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* * Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
*
* * Neither the name of VMware, Inc. nor the names of its contributors may be
* used to endorse or promote products derived from this software without
* specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL VMWARE, INC. OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
* DAMAGE.
*/
#ifndef ASM_CODE_ONLY /* C code */
#include "tools.h" /* for print() */
#include <stdio.h>
/* in asm */
void test_jecxz(int *x);
int main()
{
int x = 0;
test_jecxz(&x);
print("x=0x%08x\n", x);
print("thank you for testing the client interface\n");
}
#else /* asm code *************************************************************/
#include "asm_defines.asm"
START_FILE
#define FUNCNAME test_jecxz
DECLARE_FUNC_SEH(FUNCNAME)
GLOBAL_LABEL(FUNCNAME:)
mov REG_XAX, ARG1
/* push callee-saved registers */
PUSH_SEH(REG_XBX)
PUSH_SEH(REG_XBP)
PUSH_SEH(REG_XSI)
PUSH_SEH(REG_XDI)
END_PROLOG
/* test jecxz */
mov REG_XCX, 0
jecxz jecxz_taken
nop
jecxz_taken:
mov REG_XCX, 1
jecxz jecxz_not_taken
nop
jecxz_not_taken:
#ifdef X64
mov ecx, 0
jecxz jcxz_taken
#else
mov cx, 0
jcxz jcxz_taken
#endif
nop
jcxz_taken:
/* test loop */
mov REG_XCX, REG_XAX
inc REG_XCX
loop loop_taken
nop
loop_taken:
/* test xcx being preserved */
mov DWORD [REG_XCX], HEX(abcd1234)
add REG_XSP, 0 /* make a legal SEH64 epilog */
pop REG_XDI
pop REG_XSI
pop REG_XBP
pop REG_XBX
ret
END_FUNC(FUNCNAME)
END_FILE
#endif