1 /*
2  * Copyright (c) 2014 Wind River Systems, Inc.
3  * Copyright (c) 2016 Cadence Design Systems, Inc.
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #ifndef ZEPHYR_ARCH_XTENSA_INCLUDE_XTENSA_INTERNAL_H_
9 #define ZEPHYR_ARCH_XTENSA_INCLUDE_XTENSA_INTERNAL_H_
10 
11 #include <stdint.h>
12 
13 #include <zephyr/arch/xtensa/exception.h>
14 #include <zephyr/arch/arch_interface.h>
15 
16 /**
17  * @ingroup xtensa_internal_apis
18  * @{
19  */
20 
21 /**
22  * @brief Dump and print out the stack frame content.
23  *
24  * This mainly prints out the registers stashed in the stack frame.
25  *
26  * @param stack Pointer to stack frame.
27  */
28 void xtensa_dump_stack(const void *stack);
29 
30 /**
31  * @brief Get string description from an exception code.
32  *
33  * @param cause_code Exception code.
34  *
35  * @return String description.
36  */
37 char *xtensa_exccause(unsigned int cause_code);
38 
39 /**
40  * @brief Called upon a fatal error.
41  *
42  * @param reason The reason for the fatal error
43  * @param esf Exception context, with details and partial or full register
44  *            state when the error occurred. May in some cases be NULL.
45  */
46 void xtensa_fatal_error(unsigned int reason, const struct arch_esf *esf);
47 
48 /**
49  * @brief Perform a one-way transition from supervisor to user mode.
50  *
51  * @see arch_user_mode_enter
52  */
53 void xtensa_userspace_enter(k_thread_entry_t user_entry,
54 			    void *p1, void *p2, void *p3,
55 			    uintptr_t stack_end,
56 			    uintptr_t stack_start);
57 
58 /**
59  * @brief Check if kernel threads have access to a memory region.
60  *
61  * Given a memory region, return whether the current memory management
62  * hardware configuration would allow kernel threads to read/write
63  * that region.
64  *
65  * This is mainly used to make sure kernel has access to avoid relying
66  * on page fault to detect invalid mappings.
67  *
68  * @param addr Start address of the buffer
69  * @param size Size of the buffer
70  * @param write If non-zero, additionally check if the area is writable.
71  *              Otherwise, just check if the memory can be read.
72  *
73  * @return False if the permissions don't match.
74  */
75 bool xtensa_mem_kernel_has_access(void *addr, size_t size, int write);
76 
77 /**
78  * @}
79  */
80 
81 #endif /* ZEPHYR_ARCH_XTENSA_INCLUDE_XTENSA_INTERNAL_H_ */
82