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

📄 misc.c

📁 完整的Bell实验室的嵌入式文件系统TFS
💻 C
📖 第 1 页 / 共 2 页
字号:
    puts(prompt);}/* prascii(): *  Print the incoming data stream as ascii if printable, else just *  print a dot. */voidprascii(uchar *data,int cnt){    int i;    for(i=0;i<cnt;i++) {        if ((*data > 0x1f) && (*data < 0x80))            printf("%c",*data);        else            putchar('.');        data++;    }}/* CommandLoop(): *  This function is called at the end of monitor initialization. *  The monitor spends most of its time here, waiting for incoming *  characters on the console interface. */voidCommandLoop(void){    extern  void LowerFlashProtectWindow();    extern  void DisableBreakInterrupt();    extern  void SetMonSTATUS();    static  char cmdline[CMDLINESIZE];    char *prefill;    prefill = (char *)0;    SetMonSTATUS();    DisableBreakInterrupt();    while(1) {        stkchk("Cmdloop");              /* Verify valid monitor stack */        writeprompt();                  /* Issue prompt */        if (!prefill)            memset(cmdline,0,CMDLINESIZE);  /* Clear command line buffer */        if (getline_p(cmdline,CMDLINESIZE,INCLUDE_LINEEDIT,prefill) == 0)            continue;        if (docommand(cmdline,0) == CMD_PREFILL)            prefill = cmdline;        else            prefill = (char *)0;#if INCLUDE_LINEEDIT        historylog(cmdline);#endif#if INCLUDE_FLASH        LowerFlashProtectWindow();#endif    }}/* mstatshowcom(): *  Common stuff that can be printed by the mstat command (part of the *  target-specific code). */voidmstatshowcom(void){#if INCLUDE_ETHERNET    printf("Ptrs: moncom: 0x%lx, etheradd: 0x%lx, ipadd: 0x%lx\n",        (ulong)&moncomptr,(ulong)etheraddr,(ulong)ipaddr);#else    printf("Moncomptr: 0x%lx\n",(ulong)&moncomptr);#endif    printf("App-assigned functions...\n");    printf(" getchar: 0x%lx\n",(ulong)remotegetchar);    printf(" putchar: 0x%lx\n",(ulong)remoteputchar);    printf(" dcacheFlush: 0x%lx\n",(ulong)dcacheFlush);    printf(" icacheInvalidate: 0x%lx\n",(ulong)icacheInvalidate);}int monitorFlags;struct monflag monflagtbl[] = {    { NOMONHEADER,  "nophdr" },     /* Don't print header at startup      */    { NODEFRAGPRN,  "nopdf" },      /* Don't print defrag msg in tfsclean */    { NOTFTPPRN,    "noptftp" },    /* Don't print for tftp RRQ or WRQ    */    { NOMONCMDPRN,  "nopmcmd" },    /* Don't print for incoming moncmd    */    { NOTFTPOVW,    "notftpovw" },  /* Don't allow TFTP srvr to overwrite */    { MONCOMVERBOSE,"moncomv" },    /* Verbose moncom() calls */    { 0,0 }};/* InitMonitorFlags(): *  If the shell variable MONFLAGS exists, then use the content of that  *  variable to populate the value monitorFlags.  The syntax of the shell *  variable is "xxx:yyyy:zzzz:abcd" where xxx,yyyy,zzzz and abcd are  *  strings from the monflagtbl that represent some bit in the long that *  is to be set. */voidInitMonitorFlags(void){    char    *mf, *colon;    struct monflag *mfp;    monitorFlags = 0;    mf = getenv("MONFLAGS");    if (!mf)        return;    while(1) {        colon = strchr(mf,':');        if (colon)            *colon = 0;        mfp = monflagtbl;        while(mfp->flagname) {            if (!strcmp(mf,mfp->flagname)) {                monitorFlags |= mfp->bit;                break;            }            mfp++;        }        if (!mfp->flagname)            printf("MONFLAGS err: %s\n",mf);        if (colon)            *colon = ':';        else            break;        mf = colon+1;    }}/* init3(): *  As each target boots up, it calls init1() and init2() to do two phases *  of hardware initialization.  This third initialization phase is common *  to all targets... */voidinit3(void){    extern  void historyinit();    extern  int atinit(), ShellVarInit();#if INCLUDE_DEBUG    /* Init AT data structures. */    atinit();#endif#if INCLUDE_LINEEDIT    /* Initialize command line history table. */    historyinit();#endif    /* Init shell variable table. */    ShellVarInit();#ifdef MONCOMPTR    /* If MONCOMPTR is defined, then verify that the definition matches     * the location of the actual moncomptr value.  The definition in     * config.h is provided so that outside applications can include that     * header file so that the value passed into monConnect() is defined     * formally. The REAL value of moncomptr is based on the location of     * the pointer in monitor memory space, determined only after the final     * link has been done.  As a result, this check is used to simply verify     * that the definition matches the actual value.     */    {    if (MONCOMPTR != (ulong)&moncomptr)        printf("\nMONCOMPTR WARNING: runtime != definition\n");     }#endif#if INCLUDE_TFS    /* After basic initialization, if the monitor's run-control file     * exists, run it prior to EthernetStartup() so that the     * MAC/IP addresses can be configured based on shell variables     * that would be loaded by the rc file.     */    tfsrunrcfile();#endif    /* After MONRC is run, establish monitor flags... */    InitMonitorFlags();    /* Now that all has been initialized, display the monitor header. */    if (!MFLAGS_NOMONHEADER())        monHeader(1);#if INCLUDE_ETHERNET    EthernetStartup(0,1);#endif#if INCLUDE_TFS    tfsrunboot();#endif}/* exceptionAutoRestart(): *  Serves two purposes: *  1. If there is an EXCEPTION_SCRIPT shell variable, then see if the *      user wants it to be executed. *  2. If there is no NO_EXCEPTION_RESTART variable, then  *      call monrestart with the incoming value (usually INITIALIZE). */voidexceptionAutoRestart(int restartvalue){    char *script;    char *arglist[2];    script = getenv("EXCEPTION_SCRIPT");    if ((script) &&        (!pollConsole("Press any key to stop exception script."))) {        arglist[0] = script;        arglist[1] = (char *)0;        tfsrun(arglist,0);    }    if (!getenv("NO_EXCEPTION_RESTART")) {        if (!pollConsole("Press any key to stop auto restart."))            monrestart(restartvalue);    }}/* getAppRamStart(): *  First looks for the content of APPRAMBASE shell variable; *  if present, that string is converted to a long and returned, *  else the value of APPLICATION_RAMSTART is returned. */ulonggetAppRamStart(void){    char    *apprambase;    ulong   value;    apprambase = getenv("APPRAMBASE");    if (apprambase)        value = strtoul(apprambase,0,0);    else        value = APPLICATION_RAMSTART;    return(value);}/* inRange(): * This function is handed a range string and a value. * If the value is within the range of the string specified, then * return 1; else return 0. * The incoming string can be a mix of ranges and values with each * range and/or value separated by a comma and a range is specified  * by 2 numbers separated by a dash. */intinRange(char *range, int value){    int     lo, hi;    char    rcopy[32], *rsp, *comma, *dash;    /* If the range pointer is NULL, then return 1.     */    if (!range)        return(1);    /* Scan the range string for valid characters:     */    rsp = range;    while(*rsp) {        if ((*rsp == ',') || (*rsp == '-') ||            ((*rsp >= '0') && (*rsp <= '9')))            rsp++;        else            break;    }    if (*rsp)        return(0);    /* If incoming range string exceeds size of copy buffer, return 0.     */    if (strlen(range) > sizeof(rcopy)-1)        return(0);    strcpy(rcopy,range);    rsp = rcopy;    do {        comma = strchr(rsp,',');        if (comma)            *comma = 0;        dash = strchr(rsp,'-');        if (dash) {            lo = atoi(rsp);            hi = atoi(dash+1);            if ((value >= lo) && (value <= hi))                return(1);        }        else {            if (value == atoi(rsp))                return(1);        }        rsp = comma+1;    } while (comma);    return(0);}

⌨️ 快捷键说明

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