int paging_init(uint32_t mem_size) { uint64_t mem_end = (uint64_t)mem_size * 1024ULL; frames_count = (uint32_t)(mem_end / 0x1000ULL); frames = (uint32_t*)static_alloc(BIT_INDEX(frames_count)); memset(frames, 0, BIT_INDEX(frames_count)); /* Create kernel page directory. */ kernel_directory = static_alloc(sizeof(*kernel_directory)); memset(kernel_directory, 0, sizeof(*kernel_directory)); /* Identity map pages up to heap address. We make the first page non-present so that NULL-pointer dereferences cause * a page fault. */ frame_alloc(page_get(0, kernel_directory, true), 0); uint32_t i = 0; for (i = PAGE_SIZE; i < heap_addr; i += PAGE_SIZE) { frame_alloc(page_get(i, kernel_directory, true), PAGE_FLAGS_PRESENT); } /* Map pages for the heap. */ for (; i < HEAP_ADDRESS + HEAP_SIZE_INIT; i += PAGE_SIZE) { page_get(i, kernel_directory, true); } /* Set page fault handler. */ set_interrupt_handler(ISR_PAGE_FAULT, page_fault_handler); page_directory_load(kernel_directory); page_enable(); return 0; }
void uri_error(int size_hint, char* fmt, va_alist) #endif { va_list ap; #if HAVE_STDARG_H va_start(ap, fmt); #else va_start(ap); #endif static_alloc(&uri_errstr, &uri_errstr_size, 512 + size_hint); vsprintf(uri_errstr, fmt, ap); if(uri_modep(URI_MODE_ERROR_STDERR)) fprintf(stderr, "uri: %s", uri_errstr); va_end(ap); }