* same with xv6
[mascara-docs.git] / i386 / standford / 2004 / src / lab4 / kern / pmap.h
blobeeaaaf11483a43c8f45cb15517dbcf1eec521322
1 /* See COPYRIGHT for copyright information. */
3 #ifndef _KERN_PMAP_H_
4 #define _KERN_PMAP_H_
6 #include <inc/pmap.h>
7 #include <inc/assert.h>
10 /* This macro takes a user supplied address and turns it into
11 * something that will cause a fault if it is a kernel address. ULIM
12 * itself is guaranteed never to contain a valid page.
14 #define TRUP(_p) \
15 ({ \
16 register typeof((_p)) __m_p = (_p); \
17 (u_int) __m_p > ULIM ? (typeof(_p)) ULIM : __m_p; \
20 // translates from virtual address to physical address
21 #define PADDR(kva) \
22 ({ \
23 u_long __m_kva = (u_long) (kva); \
24 if (__m_kva < KERNBASE) \
25 panic("PADDR called with invalid kva %08lx", __m_kva);\
26 __m_kva - KERNBASE; \
29 // translates from physical address to kernel virtual address
30 #define KADDR(pa) \
31 ({ \
32 u_long __m_pa = (pa); \
33 u_long __m_ppn = PPN(__m_pa); \
34 if (__m_ppn >= npage) \
35 panic("KADDR called with invalid pa %08lx", __m_pa);\
36 __m_pa + KERNBASE; \
41 extern char bootstacktop[], bootstack[];
43 extern u_long npage;
46 extern struct Segdesc gdt[];
47 extern struct Pseudodesc gdt_pd;
48 extern struct Page *pages;
49 extern u_long npage;
50 extern u_long boot_cr3;
51 extern Pde *boot_pgdir;
53 void i386_vm_init();
54 void i386_detect_memory();
55 void page_init(void);
56 void page_check(void);
57 int page_alloc(struct Page **);
58 void page_free(struct Page *);
59 int page_insert(Pde *, struct Page *, u_long, u_int);
60 void page_remove(Pde *, u_long va);
61 struct Page *page_lookup(Pde*, u_long, Pte**);
62 void page_decref(struct Page*);
63 void tlb_invalidate(Pde *, u_long va);
65 static inline u_long
66 page2ppn(struct Page *pp)
68 return pp - pages;
71 static inline u_long
72 page2pa(struct Page *pp)
74 return page2ppn(pp)<<PGSHIFT;
77 static inline struct Page *
78 pa2page(u_long pa)
80 if (PPN(pa) >= npage)
81 panic("pa2page called with invalid pa");
82 return &pages[PPN(pa)];
85 static inline u_long
86 page2kva(struct Page *pp)
88 return KADDR(page2pa(pp));
91 int pgdir_walk(Pde *pgdir, u_long va, int create, Pte **ppte);
93 #endif /* _KERN_PMAP_H_ */