Compare commits
2 Commits
3f4b03c307
...
48237ccd95
Author | SHA1 | Date | |
---|---|---|---|
48237ccd95 | |||
99c0af752b |
2
.gitignore
vendored
2
.gitignore
vendored
@ -7,3 +7,5 @@ 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
1
cpu.c
@ -581,6 +581,7 @@ 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;
|
||||||
|
115
gui_internals.c
115
gui_internals.c
@ -14,6 +14,68 @@ 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);
|
||||||
@ -94,55 +156,9 @@ int update_internals(WINDOW *win,struct simdata_t *simdata){
|
|||||||
starty+=1;
|
starty+=1;
|
||||||
|
|
||||||
/* EXECUTE BOX */
|
/* EXECUTE BOX */
|
||||||
wattron(win,A_BOLD);
|
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);
|
||||||
drawbox(win,startx+20+boxwidth/2-50/2,starty,startx+20+boxwidth/2-50/2+50,starty+21);
|
exec_arrow_y=box_ret_dimensions->arrow1_y;
|
||||||
mvwprintw(win,starty,startx+20+boxwidth/2-8,"[ EXECUTE UNIT ]");
|
free(box_ret_dimensions);
|
||||||
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);
|
||||||
@ -205,4 +221,3 @@ int update_internals(WINDOW *win,struct simdata_t *simdata){
|
|||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
24
main.c
24
main.c
@ -41,6 +41,7 @@ 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);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,7 +62,9 @@ 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;
|
||||||
while ((opt = getopt(argc, argd, "hi:a:r:")) != -1) {
|
char *json_log_filename=NULL;
|
||||||
|
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]);
|
||||||
@ -88,6 +91,9 @@ 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;
|
||||||
@ -104,6 +110,14 @@ 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");
|
||||||
@ -275,6 +289,14 @@ 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);
|
||||||
|
13
parse_log.sh
Executable file
13
parse_log.sh
Executable file
@ -0,0 +1,13 @@
|
|||||||
|
#!/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 '^.*\...')
|
@ -25,10 +25,11 @@
|
|||||||
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)
|
||||||
ret->current_clock=0;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
ret->current_clock=0;
|
||||||
|
ret->finished_instructions=0;
|
||||||
|
|
||||||
ret->RAM=malloc(16777216); //Maximum addressable memory
|
ret->RAM=malloc(16777216); //Maximum addressable memory
|
||||||
if(!ret->RAM){
|
if(!ret->RAM){
|
||||||
|
@ -13,6 +13,7 @@ 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;
|
||||||
|
Loading…
Reference in New Issue
Block a user