Beispiel #1
0
void *
my_thread( void *v )
{
	long num = ( long ) v;
	int n;
	int EventSet = PAPI_NULL;
	long long value;

	int retval = PAPI_register_thread(  );
	if ( retval != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_register_thread", retval );
	pthread_setspecific( key, v );

	count[num] = 0;
	iter[num] = 0;
	last[num] = start;
        
	if ( PAPI_create_eventset( &EventSet ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_create_eventset failed", 1 );

	if ( PAPI_add_event( EventSet, EVENT ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_add_event failed", 1 );

	if ( PAPI_overflow( EventSet, EVENT, threshold, 0, my_handler ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_overflow failed", 1 );

	if ( PAPI_start( EventSet ) != PAPI_OK )
		test_fail( __FILE__, __LINE__, "PAPI_start failed", 1 );

	printf( "launched timer in thread %ld\n", num );

	for ( n = 1; n <= program_time; n++ ) {
		do_cycles( num, 1 );
		print_rate( num );
	}

	PAPI_stop( EventSet, &value );

        retval = PAPI_overflow( EventSet, EVENT, 0, 0, my_handler);
	if ( retval != PAPI_OK )
            test_fail( __FILE__, __LINE__, "PAPI_overflow failed to reset the overflow handler", retval );

	if ( PAPI_remove_event( EventSet, EVENT ) != PAPI_OK ) 
	    test_fail( __FILE__, __LINE__, "PAPI_remove_event", 1 );

	if ( PAPI_destroy_eventset( &EventSet ) != PAPI_OK ) 
	    test_fail( __FILE__, __LINE__, "PAPI_destroy_eventset", 1 );

	if ( PAPI_unregister_thread( ) != PAPI_OK != retval ) 
		test_fail( __FILE__, __LINE__, "PAPI_unregister_thread", 1 );

	return ( NULL );
}
Beispiel #2
0
/*
  Do 'n' instructions.
  return ERR_NONE if successful, a negative value if an error occured,
  a positive value if a breakpoint has been encountered.
*/
int hw_m68k_run(int n)
{
#if 1
  int i;
  GList *l;
  static FILE *flog;
  
  for(i=0; i<n; i++) 
  {
      UWORD opcode;

        if(flog != NULL)
        {
            //fprintf(flog, "0x%06lx\n", m68k_getpc());
        }
        else
            flog = fopen("C:\\tiemu.log", "wt");

        if(bkpts.pc_log_size > 1)
            bkpts.pc_log[bkpts.pc_wr_ptr++ % bkpts.pc_log_size] = m68k_getpc();

      opcode = nextiword();
      (*cpufunctbl[opcode])(opcode);
      do_cycles();

      if((l = bkpts.code) != NULL)
      {
          bkpts.id = 0;
          while(l)
          {
              if(GPOINTER_TO_INT(l->data) == (int)regs.pc)
              {
                bkpts.type = BK_TYPE_CODE;
		        specialflags |= SPCFLAG_BRK;
              }

              bkpts.id++;
              l = g_list_next(l);
          }
      }

      /* Debug purposes */
#if 0
      if (bInstructionsDisplay) 
	{
	  disasm(getPcRegister(), inst);
	  printf("disasm: %s\n", inst);
	}
#endif
      /* Flag management */      
      if(specialflags) 
	{
	  if(specialflags & SPCFLAG_ADRERR) 
	    {
	      Exception(3);
	      specialflags &= ~SPCFLAG_ADRERR;
	    }
	  
	  if (specialflags & SPCFLAG_DOTRACE) 
	    {
	      Exception(9);
	    }
	  
	  while (specialflags & SPCFLAG_STOP) 
	    {
	      do_cycles();
	      if (specialflags & (SPCFLAG_INT | SPCFLAG_DOINT)) 
		{
		  int intr = intlev();
		  specialflags &= ~(SPCFLAG_INT | SPCFLAG_DOINT);
		  if (intr != -1 && intr > regs.intmask) 
		    {
		      Interrupt(intr);
		      regs.stopped = 0;
		      specialflags &= ~SPCFLAG_STOP;
		    }	    
		}
	    }		
	  
	  if (specialflags & SPCFLAG_TRACE) 
	    {
	      specialflags &= ~SPCFLAG_TRACE;
	      specialflags |= SPCFLAG_DOTRACE;
	    }	  
	  if (specialflags & SPCFLAG_DOINT) 
	    {
	      int intr = intlev();
	      specialflags &= ~(SPCFLAG_INT | SPCFLAG_DOINT);
	      if (intr != -1 && intr > regs.intmask) {
		Interrupt(intr);
		regs.stopped = 0;
	      }	    
	    }
	  if (specialflags & SPCFLAG_INT) 
	    {
	      specialflags &= ~SPCFLAG_INT;
	      specialflags |= SPCFLAG_DOINT;
	    }
	  if (specialflags & SPCFLAG_BRK) 
	    {		
	      specialflags &= ~SPCFLAG_BRK;
	      return 1;		// DBG_BREAK
	    }
	  if(specialflags & SPCFLAG_DBTRACE) 
	    {
	      specialflags &= ~SPCFLAG_DBTRACE;
          return 2;     // DBG_TRACE
	    }
	}  
    }
#endif
  return 0;
}
Beispiel #3
0
static int do_specialties (int cycles)
{
    if (mispcflags & SPCFLAG_COPPER)
    {
#ifdef DEBUG_M68K
        dbg("do_specialties -> do_copper");
#endif
        do_copper ();
    }

    /*n_spcinsns++;*/
    while ((mispcflags & SPCFLAG_BLTNASTY) && cycles > 0) {
        int c = blitnasty();
        if (!c) {
            cycles -= 2 * CYCLE_UNIT;
            if (cycles < CYCLE_UNIT)
                cycles = 0;
            c = 1;
        }
#ifdef DEBUG_M68K
        dbgf("do_specialties -> do_cycles BLTNASTY %i\n",c);
#endif
        do_cycles(c * CYCLE_UNIT);
        if (mispcflags & SPCFLAG_COPPER)
        {
#ifdef DEBUG_M68K
            dbg("do_specialties -> do_copper BLTNASTY");
#endif
            do_copper ();
        }
    }

#ifdef DEBUG_M68K
    while (M68KCONTEXT.execinfo & 0x0080) {
        if (mispcflags & SPCFLAG_BRK)
            break;
        else if (M68KCONTEXT.execinfo & 0x0080)
        {
            int intr = intlev ();
            if (intr != -1 && intr > _68k_intmask)
            {
                M68KCONTEXT.execinfo &= 0xFF7F;
                break;
            }
        }
        dbg("CPU STOPPED !");
        do_cycles(4 * CYCLE_UNIT);
        if (mispcflags & SPCFLAG_COPPER)
        {
            dbg("do_specialties -> do_copper STOPPED");
            do_copper ();
        }
    }
    unset_special (SPCFLAG_STOP);
#endif

#if 0 // !defined(FAME_INTERRUPTS_SECURE_PATCH) && defined(FAME_INTERRUPTS_PATCH)
    if (uae4all_go_interrupt)
    {
        /*if (verb)*/ printf("uae4all_go_interrupt (s): %02x\n", uae4all_go_interrupt);
        M68KCONTEXT.interrupts[0]=uae4all_go_interrupt;
        M68KCONTEXT.execinfo&=0xFF67;
        uae4all_go_interrupt=0;
        m68k_irq_update(0);
    }
#endif

#ifdef SPECIAL_DEBUG_INTERRUPTS
    if ((mispcflags & SPCFLAG_DOINT)&&(!(mispcflags & SPCFLAG_INT))) {
        int intr = intlev ();
#ifdef DEBUG_INTERRUPTS_EXTRA
        dbgf("DOINT : intr = %i, intmask=%i\n", intr, _68k_intmask);
#endif
        unset_special (SPCFLAG_DOINT);
        if (intr != -1 && intr > _68k_intmask) {
            M68KCONTEXT.execinfo&=0xFF6F;
            m68k_raise_irq(intr,M68K_AUTOVECTORED_IRQ);
//		m68k_emulate(0);
        }
    }
    if (mispcflags & SPCFLAG_INT) {
#ifdef DEBUG_INTERRUPTS_EXTRA
        dbg("ESTAMOS EN INT -> PASAMOS A DOINT");
#endif
        unset_special (SPCFLAG_INT);
        set_special (SPCFLAG_DOINT);
    }
#endif

    if (mispcflags & SPCFLAG_BRK) {
        unset_special (SPCFLAG_BRK);
        return 1;
    }
    return 0;
}
Beispiel #4
0
static void m68k_run (void)
{
    uae4all_reset ();
    unsigned cycles, cycles_actual=M68KCONTEXT.cycles_counter;
    for (;;) {
#ifdef DEBUG_M68K
        dbg_cycle(m68k_fetch(m68k_get_pc(),0));
        m68k_emulate(1);

#else
        uae4all_prof_start(0);

        cycles = nextevent - currcycle;
        switch (timeslice_mode) {
        case 3:
            cycles>>=6;
            break;
        case 2:
            cycles>>=7;
            break;
        case 1:
            cycles=(cycles>>8)+(cycles>>9);
            break;
        default:
            cycles>>=8;
            break;
        }

#define NDEBUG_CYCLES
#ifdef DEBUG_CYCLES
        static unsigned next_cycles = 60000000;
        if (M68KCONTEXT.cycles_counter > next_cycles) {
            next_cycles += 100000;
            printf("cycles=%9d|%03i|%03i, pc=%.6x\n", M68KCONTEXT.cycles_counter, cycles, IO_CYCLE, _68k_getpc());
        }

        if (M68KCONTEXT.cycles_counter > 80000000) {
            // exit(0);
        }

        if (M68KCONTEXT.cycles_counter >= 500000000) {
            // do_debug = 1;
        }

#endif

#if defined(FAME_INTERRUPTS_SECURE_PATCH) && defined(FAME_INTERRUPTS_PATCH)
        if (uae4all_go_interrupt)
            m68k_emulate(FAME_INTERRUPTS_PATCH);
        else
#endif
            m68k_emulate(cycles);

        uae4all_prof_end(0);
#endif
#if 0 // def FAME_INTERRUPTS_PATCH
        if (uae4all_go_interrupt)
        {
            /*if (verb)*/ printf("uae4all_go_interrupt: %02x\n", uae4all_go_interrupt);
            M68KCONTEXT.interrupts[0]=uae4all_go_interrupt;
            M68KCONTEXT.execinfo&=0xFF67;
            uae4all_go_interrupt=0;
            m68k_irq_update(0);
        }
#endif

        uae4all_prof_start(1);

        cycles=(M68KCONTEXT.cycles_counter-cycles_actual) * cycles_factor;

#ifdef DEBUG_INTERRUPTS
        dbgf("cycles=%i (%i) -> PC=%.6x\n",cycles>>8,nextevent - currcycle, _68k_getpc());
#endif


#ifdef NO_SHORT_EVENTS
#ifdef PROTECT_INFINITE
        unsigned cuentalo=0;
#endif
        do {
#endif
            do_cycles(cycles);
            if (mispcflags)
                if (do_specialties (cycles))
                    return;
#ifndef DEBUG_M68K
#ifdef NO_SHORT_EVENTS
            cycles=2048;
#ifdef PROTECT_INFINITE
            cuentalo++;
            if (cuentalo>1024) {
                g_emulator.quit_program=RunStateReset;
                return;
            }
#endif
        } while((nextevent - currcycle)<=2048);
#endif
        cycles_actual=M68KCONTEXT.cycles_counter;
#endif
        uae4all_prof_end(1);
    }
}
Beispiel #5
0
static void m68k_run (void)
{
	uae4all_reset ();
	unsigned cycles, cycles_actual=M68KCONTEXT.cycles_counter;
	for (;;) {
		while (pause_program > 0)
		{
			usleep(200000);
		}
        
#ifdef DEBUG_M68K
		dbg_cycle(m68k_fetch(m68k_get_pc(),0));
		m68k_emulate(1);

#else
		uae4all_prof_start(0);
		cycles = nextevent - currcycle;
		switch (timeslice_mode) {
			case 3:  cycles>>=6; break;
			case 2:  cycles>>=7; break;
			case 1:  cycles=(cycles>>8)+(cycles>>9); break;
			default: cycles>>=8; break;
		}
#ifdef DEBUG_TIMESLICE
		unsigned ts=cycles;
#endif
#if defined(FAME_INTERRUPTS_SECURE_PATCH) && defined(FAME_INTERRUPTS_PATCH)
		if (uae4all_go_interrupt)
			m68k_emulate(FAME_INTERRUPTS_PATCH);
		else
#endif
			m68k_emulate(cycles);
		uae4all_prof_end(0);
#endif
#if 0 // def FAME_INTERRUPTS_PATCH
		if (uae4all_go_interrupt)
		{
			/*if (verb)*/ printf("uae4all_go_interrupt: %02x\n", uae4all_go_interrupt);
			M68KCONTEXT.interrupts[0]=uae4all_go_interrupt;
			M68KCONTEXT.execinfo&=0xFF67;
			uae4all_go_interrupt=0;
			m68k_irq_update(0);
		}
#endif
#ifdef DEBUG_M68K

		if (M68KCONTEXT.execinfo & 0x0080)
			mispcflags|=SPCFLAG_STOP;
#endif
                uae4all_prof_start(1);

		//cycles=((unsigned)(((double)(M68KCONTEXT.cycles_counter-cycles_actual))*cycles_factor))<<8;
		cycles=(M68KCONTEXT.cycles_counter-cycles_actual) * cycles_factor;

#ifdef DEBUG_INTERRUPTS
		dbgf("cycles=%i (%i) -> PC=%.6x\n",cycles>>8,nextevent - currcycle, _68k_getpc());
#endif


#ifdef NO_SHORT_EVENTS
#ifdef PROTECT_INFINITE
		unsigned cuentalo=0;
#endif
		do{
#endif
			do_cycles(cycles);
			if (mispcflags)
				if (do_specialties (cycles))
					return;
#ifndef DEBUG_M68K
#ifdef NO_SHORT_EVENTS
			cycles=2048;
#ifdef PROTECT_INFINITE
			cuentalo++;
			if (cuentalo>1024)
			{
				quit_program=2;
				return;
			}
#endif
		}while((nextevent - currcycle)<=2048);
#endif
		cycles_actual=M68KCONTEXT.cycles_counter;
#endif
                uae4all_prof_end(1);
	}
}