History

arm-asm: Add push, pop

Also edited tcctok.h to not redefine push, pop

Danny Milosavljevic committed 5 years ago

Commit b4959591 parent c5428cd3 files · +64 −1Browse files

Unified · Split

3 files
  1. arm-asm.c +58 −0
  2. arm-tok.h +5 −0
  3. tcctok.h +1 −1
arm-asm.c+58−0
@@ -171,6 +171,61 @@ static void asm_nullary_opcode(int token) · 170 unmodified lines
171171 }
172172 }
173173
174+static void asm_block_data_transfer_opcode(TCCState *s1, int token)
175+{
176+ uint32_t opcode;
177+ int op0_exclam;
178+ Operand ops[2];
179+ int nb_ops = 1;
180+ parse_operand(s1, &ops[0]);
181+ if (tok == '!') {
182+ op0_exclam = 1;
183+ next(); // skip '!'
184+ }
185+ if (tok == ',') {
186+ next(); // skip comma
187+ parse_operand(s1, &ops[1]);
188+ ++nb_ops;
189+ }
190+ if (nb_ops < 1) {
191+ expect("at least one operand");
192+ return;
193+ } else if (ops[nb_ops - 1].type != OP_REGSET32) {
194+ expect("(last operand) register list");
195+ return;
196+ }
197+
198+ // block data transfer: 1 0 0 P U S W L << 20 (general case):
199+ // operands:
200+ // Rn: bits 19...16 base register
201+ // Register List: bits 15...0
202+
203+ switch (ARM_INSTRUCTION_GROUP(token)) {
204+ case TOK_ASM_pusheq: // TODO: Optimize 1-register case to: str ?, [sp, #-4]!
205+ // Instruction: 1 I=0 P=1 U=0 S=0 W=1 L=0 << 20, op 1101
206+ // operands:
207+ // Rn: base register
208+ // Register List: bits 15...0
209+ if (nb_ops != 1)
210+ expect("exactly one operand");
211+ else
212+ asm_emit_opcode(token, (0x92d << 16) | ops[0].regset); // TODO: base register ?
213+ break;
214+ case TOK_ASM_popeq: // TODO: Optimize 1-register case to: ldr ?, [sp], #4
215+ // Instruction: 1 I=0 P=0 U=1 S=0 W=0 L=1 << 20, op 1101
216+ // operands:
217+ // Rn: base register
218+ // Register List: bits 15...0
219+ if (nb_ops != 1)
220+ expect("exactly one operand");
221+ else
222+ asm_emit_opcode(token, (0x8bd << 16) | ops[0].regset); // TODO: base register ?
223+ break;
224+ default:
225+ expect("block data transfer instruction");
226+ }
227+}
228+
174229 ST_FUNC void asm_opcode(TCCState *s1, int token)
175230 {
176231 while (token == TOK_LINEFEED) {
@@ -185,6 +240,9 @@ ST_FUNC void asm_opcode(TCCState *s1, int token) · 8 unmodified lines
185240 }
186241
187242 switch (ARM_INSTRUCTION_GROUP(token)) {
243+ case TOK_ASM_pusheq:
244+ case TOK_ASM_popeq:
245+ return asm_block_data_transfer_opcode(s1, token);
188246 case TOK_ASM_nopeq:
189247 case TOK_ASM_wfeeq:
190248 case TOK_ASM_wfieq:
arm-tok.h+5−0
@@ -54,3 +54,8 @@ · 53 unmodified lines
5454 DEF_ASM_CONDED(nop)
5555 DEF_ASM_CONDED(wfe)
5656 DEF_ASM_CONDED(wfi)
57+
58+ /* instruction macros */
59+
60+ DEF_ASM_CONDED(push)
61+ DEF_ASM_CONDED(pop)
tcctok.h+1−1
@@ -171,7 +171,7 @@ · 170 unmodified lines
171171
172172 /* pragma */
173173 DEF(TOK_pack, "pack")
174−#if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_X86_64)
174+#if !defined(TCC_TARGET_I386) && !defined(TCC_TARGET_X86_64) && !defined(TCC_TARGET_ARM)
175175 /* already defined for assembler */
176176 DEF(TOK_ASM_push, "push")
177177 DEF(TOK_ASM_pop, "pop")

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t