drc: some PCSX-specific const addr io handlers
[pcsx_rearmed.git] / libpcsxcore / ix86 / ix86.h
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
30 extern "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
100 extern s8  *x86Ptr;
101 extern u8  *j8Ptr[32];
102 extern u32 *j32Ptr[32];
103
104 void x86Init();
105 void x86SetPtr(char *ptr);
106 void x86Shutdown();
107
108 void x86SetJ8(u8 *j8);
109 void x86SetJ32(u32 *j32);
110 void 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 */
130 void MOV32RtoR(int to, int from);
131 /* mov r32 to m32 */
132 void MOV32RtoM(u32 to, int from);
133 /* mov m32 to r32 */
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);
147
148 /* mov r16 to m16 */
149 void MOV16RtoM(u32 to, int from);
150 /* mov m16 to r16 */
151 void MOV16MtoR(int to, u32 from);
152 /* mov imm16 to m16 */
153 void MOV16ItoM(u32 to, u16 from);
154
155 /* mov r8 to m8 */
156 void MOV8RtoM(u32 to, int from);
157 /* mov m8 to r8 */
158 void MOV8MtoR(int to, u32 from);
159 /* mov imm8 to m8 */
160 void MOV8ItoM(u32 to, u8 from);
161
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);
170
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);
179
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);
204
205 ////////////////////////////////////
206 // arithmetic instructions         /
207 ////////////////////////////////////
208
209 /* add imm32 to r32 */
210 void ADD32ItoR(int to, u32 from);
211 /* add imm32 to m32 */
212 void ADD32ItoM(u32 to, u32 from);
213 /* add r32 to r32 */
214 void ADD32RtoR(int to, int from);
215 /* add r32 to m32 */
216 void ADD32RtoM(u32 to, int from);
217 /* add m32 to r32 */
218 void ADD32MtoR(int to, u32 from);
219
220 /* adc imm32 to r32 */
221 void ADC32ItoR(int to, u32 from);
222 /* adc r32 to r32 */
223 void ADC32RtoR(int to, int from);
224 /* adc m32 to r32 */
225 void ADC32MtoR(int to, u32 from);
226
227 /* inc r32 */
228 void INC32R(int to);
229 /* inc m32 */
230 void INC32M(u32 to);
231
232 /* sub imm32 to r32 */
233 void SUB32ItoR(int to, u32 from);
234 /* sub r32 to r32 */
235 void SUB32RtoR(int to, int from);
236 /* sub m32 to r32 */
237 void SUB32MtoR(int to, u32 from);
238
239 /* sbb imm32 to r32 */
240 void SBB32ItoR(int to, u32 from);
241 /* sbb r32 to r32 */
242 void SBB32RtoR(int to, int from);
243 /* sbb m32 to r32 */
244 void SBB32MtoR(int to, u32 from);
245
246 /* dec r32 */
247 void DEC32R(int to);
248 /* dec m32 */
249 void DEC32M(u32 to);
250
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);
255
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);
262
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);
267
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);
272
273 ////////////////////////////////////
274 // shifting instructions           /
275 ////////////////////////////////////
276
277 /* shl imm8 to r32 */
278 void SHL32ItoR(int to, u8 from);
279 /* shl cl to r32 */
280 void SHL32CLtoR(int to);
281
282 /* shr imm8 to r32 */
283 void SHR32ItoR(int to, u8 from);
284 /* shr cl to r32 */
285 void SHR32CLtoR(int to);
286
287 /* sar imm8 to r32 */
288 void SAR32ItoR(int to, u8 from);
289 /* sar cl to r32 */
290 void 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 */
300 void OR32ItoR(int to, u32 from);
301 /* or imm32 to m32 */
302 void OR32ItoM(u32 to, u32 from);
303 /* or r32 to r32 */
304 void OR32RtoR(int to, int from);
305 /* or r32 to m32 */
306 void OR32RtoM(u32 to, int from);
307 /* or m32 to r32 */
308 void OR32MtoR(int to, u32 from);
309
310 /* xor imm32 to r32 */
311 void XOR32ItoR(int to, u32 from);
312 /* xor imm32 to m32 */
313 void XOR32ItoM(u32 to, u32 from);
314 /* xor r32 to r32 */
315 void XOR32RtoR(int to, int from);
316 /* xor r32 to m32 */
317 void XOR32RtoM(u32 to, int from);
318 /* xor m32 to r32 */
319 void XOR32MtoR(int to, u32 from);
320
321 /* and imm32 to r32 */
322 void AND32ItoR(int to, u32 from);
323 /* and imm32 to m32 */
324 void AND32ItoM(u32 to, u32 from);
325 /* and r32 to r32 */
326 void AND32RtoR(int to, int from);
327 /* and r32 to m32 */
328 void AND32RtoM(u32 to, int from);
329 /* and m32 to r32 */
330 void AND32MtoR(int to, u32 from);
331
332 /* not r32 */
333 void NOT32R(int from);
334 /* neg r32 */
335 void NEG32R(int from);
336
337 ////////////////////////////////////
338 // jump instructions               /
339 ////////////////////////////////////
340
341 /* jmp rel8 */
342 u8*  JMP8(u8 to);
343
344 /* jmp rel32 */
345 u32* JMP32(u32 to);
346 /* jmp r32 */
347 void JMP32R(int to);
348
349 /* je rel8 */
350 u8*  JE8(u8 to);
351 /* jz rel8 */
352 u8*  JZ8(u8 to);
353 /* jg rel8 */
354 u8*  JG8(u8 to);
355 /* jge rel8 */
356 u8*  JGE8(u8 to);
357 /* jl rel8 */
358 u8*  JL8(u8 to);
359 /* jle rel8 */
360 u8*  JLE8(u8 to);
361 /* jne rel8 */
362 u8*  JNE8(u8 to);
363 /* jnz rel8 */
364 u8*  JNZ8(u8 to);
365 /* jng rel8 */
366 u8*  JNG8(u8 to);
367 /* jnge rel8 */
368 u8*  JNGE8(u8 to);
369 /* jnl rel8 */
370 u8*  JNL8(u8 to);
371 /* jnle rel8 */
372 u8*  JNLE8(u8 to);
373 /* jo rel8 */
374 u8*  JO8(u8 to);
375 /* jno rel8 */
376 u8*  JNO8(u8 to);
377
378 /* je rel32 */
379 u32* JE32(u32 to);
380 /* jz rel32 */
381 u32* JZ32(u32 to);
382 /* jg rel32 */
383 u32* JG32(u32 to);
384 /* jge rel32 */
385 u32* JGE32(u32 to);
386 /* jl rel32 */
387 u32* JL32(u32 to);
388 /* jle rel32 */
389 u32* JLE32(u32 to);
390 /* jne rel32 */
391 u32* JNE32(u32 to);
392 /* jnz rel32 */
393 u32* JNZ32(u32 to);
394 /* jng rel32 */
395 u32* JNG32(u32 to);
396 /* jnge rel32 */
397 u32* JNGE32(u32 to);
398 /* jnl rel32 */
399 u32* JNL32(u32 to);
400 /* jnle rel32 */
401 u32* JNLE32(u32 to);
402 /* jo rel32 */
403 u32* JO32(u32 to);
404 /* jno rel32 */
405 u32* JNO32(u32 to);
406
407 /* call func */
408 void CALLFunc(u32 func); // based on CALL32
409 /* call rel32 */
410 void CALL32(u32 to);
411 /* call r32 */
412 void CALL32R(int to);
413 /* call m32 */
414 void CALL32M(u32 to);
415
416 ////////////////////////////////////
417 // misc instructions               /
418 ////////////////////////////////////
419
420 /* cmp imm32 to r32 */
421 void CMP32ItoR(int to, u32 from);
422 /* cmp imm32 to m32 */
423 void CMP32ItoM(u32 to, u32 from);
424 /* cmp r32 to r32 */
425 void CMP32RtoR(int to, int from);
426 /* cmp m32 to r32 */
427 void CMP32MtoR(int to, u32 from);
428
429 /* test imm32 to r32 */
430 void TEST32ItoR(int to, u32 from);
431 /* test r32 to r32 */
432 void TEST32RtoR(int to, int from);
433 /* sets r8 */
434 void SETS8R(int to);
435 /* setl r8 */
436 void SETL8R(int to);
437 /* setb r8 */
438 void SETB8R(int to);
439
440 /* cbw */
441 void CBW();
442 /* cwd */
443 void CWD();
444 /* cdq */
445 void CDQ();
446
447 /* push r32 */
448 void PUSH32R(int from);
449 /* push m32 */
450 void PUSH32M(u32 from);
451 /* push imm32 */
452 void PUSH32I(u32 from);
453
454 /* pop r32 */
455 void POP32R(int from);
456
457 /* pushad */
458 void PUSHA32();
459 /* popad */
460 void POPA32();
461
462 /* ret */
463 void RET();
464
465 /********************/
466 /* FPU instructions */
467 /********************/
468
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 */
476 void FSTP32(u32 to);
477
478 /* fldcw fpu control word from m16 */
479 void FLDCW(u32 from);
480 /* fstcw fpu control word to m16 */
481 void FNSTCW(u32 to);
482
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 */
492 void FABS();
493 /* fsqrt fpu reg stack */
494 void FSQRT();
495 /* fchs fpu reg stack */
496 void FCHS();
497
498 /********************/
499 /* MMX instructions */
500 /********************/
501
502 // r64 = mm
503
504 /* movq m64 to r64 */
505 void MOVQMtoR(int to, u32 from);
506 /* movq r64 to m64 */
507 void MOVQRtoM(u32 to, int from);
508
509 /* pand r64 to r64 */
510 void PANDRtoR(int to, int from);
511 /* pand m64 to r64 */
512 void PANDMtoR(int to, u32 from);
513
514 /* pandn r64 to r64 */
515 void PANDNRtoR(int to, int from);
516
517 /* pandn r64 to r64 */
518 void PANDNMtoR(int to, u32 from);
519
520 /* por r64 to r64 */
521 void PORRtoR(int to, int from);
522 /* por m64 to r64 */
523 void PORMtoR(int to, u32 from);
524
525 /* pxor r64 to r64 */
526 void PXORRtoR(int to, int from);
527 /* pxor m64 to r64 */
528 void PXORMtoR(int to, u32 from);
529
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);
536
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);
543
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);
552
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);
565
566 /* emms */
567 void EMMS();
568 void FEMMS();
569 void BT32ItoR(int to,int from);
570 void RCR32ItoR(int to,int from);
571
572 //Basara:changed
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);
579
580 void PSUBBRtoR(int to, int from);
581 void PSUBWRtoR(int to, int from);
582 void PSUBDRtoR(int to, int from);
583
584 void MOVQ64ItoR(int reg,u64 i); //Prototype.Todo add all consts to end of block.not after jr $+8
585
586 void PMAXSWRtoR(int to,int from);
587 void PMINSWRtoR(int to,int from);
588
589 void PCMPEQBRtoR(int to,int from);
590 void PCMPEQWRtoR(int to,int from);
591 void PCMPEQDRtoR(int to,int from);
592
593 void PCMPGTBRtoR(int to,int from);
594 void PCMPGTWRtoR(int to,int from);
595 void PCMPGTDRtoR(int to,int from);
596
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);
603
604 //Added:basara 11.01.2003
605 void FCOMP32(u32 from);
606 void FNSTSWtoAX();
607 void SETNZ8R(int to);
608
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);
613
614 void PFADDMtoR(int to,int from);
615 void PFADDRtoR(int to,int from);
616
617 void PFSUBMtoR(int to,int from);
618 void PFSUBRtoR(int to,int from);
619
620 void PFMULMtoR(int to,int from);
621 void PFMULRtoR(int to,int from);
622
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);
627
628 void PFRSQRTRtoR(int to,int from);
629 void PFRSQIT1RtoR(int to,int from);
630
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);
635
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);
640
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);
645
646 void MOVQRtoR(int to,int from);
647
648 //if to==from MMLO=MMHI
649 void PUNPCKHDQRtoR(int to,int from);
650
651 //if to==from MMHI=MMLO
652 void PUNPCKLDQRtoR(int to,int from);
653
654 /*
655         SSE     intructions 
656 */
657 void MOVAPSMtoR(int to,int from);
658 void MOVAPSRtoM(int to,int from);
659 void MOVAPSRtoR(int to,int from);
660
661 void ORPSMtoR(int to,int from);
662 void ORPSRtoR(int to,int from);
663
664 void XORPSMtoR(int to,int from);
665 void XORPSRtoR(int to,int from);
666
667 void ANDPSMtoR(int to,int from);
668 void ANDPSRtoR(int to,int from);
669
670 #ifdef __cplusplus
671 }
672 #endif
673 #endif