cpu.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #include <stdint.h>
  2. #include "cpu.h"
  3. int64_t pc;
  4. uint64_t ir;
  5. uint64_t isa;
  6. int64_t registers[32];
  7. instruction rv32i[] =
  8. {
  9. { 0x0000007f, 0x00000037, }, //lui
  10. { 0x0000007f, 0x00000017, }, //auipc
  11. { 0x0000007f, 0x0000006f, }, //jal
  12. { 0x0000707f, 0x00000067, }, //jalr
  13. { 0x0000707f, 0x00000063, }, //beq
  14. { 0x0000707f, 0x00001063, }, //bne
  15. { 0x0000707f, 0x00004063, }, //blt
  16. { 0x0000707f, 0x00005063, }, //bge
  17. { 0x0000707f, 0x00006063, }, //bltu
  18. { 0x0000707f, 0x00007063, }, //bgeu
  19. { 0x0000707f, 0x00000003, }, //lb
  20. { 0x0000707f, 0x00001003, }, //lh
  21. { 0x0000707f, 0x00002003, }, //lw
  22. { 0x0000707f, 0x00004003, }, //lbu
  23. { 0x0000707f, 0x00005003, }, //lhu
  24. { 0x0000707f, 0x00000023, }, //sb
  25. { 0x0000707f, 0x00001023, }, //sh
  26. { 0x0000707f, 0x00002023, }, //sw
  27. { 0x0000707f, 0x00000013, }, //addi
  28. { 0x0000707f, 0x00002013, }, //slti
  29. { 0x0000707f, 0x00003013, }, //sltiu
  30. { 0x0000707f, 0x00004013, }, //xori
  31. { 0x0000707f, 0x00006013, }, //ori
  32. { 0x0000707f, 0x00007013, }, //andi
  33. { 0xf800707f, 0x00001013, }, //slli
  34. { 0xf800707f, 0x00005013, }, //srli
  35. { 0xf800707f, 0x40005013, }, //srai
  36. { 0xfe00707f, 0x00000033, }, //add
  37. { 0xfe00707f, 0x40000033, }, //sub
  38. { 0xfe00707f, 0x00001033, }, //sll
  39. { 0xfe00707f, 0x00002033, }, //slt
  40. { 0xfe00707f, 0x00003033, }, //sltu
  41. { 0xfe00707f, 0x00004033, }, //xor
  42. { 0xfe00707f, 0x00005033, }, //srl
  43. { 0xfe00707f, 0x40005033, }, //sra
  44. { 0xfe00707f, 0x00006033, }, //or
  45. { 0xfe00707f, 0x00007033, }, //and
  46. { 0x0000707f, 0x0000000F, }, //fence
  47. { 0xFFFFFFFF, 0x00000073, }, //ecall
  48. { 0xFFFFFFFF, 0x00100073, }, //ebreak
  49. int decode()
  50. {
  51. }
  52. int execute()
  53. {
  54. }
  55. int fetch()
  56. {
  57. mem_read_32(pc,&ir,MEM_EX);
  58. }