config: add CONFIG_PAGE_SIZE and CONFIG_INIT_PAGE_SIZE
This commit is contained in:
@ -60,16 +60,16 @@ static void add_physical_memory(void *start, void *end) {
|
||||
|
||||
//If region starts at 0x0, make it start at next page to not screw up null pointer detection, etc.
|
||||
if (start == 0)
|
||||
start = (char *)start + MM_PAGE_SIZE;
|
||||
start = (char *)start + CONFIG_PAGE_SIZE;
|
||||
|
||||
//make sure both start and end address are aligned to the size of a page
|
||||
if ((arch_uint_ptr)start % MM_PAGE_SIZE != 0)
|
||||
start = (char*)start + (MM_PAGE_SIZE - ((arch_uint_ptr)start % MM_PAGE_SIZE));
|
||||
if (((arch_uint_ptr)end + 1) % MM_PAGE_SIZE != 0)
|
||||
end = (char*)end - ((arch_uint_ptr)end + 1) % MM_PAGE_SIZE;
|
||||
if ((arch_uint_ptr)start % CONFIG_PAGE_SIZE != 0)
|
||||
start = (char*)start + (CONFIG_PAGE_SIZE - ((arch_uint_ptr)start % CONFIG_PAGE_SIZE));
|
||||
if (((arch_uint_ptr)end + 1) % CONFIG_PAGE_SIZE != 0)
|
||||
end = (char*)end - ((arch_uint_ptr)end + 1) % CONFIG_PAGE_SIZE;
|
||||
|
||||
if ((char *)end + 1 - (char *)start < MM_PAGE_SIZE<<1) {
|
||||
print("Error: Supplied memory area(%x,%x) is smaller than the page size (%d)\n", (arch_uint_ptr)start, (arch_uint_ptr)end, MM_PAGE_SIZE);
|
||||
if ((char *)end + 1 - (char *)start < CONFIG_PAGE_SIZE<<1) {
|
||||
print("Error: Supplied memory area(%x,%x) is smaller than the page size (%d)\n", (arch_uint_ptr)start, (arch_uint_ptr)end, CONFIG_PAGE_SIZE);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -78,13 +78,13 @@ static void add_physical_memory(void *start, void *end) {
|
||||
|
||||
//TODO we're potentially losing memory here because we're calculating
|
||||
//the number of page structs we need even for those pages that will contain only page structs
|
||||
num_pages = ((char *)end + 1 - (char *)start) / MM_PAGE_SIZE;
|
||||
usable_pages = num_pages - num_pages * sizeof(struct frame) / MM_PAGE_SIZE;
|
||||
if (num_pages * sizeof(struct frame) % MM_PAGE_SIZE)
|
||||
num_pages = ((char *)end + 1 - (char *)start) / CONFIG_PAGE_SIZE;
|
||||
usable_pages = num_pages - num_pages * sizeof(struct frame) / CONFIG_PAGE_SIZE;
|
||||
if (num_pages * sizeof(struct frame) % CONFIG_PAGE_SIZE)
|
||||
usable_pages--;
|
||||
|
||||
p = (struct frame *)start;
|
||||
for (page = ((char *)start) + (num_pages - usable_pages)*MM_PAGE_SIZE; page < end; page = (void *)(((char *)page) + MM_PAGE_SIZE)) {
|
||||
for (page = ((char *)start) + (num_pages - usable_pages)*CONFIG_PAGE_SIZE; page < end; page = (void *)(((char *)page) + CONFIG_PAGE_SIZE)) {
|
||||
p->address = page;
|
||||
insert_page_frame(p);
|
||||
p++;
|
||||
@ -115,7 +115,7 @@ struct frame* get_free_frames(unsigned int power) {
|
||||
for (it2 = container(it->list.next, struct frame, list);
|
||||
it2->list.next != &free_frames_list && curr_pages < num_pages;
|
||||
it2 = container(it2->list.next, struct frame, list)) {
|
||||
if ((char*)it2->address != (char*)container(it2->list.prev, struct frame, list)->address + MM_PAGE_SIZE) {
|
||||
if ((char*)it2->address != (char*)container(it2->list.prev, struct frame, list)->address + CONFIG_PAGE_SIZE) {
|
||||
it = it2; //fast-forward 'it' to start of next contiguous section of pages
|
||||
break;
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user