kern

annotate 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
rev   line source
nuclear@17 1 #ifndef VM_H_
nuclear@17 2 #define VM_H_
nuclear@17 3
nuclear@17 4 #include <stdlib.h>
nuclear@17 5 #include "mboot.h"
nuclear@17 6
nuclear@17 7 /* page mapping flags */
nuclear@17 8 #define PG_PRESENT (1 << 0)
nuclear@17 9 #define PG_WRITABLE (1 << 1)
nuclear@17 10 #define PG_USER (1 << 2)
nuclear@17 11 #define PG_WRITE_THROUGH (1 << 3)
nuclear@17 12 #define PG_NOCACHE (1 << 4)
nuclear@17 13 #define PG_ACCESSED (1 << 5)
nuclear@17 14 #define PG_DIRTY (1 << 6)
nuclear@17 15 #define PG_TYPE (1 << 7)
nuclear@17 16 /* PG_GLOBAL mappings won't flush from TLB */
nuclear@17 17 #define PG_GLOBAL (1 << 8)
nuclear@17 18
nuclear@17 19
nuclear@17 20 #define PGSIZE 4096
nuclear@23 21 #define PAGE_COUNT (1024 * 1024)
nuclear@23 22
nuclear@17 23 #define PGOFFS_MASK 0xfff
nuclear@17 24 #define PGNUM_MASK 0xfffff000
nuclear@18 25 #define PGENT_ADDR_MASK PGNUM_MASK
nuclear@17 26
nuclear@23 27 #define ADDR_TO_PAGE(x) ((uint32_t)(x) >> 12)
nuclear@23 28 #define PAGE_TO_ADDR(x) ((uint32_t)(x) << 12)
nuclear@17 29
nuclear@17 30 #define ADDR_TO_PGTBL(x) ((uint32_t)(x) >> 22)
nuclear@17 31 #define ADDR_TO_PGTBL_PG(x) (((uint32_t)(x) >> 12) & 0x3ff)
nuclear@17 32 #define ADDR_TO_PGOFFS(x) ((uint32_t)(x) & PGOFFS_MASK)
nuclear@17 33
nuclear@17 34 #define PAGE_TO_PGTBL(x) ((uint32_t)(x) >> 10)
nuclear@17 35 #define PAGE_TO_PGTBL_PG(x) ((uint32_t)(x) & 0x3ff)
nuclear@17 36
nuclear@17 37
nuclear@26 38 void init_vm(void);
nuclear@17 39
nuclear@23 40 int map_page(int vpage, int ppage, unsigned int attr);
nuclear@23 41 int map_page_range(int vpg_start, int pgcount, int ppg_start, unsigned int attr);
nuclear@23 42 int map_mem_range(uint32_t vaddr, size_t sz, uint32_t paddr, unsigned int attr);
nuclear@17 43
nuclear@18 44 uint32_t virt_to_phys(uint32_t vaddr);
nuclear@18 45
nuclear@22 46 enum {
nuclear@22 47 MEM_KERNEL,
nuclear@22 48 MEM_USER
nuclear@22 49 };
nuclear@22 50
nuclear@22 51 int pgalloc(int num, int area);
nuclear@23 52 void pgfree(int start, int num);
nuclear@23 53
nuclear@23 54 void dbg_print_vm(int area);
nuclear@22 55
nuclear@17 56 #endif /* VM_H_ */