void InterruptHandler(long cause)
{
	
	register long aMSR;
	unsigned long 			hid0_value;
	#pragma unused (aMSR) // Do not warn - aMSR used in asm code 
	
	asm
	{
		//If we are using SPE,  we need to make sure to enable the SPE bit in the  MSR
		#if defined(__PPCZen__) || defined(__PPCe500__) || defined(__PPCe500v2__)
			mfmsr  aMSR
			oris   aMSR,aMSR,0x0200
			mtmsr  aMSR
		#endif	
	}



 switch(cause)
 {
 	case 0xC00:
 	printf("Core #%d: system call exception handler\r\n", Get_ProcessorID());
 	break;
 	
 	
 	case 0xB00:
 	// freeze the time base 
			FreezeTimeBase ();
			printf("1st tm\n\r");
			printf("-------\n\r");			
		
			
			//Print out the state of the state machine 
			// of the watchdog timer
			
		 printf("Watchdog state before...\n\r");
			GetStateInfoWD();
		
			
			// take the watchdog state machine to initial state 
			clear_enw_wis_wrs_tsr;			
		
			 
			// Print out the state of the state machine 
		// of the watchdog timer
			
			printf("Watchdog state after...\n\r");			
			GetStateInfoWD();
			printf("\n\r");

			// enable the timebase again 
     	  GET_HID0(hid0_value);
     		hid0_value |= 0x00004000;              
 
     		/// clear the timebase 
     		ResetTimeBase();

     		SET_HID0(hid0_value);
			
//	WatchDogCancel();

 	break;
 	
 	default:
    //printf("Exc: lumped..%x.\r\n",cause);
 	break;



 	
 }







}
Exemple #2
0
int main (int argc, char *argv[])
{
	int i;
	SDL_Event event;
	SDL_Surface *screen;
	struct chip8_state s;
	
	init(&s);
	atexit(SDL_Quit);
	if ((ptrGame=fopen(argv[1],"rb"))==NULL)
	{
		printf("No se puede abrir el archivo\n");
	}
	else
	{
		if (SDL_Init(SDL_INIT_VIDEO)<0)
		{
			printf("No se pudo iniciar SDL: %s\n", SDL_GetError());
			exit(1);
		}
		screen=SDL_SetVideoMode(640,320, 8, SDL_HWSURFACE);
		if (screen == NULL) 
		{
			printf("No se puede inicializar el modo gráfico: %s\n",SDL_GetError());
			exit(1);
		}
		i=fread(&(s.data[512]),1,SIZEMEM,ptrGame)+0x200;
		printf("%d bytes loaded\n", i-0x200);
		fclose(ptrGame);
		#ifdef TODEBUG
		int j;
		for(j=0x200; j<i; j++)
		{
			printf("%02X ",s.data[j]);
		}
		printf("\n");
		#endif
		int x=0;
		while(x==0&&s.PC<i+1)
		{
			ResetTimeBase();
			#ifdef TODEBUG
			printPC(&s);
			printReg(&s);
			if(getchar()==27){x=1;}
			#else
			while (SDL_PollEvent(&event))
			{
				if (event.type == SDL_QUIT) {x=1;}
				if (event.type == SDL_KEYDOWN) 
				{
					if (event.key.keysym.sym == SDLK_ESCAPE) 
					{
						x=1;
					} 
				}
			}
			#endif
			exec(&s);
			if(s.draw) drawscrn(&s,screen);
			s.keypress=keypressed();
			s.draw=0;
			s.PC+=2;
			
			if(s.DT!=0){s.DT--;}
			if(s.ST!=0){s.ST--;}
			
			do {
				frametime=CurrentTime();
			} while (frametime<4);
		}
	}
	return 0;
}
void InterruptHandler
	(
	long exceptNumber
	)
	{
	volatile unsigned long 	*pReg;
	unsigned long 			tcr_value;
	unsigned long 			hid0_value;	

    /* pointer to MCPSUMR register */
	pReg = (volatile unsigned long *)0x400e0090;

	switch (exceptNumber)
		{
		case 0x100: 
		printf("EXEPTION 0x100\n\r");
		printf("Exc 0x%8.8x : critical interrupt...\r\n",exceptNumber);
		
		break;
		case 0x200:
			/*
			* check to see whether this is cause
			* by the watchdog second timeout
			*/
			printf("EXEPTION 0x200\n\r");	
			if(*pReg & 0x00000004)
				{
				printf("pReg & 0x00000004\n\r");
			
				end_time = (dtime() * 8)/266000000;
			
				/* freeze the time base */
				FreezeTimeBase ();
				printf("2nd tm\n\r");
				printf("-------\n\r");
  				printf("time lapsed %f\n\r",end_time - start_time); 								

				/* 
				* Print out the state of the state machine 
				* of the watchdog timer
				*/
				printf("Watchdog state before...\n\r");
				GetStateInfoWD();				
				
				clear_enw_wis_wrs_tsr
				*pReg |= 0x00000004; //clearing WRS of MCPSUMR*/
								
				 
				// Print out the state of the state machine 
				// of the watchdog timer
				//
				printf("Watchdog state after...\n\r");			
				GetStateInfoWD();
				printf("\n\r");
			
				
				// programming the tcr again so that we
			// can get second timeout again.Only WRC
				// field of TCR needs to be set to 0b01
				
				GET_TCR(tcr_value);
				tcr_value &= ~0x30000000;
     			tcr_value |= 0x10000000;	     
     			SET_TCR(tcr_value);
    			
				 //enable the timebase again 
     	    	GET_HID0(hid0_value);
     			hid0_value |= 0x00004000;              
 
     			// clear the timebase 
     			ResetTimeBase();
				
				SET_HID0(hid0_value);
     			start_time = (dtime() * 8) / 266000000;     		     			

				}

		break;	

		case 0x300: 
		printf("EXEPTION 0x300\n\r");
		printf("Exc 0x%x : data storage...\r\n",exceptNumber);
		break;	
		case 0x500:
		printf("EXEPTION 0x500\n\r");
		printf("Exc 0x%x : external interrupt...\r\n",exceptNumber);break;	
		case 0xB00: 
		
		printf("EXEPTION 0xB00\n\r");
		
			// freeze the time base 
			FreezeTimeBase ();
			printf("1st tm\n\r");
			printf("-------\n\r");			
		
			
			//Print out the state of the state machine 
			// of the watchdog timer
			
			printf("Watchdog state before...\n\r");
			GetStateInfoWD();
		
			
			// take the watchdog state machine to initial state 
			clear_enw_wis_wrs_tsr;			
		
			 
			// Print out the state of the state machine 
		// of the watchdog timer
			
			printf("Watchdog state after...\n\r");			
			GetStateInfoWD();
			printf("\n\r");

			// enable the timebase again 
     	    GET_HID0(hid0_value);
     		hid0_value |= 0x00004000;              
 
     		/// clear the timebase 
     		ResetTimeBase();

     		SET_HID0(hid0_value);
			
			
		break;	
		default: 
		printf("EXEPTION DEfault\n\r");
		printf("Exc: lumped...\r\n");break;
		}

	}