2017-01-22 17:21:34 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Cadence Design Systems, Inc.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
2022-05-06 10:49:15 +02:00
|
|
|
#include <zephyr/kernel.h>
|
|
|
|
#include <zephyr/arch/cpu.h>
|
|
|
|
#include <zephyr/kernel_structs.h>
|
2017-02-06 21:25:02 +01:00
|
|
|
#include <inttypes.h>
|
2019-12-03 18:59:10 +01:00
|
|
|
#include <xtensa/config/specreg.h>
|
2021-01-07 07:11:11 +01:00
|
|
|
#include <xtensa_backtrace.h>
|
2022-12-14 09:35:36 +01:00
|
|
|
#include <zephyr/arch/common/exc_handle.h>
|
2023-12-07 01:22:52 +01:00
|
|
|
|
|
|
|
#include <xtensa_internal.h>
|
|
|
|
|
2022-05-06 10:49:15 +02:00
|
|
|
#include <zephyr/logging/log.h>
|
2020-11-26 19:32:34 +01:00
|
|
|
LOG_MODULE_DECLARE(os, CONFIG_KERNEL_LOG_LEVEL);
|
2017-01-22 17:21:34 +01:00
|
|
|
|
2024-02-15 20:50:43 +01:00
|
|
|
#if defined(CONFIG_SIMULATOR_XTENSA) || defined(XT_SIMULATOR)
|
2018-06-07 10:48:38 +02:00
|
|
|
#include <xtensa/simcall.h>
|
|
|
|
#endif
|
|
|
|
|
2023-12-08 20:10:50 +01:00
|
|
|
char *xtensa_exccause(unsigned int cause_code)
|
2017-02-06 21:25:02 +01:00
|
|
|
{
|
2019-08-21 18:52:49 +02:00
|
|
|
#if defined(CONFIG_PRINTK) || defined(CONFIG_LOG)
|
2017-02-06 21:25:02 +01:00
|
|
|
switch (cause_code) {
|
|
|
|
case 0:
|
|
|
|
return "illegal instruction";
|
|
|
|
case 1:
|
|
|
|
return "syscall";
|
|
|
|
case 2:
|
|
|
|
return "instr fetch error";
|
|
|
|
case 3:
|
|
|
|
return "load/store error";
|
|
|
|
case 4:
|
|
|
|
return "level-1 interrupt";
|
|
|
|
case 5:
|
|
|
|
return "alloca";
|
|
|
|
case 6:
|
|
|
|
return "divide by zero";
|
|
|
|
case 8:
|
|
|
|
return "privileged";
|
|
|
|
case 9:
|
|
|
|
return "load/store alignment";
|
|
|
|
case 12:
|
|
|
|
return "instr PIF data error";
|
|
|
|
case 13:
|
|
|
|
return "load/store PIF data error";
|
|
|
|
case 14:
|
|
|
|
return "instr PIF addr error";
|
|
|
|
case 15:
|
|
|
|
return "load/store PIF addr error";
|
|
|
|
case 16:
|
|
|
|
return "instr TLB miss";
|
|
|
|
case 17:
|
|
|
|
return "instr TLB multi hit";
|
|
|
|
case 18:
|
|
|
|
return "instr fetch privilege";
|
|
|
|
case 20:
|
|
|
|
return "inst fetch prohibited";
|
|
|
|
case 24:
|
|
|
|
return "load/store TLB miss";
|
|
|
|
case 25:
|
|
|
|
return "load/store TLB multi hit";
|
|
|
|
case 26:
|
|
|
|
return "load/store privilege";
|
|
|
|
case 28:
|
|
|
|
return "load prohibited";
|
|
|
|
case 29:
|
|
|
|
return "store prohibited";
|
|
|
|
case 32: case 33: case 34: case 35: case 36: case 37: case 38: case 39:
|
|
|
|
return "coprocessor disabled";
|
2022-04-26 22:22:18 +02:00
|
|
|
case 63:
|
|
|
|
/* i.e. z_except_reason */
|
|
|
|
return "zephyr exception";
|
2023-04-13 00:42:38 +02:00
|
|
|
case 64:
|
|
|
|
return "kernel oops";
|
2017-02-06 21:25:02 +01:00
|
|
|
default:
|
|
|
|
return "unknown/reserved";
|
|
|
|
}
|
2019-08-21 18:52:49 +02:00
|
|
|
#else
|
|
|
|
ARG_UNUSED(cause_code);
|
|
|
|
return "na";
|
2017-02-06 21:25:02 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-12-08 20:10:50 +01:00
|
|
|
void xtensa_fatal_error(unsigned int reason, const z_arch_esf_t *esf)
|
2019-07-11 23:18:28 +02:00
|
|
|
{
|
2023-12-12 15:57:11 +01:00
|
|
|
#ifdef CONFIG_EXCEPTION_DEBUG
|
2019-07-16 00:22:29 +02:00
|
|
|
if (esf) {
|
2022-05-12 02:45:42 +02:00
|
|
|
/* Don't want to get elbowed by xtensa_switch
|
|
|
|
* in between printing registers and dumping them;
|
|
|
|
* corrupts backtrace
|
|
|
|
*/
|
|
|
|
unsigned int key = arch_irq_lock();
|
|
|
|
|
2023-12-08 20:10:50 +01:00
|
|
|
xtensa_dump_stack(esf);
|
2022-05-12 02:45:42 +02:00
|
|
|
|
|
|
|
|
2021-01-07 07:11:11 +01:00
|
|
|
#if defined(CONFIG_XTENSA_ENABLE_BACKTRACE)
|
|
|
|
#if XCHAL_HAVE_WINDOWED
|
2023-12-08 20:10:50 +01:00
|
|
|
xtensa_backtrace_print(100, (int *)esf);
|
2021-01-07 07:11:11 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
2023-04-13 01:15:27 +02:00
|
|
|
arch_irq_unlock(key);
|
|
|
|
}
|
2023-12-12 15:57:11 +01:00
|
|
|
#endif /* CONFIG_EXCEPTION_DEBUG */
|
2023-04-13 01:15:27 +02:00
|
|
|
|
2019-07-11 23:18:28 +02:00
|
|
|
z_fatal_error(reason, esf);
|
|
|
|
}
|
2017-02-06 21:25:02 +01:00
|
|
|
|
2024-02-15 20:50:43 +01:00
|
|
|
#if defined(CONFIG_SIMULATOR_XTENSA) || defined(XT_SIMULATOR)
|
|
|
|
void xtensa_simulator_exit(int return_code)
|
2017-05-11 18:41:10 +02:00
|
|
|
{
|
|
|
|
__asm__ (
|
|
|
|
"mov a3, %[code]\n\t"
|
|
|
|
"movi a2, %[call]\n\t"
|
|
|
|
"simcall\n\t"
|
|
|
|
:
|
2017-05-15 19:02:29 +02:00
|
|
|
: [code] "r" (return_code), [call] "i" (SYS_exit)
|
2017-05-11 18:41:10 +02:00
|
|
|
: "a3", "a2");
|
2024-02-15 20:50:43 +01:00
|
|
|
|
|
|
|
CODE_UNREACHABLE;
|
2017-05-11 18:41:10 +02:00
|
|
|
}
|
2017-02-06 21:25:02 +01:00
|
|
|
|
2024-02-15 20:50:43 +01:00
|
|
|
FUNC_NORETURN void arch_system_halt(unsigned int reason)
|
2019-07-11 23:18:28 +02:00
|
|
|
{
|
2024-02-15 20:50:43 +01:00
|
|
|
xtensa_simulator_exit(255 - reason);
|
2017-02-06 21:25:02 +01:00
|
|
|
CODE_UNREACHABLE;
|
2017-01-22 17:21:34 +01:00
|
|
|
}
|
2019-07-11 23:18:28 +02:00
|
|
|
#endif
|
2022-12-16 00:05:14 +01:00
|
|
|
|
|
|
|
FUNC_NORETURN void arch_syscall_oops(void *ssf)
|
|
|
|
{
|
2023-04-13 00:42:38 +02:00
|
|
|
xtensa_arch_kernel_oops(K_ERR_KERNEL_OOPS, ssf);
|
2022-12-16 00:05:14 +01:00
|
|
|
|
|
|
|
CODE_UNREACHABLE;
|
|
|
|
}
|
2023-02-08 22:35:18 +01:00
|
|
|
|
|
|
|
#ifdef CONFIG_USERSPACE
|
|
|
|
void z_impl_xtensa_user_fault(unsigned int reason)
|
|
|
|
{
|
|
|
|
if ((_current->base.user_options & K_USER) != 0) {
|
|
|
|
if ((reason != K_ERR_KERNEL_OOPS) &&
|
|
|
|
(reason != K_ERR_STACK_CHK_FAIL)) {
|
|
|
|
reason = K_ERR_KERNEL_OOPS;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
xtensa_arch_except(reason);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void z_vrfy_xtensa_user_fault(unsigned int reason)
|
|
|
|
{
|
|
|
|
z_impl_xtensa_user_fault(reason);
|
|
|
|
}
|
|
|
|
|
2024-01-24 10:35:04 +01:00
|
|
|
#include <zephyr/syscalls/xtensa_user_fault_mrsh.c>
|
2023-02-08 22:35:18 +01:00
|
|
|
|
|
|
|
#endif /* CONFIG_USERSPACE */
|