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