Introduce old redir program
[lcapit-junk-code.git] / pet-projects / DLW-1e / das / opcode.h
blob5a718debf6dec10720fef78f7600c1a844ae7827
1 #ifndef _DAS_OPCODE_H
2 #define _DAS_OPCODE_H
4 #include <stdint.h>
6 /* type definitions*/
8 typedef uint16_t inst_t; // instruction
9 typedef uint8_t oper_t; // operand
11 /* operand struct */
12 struct operand {
13 int type;
14 oper_t value;
17 /* operand definitions */
19 #define OP_INV 0x0 /* invalid or not used */
20 #define OP_REG 0x1 /* register */
21 #define OP_IMM 0x2 /* immediate */
23 /* just for your convenience */
24 #define OP_RI (OP_REG | OP_IMM)
26 /* maximum number of operands */
27 #define OP_MAX 3
29 /* opcode table */
30 struct opcode {
31 const char *mnemonic;
32 int opcode;
33 int type;
34 int nr_operands;
35 struct operand operands[OP_MAX];
38 /* instruction types */
39 #define INST_ARIT 0
40 #define INST_BRAN 1
41 #define INST_MEM 2
42 #define INST_COMP 3
43 #define INST_NARG 4
45 /* instruction offsets */
46 #define OFF_INST 12
47 #define OFF_SRC1 10
48 #define OFF_SRC2 8
49 #define OFF_IMM_DEST OFF_SRC2
50 #define OFF_DEST 6
52 #define OFF_MEM_REG_SRC1 10
53 #define OFF_MEM_REG_DEST 6
54 #define OFF_MEM_IMM_DEST 8
56 /* masks */
57 #define MASK_IMM 0xFF
59 /* special bits */
60 #define BIT_IMM 0x8000
62 /* helper macros */
64 /* set_reg(): set register 'reg' at offset 'off' in 'instruction' */
65 static inline void set_reg(inst_t *instruction, oper_t reg, int off)
67 *instruction |= ((inst_t) (reg << off));
70 /* set_imm(): set immediate 'imm' in 'instruction' */
71 static inline void set_imm(inst_t *instruction, oper_t imm)
73 *instruction |= BIT_IMM;
74 *instruction |= ((inst_t) (MASK_IMM & imm));
77 /* exported functions */
78 struct opcode *opcode_lookup(const char *mnemonic);
80 #endif /* _DAS_OPCODE_H */