| 1 |
5 |
sergeykhbr |
/*
|
| 2 |
|
|
* Copyright 2018 Sergey Khabarov, sergeykhbr@gmail.com
|
| 3 |
|
|
*
|
| 4 |
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
|
|
* you may not use this file except in compliance with the License.
|
| 6 |
|
|
* You may obtain a copy of the License at
|
| 7 |
|
|
*
|
| 8 |
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
|
|
*
|
| 10 |
|
|
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
|
|
* See the License for the specific language governing permissions and
|
| 14 |
|
|
* limitations under the License.
|
| 15 |
|
|
*/
|
| 16 |
|
|
|
| 17 |
|
|
#ifndef __DEBUGGER_SRC_CPU_ARM_PLUGIN_INSTRUCTIONS_H__
|
| 18 |
|
|
#define __DEBUGGER_SRC_CPU_ARM_PLUGIN_INSTRUCTIONS_H__
|
| 19 |
|
|
|
| 20 |
|
|
#include <inttypes.h>
|
| 21 |
|
|
#include "generic/cpu_generic.h"
|
| 22 |
|
|
|
| 23 |
|
|
namespace debugger {
|
| 24 |
|
|
|
| 25 |
|
|
class CpuCortex_Functional;
|
| 26 |
|
|
|
| 27 |
|
|
class ArmInstruction : public GenericInstruction {
|
| 28 |
|
|
public:
|
| 29 |
|
|
ArmInstruction(CpuCortex_Functional *icpu, const char *name,
|
| 30 |
|
|
const char *bits);
|
| 31 |
|
|
|
| 32 |
|
|
// IInstruction interface:
|
| 33 |
|
|
virtual const char *name() { return name_.to_string(); }
|
| 34 |
|
|
virtual int exec(Reg64Type *payload);
|
| 35 |
|
|
|
| 36 |
|
|
/** conditions return true */
|
| 37 |
|
|
virtual int exec_checked(Reg64Type *payload) = 0;
|
| 38 |
|
|
|
| 39 |
|
|
|
| 40 |
|
|
virtual bool parse(uint32_t *payload) {
|
| 41 |
|
|
return ((payload[0] & mask_) == opcode_);
|
| 42 |
|
|
}
|
| 43 |
|
|
|
| 44 |
|
|
virtual uint32_t hash() {
|
| 45 |
|
|
return (opcode_ >> 24) & 0xF;
|
| 46 |
|
|
}
|
| 47 |
|
|
|
| 48 |
|
|
virtual bool check_cond(uint32_t cond);
|
| 49 |
|
|
|
| 50 |
|
|
virtual uint32_t shift12(DataProcessingType::reg_bits_type instr,
|
| 51 |
|
|
uint32_t reg, uint64_t Rs);
|
| 52 |
|
|
|
| 53 |
|
|
virtual uint32_t imm12(DataProcessingType::imm_bits_type instr);
|
| 54 |
|
|
|
| 55 |
|
|
protected:
|
| 56 |
|
|
virtual IFace *getInterface(const char *name);
|
| 57 |
|
|
|
| 58 |
|
|
protected:
|
| 59 |
|
|
AttributeType name_;
|
| 60 |
|
|
CpuCortex_Functional *icpu_;
|
| 61 |
|
|
Axi4TransactionType trans_;
|
| 62 |
|
|
uint32_t mask_;
|
| 63 |
|
|
uint32_t opcode_;
|
| 64 |
|
|
uint64_t *R;
|
| 65 |
|
|
};
|
| 66 |
|
|
|
| 67 |
|
|
/** opcodes:
|
| 68 |
|
|
0000 = AND - Rd:= Op1 AND Op2
|
| 69 |
|
|
0001 = EOR - Rd:= Op1 EOR Op2
|
| 70 |
|
|
0010 = SUB - Rd:= Op1 - Op2
|
| 71 |
|
|
0011 = RSB - Rd:= Op2 - Op1
|
| 72 |
|
|
0100 = ADD - Rd:= Op1 + Op2
|
| 73 |
|
|
0101 = ADC - Rd:= Op1 + Op2 + C
|
| 74 |
|
|
0110 = SBC - Rd:= Op1 - Op2 + C
|
| 75 |
|
|
0111 = RSC - Rd:= Op2 - Op1 + C
|
| 76 |
|
|
1000 = TST - set condition codes on Op1 AND Op2
|
| 77 |
|
|
1001 = TEQ - set condition codes on Op1 EOR Op2
|
| 78 |
|
|
1010 = CMP - set condition codes on Op1 - Op2
|
| 79 |
|
|
1011 = CMN - set condition codes on Op1 + Op2
|
| 80 |
|
|
1100 = ORR - Rd:= Op1 OR Op2
|
| 81 |
|
|
1101 = MOV - Rd:= Op2
|
| 82 |
|
|
1110 = BIC - Rd:= Op1 AND NOT Op2
|
| 83 |
|
|
1111 = MVN - Rd:= NOT Op2
|
| 84 |
|
|
*/
|
| 85 |
|
|
class ArmDataProcessingInstruction : public ArmInstruction {
|
| 86 |
|
|
public:
|
| 87 |
|
|
ArmDataProcessingInstruction(CpuCortex_Functional *icpu, const char *name,
|
| 88 |
|
|
const char *bits) : ArmInstruction(icpu, name, bits) {}
|
| 89 |
|
|
|
| 90 |
|
|
virtual int exec_checked(Reg64Type *payload);
|
| 91 |
|
|
protected:
|
| 92 |
|
|
enum EOperationResult {
|
| 93 |
|
|
OP_Drop,
|
| 94 |
|
|
OP_Write
|
| 95 |
|
|
};
|
| 96 |
|
|
|
| 97 |
|
|
/** Return true if need to write result into Rd register */
|
| 98 |
|
|
virtual EOperationResult do_operation(uint32_t A, uint32_t M,
|
| 99 |
|
|
uint32_t *pRes) = 0;
|
| 100 |
|
|
virtual bool is_flags_changed(DataProcessingType u);
|
| 101 |
|
|
virtual void set_flags(uint32_t A, uint32_t M, uint32_t Res);
|
| 102 |
|
|
};
|
| 103 |
|
|
|
| 104 |
|
|
} // namespace debugger
|
| 105 |
|
|
|
| 106 |
|
|
#endif // __DEBUGGER_SRC_CPU_ARM_PLUGIN_INSTRUCTIONS_H__
|