2020-01-19 02:47:20 +00:00
|
|
|
// Copyright 2020 Espressif Systems (Shanghai) PTE LTD
|
2016-11-21 09:15:37 +00:00
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
// you may not use this file except in compliance with the License.
|
|
|
|
// You may obtain a copy of the License at
|
|
|
|
//
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
//
|
|
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
// See the License for the specific language governing permissions and
|
|
|
|
// limitations under the License.
|
|
|
|
|
|
|
|
#include "esp_attr.h"
|
|
|
|
#include "soc/cpu.h"
|
|
|
|
#include "soc/soc.h"
|
2020-01-19 02:47:20 +00:00
|
|
|
#include "soc/rtc_periph.h"
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
|
|
|
|
#include "hal/cpu_hal.h"
|
|
|
|
#include "esp_debug_helpers.h"
|
|
|
|
#include "hal/cpu_types.h"
|
2020-11-06 04:00:07 +00:00
|
|
|
#include "hal/mpu_hal.h"
|
2020-01-19 02:47:20 +00:00
|
|
|
|
|
|
|
#include "hal/soc_hal.h"
|
2020-02-03 06:58:19 +00:00
|
|
|
#include "soc/soc_caps.h"
|
2020-01-19 02:02:21 +00:00
|
|
|
|
2017-01-06 09:19:09 +00:00
|
|
|
#include "sdkconfig.h"
|
2016-11-21 09:15:37 +00:00
|
|
|
|
|
|
|
void IRAM_ATTR esp_cpu_stall(int cpu_id)
|
|
|
|
{
|
2020-02-03 06:58:19 +00:00
|
|
|
#if SOC_CPU_CORES_NUM > 1
|
2020-01-19 02:47:20 +00:00
|
|
|
soc_hal_stall_core(cpu_id);
|
2020-02-03 06:58:19 +00:00
|
|
|
#endif
|
2016-11-21 09:15:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void IRAM_ATTR esp_cpu_unstall(int cpu_id)
|
|
|
|
{
|
2020-02-03 06:58:19 +00:00
|
|
|
#if SOC_CPU_CORES_NUM > 1
|
2020-01-19 02:47:20 +00:00
|
|
|
soc_hal_unstall_core(cpu_id);
|
2020-02-03 06:58:19 +00:00
|
|
|
#endif
|
2016-11-21 09:15:37 +00:00
|
|
|
}
|
2016-12-07 00:33:24 +00:00
|
|
|
|
esp_restart: fix possible race while stalling other CPU, enable WDT early
Previously esp_restart would stall the other CPU before enabling RTC_WDT.
If the other CPU was executing an s32c1i instruction, the lock signal
from CPU to the arbiter would still be held after CPU was stalled. If
the CPU running esp_restart would then try to access the same locked
memory pool, it would be stuck, because lock signal would never be
released.
With this change, esp_restart resets the other CPU before stalling it.
Ideally, we would want to reset the CPU and keep it in reset, but the
hardware doesn't have such feature for PRO_CPU (it is possible to hold
APP_CPU in reset using DPORT register). Given that ROM code will not use
s32c1i in the first few hundred cycles, doing reset and then stall seems
to be safe.
In addition to than, RTC_WDT initialization is moved to the beginning of
the function, to prevent possible lock-up if CPU stalling still has any
issue.
2017-10-26 11:11:47 +00:00
|
|
|
void IRAM_ATTR esp_cpu_reset(int cpu_id)
|
|
|
|
{
|
2020-01-19 02:47:20 +00:00
|
|
|
soc_hal_reset_core(cpu_id);
|
esp_restart: fix possible race while stalling other CPU, enable WDT early
Previously esp_restart would stall the other CPU before enabling RTC_WDT.
If the other CPU was executing an s32c1i instruction, the lock signal
from CPU to the arbiter would still be held after CPU was stalled. If
the CPU running esp_restart would then try to access the same locked
memory pool, it would be stuck, because lock signal would never be
released.
With this change, esp_restart resets the other CPU before stalling it.
Ideally, we would want to reset the CPU and keep it in reset, but the
hardware doesn't have such feature for PRO_CPU (it is possible to hold
APP_CPU in reset using DPORT register). Given that ROM code will not use
s32c1i in the first few hundred cycles, doing reset and then stall seems
to be safe.
In addition to than, RTC_WDT initialization is moved to the beginning of
the function, to prevent possible lock-up if CPU stalling still has any
issue.
2017-10-26 11:11:47 +00:00
|
|
|
}
|
|
|
|
|
2020-01-19 02:47:20 +00:00
|
|
|
esp_err_t IRAM_ATTR esp_set_watchpoint(int no, void *adr, int size, int flags)
|
2016-12-07 00:33:24 +00:00
|
|
|
{
|
2020-01-19 02:47:20 +00:00
|
|
|
watchpoint_trigger_t trigger;
|
2020-01-19 02:02:21 +00:00
|
|
|
|
2020-01-19 02:47:20 +00:00
|
|
|
switch (flags)
|
|
|
|
{
|
|
|
|
case ESP_WATCHPOINT_LOAD:
|
|
|
|
trigger = WATCHPOINT_TRIGGER_ON_RO;
|
|
|
|
break;
|
|
|
|
case ESP_WATCHPOINT_STORE:
|
|
|
|
trigger = WATCHPOINT_TRIGGER_ON_WO;
|
|
|
|
break;
|
|
|
|
case ESP_WATCHPOINT_ACCESS:
|
|
|
|
trigger = WATCHPOINT_TRIGGER_ON_RW;
|
|
|
|
break;
|
|
|
|
default:
|
2020-01-19 02:02:21 +00:00
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
}
|
|
|
|
|
2020-02-21 03:27:14 +00:00
|
|
|
cpu_hal_set_watchpoint(no, adr, size, trigger);
|
|
|
|
return ESP_OK;
|
2020-01-19 02:02:21 +00:00
|
|
|
}
|
|
|
|
|
2020-01-19 02:47:20 +00:00
|
|
|
void IRAM_ATTR esp_clear_watchpoint(int no)
|
2020-01-19 02:02:21 +00:00
|
|
|
{
|
2020-01-19 02:47:20 +00:00
|
|
|
cpu_hal_clear_watchpoint(no);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool IRAM_ATTR esp_cpu_in_ocd_debug_mode(void)
|
|
|
|
{
|
2020-11-26 05:10:21 +00:00
|
|
|
#if CONFIG_ESP32_DEBUG_OCDAWARE || \
|
|
|
|
CONFIG_ESP32S2_DEBUG_OCDAWARE || \
|
|
|
|
CONFIG_ESP32S3_DEBUG_OCDAWARE || \
|
|
|
|
CONFIG_ESP32C3_DEBUG_OCDAWARE
|
2020-01-19 02:47:20 +00:00
|
|
|
return cpu_ll_is_debugger_attached();
|
|
|
|
#else
|
|
|
|
return false; // Always return false if "OCD aware" is disabled
|
|
|
|
#endif
|
2020-01-19 02:02:21 +00:00
|
|
|
}
|
|
|
|
|
2020-02-02 15:23:16 +00:00
|
|
|
void IRAM_ATTR esp_set_breakpoint_if_jtag(void *fn)
|
|
|
|
{
|
|
|
|
if (esp_cpu_in_ocd_debug_mode()) {
|
|
|
|
cpu_hal_set_breakpoint(0, fn);
|
|
|
|
}
|
2020-11-10 07:40:01 +00:00
|
|
|
}
|
2020-11-06 04:00:07 +00:00
|
|
|
|
|
|
|
#if __XTENSA__
|
|
|
|
|
|
|
|
void esp_cpu_configure_region_protection(void)
|
|
|
|
{
|
|
|
|
/* Note: currently this is configured the same on all Xtensa targets
|
|
|
|
*
|
|
|
|
* Both chips have the address space divided into 8 regions, 512MB each.
|
|
|
|
*/
|
|
|
|
const int illegal_regions[] = {0, 4, 5, 6, 7}; // 0x00000000, 0x80000000, 0xa0000000, 0xc0000000, 0xe0000000
|
2020-11-17 04:48:35 +00:00
|
|
|
for (size_t i = 0; i < sizeof(illegal_regions) / sizeof(illegal_regions[0]); ++i) {
|
2020-11-06 04:00:07 +00:00
|
|
|
mpu_hal_set_region_access(illegal_regions[i], MPU_REGION_ILLEGAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
mpu_hal_set_region_access(1, MPU_REGION_RW); // 0x20000000
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|