Compare commits

..

No commits in common. "48237ccd9567fb15b7317eccc49783bbb889d8f7" and "3f4b03c30741cfe36c258febf89599b1516d7127" have entirely different histories.

7 changed files with 54 additions and 109 deletions

2
.gitignore vendored
View File

@ -7,5 +7,3 @@ callgrind.out
programs/cube.asm programs/cube.asm
programs/utah_teapot.asm programs/utah_teapot.asm
auxiliary_progs/stl_to_source_code auxiliary_progs/stl_to_source_code
simlog.json

1
cpu.c
View File

@ -581,7 +581,6 @@ int exec(struct simdata_t *simdata){
if(simdata->exec_data->cycles_left==0){ if(simdata->exec_data->cycles_left==0){
simdata->fetch_data->exec_done=1; simdata->fetch_data->exec_done=1;
simdata->decode_data->exec_done=1; simdata->decode_data->exec_done=1;
simdata->finished_instructions++;
} }
add_to_instr_list(&simdata->cpu_gui_hints->executing_list,simdata->exec_data->address); add_to_instr_list(&simdata->cpu_gui_hints->executing_list,simdata->exec_data->address);
return 0; return 0;

View File

@ -14,68 +14,6 @@ void drawbox(WINDOW *win,int x0, int y0, int x1, int y1){
mvwaddch(win,y1, x1, ACS_LRCORNER); mvwaddch(win,y1, x1, ACS_LRCORNER);
} }
struct box_ret_dimensions_t{
int arrow1_y;
};
struct box_ret_dimensions_t* draw_exec(WINDOW *win, int startx,int starty,int endx,int endy,struct exec_data_t* exec_data){
struct box_ret_dimensions_t* box_ret_dimensions=malloc(sizeof(struct box_ret_dimensions_t));
if(!box_ret_dimensions)
return 0;
wattron(win,A_BOLD);
int boxwidth=endx-startx;
drawbox(win,startx,starty,startx+50,endy);
mvwprintw(win,starty,startx+boxwidth/2-8,"[ EXECUTE UNIT ]");
wattroff(win,A_BOLD);
starty+=2;
char *tofree;
mvwprintw(win,starty,startx+boxwidth/2-41/2,"valid=%d EXEC_ACTION=%s",exec_data->valid, (tofree=EXEC_ACTION_t_to_string(exec_data->EXEC_ACTION)) );
free(tofree);
starty+=2;
mvwprintw(win,starty,startx+boxwidth/2-41/2,"ALU_OP=%s ", (tofree=ALU_OP_t_to_string(exec_data->ALU_OP)) );
free(tofree);
mvwprintw(win,starty,startx+boxwidth/2-41/2+20,"cycles_left=%d ", exec_data->cycles_left );
starty+=2;
mvwprintw(win,starty,startx+boxwidth/2-41/2,"COND=%s", (tofree=COND_t_to_string(exec_data->COND)) );
free(tofree);
mvwprintw(win,starty,startx+boxwidth/2-41/2+20,"address=%06X", exec_data->address);
starty+=2;
// Operand boxes
struct exec_op_t *cur;
for(int i=0;i<3;i++){
drawbox(win,startx+boxwidth/2-45/2,starty,startx+boxwidth/2-50/2+45,starty+3);
wattron(win,A_REVERSE);
switch(i){
case 0:
mvwprintw(win,starty,startx+5," Input operand 1 ");
cur=exec_data->in_op1;
break;
case 1:
box_ret_dimensions->arrow1_y=starty;
mvwprintw(win,starty,startx+5," Input operand 2 ");
cur=exec_data->in_op2;
break;
case 2:
mvwprintw(win,starty,startx+5," Output operand ");
cur=exec_data->out_op;
break;
}
wattroff(win,A_REVERSE);
starty+=2;
mvwprintw(win,starty,startx+7,"data=%06X OP_ADDR=%s",cur->data , (tofree=OP_ADDR_t_to_string(cur->OP_ADDR)) );
free(tofree);
starty+=2;
}
return box_ret_dimensions;
}
int update_internals(WINDOW *win,struct simdata_t *simdata){ int update_internals(WINDOW *win,struct simdata_t *simdata){
int width,height; int width,height;
werase(win); werase(win);
@ -156,9 +94,55 @@ int update_internals(WINDOW *win,struct simdata_t *simdata){
starty+=1; starty+=1;
/* EXECUTE BOX */ /* EXECUTE BOX */
struct box_ret_dimensions_t* box_ret_dimensions=draw_exec(win,startx+20+boxwidth/2-50/2,starty,startx+20+boxwidth/2-50/2+50,starty+21,simdata->exec_data); wattron(win,A_BOLD);
exec_arrow_y=box_ret_dimensions->arrow1_y; drawbox(win,startx+20+boxwidth/2-50/2,starty,startx+20+boxwidth/2-50/2+50,starty+21);
free(box_ret_dimensions); mvwprintw(win,starty,startx+20+boxwidth/2-8,"[ EXECUTE UNIT ]");
wattroff(win,A_BOLD);
starty+=2;
char *tofree;
mvwprintw(win,starty,startx+20+boxwidth/2-41/2,"valid=%d EXEC_ACTION=%s",simdata->exec_data->valid, (tofree=EXEC_ACTION_t_to_string(simdata->exec_data->EXEC_ACTION)) );
free(tofree);
starty+=2;
mvwprintw(win,starty,startx+20+boxwidth/2-41/2,"ALU_OP=%s ", (tofree=ALU_OP_t_to_string(simdata->exec_data->ALU_OP)) );
free(tofree);
mvwprintw(win,starty,startx+20+boxwidth/2-41/2+20,"cycles_left=%d ", simdata->exec_data->cycles_left );
starty+=2;
mvwprintw(win,starty,startx+20+boxwidth/2-41/2,"COND=%s", (tofree=COND_t_to_string(simdata->exec_data->COND)) );
free(tofree);
mvwprintw(win,starty,startx+20+boxwidth/2-41/2+20,"address=%06X", simdata->exec_data->address);
starty+=2;
// Operand boxes
struct exec_op_t *cur;
for(int i=0;i<3;i++){
drawbox(win,startx+20+boxwidth/2-45/2,starty,startx+20+boxwidth/2-50/2+45,starty+3);
wattron(win,A_REVERSE);
switch(i){
case 0:
mvwprintw(win,starty,startx+20+5," Input operand 1 ");
cur=simdata->exec_data->in_op1;
break;
case 1:
exec_arrow_y=starty;
mvwprintw(win,starty,startx+20+5," Input operand 2 ");
cur=simdata->exec_data->in_op2;
break;
case 2:
mvwprintw(win,starty,startx+20+5," Output operand ");
cur=simdata->exec_data->out_op;
break;
}
wattroff(win,A_REVERSE);
starty+=2;
mvwprintw(win,starty,startx+20+7,"data=%06X OP_ADDR=%s",cur->data , (tofree=OP_ADDR_t_to_string(cur->OP_ADDR)) );
free(tofree);
starty+=2;
}
/* Wait for exec arrow */ /* Wait for exec arrow */
mvwaddch(win,decode_arrow_exit_y,startx+20+50,ACS_LTEE); mvwaddch(win,decode_arrow_exit_y,startx+20+50,ACS_LTEE);
@ -221,3 +205,4 @@ int update_internals(WINDOW *win,struct simdata_t *simdata){
else else
return 0; return 0;
} }

24
main.c
View File

@ -41,7 +41,6 @@ void help(char* progname){
#else #else
" braille\n" " braille\n"
#endif #endif
" -o < file > Output simualtion data to specified json log file\n"
, progname); , progname);
} }
@ -62,9 +61,7 @@ int main(int argc, char* argd[] ){
char *assemble = NULL; char *assemble = NULL;
enum FB_DRIVER_t fb_driver=FB_BRAILLE; enum FB_DRIVER_t fb_driver=FB_BRAILLE;
int opt; int opt;
char *json_log_filename=NULL; while ((opt = getopt(argc, argd, "hi:a:r:")) != -1) {
FILE *JSON_LOG_FILE;
while ((opt = getopt(argc, argd, "hi:a:r:o:")) != -1) {
switch (opt) { switch (opt) {
case 'h': case 'h':
help(argd[0]); help(argd[0]);
@ -91,9 +88,6 @@ int main(int argc, char* argd[] ){
return 1; return 1;
} }
break; break;
case 'o':
json_log_filename=optarg;
break;
default: default:
help(argd[0]); help(argd[0]);
return 1; return 1;
@ -110,14 +104,6 @@ int main(int argc, char* argd[] ){
help(argd[0]); help(argd[0]);
return 1; return 1;
} }
if (json_log_filename){
JSON_LOG_FILE=fopen(json_log_filename,"w");
if(JSON_LOG_FILE==NULL){
printf("Error opening file \"%s\": %s\n",json_log_filename,strerror(errno));
return 1;
}
fprintf(JSON_LOG_FILE, "{\n\"end_of_simulation_data\" : {\n");
}
/// READ INPUT FILE /// /// READ INPUT FILE ///
FILE* rom=fopen(infile,"r"); FILE* rom=fopen(infile,"r");
@ -289,14 +275,6 @@ int main(int argc, char* argd[] ){
usleep(100000); usleep(100000);
} }
if(json_log_filename){
fprintf(JSON_LOG_FILE, "\"cycles_run_for\" : %lu ,\n", simdata->current_clock);
fprintf(JSON_LOG_FILE, "\"instructions_executed\" : %lu\n", simdata->finished_instructions);
fprintf(JSON_LOG_FILE, "}\n}\n" );
fclose(JSON_LOG_FILE);
}
if(end_gui()){ if(end_gui()){
printf("Failed on end_gui()\n"); printf("Failed on end_gui()\n");
cpu_simdata_free(simdata); cpu_simdata_free(simdata);

View File

@ -1,13 +0,0 @@
#!/bin/sh
set -eu
if ! [ "$#" = 1 ]
then
echo $0 \<simlog json file\>
exit 1
fi
CYCLES=$(cat "$1" | json2tsv | sed -n '/^\.end_of_simulation_data\.cycles_run_for\t/s/\.end_of_simulation_data\.cycles_run_for\tn\t//p' )
INSTRUCTIONS=$(cat "$1" | json2tsv | sed -n '/^\.end_of_simulation_data\.instructions_executed\t/s/\.end_of_simulation_data\.instructions_executed\tn\t//p' )
echo executed $INSTRUCTIONS instructions with an IPC=$(echo "$INSTRUCTIONS/$CYCLES" | bc -l|grep -o '^.*\...')

View File

@ -25,11 +25,10 @@
struct simdata_t *init_simdata(){ struct simdata_t *init_simdata(){
struct simdata_t * ret=malloc(sizeof(struct simdata_t)); struct simdata_t * ret=malloc(sizeof(struct simdata_t));
if(!ret) if(!ret){
return 0;
ret->current_clock=0; ret->current_clock=0;
ret->finished_instructions=0; return 0;
}
ret->RAM=malloc(16777216); //Maximum addressable memory ret->RAM=malloc(16777216); //Maximum addressable memory
if(!ret->RAM){ if(!ret->RAM){

View File

@ -13,7 +13,6 @@ enum CPU_STRUCTURE_t{ //TODO: I would prefer this would go to cpu.h
struct simdata_t{ struct simdata_t{
long unsigned int current_clock; long unsigned int current_clock;
long unsigned int finished_instructions;
uint8_t *RAM; uint8_t *RAM;
struct fetch_data_t *fetch_data; struct fetch_data_t *fetch_data;