1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058
|
// Copyright (c) 1997,1998,1999,2000 Albrecht Kleine All rights reserved
// file version #300
//-------------------------- constrains --------------------------------------
#ifdef FREEBSD
#undef EXCEPTIONS_BY_SIGNALS
#endif
#ifdef JDK102
#error no compiling for this jdk
#endif
#ifndef JDK12
#undef FAST_FPARITH
#endif
#define RESOLVE_FT 3 // resolver fault tolerance 0..3[4] (experimental)
// #define INIT0 // was needed for outdated jdk1.0.2
//-------------------------- debug messages ----------------------------------
#ifdef DEBUG
#ifdef USE_SYSLOG
// dprintf is a function definition, see below.
#define dflush while(0) fflush
#else
#define dprintf fprintf
#define dflush fflush
#endif
#undef USEASM
#else
#define dprintf while(0) fprintf
#define dflush while(0) fflush
#endif
#ifndef USE_SYSLOG
#define iprintf while(0) printf
#endif
//
#define LOCSTART 36 // offset of begin of memory for local variables
// compare layout description in InvokeCompiledMethod_Hook() !!
#define TYA_JSTACK 800000
#ifdef JDK12
#define CFR_OFF 8
#define LV_OFF 60
#else
#define CFR_OFF 4 // = (char*)&ee->curent_frame - (char*)ee
#define LV_OFF 64 // = (char*)&mbp->nlocals - (char*)mbp
#endif
#ifndef TYAASM_S
void lprintf(char *fmt, ...);
#ifdef USE_SYSLOG
void iprintf(char *fmt, ...);
#endif
void lopen(void);
void lclose(void);
#ifdef DEBUG
#ifdef USE_SYSLOG
void dprintf (FILE *ignore, char *fmt, ...);
#endif
#endif
//-------------------------- structures -------------------------------------
struct iptrans
{
unsigned char* java; // 1:1 mapping of adresses
unsigned char* x86; // (from bytcode to x86 code and vice versa)
int isdest; // TRUE if address is a jump destination
int type; // 32 possible operation types by flags (only 5 used today)
int arg; // copy of data arg
} ;
struct back
{
unsigned char* java;
unsigned char* x86;
int javadist;
int currcnt;
int destcnt;
int loop;
} ;
struct CINFO
{
unsigned char *cptr;
unsigned char *codebase;
unsigned char *bptr;
struct methodblock* mb;
struct iptrans* iptab;
int ipcnt;
struct back* backp;
int backcnt;
unsigned char** start;
unsigned char** end;
unsigned char** handler;
unsigned char** adrstart; // address where to backpatch
unsigned char** adrend;
unsigned char** adrhandler;
ClassClass **exclazz;
ExecEnv *ee;
int wide; // not yet finished (FIXME)
int isinline; // compiling an inlined method
int inlineerr; // do NOT allow compiling of inlined methods
int maxspace; // size of code array
int resspace; // reserved space at end
} ;
#define WORD unsigned short int
#define BYTE unsigned char
#define SIS4 (sizeof(stack_item))
//------------------------- recode and its helpers ----------------------------------
int recode(int j,Classjava_lang_Class *klass,struct CINFO* cinfo);
int GetMethNr(struct methodblock *mbp);
int GetMethodNumber(struct methodblock* mb,Classjava_lang_Class *klazz);
void Comp_PUSH_LocalVarToReg(int wo,struct CINFO* cinfo,int reg);
void Comp_POP_StoreLocalVarFromReg(int wo,struct CINFO* cinfo,int isnoobj,int reg);
int Comp_PUSH_LocalVarToStack(int wo,struct CINFO* cinfo);
void Comp_INC_LocalVar(int wo,int inc,struct CINFO* cinfo);
void CompVergleich(unsigned char code,int *j,unsigned short int opcode86,
struct CINFO* cinfo,int altercode);
void Comp87Vergleich(unsigned char code,struct CINFO* cinfo,unsigned char nextcode);
void Comp87ToInteger(unsigned char code,struct CINFO* cinfo);
int CompInlineFP(struct CINFO* cinfo,struct methodblock *mbp);
int CompFastCallFP(struct CINFO* cinfo,struct methodblock *mbp,int stac,int nextcode);
void MakeStackRevInstruction(struct methodblock *mb,int xstatic);
void* GetBlock(int *nr,int isfield,unsigned char code,int *pj,Classjava_lang_Class *klass,
struct CINFO* cinfo,int quick);
int getint32( int *j,struct CINFO* cinfo);
int getint16U(int *j,struct CINFO* cinfo);
int getint16S(int *j,struct CINFO* cinfo);
void BackPatchJumpDists(struct CINFO* cinfo);
void Pass2(struct CINFO *cinfo);
int LoopFinder(struct CINFO *cinfo);
void ShowPreInvokeInfo(struct methodblock *mb,int args_size,struct execenv *ee,int noncom);
void ShowPostInvokeInfo(struct methodblock *mb,struct execenv *ee,int nocom);
int ProcessExceptionTab(struct methodblock *mb,struct CINFO* cinfo);
int CompiliereMethode(struct methodblock* mb, struct CINFO *cinfo,ExecEnv *ee);
bool_t JITCompileMethod(struct methodblock *mb, struct execenv *ee);
bool_t MYInvokeCompiledMethod(JHandle *thiso, struct methodblock *mb,
int args_size, struct execenv *ee);
bool_t MyIsInstanceOf(ClassClass *dcb,ExecEnv *ee,HObject * h);
HObject *MyArrayAlloc(int type,int len);
HObject *MyObjAlloc(ClassClass *dcb);
void FastInvPrepare(struct execenv *ee,struct methodblock *mbpcalled,stack_item *sp);
unsigned long long FastInvNoCheck32(struct execenv *ee,struct methodblock *mbpcalled,stack_item *sp);
unsigned long long FastInvCheck64(struct execenv *ee,struct methodblock *mbpcalled,stack_item *sp);
unsigned long long FastInvCheck32(struct execenv *ee,struct methodblock *mbpcalled,stack_item *sp);
int CodeRunner32(ExecEnv *ee, struct methodblock *mb, int *args);
long long CodeRunner64(ExecEnv *ee, struct methodblock *mb, int *args);
long long CodeRunner64_withDummies(int d2,ExecEnv *ee, struct methodblock *mb, int *args);
int CodeRunner32_withDummies(int d2,ExecEnv *ee, struct methodblock *mb, int *args);
void debughelper(void *stacA,void *stacB,void *stacC);
void StOvExcHandler (void);
long long lldiv_wrapper(long long x,long long z);
long long llmul_wrapper(long long x,long long z);
long long llrem_wrapper(long long x,long long z);
struct methodblock *RTGetIMeth(HObject *o,ClassClass *klassX,int u);
//-----------------------------------------------------------------------------------------
void InitializeForCompiler_Hook(ClassClass *class);
bool_t InvokeCompiledMethod_Hook(JHandle *o, struct methodblock *mb, int args_size, struct execenv *ee);
#ifndef JDK12
long CompileClasses_Hook(Hjava_lang_String *hclname);
long CompileClass_Hook(ClassClass *class);
void* CompilerFreeClass_hook(ClassClass *clazz);
void CompiledCodeSignalHandler_hook(int sig,void *info,void *uc);
int PCinCompiledCode_Hook(unsigned char *pc,struct methodblock *mb);
#else
bool_t CompileClasses_Hook(Hjava_lang_String *hclname);
bool_t CompileClass_Hook(ClassClass *class);
void CompilerFreeClass_hook(ClassClass *clazz);
bool_t CompiledCodeSignalHandler_hook(int sig,void *info,void *uc);
bool_t PCinCompiledCode_Hook(unsigned char *pc,struct methodblock *mb);
JavaFrame *CompiledFramePrev_hook(JavaFrame *frame, JavaFrame *buf);
void *CompiledFrameID_hook(JavaFrame *frame);
bool_t CompilerRegisterNatives_hook(ClassClass *cb);
bool_t CompilerUnregisterNatives_hook(ClassClass *cb);
#endif
unsigned char *CompiledCodePC_Hook(JavaFrame *frame,struct methodblock *mb);
void Enable_hook(void);
void Disable_hook(void);
JHandle *CompilerCommand_hook(JHandle *x);
#ifndef JDK12
#define DEF_ResolveClassConstantFromClass(a,b,c,d) ResolveClassConstantFromClass(a,b,c,d)
#else
#define DEF_ResolveClassConstantFromClass(a,b,c,d) ResolveClassConstantFromClass2(a,b,c,d,1)
#endif
#define DEFCOMPILEDSIZE 20000 // most methods are below this value...
#define MAXCOMPILEDSIZE 1000000 // ...but for some we make an exception
#define INLINE_ERROR -1000 // error during inline compiling
#define NOSPACE_ERROR -2000
// --------------------------------------------------------------------------
// compare to memory layout sheet in tya.c (new in tya 0.8)
#define SIZEOFJMP86 5 // 5 because sizeof byte + sizeof int64 [or CB(),CL()]
#define LINKAGEERRHSIZE 4 // sizeof exception preparation code
#define DIVZEROHANDSIZE 4
#define ARROUTOFFSIZE 4
#define NEGARRSIZESIZE 4
#define NULLPTRSIZE 4
#define OUTOFMEMSIZE 4
#define ARRAYSTORESIZE 4
#define CLASSCASTSIZE 4
#define INVOKEDEXSIZE 4
#define ATHROWEXSIZE 4
#define INCOMPERRSIZE 4
#define ALLEXCEPTSIZE (LINKAGEERRHSIZE\
+DIVZEROHANDSIZE\
+ARROUTOFFSIZE\
+NEGARRSIZESIZE\
+NULLPTRSIZE\
+OUTOFMEMSIZE\
+ARRAYSTORESIZE\
+CLASSCASTSIZE\
+INVOKEDEXSIZE\
+ATHROWEXSIZE\
+INCOMPERRSIZE)
#define COMMONEXSIZE 16 // the common part for 9 others
#define RESERVED2 4 // sizeof int
#define ENTRYPOINT 64 // start of code
#if ALLEXCEPTSIZE+COMMONEXSIZE+RESERVED2 > ENTRYPOINT
#error bad ENTRYPOINT setting
#endif
#define CCF_invokeJavaMethod 1
#define CCF_invokeSynchronizedJavaMethod 2
#define CCF_invokeMask 3
#define CCF_VOID 4
#define CCF_R32 8
#define CCF_R64 16
#define CCF_COMBOK 32
#define CCF_INLINEOK 64
#define CCF_RESERVED 128
#define CCF_slenMask 0x7F00 // currently unused: done by shift right
#ifdef JDK12
#define DEF_CCF_IsInitialized CCF_IsInitialized
#else
#define CCF_CLINITPENDS 0x8000
#define CCF_CLINITRUN 0x4000
#define DEF_CCF_IsInitialized CCF_CLINITRUN
#endif
//-----------------------------------------------------------------------
#define DF_ISDEST 1
// basic operation types for iptrans->type
#define ANY 0
#define LOAD 1
#define COMP 2
#define STORE 3
#define ARIT 4
#define CONST 5
// used in iptans->arg
#define ADD 40
#define SUB 41
#ifdef COMBINEOP
#define DF_CmpL 2
#define DF_FF 4
#define DF_DD 8
#define DF_DDextra 16
#define DF_CmpI 32
#define DF_const0 64
#define DF_const1 128
#define DF_const2 256
#define DF_TestI 512
#define SET_OPTFLAG(flag) cinfo->iptab[cinfo->ipcnt ].isdest|=flag
#define GET_OPTFLAG(flag) (cinfo->iptab[cinfo->ipcnt-1].isdest & flag)
#define NEXT_LOADS_QWORD(next) \
(next==0x63||next==0x67||next==0x6B||next==0x6F||next==0x73||\
next==0x77||next==0x90||next==0x97||next==0x98||\
next==0xB5 ||next==0xE4 ||next==0x52 \
)
// this is of course a subset of NEXT_LOADS_QWORD()
#define NEXT_LOADS_2_QWORDS(next) \
(next==0x63||next==0x67||next==0x6B||next==0x6F||next==0x73||\
next==0x97||next==0x98 )
#define NEXT_LOADS_DWORD(next) \
(next==0x62||next==0x66||next==0x6A||next==0x6E||next==0x72||\
next==0x76||next==0x95||next==0x96)
#define NEXT_TESTS_WORD(next) \
(next==0x99||next==0x9A||next==0xC6||next==0xc7)
#define NEXT_LOADS_WORD(next) \
(next==0x15||next==0x1A||next==0x1B||next==0x1C||next==0x1D)
#define NEXT_COMPARES_2_WORDS(next) \
(next>=0x9F && next<=0xA4)
#endif
#if 0
the COMBINEOP pairs list
flag
----
first OP with second OP
(PRODUCER) (CONSUMER)
====================================================================
DF_CmpI
-------
fcmpl,fcmpg 0x95,0x96
dcmpl,dcmpg 0x97,0x98 --> ifeq,ifne,iflt,ifge,ifgt,ifle 0x99..0x9E
DF_CmpL
-------
lcmp 0x94 --> ifeq,ifne 0x99..0x9A
DF_DD
-----
dadd,dsub,dmul,ddiv
0x63,0x67,0x6B,0x6F --> dadd,dsub,dmul,ddiv,drem,dneg,d2f,dcmpl,dcmpg
drem,dneg 0x63,0x67,0x6B,0x6F,0x73,0x77,0x90,0x97,0x98
0x73,0x77 putfield,dastore
i2d,l2d,f2d 0xB5/0xE4,0x52
0x87,0x8A,0x8D
daload,getfield
0x31,0xB4/0xE3
invokestatic (some)
0xB8
DF_DDextra
----------
daload,getfield --> dadd,dsub,dmul,ddiv,drem,dcmpl,dcmpg
0x31,0xB4/0xE3 0x63,0x67,0x6B,0x6F,0x73,0x97,0x98
DF_FF
-----
fadd,fsub,fmul,fdiv
0x62,0x66,0x6A,0x6E --> fadd,fsub,fmul,fdiv,frem,fneg, fcmpl,fcmpg
frem,fneg 0x62,0x66,0x6A,0x6E,0x72,0x76, 0x95,0x96
0x72,0x76
DF_constX
---------
aconst_null,iconst_0 --> bastore,iastore,fastore
fconst_0, iconst1 0x54,0x4F,0x51
1,3,0xB,4
iconst_2 --> imul,idiv
5 0x68,0x6C
DF_TestI
--------
iload,aload --> ifne,ifeq,ifnull
0x15,0x17,0x2A etc. 0x9A,0x99,0xC6,0xC7
#endif
//---------------------------------------------------------------------------
void SimpleExcHandler(void);
void ExecExcep(ExecEnv *ee,HObject *exception_obj);
char *CompExceptionHandlerPart1(struct CINFO* cinfo);
void CompExceptionHandlerPart2(struct CINFO* cinfo);
void PrepareExceptions(void);
#ifdef EXT_ERR
HObject* CreateIAException(char *detail);
#endif
void CompTriggerLinkageError(struct CINFO* cinfo);
void CompTriggerLONGDivZeroException(struct CINFO* cinfo);
void CompTriggerDivZeroException(struct CINFO* cinfo);
void CompTriggerArrOutOfBoundsException(struct CINFO* cinfo);
void CompTriggerArrOutOfBoundsException2(struct CINFO* cinfo, int tmpreg);
void CompTriggerNegArraySizeException(struct CINFO* cinfo);
void CompTriggerNullPointerException(struct CINFO* cinfo, int reg);
void CompTriggerNullPointerException2(struct CINFO* cinfo, int reg);
void CompTriggerOutOfMemoryException(struct CINFO* cinfo);
void CompTriggerArrayStoreException(struct CINFO* cinfo);
void CompTriggerClassCastException(struct CINFO* cinfo);
void CompTriggerAthrowException(struct CINFO*cinfo);
void CompTriggerIncompatibleClassChangeError(struct CINFO* cinfo);
void CompTriggerExceptionFromInvoked(struct CINFO* cinfo,int ee_reg);
//---------------------------------------------------------------------------
#define ____METHOD_STARTS_HERE____ 0
#ifndef VERBOSE_ASM86
#define CB(BYTE) *cinfo->cptr++=(unsigned char)BYTE
#define CW(word) *((WORD*)cinfo->cptr)++=(WORD)(word)
#define CL(LONG) *((unsigned long*)cinfo->cptr)++=(unsigned long)(LONG)
#define emit( x )
#else
#define CB(BYTE) (*cinfo->cptr++=(unsigned char)BYTE,fprintf(stderr,"%s \t%02x\n",#BYTE,BYTE))
#define CW(word) (*((WORD*)cinfo->cptr)++=(WORD)(word),fprintf(stderr,"%s\n",#word))
#define CL(LONG) (*((unsigned long*)cinfo->cptr)++=(unsigned long)(LONG),fprintf(stderr,"%s\n",#LONG))
#define emit( x ) fprintf x
#define se stderr
extern const char * rname[];
extern const char * rname8[];
extern const char * sibdecode(int );
int decode_bytecode(unsigned char *code);
#endif
////////////////////////////////////////////////////////////////////////////////////
// Machine code data is preassembled using a Intl style syntax, no gnu-asssembler //
////////////////////////////////////////////////////////////////////////////////////
#define EAX 0
#define ECX 1
#define EDX 2
#define EBX 3
#define ESP 4
#define EBP 5
#define ESI 6
#define EDI 7
#define R8_AL 0
#define R8_CL 1
#define R8_DL 2
#define R8_BL 3
// FIXME: should rearrange that stuff....
// most of them can be expressed also (better) by a different way, see below
#define INC_AX 0x40 /* inc eax */
#define INC_BX 0x43 /* inc ebx */
#define DEC_BX 0x4B /* dec ebx */
#define DEC_AX 0x48 /* dec eax */
#define INC_DI 0x47 /* inc edi */
#define INC_SI 0x46 /* inc esi */
#define DEC_DI 0x4F /* dec edi */
#define DEC_SI 0x4E /* dec esi */
#define PREF_32 0x66 /* seg attr prefix */
#define NOP 0x90 /* do nothing */
#define NOP2 0x9090 /* do nothing twice ;-) */
#define MOV_BXAX 0xC389 /* mov ebx,eax */
#define MOV_AXDX 0xC28B /* mov eax,edx */
#define MOV_CXAX 0xC189 /* mov ecx,eax */
#define MOV_BXDX 0xDA8B /* mov ebx,edx */
#define MOV_BXCX 0xD98B /* mov ebx,ecx */
#define MOV_CXDX 0xCA8B
#define MOV_DXBX 0xDA89
#define MOV_AXBX 0xD889
#define MOV_AX_SP 0xC48B
#define ADD_BXCX 0xCB01
#define SUB_BXCX 0xCB29
#define ADD_DXDX 0xD203
#define ADD_BXDX 0xDA03
#define ADD_BXAX 0xD803 /* add ebx,eax */
#define ADC_CXDX 0xCA13 /* adc ecx,edx */
#define SBB_AXBX 0xC31B /* sbb eax,ebx */
#define SUB_CXDX 0xCA2B /* sub ecx,edx */
#define SBB_CXDX 0xCA1B /* sbb ecx,edx */
#define MOV_CX_MBX_8 0x4B8B
#define MOV_MCX_AX 0x0189
#define MOV_MCX_DX 0x1189
#define ADD_CX 0xC183
#define OR_AXCX 0xC10B /* or eax,ecx */
#define XOR_AXCX 0xC133 /* xor eax,ecx */
#define AND_AXCX 0xC123 /* and eax,ecx */
#define OR_CLCL 0xC90A /* or cl,cl */
#define OR_DXBX 0xD30B /* or edx,ebx */
#define XOR_DXBX 0xD333 /* xor edx,ebx */
#define AND_DXBX 0xD323 /* and edx,ebx */
#define OR_AXBX 0xC30B /* or eax,ebx */
#define AND_AXBX 0xC323 /* and eax,ebx */
#define XOR_AXBX 0xC333 /* xor eax,ebx */
#define XOR_BXBX 0xDB33 /* xor ebx,ebx */
#define ADD_SP_MBP_8 0x6503
#define SUB_SP_MBP_8 0x652B
#define SUB_SPDX 0xd429
#define SUB_SPBX 0xE32B /* sub esp,ebx */
#define SUB_SP_BYTE 0xEC83 /* sub esp,XX */
#define TEST_SP_LONG 0xC4F7 /* test esp,yyyyyyyy */
#define TEST_BX 0xC3F7
#define TEST_CLCL 0xC984 /* test cl,cl */
#define TEST_AXAX 0xC085 /* test eax,eax */
#define TEST_BXBX 0xDB85 /* test ebx,ebx */
#define TEST_DXDX 0xD285 /* test edx,edx */
#define TEST_CXCX 0xC985 /* test ecx,ecx */
#define TEST_DIDI 0xFF85 /* test edi,edi */
#define TEST_SISI 0xF685 /* test esi,esi */
#define MOV_BX_MAX_8 0x588B
#define MOV_BX_MAX 0x188B
#define MOV_AX_MAX_32 0x808B /* mov eax,[eax+yyyyyyyy] */
#define MOV_AX_MAX_8 0x408B
#define MOV_AX_MAX 0x008B
#define MOV_MCX_8_DX 0x5189
#define MOV_MCX_8_BX 0x5989
#define CMP_MBP_8_LONG 0x7D83
#define MOV_BX_MCX 0x198B
#define MOV_BX_MBX 0x1b8b /* mov ebx,[ebx] */
#define MOV_DX_MBX 0x138b /* mov edx,[ebx] */
#define ADD_MBP_32_LONG 0x8581 /* add [ebp+xxxxxxxx],yyyyyyyy */
#define ADD_MBP_8_LONG 0x4581 /* add [ebp+xx],yyyyyyyy */
#define ADD_MBP_8_BYTE 0x4583 /* add [ebp+xx],yy */
#define CMP_MBX_8 0x7B81 /* cmp [bx+xx],yyyyyyyy */
#define LEAVE_RET 0xC3C9 /* leave stackframe / return */
#define ENTER 0xC8 /* enter stackframe xxxx yy */
#define LOOP 0xE2 /* loop .. */
#define MOV_AX 0xB8 /* mov eax,yyyyyyyy */
#define MOV_BX 0xBB /* mov eax,yyyyyyyy */
#define MOV_CX 0xB9 /* mov ecx,yyyyyyyy */
#define MOV_DX 0xBA
#define MOV_MBP_8_AL 0x4588 /* mov [ebp+yy],al */
#define MOV_MBP_8_AX 0x4589 /* mov [ebp+yy],eax */
#define MOV_MBP_32_AX 0x8589 /* mov [ebp+yyyyyyyy],eax */
#define MOV_AL_MBP_8 0x458A /* mov al,[ebp+yy] */
#define MOV_AX_MBP_8 0x458B /* mov eax,[ebp+yy] */
#define MOV_AX_MBP_32 0x858B /* mov eax,[ebp+yyyyyyyy] */
#define MOV_BX_MBX_8 0x5B8B /* mov ebx,[ebx+yy] */
#define MOV_BX_MBX_32 0x9B8B /* mov ebx,[ebx+yyyyyyyy] */
#define MOV_AX_MBX_8 0x438B /* mov eax,[ebx+yy] */
#define MOV_AX_MBX_32 0x838B /* mov eax,[ebx+yyyyyyyy] */
#define MOV_DX_MBX_32 0x938B /* mov edx,[ebx+yyyyyyyy] */
#define MOV_CX_MBX_8 0x4B8B /* mov ecx,[ebx+yy] */
#define MOV_CX_MBP_8 0x4D8B /* mov ecx,[ebp+yy] */
#define MOV_DX_MBP_8 0x558B /* mov edx,[ebp+yy] */
#define MOV_BX_MBP_8 0x5D8B /* mov ebx,[ebp+yy] */
#define MOV_BX_MBP_8 0x5D8B
#define MOV_BX_MBP_32 0x9D8B
#define OR_MBP_8_BYTE 0x4D80
#define MOV_MBP_8_SI 0x7589
#define MOV_MBP_8_DI 0x7D89
#define MOV_SI_MBP_8 0x758B
#define MOV_DI_MBP_8 0x7D8B
#define MOV_SI_MBP_32 0xB58B
#define MOV_DI_MBP_32 0xBD8B
#define MOV_MBP_8_DX 0x5589
#define MOV_DIBX 0xFB8B /* mov edi,ebx */
#define MOV_SIBX 0xF38B /* mov esi,ebx */
#define MOV_DI_MBX_8 0x7B8B /* mov edi,[ebx+yy] */
#define MOV_MBX_8_DI 0x7B89 /* mov [ebx+yy],edi */
#define CLD_STOSD 0xABFC /* cld / stosb */
#define STOSD 0xAB /* stosd */
#define XCHG_AXCX 0x91 /* xchg eax,ecx */
#define XCHG_AXDX 0x92 /* xchg eax,edx */
#define XCHG_AXBX 0x93 /* xchg eax,ebx */
#define MOV_CXBX 0xCB8B /* mov ecx,ebx */
#define MOV_DXAX 0xD08B /* mov edx,eax */
#define MOV_MBX_LONG 0x03C7
#define MOV_MBX_DX 0x1389 /* mov [ebx],edx */
#define MOV_MBX_DL 0x1388 /* mov [ebx],dl */
#define MOV_MBX_CX 0x0B89 /* mov [ebx],ecx */
#define MOV_CX_MCX_8 0x498B /* mov ebx,[ecx+yy] */
#define MOV_MBX_8_CX 0x4B89 /* mov [ebx+yy],ecx */
#define MOV_MBX_8_AX 0x4389 /* mov [ebx+yy],eax */
#define MOV_DL_MBX_8 0x538A /* mov dl,byte ptr [ebx+yy] */
#define SHR_DX 0xEAC1 /* shr edx,yy */
#define SHR_BX 0xEBC1 /* shr ebx,yy */
#define MOV_BXBP 0xDD8B /* mov ebx,ebp */
#define MOV_AX_MBX 0x038b /* mov eax,[ebx] */
#define MOV_MBX_AX 0x0389 /* mov [ebx],eax */
#define MOV_CL_MBX 0x4B8A /* mov cl,byte ptr [ebx] */
#define AND_CX 0xE181 /* and ecx,yyyyyyyy */
#define AND_CX_BYTE 0xE183 /* and ecx,yy */
#define AND_AL 0x24
#define AND_AX_LONG 0x25 /* and eax,yyyyyyyy */
#define AND_AX_BYTE 0xE083 /* and eax,yy */
#define NEG_AX 0xD8F7 /* neg ax */
#define OR_AX 0x0d /* or ax,... */
#define OR_AXAX 0xC00B /* or ax,ax */
#define CMP_AXBX 0xD839 /* cmp eax,ebx */
#define CMP_CXBX 0xCB3B /* cmp ecx,ebx */
#define CMP_BXCX 0xCB39 /* cmp ebx,ecy */
#define CMP_CXAX 0xC139 /* cmp ecx,eax */
#define CMP_DXBX 0xDA39 /* cmp edx,ebx */
#define CMP_BXAX 0xD83B /* cmp ebx,eax */
#define CMP_DXAX 0xD03B /* cmp edx,eax */
#define CMP_BXDX 0xDA3B /* cmp ebx, edx */
#define CMP_AXCX 0xC13B /* cmp eax,ecx */
#define OR_BXBX 0xDB0B /* or ebx,ebx */
#define OR_DXDX 0xD20B /* or ebx,ebx */
#define SHL_BX 0xE3C1
#define MOV_MBP_8_BX 0x5D89
#define ADD_BXBX 0xDB03
#define SUB_BX_LONG 0xEB81
#define SUB_BX_BYTE 0xEB83 /* sub ebx,XX */
#define ADD_BX_BYTE 0xC383 /* add ebx,XX */
#define ADD_BX_LONG 0xC381 /* add ebx,XXXXXXXX */
#define MOV_AXDI 0xF889
#define MOV_AXSI 0xF089
#define MOV_DIAX 0xC789
#define MOV_SIAX 0xC689
#define MOV_BXDI 0xDF8B
#define MOV_BXSI 0xDE8B
#define ADD_DI 0xc781 /* add di,yyyyyyyy */
#define ADD_SI 0xc681 /* add si,yyyyyyyy */
#define SHL_AX 0xE0C1 /* shl eax,.. */
#define SHR_AX 0xE8C1 /* shr eax,.. */
#define SAR_AX 0xF8C1 /* sAr eax,.. */
#define SAR_DX 0xFAC1 /* sAr edx,.. */
#define SHL_AXCL 0xE0D3 /* shl eax,cl */
#define SHR_AXCL 0xE8D3 /* shr eax,cl */
#define SAR_AXCL 0xF8D3 /* sAr eax,cl */
#define SAR_DXCL 0xFAD3
#define SHR_DXCL 0xEAD3
#define PREBYTE_0F 0x0F /* prefix */
#define SHLD_DXAXCL 0xC2A5
#define SHRD_DXAXCL 0xD0AD
#define SHR_CL 0xE9C0
#define ROR_CL 0xC9C0
#define SHL_AX_1 0xE0D1 /* shl eax,1 */
#define RCL_DX_1 0xD2D1 /* rcl edx,1 */
#define SAR_DX_1 0xFAD1 /* sAr edx,1 */
#define SHR_DX_1 0xEAD1 /* shr edx,1 */
#define RCR_AX_1 0xD8D1 /* rcr eax,1 */
#define XOR_DXDX 0xD233 /* xor edx,edx */
#define XOR_AXAX 0xC033 /* xor eax,eax */
#define ADD_AXAX 0xC003 /* add eax,eax */
#define ADD_AXDX 0xC203 /* add eax,edx */
#define ADD_AXBX 0xC303 /* add eax,ebx */
#define SUB_AXBX 0xC32B /* sub eax,ebx */
#define SUB_AXDX 0xC22B /* sub eax,edx */
#define SUB_BXAX 0xD82B /* sub ebx,eax */
#define ADDAX 0xC083 /* add eax,yy */
#define ADD_DX_BYTE 0xC283
#define CMP_MDX_LONG 0x3A81
#define MOV_AX_MDX 0x028B
#define CMP_DX_LONG 0xFA81
#define ADC_DX_BYTE 0xD283
#define ADC_CX_BYTE 0xD183
#define ADC_AX_BYTE 0xD083
#define OR_CXCX 0xC90B
#define ADCBX 0xD383 /* adc ebx, */
#define IMUL_BX 0xEBF7 /* imul ebx */
#define IDIV_BX 0xFBF7 /* idiv ebx */
#define IDIV_DX 0xFAF7 /* idiv edx */
#define NOTBX 0xD3F7 /* not ebx */
#define NOTAX 0xD0F7 /* not eax */
#define CMP_AX 0x3D /* cmp eax,yyyyyyyy */
#define CMP_BX 0xFB81 /* cmp ebx,yyyyyyyy */
#define CMP_BX_BYTE 0xFB83 /* cmp ebx,yy */
#define LEA_DX_AX_8 0x508D
#define MOV_DX_MDX_8 0x528B
#define ADD_DXAX 0xC201
#define MOV_BX_SP 0xDC8B /* mov ebx,esp */
#define MOV_CX_AX 0xC88B /* mov ecx,eax */
#define CDQ 0x99 /* cdq (eax->edx:eax) */
#define CWDE 0x98
#define FLD_M_BX 0x03D9 /* fld dword [ebx] */
#define FLD_QWM_BX 0x03DD /* fld qword [ebx] */
#define FILD_QWM_BX 0x2BDF /* fild qword [ebx] */
#define FILD_M_BX 0x03DB /* fild dword [ebx] */
#define FSTP_M_BX 0x1BD9 /* fstp dword [ebx] */
#define FSTP_QWM_BX 0x1BDD /* fstp qword [ebx] */
#define FISTP_M_BX 0x1BDB /* fistp dword [ebx] */
#define FISTP_QWM_BX 0x3BDF /* fistp qword [ebx] */
#define FLD_M_BX_32 0x83DD /* fld qword ptr [ebx+xxxxxxxx] */
#define FSTP_M_BX_32 0x9BDD /* fstp qword ptr[ebx+xxxxxxxx] */
#define FADDP_ST1 0xC1DE /* faddp st1,st */
#define FSUBRP_ST1 0xE1DE /* fsubrp st1,st */
#define FSUBP_ST2 0xEADE
#define FMULP_ST1 0xC9DE /* fmulp st1,st */
#define FDIVRP_ST1 0xF1DE /* fdivrp st1,st */
#define FPREM 0xF8D9 /* fprem *** this does _NOT_ pop ! *** */
#define FCHS 0xE0D9 /* fchs */
#define FSIN 0xFED9 /* fsin */
#define FCOS 0xFFD9 /* fcos */
#define FPTAN 0xF2D9
#define FSQRT 0xFAD9
#define FYL2X 0xF1D9
#define FRNDINT 0xFCD9
#define F2XM1 0xF0D9
#define FLD1 0xE8D9
#define F_SCALE 0xFDD9 /* 'FSCALE' is used in freebsd */
#define FLD 0xC0D9
#define FLDZ 0xEED9 /* fld zero */
#define FCOMPP 0xD9DE /* fcompp */
#define FSTSW_AX 0xE0DF /* fstsw ax */
#define FSTCW_MBP 0x7DD9 /* fstcw [ebp-xx] */
#define FLDCW_MBP 0x6DD9 /* fldcw [ebp-xx] */
#define FLDW_MSP 0x04D9 /* fld dword [esp] */
#define FSTPW_MSP 0x1CD9 /* similar */
#define FLDQW_MSP 0x04DD /* ditto FIXME: rename */
#define FLDQW_M 0x04DD /* ditto */
#define FSTPQW_MSP 0x1CDD
#define FSTPQW_M 0x1CDD /* FIXME */
#define FISTP_MSP 0x1CDB
#define FISTPQ_MSP 0x3CDF
#define FILDW_MSP 0x04DB
#define FILDQW_MSP 0x2CDF
#define FXCH 0xC9D9 /* fxch */
#define FSTP_ST0 0xD8DD /* fstp st(0) */
#define FSTP_ST1 0xD9DD
#define SP_ADDR_BYTE3 0x24
#define IDX_ADDR_BYTE3 0xC3
#define INX_ADDR_BYTE3 0xD3
#define MOV_BX_MSP 0x1C8B // do not forget Byte3: this is SP_ADDR_BYTE3
#define MOV_BX_MSP_BYTE 0x5C8B //+Byte3! XX
#define MOV_BX_MSP_LONG 0x9C8B //+Byte3! YYYYYYYY
#define CMP_MAX_CX 0x4839 // cmp [eax],ecx
#define LEA_BX 0x1C8D //+ different Byte 3
#define LEA_BX_AX_LONG 0x988D /* lea ebx,[eax+yyyyyyyy] */
#define PUSHLONG2 0x6A /* push yy (short version) */
#define PUSHLONG 0x68 /* push yyyyyyyy */
#define JZ2 0x840F /* jz .... */
#define JNZ2 0x850F /* jnz .... */
#define JL2 0x8C0F /* jl .... */
#define JLE2 0x8E0F /* jle.... */
#define JG2 0x8F0F /* jg .... */
#define JGE2 0x8D0F /* jge.... */
#define JNB2 0x830F
#define JNA2 0x860F
#define JA2 0x870F
#define JB2 0x820F
#define JMP1 0xE9 /* jmp_near */
#define CALL 0xE8 /* call */
#define SAHF 0x9e /* sahf */
#define JCXZ 0xE3 /* JCXZ ..*/
#define JB 0x72 /* jb .. */
#define JE 0x74 /* je .. */
#define JNE 0x75 /* jne .. */
#define JAE 0x73 /* jae .. */
#define JA 0x77 /* ja .. */
#define JNC 0x73 /* jnc .. */
#define JNS 0x79 /* jns .. */
#define JNGE 0x7C /* jnge .. */
#define JNL 0x7D /* jnl .. */
#define JNLE 0x7F /* jnle .. */
#define JMPS 0xEB /* jmp_short .. */
#define ADD_SP_BYTE 0xC483 /* add esp,yy */
#define ADD_SP_LONG 0xC481 /* add esp,yyyyyyyy */
#define SUB_SP_BYTE 0xEC83 /* sub esp,yy */
#define SUB_SP_LONG 0xEC81 /* sub esp,yyyyyyyy */
#define PUSHPOPAX 0x5850
#define PUSHAXPOPDX 0x5A50
#define PUSHAXPOPCX 0x5950
#define POPPUSHAX 0x5058 /* this cannot be easily replaced by nulls !! */
#define PUSH_SP 0x54
#define POPAX 0x58
#define POPBX 0x5B
#define PUSHAX 0x50
#define PUSHDX 0x52
#define POPCX 0x59
#define PUSHCX 0x51
#define PUSHBX 0x53
#define POPDX 0x5A
#define PUSHDX 0x52
#define POPBP 0x5D
#define POPDI 0x5F
#define POPSI 0x5E
#define PUSHSI 0x56
#define PUSHDI 0x57
#define PUSHBP 0x55
#define MOV_BPSP 0xE589 /* mov ebp,esp */
#define MOV_SPBP 0xEC89 /* mov esp,ebp */
#define DEBUGBREAK 0xCC /* int3 */
#define CMC 0xF5 /*CMC*/
#define CLC 0xF8 /*clr cy*/
#define STC 0xF9 /*set cy*/
#define RETN 0xC3 /* ret near */
#define CALL_EBX 0xD3FF /* call ebx */
#define CALL_ECX 0xD1FF /* call ecx */
#define CALL_EAX 0xD0FF /* call eax */
#define CALL_EDX 0xD2FF /* call edx */
#define JMP_BX 0xE3FF /* jmp ebx */
/* some preassembled 4byter */
#define CALL_ADDSP 0xC483D3FF /* call [ebx] - add esp,yy */
#define POPBPDISIBX 0x5B5E5F5D /* pop ebp - pop edi - pop esi - pop ebx */
/* Different way of specifying opcodes */
#define OR_R_R( reg1, reg2 )\
emit((se, "or %s,%s\n", rname[reg1], rname[reg2]));\
CB(0x0B); CB( 0xC0 |(reg1<<3) | reg2)
#define TEST_R_R( reg1, reg2 )\
emit((se, "or %s,%s\n", rname[reg1], rname[reg2]));\
CB(0x85); CB( 0xC0 |(reg1<<3) | reg2)
#define MOV_R_MBX8( reg, off )\
emit((se, "mov %s, [ebx+%d]\n", rname[reg], off ));\
CB(0x8B); CB( 0x43 | (reg<<3)); CB(off)
#define SHR_R( reg, immed )\
emit((se, "shr %s,%d\n", rname[reg], immed));\
CB(0xC1); CB( 0xE8 | reg ); CB(immed)
// direction in cmp ???
#define CMP_R_R( reg1, reg2 )\
emit((se,"cmp %s,%s\n", rname[reg1], rname[reg2]));\
CB(0x3B); CB(0xC0 | (reg1 << 3) | reg2)
// you need to specify scale encoded (0=x1,1=x2,2=x4,3=x8)
#define SIB_SCALE1 0
#define SIB_SCALE2 1
#define SIB_SCALE4 2
#define SIB_SCALE8 3
#define SIB_RNONE 4
#define SIB( scale, scaledreg, reg ) ( (scale << 6) | (scaledreg << 3) | reg )
#define MOV_R_Rsib( reg, sibbyte )\
emit((se, "mov %s,[%s]\n",rname[reg], sibdecode(sibbyte)));\
CB( 0x8B ); CB( (reg<<3) | 0x04 ); CB(sibbyte)
#define MOV_R_Rsiboffs8( reg, sibbyte, offset )\
emit((se, "mov %s,[%s+%d]\n",rname[reg], sibdecode(sibbyte), offset));\
CB( 0x8B ); CB( (reg<<3) | 0x44 ); CB(sibbyte); CB( offset )
#define MOV_R_Rsiboffs32( reg, sibbyte, offset )\
emit((se, "mov %s,[%s+%d]\n",rname[reg], sibdecode(sibbyte), offset));\
CB( 0x8B ); CB( (reg<<3) | 0x84 ); CB(sibbyte); CL( offset )
#define MOV_Rsib_R( sibbyte, reg )\
emit((se, "mov [%s],%s\n",sibdecode(sibbyte), rname[reg]));\
CB( 0x89 ); CB( (reg<<3) | 0x04 ); CB(sibbyte)
#define MOV_Rsiboffs8_R( sibbyte, offset, reg )\
emit((se, "mov [%s+%d],%s\n", sibdecode(sibbyte), offset, rname[reg]));\
CB( 0x89 ); CB( (reg<<3) | 0x44 ); CB(sibbyte); CB( offset )
#define MOV_Rsiboffs32_R( sibbyte, offset, reg )\
emit((se, "mov [%s+%d],%s\n", sibdecode(sibbyte), offset, rname[reg]));\
CB( 0x89 ); CB( (reg<<3) | 0x84 ); CB(sibbyte); CL( offset )
#define MOV_Rsib_8R( sibbyte, reg )\
emit((se, "mov [%s],%s\n",sibdecode(sibbyte), rname8[reg]));\
CB( 0x88 ); CB( (reg<<3) | 0x04 ); CB(sibbyte)
#define MOV_R_mem( reg, adr )\
emit((se, "mov %s,[%p]\n", rname[reg], adr));\
CB( 0x8b ); CB( (reg << 3) | 0x05); CL( adr )
#define MOV_mem_R( adr, reg )\
emit((se, "mov [%p],%s\n", adr, rname[reg]));\
CB( 0x89 ); CB( (reg << 3) | 0x05); CL( adr )
#define MOV_R_Rmem( reg1, reg2 )\
emit((se, "mov %s, [%s]\n", rname[reg1], rname[reg2]));\
CB( 0x8b ); CB( (reg1<<3) | reg2 )
#define MOV_Rmem_R( reg1, reg2 )\
emit((se, "mov [%s],%s\n", rname[reg1], rname[reg2]));\
CB( 0x89 ); CB( (reg2<<3) | reg1 )
#define MOV_R_Rmemoffs8( reg1, reg2, offset )\
emit((se, "mov %s,[%s+%d]\n", rname[reg1], rname[reg2], offset));\
CB( 0x8b ); CB(0x40 |(reg1<<3)|reg2); CB( offset )
#define MOV_R_Rmemoffs32( reg1, reg2, offset )\
emit((se, "mov %s,[%s+%d]\n", rname[reg1], rname[reg2], offset));\
CB( 0x8b ); CB(0x80 |(reg1<<3)|reg2); CL( offset )
#define MOV_R_Rmemoffs_(reg1, reg2, offset ) \
if ( (offset < 128) && (offset > -129) ) \
{ MOV_R_Rmemoffs8(reg1,reg2,offset); } \
else \
{ MOV_R_Rmemoffs32(reg1,reg2,offset); }
#define MOV_Rmemoffs8_R( reg1, offset, reg2 )\
emit((se, "mov [%s+%d],%s\n", rname[reg1], offset, rname[reg2]));\
CB( 0x89 ); CB(0x40 |(reg2<<3)|reg1); CB( offset )
#define MOV_Rmemoffs32_R( reg1, offset, reg2 )\
emit((se, "mov [%s+%d],%s\n", rname[reg1], offset, rname[reg2]));\
CB( 0x89 ); CB(0x80 |(reg2<<3)|reg1); CL( offset )
#define MOV_Rmemoffs__R(reg1, offset, reg2 ) \
if ( (offset < 128) && (offset > -129) ) \
{ MOV_Rmemoffs8_R(reg1,offset,reg2); } \
else \
{ MOV_Rmemoffs32_R(reg1,offset,reg2); }
#define PUSH_Roffs8( reg, offset ) \
emit((se, "push [%s+%d]\n", rname[reg], offset));\
CB( 0xFF ); CB( 0x70 | reg ); CB(offset)
#define MOV_R_R( reg1, reg2 ) \
emit((se, "mov %s,%s\n", rname[reg1], rname[reg2]));\
CB( 0x89 ); CB(0xc0 | (reg2<<3) | reg1 )
#define INC_mem( adr ) \
emit((se, "inc [%p]\n", adr));\
CB( 0xFF ); CB( 0x05 ); CL( adr )
#endif
|