xref: /netbsd-src/external/gpl3/gdb/dist/include/opcode/msp430.h (revision 02f41505626a9ceb584d30d0789203495760ac88)
198b9484cSchristos /* Opcode table for the TI MSP430 microcontrollers
298b9484cSchristos 
3*02f41505Schristos    Copyright (C) 2002-2024 Free Software Foundation, Inc.
498b9484cSchristos    Contributed by Dmitry Diky <diwil@mail.ru>
598b9484cSchristos 
698b9484cSchristos    This program is free software; you can redistribute it and/or modify
798b9484cSchristos    it under the terms of the GNU General Public License as published by
898b9484cSchristos    the Free Software Foundation; either version 3, or (at your option)
998b9484cSchristos    any later version.
1098b9484cSchristos 
1198b9484cSchristos    This program is distributed in the hope that it will be useful,
1298b9484cSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
1398b9484cSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
1498b9484cSchristos    GNU General Public License for more details.
1598b9484cSchristos 
1698b9484cSchristos    You should have received a copy of the GNU General Public License
1798b9484cSchristos    along with this program; if not, write to the Free Software
1898b9484cSchristos    Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston,
1998b9484cSchristos    MA 02110-1301, USA.  */
2098b9484cSchristos 
2198b9484cSchristos #ifndef __MSP430_H_
2298b9484cSchristos #define __MSP430_H_
2398b9484cSchristos 
248dffb485Schristos enum msp430_expp_e
258dffb485Schristos {
268dffb485Schristos   MSP_EXPP_ALL = 0,	/* Use full the value of the expression - default.  */
278dffb485Schristos   MSP_EXPP_LO,		/* Extract least significant word from expression.  */
288dffb485Schristos   MSP_EXPP_HI,		/* Extract 2nd word from expression.  */
298dffb485Schristos   MSP_EXPP_LLO,		/* Extract least significant word from an
308dffb485Schristos 			   immediate value.  */
318dffb485Schristos   MSP_EXPP_LHI,		/* Extract 2nd word from an immediate value.  */
328dffb485Schristos   MSP_EXPP_HLO,		/* Extract 3rd word from an immediate value.  */
338dffb485Schristos   MSP_EXPP_HHI,		/* Extract 4th word from an immediate value.  */
348dffb485Schristos };
358dffb485Schristos 
3698b9484cSchristos struct msp430_operand_s
3798b9484cSchristos {
3898b9484cSchristos   int ol;	/* Operand length words.  */
3998b9484cSchristos   int am;	/* Addr mode.  */
4098b9484cSchristos   int reg;	/* Register.  */
41968cf8f2Schristos   int mode;	/* Operand mode.  */
42968cf8f2Schristos   int vshift;   /* Number of bytes to shift operand down.  */
438dffb485Schristos   enum msp430_expp_e expp;	/* For when the operand is a constant
448dffb485Schristos 				   expression, the part of the expression to
458dffb485Schristos 				   extract.  */
4698b9484cSchristos #define OP_REG		0
4798b9484cSchristos #define OP_EXP		1
4898b9484cSchristos #ifndef DASM_SECTION
4998b9484cSchristos   expressionS	exp;
5098b9484cSchristos #endif
5198b9484cSchristos };
5298b9484cSchristos 
53ba340e45Schristos /* Byte operation flag for all instructions.  Also used as the
54ba340e45Schristos    A/L bit in the extension word to indicate a 20-bit operation.  */
55ba340e45Schristos #define BYTE_OPERATION    (1 << 6)
56ba340e45Schristos /* Z/C bit in the extension word.  If set the carry bit is ignored
57ba340e45Schristos    for the duration of the operation, although it may be changed as
58ba340e45Schristos    a result of the operation.  */
59ba340e45Schristos #define IGNORE_CARRY_BIT  (1 << 8)
6098b9484cSchristos 
6198b9484cSchristos struct  msp430_opcode_s
6298b9484cSchristos {
63ba340e45Schristos   const char *name;
6498b9484cSchristos   int fmt;
6598b9484cSchristos   int insn_opnumb;
6698b9484cSchristos   int bin_opcode;
6798b9484cSchristos   int bin_mask;
6898b9484cSchristos };
6998b9484cSchristos 
70ba340e45Schristos #define MSP_INSN(name, fmt, numb, bin, mask) { #name, fmt, numb, bin, mask }
7198b9484cSchristos 
7298b9484cSchristos static struct msp430_opcode_s msp430_opcodes[] =
7398b9484cSchristos {
7498b9484cSchristos   MSP_INSN (and,   1, 2, 0xf000, 0xf000),
7598b9484cSchristos   MSP_INSN (inv,   0, 1, 0xe330, 0xfff0),
7698b9484cSchristos   MSP_INSN (xor,   1, 2, 0xe000, 0xf000),
7798b9484cSchristos   MSP_INSN (setz,  0, 0, 0xd322, 0xffff),
7898b9484cSchristos   MSP_INSN (setc,  0, 0, 0xd312, 0xffff),
7998b9484cSchristos   MSP_INSN (eint,  0, 0, 0xd232, 0xffff),
8098b9484cSchristos   MSP_INSN (setn,  0, 0, 0xd222, 0xffff),
8198b9484cSchristos   MSP_INSN (bis,   1, 2, 0xd000, 0xf000),
8298b9484cSchristos   MSP_INSN (clrz,  0, 0, 0xc322, 0xffff),
8398b9484cSchristos   MSP_INSN (clrc,  0, 0, 0xc312, 0xffff),
8498b9484cSchristos   MSP_INSN (dint,  0, 0, 0xc232, 0xffff),
8598b9484cSchristos   MSP_INSN (clrn,  0, 0, 0xc222, 0xffff),
8698b9484cSchristos   MSP_INSN (bic,   1, 2, 0xc000, 0xf000),
8798b9484cSchristos   MSP_INSN (bit,   1, 2, 0xb000, 0xf000),
8898b9484cSchristos   MSP_INSN (dadc,  0, 1, 0xa300, 0xff30),
8998b9484cSchristos   MSP_INSN (dadd,  1, 2, 0xa000, 0xf000),
9098b9484cSchristos   MSP_INSN (tst,   0, 1, 0x9300, 0xff30),
9198b9484cSchristos   MSP_INSN (cmp,   1, 2, 0x9000, 0xf000),
9298b9484cSchristos   MSP_INSN (decd,  0, 1, 0x8320, 0xff30),
9398b9484cSchristos   MSP_INSN (dec,   0, 1, 0x8310, 0xff30),
9498b9484cSchristos   MSP_INSN (sub,   1, 2, 0x8000, 0xf000),
9598b9484cSchristos   MSP_INSN (sbc,   0, 1, 0x7300, 0xff30),
9698b9484cSchristos   MSP_INSN (subc,  1, 2, 0x7000, 0xf000),
9798b9484cSchristos   MSP_INSN (adc,   0, 1, 0x6300, 0xff30),
9898b9484cSchristos   MSP_INSN (rlc,   0, 2, 0x6000, 0xf000),
9998b9484cSchristos   MSP_INSN (addc,  1, 2, 0x6000, 0xf000),
10098b9484cSchristos   MSP_INSN (incd,  0, 1, 0x5320, 0xff30),
10198b9484cSchristos   MSP_INSN (inc,   0, 1, 0x5310, 0xff30),
10298b9484cSchristos   MSP_INSN (rla,   0, 2, 0x5000, 0xf000),
10398b9484cSchristos   MSP_INSN (add,   1, 2, 0x5000, 0xf000),
10498b9484cSchristos   MSP_INSN (nop,   0, 0, 0x4303, 0xffff),
10598b9484cSchristos   MSP_INSN (clr,   0, 1, 0x4300, 0xff30),
10698b9484cSchristos   MSP_INSN (ret,   0, 0, 0x4130, 0xff30),
10798b9484cSchristos   MSP_INSN (pop,   0, 1, 0x4130, 0xff30),
10898b9484cSchristos   MSP_INSN (br,    0, 3, 0x4000, 0xf000),
10998b9484cSchristos   MSP_INSN (mov,   1, 2, 0x4000, 0xf000),
11098b9484cSchristos   MSP_INSN (jmp,   3, 1, 0x3c00, 0xfc00),
11198b9484cSchristos   MSP_INSN (jl,    3, 1, 0x3800, 0xfc00),
11298b9484cSchristos   MSP_INSN (jge,   3, 1, 0x3400, 0xfc00),
11398b9484cSchristos   MSP_INSN (jn,    3, 1, 0x3000, 0xfc00),
11498b9484cSchristos   MSP_INSN (jc,    3, 1, 0x2c00, 0xfc00),
11598b9484cSchristos   MSP_INSN (jhs,   3, 1, 0x2c00, 0xfc00),
11698b9484cSchristos   MSP_INSN (jnc,   3, 1, 0x2800, 0xfc00),
11798b9484cSchristos   MSP_INSN (jlo,   3, 1, 0x2800, 0xfc00),
11898b9484cSchristos   MSP_INSN (jz,    3, 1, 0x2400, 0xfc00),
11998b9484cSchristos   MSP_INSN (jeq,   3, 1, 0x2400, 0xfc00),
12098b9484cSchristos   MSP_INSN (jnz,   3, 1, 0x2000, 0xfc00),
12198b9484cSchristos   MSP_INSN (jne,   3, 1, 0x2000, 0xfc00),
12298b9484cSchristos   MSP_INSN (reti,  2, 0, 0x1300, 0xffc0),
12398b9484cSchristos   MSP_INSN (call,  2, 1, 0x1280, 0xffc0),
12498b9484cSchristos   MSP_INSN (push,  2, 1, 0x1200, 0xff80),
12598b9484cSchristos   MSP_INSN (sxt,   2, 1, 0x1180, 0xffc0),
12698b9484cSchristos   MSP_INSN (rra,   2, 1, 0x1100, 0xff80),
12798b9484cSchristos   MSP_INSN (swpb,  2, 1, 0x1080, 0xffc0),
12898b9484cSchristos   MSP_INSN (rrc,   2, 1, 0x1000, 0xff80),
12998b9484cSchristos   /* Simple polymorphs.  */
13098b9484cSchristos   MSP_INSN (beq,   4, 0, 0, 0xffff),
13198b9484cSchristos   MSP_INSN (bne,   4, 1, 0, 0xffff),
13298b9484cSchristos   MSP_INSN (blt,   4, 2, 0, 0xffff),
13398b9484cSchristos   MSP_INSN (bltu,  4, 3, 0, 0xffff),
13498b9484cSchristos   MSP_INSN (bge,   4, 4, 0, 0xffff),
13598b9484cSchristos   MSP_INSN (bgeu,  4, 5, 0, 0xffff),
13698b9484cSchristos   MSP_INSN (bltn,  4, 6, 0, 0xffff),
13798b9484cSchristos   MSP_INSN (jump,  4, 7, 0, 0xffff),
13898b9484cSchristos   /* Long polymorphs.  */
13998b9484cSchristos   MSP_INSN (bgt,   5, 0, 0, 0xffff),
14098b9484cSchristos   MSP_INSN (bgtu,  5, 1, 0, 0xffff),
14198b9484cSchristos   MSP_INSN (bleu,  5, 2, 0, 0xffff),
14298b9484cSchristos   MSP_INSN (ble,   5, 3, 0, 0xffff),
14398b9484cSchristos 
14403467a24Schristos   /* MSP430X instructions - these ones use an extension word.
14503467a24Schristos      A negative format indicates an MSP430X instruction.  */
14603467a24Schristos   MSP_INSN (addcx, -2, 2, 0x6000, 0xf000),
14703467a24Schristos   MSP_INSN (addx,  -2, 2, 0x5000, 0xf000),
14803467a24Schristos   MSP_INSN (andx,  -2, 2, 0xf000, 0xf000),
14903467a24Schristos   MSP_INSN (bicx,  -2, 2, 0xc000, 0xf000),
15003467a24Schristos   MSP_INSN (bisx,  -2, 2, 0xd000, 0xf000),
15103467a24Schristos   MSP_INSN (bitx,  -2, 2, 0xb000, 0xf000),
15203467a24Schristos   MSP_INSN (cmpx,  -2, 2, 0x9000, 0xf000),
15303467a24Schristos   MSP_INSN (daddx, -2, 2, 0xa000, 0xf000),
15403467a24Schristos   MSP_INSN (movx,  -2, 2, 0x4000, 0xf000),
15503467a24Schristos   MSP_INSN (subcx, -2, 2, 0x7000, 0xf000),
15603467a24Schristos   MSP_INSN (subx,  -2, 2, 0x8000, 0xf000),
15703467a24Schristos   MSP_INSN (xorx,  -2, 2, 0xe000, 0xf000),
15803467a24Schristos 
15903467a24Schristos   /* MSP430X Synthetic instructions.  */
16003467a24Schristos   MSP_INSN (adcx,  -1, 1, 0x6300, 0xff30),
16103467a24Schristos   MSP_INSN (clra,  -1, 1, 0x4300, 0xff30),
16203467a24Schristos   MSP_INSN (clrx,  -1, 1, 0x4300, 0xff30),
16303467a24Schristos   MSP_INSN (dadcx, -1, 1, 0xa300, 0xff30),
16403467a24Schristos   MSP_INSN (decx,  -1, 1, 0x8310, 0xff30),
16503467a24Schristos   MSP_INSN (decda, -1, 1, 0x8320, 0xff30),
16603467a24Schristos   MSP_INSN (decdx, -1, 1, 0x8320, 0xff30),
16703467a24Schristos   MSP_INSN (incx,  -1, 1, 0x5310, 0xff30),
16803467a24Schristos   MSP_INSN (incda, -1, 1, 0x5320, 0xff30),
16903467a24Schristos   MSP_INSN (incdx, -1, 1, 0x5320, 0xff30),
17003467a24Schristos   MSP_INSN (invx,  -1, 1, 0xe330, 0xfff0),
17103467a24Schristos   MSP_INSN (popx,  -1, 1, 0x4130, 0xff30),
17203467a24Schristos   MSP_INSN (rlax,  -1, 2, 0x5000, 0xf000),
17303467a24Schristos   MSP_INSN (rlcx,  -1, 2, 0x6000, 0xf000),
17403467a24Schristos   MSP_INSN (sbcx,  -1, 1, 0x7300, 0xff30),
17503467a24Schristos   MSP_INSN (tsta,  -1, 1, 0x9300, 0xff30),
17603467a24Schristos   MSP_INSN (tstx,  -1, 1, 0x9300, 0xff30),
17703467a24Schristos 
17803467a24Schristos   MSP_INSN (pushx, -3, 1, 0x1200, 0xff80),
17903467a24Schristos   MSP_INSN (rrax,  -3, 1, 0x1100, 0xff80),
180ba340e45Schristos   MSP_INSN (rrcx,  -3, 1, 0x1000, 0xff80), /* Synthesised as RRC but with the Z/C bit clear.  */
181ba340e45Schristos   MSP_INSN (rrux,  -3, 1, 0x1000, 0xff80), /* Synthesised as RRC but with the Z/C bit set.  */
18203467a24Schristos   MSP_INSN (swpbx, -3, 1, 0x1080, 0xffc0),
18303467a24Schristos   MSP_INSN (sxtx,  -3, 1, 0x1180, 0xffc0),
18403467a24Schristos 
18503467a24Schristos   /* MSP430X Address instructions - no extension word needed.
18603467a24Schristos      The insn_opnumb field is used to encode the nature of the
18703467a24Schristos      instruction for assembly and disassembly purposes.  */
18803467a24Schristos   MSP_INSN (calla, -1, 4, 0x1300, 0xff00),
18903467a24Schristos 
19003467a24Schristos   MSP_INSN (popm,  -1, 5, 0x1600, 0xfe00),
19103467a24Schristos   MSP_INSN (pushm, -1, 5, 0x1400, 0xfe00),
19203467a24Schristos 
19303467a24Schristos   MSP_INSN (rrcm,  -1, 6, 0x0040, 0xf3e0),
19403467a24Schristos   MSP_INSN (rram,  -1, 6, 0x0140, 0xf3e0),
19503467a24Schristos   MSP_INSN (rlam,  -1, 6, 0x0240, 0xf3e0),
19603467a24Schristos   MSP_INSN (rrum,  -1, 6, 0x0340, 0xf3e0),
19703467a24Schristos 
19803467a24Schristos   MSP_INSN (adda,  -1, 8, 0x00a0, 0xf0b0),
19903467a24Schristos   MSP_INSN (cmpa,  -1, 8, 0x0090, 0xf0b0),
20003467a24Schristos   MSP_INSN (suba,  -1, 8, 0x00b0, 0xf0b0),
20103467a24Schristos 
20203467a24Schristos   MSP_INSN (reta,  -1, 9, 0x0110, 0xffff),
20303467a24Schristos   MSP_INSN (bra,   -1, 9, 0x0000, 0xf0cf),
20403467a24Schristos   MSP_INSN (mova,  -1, 9, 0x0000, 0xf080),
20503467a24Schristos   MSP_INSN (mova,  -1, 9, 0x0080, 0xf0b0),
20603467a24Schristos   MSP_INSN (mova,  -1, 9, 0x00c0, 0xf0f0),
20703467a24Schristos 
20803467a24Schristos   /* Pseudo instruction to set the repeat field in the extension word.  */
20903467a24Schristos   MSP_INSN (rpt,   -1, 10, 0x0000, 0x0000),
21003467a24Schristos 
21198b9484cSchristos   /* End of instruction set.  */
21298b9484cSchristos   { NULL, 0, 0, 0, 0 }
21398b9484cSchristos };
21498b9484cSchristos 
21598b9484cSchristos #endif
216