1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <arch/breakpoint.h>
4 #include <arch/null_breakpoint.h>
6 #include <console/console.h>
9 static struct breakpoint_handle null_deref_bp
;
10 static struct breakpoint_handle null_fetch_bp
;
12 static int handle_fetch_breakpoint(struct breakpoint_handle handle
, struct eregs
*regs
)
14 printk(BIOS_ERR
, "Instruction fetch from address zero\n");
18 static int handle_deref_breakpoint(struct breakpoint_handle handle
, struct eregs
*regs
)
21 printk(BIOS_ERR
, "Null dereference at rip: 0x%llx\n", regs
->rip
);
23 printk(BIOS_ERR
, "Null dereference at eip: 0x%x\n", regs
->eip
);
28 static void create_deref_breakpoint(void)
30 enum breakpoint_result res
=
31 breakpoint_create_data(&null_deref_bp
, NULL
, sizeof(uintptr_t), false);
33 if (res
!= BREAKPOINT_RES_OK
) {
34 printk(BIOS_ERR
, "Failed to create NULL dereference breakpoint\n");
38 breakpoint_set_handler(null_deref_bp
, &handle_deref_breakpoint
);
39 breakpoint_enable(null_deref_bp
, true);
42 static void create_instruction_breakpoint(void)
44 enum breakpoint_result res
= breakpoint_create_instruction(&null_fetch_bp
, NULL
);
46 if (res
!= BREAKPOINT_RES_OK
) {
47 printk(BIOS_ERR
, "Failed to create address zero instruction fetch breakpoint\n");
51 breakpoint_set_handler(null_fetch_bp
, &handle_fetch_breakpoint
);
52 breakpoint_enable(null_fetch_bp
, true);
55 void null_breakpoint_init(void)
57 create_deref_breakpoint();
58 create_instruction_breakpoint();
61 void null_breakpoint_remove(void)
63 breakpoint_remove(null_fetch_bp
);
64 breakpoint_remove(null_deref_bp
);
67 static void null_breakpoint_remove_hook(void *unused
)
69 null_breakpoint_remove();
72 BOOT_STATE_INIT_ENTRY(BS_OS_RESUME
, BS_ON_ENTRY
, null_breakpoint_remove_hook
, NULL
);
73 BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_BOOT
, BS_ON_ENTRY
, null_breakpoint_remove_hook
, NULL
);