1 /***************************************************************************
2 * Copyright (C) 2007 Ryan Schultz, PCSX-df Team, PCSX team *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA. *
18 ***************************************************************************/
21 * ix86 definitions v0.5.1
22 * Authors: linuzappz <linuzappz@pcsx.net>
33 // include basic types
34 #include "../psxcommon.h"
35 #include "../r3000a.h"
36 #include "../psxhle.h"
39 #define X86FLAG_FPU 0x00000001
40 #define X86FLAG_VME 0x00000002
41 #define X86FLAG_DEBUGEXT 0x00000004
42 #define X86FLAG_4MPAGE 0x00000008
43 #define X86FLAG_TSC 0x00000010
44 #define X86FLAG_MSR 0x00000020
45 #define X86FLAG_PAE 0x00000040
46 #define X86FLAG_MCHKXCP 0x00000080
47 #define X86FLAG_CMPXCHG8B 0x00000100
48 #define X86FLAG_APIC 0x00000200
49 #define X86FLAG_SYSENTER 0x00000800
50 #define X86FLAG_MTRR 0x00001000
51 #define X86FLAG_GPE 0x00002000
52 #define X86FLAG_MCHKARCH 0x00004000
53 #define X86FLAG_CMOV 0x00008000
54 #define X86FLAG_PAT 0x00010000
55 #define X86FLAG_PSE36 0x00020000
56 #define X86FLAG_PN 0x00040000
57 #define X86FLAG_MMX 0x00800000
58 #define X86FLAG_FXSAVE 0x01000000
59 #define X86FLAG_SSE 0x02000000
63 #define X86EFLAG_MMXEXT 0x00400000
64 #define X86EFLAG_3DNOWEXT 0x40000000
65 #define X86EFLAG_3DNOW 0x80000000
68 #define write8(val) *(u8 *)x86Ptr = val; x86Ptr++;
69 #define write16(val) *(u16*)x86Ptr = val; x86Ptr+=2;
70 #define write32(val) *(u32*)x86Ptr = val; x86Ptr+=4;
71 #define write64(val) *(u64*)x86Ptr = val; x86Ptr+=8;
101 extern u8 *j8Ptr[32];
102 extern u32 *j32Ptr[32];
105 void x86SetPtr(char *ptr);
108 void x86SetJ8(u8 *j8);
109 void x86SetJ32(u32 *j32);
110 void x86Align(int bytes);
113 /********************/
114 /* IX86 intructions */
115 /********************/
125 ////////////////////////////////////
126 // mov instructions /
127 ////////////////////////////////////
130 void MOV32RtoR(int to, int from);
132 void MOV32RtoM(u32 to, int from);
134 void MOV32MtoR(int to, u32 from);
135 /* mov [r32] to r32 */
136 void MOV32RmtoR(int to, int from);
137 /* mov [r32][r32*scale] to r32 */
138 void MOV32RmStoR(int to, int from, int from2, int scale);
139 /* mov r32 to [r32] */
140 void MOV32RtoRm(int to, int from);
141 /* mov r32 to [r32][r32*scale] */
142 void MOV32RtoRmS(int to, int to2, int scale, int from);
143 /* mov imm32 to r32 */
144 void MOV32ItoR(int to, u32 from);
145 /* mov imm32 to m32 */
146 void MOV32ItoM(u32 to, u32 from);
149 void MOV16RtoM(u32 to, int from);
151 void MOV16MtoR(int to, u32 from);
152 /* mov imm16 to m16 */
153 void MOV16ItoM(u32 to, u16 from);
156 void MOV8RtoM(u32 to, int from);
158 void MOV8MtoR(int to, u32 from);
160 void MOV8ItoM(u32 to, u8 from);
162 /* movsx r8 to r32 */
163 void MOVSX32R8toR(int to, int from);
164 /* movsx m8 to r32 */
165 void MOVSX32M8toR(int to, u32 from);
166 /* movsx r16 to r32 */
167 void MOVSX32R16toR(int to, int from);
168 /* movsx m16 to r32 */
169 void MOVSX32M16toR(int to, u32 from);
171 /* movzx r8 to r32 */
172 void MOVZX32R8toR(int to, int from);
173 /* movzx m8 to r32 */
174 void MOVZX32M8toR(int to, u32 from);
175 /* movzx r16 to r32 */
176 void MOVZX32R16toR(int to, int from);
177 /* movzx m16 to r32 */
178 void MOVZX32M16toR(int to, u32 from);
180 /* cmovne r32 to r32 */
181 void CMOVNE32RtoR(int to, int from);
182 /* cmovne m32 to r32*/
183 void CMOVNE32MtoR(int to, u32 from);
184 /* cmove r32 to r32*/
185 void CMOVE32RtoR(int to, int from);
186 /* cmove m32 to r32*/
187 void CMOVE32MtoR(int to, u32 from);
188 /* cmovg r32 to r32*/
189 void CMOVG32RtoR(int to, int from);
190 /* cmovg m32 to r32*/
191 void CMOVG32MtoR(int to, u32 from);
192 /* cmovge r32 to r32*/
193 void CMOVGE32RtoR(int to, int from);
194 /* cmovge m32 to r32*/
195 void CMOVGE32MtoR(int to, u32 from);
196 /* cmovl r32 to r32*/
197 void CMOVL32RtoR(int to, int from);
198 /* cmovl m32 to r32*/
199 void CMOVL32MtoR(int to, u32 from);
200 /* cmovle r32 to r32*/
201 void CMOVLE32RtoR(int to, int from);
202 /* cmovle m32 to r32*/
203 void CMOVLE32MtoR(int to, u32 from);
205 ////////////////////////////////////
206 // arithmetic instructions /
207 ////////////////////////////////////
209 /* add imm32 to r32 */
210 void ADD32ItoR(int to, u32 from);
211 /* add imm32 to m32 */
212 void ADD32ItoM(u32 to, u32 from);
214 void ADD32RtoR(int to, int from);
216 void ADD32RtoM(u32 to, int from);
218 void ADD32MtoR(int to, u32 from);
220 /* adc imm32 to r32 */
221 void ADC32ItoR(int to, u32 from);
223 void ADC32RtoR(int to, int from);
225 void ADC32MtoR(int to, u32 from);
232 /* sub imm32 to r32 */
233 void SUB32ItoR(int to, u32 from);
235 void SUB32RtoR(int to, int from);
237 void SUB32MtoR(int to, u32 from);
239 /* sbb imm32 to r32 */
240 void SBB32ItoR(int to, u32 from);
242 void SBB32RtoR(int to, int from);
244 void SBB32MtoR(int to, u32 from);
251 /* mul eax by r32 to edx:eax */
252 void MUL32R(int from);
253 /* mul eax by m32 to edx:eax */
254 void MUL32M(u32 from);
256 /* imul eax by r32 to edx:eax */
257 void IMUL32R(int from);
258 /* imul eax by m32 to edx:eax */
259 void IMUL32M(u32 from);
260 /* imul r32 by r32 to r32 */
261 void IMUL32RtoR(int to, int from);
263 /* div eax by r32 to edx:eax */
264 void DIV32R(int from);
265 /* div eax by m32 to edx:eax */
266 void DIV32M(u32 from);
268 /* idiv eax by r32 to edx:eax */
269 void IDIV32R(int from);
270 /* idiv eax by m32 to edx:eax */
271 void IDIV32M(u32 from);
273 ////////////////////////////////////
274 // shifting instructions /
275 ////////////////////////////////////
277 /* shl imm8 to r32 */
278 void SHL32ItoR(int to, u8 from);
280 void SHL32CLtoR(int to);
282 /* shr imm8 to r32 */
283 void SHR32ItoR(int to, u8 from);
285 void SHR32CLtoR(int to);
287 /* sar imm8 to r32 */
288 void SAR32ItoR(int to, u8 from);
290 void SAR32CLtoR(int to);
292 /* sal imm8 to r32 */
293 #define SAL32ItoR SHL32ItoR
295 #define SAL32CLtoR SHL32CLtoR
297 // logical instructions
299 /* or imm32 to r32 */
300 void OR32ItoR(int to, u32 from);
301 /* or imm32 to m32 */
302 void OR32ItoM(u32 to, u32 from);
304 void OR32RtoR(int to, int from);
306 void OR32RtoM(u32 to, int from);
308 void OR32MtoR(int to, u32 from);
310 /* xor imm32 to r32 */
311 void XOR32ItoR(int to, u32 from);
312 /* xor imm32 to m32 */
313 void XOR32ItoM(u32 to, u32 from);
315 void XOR32RtoR(int to, int from);
317 void XOR32RtoM(u32 to, int from);
319 void XOR32MtoR(int to, u32 from);
321 /* and imm32 to r32 */
322 void AND32ItoR(int to, u32 from);
323 /* and imm32 to m32 */
324 void AND32ItoM(u32 to, u32 from);
326 void AND32RtoR(int to, int from);
328 void AND32RtoM(u32 to, int from);
330 void AND32MtoR(int to, u32 from);
333 void NOT32R(int from);
335 void NEG32R(int from);
337 ////////////////////////////////////
338 // jump instructions /
339 ////////////////////////////////////
408 void CALLFunc(u32 func); // based on CALL32
412 void CALL32R(int to);
414 void CALL32M(u32 to);
416 ////////////////////////////////////
417 // misc instructions /
418 ////////////////////////////////////
420 /* cmp imm32 to r32 */
421 void CMP32ItoR(int to, u32 from);
422 /* cmp imm32 to m32 */
423 void CMP32ItoM(u32 to, u32 from);
425 void CMP32RtoR(int to, int from);
427 void CMP32MtoR(int to, u32 from);
429 /* test imm32 to r32 */
430 void TEST32ItoR(int to, u32 from);
431 /* test r32 to r32 */
432 void TEST32RtoR(int to, int from);
448 void PUSH32R(int from);
450 void PUSH32M(u32 from);
452 void PUSH32I(u32 from);
455 void POP32R(int from);
465 /********************/
466 /* FPU instructions */
467 /********************/
469 /* fild m32 to fpu reg stack */
470 void FILD32(u32 from);
471 /* fistp m32 from fpu reg stack */
472 void FISTP32(u32 from);
473 /* fld m32 to fpu reg stack */
474 void FLD32(u32 from);
475 /* fstp m32 from fpu reg stack */
478 /* fldcw fpu control word from m16 */
479 void FLDCW(u32 from);
480 /* fstcw fpu control word to m16 */
483 /* fadd m32 to fpu reg stack */
484 void FADD32(u32 from);
485 /* fsub m32 to fpu reg stack */
486 void FSUB32(u32 from);
487 /* fmul m32 to fpu reg stack */
488 void FMUL32(u32 from);
489 /* fdiv m32 to fpu reg stack */
490 void FDIV32(u32 from);
491 /* fabs fpu reg stack */
493 /* fsqrt fpu reg stack */
495 /* fchs fpu reg stack */
498 /********************/
499 /* MMX instructions */
500 /********************/
504 /* movq m64 to r64 */
505 void MOVQMtoR(int to, u32 from);
506 /* movq r64 to m64 */
507 void MOVQRtoM(u32 to, int from);
509 /* pand r64 to r64 */
510 void PANDRtoR(int to, int from);
511 /* pand m64 to r64 */
512 void PANDMtoR(int to, u32 from);
514 /* pandn r64 to r64 */
515 void PANDNRtoR(int to, int from);
517 /* pandn r64 to r64 */
518 void PANDNMtoR(int to, u32 from);
521 void PORRtoR(int to, int from);
523 void PORMtoR(int to, u32 from);
525 /* pxor r64 to r64 */
526 void PXORRtoR(int to, int from);
527 /* pxor m64 to r64 */
528 void PXORMtoR(int to, u32 from);
530 /* psllq r64 to r64 */
531 void PSLLQRtoR(int to, int from);
532 /* psllq m64 to r64 */
533 void PSLLQMtoR(int to, u32 from);
534 /* psllq imm8 to r64 */
535 void PSLLQItoR(int to, u8 from);
537 /* psrlq r64 to r64 */
538 void PSRLQRtoR(int to, int from);
539 /* psrlq m64 to r64 */
540 void PSRLQMtoR(int to, u32 from);
541 /* psrlq imm8 to r64 */
542 void PSRLQItoR(int to, u8 from);
544 /* paddusb r64 to r64 */
545 void PADDUSBRtoR(int to, int from);
546 /* paddusb m64 to r64 */
547 void PADDUSBMtoR(int to, u32 from);
548 /* paddusw r64 to r64 */
549 void PADDUSWRtoR(int to, int from);
550 /* paddusw m64 to r64 */
551 void PADDUSWMtoR(int to, u32 from);
553 /* paddb r64 to r64 */
554 void PADDBRtoR(int to, int from);
555 /* paddb m64 to r64 */
556 void PADDBMtoR(int to, u32 from);
557 /* paddw r64 to r64 */
558 void PADDWRtoR(int to, int from);
559 /* paddw m64 to r64 */
560 void PADDWMtoR(int to, u32 from);
561 /* paddd r64 to r64 */
562 void PADDDRtoR(int to, int from);
563 /* paddd m64 to r64 */
564 void PADDDMtoR(int to, u32 from);
569 void BT32ItoR(int to,int from);
570 void RCR32ItoR(int to,int from);
573 void PADDSBRtoR(int to, int from);
574 void PADDSWRtoR(int to, int from);
575 void PADDSDRtoR(int to, int from);
576 void PSUBSBRtoR(int to, int from);
577 void PSUBSWRtoR(int to, int from);
578 void PSUBSDRtoR(int to, int from);
580 void PSUBBRtoR(int to, int from);
581 void PSUBWRtoR(int to, int from);
582 void PSUBDRtoR(int to, int from);
584 void MOVQ64ItoR(int reg,u64 i); //Prototype.Todo add all consts to end of block.not after jr $+8
586 void PMAXSWRtoR(int to,int from);
587 void PMINSWRtoR(int to,int from);
589 void PCMPEQBRtoR(int to,int from);
590 void PCMPEQWRtoR(int to,int from);
591 void PCMPEQDRtoR(int to,int from);
593 void PCMPGTBRtoR(int to,int from);
594 void PCMPGTWRtoR(int to,int from);
595 void PCMPGTDRtoR(int to,int from);
597 void PSRLWItoR(int to,int from);
598 void PSRLDItoR(int to,int from);
599 void PSLLWItoR(int to,int from);
600 void PSLLDItoR(int to,int from);
601 void PSRAWItoR(int to,int from);
602 void PSRADItoR(int to,int from);
604 //Added:basara 11.01.2003
605 void FCOMP32(u32 from);
607 void SETNZ8R(int to);
609 //Added:basara 14.01.2003
610 void PFCMPEQMtoR(int to,int from);
611 void PFCMPGTMtoR(int to,int from);
612 void PFCMPGEMtoR(int to,int from);
614 void PFADDMtoR(int to,int from);
615 void PFADDRtoR(int to,int from);
617 void PFSUBMtoR(int to,int from);
618 void PFSUBRtoR(int to,int from);
620 void PFMULMtoR(int to,int from);
621 void PFMULRtoR(int to,int from);
623 void PFRCPMtoR(int to,int from);
624 void PFRCPRtoR(int to,int from);
625 void PFRCPIT1RtoR(int to,int from);
626 void PFRCPIT2RtoR(int to,int from);
628 void PFRSQRTRtoR(int to,int from);
629 void PFRSQIT1RtoR(int to,int from);
631 void PF2IDMtoR(int to,int from);
632 void PF2IDRtoR(int to,int from);
633 void PI2FDMtoR(int to,int from);
634 void PI2FDRtoR(int to,int from);
636 void PFMAXMtoR(int to,int from);
637 void PFMAXRtoR(int to,int from);
638 void PFMINMtoR(int to,int from);
639 void PFMINRtoR(int to,int from);
641 void MOVDMtoR(int to, u32 from);
642 void MOVDRtoM(u32 to, int from);
643 void MOVD32RtoR(int to, int from);
644 void MOVD64RtoR(int to, int from);
646 void MOVQRtoR(int to,int from);
648 //if to==from MMLO=MMHI
649 void PUNPCKHDQRtoR(int to,int from);
651 //if to==from MMHI=MMLO
652 void PUNPCKLDQRtoR(int to,int from);
657 void MOVAPSMtoR(int to,int from);
658 void MOVAPSRtoM(int to,int from);
659 void MOVAPSRtoR(int to,int from);
661 void ORPSMtoR(int to,int from);
662 void ORPSRtoR(int to,int from);
664 void XORPSMtoR(int to,int from);
665 void XORPSRtoR(int to,int from);
667 void ANDPSMtoR(int to,int from);
668 void ANDPSRtoR(int to,int from);