2 * This file is provided under a dual BSD/GPLv2 license. When using or
3 * redistributing this file, you may do so under either license.
7 * Copyright 2008-2016 Freescale Semiconductor Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are met:
12 * * Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * * Neither the name of the above-listed copyright holders nor the
18 * names of any contributors may be used to endorse or promote products
19 * derived from this software without specific prior written permission.
23 * ALTERNATIVELY, this software may be distributed under the terms of the
24 * GNU General Public License ("GPL") as published by the Free Software
25 * Foundation, either version 2 of that License or (at your option) any
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
29 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
32 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
33 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
34 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
35 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
36 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
37 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
38 * POSSIBILITY OF SUCH DAMAGE.
41 #ifndef __RTA_JUMP_CMD_H__
42 #define __RTA_JUMP_CMD_H__
44 extern enum rta_sec_era rta_sec_era;
46 static const uint32_t jump_test_cond[][2] = {
47 { NIFP, JUMP_COND_NIFP },
48 { NIP, JUMP_COND_NIP },
49 { NOP, JUMP_COND_NOP },
50 { NCP, JUMP_COND_NCP },
51 { CALM, JUMP_COND_CALM },
52 { SELF, JUMP_COND_SELF },
53 { SHRD, JUMP_COND_SHRD },
54 { JQP, JUMP_COND_JQP },
55 { MATH_Z, JUMP_COND_MATH_Z },
56 { MATH_N, JUMP_COND_MATH_N },
57 { MATH_NV, JUMP_COND_MATH_NV },
58 { MATH_C, JUMP_COND_MATH_C },
59 { PK_0, JUMP_COND_PK_0 },
60 { PK_GCD_1, JUMP_COND_PK_GCD_1 },
61 { PK_PRIME, JUMP_COND_PK_PRIME },
62 { CLASS1, JUMP_CLASS_CLASS1 },
63 { CLASS2, JUMP_CLASS_CLASS2 },
64 { BOTH, JUMP_CLASS_BOTH }
67 static const uint32_t jump_test_math_cond[][2] = {
68 { MATH_Z, JUMP_COND_MATH_Z },
69 { MATH_N, JUMP_COND_MATH_N },
70 { MATH_NV, JUMP_COND_MATH_NV },
71 { MATH_C, JUMP_COND_MATH_C }
74 static const uint32_t jump_src_dst[][2] = {
75 { MATH0, JUMP_SRC_DST_MATH0 },
76 { MATH1, JUMP_SRC_DST_MATH1 },
77 { MATH2, JUMP_SRC_DST_MATH2 },
78 { MATH3, JUMP_SRC_DST_MATH3 },
79 { DPOVRD, JUMP_SRC_DST_DPOVRD },
80 { SEQINSZ, JUMP_SRC_DST_SEQINLEN },
81 { SEQOUTSZ, JUMP_SRC_DST_SEQOUTLEN },
82 { VSEQINSZ, JUMP_SRC_DST_VARSEQINLEN },
83 { VSEQOUTSZ, JUMP_SRC_DST_VARSEQOUTLEN }
87 rta_jump(struct program *program, uint64_t address,
88 enum rta_jump_type jump_type,
89 enum rta_jump_cond test_type,
90 uint32_t test_condition, uint32_t src_dst)
92 uint32_t opcode = CMD_JUMP;
93 unsigned int start_pc = program->current_pc;
96 if (((jump_type == GOSUB) || (jump_type == RETURN)) &&
97 (rta_sec_era < RTA_SEC_ERA_4)) {
98 pr_err("JUMP: Jump type not supported by SEC Era %d\n",
99 USER_SEC_ERA(rta_sec_era));
103 if (((jump_type == LOCAL_JUMP_INC) || (jump_type == LOCAL_JUMP_DEC)) &&
104 (rta_sec_era <= RTA_SEC_ERA_5)) {
105 pr_err("JUMP_INCDEC: Jump type not supported by SEC Era %d\n",
106 USER_SEC_ERA(rta_sec_era));
113 * opcode |= JUMP_TYPE_LOCAL;
114 * JUMP_TYPE_LOCAL is 0
118 opcode |= JUMP_TYPE_HALT;
121 opcode |= JUMP_TYPE_HALT_USER;
124 opcode |= JUMP_TYPE_NONLOCAL;
127 opcode |= JUMP_TYPE_GOSUB;
130 opcode |= JUMP_TYPE_RETURN;
132 case (LOCAL_JUMP_INC):
133 opcode |= JUMP_TYPE_LOCAL_INC;
135 case (LOCAL_JUMP_DEC):
136 opcode |= JUMP_TYPE_LOCAL_DEC;
139 pr_err("JUMP: Invalid jump type. SEC Program Line: %d\n",
140 program->current_pc);
147 * opcode |= JUMP_TEST_ALL;
152 opcode |= JUMP_TEST_INVALL;
155 opcode |= JUMP_TEST_ANY;
158 opcode |= JUMP_TEST_INVANY;
161 pr_err("JUMP: test type not supported. SEC Program Line: %d\n",
162 program->current_pc);
166 /* write test condition field */
167 if ((jump_type != LOCAL_JUMP_INC) && (jump_type != LOCAL_JUMP_DEC)) {
168 __rta_map_flags(test_condition, jump_test_cond,
169 ARRAY_SIZE(jump_test_cond), &opcode);
173 ret = __rta_map_opcode(src_dst, jump_src_dst,
174 ARRAY_SIZE(jump_src_dst), &val);
176 pr_err("JUMP_INCDEC: SRC_DST not supported. SEC PC: %d; Instr: %d\n",
178 program->current_instruction);
183 __rta_map_flags(test_condition, jump_test_math_cond,
184 ARRAY_SIZE(jump_test_math_cond), &opcode);
187 /* write local offset field for local jumps and user-defined halt */
188 if ((jump_type == LOCAL_JUMP) || (jump_type == LOCAL_JUMP_INC) ||
189 (jump_type == LOCAL_JUMP_DEC) || (jump_type == GOSUB) ||
190 (jump_type == HALT_STATUS))
191 opcode |= (uint32_t)(address & JUMP_OFFSET_MASK);
193 __rta_out32(program, opcode);
194 program->current_instruction++;
196 if (jump_type == FAR_JUMP)
197 __rta_out64(program, program->ps, address);
199 return (int)start_pc;
202 program->first_error_pc = start_pc;
203 program->current_instruction++;
207 #endif /* __RTA_JUMP_CMD_H__ */