blob: b9f31ff119ab563a65d1d649b377c52ebda3c8dd [file] [log] [blame]
Elliott Hughes606d4ae2015-11-05 18:55:20 +00001/* libs/pixelflinger/codeflinger/MIPS64Assembler.cpp
2**
3** Copyright 2015, The Android Open Source Project
4**
5** Licensed under the Apache License, Version 2.0 (the "License");
6** you may not use this file except in compliance with the License.
7** You may obtain a copy of the License at
8**
9** http://www.apache.org/licenses/LICENSE-2.0
10**
11** Unless required by applicable law or agreed to in writing, software
12** distributed under the License is distributed on an "AS IS" BASIS,
13** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14** See the License for the specific language governing permissions and
15** limitations under the License.
16*/
17
18
19/* MIPS64 assembler and ARM->MIPS64 assembly translator
20**
21** The approach is utilize MIPSAssembler generator, using inherited MIPS64Assembler
22** that overrides just the specific MIPS64r6 instructions.
23** For now ArmToMips64Assembler is copied over from ArmToMipsAssembler class,
24** changing some MIPS64r6 related stuff.
25**
26*/
27
28
29#define LOG_TAG "MIPS64Assembler"
30
31#include <stdio.h>
32#include <stdlib.h>
33#include <cutils/log.h>
34#include <cutils/properties.h>
35
Elliott Hughes606d4ae2015-11-05 18:55:20 +000036#include <private/pixelflinger/ggl_context.h>
37
38#include "MIPS64Assembler.h"
39#include "CodeCache.h"
40#include "mips64_disassem.h"
41
42
43#define NOT_IMPLEMENTED() LOG_ALWAYS_FATAL("Arm instruction %s not yet implemented\n", __func__)
44
45
46// ----------------------------------------------------------------------------
47
48namespace android {
49
50// ----------------------------------------------------------------------------
51#if 0
52#pragma mark -
53#pragma mark ArmToMips64Assembler...
54#endif
55
56ArmToMips64Assembler::ArmToMips64Assembler(const sp<Assembly>& assembly,
57 char *abuf, int linesz, int instr_count)
58 : ARMAssemblerInterface(),
59 mArmDisassemblyBuffer(abuf),
60 mArmLineLength(linesz),
61 mArmInstrCount(instr_count),
62 mInum(0),
63 mAssembly(assembly)
64{
65 mMips = new MIPS64Assembler(assembly, this);
66 mArmPC = (uint32_t **) malloc(ARM_MAX_INSTUCTIONS * sizeof(uint32_t *));
67 init_conditional_labels();
68}
69
70ArmToMips64Assembler::ArmToMips64Assembler(void* assembly)
71 : ARMAssemblerInterface(),
72 mArmDisassemblyBuffer(NULL),
73 mInum(0),
74 mAssembly(NULL)
75{
76 mMips = new MIPS64Assembler(assembly, this);
77 mArmPC = (uint32_t **) malloc(ARM_MAX_INSTUCTIONS * sizeof(uint32_t *));
78 init_conditional_labels();
79}
80
81ArmToMips64Assembler::~ArmToMips64Assembler()
82{
83 delete mMips;
84 free((void *) mArmPC);
85}
86
87uint32_t* ArmToMips64Assembler::pc() const
88{
89 return mMips->pc();
90}
91
92uint32_t* ArmToMips64Assembler::base() const
93{
94 return mMips->base();
95}
96
97void ArmToMips64Assembler::reset()
98{
99 cond.labelnum = 0;
100 mInum = 0;
101 mMips->reset();
102}
103
104int ArmToMips64Assembler::getCodegenArch()
105{
106 return CODEGEN_ARCH_MIPS64;
107}
108
109void ArmToMips64Assembler::comment(const char* string)
110{
111 mMips->comment(string);
112}
113
114void ArmToMips64Assembler::label(const char* theLabel)
115{
116 mMips->label(theLabel);
117}
118
119void ArmToMips64Assembler::disassemble(const char* name)
120{
121 mMips->disassemble(name);
122}
123
124void ArmToMips64Assembler::init_conditional_labels()
125{
126 int i;
127 for (i=0;i<99; ++i) {
128 sprintf(cond.label[i], "cond_%d", i);
129 }
130}
131
132
133
134#if 0
135#pragma mark -
136#pragma mark Prolog/Epilog & Generate...
137#endif
138
139void ArmToMips64Assembler::prolog()
140{
141 mArmPC[mInum++] = pc(); // save starting PC for this instr
142
143 mMips->DADDIU(R_sp, R_sp, -(5 * 8));
144 mMips->SD(R_s0, R_sp, 0);
145 mMips->SD(R_s1, R_sp, 8);
146 mMips->SD(R_s2, R_sp, 16);
147 mMips->SD(R_s3, R_sp, 24);
148 mMips->SD(R_s4, R_sp, 32);
149 mMips->MOVE(R_v0, R_a0); // move context * passed in a0 to v0 (arm r0)
150}
151
152void ArmToMips64Assembler::epilog(uint32_t touched)
153{
154 mArmPC[mInum++] = pc(); // save starting PC for this instr
155
156 mMips->LD(R_s0, R_sp, 0);
157 mMips->LD(R_s1, R_sp, 8);
158 mMips->LD(R_s2, R_sp, 16);
159 mMips->LD(R_s3, R_sp, 24);
160 mMips->LD(R_s4, R_sp, 32);
161 mMips->DADDIU(R_sp, R_sp, (5 * 8));
162 mMips->JR(R_ra);
163
164}
165
166int ArmToMips64Assembler::generate(const char* name)
167{
168 return mMips->generate(name);
169}
170
171void ArmToMips64Assembler::fix_branches()
172{
173 mMips->fix_branches();
174}
175
176uint32_t* ArmToMips64Assembler::pcForLabel(const char* label)
177{
178 return mMips->pcForLabel(label);
179}
180
181void ArmToMips64Assembler::set_condition(int mode, int R1, int R2) {
182 if (mode == 2) {
183 cond.type = SBIT_COND;
184 } else {
185 cond.type = CMP_COND;
186 }
187 cond.r1 = R1;
188 cond.r2 = R2;
189}
190
191//----------------------------------------------------------
192
193#if 0
194#pragma mark -
195#pragma mark Addressing modes & shifters...
196#endif
197
198
199// do not need this for MIPS, but it is in the Interface (virtual)
200int ArmToMips64Assembler::buildImmediate(
201 uint32_t immediate, uint32_t& rot, uint32_t& imm)
202{
203 // for MIPS, any 32-bit immediate is OK
204 rot = 0;
205 imm = immediate;
206 return 0;
207}
208
209// shifters...
210
211bool ArmToMips64Assembler::isValidImmediate(uint32_t immediate)
212{
213 // for MIPS, any 32-bit immediate is OK
214 return true;
215}
216
217uint32_t ArmToMips64Assembler::imm(uint32_t immediate)
218{
219 amode.value = immediate;
220 return AMODE_IMM;
221}
222
223uint32_t ArmToMips64Assembler::reg_imm(int Rm, int type, uint32_t shift)
224{
225 amode.reg = Rm;
226 amode.stype = type;
227 amode.value = shift;
228 return AMODE_REG_IMM;
229}
230
231uint32_t ArmToMips64Assembler::reg_rrx(int Rm)
232{
233 // reg_rrx mode is not used in the GLLAssember code at this time
234 return AMODE_UNSUPPORTED;
235}
236
237uint32_t ArmToMips64Assembler::reg_reg(int Rm, int type, int Rs)
238{
239 // reg_reg mode is not used in the GLLAssember code at this time
240 return AMODE_UNSUPPORTED;
241}
242
243
244// addressing modes...
245// LDR(B)/STR(B)/PLD (immediate and Rm can be negative, which indicate U=0)
246uint32_t ArmToMips64Assembler::immed12_pre(int32_t immed12, int W)
247{
248 LOG_ALWAYS_FATAL_IF(abs(immed12) >= 0x800,
249 "LDR(B)/STR(B)/PLD immediate too big (%08x)",
250 immed12);
251 amode.value = immed12;
252 amode.writeback = W;
253 return AMODE_IMM_12_PRE;
254}
255
256uint32_t ArmToMips64Assembler::immed12_post(int32_t immed12)
257{
258 LOG_ALWAYS_FATAL_IF(abs(immed12) >= 0x800,
259 "LDR(B)/STR(B)/PLD immediate too big (%08x)",
260 immed12);
261
262 amode.value = immed12;
263 return AMODE_IMM_12_POST;
264}
265
266uint32_t ArmToMips64Assembler::reg_scale_pre(int Rm, int type,
267 uint32_t shift, int W)
268{
269 LOG_ALWAYS_FATAL_IF(W | type | shift, "reg_scale_pre adv modes not yet implemented");
270
271 amode.reg = Rm;
272 // amode.stype = type; // more advanced modes not used in GGLAssembler yet
273 // amode.value = shift;
274 // amode.writeback = W;
275 return AMODE_REG_SCALE_PRE;
276}
277
278uint32_t ArmToMips64Assembler::reg_scale_post(int Rm, int type, uint32_t shift)
279{
280 LOG_ALWAYS_FATAL("adr mode reg_scale_post not yet implemented\n");
281 return AMODE_UNSUPPORTED;
282}
283
284// LDRH/LDRSB/LDRSH/STRH (immediate and Rm can be negative, which indicate U=0)
285uint32_t ArmToMips64Assembler::immed8_pre(int32_t immed8, int W)
286{
287 LOG_ALWAYS_FATAL("adr mode immed8_pre not yet implemented\n");
288
289 LOG_ALWAYS_FATAL_IF(abs(immed8) >= 0x100,
290 "LDRH/LDRSB/LDRSH/STRH immediate too big (%08x)",
291 immed8);
292 return AMODE_IMM_8_PRE;
293}
294
295uint32_t ArmToMips64Assembler::immed8_post(int32_t immed8)
296{
297 LOG_ALWAYS_FATAL_IF(abs(immed8) >= 0x100,
298 "LDRH/LDRSB/LDRSH/STRH immediate too big (%08x)",
299 immed8);
300 amode.value = immed8;
301 return AMODE_IMM_8_POST;
302}
303
304uint32_t ArmToMips64Assembler::reg_pre(int Rm, int W)
305{
306 LOG_ALWAYS_FATAL_IF(W, "reg_pre writeback not yet implemented");
307 amode.reg = Rm;
308 return AMODE_REG_PRE;
309}
310
311uint32_t ArmToMips64Assembler::reg_post(int Rm)
312{
313 LOG_ALWAYS_FATAL("adr mode reg_post not yet implemented\n");
314 return AMODE_UNSUPPORTED;
315}
316
317
318
319// ----------------------------------------------------------------------------
320
321#if 0
322#pragma mark -
323#pragma mark Data Processing...
324#endif
325
326
327static const char * const dpOpNames[] = {
328 "AND", "EOR", "SUB", "RSB", "ADD", "ADC", "SBC", "RSC",
329 "TST", "TEQ", "CMP", "CMN", "ORR", "MOV", "BIC", "MVN"
330};
331
332// check if the operand registers from a previous CMP or S-bit instruction
333// would be overwritten by this instruction. If so, move the value to a
334// safe register.
335// Note that we cannot tell at _this_ instruction time if a future (conditional)
336// instruction will _also_ use this value (a defect of the simple 1-pass, one-
337// instruction-at-a-time translation). Therefore we must be conservative and
338// save the value before it is overwritten. This costs an extra MOVE instr.
339
340void ArmToMips64Assembler::protectConditionalOperands(int Rd)
341{
342 if (Rd == cond.r1) {
343 mMips->MOVE(R_cmp, cond.r1);
344 cond.r1 = R_cmp;
345 }
346 if (cond.type == CMP_COND && Rd == cond.r2) {
347 mMips->MOVE(R_cmp2, cond.r2);
348 cond.r2 = R_cmp2;
349 }
350}
351
352
353// interprets the addressing mode, and generates the common code
354// used by the majority of data-processing ops. Many MIPS instructions
355// have a register-based form and a different immediate form. See
356// opAND below for an example. (this could be inlined)
357//
358// this works with the imm(), reg_imm() methods above, which are directly
359// called by the GLLAssembler.
360// note: _signed parameter defaults to false (un-signed)
361// note: tmpReg parameter defaults to 1, MIPS register AT
362int ArmToMips64Assembler::dataProcAdrModes(int op, int& source, bool _signed, int tmpReg)
363{
364 if (op < AMODE_REG) {
365 source = op;
366 return SRC_REG;
367 } else if (op == AMODE_IMM) {
368 if ((!_signed && amode.value > 0xffff)
369 || (_signed && ((int)amode.value < -32768 || (int)amode.value > 32767) )) {
370 mMips->LUI(tmpReg, (amode.value >> 16));
371 if (amode.value & 0x0000ffff) {
372 mMips->ORI(tmpReg, tmpReg, (amode.value & 0x0000ffff));
373 }
374 source = tmpReg;
375 return SRC_REG;
376 } else {
377 source = amode.value;
378 return SRC_IMM;
379 }
380 } else if (op == AMODE_REG_IMM) {
381 switch (amode.stype) {
382 case LSL: mMips->SLL(tmpReg, amode.reg, amode.value); break;
383 case LSR: mMips->SRL(tmpReg, amode.reg, amode.value); break;
384 case ASR: mMips->SRA(tmpReg, amode.reg, amode.value); break;
385 case ROR: mMips->ROTR(tmpReg, amode.reg, amode.value); break;
386 }
387 source = tmpReg;
388 return SRC_REG;
389 } else { // adr mode RRX is not used in GGL Assembler at this time
390 // we are screwed, this should be exception, assert-fail or something
391 LOG_ALWAYS_FATAL("adr mode reg_rrx not yet implemented\n");
392 return SRC_ERROR;
393 }
394}
395
396
397void ArmToMips64Assembler::dataProcessing(int opcode, int cc,
398 int s, int Rd, int Rn, uint32_t Op2)
399{
400 int src; // src is modified by dataProcAdrModes() - passed as int&
401
402 if (cc != AL) {
403 protectConditionalOperands(Rd);
404 // the branch tests register(s) set by prev CMP or instr with 'S' bit set
405 // inverse the condition to jump past this conditional instruction
406 ArmToMips64Assembler::B(cc^1, cond.label[++cond.labelnum]);
407 } else {
408 mArmPC[mInum++] = pc(); // save starting PC for this instr
409 }
410
411 switch (opcode) {
412 case opAND:
413 if (dataProcAdrModes(Op2, src) == SRC_REG) {
414 mMips->AND(Rd, Rn, src);
415 } else { // adr mode was SRC_IMM
416 mMips->ANDI(Rd, Rn, src);
417 }
418 break;
419
420 case opADD:
421 // set "signed" to true for adr modes
422 if (dataProcAdrModes(Op2, src, true) == SRC_REG) {
423 mMips->ADDU(Rd, Rn, src);
424 } else { // adr mode was SRC_IMM
425 mMips->ADDIU(Rd, Rn, src);
426 }
427 break;
428
429 case opSUB:
430 // set "signed" to true for adr modes
431 if (dataProcAdrModes(Op2, src, true) == SRC_REG) {
432 mMips->SUBU(Rd, Rn, src);
433 } else { // adr mode was SRC_IMM
434 mMips->SUBIU(Rd, Rn, src);
435 }
436 break;
437
438 case opADD64:
439 // set "signed" to true for adr modes
440 if (dataProcAdrModes(Op2, src, true) == SRC_REG) {
441 mMips->DADDU(Rd, Rn, src);
442 } else { // adr mode was SRC_IMM
443 mMips->DADDIU(Rd, Rn, src);
444 }
445 break;
446
447 case opSUB64:
448 // set "signed" to true for adr modes
449 if (dataProcAdrModes(Op2, src, true) == SRC_REG) {
450 mMips->DSUBU(Rd, Rn, src);
451 } else { // adr mode was SRC_IMM
452 mMips->DSUBIU(Rd, Rn, src);
453 }
454 break;
455
456 case opEOR:
457 if (dataProcAdrModes(Op2, src) == SRC_REG) {
458 mMips->XOR(Rd, Rn, src);
459 } else { // adr mode was SRC_IMM
460 mMips->XORI(Rd, Rn, src);
461 }
462 break;
463
464 case opORR:
465 if (dataProcAdrModes(Op2, src) == SRC_REG) {
466 mMips->OR(Rd, Rn, src);
467 } else { // adr mode was SRC_IMM
468 mMips->ORI(Rd, Rn, src);
469 }
470 break;
471
472 case opBIC:
473 if (dataProcAdrModes(Op2, src) == SRC_IMM) {
474 // if we are 16-bit imnmediate, load to AT reg
475 mMips->ORI(R_at, 0, src);
476 src = R_at;
477 }
478 mMips->NOT(R_at, src);
479 mMips->AND(Rd, Rn, R_at);
480 break;
481
482 case opRSB:
483 if (dataProcAdrModes(Op2, src) == SRC_IMM) {
484 // if we are 16-bit imnmediate, load to AT reg
485 mMips->ORI(R_at, 0, src);
486 src = R_at;
487 }
488 mMips->SUBU(Rd, src, Rn); // subu with the parameters reversed
489 break;
490
491 case opMOV:
492 if (Op2 < AMODE_REG) { // op2 is reg # in this case
493 mMips->MOVE(Rd, Op2);
494 } else if (Op2 == AMODE_IMM) {
495 if (amode.value > 0xffff) {
496 mMips->LUI(Rd, (amode.value >> 16));
497 if (amode.value & 0x0000ffff) {
498 mMips->ORI(Rd, Rd, (amode.value & 0x0000ffff));
499 }
500 } else {
501 mMips->ORI(Rd, 0, amode.value);
502 }
503 } else if (Op2 == AMODE_REG_IMM) {
504 switch (amode.stype) {
505 case LSL: mMips->SLL(Rd, amode.reg, amode.value); break;
506 case LSR: mMips->SRL(Rd, amode.reg, amode.value); break;
507 case ASR: mMips->SRA(Rd, amode.reg, amode.value); break;
508 case ROR: mMips->ROTR(Rd, amode.reg, amode.value); break;
509 }
510 }
511 else {
512 // adr mode RRX is not used in GGL Assembler at this time
513 mMips->UNIMPL();
514 }
515 break;
516
517 case opMVN: // this is a 1's complement: NOT
518 if (Op2 < AMODE_REG) { // op2 is reg # in this case
519 mMips->NOR(Rd, Op2, 0); // NOT is NOR with 0
520 break;
521 } else if (Op2 == AMODE_IMM) {
522 if (amode.value > 0xffff) {
523 mMips->LUI(Rd, (amode.value >> 16));
524 if (amode.value & 0x0000ffff) {
525 mMips->ORI(Rd, Rd, (amode.value & 0x0000ffff));
526 }
527 } else {
528 mMips->ORI(Rd, 0, amode.value);
529 }
530 } else if (Op2 == AMODE_REG_IMM) {
531 switch (amode.stype) {
532 case LSL: mMips->SLL(Rd, amode.reg, amode.value); break;
533 case LSR: mMips->SRL(Rd, amode.reg, amode.value); break;
534 case ASR: mMips->SRA(Rd, amode.reg, amode.value); break;
535 case ROR: mMips->ROTR(Rd, amode.reg, amode.value); break;
536 }
537 }
538 else {
539 // adr mode RRX is not used in GGL Assembler at this time
540 mMips->UNIMPL();
541 }
542 mMips->NOR(Rd, Rd, 0); // NOT is NOR with 0
543 break;
544
545 case opCMP:
546 // Either operand of a CMP instr could get overwritten by a subsequent
547 // conditional instruction, which is ok, _UNLESS_ there is a _second_
548 // conditional instruction. Under MIPS, this requires doing the comparison
549 // again (SLT), and the original operands must be available. (and this
550 // pattern of multiple conditional instructions from same CMP _is_ used
551 // in GGL-Assembler)
552 //
553 // For now, if a conditional instr overwrites the operands, we will
554 // move them to dedicated temp regs. This is ugly, and inefficient,
555 // and should be optimized.
556 //
557 // WARNING: making an _Assumption_ that CMP operand regs will NOT be
558 // trashed by intervening NON-conditional instructions. In the general
559 // case this is legal, but it is NOT currently done in GGL-Assembler.
560
561 cond.type = CMP_COND;
562 cond.r1 = Rn;
563 if (dataProcAdrModes(Op2, src, false, R_cmp2) == SRC_REG) {
564 cond.r2 = src;
565 } else { // adr mode was SRC_IMM
566 mMips->ORI(R_cmp2, R_zero, src);
567 cond.r2 = R_cmp2;
568 }
569
570 break;
571
572
573 case opTST:
574 case opTEQ:
575 case opCMN:
576 case opADC:
577 case opSBC:
578 case opRSC:
579 mMips->UNIMPL(); // currently unused in GGL Assembler code
580 break;
581 }
582
583 if (cc != AL) {
584 mMips->label(cond.label[cond.labelnum]);
585 }
586 if (s && opcode != opCMP) {
587 cond.type = SBIT_COND;
588 cond.r1 = Rd;
589 }
590}
591
592
593
594#if 0
595#pragma mark -
596#pragma mark Multiply...
597#endif
598
599// multiply, accumulate
600void ArmToMips64Assembler::MLA(int cc, int s,
601 int Rd, int Rm, int Rs, int Rn) {
602
603 //ALOGW("MLA");
604 mArmPC[mInum++] = pc(); // save starting PC for this instr
605
606 mMips->MUL(R_at, Rm, Rs);
607 mMips->ADDU(Rd, R_at, Rn);
608 if (s) {
609 cond.type = SBIT_COND;
610 cond.r1 = Rd;
611 }
612}
613
614void ArmToMips64Assembler::MUL(int cc, int s,
615 int Rd, int Rm, int Rs) {
616 mArmPC[mInum++] = pc();
617 mMips->MUL(Rd, Rm, Rs);
618 if (s) {
619 cond.type = SBIT_COND;
620 cond.r1 = Rd;
621 }
622}
623
624void ArmToMips64Assembler::UMULL(int cc, int s,
625 int RdLo, int RdHi, int Rm, int Rs) {
626 mArmPC[mInum++] = pc();
627 mMips->MUH(RdHi, Rm, Rs);
628 mMips->MUL(RdLo, Rm, Rs);
629
630 if (s) {
631 cond.type = SBIT_COND;
632 cond.r1 = RdHi; // BUG...
633 LOG_ALWAYS_FATAL("Condition on UMULL must be on 64-bit result\n");
634 }
635}
636
637void ArmToMips64Assembler::UMUAL(int cc, int s,
638 int RdLo, int RdHi, int Rm, int Rs) {
639 LOG_FATAL_IF(RdLo==Rm || RdHi==Rm || RdLo==RdHi,
640 "UMUAL(r%u,r%u,r%u,r%u)", RdLo,RdHi,Rm,Rs);
641 // *mPC++ = (cc<<28) | (1<<23) | (1<<21) | (s<<20) |
642 // (RdHi<<16) | (RdLo<<12) | (Rs<<8) | 0x90 | Rm;
643 mArmPC[mInum++] = pc();
644 mMips->NOP2();
645 NOT_IMPLEMENTED();
646 if (s) {
647 cond.type = SBIT_COND;
648 cond.r1 = RdHi; // BUG...
649 LOG_ALWAYS_FATAL("Condition on UMULL must be on 64-bit result\n");
650 }
651}
652
653void ArmToMips64Assembler::SMULL(int cc, int s,
654 int RdLo, int RdHi, int Rm, int Rs) {
655 LOG_FATAL_IF(RdLo==Rm || RdHi==Rm || RdLo==RdHi,
656 "SMULL(r%u,r%u,r%u,r%u)", RdLo,RdHi,Rm,Rs);
657 // *mPC++ = (cc<<28) | (1<<23) | (1<<22) | (s<<20) |
658 // (RdHi<<16) | (RdLo<<12) | (Rs<<8) | 0x90 | Rm;
659 mArmPC[mInum++] = pc();
660 mMips->NOP2();
661 NOT_IMPLEMENTED();
662 if (s) {
663 cond.type = SBIT_COND;
664 cond.r1 = RdHi; // BUG...
665 LOG_ALWAYS_FATAL("Condition on SMULL must be on 64-bit result\n");
666 }
667}
668void ArmToMips64Assembler::SMUAL(int cc, int s,
669 int RdLo, int RdHi, int Rm, int Rs) {
670 LOG_FATAL_IF(RdLo==Rm || RdHi==Rm || RdLo==RdHi,
671 "SMUAL(r%u,r%u,r%u,r%u)", RdLo,RdHi,Rm,Rs);
672 // *mPC++ = (cc<<28) | (1<<23) | (1<<22) | (1<<21) | (s<<20) |
673 // (RdHi<<16) | (RdLo<<12) | (Rs<<8) | 0x90 | Rm;
674 mArmPC[mInum++] = pc();
675 mMips->NOP2();
676 NOT_IMPLEMENTED();
677 if (s) {
678 cond.type = SBIT_COND;
679 cond.r1 = RdHi; // BUG...
680 LOG_ALWAYS_FATAL("Condition on SMUAL must be on 64-bit result\n");
681 }
682}
683
684
685
686#if 0
687#pragma mark -
688#pragma mark Branches...
689#endif
690
691// branches...
692
693void ArmToMips64Assembler::B(int cc, const char* label)
694{
695 mArmPC[mInum++] = pc();
696 if (cond.type == SBIT_COND) { cond.r2 = R_zero; }
697
698 switch(cc) {
699 case EQ: mMips->BEQ(cond.r1, cond.r2, label); break;
700 case NE: mMips->BNE(cond.r1, cond.r2, label); break;
701 case HS: mMips->BGEU(cond.r1, cond.r2, label); break;
702 case LO: mMips->BLTU(cond.r1, cond.r2, label); break;
703 case MI: mMips->BLT(cond.r1, cond.r2, label); break;
704 case PL: mMips->BGE(cond.r1, cond.r2, label); break;
705
706 case HI: mMips->BGTU(cond.r1, cond.r2, label); break;
707 case LS: mMips->BLEU(cond.r1, cond.r2, label); break;
708 case GE: mMips->BGE(cond.r1, cond.r2, label); break;
709 case LT: mMips->BLT(cond.r1, cond.r2, label); break;
710 case GT: mMips->BGT(cond.r1, cond.r2, label); break;
711 case LE: mMips->BLE(cond.r1, cond.r2, label); break;
712 case AL: mMips->B(label); break;
713 case NV: /* B Never - no instruction */ break;
714
715 case VS:
716 case VC:
717 default:
718 LOG_ALWAYS_FATAL("Unsupported cc: %02x\n", cc);
719 break;
720 }
721}
722
723void ArmToMips64Assembler::BL(int cc, const char* label)
724{
725 LOG_ALWAYS_FATAL("branch-and-link not supported yet\n");
726 mArmPC[mInum++] = pc();
727}
728
729// no use for Branches with integer PC, but they're in the Interface class ....
730void ArmToMips64Assembler::B(int cc, uint32_t* to_pc)
731{
732 LOG_ALWAYS_FATAL("branch to absolute PC not supported, use Label\n");
733 mArmPC[mInum++] = pc();
734}
735
736void ArmToMips64Assembler::BL(int cc, uint32_t* to_pc)
737{
738 LOG_ALWAYS_FATAL("branch to absolute PC not supported, use Label\n");
739 mArmPC[mInum++] = pc();
740}
741
742void ArmToMips64Assembler::BX(int cc, int Rn)
743{
744 LOG_ALWAYS_FATAL("branch to absolute PC not supported, use Label\n");
745 mArmPC[mInum++] = pc();
746}
747
748
749
750#if 0
751#pragma mark -
752#pragma mark Data Transfer...
753#endif
754
755// data transfer...
756void ArmToMips64Assembler::LDR(int cc, int Rd, int Rn, uint32_t offset)
757{
758 mArmPC[mInum++] = pc();
759 // work-around for ARM default address mode of immed12_pre(0)
760 if (offset > AMODE_UNSUPPORTED) offset = 0;
761 switch (offset) {
762 case 0:
763 amode.value = 0;
764 amode.writeback = 0;
765 // fall thru to next case ....
766 case AMODE_IMM_12_PRE:
767 if (Rn == ARMAssemblerInterface::SP) {
768 Rn = R_sp; // convert LDR via Arm SP to LW via Mips SP
769 }
770 mMips->LW(Rd, Rn, amode.value);
771 if (amode.writeback) { // OPTIONAL writeback on pre-index mode
772 mMips->DADDIU(Rn, Rn, amode.value);
773 }
774 break;
775 case AMODE_IMM_12_POST:
776 if (Rn == ARMAssemblerInterface::SP) {
777 Rn = R_sp; // convert STR thru Arm SP to STR thru Mips SP
778 }
779 mMips->LW(Rd, Rn, 0);
780 mMips->DADDIU(Rn, Rn, amode.value);
781 break;
782 case AMODE_REG_SCALE_PRE:
783 // we only support simple base + index, no advanced modes for this one yet
784 mMips->DADDU(R_at, Rn, amode.reg);
785 mMips->LW(Rd, R_at, 0);
786 break;
787 }
788}
789
790void ArmToMips64Assembler::LDRB(int cc, int Rd, int Rn, uint32_t offset)
791{
792 mArmPC[mInum++] = pc();
793 // work-around for ARM default address mode of immed12_pre(0)
794 if (offset > AMODE_UNSUPPORTED) offset = 0;
795 switch (offset) {
796 case 0:
797 amode.value = 0;
798 amode.writeback = 0;
799 // fall thru to next case ....
800 case AMODE_IMM_12_PRE:
801 mMips->LBU(Rd, Rn, amode.value);
802 if (amode.writeback) { // OPTIONAL writeback on pre-index mode
803 mMips->DADDIU(Rn, Rn, amode.value);
804 }
805 break;
806 case AMODE_IMM_12_POST:
807 mMips->LBU(Rd, Rn, 0);
808 mMips->DADDIU(Rn, Rn, amode.value);
809 break;
810 case AMODE_REG_SCALE_PRE:
811 // we only support simple base + index, no advanced modes for this one yet
812 mMips->DADDU(R_at, Rn, amode.reg);
813 mMips->LBU(Rd, R_at, 0);
814 break;
815 }
816
817}
818
819void ArmToMips64Assembler::STR(int cc, int Rd, int Rn, uint32_t offset)
820{
821 mArmPC[mInum++] = pc();
822 // work-around for ARM default address mode of immed12_pre(0)
823 if (offset > AMODE_UNSUPPORTED) offset = 0;
824 switch (offset) {
825 case 0:
826 amode.value = 0;
827 amode.writeback = 0;
828 // fall thru to next case ....
829 case AMODE_IMM_12_PRE:
830 if (Rn == ARMAssemblerInterface::SP) {
831 Rn = R_sp; // convert STR thru Arm SP to SW thru Mips SP
832 }
833 if (amode.writeback) { // OPTIONAL writeback on pre-index mode
834 // If we will writeback, then update the index reg, then store.
835 // This correctly handles stack-push case.
836 mMips->DADDIU(Rn, Rn, amode.value);
837 mMips->SW(Rd, Rn, 0);
838 } else {
839 // No writeback so store offset by value
840 mMips->SW(Rd, Rn, amode.value);
841 }
842 break;
843 case AMODE_IMM_12_POST:
844 mMips->SW(Rd, Rn, 0);
845 mMips->DADDIU(Rn, Rn, amode.value); // post index always writes back
846 break;
847 case AMODE_REG_SCALE_PRE:
848 // we only support simple base + index, no advanced modes for this one yet
849 mMips->DADDU(R_at, Rn, amode.reg);
850 mMips->SW(Rd, R_at, 0);
851 break;
852 }
853}
854
855void ArmToMips64Assembler::STRB(int cc, int Rd, int Rn, uint32_t offset)
856{
857 mArmPC[mInum++] = pc();
858 // work-around for ARM default address mode of immed12_pre(0)
859 if (offset > AMODE_UNSUPPORTED) offset = 0;
860 switch (offset) {
861 case 0:
862 amode.value = 0;
863 amode.writeback = 0;
864 // fall thru to next case ....
865 case AMODE_IMM_12_PRE:
866 mMips->SB(Rd, Rn, amode.value);
867 if (amode.writeback) { // OPTIONAL writeback on pre-index mode
868 mMips->DADDIU(Rn, Rn, amode.value);
869 }
870 break;
871 case AMODE_IMM_12_POST:
872 mMips->SB(Rd, Rn, 0);
873 mMips->DADDIU(Rn, Rn, amode.value);
874 break;
875 case AMODE_REG_SCALE_PRE:
876 // we only support simple base + index, no advanced modes for this one yet
877 mMips->DADDU(R_at, Rn, amode.reg);
878 mMips->SB(Rd, R_at, 0);
879 break;
880 }
881}
882
883void ArmToMips64Assembler::LDRH(int cc, int Rd, int Rn, uint32_t offset)
884{
885 mArmPC[mInum++] = pc();
886 // work-around for ARM default address mode of immed8_pre(0)
887 if (offset > AMODE_UNSUPPORTED) offset = 0;
888 switch (offset) {
889 case 0:
890 amode.value = 0;
891 // fall thru to next case ....
892 case AMODE_IMM_8_PRE: // no support yet for writeback
893 mMips->LHU(Rd, Rn, amode.value);
894 break;
895 case AMODE_IMM_8_POST:
896 mMips->LHU(Rd, Rn, 0);
897 mMips->DADDIU(Rn, Rn, amode.value);
898 break;
899 case AMODE_REG_PRE:
900 // we only support simple base +/- index
901 if (amode.reg >= 0) {
902 mMips->DADDU(R_at, Rn, amode.reg);
903 } else {
904 mMips->DSUBU(R_at, Rn, abs(amode.reg));
905 }
906 mMips->LHU(Rd, R_at, 0);
907 break;
908 }
909}
910
911void ArmToMips64Assembler::LDRSB(int cc, int Rd, int Rn, uint32_t offset)
912{
913 mArmPC[mInum++] = pc();
914 mMips->NOP2();
915 NOT_IMPLEMENTED();
916}
917
918void ArmToMips64Assembler::LDRSH(int cc, int Rd, int Rn, uint32_t offset)
919{
920 mArmPC[mInum++] = pc();
921 mMips->NOP2();
922 NOT_IMPLEMENTED();
923}
924
925void ArmToMips64Assembler::STRH(int cc, int Rd, int Rn, uint32_t offset)
926{
927 mArmPC[mInum++] = pc();
928 // work-around for ARM default address mode of immed8_pre(0)
929 if (offset > AMODE_UNSUPPORTED) offset = 0;
930 switch (offset) {
931 case 0:
932 amode.value = 0;
933 // fall thru to next case ....
934 case AMODE_IMM_8_PRE: // no support yet for writeback
935 mMips->SH(Rd, Rn, amode.value);
936 break;
937 case AMODE_IMM_8_POST:
938 mMips->SH(Rd, Rn, 0);
939 mMips->DADDIU(Rn, Rn, amode.value);
940 break;
941 case AMODE_REG_PRE:
942 // we only support simple base +/- index
943 if (amode.reg >= 0) {
944 mMips->DADDU(R_at, Rn, amode.reg);
945 } else {
946 mMips->DSUBU(R_at, Rn, abs(amode.reg));
947 }
948 mMips->SH(Rd, R_at, 0);
949 break;
950 }
951}
952
953
954
955#if 0
956#pragma mark -
957#pragma mark Block Data Transfer...
958#endif
959
960// block data transfer...
961void ArmToMips64Assembler::LDM(int cc, int dir,
962 int Rn, int W, uint32_t reg_list)
963{ // ED FD EA FA IB IA DB DA
964 // const uint8_t P[8] = { 1, 0, 1, 0, 1, 0, 1, 0 };
965 // const uint8_t U[8] = { 1, 1, 0, 0, 1, 1, 0, 0 };
966 // *mPC++ = (cc<<28) | (4<<25) | (uint32_t(P[dir])<<24) |
967 // (uint32_t(U[dir])<<23) | (1<<20) | (W<<21) | (Rn<<16) | reg_list;
968 mArmPC[mInum++] = pc();
969 mMips->NOP2();
970 NOT_IMPLEMENTED();
971}
972
973void ArmToMips64Assembler::STM(int cc, int dir,
974 int Rn, int W, uint32_t reg_list)
975{ // FA EA FD ED IB IA DB DA
976 // const uint8_t P[8] = { 0, 1, 0, 1, 1, 0, 1, 0 };
977 // const uint8_t U[8] = { 0, 0, 1, 1, 1, 1, 0, 0 };
978 // *mPC++ = (cc<<28) | (4<<25) | (uint32_t(P[dir])<<24) |
979 // (uint32_t(U[dir])<<23) | (0<<20) | (W<<21) | (Rn<<16) | reg_list;
980 mArmPC[mInum++] = pc();
981 mMips->NOP2();
982 NOT_IMPLEMENTED();
983}
984
985
986
987#if 0
988#pragma mark -
989#pragma mark Special...
990#endif
991
992// special...
993void ArmToMips64Assembler::SWP(int cc, int Rn, int Rd, int Rm) {
994 // *mPC++ = (cc<<28) | (2<<23) | (Rn<<16) | (Rd << 12) | 0x90 | Rm;
995 mArmPC[mInum++] = pc();
996 mMips->NOP2();
997 NOT_IMPLEMENTED();
998}
999
1000void ArmToMips64Assembler::SWPB(int cc, int Rn, int Rd, int Rm) {
1001 // *mPC++ = (cc<<28) | (2<<23) | (1<<22) | (Rn<<16) | (Rd << 12) | 0x90 | Rm;
1002 mArmPC[mInum++] = pc();
1003 mMips->NOP2();
1004 NOT_IMPLEMENTED();
1005}
1006
1007void ArmToMips64Assembler::SWI(int cc, uint32_t comment) {
1008 // *mPC++ = (cc<<28) | (0xF<<24) | comment;
1009 mArmPC[mInum++] = pc();
1010 mMips->NOP2();
1011 NOT_IMPLEMENTED();
1012}
1013
1014
1015#if 0
1016#pragma mark -
1017#pragma mark DSP instructions...
1018#endif
1019
1020// DSP instructions...
1021void ArmToMips64Assembler::PLD(int Rn, uint32_t offset) {
1022 LOG_ALWAYS_FATAL_IF(!((offset&(1<<24)) && !(offset&(1<<21))),
1023 "PLD only P=1, W=0");
1024 // *mPC++ = 0xF550F000 | (Rn<<16) | offset;
1025 mArmPC[mInum++] = pc();
1026 mMips->NOP2();
1027 NOT_IMPLEMENTED();
1028}
1029
1030void ArmToMips64Assembler::CLZ(int cc, int Rd, int Rm)
1031{
1032 mArmPC[mInum++] = pc();
1033 mMips->CLZ(Rd, Rm);
1034}
1035
1036void ArmToMips64Assembler::QADD(int cc, int Rd, int Rm, int Rn)
1037{
1038 // *mPC++ = (cc<<28) | 0x1000050 | (Rn<<16) | (Rd<<12) | Rm;
1039 mArmPC[mInum++] = pc();
1040 mMips->NOP2();
1041 NOT_IMPLEMENTED();
1042}
1043
1044void ArmToMips64Assembler::QDADD(int cc, int Rd, int Rm, int Rn)
1045{
1046 // *mPC++ = (cc<<28) | 0x1400050 | (Rn<<16) | (Rd<<12) | Rm;
1047 mArmPC[mInum++] = pc();
1048 mMips->NOP2();
1049 NOT_IMPLEMENTED();
1050}
1051
1052void ArmToMips64Assembler::QSUB(int cc, int Rd, int Rm, int Rn)
1053{
1054 // *mPC++ = (cc<<28) | 0x1200050 | (Rn<<16) | (Rd<<12) | Rm;
1055 mArmPC[mInum++] = pc();
1056 mMips->NOP2();
1057 NOT_IMPLEMENTED();
1058}
1059
1060void ArmToMips64Assembler::QDSUB(int cc, int Rd, int Rm, int Rn)
1061{
1062 // *mPC++ = (cc<<28) | 0x1600050 | (Rn<<16) | (Rd<<12) | Rm;
1063 mArmPC[mInum++] = pc();
1064 mMips->NOP2();
1065 NOT_IMPLEMENTED();
1066}
1067
1068// 16 x 16 signed multiply (like SMLAxx without the accumulate)
1069void ArmToMips64Assembler::SMUL(int cc, int xy,
1070 int Rd, int Rm, int Rs)
1071{
1072 mArmPC[mInum++] = pc();
1073
1074 // the 16 bits may be in the top or bottom half of 32-bit source reg,
1075 // as defined by the codes BB, BT, TB, TT (compressed param xy)
1076 // where x corresponds to Rm and y to Rs
1077
1078 // select half-reg for Rm
1079 if (xy & xyTB) {
1080 // use top 16-bits
1081 mMips->SRA(R_at, Rm, 16);
1082 } else {
1083 // use bottom 16, but sign-extend to 32
1084 mMips->SEH(R_at, Rm);
1085 }
1086 // select half-reg for Rs
1087 if (xy & xyBT) {
1088 // use top 16-bits
1089 mMips->SRA(R_at2, Rs, 16);
1090 } else {
1091 // use bottom 16, but sign-extend to 32
1092 mMips->SEH(R_at2, Rs);
1093 }
1094 mMips->MUL(Rd, R_at, R_at2);
1095}
1096
1097// signed 32b x 16b multiple, save top 32-bits of 48-bit result
1098void ArmToMips64Assembler::SMULW(int cc, int y,
1099 int Rd, int Rm, int Rs)
1100{
1101 mArmPC[mInum++] = pc();
1102
1103 // the selector yT or yB refers to reg Rs
1104 if (y & yT) {
1105 // zero the bottom 16-bits, with 2 shifts, it can affect result
1106 mMips->SRL(R_at, Rs, 16);
1107 mMips->SLL(R_at, R_at, 16);
1108
1109 } else {
1110 // move low 16-bit half, to high half
1111 mMips->SLL(R_at, Rs, 16);
1112 }
1113 mMips->MUH(Rd, Rm, R_at);
1114}
1115
1116// 16 x 16 signed multiply, accumulate: Rd = Rm{16} * Rs{16} + Rn
1117void ArmToMips64Assembler::SMLA(int cc, int xy,
1118 int Rd, int Rm, int Rs, int Rn)
1119{
1120 mArmPC[mInum++] = pc();
1121
1122 // the 16 bits may be in the top or bottom half of 32-bit source reg,
1123 // as defined by the codes BB, BT, TB, TT (compressed param xy)
1124 // where x corresponds to Rm and y to Rs
1125
1126 // select half-reg for Rm
1127 if (xy & xyTB) {
1128 // use top 16-bits
1129 mMips->SRA(R_at, Rm, 16);
1130 } else {
1131 // use bottom 16, but sign-extend to 32
1132 mMips->SEH(R_at, Rm);
1133 }
1134 // select half-reg for Rs
1135 if (xy & xyBT) {
1136 // use top 16-bits
1137 mMips->SRA(R_at2, Rs, 16);
1138 } else {
1139 // use bottom 16, but sign-extend to 32
1140 mMips->SEH(R_at2, Rs);
1141 }
1142
1143 mMips->MUL(R_at, R_at, R_at2);
1144 mMips->ADDU(Rd, R_at, Rn);
1145}
1146
1147void ArmToMips64Assembler::SMLAL(int cc, int xy,
1148 int RdHi, int RdLo, int Rs, int Rm)
1149{
1150 // *mPC++ = (cc<<28) | 0x1400080 | (RdHi<<16) | (RdLo<<12) | (Rs<<8) | (xy<<4) | Rm;
1151 mArmPC[mInum++] = pc();
1152 mMips->NOP2();
1153 NOT_IMPLEMENTED();
1154}
1155
1156void ArmToMips64Assembler::SMLAW(int cc, int y,
1157 int Rd, int Rm, int Rs, int Rn)
1158{
1159 // *mPC++ = (cc<<28) | 0x1200080 | (Rd<<16) | (Rn<<12) | (Rs<<8) | (y<<4) | Rm;
1160 mArmPC[mInum++] = pc();
1161 mMips->NOP2();
1162 NOT_IMPLEMENTED();
1163}
1164
1165// used by ARMv6 version of GGLAssembler::filter32
1166void ArmToMips64Assembler::UXTB16(int cc, int Rd, int Rm, int rotate)
1167{
1168 mArmPC[mInum++] = pc();
1169
1170 //Rd[31:16] := ZeroExtend((Rm ROR (8 * sh))[23:16]),
1171 //Rd[15:0] := ZeroExtend((Rm ROR (8 * sh))[7:0]). sh 0-3.
1172
1173 mMips->ROTR(R_at2, Rm, rotate * 8);
1174 mMips->LUI(R_at, 0xFF);
1175 mMips->ORI(R_at, R_at, 0xFF);
1176 mMips->AND(Rd, R_at2, R_at);
1177}
1178
1179void ArmToMips64Assembler::UBFX(int cc, int Rd, int Rn, int lsb, int width)
1180{
1181 /* Placeholder for UBFX */
1182 mArmPC[mInum++] = pc();
1183
1184 mMips->NOP2();
1185 NOT_IMPLEMENTED();
1186}
1187
1188// ----------------------------------------------------------------------------
1189// Address Processing...
1190// ----------------------------------------------------------------------------
1191
1192void ArmToMips64Assembler::ADDR_ADD(int cc,
1193 int s, int Rd, int Rn, uint32_t Op2)
1194{
1195// if(cc != AL){ NOT_IMPLEMENTED(); return;} //Not required
1196// if(s != 0) { NOT_IMPLEMENTED(); return;} //Not required
1197 dataProcessing(opADD64, cc, s, Rd, Rn, Op2);
1198}
1199
1200void ArmToMips64Assembler::ADDR_SUB(int cc,
1201 int s, int Rd, int Rn, uint32_t Op2)
1202{
1203// if(cc != AL){ NOT_IMPLEMENTED(); return;} //Not required
1204// if(s != 0) { NOT_IMPLEMENTED(); return;} //Not required
1205 dataProcessing(opSUB64, cc, s, Rd, Rn, Op2);
1206}
1207
1208void ArmToMips64Assembler::ADDR_LDR(int cc, int Rd, int Rn, uint32_t offset) {
1209 mArmPC[mInum++] = pc();
1210 // work-around for ARM default address mode of immed12_pre(0)
1211 if (offset > AMODE_UNSUPPORTED) offset = 0;
1212 switch (offset) {
1213 case 0:
1214 amode.value = 0;
1215 amode.writeback = 0;
1216 // fall thru to next case ....
1217 case AMODE_IMM_12_PRE:
1218 if (Rn == ARMAssemblerInterface::SP) {
1219 Rn = R_sp; // convert LDR via Arm SP to LW via Mips SP
1220 }
1221 mMips->LD(Rd, Rn, amode.value);
1222 if (amode.writeback) { // OPTIONAL writeback on pre-index mode
1223 mMips->DADDIU(Rn, Rn, amode.value);
1224 }
1225 break;
1226 case AMODE_IMM_12_POST:
1227 if (Rn == ARMAssemblerInterface::SP) {
1228 Rn = R_sp; // convert STR thru Arm SP to STR thru Mips SP
1229 }
1230 mMips->LD(Rd, Rn, 0);
1231 mMips->DADDIU(Rn, Rn, amode.value);
1232 break;
1233 case AMODE_REG_SCALE_PRE:
1234 // we only support simple base + index, no advanced modes for this one yet
1235 mMips->DADDU(R_at, Rn, amode.reg);
1236 mMips->LD(Rd, R_at, 0);
1237 break;
1238 }
1239}
1240
1241void ArmToMips64Assembler::ADDR_STR(int cc, int Rd, int Rn, uint32_t offset) {
1242 mArmPC[mInum++] = pc();
1243 // work-around for ARM default address mode of immed12_pre(0)
1244 if (offset > AMODE_UNSUPPORTED) offset = 0;
1245 switch (offset) {
1246 case 0:
1247 amode.value = 0;
1248 amode.writeback = 0;
1249 // fall thru to next case ....
1250 case AMODE_IMM_12_PRE:
1251 if (Rn == ARMAssemblerInterface::SP) {
1252 Rn = R_sp; // convert STR thru Arm SP to SW thru Mips SP
1253 }
1254 if (amode.writeback) { // OPTIONAL writeback on pre-index mode
1255 // If we will writeback, then update the index reg, then store.
1256 // This correctly handles stack-push case.
1257 mMips->DADDIU(Rn, Rn, amode.value);
1258 mMips->SD(Rd, Rn, 0);
1259 } else {
1260 // No writeback so store offset by value
1261 mMips->SD(Rd, Rn, amode.value);
1262 }
1263 break;
1264 case AMODE_IMM_12_POST:
1265 mMips->SD(Rd, Rn, 0);
1266 mMips->DADDIU(Rn, Rn, amode.value); // post index always writes back
1267 break;
1268 case AMODE_REG_SCALE_PRE:
1269 // we only support simple base + index, no advanced modes for this one yet
1270 mMips->DADDU(R_at, Rn, amode.reg);
1271 mMips->SD(Rd, R_at, 0);
1272 break;
1273 }
1274}
1275
1276#if 0
1277#pragma mark -
1278#pragma mark MIPS Assembler...
1279#endif
1280
1281
1282//**************************************************************************
1283//**************************************************************************
1284//**************************************************************************
1285
1286
1287/* MIPS64 assembler
1288** this is a subset of mips64r6, targeted specifically at ARM instruction
1289** replacement in the pixelflinger/codeflinger code.
1290**
1291** This class is extended from MIPSAssembler class and overrides only
1292** MIPS64r6 specific stuff.
1293*/
1294
1295MIPS64Assembler::MIPS64Assembler(const sp<Assembly>& assembly, ArmToMips64Assembler *parent)
1296 : mParent(parent),
1297 MIPSAssembler::MIPSAssembler(assembly, NULL)
1298{
1299}
1300
1301MIPS64Assembler::MIPS64Assembler(void* assembly, ArmToMips64Assembler *parent)
1302 : mParent(parent),
Ljubomir Papugae0c9f2b2015-12-15 15:23:01 +01001303 MIPSAssembler::MIPSAssembler(assembly)
Elliott Hughes606d4ae2015-11-05 18:55:20 +00001304{
Elliott Hughes606d4ae2015-11-05 18:55:20 +00001305}
1306
1307MIPS64Assembler::~MIPS64Assembler()
1308{
1309}
1310
1311void MIPS64Assembler::reset()
1312{
1313 if (mAssembly != NULL) {
1314 mBase = mPC = (uint32_t *)mAssembly->base();
1315 } else {
1316 mPC = mBase = base();
1317 }
1318 mBranchTargets.clear();
1319 mLabels.clear();
1320 mLabelsInverseMapping.clear();
1321 mComments.clear();
1322}
1323
1324
1325void MIPS64Assembler::disassemble(const char* name)
1326{
1327 char di_buf[140];
1328
1329 bool arm_disasm_fmt = (mParent->mArmDisassemblyBuffer == NULL) ? false : true;
1330
1331 typedef char dstr[40];
1332 dstr *lines = (dstr *)mParent->mArmDisassemblyBuffer;
1333
1334 if (mParent->mArmDisassemblyBuffer != NULL) {
1335 for (int i=0; i<mParent->mArmInstrCount; ++i) {
1336 string_detab(lines[i]);
1337 }
1338 }
1339
1340 // iArm is an index to Arm instructions 1...n for this assembly sequence
1341 // mArmPC[iArm] holds the value of the Mips-PC for the first MIPS
1342 // instruction corresponding to that Arm instruction number
1343
1344 int iArm = 0;
1345 size_t count = pc()-base();
1346 uint32_t* mipsPC = base();
1347
1348 while (count--) {
1349 ssize_t label = mLabelsInverseMapping.indexOfKey(mipsPC);
1350 if (label >= 0) {
1351 ALOGW("%s:\n", mLabelsInverseMapping.valueAt(label));
1352 }
1353 ssize_t comment = mComments.indexOfKey(mipsPC);
1354 if (comment >= 0) {
1355 ALOGW("; %s\n", mComments.valueAt(comment));
1356 }
1357 ::mips_disassem(mipsPC, di_buf, arm_disasm_fmt);
1358 string_detab(di_buf);
1359 string_pad(di_buf, 30);
1360 ALOGW("%08lx: %08x %s", uintptr_t(mipsPC), uint32_t(*mipsPC), di_buf);
1361 mipsPC++;
1362 }
1363}
1364
1365void MIPS64Assembler::fix_branches()
1366{
1367 // fixup all the branches
1368 size_t count = mBranchTargets.size();
1369 while (count--) {
1370 const branch_target_t& bt = mBranchTargets[count];
1371 uint32_t* target_pc = mLabels.valueFor(bt.label);
1372 LOG_ALWAYS_FATAL_IF(!target_pc,
1373 "error resolving branch targets, target_pc is null");
1374 int32_t offset = int32_t(target_pc - (bt.pc+1));
1375 *bt.pc |= offset & 0x00FFFF;
1376 }
1377}
1378
1379void MIPS64Assembler::DADDU(int Rd, int Rs, int Rt)
1380{
1381 *mPC++ = (spec_op<<OP_SHF) | (daddu_fn<<FUNC_SHF)
1382 | (Rs<<RS_SHF) | (Rt<<RT_SHF) | (Rd<<RD_SHF);
1383}
1384
1385void MIPS64Assembler::DADDIU(int Rt, int Rs, int16_t imm)
1386{
1387 *mPC++ = (daddiu_op<<OP_SHF) | (Rt<<RT_SHF) | (Rs<<RS_SHF) | (imm & MSK_16);
1388}
1389
1390void MIPS64Assembler::DSUBU(int Rd, int Rs, int Rt)
1391{
1392 *mPC++ = (spec_op<<OP_SHF) | (dsubu_fn<<FUNC_SHF) |
1393 (Rs<<RS_SHF) | (Rt<<RT_SHF) | (Rd<<RD_SHF) ;
1394}
1395
1396void MIPS64Assembler::DSUBIU(int Rt, int Rs, int16_t imm) // really addiu(d, s, -j)
1397{
1398 *mPC++ = (daddiu_op<<OP_SHF) | (Rt<<RT_SHF) | (Rs<<RS_SHF) | ((-imm) & MSK_16);
1399}
1400
1401void MIPS64Assembler::MUL(int Rd, int Rs, int Rt)
1402{
1403 *mPC++ = (spec_op<<OP_SHF) | (mul_fn<<RE_SHF) | (sop30_fn<<FUNC_SHF) |
1404 (Rs<<RS_SHF) | (Rt<<RT_SHF) | (Rd<<RD_SHF) ;
1405}
1406
1407void MIPS64Assembler::MUH(int Rd, int Rs, int Rt)
1408{
1409 *mPC++ = (spec_op<<OP_SHF) | (muh_fn<<RE_SHF) | (sop30_fn<<FUNC_SHF) |
1410 (Rs<<RS_SHF) | (Rt<<RT_SHF) | (Rd<<RD_SHF) ;
1411}
1412
1413void MIPS64Assembler::CLO(int Rd, int Rs)
1414{
1415 *mPC++ = (spec_op<<OP_SHF) | (17<<FUNC_SHF) |
1416 (Rd<<RD_SHF) | (Rs<<RS_SHF) | (1<<RE_SHF);
1417}
1418
1419void MIPS64Assembler::CLZ(int Rd, int Rs)
1420{
1421 *mPC++ = (spec_op<<OP_SHF) | (16<<FUNC_SHF) |
1422 (Rd<<RD_SHF) | (Rs<<RS_SHF) | (1<<RE_SHF);
1423}
1424
1425void MIPS64Assembler::LD(int Rt, int Rbase, int16_t offset)
1426{
1427 *mPC++ = (ld_op<<OP_SHF) | (Rbase<<RS_SHF) | (Rt<<RT_SHF) | (offset & MSK_16);
1428}
1429
1430void MIPS64Assembler::SD(int Rt, int Rbase, int16_t offset)
1431{
1432 *mPC++ = (sd_op<<OP_SHF) | (Rbase<<RS_SHF) | (Rt<<RT_SHF) | (offset & MSK_16);
1433}
1434
1435void MIPS64Assembler::LUI(int Rt, int16_t offset)
1436{
1437 *mPC++ = (aui_op<<OP_SHF) | (Rt<<RT_SHF) | (offset & MSK_16);
1438}
1439
1440
1441void MIPS64Assembler::JR(int Rs)
1442{
1443 *mPC++ = (spec_op<<OP_SHF) | (Rs<<RS_SHF) | (jalr_fn << FUNC_SHF);
1444 MIPS64Assembler::NOP();
1445}
1446
1447}; // namespace android: