00001 /*header file for src/memory/alloc4k.cpp*/ 00002 00003 #ifndef _CORE_MEMORY_ALLOC4K_HPP 00004 #define _CORE_MEMORY_ALLOC4K_HPP 00005 00006 /*necessary includes*/ 00007 #include "src/common/stack.hpp" 00008 #include "src/ipc/lock.hpp" 00009 #include "src/memory/zone.hpp" 00010 00011 //change a physical value to a virtual, for the early kernel data by adding 0xc0000000-0x100000 00012 #define LMA2VIRT(obj) ((uint32)(obj)+mem_kernel_start-mem_physical) 00013 00014 /*from the linker script*/ 00015 extern char bss; 00016 extern char bss2; 00017 extern char bssend; 00018 extern char end; 00019 00020 /*the way we divide the address space*/ 00021 const uint32 mem_trap_lower = 0; /*the lower null-pointer trap*/ 00022 const uint32 mem_user_start = 0x00001000; /*start of user level*/ 00023 const uint32 mem_low_start = 0x00001000; /*start of physical low page area*/ 00024 //could be 0xa0000- which is the begging of graphics card graphics mode buffer, 00025 //but there are 32kib of EBDA from 640kib downwards which we don't want to overwrite. 00026 const uint32 video_memory = 0xb8000; /*doh, this is remapped into kernel space early*/ 00027 const uint32 mem_low_end = 0x00098000; /*end of low pages area*/ 00028 const uint32 mem_user_end = 0xbfffffff; /*end of user level*/ 00029 const uint32 mem_user_load = 0x80000000; /*place to load modules/executables*/ 00030 const uint32 mem_exec = 0x80000000; /*place to start execution*/ 00031 const uint32 mem_kernel_start = 0xc0000000; /*start of kernel level*/ 00032 const uint32 mem_kernel_end = 0xffffffff; /*end of kernel level*/ 00033 const uint32 mem_heap_start = 0xd0000000; /*start of kernel heap*/ 00034 const uint32 mem_heap_end = 0xf0000000; /*end of kernel heap*/ 00035 const uint32 mem_pgd_start = 0xFF800000; /*the start of the space's page tables*/ 00036 const uint32 mem_pgt_start = 0xFFBFFFFF; /*the end of the space's page tables*/ 00037 const uint32 mem_trap_upper = 0xfffff000; /*the upper null-pointer trap*/ 00038 const uint32 mem_space_start = mem_user_start;/*where the memory map starts*/ 00039 const uint32 mem_space_end = mem_kernel_start;/*where a user memory map ends*/ 00040 const uint32 mem_space_krnend = mem_heap_start;/*where the kmem kernel memory map ends*/ 00041 const uint32 mem_physical = 0x00100000; /*load address of the kernel*/ 00042 00043 /*memory size*/ 00044 const size_t mem_4k = 4096; 00045 const size_t mem_1Mib = 0x100000; 00046 const size_t PAGE_SIZE = 4096; 00047 const size_t PGT_WIDE = 4 * mem_1Mib; //how wide does a pgt map memory? 4 Mib 00048 const size_t memory_size = mem_1Mib * 32; 00049 const uint32 mem_ksize = ((uint32) &end - mem_kernel_start); /*kernel's size*/ 00050 00051 namespace Memory { 00052 namespace Physical { 00053 00054 void init(); /*init the free-page stack*/ 00055 00056 /*======================balloc*/ 00057 extern uint32 heap_area_addend; /*how many virtual bytes are occupied before the heap*/ 00058 extern bool balloc_on; /*is it still on?*/ 00059 extern uint32 first_free_page; /*the first page to be used*/ 00060 extern IPC::Lock::lock_t lock_ZeroVirtFrame; 00061 extern void *ZeroVirtFrame; 00062 00063 extern class Memory::zone free_pages_high ; /*all pages in the high area, to be allocated*/ 00064 extern class Memory::zone free_pages_low; /*all pages in the low area, to be allocated*/ 00065 00066 const uint32 PAGESCLEANMAX = 0x20; //how many pages may be stored at a time, in the buffer 00067 extern class Memory::zone zero_pages_high ; /*all pages in the high area, to be allocated, which have already been cleared*/ 00068 extern class Memory::zone zero_pages_low; /*all pages in the low area, to be allocated, which have already been cleared*/ 00069 00070 00071 addr_t ballocate (size_t size, uint32 alignment); /*bootup malloc: virtual allocs on the heap space*/ 00072 void disable_balloc(); /*disable it*/ 00073 00074 /*======================free pages allocation*/ 00075 addr_t allocate_page_high (uint32 cnt); /*allocate from the upper pool*/ 00076 addr_t allocate_page_low (uint32 cnt); /*allocate from the lower pool*/ 00077 addr_t alloc4kDirty_high(uint32 cnt); /*reads a page from the dirty list, zeroes it*/ 00078 addr_t alloc4kDirty_low(uint32 cnt); /*reads a page from the dirty list, zeroes it*/ 00079 int free_page_high(addr_t physical); /*free a page to upper pool*/ 00080 int free_page_low(addr_t physical); /*free a page to lower pool*/ 00081 00082 /*=====================memory capacity*/ 00083 size_t get_memory_size(); /*returns all mem*/ 00084 size_t get_high_memory_size(); /*returns above 1Mib*/ 00085 00086 }; /*namespace Physical*/ 00087 }; /*namespace Memory*/ 00088 00089 int disalloc4k(addr_t physical); /*free a page; the page is then saved to the dirty page list*/ 00090 addr_t alloc4k(uint32 cnt,bool fatal); /*get me a page! if fatal, will panic on out-of-memory. allocates a clean page*/ 00091 00092 #endif