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

📄 op.c.svn-base

📁 我们自己开发的一个OSEK操作系统!不知道可不可以?
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
/* *  CRIS emulation micro-operations for qemu. * *  Copyright (c) 2007 Edgar E. Iglesias, Axis Communications AB. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */#include "exec.h"#include "host-utils.h"#define REGNAME r0#define REG (env->regs[0])#include "op_template.h"#define REGNAME r1#define REG (env->regs[1])#include "op_template.h"#define REGNAME r2#define REG (env->regs[2])#include "op_template.h"#define REGNAME r3#define REG (env->regs[3])#include "op_template.h"#define REGNAME r4#define REG (env->regs[4])#include "op_template.h"#define REGNAME r5#define REG (env->regs[5])#include "op_template.h"#define REGNAME r6#define REG (env->regs[6])#include "op_template.h"#define REGNAME r7#define REG (env->regs[7])#include "op_template.h"#define REGNAME r8#define REG (env->regs[8])#include "op_template.h"#define REGNAME r9#define REG (env->regs[9])#include "op_template.h"#define REGNAME r10#define REG (env->regs[10])#include "op_template.h"#define REGNAME r11#define REG (env->regs[11])#include "op_template.h"#define REGNAME r12#define REG (env->regs[12])#include "op_template.h"#define REGNAME r13#define REG (env->regs[13])#include "op_template.h"#define REGNAME r14#define REG (env->regs[14])#include "op_template.h"#define REGNAME r15#define REG (env->regs[15])#include "op_template.h"#define REGNAME p0#define REG (env->pregs[0])#include "op_template.h"#define REGNAME p1#define REG (env->pregs[1])#include "op_template.h"#define REGNAME p2#define REG (env->pregs[2])#include "op_template.h"#define REGNAME p3#define REG (env->pregs[3])#include "op_template.h"#define REGNAME p4#define REG (env->pregs[4])#include "op_template.h"#define REGNAME p5#define REG (env->pregs[5])#include "op_template.h"#define REGNAME p6#define REG (env->pregs[6])#include "op_template.h"#define REGNAME p7#define REG (env->pregs[7])#include "op_template.h"#define REGNAME p8#define REG (env->pregs[8])#include "op_template.h"#define REGNAME p9#define REG (env->pregs[9])#include "op_template.h"#define REGNAME p10#define REG (env->pregs[10])#include "op_template.h"#define REGNAME p11#define REG (env->pregs[11])#include "op_template.h"#define REGNAME p12#define REG (env->pregs[12])#include "op_template.h"#define REGNAME p13#define REG (env->pregs[13])#include "op_template.h"#define REGNAME p14#define REG (env->pregs[14])#include "op_template.h"#define REGNAME p15#define REG (env->pregs[15])#include "op_template.h"/* Microcode.  */void OPPROTO op_exit_tb (void){	EXIT_TB();}void OPPROTO op_goto_tb0 (void){	GOTO_TB(op_goto_tb0, PARAM1, 0);	RETURN();}void OPPROTO op_goto_tb1 (void){	GOTO_TB(op_goto_tb1, PARAM1, 1);	RETURN();}void OPPROTO op_break_im(void){	env->trapnr = PARAM1;	env->exception_index = EXCP_BREAK;	cpu_loop_exit();}void OPPROTO op_debug(void){	env->exception_index = EXCP_DEBUG;	cpu_loop_exit();}void OPPROTO op_exec_insn(void){	env->stats.exec_insns++;	RETURN();}void OPPROTO op_exec_load(void){	env->stats.exec_loads++;	RETURN();}void OPPROTO op_exec_store(void){	env->stats.exec_stores++;	RETURN();}void OPPROTO op_ccs_lshift (void){	uint32_t ccs;	/* Apply the ccs shift.  */	ccs = env->pregs[SR_CCS];	ccs = (ccs & 0xc0000000) | ((ccs << 12) >> 2);	env->pregs[SR_CCS] = ccs;}void OPPROTO op_ccs_rshift (void){	uint32_t ccs;	/* Apply the ccs shift.  */	ccs = env->pregs[SR_CCS];	ccs = (ccs & 0xc0000000) | (ccs >> 10);	env->pregs[SR_CCS] = ccs;}void OPPROTO op_setf (void){	env->pregs[SR_CCS] |= PARAM1;	RETURN();}void OPPROTO op_clrf (void){	env->pregs[SR_CCS] &= ~PARAM1;	RETURN();}void OPPROTO op_movl_debug1_T0 (void){	env->debug1 = T0;	RETURN();}void OPPROTO op_movl_debug2_T0 (void){	env->debug2 = T0;	RETURN();}void OPPROTO op_movl_debug3_T0 (void){	env->debug3 = T0;	RETURN();}void OPPROTO op_movl_debug1_T1 (void){	env->debug1 = T1;	RETURN();}void OPPROTO op_movl_debug2_T1 (void){	env->debug2 = T1;	RETURN();}void OPPROTO op_movl_debug3_T1 (void){	env->debug3 = T1;	RETURN();}void OPPROTO op_movl_debug3_im (void){	env->debug3 = PARAM1;	RETURN();}void OPPROTO op_movl_T0_flags (void){	T0 = env->pregs[SR_CCS];	RETURN();}void OPPROTO op_movl_flags_T0 (void){	env->pregs[SR_CCS] = T0;	RETURN();}void OPPROTO op_movl_sreg_T0 (void){	env->sregs[env->pregs[SR_SRS]][PARAM1] = T0;	RETURN();}void OPPROTO op_movl_tlb_lo_T0 (void){	int srs;	srs = env->pregs[SR_SRS];	if (srs == 1 || srs == 2)	{		int set;		int idx;		uint32_t lo, hi;		idx = set = env->sregs[SFR_RW_MM_TLB_SEL];		set >>= 4;		set &= 3;		idx &= 31;		/* We've just made a write to tlb_lo.  */		lo = env->sregs[SFR_RW_MM_TLB_LO];		hi = env->sregs[SFR_RW_MM_TLB_HI];		env->tlbsets[srs - 1][set][idx].lo = lo;		env->tlbsets[srs - 1][set][idx].hi = hi;	}	RETURN();}void OPPROTO op_movl_T0_sreg (void){	T0 = env->sregs[env->pregs[SR_SRS]][PARAM1];	RETURN();}void OPPROTO op_update_cc (void){	env->cc_op = PARAM1;	env->cc_dest = PARAM2;	env->cc_src = PARAM3;	RETURN();}void OPPROTO op_update_cc_op (void){	env->cc_op = PARAM1;	RETURN();}void OPPROTO op_update_cc_mask (void){	env->cc_mask = PARAM1;	RETURN();}void OPPROTO op_update_cc_dest_T0 (void){	env->cc_dest = T0;	RETURN();}void OPPROTO op_update_cc_result_T0 (void){	env->cc_result = T0;	RETURN();}void OPPROTO op_update_cc_size_im (void){	env->cc_size = PARAM1;	RETURN();}void OPPROTO op_update_cc_src_T1 (void){	env->cc_src = T1;	RETURN();}void OPPROTO op_update_cc_x (void){	env->cc_x_live = PARAM1;	env->cc_x = PARAM2;	RETURN();}/* FIXME: is this allowed?  */extern inline void evaluate_flags_writeback(uint32_t flags){	int x;	/* Extended arithmetics, leave the z flag alone.  */	env->debug3 = env->pregs[SR_CCS];	if (env->cc_x_live)		x = env->cc_x;	else		x = env->pregs[SR_CCS] & X_FLAG;	if ((x || env->cc_op == CC_OP_ADDC)	    && flags & Z_FLAG)		env->cc_mask &= ~Z_FLAG;	/* all insn clear the x-flag except setf or clrf.  */	env->pregs[SR_CCS] &= ~(env->cc_mask | X_FLAG);	flags &= env->cc_mask;	env->pregs[SR_CCS] |= flags;	RETURN();}void OPPROTO op_evaluate_flags_muls(void){	uint32_t src;	uint32_t dst;	uint32_t res;	uint32_t flags = 0;	/* were gonna have to redo the muls.  */	int64_t tmp, t0 ,t1;	int32_t mof;	int dneg;	src = env->cc_src;	dst = env->cc_dest;	res = env->cc_result;	/* cast into signed values to make GCC sign extend.  */	t0 = (int32_t)src;	t1 = (int32_t)dst;	dneg = ((int32_t)res) < 0;	tmp = t0 * t1;	mof = tmp >> 32;	if (tmp == 0)		flags |= Z_FLAG;	else if (tmp < 0)		flags |= N_FLAG;	if ((dneg && mof != -1)	    || (!dneg && mof != 0))		flags |= V_FLAG;	evaluate_flags_writeback(flags);	RETURN();}void OPPROTO op_evaluate_flags_mulu(void){	uint32_t src;	uint32_t dst;	uint32_t res;	uint32_t flags = 0;	/* were gonna have to redo the muls.  */	uint64_t tmp, t0 ,t1;	uint32_t mof;	src = env->cc_src;	dst = env->cc_dest;	res = env->cc_result;	/* cast into signed values to make GCC sign extend.  */	t0 = src;	t1 = dst;	tmp = t0 * t1;	mof = tmp >> 32;	if (tmp == 0)		flags |= Z_FLAG;	else if (tmp >> 63)		flags |= N_FLAG;	if (mof)		flags |= V_FLAG;	evaluate_flags_writeback(flags);	RETURN();}void OPPROTO op_evaluate_flags_mcp(void){	uint32_t src;	uint32_t dst;	uint32_t res;	uint32_t flags = 0;	src = env->cc_src;	dst = env->cc_dest;	res = env->cc_result;	if ((res & 0x80000000L) != 0L)	{		flags |= N_FLAG;		if (((src & 0x80000000L) == 0L)		    && ((dst & 0x80000000L) == 0L))		{			flags |= V_FLAG;		}		else if (((src & 0x80000000L) != 0L) &&			 ((dst & 0x80000000L) != 0L))		{			flags |= R_FLAG;		}	}	else	{		if (res == 0L)			flags |= Z_FLAG;		if (((src & 0x80000000L) != 0L)		    && ((dst & 0x80000000L) != 0L))			flags |= V_FLAG;		if ((dst & 0x80000000L) != 0L		    || (src & 0x80000000L) != 0L)			flags |= R_FLAG;	}	evaluate_flags_writeback(flags);	RETURN();}void OPPROTO op_evaluate_flags_alu_4(void){	uint32_t src;	uint32_t dst;	uint32_t res;	uint32_t flags = 0;	src = env->cc_src;	dst = env->cc_dest;	res = env->cc_result;	if ((res & 0x80000000L) != 0L)	{		flags |= N_FLAG;		if (((src & 0x80000000L) == 0L)		    && ((dst & 0x80000000L) == 0L))		{			flags |= V_FLAG;		}		else if (((src & 0x80000000L) != 0L) &&			 ((dst & 0x80000000L) != 0L))		{			flags |= C_FLAG;		}	}	else	{		if (res == 0L)			flags |= Z_FLAG;		if (((src & 0x80000000L) != 0L)		    && ((dst & 0x80000000L) != 0L))			flags |= V_FLAG;		if ((dst & 0x80000000L) != 0L		    || (src & 0x80000000L) != 0L)			flags |= C_FLAG;	}	if (env->cc_op == CC_OP_SUB	    || env->cc_op == CC_OP_CMP) {		flags ^= C_FLAG;	}	evaluate_flags_writeback(flags);	RETURN();}void OPPROTO op_evaluate_flags_move_4 (void){	uint32_t src;	uint32_t res;	uint32_t flags = 0;	src = env->cc_src;	res = env->cc_result;	if ((int32_t)res < 0)		flags |= N_FLAG;	else if (res == 0L)		flags |= Z_FLAG;	evaluate_flags_writeback(flags);	RETURN();}void OPPROTO op_evaluate_flags_move_2 (void){	uint32_t src;	uint32_t flags = 0;	uint16_t res;	src = env->cc_src;	res = env->cc_result;	if ((int16_t)res < 0L)		flags |= N_FLAG;	else if (res == 0)		flags |= Z_FLAG;	evaluate_flags_writeback(flags);	RETURN();}/* TODO: This is expensive. We could split things up and only evaluate part of   CCR on a need to know basis. For now, we simply re-evaluate everything.  */void OPPROTO op_evaluate_flags (void){	uint32_t src;	uint32_t dst;	uint32_t res;	uint32_t flags = 0;	src = env->cc_src;	dst = env->cc_dest;	res = env->cc_result;	/* Now, evaluate the flags. This stuff is based on	   Per Zander's CRISv10 simulator.  */	switch (env->cc_size)	{		case 1:			if ((res & 0x80L) != 0L)			{				flags |= N_FLAG;				if (((src & 0x80L) == 0L)				    && ((dst & 0x80L) == 0L))				{					flags |= V_FLAG;				}				else if (((src & 0x80L) != 0L)					 && ((dst & 0x80L) != 0L))				{					flags |= C_FLAG;				}			}			else			{				if ((res & 0xFFL) == 0L)				{					flags |= Z_FLAG;				}				if (((src & 0x80L) != 0L)				    && ((dst & 0x80L) != 0L))				{					flags |= V_FLAG;				}				if ((dst & 0x80L) != 0L				    || (src & 0x80L) != 0L)				{					flags |= C_FLAG;				}			}			break;		case 2:			if ((res & 0x8000L) != 0L)			{				flags |= N_FLAG;				if (((src & 0x8000L) == 0L)				    && ((dst & 0x8000L) == 0L))				{					flags |= V_FLAG;				}				else if (((src & 0x8000L) != 0L)					 && ((dst & 0x8000L) != 0L))				{					flags |= C_FLAG;				}			}

⌨️ 快捷键说明

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