debuggers.hg

changeset 22735:b0e8e00f5be2

tools/tests: Move x86 emulator tests into a subdir

Signed-off-by: Keir Fraser <keir@xen.org>
author Keir Fraser <keir@xen.org>
date Sat Jan 08 10:59:13 2011 +0000 (2011-01-08)
parents 2a18d709f6e9
children d45e74f45cb1
files tools/tests/Makefile tools/tests/blowfish.c tools/tests/blowfish.mk tools/tests/test_x86_emulator.c tools/tests/x86_emulate.c tools/tests/x86_emulator/Makefile tools/tests/x86_emulator/blowfish.c tools/tests/x86_emulator/blowfish.mk tools/tests/x86_emulator/test_x86_emulator.c tools/tests/x86_emulator/x86_emulate.c
line diff
     1.1 --- a/tools/tests/Makefile	Sat Jan 08 10:52:45 2011 +0000
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,44 +0,0 @@
     1.4 -
     1.5 -XEN_ROOT=../..
     1.6 -include $(XEN_ROOT)/tools/Rules.mk
     1.7 -
     1.8 -TARGET := test_x86_emulator
     1.9 -
    1.10 -.PHONY: all
    1.11 -all: $(TARGET)
    1.12 -
    1.13 -.PHONY: blowfish.h
    1.14 -blowfish.h:
    1.15 -	rm -f blowfish.bin
    1.16 -	XEN_TARGET_ARCH=x86_32 make -f blowfish.mk all
    1.17 -	(echo "static unsigned int blowfish32_code[] = {"; \
    1.18 -	od -v -t x blowfish.bin | sed 's/^[0-9]* /0x/' | sed 's/ /, 0x/g' | sed 's/$$/,/';\
    1.19 -	echo "};") >$@
    1.20 -	rm -f blowfish.bin
    1.21 -ifeq ($(XEN_COMPILE_ARCH),x86_64)
    1.22 -	XEN_TARGET_ARCH=x86_64 make -f blowfish.mk all
    1.23 -	(echo "static unsigned int blowfish64_code[] = {"; \
    1.24 -	od -v -t x blowfish.bin | sed 's/^[0-9]* /0x/' | sed 's/ /, 0x/g' | sed 's/$$/,/';\
    1.25 -	echo "};") >>$@
    1.26 -	rm -f blowfish.bin
    1.27 -endif
    1.28 -
    1.29 -$(TARGET): x86_emulate.o test_x86_emulator.o
    1.30 -	$(HOSTCC) -o $@ $^
    1.31 -
    1.32 -.PHONY: clean
    1.33 -clean:
    1.34 -	rm -rf $(TARGET) *.o *~ core blowfish.h blowfish.bin x86_emulate
    1.35 -
    1.36 -.PHONY: install
    1.37 -install:
    1.38 -
    1.39 -.PHONY: x86_emulate
    1.40 -x86_emulate:
    1.41 -	[ -L x86_emulate ] || ln -sf $(XEN_ROOT)/xen/arch/x86/x86_emulate .
    1.42 -
    1.43 -x86_emulate.o: x86_emulate.c x86_emulate
    1.44 -	$(HOSTCC) $(HOSTCFLAGS) -I$(XEN_ROOT)/xen/include -c -o $@ $<
    1.45 -
    1.46 -test_x86_emulator.o: test_x86_emulator.c blowfish.h x86_emulate
    1.47 -	$(HOSTCC) $(HOSTCFLAGS) -I$(XEN_ROOT)/xen/include -c -o $@ $<
     2.1 --- a/tools/tests/blowfish.c	Sat Jan 08 10:52:45 2011 +0000
     2.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.3 @@ -1,440 +0,0 @@
     2.4 -/*
     2.5 -blowfish.c:  C implementation of the Blowfish algorithm.
     2.6 -
     2.7 -Copyright (C) 1997 by Paul Kocher
     2.8 -
     2.9 -This library is free software; you can redistribute it and/or
    2.10 -modify it under the terms of the GNU Lesser General Public
    2.11 -License as published by the Free Software Foundation; either
    2.12 -version 2.1 of the License, or (at your option) any later version.
    2.13 -This library is distributed in the hope that it will be useful,
    2.14 -but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.15 -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    2.16 -Lesser General Public License for more details.
    2.17 -You should have received a copy of the GNU Lesser General Public
    2.18 -License along with this library; if not, write to the Free Software
    2.19 -Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.20 -*/
    2.21 -
    2.22 -#include <stdint.h>
    2.23 -
    2.24 -uint64_t blowfish_test(uint64_t input);
    2.25 -
    2.26 -asm (
    2.27 -    ".globl _start\n"
    2.28 -    "_start:\n"
    2.29 -#if defined(__i386__)
    2.30 -    "push %edx; push %eax; "
    2.31 -    "call blowfish_test; "
    2.32 -    "addl $8,%esp; "
    2.33 -#else
    2.34 -    "shlq $32,%rdx; movl %eax,%edi; orq %rdx,%rdi; "
    2.35 -    "call blowfish_test; "
    2.36 -    "movq %rax,%rdi; movl %eax,%eax; shrq $32,%rdx; "
    2.37 -#endif
    2.38 -    "ret"
    2.39 -    );
    2.40 -
    2.41 -typedef struct {
    2.42 -    uint32_t P[16 + 2];
    2.43 -    uint32_t S[4][256];
    2.44 -} BLOWFISH_CTX;
    2.45 -
    2.46 -#define N               16
    2.47 -
    2.48 -static const uint32_t ORIG_P[16 + 2] = {
    2.49 -    0x243F6A88u, 0x85A308D3u, 0x13198A2Eu, 0x03707344u,
    2.50 -    0xA4093822u, 0x299F31D0u, 0x082EFA98u, 0xEC4E6C89u,
    2.51 -    0x452821E6u, 0x38D01377u, 0xBE5466CFu, 0x34E90C6Cu,
    2.52 -    0xC0AC29B7u, 0xC97C50DDu, 0x3F84D5B5u, 0xB5470917u,
    2.53 -    0x9216D5D9u, 0x8979FB1Bu
    2.54 -};
    2.55 -
    2.56 -static const uint32_t ORIG_S[4][256] = {
    2.57 -    {   0xD1310BA6u, 0x98DFB5ACu, 0x2FFD72DBu, 0xD01ADFB7u,
    2.58 -        0xB8E1AFEDu, 0x6A267E96u, 0xBA7C9045u, 0xF12C7F99u,
    2.59 -        0x24A19947u, 0xB3916CF7u, 0x0801F2E2u, 0x858EFC16u,
    2.60 -        0x636920D8u, 0x71574E69u, 0xA458FEA3u, 0xF4933D7Eu,
    2.61 -        0x0D95748Fu, 0x728EB658u, 0x718BCD58u, 0x82154AEEu,
    2.62 -        0x7B54A41Du, 0xC25A59B5u, 0x9C30D539u, 0x2AF26013u,
    2.63 -        0xC5D1B023u, 0x286085F0u, 0xCA417918u, 0xB8DB38EFu,
    2.64 -        0x8E79DCB0u, 0x603A180Eu, 0x6C9E0E8Bu, 0xB01E8A3Eu,
    2.65 -        0xD71577C1u, 0xBD314B27u, 0x78AF2FDAu, 0x55605C60u,
    2.66 -        0xE65525F3u, 0xAA55AB94u, 0x57489862u, 0x63E81440u,
    2.67 -        0x55CA396Au, 0x2AAB10B6u, 0xB4CC5C34u, 0x1141E8CEu,
    2.68 -        0xA15486AFu, 0x7C72E993u, 0xB3EE1411u, 0x636FBC2Au,
    2.69 -        0x2BA9C55Du, 0x741831F6u, 0xCE5C3E16u, 0x9B87931Eu,
    2.70 -        0xAFD6BA33u, 0x6C24CF5Cu, 0x7A325381u, 0x28958677u,
    2.71 -        0x3B8F4898u, 0x6B4BB9AFu, 0xC4BFE81Bu, 0x66282193u,
    2.72 -        0x61D809CCu, 0xFB21A991u, 0x487CAC60u, 0x5DEC8032u,
    2.73 -        0xEF845D5Du, 0xE98575B1u, 0xDC262302u, 0xEB651B88u,
    2.74 -        0x23893E81u, 0xD396ACC5u, 0x0F6D6FF3u, 0x83F44239u,
    2.75 -        0x2E0B4482u, 0xA4842004u, 0x69C8F04Au, 0x9E1F9B5Eu,
    2.76 -        0x21C66842u, 0xF6E96C9Au, 0x670C9C61u, 0xABD388F0u,
    2.77 -        0x6A51A0D2u, 0xD8542F68u, 0x960FA728u, 0xAB5133A3u,
    2.78 -        0x6EEF0B6Cu, 0x137A3BE4u, 0xBA3BF050u, 0x7EFB2A98u,
    2.79 -        0xA1F1651Du, 0x39AF0176u, 0x66CA593Eu, 0x82430E88u,
    2.80 -        0x8CEE8619u, 0x456F9FB4u, 0x7D84A5C3u, 0x3B8B5EBEu,
    2.81 -        0xE06F75D8u, 0x85C12073u, 0x401A449Fu, 0x56C16AA6u,
    2.82 -        0x4ED3AA62u, 0x363F7706u, 0x1BFEDF72u, 0x429B023Du,
    2.83 -        0x37D0D724u, 0xD00A1248u, 0xDB0FEAD3u, 0x49F1C09Bu,
    2.84 -        0x075372C9u, 0x80991B7Bu, 0x25D479D8u, 0xF6E8DEF7u,
    2.85 -        0xE3FE501Au, 0xB6794C3Bu, 0x976CE0BDu, 0x04C006BAu,
    2.86 -        0xC1A94FB6u, 0x409F60C4u, 0x5E5C9EC2u, 0x196A2463u,
    2.87 -        0x68FB6FAFu, 0x3E6C53B5u, 0x1339B2EBu, 0x3B52EC6Fu,
    2.88 -        0x6DFC511Fu, 0x9B30952Cu, 0xCC814544u, 0xAF5EBD09u,
    2.89 -        0xBEE3D004u, 0xDE334AFDu, 0x660F2807u, 0x192E4BB3u,
    2.90 -        0xC0CBA857u, 0x45C8740Fu, 0xD20B5F39u, 0xB9D3FBDBu,
    2.91 -        0x5579C0BDu, 0x1A60320Au, 0xD6A100C6u, 0x402C7279u,
    2.92 -        0x679F25FEu, 0xFB1FA3CCu, 0x8EA5E9F8u, 0xDB3222F8u,
    2.93 -        0x3C7516DFu, 0xFD616B15u, 0x2F501EC8u, 0xAD0552ABu,
    2.94 -        0x323DB5FAu, 0xFD238760u, 0x53317B48u, 0x3E00DF82u,
    2.95 -        0x9E5C57BBu, 0xCA6F8CA0u, 0x1A87562Eu, 0xDF1769DBu,
    2.96 -        0xD542A8F6u, 0x287EFFC3u, 0xAC6732C6u, 0x8C4F5573u,
    2.97 -        0x695B27B0u, 0xBBCA58C8u, 0xE1FFA35Du, 0xB8F011A0u,
    2.98 -        0x10FA3D98u, 0xFD2183B8u, 0x4AFCB56Cu, 0x2DD1D35Bu,
    2.99 -        0x9A53E479u, 0xB6F84565u, 0xD28E49BCu, 0x4BFB9790u,
   2.100 -        0xE1DDF2DAu, 0xA4CB7E33u, 0x62FB1341u, 0xCEE4C6E8u,
   2.101 -        0xEF20CADAu, 0x36774C01u, 0xD07E9EFEu, 0x2BF11FB4u,
   2.102 -        0x95DBDA4Du, 0xAE909198u, 0xEAAD8E71u, 0x6B93D5A0u,
   2.103 -        0xD08ED1D0u, 0xAFC725E0u, 0x8E3C5B2Fu, 0x8E7594B7u,
   2.104 -        0x8FF6E2FBu, 0xF2122B64u, 0x8888B812u, 0x900DF01Cu,
   2.105 -        0x4FAD5EA0u, 0x688FC31Cu, 0xD1CFF191u, 0xB3A8C1ADu,
   2.106 -        0x2F2F2218u, 0xBE0E1777u, 0xEA752DFEu, 0x8B021FA1u,
   2.107 -        0xE5A0CC0Fu, 0xB56F74E8u, 0x18ACF3D6u, 0xCE89E299u,
   2.108 -        0xB4A84FE0u, 0xFD13E0B7u, 0x7CC43B81u, 0xD2ADA8D9u,
   2.109 -        0x165FA266u, 0x80957705u, 0x93CC7314u, 0x211A1477u,
   2.110 -        0xE6AD2065u, 0x77B5FA86u, 0xC75442F5u, 0xFB9D35CFu,
   2.111 -        0xEBCDAF0Cu, 0x7B3E89A0u, 0xD6411BD3u, 0xAE1E7E49u,
   2.112 -        0x00250E2Du, 0x2071B35Eu, 0x226800BBu, 0x57B8E0AFu,
   2.113 -        0x2464369Bu, 0xF009B91Eu, 0x5563911Du, 0x59DFA6AAu,
   2.114 -        0x78C14389u, 0xD95A537Fu, 0x207D5BA2u, 0x02E5B9C5u,
   2.115 -        0x83260376u, 0x6295CFA9u, 0x11C81968u, 0x4E734A41u,
   2.116 -        0xB3472DCAu, 0x7B14A94Au, 0x1B510052u, 0x9A532915u,
   2.117 -        0xD60F573Fu, 0xBC9BC6E4u, 0x2B60A476u, 0x81E67400u,
   2.118 -        0x08BA6FB5u, 0x571BE91Fu, 0xF296EC6Bu, 0x2A0DD915u,
   2.119 -        0xB6636521u, 0xE7B9F9B6u, 0xFF34052Eu, 0xC5855664u,
   2.120 -        0x53B02D5Du, 0xA99F8FA1u, 0x08BA4799u, 0x6E85076Au   },
   2.121 -    {   0x4B7A70E9u, 0xB5B32944u, 0xDB75092Eu, 0xC4192623u,
   2.122 -        0xAD6EA6B0u, 0x49A7DF7Du, 0x9CEE60B8u, 0x8FEDB266u,
   2.123 -        0xECAA8C71u, 0x699A17FFu, 0x5664526Cu, 0xC2B19EE1u,
   2.124 -        0x193602A5u, 0x75094C29u, 0xA0591340u, 0xE4183A3Eu,
   2.125 -        0x3F54989Au, 0x5B429D65u, 0x6B8FE4D6u, 0x99F73FD6u,
   2.126 -        0xA1D29C07u, 0xEFE830F5u, 0x4D2D38E6u, 0xF0255DC1u,
   2.127 -        0x4CDD2086u, 0x8470EB26u, 0x6382E9C6u, 0x021ECC5Eu,
   2.128 -        0x09686B3Fu, 0x3EBAEFC9u, 0x3C971814u, 0x6B6A70A1u,
   2.129 -        0x687F3584u, 0x52A0E286u, 0xB79C5305u, 0xAA500737u,
   2.130 -        0x3E07841Cu, 0x7FDEAE5Cu, 0x8E7D44ECu, 0x5716F2B8u,
   2.131 -        0xB03ADA37u, 0xF0500C0Du, 0xF01C1F04u, 0x0200B3FFu,
   2.132 -        0xAE0CF51Au, 0x3CB574B2u, 0x25837A58u, 0xDC0921BDu,
   2.133 -        0xD19113F9u, 0x7CA92FF6u, 0x94324773u, 0x22F54701u,
   2.134 -        0x3AE5E581u, 0x37C2DADCu, 0xC8B57634u, 0x9AF3DDA7u,
   2.135 -        0xA9446146u, 0x0FD0030Eu, 0xECC8C73Eu, 0xA4751E41u,
   2.136 -        0xE238CD99u, 0x3BEA0E2Fu, 0x3280BBA1u, 0x183EB331u,
   2.137 -        0x4E548B38u, 0x4F6DB908u, 0x6F420D03u, 0xF60A04BFu,
   2.138 -        0x2CB81290u, 0x24977C79u, 0x5679B072u, 0xBCAF89AFu,
   2.139 -        0xDE9A771Fu, 0xD9930810u, 0xB38BAE12u, 0xDCCF3F2Eu,
   2.140 -        0x5512721Fu, 0x2E6B7124u, 0x501ADDE6u, 0x9F84CD87u,
   2.141 -        0x7A584718u, 0x7408DA17u, 0xBC9F9ABCu, 0xE94B7D8Cu,
   2.142 -        0xEC7AEC3Au, 0xDB851DFAu, 0x63094366u, 0xC464C3D2u,
   2.143 -        0xEF1C1847u, 0x3215D908u, 0xDD433B37u, 0x24C2BA16u,
   2.144 -        0x12A14D43u, 0x2A65C451u, 0x50940002u, 0x133AE4DDu,
   2.145 -        0x71DFF89Eu, 0x10314E55u, 0x81AC77D6u, 0x5F11199Bu,
   2.146 -        0x043556F1u, 0xD7A3C76Bu, 0x3C11183Bu, 0x5924A509u,
   2.147 -        0xF28FE6EDu, 0x97F1FBFAu, 0x9EBABF2Cu, 0x1E153C6Eu,
   2.148 -        0x86E34570u, 0xEAE96FB1u, 0x860E5E0Au, 0x5A3E2AB3u,
   2.149 -        0x771FE71Cu, 0x4E3D06FAu, 0x2965DCB9u, 0x99E71D0Fu,
   2.150 -        0x803E89D6u, 0x5266C825u, 0x2E4CC978u, 0x9C10B36Au,
   2.151 -        0xC6150EBAu, 0x94E2EA78u, 0xA5FC3C53u, 0x1E0A2DF4u,
   2.152 -        0xF2F74EA7u, 0x361D2B3Du, 0x1939260Fu, 0x19C27960u,
   2.153 -        0x5223A708u, 0xF71312B6u, 0xEBADFE6Eu, 0xEAC31F66u,
   2.154 -        0xE3BC4595u, 0xA67BC883u, 0xB17F37D1u, 0x018CFF28u,
   2.155 -        0xC332DDEFu, 0xBE6C5AA5u, 0x65582185u, 0x68AB9802u,
   2.156 -        0xEECEA50Fu, 0xDB2F953Bu, 0x2AEF7DADu, 0x5B6E2F84u,
   2.157 -        0x1521B628u, 0x29076170u, 0xECDD4775u, 0x619F1510u,
   2.158 -        0x13CCA830u, 0xEB61BD96u, 0x0334FE1Eu, 0xAA0363CFu,
   2.159 -        0xB5735C90u, 0x4C70A239u, 0xD59E9E0Bu, 0xCBAADE14u,
   2.160 -        0xEECC86BCu, 0x60622CA7u, 0x9CAB5CABu, 0xB2F3846Eu,
   2.161 -        0x648B1EAFu, 0x19BDF0CAu, 0xA02369B9u, 0x655ABB50u,
   2.162 -        0x40685A32u, 0x3C2AB4B3u, 0x319EE9D5u, 0xC021B8F7u,
   2.163 -        0x9B540B19u, 0x875FA099u, 0x95F7997Eu, 0x623D7DA8u,
   2.164 -        0xF837889Au, 0x97E32D77u, 0x11ED935Fu, 0x16681281u,
   2.165 -        0x0E358829u, 0xC7E61FD6u, 0x96DEDFA1u, 0x7858BA99u,
   2.166 -        0x57F584A5u, 0x1B227263u, 0x9B83C3FFu, 0x1AC24696u,
   2.167 -        0xCDB30AEBu, 0x532E3054u, 0x8FD948E4u, 0x6DBC3128u,
   2.168 -        0x58EBF2EFu, 0x34C6FFEAu, 0xFE28ED61u, 0xEE7C3C73u,
   2.169 -        0x5D4A14D9u, 0xE864B7E3u, 0x42105D14u, 0x203E13E0u,
   2.170 -        0x45EEE2B6u, 0xA3AAABEAu, 0xDB6C4F15u, 0xFACB4FD0u,
   2.171 -        0xC742F442u, 0xEF6ABBB5u, 0x654F3B1Du, 0x41CD2105u,
   2.172 -        0xD81E799Eu, 0x86854DC7u, 0xE44B476Au, 0x3D816250u,
   2.173 -        0xCF62A1F2u, 0x5B8D2646u, 0xFC8883A0u, 0xC1C7B6A3u,
   2.174 -        0x7F1524C3u, 0x69CB7492u, 0x47848A0Bu, 0x5692B285u,
   2.175 -        0x095BBF00u, 0xAD19489Du, 0x1462B174u, 0x23820E00u,
   2.176 -        0x58428D2Au, 0x0C55F5EAu, 0x1DADF43Eu, 0x233F7061u,
   2.177 -        0x3372F092u, 0x8D937E41u, 0xD65FECF1u, 0x6C223BDBu,
   2.178 -        0x7CDE3759u, 0xCBEE7460u, 0x4085F2A7u, 0xCE77326Eu,
   2.179 -        0xA6078084u, 0x19F8509Eu, 0xE8EFD855u, 0x61D99735u,
   2.180 -        0xA969A7AAu, 0xC50C06C2u, 0x5A04ABFCu, 0x800BCADCu,
   2.181 -        0x9E447A2Eu, 0xC3453484u, 0xFDD56705u, 0x0E1E9EC9u,
   2.182 -        0xDB73DBD3u, 0x105588CDu, 0x675FDA79u, 0xE3674340u,
   2.183 -        0xC5C43465u, 0x713E38D8u, 0x3D28F89Eu, 0xF16DFF20u,
   2.184 -        0x153E21E7u, 0x8FB03D4Au, 0xE6E39F2Bu, 0xDB83ADF7u   },
   2.185 -    {   0xE93D5A68u, 0x948140F7u, 0xF64C261Cu, 0x94692934u,
   2.186 -        0x411520F7u, 0x7602D4F7u, 0xBCF46B2Eu, 0xD4A20068u,
   2.187 -        0xD4082471u, 0x3320F46Au, 0x43B7D4B7u, 0x500061AFu,
   2.188 -        0x1E39F62Eu, 0x97244546u, 0x14214F74u, 0xBF8B8840u,
   2.189 -        0x4D95FC1Du, 0x96B591AFu, 0x70F4DDD3u, 0x66A02F45u,
   2.190 -        0xBFBC09ECu, 0x03BD9785u, 0x7FAC6DD0u, 0x31CB8504u,
   2.191 -        0x96EB27B3u, 0x55FD3941u, 0xDA2547E6u, 0xABCA0A9Au,
   2.192 -        0x28507825u, 0x530429F4u, 0x0A2C86DAu, 0xE9B66DFBu,
   2.193 -        0x68DC1462u, 0xD7486900u, 0x680EC0A4u, 0x27A18DEEu,
   2.194 -        0x4F3FFEA2u, 0xE887AD8Cu, 0xB58CE006u, 0x7AF4D6B6u,
   2.195 -        0xAACE1E7Cu, 0xD3375FECu, 0xCE78A399u, 0x406B2A42u,
   2.196 -        0x20FE9E35u, 0xD9F385B9u, 0xEE39D7ABu, 0x3B124E8Bu,
   2.197 -        0x1DC9FAF7u, 0x4B6D1856u, 0x26A36631u, 0xEAE397B2u,
   2.198 -        0x3A6EFA74u, 0xDD5B4332u, 0x6841E7F7u, 0xCA7820FBu,
   2.199 -        0xFB0AF54Eu, 0xD8FEB397u, 0x454056ACu, 0xBA489527u,
   2.200 -        0x55533A3Au, 0x20838D87u, 0xFE6BA9B7u, 0xD096954Bu,
   2.201 -        0x55A867BCu, 0xA1159A58u, 0xCCA92963u, 0x99E1DB33u,
   2.202 -        0xA62A4A56u, 0x3F3125F9u, 0x5EF47E1Cu, 0x9029317Cu,
   2.203 -        0xFDF8E802u, 0x04272F70u, 0x80BB155Cu, 0x05282CE3u,
   2.204 -        0x95C11548u, 0xE4C66D22u, 0x48C1133Fu, 0xC70F86DCu,
   2.205 -        0x07F9C9EEu, 0x41041F0Fu, 0x404779A4u, 0x5D886E17u,
   2.206 -        0x325F51EBu, 0xD59BC0D1u, 0xF2BCC18Fu, 0x41113564u,
   2.207 -        0x257B7834u, 0x602A9C60u, 0xDFF8E8A3u, 0x1F636C1Bu,
   2.208 -        0x0E12B4C2u, 0x02E1329Eu, 0xAF664FD1u, 0xCAD18115u,
   2.209 -        0x6B2395E0u, 0x333E92E1u, 0x3B240B62u, 0xEEBEB922u,
   2.210 -        0x85B2A20Eu, 0xE6BA0D99u, 0xDE720C8Cu, 0x2DA2F728u,
   2.211 -        0xD0127845u, 0x95B794FDu, 0x647D0862u, 0xE7CCF5F0u,
   2.212 -        0x5449A36Fu, 0x877D48FAu, 0xC39DFD27u, 0xF33E8D1Eu,
   2.213 -        0x0A476341u, 0x992EFF74u, 0x3A6F6EABu, 0xF4F8FD37u,
   2.214 -        0xA812DC60u, 0xA1EBDDF8u, 0x991BE14Cu, 0xDB6E6B0Du,
   2.215 -        0xC67B5510u, 0x6D672C37u, 0x2765D43Bu, 0xDCD0E804u,
   2.216 -        0xF1290DC7u, 0xCC00FFA3u, 0xB5390F92u, 0x690FED0Bu,
   2.217 -        0x667B9FFBu, 0xCEDB7D9Cu, 0xA091CF0Bu, 0xD9155EA3u,
   2.218 -        0xBB132F88u, 0x515BAD24u, 0x7B9479BFu, 0x763BD6EBu,
   2.219 -        0x37392EB3u, 0xCC115979u, 0x8026E297u, 0xF42E312Du,
   2.220 -        0x6842ADA7u, 0xC66A2B3Bu, 0x12754CCCu, 0x782EF11Cu,
   2.221 -        0x6A124237u, 0xB79251E7u, 0x06A1BBE6u, 0x4BFB6350u,
   2.222 -        0x1A6B1018u, 0x11CAEDFAu, 0x3D25BDD8u, 0xE2E1C3C9u,
   2.223 -        0x44421659u, 0x0A121386u, 0xD90CEC6Eu, 0xD5ABEA2Au,
   2.224 -        0x64AF674Eu, 0xDA86A85Fu, 0xBEBFE988u, 0x64E4C3FEu,
   2.225 -        0x9DBC8057u, 0xF0F7C086u, 0x60787BF8u, 0x6003604Du,
   2.226 -        0xD1FD8346u, 0xF6381FB0u, 0x7745AE04u, 0xD736FCCCu,
   2.227 -        0x83426B33u, 0xF01EAB71u, 0xB0804187u, 0x3C005E5Fu,
   2.228 -        0x77A057BEu, 0xBDE8AE24u, 0x55464299u, 0xBF582E61u,
   2.229 -        0x4E58F48Fu, 0xF2DDFDA2u, 0xF474EF38u, 0x8789BDC2u,
   2.230 -        0x5366F9C3u, 0xC8B38E74u, 0xB475F255u, 0x46FCD9B9u,
   2.231 -        0x7AEB2661u, 0x8B1DDF84u, 0x846A0E79u, 0x915F95E2u,
   2.232 -        0x466E598Eu, 0x20B45770u, 0x8CD55591u, 0xC902DE4Cu,
   2.233 -        0xB90BACE1u, 0xBB8205D0u, 0x11A86248u, 0x7574A99Eu,
   2.234 -        0xB77F19B6u, 0xE0A9DC09u, 0x662D09A1u, 0xC4324633u,
   2.235 -        0xE85A1F02u, 0x09F0BE8Cu, 0x4A99A025u, 0x1D6EFE10u,
   2.236 -        0x1AB93D1Du, 0x0BA5A4DFu, 0xA186F20Fu, 0x2868F169u,
   2.237 -        0xDCB7DA83u, 0x573906FEu, 0xA1E2CE9Bu, 0x4FCD7F52u,
   2.238 -        0x50115E01u, 0xA70683FAu, 0xA002B5C4u, 0x0DE6D027u,
   2.239 -        0x9AF88C27u, 0x773F8641u, 0xC3604C06u, 0x61A806B5u,
   2.240 -        0xF0177A28u, 0xC0F586E0u, 0x006058AAu, 0x30DC7D62u,
   2.241 -        0x11E69ED7u, 0x2338EA63u, 0x53C2DD94u, 0xC2C21634u,
   2.242 -        0xBBCBEE56u, 0x90BCB6DEu, 0xEBFC7DA1u, 0xCE591D76u,
   2.243 -        0x6F05E409u, 0x4B7C0188u, 0x39720A3Du, 0x7C927C24u,
   2.244 -        0x86E3725Fu, 0x724D9DB9u, 0x1AC15BB4u, 0xD39EB8FCu,
   2.245 -        0xED545578u, 0x08FCA5B5u, 0xD83D7CD3u, 0x4DAD0FC4u,
   2.246 -        0x1E50EF5Eu, 0xB161E6F8u, 0xA28514D9u, 0x6C51133Cu,
   2.247 -        0x6FD5C7E7u, 0x56E14EC4u, 0x362ABFCEu, 0xDDC6C837u,
   2.248 -        0xD79A3234u, 0x92638212u, 0x670EFA8Eu, 0x406000E0u  },
   2.249 -    {   0x3A39CE37u, 0xD3FAF5CFu, 0xABC27737u, 0x5AC52D1Bu,
   2.250 -        0x5CB0679Eu, 0x4FA33742u, 0xD3822740u, 0x99BC9BBEu,
   2.251 -        0xD5118E9Du, 0xBF0F7315u, 0xD62D1C7Eu, 0xC700C47Bu,
   2.252 -        0xB78C1B6Bu, 0x21A19045u, 0xB26EB1BEu, 0x6A366EB4u,
   2.253 -        0x5748AB2Fu, 0xBC946E79u, 0xC6A376D2u, 0x6549C2C8u,
   2.254 -        0x530FF8EEu, 0x468DDE7Du, 0xD5730A1Du, 0x4CD04DC6u,
   2.255 -        0x2939BBDBu, 0xA9BA4650u, 0xAC9526E8u, 0xBE5EE304u,
   2.256 -        0xA1FAD5F0u, 0x6A2D519Au, 0x63EF8CE2u, 0x9A86EE22u,
   2.257 -        0xC089C2B8u, 0x43242EF6u, 0xA51E03AAu, 0x9CF2D0A4u,
   2.258 -        0x83C061BAu, 0x9BE96A4Du, 0x8FE51550u, 0xBA645BD6u,
   2.259 -        0x2826A2F9u, 0xA73A3AE1u, 0x4BA99586u, 0xEF5562E9u,
   2.260 -        0xC72FEFD3u, 0xF752F7DAu, 0x3F046F69u, 0x77FA0A59u,
   2.261 -        0x80E4A915u, 0x87B08601u, 0x9B09E6ADu, 0x3B3EE593u,
   2.262 -        0xE990FD5Au, 0x9E34D797u, 0x2CF0B7D9u, 0x022B8B51u,
   2.263 -        0x96D5AC3Au, 0x017DA67Du, 0xD1CF3ED6u, 0x7C7D2D28u,
   2.264 -        0x1F9F25CFu, 0xADF2B89Bu, 0x5AD6B472u, 0x5A88F54Cu,
   2.265 -        0xE029AC71u, 0xE019A5E6u, 0x47B0ACFDu, 0xED93FA9Bu,
   2.266 -        0xE8D3C48Du, 0x283B57CCu, 0xF8D56629u, 0x79132E28u,
   2.267 -        0x785F0191u, 0xED756055u, 0xF7960E44u, 0xE3D35E8Cu,
   2.268 -        0x15056DD4u, 0x88F46DBAu, 0x03A16125u, 0x0564F0BDu,
   2.269 -        0xC3EB9E15u, 0x3C9057A2u, 0x97271AECu, 0xA93A072Au,
   2.270 -        0x1B3F6D9Bu, 0x1E6321F5u, 0xF59C66FBu, 0x26DCF319u,
   2.271 -        0x7533D928u, 0xB155FDF5u, 0x03563482u, 0x8ABA3CBBu,
   2.272 -        0x28517711u, 0xC20AD9F8u, 0xABCC5167u, 0xCCAD925Fu,
   2.273 -        0x4DE81751u, 0x3830DC8Eu, 0x379D5862u, 0x9320F991u,
   2.274 -        0xEA7A90C2u, 0xFB3E7BCEu, 0x5121CE64u, 0x774FBE32u,
   2.275 -        0xA8B6E37Eu, 0xC3293D46u, 0x48DE5369u, 0x6413E680u,
   2.276 -        0xA2AE0810u, 0xDD6DB224u, 0x69852DFDu, 0x09072166u,
   2.277 -        0xB39A460Au, 0x6445C0DDu, 0x586CDECFu, 0x1C20C8AEu,
   2.278 -        0x5BBEF7DDu, 0x1B588D40u, 0xCCD2017Fu, 0x6BB4E3BBu,
   2.279 -        0xDDA26A7Eu, 0x3A59FF45u, 0x3E350A44u, 0xBCB4CDD5u,
   2.280 -        0x72EACEA8u, 0xFA6484BBu, 0x8D6612AEu, 0xBF3C6F47u,
   2.281 -        0xD29BE463u, 0x542F5D9Eu, 0xAEC2771Bu, 0xF64E6370u,
   2.282 -        0x740E0D8Du, 0xE75B1357u, 0xF8721671u, 0xAF537D5Du,
   2.283 -        0x4040CB08u, 0x4EB4E2CCu, 0x34D2466Au, 0x0115AF84u,
   2.284 -        0xE1B00428u, 0x95983A1Du, 0x06B89FB4u, 0xCE6EA048u,
   2.285 -        0x6F3F3B82u, 0x3520AB82u, 0x011A1D4Bu, 0x277227F8u,
   2.286 -        0x611560B1u, 0xE7933FDCu, 0xBB3A792Bu, 0x344525BDu,
   2.287 -        0xA08839E1u, 0x51CE794Bu, 0x2F32C9B7u, 0xA01FBAC9u,
   2.288 -        0xE01CC87Eu, 0xBCC7D1F6u, 0xCF0111C3u, 0xA1E8AAC7u,
   2.289 -        0x1A908749u, 0xD44FBD9Au, 0xD0DADECBu, 0xD50ADA38u,
   2.290 -        0x0339C32Au, 0xC6913667u, 0x8DF9317Cu, 0xE0B12B4Fu,
   2.291 -        0xF79E59B7u, 0x43F5BB3Au, 0xF2D519FFu, 0x27D9459Cu,
   2.292 -        0xBF97222Cu, 0x15E6FC2Au, 0x0F91FC71u, 0x9B941525u,
   2.293 -        0xFAE59361u, 0xCEB69CEBu, 0xC2A86459u, 0x12BAA8D1u,
   2.294 -        0xB6C1075Eu, 0xE3056A0Cu, 0x10D25065u, 0xCB03A442u,
   2.295 -        0xE0EC6E0Eu, 0x1698DB3Bu, 0x4C98A0BEu, 0x3278E964u,
   2.296 -        0x9F1F9532u, 0xE0D392DFu, 0xD3A0342Bu, 0x8971F21Eu,
   2.297 -        0x1B0A7441u, 0x4BA3348Cu, 0xC5BE7120u, 0xC37632D8u,
   2.298 -        0xDF359F8Du, 0x9B992F2Eu, 0xE60B6F47u, 0x0FE3F11Du,
   2.299 -        0xE54CDA54u, 0x1EDAD891u, 0xCE6279CFu, 0xCD3E7E6Fu,
   2.300 -        0x1618B166u, 0xFD2C1D05u, 0x848FD2C5u, 0xF6FB2299u,
   2.301 -        0xF523F357u, 0xA6327623u, 0x93A83531u, 0x56CCCD02u,
   2.302 -        0xACF08162u, 0x5A75EBB5u, 0x6E163697u, 0x88D273CCu,
   2.303 -        0xDE966292u, 0x81B949D0u, 0x4C50901Bu, 0x71C65614u,
   2.304 -        0xE6C6C7BDu, 0x327A140Au, 0x45E1D006u, 0xC3F27B9Au,
   2.305 -        0xC9AA53FDu, 0x62A80F00u, 0xBB25BFE2u, 0x35BDD2F6u,
   2.306 -        0x71126905u, 0xB2040222u, 0xB6CBCF7Cu, 0xCD769C2Bu,
   2.307 -        0x53113EC0u, 0x1640E3D3u, 0x38ABBD60u, 0x2547ADF0u,
   2.308 -        0xBA38209Cu, 0xF746CE76u, 0x77AFA1C5u, 0x20756060u,
   2.309 -        0x85CBFE4Eu, 0x8AE88DD8u, 0x7AAAF9B0u, 0x4CF9AA7Eu,
   2.310 -        0x1948C25Cu, 0x02FB8A8Cu, 0x01C36AE4u, 0xD6EBE1F9u,
   2.311 -        0x90D4F869u, 0xA65CDEA0u, 0x3F09252Du, 0xC208E69Fu,
   2.312 -        0xB74E6132u, 0xCE77E25Bu, 0x578FDFE3u, 0x3AC372E6u  }
   2.313 -};
   2.314 -
   2.315 -
   2.316 -static uint32_t F(BLOWFISH_CTX *ctx, uint32_t x) {
   2.317 -    uint16_t a, b, c, d;
   2.318 -    uint32_t  y;
   2.319 -
   2.320 -    d = (uint16_t)(x & 0xFF);
   2.321 -    x >>= 8;
   2.322 -    c = (uint16_t)(x & 0xFF);
   2.323 -    x >>= 8;
   2.324 -    b = (uint16_t)(x & 0xFF);
   2.325 -    x >>= 8;
   2.326 -    a = (uint16_t)(x & 0xFF);
   2.327 -    y = ctx->S[0][a] + ctx->S[1][b];
   2.328 -    y = y ^ ctx->S[2][c];
   2.329 -    y = y + ctx->S[3][d];
   2.330 -
   2.331 -    return y;
   2.332 -}
   2.333 -
   2.334 -
   2.335 -static void Blowfish_Encrypt(BLOWFISH_CTX *ctx, uint32_t *xl, uint32_t *xr){
   2.336 -    uint32_t  Xl;
   2.337 -    uint32_t  Xr;
   2.338 -    uint32_t  temp;
   2.339 -    short       i;
   2.340 -
   2.341 -    Xl = *xl;
   2.342 -    Xr = *xr;
   2.343 -
   2.344 -    for (i = 0; i < N; ++i) {
   2.345 -        Xl = Xl ^ ctx->P[i];
   2.346 -        Xr = F(ctx, Xl) ^ Xr;
   2.347 -
   2.348 -        temp = Xl;
   2.349 -        Xl = Xr;
   2.350 -        Xr = temp;
   2.351 -    }
   2.352 -
   2.353 -    temp = Xl;
   2.354 -    Xl = Xr;
   2.355 -    Xr = temp;
   2.356 -
   2.357 -    Xr = Xr ^ ctx->P[N];
   2.358 -    Xl = Xl ^ ctx->P[N + 1];
   2.359 -
   2.360 -    *xl = Xl;
   2.361 -    *xr = Xr;
   2.362 -}
   2.363 -
   2.364 -
   2.365 -static void Blowfish_Decrypt(BLOWFISH_CTX *ctx, uint32_t *xl, uint32_t *xr){
   2.366 -    uint32_t  Xl;
   2.367 -    uint32_t  Xr;
   2.368 -    uint32_t  temp;
   2.369 -    short       i;
   2.370 -
   2.371 -    Xl = *xl;
   2.372 -    Xr = *xr;
   2.373 -
   2.374 -    for (i = N + 1; i > 1; --i) {
   2.375 -        Xl = Xl ^ ctx->P[i];
   2.376 -        Xr = F(ctx, Xl) ^ Xr;
   2.377 -
   2.378 -        /* Exchange Xl and Xr */
   2.379 -        temp = Xl;
   2.380 -        Xl = Xr;
   2.381 -        Xr = temp;
   2.382 -    }
   2.383 -
   2.384 -    /* Exchange Xl and Xr */
   2.385 -    temp = Xl;
   2.386 -    Xl = Xr;
   2.387 -    Xr = temp;
   2.388 -
   2.389 -    Xr = Xr ^ ctx->P[1];
   2.390 -    Xl = Xl ^ ctx->P[0];
   2.391 -
   2.392 -    *xl = Xl;
   2.393 -    *xr = Xr;
   2.394 -}
   2.395 -
   2.396 -static void Blowfish_Init(BLOWFISH_CTX *ctx, unsigned char *key, int keyLen) {
   2.397 -    int i, j, k;
   2.398 -    uint32_t data, datal, datar;
   2.399 -
   2.400 -    for (i = 0; i < 4; i++) {
   2.401 -        for (j = 0; j < 256; j++)
   2.402 -            ctx->S[i][j] = ORIG_S[i][j];
   2.403 -    }
   2.404 -
   2.405 -    j = 0;
   2.406 -    for (i = 0; i < N + 2; ++i) {
   2.407 -        data = 0x00000000;
   2.408 -        for (k = 0; k < 4; ++k) {
   2.409 -            data = (data << 8) | key[j];
   2.410 -            j = j + 1;
   2.411 -            if (j >= keyLen)
   2.412 -                j = 0;
   2.413 -        }
   2.414 -        ctx->P[i] = ORIG_P[i] ^ data;
   2.415 -    }
   2.416 -
   2.417 -    datal = 0x00000000;
   2.418 -    datar = 0x00000000;
   2.419 -
   2.420 -    for (i = 0; i < N + 2; i += 2) {
   2.421 -        Blowfish_Encrypt(ctx, &datal, &datar);
   2.422 -        ctx->P[i] = datal;
   2.423 -        ctx->P[i + 1] = datar;
   2.424 -    }
   2.425 -
   2.426 -    for (i = 0; i < 4; ++i) {
   2.427 -        for (j = 0; j < 256; j += 2) {
   2.428 -            Blowfish_Encrypt(ctx, &datal, &datar);
   2.429 -            ctx->S[i][j] = datal;
   2.430 -            ctx->S[i][j + 1] = datar;
   2.431 -        }
   2.432 -    }
   2.433 -}
   2.434 -
   2.435 -uint64_t blowfish_test(uint64_t input)
   2.436 -{
   2.437 -    uint32_t L = input >> 32, R = input;
   2.438 -    BLOWFISH_CTX ctx;
   2.439 -    Blowfish_Init(&ctx, (unsigned char*)"TESTKEY", 7);
   2.440 -    Blowfish_Encrypt(&ctx, &L, &R);
   2.441 -    Blowfish_Decrypt(&ctx, &L, &R);
   2.442 -    return ((uint64_t)L << 32) | R;
   2.443 -}
     3.1 --- a/tools/tests/blowfish.mk	Sat Jan 08 10:52:45 2011 +0000
     3.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.3 @@ -1,17 +0,0 @@
     3.4 -
     3.5 -XEN_ROOT = ../..
     3.6 -CFLAGS =
     3.7 -include $(XEN_ROOT)/tools/Rules.mk
     3.8 -
     3.9 -$(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS))
    3.10 -
    3.11 -CFLAGS += -fno-builtin -msoft-float
    3.12 -
    3.13 -.PHONY: all
    3.14 -all: blowfish.bin
    3.15 -
    3.16 -blowfish.bin: blowfish.c
    3.17 -	$(CC) $(CFLAGS) -c blowfish.c
    3.18 -	$(LD) $(LDFLAGS_DIRECT) -N -Ttext 0x100000 -o blowfish.tmp blowfish.o
    3.19 -	$(OBJCOPY) -O binary blowfish.tmp blowfish.bin
    3.20 -	rm -f blowfish.tmp
     4.1 --- a/tools/tests/test_x86_emulator.c	Sat Jan 08 10:52:45 2011 +0000
     4.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     4.3 @@ -1,503 +0,0 @@
     4.4 -#include <stdio.h>
     4.5 -#include <stdlib.h>
     4.6 -#include <string.h>
     4.7 -#include <stdint.h>
     4.8 -#include <public/xen.h>
     4.9 -#include <sys/mman.h>
    4.10 -
    4.11 -#include "x86_emulate/x86_emulate.h"
    4.12 -#include "blowfish.h"
    4.13 -
    4.14 -#define MMAP_SZ 16384
    4.15 -
    4.16 -/* EFLAGS bit definitions. */
    4.17 -#define EFLG_OF (1<<11)
    4.18 -#define EFLG_DF (1<<10)
    4.19 -#define EFLG_SF (1<<7)
    4.20 -#define EFLG_ZF (1<<6)
    4.21 -#define EFLG_AF (1<<4)
    4.22 -#define EFLG_PF (1<<2)
    4.23 -#define EFLG_CF (1<<0)
    4.24 -
    4.25 -static int read(
    4.26 -    unsigned int seg,
    4.27 -    unsigned long offset,
    4.28 -    void *p_data,
    4.29 -    unsigned int bytes,
    4.30 -    struct x86_emulate_ctxt *ctxt)
    4.31 -{
    4.32 -    memcpy(p_data, (void *)offset, bytes);
    4.33 -    return X86EMUL_OKAY;
    4.34 -}
    4.35 -
    4.36 -static int write(
    4.37 -    unsigned int seg,
    4.38 -    unsigned long offset,
    4.39 -    void *p_data,
    4.40 -    unsigned int bytes,
    4.41 -    struct x86_emulate_ctxt *ctxt)
    4.42 -{
    4.43 -    memcpy((void *)offset, p_data, bytes);
    4.44 -    return X86EMUL_OKAY;
    4.45 -}
    4.46 -
    4.47 -static int cmpxchg(
    4.48 -    unsigned int seg,
    4.49 -    unsigned long offset,
    4.50 -    void *old,
    4.51 -    void *new,
    4.52 -    unsigned int bytes,
    4.53 -    struct x86_emulate_ctxt *ctxt)
    4.54 -{
    4.55 -    memcpy((void *)offset, new, bytes);
    4.56 -    return X86EMUL_OKAY;
    4.57 -}
    4.58 -
    4.59 -static struct x86_emulate_ops emulops = {
    4.60 -    .read       = read,
    4.61 -    .insn_fetch = read,
    4.62 -    .write      = write,
    4.63 -    .cmpxchg    = cmpxchg,
    4.64 -};
    4.65 -
    4.66 -int main(int argc, char **argv)
    4.67 -{
    4.68 -    struct x86_emulate_ctxt ctxt;
    4.69 -    struct cpu_user_regs regs;
    4.70 -    char *instr;
    4.71 -    unsigned int *res, i, j;
    4.72 -    int rc;
    4.73 -#ifndef __x86_64__
    4.74 -    unsigned int bcdres_native, bcdres_emul;
    4.75 -#endif
    4.76 -
    4.77 -    ctxt.regs = &regs;
    4.78 -    ctxt.force_writeback = 0;
    4.79 -    ctxt.addr_size = 32;
    4.80 -    ctxt.sp_size   = 32;
    4.81 -
    4.82 -    res = mmap((void *)0x100000, MMAP_SZ, PROT_READ|PROT_WRITE|PROT_EXEC,
    4.83 -               MAP_FIXED|MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
    4.84 -    if ( res == MAP_FAILED )
    4.85 -    {
    4.86 -        fprintf(stderr, "mmap to low address failed\n");
    4.87 -        exit(1);
    4.88 -    }
    4.89 -    instr = (char *)res + 0x100;
    4.90 -
    4.91 -    printf("%-40s", "Testing addl %%ecx,(%%eax)...");
    4.92 -    instr[0] = 0x01; instr[1] = 0x08;
    4.93 -    regs.eflags = 0x200;
    4.94 -    regs.eip    = (unsigned long)&instr[0];
    4.95 -    regs.ecx    = 0x12345678;
    4.96 -    regs.eax    = (unsigned long)res;
    4.97 -    *res        = 0x7FFFFFFF;
    4.98 -    rc = x86_emulate(&ctxt, &emulops);
    4.99 -    if ( (rc != X86EMUL_OKAY) || 
   4.100 -         (*res != 0x92345677) || 
   4.101 -         (regs.eflags != 0xa94) ||
   4.102 -         (regs.eip != (unsigned long)&instr[2]) )
   4.103 -        goto fail;
   4.104 -    printf("okay\n");
   4.105 -
   4.106 -    printf("%-40s", "Testing addl %%ecx,%%eax...");
   4.107 -    instr[0] = 0x01; instr[1] = 0xc8;
   4.108 -    regs.eflags = 0x200;
   4.109 -    regs.eip    = (unsigned long)&instr[0];
   4.110 -    regs.ecx    = 0x12345678;
   4.111 -    regs.eax    = 0x7FFFFFFF;
   4.112 -    rc = x86_emulate(&ctxt, &emulops);
   4.113 -    if ( (rc != X86EMUL_OKAY) || 
   4.114 -         (regs.ecx != 0x12345678) ||
   4.115 -         (regs.eax != 0x92345677) ||
   4.116 -         (regs.eflags != 0xa94) ||
   4.117 -         (regs.eip != (unsigned long)&instr[2]) )
   4.118 -        goto fail;
   4.119 -    printf("okay\n");
   4.120 -
   4.121 -    printf("%-40s", "Testing xorl (%%eax),%%ecx...");
   4.122 -    instr[0] = 0x33; instr[1] = 0x08;
   4.123 -    regs.eflags = 0x200;
   4.124 -    regs.eip    = (unsigned long)&instr[0];
   4.125 -#ifdef __x86_64__
   4.126 -    regs.ecx    = 0xFFFFFFFF12345678UL;
   4.127 -#else
   4.128 -    regs.ecx    = 0x12345678UL;
   4.129 -#endif
   4.130 -    regs.eax    = (unsigned long)res;
   4.131 -    rc = x86_emulate(&ctxt, &emulops);
   4.132 -    if ( (rc != X86EMUL_OKAY) || 
   4.133 -         (*res != 0x92345677) || 
   4.134 -         (regs.ecx != 0x8000000FUL) ||
   4.135 -         (regs.eip != (unsigned long)&instr[2]) )
   4.136 -        goto fail;
   4.137 -    printf("okay\n");
   4.138 -
   4.139 -    printf("%-40s", "Testing movl (%%eax),%%ecx...");
   4.140 -    instr[0] = 0x8b; instr[1] = 0x08;
   4.141 -    regs.eflags = 0x200;
   4.142 -    regs.eip    = (unsigned long)&instr[0];
   4.143 -    regs.ecx    = ~0UL;
   4.144 -    regs.eax    = (unsigned long)res;
   4.145 -    rc = x86_emulate(&ctxt, &emulops);
   4.146 -    if ( (rc != X86EMUL_OKAY) || 
   4.147 -         (*res != 0x92345677) || 
   4.148 -         (regs.ecx != 0x92345677UL) ||
   4.149 -         (regs.eip != (unsigned long)&instr[2]) )
   4.150 -        goto fail;
   4.151 -    printf("okay\n");
   4.152 -
   4.153 -    printf("%-40s", "Testing lock cmpxchgb %%cl,(%%ebx)...");
   4.154 -    instr[0] = 0xf0; instr[1] = 0x0f; instr[2] = 0xb0; instr[3] = 0x0b;
   4.155 -    regs.eflags = 0x200;
   4.156 -    regs.eip    = (unsigned long)&instr[0];
   4.157 -    regs.eax    = 0x92345677UL;
   4.158 -    regs.ecx    = 0xAA;
   4.159 -    regs.ebx    = (unsigned long)res;
   4.160 -    rc = x86_emulate(&ctxt, &emulops);
   4.161 -    if ( (rc != X86EMUL_OKAY) || 
   4.162 -         (*res != 0x923456AA) || 
   4.163 -         (regs.eflags != 0x244) ||
   4.164 -         (regs.eax != 0x92345677UL) ||
   4.165 -         (regs.eip != (unsigned long)&instr[4]) )
   4.166 -        goto fail;
   4.167 -    printf("okay\n");
   4.168 -
   4.169 -    printf("%-40s", "Testing lock cmpxchgb %%cl,(%%ebx)...");
   4.170 -    instr[0] = 0xf0; instr[1] = 0x0f; instr[2] = 0xb0; instr[3] = 0x0b;
   4.171 -    regs.eflags = 0x200;
   4.172 -    regs.eip    = (unsigned long)&instr[0];
   4.173 -    regs.eax    = 0xAABBCC77UL;
   4.174 -    regs.ecx    = 0xFF;
   4.175 -    regs.ebx    = (unsigned long)res;
   4.176 -    rc = x86_emulate(&ctxt, &emulops);
   4.177 -    if ( (rc != X86EMUL_OKAY) || 
   4.178 -         (*res != 0x923456AA) || 
   4.179 -         ((regs.eflags&0x240) != 0x200) ||
   4.180 -         (regs.eax != 0xAABBCCAA) ||
   4.181 -         (regs.ecx != 0xFF) ||
   4.182 -         (regs.eip != (unsigned long)&instr[4]) )
   4.183 -        goto fail;
   4.184 -    printf("okay\n");
   4.185 -
   4.186 -    printf("%-40s", "Testing xchgl %%ecx,(%%eax)...");
   4.187 -    instr[0] = 0x87; instr[1] = 0x08;
   4.188 -    regs.eflags = 0x200;
   4.189 -    regs.eip    = (unsigned long)&instr[0];
   4.190 -    regs.ecx    = 0x12345678;
   4.191 -    regs.eax    = (unsigned long)res;
   4.192 -    rc = x86_emulate(&ctxt, &emulops);
   4.193 -    if ( (rc != X86EMUL_OKAY) || 
   4.194 -         (*res != 0x12345678) || 
   4.195 -         (regs.eflags != 0x200) ||
   4.196 -         (regs.ecx != 0x923456AA) ||
   4.197 -         (regs.eip != (unsigned long)&instr[2]) )
   4.198 -        goto fail;
   4.199 -    printf("okay\n");
   4.200 -
   4.201 -    printf("%-40s", "Testing lock cmpxchgl %%ecx,(%%ebx)...");
   4.202 -    instr[0] = 0xf0; instr[1] = 0x0f; instr[2] = 0xb1; instr[3] = 0x0b;
   4.203 -    regs.eflags = 0x200;
   4.204 -    *res        = 0x923456AA;
   4.205 -    regs.eip    = (unsigned long)&instr[0];
   4.206 -    regs.eax    = 0x923456AAUL;
   4.207 -    regs.ecx    = 0xDDEEFF00L;
   4.208 -    regs.ebx    = (unsigned long)res;
   4.209 -    rc = x86_emulate(&ctxt, &emulops);
   4.210 -    if ( (rc != X86EMUL_OKAY) || 
   4.211 -         (*res != 0xDDEEFF00) || 
   4.212 -         (regs.eflags != 0x244) ||
   4.213 -         (regs.eax != 0x923456AAUL) ||
   4.214 -         (regs.eip != (unsigned long)&instr[4]) )
   4.215 -        goto fail;
   4.216 -    printf("okay\n");
   4.217 -
   4.218 -    printf("%-40s", "Testing rep movsw...");
   4.219 -    instr[0] = 0xf3; instr[1] = 0x66; instr[2] = 0xa5;
   4.220 -    *res        = 0x22334455;
   4.221 -    regs.eflags = 0x200;
   4.222 -    regs.ecx    = 23;
   4.223 -    regs.eip    = (unsigned long)&instr[0];
   4.224 -    regs.esi    = (unsigned long)res + 0;
   4.225 -    regs.edi    = (unsigned long)res + 2;
   4.226 -    rc = x86_emulate(&ctxt, &emulops);
   4.227 -    if ( (rc != X86EMUL_OKAY) || 
   4.228 -         (*res != 0x44554455) ||
   4.229 -         (regs.eflags != 0x200) ||
   4.230 -         (regs.ecx != 22) || 
   4.231 -         (regs.esi != ((unsigned long)res + 2)) ||
   4.232 -         (regs.edi != ((unsigned long)res + 4)) ||
   4.233 -         (regs.eip != (unsigned long)&instr[0]) )
   4.234 -        goto fail;
   4.235 -    printf("okay\n");
   4.236 -
   4.237 -    printf("%-40s", "Testing btrl $0x1,(%edi)...");
   4.238 -    instr[0] = 0x0f; instr[1] = 0xba; instr[2] = 0x37; instr[3] = 0x01;
   4.239 -    *res        = 0x2233445F;
   4.240 -    regs.eflags = 0x200;
   4.241 -    regs.eip    = (unsigned long)&instr[0];
   4.242 -    regs.edi    = (unsigned long)res;
   4.243 -    rc = x86_emulate(&ctxt, &emulops);
   4.244 -    if ( (rc != X86EMUL_OKAY) ||
   4.245 -         (*res != 0x2233445D) ||
   4.246 -         ((regs.eflags&0x201) != 0x201) ||
   4.247 -         (regs.eip != (unsigned long)&instr[4]) )
   4.248 -        goto fail;
   4.249 -    printf("okay\n");
   4.250 -
   4.251 -    printf("%-40s", "Testing btrl %eax,(%edi)...");
   4.252 -    instr[0] = 0x0f; instr[1] = 0xb3; instr[2] = 0x07;
   4.253 -    *res        = 0x2233445F;
   4.254 -    regs.eflags = 0x200;
   4.255 -    regs.eip    = (unsigned long)&instr[0];
   4.256 -    regs.eax    = -32;
   4.257 -    regs.edi    = (unsigned long)(res+1);
   4.258 -    rc = x86_emulate(&ctxt, &emulops);
   4.259 -    if ( (rc != X86EMUL_OKAY) ||
   4.260 -         (*res != 0x2233445E) ||
   4.261 -         ((regs.eflags&0x201) != 0x201) ||
   4.262 -         (regs.eip != (unsigned long)&instr[3]) )
   4.263 -        goto fail;
   4.264 -    printf("okay\n");
   4.265 -
   4.266 -    res[0] = 0x12345678;
   4.267 -    res[1] = 0x87654321;
   4.268 -
   4.269 -    printf("%-40s", "Testing cmpxchg8b (%edi) [succeeding]...");
   4.270 -    instr[0] = 0x0f; instr[1] = 0xc7; instr[2] = 0x0f;
   4.271 -    regs.eflags = 0x200;
   4.272 -    regs.eax    = res[0];
   4.273 -    regs.edx    = res[1];
   4.274 -    regs.ebx    = 0x9999AAAA;
   4.275 -    regs.ecx    = 0xCCCCFFFF;
   4.276 -    regs.eip    = (unsigned long)&instr[0];
   4.277 -    regs.edi    = (unsigned long)res;
   4.278 -    rc = x86_emulate(&ctxt, &emulops);
   4.279 -    if ( (rc != X86EMUL_OKAY) ||
   4.280 -         (res[0] != 0x9999AAAA) ||
   4.281 -         (res[1] != 0xCCCCFFFF) ||
   4.282 -         ((regs.eflags&0x240) != 0x240) ||
   4.283 -         (regs.eip != (unsigned long)&instr[3]) )
   4.284 -        goto fail;
   4.285 -    printf("okay\n");
   4.286 -
   4.287 -    printf("%-40s", "Testing cmpxchg8b (%edi) [failing]...");
   4.288 -    instr[0] = 0x0f; instr[1] = 0xc7; instr[2] = 0x0f;
   4.289 -    regs.eflags = 0x200;
   4.290 -    regs.eip    = (unsigned long)&instr[0];
   4.291 -    regs.edi    = (unsigned long)res;
   4.292 -    rc = x86_emulate(&ctxt, &emulops);
   4.293 -    if ( (rc != X86EMUL_OKAY) || 
   4.294 -         (res[0] != 0x9999AAAA) ||
   4.295 -         (res[1] != 0xCCCCFFFF) ||
   4.296 -         (regs.eax != 0x9999AAAA) ||
   4.297 -         (regs.edx != 0xCCCCFFFF) ||
   4.298 -         ((regs.eflags&0x240) != 0x200) ||
   4.299 -         (regs.eip != (unsigned long)&instr[3]) )
   4.300 -        goto fail;
   4.301 -    printf("okay\n");
   4.302 -
   4.303 -    printf("%-40s", "Testing movsxbd (%%eax),%%ecx...");
   4.304 -    instr[0] = 0x0f; instr[1] = 0xbe; instr[2] = 0x08;
   4.305 -    regs.eflags = 0x200;
   4.306 -    regs.eip    = (unsigned long)&instr[0];
   4.307 -    regs.ecx    = 0x12345678;
   4.308 -    regs.eax    = (unsigned long)res;
   4.309 -    *res        = 0x82;
   4.310 -    rc = x86_emulate(&ctxt, &emulops);
   4.311 -    if ( (rc != X86EMUL_OKAY) ||
   4.312 -         (*res != 0x82) ||
   4.313 -         (regs.ecx != 0xFFFFFF82) ||
   4.314 -         ((regs.eflags&0x240) != 0x200) ||
   4.315 -         (regs.eip != (unsigned long)&instr[3]) )
   4.316 -        goto fail;
   4.317 -    printf("okay\n");
   4.318 -
   4.319 -    printf("%-40s", "Testing movzxwd (%%eax),%%ecx...");
   4.320 -    instr[0] = 0x0f; instr[1] = 0xb7; instr[2] = 0x08;
   4.321 -    regs.eflags = 0x200;
   4.322 -    regs.eip    = (unsigned long)&instr[0];
   4.323 -    regs.ecx    = 0x12345678;
   4.324 -    regs.eax    = (unsigned long)res;
   4.325 -    *res        = 0x1234aa82;
   4.326 -    rc = x86_emulate(&ctxt, &emulops);
   4.327 -    if ( (rc != X86EMUL_OKAY) ||
   4.328 -         (*res != 0x1234aa82) ||
   4.329 -         (regs.ecx != 0xaa82) ||
   4.330 -         ((regs.eflags&0x240) != 0x200) ||
   4.331 -         (regs.eip != (unsigned long)&instr[3]) )
   4.332 -        goto fail;
   4.333 -    printf("okay\n");
   4.334 -
   4.335 -    printf("%-40s", "Testing xadd %%ax,(%%ecx)...");
   4.336 -    instr[0] = 0x66; instr[1] = 0x0f; instr[2] = 0xc1; instr[3] = 0x01;
   4.337 -    regs.eflags = 0x200;
   4.338 -    regs.eip    = (unsigned long)&instr[0];
   4.339 -    regs.ecx    = (unsigned long)res;
   4.340 -    regs.eax    = 0x12345678;
   4.341 -    *res        = 0x11111111;
   4.342 -    rc = x86_emulate(&ctxt, &emulops);
   4.343 -    if ( (rc != X86EMUL_OKAY) ||
   4.344 -         (*res != 0x11116789) ||
   4.345 -         (regs.eax != 0x12341111) ||
   4.346 -         ((regs.eflags&0x240) != 0x200) ||
   4.347 -         (regs.eip != (unsigned long)&instr[4]) )
   4.348 -        goto fail;
   4.349 -    printf("okay\n");
   4.350 -
   4.351 -    printf("%-40s", "Testing dec %%ax...");
   4.352 -    instr[0] = 0x66; instr[1] = 0x48;
   4.353 -    regs.eflags = 0x200;
   4.354 -    regs.eip    = (unsigned long)&instr[0];
   4.355 -    regs.eax    = 0x00000000;
   4.356 -    rc = x86_emulate(&ctxt, &emulops);
   4.357 -    if ( (rc != X86EMUL_OKAY) ||
   4.358 -         (regs.eax != 0x0000ffff) ||
   4.359 -         ((regs.eflags&0x240) != 0x200) ||
   4.360 -         (regs.eip != (unsigned long)&instr[2]) )
   4.361 -        goto fail;
   4.362 -    printf("okay\n");
   4.363 -
   4.364 -    printf("%-40s", "Testing lea 8(%%ebp),%%eax...");
   4.365 -    instr[0] = 0x8d; instr[1] = 0x45; instr[2] = 0x08;
   4.366 -    regs.eflags = 0x200;
   4.367 -    regs.eip    = (unsigned long)&instr[0];
   4.368 -    regs.eax    = 0x12345678;
   4.369 -    regs.ebp    = 0xaaaaaaaa;
   4.370 -    rc = x86_emulate(&ctxt, &emulops);
   4.371 -    if ( (rc != X86EMUL_OKAY) ||
   4.372 -         (regs.eax != 0xaaaaaab2) ||
   4.373 -         ((regs.eflags&0x240) != 0x200) ||
   4.374 -         (regs.eip != (unsigned long)&instr[3]) )
   4.375 -        goto fail;
   4.376 -    printf("okay\n");
   4.377 -
   4.378 -    printf("%-40s", "Testing daa/das (all inputs)...");
   4.379 -#ifndef __x86_64__
   4.380 -    /* Bits 0-7: AL; Bit 8: EFLG_AF; Bit 9: EFLG_CF; Bit 10: DAA vs. DAS. */
   4.381 -    for ( i = 0; i < 0x800; i++ )
   4.382 -    {
   4.383 -        regs.eflags  = (i & 0x200) ? EFLG_CF : 0;
   4.384 -        regs.eflags |= (i & 0x100) ? EFLG_AF : 0;
   4.385 -        if ( i & 0x400 )
   4.386 -            __asm__ (
   4.387 -                "pushf; and $0xffffffee,(%%esp); or %1,(%%esp); popf; das; "
   4.388 -                "pushf; popl %1"
   4.389 -                : "=a" (bcdres_native), "=r" (regs.eflags)
   4.390 -                : "0" (i & 0xff), "1" (regs.eflags) );
   4.391 -        else
   4.392 -            __asm__ (
   4.393 -                "pushf; and $0xffffffee,(%%esp); or %1,(%%esp); popf; daa; "
   4.394 -                "pushf; popl %1"
   4.395 -                : "=a" (bcdres_native), "=r" (regs.eflags)
   4.396 -                : "0" (i & 0xff), "1" (regs.eflags) );
   4.397 -        bcdres_native |= (regs.eflags & EFLG_PF) ? 0x1000 : 0;
   4.398 -        bcdres_native |= (regs.eflags & EFLG_ZF) ? 0x800 : 0;
   4.399 -        bcdres_native |= (regs.eflags & EFLG_SF) ? 0x400 : 0;
   4.400 -        bcdres_native |= (regs.eflags & EFLG_CF) ? 0x200 : 0;
   4.401 -        bcdres_native |= (regs.eflags & EFLG_AF) ? 0x100 : 0;
   4.402 -
   4.403 -        instr[0] = (i & 0x400) ? 0x2f: 0x27; /* daa/das */
   4.404 -        regs.eflags  = (i & 0x200) ? EFLG_CF : 0;
   4.405 -        regs.eflags |= (i & 0x100) ? EFLG_AF : 0;
   4.406 -        regs.eip    = (unsigned long)&instr[0];
   4.407 -        regs.eax    = (unsigned char)i;
   4.408 -        rc = x86_emulate(&ctxt, &emulops);
   4.409 -        bcdres_emul  = regs.eax;
   4.410 -        bcdres_emul |= (regs.eflags & EFLG_PF) ? 0x1000 : 0;
   4.411 -        bcdres_emul |= (regs.eflags & EFLG_ZF) ? 0x800 : 0;
   4.412 -        bcdres_emul |= (regs.eflags & EFLG_SF) ? 0x400 : 0;
   4.413 -        bcdres_emul |= (regs.eflags & EFLG_CF) ? 0x200 : 0;
   4.414 -        bcdres_emul |= (regs.eflags & EFLG_AF) ? 0x100 : 0;
   4.415 -        if ( (rc != X86EMUL_OKAY) || (regs.eax > 255) ||
   4.416 -             (regs.eip != (unsigned long)&instr[1]) )
   4.417 -            goto fail;
   4.418 -
   4.419 -        if ( bcdres_emul != bcdres_native )
   4.420 -        {
   4.421 -            printf("%s:    AL=%02x %s %s\n"
   4.422 -                   "Output: AL=%02x %s %s %s %s %s\n"
   4.423 -                   "Emul.:  AL=%02x %s %s %s %s %s\n",
   4.424 -                   (i & 0x400) ? "DAS" : "DAA",
   4.425 -                   (unsigned char)i,
   4.426 -                   (i & 0x200) ? "CF" : "  ",
   4.427 -                   (i & 0x100) ? "AF" : "  ",
   4.428 -                   (unsigned char)bcdres_native,
   4.429 -                   (bcdres_native & 0x200) ? "CF" : "  ",
   4.430 -                   (bcdres_native & 0x100) ? "AF" : "  ",
   4.431 -                   (bcdres_native & 0x1000) ? "PF" : "  ",
   4.432 -                   (bcdres_native & 0x800) ? "ZF" : "  ",
   4.433 -                   (bcdres_native & 0x400) ? "SF" : "  ",
   4.434 -                   (unsigned char)bcdres_emul,
   4.435 -                   (bcdres_emul & 0x200) ? "CF" : "  ",
   4.436 -                   (bcdres_emul & 0x100) ? "AF" : "  ",
   4.437 -                   (bcdres_emul & 0x1000) ? "PF" : "  ",
   4.438 -                   (bcdres_emul & 0x800) ? "ZF" : "  ",
   4.439 -                   (bcdres_emul & 0x400) ? "SF" : "  ");
   4.440 -            goto fail;
   4.441 -        }
   4.442 -    }
   4.443 -    printf("okay\n");
   4.444 -#else
   4.445 -    printf("skipped\n");
   4.446 -#endif
   4.447 -
   4.448 -    for ( j = 1; j <= 2; j++ )
   4.449 -    {
   4.450 -#if defined(__i386__)
   4.451 -        if ( j == 2 ) break;
   4.452 -        memcpy(res, blowfish32_code, sizeof(blowfish32_code));
   4.453 -#else
   4.454 -        memcpy(res, (j == 1) ? blowfish32_code : blowfish64_code,
   4.455 -               (j == 1) ? sizeof(blowfish32_code) : sizeof(blowfish64_code));
   4.456 -#endif
   4.457 -        printf("Testing blowfish %u-bit code sequence", j*32);
   4.458 -        regs.eax = 2;
   4.459 -        regs.edx = 1;
   4.460 -        regs.eip = (unsigned long)res;
   4.461 -        regs.esp = (unsigned long)res + MMAP_SZ - 4;
   4.462 -        if ( j == 2 )
   4.463 -        {
   4.464 -            ctxt.addr_size = ctxt.sp_size = 64;
   4.465 -            *(uint32_t *)(unsigned long)regs.esp = 0;
   4.466 -            regs.esp -= 4;
   4.467 -        }
   4.468 -        *(uint32_t *)(unsigned long)regs.esp = 0x12345678;
   4.469 -        regs.eflags = 2;
   4.470 -        i = 0;
   4.471 -        while ( regs.eip != 0x12345678 )
   4.472 -        {
   4.473 -            if ( (i++ & 8191) == 0 )
   4.474 -                printf(".");
   4.475 -            rc = x86_emulate(&ctxt, &emulops);
   4.476 -            if ( rc != X86EMUL_OKAY )
   4.477 -            {
   4.478 -                printf("failed at %%eip == %08x\n", (unsigned int)regs.eip);
   4.479 -                return 1;
   4.480 -            }
   4.481 -        }
   4.482 -        if ( (regs.esp != ((unsigned long)res + MMAP_SZ)) ||
   4.483 -             (regs.eax != 2) || (regs.edx != 1) )
   4.484 -            goto fail;
   4.485 -        printf("okay\n");
   4.486 -    }
   4.487 -
   4.488 -    printf("%-40s", "Testing blowfish native execution...");    
   4.489 -    asm volatile (
   4.490 -#if defined(__i386__)
   4.491 -        "movl $0x100000,%%ecx; call *%%ecx"
   4.492 -#else
   4.493 -        "movl $0x100000,%%ecx; call *%%rcx"
   4.494 -#endif
   4.495 -        : "=a" (regs.eax), "=d" (regs.edx)
   4.496 -        : "0" (2), "1" (1) : "ecx" );
   4.497 -    if ( (regs.eax != 2) || (regs.edx != 1) )
   4.498 -        goto fail;
   4.499 -    printf("okay\n");
   4.500 -
   4.501 -    return 0;
   4.502 -
   4.503 - fail:
   4.504 -    printf("failed!\n");
   4.505 -    return 1;
   4.506 -}
     5.1 --- a/tools/tests/x86_emulate.c	Sat Jan 08 10:52:45 2011 +0000
     5.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.3 @@ -1,7 +0,0 @@
     5.4 -#include <stddef.h>
     5.5 -#include <stdint.h>
     5.6 -#include <string.h>
     5.7 -#include <public/xen.h>
     5.8 -
     5.9 -#include "x86_emulate/x86_emulate.h"
    5.10 -#include "x86_emulate/x86_emulate.c"
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/tools/tests/x86_emulator/Makefile	Sat Jan 08 10:59:13 2011 +0000
     6.3 @@ -0,0 +1,44 @@
     6.4 +
     6.5 +XEN_ROOT=../../..
     6.6 +include $(XEN_ROOT)/tools/Rules.mk
     6.7 +
     6.8 +TARGET := test_x86_emulator
     6.9 +
    6.10 +.PHONY: all
    6.11 +all: $(TARGET)
    6.12 +
    6.13 +.PHONY: blowfish.h
    6.14 +blowfish.h:
    6.15 +	rm -f blowfish.bin
    6.16 +	XEN_TARGET_ARCH=x86_32 make -f blowfish.mk all
    6.17 +	(echo "static unsigned int blowfish32_code[] = {"; \
    6.18 +	od -v -t x blowfish.bin | sed 's/^[0-9]* /0x/' | sed 's/ /, 0x/g' | sed 's/$$/,/';\
    6.19 +	echo "};") >$@
    6.20 +	rm -f blowfish.bin
    6.21 +ifeq ($(XEN_COMPILE_ARCH),x86_64)
    6.22 +	XEN_TARGET_ARCH=x86_64 make -f blowfish.mk all
    6.23 +	(echo "static unsigned int blowfish64_code[] = {"; \
    6.24 +	od -v -t x blowfish.bin | sed 's/^[0-9]* /0x/' | sed 's/ /, 0x/g' | sed 's/$$/,/';\
    6.25 +	echo "};") >>$@
    6.26 +	rm -f blowfish.bin
    6.27 +endif
    6.28 +
    6.29 +$(TARGET): x86_emulate.o test_x86_emulator.o
    6.30 +	$(HOSTCC) -o $@ $^
    6.31 +
    6.32 +.PHONY: clean
    6.33 +clean:
    6.34 +	rm -rf $(TARGET) *.o *~ core blowfish.h blowfish.bin x86_emulate
    6.35 +
    6.36 +.PHONY: install
    6.37 +install:
    6.38 +
    6.39 +.PHONY: x86_emulate
    6.40 +x86_emulate:
    6.41 +	[ -L x86_emulate ] || ln -sf $(XEN_ROOT)/xen/arch/x86/x86_emulate .
    6.42 +
    6.43 +x86_emulate.o: x86_emulate.c x86_emulate
    6.44 +	$(HOSTCC) $(HOSTCFLAGS) -I$(XEN_ROOT)/xen/include -c -o $@ $<
    6.45 +
    6.46 +test_x86_emulator.o: test_x86_emulator.c blowfish.h x86_emulate
    6.47 +	$(HOSTCC) $(HOSTCFLAGS) -I$(XEN_ROOT)/xen/include -c -o $@ $<
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/tools/tests/x86_emulator/blowfish.c	Sat Jan 08 10:59:13 2011 +0000
     7.3 @@ -0,0 +1,440 @@
     7.4 +/*
     7.5 +blowfish.c:  C implementation of the Blowfish algorithm.
     7.6 +
     7.7 +Copyright (C) 1997 by Paul Kocher
     7.8 +
     7.9 +This library is free software; you can redistribute it and/or
    7.10 +modify it under the terms of the GNU Lesser General Public
    7.11 +License as published by the Free Software Foundation; either
    7.12 +version 2.1 of the License, or (at your option) any later version.
    7.13 +This library is distributed in the hope that it will be useful,
    7.14 +but WITHOUT ANY WARRANTY; without even the implied warranty of
    7.15 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    7.16 +Lesser General Public License for more details.
    7.17 +You should have received a copy of the GNU Lesser General Public
    7.18 +License along with this library; if not, write to the Free Software
    7.19 +Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    7.20 +*/
    7.21 +
    7.22 +#include <stdint.h>
    7.23 +
    7.24 +uint64_t blowfish_test(uint64_t input);
    7.25 +
    7.26 +asm (
    7.27 +    ".globl _start\n"
    7.28 +    "_start:\n"
    7.29 +#if defined(__i386__)
    7.30 +    "push %edx; push %eax; "
    7.31 +    "call blowfish_test; "
    7.32 +    "addl $8,%esp; "
    7.33 +#else
    7.34 +    "shlq $32,%rdx; movl %eax,%edi; orq %rdx,%rdi; "
    7.35 +    "call blowfish_test; "
    7.36 +    "movq %rax,%rdi; movl %eax,%eax; shrq $32,%rdx; "
    7.37 +#endif
    7.38 +    "ret"
    7.39 +    );
    7.40 +
    7.41 +typedef struct {
    7.42 +    uint32_t P[16 + 2];
    7.43 +    uint32_t S[4][256];
    7.44 +} BLOWFISH_CTX;
    7.45 +
    7.46 +#define N               16
    7.47 +
    7.48 +static const uint32_t ORIG_P[16 + 2] = {
    7.49 +    0x243F6A88u, 0x85A308D3u, 0x13198A2Eu, 0x03707344u,
    7.50 +    0xA4093822u, 0x299F31D0u, 0x082EFA98u, 0xEC4E6C89u,
    7.51 +    0x452821E6u, 0x38D01377u, 0xBE5466CFu, 0x34E90C6Cu,
    7.52 +    0xC0AC29B7u, 0xC97C50DDu, 0x3F84D5B5u, 0xB5470917u,
    7.53 +    0x9216D5D9u, 0x8979FB1Bu
    7.54 +};
    7.55 +
    7.56 +static const uint32_t ORIG_S[4][256] = {
    7.57 +    {   0xD1310BA6u, 0x98DFB5ACu, 0x2FFD72DBu, 0xD01ADFB7u,
    7.58 +        0xB8E1AFEDu, 0x6A267E96u, 0xBA7C9045u, 0xF12C7F99u,
    7.59 +        0x24A19947u, 0xB3916CF7u, 0x0801F2E2u, 0x858EFC16u,
    7.60 +        0x636920D8u, 0x71574E69u, 0xA458FEA3u, 0xF4933D7Eu,
    7.61 +        0x0D95748Fu, 0x728EB658u, 0x718BCD58u, 0x82154AEEu,
    7.62 +        0x7B54A41Du, 0xC25A59B5u, 0x9C30D539u, 0x2AF26013u,
    7.63 +        0xC5D1B023u, 0x286085F0u, 0xCA417918u, 0xB8DB38EFu,
    7.64 +        0x8E79DCB0u, 0x603A180Eu, 0x6C9E0E8Bu, 0xB01E8A3Eu,
    7.65 +        0xD71577C1u, 0xBD314B27u, 0x78AF2FDAu, 0x55605C60u,
    7.66 +        0xE65525F3u, 0xAA55AB94u, 0x57489862u, 0x63E81440u,
    7.67 +        0x55CA396Au, 0x2AAB10B6u, 0xB4CC5C34u, 0x1141E8CEu,
    7.68 +        0xA15486AFu, 0x7C72E993u, 0xB3EE1411u, 0x636FBC2Au,
    7.69 +        0x2BA9C55Du, 0x741831F6u, 0xCE5C3E16u, 0x9B87931Eu,
    7.70 +        0xAFD6BA33u, 0x6C24CF5Cu, 0x7A325381u, 0x28958677u,
    7.71 +        0x3B8F4898u, 0x6B4BB9AFu, 0xC4BFE81Bu, 0x66282193u,
    7.72 +        0x61D809CCu, 0xFB21A991u, 0x487CAC60u, 0x5DEC8032u,
    7.73 +        0xEF845D5Du, 0xE98575B1u, 0xDC262302u, 0xEB651B88u,
    7.74 +        0x23893E81u, 0xD396ACC5u, 0x0F6D6FF3u, 0x83F44239u,
    7.75 +        0x2E0B4482u, 0xA4842004u, 0x69C8F04Au, 0x9E1F9B5Eu,
    7.76 +        0x21C66842u, 0xF6E96C9Au, 0x670C9C61u, 0xABD388F0u,
    7.77 +        0x6A51A0D2u, 0xD8542F68u, 0x960FA728u, 0xAB5133A3u,
    7.78 +        0x6EEF0B6Cu, 0x137A3BE4u, 0xBA3BF050u, 0x7EFB2A98u,
    7.79 +        0xA1F1651Du, 0x39AF0176u, 0x66CA593Eu, 0x82430E88u,
    7.80 +        0x8CEE8619u, 0x456F9FB4u, 0x7D84A5C3u, 0x3B8B5EBEu,
    7.81 +        0xE06F75D8u, 0x85C12073u, 0x401A449Fu, 0x56C16AA6u,
    7.82 +        0x4ED3AA62u, 0x363F7706u, 0x1BFEDF72u, 0x429B023Du,
    7.83 +        0x37D0D724u, 0xD00A1248u, 0xDB0FEAD3u, 0x49F1C09Bu,
    7.84 +        0x075372C9u, 0x80991B7Bu, 0x25D479D8u, 0xF6E8DEF7u,
    7.85 +        0xE3FE501Au, 0xB6794C3Bu, 0x976CE0BDu, 0x04C006BAu,
    7.86 +        0xC1A94FB6u, 0x409F60C4u, 0x5E5C9EC2u, 0x196A2463u,
    7.87 +        0x68FB6FAFu, 0x3E6C53B5u, 0x1339B2EBu, 0x3B52EC6Fu,
    7.88 +        0x6DFC511Fu, 0x9B30952Cu, 0xCC814544u, 0xAF5EBD09u,
    7.89 +        0xBEE3D004u, 0xDE334AFDu, 0x660F2807u, 0x192E4BB3u,
    7.90 +        0xC0CBA857u, 0x45C8740Fu, 0xD20B5F39u, 0xB9D3FBDBu,
    7.91 +        0x5579C0BDu, 0x1A60320Au, 0xD6A100C6u, 0x402C7279u,
    7.92 +        0x679F25FEu, 0xFB1FA3CCu, 0x8EA5E9F8u, 0xDB3222F8u,
    7.93 +        0x3C7516DFu, 0xFD616B15u, 0x2F501EC8u, 0xAD0552ABu,
    7.94 +        0x323DB5FAu, 0xFD238760u, 0x53317B48u, 0x3E00DF82u,
    7.95 +        0x9E5C57BBu, 0xCA6F8CA0u, 0x1A87562Eu, 0xDF1769DBu,
    7.96 +        0xD542A8F6u, 0x287EFFC3u, 0xAC6732C6u, 0x8C4F5573u,
    7.97 +        0x695B27B0u, 0xBBCA58C8u, 0xE1FFA35Du, 0xB8F011A0u,
    7.98 +        0x10FA3D98u, 0xFD2183B8u, 0x4AFCB56Cu, 0x2DD1D35Bu,
    7.99 +        0x9A53E479u, 0xB6F84565u, 0xD28E49BCu, 0x4BFB9790u,
   7.100 +        0xE1DDF2DAu, 0xA4CB7E33u, 0x62FB1341u, 0xCEE4C6E8u,
   7.101 +        0xEF20CADAu, 0x36774C01u, 0xD07E9EFEu, 0x2BF11FB4u,
   7.102 +        0x95DBDA4Du, 0xAE909198u, 0xEAAD8E71u, 0x6B93D5A0u,
   7.103 +        0xD08ED1D0u, 0xAFC725E0u, 0x8E3C5B2Fu, 0x8E7594B7u,
   7.104 +        0x8FF6E2FBu, 0xF2122B64u, 0x8888B812u, 0x900DF01Cu,
   7.105 +        0x4FAD5EA0u, 0x688FC31Cu, 0xD1CFF191u, 0xB3A8C1ADu,
   7.106 +        0x2F2F2218u, 0xBE0E1777u, 0xEA752DFEu, 0x8B021FA1u,
   7.107 +        0xE5A0CC0Fu, 0xB56F74E8u, 0x18ACF3D6u, 0xCE89E299u,
   7.108 +        0xB4A84FE0u, 0xFD13E0B7u, 0x7CC43B81u, 0xD2ADA8D9u,
   7.109 +        0x165FA266u, 0x80957705u, 0x93CC7314u, 0x211A1477u,
   7.110 +        0xE6AD2065u, 0x77B5FA86u, 0xC75442F5u, 0xFB9D35CFu,
   7.111 +        0xEBCDAF0Cu, 0x7B3E89A0u, 0xD6411BD3u, 0xAE1E7E49u,
   7.112 +        0x00250E2Du, 0x2071B35Eu, 0x226800BBu, 0x57B8E0AFu,
   7.113 +        0x2464369Bu, 0xF009B91Eu, 0x5563911Du, 0x59DFA6AAu,
   7.114 +        0x78C14389u, 0xD95A537Fu, 0x207D5BA2u, 0x02E5B9C5u,
   7.115 +        0x83260376u, 0x6295CFA9u, 0x11C81968u, 0x4E734A41u,
   7.116 +        0xB3472DCAu, 0x7B14A94Au, 0x1B510052u, 0x9A532915u,
   7.117 +        0xD60F573Fu, 0xBC9BC6E4u, 0x2B60A476u, 0x81E67400u,
   7.118 +        0x08BA6FB5u, 0x571BE91Fu, 0xF296EC6Bu, 0x2A0DD915u,
   7.119 +        0xB6636521u, 0xE7B9F9B6u, 0xFF34052Eu, 0xC5855664u,
   7.120 +        0x53B02D5Du, 0xA99F8FA1u, 0x08BA4799u, 0x6E85076Au   },
   7.121 +    {   0x4B7A70E9u, 0xB5B32944u, 0xDB75092Eu, 0xC4192623u,
   7.122 +        0xAD6EA6B0u, 0x49A7DF7Du, 0x9CEE60B8u, 0x8FEDB266u,
   7.123 +        0xECAA8C71u, 0x699A17FFu, 0x5664526Cu, 0xC2B19EE1u,
   7.124 +        0x193602A5u, 0x75094C29u, 0xA0591340u, 0xE4183A3Eu,
   7.125 +        0x3F54989Au, 0x5B429D65u, 0x6B8FE4D6u, 0x99F73FD6u,
   7.126 +        0xA1D29C07u, 0xEFE830F5u, 0x4D2D38E6u, 0xF0255DC1u,
   7.127 +        0x4CDD2086u, 0x8470EB26u, 0x6382E9C6u, 0x021ECC5Eu,
   7.128 +        0x09686B3Fu, 0x3EBAEFC9u, 0x3C971814u, 0x6B6A70A1u,
   7.129 +        0x687F3584u, 0x52A0E286u, 0xB79C5305u, 0xAA500737u,
   7.130 +        0x3E07841Cu, 0x7FDEAE5Cu, 0x8E7D44ECu, 0x5716F2B8u,
   7.131 +        0xB03ADA37u, 0xF0500C0Du, 0xF01C1F04u, 0x0200B3FFu,
   7.132 +        0xAE0CF51Au, 0x3CB574B2u, 0x25837A58u, 0xDC0921BDu,
   7.133 +        0xD19113F9u, 0x7CA92FF6u, 0x94324773u, 0x22F54701u,
   7.134 +        0x3AE5E581u, 0x37C2DADCu, 0xC8B57634u, 0x9AF3DDA7u,
   7.135 +        0xA9446146u, 0x0FD0030Eu, 0xECC8C73Eu, 0xA4751E41u,
   7.136 +        0xE238CD99u, 0x3BEA0E2Fu, 0x3280BBA1u, 0x183EB331u,
   7.137 +        0x4E548B38u, 0x4F6DB908u, 0x6F420D03u, 0xF60A04BFu,
   7.138 +        0x2CB81290u, 0x24977C79u, 0x5679B072u, 0xBCAF89AFu,
   7.139 +        0xDE9A771Fu, 0xD9930810u, 0xB38BAE12u, 0xDCCF3F2Eu,
   7.140 +        0x5512721Fu, 0x2E6B7124u, 0x501ADDE6u, 0x9F84CD87u,
   7.141 +        0x7A584718u, 0x7408DA17u, 0xBC9F9ABCu, 0xE94B7D8Cu,
   7.142 +        0xEC7AEC3Au, 0xDB851DFAu, 0x63094366u, 0xC464C3D2u,
   7.143 +        0xEF1C1847u, 0x3215D908u, 0xDD433B37u, 0x24C2BA16u,
   7.144 +        0x12A14D43u, 0x2A65C451u, 0x50940002u, 0x133AE4DDu,
   7.145 +        0x71DFF89Eu, 0x10314E55u, 0x81AC77D6u, 0x5F11199Bu,
   7.146 +        0x043556F1u, 0xD7A3C76Bu, 0x3C11183Bu, 0x5924A509u,
   7.147 +        0xF28FE6EDu, 0x97F1FBFAu, 0x9EBABF2Cu, 0x1E153C6Eu,
   7.148 +        0x86E34570u, 0xEAE96FB1u, 0x860E5E0Au, 0x5A3E2AB3u,
   7.149 +        0x771FE71Cu, 0x4E3D06FAu, 0x2965DCB9u, 0x99E71D0Fu,
   7.150 +        0x803E89D6u, 0x5266C825u, 0x2E4CC978u, 0x9C10B36Au,
   7.151 +        0xC6150EBAu, 0x94E2EA78u, 0xA5FC3C53u, 0x1E0A2DF4u,
   7.152 +        0xF2F74EA7u, 0x361D2B3Du, 0x1939260Fu, 0x19C27960u,
   7.153 +        0x5223A708u, 0xF71312B6u, 0xEBADFE6Eu, 0xEAC31F66u,
   7.154 +        0xE3BC4595u, 0xA67BC883u, 0xB17F37D1u, 0x018CFF28u,
   7.155 +        0xC332DDEFu, 0xBE6C5AA5u, 0x65582185u, 0x68AB9802u,
   7.156 +        0xEECEA50Fu, 0xDB2F953Bu, 0x2AEF7DADu, 0x5B6E2F84u,
   7.157 +        0x1521B628u, 0x29076170u, 0xECDD4775u, 0x619F1510u,
   7.158 +        0x13CCA830u, 0xEB61BD96u, 0x0334FE1Eu, 0xAA0363CFu,
   7.159 +        0xB5735C90u, 0x4C70A239u, 0xD59E9E0Bu, 0xCBAADE14u,
   7.160 +        0xEECC86BCu, 0x60622CA7u, 0x9CAB5CABu, 0xB2F3846Eu,
   7.161 +        0x648B1EAFu, 0x19BDF0CAu, 0xA02369B9u, 0x655ABB50u,
   7.162 +        0x40685A32u, 0x3C2AB4B3u, 0x319EE9D5u, 0xC021B8F7u,
   7.163 +        0x9B540B19u, 0x875FA099u, 0x95F7997Eu, 0x623D7DA8u,
   7.164 +        0xF837889Au, 0x97E32D77u, 0x11ED935Fu, 0x16681281u,
   7.165 +        0x0E358829u, 0xC7E61FD6u, 0x96DEDFA1u, 0x7858BA99u,
   7.166 +        0x57F584A5u, 0x1B227263u, 0x9B83C3FFu, 0x1AC24696u,
   7.167 +        0xCDB30AEBu, 0x532E3054u, 0x8FD948E4u, 0x6DBC3128u,
   7.168 +        0x58EBF2EFu, 0x34C6FFEAu, 0xFE28ED61u, 0xEE7C3C73u,
   7.169 +        0x5D4A14D9u, 0xE864B7E3u, 0x42105D14u, 0x203E13E0u,
   7.170 +        0x45EEE2B6u, 0xA3AAABEAu, 0xDB6C4F15u, 0xFACB4FD0u,
   7.171 +        0xC742F442u, 0xEF6ABBB5u, 0x654F3B1Du, 0x41CD2105u,
   7.172 +        0xD81E799Eu, 0x86854DC7u, 0xE44B476Au, 0x3D816250u,
   7.173 +        0xCF62A1F2u, 0x5B8D2646u, 0xFC8883A0u, 0xC1C7B6A3u,
   7.174 +        0x7F1524C3u, 0x69CB7492u, 0x47848A0Bu, 0x5692B285u,
   7.175 +        0x095BBF00u, 0xAD19489Du, 0x1462B174u, 0x23820E00u,
   7.176 +        0x58428D2Au, 0x0C55F5EAu, 0x1DADF43Eu, 0x233F7061u,
   7.177 +        0x3372F092u, 0x8D937E41u, 0xD65FECF1u, 0x6C223BDBu,
   7.178 +        0x7CDE3759u, 0xCBEE7460u, 0x4085F2A7u, 0xCE77326Eu,
   7.179 +        0xA6078084u, 0x19F8509Eu, 0xE8EFD855u, 0x61D99735u,
   7.180 +        0xA969A7AAu, 0xC50C06C2u, 0x5A04ABFCu, 0x800BCADCu,
   7.181 +        0x9E447A2Eu, 0xC3453484u, 0xFDD56705u, 0x0E1E9EC9u,
   7.182 +        0xDB73DBD3u, 0x105588CDu, 0x675FDA79u, 0xE3674340u,
   7.183 +        0xC5C43465u, 0x713E38D8u, 0x3D28F89Eu, 0xF16DFF20u,
   7.184 +        0x153E21E7u, 0x8FB03D4Au, 0xE6E39F2Bu, 0xDB83ADF7u   },
   7.185 +    {   0xE93D5A68u, 0x948140F7u, 0xF64C261Cu, 0x94692934u,
   7.186 +        0x411520F7u, 0x7602D4F7u, 0xBCF46B2Eu, 0xD4A20068u,
   7.187 +        0xD4082471u, 0x3320F46Au, 0x43B7D4B7u, 0x500061AFu,
   7.188 +        0x1E39F62Eu, 0x97244546u, 0x14214F74u, 0xBF8B8840u,
   7.189 +        0x4D95FC1Du, 0x96B591AFu, 0x70F4DDD3u, 0x66A02F45u,
   7.190 +        0xBFBC09ECu, 0x03BD9785u, 0x7FAC6DD0u, 0x31CB8504u,
   7.191 +        0x96EB27B3u, 0x55FD3941u, 0xDA2547E6u, 0xABCA0A9Au,
   7.192 +        0x28507825u, 0x530429F4u, 0x0A2C86DAu, 0xE9B66DFBu,
   7.193 +        0x68DC1462u, 0xD7486900u, 0x680EC0A4u, 0x27A18DEEu,
   7.194 +        0x4F3FFEA2u, 0xE887AD8Cu, 0xB58CE006u, 0x7AF4D6B6u,
   7.195 +        0xAACE1E7Cu, 0xD3375FECu, 0xCE78A399u, 0x406B2A42u,
   7.196 +        0x20FE9E35u, 0xD9F385B9u, 0xEE39D7ABu, 0x3B124E8Bu,
   7.197 +        0x1DC9FAF7u, 0x4B6D1856u, 0x26A36631u, 0xEAE397B2u,
   7.198 +        0x3A6EFA74u, 0xDD5B4332u, 0x6841E7F7u, 0xCA7820FBu,
   7.199 +        0xFB0AF54Eu, 0xD8FEB397u, 0x454056ACu, 0xBA489527u,
   7.200 +        0x55533A3Au, 0x20838D87u, 0xFE6BA9B7u, 0xD096954Bu,
   7.201 +        0x55A867BCu, 0xA1159A58u, 0xCCA92963u, 0x99E1DB33u,
   7.202 +        0xA62A4A56u, 0x3F3125F9u, 0x5EF47E1Cu, 0x9029317Cu,
   7.203 +        0xFDF8E802u, 0x04272F70u, 0x80BB155Cu, 0x05282CE3u,
   7.204 +        0x95C11548u, 0xE4C66D22u, 0x48C1133Fu, 0xC70F86DCu,
   7.205 +        0x07F9C9EEu, 0x41041F0Fu, 0x404779A4u, 0x5D886E17u,
   7.206 +        0x325F51EBu, 0xD59BC0D1u, 0xF2BCC18Fu, 0x41113564u,
   7.207 +        0x257B7834u, 0x602A9C60u, 0xDFF8E8A3u, 0x1F636C1Bu,
   7.208 +        0x0E12B4C2u, 0x02E1329Eu, 0xAF664FD1u, 0xCAD18115u,
   7.209 +        0x6B2395E0u, 0x333E92E1u, 0x3B240B62u, 0xEEBEB922u,
   7.210 +        0x85B2A20Eu, 0xE6BA0D99u, 0xDE720C8Cu, 0x2DA2F728u,
   7.211 +        0xD0127845u, 0x95B794FDu, 0x647D0862u, 0xE7CCF5F0u,
   7.212 +        0x5449A36Fu, 0x877D48FAu, 0xC39DFD27u, 0xF33E8D1Eu,
   7.213 +        0x0A476341u, 0x992EFF74u, 0x3A6F6EABu, 0xF4F8FD37u,
   7.214 +        0xA812DC60u, 0xA1EBDDF8u, 0x991BE14Cu, 0xDB6E6B0Du,
   7.215 +        0xC67B5510u, 0x6D672C37u, 0x2765D43Bu, 0xDCD0E804u,
   7.216 +        0xF1290DC7u, 0xCC00FFA3u, 0xB5390F92u, 0x690FED0Bu,
   7.217 +        0x667B9FFBu, 0xCEDB7D9Cu, 0xA091CF0Bu, 0xD9155EA3u,
   7.218 +        0xBB132F88u, 0x515BAD24u, 0x7B9479BFu, 0x763BD6EBu,
   7.219 +        0x37392EB3u, 0xCC115979u, 0x8026E297u, 0xF42E312Du,
   7.220 +        0x6842ADA7u, 0xC66A2B3Bu, 0x12754CCCu, 0x782EF11Cu,
   7.221 +        0x6A124237u, 0xB79251E7u, 0x06A1BBE6u, 0x4BFB6350u,
   7.222 +        0x1A6B1018u, 0x11CAEDFAu, 0x3D25BDD8u, 0xE2E1C3C9u,
   7.223 +        0x44421659u, 0x0A121386u, 0xD90CEC6Eu, 0xD5ABEA2Au,
   7.224 +        0x64AF674Eu, 0xDA86A85Fu, 0xBEBFE988u, 0x64E4C3FEu,
   7.225 +        0x9DBC8057u, 0xF0F7C086u, 0x60787BF8u, 0x6003604Du,
   7.226 +        0xD1FD8346u, 0xF6381FB0u, 0x7745AE04u, 0xD736FCCCu,
   7.227 +        0x83426B33u, 0xF01EAB71u, 0xB0804187u, 0x3C005E5Fu,
   7.228 +        0x77A057BEu, 0xBDE8AE24u, 0x55464299u, 0xBF582E61u,
   7.229 +        0x4E58F48Fu, 0xF2DDFDA2u, 0xF474EF38u, 0x8789BDC2u,
   7.230 +        0x5366F9C3u, 0xC8B38E74u, 0xB475F255u, 0x46FCD9B9u,
   7.231 +        0x7AEB2661u, 0x8B1DDF84u, 0x846A0E79u, 0x915F95E2u,
   7.232 +        0x466E598Eu, 0x20B45770u, 0x8CD55591u, 0xC902DE4Cu,
   7.233 +        0xB90BACE1u, 0xBB8205D0u, 0x11A86248u, 0x7574A99Eu,
   7.234 +        0xB77F19B6u, 0xE0A9DC09u, 0x662D09A1u, 0xC4324633u,
   7.235 +        0xE85A1F02u, 0x09F0BE8Cu, 0x4A99A025u, 0x1D6EFE10u,
   7.236 +        0x1AB93D1Du, 0x0BA5A4DFu, 0xA186F20Fu, 0x2868F169u,
   7.237 +        0xDCB7DA83u, 0x573906FEu, 0xA1E2CE9Bu, 0x4FCD7F52u,
   7.238 +        0x50115E01u, 0xA70683FAu, 0xA002B5C4u, 0x0DE6D027u,
   7.239 +        0x9AF88C27u, 0x773F8641u, 0xC3604C06u, 0x61A806B5u,
   7.240 +        0xF0177A28u, 0xC0F586E0u, 0x006058AAu, 0x30DC7D62u,
   7.241 +        0x11E69ED7u, 0x2338EA63u, 0x53C2DD94u, 0xC2C21634u,
   7.242 +        0xBBCBEE56u, 0x90BCB6DEu, 0xEBFC7DA1u, 0xCE591D76u,
   7.243 +        0x6F05E409u, 0x4B7C0188u, 0x39720A3Du, 0x7C927C24u,
   7.244 +        0x86E3725Fu, 0x724D9DB9u, 0x1AC15BB4u, 0xD39EB8FCu,
   7.245 +        0xED545578u, 0x08FCA5B5u, 0xD83D7CD3u, 0x4DAD0FC4u,
   7.246 +        0x1E50EF5Eu, 0xB161E6F8u, 0xA28514D9u, 0x6C51133Cu,
   7.247 +        0x6FD5C7E7u, 0x56E14EC4u, 0x362ABFCEu, 0xDDC6C837u,
   7.248 +        0xD79A3234u, 0x92638212u, 0x670EFA8Eu, 0x406000E0u  },
   7.249 +    {   0x3A39CE37u, 0xD3FAF5CFu, 0xABC27737u, 0x5AC52D1Bu,
   7.250 +        0x5CB0679Eu, 0x4FA33742u, 0xD3822740u, 0x99BC9BBEu,
   7.251 +        0xD5118E9Du, 0xBF0F7315u, 0xD62D1C7Eu, 0xC700C47Bu,
   7.252 +        0xB78C1B6Bu, 0x21A19045u, 0xB26EB1BEu, 0x6A366EB4u,
   7.253 +        0x5748AB2Fu, 0xBC946E79u, 0xC6A376D2u, 0x6549C2C8u,
   7.254 +        0x530FF8EEu, 0x468DDE7Du, 0xD5730A1Du, 0x4CD04DC6u,
   7.255 +        0x2939BBDBu, 0xA9BA4650u, 0xAC9526E8u, 0xBE5EE304u,
   7.256 +        0xA1FAD5F0u, 0x6A2D519Au, 0x63EF8CE2u, 0x9A86EE22u,
   7.257 +        0xC089C2B8u, 0x43242EF6u, 0xA51E03AAu, 0x9CF2D0A4u,
   7.258 +        0x83C061BAu, 0x9BE96A4Du, 0x8FE51550u, 0xBA645BD6u,
   7.259 +        0x2826A2F9u, 0xA73A3AE1u, 0x4BA99586u, 0xEF5562E9u,
   7.260 +        0xC72FEFD3u, 0xF752F7DAu, 0x3F046F69u, 0x77FA0A59u,
   7.261 +        0x80E4A915u, 0x87B08601u, 0x9B09E6ADu, 0x3B3EE593u,
   7.262 +        0xE990FD5Au, 0x9E34D797u, 0x2CF0B7D9u, 0x022B8B51u,
   7.263 +        0x96D5AC3Au, 0x017DA67Du, 0xD1CF3ED6u, 0x7C7D2D28u,
   7.264 +        0x1F9F25CFu, 0xADF2B89Bu, 0x5AD6B472u, 0x5A88F54Cu,
   7.265 +        0xE029AC71u, 0xE019A5E6u, 0x47B0ACFDu, 0xED93FA9Bu,
   7.266 +        0xE8D3C48Du, 0x283B57CCu, 0xF8D56629u, 0x79132E28u,
   7.267 +        0x785F0191u, 0xED756055u, 0xF7960E44u, 0xE3D35E8Cu,
   7.268 +        0x15056DD4u, 0x88F46DBAu, 0x03A16125u, 0x0564F0BDu,
   7.269 +        0xC3EB9E15u, 0x3C9057A2u, 0x97271AECu, 0xA93A072Au,
   7.270 +        0x1B3F6D9Bu, 0x1E6321F5u, 0xF59C66FBu, 0x26DCF319u,
   7.271 +        0x7533D928u, 0xB155FDF5u, 0x03563482u, 0x8ABA3CBBu,
   7.272 +        0x28517711u, 0xC20AD9F8u, 0xABCC5167u, 0xCCAD925Fu,
   7.273 +        0x4DE81751u, 0x3830DC8Eu, 0x379D5862u, 0x9320F991u,
   7.274 +        0xEA7A90C2u, 0xFB3E7BCEu, 0x5121CE64u, 0x774FBE32u,
   7.275 +        0xA8B6E37Eu, 0xC3293D46u, 0x48DE5369u, 0x6413E680u,
   7.276 +        0xA2AE0810u, 0xDD6DB224u, 0x69852DFDu, 0x09072166u,
   7.277 +        0xB39A460Au, 0x6445C0DDu, 0x586CDECFu, 0x1C20C8AEu,
   7.278 +        0x5BBEF7DDu, 0x1B588D40u, 0xCCD2017Fu, 0x6BB4E3BBu,
   7.279 +        0xDDA26A7Eu, 0x3A59FF45u, 0x3E350A44u, 0xBCB4CDD5u,
   7.280 +        0x72EACEA8u, 0xFA6484BBu, 0x8D6612AEu, 0xBF3C6F47u,
   7.281 +        0xD29BE463u, 0x542F5D9Eu, 0xAEC2771Bu, 0xF64E6370u,
   7.282 +        0x740E0D8Du, 0xE75B1357u, 0xF8721671u, 0xAF537D5Du,
   7.283 +        0x4040CB08u, 0x4EB4E2CCu, 0x34D2466Au, 0x0115AF84u,
   7.284 +        0xE1B00428u, 0x95983A1Du, 0x06B89FB4u, 0xCE6EA048u,
   7.285 +        0x6F3F3B82u, 0x3520AB82u, 0x011A1D4Bu, 0x277227F8u,
   7.286 +        0x611560B1u, 0xE7933FDCu, 0xBB3A792Bu, 0x344525BDu,
   7.287 +        0xA08839E1u, 0x51CE794Bu, 0x2F32C9B7u, 0xA01FBAC9u,
   7.288 +        0xE01CC87Eu, 0xBCC7D1F6u, 0xCF0111C3u, 0xA1E8AAC7u,
   7.289 +        0x1A908749u, 0xD44FBD9Au, 0xD0DADECBu, 0xD50ADA38u,
   7.290 +        0x0339C32Au, 0xC6913667u, 0x8DF9317Cu, 0xE0B12B4Fu,
   7.291 +        0xF79E59B7u, 0x43F5BB3Au, 0xF2D519FFu, 0x27D9459Cu,
   7.292 +        0xBF97222Cu, 0x15E6FC2Au, 0x0F91FC71u, 0x9B941525u,
   7.293 +        0xFAE59361u, 0xCEB69CEBu, 0xC2A86459u, 0x12BAA8D1u,
   7.294 +        0xB6C1075Eu, 0xE3056A0Cu, 0x10D25065u, 0xCB03A442u,
   7.295 +        0xE0EC6E0Eu, 0x1698DB3Bu, 0x4C98A0BEu, 0x3278E964u,
   7.296 +        0x9F1F9532u, 0xE0D392DFu, 0xD3A0342Bu, 0x8971F21Eu,
   7.297 +        0x1B0A7441u, 0x4BA3348Cu, 0xC5BE7120u, 0xC37632D8u,
   7.298 +        0xDF359F8Du, 0x9B992F2Eu, 0xE60B6F47u, 0x0FE3F11Du,
   7.299 +        0xE54CDA54u, 0x1EDAD891u, 0xCE6279CFu, 0xCD3E7E6Fu,
   7.300 +        0x1618B166u, 0xFD2C1D05u, 0x848FD2C5u, 0xF6FB2299u,
   7.301 +        0xF523F357u, 0xA6327623u, 0x93A83531u, 0x56CCCD02u,
   7.302 +        0xACF08162u, 0x5A75EBB5u, 0x6E163697u, 0x88D273CCu,
   7.303 +        0xDE966292u, 0x81B949D0u, 0x4C50901Bu, 0x71C65614u,
   7.304 +        0xE6C6C7BDu, 0x327A140Au, 0x45E1D006u, 0xC3F27B9Au,
   7.305 +        0xC9AA53FDu, 0x62A80F00u, 0xBB25BFE2u, 0x35BDD2F6u,
   7.306 +        0x71126905u, 0xB2040222u, 0xB6CBCF7Cu, 0xCD769C2Bu,
   7.307 +        0x53113EC0u, 0x1640E3D3u, 0x38ABBD60u, 0x2547ADF0u,
   7.308 +        0xBA38209Cu, 0xF746CE76u, 0x77AFA1C5u, 0x20756060u,
   7.309 +        0x85CBFE4Eu, 0x8AE88DD8u, 0x7AAAF9B0u, 0x4CF9AA7Eu,
   7.310 +        0x1948C25Cu, 0x02FB8A8Cu, 0x01C36AE4u, 0xD6EBE1F9u,
   7.311 +        0x90D4F869u, 0xA65CDEA0u, 0x3F09252Du, 0xC208E69Fu,
   7.312 +        0xB74E6132u, 0xCE77E25Bu, 0x578FDFE3u, 0x3AC372E6u  }
   7.313 +};
   7.314 +
   7.315 +
   7.316 +static uint32_t F(BLOWFISH_CTX *ctx, uint32_t x) {
   7.317 +    uint16_t a, b, c, d;
   7.318 +    uint32_t  y;
   7.319 +
   7.320 +    d = (uint16_t)(x & 0xFF);
   7.321 +    x >>= 8;
   7.322 +    c = (uint16_t)(x & 0xFF);
   7.323 +    x >>= 8;
   7.324 +    b = (uint16_t)(x & 0xFF);
   7.325 +    x >>= 8;
   7.326 +    a = (uint16_t)(x & 0xFF);
   7.327 +    y = ctx->S[0][a] + ctx->S[1][b];
   7.328 +    y = y ^ ctx->S[2][c];
   7.329 +    y = y + ctx->S[3][d];
   7.330 +
   7.331 +    return y;
   7.332 +}
   7.333 +
   7.334 +
   7.335 +static void Blowfish_Encrypt(BLOWFISH_CTX *ctx, uint32_t *xl, uint32_t *xr){
   7.336 +    uint32_t  Xl;
   7.337 +    uint32_t  Xr;
   7.338 +    uint32_t  temp;
   7.339 +    short       i;
   7.340 +
   7.341 +    Xl = *xl;
   7.342 +    Xr = *xr;
   7.343 +
   7.344 +    for (i = 0; i < N; ++i) {
   7.345 +        Xl = Xl ^ ctx->P[i];
   7.346 +        Xr = F(ctx, Xl) ^ Xr;
   7.347 +
   7.348 +        temp = Xl;
   7.349 +        Xl = Xr;
   7.350 +        Xr = temp;
   7.351 +    }
   7.352 +
   7.353 +    temp = Xl;
   7.354 +    Xl = Xr;
   7.355 +    Xr = temp;
   7.356 +
   7.357 +    Xr = Xr ^ ctx->P[N];
   7.358 +    Xl = Xl ^ ctx->P[N + 1];
   7.359 +
   7.360 +    *xl = Xl;
   7.361 +    *xr = Xr;
   7.362 +}
   7.363 +
   7.364 +
   7.365 +static void Blowfish_Decrypt(BLOWFISH_CTX *ctx, uint32_t *xl, uint32_t *xr){
   7.366 +    uint32_t  Xl;
   7.367 +    uint32_t  Xr;
   7.368 +    uint32_t  temp;
   7.369 +    short       i;
   7.370 +
   7.371 +    Xl = *xl;
   7.372 +    Xr = *xr;
   7.373 +
   7.374 +    for (i = N + 1; i > 1; --i) {
   7.375 +        Xl = Xl ^ ctx->P[i];
   7.376 +        Xr = F(ctx, Xl) ^ Xr;
   7.377 +
   7.378 +        /* Exchange Xl and Xr */
   7.379 +        temp = Xl;
   7.380 +        Xl = Xr;
   7.381 +        Xr = temp;
   7.382 +    }
   7.383 +
   7.384 +    /* Exchange Xl and Xr */
   7.385 +    temp = Xl;
   7.386 +    Xl = Xr;
   7.387 +    Xr = temp;
   7.388 +
   7.389 +    Xr = Xr ^ ctx->P[1];
   7.390 +    Xl = Xl ^ ctx->P[0];
   7.391 +
   7.392 +    *xl = Xl;
   7.393 +    *xr = Xr;
   7.394 +}
   7.395 +
   7.396 +static void Blowfish_Init(BLOWFISH_CTX *ctx, unsigned char *key, int keyLen) {
   7.397 +    int i, j, k;
   7.398 +    uint32_t data, datal, datar;
   7.399 +
   7.400 +    for (i = 0; i < 4; i++) {
   7.401 +        for (j = 0; j < 256; j++)
   7.402 +            ctx->S[i][j] = ORIG_S[i][j];
   7.403 +    }
   7.404 +
   7.405 +    j = 0;
   7.406 +    for (i = 0; i < N + 2; ++i) {
   7.407 +        data = 0x00000000;
   7.408 +        for (k = 0; k < 4; ++k) {
   7.409 +            data = (data << 8) | key[j];
   7.410 +            j = j + 1;
   7.411 +            if (j >= keyLen)
   7.412 +                j = 0;
   7.413 +        }
   7.414 +        ctx->P[i] = ORIG_P[i] ^ data;
   7.415 +    }
   7.416 +
   7.417 +    datal = 0x00000000;
   7.418 +    datar = 0x00000000;
   7.419 +
   7.420 +    for (i = 0; i < N + 2; i += 2) {
   7.421 +        Blowfish_Encrypt(ctx, &datal, &datar);
   7.422 +        ctx->P[i] = datal;
   7.423 +        ctx->P[i + 1] = datar;
   7.424 +    }
   7.425 +
   7.426 +    for (i = 0; i < 4; ++i) {
   7.427 +        for (j = 0; j < 256; j += 2) {
   7.428 +            Blowfish_Encrypt(ctx, &datal, &datar);
   7.429 +            ctx->S[i][j] = datal;
   7.430 +            ctx->S[i][j + 1] = datar;
   7.431 +        }
   7.432 +    }
   7.433 +}
   7.434 +
   7.435 +uint64_t blowfish_test(uint64_t input)
   7.436 +{
   7.437 +    uint32_t L = input >> 32, R = input;
   7.438 +    BLOWFISH_CTX ctx;
   7.439 +    Blowfish_Init(&ctx, (unsigned char*)"TESTKEY", 7);
   7.440 +    Blowfish_Encrypt(&ctx, &L, &R);
   7.441 +    Blowfish_Decrypt(&ctx, &L, &R);
   7.442 +    return ((uint64_t)L << 32) | R;
   7.443 +}
     8.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/tools/tests/x86_emulator/blowfish.mk	Sat Jan 08 10:59:13 2011 +0000
     8.3 @@ -0,0 +1,17 @@
     8.4 +
     8.5 +XEN_ROOT = ../../..
     8.6 +CFLAGS =
     8.7 +include $(XEN_ROOT)/tools/Rules.mk
     8.8 +
     8.9 +$(call cc-options-add,CFLAGS,CC,$(EMBEDDED_EXTRA_CFLAGS))
    8.10 +
    8.11 +CFLAGS += -fno-builtin -msoft-float
    8.12 +
    8.13 +.PHONY: all
    8.14 +all: blowfish.bin
    8.15 +
    8.16 +blowfish.bin: blowfish.c
    8.17 +	$(CC) $(CFLAGS) -c blowfish.c
    8.18 +	$(LD) $(LDFLAGS_DIRECT) -N -Ttext 0x100000 -o blowfish.tmp blowfish.o
    8.19 +	$(OBJCOPY) -O binary blowfish.tmp blowfish.bin
    8.20 +	rm -f blowfish.tmp
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/tools/tests/x86_emulator/test_x86_emulator.c	Sat Jan 08 10:59:13 2011 +0000
     9.3 @@ -0,0 +1,503 @@
     9.4 +#include <stdio.h>
     9.5 +#include <stdlib.h>
     9.6 +#include <string.h>
     9.7 +#include <stdint.h>
     9.8 +#include <public/xen.h>
     9.9 +#include <sys/mman.h>
    9.10 +
    9.11 +#include "x86_emulate/x86_emulate.h"
    9.12 +#include "blowfish.h"
    9.13 +
    9.14 +#define MMAP_SZ 16384
    9.15 +
    9.16 +/* EFLAGS bit definitions. */
    9.17 +#define EFLG_OF (1<<11)
    9.18 +#define EFLG_DF (1<<10)
    9.19 +#define EFLG_SF (1<<7)
    9.20 +#define EFLG_ZF (1<<6)
    9.21 +#define EFLG_AF (1<<4)
    9.22 +#define EFLG_PF (1<<2)
    9.23 +#define EFLG_CF (1<<0)
    9.24 +
    9.25 +static int read(
    9.26 +    unsigned int seg,
    9.27 +    unsigned long offset,
    9.28 +    void *p_data,
    9.29 +    unsigned int bytes,
    9.30 +    struct x86_emulate_ctxt *ctxt)
    9.31 +{
    9.32 +    memcpy(p_data, (void *)offset, bytes);
    9.33 +    return X86EMUL_OKAY;
    9.34 +}
    9.35 +
    9.36 +static int write(
    9.37 +    unsigned int seg,
    9.38 +    unsigned long offset,
    9.39 +    void *p_data,
    9.40 +    unsigned int bytes,
    9.41 +    struct x86_emulate_ctxt *ctxt)
    9.42 +{
    9.43 +    memcpy((void *)offset, p_data, bytes);
    9.44 +    return X86EMUL_OKAY;
    9.45 +}
    9.46 +
    9.47 +static int cmpxchg(
    9.48 +    unsigned int seg,
    9.49 +    unsigned long offset,
    9.50 +    void *old,
    9.51 +    void *new,
    9.52 +    unsigned int bytes,
    9.53 +    struct x86_emulate_ctxt *ctxt)
    9.54 +{
    9.55 +    memcpy((void *)offset, new, bytes);
    9.56 +    return X86EMUL_OKAY;
    9.57 +}
    9.58 +
    9.59 +static struct x86_emulate_ops emulops = {
    9.60 +    .read       = read,
    9.61 +    .insn_fetch = read,
    9.62 +    .write      = write,
    9.63 +    .cmpxchg    = cmpxchg,
    9.64 +};
    9.65 +
    9.66 +int main(int argc, char **argv)
    9.67 +{
    9.68 +    struct x86_emulate_ctxt ctxt;
    9.69 +    struct cpu_user_regs regs;
    9.70 +    char *instr;
    9.71 +    unsigned int *res, i, j;
    9.72 +    int rc;
    9.73 +#ifndef __x86_64__
    9.74 +    unsigned int bcdres_native, bcdres_emul;
    9.75 +#endif
    9.76 +
    9.77 +    ctxt.regs = &regs;
    9.78 +    ctxt.force_writeback = 0;
    9.79 +    ctxt.addr_size = 32;
    9.80 +    ctxt.sp_size   = 32;
    9.81 +
    9.82 +    res = mmap((void *)0x100000, MMAP_SZ, PROT_READ|PROT_WRITE|PROT_EXEC,
    9.83 +               MAP_FIXED|MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
    9.84 +    if ( res == MAP_FAILED )
    9.85 +    {
    9.86 +        fprintf(stderr, "mmap to low address failed\n");
    9.87 +        exit(1);
    9.88 +    }
    9.89 +    instr = (char *)res + 0x100;
    9.90 +
    9.91 +    printf("%-40s", "Testing addl %%ecx,(%%eax)...");
    9.92 +    instr[0] = 0x01; instr[1] = 0x08;
    9.93 +    regs.eflags = 0x200;
    9.94 +    regs.eip    = (unsigned long)&instr[0];
    9.95 +    regs.ecx    = 0x12345678;
    9.96 +    regs.eax    = (unsigned long)res;
    9.97 +    *res        = 0x7FFFFFFF;
    9.98 +    rc = x86_emulate(&ctxt, &emulops);
    9.99 +    if ( (rc != X86EMUL_OKAY) || 
   9.100 +         (*res != 0x92345677) || 
   9.101 +         (regs.eflags != 0xa94) ||
   9.102 +         (regs.eip != (unsigned long)&instr[2]) )
   9.103 +        goto fail;
   9.104 +    printf("okay\n");
   9.105 +
   9.106 +    printf("%-40s", "Testing addl %%ecx,%%eax...");
   9.107 +    instr[0] = 0x01; instr[1] = 0xc8;
   9.108 +    regs.eflags = 0x200;
   9.109 +    regs.eip    = (unsigned long)&instr[0];
   9.110 +    regs.ecx    = 0x12345678;
   9.111 +    regs.eax    = 0x7FFFFFFF;
   9.112 +    rc = x86_emulate(&ctxt, &emulops);
   9.113 +    if ( (rc != X86EMUL_OKAY) || 
   9.114 +         (regs.ecx != 0x12345678) ||
   9.115 +         (regs.eax != 0x92345677) ||
   9.116 +         (regs.eflags != 0xa94) ||
   9.117 +         (regs.eip != (unsigned long)&instr[2]) )
   9.118 +        goto fail;
   9.119 +    printf("okay\n");
   9.120 +
   9.121 +    printf("%-40s", "Testing xorl (%%eax),%%ecx...");
   9.122 +    instr[0] = 0x33; instr[1] = 0x08;
   9.123 +    regs.eflags = 0x200;
   9.124 +    regs.eip    = (unsigned long)&instr[0];
   9.125 +#ifdef __x86_64__
   9.126 +    regs.ecx    = 0xFFFFFFFF12345678UL;
   9.127 +#else
   9.128 +    regs.ecx    = 0x12345678UL;
   9.129 +#endif
   9.130 +    regs.eax    = (unsigned long)res;
   9.131 +    rc = x86_emulate(&ctxt, &emulops);
   9.132 +    if ( (rc != X86EMUL_OKAY) || 
   9.133 +         (*res != 0x92345677) || 
   9.134 +         (regs.ecx != 0x8000000FUL) ||
   9.135 +         (regs.eip != (unsigned long)&instr[2]) )
   9.136 +        goto fail;
   9.137 +    printf("okay\n");
   9.138 +
   9.139 +    printf("%-40s", "Testing movl (%%eax),%%ecx...");
   9.140 +    instr[0] = 0x8b; instr[1] = 0x08;
   9.141 +    regs.eflags = 0x200;
   9.142 +    regs.eip    = (unsigned long)&instr[0];
   9.143 +    regs.ecx    = ~0UL;
   9.144 +    regs.eax    = (unsigned long)res;
   9.145 +    rc = x86_emulate(&ctxt, &emulops);
   9.146 +    if ( (rc != X86EMUL_OKAY) || 
   9.147 +         (*res != 0x92345677) || 
   9.148 +         (regs.ecx != 0x92345677UL) ||
   9.149 +         (regs.eip != (unsigned long)&instr[2]) )
   9.150 +        goto fail;
   9.151 +    printf("okay\n");
   9.152 +
   9.153 +    printf("%-40s", "Testing lock cmpxchgb %%cl,(%%ebx)...");
   9.154 +    instr[0] = 0xf0; instr[1] = 0x0f; instr[2] = 0xb0; instr[3] = 0x0b;
   9.155 +    regs.eflags = 0x200;
   9.156 +    regs.eip    = (unsigned long)&instr[0];
   9.157 +    regs.eax    = 0x92345677UL;
   9.158 +    regs.ecx    = 0xAA;
   9.159 +    regs.ebx    = (unsigned long)res;
   9.160 +    rc = x86_emulate(&ctxt, &emulops);
   9.161 +    if ( (rc != X86EMUL_OKAY) || 
   9.162 +         (*res != 0x923456AA) || 
   9.163 +         (regs.eflags != 0x244) ||
   9.164 +         (regs.eax != 0x92345677UL) ||
   9.165 +         (regs.eip != (unsigned long)&instr[4]) )
   9.166 +        goto fail;
   9.167 +    printf("okay\n");
   9.168 +
   9.169 +    printf("%-40s", "Testing lock cmpxchgb %%cl,(%%ebx)...");
   9.170 +    instr[0] = 0xf0; instr[1] = 0x0f; instr[2] = 0xb0; instr[3] = 0x0b;
   9.171 +    regs.eflags = 0x200;
   9.172 +    regs.eip    = (unsigned long)&instr[0];
   9.173 +    regs.eax    = 0xAABBCC77UL;
   9.174 +    regs.ecx    = 0xFF;
   9.175 +    regs.ebx    = (unsigned long)res;
   9.176 +    rc = x86_emulate(&ctxt, &emulops);
   9.177 +    if ( (rc != X86EMUL_OKAY) || 
   9.178 +         (*res != 0x923456AA) || 
   9.179 +         ((regs.eflags&0x240) != 0x200) ||
   9.180 +         (regs.eax != 0xAABBCCAA) ||
   9.181 +         (regs.ecx != 0xFF) ||
   9.182 +         (regs.eip != (unsigned long)&instr[4]) )
   9.183 +        goto fail;
   9.184 +    printf("okay\n");
   9.185 +
   9.186 +    printf("%-40s", "Testing xchgl %%ecx,(%%eax)...");
   9.187 +    instr[0] = 0x87; instr[1] = 0x08;
   9.188 +    regs.eflags = 0x200;
   9.189 +    regs.eip    = (unsigned long)&instr[0];
   9.190 +    regs.ecx    = 0x12345678;
   9.191 +    regs.eax    = (unsigned long)res;
   9.192 +    rc = x86_emulate(&ctxt, &emulops);
   9.193 +    if ( (rc != X86EMUL_OKAY) || 
   9.194 +         (*res != 0x12345678) || 
   9.195 +         (regs.eflags != 0x200) ||
   9.196 +         (regs.ecx != 0x923456AA) ||
   9.197 +         (regs.eip != (unsigned long)&instr[2]) )
   9.198 +        goto fail;
   9.199 +    printf("okay\n");
   9.200 +
   9.201 +    printf("%-40s", "Testing lock cmpxchgl %%ecx,(%%ebx)...");
   9.202 +    instr[0] = 0xf0; instr[1] = 0x0f; instr[2] = 0xb1; instr[3] = 0x0b;
   9.203 +    regs.eflags = 0x200;
   9.204 +    *res        = 0x923456AA;
   9.205 +    regs.eip    = (unsigned long)&instr[0];
   9.206 +    regs.eax    = 0x923456AAUL;
   9.207 +    regs.ecx    = 0xDDEEFF00L;
   9.208 +    regs.ebx    = (unsigned long)res;
   9.209 +    rc = x86_emulate(&ctxt, &emulops);
   9.210 +    if ( (rc != X86EMUL_OKAY) || 
   9.211 +         (*res != 0xDDEEFF00) || 
   9.212 +         (regs.eflags != 0x244) ||
   9.213 +         (regs.eax != 0x923456AAUL) ||
   9.214 +         (regs.eip != (unsigned long)&instr[4]) )
   9.215 +        goto fail;
   9.216 +    printf("okay\n");
   9.217 +
   9.218 +    printf("%-40s", "Testing rep movsw...");
   9.219 +    instr[0] = 0xf3; instr[1] = 0x66; instr[2] = 0xa5;
   9.220 +    *res        = 0x22334455;
   9.221 +    regs.eflags = 0x200;
   9.222 +    regs.ecx    = 23;
   9.223 +    regs.eip    = (unsigned long)&instr[0];
   9.224 +    regs.esi    = (unsigned long)res + 0;
   9.225 +    regs.edi    = (unsigned long)res + 2;
   9.226 +    rc = x86_emulate(&ctxt, &emulops);
   9.227 +    if ( (rc != X86EMUL_OKAY) || 
   9.228 +         (*res != 0x44554455) ||
   9.229 +         (regs.eflags != 0x200) ||
   9.230 +         (regs.ecx != 22) || 
   9.231 +         (regs.esi != ((unsigned long)res + 2)) ||
   9.232 +         (regs.edi != ((unsigned long)res + 4)) ||
   9.233 +         (regs.eip != (unsigned long)&instr[0]) )
   9.234 +        goto fail;
   9.235 +    printf("okay\n");
   9.236 +
   9.237 +    printf("%-40s", "Testing btrl $0x1,(%edi)...");
   9.238 +    instr[0] = 0x0f; instr[1] = 0xba; instr[2] = 0x37; instr[3] = 0x01;
   9.239 +    *res        = 0x2233445F;
   9.240 +    regs.eflags = 0x200;
   9.241 +    regs.eip    = (unsigned long)&instr[0];
   9.242 +    regs.edi    = (unsigned long)res;
   9.243 +    rc = x86_emulate(&ctxt, &emulops);
   9.244 +    if ( (rc != X86EMUL_OKAY) ||
   9.245 +         (*res != 0x2233445D) ||
   9.246 +         ((regs.eflags&0x201) != 0x201) ||
   9.247 +         (regs.eip != (unsigned long)&instr[4]) )
   9.248 +        goto fail;
   9.249 +    printf("okay\n");
   9.250 +
   9.251 +    printf("%-40s", "Testing btrl %eax,(%edi)...");
   9.252 +    instr[0] = 0x0f; instr[1] = 0xb3; instr[2] = 0x07;
   9.253 +    *res        = 0x2233445F;
   9.254 +    regs.eflags = 0x200;
   9.255 +    regs.eip    = (unsigned long)&instr[0];
   9.256 +    regs.eax    = -32;
   9.257 +    regs.edi    = (unsigned long)(res+1);
   9.258 +    rc = x86_emulate(&ctxt, &emulops);
   9.259 +    if ( (rc != X86EMUL_OKAY) ||
   9.260 +         (*res != 0x2233445E) ||
   9.261 +         ((regs.eflags&0x201) != 0x201) ||
   9.262 +         (regs.eip != (unsigned long)&instr[3]) )
   9.263 +        goto fail;
   9.264 +    printf("okay\n");
   9.265 +
   9.266 +    res[0] = 0x12345678;
   9.267 +    res[1] = 0x87654321;
   9.268 +
   9.269 +    printf("%-40s", "Testing cmpxchg8b (%edi) [succeeding]...");
   9.270 +    instr[0] = 0x0f; instr[1] = 0xc7; instr[2] = 0x0f;
   9.271 +    regs.eflags = 0x200;
   9.272 +    regs.eax    = res[0];
   9.273 +    regs.edx    = res[1];
   9.274 +    regs.ebx    = 0x9999AAAA;
   9.275 +    regs.ecx    = 0xCCCCFFFF;
   9.276 +    regs.eip    = (unsigned long)&instr[0];
   9.277 +    regs.edi    = (unsigned long)res;
   9.278 +    rc = x86_emulate(&ctxt, &emulops);
   9.279 +    if ( (rc != X86EMUL_OKAY) ||
   9.280 +         (res[0] != 0x9999AAAA) ||
   9.281 +         (res[1] != 0xCCCCFFFF) ||
   9.282 +         ((regs.eflags&0x240) != 0x240) ||
   9.283 +         (regs.eip != (unsigned long)&instr[3]) )
   9.284 +        goto fail;
   9.285 +    printf("okay\n");
   9.286 +
   9.287 +    printf("%-40s", "Testing cmpxchg8b (%edi) [failing]...");
   9.288 +    instr[0] = 0x0f; instr[1] = 0xc7; instr[2] = 0x0f;
   9.289 +    regs.eflags = 0x200;
   9.290 +    regs.eip    = (unsigned long)&instr[0];
   9.291 +    regs.edi    = (unsigned long)res;
   9.292 +    rc = x86_emulate(&ctxt, &emulops);
   9.293 +    if ( (rc != X86EMUL_OKAY) || 
   9.294 +         (res[0] != 0x9999AAAA) ||
   9.295 +         (res[1] != 0xCCCCFFFF) ||
   9.296 +         (regs.eax != 0x9999AAAA) ||
   9.297 +         (regs.edx != 0xCCCCFFFF) ||
   9.298 +         ((regs.eflags&0x240) != 0x200) ||
   9.299 +         (regs.eip != (unsigned long)&instr[3]) )
   9.300 +        goto fail;
   9.301 +    printf("okay\n");
   9.302 +
   9.303 +    printf("%-40s", "Testing movsxbd (%%eax),%%ecx...");
   9.304 +    instr[0] = 0x0f; instr[1] = 0xbe; instr[2] = 0x08;
   9.305 +    regs.eflags = 0x200;
   9.306 +    regs.eip    = (unsigned long)&instr[0];
   9.307 +    regs.ecx    = 0x12345678;
   9.308 +    regs.eax    = (unsigned long)res;
   9.309 +    *res        = 0x82;
   9.310 +    rc = x86_emulate(&ctxt, &emulops);
   9.311 +    if ( (rc != X86EMUL_OKAY) ||
   9.312 +         (*res != 0x82) ||
   9.313 +         (regs.ecx != 0xFFFFFF82) ||
   9.314 +         ((regs.eflags&0x240) != 0x200) ||
   9.315 +         (regs.eip != (unsigned long)&instr[3]) )
   9.316 +        goto fail;
   9.317 +    printf("okay\n");
   9.318 +
   9.319 +    printf("%-40s", "Testing movzxwd (%%eax),%%ecx...");
   9.320 +    instr[0] = 0x0f; instr[1] = 0xb7; instr[2] = 0x08;
   9.321 +    regs.eflags = 0x200;
   9.322 +    regs.eip    = (unsigned long)&instr[0];
   9.323 +    regs.ecx    = 0x12345678;
   9.324 +    regs.eax    = (unsigned long)res;
   9.325 +    *res        = 0x1234aa82;
   9.326 +    rc = x86_emulate(&ctxt, &emulops);
   9.327 +    if ( (rc != X86EMUL_OKAY) ||
   9.328 +         (*res != 0x1234aa82) ||
   9.329 +         (regs.ecx != 0xaa82) ||
   9.330 +         ((regs.eflags&0x240) != 0x200) ||
   9.331 +         (regs.eip != (unsigned long)&instr[3]) )
   9.332 +        goto fail;
   9.333 +    printf("okay\n");
   9.334 +
   9.335 +    printf("%-40s", "Testing xadd %%ax,(%%ecx)...");
   9.336 +    instr[0] = 0x66; instr[1] = 0x0f; instr[2] = 0xc1; instr[3] = 0x01;
   9.337 +    regs.eflags = 0x200;
   9.338 +    regs.eip    = (unsigned long)&instr[0];
   9.339 +    regs.ecx    = (unsigned long)res;
   9.340 +    regs.eax    = 0x12345678;
   9.341 +    *res        = 0x11111111;
   9.342 +    rc = x86_emulate(&ctxt, &emulops);
   9.343 +    if ( (rc != X86EMUL_OKAY) ||
   9.344 +         (*res != 0x11116789) ||
   9.345 +         (regs.eax != 0x12341111) ||
   9.346 +         ((regs.eflags&0x240) != 0x200) ||
   9.347 +         (regs.eip != (unsigned long)&instr[4]) )
   9.348 +        goto fail;
   9.349 +    printf("okay\n");
   9.350 +
   9.351 +    printf("%-40s", "Testing dec %%ax...");
   9.352 +    instr[0] = 0x66; instr[1] = 0x48;
   9.353 +    regs.eflags = 0x200;
   9.354 +    regs.eip    = (unsigned long)&instr[0];
   9.355 +    regs.eax    = 0x00000000;
   9.356 +    rc = x86_emulate(&ctxt, &emulops);
   9.357 +    if ( (rc != X86EMUL_OKAY) ||
   9.358 +         (regs.eax != 0x0000ffff) ||
   9.359 +         ((regs.eflags&0x240) != 0x200) ||
   9.360 +         (regs.eip != (unsigned long)&instr[2]) )
   9.361 +        goto fail;
   9.362 +    printf("okay\n");
   9.363 +
   9.364 +    printf("%-40s", "Testing lea 8(%%ebp),%%eax...");
   9.365 +    instr[0] = 0x8d; instr[1] = 0x45; instr[2] = 0x08;
   9.366 +    regs.eflags = 0x200;
   9.367 +    regs.eip    = (unsigned long)&instr[0];
   9.368 +    regs.eax    = 0x12345678;
   9.369 +    regs.ebp    = 0xaaaaaaaa;
   9.370 +    rc = x86_emulate(&ctxt, &emulops);
   9.371 +    if ( (rc != X86EMUL_OKAY) ||
   9.372 +         (regs.eax != 0xaaaaaab2) ||
   9.373 +         ((regs.eflags&0x240) != 0x200) ||
   9.374 +         (regs.eip != (unsigned long)&instr[3]) )
   9.375 +        goto fail;
   9.376 +    printf("okay\n");
   9.377 +
   9.378 +    printf("%-40s", "Testing daa/das (all inputs)...");
   9.379 +#ifndef __x86_64__
   9.380 +    /* Bits 0-7: AL; Bit 8: EFLG_AF; Bit 9: EFLG_CF; Bit 10: DAA vs. DAS. */
   9.381 +    for ( i = 0; i < 0x800; i++ )
   9.382 +    {
   9.383 +        regs.eflags  = (i & 0x200) ? EFLG_CF : 0;
   9.384 +        regs.eflags |= (i & 0x100) ? EFLG_AF : 0;
   9.385 +        if ( i & 0x400 )
   9.386 +            __asm__ (
   9.387 +                "pushf; and $0xffffffee,(%%esp); or %1,(%%esp); popf; das; "
   9.388 +                "pushf; popl %1"
   9.389 +                : "=a" (bcdres_native), "=r" (regs.eflags)
   9.390 +                : "0" (i & 0xff), "1" (regs.eflags) );
   9.391 +        else
   9.392 +            __asm__ (
   9.393 +                "pushf; and $0xffffffee,(%%esp); or %1,(%%esp); popf; daa; "
   9.394 +                "pushf; popl %1"
   9.395 +                : "=a" (bcdres_native), "=r" (regs.eflags)
   9.396 +                : "0" (i & 0xff), "1" (regs.eflags) );
   9.397 +        bcdres_native |= (regs.eflags & EFLG_PF) ? 0x1000 : 0;
   9.398 +        bcdres_native |= (regs.eflags & EFLG_ZF) ? 0x800 : 0;
   9.399 +        bcdres_native |= (regs.eflags & EFLG_SF) ? 0x400 : 0;
   9.400 +        bcdres_native |= (regs.eflags & EFLG_CF) ? 0x200 : 0;
   9.401 +        bcdres_native |= (regs.eflags & EFLG_AF) ? 0x100 : 0;
   9.402 +
   9.403 +        instr[0] = (i & 0x400) ? 0x2f: 0x27; /* daa/das */
   9.404 +        regs.eflags  = (i & 0x200) ? EFLG_CF : 0;
   9.405 +        regs.eflags |= (i & 0x100) ? EFLG_AF : 0;
   9.406 +        regs.eip    = (unsigned long)&instr[0];
   9.407 +        regs.eax    = (unsigned char)i;
   9.408 +        rc = x86_emulate(&ctxt, &emulops);
   9.409 +        bcdres_emul  = regs.eax;
   9.410 +        bcdres_emul |= (regs.eflags & EFLG_PF) ? 0x1000 : 0;
   9.411 +        bcdres_emul |= (regs.eflags & EFLG_ZF) ? 0x800 : 0;
   9.412 +        bcdres_emul |= (regs.eflags & EFLG_SF) ? 0x400 : 0;
   9.413 +        bcdres_emul |= (regs.eflags & EFLG_CF) ? 0x200 : 0;
   9.414 +        bcdres_emul |= (regs.eflags & EFLG_AF) ? 0x100 : 0;
   9.415 +        if ( (rc != X86EMUL_OKAY) || (regs.eax > 255) ||
   9.416 +             (regs.eip != (unsigned long)&instr[1]) )
   9.417 +            goto fail;
   9.418 +
   9.419 +        if ( bcdres_emul != bcdres_native )
   9.420 +        {
   9.421 +            printf("%s:    AL=%02x %s %s\n"
   9.422 +                   "Output: AL=%02x %s %s %s %s %s\n"
   9.423 +                   "Emul.:  AL=%02x %s %s %s %s %s\n",
   9.424 +                   (i & 0x400) ? "DAS" : "DAA",
   9.425 +                   (unsigned char)i,
   9.426 +                   (i & 0x200) ? "CF" : "  ",
   9.427 +                   (i & 0x100) ? "AF" : "  ",
   9.428 +                   (unsigned char)bcdres_native,
   9.429 +                   (bcdres_native & 0x200) ? "CF" : "  ",
   9.430 +                   (bcdres_native & 0x100) ? "AF" : "  ",
   9.431 +                   (bcdres_native & 0x1000) ? "PF" : "  ",
   9.432 +                   (bcdres_native & 0x800) ? "ZF" : "  ",
   9.433 +                   (bcdres_native & 0x400) ? "SF" : "  ",
   9.434 +                   (unsigned char)bcdres_emul,
   9.435 +                   (bcdres_emul & 0x200) ? "CF" : "  ",
   9.436 +                   (bcdres_emul & 0x100) ? "AF" : "  ",
   9.437 +                   (bcdres_emul & 0x1000) ? "PF" : "  ",
   9.438 +                   (bcdres_emul & 0x800) ? "ZF" : "  ",
   9.439 +                   (bcdres_emul & 0x400) ? "SF" : "  ");
   9.440 +            goto fail;
   9.441 +        }
   9.442 +    }
   9.443 +    printf("okay\n");
   9.444 +#else
   9.445 +    printf("skipped\n");
   9.446 +#endif
   9.447 +
   9.448 +    for ( j = 1; j <= 2; j++ )
   9.449 +    {
   9.450 +#if defined(__i386__)
   9.451 +        if ( j == 2 ) break;
   9.452 +        memcpy(res, blowfish32_code, sizeof(blowfish32_code));
   9.453 +#else
   9.454 +        memcpy(res, (j == 1) ? blowfish32_code : blowfish64_code,
   9.455 +               (j == 1) ? sizeof(blowfish32_code) : sizeof(blowfish64_code));
   9.456 +#endif
   9.457 +        printf("Testing blowfish %u-bit code sequence", j*32);
   9.458 +        regs.eax = 2;
   9.459 +        regs.edx = 1;
   9.460 +        regs.eip = (unsigned long)res;
   9.461 +        regs.esp = (unsigned long)res + MMAP_SZ - 4;
   9.462 +        if ( j == 2 )
   9.463 +        {
   9.464 +            ctxt.addr_size = ctxt.sp_size = 64;
   9.465 +            *(uint32_t *)(unsigned long)regs.esp = 0;
   9.466 +            regs.esp -= 4;
   9.467 +        }
   9.468 +        *(uint32_t *)(unsigned long)regs.esp = 0x12345678;
   9.469 +        regs.eflags = 2;
   9.470 +        i = 0;
   9.471 +        while ( regs.eip != 0x12345678 )
   9.472 +        {
   9.473 +            if ( (i++ & 8191) == 0 )
   9.474 +                printf(".");
   9.475 +            rc = x86_emulate(&ctxt, &emulops);
   9.476 +            if ( rc != X86EMUL_OKAY )
   9.477 +            {
   9.478 +                printf("failed at %%eip == %08x\n", (unsigned int)regs.eip);
   9.479 +                return 1;
   9.480 +            }
   9.481 +        }
   9.482 +        if ( (regs.esp != ((unsigned long)res + MMAP_SZ)) ||
   9.483 +             (regs.eax != 2) || (regs.edx != 1) )
   9.484 +            goto fail;
   9.485 +        printf("okay\n");
   9.486 +    }
   9.487 +
   9.488 +    printf("%-40s", "Testing blowfish native execution...");    
   9.489 +    asm volatile (
   9.490 +#if defined(__i386__)
   9.491 +        "movl $0x100000,%%ecx; call *%%ecx"
   9.492 +#else
   9.493 +        "movl $0x100000,%%ecx; call *%%rcx"
   9.494 +#endif
   9.495 +        : "=a" (regs.eax), "=d" (regs.edx)
   9.496 +        : "0" (2), "1" (1) : "ecx" );
   9.497 +    if ( (regs.eax != 2) || (regs.edx != 1) )
   9.498 +        goto fail;
   9.499 +    printf("okay\n");
   9.500 +
   9.501 +    return 0;
   9.502 +
   9.503 + fail:
   9.504 +    printf("failed!\n");
   9.505 +    return 1;
   9.506 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/tools/tests/x86_emulator/x86_emulate.c	Sat Jan 08 10:59:13 2011 +0000
    10.3 @@ -0,0 +1,7 @@
    10.4 +#include <stddef.h>
    10.5 +#include <stdint.h>
    10.6 +#include <string.h>
    10.7 +#include <public/xen.h>
    10.8 +
    10.9 +#include "x86_emulate/x86_emulate.h"
   10.10 +#include "x86_emulate/x86_emulate.c"