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

📄 agdi.cpp

📁 KEIL的例程
💻 CPP
📖 第 1 页 / 共 5 页
字号:
        }
      }
    }
  }
  return (0);
}


/*
 * Search for Breakpoint at address 'nAdr'
 */
  
DWORD BrkWalk (DWORD nAdr)  {
  AG_BP   *pB;

  for ( pB = *pBhead ; pB ; pB = pB->next )  {
    if (!pB->enabled) continue;         // this Break is disabled.
    switch (pB->type)  {
      case AG_ABREAK:                 // Address Break
        if (nAdr == pB->Adr)  {       // match
          if (pB->rcount == 1)  {
            if (pB->cmd)  {           // is command defined
              pCbFunc (AG_CB_EXECCMD, pB->cmd);  // execute command
              return (0);             // continue app when command is defined
            }
            return (1);               // don't continue app
          }
          --pB->rcount;               // decrease counter
          return (0);                 // continue app
        }
        break;

      case AG_CBREAK:                 // Conditional Break, not supported
        break;

      case AG_WBREAK:                 // Watchpoint-Break, not supported
        break;
    }
  }
  return (2);                         // no break reason found
}


AG_BP *MBreakFunc (U16 nCode, U16 n1, UL32 nAdr, AG_BP *pBp)  {
  MAMAP         x;
  struct EMM  (*s)[256];
  struct EMM      acc;
  U16         *pB;
  AG_BP       *bptemp;

  if (nCode != 5)  {
    x.a32 = nAdr;                    // requested code address
    s =  slots [x.ub[3]];            // a24-a31
    
    if (!s) {
      s = (struct EMM (*)[256])calloc(sizeof(struct EMM) * 256,1);
      slots[x.ub[3]] = s;
    }
    acc = (*s)[x.ub[2]];                       // slot available?
    if (acc.mem == NULL)  {
      acc.mem = (BYTE *) calloc(_MSGM, 1);      // map 64K + 4
      acc.atr = (DWORD *) calloc(_MSGM, 1);     // map 64K + 4
      (*s)[x.ub[2]] = acc;
   
      s =  slots [x.ub[3]];            // slot available?
      if (!s) return (NULL);
      acc = (*s)[x.ub[2]];      // slot available?
      if (acc.mem == NULL || acc.atr == NULL) // exit if automap failed
        return (NULL);               // failed: unmapped address
    }
    pB = &((WORD *)acc.atr)[x.w16>>1];  
  }

  switch (nCode)  {
    case 2:                          // Notification: 'pB' will be unlinked
      *pB &= ~(ATRX_BREAK | ATRX_BPDIS);
      break;

    case 3:                          // not sent
    case 6:                          // not sent
    case 7:                          // not sent
    case 8:                          // not sent
      break;

    case 1:                          // Notification: 'pB' will be linked
    case 4:                          // 'pB->enabled' may have changed
      if (pBp->enabled) {
        *pB = (*pB & ~ATRX_BPDIS) | ATRX_BREAK; // enable it
      } else {
        *pB = (*pB & ~ATRX_BREAK) | ATRX_BPDIS; // disable it
      }
      break;           

    case 5:                          // Bp-accept function
      abreaks = cbreaks = wbreaks = 0;       /* Assume no Conditional-Breaks */
      for ( bptemp = *pBhead ; bptemp ; bptemp = bptemp->next )  {
        if (bptemp->enabled) {
          switch (bptemp->type)  {
            case AG_ABREAK: ++abreaks; break;     /* increase Nr. of AddressBreaks */
            case AG_CBREAK: ++cbreaks; break;     /* increase Nr. of CondBreaks */
            case AG_WBREAK: ++wbreaks; break;     /* increase Nr. of WatchBreaks */
          }
        }
      }
      if (cbreaks) pBp = NULL;                   // monitor only supports ABREAKS

      break;                                    // TODO: set Bp to NULL if unsupported.
  }
    return (pBp);
}


_EXPO_ AG_BP *AG_BreakFunc (U16 nCode, U16 n1, GADR *pA, AG_BP *pB)  {

  if (PlayDead) return(NULL);

  pB = MBreakFunc (nCode, n1, pA->Adr, pB);
  
  if (PlayDead == 1) {   // Disables the driver after the communication breaks down.
    PostMessage (hMfrm, Uv2Msg, MSG_UV2_TERMINATE, 0);
  }
  return (pB);
}



static const char szGWW[] =
    "Application does not run in real time because " \
    "of conditional breakpoint(s) !\n";


/*
 * Execute until 'nAdr' is reached or some other Bp fires.
 */

void GoUntil (DWORD nAdr)  {     // 0xFFFFFFFF := go forever
  AG_BP   abp;

  pBX = NULL;                     // clear temporary Bp pointer.
  if (StopRun)  {                 // Stop-Button pressed
    StopRun = 0;
    return;
  }

  if (cbreaks || wbreaks)  {      // cond/watch break(s): need to single step
    txtout ((char *) szGWW);      // give the user a note about it.
  }
  else  {                         // Go, setup Bp's first
    if (IsBreak (curPC))  {       // Bp at current PC, step over it.
      Step();
    }
    if (!SaCBreaks (1, nAdr))  {  // set breakpoints (1:=set, 0:=clear)
      StopRun = 0;                // write breakcode(s) failed.
      return;                     // cancel Go
    }
  }

  while (!StopRun)  {
    if (IsBreak (nAdr) || cbreaks || wbreaks)  {
      Step();                    // One Step, then ReadPC()
      Invalidate();              // registers, d/i-caches
      if (BrkWalk (curPC) == 0x01) break;
      if (IsBreak (curPC)) continue;
    }
    if (cbreaks || wbreaks)  {
      continue;                  // continue stepping with c/wbreaks
    }

    GoMode = 1;
    abp.enabled = 0;
    if (pBX == NULL)  {               // setup a temporary Bp
      if (nAdr != 0xFFFFFFFF)  {      // example: g,main
        pBX = &abp;
        abp.type    = AG_ABREAK;
        abp.enabled = 1;
        abp.rcount  = 1;
        abp.ocount  = 1;
        abp.Adr     = nAdr;
        if (!SetClrBp (1, pBX))  {    // setup temporary break
          return;
        }
      }
    }

    GoCmd();

    if (abp.enabled)  {          // clear temporary break
      SetClrBp (0, &abp);
      pBX = NULL;
    }

    GoMode = 0;

    if (PlayDead) return;
    curPC = ReadPC();
    if (BrkWalk (curPC)) break;
  }

  SaCBreaks (0, nAdr);           // set breakpoints (1:=set, 0:=clear)
}



/*
 * Go/Step/Stop commands
 */

_EXPO_ U32 AG_GoStep (U16 nCode, U32 nSteps, GADR *pA)  {
  U32     nE;

  if (PlayDead) return (0);           // driver is disconnected.

  nE = 0;                             // clear error code
  switch (nCode)  {
    case AG_STOPRUN:                  // Stop Go/Step.
      StopRun = 1;
      nE = StopExec();                // nE:  1=Stopped, 0=executing
      if (nE == 1) iRun = 0;          // stopped.
      if (!iRun)  {
        Invalidate();                 // registers, caches, etc.
      }
      break;

    case AG_NSTEP:                    // execute 'nSteps' instruction steps
      iRun = 1;                       // 'executing'
      for ( ; nSteps != 0 ; --nSteps )  {
        if (StopRun) break;           // Stop-Button was pressed
        if (Step() != 0x01) break;    // 0x01 means 'Ok.'
      }
      StopRun = 0;                    // clear Stop-Button flag.
      Invalidate();                   // registers, caches, etc.
      iRun = 0;                       // clear 'executing' flag
      break;

    case AG_GOTILADR:                 // run til 'pA->Adr' or some Bp,
      iRun = 1;                       // whichever comes first
      GoUntil (pA->Adr);
      StopRun = 0;
      Invalidate();                   // registers, caches, etc.
      iRun = 0;                       // clear 'executing' flag
      break;

    case AG_GOFORBRK:                 // run forever or till some Bp reached.
      iRun = 1;
      GoUntil (0xFFFFFFFF);           // means 'go forever'
      StopRun = 0;
      Invalidate();                   // registers, caches, etc.
      iRun = 0;                       // clear 'executing' flag
      break;
  }

  if (PlayDead)  {                    // target not connected
    StopTarget();                     // shut it down
    PostMessage (hMfrm, Uv2Msg, MSG_UV2_TERMINATE, 0); // terminate ourselves
  }
  else  {
    GetRegs();                        // get target registers
    *pCURPC = REGARM.cur[15];              // let uVision2 know about PC...
  }
  return (nE);
}




_EXPO_ U32 AG_Serial (U16 nCode, U32 nSerNo, U32 nMany, void *vp)  {
  struct SerAS  va;

  if (PlayDead) return (0);    // driver is disconnected.
  va.n1 = nSerNo;              // 0:=Serial #1,  1:=Serial #2
  va.n2 = nMany;               // number of items to write

  switch (nCode)  {
    case AG_SERBOUT:           // write nMany bytes to Serial #1 Window of uVision2
      va.v.pS = (SC8 *) vp;    // content
      SendMessage (hMfrm, Uv2Msg, MSG_UV2_SERBOUT, (LPARAM) &va);
      break;

    case AG_SERWOUT:           // write nMany words to Serial #1 Window
//    va.v.pW = (U16 *) vp;    // content
//    SendMessage (hMfrm, Uv2Msg, MSG_UV2_SERWOUT, (LPARAM) &va);
      break;

    case AG_SERXIN:            // Key was pressed in Serial Window #1 or #2
//    WriteToSerPort (nSerNo, (char *) vp, nMany); // Output to serial interface
//    nSerno := Window number (#0 or #1)
//    vp     := &character(s) to send
//    nMany  := number of characters to send
      break;
  }
  return (0);
}


#if 0  // Example on how to output a string to uVision's serial window #1:
  char szSerTxt[] = "this should appear in serial window #1";
  AG_Serial (AG_SERBOUT, 0, sizeof (szSerTxt) - 1, (void *) szSerTxt);
#endif



/*
 * Trace-History access function (future extension)
 * Note: Trace is currently not supported when uVision2 is used with a target driver !
 */

_EXPO_ U32 AG_HistFunc (U32 nCode, I32 indx, I32 dir, void *vp)  {
  U32     nR = 0;

  if (PlayDead) return (0);
#if 0                  // TODO: Trace Recording Stuff
  switch (nCode)  {
    case 0:                              // Function #0: get Hist index
      break;       // dir:=1 forward, dir:=0 backward
    case 1:                              // Function #1: GetTracePC
      break;       // get PC of trace record 'indx'
    case 2:                              // Function #2: GetHistRegs
      break;       // get recorded regs of record 'indx'
    case 3:                              // Function #3: get Nr. of entries
      break;       // get number of instructions recorded so far
  }
  nR = HistFunc1 (nCode, indx, dir, (UC8 *) vp);
  return (nR);
#endif
  if (PlayDead == 1)  {
    StopTarget();
    PostMessage (hMfrm, Uv2Msg, MSG_UV2_TERMINATE, 0);
  }
  return (nR);
}


/*
 * New Register-Manager
 */

struct rGroup rGroups[] =  {
  { 0x00, 0x01, "Current",         },        // Group 0 (Current), show expanded
  { 0x00, 0x00, "User/System",     },        // Group 1 (User & System), collapsed
  { 0x00, 0x00, "Fast Interrupt",  },        // Group 2 (Fast Interrupt), collapsed
  { 0x00, 0x00, "Interrupt",       },        // Group 3 (Interrupt), collapsed
  { 0x00, 0x00, "Supervisor",      },        // Group 4 (Supervisor), collapsed
  { 0x00, 0x00, "Abort",           },        // Group 5 (Abort), collapsed
  { 0x00, 0x00, "Undefined",       },        // Group 6 (Undefined), collapsed
  { 0x00, 0x01, "Internal",        },        // Group 7 (Internal), show expanded
};

struct rItem rItems[] =  {
//--desc-nGi-nItem-szReg[]--isPC-cc-iHig--
  { 0x01, 0, 0x00, "R0",      0, 1, 0,  },
  { 0x01, 0, 0x01, "R1",      0, 1, 0,  },
  { 0x01, 0, 0x02, "R2",      0, 1, 0,  },
  { 0x01, 0, 0x03, "R3",      0, 1, 0,  },
  { 0x01, 0, 0x04, "R4",      0, 1, 0,  },
  { 0x01, 0, 0x05, "R5",      0, 1, 0,  },
  { 0x01, 0, 0x06, "R6",      0, 1, 0,  },
  { 0x01, 0, 0x07, "R7",      0, 1, 0,  },
  { 0x01, 0, 0x08, "R8",      0, 1, 0,  },
  { 0x01, 0, 0x09, "R9",      0, 1, 0,  },
  { 0x01, 0, 0x0A, "R10",     0, 1, 0,  },
  { 0x01, 0, 0x0B, "R11",     0, 1, 0,  },
  { 0x01, 0, 0x0C, "R12",     0, 1, 0,  },
  { 0x01, 0, 0x0D, "R13 (SP)",0, 1, 0,  },
  { 0x01, 0, 0x0E, "R14 (LR)",0, 1, 0,  },
  { 0x01, 0, 0x0F, "R15 (PC)",0, 1, 0,  },
  { 0x01, 0, 0x800,"CPSR",    0, 1, 0,  },
  { 0x01, 0, 0x801,"N",       0, 1, 0,  },
  { 0x01, 0, 0x802,"Z",       0, 1, 0,  },
  { 0x01, 0, 0x803,"C",       0, 1, 0,  },
  { 0x01, 0, 0x804,"V",       0, 1, 0,  },
  { 0x01, 0, 0x805,"I",       0, 1, 0,  },
  { 0x01, 0, 0x806,"F",       0, 1, 0,  },
  { 0x01, 0, 0x807,"T",       0, 1, 0,  },
  { 0x01, 0, 0x808,"M",       0, 1, 0,  },
  { 0x01, 0, 0x809,"",        0, 0, 0,  },  // Delimiter
  { 0x01, 0, 0x900,"SPSR",    0, 1, 0,  },
  { 0x01, 0, 0x901,"N",       0, 1, 0,  },
  { 0x01, 0, 0x902,"Z",       0, 1, 0,  },
  { 0x01, 0, 0x903,"C",       0, 1, 0,  },
  { 0x01, 0, 0x904,"V",       0, 1, 0,  },
  { 0x01, 0, 0x905,"I",       0, 1, 0,  },
  { 0x01, 0, 0x906,"F",       0, 1, 0,  },
  { 0x01, 0, 0x907,"T",       0, 1, 0,  },
  { 0x01, 0, 0x908,"M",       0, 1, 0,  },
  { 0x01, 0, 0x909,"",        0, 0, 0,  },  // Delimiter

  { 0x01, 1, 0x10, "R8",      0, 1, 0,  },
  { 0x01, 1, 0x11, "R9",      0, 1, 0,  },
  { 0x01, 1, 0x12, "R10",     0, 1, 0,  },
  { 0x01, 1, 0x13, "R11",     0, 1, 0,  },
  { 0x01, 1, 0x14, "R12",     0, 1, 0,  },
  { 0x01, 1, 0x15, "R13 (SP)",0, 1, 0,  },
  { 0x01, 1, 0x16, "R14 (LR)",0, 1, 0,  },

  { 0x01, 2, 0x20, "R8",      0, 1, 0,  },
  { 0x01, 2, 0x21, "R9",      0, 1, 0,  },
  { 0x01, 2, 0x22, "R10",     0, 1, 0,  },
  { 0x01, 2, 0x23, "R11",     0, 1, 0,  },
  { 0x01, 2, 0x24, "R12",     0, 1, 0,  },
  { 0x01, 2, 0x25, "R13 (SP)",0, 1, 0,  },
  { 0x01, 2, 0x26, "R14 (LR)",0, 1, 0,  },
  { 0x01, 2, 0x200,"SPSR",    0, 1, 0,  },
  { 0x01, 2, 0x201,"N",       0, 1, 0,  },
  { 0x01, 2, 0x202,"Z",       0, 1, 0,  },
  { 0x01, 2, 0x203,"C",       0, 1, 0,  },
  { 0x01, 2, 0x204,"V",       0, 1, 0,  },
  { 0x01, 2, 0x205,"I",       0, 1, 0,  },
  { 0x01, 2, 0x206,"F",       0, 1, 0,  },
  { 0x01, 2, 0x207,"T",       0, 1, 0,  },
  { 0x01, 2, 0x208,"M",       0, 1, 0,  },
  { 0x01, 2, 0x209,"",        0, 0, 0,  },  // Delimiter

  { 0x01, 3, 0x30, "R13 (SP)",0, 1, 0,  },
  { 0x01, 3, 0x31, "R14 (LR)",0, 1, 0,  },
  { 0x01, 3, 0x300,"SPSR",    0, 1, 0,  },
  { 0x01, 3, 0x301,"N",       0, 1, 0,  },
  { 0x01, 3, 0x302,"Z",       0, 1, 0,  },
  { 0x01, 3, 0x303,"C",       0, 1, 0,  },
  { 0x01, 3, 0x304,"V",       0, 1, 0,  },
  { 0x01, 3, 0x305,"I",       0, 1, 0,  },
  { 0x01, 3, 0x306,"F",       0, 1, 0,  },
  { 0x01, 3, 0x307,"T",       0, 1, 0,  },
  { 0x01, 3, 0x308,"M",       0, 1, 0,  },
  { 0x01, 3, 0x309,"",        0, 0, 0,  },  // Delimiter

  { 0x01, 4, 0x40, "R13 (SP)",0, 1, 0,  },
  { 0x01, 4, 0x41, "R14 (LR)",0, 1, 0,  },
  { 0x01, 4, 0x400,"SPSR",    0, 1, 0,  },
  { 0x01, 4, 0x401,"N"

⌨️ 快捷键说明

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