1 /*
2  * Copyright (c) 2018 Synopsys, Inc. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #include <zephyr/device.h>
8 #include <zephyr/kernel.h>
9 #include <errno.h>
10 #include <zephyr/types.h>
11 #include <zephyr/init.h>
12 #include <zephyr/toolchain.h>
13 
14 #include <zephyr/arch/arc/v2/secureshield/arc_secure.h>
15 
16 static void _default_sjli_entry(void);
17 /*
18  * sjli vector table must be in instruction space
19  * \todo: how to let user to install customized sjli entry easily, e.g.
20  *  through macros or with the help of compiler?
21  */
22 const static uint32_t _sjli_vector_table[CONFIG_SJLI_TABLE_SIZE] = {
23 	[0] = (uint32_t)_arc_do_secure_call,
24 	[1 ... (CONFIG_SJLI_TABLE_SIZE - 1)] = (uint32_t)_default_sjli_entry,
25 };
26 
27 /*
28  * @brief default entry of sjli call
29  *
30  */
_default_sjli_entry(void)31 static void _default_sjli_entry(void)
32 {
33 	printk("default sjli entry\n");
34 }
35 
36 /*
37  * @brief initialization of sjli related functions
38  *
39  */
sjli_table_init(void)40 static void sjli_table_init(void)
41 {
42 	/* install SJLI table */
43 	z_arc_v2_aux_reg_write(_ARC_V2_NSC_TABLE_BASE, _sjli_vector_table);
44 	z_arc_v2_aux_reg_write(_ARC_V2_NSC_TABLE_TOP,
45 		(_sjli_vector_table + CONFIG_SJLI_TABLE_SIZE));
46 }
47 
48 /*
49  * @brief initialization of secureshield related functions.
50  */
arc_secureshield_init(void)51 void arc_secureshield_init(void)
52 {
53 	sjli_table_init();
54 
55 	/* set nic bit to enable seti/clri and
56 	 * sleep/wevt in normal mode.
57 	 * If not set, direct call of seti/clri etc. will raise exception.
58 	 * Then, these seti/clri instructions should be replaced with secure
59 	 * secure services (sjli call)
60 	 *
61 	 */
62 	__asm__ volatile("sflag  0x20");
63 }
64