diff --git a/cpu.c b/cpu.c index f8e03d9..f84901e 100644 --- a/cpu.c +++ b/cpu.c @@ -4,6 +4,10 @@ #include #include +/* Known errors: + * 1) Exec does the calculations on the first clock cycle, there is a bug where in some cases exec isn't run on the last cycle and because of this the CPU still works. + */ + struct fetch_data_t *malloc_fetch_data(){ struct fetch_data_t *ret=malloc(sizeof(struct fetch_data_t)); @@ -606,44 +610,54 @@ int cpu_cycle_clock(struct simdata_t *simdata){ free_instr_list(&simdata->cpu_gui_hints->fetching_list); free_instr_list(&simdata->cpu_gui_hints->decoding_list); free_instr_list(&simdata->cpu_gui_hints->executing_list); - switch(exec(simdata)){ - case 0: break; - case 2: return 4; - default: return 1; + switch(simdata->cpu_structure){ + case CPU_STRUCTURE_SIMPLE_PIPELINED: + switch(exec(simdata)){ + case 0: break; + case 2: return 4; + default: return 1; + } + switch(decode(simdata)){ + case 0: break; + default: return 2; + } + switch(fetch(simdata)){ + case 0: break; + default: return 3; + } + break; + case CPU_STRUCTURE_SIMPLE_NON_PIPELINED: + switch(state){ + case 0: + switch(fetch(simdata)){ + case 0: break; + default: return 3; + } + break; + case 1: + switch(decode(simdata)){ + case 0: break; + default: return 2; + } + break; + case 2: + switch(exec(simdata)){ + case 0: break; + case 2: return 4; + default: return 1; + } + break; + } + if(state==2){ + if(simdata->decode_data->exec_done) + state=0; + }else + state++; + break; + default: + return 4; + } - switch(decode(simdata)){ - case 0: break; - default: return 2; - } - switch(fetch(simdata)){ - case 0: break; - default: return 3; - } -// switch(state){ -// case 0: -// switch(fetch(simdata)){ -// case 0: break; -// default: return 3; -// } -// break; -// case 1: -// switch(decode(simdata)){ -// case 0: break; -// default: return 2; -// } -// break; -// case 2: -// switch(exec(simdata)){ -// case 0: break; -// case 2: return 4; -// default: return 1; -// } -// break; -// } -// if(state==2) -// state=0; -// else -// state++; simdata->current_clock++; return 0; } diff --git a/main.c b/main.c index bbb0ae2..689560b 100644 --- a/main.c +++ b/main.c @@ -42,6 +42,8 @@ void help(char* progname){ " braille\n" #endif " -o < file > Output simualtion data to specified json log file\n" + " -S < cpu structure > Select the structure of the cpu. You can choose one\n" + " of the following: simple, pipelined\n" , progname); } @@ -62,9 +64,13 @@ int main(int argc, char* argd[] ){ char *assemble = NULL; enum FB_DRIVER_t fb_driver=FB_BRAILLE; int opt; + char *json_log_filename=NULL; FILE *JSON_LOG_FILE; - while ((opt = getopt(argc, argd, "hi:a:r:o:")) != -1) { + + char *structure="pipelined"; + + while ((opt = getopt(argc, argd, "hi:a:r:o:S:")) != -1) { switch (opt) { case 'h': help(argd[0]); @@ -94,6 +100,9 @@ int main(int argc, char* argd[] ){ case 'o': json_log_filename=optarg; break; + case 'S': + structure=optarg; + break; default: help(argd[0]); return 1; @@ -110,6 +119,7 @@ int main(int argc, char* argd[] ){ help(argd[0]); return 1; } + if (json_log_filename){ JSON_LOG_FILE=fopen(json_log_filename,"w"); if(JSON_LOG_FILE==NULL){ @@ -133,6 +143,19 @@ int main(int argc, char* argd[] ){ return 1; } + if(strcmp("simple",structure)==0){ + simdata->cpu_structure=CPU_STRUCTURE_SIMPLE_NON_PIPELINED; + }else if(strcmp("pipelined",structure)==0){ + simdata->cpu_structure=CPU_STRUCTURE_SIMPLE_PIPELINED; + }else{ + printf("Invalid cpu structure \"%s\"\n",structure); + fclose(rom); + free_simdata(simdata); + return 1; + } + + + if ( assemble != NULL ){ /* RUN ASSEMBLER */ struct assembler_context_t *assembler_context=malloc_assembler_context(); diff --git a/simdata.c b/simdata.c index b964e81..b34a011 100644 --- a/simdata.c +++ b/simdata.c @@ -46,7 +46,6 @@ struct simdata_t *init_simdata(){ ret->cpu_gui_hints->executing_list=NULL; ret->terminal_output=malloc(0); ret->terminal_output_size=0; - ret->cpu_structure=CPU_STRUCTURE_SIMPLE_PIPELINED; return ret; }