kern

annotate src/vm.h @ 49:50730d42d2d3

fuck yeah, now do priviledge levels and TSS
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 30 Jul 2011 07:21:54 +0300
parents 5f6c5751ae05
children 88a6c4e192f9
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@47 7 #define KMEM_START 0xc0000000
nuclear@47 8
nuclear@17 9 /* page mapping flags */
nuclear@17 10 #define PG_PRESENT (1 << 0)
nuclear@17 11 #define PG_WRITABLE (1 << 1)
nuclear@17 12 #define PG_USER (1 << 2)
nuclear@17 13 #define PG_WRITE_THROUGH (1 << 3)
nuclear@17 14 #define PG_NOCACHE (1 << 4)
nuclear@17 15 #define PG_ACCESSED (1 << 5)
nuclear@17 16 #define PG_DIRTY (1 << 6)
nuclear@17 17 #define PG_TYPE (1 << 7)
nuclear@17 18 /* PG_GLOBAL mappings won't flush from TLB */
nuclear@17 19 #define PG_GLOBAL (1 << 8)
nuclear@17 20
nuclear@17 21
nuclear@17 22 #define PGSIZE 4096
nuclear@23 23 #define PAGE_COUNT (1024 * 1024)
nuclear@23 24
nuclear@17 25 #define PGOFFS_MASK 0xfff
nuclear@17 26 #define PGNUM_MASK 0xfffff000
nuclear@18 27 #define PGENT_ADDR_MASK PGNUM_MASK
nuclear@17 28
nuclear@23 29 #define ADDR_TO_PAGE(x) ((uint32_t)(x) >> 12)
nuclear@23 30 #define PAGE_TO_ADDR(x) ((uint32_t)(x) << 12)
nuclear@17 31
nuclear@17 32 #define ADDR_TO_PGTBL(x) ((uint32_t)(x) >> 22)
nuclear@17 33 #define ADDR_TO_PGTBL_PG(x) (((uint32_t)(x) >> 12) & 0x3ff)
nuclear@17 34 #define ADDR_TO_PGOFFS(x) ((uint32_t)(x) & PGOFFS_MASK)
nuclear@17 35
nuclear@17 36 #define PAGE_TO_PGTBL(x) ((uint32_t)(x) >> 10)
nuclear@17 37 #define PAGE_TO_PGTBL_PG(x) ((uint32_t)(x) & 0x3ff)
nuclear@17 38
nuclear@17 39
nuclear@26 40 void init_vm(void);
nuclear@17 41
nuclear@23 42 int map_page(int vpage, int ppage, unsigned int attr);
nuclear@43 43 int unmap_page(int vpage);
nuclear@23 44 int map_page_range(int vpg_start, int pgcount, int ppg_start, unsigned int attr);
nuclear@43 45 int unmap_page_range(int vpg_start, int pgcount);
nuclear@23 46 int map_mem_range(uint32_t vaddr, size_t sz, uint32_t paddr, unsigned int attr);
nuclear@17 47
nuclear@43 48 int virt_to_phys_page(int vpg);
nuclear@18 49 uint32_t virt_to_phys(uint32_t vaddr);
nuclear@18 50
nuclear@22 51 enum {
nuclear@22 52 MEM_KERNEL,
nuclear@22 53 MEM_USER
nuclear@22 54 };
nuclear@22 55
nuclear@22 56 int pgalloc(int num, int area);
nuclear@47 57 int pgalloc_vrange(int start, int num);
nuclear@23 58 void pgfree(int start, int num);
nuclear@23 59
nuclear@47 60 uint32_t clone_vm(void);
nuclear@43 61
nuclear@23 62 void dbg_print_vm(int area);
nuclear@22 63
nuclear@47 64 /* defined in vm-asm.S */
nuclear@47 65 void set_pgdir_addr(uint32_t addr);
nuclear@47 66
nuclear@17 67 #endif /* VM_H_ */