-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMemoryConstants.h
More file actions
33 lines (24 loc) · 980 Bytes
/
MemoryConstants.h
File metadata and controls
33 lines (24 loc) · 980 Bytes
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
#pragma once
#include <climits>
#include <stdint.h>
typedef int word_t;
#define WORD_WIDTH (sizeof(word_t) * CHAR_BIT)
// number of bits in the offset
#define OFFSET_WIDTH 4
// page/frame size in words
// in this implementation this is also the number of entries in a table
#define PAGE_SIZE (1LL << OFFSET_WIDTH)
// number of bits in a physical address
#define PHYSICAL_ADDRESS_WIDTH 10
// RAM size in words
#define RAM_SIZE (1LL << PHYSICAL_ADDRESS_WIDTH)
// number of bits in a virtual address
#define VIRTUAL_ADDRESS_WIDTH 20
// virtual memory size in words
#define VIRTUAL_MEMORY_SIZE (1LL << VIRTUAL_ADDRESS_WIDTH)
// number of frames in the RAM
#define NUM_FRAMES (RAM_SIZE / PAGE_SIZE)
// number of pages in the virtual memory
#define NUM_PAGES (VIRTUAL_MEMORY_SIZE / PAGE_SIZE)
#define CEIL(VARIABLE) ( (VARIABLE - (int)VARIABLE)==0 ? (int)VARIABLE : (int)VARIABLE+1 )
#define TABLES_DEPTH CEIL((((VIRTUAL_ADDRESS_WIDTH - OFFSET_WIDTH) / (double)OFFSET_WIDTH)))