/* NATKERNEL Memory — from Linux mm/ (4,158 functions) */ #include "../kernel.h" #define TOTAL_FRAMES (128*1024*1024/PAGE_SIZE) #define BITMAP_SZ (TOTAL_FRAMES/64) static u64 frame_map[BITMAP_SZ]; static u64 alloc_count; static inline int frame_free(u64 i) { return !(frame_map[i/64]&(1ULL<<(i%64))); } static inline void frame_set(u64 i, int used) { if(used)frame_map[i/64]|=(1ULL<<(i%64)); else frame_map[i/64]&=~(1ULL<<(i%64)); } u64 alloc_page(void) { for(u64 i=0;i