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

Subversion Repositories fwrisc

[/] [fwrisc/] [trunk/] [ve/] [fwrisc_fpga/] [tests/] [fwrisc_fpga_tests.cpp] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 mballance
/*
2
 * fwrisc_fpga_tests.cpp
3
 *
4
 *  Created on: Nov 21, 2018
5
 *      Author: ballance
6
 */
7
 
8
#include "fwrisc_fpga_tests.h"
9
#include "GoogletestVlCmdlineProcessor.h"
10
 
11
fwrisc_fpga_tests::fwrisc_fpga_tests() {
12
 
13
        m_led = [&](uint8_t led0, uint8_t led1) { };
14
 
15
}
16
 
17
fwrisc_fpga_tests::~fwrisc_fpga_tests() {
18
        // TODO Auto-generated destructor stub
19
}
20
 
21
void fwrisc_fpga_tests::SetUp() {
22
        const GoogletestVlCmdlineProcessor &clp = GoogletestVlCmdlineProcessor::instance();
23
        std::string elf_file, v;
24
 
25
        BaseT::SetUp();
26
        addClock(top()->clock, 20);
27
 
28
        m_trace_funcs = clp.has_plusarg("+TRACE_FUNCS");
29
        m_trace_instr = clp.has_plusarg("+TRACE_INSTR");
30
 
31
 
32
        clp.get_plusarg_value("+SW_IMAGE", elf_file);
33
 
34
        if (!m_symtab.read(elf_file)) {
35
                fprintf(stdout, "Error: failed to read elf file\n");
36
        }
37
 
38
        test = this;
39
}
40
 
41
void fwrisc_fpga_tests::regwrite(uint32_t raddr, uint32_t rdata) {
42
 
43
}
44
 
45
void fwrisc_fpga_tests::exec(uint32_t addr, uint32_t instr) {
46
        if (m_trace_funcs) {
47
        if (m_call_stack.size() == 0) {
48
                // Look for an entry symbol
49
                int32_t sym_idx;
50
 
51
                if ((sym_idx = m_symtab.find_sym(addr)) != -1) {
52
                        if (sym_idx+1 >= m_symtab.n_syms()) {
53
                                fprintf(stdout, "Error: entering the last symbol in the file\n");
54
                                fflush(stdout);
55
                        }
56
                        const Elf32_Sym &next = m_symtab.get_sym(sym_idx+1);
57
                        const std::string &func = m_symtab.get_sym_name(sym_idx);
58
                        if (m_filter_funcs.find(func) == m_filter_funcs.end()) {
59
                                fprintf(stdout, "%s==> %s\n", m_indent.c_str(), func.c_str());
60
                                fflush(stdout);
61
                        }
62
                        m_call_stack.push(std::pair<Elf32_Addr,Elf32_Addr>(addr,next.st_value-4));
63
                        m_indent.append("  ");
64
                }
65
        } else {
66
                // We should be in a function
67
                const std::pair<Elf32_Addr,Elf32_Addr> &func = m_call_stack.top();
68
 
69
                if (addr < func.first || addr > func.second) {
70
                        // We're outside the current function
71
                        int32_t sym_idx;
72
 
73
                        if ((sym_idx = m_symtab.find_sym(addr)) != -1) {
74
                                // We jumped to the beginning of a new function
75
                                // Consider this entering a new function
76
                                if (sym_idx+1 >= m_symtab.n_syms()) {
77
                                        fprintf(stdout, "Error: entering the last symbol in the file\n");
78
                                        fflush(stdout);
79
                                }
80
                                const Elf32_Sym &next = m_symtab.get_sym(sym_idx+1);
81
                                const std::string &func = m_symtab.get_sym_name(sym_idx);
82
                                if (m_filter_funcs.find(func) == m_filter_funcs.end()) {
83
                                        fprintf(stdout, "%s==> %s\n", m_indent.c_str(), func.c_str());
84
                                        fflush(stdout);
85
                                }
86
                                m_call_stack.push(std::pair<Elf32_Addr,Elf32_Addr>(addr,next.st_value-4));
87
                                m_indent.append("  ");
88
                        } else {
89
                                sym_idx = m_symtab.find_sym(func.first);
90
                                // Consider this exiting the current scope
91
                                m_call_stack.pop();
92
 
93
                                const std::pair<Elf32_Addr,Elf32_Addr> &new_func = m_call_stack.top();
94
 
95
                                m_indent = m_indent.substr(0, m_indent.size()-2);
96
                                if (addr >= new_func.first && addr <= new_func.second) {
97
                                        const std::string &func = m_symtab.get_sym_name(sym_idx);
98
                                        if (m_filter_funcs.find(func) == m_filter_funcs.end()) {
99
                                                fprintf(stdout, "%s<== %s\n", m_indent.c_str(), func.c_str());
100
                                                fflush(stdout);
101
                                        }
102
                                } else {
103
//                                      fprintf(stdout, "Error: left function for unknown scope 0x%08x..0x%08x (0x%08x)\n",
104
//                                                      new_func.first, new_func.second, addr);
105
//                                      fflush(stdout);
106
                                }
107
                        }
108
                }
109
        }
110
        }
111
        if (m_trace_instr) {
112
                fprintf(stdout, "EXEC: 0x%08x\n", addr);
113
        }
114
}
115
 
116
void fwrisc_fpga_tests::memwrite(uint32_t addr, uint8_t mask, uint32_t data) {
117
 
118
}
119
 
120
void fwrisc_fpga_tests::led(uint8_t led0, uint8_t led1) {
121
        m_led(led0, led1);
122
}
123
 
124
TEST_F(fwrisc_fpga_tests, led_flash) {
125
        uint32_t cnt = 0;
126
 
127
        raiseObjection(this);
128
        m_led = [&](uint8_t led0, uint8_t led1) {
129
                uint32_t exp = (led0 | (led1 << 1));
130
                cnt++;
131
 
132
                EXPECT_EQ((cnt&3), exp);
133
 
134
                if (cnt > 16) {
135
                        dropObjection(this);
136
                }
137
                fprintf(stdout, "led0=%d led1=%d\n", led0, led1);
138
        };
139
        run(100000);
140
}
141
 
142
TEST_F(fwrisc_fpga_tests, zephyr_hello_world) {
143
        raiseObjection(this);
144
        run(100000000);
145
}
146
 
147
fwrisc_fpga_tests *fwrisc_fpga_tests::test = 0;
148
 
149
extern "C" int unsigned fwrisc_tracer_bfm_register(const char *path) {
150
        fprintf(stdout, "register: %s\n", path);
151
        return 0;
152
}
153
 
154
extern "C" void fwrisc_tracer_bfm_regwrite(unsigned int id, unsigned int raddr, unsigned int rdata) {
155
        fwrisc_fpga_tests::test->regwrite(raddr, rdata);
156
}
157
 
158
extern "C" void fwrisc_tracer_bfm_memwrite(unsigned int id, unsigned int addr, unsigned char mask, unsigned int data) {
159
        fwrisc_fpga_tests::test->memwrite(addr, mask, data);
160
}
161
 
162
extern "C" void fwrisc_tracer_bfm_exec(unsigned int id, unsigned int addr, unsigned int instr) {
163
        fwrisc_fpga_tests::test->exec(addr, instr);
164
}
165
 
166
extern "C" void fwrisc_fpga_tb_led(uint8_t led0, uint8_t led1) {
167
        fwrisc_fpga_tests::test->led(led0, led1);
168
}
169
 
170
 

powered by: WebSVN 2.1.0

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