#include #include #include #include "print.h" #include "../shared/a64instruction/a64instruction_global.h" #include "emulator.h" #include "machine_util.h" #define UNSET_CONDITION_CODE_CHAR '-' // Prints the current machine state into the provided stream void printState(Machine *state, FILE *stream) { printRegisters(state, stream); printMemory(state, stream); } // Prints the current machine registers into the provided stream void printRegisters(Machine *state, FILE *stream) { fprintf(stream, "Registers:\n"); for (int i = 0; i < REGISTER_COUNT; i++) { fprintf(stream, "X%02d\t= %016" PRIx64 "\n", i, state->registers[i]); } fprintf(stream, "PC\t= %016" PRIx64 "\n", state->pc); fprintf(stream, "PSTATE\t: %c%c%c%c", state->conditionCodes.Negative ? 'N' : UNSET_CONDITION_CODE_CHAR, state->conditionCodes.Zero ? 'Z' : UNSET_CONDITION_CODE_CHAR, state->conditionCodes.Carry ? 'C' : UNSET_CONDITION_CODE_CHAR, state->conditionCodes.Overflow ? 'V' : UNSET_CONDITION_CODE_CHAR); } // Prints all non-zero memory locations into the provided stream void printMemory(Machine *state, FILE *stream) { fprintf(stream, "\nNon-zero memory:\n"); // print memory 4 byte aligned for (int addr = 0; addr < MEMORY_SIZE; addr+= 4) { word data = readMemory(state->memory, addr, a64inst_W); if (data != 0) { fprintf(stream, "0x%08x: %08x\n", addr, data); } } }