boot.c 1.31 KB
#include <ultra64.h>
#include <string.h>
#include "rdpvector.h"

char	bootStack[STACKSIZE];

extern char _codeSegmentRomStart[];
extern char _codeSegmentRomEnd[];
extern char _codeSegmentStart[];
extern char _codeSegmentTextStart[];
extern char _codeSegmentTextEnd[];
extern char _codeSegmentDataStart[];
extern char _codeSegmentDataEnd[];
extern char _codeSegmentBssStart[];
extern char _codeSegmentBssEnd[];

/*
 * The boot() function MUST be the first function in this module, otherwise
 * the original boot thread (loaded at 2MB in rdram) will be unable to invoke 
 * this secondary boot procedure, which loads the program low in rdram.
 */
boot(void *arg)
{
  
    void (*func)(void);
    
    /*
     * Load in the code segment.  The "boot" portion of the code segment
     * will load in the texture segment and the static segment.
     */
    __osPiRawStartDma(OS_READ, (u32)_codeSegmentRomStart, _codeSegmentStart, 
		   _codeSegmentRomEnd-_codeSegmentRomStart);

    while(osPiGetStatus() & PI_STATUS_DMA_BUSY);

    osInvalICache(_codeSegmentTextStart,
		  _codeSegmentTextEnd-_codeSegmentTextStart);
    osInvalDCache(_codeSegmentDataStart,
		  _codeSegmentDataEnd-_codeSegmentDataStart);

    bzero(_codeSegmentBssStart, _codeSegmentBssEnd-_codeSegmentBssStart);

    func = (void (*)(void))_codeSegmentStart;
    func();

}