all repos — mgba @ 4bba75dd0a6b10aec42119000da9d31e1898f496

mGBA Game Boy Advance Emulator

src/arm.h (view raw)

  1#ifndef ARM_H
  2#define ARM_H
  3
  4#include <stdint.h>
  5
  6enum {
  7	ARM_SP = 13,
  8	ARM_LR = 14,
  9	ARM_PC = 15
 10};
 11
 12enum ExecutionMode {
 13	MODE_ARM = 0,
 14	MODE_THUMB = 1
 15};
 16
 17enum PrivilegeMode {
 18	MODE_USER = 0x10,
 19	MODE_FIQ = 0x11,
 20	MODE_IRQ = 0x12,
 21	MODE_SUPERVISOR = 0x13,
 22	MODE_ABORT = 0x17,
 23	MODE_UNDEFINED = 0x1B,
 24	MODE_SYSTEM = 0x1F
 25};
 26
 27enum WordSize {
 28	WORD_SIZE_ARM = 4,
 29	WORD_SIZE_THUMB = 2
 30};
 31
 32enum ExecutionVector {
 33	BASE_RESET = 0x00000000,
 34	BASE_UNDEF = 0x00000004,
 35	BASE_SWI = 0x00000008,
 36	BASE_PABT = 0x0000000C,
 37	BASE_DABT = 0x00000010,
 38	BASE_IRQ = 0x00000018,
 39	BASE_FIQ = 0x0000001C
 40};
 41
 42enum RegisterBank {
 43	BANK_NONE = 0,
 44	BANK_FIQ = 1,
 45	BANK_IRQ = 2,
 46	BANK_SUPERVISOR = 3,
 47	BANK_ABORT = 4,
 48	BANK_UNDEFINED = 5
 49};
 50
 51struct ARMCore;
 52
 53union PSR {
 54	struct {
 55		enum PrivilegeMode priv : 5;
 56		int t : 1;
 57		int f : 1;
 58		int i : 1;
 59		int : 20;
 60		int v : 1;
 61		int c : 1;
 62		int z : 1;
 63		int n : 1;
 64	};
 65
 66	int32_t packed;
 67};
 68
 69struct ARMMemory {
 70	int32_t (*load32)(struct ARMMemory*, uint32_t address);
 71	int16_t (*load16)(struct ARMMemory*, uint32_t address);
 72	uint16_t (*loadU16)(struct ARMMemory*, uint32_t address);
 73	int8_t (*load8)(struct ARMMemory*, uint32_t address);
 74	uint8_t (*loadU8)(struct ARMMemory*, uint32_t address);
 75
 76	void (*store32)(struct ARMMemory*, uint32_t address, int32_t value);
 77	void (*store16)(struct ARMMemory*, uint32_t address, int16_t value);
 78	void (*store8)(struct ARMMemory*, uint32_t address, int8_t value);
 79};
 80
 81struct ARMBoard {
 82	struct ARMCore* cpu;
 83	void (*reset)(struct ARMBoard* board);
 84};
 85
 86struct ARMCore {
 87	int32_t gprs[16];
 88	union PSR cpsr;
 89	union PSR spsr;
 90
 91	int32_t cyclesToEvent;
 92
 93	int32_t bankedRegisters[6][7];
 94	int32_t bankedSPSRs[6];
 95
 96	int32_t shifterOperand;
 97	int32_t shifterCarryOut;
 98
 99	enum ExecutionMode executionMode;
100	enum PrivilegeMode privilegeMode;
101
102	struct ARMMemory* memory;
103	struct ARMBoard* board;
104};
105
106void ARMInit(struct ARMCore* cpu);
107void ARMAssociateMemory(struct ARMCore* cpu, struct ARMMemory* memory);
108void ARMAssociateBoard(struct ARMCore* cpu, struct ARMBoard* board);
109
110void ARMReset(struct ARMCore* cpu);
111void ARMSetPrivilegeMode(struct ARMCore*, enum PrivilegeMode);
112
113#endif