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

📄 cpu.h

📁 浙江大学的悟空嵌入式系统模拟器
💻 H
字号:
/**
 *  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.
 */ 

//=============================================================================
/**
 *
 *  \class PPC_CPU
 *
 *  \brief CPU for PowerPC architecture
 *  
 *  \author  Chenfeng Zhou <ini_autumn@163.com>
 *
 *  file: Processor/PPC/CPU.h
 *
 *  Created    : <2005-02-05 12:23:11 by Cheney Chow>
 *  Last update: <2005-02-09 23:44:56 by Cheney Chow>
 *
 *  $Id: CPU.h,v 1.1 2005/06/16 06:01:44 qilj Exp $
 */
//=============================================================================

#ifndef _PPC_PROCESSOR_H_
#define _PPC_PROCESSOR_H_

#include <stack>

#include "Core/Processor.h"
#include "Core/Datatype.h"

#include "Types.h"
#include "Regfile_Adaptor.h"
#include "MMU.h"


namespace PPC {

    class PPC_Instruction_Set;
    
	//! Two OS supported till now;
	typedef enum {
		OS_UCOS,
		OS_LINUX,
	}Os_Type;

	typedef struct {

		//! what os we're running;
		Os_Type os;

		//! For lwarx/stwcx;
		bool have_reservation;
		Core::u32 reservation;

		//! Number of ops executed
		Core::u32 ops;

		//! Time facility
		Core::u64 ptb;
		Core::u64 pdec;

		//! Enable external exception
		bool enable_ee;
		std::stack<bool> enable_ee_stack;

		bool cpu_stop;
	
	}CPU_State;

    class PPC_CPU : public Core::CPU_32Bit 
	{        
    public:
		/// We'll pass PPC_Instruction_Set
		PPC_CPU (Core::Instruction_Set &, PPC_MMU*);
        virtual ~PPC_CPU ();

        //! Cpu start
        //! virtual `run'
        virtual void run ();

		virtual bool set_pc (PPC_Address_T val) { pc_= val; return true;}

        //! Get pc counter
        virtual PPC_Address_T get_pc () {return pc_;}

		//! Get npc counter
		PPC_Address_T get_npc () {return npc_;}

		//! Set npc counter
		void set_npc (PPC_Address_T npc) {npc_ = npc;}

        //! Get register;
        PPC_Register &get_register (int index);

		Regfile_Adaptor & get_regfile () { return reg_file_adaptor_;}
        
		//! Get CPU state;
		CPU_State &get_cpu_state() { return cpu_state_;}

		PPC_Instr_T get_current_instr() { return current_instr_; }

		//! Discard useless dummy mmu;
		void switch_mmu () { mmu_ = new MMU();}

		Os_Type os_type () {return cpu_state_.os;}

    private:
        //! Init cpu, including register, pc, etc
        int init_cpu ();

        //! Init register file contained in base class `Processor'
        int init_reg_file ();

        void init_pc_npc ();
        
		void init_cpu_state ();

		//! handle externel exceptions;
		void post_routine ();

        virtual PPC_Instr_T fetch_instruction(PPC_Address_T pc);

		Core::Instruction_Set &get_instr_set () {return instr_set_;}
        
        //! Implement the damned pure virtual functions
        //! currently nothing will be done
		virtual void on_interrupt (Core::Interrupt_Type) {}

        virtual void on_prefetch_exception () {}

        virtual void on_memory_exception () {}

        virtual void on_undefined_instruction (PPC_Instr_T) {}

        virtual void install_coprocessor () {}

		virtual void on_create(void);

		virtual void step_info() {}

		virtual void con() {}

		virtual Core::s32 insert_breakpoint(Core::Debugger::Breakpoint_Type btype,Core::u32 addr, size_t len)
		{return 0;}

		virtual Core::s32 remove_breakpoint(Core::Debugger::Breakpoint_Type btype, Core::u32 addr, size_t len) 
		{return 0;}

		virtual void on_destroy(void) {}
		virtual void on_reset() {set_pc(0);}

		//! handle ucos instructions enable/disable external exception;
		//! Return value:
		//! true: external handled;
		//! false: no ee instructions;
		bool ucos_ee_handler ();

    private:
        Regfile_Adaptor reg_file_adaptor_;
        
        PPC_Instr_T current_instr_;
        PPC_Address_T pc_;
        PPC_Address_T npc_;
        
        CPU_State cpu_state_;
    };

    #include "CPU_i.h"
    
} //namespace PPC

#endif  // _PPC_PROCESSOR_H_

⌨️ 快捷键说明

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