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

📄 cr_logical_instruction.cpp

📁 浙江大学的悟空嵌入式系统模拟器
💻 CPP
字号:
/* -*- C++ -*- */

/**
*  Copyright (c) 2005 Zhejiang University, P.R.China
*
*  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; either version 2 of the License, or
*  (at your option) any later version.
*
*  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.
*/

///==================================================
/**
* @file        CR_Logical_Instruction.cpp
* @brief       Conditional instruction manipulation
*
* @author      Chenfeng Zhou <ini_autumn@163.com> 
*
* Created    : <2005-02-12 11:09:48 by Cheney Chow>
* Last update: <2005-03-08 19:59:45 by Cheney Chow>
*
* $Id: CR_Logical_Instruction.cpp,v 1.1 2005/06/16 06:01:44 qilj Exp $
*/
///==================================================

#include "Instruction.h"
#include "Instr_Declare.h"
#include "Utils/Debug.h"
#include "Exception.h"
#include "Register.h"
#include "Reg_Utils.h"
#include "Parser.h"

namespace PPC 
{
	//! The crA that parsed out of instr is from left to right;
	inline bool CR_BIT_SET(PPC_s32 crA)
	{
		return REG_BIT_IS_SET(CR, 31 - crA);
	}

	PPC_INSTRUCTION_IMPL(op_crand)
	{
		PPC_s32 crD, crA, crB;
		X_Form_Parser::parse_x(instr, crD, crA, crB);

		PPC_TRACE_3("crand", crD, crA, crB);

		if (CR_BIT_SET(crA) && CR_BIT_SET(crB))
			REG_SET_BIT(CR, (31 - crD));
		else
			REG_CLEAR_BIT(CR, (31 - crD));
	}

	PPC_INSTRUCTION_IMPL(op_crandc)
	{
		PPC_s32 crD, crA, crB;
		X_Form_Parser::parse_x(instr, crD, crA, crB);

		PPC_TRACE_3("crandc", crD, crA, crB);

		if (CR_BIT_SET(crA) && !CR_BIT_SET(crB))
			REG_SET_BIT(CR, (31 - crD));
		else
			REG_CLEAR_BIT(CR, (31 - crD));
	}

	PPC_INSTRUCTION_IMPL(op_creqv)
	{
		PPC_s32 crD, crA, crB;
		X_Form_Parser::parse_x(instr, crD, crA, crB);
		PPC_TRACE_3("creqv", crD, crA, crB);

		if ((CR_BIT_SET(crA) && CR_BIT_SET(crB))
			|| (!CR_BIT_SET(crA) && !CR_BIT_SET(crB)))
			REG_SET_BIT(CR, (31 - crD));
		else
			REG_CLEAR_BIT(CR, (31 - crD));	
	}

	PPC_INSTRUCTION_IMPL(op_crnand)
	{
		PPC_s32 crD, crA, crB;
		X_Form_Parser::parse_x(instr, crD, crA, crB);

		PPC_TRACE_3("crnand", crD, crA, crB);

		if (!(CR_BIT_SET(crA) && CR_BIT_SET(crB)))
			REG_SET_BIT(CR, (31 - crD));
		else
			REG_CLEAR_BIT(CR, (31 - crD));
	}

	PPC_INSTRUCTION_IMPL(op_crnor)
	{
		PPC_s32 crD, crA, crB;
		X_Form_Parser::parse_x(instr, crD, crA, crB);

		PPC_TRACE_3("crnor", crD, crA, crB);

		PPC_u32 t = (1<<(31-crA)) | (1<<(31-crB));

		if ( !(REG_TO_INT(REG(CR)) & t) )
			REG_SET_BIT(CR, (31 - crD));
		else
			REG_CLEAR_BIT(CR, (31 - crD));
	}

	PPC_INSTRUCTION_IMPL(op_cror)
	{
		PPC_s32 crD, crA, crB;
		X_Form_Parser::parse_x(instr, crD, crA, crB);

		PPC_TRACE_3("cror", crD, crA, crB);

		PPC_u32 t = (1<<(31-crA)) | (1<<(31-crB));

		if ( REG_TO_INT(REG(CR)) & t )
			REG_SET_BIT(CR, (31 - crD));
		else
			REG_CLEAR_BIT(CR, (31 - crD));
	}

	PPC_INSTRUCTION_IMPL(op_crorc)
	{
		PPC_s32 crD, crA, crB;
		X_Form_Parser::parse_x(instr, crD, crA, crB);
		PPC_TRACE_3("crorc", crD, crA, crB);

		if ( CR_BIT_SET(crA) || !CR_BIT_SET(crB))
			REG_SET_BIT(CR, (31 - crD));
		else
			REG_CLEAR_BIT(CR, (31 - crD));
	}

	PPC_INSTRUCTION_IMPL(op_crxor)
	{
		PPC_s32 crD, crA, crB;
		X_Form_Parser::parse_x(instr, crD, crA, crB);
		PPC_TRACE_3("crxor", crD, crA, crB);

		if ((!CR_BIT_SET(crA) && CR_BIT_SET(crB))
			|| (CR_BIT_SET(crA) && !CR_BIT_SET(crB)))
			REG_SET_BIT(CR, (31 - crD));
		else
			REG_CLEAR_BIT(CR, (31 - crD));
	}

	static PPC_u32 MASK_TABLE[8] = {
			0xfffffff0,
			0xffffff0f,
			0xfffff0ff,
			0xffff0fff,
			0xfff0ffff,
			0xff0fffff,
			0xf0ffffff,
			0x0fffffff,
	};

	PPC_INSTRUCTION_IMPL(op_mcrf)
	{
		//PPC_ERROR(("mcrf not implented!\n"));
		PPC_s32 crD, crS, zero;
		X_Form_Parser::parse_x(instr, crD, crS, zero);

		PPC_TRACE_2("mcrf", crD, crS);

		crD >>= 2;
		crS >>= 2;

		crD = 7 - crD;
		crS = 7 - crS;

		PPC_u32 c = (REG_TO_INT(REG(CR)) >> (crS * 4)) & 0xf;
		PPC_u32 mask = MASK_TABLE[crD];

		REG(CR).convert_from_int(REG_TO_INT(REG(CR)) & mask);
		REG(CR).convert_from_int(REG_TO_INT(REG(CR)) | (c << (crD * 4)));
	}

} //namespace PPC

⌨️ 快捷键说明

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