OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [cpu_arm_plugin/] [instructions.cpp] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
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
#include "api_utils.h"
18
#include "arm-isa.h"
19
#include "instructions.h"
20
#include "cpu_arm7_func.h"
21
 
22
namespace debugger {
23
 
24
ArmInstruction::ArmInstruction(CpuCortex_Functional *icpu, const char *name,
25
                                    const char *bits) {
26
    icpu_ = icpu;
27
    R = icpu->getpRegs();
28
    name_.make_string(name);
29
    mask_ = 0;
30
    opcode_ = 0;
31
    for (int i = 0; i < 32; i++) {
32
        switch (bits[i]) {
33
        case '0':
34
            break;
35
        case '1':
36
            opcode_ |= (1 << (31 - i));
37
            break;
38
        case '?':
39
            mask_ |= (1 << (31 - i));
40
            break;
41
        default:;
42
        }
43
    }
44
    mask_ ^= ~0;
45
}
46
 
47
IFace *ArmInstruction::getInterface(const char *name) {
48
    return icpu_->getInterface(name);
49
}
50
 
51
int ArmInstruction::exec(Reg64Type *payload) {
52
#if 1
53
    if (icpu_->getPC() == 0xf24) {
54
        bool st = true;
55
    }
56
#endif
57
    if (check_cond(payload->buf32[0] >> 28)) {
58
        return exec_checked(payload);
59
    }
60
    return 4;
61
}
62
 
63
bool ArmInstruction::check_cond(uint32_t cond) {
64
    switch (cond) {
65
    case Cond_EQ:
66
        return icpu_->getZ() == 1;
67
    case Cond_NE:
68
        return icpu_->getZ() == 0;
69
    case Cond_CS:
70
        return icpu_->getC() == 1;
71
    case Cond_CC:
72
        return icpu_->getC() == 0;
73
    case Cond_MI:
74
        return icpu_->getN() == 1;
75
    case Cond_PL:
76
        return icpu_->getN() == 0;
77
    case Cond_VS:
78
        return icpu_->getV() == 1;
79
    case Cond_VC:
80
        return icpu_->getV() == 0;
81
    case Cond_HI:
82
        return icpu_->getC() && !icpu_->getZ();
83
    case Cond_LS:
84
        return !icpu_->getC() || icpu_->getZ();
85
    case Cond_GE:
86
        return !(icpu_->getN() ^ icpu_->getV());
87
    case Cond_LT:
88
        return (icpu_->getN() ^ icpu_->getV()) == 1;
89
    case Cond_GT:
90
        return !icpu_->getZ() && !(icpu_->getN() ^ icpu_->getV());
91
    case Cond_LE:
92
        return icpu_->getZ() || (icpu_->getN() ^ icpu_->getV());
93
    default:;
94
        return true;
95
    }
96
}
97
 
98
uint32_t ArmInstruction::shift12(DataProcessingType::reg_bits_type instr,
99
                                uint32_t reg, uint64_t Rs) {
100
    uint32_t ret = reg;
101
    uint32_t shift = instr.shift;
102
    if (instr.sh_sel) {
103
        shift = static_cast<uint32_t>(Rs & 0x1f);
104
    }
105
    switch (instr.sh_type) {
106
    case 0:     // logical left
107
        ret <<= shift;
108
        break;
109
    case 1:     // logical right
110
        ret >>= shift;
111
        break;
112
    case 2:     // arith. right
113
        ret =
114
            static_cast<uint32_t>((static_cast<int>(ret) >> shift));
115
        break;
116
    case 3:     // rotate right
117
        ret = (ret >> shift) | (ret << (32 - shift));
118
        break;
119
    }
120
    return ret;
121
}
122
 
123
uint32_t ArmInstruction::imm12(DataProcessingType::imm_bits_type instr) {
124
    uint32_t rsh = 2*instr.rotate;
125
    uint32_t imm = (instr.imm >> rsh) | (instr.imm << (32 - rsh));
126
    return imm;
127
}
128
 
129
}  // namespace debugger

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.