static int pmuL2_process_arg(int option, char *arg) { unsigned int event, freq; int err1, err2; /* * argument parsing */ switch (option) { case '2': // pmu-l2-evt // getopt_long guarants optarg is not NULL err1 = get_num(strtok(arg, ":"), &event, 0); err2 = get_num(strtok(NULL, ":"), &freq, 1); if (err1 || err2) { printf("!!! ERROR: invalid L2_PMU argument: \"%s\" !!!\n", arg); return -1; } if(assign_counter(event, freq)<0) { return -1; } return 1; case 't': // pmu-l2-toggle toggle_mode = 1; return 1; } return 0; }
/* HALT * Input: Three ints (A, B, C) representing registers * * This function ends the program. * * Output: N/A */ void halt(int A, int B, int C) { (void) A; (void) B; (void) C; Seg_array instruct = SEG_MEMORY[0]; assign_counter(instruct->num_elements); return; }
/* LOAD_PROGRAM * Input: Three ints (A, B, C) representing registers * Seq_T segment = (Seq_T)Seq_get(SEGMEMORY, 0); * This function searches for the segment at the id * found in register B. If the id is zero, the counter * to the value found in register C. If the id is not * the instruction code segment is freed and the * segment at id is duplicated and placed in the 0th * position in the segment_memory sequence. * * Output: N/A */ void load_program(int A, int B, int C) { // fprintf(stderr, "in load prog\n"); (void) A; uint32_t b = register_at(B); uint32_t c = register_at(C); if (b == 0){ uint32_t c = register_at(C); if (c == 0) assign_counter(-1); else assign_counter(c - 1); return; } Seg_array seg_array = SEG_MEMORY[b]; Seg_array new_seg_array = array_copy(seg_array); Seg_array inst_seg_array = SEG_MEMORY[0]; FREE(inst_seg_array); SEG_MEMORY[0] = new_seg_array; if (c == 0) assign_counter(-1); assign_counter(c - 1); }