rand.c 4.25 KB
#include <PR/bcp.h>
#include <PR/R4300.h>
#include <PR/bbsim.h>
#include <PR/bbskapi.h>
#include <PR/bbvirage.h>
#include <PR/os.h>
#include <PR/os_bbfs.h>
#include <PR/os_bbatb.h>
#include <PR/os_bbexec.h>
#include <sha1.h>

#include "libfb.h"
#include "rand.h"



/*
 * buffer for FS must be dcache aligned. use macro below.
 */
#define ALIGN_DCACHE __attribute__((aligned(DCACHE_LINESIZE)))

/*
 * debug print support
 */

#undef PRINTF

#ifdef DEBUG
#define	PRINTF	osSyncPrintf
#else
#define	PRINTF(format, args...)
#endif



/*
 * Thread and stack structures
 */

char   bootStack[STACKSIZE] __attribute__ ((aligned (8)));

static OSThread idleThread;
static char     idleThreadStack[STACKSIZE] __attribute__ ((aligned (8)));

static OSThread mainThread;
static char     mainThreadStack[STACKSIZE] __attribute__ ((aligned (8)));

/* 
 * FS specific definitions
 */

static void	idleproc(char *);
static void	mainproc(char *);



#define DMA_QUEUE_SIZE	200

static OSMesg           PiMessages[DMA_QUEUE_SIZE];
static OSMesgQueue      PiMessageQ;

static OSMesg           SiMessages[DMA_QUEUE_SIZE];
static OSMesgQueue      SiMessageQ;



/*
 * simple graphics
 */
static OSMesgQueue      retraceMessageQ;
static OSMesg           dummyMessage, retraceMessageBuf;

#if SCREEN_LOW
#define WD	320
#define HT	240
#else
#define WD	640
#define HT	480
#endif
static u16 cfb[WD*HT] __attribute__((aligned(64)));


void  __osBbVideoPllInit(u32);
void boot(u32 miSecModeRegVal)
{
    /* Init the video PLL */
    __osBbVideoPllInit(OS_TV_NTSC);

    osInitialize();

    osCreateThread(&idleThread, 1, (void(*)(void *))idleproc, (void *)0,
                   idleThreadStack+STACKSIZE, 8);
    osStartThread(&idleThread);
}


static void
idleproc(char *argv)		/* priority 8 */
{
    osCreateViManager(OS_PRIORITY_VIMGR);
#if	SCREEN_LOW
    osViSetMode(&osViModeTable[OS_VI_NTSC_LPN1]);
#else
    osViSetMode(&osViModeTable[OS_VI_NTSC_HPF1]);
#endif

    /*
     * Start PI Mgr for access to cartridge - start before the debugger
     */
    osCreatePiManager((OSPri) OS_PRIORITY_PIMGR, &PiMessageQ, PiMessages,
            DMA_QUEUE_SIZE);

    osCreateMesgQueue(&SiMessageQ, SiMessages, DMA_QUEUE_SIZE);
    osSetEventMesg(OS_EVENT_SI, &SiMessageQ, (OSMesg)DMA_QUEUE_SIZE);
    /*
     * The main thread's priority must be the same or lower than the original
     * idle's thread priority. This allows the idle thread to change its
     * priority to 0 before the main thread starts execution.
     */
    osCreateThread(&mainThread, 3, (void(*)(void *))mainproc, argv,
           mainThreadStack+STACKSIZE/8, (OSPri)7);
    osStartThread(&mainThread);

    osSetThreadPri(0, OS_PRIORITY_IDLE);

    for(;;) {
#if 0
	osBbSetErrorLed(1);
	delay();
	osBbSetErrorLed(0);
	delay();
#endif
    }
}


#define INPUT_SIZE 512
void mainproc(char *argv)
{
  u8 keydata[20];
  int i;
  char outstring[512];
  u32 starttime;
  u32 endtime;
  int ret;
   
#if SCREEN_LOW
    fbInit(FB_LOW_RES);
#else
    fbInit(FB_HIGH_RES);
#endif
    /* setup text output to screen */
    osCreateMesgQueue(&retraceMessageQ, &retraceMessageBuf, 1);
    osViSetEvent(&retraceMessageQ, dummyMessage, 1);
    osViBlack(1);
    osViSwapBuffer(cfb);
    fbSetBg(fbBlack);
    fbClear();
    osViBlack(0);
    osWritebackDCacheAll();
    osViSwapBuffer(cfb);
    

    fbPrintStr(fbWhite, 10, 3, "Randoms Test App");
    osWritebackDCacheAll();
    
    /*
    PRINTF("before loop\n");
    */
    starttime = osGetCount();
    for(i =0; i < 1; i++){
      ret = skGetRandomKeyData(keydata, 16);
      if (ret != SK_API_SUCCESS){
	PRINTF("ATLEAST SOME TESTS FAIL in SK");
      /* quit here in the SK */
      }
      else{
	PRINTF("ALL TESTS PASS");
        sprintf(outstring, "%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x  %02x %02x %02x %02x  %02x", keydata[0], keydata[1], keydata[2], keydata[3], keydata[4], keydata[5], keydata[6], keydata[7], keydata[8], keydata[9], keydata[10], keydata[11], keydata[12], keydata[13], keydata[14], keydata[15]);
	fbPrintStr(fbWhite, 10, 22, outstring);
	osWritebackDCacheAll();
    
	PRINTF(outstring);
      }
    }
    endtime = osGetCount();
    bzero(outstring, sizeof(outstring));
    sprintf(outstring, "Time Taken = %llu", OS_CYCLES_TO_USEC(endtime - starttime));
    fbPrintStr(fbWhite, 10, 23, outstring);
    osWritebackDCacheAll();
}