src/arm/isa-inlines.h (view raw)
1#ifndef ISA_INLINES_H
2#define ISA_INLINES_H
3
4#include "common.h"
5
6#include "arm.h"
7
8#define UNUSED(V) (void)(V)
9
10#define DO_4(DIRECTIVE) \
11 DIRECTIVE, \
12 DIRECTIVE, \
13 DIRECTIVE, \
14 DIRECTIVE
15
16#define DO_8(DIRECTIVE) \
17 DIRECTIVE, \
18 DIRECTIVE, \
19 DIRECTIVE, \
20 DIRECTIVE, \
21 DIRECTIVE, \
22 DIRECTIVE, \
23 DIRECTIVE, \
24 DIRECTIVE
25
26#define DO_256(DIRECTIVE) \
27 DO_4(DO_8(DO_8(DIRECTIVE)))
28
29#define DO_INTERLACE(LEFT, RIGHT) \
30 LEFT, \
31 RIGHT
32
33#define ARM_COND_EQ (cpu->cpsr.z)
34#define ARM_COND_NE (!cpu->cpsr.z)
35#define ARM_COND_CS (cpu->cpsr.c)
36#define ARM_COND_CC (!cpu->cpsr.c)
37#define ARM_COND_MI (cpu->cpsr.n)
38#define ARM_COND_PL (!cpu->cpsr.n)
39#define ARM_COND_VS (cpu->cpsr.v)
40#define ARM_COND_VC (!cpu->cpsr.v)
41#define ARM_COND_HI (cpu->cpsr.c && !cpu->cpsr.z)
42#define ARM_COND_LS (!cpu->cpsr.c || cpu->cpsr.z)
43#define ARM_COND_GE (!cpu->cpsr.n == !cpu->cpsr.v)
44#define ARM_COND_LT (!cpu->cpsr.n != !cpu->cpsr.v)
45#define ARM_COND_GT (!cpu->cpsr.z && !cpu->cpsr.n == !cpu->cpsr.v)
46#define ARM_COND_LE (cpu->cpsr.z || !cpu->cpsr.n != !cpu->cpsr.v)
47#define ARM_COND_AL 1
48
49#define ARM_SIGN(I) ((I) >> 31)
50#define ARM_ROR(I, ROTATE) ((((uint32_t) (I)) >> ROTATE) | ((I) << (32 - ROTATE)))
51
52#define ARM_CARRY_FROM(M, N, D) (((uint32_t) (M) >> 31) + ((uint32_t) (N) >> 31) > ((uint32_t) (D) >> 31))
53#define ARM_BORROW_FROM(M, N, D) (((uint32_t) (M)) >= ((uint32_t) (N)))
54#define ARM_V_ADDITION(M, N, D) (!(ARM_SIGN((M) ^ (N))) && (ARM_SIGN((M) ^ (D))) && (ARM_SIGN((N) ^ (D))))
55#define ARM_V_SUBTRACTION(M, N, D) ((ARM_SIGN((M) ^ (N))) && (ARM_SIGN((M) ^ (D))))
56
57#define ARM_WAIT_MUL(R) \
58 if ((R & 0xFFFFFF00) == 0xFFFFFF00 || !(R & 0xFFFFFF00)) { \
59 cpu->cycles += 1; \
60 } else if ((R & 0xFFFF0000) == 0xFFFF0000 || !(R & 0xFFFF0000)) { \
61 cpu->cycles += 2; \
62 } else if ((R & 0xFF000000) == 0xFF000000 || !(R & 0xFF000000)) { \
63 cpu->cycles += 3; \
64 } else { \
65 cpu->cycles += 4; \
66 }
67
68#define ARM_STUB cpu->irqh.hitStub(cpu, opcode)
69#define ARM_ILL cpu->irqh.hitIllegal(cpu, opcode)
70
71#define ARM_WRITE_PC \
72 cpu->gprs[ARM_PC] = (cpu->gprs[ARM_PC] & -WORD_SIZE_ARM) + WORD_SIZE_ARM; \
73 cpu->memory.setActiveRegion(cpu, cpu->gprs[ARM_PC] - WORD_SIZE_ARM); \
74 currentCycles += 2 + cpu->memory.activeNonseqCycles32 + cpu->memory.activePrefetchCycles32;
75
76#define THUMB_WRITE_PC \
77 cpu->gprs[ARM_PC] = (cpu->gprs[ARM_PC] & -WORD_SIZE_THUMB) + WORD_SIZE_THUMB; \
78 cpu->memory.setActiveRegion(cpu, cpu->gprs[ARM_PC] - WORD_SIZE_THUMB); \
79 currentCycles += 2 + cpu->memory.activeNonseqCycles16 + cpu->memory.activePrefetchCycles16;
80
81static inline int _ARMModeHasSPSR(enum PrivilegeMode mode) {
82 return mode != MODE_SYSTEM && mode != MODE_USER;
83}
84
85static inline void _ARMSetMode(struct ARMCore* cpu, enum ExecutionMode executionMode) {
86 if (executionMode == cpu->executionMode) {
87 return;
88 }
89
90 cpu->executionMode = executionMode;
91 switch (executionMode) {
92 case MODE_ARM:
93 cpu->cpsr.t = 0;
94 break;
95 case MODE_THUMB:
96 cpu->cpsr.t = 1;
97 }
98}
99
100static inline void _ARMReadCPSR(struct ARMCore* cpu) {
101 _ARMSetMode(cpu, cpu->cpsr.t);
102 ARMSetPrivilegeMode(cpu, cpu->cpsr.priv);
103 cpu->irqh.readCPSR(cpu);
104}
105
106#endif