forked from Coekjan/SOMOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpmap.c
718 lines (589 loc) · 20.2 KB
/
pmap.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
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
#include "mmu.h"
#include "pmap.h"
#include "printf.h"
#include "env.h"
#include "error.h"
/* These variables are set by mips_detect_memory() */
u_long maxpa; /* Maximum physical address */
u_long npage; /* Amount of memory(in pages) */
u_long basemem; /* Amount of base memory(in bytes) */
u_long extmem; /* Amount of extended memory(in bytes) */
Pde *boot_pgdir;
struct Page *pages;
static u_long freemem;
static struct Page_list page_free_list; /* Free list of physical pages */
/* Overview:
Initialize basemem and npage.
Set basemem to be 64MB, and calculate corresponding npage value.*/
void mips_detect_memory()
{
/* Step 1: Initialize basemem.
* (When use real computer, CMOS tells us how many kilobytes there are). */
maxpa = 0x4000000;
npage = maxpa >> PGSHIFT;
basemem = 0x4000000;
extmem = 0x0;
// Step 2: Calculate corresponding npage value.
printf("Physical memory: %dK available, ", (int)(maxpa / 1024));
printf("base = %dK, extended = %dK\n", (int)(basemem / 1024),
(int)(extmem / 1024));
}
/* Overview:
Allocate `n` bytes physical memory with alignment `align`, if `clear` is set, clear the
allocated memory.
This allocator is used only while setting up virtual memory system.
Post-Condition:
If we're out of memory, should panic, else return this address of memory we have allocated.*/
static void *alloc(u_int n, u_int align, int clear)
{
extern char end[];
u_long alloced_mem;
/* Initialize `freemem` if this is the first time. The first virtual address that the
* linker did *not* assign to any kernel code or global variables. */
if (freemem == 0)
{
freemem = (u_long)end; // end
}
/* Step 1: Round up `freemem` up to be aligned properly */
freemem = ROUND(freemem, align);
/* Step 2: Save current value of `freemem` as allocated chunk. */
alloced_mem = freemem;
/* Step 3: Increase `freemem` to record allocation. */
freemem = freemem + n;
// We're out of memory, PANIC !!
if (PADDR(freemem) >= maxpa)
{
panic("out of memorty\n");
return (void *)-E_NO_MEM;
}
/* Step 4: Clear allocated chunk if parameter `clear` is set. */
if (clear)
{
bzero((void *)alloced_mem, n);
}
/* Step 5: return allocated chunk. */
return (void *)alloced_mem;
}
/* Overview:
Get the page table entry for virtual address `va` in the given
page directory `pgdir`.
If the page table is not exist and the parameter `create` is set to 1,
then create it.*/
static Pte *boot_pgdir_walk(Pde *pgdir, u_long va, int create)
{
Pde *pgdir_entryp;
Pte *pgtable, *pgtable_entry;
/* Step 1: Get the corresponding page directory entry and page table. */
pgdir_entryp = pgdir + PDX(va); // higher 10 bits
/* Step 2: If the corresponding page table is not exist and parameter `create`
* is set, create one. And set the correct permission bits for this new page
* table. */
if (!(*pgdir_entryp & PTE_V))
{ // not valid => not exists.
if (create)
{
// page_init is not called yet, we should use alloc instead of page_alloc
*pgdir_entryp = PADDR(alloc(BY2PG, BY2PG, 1));
*pgdir_entryp = *pgdir_entryp | PTE_V | PTE_R;
// PTE_V : valid
}
else
return 0;
}
/* Step 3: Get the page table entry for `va`, and return it. */
/* Hint: Use KADDR and PTE_ADDR to get the page table from page directory
* entry value. */
pgtable = (Pte *)KADDR(PTE_ADDR(*pgdir_entryp));
pgtable_entry = pgtable + PTX(va);
return pgtable_entry;
}
/*Overview:
Map [va, va+size) of virtual address space to physical [pa, pa+size) in the page
table rooted at pgdir.
Use permission bits `perm|PTE_V` for the entries.
Use permission bits `perm` for the entries.
Pre-Condition:
Size is a multiple of BY2PG.*/
void boot_map_segment(Pde *pgdir, u_long va, u_long size, u_long pa, int perm)
{
int i;
Pte *pgtable_entry;
/* Step 1: Check if `size` is a multiple of BY2PG. */
size = ROUND(size, BY2PG);
/* Step 2: Map virtual address space to physical address. */
/* Hint: Use `boot_pgdir_walk` to get the page table entry of virtual address `va`. */
for (i = 0; i < size; i += BY2PG)
{
pgtable_entry = boot_pgdir_walk(pgdir, va + i, 1);
*pgtable_entry = PTE_ADDR(pa + i) | (perm | PTE_V);
// PTE_ADDR : floor of | maybe va/pa is not multiple of BY2PG
}
}
/* Overview:
Set up two-level page table.
Hint:
You can get more details about `UPAGES` and `UENVS` in include/mmu.h. */
void mips_vm_init()
{
extern char end[];
extern int mCONTEXT;
extern struct Env *envs;
Pde *pgdir;
u_int n;
/* Step 1: Allocate a page for page directory(first level page table). */
pgdir = alloc(BY2PG, BY2PG, 1);
printf("to memory %x for struct page directory.\n", freemem);
mCONTEXT = (int)pgdir;
boot_pgdir = pgdir;
/* Step 2: Allocate proper size of physical memory for global array `pages`,
* for physical memory management. Then, map virtual address `UPAGES` to
* physical address `pages` allocated before. For consideration of alignment,
* you should round up the memory size before map. */
pages = (struct Page *)alloc(npage * sizeof(struct Page), BY2PG, 1);
printf("to memory %x for struct Pages.\n", freemem);
n = ROUND(npage * sizeof(struct Page), BY2PG);
boot_map_segment(pgdir, UPAGES, n, PADDR(pages), PTE_R);
/* Step 3, Allocate proper size of physical memory for global array `envs`,
* for process management. Then map the physical address to `UENVS`. */
envs = (struct Env *)alloc(NENV * sizeof(struct Env), BY2PG, 1);
n = ROUND(NENV * sizeof(struct Env), BY2PG);
boot_map_segment(pgdir, UENVS, n, PADDR(envs), PTE_R);
printf("pmap.c:\t mips vm init success\n");
}
/*Overview:
Initialize page structure and memory free list.
The `pages` array has one `struct Page` entry per physical page. Pages
are reference counted, and free pages are kept on a linked list.
Hint:
Use `LIST_INSERT_HEAD` to insert something to list.*/
void page_init(void)
{
/* Step 1: Initialize page_free_list. */
/* Hint: Use macro `LIST_INIT` defined in include/queue.h. */
LIST_INIT(&page_free_list);
/* Step 2: Align `freemem` up to multiple of BY2PG. */
freemem = ROUND(freemem, BY2PG);
/* Step 3: Mark all memory blow `freemem` as used(set `pp_ref`
* filed to 1) */
int size = PADDR(freemem) / BY2PG;
int i;
for (i = 0; i < size; ++i)
{
pages[i].pp_ref = 1;
}
/* Step 4: Mark the other memory as free. */
for (i = size; i < npage; ++i)
{
pages[i].pp_ref = 0;
LIST_INSERT_HEAD(&page_free_list, pages + i, pp_link);
}
LIST_REMOVE(pa2page(PADDR(TIMESTACK - BY2PG)), pp_link);
}
/*Overview:
Allocates a physical page from free memory, and clear this page.
Post-Condition:
If failed to allocate a new page(out of memory(there's no free page)),
return -E_NO_MEM.
Else, set the address of allocated page to *pp, and returned 0.
Note:
Does NOT increment the reference count of the page - the caller must do
these if necessary (either explicitly or via page_insert).
Hint:
Use LIST_FIRST and LIST_REMOVE defined in include/queue.h .*/
int page_alloc(struct Page **pp)
{
struct Page *ppage_temp;
/* Step 1: Get a page from free memory. If fails, return the error code.*/
if (LIST_EMPTY(&page_free_list))
{
return -E_NO_MEM;
}
ppage_temp = LIST_FIRST(&page_free_list);
LIST_REMOVE(ppage_temp, pp_link);
/* Step 2: Initialize this page.
* Hint: use `bzero`. */
bzero(page2kva(ppage_temp), BY2PG); // bzero requests virtual address!!!!
*pp = ppage_temp;
return 0;
}
/*Overview:
Release a page, mark it as free if it's `pp_ref` reaches 0.
Hint:
When to free a page, just insert it to the page_free_list.*/
void page_free(struct Page *pp)
{
/* Step 1: If there's still virtual address refers to this page, do nothing. */
if (pp->pp_ref > 0)
{
return;
}
/* Step 2: If the `pp_ref` reaches to 0, mark this page as free and return. */
else if (pp->pp_ref == 0)
{
LIST_INSERT_HEAD(&page_free_list, pp, pp_link);
return;
}
/* If the value of `pp_ref` less than 0, some error must occurred before,
* so PANIC !!! */
panic("cgh:pp->pp_ref is less than zero\n");
}
/*Overview:
Given `pgdir`, a pointer to a page directory, pgdir_walk returns a pointer
to the page table entry (with permission PTE_R|PTE_V) for virtual address 'va'.
Pre-Condition:
The `pgdir` should be two-level page table structure.
Post-Condition:
If we're out of memory, return -E_NO_MEM.
Else, we get the page table entry successfully, store the value of page table
entry to *ppte, and return 0, indicating success.
Hint:
We use a two-level pointer to store page table entry and return a state code to indicate
whether this function execute successfully or not.
This function have something in common with function `boot_pgdir_walk`.*/
int pgdir_walk(Pde *pgdir, u_long va, int create, Pte **ppte)
{
Pde *pgdir_entryp;
Pte *pgtable;
struct Page *ppage;
/* Step 1: Get the corresponding page directory entry and page table. */
pgdir_entryp = pgdir + PDX(va);
/* Step 2: If the corresponding page table is not exist(valid) and parameter `create`
* is set, create one. And set the correct permission bits for this new page
* table.
* When creating new page table, maybe out of memory. */
if (!((*pgdir_entryp) & PTE_V))
{
if (create)
{
if (page_alloc(&ppage) == -E_NO_MEM)
{
return -E_NO_MEM;
}
else
{
*pgdir_entryp = page2pa(ppage);
*pgdir_entryp = (*pgdir_entryp) | PTE_V | PTE_R;
ppage->pp_ref++;
}
}
else
{
*ppte = 0;
return 0;
}
}
/* Step 3: Set the page table entry to `*ppte` as return value. */
pgtable = (Pte *)KADDR(PTE_ADDR(*pgdir_entryp));
*ppte = pgtable + PTX(va);
return 0;
}
/*Overview:
Map the physical page 'pp' at virtual address 'va'.
The permissions (the low 12 bits) of the page table entry should be set to 'perm|PTE_V'.
Post-Condition:
Return 0 on success
Return -E_NO_MEM, if page table couldn't be allocated
Hint:
If there is already a page mapped at `va`, call page_remove() to release this mapping.
The `pp_ref` should be incremented if the insertion succeeds.*/
int page_insert(Pde *pgdir, struct Page *pp, u_long va, u_int perm)
{
u_int PERM;
Pte *pgtable_entry;
PERM = perm | PTE_V;
/* Step 1: Get corresponding page table entry. */
pgdir_walk(pgdir, va, 0, &pgtable_entry);
if (pgtable_entry != 0 && (*pgtable_entry & PTE_V) != 0)
{
if (pa2page(*pgtable_entry) != pp)
{
page_remove(pgdir, va);
}
else
{
tlb_invalidate(pgdir, va);
*pgtable_entry = (page2pa(pp) | PERM);
return 0;
}
}
/* Step 2: Update TLB. */
/* hint: use tlb_invalidate function */
tlb_invalidate(pgdir, va);
/* Step 3: Do check, re-get page table entry to validate the insertion. */
if (pgdir_walk(pgdir, va, 1, &pgtable_entry))
{
return -E_NO_MEM;
}
*pgtable_entry = page2pa(pp) | PERM;
pp->pp_ref++;
/* Step 3.1 Check if the page can be insert, if can’t return -E_NO_MEM */
/* Step 3.2 Insert page and increment the pp_ref */
return 0;
}
/*Overview:
Look up the Page that virtual address `va` map to.
Post-Condition:
Return a pointer to corresponding Page, and store it's page table entry to *ppte.
If `va` doesn't mapped to any Page, return NULL.*/
struct Page *
page_lookup(Pde *pgdir, u_long va, Pte **ppte)
{
struct Page *ppage;
Pte *pte;
/* Step 1: Get the page table entry. */
pgdir_walk(pgdir, va, 0, &pte);
/* Hint: Check if the page table entry doesn't exist or is not valid. */
if (pte == 0)
{
return 0;
}
if ((*pte & PTE_V) == 0)
{
return 0; //the page is not in memory.
}
/* Step 2: Get the corresponding Page struct. */
/* Hint: Use function `pa2page`, defined in include/pmap.h . */
ppage = pa2page(*pte);
if (ppte)
{
*ppte = pte;
}
return ppage;
}
// Overview:
// Decrease the `pp_ref` value of Page `*pp`, if `pp_ref` reaches to 0, free this page.
void page_decref(struct Page *pp)
{
if (--pp->pp_ref == 0)
{
page_free(pp);
}
}
// Overview:
// Unmaps the physical page at virtual address `va`.
void page_remove(Pde *pgdir, u_long va)
{
Pte *pagetable_entry;
struct Page *ppage;
/* Step 1: Get the page table entry, and check if the page table entry is valid. */
ppage = page_lookup(pgdir, va, &pagetable_entry);
if (ppage == 0)
{
return;
}
/* Step 2: Decrease `pp_ref` and decide if it's necessary to free this page. */
/* Hint: When there's no virtual address mapped to this page, release it. */
ppage->pp_ref--;
if (ppage->pp_ref == 0)
{
page_free(ppage);
}
/* Step 3: Update TLB. */
*pagetable_entry = 0;
tlb_invalidate(pgdir, va);
return;
}
// Overview:
// Update TLB.
void tlb_invalidate(Pde *pgdir, u_long va)
{
if (curenv)
{
tlb_out(PTE_ADDR(va) | GET_ENV_ASID(curenv->env_id));
}
else
{
tlb_out(PTE_ADDR(va));
}
}
void physical_memory_manage_check(void)
{
struct Page *pp, *pp0, *pp1, *pp2;
struct Page_list fl;
int *temp;
// should be able to allocate three pages
pp0 = pp1 = pp2 = 0;
assert(page_alloc(&pp0) == 0);
assert(page_alloc(&pp1) == 0);
assert(page_alloc(&pp2) == 0);
assert(pp0);
assert(pp1 && pp1 != pp0);
assert(pp2 && pp2 != pp1 && pp2 != pp0);
// temporarily steal the rest of the free pages
fl = page_free_list;
// now this page_free list must be empty!!!!
LIST_INIT(&page_free_list);
// should be no free memory
assert(page_alloc(&pp) == -E_NO_MEM);
temp = (int *)page2kva(pp0);
//write 1000 to pp0
*temp = 1000;
// free pp0
page_free(pp0);
printf("The number in address temp is %d\n", *temp);
// alloc again
assert(page_alloc(&pp0) == 0);
assert(pp0);
// pp0 should not change
assert(temp == (int *)page2kva(pp0));
// pp0 should be zero
assert(*temp == 0);
page_free_list = fl;
page_free(pp0);
page_free(pp1);
page_free(pp2);
struct Page_list test_free;
struct Page *test_pages;
test_pages = (struct Page *)alloc(10 * sizeof(struct Page), BY2PG, 1);
LIST_INIT(&test_free);
//LIST_FIRST(&test_free) = &test_pages[0];
int i, j = 0;
struct Page *p, *q;
//test inert tail
for (i = 0; i < 10; i++)
{
test_pages[i].pp_ref = i;
//test_pages[i].pp_link=NULL;
//printf("0x%x 0x%x\n",&test_pages[i], test_pages[i].pp_link.le_next);
LIST_INSERT_TAIL(&test_free, &test_pages[i], pp_link);
//printf("0x%x 0x%x\n",&test_pages[i], test_pages[i].pp_link.le_next);
}
p = LIST_FIRST(&test_free);
int answer1[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
assert(p != NULL);
while (p != NULL)
{
//printf("%d %d\n",p->pp_ref,answer1[j]);
assert(p->pp_ref == answer1[j++]);
//printf("ptr: 0x%x v: %d\n",(p->pp_link).le_next,((p->pp_link).le_next)->pp_ref);
p = LIST_NEXT(p, pp_link);
}
// insert_after test
int answer2[] = {0, 1, 2, 3, 4, 20, 5, 6, 7, 8, 9};
q = (struct Page *)alloc(sizeof(struct Page), BY2PG, 1);
q->pp_ref = 20;
//printf("---%d\n",test_pages[4].pp_ref);
LIST_INSERT_AFTER(&test_pages[4], q, pp_link);
//printf("---%d\n",LIST_NEXT(&test_pages[4],pp_link)->pp_ref);
p = LIST_FIRST(&test_free);
j = 0;
//printf("into test\n");
while (p != NULL)
{
// printf("%d %d\n",p->pp_ref,answer2[j]);
assert(p->pp_ref == answer2[j++]);
p = LIST_NEXT(p, pp_link);
}
printf("physical_memory_manage_check() succeeded\n");
}
void page_check(void)
{
struct Page *pp, *pp0, *pp1, *pp2;
struct Page_list fl;
// should be able to allocate three pages
pp0 = pp1 = pp2 = 0;
assert(page_alloc(&pp0) == 0);
assert(page_alloc(&pp1) == 0);
assert(page_alloc(&pp2) == 0);
assert(pp0);
assert(pp1 && pp1 != pp0);
assert(pp2 && pp2 != pp1 && pp2 != pp0);
// temporarily steal the rest of the free pages
fl = page_free_list;
// now this page_free list must be empty!!!!
LIST_INIT(&page_free_list);
// should be no free memory
assert(page_alloc(&pp) == -E_NO_MEM);
// there is no free memory, so we can't allocate a page table
assert(page_insert(boot_pgdir, pp1, 0x0, 0) < 0);
// free pp0 and try again: pp0 should be used for page table
page_free(pp0);
assert(page_insert(boot_pgdir, pp1, 0x0, 0) == 0);
assert(PTE_ADDR(boot_pgdir[0]) == page2pa(pp0));
printf("va2pa(boot_pgdir, 0x0) is %x\n", va2pa(boot_pgdir, 0x0));
printf("page2pa(pp1) is %x\n", page2pa(pp1));
// printf("pp1->pp_ref is %d\n",pp1->pp_ref);
assert(va2pa(boot_pgdir, 0x0) == page2pa(pp1));
assert(pp1->pp_ref == 1);
// should be able to map pp2 at BY2PG because pp0 is already allocated for page table
assert(page_insert(boot_pgdir, pp2, BY2PG, 0) == 0);
assert(va2pa(boot_pgdir, BY2PG) == page2pa(pp2));
assert(pp2->pp_ref == 1);
// should be no free memory
assert(page_alloc(&pp) == -E_NO_MEM);
printf("start page_insert\n");
// should be able to map pp2 at BY2PG because it's already there
assert(page_insert(boot_pgdir, pp2, BY2PG, 0) == 0);
assert(va2pa(boot_pgdir, BY2PG) == page2pa(pp2));
assert(pp2->pp_ref == 1);
// pp2 should NOT be on the free list
// could happen in ref counts are handled sloppily in page_insert
assert(page_alloc(&pp) == -E_NO_MEM);
// should not be able to map at PDMAP because need free page for page table
assert(page_insert(boot_pgdir, pp0, PDMAP, 0) < 0);
// insert pp1 at BY2PG (replacing pp2)
assert(page_insert(boot_pgdir, pp1, BY2PG, 0) == 0);
// should have pp1 at both 0 and BY2PG, pp2 nowhere, ...
assert(va2pa(boot_pgdir, 0x0) == page2pa(pp1));
assert(va2pa(boot_pgdir, BY2PG) == page2pa(pp1));
// ... and ref counts should reflect this
assert(pp1->pp_ref == 2);
printf("pp2->pp_ref %d\n", pp2->pp_ref);
assert(pp2->pp_ref == 0);
printf("end page_insert\n");
// pp2 should be returned by page_alloc
assert(page_alloc(&pp) == 0 && pp == pp2);
// unmapping pp1 at 0 should keep pp1 at BY2PG
page_remove(boot_pgdir, 0x0);
assert(va2pa(boot_pgdir, 0x0) == ~0);
assert(va2pa(boot_pgdir, BY2PG) == page2pa(pp1));
assert(pp1->pp_ref == 1);
assert(pp2->pp_ref == 0);
// unmapping pp1 at BY2PG should free it
page_remove(boot_pgdir, BY2PG);
assert(va2pa(boot_pgdir, 0x0) == ~0);
assert(va2pa(boot_pgdir, BY2PG) == ~0);
assert(pp1->pp_ref == 0);
assert(pp2->pp_ref == 0);
// so it should be returned by page_alloc
assert(page_alloc(&pp) == 0 && pp == pp1);
// should be no free memory
assert(page_alloc(&pp) == -E_NO_MEM);
// forcibly take pp0 back
assert(PTE_ADDR(boot_pgdir[0]) == page2pa(pp0));
boot_pgdir[0] = 0;
assert(pp0->pp_ref == 1);
pp0->pp_ref = 0;
// give free list back
page_free_list = fl;
// free the pages we took
page_free(pp0);
page_free(pp1);
page_free(pp2);
printf("page_check() succeeded!\n");
}
void pageout(int va, int context)
{
u_long r;
struct Page *p = NULL;
if (context < 0x80000000)
{
panic("tlb refill and alloc error!");
}
if ((va > 0x7f400000) && (va < 0x7f800000))
{
panic(">>>>>>>>>>>>>>>>>>>>>>it's env's zone");
}
if (va < 0x10000)
{
panic("^^^^^^TOO LOW^^^^^^^^^");
}
if ((r = page_alloc(&p)) < 0)
{
panic("page alloc error!");
}
p->pp_ref++;
page_insert((Pde *)context, p, VA2PFN(va), PTE_R);
// printf("pageout:\t@@@___0x%x___@@@ ins a page \n", va);
// printf("envid: %d\n", curenv->env_id);
}