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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [cpu_arm_plugin/] [cpu_arm7_func.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_core.h>
18
#include "cpu_arm7_func.h"
19
 
20
namespace debugger {
21
 
22
CpuCortex_Functional::CpuCortex_Functional(const char *name) :
23
    CpuGeneric(name),
24
    portRegs_(this, "regs", 0x8000, Reg_Total),
25
    portSavedRegs_(this, "savedregs", 0, Reg_Total) {
26
    registerInterface(static_cast<ICpuArm *>(this));
27
    registerAttribute("VectorTable", &vectorTable_);
28
    p_psr_ = reinterpret_cast<ProgramStatusRegsiterType *>(
29
            &portRegs_.getp()[Reg_cpsr]);
30
}
31
 
32
CpuCortex_Functional::~CpuCortex_Functional() {
33
}
34
 
35
void CpuCortex_Functional::postinitService() {
36
    // Supported instruction sets:
37
    for (int i = 0; i < INSTR_HASH_TABLE_SIZE; i++) {
38
        listInstr_[i].make_list(0);
39
    }
40
    addArm7tmdiIsa();
41
 
42
    // Power-on
43
    reset(false);
44
 
45
    CpuGeneric::postinitService();
46
}
47
 
48
unsigned CpuCortex_Functional::addSupportedInstruction(
49
                                    ArmInstruction *instr) {
50
    AttributeType tmp(instr);
51
    listInstr_[instr->hash()].add_to_list(&tmp);
52
    return 0;
53
}
54
 
55
void CpuCortex_Functional::handleTrap() {
56
    if (interrupt_pending_ == 0) {
57
        return;
58
    }
59
    npc_.setValue(0 + 4*0);
60
    interrupt_pending_ = 0;
61
}
62
 
63
void CpuCortex_Functional::reset(bool active) {
64
    CpuGeneric::reset(active);
65
    portRegs_.reset();
66
    estate_ = CORE_Halted;
67
}
68
 
69
GenericInstruction *CpuCortex_Functional::decodeInstruction(Reg64Type *cache) {
70
    ArmInstruction *instr = NULL;
71
    int hash_idx = hash32(cacheline_[0].buf32[0]);
72
    for (unsigned i = 0; i < listInstr_[hash_idx].size(); i++) {
73
        instr = static_cast<ArmInstruction *>(
74
                        listInstr_[hash_idx][i].to_iface());
75
        if (instr->parse(cacheline_[0].buf32)) {
76
            break;
77
        }
78
        instr = NULL;
79
    }
80
    portRegs_.getp()[Reg_pc].val = getPC();
81
    return instr;
82
}
83
 
84
void CpuCortex_Functional::generateIllegalOpcode() {
85
    //raiseSignal(EXCEPTION_InstrIllegal);
86
    RISCV_error("Illegal instruction at 0x%08" RV_PRI64 "x", getPC());
87
}
88
 
89
void CpuCortex_Functional::trackContextStart() {
90
    if (reg_trace_file == 0) {
91
        return;
92
    }
93
    /** Save previous reg values to find modification after exec() */
94
    uint64_t *dst = portSavedRegs_.getpR64();
95
    uint64_t *src = portRegs_.getpR64();
96
    memcpy(dst, src, Reg_Total*sizeof(uint64_t));
97
}
98
 
99
void CpuCortex_Functional::trackContextEnd() {
100
    if (reg_trace_file == 0) {
101
        return;
102
    }
103
    int sz;
104
    char tstr[1024];
105
    const char *pinstrname = "unknown";
106
    if (instr_) {
107
        pinstrname = instr_->name();
108
    }
109
    sz = RISCV_sprintf(tstr, sizeof(tstr),"%8I64d [%08x]: %8s ",
110
        step_cnt_, pc_.getValue().buf32[0],
111
        pinstrname);
112
 
113
    bool reg_changed = false;
114
    uint64_t *prev = portSavedRegs_.getpR64();
115
    uint64_t *cur = portRegs_.getpR64();
116
    for (int i = 0; i < Reg_Total; i++) {
117
        if (prev[i] != cur[i]) {
118
            reg_changed = true;
119
            sz += RISCV_sprintf(&tstr[sz], sizeof(tstr) - sz,
120
                    "%3s <= %016I64x ",
121
                    IREGS_NAMES[i], cur[i]);
122
        }
123
    }
124
    if (instr_ && !reg_changed) {
125
        sz += RISCV_sprintf(&tstr[sz], sizeof(tstr) - sz, "-", NULL);
126
    }
127
    (*reg_trace_file) << tstr << "\n";
128
    reg_trace_file->flush();
129
}
130
 
131
void CpuCortex_Functional::raiseSignal(int idx) {
132
    RISCV_error("Raise unsupported signal %d", idx);
133
}
134
 
135
void CpuCortex_Functional::lowerSignal(int idx) {
136
    interrupt_pending_ &= ~(1 << idx);
137
    RISCV_error("Lower unsupported signal %d", idx);
138
}
139
 
140
}  // namespace debugger
141
 

powered by: WebSVN 2.1.0

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