⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ppc_dec.c

📁 SkyEye是一个可以运行嵌入式操作系统的硬件仿真工具
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *	PearPC *	ppc_dec.cc * *	Copyright (C) 2003, 2004 Sebastian Biallas (sb@biallas.net) *	Portions Copyright (C) 2004 Daniel Foesch (dfoesch@cs.nmsu.edu) *	Portions Copyright (C) 2004 Apple Computer, Inc. * *	This program is free software; you can redistribute it and/or modify *	it under the terms of the GNU General Public License version 2 as *	published by the Free Software Foundation. * *	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 for more details. * *	You should have received a copy of the GNU General Public License *	along with this program; if not, write to the Free Software *	Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *//*#include "cstring"#include "system/types.h"#include "cpu/debug.h"#include "cpu/cpu.h"*/#include <stdio.h>#include "types.h"#include "tracers.h"#include "ppc_alu.h"#include "ppc_cpu.h"#include "ppc_dec.h"#include "ppc_exc.h"#include "ppc_fpu.h"#include "ppc_vec.h"#include "ppc_mmu.h"#include "ppc_opc.h"//#include "io/prom/promosi.h"static void ppc_opc_invalid(){	/* FIXME by Michael.Kang	if (gCPU.pc == gPromOSIEntry && gCPU.current_opc == PROM_MAGIC_OPCODE) {		call_prom_osi();		return;	}*/	if (gCPU.current_opc == 0x00333301) {		// memset(r3, r4, r5)		uint32 dest = gCPU.gpr[3];		uint32 c = gCPU.gpr[4];		uint32 size = gCPU.gpr[5];		if (dest & 0xfff) {			byte *dst;			ppc_direct_effective_memory_handle(dest, dst);			uint32 a = 4096 - (dest & 0xfff);			memset(dst, c, a);			size -= a;			dest += a;		}		while (size >= 4096) {			byte *dst;			ppc_direct_effective_memory_handle(dest, dst);			memset(dst, c, 4096);			dest += 4096;			size -= 4096;		}		if (size) {			byte *dst;			ppc_direct_effective_memory_handle(dest, dst);			memset(dst, c, size);		}		gCPU.pc = gCPU.npc;		return;	}	if (gCPU.current_opc == 0x00333302) {		// memcpy		uint32 dest = gCPU.gpr[3];		uint32 src = gCPU.gpr[4];		uint32 size = gCPU.gpr[5];		byte *d, *s;		ppc_direct_effective_memory_handle(dest, d);		ppc_direct_effective_memory_handle(src, s);		while (size--) {			if (!(dest & 0xfff)) ppc_direct_effective_memory_handle(dest, d);			if (!(src & 0xfff)) ppc_direct_effective_memory_handle(src, s);			*d = *s;			src++; dest++; d++; s++;		}		gCPU.pc = gCPU.npc;		return;	}	fprintf(stderr, "[PPC/DEC] Bad opcode: %08x (%u:%u)\n",		gCPU.current_opc, PPC_OPC_MAIN(gCPU.current_opc),		PPC_OPC_EXT(gCPU.current_opc));	fprintf(stderr, "pc=0x%x\n",gCPU.pc);	skyeye_exit(-1);	//SINGLESTEP("unknown instruction\n");}// main opcode 19static void ppc_opc_group_1(){	uint32 ext = PPC_OPC_EXT(gCPU.current_opc);	//printf("DBG:in %s,before exec pc=0x%x,opc=0x%x,ext=0x%x\n", __FUNCTION__, gCPU.pc, gCPU.current_opc, ext);	if (ext & 1) {		// crxxx		if (ext <= 225) {			switch (ext) {				case 33: ppc_opc_crnor(); return;				case 129: ppc_opc_crandc(); return;				case 193: ppc_opc_crxor(); return;				case 225: ppc_opc_crnand(); return;			}		} else {			switch (ext) {				case 257: ppc_opc_crand(); return;				case 289: ppc_opc_creqv(); return;				case 417: ppc_opc_crorc(); return;				case 449: ppc_opc_cror(); return;			}		}	} else if (ext & (1<<9)) {		// bcctrx		if (ext == 528) {			ppc_opc_bcctrx(); 			return;		}	} else {		switch (ext) {			case 16: ppc_opc_bclrx(); return;			case 0: ppc_opc_mcrf(); return;			case 50: ppc_opc_rfi(); return;			case 150: ppc_opc_isync(); return;		}	}	ppc_opc_invalid();}ppc_opc_function ppc_opc_table_group2[1015];//ppc_opc_function * ppc_opc_table_group2;// main opcode 31static void ppc_opc_init_group2(){	uint i;	//ppc_opc_table_group2 = (ppc_opc_function *)malloc(sizeof(ppc_opc_function) * 1015);	for (i=0; i<(sizeof ppc_opc_table_group2 / sizeof ppc_opc_table_group2[0]); i++) {		ppc_opc_table_group2[i] = ppc_opc_invalid;	}	ppc_opc_table_group2[0] = ppc_opc_cmp;	ppc_opc_table_group2[4] = ppc_opc_tw;	ppc_opc_table_group2[8] = ppc_opc_subfcx;//+	ppc_opc_table_group2[10] = ppc_opc_addcx;//+	ppc_opc_table_group2[11] = ppc_opc_mulhwux;	ppc_opc_table_group2[15] = ppc_opc_isel;	ppc_opc_table_group2[19] = ppc_opc_mfcr;	ppc_opc_table_group2[20] = ppc_opc_lwarx;	ppc_opc_table_group2[23] = ppc_opc_lwzx;	ppc_opc_table_group2[24] = ppc_opc_slwx;	ppc_opc_table_group2[26] = ppc_opc_cntlzwx;	ppc_opc_table_group2[28] = ppc_opc_andx;	ppc_opc_table_group2[32] = ppc_opc_cmpl;	ppc_opc_table_group2[40] = ppc_opc_subfx;	ppc_opc_table_group2[47] = ppc_opc_iselgt;	ppc_opc_table_group2[54] = ppc_opc_dcbst;	ppc_opc_table_group2[55] = ppc_opc_lwzux;	ppc_opc_table_group2[60] = ppc_opc_andcx;	ppc_opc_table_group2[75] = ppc_opc_mulhwx;	ppc_opc_table_group2[79] = ppc_opc_iseleq;	ppc_opc_table_group2[83] = ppc_opc_mfmsr;	ppc_opc_table_group2[86] = ppc_opc_dcbf;	ppc_opc_table_group2[87] = ppc_opc_lbzx;	ppc_opc_table_group2[104] = ppc_opc_negx;	ppc_opc_table_group2[119] = ppc_opc_lbzux;	ppc_opc_table_group2[124] = ppc_opc_norx;	ppc_opc_table_group2[131] = ppc_opc_wrtee;	ppc_opc_table_group2[136] = ppc_opc_subfex;//+	ppc_opc_table_group2[138] = ppc_opc_addex;//+	ppc_opc_table_group2[143] = ppc_opc_isel;	ppc_opc_table_group2[144] = ppc_opc_mtcrf;	ppc_opc_table_group2[146] = ppc_opc_mtmsr;	ppc_opc_table_group2[150] = ppc_opc_stwcx_;	ppc_opc_table_group2[151] = ppc_opc_stwx;	ppc_opc_table_group2[163] = ppc_opc_wrteei;	ppc_opc_table_group2[166] = ppc_opc_dcbtls;	ppc_opc_table_group2[183] = ppc_opc_stwux;	ppc_opc_table_group2[200] = ppc_opc_subfzex;//+	ppc_opc_table_group2[202] = ppc_opc_addzex;//+	ppc_opc_table_group2[207] = ppc_opc_isel;	ppc_opc_table_group2[210] = ppc_opc_mtsr;	ppc_opc_table_group2[215] = ppc_opc_stbx;	ppc_opc_table_group2[232] = ppc_opc_subfmex;//+	ppc_opc_table_group2[234] = ppc_opc_addmex;	ppc_opc_table_group2[235] = ppc_opc_mullwx;//+	ppc_opc_table_group2[242] = ppc_opc_mtsrin;	ppc_opc_table_group2[246] = ppc_opc_dcbtst;	ppc_opc_table_group2[247] = ppc_opc_stbux;	ppc_opc_table_group2[266] = ppc_opc_addx;//+	ppc_opc_table_group2[278] = ppc_opc_dcbt;	ppc_opc_table_group2[279] = ppc_opc_lhzx;	ppc_opc_table_group2[284] = ppc_opc_eqvx;	ppc_opc_table_group2[306] = ppc_opc_tlbie;	ppc_opc_table_group2[310] = ppc_opc_eciwx;	ppc_opc_table_group2[311] = ppc_opc_lhzux;	ppc_opc_table_group2[316] = ppc_opc_xorx;	ppc_opc_table_group2[339] = ppc_opc_mfspr;	ppc_opc_table_group2[343] = ppc_opc_lhax;	ppc_opc_table_group2[335] = ppc_opc_isel;	ppc_opc_table_group2[370] = ppc_opc_tlbia;	ppc_opc_table_group2[371] = ppc_opc_mftb;	ppc_opc_table_group2[375] = ppc_opc_lhaux;	ppc_opc_table_group2[407] = ppc_opc_sthx;	ppc_opc_table_group2[412] = ppc_opc_orcx;	ppc_opc_table_group2[438] = ppc_opc_ecowx;	ppc_opc_table_group2[439] = ppc_opc_sthux;	ppc_opc_table_group2[444] = ppc_opc_orx;	ppc_opc_table_group2[459] = ppc_opc_divwux;//+	ppc_opc_table_group2[463] = ppc_opc_isel;	ppc_opc_table_group2[467] = ppc_opc_mtspr;	ppc_opc_table_group2[470] = ppc_opc_dcbi;	ppc_opc_table_group2[476] = ppc_opc_nandx;	ppc_opc_table_group2[491] = ppc_opc_divwx;//+	ppc_opc_table_group2[512] = ppc_opc_mcrxr;	ppc_opc_table_group2[533] = ppc_opc_lswx;	ppc_opc_table_group2[534] = ppc_opc_lwbrx;	ppc_opc_table_group2[535] = ppc_opc_lfsx;	ppc_opc_table_group2[536] = ppc_opc_srwx;	ppc_opc_table_group2[566] = ppc_opc_tlbsync;	ppc_opc_table_group2[567] = ppc_opc_lfsux;	ppc_opc_table_group2[591] = ppc_opc_isel;	ppc_opc_table_group2[595] = ppc_opc_mfsr;	ppc_opc_table_group2[597] = ppc_opc_lswi;	ppc_opc_table_group2[598] = ppc_opc_sync;	ppc_opc_table_group2[599] = ppc_opc_lfdx;	ppc_opc_table_group2[631] = ppc_opc_lfdux;	ppc_opc_table_group2[659] = ppc_opc_mfsrin;	ppc_opc_table_group2[661] = ppc_opc_stswx;	ppc_opc_table_group2[662] = ppc_opc_stwbrx;	ppc_opc_table_group2[663] = ppc_opc_stfsx;	ppc_opc_table_group2[695] = ppc_opc_stfsux;	ppc_opc_table_group2[725] = ppc_opc_stswi;	ppc_opc_table_group2[727] = ppc_opc_stfdx;	ppc_opc_table_group2[758] = ppc_opc_dcba;	ppc_opc_table_group2[759] = ppc_opc_stfdux;	ppc_opc_table_group2[783] = ppc_opc_isel;	ppc_opc_table_group2[786] = ppc_opc_tlbivax; /* TLB invalidated virtual address indexed */	ppc_opc_table_group2[790] = ppc_opc_lhbrx;	ppc_opc_table_group2[792] = ppc_opc_srawx;	ppc_opc_table_group2[824] = ppc_opc_srawix;	ppc_opc_table_group2[847] = ppc_opc_isel;	ppc_opc_table_group2[854] = ppc_opc_eieio;	ppc_opc_table_group2[911] = ppc_opc_isel;	ppc_opc_table_group2[914] = ppc_opc_tlbsx;	ppc_opc_table_group2[918] = ppc_opc_sthbrx;	ppc_opc_table_group2[922] = ppc_opc_extshx;	ppc_opc_table_group2[946] = ppc_opc_tlbrehi;	ppc_opc_table_group2[954] = ppc_opc_extsbx;	ppc_opc_table_group2[975] = ppc_opc_isel;	ppc_opc_table_group2[943] = ppc_opc_isel;	ppc_opc_table_group2[978] = ppc_opc_tlbwe; /* TLB write entry */	ppc_opc_table_group2[982] = ppc_opc_icbi;	ppc_opc_table_group2[983] = ppc_opc_stfiwx;	ppc_opc_table_group2[1014] = ppc_opc_dcbz;	if ((ppc_cpu_get_pvr(0) & 0xffff0000) == 0x000c0000) {		/* Added for Altivec support */		ppc_opc_table_group2[6] = ppc_opc_lvsl;		ppc_opc_table_group2[7] = ppc_opc_lvebx;		ppc_opc_table_group2[38] = ppc_opc_lvsr;		ppc_opc_table_group2[39] = ppc_opc_lvehx;		ppc_opc_table_group2[71] = ppc_opc_lvewx;		ppc_opc_table_group2[103] = ppc_opc_lvx;		ppc_opc_table_group2[135] = ppc_opc_stvebx;		ppc_opc_table_group2[167] = ppc_opc_stvehx;		ppc_opc_table_group2[199] = ppc_opc_stvewx;		ppc_opc_table_group2[231] = ppc_opc_stvx;		ppc_opc_table_group2[342] = ppc_opc_dst;		ppc_opc_table_group2[359] = ppc_opc_lvxl;		ppc_opc_table_group2[374] = ppc_opc_dstst;		ppc_opc_table_group2[487] = ppc_opc_stvxl;		ppc_opc_table_group2[822] = ppc_opc_dss;	}}// main opcode 31inline static void ppc_opc_group_2(){	uint32 ext = PPC_OPC_EXT(gCPU.current_opc);	/*	if(gCPU.pc >= 0xfff80100 && gCPU.pc < 0xfffff000)                        printf("DBG:before exec pc=0x%x,opc=0x%x,ext=0x%x\n", gCPU.pc, gCPU.current_opc, ext);	*/	if (ext >= (sizeof ppc_opc_table_group2 / sizeof ppc_opc_table_group2[0])) {		ppc_opc_invalid();	}	ppc_opc_table_group2[ext]();}// main opcode 59static void ppc_opc_group_f1(){	if ((gCPU.msr & MSR_FP) == 0) {		ppc_exception(PPC_EXC_NO_FPU,0 ,0);		return;	}	uint32 ext = PPC_OPC_EXT(gCPU.current_opc);	switch (ext & 0x1f) {		case 18: ppc_opc_fdivsx(); return;		case 20: ppc_opc_fsubsx(); return;		case 21: ppc_opc_faddsx(); return;		case 22: ppc_opc_fsqrtsx(); return;		case 24: ppc_opc_fresx(); return;		case 25: ppc_opc_fmulsx(); return;		case 28: ppc_opc_fmsubsx(); return;		case 29: ppc_opc_fmaddsx(); return;		case 30: ppc_opc_fnmsubsx(); return;		case 31: ppc_opc_fnmaddsx(); return;	}	ppc_opc_invalid();

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -