spacepaste

  1.  
  2. struct virtual_cpu_register_bank {
  3. int r1;
  4. int r2;
  5. int r3;
  6. int32_t pc;
  7. char * name;
  8. CPU_TYPE type;
  9. };
  10. struct virtual_cpu_sub_core {
  11. struct virtual_cpu_register_bank virtual_register;
  12. int op;
  13. int status;
  14. char * name;
  15. };
  16. struct virtual_cpu_core {
  17. struct virtual_cpu_sub_core previous;
  18. struct virtual_cpu_sub_core current;
  19. int status;
  20. int power;
  21. char * cpu_power_state[2];
  22. char * name;
  23. bool init;
  24. };
  25. struct virtual_cpu {
  26. int core_count;
  27. struct virtual_cpu_core *core;
  28. struct Queue *q;
  29. char ** table_instructions;
  30. char ** table_types;
  31. char ** table_registers;
  32. char ** table_encoding;
  33. struct instruction * instruction_bank;
  34. char * name;
  35. } cpu_default;
  36. void cpu_register_info_minimal(struct virtual_cpu_register_bank *virtual_register) {
  37. printf("VIRTUAL CPU: INFO : register bank name: %s\n", virtual_register->name);
  38. printf("VIRTUAL CPU: INFO : size of %s: %zu\n", virtual_register->name, sizeof(*virtual_register));
  39. printf("VIRTUAL CPU: INFO : %s : r1: %d\n", virtual_register->name, virtual_register->r1);
  40. printf("VIRTUAL CPU: INFO : %s : r2: %d\n", virtual_register->name, virtual_register->r2);
  41. printf("VIRTUAL CPU: INFO : %s : r3: %d\n", virtual_register->name, virtual_register->r3);
  42. printf("VIRTUAL CPU: INFO : %s : pc: %d\n", virtual_register->name, virtual_register->pc);
  43. printf("VIRTUAL CPU: INFO : %s : name: %s\n", virtual_register->name, virtual_register->name);
  44. }
  45. void cpu_register_info(struct virtual_cpu *cpu, struct virtual_cpu_core *core, struct virtual_cpu_sub_core *sub_core, struct virtual_cpu_register_bank *virtual_register) {
  46. printf("VIRTUAL CPU: INFO : %s : %s : %s : register bank name: %s\n", cpu->name, core->name, sub_core->name, virtual_register->name);
  47. printf("VIRTUAL CPU: INFO : %s : %s : %s : size of %s: %zu\n", cpu->name, core->name, sub_core->name, virtual_register->name, sizeof(*virtual_register));
  48. printf("VIRTUAL CPU: INFO : %s : %s : %s : %s : r1: %d\n", cpu->name, core->name, sub_core->name, virtual_register->name, virtual_register->r1);
  49. printf("VIRTUAL CPU: INFO : %s : %s : %s : %s : r2: %d\n", cpu->name, core->name, sub_core->name, virtual_register->name, virtual_register->r2);
  50. printf("VIRTUAL CPU: INFO : %s : %s : %s : %s : r3: %d\n", cpu->name, core->name, sub_core->name, virtual_register->name, virtual_register->r3);
  51. printf("VIRTUAL CPU: INFO : %s : %s : %s : %s : pc: %d\n", cpu->name, core->name, sub_core->name, virtual_register->name, virtual_register->pc);
  52. }
  53. void cpu_sub_core_info(struct virtual_cpu *cpu, struct virtual_cpu_core *core, struct virtual_cpu_sub_core *sub_core) {
  54. printf("VIRTUAL CPU: INFO : %s : %s : sub core name: %s\n", cpu->name, core->name, sub_core->name);
  55. printf("VIRTUAL CPU: INFO : %s : %s : size of %s: %zu\n", cpu->name, core->name, sub_core->name, sizeof(*sub_core));
  56. cpu_register_info(cpu, core, sub_core, &sub_core->virtual_register);
  57. }
  58. void cpu_core_info(struct virtual_cpu *cpu, struct virtual_cpu_core *core) {
  59. printf("VIRTUAL CPU: INFO : %s : core name: %s\n", cpu->name, core->name);
  60. printf("VIRTUAL CPU: INFO : %s : size of %s: %zu\n", cpu->name, core->name,
  61. sizeof(*core)-
  62. sizeof(core->cpu_power_state)+
  63. (
  64. sizeof(core->cpu_power_state)*env__size(core->cpu_power_state)
  65. )
  66. );
  67. printf("VIRTUAL CPU: INFO : %s : %s : cpu power status: %s\n", cpu->name, core->name, core->cpu_power_state[core->power]);
  68. printf("VIRTUAL CPU: INFO : %s : %s : status: %d\n", cpu->name, core->name, core->status);
  69. cpu_sub_core_info(cpu, core, &core->previous);
  70. cpu_sub_core_info(cpu, core, &core->current);
  71. }
  72. void cpu_info(struct virtual_cpu *cpu) {
  73. virtual_cpu_check(cpu);
  74. printf("VIRTUAL CPU: INFO : cpu name: %s\n", cpu->name);
  75. printf("VIRTUAL CPU: INFO : cpu cores: %d\n", cpu->core_count);
  76. printf
  77. (
  78. "VIRTUAL CPU: INFO : size of %s: %zu\n", cpu->name,
  79. (
  80. sizeof(*cpu)-
  81. (
  82. sizeof(cpu->q)+
  83. sizeof(cpu->core)+
  84. sizeof(cpu->table_instructions)+
  85. sizeof(cpu->table_types)+
  86. sizeof(cpu->table_registers)+
  87. sizeof(cpu->table_encoding)+
  88. sizeof(cpu->instruction_bank)
  89. )+
  90. (
  91. (
  92. sizeof(cpu->core[0])-
  93. sizeof(cpu->core[0].cpu_power_state)+
  94. (
  95. sizeof(cpu->core[0].cpu_power_state)*env__size(cpu->core[0].cpu_power_state)
  96. )
  97. ) * cpu->core_count
  98. )
  99. ) +
  100. (
  101. sizeof(cpu->table_instructions) * env__size(cpu->table_instructions)+
  102. sizeof(cpu->table_types) *env__size(cpu->table_types)+
  103. sizeof(cpu->table_registers) * env__size(cpu->table_registers)+
  104. sizeof(cpu->table_encoding) * env__size(cpu->table_encoding)+
  105. sizeof(*cpu->instruction_bank) * env__size(&cpu->instruction_bank)
  106. )
  107. );
  108. printf("VIRTUAL CPU: INFO : size of instruction table: %zu\n", sizeof(cpu->table_instructions) * env__size(cpu->table_instructions));
  109. printf("VIRTUAL CPU: INFO : size of types table: %zu\n", sizeof(cpu->table_types) * env__size(cpu->table_types));
  110. printf("VIRTUAL CPU: INFO : size of registers table: %zu\n", sizeof(cpu->table_registers) * env__size(cpu->table_registers));
  111. printf("VIRTUAL CPU: INFO : size of encoding table: %zu\n", sizeof(cpu->table_encoding) * env__size(cpu->table_encoding));
  112. printf("VIRTUAL CPU: INFO : size of instruction bank: %zu\n", sizeof(*cpu->instruction_bank) * env__size(&cpu->instruction_bank));
  113. for (int i = 0; i < 1; i++) cpu_core_info(cpu, &cpu->core[i]);
  114. }
  115.