2021-08-05 17:35:07 +02:00
|
|
|
/*
|
|
|
|
|
* SPDX-FileCopyrightText: 2020-2021 Espressif Systems (Shanghai) CO LTD
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
|
*/
|
2016-11-21 17:15:37 +08:00
|
|
|
|
|
|
|
|
#include "esp_attr.h"
|
2021-12-14 10:08:15 +05:30
|
|
|
#include "esp_cpu.h"
|
2016-11-21 17:15:37 +08:00
|
|
|
#include "soc/soc.h"
|
2020-01-19 10:47:20 +08:00
|
|
|
#include "soc/rtc_periph.h"
|
|
|
|
|
#include "sdkconfig.h"
|
|
|
|
|
|
|
|
|
|
#include "hal/cpu_hal.h"
|
|
|
|
|
#include "hal/cpu_types.h"
|
2020-11-06 15:00:07 +11:00
|
|
|
#include "hal/mpu_hal.h"
|
2020-01-19 10:47:20 +08:00
|
|
|
|
2021-02-19 20:23:32 +08:00
|
|
|
#include "esp_cpu.h"
|
|
|
|
|
|
2020-01-19 10:47:20 +08:00
|
|
|
#include "hal/soc_hal.h"
|
2020-02-03 14:58:19 +08:00
|
|
|
#include "soc/soc_caps.h"
|
2020-01-19 10:02:21 +08:00
|
|
|
|
2017-01-06 17:19:09 +08:00
|
|
|
#include "sdkconfig.h"
|
2016-11-21 17:15:37 +08:00
|
|
|
|
|
|
|
|
void IRAM_ATTR esp_cpu_stall(int cpu_id)
|
|
|
|
|
{
|
2020-02-03 14:58:19 +08:00
|
|
|
#if SOC_CPU_CORES_NUM > 1
|
2020-01-19 10:47:20 +08:00
|
|
|
soc_hal_stall_core(cpu_id);
|
2020-02-03 14:58:19 +08:00
|
|
|
#endif
|
2016-11-21 17:15:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void IRAM_ATTR esp_cpu_unstall(int cpu_id)
|
|
|
|
|
{
|
2020-02-03 14:58:19 +08:00
|
|
|
#if SOC_CPU_CORES_NUM > 1
|
2020-01-19 10:47:20 +08:00
|
|
|
soc_hal_unstall_core(cpu_id);
|
2020-02-03 14:58:19 +08:00
|
|
|
#endif
|
2016-11-21 17:15:37 +08:00
|
|
|
}
|
2016-12-06 16:33:24 -08:00
|
|
|
|
2017-10-26 19:11:47 +08:00
|
|
|
void IRAM_ATTR esp_cpu_reset(int cpu_id)
|
|
|
|
|
{
|
2020-01-19 10:47:20 +08:00
|
|
|
soc_hal_reset_core(cpu_id);
|
2017-10-26 19:11:47 +08:00
|
|
|
}
|
|
|
|
|
|
2021-02-19 20:23:32 +08:00
|
|
|
esp_err_t IRAM_ATTR esp_cpu_set_watchpoint(int no, void *adr, int size, int flags)
|
2016-12-06 16:33:24 -08:00
|
|
|
{
|
2020-01-19 10:47:20 +08:00
|
|
|
watchpoint_trigger_t trigger;
|
2020-01-19 10:02:21 +08:00
|
|
|
|
2020-01-19 10:47:20 +08:00
|
|
|
switch (flags)
|
|
|
|
|
{
|
2021-12-14 10:08:15 +05:30
|
|
|
case ESP_CPU_WATCHPOINT_LOAD:
|
2020-01-19 10:47:20 +08:00
|
|
|
trigger = WATCHPOINT_TRIGGER_ON_RO;
|
|
|
|
|
break;
|
2021-12-14 10:08:15 +05:30
|
|
|
case ESP_CPU_WATCHPOINT_STORE:
|
2020-01-19 10:47:20 +08:00
|
|
|
trigger = WATCHPOINT_TRIGGER_ON_WO;
|
|
|
|
|
break;
|
2021-12-14 10:08:15 +05:30
|
|
|
case ESP_CPU_WATCHPOINT_ACCESS:
|
2020-01-19 10:47:20 +08:00
|
|
|
trigger = WATCHPOINT_TRIGGER_ON_RW;
|
|
|
|
|
break;
|
|
|
|
|
default:
|
2020-01-19 10:02:21 +08:00
|
|
|
return ESP_ERR_INVALID_ARG;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-21 08:27:14 +05:00
|
|
|
cpu_hal_set_watchpoint(no, adr, size, trigger);
|
|
|
|
|
return ESP_OK;
|
2020-01-19 10:02:21 +08:00
|
|
|
}
|
|
|
|
|
|
2021-02-19 20:23:32 +08:00
|
|
|
void IRAM_ATTR esp_cpu_clear_watchpoint(int no)
|
2020-01-19 10:02:21 +08:00
|
|
|
{
|
2020-01-19 10:47:20 +08:00
|
|
|
cpu_hal_clear_watchpoint(no);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IRAM_ATTR esp_cpu_in_ocd_debug_mode(void)
|
|
|
|
|
{
|
2020-11-26 16:10:21 +11:00
|
|
|
#if CONFIG_ESP32_DEBUG_OCDAWARE || \
|
|
|
|
|
CONFIG_ESP32S2_DEBUG_OCDAWARE || \
|
|
|
|
|
CONFIG_ESP32S3_DEBUG_OCDAWARE || \
|
2021-06-10 15:22:43 +08:00
|
|
|
CONFIG_ESP32C3_DEBUG_OCDAWARE || \
|
2021-11-06 17:23:21 +08:00
|
|
|
CONFIG_ESP32H2_DEBUG_OCDAWARE || \
|
|
|
|
|
CONFIG_ESP8684_DEBUG_OCDAWARE
|
2020-01-19 10:47:20 +08:00
|
|
|
return cpu_ll_is_debugger_attached();
|
|
|
|
|
#else
|
|
|
|
|
return false; // Always return false if "OCD aware" is disabled
|
|
|
|
|
#endif
|
2020-01-19 10:02:21 +08:00
|
|
|
}
|
|
|
|
|
|
2020-11-06 15:00:07 +11: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 12:48:35 +08:00
|
|
|
for (size_t i = 0; i < sizeof(illegal_regions) / sizeof(illegal_regions[0]); ++i) {
|
2020-11-06 15:00:07 +11:00
|
|
|
mpu_hal_set_region_access(illegal_regions[i], MPU_REGION_ILLEGAL);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mpu_hal_set_region_access(1, MPU_REGION_RW); // 0x20000000
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|