kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

dbg.c (981B)


      1 /* ARM32 (Thumb-2) debugger ops. Phase 1 provides the breakpoint primitive
      2  * (BKPT #0 = 0xBE00, a 16-bit Thumb instruction) and the instruction-length
      3  * bounds; displaced-step and decode are host-gated follow-ons (no AArch32
      4  * execution on the arm64 dev host). */
      5 #include <string.h>
      6 
      7 #include "arch/arch.h"
      8 
      9 static KitStatus arm32_dbg_breakpoint_patch(u8* out, u32 cap, u32* len_out) {
     10   /* BKPT #0, Thumb T1 encoding 0xBE00, little-endian half-word. */
     11   static const u8 bkpt[2] = {0x00u, 0xBEu};
     12   if (!out || !len_out) return KIT_INVALID;
     13   if (cap < sizeof bkpt) return KIT_INVALID;
     14   memcpy(out, bkpt, sizeof bkpt);
     15   *len_out = (u32)sizeof bkpt;
     16   return KIT_OK;
     17 }
     18 
     19 static u64 arm32_dbg_breakpoint_addr_from_fault_pc(u64 fault_pc) {
     20   return fault_pc;
     21 }
     22 
     23 const ArchDbgOps arm32_dbg_ops = {
     24     .min_insn_len = 2u,
     25     .max_insn_len = 4u,
     26     .breakpoint_patch = arm32_dbg_breakpoint_patch,
     27     .breakpoint_addr_from_fault_pc = arm32_dbg_breakpoint_addr_from_fault_pc,
     28 };