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

📄 core.c

📁 32cpu的代码
💻 C
📖 第 1 页 / 共 2 页
字号:
#include <stdio.h>
#include "cpu.h"
   void  instruction_fetch();
   void  instruction_decode();
   void  instruction_execute();
   void  memory_access();
   void  write_back();
   void  decode_pre();
   void check_cp0_reg(); 

void  core(){
            if(wp_stop == 0){
         	 write_back();
         	    Random=Random + 1;
         	    Random=Random&(0x0000000f);
         	    CPR[1]=Random;
         	// printf("pc_address_wp=0x%08x\n",pc_address_wp);
              }else{
                 wp_stop=wp_stop-1;
         	    Random=Random + 1;
         	    Random=Random&(0x0000000f);
         	    CPR[1]=Random;
               }
                 check_cp0_reg();
            if(dp_stop == 0){
         	 decode_pre();
         	// printf("pc_address_dp   decode pre=0x%08x  0x%08x\n",pc_address_dp,instruction_dp);
              }else{
                 decode_pre();
                 opa_dp=0;
                 opb_dp=0;
                 load_store_flag_dp=0;
                 result_regnum_dp=0;
                 write_trace_flag_dp=0;
                 instruction_type_dp=0;
                 normal_instr_num_ep=0;
                 special_instr_num_dp=0;
                 special2_instr_num_dp=0;
                 cp0_co_instr_num_dp=0;
                 regimm_instr_num_dp=0;
                 cp0_instr_num_dp=0;
                // nullify_flag_dp=0;
                 branch_address_offset_dp=0;
               } 
                 
            if(mp_stop == 0){
            	trap_flag_mp=trap_flag_ep;
            	trap_flag=trap_flag_mp;
            //    result_first_wp=result_first_mp;
	//	result_first_mp=result_first_ep;
          //      result_second_wp=result_second_mp;
	//	result_second_mp=result_second_ep;            	
            	
         	 memory_access();
         	    Random=Random + 1;
         	    Random=Random&(0x0000000f);
         	    CPR[1]=Random;
         	 //printf("pc_address_mp=0x%08x 0x%08x\n",pc_address_mp,instruction_mp);
              }else{
                 mp_stop=mp_stop-1;
         	    Random=Random + 1;
         	    Random=Random&(0x0000000f);
         	    CPR[1]=Random;
               }

 

               
            if(ep_stop == 0){

         	 instruction_execute();
         	    Random=Random + 1;
         	    Random=Random&(0x0000000f);
         	    CPR[1]=Random;
         	 //printf("pc_address_ep=0x%08x 0x%08x\n",pc_address_ep,instruction_ep);
              }else{
                 ep_stop=ep_stop-1;
         	    Random=Random + 1;
         	    Random=Random&(0x0000000f);
         	    CPR[1]=Random;
               }
               check_cp0_reg();

               
            if(dp_stop == 0){
         	 instruction_decode(); 
         	    Random=Random + 1;
         	    Random=Random&(0x0000000f);
         	    CPR[1]=Random;
         	 //printf("pc_address_dp=0x%08x 0x%08x\n",pc_address_dp,instruction_dp); 
              }else{
                 dp_stop=dp_stop-1;
         	    Random=Random + 1;
         	    Random=Random&(0x0000000f);
         	    CPR[1]=Random;
               }

	      
	        check_cp0_reg();
            if(ip_stop == 0){
            	  exception_flag=exception_flag_mp;
            	  exception_flag_mp=exception_flag_ep;
            	  exception_flag_ep=exception_flag_dp;
            	  exception_flag_dp=exception_flag_ip;
              instruction_op=instruction_wp;
	      instruction_wp=instruction_mp;
	      instruction_mp=instruction_ep;
	      instruction_ep=instruction_dp;
         	  instruction_fetch();
         	    Random=Random + 1;
         	    Random=Random&(0x0000000f);
         	    CPR[1]=Random;
         	 // printf("pc_address_ip=0x%08x\n",pc_address_ip);
              }else{
                  exception_flag=exception_flag_mp;
                  exception_flag_mp=exception_flag_ep;
            	  exception_flag_ep=exception_flag_dp;
            	  exception_flag_dp=exception_flag_ip;
              instruction_op=instruction_wp;
	      instruction_wp=instruction_mp;
	      instruction_mp=instruction_ep;
	      instruction_ep=instruction_dp;    
                  instruction_dp=0x00000000;
		    pc_wp=pc_mp;
	            pc_mp=pc_ep;
	            pc_ep=pc_dp;
	           // pc_dp=pc_ip;
	            pc_address_op=pc_address_wp;
	            pc_address_wp=pc_address_mp;
	            pc_address_mp=pc_address_ep;
	            pc_address_ep=pc_address_dp;
	           // pc_address_dp=pc_address_ip;
                  ip_stop=ip_stop - 1;
         	    Random=Random + 1;
         	    Random=Random&(0x0000000f);
         	    CPR[1]=Random;
               }
               
/*       old pipeline        
             write_back(); 
             memory_access();
           instruction_fetch();
              decode_pre();
              instruction_execute();
            instruction_decode(); */ 
	
}



void memory_access(){
/////////////////////////////Memory Access//////////////////////////
   long  old_value;
if(exception_invalid_instr_flag == 0){
	                
                                    if(result_regnum_mp==500){
                                        	switch(cp0_co_instr_num_mp)
                                        	{case 1:break;
                                        	 case 2: printf("cpr[10]=%08x\n",CPR[10]);
                                        	         Entryhi=CPR[10];
                                        	         Entrylo0=CPR[2];
                                        	         Entrylo1=CPR[3];
                                        	         Index=CPR[0];
                                        	         Random=CPR[1];
                                        	         mmu_machine_check(2);  //tlbwi 
                                        	         break;
                                        	 case 6: Entryhi=CPR[10];
                                        	         Entrylo0=CPR[2];
                                        	         Entrylo1=CPR[3];
                                        	         Index=CPR[0];
                                        	         Random=CPR[1];
                                        	         mmu_machine_check(6);  //tlbwr 
                                        	         break;
                                        	 case 8: break;
                                        	 default:printf("tlb instruction error in write back!\n");
                                        	         exception_flag_mp=18;
                                        		}
	                                        }

       if(load_store_flag_mp && (nullify_flag_mp == 0)){
		switch(normal_instr_num_mp)
		{
		  case  32 :// printf(" lb  \n");
		                   result_first_ep=dcache((unsigned long)opa_mp,opb_mp,1,0);
		                   #ifdef DEBUG
		                   printf("______result_first_ep=%08x",result_first_ep);
		                   #endif
		                   result_second_mp=0;
		                   if(exception_flag_mp == 25){
		                   	exception_flag_mp=24;
		                    ErrorEPC=pc_address_mp;
		                    EPC=pc_address_mp;
		                    CPR[30]=pc_address_mp;
		                    CPR[14]=pc_address_mp;
		                }
		                   if(exception_flag_mp == 30){
		                   	exception_flag_mp=29;
		                    ErrorEPC=pc_address_mp;
		                    EPC=pc_address_mp;
		                    CPR[30]=pc_address_mp;
		                    CPR[14]=pc_address_mp;
		                   	}
		                   break;

⌨️ 快捷键说明

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