loongarch-hw-point.h revision 1.1.1.1 1 1.1 christos /* Native-dependent code for GNU/Linux on LoongArch processors.
2 1.1 christos
3 1.1 christos Copyright (C) 2024 Free Software Foundation, Inc.
4 1.1 christos Contributed by Loongson Ltd.
5 1.1 christos
6 1.1 christos This file is part of GDB.
7 1.1 christos
8 1.1 christos This program is free software; you can redistribute it and/or modify
9 1.1 christos it under the terms of the GNU General Public License as published by
10 1.1 christos the Free Software Foundation; either version 3 of the License, or
11 1.1 christos (at your option) any later version.
12 1.1 christos
13 1.1 christos This program is distributed in the hope that it will be useful,
14 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
15 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 1.1 christos GNU General Public License for more details.
17 1.1 christos
18 1.1 christos You should have received a copy of the GNU General Public License
19 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 1.1 christos
21 1.1 christos #ifndef GDB_NAT_LOONGARCH_HW_POINT_H
22 1.1 christos #define GDB_NAT_LOONGARCH_HW_POINT_H
23 1.1 christos
24 1.1 christos /* Macro definitions, data structures, and code for the hardware
25 1.1 christos breakpoint and hardware watchpoint support follow. We use the
26 1.1 christos following abbreviations throughout the code:
27 1.1 christos
28 1.1 christos hw - hardware
29 1.1 christos bp - breakpoint
30 1.1 christos wp - watchpoint */
31 1.1 christos
32 1.1 christos /* Maximum number of hardware breakpoint and watchpoint registers.
33 1.1 christos Neither of these values may exceed the width of dr_changed_t
34 1.1 christos measured in bits. */
35 1.1 christos
36 1.1 christos #define LOONGARCH_HBP_MAX_NUM 8
37 1.1 christos #define LOONGARCH_HWP_MAX_NUM 8
38 1.1 christos
39 1.1 christos
40 1.1 christos /* The maximum length of a memory region that can be watched by one
41 1.1 christos hardware watchpoint register. */
42 1.1 christos
43 1.1 christos #define LOONGARCH_HWP_MAX_LEN_PER_REG 8
44 1.1 christos #define CTRL_PLV3_ENABLE 0x10
45 1.1 christos
46 1.1 christos #define DR_CONTROL_ENABLED(ctrl) ((ctrl & CTRL_PLV3_ENABLE) == CTRL_PLV3_ENABLE)
47 1.1 christos
48 1.1 christos /* Structure for managing the hardware breakpoint/watchpoint resources.
49 1.1 christos DR_ADDR_* stores the address, DR_CTRL_* stores the control register
50 1.1 christos content, and DR_REF_COUNT_* counts the numbers of references to the
51 1.1 christos corresponding bp/wp, by which way the limited hardware resources
52 1.1 christos are not wasted on duplicated bp/wp settings (though so far gdb has
53 1.1 christos done a good job by not sending duplicated bp/wp requests). */
54 1.1 christos
55 1.1 christos struct loongarch_debug_reg_state
56 1.1 christos {
57 1.1 christos /* hardware breakpoint */
58 1.1 christos CORE_ADDR dr_addr_bp[LOONGARCH_HBP_MAX_NUM];
59 1.1 christos unsigned int dr_ctrl_bp[LOONGARCH_HBP_MAX_NUM];
60 1.1 christos unsigned int dr_ref_count_bp[LOONGARCH_HBP_MAX_NUM];
61 1.1 christos
62 1.1 christos /* hardware watchpoint */
63 1.1 christos CORE_ADDR dr_addr_wp[LOONGARCH_HWP_MAX_NUM];
64 1.1 christos unsigned int dr_ctrl_wp[LOONGARCH_HWP_MAX_NUM];
65 1.1 christos unsigned int dr_ref_count_wp[LOONGARCH_HWP_MAX_NUM];
66 1.1 christos };
67 1.1 christos
68 1.1 christos extern int loongarch_num_bp_regs;
69 1.1 christos extern int loongarch_num_wp_regs;
70 1.1 christos
71 1.1 christos /* Invoked when IDXth breakpoint/watchpoint register pair needs to be
72 1.1 christos updated. */
73 1.1 christos
74 1.1 christos void loongarch_notify_debug_reg_change (ptid_t ptid, int is_watchpoint,
75 1.1 christos unsigned int idx);
76 1.1 christos
77 1.1 christos
78 1.1 christos int loongarch_handle_breakpoint (enum target_hw_bp_type type, CORE_ADDR addr,
79 1.1 christos int len, int is_insert, ptid_t ptid,
80 1.1 christos struct loongarch_debug_reg_state *state);
81 1.1 christos
82 1.1 christos int loongarch_handle_watchpoint (enum target_hw_bp_type type, CORE_ADDR addr,
83 1.1 christos int len, int is_insert, ptid_t ptid,
84 1.1 christos struct loongarch_debug_reg_state *state);
85 1.1 christos
86 1.1 christos /* Return TRUE if there are any hardware breakpoints. If WATCHPOINT is TRUE,
87 1.1 christos check hardware watchpoints instead. */
88 1.1 christos
89 1.1 christos bool loongarch_any_set_debug_regs_state (loongarch_debug_reg_state *state,
90 1.1 christos bool watchpoint);
91 1.1 christos
92 1.1 christos /* Print the values of the cached breakpoint/watchpoint registers. */
93 1.1 christos
94 1.1 christos void loongarch_show_debug_reg_state (struct loongarch_debug_reg_state *state,
95 1.1 christos const char *func, CORE_ADDR addr,
96 1.1 christos int len, enum target_hw_bp_type type);
97 1.1 christos
98 1.1 christos /* Return true if we can watch a memory region that starts address
99 1.1 christos ADDR and whose length is LEN in bytes. */
100 1.1 christos
101 1.1 christos int loongarch_region_ok_for_watchpoint (CORE_ADDR addr, int len);
102 1.1 christos
103 1.1 christos #endif /* GDB_NAT_LOONGARCH_HW_POINT_H */
104