src/arm.c (view raw)
1#include "arm.h"
2
3static void _ARMSetMode(struct ARMCore*, enum ExecutionMode);
4static ARMInstruction _ARMLoadInstructionARM(struct ARMMemory*, uint32_t address);
5static ARMInstruction _ARMLoadInstructionThumb(struct ARMMemory*, uint32_t address);
6
7static void _ARMSetMode(struct ARMCore* cpu, enum ExecutionMode executionMode) {
8 if (executionMode == cpu->executionMode) {
9 return;
10 }
11
12 cpu->executionMode = executionMode;
13 switch (executionMode) {
14 case MODE_ARM:
15 cpu->cpsr.t = 0;
16 cpu->instructionWidth = WORD_SIZE_ARM;
17 cpu->loadInstruction = _ARMLoadInstructionARM;
18 break;
19 case MODE_THUMB:
20 cpu->cpsr.t = 1;
21 cpu->instructionWidth = WORD_SIZE_THUMB;
22 cpu->loadInstruction = _ARMLoadInstructionThumb;
23 }
24}
25
26static ARMInstruction _ARMLoadInstructionARM(struct ARMMemory* memory, uint32_t address) {
27 int32_t opcode = memory->load32(memory, address);
28 return 0;
29}
30
31static ARMInstruction _ARMLoadInstructionThumb(struct ARMMemory* memory, uint32_t address) {
32 uint16_t opcode = memory->loadU16(memory, address);
33 return 0;
34}
35
36void ARMInit(struct ARMCore* cpu) {
37 int i;
38 for (i = 0; i < 16; ++i) {
39 cpu->gprs[i] = 0;
40 }
41
42 cpu->cpsr.packed = 0;
43 cpu->spsr.packed = 0;
44
45 cpu->cyclesToEvent = 0;
46
47 cpu->shifterOperand = 0;
48 cpu->shifterCarryOut = 0;
49
50 cpu->memory = 0;
51 cpu->board = 0;
52
53 cpu->executionMode = MODE_THUMB;
54 _ARMSetMode(cpu, MODE_ARM);
55}
56
57void ARMAssociateMemory(struct ARMCore* cpu, struct ARMMemory* memory) {
58 cpu->memory = memory;
59}
60
61void ARMCycle(struct ARMCore* cpu) {
62 // TODO
63 ARMInstruction instruction = cpu->loadInstruction(cpu->memory, cpu->gprs[ARM_PC] - cpu->instructionWidth);
64}