vm_types.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /* Copyright (C) 2016 Jeremiah Orians
  2. * This file is part of stage0.
  3. *
  4. * stage0 is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * stage0 is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with stage0. If not, see <http://www.gnu.org/licenses/>.
  16. */
  17. #include <stdint.h>
  18. #include <stdbool.h>
  19. #include <string.h>
  20. #ifdef VM256
  21. typedef __int512_t signed_wide_register;
  22. typedef __uint512_t unsigned_wide_register;
  23. typedef __int256_t signed_vm_register;
  24. typedef __uint256_t unsigned_vm_register;
  25. #define umax 256
  26. #define imax 255
  27. #define reg_size 32
  28. #define arch_name "knight256-base"
  29. #elif VM128
  30. typedef __int256_t signed_wide_register;
  31. typedef __uint256_t unsigned_wide_register;
  32. typedef __int128_t signed_vm_register;
  33. typedef __uint128_t unsigned_vm_register;
  34. #define umax 128
  35. #define imax 127
  36. #define reg_size 16
  37. #define arch_name "knight128-base"
  38. #elif VM64
  39. typedef __int128_t signed_wide_register;
  40. typedef __uint128_t unsigned_wide_register;
  41. typedef int64_t signed_vm_register;
  42. typedef uint64_t unsigned_vm_register;
  43. #define umax 64
  44. #define imax 63
  45. #define reg_size 8
  46. #define arch_name "knight64-base"
  47. #elif VM32
  48. typedef int64_t signed_wide_register;
  49. typedef uint64_t unsigned_wide_register;
  50. typedef int32_t signed_vm_register;
  51. typedef uint32_t unsigned_vm_register;
  52. #define umax 32
  53. #define imax 31
  54. #define reg_size 4
  55. #define arch_name "knight32-base"
  56. #else
  57. typedef int32_t signed_wide_register;
  58. typedef uint32_t unsigned_wide_register;
  59. typedef int16_t signed_vm_register;
  60. typedef uint16_t unsigned_vm_register;
  61. #define umax 16
  62. #define imax 15
  63. #define reg_size 2
  64. #define arch_name "knight16-base"
  65. #define vm16 42
  66. #endif
  67. /* Virtual machine state */
  68. struct lilith
  69. {
  70. uint8_t *memory;
  71. size_t amount_of_Ram;
  72. unsigned_vm_register reg[16];
  73. unsigned_vm_register ip;
  74. bool halted;
  75. bool exception;
  76. };
  77. /* Unpacked instruction */
  78. struct Instruction
  79. {
  80. unsigned_vm_register ip;
  81. uint8_t raw0, raw1, raw2, raw3;
  82. char opcode[3];
  83. uint32_t raw_XOP;
  84. char XOP[6];
  85. char operation[9];
  86. int16_t raw_Immediate;
  87. char Immediate[7];
  88. uint32_t HAL_CODE;
  89. uint8_t reg0;
  90. uint8_t reg1;
  91. uint8_t reg2;
  92. uint8_t reg3;
  93. bool invalid;
  94. };