kern
view src/vm.h @ 90:7ff2b4971216
started work on the filesystem
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 09 Dec 2011 13:44:15 +0200 |
parents | b45e2d5f0ae1 |
children |
line source
1 #ifndef VM_H_
2 #define VM_H_
4 #include <stdlib.h>
5 #include "mboot.h"
6 #include "rbtree.h"
8 #define KMEM_START 0xc0000000
9 #define KMEM_START_PAGE ADDR_TO_PAGE(KMEM_START)
11 /* page mapping flags */
12 #define PG_PRESENT (1 << 0)
13 #define PG_WRITABLE (1 << 1)
14 #define PG_USER (1 << 2)
15 #define PG_WRITE_THROUGH (1 << 3)
16 #define PG_NOCACHE (1 << 4)
17 #define PG_ACCESSED (1 << 5)
18 #define PG_DIRTY (1 << 6)
19 #define PG_TYPE (1 << 7)
20 /* PG_GLOBAL mappings won't flush from TLB */
21 #define PG_GLOBAL (1 << 8)
24 #define PGSIZE 4096
25 #define PAGE_COUNT (1024 * 1024)
27 #define PGOFFS_MASK 0xfff
28 #define PGNUM_MASK 0xfffff000
29 #define PGENT_ADDR_MASK PGNUM_MASK
31 #define ADDR_TO_PAGE(x) ((uint32_t)(x) >> 12)
32 #define PAGE_TO_ADDR(x) ((uint32_t)(x) << 12)
34 #define ADDR_TO_PGTBL(x) ((uint32_t)(x) >> 22)
35 #define ADDR_TO_PGTBL_PG(x) (((uint32_t)(x) >> 12) & 0x3ff)
36 #define ADDR_TO_PGOFFS(x) ((uint32_t)(x) & PGOFFS_MASK)
38 #define PAGE_TO_PGTBL(x) ((uint32_t)(x) >> 10)
39 #define PAGE_TO_PGTBL_PG(x) ((uint32_t)(x) & 0x3ff)
41 /* argument to clone_vm */
42 #define CLONE_SHARED 0
43 #define CLONE_COW 1
45 /* last argument to *_page_bit */
46 #define PAGE_ONLY 0
47 #define WHOLE_PATH 1
49 struct vm_page {
50 int vpage, ppage;
51 unsigned int flags;
53 int nref;
54 };
56 struct process;
58 void init_vm(void);
60 int map_page(int vpage, int ppage, unsigned int attr);
61 int unmap_page(int vpage);
62 int map_page_range(int vpg_start, int pgcount, int ppg_start, unsigned int attr);
63 int unmap_page_range(int vpg_start, int pgcount);
64 int map_mem_range(uint32_t vaddr, size_t sz, uint32_t paddr, unsigned int attr);
66 uint32_t virt_to_phys(uint32_t vaddr);
67 int virt_to_phys_page(int vpg);
69 uint32_t virt_to_phys_proc(struct process *p, uint32_t vaddr);
70 int virt_to_phys_page_proc(struct process *p, int vpg);
72 enum {
73 MEM_KERNEL,
74 MEM_USER
75 };
77 int pgalloc(int num, int area);
78 int pgalloc_vrange(int start, int num);
79 void pgfree(int start, int num);
81 /* don't be fooled by the fact these two accept process arguments
82 * they in fact work only for the "current" process (psrc and p)
83 */
84 void clone_vm(struct process *pdest, struct process *psrc, int cow);
85 void cleanup_vm(struct process *p);
87 int get_page_bit(int pgnum, uint32_t bit, int wholepath);
88 void set_page_bit(int pgnum, uint32_t bit, int wholepath);
89 void clear_page_bit(int pgnum, uint32_t bit, int wholepath);
91 /* construct the vm map for the current user mappings */
92 int cons_vmmap(struct rbtree *vmmap);
94 struct vm_page *get_vm_page(int vpg);
95 struct vm_page *get_vm_page_proc(struct process *p, int vpg);
97 void dbg_print_vm(int area);
99 /* defined in vm-asm.S */
100 void set_pgdir_addr(uint32_t addr);
101 uint32_t get_pgdir_addr(void);
103 #endif /* VM_H_ */