-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.c
93 lines (77 loc) · 2.49 KB
/
main.c
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
#include <stdio.h>
#include "mm.h"
#include "pc.h"
extern pc_t pc; /* pc.h */
extern mm_t mm; /* mm.h */
/* Entry point to test program */
int main(void)
{
int i;
gdt_entry_t *gdt_base;
ptab_entry_t *ptab;
/* Not so magical emulation */
char *mbase = (char *)(
(uint32_t)&pc.mem[2 * MM_PAGE_SIZE]
& ~(MM_PAGE_SIZE - 1)
);
mm.pfbm = (bitmap_t *) (mbase + 0 * MM_PAGE_SIZE);
mm.pdir = (ptab_entry_t *) (mbase + 1 * MM_PAGE_SIZE);
ptab = (ptab_entry_t *) (mbase + 2 * MM_PAGE_SIZE);
mm.gdt = (gdt_ptr_t *) (mbase + 10 * MM_PAGE_SIZE);
gdt_base = (gdt_entry_t *) (mbase + 11 * MM_PAGE_SIZE);
/* Emulation ends here */
/* Prepare the environment */
mm.gdt->base = (uint32_t)gdt_base;
gdt_add(mm.gdt, 0, 0, 0, 0, 0); /* Null segment */
gdt_add(mm.gdt, 1, 0, 0xffffffff, 0x9a, 0xcf); /* CS */
gdt_add(mm.gdt, 2, 0, 0xffffffff, 0x92, 0xcf); /* DS */
gdt_add(mm.gdt, 3, 0, 0xffffffff, 0xfa, 0xcf); /* User-mode CS */
gdt_add(mm.gdt, 4, 0, 0xffffffff, 0xf2, 0xcf); /* User-mode DS */
gdt_load(mm.gdt);
bitmap_clear(mm.pfbm);
for(i = 0; i < 1024; i++) {
ptab_entry_clear(&mm.pdir[i]);
ptab_entry_set_bit_p(&mm.pdir[i], 1);
}
ptab_entry_set_pfa(mm.pdir, (uint32_t)ptab);
ptab_load(mm.pdir);
/* Start tests */
do {
int i;
struct vm_request_args {
uint32_t vaddr;
int length;
int expected;
char finish;
};
struct vm_request_args vra[] = {
{0, 1, 1, 1},
{4096, 1, 1, 1},
{4096, 1, 0, 1},
{8192, 3, 1, 1},
{0, 0, 0, 0},
};
puts("vm_request");
puts("----------");
for(i = 0; 0 < vra[i].finish; i++) {
printf("vm_request(%d, %d) => %d | %d\n",
vra[i].vaddr,
vra[i].length,
vm_request(vra[i].vaddr, vra[i].length),
vra[i].expected
);
}
puts("");
puts("vm_return");
puts("----------");
for(i = 0; 0 < vra[i].finish; i++) {
printf("vm_return(%d, %d) => %d | %d\n",
vra[i].vaddr,
vra[i].length,
vm_return(vra[i].vaddr, vra[i].length),
vra[i].expected
);
}
} while(0);
return 0;
}