aboutsummaryrefslogtreecommitdiff
path: root/qtmips_machine/cache.h
blob: 3ad3bdb17f6d770ea709397f75c748778dda4488 (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
#ifndef CACHE_H
#define CACHE_H

#include <memory.h>
#include <machineconfig.h>
#include <stdint.h>

namespace machine {

class Cache : public MemoryAccess {
    Q_OBJECT
public:
    Cache(Memory *m, MachineConfigCache *c);

    void wword(std::uint32_t address, std::uint32_t value);
    std::uint32_t rword(std::uint32_t address) const;

    void flush(); // flush/sync cache

    unsigned hit(); // Number of recorded hits
    unsigned miss(); // Number of recorded misses

    // TODO reset

private:
    MachineConfigCache cnf;
    Memory *mem;

    struct cache_data {
        bool valid, dirty;
        std::uint32_t tag;
        std::uint32_t *data;
    };
    mutable struct cache_data **dt;

    mutable unsigned hitc, missc;

    void access(std::uint32_t address, std::uint32_t **data, bool read) const;
};

}

#endif // CACHE_H