#include #include "simdata.h" #include "cpu.h" #include void drawbox(WINDOW *win,int x0, int y0, int x1, int y1){ mvwhline(win,y0, x0, 0, x1-x0); mvwhline(win,y1, x0, 0, x1-x0); mvwvline(win,y0, x0, 0, y1-y0); mvwvline(win,y0, x1, 0, y1-y0); mvwaddch(win,y0, x0, ACS_ULCORNER); mvwaddch(win,y1, x0, ACS_LLCORNER); mvwaddch(win,y0, x1, ACS_URCORNER); mvwaddch(win,y1, x1, ACS_LRCORNER); } int update_internals(WINDOW *win,struct simdata_t *simdata){ int width,height; werase(win); getmaxyx(win,height,width); box(win, 0 , 0); mvwprintw(win,0,width/2-6,"[ INTERNALS ]"); if(simdata->registers==NULL||simdata->exec_data==NULL){ mvwprintw(win,1,1,"Data not initialised"); return 0; } int graph_height,graph_width; switch(simdata->cpu_structure){ case CPU_STRUCTURE_SIMPLE_PIPELINED: graph_height=42; graph_width=59; break; default: graph_height=1; graph_height=41; break; } int starty,startx,boxwidth; starty=height/2-graph_height/2; startx=width/2-graph_width/2; switch(simdata->cpu_structure){ case CPU_STRUCTURE_SIMPLE_PIPELINED: int fetch_arrow_enter_y; int decode_arrow_exit_y; boxwidth=50; /* FETCH BOX */ drawbox(win,startx+boxwidth/2-50/2,starty,startx+boxwidth/2-50/2+50,starty+4); mvwprintw(win,starty,startx+boxwidth/2-4,"[ FETCH ]"); starty+=2; mvwprintw(win,starty,startx+boxwidth/2-15/2,"wait_for_exec=%d",simdata->fetch_data->wait_for_exec); fetch_arrow_enter_y=starty; starty+=2; /* -------> */ mvwaddch(win,starty,startx+boxwidth/2,ACS_TTEE); starty++; mvwvline(win,starty,startx+boxwidth/2, 0, 2); starty+=2; mvwaddch(win,starty,startx+boxwidth/2,'V'); starty+=1; starty+=1; /* DECODE BOX */ drawbox(win,startx+boxwidth/2-50/2,starty,startx+boxwidth/2-50/2+50,starty+6); mvwprintw(win,starty,startx+boxwidth/2-5,"[ DECODE ]"); starty+=2; mvwprintw(win,starty,startx+boxwidth/2-7/2,"valid=%d",simdata->decode_data->valid); decode_arrow_exit_y=starty; starty+=2; mvwprintw(win,starty,startx+boxwidth/2-41/2,"in_bytecode=0x%08X address=0x%06X",simdata->decode_data->in_bytecode,simdata->decode_data->address); starty+=2; /* -------> */ mvwaddch(win,starty,startx+boxwidth/2,ACS_TTEE); starty++; mvwvline(win,starty,startx+boxwidth/2, 0, 2); starty+=2; mvwaddch(win,starty,startx+boxwidth/2,'V'); starty+=1; starty+=1; /* EXECUTE BOX */ drawbox(win,startx+boxwidth/2-50/2,starty,startx+boxwidth/2-50/2+50,starty+21); mvwprintw(win,starty,startx+boxwidth/2-8,"[ EXECUTE UNIT ]"); starty+=2; char *tofree; mvwprintw(win,starty,startx+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+boxwidth/2-41/2,"ALU_OP=%s", (tofree=ALU_OP_t_to_string(simdata->exec_data->ALU_OP)) ); free(tofree); starty+=2; mvwprintw(win,starty,startx+boxwidth/2-41/2,"COND=%s", (tofree=COND_t_to_string(simdata->exec_data->COND)) ); free(tofree); mvwprintw(win,starty,startx+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+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=simdata->exec_data->in_op1; break; case 1: mvwprintw(win,starty,startx+5," Input operand 2 "); cur=simdata->exec_data->in_op2; break; case 2: mvwprintw(win,starty,startx+5," Output operand "); cur=simdata->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; } /* Wait for exec arrow */ mvwaddch(win,decode_arrow_exit_y,startx+50,ACS_LTEE); mvwhline(win,decode_arrow_exit_y,startx+51, 0, 3); mvwaddch(win,decode_arrow_exit_y,startx+54,ACS_LRCORNER); mvwvline(win,fetch_arrow_enter_y+1,startx+54, 0,decode_arrow_exit_y-fetch_arrow_enter_y-1); mvwaddch(win,fetch_arrow_enter_y,startx+54,ACS_URCORNER); mvwhline(win,fetch_arrow_enter_y,startx+53, 0, 1); mvwaddch(win,fetch_arrow_enter_y,startx+52,'<'); mvwprintw(win,fetch_arrow_enter_y+(decode_arrow_exit_y-fetch_arrow_enter_y-1)/2-1,startx+55,"Wait"); mvwprintw(win,fetch_arrow_enter_y+(decode_arrow_exit_y-fetch_arrow_enter_y-1)/2 ,startx+55,"For"); mvwprintw(win,fetch_arrow_enter_y+(decode_arrow_exit_y-fetch_arrow_enter_y-1)/2+1,startx+55,"Exec"); break; default: mvwprintw(win,starty,startx,"No graph available for this cpu structure"); break; } if(height==3) return 0; else return 0; }