aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine/qtmipsmachine.cpp
blob: 3d5ce98ced64a40e358d69505314ce497bf60cda (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "qtmipsmachine.h"
#include "programloader.h"

QtMipsMachine::QtMipsMachine(const MachineConfig &cc) {
    ProgramLoader program(cc.elf());

    regs = new Registers();
    mem = new Memory();

    program.to_memory(mem);
    program_end = program.end();

    MemoryAccess *coremem;
    switch (cc.cache()) {
    case MachineConfig::CCT_NONE:
        cch = nullptr;
        coremem = mem;
        break;
    case MachineConfig::CCT_ASSOCIATIVE:
        // TODO
        coremem = mem;
        //coremem = cch = new CacheAssociative();
        break;
    }

    // TODO pipelined
    cr = new CoreSingle(regs, coremem);

    run_speed = 1;
    run_t = new QTimer(this);
    connect(run_t, SIGNAL(timeout()), this, SLOT(step()));
}

void QtMipsMachine::set_speed(unsigned val) {
    run_speed = val;
}

const Registers *QtMipsMachine::registers() {
    return regs;
}

const Memory *QtMipsMachine::memory() {
    return mem;
}

const Cache *QtMipsMachine::cache() {
    return cch;
}

const Core *QtMipsMachine::core() {
    return cr;
}

void QtMipsMachine::play() {
    run_t->start(run_speed);
}

void QtMipsMachine::pause() {
    run_t->stop();
}

void QtMipsMachine::step() {
    cr->step();
    if (regs->read_pc() >= program_end)
        emit program_exit();
}

void QtMipsMachine::restart() {
    // TODO
}