logtest.c 3.85 KB
/*====================================================================
 * logtest.c
 *
 * Copyright 1995, Silicon Graphics, Inc.
 * All Rights Reserved.
 *
 * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics,
 * Inc.; the contents of this file may not be disclosed to third
 * parties, copied or duplicated in any form, in whole or in part,
 * without the prior written permission of Silicon Graphics, Inc.
 *
 * RESTRICTED RIGHTS LEGEND:
 * Use, duplication or disclosure by the Government is subject to
 * restrictions as set forth in subdivision (c)(1)(ii) of the Rights
 * in Technical Data and Computer Software clause at DFARS
 * 252.227-7013, and/or in similar or successor clauses in the FAR,
 * DOD or NASA FAR Supplement. Unpublished - rights reserved under the
 * Copyright Laws of the United States.
 *====================================================================*/

#include <ultralog.h>
#include <ultra64.h>
#include "logtest.h"
#include <os_internal.h>
#include <rmon.h>

#define LOG_LEN 0x1000
#define MY_RMON_STACKSIZE 16384
#define DMA_QUEUE_SIZE  200

u64	        bootStack[STACKSIZE/8];
static u64      rmonStack[MY_RMON_STACKSIZE/8];
static OSThread rmonThread;

static OSThread	mainThread;
static u64	mainThreadStack[STACKSIZE/8];
static void	mainproc(char *);

static OSThread	gameThread;
static u64	gameThreadStack[STACKSIZE/8];
static void	gameproc(void *);

static OSMesg           PiMessages[DMA_QUEUE_SIZE];
static OSMesgQueue      PiMessageQ;

u32 logData[LOG_LEN/sizeof(long)];

int printOnly = 0;
int debugger = 0;

#if defined( _HW_VERSION_1 )
#define PRINTF  rmonPrintf
#else
#define PRINTF  osSyncPrintf
#endif

boot(void *arg)
{
    osInitialize();
    osCreateThread(&mainThread, 1, (void(*)(void *))mainproc, arg,
		  mainThreadStack+STACKSIZE/8, (OSPri)10);

    osStartThread(&mainThread);
}

static void mainproc(char *argv) 
{
    int printOnly;
    
    osCreateThread(&gameThread, 6, gameproc, argv, gameThreadStack+STACKSIZE/8,
                   (OSPri)10);
    /*
     * Start PI Mgr for access to cartridge - start before debugger?
     */
    osCreatePiManager((OSPri) OS_PRIORITY_PIMGR, &PiMessageQ, PiMessages,
			DMA_QUEUE_SIZE);

    /*
     * determine what mode to start up in.
     */
printOnly = 1;
    
    if (printOnly) {
        osCreateThread(&rmonThread, 0, rmonMain, (void *)0,
                       rmonStack+MY_RMON_STACKSIZE/8,
                       (OSPri)OS_PRIORITY_RMON );
        osStartThread(&rmonThread);
        osStartThread(&gameThread);
    } else if (debugger) {
        osCreateThread(&rmonThread, 0, rmonMain, (void *)0,
                       rmonStack+MY_RMON_STACKSIZE/8,
                       (OSPri) OS_PRIORITY_RMON );
        osStartThread(&rmonThread);
    } else {
        osStartThread(&gameThread);
    }    

    osSetThreadPri(0, 0);
    for(;;);
}

static void gameproc(void *arg)
{    
    OSLog       logger;
    OSLog       *log = &logger;
    int         x_int = 1;
    short       x_short = 5;
    char        x_char = 10;
    float       x_float = 1.0;
    u32         start,end;
    int         i;
    
    x_float = 1.0;      /* hack around bug */
    x_float = 1.0;
    
PRINTF("---- <start logtest> ----\n");
    osCreateLog(log, logData, LOG_LEN);
PRINTF("created log\n");
    
    osLogEvent(log, 0, 0); 
    osLogEvent(log, 1, 1, x_int);
    osLogEvent(log, 2, 1, x_short);
    osLogEvent(log, 3, 1, x_char);
    osLogEvent(log, 4, 1, OS_LOG_FLOAT(x_float));
    osLogEvent(log, 5, 2, x_int, OS_LOG_FLOAT(x_float));
    osLogEvent(log, 6, 4, 0, 1, 2, 3);
    PRINTF("logged events\n");  

    for(i = 0; i < 5; i++) {
        start = osGetCount();
        osDelay(100000);
        end = osGetCount();
        osLogEvent(log, 7, 1, end - start);
        PRINTF("end 0x%x, start 0x%x\n", end, start);
    }
    
PRINTF("flushing log...\n");
    osFlushLog(log);
PRINTF("flushed log\n");

    while(1);
}