kern

view src/vm.h @ 67:ebca81749ef5

added strcmp
author John Tsiombikas <nuclear@mutantstargoat.com>
date Sun, 09 Oct 2011 20:38:35 +0300
parents 88a6c4e192f9
children 0a205396e1a0
line source
1 #ifndef VM_H_
2 #define VM_H_
4 #include <stdlib.h>
5 #include "mboot.h"
7 #define KMEM_START 0xc0000000
9 /* page mapping flags */
10 #define PG_PRESENT (1 << 0)
11 #define PG_WRITABLE (1 << 1)
12 #define PG_USER (1 << 2)
13 #define PG_WRITE_THROUGH (1 << 3)
14 #define PG_NOCACHE (1 << 4)
15 #define PG_ACCESSED (1 << 5)
16 #define PG_DIRTY (1 << 6)
17 #define PG_TYPE (1 << 7)
18 /* PG_GLOBAL mappings won't flush from TLB */
19 #define PG_GLOBAL (1 << 8)
22 #define PGSIZE 4096
23 #define PAGE_COUNT (1024 * 1024)
25 #define PGOFFS_MASK 0xfff
26 #define PGNUM_MASK 0xfffff000
27 #define PGENT_ADDR_MASK PGNUM_MASK
29 #define ADDR_TO_PAGE(x) ((uint32_t)(x) >> 12)
30 #define PAGE_TO_ADDR(x) ((uint32_t)(x) << 12)
32 #define ADDR_TO_PGTBL(x) ((uint32_t)(x) >> 22)
33 #define ADDR_TO_PGTBL_PG(x) (((uint32_t)(x) >> 12) & 0x3ff)
34 #define ADDR_TO_PGOFFS(x) ((uint32_t)(x) & PGOFFS_MASK)
36 #define PAGE_TO_PGTBL(x) ((uint32_t)(x) >> 10)
37 #define PAGE_TO_PGTBL_PG(x) ((uint32_t)(x) & 0x3ff)
39 /* argument to clone_vm */
40 #define CLONE_SHARED 0
41 #define CLONE_COW 1
43 /* last argument to *_page_bit */
44 #define PAGE_ONLY 0
45 #define WHOLE_PATH 1
47 void init_vm(void);
49 int map_page(int vpage, int ppage, unsigned int attr);
50 int unmap_page(int vpage);
51 int map_page_range(int vpg_start, int pgcount, int ppg_start, unsigned int attr);
52 int unmap_page_range(int vpg_start, int pgcount);
53 int map_mem_range(uint32_t vaddr, size_t sz, uint32_t paddr, unsigned int attr);
55 int virt_to_phys_page(int vpg);
56 uint32_t virt_to_phys(uint32_t vaddr);
58 enum {
59 MEM_KERNEL,
60 MEM_USER
61 };
63 int pgalloc(int num, int area);
64 int pgalloc_vrange(int start, int num);
65 void pgfree(int start, int num);
67 uint32_t clone_vm(int cow);
69 int get_page_bit(int pgnum, uint32_t bit, int wholepath);
70 void set_page_bit(int pgnum, uint32_t bit, int wholepath);
71 void clear_page_bit(int pgnum, uint32_t bit, int wholepath);
73 void dbg_print_vm(int area);
75 /* defined in vm-asm.S */
76 void set_pgdir_addr(uint32_t addr);
77 uint32_t get_pgdir_addr(void);
79 #endif /* VM_H_ */