main.c

来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C语言 代码 · 共 283 行

C
283
字号
/*****************************************************************************
* 
*   THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
*   ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
*   THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
*   PARTICULAR PURPOSE.
*   Copyright (c) 1998 Hitachi,Ltd.
*
*
*   @doc EXTERNAL BOOTLOAD
*
*   @module main.c | Boot loader main module
*
*   @comm
*           This file contains the C main for the boot loader.  NOTE: The 
*           firmware "entry" point (the realy entry point is _EntryPoint 
*           in init assembler file.
*
*   @topic  BootLoad |
*           The Windows Ce boot loader is the code that is executed on a Windows CE 
*           development system at power-on reset and loads the Windows CE
*           operating system. The boot loader also provides code that monitors
*           the behavior of a Windows CE platform between the time the boot loader
*           starts running and the time the full operating system debugger is 
*           available. Windows CE OEMs are supplied with sample boot loader code 
*           that runs on a particular development platform and CPU. 
*
*       
******************************************************************************/

#include <loader.h>
#include <oemfw.h>
#include <platform.h>

void OEMInitDebugSerial(void);
int memcmp(const void *s1, const void *s2, int n);
void *memcpy(void *s1, const void *s2, int n);
void *memset(void *s, int c, int n);

typedef struct ROMHDR {
	int     dllfirst;                               // first DLL address
	int     dlllast;                                // last DLL address
	int     physfirst;                              // first physical address
	int   physlast;                         // highest physical address
	int     nummods;                                // number of TOCentry's
	int     ulRAMStart;                             // start of RAM
	int     ulRAMFree;                              // start of RAM free space
	int     ulRAMEnd;                               // end of RAM
	int     ulCopyEntries;                  // number of copy section entries
	int     ulCopyOffset;                   // offset to copy section
	int     ulProfileEntries;               // number of PROFentries
	int     ulProfileOffset;                // offset to PROFentries
	int     numfiles;                               // number of FILES
	int     ulObjstoreStart;                // object store starting address
	int     ulObjstoreLen;                  // object store length
	int     ulDrivglobStart;                // device driver global starting address
	int     ulDrivglobLen;                  // device driver global length
	int     ulFramebufStart;                // display frame buffer starting address
	int     ulFramebufLen;                  // display frame buffer length
	int     ulTrackingStart;                // tracking memory starting address
	int     ulTrackingLen;                  // tracking memory ending address
} ROMHDR;

typedef struct COPYentry {
	int     ulSource;                               // copy source address
	int     ulDest;                                 // copy destination address
	int     ulCopyLen;                              // copy length
	int     ulDestLen;                              // copy destination length 
								// (zero fill to end if > ulCopyLen)
} COPYentry;

typedef volatile unsigned int *VPDWORD;

ROMHDR * const pTOC = (ROMHDR *)-1;     // Gets replaced by RomLoader with real address
void KernelRelocate(void);

typedef volatile unsigned int *VPDWORD;
unsigned int ulRamBufStart;				// starting address of available RAM
unsigned int ulRamBufEnd;				// ending address of available RAM

//#ifndef R3000
//void memset(char * dest, int c, unsigned int count);
//void memcpy(char * dest, char * src, unsigned int count);
//#endif

unsigned int vAddr;


// -----------------------------------------------------------------------------
//
//  IsDRAM
//
//  Is there DRAM available at the specified location?  This test must be non-
//  destructive... can't alter the contents except temporarily.
//
// -----------------------------------------------------------------------------
unsigned int IsDRAM(unsigned int dwMemStartAddr, unsigned int dwMaxMemLength)
{

#define EXTENSION_CHECK_SIZE 4
#define DRAM_TEST_INTERVAL 0x100000

   unsigned int testvect [EXTENSION_CHECK_SIZE] ={0x55aaaa55,0xaa5555aa,12345678,0xf00f4466 };
   unsigned int backup   [EXTENSION_CHECK_SIZE];
   unsigned int *target;
   unsigned int bMismatch= FALSE;
   unsigned int length;

   //
   // Probe each page until we find one that fails
   //
   for (length = 0; (length < dwMaxMemLength) && !bMismatch ; ) {
      target = (unsigned int *) (length + dwMemStartAddr);
      //
      // Save the original data in backup buffer
      //
      memcpy( backup, target, sizeof(testvect) );
      //  
      // Now fill memory from the test vector
      //
      memcpy( target, testvect, sizeof(testvect) );
      //  
      // Now compare memory to the test vector
      //
      if ( memcmp( target, testvect, sizeof(testvect) ) )
         bMismatch = TRUE;
      else
         length += DRAM_TEST_INTERVAL;   // OK, advance our probe pointer        
      //
      // Don't forget to restore the saved data.
      //
      memcpy( target, backup, sizeof(backup) );  
   }

#if ((SH_PLATFORM==PLATFORM_ASPEN)||(SH_PLATFORM==PLATFORM_BIGSUR))
	/* Check out whether there is any shadowing of RAM taking place on
	 * ASPEN/Bigsur	platform.
	 */
	{
		unsigned saved_data, data, i;
		unsigned *location;
   		// Now check for shadowing. It is possible that 0c000000 and 0d000000 Map
   		// to the Same physical RAM. So make sure that the length is the actual
   		// amount of RAM present.
   		// For this write out a test pattern at 0x000000 and
   		// check out the following locations :-
   		//   0c100000
   		//   0c200000
   		//   0c400000
   		//   0c800000
   		//   0d000000

#define MEM_START  0x0c000000
#define TEST_DATA  0xDEADBEEF
#define AREA3_SIZE 0x04000000 // Max. amt. of mem. that can be attached.

		// Write test data to MEM_START
		location = (unsigned *)MEM_START;
   		saved_data = *location;
		*location = TEST_DATA;
   		for(i=DRAM_TEST_INTERVAL; i < AREA3_SIZE; i*=2) {
			data = *(unsigned *)((unsigned)location + i);
			
			// If the data is the same, it means that this is a shadowed location.
			if(data == TEST_DATA) 
				break;
		}
		location = (unsigned *)MEM_START;
   		*location = saved_data;

#ifdef DEBUG
		if((unsigned)i < AREA3_SIZE) {
			OutputFormatString("Memory Shadowing takes place from 0x%x\r\n", i);
		}
#endif

	// OutputFormatString("i=0x%x, length=0x%x\r\n", i, length);
	/* Check whether the lenght you got earlier lies within MEM_START + i 
	 * to make sure it was not shadowed RAM that you detected.
	 */
	if( ((dwMemStartAddr + length) & 0x0FFFFFFF) > ((MEM_START + i) & 0x0FFFFFFF) ) {
			length = (unsigned)i - ((dwMemStartAddr - MEM_START)& 0x0fffffff);
		}
	}
#endif ((SH_PLATFORM==PLATFORM_ASPEN)||(SH_PLATFORM==PLATFORM_BIGSUR))
       
#ifdef DEBUG
	OutputFormatString("IsDRAM Returning length 0x%x\r\n", length);
#endif
   return (length);
}

//
// Move all writeable data sections into RAM
//
void KernelRelocate(void)
{
    unsigned int loop;
    COPYentry *cptr;

    for (loop = 0; (unsigned)loop < (unsigned)pTOC->ulCopyEntries; loop++) { 
    	cptr = (COPYentry *)(pTOC->ulCopyOffset + loop*sizeof(COPYentry));
	    if (cptr->ulCopyLen)
	        memcpy((void *)cptr->ulDest, (void *)cptr->ulSource, cptr->ulCopyLen);
    	if (cptr->ulCopyLen != cptr->ulDestLen)
	        memset((void *)(cptr->ulDest + cptr->ulCopyLen), 0, cptr->ulDestLen - cptr->ulCopyLen);
        }
}


void main(void)
{
    // move writeable data to RAM
    KernelRelocate();

    
    //
    // Initialize the monitor port (for development system)
    // This should be done first since otherwise we can not
    // print any message onto the monitor
    //
	OEMInitDebugSerial();


	ulRamBufStart= ulRamBufEnd=pTOC->ulRAMEnd; // compute amount of RAM available
	ulRamBufEnd+= 0x100000;
	ulRamBufEnd&= 0xfff00000;
	ulRamBufEnd|=0xa0000000;
//	OutputFormatString("\r\nLooking for RAM from %Xh for 32Mbytes\r\n",ulRamBufEnd);

	OutputFormatString("\r\nLooking for RAM \r\n");

	// Detect whether this version is built to run from SH4 on chip RAM
	// or normal SDRAM. If it is built to run from on chip RAM, then do
	// not call IsDRAM. Manually set RAM END in that case.

	// OutputFormatString("\r\nRAMEnd = 0x%x\r\n", pTOC->ulRAMEnd);

	if( 0x7C000000 == (pTOC->ulRAMEnd & 0x7c000000) ) {
		// WRITE_REGISTER_ULONG(LED_ALPHA,0x25);
		ulRamBufEnd = 0x7C002FFC;
	}
	else {
		// WRITE_REGISTER_ULONG(LED_ALPHA,0x27);
		ulRamBufEnd+= IsDRAM(ulRamBufEnd,0x2000000);
		ulRamBufEnd-= 4;
	}
	ulRamBufStart |= 0xA0000000;
	ulRamBufEnd   |= 0xA0000000;
	OutputFormatString("Available RAM Start:%Xh End:%Xh\r\n",ulRamBufStart,ulRamBufEnd);
    
    //
    // At this time, the CPU has been initialized
    //
    if (PowerOnSelfTest()) { 
	//
	// If power on self test returns 0,
	// We'll jump to debugger directly
	// This doesn't mean the debugger will run (since the system fails
	// pass the test).  However, since most likely the failure is due
	// to some I/O device (hopefully not the monitor port) and since
	// the debugger does not need these devices to run, it'll still
	// run OK.
	//
    	// DownloadImage(NULL, &vAddr, 1);
    }
    
    //
    // If returns (the image is not auto-launched), step into monitor
    //
    StartMonitor();
    
    //
    // Monitor never returns
    //
}


// SDBTEST_main() {}
DispDrvrInitialize() { return 1; }
void Dummy_func() {}
void dummy() {}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?