diff --git a/src/a64instruction.h b/src/a64instruction.h index 31fc602..463e75a 100644 --- a/src/a64instruction.h +++ b/src/a64instruction.h @@ -1,3 +1,5 @@ +#ifndef __A64INSTRUCTION__ +#define __A64INSTRUCTION__ #include "a64instruction_DPImmediate.h" #include "a64instruction_Branch.h" #include "a64instruction_SingleTransfer.h" @@ -22,3 +24,5 @@ typedef struct { a64inst_SingleTransferData SingleTransferData; } data; } a64inst_instruction; + +#endif diff --git a/src/decode.h b/src/decode.h index a141a8f..09a1c55 100644 --- a/src/decode.h +++ b/src/decode.h @@ -69,5 +69,3 @@ #define BRANCH_CONDITIONAL_COND_MSB 4 #define BRANCH_CONDITIONAL_OFFSET_LSB 5 #define BRANCH_CONDITIONAL_OFFSET_MSB 24 - -a64inst_instruction *decode(word w); \ No newline at end of file diff --git a/src/emulate.c b/src/emulate.c index 3bbb3d7..54b0d68 100755 --- a/src/emulate.c +++ b/src/emulate.c @@ -1,5 +1,12 @@ #include #include +#include "emulator.h" +#include "fileio.h" +#include "print.h" +#include "decode.h" +#include "execute.h" + +extern a64inst_instruction *decode(word w); int main(int argc, char **argv) { @@ -18,6 +25,28 @@ int main(int argc, char **argv) { } } + // Initialising the machine state + Machine *state = {0}; + state->memory = fileio_loadBin(argv[1], MEMORY_SIZE); + state->conditionCodes = (PState){0, 1, 0, 0}; + state->pc = 0x0; + // get + a64inst_instruction *inst; + do { + + word instruction = readWord(state, state->pc); + inst = decode(instruction); + execute(state, inst); + + state->pc += 1; + + } while (inst->type != a64inst_HALT); + + printState(state, out); + + free(state->memory); + + return EXIT_SUCCESS; } diff --git a/src/emulator.h b/src/emulator.h index f6a3cb2..59942df 100644 --- a/src/emulator.h +++ b/src/emulator.h @@ -1,6 +1,7 @@ #ifndef __EMULATOR__ #define __EMULATOR__ #include "global.h" +#include /************************************ * DEFINITIONS @@ -23,7 +24,7 @@ typedef struct { typedef struct { word registers[REGISTER_COUNT]; word pc; - byte memory[MEMORY_SIZE]; + byte *memory; PState conditionCodes; } Machine; diff --git a/src/execute.c b/src/execute.c index e1ebbf9..d0c2c5e 100644 --- a/src/execute.c +++ b/src/execute.c @@ -1,18 +1,18 @@ #include "execute.h" -void execute(a64inst_instruction inst) { +void execute(Machine *state, a64inst_instruction *inst) { - switch (inst.type) { - case a64inst_Halt: + switch (inst->type) { + case a64inst_HALT: // Halt the program break; - case a64inst_DPImmediate: + case a64inst_DPIMMEDIATE: // Execute a data processing immediate instruction break; - case a64inst_Branch: + case a64inst_BRANCH: // Execute a branch instruction break; - case a64inst_DPRegister: + case a64inst_DPREGISTER: // Execute a data processing register instruction break; default: diff --git a/src/execute.h b/src/execute.h index fd9da37..fcf39ec 100644 --- a/src/execute.h +++ b/src/execute.h @@ -1,3 +1,7 @@ +#ifndef __EXECUTE__ +#define __EXECUTE__ #include "a64instruction.h" +#include "emulator.h" -void execute(a64inst_instruction inst); \ No newline at end of file +void execute(Machine *state, a64inst_instruction *inst); +#endif