boot1.c 3.46 KB

/*---------------------------------------------------------------------*
        Copyright (C) 1998 Nintendo. (Originated by SGI)
        
        $RCSfile: boot1.c,v $
        $Revision: 1.1.1.1 $
        $Date: 2002/05/02 03:27:20 $
 *---------------------------------------------------------------------*/
#include <ultra64.h>
#include "reboot.h"

static void	idle(void *);
static void	main(void *);

static OSThread	idleThread;
static char	idleThreadStack[STACKSIZE];

static OSThread	mainThread;
static char	mainThreadStack[STACKSIZE];

static OSThread	rmonThread;
static char	rmonThreadStack[RMON_STACKSIZE];

OSMesgQueue rspMessageQ, rdpMessageQ;
OSMesg      rspMessageBuf, rdpMessageBuf;

/*
 * necessary for RSP tasks:
 */
u64 dram_stack[SP_DRAM_STACK_SIZE64];   /* used for matrix stack */
u64 rdp_output_len;         /* RSP writes back size of RDP data */
u64 rdp_output[4096];        /* RSP writes back RDP data */

/*
 * Task descriptor.
 */
OSTask  tlist =
{
    M_GFXTASK,          /* task type */
    OS_TASK_DP_WAIT,        /* task flags */
    NULL,           /* boot ucode pointer (fill in later) */
    0,              /* boot ucode size (fill in later) */
    NULL,           /* task ucode pointer (fill in later) */
    SP_UCODE_SIZE,      /* task ucode size */
    NULL,           /* task ucode data pointer (fill in later) */
    SP_UCODE_DATA_SIZE,     /* task ucode data size */
    &(dram_stack[0]),       /* task dram stack pointer */
    SP_DRAM_STACK_SIZE8,    /* task dram stack size */
    &(rdp_output[0]),       /* task output buffer ptr (not always used) */
    &rdp_output_len,        /* task output buffer size ptr */
    NULL,           /* task data pointer (fill in later) */
    0,              /* task data size (fill in later) */
    NULL,           /* task yield buffer ptr (not used here) */
    0               /* task yield buffer size (not used here) */
};

Gfx     *glistp;    /* global for test case procs */
Gfx		gbuffer[10];

boot1(void)
{
    osInitialize();
    osCreateThread(&mainThread, 1, main, (void *)0,
		   mainThreadStack+STACKSIZE, 10);
    osStartThread(&mainThread);
}

static void
main(void *arg)
{
	OSTask      *tlistp;

    /*
     * Create idle thread
     */
    osCreateThread(&idleThread, 3, idle, (void *)0,
		   idleThreadStack+STACKSIZE, 0);
    osStartThread(&idleThread);

    /*
     * Create rmon thread
     */
    osCreateThread(&rmonThread, 0, rmonMain, (void *)0,
		rmonThreadStack+RMON_STACKSIZE, OS_PRIORITY_RMON);
    osStartThread(&rmonThread);

    rmonPrintf("in operational code\n");

	osCreateMesgQueue(&rspMessageQ, &rspMessageBuf, 1);
    osSetEventMesg(OS_EVENT_SP, &rspMessageQ, NULL);
   
    osCreateMesgQueue(&rdpMessageQ, &rdpMessageBuf, 1);
    osSetEventMesg(OS_EVENT_DP, &rdpMessageQ, NULL);

	for(;;) {
		glistp = &gbuffer[0];
		tlistp = &tlist;
		gSPSegment(glistp++, 0, 0x0);	
		gDPFullSync(glistp++);
		gSPEndDisplayList(glistp++);

		tlistp->t.ucode_boot = (u64 *) rspbootTextStart;
		tlistp->t.ucode_boot_size = (u32)rspbootTextEnd - (u32)rspbootTextStart;
		tlistp->t.ucode = (u64 *) gspFast3D_dramTextStart;
		tlistp->t.ucode_data = (u64 *) gspFast3D_dramDataStart;
		tlistp->t.data_ptr = (u64 *) &gbuffer[0];
		tlistp->t.data_size = (u32)((glistp - &gbuffer[0]) * sizeof(Gfx));
	
		osWritebackDCache(gbuffer, sizeof(gbuffer));

		rmonPrintf("starting Rsp task\n");
		osSpTaskStart(tlistp);

		(void)osRecvMesg(&rspMessageQ, NULL, OS_MESG_BLOCK);
		rmonPrintf("received Rsp message\n");
	}
}

static void
idle(void *arg)
{
	for (;;);
}