10 /* A free page owned by the page allocator. */
13 struct page *next; /* Next free page, or null at end of chain. */
16 static struct page *free_pages;
17 static uint8_t *uninit_start, *uninit_end;
22 /* Kernel static code and data, in 4 kB pages.
24 We can figure this out because the linker records the start
25 and end of the kernel as _start and _end. See
27 extern char _start, _end;
29 kernel_pages = (&_end - &_start + 4095) / 4096;
31 /* Then we know how much is available to allocate. */
32 uninit_start = ptov (LOADER_KERN_BASE + kernel_pages * PGSIZE);
33 uninit_end = ptov (ram_pages * PGSIZE);
37 palloc_get (enum palloc_flags flags)
41 if (free_pages == NULL && uninit_start < uninit_end)
43 palloc_free (uninit_start);
44 uninit_start += PGSIZE;
50 free_pages = page->next;
52 memset (page, 0, PGSIZE);
56 if (flags & PAL_ASSERT)
57 PANIC ("palloc_get: out of pages");
64 palloc_free (void *page_)
66 struct page *page = page_;
67 ASSERT((uintptr_t) page % PGSIZE == 0);
69 memset (page, 0xcc, PGSIZE);
71 page->next = free_pages;