Ejemplo n.º 1
0
void flush_delay()
{
	reset_engine();
    #ifdef SUPPORT_SMART1
    if(g_smart_power_down_flag == 0)
    {
        updata_smart_n(smart_power_down_addr,0x01);
        g_smart_power_down_flag = 1;
        reset_engine();
    }
    #endif
	sata.CHP_cmd = CHP_CMD_FLUSH;
	wait_chp_ready();
	reset_engine();
}
Ejemplo n.º 2
0
void chp_burst(u8 cmd,u8 cnt,u8 base_addr)//read cnt should < chp_number * stripe, or sync fifo bug will be trigged  
{
	reset_engine();
	save_lba();
	sata.SUP_LBA0 = SMART_BASE_ADDR0;
	sata.SUP_LBA1 = SMART_BASE_ADDR1;
	sata.SUP_LBA2 = SMART_BASE_ADDR2;
	sata.SUP_LBA3 = SMART_BASE_ADDR3;
	sata.SUP_LBA4 = SMART_BASE_ADDR4;
	sata.SUP_LBA5 = SMART_BASE_ADDR5;
	for(;base_addr>0;base_addr--)
	{
        auto_increase_lba;
	}
	sata.CHP_cmd = cmd;
	SFR_dma_base = 0x0000;
	SFR_dma_max_num_l = cnt;
	SFR_dma_max_num_h = 0x00;
	if(cmd == CHP_CMD_WRITE)
    {
        SFR_dma_cntl = SFR_dma_cntl_run;
    }
    else
    {
    	SFR_dma_cntl = SFR_dma_cntl_run | SFR_dma_cntl_dir_read;
    }
	while(!dma_done);
    clear_dma_run;
    recover_lba();
}
Ejemplo n.º 3
0
void choose_mode()
{
    switch(sata.FIS_feature)
    {
        case read_only_enable:
        {
            chp_burst(CHP_CMD_READ,0x01,block_base_log);
            SFR_ext_sram_addr = 0x0007;
            SFR_ext_sram_cntl = 0x00;
            SFR_ext_sram_data = read_only_enable;
            chp_burst(CHP_CMD_WRITE,0x01,block_base_log);
			flush_delay();
            read_only_flag = read_only_enable;
            tx_fis_34(status_good,error_no,int_set);
            break;
        }
        case read_only_disable:
        {
            chp_burst(CHP_CMD_READ,0x01,block_base_log);
            SFR_ext_sram_addr = 0x0007;
            SFR_ext_sram_cntl = 0x00;
            SFR_ext_sram_data = read_only_disable;
            chp_burst(CHP_CMD_WRITE,0x01,block_base_log);
			flush_delay();
            read_only_flag = read_only_disable;
            tx_fis_34(status_good,error_no,int_set);
            break;
        }
        default: 
		    tx_fis_34(status_bad,error_abort,int_set);
			break;
    }
    reset_engine();
    return;
}
void
decide_eye(int pos)
{
  int color;
  struct eyevalue value;
  int attack_point;
  int defense_point;
  int eyepos;
  SGFTree tree;

  reset_engine();
  silent_examine_position(BLACK, EXAMINE_DRAGONS_WITHOUT_OWL);
  
  if (black_eye[pos].color == BLACK_BORDER) 
    color = BLACK;
  else if (white_eye[pos].color == WHITE_BORDER) 
    color = WHITE;
  else {
    gprintf("The eye at %1m is not of a single color.\n", pos);
    return;
  }

  if (printboard)
    showboard(0);

  /* Enable sgf output. */
  if (*outfilename)
    sgffile_begindump(&tree);
  count_variations = 1;
  
  if (black_eye[pos].color == BLACK_BORDER) {
    eyepos = black_eye[pos].origin;
    compute_eyes(eyepos, &value, &attack_point, &defense_point,
		 black_eye, half_eye, 0, EMPTY);
    gprintf("Black eyespace at %1m: %s\n", eyepos, eyevalue_to_string(&value));
    if (eye_move_urgency(&value) > 0) {
      gprintf("  vital points: %1m (attack) %1m (defense)\n", attack_point,
	      defense_point);
    }
  }
  
  if (white_eye[pos].color == WHITE_BORDER) {
    eyepos = white_eye[pos].origin;
    compute_eyes(eyepos, &value, &attack_point, &defense_point,
		 white_eye, half_eye, 0, EMPTY);
    gprintf("White eyespace at %1m: %s\n", eyepos, eyevalue_to_string(&value));
    if (eye_move_urgency(&value) > 0) {
      gprintf("  vital points: %1m (attack) %1m (defense)\n", attack_point,
	      defense_point);
    }
  }
  
  /* Finish sgf output. */
  sgffile_enddump(outfilename);
  count_variations = 0;
}
Ejemplo n.º 5
0
static void
cmd_undo(void)
{
    if (is_force_mode) {
        if (revert() != 0)
            general_error();
        reset_engine(current_position());
        debug_engine_set_player_to_move(turn());
    }
}
void
decide_dragon_data(int pos)
{
  if (board[pos] == EMPTY) {
    fprintf(stderr, "gnugo: --decide-dragon-data called on an empty vertex\n");
    return ;
  }
  reset_engine();
  silent_examine_position(board[pos], FULL_EXAMINE_DRAGONS);

  gprintf("Dragon at %1m:\n", pos);
  report_dragon(stderr, pos);
}
Ejemplo n.º 7
0
static void
cmd_redo(void)
{
    mtx_lock(&game_mutex);

    if (is_force_mode) {
        if (forward() != 0)
            general_error();
        reset_engine(current_position());
        debug_engine_set_player_to_move(turn());
    }

    mtx_unlock(&game_mutex);
}
Ejemplo n.º 8
0
void
decide_oracle(Gameinfo *gameinfo, char *infilename, char *untilstring)
{
  SGFTree tree;

  reset_engine();
  if (*outfilename)
    sgffile_begindump(&tree);

  count_variations = 1;
  summon_oracle();
  oracle_loadsgf(infilename, untilstring);
  consult_oracle(gameinfo->to_move);
  sgffile_enddump(outfilename);
  dismiss_oracle();
  count_variations = 0;
}
Ejemplo n.º 9
0
void
decide_semeai(int apos, int bpos)
{
  SGFTree tree;
  int resulta, resultb, move, result_certain;
  int color = board[apos];

  if (color == EMPTY || board[bpos] != OTHER_COLOR(color)) {
    gprintf("gnugo: --decide-semeai called on invalid data\n");
    return;
  }

  /* Prepare pattern matcher and reading code. */
  reset_engine();

  silent_examine_position(EXAMINE_DRAGONS_WITHOUT_OWL);
  gprintf("finished examine_position\n");
  count_variations = 1;

  if (*outfilename)
    sgffile_begindump(&tree);

  gprintf("Analyzing semeai between %1m and %1m, %C moves first\n",
	  apos, bpos, board[apos]);
  owl_analyze_semeai(apos, bpos, &resulta, &resultb, &move, &result_certain);
  gprintf("Semeai defense of %1m: result %s %1m\n",
	  apos, result_to_string(resulta), move);
  gprintf("Semeai attack of %1m: result %s %1m\n",
	  bpos, result_to_string(resultb), move);
  gprintf("%d nodes%s\n\n", count_variations,
	  result_certain ? "" : ", uncertain result");
  
  gprintf("Analyzing semeai between %1m and %1m, %C moves first\n",
	  bpos, apos, board[bpos]);
  owl_analyze_semeai(bpos, apos, &resultb, &resulta, &move, &result_certain);
  gprintf("Semeai defense of %1m: result %s %1m\n",
	  bpos, result_to_string(resultb), move);
  gprintf("Semeai attack of %1m: result %s %1m\n",
	  apos, result_to_string(resulta), move);
  gprintf("%d nodes%s\n", count_variations,
	  result_certain ? "" : ", uncertain result");

  sgffile_enddump(outfilename);
  count_variations = 0;
}
void
decide_tactical_semeai(int apos, int bpos)
{
  SGFTree tree;
  int resulta, resultb, move;
  int color = board[apos];

  if (color == EMPTY || board[bpos] != OTHER_COLOR(color)) {
    gprintf("gnugo: --decide-semeai called on invalid data\n");
    return;
  }

  /* Prepare pattern matcher and reading code. */
  reset_engine();

  silent_examine_position(board[apos], EXAMINE_DRAGONS_WITHOUT_OWL);
  gprintf("finished examine_position\n");
  count_variations = 1;

  /* We want to see the reading performed, not just a result picked
   * from the cache. Thus we clear the cache here. */
  reading_cache_clear();
  
  if (*outfilename)
    sgffile_begindump(&tree);

  owl_analyze_semeai(apos, bpos, &resulta, &resultb, &move, 0);
  gprintf("After %s at %1m, %1m is %s, %1m is %s (%d nodes)\n",
	  color == BLACK ? "black" : "white",
	  move,
	  apos, safety_to_string(resulta),
  	  bpos, safety_to_string(resultb),
	  count_variations);
  owl_analyze_semeai(bpos, apos, &resultb, &resulta, &move, 0);
  gprintf("After %s at %1m, %1m is %s, %1m is %s (%d nodes)\n",
	  color == BLACK ? "white" : "black",
	  move,
	  apos, safety_to_string(resulta),
  	  bpos, safety_to_string(resultb),
	  count_variations);

  sgffile_enddump(outfilename);
  count_variations = 0;
}
void
decide_surrounded(int pos)
{
  int surround_status;

  if (board[pos] == EMPTY) {
    fprintf(stderr, "location must not be empty!\n");
    return;
  }

  /* Prepare pattern matcher and reading code. */
  reset_engine();

  silent_examine_position(board[pos], EXAMINE_ALL);
  surround_status = compute_surroundings(pos, NO_MOVE, 1, NULL);
  if (surround_status == 1)
    gprintf("the dragon at %1m is SURROUNDED!\n", pos);
  else if (surround_status == 2)
    gprintf("the dragon at %1m is WEAKLY SURROUNDED!\n", pos);
  else
    gprintf("the dragon at %1m is not surrounded.\n", pos);
}  
void
decide_combination(int color)
{
  int attack_move;
  char defense_moves[BOARDMAX];
  SGFTree tree;
  int first = 1;
  int pos;

  /* Prepare pattern matcher and reading code. */
  reset_engine();

  silent_examine_position(color, EXAMINE_ALL);

  if (*outfilename)
    sgffile_begindump(&tree);
  count_variations = 1;

  if (atari_atari(color, &attack_move, defense_moves, verbose)) {
    gprintf("Combination attack for %C at %1m, defense at ", color,
	    attack_move);
    for (pos = BOARDMIN; pos < BOARDMAX; pos++) {
      if (ON_BOARD(pos) && defense_moves[pos]) {
	if (first)
	  first = 0;
	else
	  gprintf(", ");
	gprintf("%1m", pos);
      }
    }
    gprintf("\n");
  }
  else
    gprintf("No Combination attack for %C\n", color);
  
  sgffile_enddump(outfilename);
  count_variations = 0;
}
Ejemplo n.º 13
0
static void
cmd_new(void)
{
    callback_key++;
    stop_thinking();

    mtx_lock(&game_mutex);

    game_destroy(game);
    if ((game = game_create()) == NULL)
        INTERNAL_ERROR();
    reset_engine(current_position());
    debug_engine_set_player_to_move(turn());
    computer_side = black;
    set_thinking_done_cb(computer_move, ++callback_key);
    unset_search_depth_limit();
    if (!(is_xboard || is_uci))
        puts("New game - computer black");
    game_started = false;
    is_force_mode = false;

    mtx_unlock(&game_mutex);
}
Ejemplo n.º 14
0
static void
cmd_setboard(void)
{
    struct game *g;

    if (game_started)
        return;

    g = game_create_fen(xstrtok_r(NULL, "\n\r", &line_lasts));
    if (g == NULL) {
        (void) fprintf(stderr, "Unable to parse FEN\n");
        return;
    }

    mtx_lock(&game_mutex);

    game_destroy(game);
    game = g;
    reset_engine(current_position());
    debug_engine_set_player_to_move(turn());

    mtx_unlock(&game_mutex);
}
void
decide_position(int color)
{
  int pos;
  int move = NO_MOVE;
  int acode = 0, dcode = 0;
  int kworm;
  static const char *snames[] = {"dead", "alive", "critical", "unknown"};
  SGFTree tree;

  /* Prepare pattern matcher and reading code. */
  reset_engine();

  silent_examine_position(color, EXAMINE_DRAGONS_WITHOUT_OWL);

  /* We want to see the reading performed, not just a result picked
   * from the cache. Thus we clear the cache here. */
  reading_cache_clear();

  if (*outfilename)
    sgffile_begindump(&tree);

  count_variations = 1;

  for (pos = BOARDMIN; pos < BOARDMAX; pos++) {
    if (!ON_BOARD(pos)
	|| dragon[pos].origin != pos
	|| board[pos] == EMPTY
	|| DRAGON2(pos).escape_route >= 6)
      continue;

    gprintf("\nanalyzing %1m\n", pos);
    gprintf("status=%s, escape=%d\n", 
	    snames[dragon[pos].crude_status], DRAGON2(pos).escape_route);
    acode = owl_attack(pos, &move, NULL, &kworm);
    if (acode) {
      if (acode == WIN) {
	if (move == NO_MOVE)
	  gprintf("%1m is dead as it stands\n", pos);
	else
	  gprintf("%1m can be attacked at %1m (%d variations)\n", 
		  pos, move, count_variations);
      }
      else if (acode == KO_A)
	gprintf("%1m can be attacked with ko (good) at %1m (%d variations)\n", 
		pos, move, count_variations);
      else if (acode == KO_B)
	gprintf("%1m can be attacked with ko (bad) at %1m (%d variations)\n", 
		pos, move, count_variations);
      else if (acode == GAIN)
	gprintf("%1m can be attacked with gain (captures %1m) at %1m (%d variations)", 
		pos, kworm, move, count_variations);
      
      count_variations = 1;
      dcode = owl_defend(pos, &move, NULL, &kworm);
      if (dcode) {
	if (dcode == WIN) {
	  if (move == NO_MOVE)
	    gprintf("%1m is alive as it stands\n", pos);
	  else 
	    gprintf("%1m can be defended at %1m (%d variations)\n", 
		    pos, move, count_variations);
	}
	else if (dcode == KO_A)
	  gprintf("%1m can be defended with ko (good) at %1m (%d variations)\n", 
		  pos, move, count_variations);
	else if (dcode == KO_B)
	  gprintf("%1m can be defended with ko (bad) at %1m (%d variations)\n",
		  pos, move, count_variations);
	else if (dcode == LOSS)
	  gprintf("%1m can be defended with loss (loses %1m) at %1m (%d variations)", 
		  pos, kworm, move, count_variations);
      }
      else
	gprintf("%1m cannot be defended (%d variations)\n", 
		pos, count_variations);
    }
    else 
      gprintf("%1m cannot be attacked (%d variations)\n", 
	      pos, count_variations);
    
    if (acode) {
      if (dcode)
	gprintf("status of %1m revised to CRITICAL\n", pos);
      else
	gprintf("status of %1m revised to DEAD\n", pos);
    }
    else
      gprintf("status of %1m revised to ALIVE\n", pos);
  }
  
  sgffile_enddump(outfilename);
  count_variations = 0;
}
Ejemplo n.º 16
0
void write_handler()
{
	#ifdef security_debug
	enable_fetch_lba;
	myprintf("\nLBAw0: %x %x %x %x %x %x ",sata.SUP_LBA5,sata.SUP_LBA4,sata.SUP_LBA3,sata.SUP_LBA2,sata.SUP_LBA1,sata.SUP_LBA0);
	disable_fetch_lba;	
	#endif
    //if not continue
     {
	reset_engine_read_write();	//reset_engine and check srst in wait rdy	
	//check_lba();
     	
    	if(g_current_fis_num != SFR_fis_num)return;

	#ifdef security_debug
	enable_fetch_lba;
	myprintf("\nLBAw1: %x %x %x %x %x %x ",sata.SUP_LBA5,sata.SUP_LBA4,sata.SUP_LBA3,sata.SUP_LBA2,sata.SUP_LBA1,sata.SUP_LBA0);
	disable_fetch_lba;
	#endif
	
        #ifdef READ_ONLY 
			#ifdef BUF_CMD_EN
				buf_check_cnt = 0x00;
			#endif
        if(read_only_flag == read_only_enable) 
        {
            SFR_smart_load = smart_load_sata_cnt;
            set_burst_run_wr;
        }
        else 
		#endif
        {
            sata.CHP_cmd = CHP_CMD_WRITE;
            SFR_smart_load = smart_load_chp_cnt | smart_load_sata_cnt;
            SFR_dma_base = 0x0000;
            set_dma_run_wr;
    		g_cont_en = 1;
        }
     }
     
write_cont:
     while(!sata_burst_done)
     {
	    if(g_current_fis_num != SFR_fis_num)return;
	 }
     if(sata_burst_abort)goto write_handler_err;

    #ifdef READ_ONLY
    if(read_only_flag == read_only_enable)
	{
		tx_fis_34(status_good,error_no, int_set);
		goto write_handler_over;
	} 
    #endif
     
     while(!dma_done)
     {
	    if(g_current_fis_num != SFR_fis_num)return;
	 }

     tx_fis_34(status_good,error_no, int_set);
	 if(((sata.CHP0_status_high & 0x80) == 0x80)||((sata.CHP1_status_high & 0x80) == 0x80)||((sata.CHP2_status_high & 0x80) == 0x80)||((sata.CHP3_status_high & 0x80) == 0x80)||((sata.CHP4_status_high & 0x80) == 0x80)) 
     {
        goto write_handler_over;
     }
     //check whether there is continue command.
	 SFR_watch_dog_high = 0x00;
     while(1)
     {
        if(g_current_fis_num != SFR_fis_num)
        {
            //normal_cmd_cont will only be updated when get a new command in RTL.
            //if it's a FIS27 - Control: normal_cmd_cont will stay in 1
            if(normal_cmd_cont && g_cont_en && ((SFR_quick_cmd & quick_cmd_write_dma) != 0x00) )
            {
                SFR_smart_load = smart_load_add_chp_cnt | smart_load_add_sata_cnt;
                sata_burst_cont = 1;
                dma_cont = 1;
                g_current_fis_num = SFR_fis_num;  //we  may  not  go  to  main
                sata.ncq_cntl = (sata.ncq_cntl & (~ncq_cntl_new_fis27));
                #ifdef BUF_CMD_EN
				buf_check_cnt = 0x00;
                #endif
                goto write_cont;
            }
            else break;
        }
        if(sata.watch_dog_cnt_low > 0x04) break;
    }
     #ifdef SUPPORT_SMART1
     smart_write_cnt();
	 #endif
     goto write_handler_over;    
         
write_handler_err:
     tx_fis_34(status_bad,error_abort,int_set);
	 #ifdef SUPPORT_SMART1
     updata_smart(smart_crc_num_addr,0x01);
     #endif
write_handler_over:
     //I am not sure host will retry that command immediatelly, need to break the continue mode
	 reset_engine();
     return;
}
Ejemplo n.º 17
0
/////////////////////////////////////////////////////////////////////
//(1)handle: READ_MULTIPLE, READ_SECTOR, WRITE_MULTIPLE, WRITE_SECTOR
//(2)require PIO setup FIS.
//(3)not enable AUTO mode
//(4)don't cares speed.
/////////////////////////////////////////////////////////////////////
void pio_read_handler()
{
    u8 idata pio_interrput;
    pio_interrput = pio_write_begin;
    if(g_flag_lba_err)goto pio_handler_err; 
    
    
    do{   
		reset_engine_read_write();	//reset_engine and check srst in wait rdy	
		if(g_current_fis_num != SFR_fis_num)return;
	
    	//if(g_flag_dir==DIR_WRITE)sata.CHP_cmd = CHP_CMD_WRITE;
    	sata.CHP_cmd = CHP_CMD_READ;
    	SFR_dma_max_num = 0x0001;
        //myprintf("\nchp_en :%xchp_stripe:%x%x",SFR_CHP_en,sata.CHP_stripe_h,sata.CHP_stripe);
        {
           if(g_sec_cnt.word==1)tx_fis_5f(status_drq, error_no, pm_pio_read, g_sec_cnt.byte.l, g_sec_cnt.byte.h, status_good);
           else tx_fis_5f(status_drq, error_no, pm_pio_read, g_sec_cnt.byte.l, g_sec_cnt.byte.h, status_bsy);                 
        }

        
        //to save some code
        //SFR_dma_base = 0x0000;
        SFR_dma_cntl = SFR_dma_cntl_run | SFR_dma_cntl_conj | SFR_dma_cntl_dir_read;
        
        while(!sata_burst_done)
		{
		   if(g_current_fis_num != SFR_fis_num)return;
		}
        if(sata_burst_abort)goto pio_handler_err;
                
       
        while(!dma_done)
		{
	       if(g_current_fis_num != SFR_fis_num)return;
	    }
			
       
		SFR_dma_cntl =  SFR_dma_cntl_conj;
        g_sec_cnt.word--;
		auto_increase_lba;
                
    }while(g_sec_cnt.word>0);
    sata.FIS_seccnt = g_sec_cnt.byte.l;
	sata.FIS_seccnt_ext = g_sec_cnt.byte.h;
	//smart data handle
	#ifdef SUPPORT_SMART1
    {
	    //smart data handle
	    smart_read_cnt();
    }
	#endif
    return;      
        
pio_handler_err:
	tx_fis_34(status_bad,error_abort,int_set);
    reset_engine();
    #ifdef SUPPORT_SMART1
    updata_smart(smart_crc_num_addr,0x01);
    reset_engine();
    #endif
	return;
}
void
decide_owl(int pos)
{
  int move = NO_MOVE;
  int acode, dcode;
  SGFTree tree;
  int result_certain;
  int kworm;

  if (board[pos] == EMPTY) {
    fprintf(stderr, "gnugo: --decide-dragon called on an empty vertex\n");
    return ;
  }

  /* Prepare pattern matcher and reading code. */
  reset_engine();

  silent_examine_position(board[pos], EXAMINE_DRAGONS_WITHOUT_OWL);
  gprintf("finished examine_position\n");

  /* We want to see the reading performed, not just a result picked
   * from the cache. Thus we clear the cache here.
   */
  reading_cache_clear();
  
  if (*outfilename)
    sgffile_begindump(&tree);

  count_variations = 1;
  acode = owl_attack(pos, &move, &result_certain, &kworm);
  if (acode) {
    if (acode == WIN) {
      if (move == NO_MOVE)
	gprintf("%1m is dead as it stands", pos);
      else
	gprintf("%1m can be attacked at %1m (%d variations)", 
		pos, move, count_variations);
    }
    else if (acode == KO_A)
      gprintf("%1m can be attacked with ko (good) at %1m (%d variations)", 
	      pos, move, count_variations);
    else if (acode == KO_B)
      gprintf("%1m can be attacked with ko (bad) at %1m (%d variations)", 
	      pos, move, count_variations);
    else if (acode == GAIN)
      gprintf("%1m can be attacked with gain (captures %1m) at %1m (%d variations)", 
	      pos, kworm, move, count_variations);
  }
  else 
    gprintf("%1m cannot be attacked (%d variations)", pos, count_variations);
  
  if (result_certain)
    gprintf("\n");
  else
    gprintf(" result uncertain\n");

  reading_cache_clear();
  count_variations = 1;
  dcode = owl_defend(pos, &move, &result_certain, &kworm);

  if (dcode) {
    if (dcode == WIN) {
      if (move == NO_MOVE)
	gprintf("%1m is alive as it stands", pos);
      else 
	gprintf("%1m can be defended at %1m (%d variations)", 
		pos, move, count_variations);
    }
    else if (dcode == KO_A)
      gprintf("%1m can be defended with ko (good) at %1m (%d variations)", 
	      pos, move, count_variations);
    else if (dcode == KO_B)
      gprintf("%1m can be defended with ko (bad) at %1m (%d variations)", 
	      pos, move, count_variations);
    else if (dcode == LOSS)
      gprintf("%1m can be defended with loss (loses %1m) at %1m (%d variations)", 
	      pos, kworm, move, count_variations);
  }
  else
    gprintf("%1m cannot be defended (%d variations)",
	    pos, count_variations);

  if (result_certain)
    gprintf("\n");
  else
    gprintf(" result uncertain\n");
  
  sgffile_enddump(outfilename);
  count_variations = 0;
}
void
decide_connection(int apos, int bpos)
{
  int move;
  int result;
  SGFTree tree;

  ASSERT_ON_BOARD1(apos);
  ASSERT_ON_BOARD1(bpos);
  
  if (board[apos] == EMPTY || board[bpos] == EMPTY) {
    fprintf(stderr, "gnugo: --decide-connection called on an empty vertex\n");
    return;
  }

  if (board[apos] != board[bpos]) {
    fprintf(stderr, "gnugo: --decide-connection called for strings of different colors\n");
    return;
  }

  if (*outfilename)
    sgffile_begindump(&tree);

  /* Prepare pattern matcher and reading code. */
  reset_engine();

  count_variations = 1;
  result = string_connect(apos, bpos, &move);
  if (result == WIN) {
    if (move == NO_MOVE)
      gprintf("%1m and %1m are connected as it stands (%d variations)\n", 
	      apos, bpos, count_variations);
    else
	gprintf("%1m and %1m can be connected at %1m (%d variations)\n", 
		apos, bpos, move, count_variations);
  }
  else if (result == KO_A)
    gprintf("%1m and %1m can be connected with ko (good) at %1m (%d variations)\n", 
	    apos, bpos, move, count_variations);
  else if (result == KO_B)
    gprintf("%1m and %1m can be connected with ko (bad) at %1m (%d variations)\n", 
	    apos, bpos, move, count_variations);
  else
    gprintf("%1m and %1m cannot be connected (%d variations)\n", 
	    apos, bpos, count_variations);
  
  count_variations = 1;
  result = disconnect(apos, bpos, &move);
  if (result == WIN) {
    if (move == NO_MOVE)
      gprintf("%1m and %1m are disconnected as it stands (%d variations)\n", 
	      apos, bpos, count_variations);
    else
	gprintf("%1m and %1m can be disconnected at %1m (%d variations)\n", 
		apos, bpos, move, count_variations);
  }
  else if (result == KO_A)
    gprintf("%1m and %1m can be disconnected with ko (good) at %1m (%d variations)\n", 
	    apos, bpos, move, count_variations);
  else if (result == KO_B)
    gprintf("%1m and %1m can be disconnected with ko (bad) at %1m (%d variations)\n", 
	    apos, bpos, move, count_variations);
  else
    gprintf("%1m and %1m cannot be disconnected (%d variations)\n", 
	    apos, bpos, count_variations);
  
  sgffile_enddump(outfilename);
  count_variations = 0;
}
Ejemplo n.º 20
0
/* END:   Added by huawei, 2013/10/28 */
void trim_handler()
{
    u16_t idata jj;
    u16_t idata sram_addr,addr_temp;

    //sata dma 读取主机发送来的指令
    reset_engine();
    sram_addr.word=0;
    SFR_sata_burst_cnt = sata.FIS_seccnt;
    SFR_sata_burst_base = 0x0000;
    SFR_sata_burst_cntl = SFR_sata_burst_cntl_run | SFR_sata_burst_cntl_dma_act;
    while(!sata_burst_done);
    if(sata_burst_abort) {
        tx_fis_34(status_good,error_no,int_set);
        goto end_of_trim;
    }
    clear_burst_run;

    //对master模式中的LBA进行偏移处理
    if(security_mode==show_master)
    {
        jj.word= 64*sata.FIS_seccnt;
        SFR_ext_sram_addr = 0x0000;
        sram_addr.word= 0;
        while(sram_addr.word< jj.word)    // affirm that 64*sata.fis_seccnt is right
        {
            SFR_ext_sram_addr = (sram_addr.word<<3)+0x06;
            SFR_ext_sram_cntl = 0x10;  //enable addr auto add one
            if((SFR_ext_sram_data == 0x00)&&(SFR_ext_sram_data == 0x00)) {
                break;    //check the Range Length, zero:break
            }
            //LBA偏移操作
            SFR_ext_sram_addr = (sram_addr.word<<3);
            SFR_ext_sram_cntl = 0x00;  //disenable addr auto add one
            SFR_ext_sram_data = SFR_ext_sram_data+0x00;//LBA0
            SFR_ext_sram_addr++;
            SFR_ext_sram_data = SFR_ext_sram_data+0x00;//LBA1
            SFR_ext_sram_addr++;
            SFR_ext_sram_data = SFR_ext_sram_data+0xc0;//LBA2
            SFR_ext_sram_addr++;
            SFR_ext_sram_data = SFR_ext_sram_data+0x08;//LBA3
            SFR_ext_sram_addr++;
            SFR_ext_sram_data = SFR_ext_sram_data+0x00;//LBA4
            SFR_ext_sram_addr++;
            SFR_ext_sram_data = SFR_ext_sram_data+0x00;//LBA5
            sram_addr.word++;
        }
    }

    //计算得到TRIM的Entry数量,每个entry占用8个字节
    jj.word= 64*sata.FIS_seccnt;
    SFR_ext_sram_addr = 0x0000;
    SFR_ext_sram_cntl = 0x10;  //enable addr auto add one
    sram_addr.word= 0;
    while(sram_addr.word< jj.word)    //////////////////////////////??????? affirm that 64*sata.fis_seccnt is right
    {
        addr_temp.word = sram_addr.word;
        SFR_ext_sram_addr = (sram_addr.word<<3)+0x06;
        if((SFR_ext_sram_data == 0x00)&&(SFR_ext_sram_data == 0x00)) {
            break;    //check the Range Length, zero:break
        }
        sum.Number = 0;
        for(; sram_addr.word< jj.word; sram_addr.word++)
        {
            SFR_ext_sram_addr = (sram_addr.word<<3);
            fetch_table_lba();
            trim_addr_offset.No[3] = SFR_ext_sram_data;
            trim_addr_offset.No[2] = SFR_ext_sram_data;
            trim_addr_offset.No[1] = 0x00;
            trim_addr_offset.No[0] = 0x00;
            lba_adder();
            sum.Number += trim_addr_offset.Number;
            if(sram_addr.word == ( jj.word-1)) {
                goto continue_end;
            }
            if(cmp_lba()) {
                break;   //if lba discontinue
            }
        }
continue_end:
        //check if the lba exceed the os visible area
        if(trim_check_lba()) {
            tx_fis_34(status_good,error_no,int_set);
            goto end_of_trim;
        }
        fetch_block_border(addr_temp);
        sram_addr.word++;
        if(sum.Number <= trim_addr_offset.Number) {
            continue;
        }
        sum.Number -= trim_addr_offset.Number;
        send_trim_cmd(sum);
    }
    SFR_ext_sram_cntl = 0x00;  //disable addr auto add one
    tx_fis_34(status_good,error_no,int_set);
end_of_trim:
    reset_engine();
}
Ejemplo n.º 21
0
///////////////////////////////////////////////////////////////////////
//load identify data from code area to SUP 32K FIFO. 
//Then send to SATA host.
///////////////////////////////////////////////////////////////////////
void identify_device()
{
	u16 i =0;
	u8 tmp,tmp1;
	u16_t tmp2;
    
    //clear_dma_run;
    //reset_dma_engine();
        
	//prepare data, read it from code area
	SFR_ext_sram_addr = 0x0000;
	SFR_ext_sram_cntl = 0x10;	//enable auto increese of the sram address
	g_tmp_addr = identify_data_addr;
    for(i=0;i<512;i++)
    {
	    SFR_ext_sram_data = read_code(g_tmp_addr);
        g_tmp_addr ++; 
    }
    
    #ifdef SUPPORT_SECURITY
    if(security_mode == show_master)//48GB
    {
        SFR_ext_sram_addr = 0x0078;
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0x06;

        SFR_ext_sram_addr = 0x00C8;  //identify word 100-103
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0x06;

	g_tmp_addr = identify_data_addr+0xad;//28bits or 48bits
	tmp1=read_code(g_tmp_addr);
	tmp1=tmp1&0xFB;//28bits
      SFR_ext_sram_addr = 0x00ad;
      SFR_ext_sram_data=tmp1;
    }	
	else if(security_mode == show_user) //24GB
    {
        SFR_ext_sram_addr = 0x0078;
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0xEE;
        SFR_ext_sram_data = 0x02;

        SFR_ext_sram_addr = 0x00C8;  //identify word 100-103
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0x00;
        SFR_ext_sram_data = 0xEE;
        SFR_ext_sram_data = 0x02;

	g_tmp_addr = identify_data_addr+0xad;//28bits or 48bits
	tmp1=read_code(g_tmp_addr);
	tmp1=tmp1&0xFB;//28bits
      SFR_ext_sram_addr = 0x00ad;
      SFR_ext_sram_data=tmp1;
    }	
	
    #endif

	#ifdef security_debug_chs
	g_tmp_addr = identify_data_addr+0x2;//number of logical cylinders
	tmp2.byte.h=read_code(g_tmp_addr);
	g_tmp_addr = identify_data_addr+0x3;//number of logical cylinders
	tmp2.byte.l=read_code(g_tmp_addr);
	myprintf("\ncylinders:%x%x",tmp2.byte.h,tmp2.byte.l);

	g_tmp_addr = identify_data_addr+0x6;//number of logical heads
	tmp2.byte.h=read_code(g_tmp_addr);
	g_tmp_addr = identify_data_addr+0x7;//number of logical heads
	tmp2.byte.l=read_code(g_tmp_addr);
	myprintf("\nheads:%x%x",tmp2.byte.h,tmp2.byte.l);

	g_tmp_addr = identify_data_addr+0xC;//sectors per track
	tmp2.byte.h=read_code(g_tmp_addr);
	g_tmp_addr = identify_data_addr+0xD;//sectors per track
	tmp2.byte.l=read_code(g_tmp_addr);
	myprintf("\nsectors:%x%x",tmp2.byte.h,tmp2.byte.l);
	
	#endif
		
    SFR_ext_sram_addr = 0x0104;   //siganature
    SFR_ext_sram_data = 0x53;  //S
    SFR_ext_sram_data = 0x41;  //A
    SFR_ext_sram_data = 0x47;  //G
    SFR_ext_sram_data = 0x45;  //E
	SFR_ext_sram_cntl = 0x00;	//disable auto increae of the sram address
	
	
	
	
	tmp = gen_check_sum();
	SFR_ext_sram_addr = 0x01ff;
	SFR_ext_sram_data = tmp;

	//send PIO_SETUP_FIS
	tx_fis_5f(status_drq, error_no, pm_pio_read, 0x01, 0x00, status_good);
	//burst it to sata host
	sata_burst(PIO_READ,0x01);
    if(sata_burst_abort)
    {
        tx_fis_34(status_bad,error_abort,int_set);
        reset_engine();
        #ifdef SUPPORT_SMART1
        updata_smart(smart_crc_num_addr,0x01);
        reset_engine();
        #endif
	    return;
    }
}
Ejemplo n.º 22
0
void chp_clock_off()
{    
	//smart data handle
	#ifdef SUPPORT_SMART1
	if(g_smart_read_handle == 1)	
	{
		updata_smart(smart_read_addr,g_smart_read_cnt);
		g_smart_read_cnt = 0x00;
		g_smart_read_handle = 0;
	}
	if(g_smart_write_handle == 1)	
	{
		updata_smart(smart_write_addr,g_smart_write_cnt);
		g_smart_write_cnt = 0x00;
		g_smart_write_handle = 0;
	}
    reset_engine();
	#endif
	
    #ifdef ENABLE_PRINT_CHP
    sata.uart_status = sata.uart_status&(~0x40); //set CHP interrupt disable: bit 6 in uart_status
    #endif
    //for continue command, CHP is waiting for the STOP command
    //we need to let it finish the data transmission to lower layer(SD/MMC)
    reset_engine();
    sata.led0_blink = 0x0f;
   // reset_auto_read;
   // reset_dma_engine();
    
    if(check_sd_mode)         //if chp0 connect to sd/mmc
    {
        //power saving: close the CHP clock
        sata.CHP_cmd = CHP_CMD_SHUTDOWN_CLOCK;
        //wait for command sync to CHP
        delay(10);
        //reset CPU and close clock
        sata.CHP_clock_set = 0x80 | 0x40 | 0x00; 
		//sata.CHP_clock_set = ((DFT_CHP_CLOCK_SET | 0x80 | 0x40) & 0xf0); 
    }
	else
	{
        sata.CHP_cmd = CHP_CMD_FLASH_SLEEP;
		wait_chp_not_ready();
		delay(100);
	}
	g_chp_active = 0;
    g_cont_en = 0;
    #ifdef ENABLE_PRINT_CHP
    sata.uart_status = sata.uart_status | 0x40; //set CHP interrupt enable: bit 6 in uart_status
    #endif

    
#ifdef ENABLE_SUP_CLK_OFF
	
    myprintf("\noff");
    sata.ncq_cntl = sata.ncq_cntl | ncq_cntl_block_rdy;
	delay(5); //wait for block R_RDY to take effect
	if((sata.ncq_cntl & ncq_cntl_link_idle) == 0x00)goto chp_clock_off_over;
	if(g_current_fis_num != SFR_fis_num)goto chp_clock_off_over;
    sata.power_cntl |= power_cntl_en_sleep;
	delay(30);
	chp_clock_off_over:
	sata.ncq_cntl = sata.ncq_cntl & (~ncq_cntl_block_rdy);
#endif

    
}
Ejemplo n.º 23
0
void chs_write_handle()
{
	//reset_engine();
	check_chs();
	reset_engine_read_write();	//reset_engine and check srst in wait rdy	
	if(g_current_fis_num != SFR_fis_num)return;
    
    #ifdef READ_ONLY  
		#ifdef BUF_CMD_EN
			buf_check_cnt = 0x00;
		#endif
    if(read_only_flag == read_only_enable) 
    {
        SFR_smart_load = smart_load_sata_cnt;
        set_burst_run_wr;
    }
    else 
	#endif
    {
        sata.CHP_cmd = CHP_CMD_WRITE;
    	g_cont_en = 1;
    	SFR_smart_load = smart_load_chp_cnt | smart_load_sata_cnt;
    	SFR_dma_base = 0x0000;
    	set_dma_run_wr;
	}
	
	#ifdef security_debug_chs		
	enable_fetch_lba;
	myprintf("\nCHSw0: %x %x %x %x %x %x ",sata.SUP_LBA5,sata.SUP_LBA4,sata.SUP_LBA3,sata.SUP_LBA2,sata.SUP_LBA1,sata.SUP_LBA0);
	disable_fetch_lba;	
	#endif	
	
chs_write_cont:
	while(!sata_burst_done)
		{
		if(g_current_fis_num != SFR_fis_num)return;
		}
	if(sata_burst_abort)goto chs_write_err;	
    
    #ifdef READ_ONLY
    if(read_only_flag == read_only_enable)
	{
		tx_fis_34(status_good,error_no, int_set);
		goto chs_write_over;
	} 
    #endif
    
	while(!dma_done)
		{
		if(g_current_fis_num != SFR_fis_num)return;
		}

	tx_fis_34(status_good,error_no, int_set);
	if(((sata.CHP0_status_high & 0x80) == 0x80)||((sata.CHP1_status_high & 0x80) == 0x80)||((sata.CHP2_status_high & 0x80) == 0x80)||((sata.CHP3_status_high & 0x80) == 0x80)||((sata.CHP4_status_high & 0x80) == 0x80)) 
    {
       goto chs_write_over;
    }
	clear_dma_run;

	
	soft_lba_add();
	
	#ifdef security_debug_chs		
	enable_fetch_lba;
	myprintf("\nCHSw0: %x %x %x %x %x %x ",sata.SUP_LBA5,sata.SUP_LBA4,sata.SUP_LBA3,sata.SUP_LBA2,sata.SUP_LBA1,sata.SUP_LBA0);
	disable_fetch_lba;	
	#endif	
	
	//check whether there is another continue command
	SFR_watch_dog_high = 0x00;
	while(1)
    {
        if(g_current_fis_num != SFR_fis_num)
        {
            check_sec_cnt();
           // check_lba();
            if((SFR_FIS0_2 == ata_write_dma) && check_chs_cmd)
			{
			    //if not continue
			    if(chs_cmp_lba()==0x00)break;
			    
				g_current_fis_num = SFR_fis_num;  
			    sata.ncq_cntl = (sata.ncq_cntl & (~ncq_cntl_new_fis27));
                SFR_smart_load = smart_load_chp_cnt | smart_load_sata_cnt;
	            SFR_dma_base = 0x0000;
	            set_dma_run_wr;
                goto chs_write_cont;
            }
            else  break;
        }
        if(sata.watch_dog_cnt_low > 0x04) break;
    }
	goto chs_write_over;

chs_write_err:
    tx_fis_34(status_bad,error_abort,int_set);
	#ifdef SUPPORT_SMART1
    updata_smart(smart_crc_num_addr,0x01);
    #endif
chs_write_over:
	reset_engine();
	return;
}
Ejemplo n.º 24
0
void main()
{	
	 init(0x00);
	 
	 /* wait EFM32 to choose a partition or ATA password is supported*/
	 #ifdef GPIO_security
	  GPIO_security_init();	 
	 //security_nd_chk = security_cmd_info_read(scl_security_nd_chk);//security function need or not 
	 //myprintf("\nsysmode:%c",security_nd_chk);
	 
	 //while(/*(security_nd_chk=='Y') && */(!g_security_enable) && (security_mode !=show_master) && (security_mode !=show_user) && (security_mode !=show_all))
	 //	{
	 //	GPIO_security_cmd(1);
	//	myprintf("\nwait chk");
	//	uart_show=0x1;
	// }
	 //init();
	 #endif
	 
	   
    while(1)
    {
  
	#ifdef SUPER_ERASE

	#ifdef GPIO_security
	if((security_mode !=show_master) && (security_mode !=show_user) && (security_mode !=show_all))
	{
		g_security_lock=1;
	 	GPIO_security_cmd(0x01);
	}
	else
	{
		g_security_lock=0;
		if(g_SYS_YD==0x01)
		{
		  GPIO_security_cmd(0x00);
		}
		else
		{  	//myprintf("\nwhile erase");
		  GPIO_security_cmd(0x01);
		}
	}
		
	#endif
	
	
	if((security_erase==show_master) ||(security_erase==show_user))
	 	{
		security_cmd_info_write('N', scl_security_nd_chk);//need reconfig
		myprintf("\nes0");
		intial_data_partition(0);//erase partition
		security_erase=0x00;
		myprintf("\ned0");
	}
	else if(security_erase==show_all)
		{
		security_cmd_info_write('N', scl_security_nd_chk);//need reconfig
		myprintf("\nes0");
		intial_data_partition(1);//erase partition
	  	security_erase=0x00;
		myprintf("\ned1");
	}


	 if(uart_show)
	 	{
		  if(security_mode == show_master)
		  	{
			myprintf("\nmaster mode");
			uart_show=0;
		  }
		  else if(security_mode == show_user)
		  	{
			myprintf("\nuser mode");
			uart_show=0;
		  }
		  else if(security_mode == show_all)
		  	{
			myprintf("\nzsd mode");
			uart_show=0;
		  }
		  tx_fis_A1(status_good, error_no, int_set);

		  init(0x01);
	 	}

	 #endif
	 
	#ifdef security_debug
	  myprintf("\rSV:%x",SFR_spi_io);
	#endif

	#ifdef BUF_CMD_EN
            //todo: if NCQ error, need additional control here???
                cmd_buffer_check();
        #endif
        //check new fis received from host(exclude data fis)
        //sata.led0_cntl = 0x80;      //rom is using 0xd4
        if(g_current_fis_num != SFR_fis_num)
        { 
            //sata.led0_cntl = 0x00;      //rom is using 0xd4
            sata.led0_blink = 0x44;
            //myprintf("\nSR0:%x",SFR_FIS0_1);
            //todo: add an led1 here.
            //myprintf("\nfine a new cmd:%x",SFR_FIS0_2);
            
            g_current_fis_num = SFR_fis_num;
            
            //clear the fis27 flag.
            sata.ncq_cntl = (sata.ncq_cntl & (~ncq_cntl_new_fis27));
            
            //if in SLEEP mode, only respond to SRST. Please refer to ATA8 Charpter 7.55.2
            
			//TODO: need to open this after this is tested.
            //if(g_power_mode == power_mode_sleep)goto check_control; 

			
            #ifdef SUPPORT_NCQ
            if(g_ncq_halt)
            {
               if(check_ncq_read_log);
               //else goto Over;
               else continue;
            }
			#endif
            
            //open the CHP clock
            chp_clock_on();
			
            #ifdef SUPPORT_SMART1
            if(g_smart_power_down_flag == 1)
            {
                updata_smart(smart_power_down_addr,0x01);
                g_smart_power_down_flag = 0;
                reset_engine();
            }
            #endif

            //this will load the sector count
            check_sec_cnt();
            //myprintf("\nsec_cnt:%x",g_sec_cnt.byte.l);
            check_lba();
		//myprintf("\nLBAchk0:%x");
		
            if(SFR_quick_cmd!=0)
            {
                #ifdef SUPPORT_SECURITY
                //analyze_states();
                g_security_prepared = 0;
                if(g_security_lock == 1) 
                {
                tx_fis_34(status_bad, error_abort,int_set);
                }
                else
                #endif
                {
                    #ifdef BUF_CMD_EN
                    if(SFR_quick_cmd & quick_cmd_write_dma)
                    {

                        //break buffer command flow:
                        //(1)continue command
                        //(2)chs mode command
                        //(3)counter > threshold
    					if(check_chs_cmd)
    					{
    						if(buf_not_empty) g_current_fis_num--;
    						else
    						{ 
    							chs_write_handle();
    							buf_check_cnt = 0x00;
    						}
    					}
                        else if(normal_cmd_cont || (g_sec_cnt.word == 0x0000) || (g_sec_cnt.byte.h!=0x00) || (g_sec_cnt.byte.l >BUF_SEC_CNT_THRESHOLD) ||(g_enable_write_cache == 0))
                        {
                             
                             if(buf_not_empty) g_current_fis_num--;
                             else
                             {
                                write_handler();
                                buf_check_cnt = 0x00;
                             }
                             
                        } 
                        else if(buf_check_cnt<BUF_START_CNT)
                        {
                            if(buf_not_empty) g_current_fis_num--;
                            else
                            {
                               write_handler();
                               buf_check_cnt++;
                            }
                        }
                        else
                        {      
                             //check_lba();
                             //the if will not happen
                             if(g_flag_lba_err)
                             {
                                 tx_fis_34(status_bad,error_abort,int_set);
                                 reset_engine();
                             }
                             else
                             {
                                 buf_sector_num.word = 0;
                                 buf_cmd_flag = DEF_CHP_EN;
                                 cmd_buffer_set_param();
                                 //TODO: add reset_engine here???
                                 g_cont_en = 0;
                             }
                         }
                    }
                    //need to flush all data in FIFO before other commands
                    else if(buf_not_empty)g_current_fis_num--;                     
                    #else
                    if(SFR_quick_cmd & quick_cmd_write_dma)
                    {
    					if(check_chs_cmd)chs_write_handle();
    					else write_handler();
                    }
                    #endif
                    
                                                      
                 
                    //(2)this is read_dma or read_dma_ext
                    else if(SFR_quick_cmd & quick_cmd_read_dma)
                    {  
                       // myprintf("\nr");
    				   if(check_chs_cmd)chs_read_handle();
                       else read_handler();
     
                    }
                    else if(SFR_quick_cmd & (quick_cmd_write_mul | quick_cmd_write_sec))  
                    {              
                        g_flag_dir = DIR_WRITE;
                        pio_write_handler();              
                     }   
                    
                    //(4)read pio: read_sector([ext]) or read_multiple([ext])
                    //else if((SFR_quick_cmd&quick_cmd_read_mul) || (SFR_quick_cmd&quick_cmd_read_sec));
                    else if(SFR_quick_cmd & (quick_cmd_read_mul | quick_cmd_read_sec))
                    {
                       g_flag_dir = DIR_READ;
                       pio_read_handler();
                    }
                    g_power_mode = power_mode_act;
                }
            }
            else if(SFR_FIS0_0 == 0x27)//this is H2D fis
            { 
                #ifdef BUF_CMD_EN
                if(buf_not_empty)g_current_fis_num--; 
                else if((SFR_FIS0_1 & 0x80) !=0) //this is a command, not control
                #else
                if((SFR_FIS0_1 & 0x80) !=0) //this is a command, not control
                #endif
                {
                    #ifdef SUPPORT_SECURITY
                    if(SFR_FIS0_2 != ata_security_erase_unit) g_security_prepared = 0;
                    #endif
                    if(SFR_FIS0_2 == ata_write_dma_fua_ext)
                    {
                        write_handler();
					    g_power_mode = power_mode_act; 
                    }
                    else if(SFR_FIS0_2 == ata_write_multi_fua_ext)
                    {
                        g_flag_dir = DIR_WRITE;
                        pio_write_handler(); 
						g_power_mode = power_mode_act;                        
                    }
                    
                    #ifdef SUPPORT_NCQ
                    else if(SFR_FIS0_2 == ata_read_fpdma)
                    {
                        g_flag_dir = DIR_READ;
                        ncq_resp_cmd();
                        g_power_mode = power_mode_act;
                    }
                    else if(SFR_FIS0_2 == ata_write_fpdma)
                    {
                        g_flag_dir = DIR_WRITE;
                        ncq_resp_cmd();
                        g_power_mode = power_mode_act;
                    }
                    #endif
                    else
                    {
                        reset_engine();
                        switch(SFR_FIS0_2)//this is the ata command index
                        {  
                        
                            //NCQ
                            #ifdef SUPPORT_NCQ
                        
                            case ata_ncq_management:
                            {
                                ncq_management_hander();
                                g_power_mode = power_mode_act;
                                break;
                            }
                        
                            case ata_read_log_ext:
                            {
                                ncq_read_log();
                                g_power_mode = power_mode_act;
                                break;
                            }        
                            case ata_read_log_dma_ext:
                            {
                                ncq_read_log();
                                g_power_mode = power_mode_act;
                                break;
                            }
                        
                            #endif
                        ///////////////////////////////////////////////////
                        ///////////BASIC
                        ///////////////////////////////////////////////////
                            case ata_nop:                   
                            {
                                //note: sub-code is used for overlapped feature support.
                                tx_fis_34(status_bad, error_abort,int_set); 
                                break;
                            }
                            case  ata_seek:	
                            {
                                //this is sent by host to signify the device that it may access the specified address in the following commands
                            
                                if(g_flag_lba_err) tx_fis_34(status_bad,error_abort, int_set);
                                else tx_fis_34(status_good,error_no,int_set);
                                g_power_mode = power_mode_act;
                                break;							
                            }
                            case ata_recalibrate:
                            {
                                //this is vendor specific - ATA4
                                tx_fis_34(status_good,error_no,int_set);
                                break;
                            }
                            case ata_exec_diag:
                            {
                                init_tx_fis();
                                tx_fis_34(status_bad&0xf2,0x01,int_set);       //0x01h indicated device0 passed and device1 not present
                                break;
                            }
                            case  ata_init_dev_para:	
                            {
                                //this is to set CHS translation.
                                //todo: change the setting of hardware operation: CHS translation.
                                init_dev_para();
                                break;							
                            }
                            case ata_flush_cache:
                            {
                            //TODO: flush the CHPs.
                            //This command is used by the host to request the device to flush the write cache. If there is data in the write
                            //cache, that data shall be written to the media. This command shall not indication completion until the data is
                            //flushed to the media or an error occurs.
                            //NOTE . This command may take longer than 30 s to complete.
                                flush_delay();
                                tx_fis_34(status_good,error_no,int_set);
                                g_power_mode = power_mode_act;
                                break;
                            }
                            case ata_flush_cache_ext:
                            {
                            	flush_delay();
                                tx_fis_34(status_good,error_no,int_set);
                                g_power_mode = power_mode_act;
                                break;
                            }
                            case ata_read_verify: //this command wasn't completed, the write protect error should be took into accout
                            {
                                if(g_flag_lba_err) tx_fis_34(status_bad,error_abort, int_set);
                                else tx_fis_34(status_good,error_no,int_set);
                                g_power_mode = power_mode_act;
                                break;	
                            }
                            case ata_read_verify_ext:  //this command wasn't completed, the write protect error should be took into accout
                            {
                                if(g_flag_lba_err) tx_fis_34(status_bad,error_abort, int_set);
                                else tx_fis_34(status_good,error_no,int_set);
                                g_power_mode = power_mode_act;
                                break;	
                            }

                            #ifdef SUPPORT_SMART

                            case ata_smart:
                            {
                                //myprintf("\nsmart_handler");
                                smart_handler();
                                break;
                            }
                        
                            #endif

                       
                        case ata_data_set_management:
                        {
                            #ifdef SUPPORT_TRIM
                           //#if 0
                                //if(check_sd_mode) tx_fis_34(status_good,error_no,int_set);
                                //else 
                                if((sata.FIS_seccnt_ext !=0)||(sata.FIS_seccnt >0x20)||((sata.FIS_seccnt_ext==0)&&(sata.FIS_seccnt==0)))
                                {
                                     tx_fis_34(status_good,error_no,int_set);
                                }
                                else  trim_handler();
                            #else
                                tx_fis_34(status_good,error_no,int_set);
                            #endif
                            
                            break;
                            
                        }
                        

                            ////////////////////////////////////////////////////
                            /////POWER MANAGEMENT FEATURE SET
                            ////////////////////////////////////////////////////
                            case ata_chk_power_mode:
                            {
                                sata.FIS_seccnt=g_power_mode;
                                tx_fis_34(status_good,error_no,int_set);
                            
                                break;
                            }
                            case ata_idle:
                            {
                                flush_delay();
                                g_power_mode=power_mode_idle;
                                tx_fis_34(status_good,error_no,int_set);
                                break;
                            } 
                            case ata_idle_imd:
                            { 
                                flush_delay();
                                g_power_mode=power_mode_idle;
                                tx_fis_34(status_good,error_no,int_set);
                                break;                                                                                                
                            }
                            case ata_sleep:
                            {  
                                flush_delay();
                                g_power_mode=power_mode_sleep;
                                tx_fis_34(status_good,error_no,int_set);
                                break;                                                                             
                            }
                            case ata_standby:
                            {
                                flush_delay();
                                g_power_mode=power_mode_standby;
                                tx_fis_34(status_good,error_no,int_set);                           
                                break; 
                            }
                            case ata_standby_imd:
                            {  
                                flush_delay();
                                g_power_mode=power_mode_standby;
                                tx_fis_34(status_good,error_no,int_set);
                                break;                                                                                                       
                            }
                        
                        ///////////////////////////////////////////////////////
                        ///////////////////////////////////////////////////////
                            case ata_identify_device:
                            {
                                identify_device();
                                break;
                            }
                            case ata_set_multiple:
                            { 
                                if(sata.fis_rcv_content[4*3+0] == 0x01)
                                {
                                // we support transmitting 1 sector per multiple operation only, so the identify_data[59] low will not change                      
                                /*
                                                        identify_data[59] &= 0xff00;
                                                        identify_data[59] |=0x0001; 
                                                        */
                                    tx_fis_34(status_good,error_no,int_set);
                                    break;
                                }  
                                else
                                {
                                    tx_fis_34(status_bad,error_abort,int_set);
                                    break;
                                }
                            }
                            case ata_set_feature:
                            {
							    set_feature();
                                //tx_fis_34(status_good,error_no,int_set);
                                break;
                            }
    					    case ata_security_freeze_lock:  //ok
                            {
                                #ifdef SUPPORT_SECURITY
                               if(g_security_lock == 1)
                                {
                                    tx_fis_34(status_bad, error_abort,int_set);
                                }
                                else
                                {
                                    if(g_security_enable == 0) security_state_flag = SEC2;
                                    else security_state_flag = SEC6;
                                    analyze_states();
                                    tx_fis_34(status_good,error_no,int_set);
                                }
                                #else
                                tx_fis_34(status_good,error_no,int_set);
                                #endif
                                break;	
                            }

                            //////////////////////////////////////////////////
                            #ifdef SUPPORT_SECURITY

			        case ata_security_erase_pre:   /* BIOS没有权限擦除硬盘,所以直接返回 */
                            {
                                if(g_security_frozen == 1)
                                {
                                    g_security_prepared = 0;
                                    tx_fis_34(status_bad, error_abort,int_set);
                                }
                                else
                                {
                                    //g_security_prepared = 1;
                                   // security_state_flag = SEC4;
                                    tx_fis_34(status_good,error_no,int_set);
                                }
                                //analyze_states();
                                break;
                            }

				case ata_security_erase_unit:       /* BIOS没有权限擦除硬盘,所以直接返回 */
                            {
                                if(g_security_frozen == 1)
                                {
                                    g_security_prepared = 0;
                                    tx_fis_34(status_bad, error_abort,int_set);
                                }
                                else
                                {
                                   /*if(g_security_prepared == 0) g_security_abort = 1;
                                    else security_erase_unit();
                                    if(g_security_abort == 1) 
                                    {
                                        g_security_abort = 0;
                                        tx_fis_34(status_bad, error_abort,int_set);
                                    }
                                    else 
                                    {
                                        g_security_prepared = 0;
                                        security_state_flag = SEC1;*/
                                        tx_fis_34(status_good,error_no,int_set);
                                    /*}    
                                    analyze_states();*/
                                }
                                break;
                            }
				
                            case ata_security_dis_pwd:      //ok
                            {
				   //此处删掉frozen下不能取消密码功能,dell 1014 进入bios的时候已经frozen了
				    if(/*(g_security_frozen == 1) ||*/ (g_security_lock == 1))
                                {
                                    g_security_prepared = 0;
                                    tx_fis_34(status_bad, error_abort,int_set);
                                }
                                else
                                {
                                    security_dis_pwd();
                                    if(g_security_abort == 1) 
                                    {
                                        g_security_abort = 0;
                                        tx_fis_34(status_bad, error_abort,int_set);
                                    }
                                    else 
                                    {
                                        security_state_flag = SEC1;
                                        tx_fis_34(status_good,error_no,int_set);
                                    }
                                    analyze_states();
                                }
                                break;
                            }
                            
                            case ata_security_set_pwd:  //ok
                            {
                                if((g_security_frozen == 1) )
                                {
                                    g_security_prepared = 0;
                                    tx_fis_34(status_bad, error_abort,int_set);
                                }
                                else
                                {
                                    security_set_pwd();
                                    if(g_security_abort == 1) 
                                    {
                                        g_security_abort = 0;
                                        tx_fis_34(status_bad, error_abort,int_set);
                                    }
                                    else tx_fis_34(status_good,error_no,int_set);
                                    analyze_states();
                                }
                                break;
                            }
                            
                            case ata_security_unlock:   //ok
                            {
                                //analyze_states();
				    	//myprintf("\nunlock");
                                security_unlock();
                                if(g_security_abort == 1) 
                                {
                                    g_security_abort = 0;
                                    tx_fis_34(status_bad, error_abort,int_set);
                                }
                                else 
                                {
                                    
                                    security_state_flag = SEC5;
                                    tx_fis_34(status_good,error_no,int_set);
                                }
                                analyze_states();
                                break;
                            }
                            #endif
                            ///////////////////////////////////////////////
                            
							#ifdef SUPER_ERASE
							case ata_down_microcode:
							{
                                if(sata.FIS_feature == 0xCC)//super erase
								{
								    intial_data_partition(1);//erase all
								   // security_erase_pa(1);
								    tx_fis_34(status_good,error_no,int_set);
                                    break;
                                }
								else 
								{
									tx_fis_34(status_bad, error_abort,int_set); 
									break;
								}
							}
							#endif

							#ifdef READ_ONLY
                            case ata_read_only:
                            {
                                choose_mode();
                                break;
                            }
                            #endif
							
                            default :
							{
                                tx_fis_34(status_bad, error_abort,int_set); 
                                break;
                            }
                        }
                    }
                }
                
                else //control command process 
                {
                    #ifdef BUF_CMD_EN
                    buf_data_pending = 0;
                    #endif
                    reset_engine();
                    //check_control:
                    //IF SRST
                    if((SFR_cmd_aux & 0x01)!=0) 
                    {
                        //wait until SRST is deasserted.
                        while((sata.fis_rcv_content[15] & 0x04)==0x04);
                        //clear the fis27 flag.
                        //sata.ncq_cntl = (sata.ncq_cntl & (~ncq_cntl_new_fis27));
                        //hardware latch the SRST state, firmware clear it.
                        SFR_cmd_aux = 0x00;
                        g_current_fis_num = SFR_fis_num;
                        //only resonse when SRST is not set                        
                    }

                    //also response the other controls without SRST bit set.
                    if(g_power_mode != power_mode_sleep)
                    {
                        init_tx_fis();
						//reset link(bit2) and transport(bit3).
						//if SRST, we may recover from abnormal state
                        sata.rst_cntl = sata.rst_cntl | 0x0C;
                        delay(5);
						sata.ncq_cntl = (sata.ncq_cntl & (~ncq_cntl_new_fis27));
                        tx_fis_34(status_good,0x01,int_no);
                        #ifdef SUPPORT_SMART1
                        updata_smart(smart_softrst_num_addr,0x01);
                        reset_engine();
                        #endif
                    }
                }
            }
            else if(SFR_FIS0_0 == 0x58)
            {
                bist_handler();
            }
            SFR_watch_dog_high = 0x00;
        }
        else
        {
            //(1)if current loop has command, not handle DMA setup
            //(2)if current loop handle DMA setup, not send SET DEV BITS FIS
            //(3)otherwise send SET_DEV_BITS FIS
            #ifdef SUPPORT_NCQ
            ncq_handler();
            #endif
        }
		#ifdef SUPPORT_SMART1
        if(check_sd_mode) smart_card_crc();
		else smart_block_handle();
		#endif
        
        /*
		if(g_power_mode == power_mode_idle)
		{
			if(SFR_watch_dog_high >= 0x20)	g_power_mode = power_mode_standby;			
		}
		*/
		if((SFR_watch_dog_high > 0x30) && g_chp_active)chp_clock_off();
    }
    
}
Ejemplo n.º 25
0
void 
load_and_score_sgf_file(SGFTree *tree, Gameinfo *gameinfo, 
			const char *scoringmode)
{
  int move;
  float move_value;
  char *tempc = NULL;
  char text[250];
  char winner;
  int next;
  int pass = 0;
  int method;
  float score;
  SGFTree local_tree;
  SGFTree *score_tree = tree;
  
  /* Default scoring method is ESTIMATE since it's fastest. */
  method = ESTIMATE;
  if (strcmp(scoringmode, "finish") == 0)
    method = FINISH;
  else if (strcmp(scoringmode, "aftermath") == 0)
    method = AFTERMATH;

  /* For aftermath scoring we compress the previous moves to a static
   * board position in the output sgf. This helps a lot when debugging
   * scoring mistakes. We don't do this for the finish method,
   * however, since users may be better served by having GNU Go's
   * selfplay added to the original game record.
   */
  if (method == AFTERMATH) {
    sgftree_clear(&local_tree);
    /* Modify komi to compensate for captured stones. We start at a
     * setup position and since there is no standard sgf property to
     * tell the number of captured stones, a modified komi is the best
     * available solution.
     */
    sgftreeCreateHeaderNode(&local_tree, board_size,
			    komi + black_captured - white_captured, handicap);
    sgffile_printboard(&local_tree);
    sgfAddProperty(local_tree.lastnode, "PL",
		   gameinfo->to_move == WHITE ? "W" : "B");
    score_tree = &local_tree;
  }
  
  next = gameinfo->to_move;
  reset_engine();
  
  /* Complete the game by selfplay for the finish and aftermath methods. */
  if (method != ESTIMATE) {
    doing_scoring = 1;
    while (pass < 2) {
      move = genmove_conservative(next, &move_value);
      if (move != PASS_MOVE) {
	pass = 0;
	gprintf("%d %s move %1m\n", movenum,
		next == WHITE ? "white (O)" : "black (X)", move);
      }
      else {
	pass++;
	gprintf("%d %s move PASS\n", movenum, 
		next == WHITE ? "white (O)" : "black (X)");
      }
      play_move(move, next);
      sgffile_add_debuginfo(score_tree->lastnode, move_value);
      sgftreeAddPlay(score_tree, next, I(move), J(move));
      sgffile_output(score_tree);
      next = OTHER_COLOR(next);
    }
    doing_scoring = 0;
  }
  
  /* Calculate the score. */
  if (method == AFTERMATH)
    score = aftermath_compute_score(next, score_tree);
  else
    score = gnugo_estimate_score(NULL, NULL);
  
  if (score < 0.0) {
    sprintf(text, "Black wins by %1.1f points\n", -score);
    winner = 'B';
  }
  else if (score > 0.0) {
    sprintf(text, "White wins by %1.1f points\n", score);
    winner = 'W';
  }
  else {
    sprintf(text, "Jigo\n");
    winner = '0';
  }
  fputs(text, stdout);
  sgftreeAddComment(score_tree, text);

  /* For the finish and aftermath methods we compare the score with
   * what's stored in the game record.
   *
   * FIXME: No comparison is made if the stored result was 0. Wins by
   *        time or forfeit are not handled either.
   *
   * FIXME: Does anybody actually care about this information? Just
   *        removing this piece of code is a tempting alternative.
   */
  if (method != ESTIMATE && sgfGetCharProperty(tree->root, "RE", &tempc)) {
    char dummy;
    float result;
    if (sscanf(tempc, "%1c%f", &dummy, &result) == 2) {
      fprintf(stdout, "Result from file: %c+%1.1f\n", dummy, result);
      fputs("GNU Go result and result from file are ", stdout);
      if (result == fabs(score) && winner == dummy)
	fputs("identical\n", stdout);
      else
	fputs("different\n", stdout);
      
    }
    else {
      if (tempc[2] == 'R') {
	fprintf(stdout, "Result from file: Resign\n");
	fputs("GNU Go result and result from file are ", stdout);
	if (tempc[0] == winner)
	  fputs("identical\n", stdout);
	else
	  fputs("different\n", stdout);
      }
    }
  }

  if (method != ESTIMATE)
    sgfWriteResult(score_tree->root, score, 1);
  
  sgffile_output(score_tree);
}
void
decide_string(int pos)
{
  int aa, dd;
  int acode, dcode;
  SGFTree  tree;
  
  if (board[pos] == EMPTY) {
    fprintf(stderr, "gnugo: --decide-string called on an empty vertex\n");
    return ;
  }

  if (*outfilename)
    sgffile_begindump(&tree);

  /* Prepare pattern matcher and reading code. */
  reset_engine();

  count_variations = 1;
  acode = attack(pos, &aa);
  if (acode) {
    if (acode == WIN)
      gprintf("%1m can be attacked at %1m (%d variations)\n", 
	      pos, aa, count_variations);
    else if (acode == KO_A)
	gprintf("%1m can be attacked with ko (good) at %1m (%d variations)\n", 
	      pos, aa, count_variations);
    else if (acode == KO_B)
	gprintf("%1m can be attacked with ko (bad) at %1m (%d variations)\n", 
		pos, aa, count_variations);

    if (debug & DEBUG_READING_PERFORMANCE) {
      gprintf("Reading shadow: \n");
      draw_reading_shadow();
    }

    count_variations = 1;
    dcode = find_defense(pos, &dd);
    if (dcode) {
      if (dcode == WIN)
	gprintf("%1m can be defended at %1m (%d variations)\n", 
		pos, dd, count_variations);
      else if (dcode == KO_A)
	gprintf("%1m can be defended with ko (good) at %1m (%d variations)\n", 
		pos, dd, count_variations);
      else if (dcode == KO_B)
	gprintf("%1m can be defended with ko (bad) at %1m (%d variations)\n", 
		pos, dd, count_variations);
    }
    else
      gprintf("%1m cannot be defended (%d variations)\n", 
	      pos, count_variations);
    if (debug & DEBUG_READING_PERFORMANCE) {
      gprintf("Reading shadow: \n");
      draw_reading_shadow();
    }

  }
  else {
    gprintf("%1m cannot be attacked (%d variations)\n", 
	    pos, count_variations);
    if (debug & DEBUG_READING_PERFORMANCE) {
      gprintf("Reading shadow: \n");
      draw_reading_shadow();
    }
  }

  sgffile_enddump(outfilename);
  count_variations = 0;
}
Ejemplo n.º 27
0
void read_handler()
{
    u8 temp_sel, temp8;
    u8 temp_lba_low;
	u8 boundary_check;

#ifdef security_debug
	enable_fetch_lba;
	myprintf("\nLBAr0: %x %x %x %x %x %x ",sata.SUP_LBA5,sata.SUP_LBA4,sata.SUP_LBA3,sata.SUP_LBA2,sata.SUP_LBA1,sata.SUP_LBA0);
	disable_fetch_lba;
#endif

    //the first coming in will always be considered as not continue
    //if not continue
    {
       // check_lba();
        temp_lba_low = sata.SUP_LBA0;
		reset_engine_read_write();	//reset_engine and check srst in wait rdy	
		if(g_current_fis_num != SFR_fis_num)return;
		
#ifdef security_debug
	enable_fetch_lba;
	myprintf("\nLBAr1: %x %x %x %x %x %x ",sata.SUP_LBA5,sata.SUP_LBA4,sata.SUP_LBA3,sata.SUP_LBA2,sata.SUP_LBA1,sata.SUP_LBA0);
	disable_fetch_lba;
#endif

        sata.CHP_cmd = CHP_CMD_READ;
        SFR_smart_load = smart_load_chp_cnt | smart_load_sata_cnt;
        SFR_dma_base = 0x0000;
        SFR_dma_cntl = 0xdc; //we will enable preread
        g_cont_en = 1;
        temp_sel = 0x00;
		if(STRIPE_8K_SET)boundary_check = 0x0f;
		else if(STRIPE_4K_SET)boundary_check = 0x07;
		else boundary_check = 0x03;
    }
read_cont:
    if(SFR_CHP_en == 0x01)
    {
        while(!sata_burst_done)
        {
            temp8 = SFR_dma_done_num_l;
            if((((temp_lba_low + temp8) & boundary_check) == 0x00)&& (temp_sel != temp8))//4k  boundary
            {
                temp_sel = temp8;
                sata.CHP_cmd = CHP_CMD_NEXT_BURST;
            }
            if(g_current_fis_num != SFR_fis_num)return;
        }
    }
    else //not 1 channel
    {
        while(!sata_burst_done)
        {
     	    if(temp_sel != sata.chp_bus_sel)
		    {
			    sata.CHP_cmd_sel = temp_sel;
			    sata.CHP_cmd = CHP_CMD_NEXT_BURST;
			    temp_sel = sata.chp_bus_sel;
			    sata.CHP_cmd_sel = 0xff;
     	    }
		    if(g_current_fis_num != SFR_fis_num)return;
        }
    }
  
    if(sata_burst_abort)goto read_handler_err;
    tx_fis_34(status_good,error_no, int_set);
    if(((sata.CHP0_status_high & 0x80) == 0x80)||((sata.CHP1_status_high & 0x80) == 0x80)||((sata.CHP2_status_high & 0x80) == 0x80)||((sata.CHP3_status_high & 0x80) == 0x80)||((sata.CHP4_status_high & 0x80) == 0x80)) 
    {
       goto read_handler_over;
    }
    //check whether there is continue command.
	SFR_watch_dog_high = 0x00;
    while(1)
     {
     	if(SFR_CHP_en != 0x01)
     	{
     		if(temp_sel != sata.chp_bus_sel)
			{
				sata.CHP_cmd_sel = temp_sel;
				sata.CHP_cmd = CHP_CMD_NEXT_BURST;
				temp_sel = sata.chp_bus_sel;
				sata.CHP_cmd_sel = 0xff;
     		}
     	}
		else
		{
			temp8 =  SFR_dma_done_num_l;
            if((((temp_lba_low + temp8) & 0x07) == 0x00)&& (temp_sel != temp8))//4k  boundary
            {
                temp_sel = temp8;
                sata.CHP_cmd = CHP_CMD_NEXT_BURST;
            }
		
		}
        if(g_current_fis_num != SFR_fis_num)
        {
            //normal_cmd_cont will only be updated when get a new command in RTL.
            //if it's a FIS27 - Control: normal_cmd_cont will stay in 1
            if(normal_cmd_cont && g_cont_en && ((SFR_quick_cmd & quick_cmd_read_dma) != 0x00) )
            {
                //to fix copy machine
                delay(1);
                //////////////////
                SFR_smart_load = smart_load_add_chp_cnt | smart_load_add_sata_cnt;
                sata_burst_cont = 1;
                //dma_cont = 1; //we have set pre-read, so this can be commented
                g_current_fis_num = SFR_fis_num;  
                sata.ncq_cntl = (sata.ncq_cntl & (~ncq_cntl_new_fis27));
                goto read_cont;
            }
            else break;
        }
        if(SFR_watch_dog_high > 0x20) break;
    }
    #ifdef SUPPORT_SMART1
	smart_read_cnt();
	#endif
	goto read_handler_over;	
	
read_handler_err:
    
    tx_fis_34(status_bad,error_abort,int_set);
	#ifdef SUPPORT_SMART1
    updata_smart(smart_crc_num_addr,0x01);
    #endif
	//I am not sure host will retry that command immediatelly, need to break the continue mode
read_handler_over:
	reset_engine();
	return;
}
Ejemplo n.º 28
0
void pio_write_handler()
{
    u8 idata pio_interrput;
    pio_interrput = pio_write_begin;
    if(g_flag_lba_err)goto pio_handler_err; 
	//(1)reset_engine and check srst in wait rdy	
	reset_engine_read_write();	
	if(g_current_fis_num != SFR_fis_num)return;
  
	//(2)write/read command to CHP
	#ifdef READ_ONLY
    if(read_only_flag == read_only_enable) 
	{
		SFR_sata_burst_cnt= 0x0001;
	}
	else
	#endif
    {
        sata.CHP_cmd = CHP_CMD_WRITE;
        SFR_dma_max_num = 0x0001;
    }
    //(3)loop of burst. we only support 512 byte data FIS for one PIO_SETUP FIS  
    do{    
       
        //myprintf("\nchp_en :%xchp_stripe:%x%x",SFR_CHP_en,sata.CHP_stripe_h,sata.CHP_stripe);
        
        {
            tx_fis_5f(status_drq, error_no, pm_pio_write|pio_interrput, g_sec_cnt.byte.l, g_sec_cnt.byte.h, status_bsy);
            pio_interrput = pio_write_next;
        }
        
        #ifdef READ_ONLY
        if(read_only_flag == read_only_enable) SFR_sata_burst_cntl = SFR_sata_burst_cntl_run;
        else 
        #else
		{
        	SFR_dma_cntl = SFR_dma_cntl_run | SFR_dma_cntl_conj;
		}
        #endif

       
        
        
        while(!sata_burst_done)
		{
		   if(g_current_fis_num != SFR_fis_num)return;
		}
        if(sata_burst_abort)goto pio_handler_err;

        #ifdef READ_ONLY
        if(read_only_flag == read_only_enable) ;
		else
        #endif
        {
           while(!dma_done)
		   {
	          if(g_current_fis_num != SFR_fis_num)return;
	       }
        }
        
		SFR_dma_cntl =  SFR_dma_cntl_conj;
        g_sec_cnt.word--;
		auto_increase_lba;
                
    }while(g_sec_cnt.word>0);
    sata.FIS_seccnt = g_sec_cnt.byte.l;
	sata.FIS_seccnt_ext = g_sec_cnt.byte.h;
	//smart data handle
	#ifdef SUPPORT_SMART1
    {
	    //smart data handle
     	smart_write_cnt();
    }
	#endif
    tx_fis_34(status_good,error_no,int_set);
    return;      
        
pio_handler_err:
	tx_fis_34(status_bad,error_abort,int_set);
    reset_engine();
    #ifdef SUPPORT_SMART1
    updata_smart(smart_crc_num_addr,0x01);
    reset_engine();
    #endif
	return;
}
void 
load_and_score_sgf_file(SGFTree *tree, Gameinfo *gameinfo, 
			const char *scoringmode)
{
  int i, j, move_val;
  float result;
  char *tempc = NULL;
  char dummy;
  char text[250];
  char winner;
  int next;
  int pass = 0;
  SGFTree score_tree;
  
  sgftree_clear(&score_tree);
  sgftreeCreateHeaderNode(&score_tree, board_size, komi);
  sgffile_printboard(&score_tree);
  
  next = gameinfo->to_move;
  doing_scoring = 1;
  reset_engine();
  
  if (!strcmp(scoringmode, "finish") || !strcmp(scoringmode, "aftermath")) {
    do {
      move_val = genmove_conservative(&i, &j, next);
      if (move_val >= 0) {
	pass = 0;
	gprintf("%d %s move %m\n", movenum,
		next == WHITE ? "white (O)" : "black (X)", i, j);
      }
      else {
	++pass;
	gprintf("%d %s move : PASS!\n", movenum, 
		next == WHITE ? "white (O)" : "black (X)");
      }
      play_move(POS(i, j), next);
      sgffile_add_debuginfo(score_tree.lastnode, move_val);
      sgftreeAddPlay(&score_tree, next, i, j);
      sgffile_output(&score_tree);
      next = OTHER_COLOR(next);
    } while (movenum <= 10000 && pass < 2);

    if (pass >= 2) {
      /* Calculate the score */
      if (!strcmp(scoringmode, "aftermath"))
	score = aftermath_compute_score(next, komi, &score_tree);
      else
	score = gnugo_estimate_score(&lower_bound, &upper_bound);

      if (score < 0.0) {
	sprintf(text, "Black wins by %1.1f points\n", -score);
	winner = 'B';
      }
      else if (score > 0.0) {
	sprintf(text, "White wins by %1.1f points\n", score);
	winner = 'W';
      }
      else {
	sprintf(text, "Jigo\n");
	winner = '0';
      }
      fputs(text, stdout);
      sgftreeAddComment(&score_tree, text);
      if (sgfGetCharProperty(tree->root, "RE", &tempc)) {
	if (sscanf(tempc, "%1c%f", &dummy, &result) == 2) {
	  fprintf(stdout, "Result from file: %1.1f\n", result);
	  fputs("GNU Go result and result from file are ", stdout);
	  if (result == fabs(score) && winner == dummy)
	    fputs("identical\n", stdout);
	  else
	    fputs("different\n", stdout);
	      
	}
	else {
	  if (tempc[2] == 'R') {
	    fprintf(stdout, "Result from file: Resign\n");
	    fputs("GNU Go result and result from file are ", stdout);
	    if (tempc[0] == winner)
	      fputs("identical\n", stdout);
	    else
	      fputs("different\n", stdout);
	  }
	}
      }
      sgfWriteResult(score_tree.root, score, 1);
      sgffile_output(&score_tree);
    }
  }
  doing_scoring = 0;

  if (strcmp(scoringmode, "aftermath")) {
    /* Before we call estimate_score() we must make sure that the dragon
     * status is computed. Therefore the call to examine_position().
     */
    examine_position(next, EXAMINE_ALL);
    score = estimate_score(NULL, NULL);

    fprintf(stdout, "\n%s seems to win by %1.1f points\n",
      score < 0 ? "B" : "W",
      score < 0 ? -score : score);
  }
}
Ejemplo n.º 30
0
/* This is a substitute for genmove_conservative() which only does
 * what is required when doing the aftermath. Notice though that this
 * generates an "ordinary" move, in contrast to aftermath_genmove().
 * Usually this should turn up a pass, but when it doesn't it's
 * important not to miss the move.
 */
static int
reduced_genmove(int *move, int color)
{
  float val;
  int save_verbose;
  float upper_bound, lower_bound;
  float our_score;

  /* no move is found yet. */
  *move = NO_MOVE;  
  val = -1; 
  
  /* Prepare pattern matcher and reading code. */
  reset_engine();

  /* Find out information about the worms and dragons. */
  examine_position(EXAMINE_ALL);

  /* Make a score estimate. This can be used in later stages of the 
   * move generation.  If we are ahead, we can play safely and if
   * we are behind, we have to play more daringly.
   */
  estimate_score(&upper_bound, &lower_bound);
  if (verbose || showscore) {
    if (lower_bound == upper_bound)
      gprintf("\nScore estimate: %s %f\n",
	      lower_bound > 0 ? "W " : "B ", gg_abs(lower_bound));
    else
      gprintf("\nScore estimate: %s %f to %s %f\n",
	      lower_bound > 0 ? "W " : "B ", gg_abs(lower_bound),
	      upper_bound > 0 ? "W " : "B ", gg_abs(upper_bound));
    fflush(stderr);
  }

  /* The score will be used to determine when we are safely
   * ahead. So we want the most conservative score.
   */
  if (color == WHITE)
    our_score = lower_bound;
  else
    our_score = -upper_bound;

  gg_assert(stackp == 0);
  
  /*
   * Ok, information gathering is complete. Now start to find some moves!
   */

  /* Pick up moves that we know of already. */
  save_verbose = verbose;
  if (verbose > 0)
    verbose--;
  collect_move_reasons(color);
  verbose = save_verbose;
  
  /* Look for combination attacks and defenses against them. */
  combinations(color);
  gg_assert(stackp == 0);

  /* Review the move reasons and estimate move values. */
  if (review_move_reasons(move, &val, color, 0.0, our_score, NULL))
    TRACE("Move generation likes %1m with value %f\n", *move, val);
  gg_assert(stackp == 0);

  /* If no move is found then pass. */
  if (val < 0.0) {
    TRACE("I pass.\n");
    *move = NO_MOVE;
  }
  else
    TRACE("reduced_genmove() recommends %1m with value %f\n", *move, val);
 
  return val;
}