mips/include/mips32r6.h

431 lines
10 KiB
C
Raw Normal View History

2024-10-04 23:41:10 +00:00
/* Copyright (c) 2024 Freya Murphy */
#ifndef __MIPS32R6_H__
#define __MIPS32R6_H__
#include <mlimits.h>
#include <stdint.h>
2024-10-09 16:08:58 +00:00
#include <mips.h>
2024-10-04 23:41:10 +00:00
2024-10-21 16:27:18 +00:00
// TODO:
// balc
// TODO: [add]
// align
// aluipc
// aui
// auipc
// bal real ins
// balc
// bc
// bc1eqz
// bc1nez
// bc2eqz
// bc2nez
// b{le,ge,gt,lt,eq,ne}ZALC
// b<cond>c
// bitswap
// bovc
// bnvc
// crc32{b,h,w}
// c2c32c{b,h,w}
// div, mod, divu, modu
// dvp
// eretnc
// evp
// gnvi
// ginvt
// jialc
// jic
// jr assembly idiom
// llwp
// llwpe
// lsa
// lwpc
// mfhc0
// mthc0
// mul muh mulu muhu
// nal
// scwp
// scwpe
// seleqz selnez
// sigrie
// TODO: [remove]
// bc1f
// bc1fl
// bc1tl
// bc1tl
// bc2f
// bc2fl
// bc2t
// bc2tl
// all branch likely
// div
// divu
// jr
// ldxc1
// lui
// luxc1
// lwl
// lwr
// lwxc1
// madd
// maddu
// mfhi
// mflo
// movf
// movn
// movt
// movz
// msub
// msubu
// mthi
// mtlo
// mul
// mult
// multu
// prefx
// sdxc1
// suxc1
// swl
// swr
// swxc1
// teqi
// tgei
// tgeiu
// tlti
// tltiu
// tnei
2024-10-04 23:41:10 +00:00
/* mips instructions */
enum mips32r6_instruction_type {
MIPS32R6_INS_ADD,
MIPS32R6_INS_ADDI,
MIPS32R6_INS_ADDIU,
MIPS32R6_INS_ADDU,
MIPS32R6_INS_AND,
MIPS32R6_INS_ANDI,
2024-10-21 16:27:18 +00:00
MIPS32R6_INS_BC1F,
MIPS32R6_INS_BC1FL,
MIPS32R6_INS_BC1T,
MIPS32R6_INS_BC1TL,
MIPS32R6_INS_BC2F,
MIPS32R6_INS_BC2FL,
MIPS32R6_INS_BC2T,
MIPS32R6_INS_BC2TL,
2024-10-04 23:41:10 +00:00
MIPS32R6_INS_BEQ,
2024-10-21 16:27:18 +00:00
MIPS32R6_INS_BEQL,
2024-10-04 23:41:10 +00:00
MIPS32R6_INS_BGEZ,
MIPS32R6_INS_BGEZAL,
2024-10-21 16:27:18 +00:00
MIPS32R6_INS_BGEZALL,
MIPS32R6_INS_BGEZL,
2024-10-04 23:41:10 +00:00
MIPS32R6_INS_BGTZ,
2024-10-21 16:27:18 +00:00
MIPS32R6_INS_BGTZL,
2024-10-04 23:41:10 +00:00
MIPS32R6_INS_BLEZ,
2024-10-21 16:27:18 +00:00
MIPS32R6_INS_BLEZL,
2024-10-04 23:41:10 +00:00
MIPS32R6_INS_BLTZ,
MIPS32R6_INS_BLTZAL,
2024-10-21 16:27:18 +00:00
MIPS32R6_INS_BLTZALL,
MIPS32R6_INS_BLTZL,
2024-10-04 23:41:10 +00:00
MIPS32R6_INS_BNE,
2024-10-21 16:27:18 +00:00
MIPS32R6_INS_BNEL,
MIPS32R6_INS_BREAK,
MIPS32R6_INS_CACHE,
MIPS32R6_INS_CFC1,
MIPS32R6_INS_CFC2,
MIPS32R6_INS_CLO,
MIPS32R6_INS_CLZ,
MIPS32R6_INS_COP2,
MIPS32R6_INS_CTC1,
MIPS32R6_INS_CTC2,
MIPS32R6_INS_DERET,
MIPS32R6_INS_DI,
2024-10-04 23:41:10 +00:00
MIPS32R6_INS_DIV,
MIPS32R6_INS_DIVU,
2024-10-21 16:27:18 +00:00
MIPS32R6_INS_EI,
MIPS32R6_INS_ERET,
MIPS32R6_INS_EXT,
MIPS32R6_INS_INS,
2024-10-04 23:41:10 +00:00
MIPS32R6_INS_J,
MIPS32R6_INS_JAL,
MIPS32R6_INS_JALR,
MIPS32R6_INS_JR,
MIPS32R6_INS_LB,
MIPS32R6_INS_LBU,
2024-10-21 16:27:18 +00:00
MIPS32R6_INS_LDC1,
MIPS32R6_INS_LDC2,
MIPS32R6_INS_LDXC1,
2024-10-04 23:41:10 +00:00
MIPS32R6_INS_LH,
MIPS32R6_INS_LHU,
2024-10-21 16:27:18 +00:00
MIPS32R6_INS_LL,
2024-10-04 23:41:10 +00:00
MIPS32R6_INS_LUI,
2024-10-21 16:27:18 +00:00
MIPS32R6_INS_LUXC1,
2024-10-04 23:41:10 +00:00
MIPS32R6_INS_LW,
2024-10-21 16:27:18 +00:00
MIPS32R6_INS_LWC1,
MIPS32R6_INS_LWC2,
MIPS32R6_INS_LWL,
MIPS32R6_INS_LWR,
MIPS32R6_INS_LWXC1,
MIPS32R6_INS_MADD,
MIPS32R6_INS_MADDU,
MIPS32R6_INS_MFC0,
MIPS32R6_INS_MFC1,
MIPS32R6_INS_MFC2,
MIPS32R6_INS_MFHC1,
MIPS32R6_INS_MFHC2,
MIPS32R6_INS_MFHI,
MIPS32R6_INS_MFLO,
MIPS32R6_INS_MOVF,
MIPS32R6_INS_MOVN,
MIPS32R6_INS_MOVT,
MIPS32R6_INS_MOVZ,
MIPS32R6_INS_MSUB,
MIPS32R6_INS_MSUBU,
MIPS32R6_INS_MTC0,
MIPS32R6_INS_MTC1,
MIPS32R6_INS_MTC2,
MIPS32R6_INS_MTHC1,
MIPS32R6_INS_MTHC2,
MIPS32R6_INS_MTHI,
MIPS32R6_INS_MTLO,
2024-10-04 23:41:10 +00:00
MIPS32R6_INS_MUL,
2024-10-21 16:27:18 +00:00
MIPS32R6_INS_MULT,
MIPS32R6_INS_MULTU,
MIPS32R6_INS_NOR,
MIPS32R6_INS_OR,
MIPS32R6_INS_ORI,
MIPS32R6_INS_PREF,
MIPS32R6_INS_PREFX,
MIPS32R6_INS_RDHWR,
MIPS32R6_INS_RDPGPR,
MIPS32R6_INS_ROTR,
MIPS32R6_INS_ROTRV,
2024-10-04 23:41:10 +00:00
MIPS32R6_INS_SB,
2024-10-21 16:27:18 +00:00
MIPS32R6_INS_SC,
MIPS32R6_INS_SDBBP,
MIPS32R6_INS_SDC1,
MIPS32R6_INS_SDC2,
MIPS32R6_INS_SDXC1,
MIPS32R6_INS_SEB,
MIPS32R6_INS_SEH,
2024-10-04 23:41:10 +00:00
MIPS32R6_INS_SH,
MIPS32R6_INS_SLL,
MIPS32R6_INS_SLLV,
MIPS32R6_INS_SLT,
MIPS32R6_INS_SLTI,
MIPS32R6_INS_SLTIU,
MIPS32R6_INS_SLTU,
MIPS32R6_INS_SRA,
MIPS32R6_INS_SRAV,
MIPS32R6_INS_SRL,
MIPS32R6_INS_SRLV,
MIPS32R6_INS_SUB,
MIPS32R6_INS_SUBU,
2024-10-21 16:27:18 +00:00
MIPS32R6_INS_SUXC1,
MIPS32R6_INS_SW,
MIPS32R6_INS_SWC1,
MIPS32R6_INS_SWC2,
MIPS32R6_INS_SWL,
MIPS32R6_INS_SWR,
MIPS32R6_INS_SWXC1,
MIPS32R6_INS_SYNC,
MIPS32R6_INS_SYNCI,
2024-10-04 23:41:10 +00:00
MIPS32R6_INS_SYSCALL,
2024-10-21 16:27:18 +00:00
MIPS32R6_INS_TEQ,
MIPS32R6_INS_TEQI,
MIPS32R6_INS_TGE,
MIPS32R6_INS_TGEI,
MIPS32R6_INS_TGEIU,
MIPS32R6_INS_TGEU,
MIPS32R6_INS_TLBP,
MIPS32R6_INS_TLBR,
MIPS32R6_INS_TLBWI,
MIPS32R6_INS_TLBWR,
MIPS32R6_INS_TLT,
MIPS32R6_INS_TLTI,
MIPS32R6_INS_TLTIU,
MIPS32R6_INS_TLTU,
MIPS32R6_INS_TNE,
MIPS32R6_INS_TNEI,
MIPS32R6_INS_WAIT,
MIPS32R6_INS_WRPGPR,
MIPS32R6_INS_WSBH,
2024-10-04 23:41:10 +00:00
MIPS32R6_INS_XOR,
MIPS32R6_INS_XORI,
__MIPS32R6_INS_NULL,
};
2024-10-21 16:27:18 +00:00
// op code groups
2024-10-04 23:41:10 +00:00
#define MIPS32R6_OP_SPECIAL 0b000000
2024-10-21 16:27:18 +00:00
#define MIPS32R6_OP_SPECIAL2 0b011100
#define MIPS32R6_OP_SPECIAL3 0b011111
#define MIPS32R6_OP_REGIMM 0b000001
#define MIPS32R6_OP_COP0 0b010000
#define MIPS32R6_OP_COP1 0b010001
#define MIPS32R6_OP_COP2 0b010010
#define MIPS32R6_OP_COP1X 0b010011
// op codes
2024-10-04 23:41:10 +00:00
#define MIPS32R6_OP_ADDI 0b001000
#define MIPS32R6_OP_ADDIU 0b001001
#define MIPS32R6_OP_ANDI 0b001100
#define MIPS32R6_OP_BC 0b110010
#define MIPS32R6_OP_BEQ 0b000100
#define MIPS32R6_OP_BEQL 0b010100
#define MIPS32R6_OP_BGTZ 0b000111
#define MIPS32R6_OP_BGTZL 0b010111
#define MIPS32R6_OP_BLEZ 0b000110
#define MIPS32R6_OP_BLEZL 0b010110
#define MIPS32R6_OP_BNE 0b000101
#define MIPS32R6_OP_BNEL 0b010101
2024-10-21 16:27:18 +00:00
#define MIPS32R6_OP_CACHE 0b101111
2024-10-04 23:41:10 +00:00
#define MIPS32R6_OP_J 0b000010
#define MIPS32R6_OP_JAL 0b000011
#define MIPS32R6_OP_JALX 0b011101
#define MIPS32R6_OP_LB 0b100000
#define MIPS32R6_OP_LBU 0b100100
2024-10-21 16:27:18 +00:00
#define MIPS32R6_OP_LDC1 0b110101
#define MIPS32R6_OP_LDC2 0b110110
2024-10-04 23:41:10 +00:00
#define MIPS32R6_OP_LH 0b100001
#define MIPS32R6_OP_LHU 0b100101
2024-10-21 16:27:18 +00:00
#define MIPS32R6_OP_LL 0b110000
2024-10-04 23:41:10 +00:00
#define MIPS32R6_OP_LUI 0b001111
#define MIPS32R6_OP_LW 0b100011
2024-10-21 16:27:18 +00:00
#define MIPS32R6_OP_LWC1 0b110001
#define MIPS32R6_OP_LWC2 0b110010
#define MIPS32R6_OP_LWL 0b100010
#define MIPS32R6_OP_LWR 0b100110
#define MIPS32R6_OP_ORI 0b001101
#define MIPS32R6_OP_PREF 0b110011
2024-10-04 23:41:10 +00:00
#define MIPS32R6_OP_SB 0b101000
2024-10-21 16:27:18 +00:00
#define MIPS32R6_OP_SC 0b111000
#define MIPS32R6_OP_SDC1 0b111101
#define MIPS32R6_OP_SDC2 0b111110
2024-10-04 23:41:10 +00:00
#define MIPS32R6_OP_SH 0b101001
#define MIPS32R6_OP_SLTI 0b001010
#define MIPS32R6_OP_SLTIU 0b001011
2024-10-21 16:27:18 +00:00
#define MIPS32R6_OP_SW 0b101011
#define MIPS32R6_OP_SWC1 0b111001
#define MIPS32R6_OP_SWC2 0b111010
#define MIPS32R6_OP_SWL 0b101010
#define MIPS32R6_OP_SWR 0b101110
2024-10-04 23:41:10 +00:00
#define MIPS32R6_OP_XORI 0b001110
2024-10-21 16:27:18 +00:00
// op special
2024-10-04 23:41:10 +00:00
#define MIPS32R6_FUNCT_ADD 0b100000
#define MIPS32R6_FUNCT_ADDU 0b100001
#define MIPS32R6_FUNCT_AND 0b100100
2024-10-21 16:27:18 +00:00
#define MIPS32R6_FUNCT_BREAK 0b001101
#define MIPS32R6_FUNCT_DIV 0b000011
#define MIPS32R6_FUNCT_DIVU 0b011011
2024-10-04 23:41:10 +00:00
#define MIPS32R6_FUNCT_JALR 0b001001
#define MIPS32R6_FUNCT_JR 0b001000
#define MIPS32R6_FUNCT_MFHI 0b010000
#define MIPS32R6_FUNCT_MFLO 0b010010
2024-10-21 16:27:18 +00:00
#define MIPS32R6_FUNCT_MOVCL 0b000001
#define MIPS32R6_FUNCT_MOVN 0b001011
#define MIPS32R6_FUNCT_MOVZ 0b001010
2024-10-04 23:41:10 +00:00
#define MIPS32R6_FUNCT_MTHI 0b010001
#define MIPS32R6_FUNCT_MTLO 0b010011
2024-10-21 16:27:18 +00:00
#define MIPS32R6_FUNCT_MULT 0b011000
#define MIPS32R6_FUNCT_MULTU 0b011001
#define MIPS32R6_FUNCT_NOR 0b100111
#define MIPS32R6_FUNCT_OR 0b100101
2024-10-04 23:41:10 +00:00
#define MIPS32R6_FUNCT_SLL 0b000000
#define MIPS32R6_FUNCT_SLLV 0b000100
#define MIPS32R6_FUNCT_SLT 0b101010
#define MIPS32R6_FUNCT_SLTU 0b101011
#define MIPS32R6_FUNCT_SRA 0b000011
#define MIPS32R6_FUNCT_SRAV 0b000111
#define MIPS32R6_FUNCT_SRL 0b000010
#define MIPS32R6_FUNCT_SRLV 0b000110
#define MIPS32R6_FUNCT_SUB 0b100010
#define MIPS32R6_FUNCT_SUBU 0b100011
2024-10-21 16:27:18 +00:00
#define MIPS32R6_FUNCT_SYNC 0b001111
2024-10-04 23:41:10 +00:00
#define MIPS32R6_FUNCT_SYSCALL 0b001100
2024-10-21 16:27:18 +00:00
#define MIPS32R6_FUNCT_TEQ 0b110100
#define MIPS32R6_FUNCT_TGE 0b110000
#define MIPS32R6_FUNCT_TGEU 0b110001
#define MIPS32R6_FUNCT_TLT 0b110010
#define MIPS32R6_FUNCT_TLTU 0b110011
#define MIPS32R6_FUNCT_TNE 0b110110
2024-10-04 23:41:10 +00:00
#define MIPS32R6_FUNCT_XOR 0b100110
2024-10-21 16:27:18 +00:00
// op special2
#define MIPS32R6_FUNCT_CLO 0b100001
#define MIPS32R6_FUNCT_CLZ 0b100000
#define MIPS32R6_FUNCT_MADD 0b000000
#define MIPS32R6_FUNCT_MADDU 0b000001
#define MIPS32R6_FUNCT_MSUB 0b000100
#define MIPS32R6_FUNCT_MSUBU 0b000101
#define MIPS32R6_FUNCT_MUL 0b000010
#define MIPS32R6_FUNCT_SDBBP 0b111111
// op special 3
#define MIPS32R6_FUNCT_EXT 0b000000
#define MIPS32R6_FUNCT_INS 0b000100
#define MIPS32R6_FUNCT_RDHWR 0b111011
#define MIPS32R6_FUNCT_BSHFL 0b100000
// op bshfl
#define MIPS32R6_FUNCT_SEB 0b10000
#define MIPS32R6_FUNCT_SEH 0b11000
#define MIPS32R6_FUNCT_WSBH 0b00010
// op regimm
2024-10-04 23:41:10 +00:00
#define MIPS32R6_FUNCT_BGEZ 0b00001
#define MIPS32R6_FUNCT_BGEZAL 0b10001
#define MIPS32R6_FUNCT_BGEZALL 0b10011
#define MIPS32R6_FUNCT_BGEZL 0b00011
#define MIPS32R6_FUNCT_BLTZ 0b00000
#define MIPS32R6_FUNCT_BLTZAL 0b10000
#define MIPS32R6_FUNCT_BLTZALL 0b10010
#define MIPS32R6_FUNCT_BLTZL 0b00010
2024-10-21 16:27:18 +00:00
#define MIPS32R6_FUNCT_SYNCI 0b11111
#define MIPS32R6_FUNCT_TEQI 0b01100
#define MIPS32R6_FUNCT_TGEI 0b01000
#define MIPS32R6_FUNCT_TGEIU 0b01001
#define MIPS32R6_FUNCT_TLTI 0b01010
#define MIPS32R6_FUNCT_TLTIU 0b01011
#define MIPS32R6_FUNCT_TNEI 0b01110
// op cop cfunct
#define MIPS32R6_FUNCT_BC 0b01000
#define MIPS32R6_FUNCT_CF 0b00010
#define MIPS32R6_FUNCT_CT 0b00110
#define MIPS32R6_FUNCT_MF 0b00000
#define MIPS32R6_FUNCT_MFH 0b00011
#define MIPS32R6_FUNCT_MT 0b00100
#define MIPS32R6_FUNCT_MTH 0b00111
#define MIPS32R6_FUNCT_MFMC0 0b01011
#define MIPS32R6_FUNCT_RDPGPR 0b01010
#define MIPS32R6_FUNCT_WRPGPR 0b01110
// op cop funct
#define MIPS32R6_FUNCT_DERET 0b011111
#define MIPS32R6_FUNCT_ERET 0b011000
#define MIPS32R6_FUNCT_TLBP 0b001000
#define MIPS32R6_FUNCT_TLBR 0b000001
#define MIPS32R6_FUNCT_TLBWI 0b000010
#define MIPS32R6_FUNCT_TLBWR 0b000110
2024-10-04 23:41:10 +00:00
2024-10-21 16:27:18 +00:00
// op cop1x
#define MIPS32R6_FUNCT_LDXC1 0b000001
#define MIPS32R6_FUNCT_LUXC1 0b000101
#define MIPS32R6_FUNCT_LWXC1 0b000000
#define MIPS32R6_FUNCT_PREFX 0b001111
#define MIPS32R6_FUNCT_SDXC1 0b001001
#define MIPS32R6_FUNCT_SUXC1 0b001101
#define MIPS32R6_FUNCT_SWXC1 0b001000
#define MIPS32R6_FUNCT_WAIT 0b100000
2024-10-04 23:41:10 +00:00
#define __MIPS32R6_INS_LEN (__MIPS32R6_INS_NULL)
2024-10-21 16:27:18 +00:00
#define __MIPS32R6_PSEUDO_LEN (38)
2024-10-04 23:41:10 +00:00
#define __MIPS32R6_GRAMMER_LEN (__MIPS32R6_INS_LEN + __MIPS32R6_PSEUDO_LEN)
extern struct mips32_grammer mips32r6_grammers[__MIPS32R6_GRAMMER_LEN];
extern union mips32_instruction mips32r6_instructions[__MIPS32R6_INS_LEN];
#endif /* __MIPS32R6_H__ */