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

📄 h8s_stub.c

📁 ecos移植到R8H系列的源码。源码包来自http://www.cetoni.de/develop/develop_ecosh8s_en.html
💻 C
📖 第 1 页 / 共 3 页
字号:
         //
         // Mnemonic | Meaning                      | Condition                    |
         // ---------+------------------------------+------------------------------+
         // BRN      | Never                        | false                        |
         //
         case GDB_H8S_OP_BCC_BF :
              break;

         //
         // Mnemonic | Meaning                      | Condition                    |
         // ---------+------------------------------+------------------------------+
         // BHI      | High                         | C v Z = 0                    |
         //
         case GDB_H8S_OP_BCC_BHI :
              if (!(GDB_H8S_CCR_C(ccr) | GDB_H8S_CCR_Z(ccr)))
              {
                 dest = pc_in + disp + instr_len;
              }
              break;

         //
         // Mnemonic | Meaning                      | Condition                    |
         // ---------+------------------------------+------------------------------+
         // BLS      | Low or Same                  | C v Z = 1                    |
         //
         case GDB_H8S_OP_BCC_BLS :
              if (GDB_H8S_CCR_C(ccr) | GDB_H8S_CCR_Z(ccr))
              {
                 dest = pc_in + disp + instr_len;
              }
              break;

         //
         // Mnemonic | Meaning                      | Condition                    |
         // ---------+------------------------------+------------------------------+
         // BHS      | Carry Clear (High or Same)   | C = 0                        |
         //
         case GDB_H8S_OP_BCC_BHS :
              if (!GDB_H8S_CCR_C(ccr))
              {
                 dest = pc_in + disp + instr_len;
              }
              break;

         //
         // Mnemonic | Meaning                      | Condition                    |
         // ---------+------------------------------+------------------------------+
         // BLO      | Carry Set (Low)              | C = 1                        |
         //
         case GDB_H8S_OP_BCC_BLO :
              if (GDB_H8S_CCR_C(ccr))
              {
                 dest = pc_in + disp + instr_len;
              }
              break;

         //
         // Mnemonic | Meaning                      | Condition                    |
         // ---------+------------------------------+------------------------------+
         // BNE      | Not Equal                    | Z = 0                        |
         //
         case GDB_H8S_OP_BCC_BNE :
              if (!GDB_H8S_CCR_Z(ccr))
              {
                 dest = pc_in + disp + instr_len;
              }
              break;

         //
         // Mnemonic | Meaning                      | Condition                    |
         // ---------+------------------------------+------------------------------+
         // BEQ      | EQual                        | Z = 1                        |
         //
         case GDB_H8S_OP_BCC_BEQ :
              if (GDB_H8S_CCR_Z(ccr))
              {
                 dest = pc_in + disp + instr_len;
              }
              break;

         //
         // Mnemonic | Meaning                      | Condition                    |
         // ---------+------------------------------+------------------------------+
         // BVC      | oVerflow Clear               | V = 0                        |
         //
         case GDB_H8S_OP_BCC_BVC :
              if (!GDB_H8S_CCR_V(ccr))
              {
                 dest = pc_in + disp + instr_len;
              }
              break;

         //
         // Mnemonic | Meaning                      | Condition                    |
         // ---------+------------------------------+------------------------------+
         // BVS      | oVerflow Set                 | V = 1                        |
         //
         case GDB_H8S_OP_BCC_BVS :
              if (GDB_H8S_CCR_V(ccr))
              {
                 dest = pc_in + disp + instr_len;
              }
              break;

         //
         // Mnemonic | Meaning                      | Condition                    |
         // ---------+------------------------------+------------------------------+
         // BPL      | PLus                         | N = 0                        |
         //
         case GDB_H8S_OP_BCC_BPL :
              if (!GDB_H8S_CCR_N(ccr))
              {
                 dest = pc_in + disp + instr_len;
              }
              break;

         //
         // Mnemonic | Meaning                      | Condition                    |
         // ---------+------------------------------+------------------------------+
         // BMI      | MInus                        | N = 1                        |
         //
         case GDB_H8S_OP_BCC_BMI :
              if (GDB_H8S_CCR_N(ccr))
              {
                 dest = pc_in + disp + instr_len;
              }
              break;

         //
         // Mnemonic | Meaning                      | Condition                    |
         // ---------+------------------------------+------------------------------+
         // BGE      | Greater or Equal             | N xor V = 0                  |
         //
         case GDB_H8S_OP_BCC_BGE :
              if (!(GDB_H8S_CCR_N(ccr) ^ GDB_H8S_CCR_V(ccr)))
              {
                 dest = pc_in + disp + instr_len;
              }
              break;

         //
         // Mnemonic | Meaning                      | Condition                    |
         // ---------+------------------------------+------------------------------+
         // BLT      | Less Than                    | N xor V = 1                  |
         //
         case GDB_H8S_OP_BCC_BLT :
             if (GDB_H8S_CCR_N(ccr) ^ GDB_H8S_CCR_V(ccr))
             {
                dest = pc_in + disp + instr_len;
             }
             break;

         //
         // Mnemonic | Meaning                      | Condition                    |
         // ---------+------------------------------+------------------------------+
         // BGT      | Greater Than                 | Z v (N xor V) = 0            |
         //
         case GDB_H8S_OP_BCC_BGT:
              if (!(GDB_H8S_CCR_Z(ccr) | (GDB_H8S_CCR_N(ccr) ^ GDB_H8S_CCR_V(ccr))))
              {
                 dest = pc_in + disp + instr_len;
              }
              break;

         //
         // Mnemonic | Meaning                      | Condition                    |
         // ---------+------------------------------+------------------------------+
         // BLE      | Less or Equal                | Z v (N xor V) = 1            |
         //
         case GDB_H8S_OP_BCC_BLE:
              if (GDB_H8S_CCR_Z(ccr) | (GDB_H8S_CCR_N(ccr) ^ GDB_H8S_CCR_V(ccr)))
              {
                 dest = pc_in + disp + instr_len;
              }
              break;

         default : ; // nothing to do here
     } // End of switch (r)
   } // End of else if (GDB_H8S_OP_BCC8(op) || GDB_H8S_OP_BCC16(op))

   return dest;
}


//============================================================================
//                            SINGLE STEPPING
///     
///  Prepares for single stepping.
///  Set things up so that the next user resume will execute one 
///  instruction. This may be done by setting breakpoints or setting a 
///  single step flag in the saved user registers, for example. 
//============================================================================
void __single_step (void)
{
   unsigned long      pc;
   short              len;                    // stores length of instruction
   long               dest;                   // destination address
   HAL_STUB_H8S_INSTR op;                     // opcode
   
   //
   // mark the single stepping flag and get the instruction and the length
   // of the instruction the PC currently pointing to
   //
   HalStubStepping = 1;                       // set single step flag
   pc = get_register(PC);                 // get saved PC value
   op = *(HAL_STUB_H8S_INSTR*)pc;             // get opcode
   len = GdbH8sInstrLen(pc);                  // get length of instruction

   //
   // If it is a branch the lets calculate the destination of the branch
   // else the next instruction is simply the current PC + length of
   // instruction PC is pointing to
   //
   if (GdbIsBranch(op))                       // if it is a branch then we have
   {                                          // to calculate the destination address
      dest = GdbGetBranchDest(pc);            // of the next instruction
   }
   else                                       // if it isn't a branch then next instruction
   {                                          // simply follows actual instruction
      dest = pc + len;            
   }
   
   //
   // Now backup the instruction of the destination of the current instruction
   // and save the address. Then plant a breakpoint there.
   //
   HalStubStepBuf.pinstr_addr  = (HAL_STUB_H8S_INSTR *)dest; // set pointer to address of next instruction
   HalStubStepBuf.saved_instr = *HalStubStepBuf.pinstr_addr; // backup the instruction
   *HalStubStepBuf.pinstr_addr = HAL_BREAKINST;              // set trapa instruction to this address so
                                                             // an exception will occur for single stepping
} 


//============================================================================
//                            CLEAR SINGLE STEP STATE
///    
///  Undo the effect of a previous __single_step().  
///  If we single stepped, restore the old instruction. 
//============================================================================
void __clear_single_step (void)
{  
    //
    // if we did single stepping restore the content of the address
    // where we placed the TRAP instruction
    //
    if (HalStubStepping) 
    {
        *HalStubStepBuf.pinstr_addr = HalStubStepBuf.saved_instr;
    } 
    
    HalStubStepping = 0;  
}


//============================================================================
//                         INSTALL AND CLEAR BREAKPOINTS
///    
///  Not used in this stub.
///  NOP since single-step HW exceptions are used instead of breakpoints.
//============================================================================
void __install_breakpoints (void)
{
    // nothing to do here
}


//============================================================================
//                         INSTALL AND CLEAR BREAKPOINTS
///
///  Not used in this stub.
///   NOP since single-step HW exceptions are used instead of breakpoints.
//============================================================================
void __clear_breakpoints (void)
{
    // nothing to do here
}


externC void CYG_LABEL_NAME(breakinst)(void);
//============================================================================
//                         IS BREAKPOINT FUNCTION
///
///    Checks if pc points to breakpoint function.
///    If the breakpoint we hit is in the breakpoint() instruction, return a
///    non-zero value.
///
///    \return Non-zero if a breakpoint() function was hit.
//============================================================================
int __is_breakpoint_function()
{
    unsigned long pc;
    pc = get_register(PC);   
    return pc == (target_register_t)&CYG_LABEL_NAME(breakinst); 
}


//============================================================================
//                           SKIP CURRENT INSTRUCTION
///    
///  Skip the current instruction.
//============================================================================
void __skipinst (void)
{
    unsigned long pc = get_register (PC);
    pc += GdbH8sInstrLen (pc);
    put_register (PC, (target_register_t) pc);
}

#endif // CYGDBG_HAL_DEBUG_GDB_INCLUDE_STUBS
//----------------------------------------------------------------------------
// End of h8s_stub.c

⌨️ 快捷键说明

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