示例#1
0
文件: p_sh.c 项目: fervagar/frop
void set_register(int reg){
  struct Lnode *ptr = NULL;

  if(reg == 7)
    reg = 3;

  switch (reg) {
    case -1: //Store instuctions
      ptr = key_instructions.str;
      break;
    case 0:
      ptr = key_instructions.write_r0;
      break;
    case 1:
      ptr = key_instructions.write_r1;
      break;
    case 2:
      ptr = key_instructions.write_r2;
      break;
    case 3:
      ptr = key_instructions.Inputs[7-3];
      break;
  }

  if(ptr != NULL){
    process_outputs(ptr, payload->head);
    write_gadget(ptr);
    process_inputs(ptr);
    if(reg >= 0){
      state[reg] = 1;
    }
  }
}
示例#2
0
文件: p_sh.c 项目: fervagar/frop
/* Add auxiliar gadget to write in INPUT registers */
struct Lnode *write_auxiliar_gadget(int reg, struct Lnode *existing_node){
  Gadget_t *gadget_struct = NULL;
  struct Lnode *gadget = NULL;
  struct Lnode *aux = NULL;
  char *strings[3];
  uint32_t addr;
  int i, *Outputs;

  gadget = get_gadget_pointer(reg);
  gadget_struct = GETPOINTER(gadget, Gadget_t);
  addr = gadget_struct->instruction->addr;
  Outputs = gadget_struct->Outputs;

  for(i = 0; i < 14; i++){
    if(Outputs[i] && inputs_vector_state[i]){
      inputs_vector_state[i] = 0;
      //inputs_vector_refs[i] = 0;
    }
  }

  for(i = 0, aux = gadget; aux != NULL; aux = aux->next, i++){
      strings[i] = (GETPOINTER(aux, Gadget_t))->instruction->string;
    }
    for(; i < 3; i++)
      strings[i] = 0;


  process_outputs(gadget, existing_node);
  aux = add_node_to_payload(addr, gadget, strings[0], strings[1], strings[2], existing_node);
  //process_inputs(gadget);

  return aux;
}
示例#3
0
文件: p_sh.c 项目: fervagar/frop
void write_stores(){
  unsigned char store_writes_r3, store_writes_r4;
  struct Lnode *store_pop = NULL;
  int i, j, *Outputs[3], sum[3];

  for(i = 0; i < 3; i++){
    process_inputs(key_instructions.str);
    write_gadget(key_instructions.str);
    process_outputs(key_instructions.str, payload->head);
  }

  store_writes_r3 = store_writes_r(3);
  store_writes_r4 = store_writes_r(4);


  if(store_writes_r3 | store_writes_r4){
    if(store_writes_r3 && store_writes_r4){
      for(store_pop = key_instructions.str;
        store_pop->next != NULL; store_pop = store_pop->next);
      Outputs[0] = (GETPOINTER(store_pop, Gadget_t))->Outputs;
      Outputs[1] = (GETPOINTER(key_instructions.Inputs[3-3], Gadget_t))->Outputs;
      Outputs[2] = (GETPOINTER(key_instructions.Inputs[4-3], Gadget_t))->Outputs;

      for(j = 0; j < 3; j++){
        sum[j] = 0;
        for(i = 0; i < 14; i++){
          if(Outputs[j][i]){
            sum[j]++;
          }
        }
      }
      if( (sum[0] - 1) <= sum[1] + sum[2]){
        write_auxiliar_gadget(-1, payload->head); //'pop' of the store
      }
      else{
        write_auxiliar_gadget(4, payload->head);
        write_auxiliar_gadget(3, payload->head);
      }
    }
    else if(store_writes_r3){
      write_auxiliar_gadget(3, payload->head);
    }
    else{
      write_auxiliar_gadget(4, payload->head);
    }
  }
}
示例#4
0
文件: p_sh.c 项目: fervagar/frop
void resolve_dependences(){
  struct Lnode *payload_node = NULL;
  payload_gadget_t *payload_node_struct = NULL;
  /* Local state of pending inputs (previous iteration) */
  unsigned char inputs_vector_state_LOCAL[14];
  unsigned char looping = 1;
  int i;

  while(looping){
    copy_vector(inputs_vector_state_LOCAL, inputs_vector_state, 14);
    clear_vector(inputs_vector_state, 14, 0);
    inputs_vector_state[7] = 1;
    inputs_vector_values[7] = 11;
    inputs_vector_refs[7] = 0;

    for(payload_node = payload->tail; payload_node != NULL; payload_node = payload_node->prev){
      payload_node_struct = GETPOINTER(payload_node, payload_gadget_t);
      process_outputs(payload_node_struct->gadget, payload_node);
      process_inputs(payload_node_struct->gadget);
      for(i = 0; i < 14; i++){
        if(inputs_vector_state[i] && inputs_vector_state_LOCAL[i]){
          // Input not provided //
          if(payload_node != payload->head || !store_writes_r(i)){
            // Fix it
            if(check_my_outputs(i)){
              // Auxiliar gadget (which writes into i) writes also into another pending input //
              inputs_vector_refs[i] = payload_node;
            }
            else{
              payload_node = write_auxiliar_gadget(i, payload_node);
            }
          }
        }
      }
    }

    looping = 0;
    for(i = 0; i < 14; i++){
      if(inputs_vector_state[i] && !store_writes_r(i)){
        write_auxiliar_gadget(i, payload_node);
        looping = 1;
      }
    }
  }
}
int main(int argc, char** argv) {
    /*
     * argv[1] = first run's directory 
     * argv[2] = second run's directory
    */
    if (argc != 4) {
        DEBUG(stderr, "argv[1] = first run's directory, argv[2] = second run's directory, argv[3] = input file\n");
    }
    assert(argc == 4);
    DEBUG(stderr, "argv0 = %s, argv1 = %s, argv2 = %s \n", argv[0], argv[1], argv[2]);

    first_dir = (struct directory_files*) malloc(sizeof(struct directory_files));
    second_dir = (struct directory_files*) malloc(sizeof(struct directory_files));
    gettimeofday(&stats.start, NULL);

    DEBUG(stderr, "init_filename\n");
    if (!init_filenames(argv[1], argv[2], argv[3])) {
        fprintf(stderr, "init filenames failed\n");
        exit(1);
    }

    DEBUG(stderr, "build_address_lookup\n");
    if (!build_address_lookup(first_dir->snapshot, second_dir->snapshot)) {
        fprintf(stderr, "build_dictionary failed\n");
        exit(1);
    }

    build_tables(first_dir, second_dir);

//    init_get_input_addrs(second_dir->dataflow_result);
    process_outputs(argv[3]);

    save_outputs();

    gettimeofday(&stats.end, NULL);
    print_stats(stats);
    return 1;
}
int main (int argc, char* argv[])
{
    dat_t<FLEN>* inputA;
    dat_t<FLEN>* inputB;
    dat_t<1>* expected_out;
    dat_t<5>* expected_exceptionFlags;
    dat_t<1>* actual_out;
    dat_t<5>* actual_exceptionFlags;
    dat_t<1>* check;
    dat_t<1>* pass;
    dut_t* module = new dut_t();
    size_t cnt = 0;
    size_t error = 0;

    module->init();

    inputA = SIGNAL(FLEN, compareOp, a);
    inputB = SIGNAL(FLEN, compareOp, b);
    expected_out = SIGNAL(FLEN, compareOp, expected_out);
    expected_exceptionFlags = SIGNAL(FLEN, compareOp, expected_exceptionFlags);
    actual_out = SIGNAL(FLEN, compareOp, actual_out);
    actual_exceptionFlags = SIGNAL(FLEN, compareOp, actual_exceptionFlags);
    check = SIGNAL(FLEN, compareOp, check);
    pass = SIGNAL(FLEN, compareOp, pass);

    // reset
    for (size_t i=0; i<10; i++) {
        module->clock_lo(LIT<1>(1));
        module->clock_hi(LIT<1>(1));
    }

    // main operation
    for (;;) {
        if (
               ! process_inputs(inputA, inputB)
            || ! process_outputs(expected_out, expected_exceptionFlags)
        ) {
            printf("Ran %ld tests.\n", cnt);
            if (!error) fputs("No errors found.\n", stdout);
            break;
        }

        module->clock_lo(LIT<1>(0));

        if (check->to_bool()) {
            if ((cnt % 10000 == 0) && cnt) printf("Ran %ld tests.\n", cnt);
            if (!pass->to_bool()) {
                error++;
                printf("[%07ld]", cnt);
                printf(
                    " %s %s",
                    inputA->to_str().c_str(),
                    inputB->to_str().c_str()
                );
                printf(
                    " => %s %s   expected: %s %s\n",
                    actual_out->to_str().c_str(),
                    actual_exceptionFlags->to_str().c_str(),
                    expected_out->to_str().c_str(),
                    expected_exceptionFlags->to_str().c_str()
                );
                if (error == 20) {
                    printf("Reached %ld errors. Aborting.\n", error);
                    break;
                }
            }
            cnt++;
        }

        module->clock_hi(LIT<1>(0));
    }

    return 0;
}