📄 pc.c
字号:
#include <stdio.h>
#include "cpu.h"
extern void reg_initialize();
void instruction_fetch(){
int i;
char temp_end;
///////////////////////////Instruction fetch//////////////////
//printf("pc_address_wp=%x\n",pc_address_wp);
//printf("pc_address_mp=%x\n",pc_address_mp);
//printf("pc_address_ep=%x\n",pc_address_ep);
//printf("pc_address_dp=%x\n",pc_address_dp);
//printf("pc_address_ip=%x\n",pc_address_ip);
// pc=pc_next;
if(pc_ip==-1){
pc_wp=pc_mp;
pc_mp=pc_ep;
pc_ep=pc_dp;
pc_dp=0;
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=0xbfc00000;
}else{
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;
}
branch_flag=branch_flag_ep;
//judge Interrupt happen
//judge IM,IE,EXL,ERL in Suatus register and judge
if(Reset == 1){
Reset=0;
//exception_flag_ip=1;
exception_flag=1;
reg_initialize();
}
if(Soft_reset == 1){
Soft_reset=0;
//exception_flag_ip=1;
exception_flag=2;
//reg_initialize();
}
if(NMI == 1){
NMI=0;
//exception_flag_ip=1;
exception_flag=5;
//reg_initialize();
}
if(((Cause>>8)&(0x00000001) == 1) && ((Status&(0x00000107)) == 0x00000101)){
//Soft Interrupt
exception_flag_ip=7;
}
if(((Cause>>9)&(0x00000001) == 1) && ((Status&(0x00000207)) == 0x00000201)){
//Soft Interrupt
exception_flag_ip=7;
}
if((Interrupt0 == 1) && ((Status&(0x00000407)) == 0x00000401)){
//Hard Interrupt
Cause=Cause|(0x00000400);
CPR[13]=Cause;
exception_flag_ip=7;
}
if((Interrupt1 == 1) && ((Status&(0x00000807)) == 0x00000801)){
//Hard Interrupt
Cause=Cause|(0x00000800);
CPR[13]=Cause;
exception_flag_ip=7;
}
if((Interrupt2 == 1) && ((Status&(0x00001007)) == 0x00001001)){
//Hard Interrupt
Cause=Cause|(0x00001000);
CPR[13]=Cause;
exception_flag_ip=7;
}
if((Interrupt3 == 1) && ((Status&(0x00002007)) == 0x00002001)){
//Hard Interrupt
Cause=Cause|(0x00002000);
CPR[13]=Cause;
exception_flag_ip=7;
}
if((Interrupt4 == 1) && ((Status&(0x00004007)) == 0x00004001)){
//Hard Interrupt
Cause=Cause|(0x00004000);
CPR[13]=Cause;
exception_flag_ip=7;
}
if((Interrupt5 == 1) && ((Status&(0x00008007)) == 0x00008001)){
//Hard Interrupt
Cause=Cause|(0x00008000);
CPR[13]=Cause;
exception_flag_ip=7;
}
if((exception_flag)||(trap_flag)){
printf("exception \n");
printf("exception_flag=%08x\n",exception_flag);
exception_answer();
// for(i=0;i<32;i++){
// instruction_wp=instruction_mp;
// instruction_mp=instruction_ep;
// instruction_ep=instruction_dp;
// }
// pc_ip=pc_ip+1;
}else if(branch_flag){
printf("branch!\n");
//fprintf(reg_trace_fp,"branch !branch_address_offset_ep=0x%08x\n",branch_address_offset_ep);
pc_dp=pc_ip + branch_address_offset_ep-1;
pc_address_dp=pc_address_ip + branch_address_offset_ep*4-4;
pc_ip=pc_ip + branch_address_offset_ep;
pc_address_ip=pc_address_ip + branch_address_offset_ep*4;
branch_flag=0;
if((pc_address_ip&(0xfff00000))==0xbfc00000){
// instruction_dp=(pc_ip==0)? instr_out[pc_ip] : instruction_ip;
// instruction_ip=(pc_ip==0)? instr_out[pc_ip+1] : instr_out[pc_ip];
//printf("branch pc_address_dp=0x%08x pc_address_ip=0x%08x\n",pc_address_dp,pc_address_ip);
//printf("branch_address_offset_dp=0x%08x branch_address_offset_ep=0x%08x\n",branch_address_offset_dp,branch_address_offset_ep);
instruction_dp=(pc_ip==0)? icache(pc_address_ip,0) : icache(pc_address_dp,0);
instruction_ip=(pc_ip==0)? icache(pc_address_ip+4,0) : icache(pc_address_ip,0);
}else if((pc_address_ip&(0xf0000000))==0x90000000){
// instruction_dp=(pc_ip==0)? instr_out_1[pc_ip] : instruction_ip;
// instruction_ip=(pc_ip==0)? instr_out_1[pc_ip+1] : instr_out_1[pc_ip];
instruction_dp=(pc_ip==0)? icache(pc_address_ip,0) : icache(pc_address_dp,0);
instruction_ip=(pc_ip==0)? icache(pc_address_ip+4,0) : icache(pc_address_ip,0);
}else if((pc_address_ip&(0xfff00000))==0x40400000){
instruction_dp=(pc_ip==0)? icache(pc_address_ip,0) : icache(pc_address_dp,0);
instruction_ip=(pc_ip==0)? icache(pc_address_ip+4,0) : icache(pc_address_ip,0);
}else{
instruction_dp=(pc_ip==0)? icache(pc_address_ip,0) : instruction_ip;
instruction_ip=(pc_ip==0)? icache(pc_address_ip+4,0) : icache(pc_address_ip,0);
printf("error,pc not in 0xbfc0 or 0x9000 \n");
}
/* if((pc_address_ip&(0xfff00000))==0xbfc00000){
// instruction_dp=(pc_ip==0)? instr_out[pc_ip] : instr_out[pc_ip];
// instruction_ip=instr_out[pc_ip+1];
instruction_dp=icache(pc_address_ip,0);
instruction_ip=icache(pc_address_ip+4,0);
}else if((pc_address_ip&(0xf0000000))==0x90000000){
// instruction_dp=(pc_ip==0)? instr_out_1[pc_ip] : instr_out_1[pc_ip];
// instruction_ip=instr_out_1[pc_ip+1];
instruction_dp=icache(pc_address_ip,0);
instruction_ip=icache(pc_address_ip+4,0);
}else if((pc_address_ip&(0xfff00000))==0x40400000){
instruction_dp=icache(pc_address_ip,0);
instruction_ip=icache(pc_address_ip+4,0);
}else{
printf("error,pc not in 0xbfc0 or 0x9000 \n");
}
*/
// }
// pc_ip=pc_ip+1;
}else if(jump_flag){
//pc_ip=(jump_address&(0x000fffff))/4; //不准确,需要修改
pc_ip=(jump_address&(0x0000ffff))/4;
pc_address_ip=jump_address;
#ifdef DEBUG
printf("jump_flag=1\n");
printf("jump_address=%x\n",jump_address);
printf("pc_ip=%x,pc_address_ip=%x\n",pc_ip,pc_address_ip);
printf("jump_address=%x,pc_ip=%x,pc_address_ip=%x\n",jump_address,pc_ip,pc_address_wp);
#endif
jump_flag=0;
jump_address=0;
// for(i=0;i<32;i++){
// instruction_wp=instruction_mp;
// instruction_mp=instruction_ep;
// instruction_ep=instruction_dp;
if((pc_address_ip&(0xfff00000))==0xbfc00000){
// instruction_dp=(pc_ip==0)? instr_out[pc_ip] : instruction_ip;
// instruction_ip=(pc_ip==0)? instr_out[pc_ip+1] : instr_out[pc_ip];
instruction_dp=(pc_ip==0)? icache(pc_address_ip,0) : instruction_ip;
instruction_ip=(pc_ip==0)? icache(pc_address_ip+4,0) : icache(pc_address_ip,0);
}else if((pc_address_ip&(0xf0000000))==0x90000000){
// instruction_dp=(pc_ip==0)? instr_out_1[pc_ip] : instruction_ip;
// instruction_ip=(pc_ip==0)? instr_out_1[pc_ip+1] : instr_out_1[pc_ip];
instruction_dp=(pc_ip==0)? icache(pc_address_ip,0) : instruction_ip;
instruction_ip=(pc_ip==0)? icache(pc_address_ip+4,0) : icache(pc_address_ip,0);
}else if((pc_address_ip&(0xfff00000))==0x40400000){
instruction_dp=(pc_ip==0)? icache(pc_address_ip,0) : instruction_ip;
instruction_ip=(pc_ip==0)? icache(pc_address_ip+4,0) : icache(pc_address_ip,0);
}else{
instruction_dp=(pc_ip==0)? icache(pc_address_ip,0) : instruction_ip;
instruction_ip=(pc_ip==0)? icache(pc_address_ip+4,0) : icache(pc_address_ip,0);
printf("error,pc not in 0xbfc0 or 0x9000 \n");
}
// }
}else{
pc_ip=pc_ip+1;
pc_address_ip=pc_address_ip+4;
// for(i=0;i<32;i++){
// instruction_wp=instruction_mp;
// instruction_mp=instruction_ep;
// instruction_ep=instruction_dp;
if((pc_address_ip&(0xfff00000))==0xbfc00000){
// instruction_dp=(pc_ip==0)? instr_out[pc_ip] : instruction_ip;
// instruction_ip=(pc_ip==0)? instr_out[pc_ip+1] : instr_out[pc_ip];
instruction_dp=(pc_ip==0)? icache(pc_address_ip,0) : instruction_ip;
instruction_ip=(pc_ip==0)? icache(pc_address_ip+4,0) : icache(pc_address_ip,0);
}else if((pc_address_ip&(0xf0000000))==0x90000000){
// instruction_dp=(pc_ip==0)? instr_out_1[pc_ip] : instruction_ip;
// instruction_ip=(pc_ip==0)? instr_out_1[pc_ip+1] : instr_out_1[pc_ip];
instruction_dp=(pc_ip==0)? icache(pc_address_ip,0) : instruction_ip;
instruction_ip=(pc_ip==0)? icache(pc_address_ip+4,0) : icache(pc_address_ip,0);
}else if((pc_address_ip&(0xfff00000))==0x40400000){
instruction_dp=(pc_ip==0)? icache(pc_address_ip,0) : instruction_ip;
instruction_ip=(pc_ip==0)? icache(pc_address_ip+4,0) : icache(pc_address_ip,0);
}else{
instruction_dp=(pc_ip==0)? icache(pc_address_ip,0) : instruction_ip;
instruction_ip=(pc_ip==0)? icache(pc_address_ip+4,0) : icache(pc_address_ip,0);
printf("error,pc not in 0xbfc0 or 0x9000 \n");
}
// }
}
if(pc_ip==0){
pc_dp=pc_ip;
pc_ip=pc_ip+1;
pc_address_dp=pc_address_ip;
pc_address_ip=pc_address_ip+4;
}
// for(i=0;i<32;i++){
// printf("%08x\n",instruction_dp);
// }
// printf(" 0x%08x ",pc_address_ip);
printf("\n");
///////////////////////////////////////////////////////////////////////////////
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -