1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef _BREAKPOINT_H_
3 #define _BREAKPOINT_H_
4
5 #include <arch/registers.h>
6 #include <types.h>
7
8 #if CONFIG(DEBUG_HW_BREAKPOINTS) && \
9 (CONFIG(DEBUG_HW_BREAKPOINTS_IN_ALL_STAGES) || ENV_RAMSTAGE)
10 struct breakpoint_handle {
11 int bp;
12 };
13
14 typedef int (*breakpoint_handler)(struct breakpoint_handle, struct eregs *info);
15
16 enum breakpoint_result {
17 BREAKPOINT_RES_OK = 0,
18 BREAKPOINT_RES_NONE_AVAILABLE = -1,
19 BREAKPOINT_RES_INVALID_HANDLE = -2,
20 BREAKPOINT_RES_INVALID_LENGTH = -3
21 };
22
23 enum breakpoint_type {
24 BREAKPOINT_TYPE_INSTRUCTION = 0x0,
25 BREAKPOINT_TYPE_DATA_WRITE = 0x1,
26 BREAKPOINT_TYPE_IO = 0x2,
27 BREAKPOINT_TYPE_DATA_RW = 0x3,
28 };
29
30 /* Creates an instruction breakpoint at the given address. */
31 enum breakpoint_result breakpoint_create_instruction(struct breakpoint_handle *out_handle,
32 void *virt_addr);
33 /* Creates a data breakpoint at the given address for len bytes. */
34 enum breakpoint_result breakpoint_create_data(struct breakpoint_handle *out_handle,
35 void *virt_addr, size_t len, bool write_only);
36 /* Removes a given breakpoint. */
37 enum breakpoint_result breakpoint_remove(struct breakpoint_handle handle);
38 /* Enables or disables a given breakpoint. */
39 enum breakpoint_result breakpoint_enable(struct breakpoint_handle handle, bool enabled);
40 /* Returns the type of a breakpoint. */
41 enum breakpoint_result breakpoint_get_type(struct breakpoint_handle handle,
42 enum breakpoint_type *type);
43 /*
44 * Sets a handler function to be called when the breakpoint is hit. The handler should return 0
45 * to continue or any other value to halt execution as a fatal error.
46 */
47 enum breakpoint_result breakpoint_set_handler(struct breakpoint_handle handle,
48 breakpoint_handler handler);
49 /* Called by x86_exception to dispatch breakpoint exceptions to the correct handler. */
50 int breakpoint_dispatch_handler(struct eregs *info);
51 #else
breakpoint_dispatch_handler(struct eregs * info)52 static inline int breakpoint_dispatch_handler(struct eregs *info)
53 {
54 /* Not implemented */
55 return 0;
56 }
57 #endif
58 #endif /* _BREAKPOINT_H_ */
59