1234a0538SKuninori Morimoto // SPDX-License-Identifier: GPL-2.0
2bd079997SPaul Mundt /*
3bd079997SPaul Mundt  * arch/sh/kernel/cpu/sh2a/opcode_helper.c
4bd079997SPaul Mundt  *
5bd079997SPaul Mundt  * Helper for the SH-2A 32-bit opcodes.
6bd079997SPaul Mundt  *
7bd079997SPaul Mundt  *  Copyright (C) 2007  Paul Mundt
8bd079997SPaul Mundt  */
9bd079997SPaul Mundt #include <linux/kernel.h>
10bd079997SPaul Mundt 
11bd079997SPaul Mundt /*
12bd079997SPaul Mundt  * Instructions on SH are generally fixed at 16-bits, however, SH-2A
13bd079997SPaul Mundt  * introduces some 32-bit instructions. Since there are no real
14bd079997SPaul Mundt  * constraints on their use (and they can be mixed and matched), we need
15bd079997SPaul Mundt  * to check the instruction encoding to work out if it's a true 32-bit
16bd079997SPaul Mundt  * instruction or not.
17bd079997SPaul Mundt  *
18bd079997SPaul Mundt  * Presently, 32-bit opcodes have only slight variations in what the
19bd079997SPaul Mundt  * actual encoding looks like in the first-half of the instruction, which
20bd079997SPaul Mundt  * makes it fairly straightforward to differentiate from the 16-bit ones.
21bd079997SPaul Mundt  *
22bd079997SPaul Mundt  * First 16-bits of encoding		Used by
23bd079997SPaul Mundt  *
24bd079997SPaul Mundt  *	0011nnnnmmmm0001	mov.b, mov.w, mov.l, fmov.d,
25bd079997SPaul Mundt  *				fmov.s, movu.b, movu.w
26bd079997SPaul Mundt  *
27bd079997SPaul Mundt  *	0011nnnn0iii1001        bclr.b, bld.b, bset.b, bst.b, band.b,
28bd079997SPaul Mundt  *				bandnot.b, bldnot.b, bor.b, bornot.b,
29bd079997SPaul Mundt  *				bxor.b
30bd079997SPaul Mundt  *
31bd079997SPaul Mundt  *	0000nnnniiii0000        movi20
32bd079997SPaul Mundt  *	0000nnnniiii0001        movi20s
33bd079997SPaul Mundt  */
instruction_size(unsigned int insn)34bd079997SPaul Mundt unsigned int instruction_size(unsigned int insn)
35bd079997SPaul Mundt {
36bd079997SPaul Mundt 	/* Look for the common cases */
37bd079997SPaul Mundt 	switch ((insn & 0xf00f)) {
38bd079997SPaul Mundt 	case 0x0000:	/* movi20 */
39bd079997SPaul Mundt 	case 0x0001:	/* movi20s */
40bd079997SPaul Mundt 	case 0x3001:	/* 32-bit mov/fmov/movu variants */
41bd079997SPaul Mundt 		return 4;
42bd079997SPaul Mundt 	}
43bd079997SPaul Mundt 
44bd079997SPaul Mundt 	/* And the special cases.. */
45bd079997SPaul Mundt 	switch ((insn & 0xf08f)) {
46bd079997SPaul Mundt 	case 0x3009:	/* 32-bit b*.b bit operations */
47bd079997SPaul Mundt 		return 4;
48bd079997SPaul Mundt 	}
49bd079997SPaul Mundt 
50bd079997SPaul Mundt 	return 2;
51bd079997SPaul Mundt }
52