aarch64: add support for "reset halt"
[fw/openocd] / src / target / armv8_dpm.h
1 /*
2  * Copyright (C) 2009 by David Brownell
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14
15 #ifndef OPENOCD_TARGET_ARMV8_DPM_H
16 #define OPENOCD_TARGET_ARMV8_DPM_H
17
18 #include "arm_dpm.h"
19 #include "helper/bits.h"
20
21 /* forward-declare struct armv8_common */
22 struct armv8_common;
23
24 /**
25  * This wraps an implementation of DPM primitives.  Each interface
26  * provider supplies a structure like this, which is the glue between
27  * upper level code and the lower level hardware access.
28  *
29  * It is a PRELIMINARY AND INCOMPLETE set of primitives, starting with
30  * support for CPU register access.
31  */
32 int armv8_dpm_setup(struct arm_dpm *dpm);
33 int armv8_dpm_initialize(struct arm_dpm *dpm);
34
35 int armv8_dpm_read_current_registers(struct arm_dpm *dpm);
36 int armv8_dpm_modeswitch(struct arm_dpm *dpm, enum arm_mode mode);
37
38
39 int armv8_dpm_write_dirty_registers(struct arm_dpm *dpm, bool bpwp);
40
41 void armv8_dpm_report_wfar(struct arm_dpm *dpm, uint64_t wfar);
42
43 /* DSCR bits; see ARMv7a arch spec section C10.3.1.
44  * Not all v7 bits are valid in v6.
45  */
46 #define DSCR_DEBUG_STATUS_MASK          (0x1F <<  0)
47 #define DSCR_ERR                                        (0x1 <<  6)
48 #define DSCR_SYS_ERROR_PEND                     (0x1 <<  7)
49 #define DSCR_CUR_EL                                     (0x3 <<  8)
50 #define DSCR_EL_STATUS_MASK                     (0xF << 10)
51 #define DSCR_HDE                                        (0x1 << 14)
52 #define DSCR_SDD                                        (0x1 << 16)
53 #define DSCR_NON_SECURE             (0x1 << 18)
54 #define DSCR_MA                                         (0x1 << 20)
55 #define DSCR_TDA                                        (0x1 << 21)
56 #define DSCR_INTDIS_MASK                        (0x3 << 22)
57 #define DSCR_ITE                                        (0x1 << 24)
58 #define DSCR_PIPE_ADVANCE           (0x1 << 25)
59 #define DSCR_TXU                                        (0x1 << 26)
60 #define DSCR_RTO                                        (0x1 << 27) /* bit 28 is reserved */
61 #define DSCR_ITO                                        (0x1 << 28)
62 #define DSCR_DTR_TX_FULL            (0x1 << 29)
63 #define DSCR_DTR_RX_FULL            (0x1 << 30) /* bit 31 is reserved */
64
65
66
67 /* Methods of entry into debug mode */
68 #define DSCRV8_ENTRY_NON_DEBUG                  (0x2)
69 #define DSCRV8_ENTRY_RESTARTING                 (0x1)
70 #define DSCRV8_ENTRY_BKPT                               (0x7)
71 #define DSCRV8_ENTRY_EXT_DEBUG                  (0x13)
72 #define DSCRV8_ENTRY_HALT_STEP_NORMAL   (0x1B)
73 #define DSCRV8_ENTRY_HALT_STEP_EXECLU   (0x1F)
74 #define DSCRV8_ENTRY_OS_UNLOCK                  (0x23)
75 #define DSCRV8_ENTRY_RESET_CATCH                (0x27)
76 #define DSCRV8_ENTRY_WATCHPOINT                 (0x2B)
77 #define DSCRV8_ENTRY_HLT                                (0x2F)
78 #define DSCRV8_ENTRY_SW_ACCESS_DBG              (0x33)
79 #define DSCRV8_ENTRY_EXCEPTION_CATCH    (0x37)
80 #define DSCRV8_ENTRY_HALT_STEP                  (0x3B)
81 #define DSCRV8_HALT_MASK                        (0x3C)
82
83 /*DRCR registers*/
84 #define DRCR_CSE                                (1 << 2)
85 #define DRCR_CSPA                               (1 << 3)
86 #define DRCR_CBRRQ                              (1 << 4)
87
88
89 /* DTR modes */
90 #define DSCR_EXT_DCC_NON_BLOCKING     (0x0 << 20)
91 #define DSCR_EXT_DCC_STALL_MODE       (0x1 << 20)
92 #define DSCR_EXT_DCC_FAST_MODE        (0x2 << 20)  /* bits 22, 23 are reserved */
93
94
95 /* DRCR (debug run control register) bits */
96 #define DRCR_HALT                               (1 << 0)
97 #define DRCR_RESTART                    (1 << 1)
98 #define DRCR_CLEAR_EXCEPTIONS   (1 << 2)
99
100 /* ECR (Execution Control Register) bits */
101 #define ECR_RCE         BIT(1)
102
103 /* ESR (Event Status Register) bits */
104 #define ESR_RC          BIT(1)
105
106 /* PRSR (processor debug status register) bits */
107 #define PRSR_PU                                 (1 << 0)
108 #define PRSR_SPD                                (1 << 1)
109 #define PRSR_RESET                              (1 << 2)
110 #define PRSR_SR                                 (1 << 3)
111 #define PRSR_HALT                               (1 << 4)
112 #define PRSR_OSLK                               (1 << 5)
113 #define PRSR_DLK                                (1 << 6)
114 #define PRSR_EDAD                               (1 << 7)
115 #define PRSR_SDAD                               (1 << 8)
116 #define PRSR_EPMAD                              (1 << 9)
117 #define PRSR_SPMAD                              (1 << 10)
118 #define PRSR_SDR                                (1 << 11)
119
120 /* PRCR (processor debug control register) bits */
121 #define PRCR_CORENPDRQ                  (1 << 0)
122 #define PRCR_CWRR                               (1 << 2)
123 #define PRCR_COREPURQ                   (1 << 3)
124
125 void armv8_dpm_report_dscr(struct arm_dpm *dpm, uint32_t dcsr);
126 void armv8_dpm_handle_exception(struct arm_dpm *dpm, bool do_restore);
127 enum arm_state armv8_dpm_get_core_state(struct arm_dpm *dpm);
128
129 #endif /* OPENOCD_TARGET_ARM_DPM_H */