1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 /***************************************************************************
4 * Reset stub used by esp32 target *
5 * Copyright (C) 2017 Espressif Systems Ltd. *
6 ***************************************************************************/
8 #define RTC_CNTL_RESET_STATE_REG 0x3ff48034
9 #define RTC_CNTL_RESET_STATE_DEF 0x3000
10 #define RTC_CNTL_CLK_CONF_REG 0x3ff48070
11 #define RTC_CNTL_CLK_CONF_DEF 0x2210
12 #define RTC_CNTL_STORE4_REG 0x3ff480b0
13 #define RTC_CNTL_STORE5_REG 0x3ff480b4
14 #define WDT_WKEY_VALUE 0x50D83AA1
15 #define TIMG0_WDTWPROTECT_REG 0x3ff5f064
16 #define TIMG0_WDTCONFIG0_REG 0x3ff5f048
17 #define TIMG1_WDTWPROTECT_REG 0x3FF60064
18 #define TIMG1_WDTCONFIG0_REG 0x3ff60048
19 #define RTC_CNTL_WDTCONFIG0_REG 0x3ff4808c
20 #define RTC_CNTL_WDTWPROTECT_REG 0x3ff480a4
21 #define JTAG_ENABLE_REG 0x3ff5a1fc
22 #define RTC_CNTL_OPTIONS0_REG 0x3ff48000
23 #define RTC_CNTL_OPTIONS0_DEF 0x1c492000
24 #define RTC_CNTL_SW_SYS_RST 0x80000000
25 #define DPORT_APPCPU_CTRL_A_REG 0x3ff0002c
26 #define DPORT_APPCPU_RST_EN 0x1
27 #define DPORT_APPCPU_CTRL_B_REG 0x3ff00030
28 #define DPORT_APPCPU_CLKGATE_EN 0x1
29 #define DPORT_APPCPU_CTRL_C_REG 0x3ff00034
30 #define DPORT_APPCPU_CTRL_D_REG 0x3ff00038
33 /* This stub is copied to RTC_SLOW_MEM by OpenOCD, and the CPU starts executing
34 * it instead of the ROM code (0x40000400). This stub disables watchdogs and
36 * OpenOCD will then halt the target and perform CPU reset using OCD.
40 /* Has to be at offset 0. This is the entry point of the CPU, once
41 * RTC_CNTL_PROCPU_STAT_VECTOR_SEL is cleared.
42 * CPU will come here after the system reset, triggered by RTC_CNTL_SW_SYS_RST.
44 .global cpu_at_start_handler
45 .type cpu_at_start_handler,@function
51 /* Has to be at offset 4. Once the stub code has been uploaded into RTC Slow
52 * memory, OpenOCD will set the PC to this address, and resume execution.
53 * The stub will then jump to 'reset' label and perform the reset.
55 .global cpu_reset_handler
56 .type cpu_reset_handler,@function
66 /* Use a5 as a zero register */
68 /* Select static reset vector 0 (XCHAL_RESET_VECTOR0_VADDR, 0x50000000) */
69 movi a4, RTC_CNTL_RESET_STATE_REG
71 /* Set some clock-related RTC registers to the default values */
72 movi a4, RTC_CNTL_STORE4_REG
74 movi a4, RTC_CNTL_STORE5_REG
76 movi a4, RTC_CNTL_CLK_CONF_REG
77 movi a3, RTC_CNTL_CLK_CONF_DEF
79 /* Reset the digital part of the chip (RTC controller doesn't get reset) */
80 movi a3, (RTC_CNTL_OPTIONS0_DEF | RTC_CNTL_SW_SYS_RST)
81 movi a4, RTC_CNTL_OPTIONS0_REG
83 /* Doesn't reach beyond this instruction */
87 /* If running on the APP CPU, skip directly to the parking loop */
92 /* Use a5 as a zero register */
94 /* Disable the watchdogs */
95 movi a3, WDT_WKEY_VALUE
96 movi a4, RTC_CNTL_WDTWPROTECT_REG
98 movi a4, TIMG0_WDTWPROTECT_REG
100 movi a4, TIMG1_WDTWPROTECT_REG
102 movi a4, RTC_CNTL_WDTCONFIG0_REG
104 movi a4, TIMG0_WDTCONFIG0_REG
106 movi a4, TIMG1_WDTCONFIG0_REG
108 /* Enable JTAG (needed since rev. 3) */
109 movi a4, JTAG_ENABLE_REG
111 /* Clear APP_CPU boot address */
112 movi a4, DPORT_APPCPU_CTRL_D_REG
114 /* Clear APP_CPU clock gating */
115 movi a4, DPORT_APPCPU_CTRL_B_REG
116 movi a3, DPORT_APPCPU_CLKGATE_EN
118 /* Set and clear APP_CPU reset */
119 movi a4, DPORT_APPCPU_CTRL_A_REG
120 movi a3, DPORT_APPCPU_RST_EN
123 /* Restore the reset vector to ROM */
124 movi a4, RTC_CNTL_RESET_STATE_REG
125 movi a3, RTC_CNTL_RESET_STATE_DEF
130 /* PRO and APP CPU will be in this loop, until OpenOCD
131 * finds the JTAG taps and puts the CPUs into debug mode.