psx emulator
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

  1. #include "insn.h"
  2. #include "cpu.h"
  3. #include "util.h"
  4. #include <stddef.h>
  5. #define TABLE_SIZE 0x34
  6. static cpu_insn_handler primary_insn_handler[TABLE_SIZE] = {NULL};
  7. static cpu_insn_handler secondary_insn_handler[TABLE_SIZE] = {NULL};
  8. static inline op_primary_t extract_primary_op(uint32_t insn) {
  9. return (insn >> 26) & 0x3f;
  10. }
  11. static inline op_secondary_t extract_secondary_op(uint32_t insn) {
  12. return (insn >> 0) & 0x3f;
  13. }
  14. void insn_execute(cpu_t *cpu, uint32_t raw_insn) {
  15. const op_primary_t op = extract_primary_op(raw_insn);
  16. const insn_t insn = *(insn_t *)&raw_insn;
  17. if (op == SPECIAL) {
  18. const op_secondary_t op2 = extract_secondary_op(raw_insn);
  19. if (op2 > TABLE_SIZE || secondary_insn_handler[op2] == NULL) {
  20. fatal("unsupported instruction: insn=%08x, op=%02x, op2=%02x", raw_insn,
  21. op, op2);
  22. }
  23. secondary_insn_handler[op2](cpu, insn);
  24. }
  25. if (op > TABLE_SIZE || primary_insn_handler[op] == NULL) {
  26. fatal("unsupported instruction: insn=%08x, op=%02x", raw_insn, op);
  27. }
  28. primary_insn_handler[op](cpu, insn);
  29. }