1/*
2 * Copyright (c) 2018 Synopsys.
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6#include <zephyr/toolchain.h>
7#include <zephyr/linker/sections.h>
8#include <zephyr/arch/cpu.h>
9
10.macro clear_scratch_regs
11	mov r1, 0
12	mov r2, 0
13	mov r3, 0
14	mov r4, 0
15	mov r5, 0
16	mov r6, 0
17	mov r7, 0
18	mov r8, 0
19	mov r9, 0
20	mov r10, 0
21	mov r11, 0
22	mov r12, 0
23.endm
24
25.macro clear_callee_regs
26	mov r25, 0
27	mov r24, 0
28	mov r23, 0
29	mov r22, 0
30	mov r21, 0
31	mov r20, 0
32	mov r19, 0
33	mov r18, 0
34	mov r17, 0
35	mov r16, 0
36
37	mov r15, 0
38	mov r14, 0
39	mov r13, 0
40.endm
41
42GTEXT(arc_go_to_normal)
43GTEXT(_arc_do_secure_call)
44GDATA(arc_s_call_table)
45
46
47SECTION_FUNC(TEXT, _arc_do_secure_call)
48	/* r0-r5: arg1-arg6, r6 is call id */
49	/* the call id should be checked */
50	/* disable normal interrupt happened when processor in secure mode ? */
51	/* seti (0x30 | (ARC_N_IRQ_START_LEVEL-1)) */
52	breq r6, ARC_S_CALL_CLRI, _s_clri
53	breq r6, ARC_S_CALL_SETI, _s_seti
54	push_s blink
55	mov	blink, arc_s_call_table
56	ld.as r6, [blink, r6]
57
58	jl	[r6]
59
60	/*
61	 * no need to clear callee regs, as they will be saved and restored
62	 * automatically
63	 */
64	clear_scratch_regs
65
66	mov r29, 0
67	mov r30, 0
68
69
70_arc_do_secure_call_exit:
71	pop_s blink
72
73	j [blink]
74	/* enable normal interrupt */
75	/*
76	 * j.d [blink]
77	 * seti (0x30 | (CONFIG_NUM_IRQ_PRIO_LEVELS - 1))
78	 */
79
80_s_clri:
81	lr r0, [_ARC_V2_STATUS32]
82	and r0, r0, 0x1e
83	asr r0, r0
84	or r0, r0, 0x30
85	mov r6, (0x30 | (ARC_N_IRQ_START_LEVEL-1))
86
87	j.d [blink]
88	seti r6
89
90_s_seti:
91	btst r0, 4
92	jnz __seti_0
93	mov r0, (CONFIG_NUM_IRQ_PRIO_LEVELS - 1)
94	lr r6, [_ARC_V2_STATUS32]
95	and r6, r6, 0x1e
96	asr r6, r6
97	cmp r0, r6
98	mov.hs r0, r6
99__seti_0:
100	and r0, r0, 0xf
101	brhs r0, ARC_N_IRQ_START_LEVEL, __seti_1
102	mov r0, ARC_N_IRQ_START_LEVEL
103__seti_1:
104	or r0, r0, 0x30
105
106	j.d [blink]
107	seti r0
108
109
110SECTION_FUNC(TEXT, arc_go_to_normal)
111	clear_callee_regs
112	clear_scratch_regs
113
114	mov fp, 0
115	mov r29, 0
116	mov r30, 0
117	mov blink, 0
118
119	jl [r0]
120	/* should not come here */
121	kflag 1
122
123