main.c

来自「WinCE 3.0 BSP, 包含Inter SA1110, Intel_815」· C语言 代码 · 共 1,072 行 · 第 1/3 页

C
1,072
字号
/*++
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) 1995-2000 Microsoft Corporation.  All rights reserved.

Module Name:

Abstract:

Functions:


Notes:

--*/

#include <conio.h>
#include <fcntl.h>
#include <io.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <signal.h>

#include "loadcepc.h"
#include "xmsapi.h"
#include "ethernet.h"
#include "..\inc\bootarg.h"

#pragma warning(disable: 4001)

#define CHUNKSIZE   32768
#define COPY_FLAG_UPDATE_EXISTING   0x0001
#define COPY_FLAG_UPDATE_OR_ADD     0x0002

int     LoadImage(BOOL bVerbose, BOOL bParallelDownload, char *pszFileName, PULONG pulEntryAddress);

int     ExecuteImage(BOOL bVerbose, ULONG ulEntryPoint);

void    Launch(ULONG ulEntryPoint, ULONG ulArguments);

UCHAR   SetVideoMode(int iDesiredMode);
BOOL    ParseVESAOptions(char * params);

UCHAR   GetPCIConfigMechanism();
BOOL ParseEthernetOptions(char * argstr);

extern int NoPPFS;                      // parallel port not present flag
int OEMParallelPortGetByte(void);
void OEMParallelPortSendByte(UCHAR chData);
void OEMParallelPortInit(void);
void DisplayDirectory(char *pszPath);
void GetFile(char *pszSource, char *pszDestination, USHORT usCopyFlags);

BOOL SMCDetect(BYTE **ppbBaseAddress, USHORT *pwIrq);

const unsigned char   BootHeader[] = {
    0xAA,                               // header = 4 bytes
    0x55,
    0x55,
    0xAA,
    0x00,                               // opcode = 2 bytes (0 = BOOT)
    0x00,
    };
#define BOOT_HEADER_SIZE (sizeof(BootHeader) / sizeof(BootHeader[0]))

const unsigned char   BootTail[] = {
    0x5A,                               // trail = 4 bytes
    0xA5,
    0x0A,
    0x1A
    };
#define BOOT_TAIL_SIZE (sizeof(BootTail) / sizeof(BootTail[0]))

#define BOOT_TYPE -4                    // boot type for x86

struct
{
    ULONG   ulRate;
    UCHAR   ucDivisor;
}   BaudTable[] =
{
    { 9600, 12 },
    { 19200, 6 },
    { 38400, 3 },
    { 57600, 2 },
    { 115200, 1 }
};

#define NUM_BAUD_RATES  (sizeof(BaudTable) / sizeof(BaudTable[0]))

BOOT_ARGS BootArgs;
USHORT    usBlockHandle; // XMS memory handle

BOOL    bSerialDownload=FALSE;
extern int OEMReadDebugByte(void);
extern void OEMReadDebugBytes(unsigned char * ucBuffer, int usReadSize);
extern void OEMWriteDebugByte(unsigned char ch);

void
usage(char *pszProgramNameArg)
{
    char *  pszProgram;

    pszProgram = strrchr(pszProgramNameArg, '\\');

    if (pszProgram != NULL)
    {
        pszProgram++;
    }
    else
    {
        pszProgram = pszProgramNameArg;
    }

//         "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
    printf(
           "\n"
           "%s: Loads an NK ROM image into memory and boots it\n"
           "\n"
           "Usage:%s [/B:baud] [/C:port] [/D:display] [/P] [/Q] [/H] [/V]\n"
           "  [/E:Card:IO:IRQ[:<dotted IP>]] [/L:VX:VY:BPP[:PX:PY]] [<file name>]\n"
           "\n"
           "  /B  Baudrate - 9600, 19200, 38400, 57600, or 115200 (default 19200)\n"
           "\n"
           "  /C  COM Port - 1 = COM1, 2 = COM2 (default COM1)\n"
           "\n"
           "  /D  Display Resolution - 0 = 320x200x256 (default), 1 = 480x240x256,\n"
           "      2 = 640x480x256, 3 = 800x600x256, 4 = 1024x768x256\n"
           "      5 = 240x320x256, 6 = 208x240x256\n"
           "\n"
           "  /P  Parallel port boot download.\n"
           "\n"
           "  /Q  Serial port boot download.\n"
           "\n"
           "  /H  Help - displays this message\n"
           "\n"
           "  /V  Verbose - displays extra status information during boot\n"
           "\n"
           "  Default <file name> is NK.BIN except for /P option which uses\n"
           "  default on host unless <file name> specified.\n"
           "\n"
           "Press any key for more options..."
           ,pszProgram, pszProgram);
    __asm
    {
        push    dx
        xor     ax,ax
        int     0x16
        pop     dx
    }

//         "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
    printf(
           "\n"
           "\n"
           "\n"
           "Usage:%s [/B:baud] [/C:port] [/D:display] [/P] [/Q] [/H] [/V]\n"
           "  [/E:Card:IO:IRQ[:<dotted IP>]] [/L:VX:VY:BPP[:PX:PY]] [<file name>]\n"
           "\n"
           "\n"
           "  /E:Card:IO:IRQ[:<dotted IP>]  (Debug Ethernet Card parameters)\n"
           "      Card (Type) - 0 = SMC9000, 1 = NE2000, 2 = Default \n"
           "      IO (Base Address in hexidecimal) - 0 = Find PCI Card with matching IRQ\n"
           "      IRQ - Interrupt (specified in hexidecimal or decimal)\n"
           "      Dotted IP - Optional static IP address (No DHCP)\n"
           "\n"
           "\n"
           "  /L:DX:DY:BPP[:PX:PY] (Use VESA VBE Linear/Flat Framebuffer video mode)\n"
           "      DX  - Display X Size\n"
           "      DY  - Display Y Size\n"
           "      BPP - Bits Per Pixel Color Depth (8, 16, 24, or 32)\n"
           "      PX  - Optional Physical Screen X Size\n"
           "      PY  - Optional Physical Screen Y Size\n"
           "\n"
           "\n"
           "\n"
           "\n"
           "Press any key for more options..."
           ,pszProgram);

    __asm
    {
        push    dx
        xor     ax,ax
        int     0x16
        pop     dx
    }

//         "12345678901234567890123456789012345678901234567890123456789012345678901234567890"
    printf(
           "\n"
           "Usage: %s -s[:]<pattern> -(g|r|u)[[:]<pattern> [<destination>]\n"
           "-s    Show a directory of files matching <pattern>.\n"
           "\n"
           "-g    Get files matching <pattern> and copy them to the\n"
           "      optionally specified <destination>.  Any existing file with\n"
           "      the same name will be overwritten.\n"
           "\n"
           "-r    Refresh files matching <pattern> which already exist in <destination>\n"
           "      and have a timestamp newer than the one in <destination>.\n"
           "\n"
           "-u    Update files matching <pattern> which don't already exist in\n"
           "      <destination> or those that have a timestamp newer than those\n"
           "      in <destination>.\n"
           "\n"
           "<pattern> Windows filename path with optional wildcard characters.\n"
           "\n"
           "<destination> If not specified then the current directory is the default.\n"
           "      If specified and it doesn't exist and the last character is \\,\n"
           "      then the directory is created.  Otherwise <destination> is\n"
           "      treated as the name of the file.\n"
           "      It is an error for <pattern> to match multiple files\n"
           "      when <destination> specifies a file.\n"
           ,pszProgram);
}

/* This is the function that handles Ctrl+C/Ctrl+Break while downloading. */
/* We need to Unlock/free XMS or we can't do loadcepc without rebooting again */
void exitfunc (int sig)
{
    if (usBlockHandle) {
        XmsUnlockExtendedMemory(usBlockHandle);
        XmsFreeExtendedMemory(usBlockHandle);
    }
    exit (sig);
}

int
main(int argc, char **argv)
{

    char *  pszFileName = "nk.bin";
    ULONG   ulEntryPoint;
    ULONG   ulArguments;
    int     xmsError;
    BOOL    bEnabled;
    BOOL    bVerbose = FALSE;
    BOOL    bParallelDownload=FALSE;
    int     iDesiredMode = 0;
    ULONG   ulBaudRate;
    char    cOption;
    int     i;
    int     ret;
    int     iPpfstool=0;

    /* setup signal handler for Ctrl+C/Ctrl+Break */
    signal (SIGINT, exitfunc);
    signal (SIGTERM, exitfunc);
    signal (SIGABRT, exitfunc);

    /* Set up boot args struct */
    BootArgs.ucVideoMode     = 0;
    BootArgs.ucComPort       = 1;
    BootArgs.ucBaudDivisor   = 6;
    BootArgs.ucPCIConfigType = 0;

    BootArgs.dwSig = BOOTARG_SIG;
    BootArgs.dwLen = sizeof(BOOT_ARGS);
    usBlockHandle = 0;

    OEMParallelPortInit();              // initialize parallel port
    /*
    ** Parse arguments
    */

    if (argc > 1)
    {
        int iArgIndex;

        for (iArgIndex = 1; iArgIndex < argc; iArgIndex++)
        {
            if (argv[iArgIndex][0] != '/' && argv[iArgIndex][0] != '-')
            {
                break;
            }
            cOption = (char)tolower(argv[iArgIndex][1]);
            switch (cOption)
            {
            case 'b':   /* Baud rate */
                if (argv[iArgIndex][2] != ':' ||
                    argv[iArgIndex][3] < '0' || argv[iArgIndex][3] > '9')
                {
                    printf("Invalid option - %s\n", argv[iArgIndex]);
                    usage(argv[0]);
                    ret = 1;
                    goto main_error;
                }

                ulBaudRate = atol(&argv[iArgIndex][3]);

                for (i = 0; i < NUM_BAUD_RATES; i++)
                {
                    if (BaudTable[i].ulRate == ulBaudRate)
                    {
                        BootArgs.ucBaudDivisor = BaudTable[i].ucDivisor;
                        break;
                    }
                }

                if (i >= NUM_BAUD_RATES)
                {
                    printf("Unsupported baud rate - %s\n", argv[iArgIndex]);
                    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;

⌨️ 快捷键说明

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