diff options
Diffstat (limited to 'paging.c')
-rw-r--r-- | paging.c | 30 |
1 files changed, 17 insertions, 13 deletions
@@ -122,7 +122,7 @@ struct section_node void *owner; // 0 if free, 1 if used by kernel, 2 if split to pages // it's actually a 2-directional lists; - // end of list is marked by reference to itself; + // end of list is marked by reference to SECTION_NULL; // we use offsets into sections_list array instead of pointers; uint16_t prev, next; }; @@ -133,7 +133,7 @@ static uint16_t all_sections_count, kernel_sections_count, split_sections_count, free_sections_count; -// those are undefined when the corresponding count is 0; +// those are SECTION_NULL when the corresponding count is 0; static uint16_t first_free_section, first_kernel_section, first_split_section; @@ -146,11 +146,13 @@ void setup_pager_structures(uint32_t available_mem) sections_list = (struct section_node*) SECTIONS_LIST_START; + first_split_section = SECTION_NULL; + for (uint16_t i = 0; i < kernel_sections_count; i++) sections_list[i] = (struct section_node) { .owner = OWNER_KERNEL, - .prev = i == 0 ? i : i - 1, - .next = i == kernel_sections_count - 1 ? i : i + 1 + .prev = i == 0 ? SECTION_NULL : i - 1, + .next = i == kernel_sections_count - 1 ? SECTION_NULL : i + 1 }; first_kernel_section = 0; @@ -159,8 +161,8 @@ void setup_pager_structures(uint32_t available_mem) i < all_sections_count; i++) sections_list[i] = (struct section_node) { .owner = OWNER_FREE, - .prev = i == kernel_sections_count ? i : i - 1, - .next = i == all_sections_count - 1 ? i : i + 1 + .prev = i == kernel_sections_count ? SECTION_NULL : i - 1, + .next = i == all_sections_count - 1 ? SECTION_NULL : i + 1 }; first_free_section = kernel_sections_count; @@ -170,11 +172,11 @@ void setup_pager_structures(uint32_t available_mem) puts(" free sections left for use"); } -// return section number or CLAIM_FAILURE in case of failure +// return section number or SECTION_NULL in case of failure static uint16_t claim_section(void *owner) { if (!free_sections_count) - return CLAIM_FAILURE; // failure + return SECTION_NULL; // failure uint16_t section = first_free_section; @@ -183,10 +185,12 @@ static uint16_t claim_section(void *owner) uint16_t next; next = sections_list[section].next; - sections_list[next].prev = next; + sections_list[next].prev = SECTION_NULL; first_free_section = next; } + else + first_free_section = SECTION_NULL; if (owner == OWNER_KERNEL) { @@ -194,7 +198,7 @@ static uint16_t claim_section(void *owner) sections_list[section] = (struct section_node) { .owner = owner, - .prev = section, + .prev = SECTION_NULL, .next = first_kernel_section }; @@ -205,8 +209,8 @@ static uint16_t claim_section(void *owner) else sections_list[section] = (struct section_node) { .owner = owner, - .prev = section, - .next = section + .prev = SECTION_NULL, + .next = SECTION_NULL }; return section; @@ -218,7 +222,7 @@ uint16_t claim_and_map_section { uint16_t section = claim_section(owner); - if (section == CLAIM_FAILURE) + if (section == SECTION_NULL) return section; short_section_descriptor_t volatile *section_entry = |