ARM硬件断点

hw_breakpoint 是由处理器提供专门断点寄存器来保存一个地址,是需要处理器支持的。处理器在执行过程中会不断去匹配,当匹配上后则会产生中断。

内核自带了硬件断点的样例linux-3.16\samples\hw_breakpoint\data_breakpoint.c

cpp 复制代码
static void sample_hbp_handler(struct perf_event *bp,
			       struct perf_sample_data *data,
			       struct pt_regs *regs)
{
	printk(KERN_INFO "%s value is changed\n", ksym_name);
	dump_stack();
	printk(KERN_INFO "Dump stack from sample_hbp_handler\n");
}

static int __init hw_break_module_init(void* addr)
{
	int ret;
	struct perf_event_attr attr;

	hw_breakpoint_init(&attr);
	attr.bp_addr = addr;
	attr.bp_len = HW_BREAKPOINT_LEN_4;//监控addr开始的4字节
	attr.bp_type = HW_BREAKPOINT_W | HW_BREAKPOINT_R;//读写该地址都能触发

	sample_hbp = register_wide_hw_breakpoint(&attr, sample_hbp_handler, NULL);
	if (IS_ERR((void __force *)sample_hbp)) {
		ret = PTR_ERR((void __force *)sample_hbp);
		goto fail;
	}

	printk(KERN_INFO "HW Breakpoint for write installed\n");

	return 0;

fail:
	printk(KERN_INFO "Breakpoint registration failed\n");

	return ret;

看网上说ARM Architecture Reference Manual Supplement ARMv8.1, for ARMv8-A architecture profile这些文档的degug register里面有。文档可以在这个网站下载

https://developer.arm.com/documentation

Documentation -- Arm Developer

可以看到应该是每个cpu都注册了一个。感觉应该是在一个cpu上注册,所有cpu都会去检查(原理不清楚,上面的文档没有看明白,猜测的)

cpp 复制代码
struct perf_event * __percpu *
register_wide_hw_breakpoint(struct perf_event_attr *attr,
			    perf_overflow_handler_t triggered,
			    void *context)
{
	struct perf_event * __percpu *cpu_events, *bp;
........................................
	for_each_online_cpu(cpu) {
		bp = perf_event_create_kernel_counter(attr, cpu, NULL,
						      triggered, context);
...................................................
}

暂时不写了

相关推荐
jianqiang.xue4 天前
3倍向量算力:Arm给最小MCU装上本地AI
arm开发·人工智能·单片机
蜀黍@猿4 天前
ARM 汇编入门(十二):MMU、页表与虚拟内存全解析
汇编·arm开发·stm32·mcu
蜀黍@猿5 天前
ARM 汇编入门(十):标量浮点与 VFP 指令全解析
汇编·arm开发·stm32·mcu
Good白10197 天前
嵌入式:1.嵌入式入门|初识嵌入式、处理器、ARM与STM32
arm开发·stm32·嵌入式硬件
물の韜7 天前
ZYNQ/FMQL系列Linux之I2C开发实战
linux·arm开发·嵌入式硬件·设备树·iic·zynq
女神下凡8 天前
芯参谋(95):嵌入式文件系统_开发指南
linux·服务器·arm开发·驱动开发·设计规范
女神下凡12 天前
芯参谋(85):Linux_PPI_NAND_驱动开发指南
linux·运维·arm开发·驱动开发·单片机·嵌入式硬件·设计规范
NamoAmitabha12812 天前
ARM Cortex-A9 核心架构(演化后的“缝合怪”)--deepseek
arm开发·zynq--ps
AllData公司负责人13 天前
AllData 可定义数据中台完成信创适配|银河麒麟 + 海光X86 CPU / 华为鲲鹏ARM CPU+ OceanBase / 人大金仓国产化环境部署落地
大数据·arm开发·数据库·人工智能·oceanbase·kingbase