-
Notifications
You must be signed in to change notification settings - Fork 0
/
vmm.h~
128 lines (101 loc) · 2.84 KB
/
vmm.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
#ifndef VMM_H
#define VMM_H
#ifndef DEBUG
#define DEBUG
#endif
#undef DEBUG
/* 模拟辅存的文件路径 */
#define AUXILIARY_MEMORY "vmm_auxMem"
/* 页面大小(字节)*/
#define PAGE_SIZE 4
/* 虚存空间大小(字节) */
#define VIRTUAL_MEMORY_SIZE (64 * 4)
/* 实存空间大小(字节) */
#define ACTUAL_MEMORY_SIZE (32 * 4)
/* 总虚页数 */
#define PAGE_SUM (VIRTUAL_MEMORY_SIZE / PAGE_SIZE)
/* 总物理块数 */
#define BLOCK_SUM (ACTUAL_MEMORY_SIZE / PAGE_SIZE)
/*总页目录数*/
#define ROOT_PAGE_SUM 4
/*二级页表项数*/
#define SEC_PAGE_SUM (PAGE_SUM/ROOT_PAGE_SUM)
/* 可读标识位 */
#define READABLE 0x01u
/* 可写标识位 */
#define WRITABLE 0x02u
/* 可执行标识位 */
#define EXECUTABLE 0x04u
#define FIFO_NAME "/tmp/vmm_fifo"
/* 定义字节类型 */
#define BYTE unsigned char
typedef enum {
TRUE = 1, FALSE = 0
} BOOL;
/* 页表项 */
typedef struct
{
unsigned int pageNum;
unsigned int blockNum; //物理块号
BOOL filled; //页面装入特征位
BYTE proType; //页面保护类型
BOOL edited; //页面修改标识
unsigned long auxAddr; //外存地址
unsigned long count; //页面使用计数器
int processnum;//进程编号
} PageTableItem, *Ptr_PageTableItem;
/* 访存请求类型 */
typedef enum {
REQUEST_READ,
REQUEST_WRITE,
REQUEST_EXECUTE
} MemoryAccessRequestType;
/* 访存请求 */
typedef struct
{
MemoryAccessRequestType reqType; //访存请求类型
unsigned long virAddr; //虚地址
BYTE value; //写请求的值
int processnum;//进程编号
} MemoryAccessRequest, *Ptr_MemoryAccessRequest;
typedef struct
{
MemoryAccessRequest memAccReq;
char cmdType;
}VMM_cmd, *Ptr_VMM_cmd;
/* 访存错误代码 */
typedef enum {
ERROR_READ_DENY, //该页不可读
ERROR_WRITE_DENY, //该页不可写
ERROR_EXECUTE_DENY, //该页不可执行
ERROR_INVALID_REQUEST, //非法请求类型
ERROR_OVER_BOUNDARY, //地址越界
ERROR_FILE_OPEN_FAILED, //文件打开失败
ERROR_FILE_CLOSE_FAILED, //文件关闭失败
ERROR_FILE_SEEK_FAILED, //文件指针定位失败
ERROR_FILE_READ_FAILED, //文件读取失败
ERROR_FILE_WRITE_FAILED, //文件写入失败
ERROR_FIFO_REMOVE_FAILED, //FIFO移除失败
ERROR_FIFO_MAKE_FAILED, //FIFO创建失败
ERROR_FIFO_OPEN_FAILED, //FIFO打开失败
ERROR_FIFO_READ_FAILED //FIFO读取失败
} ERROR_CODE;
/* 产生访存请求 */
void do_request();
/* 响应访存请求 */
void do_response();
/* 处理缺页中断 */
void do_page_fault(Ptr_PageTableItem);
/* LFU页面替换 */
void do_LFU(Ptr_PageTableItem);
/* 装入页面 */
void do_page_in(Ptr_PageTableItem, unsigned in);
/* 写出页面 */
void do_page_out(Ptr_PageTableItem);
/* 错误处理 */
void do_error(ERROR_CODE);
/* 打印页表相关信息 */
void do_print_info();
/* 获取页面保护类型字符串 */
char *get_proType_str(char *, BYTE);
#endif