| 
									
										
										
										
											2009-04-01 20:22:43 +00:00
										 |  |  | // Copyright (C) 2003-2009 Dolphin Project.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // This program is free software: you can redistribute it and/or modify
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by
 | 
					
						
							|  |  |  | // the Free Software Foundation, version 2.0.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
					
						
							|  |  |  | // GNU General Public License 2.0 for more details.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // A copy of the GPL 2.0 should have been included with the program.
 | 
					
						
							|  |  |  | // If not, see http://www.gnu.org/licenses/
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Official SVN repository and contact information can be found at
 | 
					
						
							|  |  |  | // http://code.google.com/p/dolphin-emu/
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Additional copyrights go to Duddie (c) 2005 (duddie@walla.com)
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef _DSPTABLES_H
 | 
					
						
							|  |  |  | #define _DSPTABLES_H
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-01 20:57:20 +00:00
										 |  |  | #include "Common.h"
 | 
					
						
							| 
									
										
										
										
											2009-04-05 11:55:18 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-18 11:31:37 +00:00
										 |  |  | // The non-ADDR ones that end with _D are the opposite one - if the bit specify
 | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | // ACC0, then ACC_D will be ACC1.
 | 
					
						
							| 
									
										
										
										
											2009-04-14 20:44:03 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | // The values of these are very important.
 | 
					
						
							|  |  |  | // For the reg ones, the value >> 8 is the base register.
 | 
					
						
							|  |  |  | // & 0x80  means it's a "D".
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | enum partype_t | 
					
						
							| 
									
										
										
										
											2009-04-01 20:22:43 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-03 09:14:52 +00:00
										 |  |  | 	P_NONE		= 0x0000, | 
					
						
							| 
									
										
										
										
											2009-04-18 11:31:37 +00:00
										 |  |  | 	P_VAL       = 0x0001, | 
					
						
							| 
									
										
										
										
											2009-04-03 09:14:52 +00:00
										 |  |  | 	P_IMM		= 0x0002, | 
					
						
							|  |  |  | 	P_MEM		= 0x0003, | 
					
						
							|  |  |  | 	P_STR		= 0x0004, | 
					
						
							| 
									
										
										
										
											2009-04-18 11:31:37 +00:00
										 |  |  | 	P_ADDR_I	= 0x0005, | 
					
						
							|  |  |  | 	P_ADDR_D	= 0x0006, | 
					
						
							| 
									
										
										
										
											2009-04-03 09:14:52 +00:00
										 |  |  | 	P_REG		= 0x8000, | 
					
						
							| 
									
										
										
										
											2009-04-16 16:02:54 +00:00
										 |  |  | 	P_REG04     = P_REG | 0x0400, // IX
 | 
					
						
							|  |  |  | 	P_REG08		= P_REG | 0x0800,  | 
					
						
							| 
									
										
										
										
											2009-04-03 09:14:52 +00:00
										 |  |  | 	P_REG18		= P_REG | 0x1800, | 
					
						
							|  |  |  | 	P_REGM18	= P_REG | 0x1810, // used in multiply instructions
 | 
					
						
							|  |  |  | 	P_REG19		= P_REG | 0x1900, | 
					
						
							|  |  |  | 	P_REGM19	= P_REG | 0x1910, // used in multiply instructions
 | 
					
						
							| 
									
										
										
										
											2009-04-14 20:44:03 +00:00
										 |  |  | 	P_REG1A		= P_REG | 0x1a80, | 
					
						
							| 
									
										
										
										
											2009-04-03 09:14:52 +00:00
										 |  |  | 	P_REG1C		= P_REG | 0x1c00, | 
					
						
							|  |  |  | //	P_ACC		= P_REG | 0x1c10, // used for global accum (gcdsptool's value)
 | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | 	P_ACC_D		= P_REG | 0x1c80, | 
					
						
							| 
									
										
										
										
											2009-04-14 20:44:03 +00:00
										 |  |  | 	P_ACCL		= P_REG | 0x1c00, // used for low part of accum
 | 
					
						
							|  |  |  | 	P_ACCM		= P_REG | 0x1e00, // used for mid part of accum
 | 
					
						
							| 
									
										
										
										
											2009-04-03 09:14:52 +00:00
										 |  |  | 	// The following are not in gcdsptool
 | 
					
						
							|  |  |  | 	P_ACCM_D	= P_REG | 0x1e80, | 
					
						
							| 
									
										
										
										
											2009-04-14 20:44:03 +00:00
										 |  |  | 	P_ACC		= P_REG | 0x2000, // used for full accum.
 | 
					
						
							| 
									
										
										
										
											2009-04-03 09:14:52 +00:00
										 |  |  | 	P_AX		= P_REG | 0x2200, | 
					
						
							|  |  |  | 	P_REGS_MASK	= 0x03f80, // gcdsptool's value = 0x01f80
 | 
					
						
							| 
									
										
										
										
											2009-04-01 20:22:43 +00:00
										 |  |  | 	P_REF       = P_REG | 0x4000, | 
					
						
							|  |  |  | 	P_PRG       = P_REF | P_REG, | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	// The following seem like junk:
 | 
					
						
							|  |  |  | 	//	P_REG10		= P_REG | 0x1000,
 | 
					
						
							|  |  |  | 	//	P_AX_D		= P_REG | 0x2280,
 | 
					
						
							| 
									
										
										
										
											2009-04-01 20:22:43 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #define P_EXT   0x80
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-01 22:41:16 +00:00
										 |  |  | #define OPTABLE_SIZE 65536
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-01 20:22:43 +00:00
										 |  |  | union UDSPInstruction | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u16 hex; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	UDSPInstruction(u16 _hex)	{ hex = _hex; } | 
					
						
							|  |  |  | 	UDSPInstruction()	        { hex = 0; } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	struct | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		signed shift        : 6; | 
					
						
							|  |  |  | 		unsigned negating   : 1; | 
					
						
							|  |  |  | 		unsigned arithmetic : 1; | 
					
						
							|  |  |  | 		unsigned areg       : 1; | 
					
						
							|  |  |  | 		unsigned op         : 7; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 	struct | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		unsigned ushift     : 6; | 
					
						
							|  |  |  | 	}; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-01 21:30:09 +00:00
										 |  |  | 	// TODO: Figure out more instruction structures (add structs here)
 | 
					
						
							| 
									
										
										
										
											2009-04-01 20:22:43 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-01 21:30:09 +00:00
										 |  |  | typedef void (*dspInstFunc)(const UDSPInstruction&); | 
					
						
							| 
									
										
										
										
											2009-04-01 20:22:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | struct param2_t | 
					
						
							| 
									
										
										
										
											2009-04-01 20:22:43 +00:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | 	partype_t type; | 
					
						
							| 
									
										
										
										
											2009-04-01 20:22:43 +00:00
										 |  |  | 	u8 size; | 
					
						
							|  |  |  | 	u8 loc; | 
					
						
							|  |  |  | 	s8 lshift; | 
					
						
							|  |  |  | 	u16 mask; | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2009-04-01 20:22:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-01 22:03:52 +00:00
										 |  |  | typedef struct | 
					
						
							| 
									
										
										
										
											2009-04-01 20:22:43 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	const char *name; | 
					
						
							|  |  |  | 	u16 opcode; | 
					
						
							|  |  |  | 	u16 opcode_mask; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	dspInstFunc interpFunc; | 
					
						
							|  |  |  | 	dspInstFunc jitFunc; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	u8 size; | 
					
						
							|  |  |  | 	u8 param_count; | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | 	param2_t params[8]; | 
					
						
							| 
									
										
										
										
											2009-04-02 17:45:18 +00:00
										 |  |  | 	dspInstFunc prologue; | 
					
						
							|  |  |  | 	dspInstFunc epilogue; | 
					
						
							| 
									
										
										
										
											2009-04-01 22:03:52 +00:00
										 |  |  | } DSPOPCTemplate; | 
					
						
							| 
									
										
										
										
											2009-04-01 20:22:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | typedef DSPOPCTemplate opc_t; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | // Opcodes
 | 
					
						
							|  |  |  | extern const DSPOPCTemplate opcodes[]; | 
					
						
							| 
									
										
										
										
											2009-04-14 22:30:31 +00:00
										 |  |  | extern const int opcodes_size; | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | extern const DSPOPCTemplate opcodes_ext[]; | 
					
						
							| 
									
										
										
										
											2009-04-14 22:30:31 +00:00
										 |  |  | extern const int opcodes_ext_size; | 
					
						
							| 
									
										
										
										
											2009-04-05 17:29:06 +00:00
										 |  |  | extern u8 opSize[OPTABLE_SIZE]; | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | extern const DSPOPCTemplate cw; | 
					
						
							| 
									
										
										
										
											2009-04-01 20:22:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-01 22:41:16 +00:00
										 |  |  | extern dspInstFunc opTable[]; | 
					
						
							| 
									
										
										
										
											2009-04-08 20:26:33 +00:00
										 |  |  | extern dspInstFunc prologueTable[OPTABLE_SIZE]; | 
					
						
							|  |  |  | extern dspInstFunc epilogueTable[OPTABLE_SIZE]; | 
					
						
							| 
									
										
										
										
											2009-04-01 22:41:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-12 10:21:40 +00:00
										 |  |  | // Predefined labels
 | 
					
						
							|  |  |  | struct pdlabel_t | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	u16 addr; | 
					
						
							|  |  |  | 	const char* name; | 
					
						
							|  |  |  | 	const char* description; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | extern const pdlabel_t regnames[]; | 
					
						
							|  |  |  | extern const pdlabel_t pdlabels[]; | 
					
						
							|  |  |  | extern const u32 pdlabels_size; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const char *pdname(u16 val); | 
					
						
							|  |  |  | const char *pdregname(int val); | 
					
						
							|  |  |  | const char *pdregnamelong(int val); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-01 20:22:43 +00:00
										 |  |  | void InitInstructionTable(); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-08 20:26:33 +00:00
										 |  |  | inline void ExecuteInstruction(const UDSPInstruction& inst) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	// TODO: Move the prologuetable calls into the relevant instructions themselves.
 | 
					
						
							|  |  |  | 	// Better not do things like this until things work correctly though.
 | 
					
						
							|  |  |  | 	if (prologueTable[inst.hex]) | 
					
						
							|  |  |  | 		prologueTable[inst.hex](inst); | 
					
						
							|  |  |  | 	opTable[inst.hex](inst); | 
					
						
							|  |  |  | 	if (epilogueTable[inst.hex]) | 
					
						
							|  |  |  | 		epilogueTable[inst.hex](inst); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2009-04-01 20:22:43 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-06 18:47:21 +00:00
										 |  |  | // This one's pretty slow, try to use it only at init or seldomly.
 | 
					
						
							|  |  |  | // returns NULL if no matching instruction.
 | 
					
						
							|  |  |  | const DSPOPCTemplate *GetOpTemplate(const UDSPInstruction &inst); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2009-04-01 20:22:43 +00:00
										 |  |  | #endif // _DSPTABLES_H
 |