-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefinitions.h
58 lines (45 loc) · 1.31 KB
/
definitions.h
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
#ifndef DEFINITIONS_H
#define DEFINITIONS_H
#include <stdint.h>
#include <stdbool.h>
#define RED() printf("\033[1;31m");
#define BLACK() printf("\033[0m");
#define GREEN() printf("\x1b[32m");
#define N_SLOTS_RM 8
#define N_SLOTS_VM 16
#define N_SLOTS_SWAP 16 // |SW| >= |VM| - |RM|
#define MAX_CONTENT_VAL 1000
typedef struct{
uint8_t referenced_counter;
int R;// referenced bit
bool is_free;// true when the memory page is unused
int content;
}page_t;
typedef struct {
page_t page;
}mem_slot_t;
typedef struct {
page_t page;
int8_t old_rm_addr;
int8_t old_vm_addr;
}sw_mem_slot_t;
extern mem_slot_t real_memory[N_SLOTS_RM];
//mem_slot_t virtual_memory[N_SLOTS_VM];
extern sw_mem_slot_t swap[N_SLOTS_SWAP];
typedef struct{
bool is_mapped;
int8_t real_addr; // between 0 and N_SLOTS_RM - 1
}page_table_entry_t;
// process table stores the mapping between VM and RM
extern page_table_entry_t page_table[N_SLOTS_VM];
int reference_page(int8_t addr);
// returns the last recently used page
// and changes lib_addr to the freed address
// on the real memory
page_t lru_page(int8_t *lib_addr);
void init_pages_as_free();
void unreference_all_pages();
int8_t get_swap_address(int8_t v_addr, int8_t r_addr);
page_t remove_from_swap(int8_t swap_addr);
void update_counters();
#endif // DEFINITIONS_H