annotate python/ppci/target/arm/__init__.py @ 362:c05ab629976a

Added CPUID for arm
author Windel Bouwman
date Sat, 15 Mar 2014 10:56:34 +0100
parents b4ac28efcdf4
children c49459768aaa
rev   line source
342
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
1
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
2 from ..basetarget import Target
345
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
3 from ..arm.registers import R0, R1, R2, R3, R4, R5, R6, R7
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
4 from ..arm.registers import R8, R9, R10, R11, R12, SP, LR, PC
342
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
5 from ..arm.registers import register_range
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
6
359
b4ac28efcdf4 Reorganize files
Windel Bouwman
parents: 357
diff changeset
7 from .instructions import Dcd, Mov, Mov1, Add, Add2, Sub, Orr1, Mul, Mov2, Add1, Mul1
356
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
8 from .instructions import Lsr1, Lsl1, And1, Sub1
352
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 350
diff changeset
9 from .instructions import B, Bl, Ble, Bgt, Beq, Blt, Cmp, Cmp2
354
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 352
diff changeset
10 from .instructions import Push, Pop, Str, Ldr, Ldr3, Str1, Ldr1, Adr
362
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
11 from .instructions import Mcr, Mrc
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
12 from .selector import ArmInstructionSelector
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
13 from .frame import ArmFrame
342
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
14
345
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
15 class ArmTarget(Target):
342
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
16 def __init__(self):
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
17 super().__init__('arm')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
18 self.make_parser()
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
19 self.ins_sel = ArmInstructionSelector()
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
20 self.FrameClass = ArmFrame
342
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
21
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
22 self.add_lowering(Ldr3, lambda im: Ldr3(im.dst[0], im.others[0]))
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
23 self.add_lowering(Str1, lambda im: Str1(im.src[1], im.src[0], im.others[0]))
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
24 self.add_lowering(Ldr1, lambda im: Ldr1(im.dst[0], im.src[0], im.others[0]))
354
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 352
diff changeset
25 self.add_lowering(Adr, lambda im: Adr(im.dst[0], im.others[0]))
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
26 self.add_lowering(Mov2, lambda im: Mov2(im.dst[0], im.src[0]))
352
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 350
diff changeset
27 self.add_lowering(Cmp2, lambda im: Cmp2(im.src[0], im.src[1]))
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 350
diff changeset
28 self.add_lowering(Add1, lambda im: Add1(im.dst[0], im.src[0], im.src[1]))
359
b4ac28efcdf4 Reorganize files
Windel Bouwman
parents: 357
diff changeset
29 self.add_lowering(Add2, lambda im: Add2(im.dst[0], im.src[0], im.others[0]))
356
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
30 self.add_lowering(Sub1, lambda im: Sub1(im.dst[0], im.src[0], im.src[1]))
354
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 352
diff changeset
31 self.add_lowering(Mul1, lambda im: Mul1(im.dst[0], im.src[0], im.src[1]))
356
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
32 self.add_lowering(Lsr1, lambda im: Lsr1(im.dst[0], im.src[0], im.src[1]))
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
33 self.add_lowering(And1, lambda im: And1(im.dst[0], im.src[0], im.src[1]))
357
818be710e13d Added acceptance function to burg
Windel Bouwman
parents: 356
diff changeset
34 self.add_lowering(Mov1, lambda im: Mov1(im.dst[0], im.others[0]))
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
35
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
36 def make_parser(self):
342
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
37 # Assembly grammar:
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
38 self.add_keyword('r0')
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
39 self.add_keyword('r1')
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
40 self.add_keyword('r2')
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
41 self.add_keyword('r3')
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
42 self.add_keyword('r4')
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
43 self.add_keyword('r5')
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
44 self.add_keyword('r6')
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
45 self.add_keyword('r7')
345
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
46 self.add_keyword('r8')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
47 self.add_keyword('r9')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
48 self.add_keyword('r10')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
49 self.add_keyword('r11')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
50 self.add_keyword('r12')
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
51 self.add_keyword('sp')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
52 self.add_keyword('lr')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
53 self.add_keyword('pc')
342
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
54
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
55 self.add_rule('reg', ['r0'], lambda rhs: R0)
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
56 self.add_rule('reg', ['r1'], lambda rhs: R1)
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
57 self.add_rule('reg', ['r2'], lambda rhs: R2)
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
58 self.add_rule('reg', ['r3'], lambda rhs: R3)
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
59 self.add_rule('reg', ['r4'], lambda rhs: R4)
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
60 self.add_rule('reg', ['r5'], lambda rhs: R5)
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
61 self.add_rule('reg', ['r6'], lambda rhs: R6)
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
62 self.add_rule('reg', ['r7'], lambda rhs: R7)
345
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
63 self.add_rule('reg', ['r8'], lambda rhs: R8)
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
64 self.add_rule('reg', ['r9'], lambda rhs: R9)
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
65 self.add_rule('reg', ['r10'], lambda rhs: R10)
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
66 self.add_rule('reg', ['r11'], lambda rhs: R11)
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
67 self.add_rule('reg', ['r12'], lambda rhs: R12)
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
68 self.add_rule('reg', ['sp'], lambda rhs: SP)
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
69 self.add_rule('reg', ['lr'], lambda rhs: LR)
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
70 self.add_rule('reg', ['pc'], lambda rhs: PC)
342
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
71
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
72 self.add_keyword('dcd')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
73 self.add_instruction(['dcd', 'imm32'],
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
74 lambda rhs: Dcd(rhs[1]))
342
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
75
345
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
76 self.add_keyword('mov')
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
77 self.add_instruction(['mov', 'reg', ',', 'imm32'],
342
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
78 lambda rhs: Mov(rhs[1], rhs[3]))
362
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
79 self.add_instruction(['mov', 'reg', ',', 'reg'],
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
80 lambda rhs: Mov(rhs[1], rhs[3]))
342
86b02c98a717 Moved target directory
Windel Bouwman
parents:
diff changeset
81
352
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 350
diff changeset
82 self.add_keyword('cmp')
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 350
diff changeset
83 self.add_instruction(['cmp', 'reg', ',', 'imm32'],
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 350
diff changeset
84 lambda rhs: Cmp(rhs[1], rhs[3]))
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 350
diff changeset
85 self.add_instruction(['cmp', 'reg', ',', 'reg'],
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 350
diff changeset
86 lambda rhs: Cmp(rhs[1], rhs[3]))
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 350
diff changeset
87
899ae3aea803 First kernel run for vexpressA9
Windel Bouwman
parents: 350
diff changeset
88 # Arithmatic:
345
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
89 self.add_keyword('add')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
90 self.add_instruction(['add', 'reg', ',', 'reg', ',', 'imm32'],
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
91 lambda rhs: Add(rhs[1], rhs[3], rhs[5]))
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
92
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
93 self.add_instruction(['add', 'reg', ',', 'reg', ',', 'reg'],
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
94 lambda rhs: Add(rhs[1], rhs[3], rhs[5]))
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
95
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
96 self.add_keyword('sub')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
97 self.add_instruction(['sub', 'reg', ',', 'reg', ',', 'imm32'],
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
98 lambda rhs: Sub(rhs[1], rhs[3], rhs[5]))
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
99
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
100 self.add_instruction(['sub', 'reg', ',', 'reg', ',', 'reg'],
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
101 lambda rhs: Sub(rhs[1], rhs[3], rhs[5]))
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
102
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
103 self.add_keyword('mul')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
104 self.add_instruction(['mul', 'reg', ',', 'reg', ',', 'reg'],
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
105 lambda rhs: Mul(rhs[1], rhs[3], rhs[5]))
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
106
345
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
107 self.add_keyword('orr')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
108 self.add_instruction(['orr', 'reg', ',', 'reg', ',', 'reg'],
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
109 lambda rhs: Orr1(rhs[1], rhs[3], rhs[5]))
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
110
356
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
111 self.add_keyword('and')
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
112 self.add_instruction(['and', 'reg', ',', 'reg', ',', 'reg'],
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
113 lambda rhs: And1(rhs[1], rhs[3], rhs[5]))
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
114
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
115 self.add_keyword('lsr')
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
116 self.add_instruction(['lsr', 'reg', ',', 'reg', ',', 'reg'],
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
117 lambda rhs: Lsr1(rhs[1], rhs[3], rhs[5]))
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
118
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
119 self.add_keyword('lsl')
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
120 self.add_instruction(['lsl', 'reg', ',', 'reg', ',', 'reg'],
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
121 lambda rhs: Lsl1(rhs[1], rhs[3], rhs[5]))
52492b304adf Added newline to print
Windel Bouwman
parents: 354
diff changeset
122
345
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
123
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
124 # Jumping:
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
125 self.add_keyword('b')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
126 self.add_instruction(['b', 'ID'], lambda rhs: B(rhs[1].val))
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
127 self.add_keyword('ble')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
128 self.add_instruction(['ble', 'ID'], lambda rhs: Ble(rhs[1].val))
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
129 self.add_keyword('bgt')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
130 self.add_instruction(['bgt', 'ID'], lambda rhs: Bgt(rhs[1].val))
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
131 self.add_keyword('beq')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
132 self.add_instruction(['beq', 'ID'], lambda rhs: Beq(rhs[1].val))
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
133 self.add_keyword('blt')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
134 self.add_instruction(['blt', 'ID'], lambda rhs: Blt(rhs[1].val))
345
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
135
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
136 self.add_keyword('bl')
b4882ff0ed06 Added more arm isa tests
Windel Bouwman
parents: 342
diff changeset
137 self.add_instruction(['bl', 'ID'], lambda rhs: Bl(rhs[1].val))
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
138
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
139 # memory:
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
140 self.add_keyword('pop')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
141 self.add_instruction(['pop', 'reg_list'], lambda rhs: Pop(rhs[1]))
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
142
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
143 self.add_keyword('push')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
144 self.add_instruction(['push', 'reg_list'], lambda rhs: Push(rhs[1]))
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
145
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
146 self.add_keyword('ldr')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
147 self.add_instruction(['ldr', 'reg', ',', '[', 'reg', ',', 'imm8', ']'],
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
148 lambda rhs: Ldr(rhs[1], rhs[4], rhs[6]))
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
149
350
2b02bd286fe9 Fixed A9 hello worle
Windel Bouwman
parents: 346
diff changeset
150 self.add_instruction(['ldr', 'reg', ',', 'ID'],
2b02bd286fe9 Fixed A9 hello worle
Windel Bouwman
parents: 346
diff changeset
151 lambda rhs: Ldr(rhs[1], rhs[3].val))
2b02bd286fe9 Fixed A9 hello worle
Windel Bouwman
parents: 346
diff changeset
152
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
153 self.add_keyword('str')
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
154 self.add_instruction(['str', 'reg', ',', '[', 'reg', ',', 'imm8', ']'],
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
155 lambda rhs: Str(rhs[1], rhs[4], rhs[6]))
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
156
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
157 self.add_instruction(['str', 'reg', ',', '[', 'reg', ',', 'reg', ']'],
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
158 lambda rhs: Str(rhs[1], rhs[4], rhs[6]))
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
159
354
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 352
diff changeset
160 self.add_keyword('adr')
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 352
diff changeset
161 self.add_instruction(['adr', 'reg', ',', 'ID'],
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 352
diff changeset
162 lambda rhs: Adr(rhs[1], rhs[3].val))
5477e499b039 Added some sort of string functionality
Windel Bouwman
parents: 352
diff changeset
163
346
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
164 # Register list grammar:
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
165 self.add_rule('reg_list', ['{', 'reg_list_inner', '}'],
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
166 lambda rhs: rhs[1])
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
167 self.add_rule('reg_list_inner', ['reg_or_range'],
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
168 lambda rhs: rhs[0])
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
169 self.add_rule('reg_list_inner', ['reg_or_range', ',', 'reg_list_inner'],
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
170 lambda rhs: rhs[0] | rhs[2])
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
171 self.add_rule('reg_or_range', ['reg'], lambda rhs: {rhs[0]})
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
172
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
173 self.add_rule('reg_or_range', ['reg', '-', 'reg'],
3bb7dcfe5529 expanded arm target
Windel Bouwman
parents: 345
diff changeset
174 lambda rhs: register_range(rhs[0], rhs[2]))
362
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
175
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
176 # Add MCR and MRC (co-processor)
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
177 for i in range(16):
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
178 creg = 'c{}'.format(i)
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
179 self.add_keyword(creg)
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
180 self.add_rule('coreg', [creg], i)
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
181
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
182 for i in range(8, 16):
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
183 px = 'p{}'.format(i)
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
184 self.add_keyword(px)
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
185 # Ran into trouble when using i inside lambda function:
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
186 # When using inside lambda (as a closure), i is bound to the latest
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
187 # value (15)
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
188 self.add_rule('coproc', [px], i)
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
189
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
190 self.add_keyword('mcr')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
191 self.add_instruction(['mcr', 'coproc', ',', 'imm3', ',', 'reg', ',', 'coreg', ',', 'coreg', ',', 'imm3'],
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
192 lambda rhs: Mcr(rhs[1], rhs[3], rhs[5], rhs[7], rhs[9], rhs[11]))
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
193
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
194 self.add_keyword('mrc')
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
195 self.add_instruction(['mrc', 'coproc', ',', 'imm3', ',', 'reg', ',', 'coreg', ',', 'coreg', ',', 'imm3'],
c05ab629976a Added CPUID for arm
Windel Bouwman
parents: 359
diff changeset
196 lambda rhs: Mrc(rhs[1], rhs[3], rhs[5], rhs[7], rhs[9], rhs[11]))