kern
view src/vm.h @ 30:a2c6110bd24b
refactored the code a bit, and merged with the malloc implementation branch
author | John Tsiombikas <nuclear@siggraph.org> |
---|---|
date | Fri, 27 May 2011 22:09:10 +0300 |
parents | 5454cee245a3 |
children | 5f6c5751ae05 |
line source
1 #ifndef VM_H_
2 #define VM_H_
4 #include <stdlib.h>
5 #include "mboot.h"
7 /* page mapping flags */
8 #define PG_PRESENT (1 << 0)
9 #define PG_WRITABLE (1 << 1)
10 #define PG_USER (1 << 2)
11 #define PG_WRITE_THROUGH (1 << 3)
12 #define PG_NOCACHE (1 << 4)
13 #define PG_ACCESSED (1 << 5)
14 #define PG_DIRTY (1 << 6)
15 #define PG_TYPE (1 << 7)
16 /* PG_GLOBAL mappings won't flush from TLB */
17 #define PG_GLOBAL (1 << 8)
20 #define PGSIZE 4096
21 #define PAGE_COUNT (1024 * 1024)
23 #define PGOFFS_MASK 0xfff
24 #define PGNUM_MASK 0xfffff000
25 #define PGENT_ADDR_MASK PGNUM_MASK
27 #define ADDR_TO_PAGE(x) ((uint32_t)(x) >> 12)
28 #define PAGE_TO_ADDR(x) ((uint32_t)(x) << 12)
30 #define ADDR_TO_PGTBL(x) ((uint32_t)(x) >> 22)
31 #define ADDR_TO_PGTBL_PG(x) (((uint32_t)(x) >> 12) & 0x3ff)
32 #define ADDR_TO_PGOFFS(x) ((uint32_t)(x) & PGOFFS_MASK)
34 #define PAGE_TO_PGTBL(x) ((uint32_t)(x) >> 10)
35 #define PAGE_TO_PGTBL_PG(x) ((uint32_t)(x) & 0x3ff)
38 void init_vm(void);
40 int map_page(int vpage, int ppage, unsigned int attr);
41 int map_page_range(int vpg_start, int pgcount, int ppg_start, unsigned int attr);
42 int map_mem_range(uint32_t vaddr, size_t sz, uint32_t paddr, unsigned int attr);
44 uint32_t virt_to_phys(uint32_t vaddr);
46 enum {
47 MEM_KERNEL,
48 MEM_USER
49 };
51 int pgalloc(int num, int area);
52 void pgfree(int start, int num);
54 void dbg_print_vm(int area);
56 #endif /* VM_H_ */