expression_with_stack:make stack overflow detection watchpoint optional

This commit is contained in:
Felipe Neves 2020-01-06 17:01:53 -03:00
parent 0a8c641e6f
commit c309112b8a
2 changed files with 23 additions and 0 deletions

View File

@ -1,10 +1,26 @@
// Copyright 2015-2019 Espressif Systems (Shanghai) PTE LTD
//
// 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_expression_with_stack.h> #include <esp_expression_with_stack.h>
#include <freertos/xtensa_rtos.h> #include <freertos/xtensa_rtos.h>
#include <freertos/xtensa_context.h> #include <freertos/xtensa_context.h>
StackType_t * esp_switch_stack_setup(StackType_t *stack, size_t stack_size) StackType_t * esp_switch_stack_setup(StackType_t *stack, size_t stack_size)
{ {
#if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK
int watchpoint_place = (((int)stack + 31) & ~31); int watchpoint_place = (((int)stack + 31) & ~31);
#endif
StackType_t *top_of_stack = (StackType_t *)&stack[0] + StackType_t *top_of_stack = (StackType_t *)&stack[0] +
((stack_size * sizeof(StackType_t)) / sizeof(StackType_t)); ((stack_size * sizeof(StackType_t)) / sizeof(StackType_t));
@ -18,6 +34,9 @@ StackType_t * esp_switch_stack_setup(StackType_t *stack, size_t stack_size)
frame->a0 = 0; frame->a0 = 0;
frame->a1 = (UBaseType_t)top_of_stack; frame->a1 = (UBaseType_t)top_of_stack;
#if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK
esp_set_watchpoint(2, (char*)watchpoint_place, 32, ESP_WATCHPOINT_STORE); esp_set_watchpoint(2, (char*)watchpoint_place, 32, ESP_WATCHPOINT_STORE);
#endif
return top_of_stack; return top_of_stack;
} }

View File

@ -46,9 +46,13 @@ esp_switch_stack_exit:
#ifndef __XTENSA_CALL0_ABI__ #ifndef __XTENSA_CALL0_ABI__
entry sp, 0x10 entry sp, 0x10
#if CONFIG_FREERTOS_WATCHPOINT_END_OF_STACK
movi a6, 2 movi a6, 2
movi a4, esp_clear_watchpoint movi a4, esp_clear_watchpoint
callx4 a4 /* clear the watchpoint before releasing stack */ callx4 a4 /* clear the watchpoint before releasing stack */
#endif
l32i a4, a2, 0 /* recover the original task stack */ l32i a4, a2, 0 /* recover the original task stack */
mov a1, a4 /* put it on sp register again */ mov a1, a4 /* put it on sp register again */
retw retw