From e1051b8c95059c28d8215b84dcbe4f41b326cb56 Mon Sep 17 00:00:00 2001 From: Tobias Klauser Date: Thu, 11 Nov 2010 09:27:41 +0100 Subject: Baisc instruction handling --- instruction.h | 150 ++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 83 insertions(+), 67 deletions(-) (limited to 'instruction.h') diff --git a/instruction.h b/instruction.h index 7b5d510..57fd1b6 100644 --- a/instruction.h +++ b/instruction.h @@ -24,6 +24,9 @@ struct i_type { uint8_t a:5; } __packed; +#define I_TYPE(instr, op) \ + struct i_type *instr = (struct i_type *) &op + /* R-Type instruction */ struct r_type { uint8_t op:6; @@ -43,87 +46,29 @@ struct r_type { uint8_t a:5; } __packed; +#define R_TYPE(instr, op) \ + struct r_type *instr = (struct r_type *) &op + /* J-Type instruction */ struct j_type { uint8_t op:6; uint32_t imm26:26; } __packed; +#define J_TYPE(instr, op) \ + struct j_type *instr = (struct j_type *) &op + /* * Instruction Opcodes */ -/* OPX Encodings for R-Type instructions */ -enum { - /* 0x00 */ - ERET = 0x01, - ROLI = 0x02, - ROL = 0x03, - FLUSHP = 0x04, - RET = 0x05, - NOR = 0x06, - MULXUU = 0x07, - CMPGE = 0x08, - BRET = 0x09, - /* 0x0A */ - ROR = 0x0B, - FLUSHI = 0x0C, - JMP = 0x0D, - AND = 0x0E, - /* 0x0F */ - CMPLT = 0x10, - /* 0x11 */ - SLLI = 0x12, - SLL = 0x13, - /* 0x14 */ - /* 0x15 */ - OR = 0x16, - MULXSU = 0x17, - CMPNE = 0x18, - /* 0x19 */ - SRLI = 0x1A, - SRL = 0x1B, - NEXTPC = 0x1C, - CALLR = 0x1D, - XOR = 0x1E, - MULXSS = 0x1F, - CMPEQ = 0x20, - /* 0x21 */ - /* 0x22 */ - /* 0x23 */ - DIVU = 0x24, - DIV = 0x25, - RDCTL = 0x26, - MUL = 0x27, - CMPGEU = 0x28, - INITI = 0x29, - /* 0x2A */ - /* 0x2B */ - /* 0x2C */ - TRAP = 0x2D, - WRCTL = 0x2E, - /* 0x2F */ - CMPLTU = 0x30, - ADD = 0x31, - /* 0x32 */ - /* 0x33 */ - BREAK = 0x34, - /* 0x35 */ - SYNC = 0x36, - /* 0x37 */ - /* 0x38 */ - SUB = 0x39, - SRAI = 0x3A, - SRA = 0x3b, -}; - /* - * OP Encodings for I-Type instructions (except for CALL, which is a J-type - * instruction) + * OP Encodings for I-Type instructions (except for CALL and JMPI, which are + * J-type instructions) */ enum { CALL = 0x00, /* J-type */ - JMPI = 0x01, + JMPI = 0x01, /* J-type */ /* 0x02 */ LDBU = 0x03, ADDI = 0x04, @@ -184,5 +129,76 @@ enum { FLUSHD = 0x3B, XORHI = 0x3C, }; +#define I_TYPE_COUNT 0x40 + +/* OPX Encodings for R-Type instructions */ +enum { + /* 0x00 */ + ERET = 0x01, + ROLI = 0x02, + ROL = 0x03, + FLUSHP = 0x04, + RET = 0x05, + NOR = 0x06, + MULXUU = 0x07, + CMPGE = 0x08, + BRET = 0x09, + /* 0x0A */ + ROR = 0x0B, + FLUSHI = 0x0C, + JMP = 0x0D, + AND = 0x0E, + /* 0x0F */ + CMPLT = 0x10, + /* 0x11 */ + SLLI = 0x12, + SLL = 0x13, + /* 0x14 */ + /* 0x15 */ + OR = 0x16, + MULXSU = 0x17, + CMPNE = 0x18, + /* 0x19 */ + SRLI = 0x1A, + SRL = 0x1B, + NEXTPC = 0x1C, + CALLR = 0x1D, + XOR = 0x1E, + MULXSS = 0x1F, + CMPEQ = 0x20, + /* 0x21 */ + /* 0x22 */ + /* 0x23 */ + DIVU = 0x24, + DIV = 0x25, + RDCTL = 0x26, + MUL = 0x27, + CMPGEU = 0x28, + INITI = 0x29, + /* 0x2A */ + /* 0x2B */ + /* 0x2C */ + TRAP = 0x2D, + WRCTL = 0x2E, + /* 0x2F */ + CMPLTU = 0x30, + ADD = 0x31, + /* 0x32 */ + /* 0x33 */ + BREAK = 0x34, + /* 0x35 */ + SYNC = 0x36, + /* 0x37 */ + /* 0x38 */ + SUB = 0x39, + SRAI = 0x3A, + SRA = 0x3b, +}; +#define R_TYPE_COUNT 0x40 + +/* Forward declaration */ +struct nios2; + +typedef uint32_t (*instruction_handler)(struct nios2 *cpu, uint32_t opcode); #endif /* _INSTRUCTION_H_ */ -- cgit v1.2.3-54-g00ecf