⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 CEPC的引导代码,在BOIS基础上自定义引导WINCE内核,基于VC的工程
💻 C
📖 第 1 页 / 共 3 页
字号:
                    usage(argv[0]);
                    ret = 1;
                    goto main_error;
                }
                break;

            case 'c':   /* COM port */
                if (argv[iArgIndex][2] != ':' ||
                    (argv[iArgIndex][3] != '1' && argv[iArgIndex][3] != '2'))
                {
                    printf("Invalid option - %s\n", argv[iArgIndex]);
                    usage(argv[0]);
                    ret = 1;
                    goto main_error;
                }
                BootArgs.ucComPort = (UCHAR)(argv[iArgIndex][3] - '0');
                break;

            case 'd':   /* Display mode */
                if (argv[iArgIndex][2] != ':' ||
                    argv[iArgIndex][3] < '0' || argv[iArgIndex][3] > '6')
                {
                    printf("Invalid option - %s\n", argv[iArgIndex]);
                    usage(argv[0]);
                    ret = 1;
                    goto main_error;
                }
                iDesiredMode = (int)(argv[iArgIndex][3] - '0');
                break;

			case 'e':
				if (!ParseEthernetOptions(argv[iArgIndex])) {
					printf("Invalid option - %s\n", argv[iArgIndex]);
					usage(argv[0]);
					ret = 1;
					goto main_error;
				}
				break;

			case 'l':	/* VESA VBE Linear/Flat Framebuffer display mode */
				if (!ParseVESAOptions(argv[iArgIndex]))
				{
					printf("Invalid option - %s\n", argv[iArgIndex]);
					usage(argv[0]);
					ret = 1;
					goto main_error;
				}
				iDesiredMode = BootArgs.vesaMode;
				break;

			case 'p':	/* Parallel port boot download */
				bParallelDownload=TRUE;
				pszFileName= NULL;
				break;

			case 'q':	/* Serial port boot download */
				bSerialDownload=TRUE;
				pszFileName= NULL;
				break;

            case 'v':
                bVerbose = TRUE;
                break;

            case 's':
                {
                    char   *pszPath;
					iPpfstool=1;
                    if (argv[iArgIndex][2] != '\0')
                    {
                        pszPath = &argv[iArgIndex][2];
                        if (*pszPath == ':')
                        {
                            pszPath++;
                        }
                    }
                    else if (argc > (i+1) && argv[iArgIndex+1][0] != '-' && argv[iArgIndex+1][0] != '/')
                    {
                        pszPath = argv[iArgIndex+1];
                        i++;
                    }
                    else
                    {
                        pszPath = "*.*";
                    }
                    DisplayDirectory(pszPath);
                }
                break;

                case 'g':
                case 'r':
                case 'u':
                {
                    char    *pszSource;
                    char    *pszDestination;

					iPpfstool=1;
                    if (argv[iArgIndex][2] != '\0')
                    {
                        pszSource = &argv[iArgIndex][2];
                        if (*pszSource == ':')
                        {
                            pszSource++;
                        }
                    }
                    else if (argc > (iArgIndex+1) && argv[iArgIndex+1][0] != '-' && argv[iArgIndex+1][0] != '/')
                    {
                        pszSource = argv[iArgIndex+1];
                        iArgIndex++;
                    }
                    else
                    {
                        printf("Error source path missing\n");
                        break;
                    }

                    if (argc > (iArgIndex+1) && argv[iArgIndex+1][0] != '-' && argv[iArgIndex+1][0] != '/')
                    {
                        pszDestination = argv[iArgIndex+1];
                        i++;
                    }
                    else
                    {
                        pszDestination = NULL;
                    }

                    GetFile(
                        pszSource, pszDestination,
                        cOption == 'r' ? COPY_FLAG_UPDATE_EXISTING :
                        cOption == 'u' ? COPY_FLAG_UPDATE_OR_ADD :
                        0);
                }
                break;

                default:
                    printf("Unrecognized option - %s\n", argv[iArgIndex]);
                    /* FALL THROUGH */

                case '?':
                case 'h':
                    usage(argv[0]);
                    ret = 1;
                    goto main_error;
            }
        }

        if (iArgIndex == (argc - 1))
        {
            pszFileName = argv[iArgIndex];
        }
    }

	if (iPpfstool) {
        ret = 0;
        goto main_error;
    }

    if (!XmsIsInstalled())
    {
        printf("HIMEM.SYS must be loaded\n");
        ret = 2;
        goto main_error;
    }

    if (bVerbose)
    {
        if ((xmsError = XmsQueryA20(&bEnabled)) != XMS_SUCCESS)
        {
            printf("Error querying A20 status - %s\n", XmsErrorString(xmsError));
            ret = 3;
            goto main_error;
        }

        if (bEnabled)
        {
            printf("Warning A20 line already enabled\n");
        }
    }

    /*
    ** Check if PCI Bios is available, if so find out config mechanism
    */

    BootArgs.ucPCIConfigType = GetPCIConfigMechanism();

    if (!LoadImage(bVerbose, bParallelDownload, pszFileName, &ulEntryPoint))
    {
        ret = 4;
        goto main_error;
    }

    /*
    ** Enable A20 line
    */

    if ((xmsError = XmsLocalEnableA20()) != XMS_SUCCESS)
    {
        printf("Can't enable A20 line, error = 0x%4.4X\n", xmsError);

        ret = 5;
        goto main_error;
    }

    BootArgs.ucVideoMode = SetVideoMode(iDesiredMode);
    DrawLog(BootArgs.cxDisplayScreen,BootArgs.cyDisplayScreen);
	if (BootArgs.ucVideoMode == 0)			// if using default mode
	{
		BootArgs.cxDisplayScreen     = 320;	// set params for flat framebuffer driver accordingly
		BootArgs.cyDisplayScreen     = 200;
		BootArgs.cxPhysicalScreen    = 320;	
		BootArgs.cyPhysicalScreen    = 200;
		BootArgs.bppScreen           = 8;
		BootArgs.cbScanLineLength    = 320;
		BootArgs.pvFlatFrameBuffer   = 0x800A0000;
	}
	else if (BootArgs.ucVideoMode != 0xFF)	// if not using VESA mode
	{
		BootArgs.cxDisplayScreen     = 0;	// clear these so flat framebuffer driver sees all zeroes and faults
		BootArgs.cyDisplayScreen     = 0;
		BootArgs.cxPhysicalScreen    = 0;	
		BootArgs.cyPhysicalScreen    = 0;
		BootArgs.bppScreen           = 0;
		BootArgs.cbScanLineLength    = 0;
		BootArgs.pvFlatFrameBuffer   = 0;
	}

	if (bSerialDownload)
		BootArgs.ucBaudDivisor|=0x80;

    if (bVerbose)
    {
        printf("Jumping to 0x%8.8lX\n", ulEntryPoint);
    }
    
    
    /*printf("Windows CE is starting,Please wait........\n");    
    printf("Windows CE is starting,Please wait........\n");
    printf("Windows CE is starting,Please wait........\n");
    printf("Windows CE is starting,Please wait........\n");
    printf("Windows CE is starting,Please wait........\n");
	printf("Windows CE is starting,Please wait........\n");    
	*/
	

    /*
    ** Convert arguments to linear addres
    */
    

    ulArguments = (((ULONG)(void far *)&BootArgs) >> 16) << 4;
    ulArguments += ((ULONG)(void far *)&BootArgs) & 0xFFFF;

    Launch(ulEntryPoint, ulArguments);
                                                                                   
    /*
    ** Launch shouldn't have returned
    */
    
    return 0;

main_error:
    if (usBlockHandle) {
        XmsUnlockExtendedMemory(usBlockHandle);
        XmsFreeExtendedMemory(usBlockHandle);
    }
    return ret;
}

USHORT DownloadRead(int hImage, UCHAR* ucBuffer, USHORT usReadSize, BOOL bParallelDownload)
{
	USHORT	loop;

	if (bParallelDownload)
	{
		for (loop = 0; loop < usReadSize; loop++ )
		{
			ucBuffer[loop]= (UCHAR)OEMParallelPortGetByte();
			if (NoPPFS)
			{
				return 0;
			}
		}
		return usReadSize;
	}
	else if (bSerialDownload)
	{
		OEMReadDebugBytes(ucBuffer,usReadSize);
		return usReadSize;
	}
	else
	{
		return _read(hImage, ucBuffer, usReadSize);
	}
}

int
LoadImage(BOOL bVerbose, BOOL bParallelDownload, char *pszFileName, PULONG pulEntryPoint)
{
    int             hImage;
    long            lImageSize;

    int             xmsError;

    USHORT          usTotalFree;
    USHORT          usLargestBlock;

    ULONG           ulLinearAddress;

    ULONG           ulSectionAddress;
    ULONG           ulSectionSize;
    ULONG           ulSectionChecksum;

    ULONG           ulSectionOffset;
    ULONG           ulChecksum;

    USHORT          usReadSize;
    USHORT          usAmountRead;
	ULONG			ulReadTotal=0;
	ULONG			ulReadProgress=0;

    USHORT          usIndex;

    static UCHAR    ucBuffer[ CHUNKSIZE ];

    static UCHAR    ucSignature[] = { 'B', '0', '0', '0', 'F', 'F', '\n' };
	int i;
	UCHAR			BootPacket[256];
	UCHAR			*pDestByte;
	UCHAR			*pTemp;
	unsigned int	chksum;
	long int		uiTemp;
	long int	 	bootType;
	unsigned		len;

    /*
    ** Stop the floppy motor in case it contained the image file
    */

    __asm
    {
        push    dx
        mov     dx, 03F2h   ; Floppy motor and DMA control
        in      al, dx
        and     al, 00Fh    ; Clear motor on bits
        out     dx, al
        pop     dx
    }
    /*
    ** Find the largest Extended Memory block and allocate it
    */

    xmsError = XmsQueryFreeExtendedMemory(&usLargestBlock, &usTotalFree);

    if (xmsError != XMS_SUCCESS)
    {
        printf("Error querying free extended memory - %s\n", XmsErrorString(xmsError));
		if (!bParallelDownload && !bSerialDownload)
	        _close(hImage);

        return FALSE;
    }

    if (bVerbose)
    {
        /*
        ** Print info about memory available
        */

        printf(
            "Total free extended memory = %u, largest block = %u\n",
            usTotalFree, usLargestBlock);
    }

    xmsError = XmsAllocateExtendedMemory(usLargestBlock, &usBlockHandle);

    if (xmsError != XMS_SUCCESS)
    {
        printf("Error allocating extended memory - %s\n", XmsErrorString(xmsError));
		if (!bParallelDownload && !bSerialDownload)
	        _close(hImage);

        return FALSE;
    }
    //printf("XMS usBlockHandle = 0x%x\n", usBlockHandle);

    /*
    ** Lock the block and obtain its linear address.  Then ensure that the
    ** image fits into it.
    */

⌨️ 快捷键说明

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