Add fault handling for ESP32, ESP32-S2, and ESP32-S3.
Also bump the version.
This commit is contained in:
2
Makefile
2
Makefile
@ -12,7 +12,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
VERSION=7.0.7.5
|
VERSION=7.0.7.6
|
||||||
STABLE_VERSION=7.0.6.19
|
STABLE_VERSION=7.0.6.19
|
||||||
OLD_STABLE_VERSION=7.0.5.4
|
OLD_STABLE_VERSION=7.0.5.4
|
||||||
REVISION=$(shell git rev-parse HEAD | head -c 20)
|
REVISION=$(shell git rev-parse HEAD | head -c 20)
|
||||||
|
|||||||
@ -12,8 +12,10 @@
|
|||||||
// See the License for the specific language governing permissions and
|
// See the License for the specific language governing permissions and
|
||||||
// limitations under the License.
|
// limitations under the License.
|
||||||
|
|
||||||
#ifdef HAS_SIGNALS
|
#if defined(HAS_SIGNALS) || defined(ENABLE_ESP32_FORTH_FAULT_HANDLING)
|
||||||
# include <setjmp.h>
|
# include <setjmp.h>
|
||||||
|
#endif
|
||||||
|
#if defined(HAS_SIGNALS)
|
||||||
# include <signal.h>
|
# include <signal.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@ -21,10 +23,12 @@
|
|||||||
#define NEXT w = *ip++; JMPW
|
#define NEXT w = *ip++; JMPW
|
||||||
#define ADDROF(x) (&& OP_ ## x)
|
#define ADDROF(x) (&& OP_ ## x)
|
||||||
|
|
||||||
#ifdef HAS_SIGNALS
|
#if defined(HAS_SIGNALS) || defined(ENABLE_ESP32_FORTH_FAULT_HANDLING)
|
||||||
static __thread jmp_buf g_forth_fault;
|
static __thread jmp_buf g_forth_fault;
|
||||||
static __thread int g_forth_signal;
|
static __thread int g_forth_signal;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#if defined(HAS_SIGNALS)
|
||||||
static void forth_signal_handler(int sig) {
|
static void forth_signal_handler(int sig) {
|
||||||
g_forth_signal = sig;
|
g_forth_signal = sig;
|
||||||
sigset_t ss;
|
sigset_t ss;
|
||||||
@ -34,6 +38,17 @@ static void forth_signal_handler(int sig) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if defined(ENABLE_ESP32_FORTH_FAULT_HANDLING)
|
||||||
|
# include "soc/soc.h"
|
||||||
|
# include <xtensa/xtensa_api.h>
|
||||||
|
static __thread uint32_t g_forth_setlevel;
|
||||||
|
static void IRAM_ATTR forth_exception_handler(XtExcFrame *frame) {
|
||||||
|
g_forth_signal = frame->exccause;
|
||||||
|
XTOS_RESTORE_INTLEVEL(g_forth_setlevel);
|
||||||
|
longjmp(g_forth_fault, 1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
static cell_t *forth_run(cell_t *init_rp) {
|
static cell_t *forth_run(cell_t *init_rp) {
|
||||||
static const BUILTIN_WORD builtins[] = {
|
static const BUILTIN_WORD builtins[] = {
|
||||||
#define Z(flags, name, op, code) \
|
#define Z(flags, name, op, code) \
|
||||||
@ -50,7 +65,7 @@ static cell_t *forth_run(cell_t *init_rp) {
|
|||||||
if (!init_rp) {
|
if (!init_rp) {
|
||||||
g_sys->DOCREATE_OP = ADDROF(DOCREATE);
|
g_sys->DOCREATE_OP = ADDROF(DOCREATE);
|
||||||
g_sys->builtins = builtins;
|
g_sys->builtins = builtins;
|
||||||
#ifdef HAS_SIGNALS
|
#if defined(HAS_SIGNALS)
|
||||||
struct sigaction sa;
|
struct sigaction sa;
|
||||||
memset(&sa, 0, sizeof(sa));
|
memset(&sa, 0, sizeof(sa));
|
||||||
sa.sa_handler = forth_signal_handler;
|
sa.sa_handler = forth_signal_handler;
|
||||||
@ -58,13 +73,27 @@ static cell_t *forth_run(cell_t *init_rp) {
|
|||||||
sigaction(SIGBUS, &sa, 0);
|
sigaction(SIGBUS, &sa, 0);
|
||||||
sigaction(SIGINT, &sa, 0);
|
sigaction(SIGINT, &sa, 0);
|
||||||
sigaction(SIGFPE, &sa, 0);
|
sigaction(SIGFPE, &sa, 0);
|
||||||
|
#endif
|
||||||
|
#if defined(ENABLE_ESP32_FORTH_FAULT_HANDLING)
|
||||||
|
xt_set_exception_handler(EXCCAUSE_LOAD_STORE_ERROR, forth_exception_handler);
|
||||||
|
xt_set_exception_handler(EXCCAUSE_PRIVILEGED, forth_exception_handler);
|
||||||
|
xt_set_exception_handler(EXCCAUSE_UNALIGNED, forth_exception_handler);
|
||||||
|
xt_set_exception_handler(EXCCAUSE_DIVIDE_BY_ZERO, forth_exception_handler);
|
||||||
|
xt_set_exception_handler(EXCCAUSE_INSTR_ERROR, forth_exception_handler);
|
||||||
|
xt_set_exception_handler(EXCCAUSE_ILLEGAL, forth_exception_handler);
|
||||||
|
xt_set_exception_handler(EXCCAUSE_LOAD_PROHIBITED, forth_exception_handler);
|
||||||
|
xt_set_exception_handler(EXCCAUSE_STORE_PROHIBITED, forth_exception_handler);
|
||||||
|
xt_set_exception_handler(EXCCAUSE_INSTR_PROHIBITED, forth_exception_handler);
|
||||||
|
uint32_t default_setlevel = XTOS_SET_INTLEVEL(XCHAL_EXCM_LEVEL);
|
||||||
|
XTOS_RESTORE_INTLEVEL(default_setlevel);
|
||||||
|
g_forth_setlevel = default_setlevel;
|
||||||
#endif
|
#endif
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
register cell_t *ip, *rp, *sp, tos, w;
|
register cell_t *ip, *rp, *sp, tos, w;
|
||||||
register float *fp, ft;
|
register float *fp, ft;
|
||||||
rp = init_rp; UNPARK;
|
rp = init_rp; UNPARK;
|
||||||
#ifdef HAS_SIGNALS
|
#if defined(HAS_SIGNALS) || defined(ENABLE_ESP32_FORTH_FAULT_HANDLING)
|
||||||
if (setjmp(g_forth_fault)) {
|
if (setjmp(g_forth_fault)) {
|
||||||
rp = *g_sys->throw_handler;
|
rp = *g_sys->throw_handler;
|
||||||
*g_sys->throw_handler = (cell_t *) *rp--;
|
*g_sys->throw_handler = (cell_t *) *rp--;
|
||||||
|
|||||||
@ -86,7 +86,7 @@ static cell_t ResizeFile(cell_t fd, cell_t size);
|
|||||||
#define REQUIRED_SYSTEM_SUPPORT \
|
#define REQUIRED_SYSTEM_SUPPORT \
|
||||||
X("MS-TICKS", MS_TICKS, PUSH millis()) \
|
X("MS-TICKS", MS_TICKS, PUSH millis()) \
|
||||||
XV(internals, "RAW-YIELD", RAW_YIELD, yield()) \
|
XV(internals, "RAW-YIELD", RAW_YIELD, yield()) \
|
||||||
XV(internals, "RAW-TERMINATE", RAW_TERMINATE, exit(n0))
|
XV(internals, "RAW-TERMINATE", RAW_TERMINATE, ESP.restart())
|
||||||
|
|
||||||
#define REQUIRED_SERIAL_SUPPORT \
|
#define REQUIRED_SERIAL_SUPPORT \
|
||||||
XV(serial, "Serial.begin", SERIAL_BEGIN, Serial.begin(tos); DROP) \
|
XV(serial, "Serial.begin", SERIAL_BEGIN, Serial.begin(tos); DROP) \
|
||||||
|
|||||||
@ -52,6 +52,11 @@
|
|||||||
# define ENABLE_RMT_SUPPORT
|
# define ENABLE_RMT_SUPPORT
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
// ESP32-C3 doesn't support fault handling yet.
|
||||||
|
#if !defined(CONFIG_IDF_TARGET_ESP32C3)
|
||||||
|
# define ENABLE_ESP32_FORTH_FAULT_HANDLING
|
||||||
|
#endif
|
||||||
|
|
||||||
// Uncomment this #define for OLED Support.
|
// Uncomment this #define for OLED Support.
|
||||||
// You will need to install these libraries from the Library Manager:
|
// You will need to install these libraries from the Library Manager:
|
||||||
// Adafruit SSD1306
|
// Adafruit SSD1306
|
||||||
|
|||||||
@ -39,6 +39,9 @@ PLATFORM_SIMULATED_OPCODE_LIST
|
|||||||
#define heap_caps_get_largest_free_block(x) SIM_HEAP_SIZE
|
#define heap_caps_get_largest_free_block(x) SIM_HEAP_SIZE
|
||||||
#define heap_caps_get_free_size(x) SIM_HEAP_SIZE
|
#define heap_caps_get_free_size(x) SIM_HEAP_SIZE
|
||||||
|
|
||||||
|
// Fault handling can't work in the simulator for now.
|
||||||
|
#undef ENABLE_ESP32_FORTH_FAULT_HANDLING
|
||||||
|
|
||||||
#include "common/bits.h"
|
#include "common/bits.h"
|
||||||
#include "common/core.h"
|
#include "common/core.h"
|
||||||
#include "common/interp.h"
|
#include "common/interp.h"
|
||||||
|
|||||||
Reference in New Issue
Block a user