www.pudn.com > S3c2410bsp.rar > bootInit.c


/* bootInit.c - ROM initialization module */

/* Copyright 2004-2005  */

#include "copyright_wrs.h"


#include "vxWorks.h"
#include "sysLib.h"
#include "config.h"
#include "errno.h"
#include "sioLib.h"

#define	UNCMP_RTN	inflate

#ifndef USER_RESERVED_MEM
#   define USER_RESERVED_MEM 0
#endif


#define	SYS_MEM_TOP \
	(LOCAL_MEM_LOCAL_ADRS + LOCAL_MEM_SIZE - USER_RESERVED_MEM)

#define SYS_MEM_BOTTOM \
	(LOCAL_MEM_LOCAL_ADRS + RESERVED)

#define BINARRAYEND_ROUNDOFF	(ROUND_DOWN(binArrayEnd, sizeof(long))) 


#define WR_LONG_SDRAM(addr , data) *((volatile unsigned long *)(addr))=(unsigned long)data
#define WR_SHORT_SDRAM(addr , data) *((volatile unsigned short *)(addr))=(unsigned short)data
#define WR_CHAR_SDRAM(addr , data) *((volatile unsigned char *)(addr))=(unsigned char)data

#define RD_LONG_SDRAM(addr) (*((volatile unsigned long *)(addr)))
#define RD_SHORT_SDRAM(addr) (*((volatile unsigned short *)(addr)))
#define RD_CHAR_SDRAM(addr) (*((volatile unsigned char *)(addr)))

IMPORT void	romInit ();
IMPORT STATUS	UNCMP_RTN ();
IMPORT void	usrInit ();
IMPORT void	sysInitAlt ();
IMPORT void	start ();


/**/
IMPORT UCHAR	binArrayStart [];	
IMPORT UCHAR	binArrayEnd [];		
IMPORT char	etext [];		
IMPORT char	end [];			
IMPORT UCHAR	wrs_kernel_data_start [];  
IMPORT UCHAR	wrs_kernel_data_end [];   


#if	((CPU_FAMILY == MIPS) || (CPU_FAMILY==PPC) || \
	 (CPU_FAMILY==COLDFIRE))
#define	RESIDENT_DATA	RAM_DST_ADRS
#else
#define	RESIDENT_DATA 	wrs_kernel_data_start	
#endif

#ifndef RAM_DST_ADRS                
#define RAM_DST_ADRS        RAM_HIGH_ADRS
#endif

#ifdef	BOOTCODE_IN_RAM			
#undef	ROM_TEXT_ADRS
#undef	ROM_BASE_ADRS
#define	ROM_TEXT_ADRS	((UINT)romInit)
#define	ROM_BASE_ADRS	((UINT)romInit)
#endif	/* BOOTCODE_IN_RAM */

#ifndef ROM_COPY_SIZE
#define	ROM_COPY_SIZE	(ROM_SIZE - (ROM_TEXT_ADRS - ROM_BASE_ADRS))
#endif

#define ROM_OFFSET(adr)	(((UINT)adr - (UINT)romInit) + ROM_TEXT_ADRS)


LOCAL void copyLongs (FAST UINT *source, FAST UINT *destination, UINT nlongs);
#ifndef	BOOTCODE_IN_RAM
LOCAL void fillLongs (FAST UINT *buf, UINT nlongs, FAST UINT val);
#endif	/* BOOTCODE_IN_RAM */
#if (CPU==XSCALE)
int checkLongs (FAST UINT *source, FAST UINT *destination, UINT nlongs);
#endif


void romStart
    (
    FAST int startType		
    )

    {
    
	
#if ((CPU_FAMILY==SPARC) || (CPU_FAMILY==MIPS) || (CPU_FAMILY==I80X86) || \
     (CPU_FAMILY==PPC) || (CPU_FAMILY==ARM))
    volatile			
#endif 
    FUNCPTR absEntry;		
#if (CPU_FAMILY==ARM) && (!defined(ROM_RESIDENT)) && !defined(BOOTCODE_IN_RAM)
    VOIDFUNCPTR ramfillLongs = fillLongs;     
#define fillLongs(a,b,c) ramfillLongs(a,b,c)
#endif 
#if (CPU_FAMILY==MC680X0) && !defined(ROM_RESIDENT) && !defined(BOOTCODE_IN_RAM)
    volatile VOIDFUNCPTR romcopyLongs = ©Longs; 
#define copyLongs romcopyLongs
#endif 

#ifdef ROM_RESIDENT
     
    
#if  (CPU_FAMILY == SPARC)
    copyLongs ((UINT *)(etext + 8), (UINT *) RESIDENT_DATA,
#else
    copyLongs ((UINT *)etext, (UINT *) RESIDENT_DATA,
#endif
        ((UINT) wrs_kernel_data_end - (UINT) RESIDENT_DATA) / sizeof (long));

#else	/* ROM_RESIDENT */

	

#ifdef UNCOMPRESS	
	

#if	(CPU_FAMILY == MIPS)
    ((FUNCPTR)ROM_OFFSET(copyLongs)) (ROM_TEXT_ADRS, (UINT)K0_TO_K1(romInit),
		ROM_COPY_SIZE / sizeof (long));
#else	/* CPU_FAMILY == MIPS */
	
#ifndef RAM_SIM 
	
    ((FUNCPTR)ROM_OFFSET(copyLongs)) (ROM_TEXT_ADRS, (UINT)romInit,
		ROM_COPY_SIZE / sizeof (long));	

		

#endif	
#endif	

#else	

#if	(CPU_FAMILY == MIPS)
    ((FUNCPTR)ROM_OFFSET(copyLongs)) (ROM_TEXT_ADRS, (UINT)K0_TO_K1(romInit),
		((UINT)wrs_kernel_data_end - (UINT)romInit) / sizeof (long));
#else	/* CPU_FAMILY == MIPS */
    ((FUNCPTR)ROM_OFFSET(copyLongs)) (ROM_TEXT_ADRS, (UINT)romInit,
		((UINT)binArrayStart - (UINT)romInit)/ sizeof (long));

    ((FUNCPTR)ROM_OFFSET(copyLongs)) 
           ((UINT *)((UINT)ROM_TEXT_ADRS + ((UINT)BINARRAYEND_ROUNDOFF - 
           (UINT)romInit)), (UINT *)BINARRAYEND_ROUNDOFF, 
           ((UINT)wrs_kernel_data_end - (UINT)binArrayEnd) / sizeof (long));

#if (CPU==XSCALE)
    ((FUNCPTR)ROM_OFFSET(checkLongs))
                 (ROM_TEXT_ADRS, (UINT)romInit,
                 ((UINT)binArrayStart - (UINT)romInit) / sizeof (long));

    ((FUNCPTR)ROM_OFFSET(checkLongs))
           ((UINT *)((UINT)ROM_TEXT_ADRS + ((UINT)BINARRAYEND_ROUNDOFF - 
            (UINT)romInit)), (UINT *)BINARRAYEND_ROUNDOFF,
            ((UINT)wrs_kernel_data_end - (UINT)binArrayEnd) / sizeof (long));
#endif
#endif	/* CPU_FAMILY == MIPS */

#endif	/* UNCOMPRESS */
#endif	/* ROM_RESIDENT */

	

#if	(CPU_FAMILY != MIPS) && (!defined (BOOTCODE_IN_RAM))


    if (startType & BOOT_CLEAR)
	{
#ifdef ROM_RESIDENT
	fillLongs ((UINT *)SYS_MEM_BOTTOM,
		((UINT) RESIDENT_DATA - STACK_SAVE - (UINT)SYS_MEM_BOTTOM)
		/ sizeof(long), 0);
	fillLongs (((UINT *) wrs_kernel_data_end),
	((UINT)SYS_MEM_TOP - ((UINT) wrs_kernel_data_end)) / sizeof(long), 0);

#else	/* ROM_RESIDENT */
	fillLongs ((UINT *)(SYS_MEM_BOTTOM),
		((UINT)romInit - STACK_SAVE - (UINT)SYS_MEM_BOTTOM) /
		sizeof(long), 0);

#if     defined (UNCOMPRESS)
	fillLongs ((UINT *)((UINT)romInit + ROM_COPY_SIZE),
		    ((UINT)SYS_MEM_TOP - ((UINT)romInit + ROM_COPY_SIZE))
		    / sizeof(long), 0);
#else
	fillLongs ((UINT *)wrs_kernel_data_end,
		((UINT)SYS_MEM_TOP - (UINT)wrs_kernel_data_end) / sizeof (long), 0);
#endif 	/* UNCOMPRESS */
#endif 	/* ROM_RESIDENT */


	*(BOOT_LINE_ADRS) = EOS;
	}

#endif	

	

#if	defined (UNCOMPRESS) || defined (ROM_RESIDENT)
#if	(CPU_FAMILY == I960)
    absEntry = (FUNCPTR)sysInitAlt;			
#else
	
    absEntry = (FUNCPTR)usrInit;			
	
#endif	/* CPU_FAMILY == I960 */

#else  
    {
#if	(CPU_FAMILY == MIPS)
    volatile FUNCPTR absUncompress = (FUNCPTR) UNCMP_RTN;
    if ((absUncompress) ((UCHAR *)ROM_OFFSET(binArrayStart),
			 (UCHAR *)K0_TO_K1(RAM_DST_ADRS),
			 (int)((UINT)binArrayEnd - (UINT)binArrayStart)) != OK)
#elif	(CPU_FAMILY == I80X86) || (CPU_FAMILY == ARM)
    volatile FUNCPTR absUncompress = (FUNCPTR) UNCMP_RTN;
    if ((absUncompress) ((UCHAR *)ROM_OFFSET(binArrayStart),
	            (UCHAR *)RAM_DST_ADRS, binArrayEnd - binArrayStart) != OK)
#else
    if (UNCMP_RTN ((UCHAR *)ROM_OFFSET(binArrayStart),
	            (UCHAR *)RAM_DST_ADRS, binArrayEnd - binArrayStart) != OK)
#endif	
	return;		

    absEntry = (FUNCPTR)RAM_DST_ADRS;			
    }
#endif	

#if	((CPU_FAMILY == ARM) && ARM_THUMB)
    absEntry = (FUNCPTR)((UINT32)absEntry | 1);		/* force Thumb state */
#endif	/* CPU_FAMILY == ARM */

	
    (absEntry) (startType);

}

#if     (CPU_FAMILY==ARM) && (!defined(ROM_RESIDENT))
#undef fillLongs
#endif 


#if (CPU_FAMILY==MC680X0) && !defined(ROM_RESIDENT) && !defined(BOOTCODE_IN_RAM)
#undef copyLongs	
#endif /* CPU_FAMILY==MC680X0 */

/*******************************************************************************
*/

LOCAL void copyLongs (source, destination, nlongs)
    FAST UINT *source;		
    FAST UINT *destination;	
    UINT nlongs;		
{
    FAST UINT *dstend = destination + nlongs;
    FAST UINT nchunks;

    for (nchunks = nlongs / 8; nchunks; --nchunks)
	{
#if (CPU_FAMILY == MC680X0)
	*destination++ = *source++;	/* 0 */
	*destination++ = *source++;	/* 1 */
	*destination++ = *source++;	/* 2 */
	*destination++ = *source++;	/* 3 */
	*destination++ = *source++;	/* 4 */
	*destination++ = *source++;	/* 5 */
	*destination++ = *source++;	/* 6 */
	*destination++ = *source++;	/* 7 */
#else
	destination[0] = source[0];
	destination[1] = source[1];
	destination[2] = source[2];
	destination[3] = source[3];
	destination[4] = source[4];
	destination[5] = source[5];
	destination[6] = source[6];
	destination[7] = source[7];
	destination += 8, source += 8;
	
#endif /* CPU_FAMILY == MC680X0 */
	}

    while (destination < dstend)
	*destination++ = *source++;
}

#ifndef	BOOTCODE_IN_RAM
/*******************************************************************************
*/

LOCAL void fillLongs (buf, nlongs, val)
    FAST UINT *buf;
    UINT nlongs;	
    FAST UINT val;	

{
    FAST UINT *bufend = buf + nlongs;
    FAST UINT nchunks;

    for (nchunks = nlongs / 8; nchunks; --nchunks)
	{
#if (CPU_FAMILY == MC680X0)
	*buf++ = val;	/* 0 */
	*buf++ = val;	/* 1 */
	*buf++ = val;	/* 2 */
	*buf++ = val;	/* 3 */
	*buf++ = val;	/* 4 */
	*buf++ = val;	/* 5 */
	*buf++ = val;	/* 6 */
	*buf++ = val;	/* 7 */
#else
	buf[0] = val;
	buf[1] = val;
	buf[2] = val;
	buf[3] = val;
	buf[4] = val;
	buf[5] = val;
	buf[6] = val;
	buf[7] = val;
	buf += 8;
#endif /* CPU_FAMILY == MC680X0 */
	}

    while (buf < bufend)
	*buf++ = val;
}
#endif	/* BOOTCODE_IN_RAM */

#if (CPU==XSCALE)
int checkLongs (source, destination, nlongs)
    FAST UINT *source;         
    FAST UINT *destination;    
    UINT nlongs;              

{
    int fine = 1;

    FAST UINT *dstend = destination + nlongs;

    while (destination < dstend)
    {
        if (*destination++ != *source++)
        {
            fine = 0;
            break;
        }
    }
    return fine;
}
#endif