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

📄 at.c

📁 完整的Bell实验室的嵌入式文件系统TFS
💻 C
📖 第 1 页 / 共 2 页
字号:
};intatlist(int type){    int i, j, tot;    struct atstruct *atp;    tot = 0;    atp = attbl;    for(i=0;i<ATLISTSIZE;i++) {        if (atp->inuse) {            printf("%d: AT 0x%x ",                i,atp->address);            tot++;            switch (atp->Condition) {            case PASS_COUNT:                printf("if PCNT (%d) == %d, ",                    atp->Cpcnt,atp->Cconst);                break;            case FUNC_CALL:                printf("if 0x%x() == %d, ",                    atp->Cfptr,atp->Cconst);                break;            case VAR_EQ_CONST:                printf("if VAR%d.%d == 0x%x, ",                    atp->Cvar,atp->Csize,atp->Cconst);                break;            case VAR_EQ_LOC:                printf("if VAR%d.%d == *0x%x, ",                    atp->Cvar,atp->Csize,atp->Cconst);                break;            case FLG_ALL_SET:                printf("if FLAG | 0x%x == 0x%x, ",                    atp->Cconst,atp->Cconst);                break;            case FLG_ANY_SET:                printf("if FLAG | 0x%x != 0, ",atp->Cconst);                break;            case FLG_EQ_CONST:                printf("if FLAG == 0x%x, ",atp->Cconst);                break;            }            switch(atp->Action) {            case VAR_INC:                printf("VAR%d++\n",atp->Avar);                break;            case VAR_DEC:                printf("VAR%d--\n",atp->Avar);                break;            case VAR_EQ:                printf("VAR%d = 0x%x\n",atp->Avar,atp->Aconst);                break;            case FLG_SET:                printf("FLAG |= 0x%x\n",atp->Aconst);                break;            case FLG_CLR:                printf("FLAG &= 0x%x\n",atp->Aconst);                break;            case FLG_EQ:                printf("FLAG = 0x%x\n",atp->Aconst);                break;            case BREAK:                printf("BREAK\n");                break;            }        }        atp++;    }    if (type == 0)        return(tot);    printf("AT VARS:\n");    for(j=1,i=0;i<ATVARTOT;i++,j++)        printf("  V%02d: 0x%x (%d)\n",i,atvars[i],atvars[i]);    printf("\nAT FLAG: 0x%02x\n",atflag);    return(tot);}intatdelete(int n){    int i;    if (n == -1) {        for(i=0;i<ATLISTSIZE;i++)            atclearitem(&attbl[i]);        return(0);    }    if (n < ATLISTSIZE)        atclearitem(&attbl[n]);    return(0);}/* atclearitem(): *  Clear out all members of the specified attbl[] item. */voidatclearitem(struct atstruct *atptr){    atptr->inuse = 0;    atptr->origtext = 0;    atptr->address = 0;    atptr->Condition = 0;    atptr->Cvar = 0;    atptr->Cconst = 0;    atptr->Cadd = 0;    atptr->Csize = 0;    atptr->Action = 0;    atptr->Avar = 0;    atptr->Aconst = 0;}voidatinit(void){    int i;    ulong   *vloc;    extern  void at_hdlr(), trace_hdlr();    for(i=0;i<ATLISTSIZE;i++) {        atclearitem(&attbl[i]);        attbl[i].idx = i;    }    for(i=0;i<ATVARTOT;i++)        atvars[i] = 0;    /* Load the trap handler into the vector table: */    vloc = (ulong *)(0x80 + (uchar)(TRAPNUM*4));    *vloc = (ulong)at_hdlr;    /* Load the trace handler into the vector table: */    vloc = (ulong *)(0x24);    *vloc = (ulong)trace_hdlr;    atflag = 0;}/* atswap(): *  Swap the position of 2 AT structures in the list. *  The incoming string should be formatted as XX,YY *  meaning that items XX and YY are swapped in the at list. *  If either of the items do not exist, the swap is aborted. *  This allows the debugger to arrange the at statments in a  *  particular sequence that carries out the programmed state *  machine. */intatswap(char *string){    int item1, item2;    char    *comma;    struct  atstruct atitem;    comma = strchr(string,',');    if (!comma) {        printf("Swap syntax error\n");        return(-1);    }    item1 = atoi(string);    item2 = atoi(comma+1);    if ((item1 < 0) || (item2 < 0) ||        (item1 >= ATLISTSIZE) || (item2 >= ATLISTSIZE)) {        printf("Swap item out of range\n");        return(-1);    }    if ((attbl[item1].inuse==0) || (attbl[item2].inuse==0)) {        printf("Swap item not in use\n");        return(-1);    }    /* Make the swap: */    atitem = attbl[item1];    attbl[item1] = attbl[item2];    attbl[item2] = atitem;    return(0);}/* installatpoints(): *  Replace all locations that have at-statements with TRAP. */voidinstallatpoints(void){    int i;    ushort  settrap();    for(i=0;i<ATLISTSIZE;i++) {        if (attbl[i].inuse)            settrap((uchar *)attbl[i].address);    }}ushort  settrap(char *address){    ushort  orig;    orig = *(ushort *)address;    *address = TRAPU;    *(address+1) = TRAPL;    return(orig);}/* removeatpoints(): *  Remove all traps and reload the original text. */voidremoveatpoints(void){    int i;    for(i=0;i<ATLISTSIZE;i++) {        if (attbl[i].inuse)            *(ushort *)(attbl[i].address) = attbl[i].origtext;    }}/* attrap(): *  This is the FIRST piece of code called after a breakpoint trap *  is hit. */voidattrap(void){    extern  int SetStepOverBreakpoint;    int i;    struct  atstruct *atp;    ulong   pc;    atp = attbl;    getreg("PC",&pc);    pc -= 2;    putreg("PC",pc);    if (SetStepOverBreakpoint) {        StepOverTrap();        /* Should not return */    }    removeatpoints();    for(i=0;i<ATLISTSIZE;i++) {        if ((atp->inuse) && (atp->address == pc)) {            if (atcondition(atp))                ataction(atp);        }        atp++;    }    setTraceBit();    StateOfMonitor = BREAKPOINT;    resume();}/* atcondition(): *  Test the specified condition and return 1 if condition is met; *  else return 0.  Note that if there is no condition, then  *  assume an unconditional action and return 1. */intatcondition(struct atstruct *atp){    if (atp->Condition == 0)        return(1);    switch(atp->Condition) {    case PASS_COUNT:        atp->Cpcnt++;        if (atp->Cpcnt >= atp->Cconst) {            atp->Cpcnt = 0;            return(1);        }        break;    case FUNC_CALL:        if (atp->Cfptr() == atp->Cconst)            return(1);        break;    case VAR_EQ_LOC:        if (atp->Csize == 1) {            if (*(uchar *)(atp->Cadd) == (uchar)atp->Cconst)                return(1);        }        else if (atp->Csize == 2) {            if (*(ushort *)(atp->Cadd) == (ushort)atp->Cconst)                return(1);        }        else {            if (*(ulong *)(atp->Cadd) == (ulong)atp->Cconst)                return(1);        }        break;    case VAR_EQ_CONST:        if (atvars[atp->Cvar] == atp->Cconst)            return(1);        break;    case FLG_ALL_SET:        if ((atflag & atp->Cconst) == atp->Cconst)            return(1);        break;    case FLG_ANY_SET:        if (atflag & atp->Cconst)            return(1);        break;    case FLG_EQ_CONST:        if (atflag == atp->Cconst)            return(1);        break;    }    return(0);}/* ataction(): *  Carry out the action specified in the incoming structure. */voidataction(struct atstruct *atp){    switch(atp->Action) {    case VAR_INC:        atvars[atp->Avar]++;        break;    case VAR_DEC:        atvars[atp->Avar]--;        break;    case VAR_EQ:        atvars[atp->Avar] = atp->Aconst;        break;    case FLG_SET:        atflag |= atp->Aconst;        break;    case FLG_CLR:        atflag &= ~(atp->Aconst);        break;    case FLG_EQ:        atflag = atp->Aconst;        break;    case BREAK:        getreg("PC",&PCatBreak);        printf("BREAKPOINT %d 0x%x\n",atp->idx,atp->address);        monrestart(BREAKPOINT);        break;    }}voidasyncbreak(void){    printf("ASYNC_BREAK @ 0x%x\n",PCatBreak);    monrestart(BREAKPOINT);}#elsevoidattrap(void){    printf("attrap() called with no debugger\n");    monrestart(BREAKPOINT);}voidasyncbreak(void){    printf("asyncbreak() called with no debugger\n");    monrestart(BREAKPOINT);}#endif

⌨️ 快捷键说明

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