dma: don't generate irqs after aborted DMA
[pcsx_rearmed.git] / libpcsxcore / ix86 / ix86.h
CommitLineData
ef79bbde
P
1/***************************************************************************
2 * Copyright (C) 2007 Ryan Schultz, PCSX-df Team, PCSX team *
3 * *
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. *
8 * *
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. *
13 * *
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 ***************************************************************************/
19
20/*
21 * ix86 definitions v0.5.1
22 * Authors: linuzappz <linuzappz@pcsx.net>
23 * alexey silinov
24 */
25
26#ifndef __IX86_H__
27#define __IX86_H__
28
29#ifdef __cplusplus
30extern "C" {
31#endif
32
33// include basic types
34#include "../psxcommon.h"
35#include "../r3000a.h"
36#include "../psxhle.h"
37
38// x86Flags defines
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
60
61// x86EFlags defines
62
63#define X86EFLAG_MMXEXT 0x00400000
64#define X86EFLAG_3DNOWEXT 0x40000000
65#define X86EFLAG_3DNOW 0x80000000
66
67/* general defines */
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;
72
73#define EAX 0
74#define EBX 3
75#define ECX 1
76#define EDX 2
77#define ESI 6
78#define EDI 7
79#define EBP 5
80#define ESP 4
81
82#define MM0 0
83#define MM1 1
84#define MM2 2
85#define MM3 3
86#define MM4 4
87#define MM5 5
88#define MM6 6
89#define MM7 7
90
91#define XMM0 0
92#define XMM1 1
93#define XMM2 2
94#define XMM3 3
95#define XMM4 4
96#define XMM5 5
97#define XMM6 6
98#define XMM7 7
99
100extern s8 *x86Ptr;
101extern u8 *j8Ptr[32];
102extern u32 *j32Ptr[32];
103
104void x86Init();
105void x86SetPtr(char *ptr);
106void x86Shutdown();
107
108void x86SetJ8(u8 *j8);
109void x86SetJ32(u32 *j32);
110void x86Align(int bytes);
111
112
113/********************/
114/* IX86 intructions */
115/********************/
116
117/*
118 * scale values:
119 * 0 - *1
120 * 1 - *2
121 * 2 - *4
122 * 3 - *8
123 */
124
125////////////////////////////////////
126// mov instructions /
127////////////////////////////////////
128
129/* mov r32 to r32 */
130void MOV32RtoR(int to, int from);
131/* mov r32 to m32 */
132void MOV32RtoM(u32 to, int from);
133/* mov m32 to r32 */
134void MOV32MtoR(int to, u32 from);
135/* mov [r32] to r32 */
136void MOV32RmtoR(int to, int from);
137/* mov [r32][r32*scale] to r32 */
138void MOV32RmStoR(int to, int from, int from2, int scale);
139/* mov r32 to [r32] */
140void MOV32RtoRm(int to, int from);
141/* mov r32 to [r32][r32*scale] */
142void MOV32RtoRmS(int to, int to2, int scale, int from);
143/* mov imm32 to r32 */
144void MOV32ItoR(int to, u32 from);
145/* mov imm32 to m32 */
146void MOV32ItoM(u32 to, u32 from);
147
148/* mov r16 to m16 */
149void MOV16RtoM(u32 to, int from);
150/* mov m16 to r16 */
151void MOV16MtoR(int to, u32 from);
152/* mov imm16 to m16 */
153void MOV16ItoM(u32 to, u16 from);
154
155/* mov r8 to m8 */
156void MOV8RtoM(u32 to, int from);
157/* mov m8 to r8 */
158void MOV8MtoR(int to, u32 from);
159/* mov imm8 to m8 */
160void MOV8ItoM(u32 to, u8 from);
161
162/* movsx r8 to r32 */
163void MOVSX32R8toR(int to, int from);
164/* movsx m8 to r32 */
165void MOVSX32M8toR(int to, u32 from);
166/* movsx r16 to r32 */
167void MOVSX32R16toR(int to, int from);
168/* movsx m16 to r32 */
169void MOVSX32M16toR(int to, u32 from);
170
171/* movzx r8 to r32 */
172void MOVZX32R8toR(int to, int from);
173/* movzx m8 to r32 */
174void MOVZX32M8toR(int to, u32 from);
175/* movzx r16 to r32 */
176void MOVZX32R16toR(int to, int from);
177/* movzx m16 to r32 */
178void MOVZX32M16toR(int to, u32 from);
179
180/* cmovne r32 to r32 */
181void CMOVNE32RtoR(int to, int from);
182/* cmovne m32 to r32*/
183void CMOVNE32MtoR(int to, u32 from);
184/* cmove r32 to r32*/
185void CMOVE32RtoR(int to, int from);
186/* cmove m32 to r32*/
187void CMOVE32MtoR(int to, u32 from);
188/* cmovg r32 to r32*/
189void CMOVG32RtoR(int to, int from);
190/* cmovg m32 to r32*/
191void CMOVG32MtoR(int to, u32 from);
192/* cmovge r32 to r32*/
193void CMOVGE32RtoR(int to, int from);
194/* cmovge m32 to r32*/
195void CMOVGE32MtoR(int to, u32 from);
196/* cmovl r32 to r32*/
197void CMOVL32RtoR(int to, int from);
198/* cmovl m32 to r32*/
199void CMOVL32MtoR(int to, u32 from);
200/* cmovle r32 to r32*/
201void CMOVLE32RtoR(int to, int from);
202/* cmovle m32 to r32*/
203void CMOVLE32MtoR(int to, u32 from);
204
205////////////////////////////////////
206// arithmetic instructions /
207////////////////////////////////////
208
209/* add imm32 to r32 */
210void ADD32ItoR(int to, u32 from);
211/* add imm32 to m32 */
212void ADD32ItoM(u32 to, u32 from);
213/* add r32 to r32 */
214void ADD32RtoR(int to, int from);
215/* add r32 to m32 */
216void ADD32RtoM(u32 to, int from);
217/* add m32 to r32 */
218void ADD32MtoR(int to, u32 from);
219
220/* adc imm32 to r32 */
221void ADC32ItoR(int to, u32 from);
222/* adc r32 to r32 */
223void ADC32RtoR(int to, int from);
224/* adc m32 to r32 */
225void ADC32MtoR(int to, u32 from);
226
227/* inc r32 */
228void INC32R(int to);
229/* inc m32 */
230void INC32M(u32 to);
231
232/* sub imm32 to r32 */
233void SUB32ItoR(int to, u32 from);
234/* sub r32 to r32 */
235void SUB32RtoR(int to, int from);
236/* sub m32 to r32 */
237void SUB32MtoR(int to, u32 from);
238
239/* sbb imm32 to r32 */
240void SBB32ItoR(int to, u32 from);
241/* sbb r32 to r32 */
242void SBB32RtoR(int to, int from);
243/* sbb m32 to r32 */
244void SBB32MtoR(int to, u32 from);
245
246/* dec r32 */
247void DEC32R(int to);
248/* dec m32 */
249void DEC32M(u32 to);
250
251/* mul eax by r32 to edx:eax */
252void MUL32R(int from);
253/* mul eax by m32 to edx:eax */
254void MUL32M(u32 from);
255
256/* imul eax by r32 to edx:eax */
257void IMUL32R(int from);
258/* imul eax by m32 to edx:eax */
259void IMUL32M(u32 from);
260/* imul r32 by r32 to r32 */
261void IMUL32RtoR(int to, int from);
262
263/* div eax by r32 to edx:eax */
264void DIV32R(int from);
265/* div eax by m32 to edx:eax */
266void DIV32M(u32 from);
267
268/* idiv eax by r32 to edx:eax */
269void IDIV32R(int from);
270/* idiv eax by m32 to edx:eax */
271void IDIV32M(u32 from);
272
273////////////////////////////////////
274// shifting instructions /
275////////////////////////////////////
276
277/* shl imm8 to r32 */
278void SHL32ItoR(int to, u8 from);
279/* shl cl to r32 */
280void SHL32CLtoR(int to);
281
282/* shr imm8 to r32 */
283void SHR32ItoR(int to, u8 from);
284/* shr cl to r32 */
285void SHR32CLtoR(int to);
286
287/* sar imm8 to r32 */
288void SAR32ItoR(int to, u8 from);
289/* sar cl to r32 */
290void SAR32CLtoR(int to);
291
292/* sal imm8 to r32 */
293#define SAL32ItoR SHL32ItoR
294/* sal cl to r32 */
295#define SAL32CLtoR SHL32CLtoR
296
297// logical instructions
298
299/* or imm32 to r32 */
300void OR32ItoR(int to, u32 from);
301/* or imm32 to m32 */
302void OR32ItoM(u32 to, u32 from);
303/* or r32 to r32 */
304void OR32RtoR(int to, int from);
305/* or r32 to m32 */
306void OR32RtoM(u32 to, int from);
307/* or m32 to r32 */
308void OR32MtoR(int to, u32 from);
309
310/* xor imm32 to r32 */
311void XOR32ItoR(int to, u32 from);
312/* xor imm32 to m32 */
313void XOR32ItoM(u32 to, u32 from);
314/* xor r32 to r32 */
315void XOR32RtoR(int to, int from);
316/* xor r32 to m32 */
317void XOR32RtoM(u32 to, int from);
318/* xor m32 to r32 */
319void XOR32MtoR(int to, u32 from);
320
321/* and imm32 to r32 */
322void AND32ItoR(int to, u32 from);
323/* and imm32 to m32 */
324void AND32ItoM(u32 to, u32 from);
325/* and r32 to r32 */
326void AND32RtoR(int to, int from);
327/* and r32 to m32 */
328void AND32RtoM(u32 to, int from);
329/* and m32 to r32 */
330void AND32MtoR(int to, u32 from);
331
332/* not r32 */
333void NOT32R(int from);
334/* neg r32 */
335void NEG32R(int from);
336
337////////////////////////////////////
338// jump instructions /
339////////////////////////////////////
340
341/* jmp rel8 */
342u8* JMP8(u8 to);
343
344/* jmp rel32 */
345u32* JMP32(u32 to);
346/* jmp r32 */
347void JMP32R(int to);
348
349/* je rel8 */
350u8* JE8(u8 to);
351/* jz rel8 */
352u8* JZ8(u8 to);
353/* jg rel8 */
354u8* JG8(u8 to);
355/* jge rel8 */
356u8* JGE8(u8 to);
357/* jl rel8 */
358u8* JL8(u8 to);
359/* jle rel8 */
360u8* JLE8(u8 to);
361/* jne rel8 */
362u8* JNE8(u8 to);
363/* jnz rel8 */
364u8* JNZ8(u8 to);
365/* jng rel8 */
366u8* JNG8(u8 to);
367/* jnge rel8 */
368u8* JNGE8(u8 to);
369/* jnl rel8 */
370u8* JNL8(u8 to);
371/* jnle rel8 */
372u8* JNLE8(u8 to);
373/* jo rel8 */
374u8* JO8(u8 to);
375/* jno rel8 */
376u8* JNO8(u8 to);
377
378/* je rel32 */
379u32* JE32(u32 to);
380/* jz rel32 */
381u32* JZ32(u32 to);
382/* jg rel32 */
383u32* JG32(u32 to);
384/* jge rel32 */
385u32* JGE32(u32 to);
386/* jl rel32 */
387u32* JL32(u32 to);
388/* jle rel32 */
389u32* JLE32(u32 to);
390/* jne rel32 */
391u32* JNE32(u32 to);
392/* jnz rel32 */
393u32* JNZ32(u32 to);
394/* jng rel32 */
395u32* JNG32(u32 to);
396/* jnge rel32 */
397u32* JNGE32(u32 to);
398/* jnl rel32 */
399u32* JNL32(u32 to);
400/* jnle rel32 */
401u32* JNLE32(u32 to);
402/* jo rel32 */
403u32* JO32(u32 to);
404/* jno rel32 */
405u32* JNO32(u32 to);
406
407/* call func */
408void CALLFunc(u32 func); // based on CALL32
409/* call rel32 */
410void CALL32(u32 to);
411/* call r32 */
412void CALL32R(int to);
413/* call m32 */
414void CALL32M(u32 to);
415
416////////////////////////////////////
417// misc instructions /
418////////////////////////////////////
419
420/* cmp imm32 to r32 */
421void CMP32ItoR(int to, u32 from);
422/* cmp imm32 to m32 */
423void CMP32ItoM(u32 to, u32 from);
424/* cmp r32 to r32 */
425void CMP32RtoR(int to, int from);
426/* cmp m32 to r32 */
427void CMP32MtoR(int to, u32 from);
428
429/* test imm32 to r32 */
430void TEST32ItoR(int to, u32 from);
431/* test r32 to r32 */
432void TEST32RtoR(int to, int from);
433/* sets r8 */
434void SETS8R(int to);
435/* setl r8 */
436void SETL8R(int to);
437/* setb r8 */
438void SETB8R(int to);
439
440/* cbw */
441void CBW();
442/* cwd */
443void CWD();
444/* cdq */
445void CDQ();
446
447/* push r32 */
448void PUSH32R(int from);
449/* push m32 */
450void PUSH32M(u32 from);
451/* push imm32 */
452void PUSH32I(u32 from);
453
454/* pop r32 */
455void POP32R(int from);
456
457/* pushad */
458void PUSHA32();
459/* popad */
460void POPA32();
461
462/* ret */
463void RET();
464
465/********************/
466/* FPU instructions */
467/********************/
468
469/* fild m32 to fpu reg stack */
470void FILD32(u32 from);
471/* fistp m32 from fpu reg stack */
472void FISTP32(u32 from);
473/* fld m32 to fpu reg stack */
474void FLD32(u32 from);
475/* fstp m32 from fpu reg stack */
476void FSTP32(u32 to);
477
478/* fldcw fpu control word from m16 */
479void FLDCW(u32 from);
480/* fstcw fpu control word to m16 */
481void FNSTCW(u32 to);
482
483/* fadd m32 to fpu reg stack */
484void FADD32(u32 from);
485/* fsub m32 to fpu reg stack */
486void FSUB32(u32 from);
487/* fmul m32 to fpu reg stack */
488void FMUL32(u32 from);
489/* fdiv m32 to fpu reg stack */
490void FDIV32(u32 from);
491/* fabs fpu reg stack */
492void FABS();
493/* fsqrt fpu reg stack */
494void FSQRT();
495/* fchs fpu reg stack */
496void FCHS();
497
498/********************/
499/* MMX instructions */
500/********************/
501
502// r64 = mm
503
504/* movq m64 to r64 */
505void MOVQMtoR(int to, u32 from);
506/* movq r64 to m64 */
507void MOVQRtoM(u32 to, int from);
508
509/* pand r64 to r64 */
510void PANDRtoR(int to, int from);
511/* pand m64 to r64 */
512void PANDMtoR(int to, u32 from);
513
514/* pandn r64 to r64 */
515void PANDNRtoR(int to, int from);
516
517/* pandn r64 to r64 */
518void PANDNMtoR(int to, u32 from);
519
520/* por r64 to r64 */
521void PORRtoR(int to, int from);
522/* por m64 to r64 */
523void PORMtoR(int to, u32 from);
524
525/* pxor r64 to r64 */
526void PXORRtoR(int to, int from);
527/* pxor m64 to r64 */
528void PXORMtoR(int to, u32 from);
529
530/* psllq r64 to r64 */
531void PSLLQRtoR(int to, int from);
532/* psllq m64 to r64 */
533void PSLLQMtoR(int to, u32 from);
534/* psllq imm8 to r64 */
535void PSLLQItoR(int to, u8 from);
536
537/* psrlq r64 to r64 */
538void PSRLQRtoR(int to, int from);
539/* psrlq m64 to r64 */
540void PSRLQMtoR(int to, u32 from);
541/* psrlq imm8 to r64 */
542void PSRLQItoR(int to, u8 from);
543
544/* paddusb r64 to r64 */
545void PADDUSBRtoR(int to, int from);
546/* paddusb m64 to r64 */
547void PADDUSBMtoR(int to, u32 from);
548/* paddusw r64 to r64 */
549void PADDUSWRtoR(int to, int from);
550/* paddusw m64 to r64 */
551void PADDUSWMtoR(int to, u32 from);
552
553/* paddb r64 to r64 */
554void PADDBRtoR(int to, int from);
555/* paddb m64 to r64 */
556void PADDBMtoR(int to, u32 from);
557/* paddw r64 to r64 */
558void PADDWRtoR(int to, int from);
559/* paddw m64 to r64 */
560void PADDWMtoR(int to, u32 from);
561/* paddd r64 to r64 */
562void PADDDRtoR(int to, int from);
563/* paddd m64 to r64 */
564void PADDDMtoR(int to, u32 from);
565
566/* emms */
567void EMMS();
568void FEMMS();
569void BT32ItoR(int to,int from);
570void RCR32ItoR(int to,int from);
571
572//Basara:changed
573void PADDSBRtoR(int to, int from);
574void PADDSWRtoR(int to, int from);
575void PADDSDRtoR(int to, int from);
576void PSUBSBRtoR(int to, int from);
577void PSUBSWRtoR(int to, int from);
578void PSUBSDRtoR(int to, int from);
579
580void PSUBBRtoR(int to, int from);
581void PSUBWRtoR(int to, int from);
582void PSUBDRtoR(int to, int from);
583
584void MOVQ64ItoR(int reg,u64 i); //Prototype.Todo add all consts to end of block.not after jr $+8
585
586void PMAXSWRtoR(int to,int from);
587void PMINSWRtoR(int to,int from);
588
589void PCMPEQBRtoR(int to,int from);
590void PCMPEQWRtoR(int to,int from);
591void PCMPEQDRtoR(int to,int from);
592
593void PCMPGTBRtoR(int to,int from);
594void PCMPGTWRtoR(int to,int from);
595void PCMPGTDRtoR(int to,int from);
596
597void PSRLWItoR(int to,int from);
598void PSRLDItoR(int to,int from);
599void PSLLWItoR(int to,int from);
600void PSLLDItoR(int to,int from);
601void PSRAWItoR(int to,int from);
602void PSRADItoR(int to,int from);
603
604//Added:basara 11.01.2003
605void FCOMP32(u32 from);
606void FNSTSWtoAX();
607void SETNZ8R(int to);
608
609//Added:basara 14.01.2003
610void PFCMPEQMtoR(int to,int from);
611void PFCMPGTMtoR(int to,int from);
612void PFCMPGEMtoR(int to,int from);
613
614void PFADDMtoR(int to,int from);
615void PFADDRtoR(int to,int from);
616
617void PFSUBMtoR(int to,int from);
618void PFSUBRtoR(int to,int from);
619
620void PFMULMtoR(int to,int from);
621void PFMULRtoR(int to,int from);
622
623void PFRCPMtoR(int to,int from);
624void PFRCPRtoR(int to,int from);
625void PFRCPIT1RtoR(int to,int from);
626void PFRCPIT2RtoR(int to,int from);
627
628void PFRSQRTRtoR(int to,int from);
629void PFRSQIT1RtoR(int to,int from);
630
631void PF2IDMtoR(int to,int from);
632void PF2IDRtoR(int to,int from);
633void PI2FDMtoR(int to,int from);
634void PI2FDRtoR(int to,int from);
635
636void PFMAXMtoR(int to,int from);
637void PFMAXRtoR(int to,int from);
638void PFMINMtoR(int to,int from);
639void PFMINRtoR(int to,int from);
640
641void MOVDMtoR(int to, u32 from);
642void MOVDRtoM(u32 to, int from);
643void MOVD32RtoR(int to, int from);
644void MOVD64RtoR(int to, int from);
645
646void MOVQRtoR(int to,int from);
647
648//if to==from MMLO=MMHI
649void PUNPCKHDQRtoR(int to,int from);
650
651//if to==from MMHI=MMLO
652void PUNPCKLDQRtoR(int to,int from);
653
654/*
655 SSE intructions
656*/
657void MOVAPSMtoR(int to,int from);
658void MOVAPSRtoM(int to,int from);
659void MOVAPSRtoR(int to,int from);
660
661void ORPSMtoR(int to,int from);
662void ORPSRtoR(int to,int from);
663
664void XORPSMtoR(int to,int from);
665void XORPSRtoR(int to,int from);
666
667void ANDPSMtoR(int to,int from);
668void ANDPSRtoR(int to,int from);
669
670#ifdef __cplusplus
671}
672#endif
673#endif