-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmem.h
More file actions
45 lines (37 loc) · 1.18 KB
/
mem.h
File metadata and controls
45 lines (37 loc) · 1.18 KB
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
#include <stdint.h>
#include <stdbool.h>
#include "consts.h"
#ifndef MEM_H
#define MEM_H
#define MEMSZ (640 * KB)
#define END_OF_MEM (MEMSZ + MIPS_RESERVE)
struct cache {
size_t hits; // Cache hits
size_t misses; // Cache misses
uint32_t n_sets; // Number of sets in cache
uint32_t n_blocks_per_set; // Number of block in set
uint32_t n_words_per_block; // Number of words per block
struct block *blocks;
};
struct block {
bool valid; // Block references valid data?
bool modified; // Block modified?
uint32_t age; // When was the block inserted (higher = older)
uint32_t tag; // Upper part of address
uint32_t *data; // Data segment of block
};
// Caches
extern struct cache icache;
extern struct cache dcache;
extern struct cache l2cache;
struct cache icache;
struct cache dcache;
struct cache l2cache;
// Setup memory and cache
int mem_init(const char *path, uint32_t *PC);
int cache_init(struct cache *c);
// Cache operations
int inst_read(uint32_t addr, uint32_t *read_inst);
int data_read(uint32_t addr, uint32_t *read_data);
int data_write(uint32_t addr, uint32_t data);
#endif