Skip to content

Commit

Permalink
Merge pull request #37 from chaos4ever/feature/support-larger-servers
Browse files Browse the repository at this point in the history
Support larger servers than a few megabytes (don't hardwire physical AVL tree location)
  • Loading branch information
perlun committed May 24, 2015
2 parents 4fbb115 + 327397d commit 0d69991
Show file tree
Hide file tree
Showing 10 changed files with 101 additions and 98 deletions.
3 changes: 2 additions & 1 deletion storm/generic/avl.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

// Given a new node, this function sets all properties for the node.
void avl_node_reset(avl_node_type *node, unsigned int start, unsigned int busy_length, unsigned int free_length,
avl_node_type *parent)
avl_node_type *parent, const char *description)
{
node->start = start;
node->busy_length = busy_length;
Expand All @@ -32,6 +32,7 @@ void avl_node_reset(avl_node_type *node, unsigned int start, unsigned int busy_l
node->balance = 0;
node->largest_free_less = 0;
node->largest_free_more = 0;
node->description = description;
}

// Find a free node in the entry bitmap. This function is also responsible for growing the tree when needed.
Expand Down
6 changes: 3 additions & 3 deletions storm/ia32/memory_global.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ void memory_global_init(void)

// Initialise the tree, starting with an empty entry.
avl_node_reset(global_avl_header->root, GET_PAGE_NUMBER(BASE_GLOBAL_HEAP),
0, SIZE_IN_PAGES(SIZE_GLOBAL_HEAP), NULL);
0, SIZE_IN_PAGES(SIZE_GLOBAL_HEAP), NULL, "Unallocated global memory");

// And mark that entry as used in the bitmap.
global_avl_header->bitmap[0] = 1;
Expand All @@ -88,7 +88,7 @@ void memory_global_init(void)
global_slab_heap = (slab_heap_type *) (memory_global_allocate_page(1) * SIZE_PAGE);

// FIXME: Check return value.
memory_physical_allocate(&physical_page, 1, "Global SLAB heap.");
memory_physical_allocate(&physical_page, 1, "Global SLAB heap physical page.");

memory_virtual_map(GET_PAGE_NUMBER(global_slab_heap), physical_page, 1, PAGE_KERNEL);
slab_heap_init(global_slab_heap);
Expand Down Expand Up @@ -139,7 +139,7 @@ static u32 memory_global_allocate_page(u32 length)
insert_node = avl_node_allocate(global_avl_header);

avl_node_reset(insert_node, node->start + node->busy_length,
length, node->free_length - length, NULL);
length, node->free_length - length, NULL, "Global memory");

node->free_length = 0;
avl_update_tree_largest_free(node->parent);
Expand Down
53 changes: 26 additions & 27 deletions storm/ia32/memory_physical.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
#include <storm/generic/thread.h>
#include <storm/generic/types.h>

u32 page_avl_base = BASE_PAGE_AVL;
u32 page_avl_base;
avl_header_type *page_avl_header;
u32 pages_left, physical_pages;
u32 page_avl_pages;
Expand All @@ -56,8 +56,11 @@ void memory_physical_init(void)
page_avl_array_pages = SIZE_IN_PAGES(sizeof(avl_node_type) * physical_pages);
page_avl_pages = page_avl_intro_pages + page_avl_array_pages;

// As demonstrated here, the AVL system is placed at the very end of the physical memory.
page_avl_base = (physical_pages - page_avl_pages) * SIZE_PAGE;

// Put the AVL header where it should be.
page_avl_header = (avl_header_type *)(page_avl_base);
page_avl_header = (avl_header_type *) page_avl_base;

// Fill in the values in the AVL header.
page_avl_header->limit_nodes = physical_pages;
Expand All @@ -75,58 +78,51 @@ void memory_physical_init(void)
memory_set_u8((u8 *) page_avl_header->bitmap, 0, physical_pages / 8);

// Initialise the tree. All memory is free.
avl_node_reset(page_avl_header->root, 0, 0, physical_pages, NULL);
avl_node_reset(page_avl_header->root, 0, 0, physical_pages, NULL, "Unallocated physical memory");

// And mark that entry as used in the bitmap.
page_avl_header->bitmap[0] = 1;

// Now, let's do it like they do on the discovery channel. Mark the reserved memory as reserved.
memory_physical_reserve(GET_PAGE_NUMBER(BASE_GDT), SIZE_IN_PAGES(SIZE_GDT_IDT));
memory_physical_reserve(GET_PAGE_NUMBER(BASE_KERNEL_TSS), SIZE_IN_PAGES(SIZE_KERNEL_TSS));
memory_physical_reserve(GET_PAGE_NUMBER(BASE_KERNEL_STACK), SIZE_IN_PAGES(SIZE_KERNEL_STACK));
memory_physical_reserve(GET_PAGE_NUMBER(BASE_MODULE_NAME), SIZE_IN_PAGES(SIZE_MODULE_NAME));
memory_physical_reserve(GET_PAGE_NUMBER(BASE_GDT), SIZE_IN_PAGES(SIZE_GDT_IDT), "IDT");
memory_physical_reserve(GET_PAGE_NUMBER(BASE_KERNEL_TSS), SIZE_IN_PAGES(SIZE_KERNEL_TSS), "Kernel TSS");
memory_physical_reserve(GET_PAGE_NUMBER(BASE_KERNEL_STACK), SIZE_IN_PAGES(SIZE_KERNEL_STACK), "Kernel stack");
memory_physical_reserve(GET_PAGE_NUMBER(BASE_MODULE_NAME), SIZE_IN_PAGES(SIZE_MODULE_NAME), "Module names");

// Reserve the memory for the kernel.
memory_physical_reserve(GET_PAGE_NUMBER(BASE_KERNEL), SIZE_IN_PAGES((u32) &_end - BASE_KERNEL));
memory_physical_reserve(GET_PAGE_NUMBER(BASE_KERNEL), SIZE_IN_PAGES((u32) &_end - BASE_KERNEL), "Kernel code and data");

// If we have more than 16 megs of RAM, we need to allocate DMA buffers to avoid lots of trouble later.
// FIXME: Should be configurable via command line switch too.
DEBUG_MESSAGE(DEBUG, "Reserving memory for DMA...");

// FIXME: For now, we have to do this unconditionally.
// if (physical_pages * SIZE_PAGE > 16 * MB)
{
memory_physical_reserve(GET_PAGE_NUMBER(BASE_DMA), SIZE_IN_PAGES(SIZE_DMA));
memory_physical_reserve(GET_PAGE_NUMBER(BASE_DMA), SIZE_IN_PAGES(SIZE_DMA), "DMA");
}

// The memory between 640k and 1024k are 'reserved' for various ISA plug in cards and other junk. Nevertheless, if
// we mess with it, it may mess with us, so we'd better not.
DEBUG_MESSAGE(DEBUG, "Reserving high memory...");

memory_physical_reserve(GET_PAGE_NUMBER(BASE_UPPER), SIZE_IN_PAGES(SIZE_UPPER));
memory_physical_reserve(GET_PAGE_NUMBER(BASE_UPPER), SIZE_IN_PAGES(SIZE_UPPER), "High memory");

// Reserve the memory used by the AVL system.
DEBUG_MESSAGE(DEBUG, "Reserving physical memory AVL-data...");

memory_physical_reserve(GET_PAGE_NUMBER((u32) page_avl_header), page_avl_pages);
memory_physical_reserve(GET_PAGE_NUMBER(page_avl_base), page_avl_pages, "Physical memory AVL data");

// And of course the server images too.
DEBUG_MESSAGE(DEBUG, "Reserving memory for servers...");

for (counter = 0; counter < multiboot_info.number_of_modules; counter++)
{
memory_physical_reserve(GET_PAGE_NUMBER(multiboot_module_info[counter].start),
SIZE_IN_PAGES(multiboot_module_info[counter].end - multiboot_module_info[counter].start));
SIZE_IN_PAGES(multiboot_module_info[counter].end - multiboot_module_info[counter].start), multiboot_module_info[counter].name);
}
}

// Reserve a region, so it won't get allocated later.
return_type memory_physical_reserve(unsigned int start, unsigned int length)
return_type memory_physical_reserve(unsigned int start, unsigned int length, const char *description)
{
avl_node_type *node = page_avl_header->root;
avl_node_type *insert_node;

DEBUG_MESSAGE(DEBUG, "start = %u, length = %u", start, length);
DEBUG_MESSAGE(DEBUG, "Reserving from 0x%x to 0x%x for %s", start * SIZE_PAGE, ((start + length) * SIZE_PAGE) - 1,
description);

#ifdef CHECK
avl_debug_tree_check(page_avl_header, page_avl_header->root);
Expand All @@ -151,8 +147,8 @@ return_type memory_physical_reserve(unsigned int start, unsigned int length)
((start + length) <= (node->start + node->busy_length + node->free_length)))
{
insert_node = avl_node_allocate(page_avl_header);
avl_node_reset(insert_node, start, length,
node->start + node->busy_length + node->free_length - start - length, NULL);
avl_node_reset(insert_node, start, length, node->start + node->busy_length + node->free_length - start - length,
NULL, description);

node->free_length = start - node->start - node->busy_length;

Expand All @@ -172,7 +168,8 @@ return_type memory_physical_reserve(unsigned int start, unsigned int length)
else
{
// I smell something rotten in the land of England...
DEBUG_HALT("You tried to reserve something that was already taken.");
DEBUG_HALT("You tried to reserve %u pages starting at 0x%x, but they are already taken by %s", length,
start * SIZE_PAGE, node->description);
return RETURN_PAGE_NOT_FOUND;
}
}
Expand All @@ -182,7 +179,7 @@ return_type memory_physical_reserve(unsigned int start, unsigned int length)
}

// Allocate some pages.
return_type memory_physical_allocate(u32 *page, unsigned int length, char *description UNUSED)
return_type memory_physical_allocate(u32 *page, unsigned int length, const char *description)
{
avl_node_type *node = page_avl_header->root;
avl_node_type *insert_node;
Expand Down Expand Up @@ -227,6 +224,7 @@ return_type memory_physical_allocate(u32 *page, unsigned int length, char *descr
{
node->busy_length = length;
node->free_length -= length;
node->description = description;

DEBUG_MESSAGE(DEBUG, "Special case!\n");

Expand All @@ -246,7 +244,8 @@ return_type memory_physical_allocate(u32 *page, unsigned int length, char *descr
else
{
insert_node = avl_node_allocate(page_avl_header);
avl_node_reset(insert_node, node->start + node->busy_length, length, node->free_length - length, NULL);
avl_node_reset(insert_node, node->start + node->busy_length, length, node->free_length - length, NULL,
description);
// debug_print ("evald = %u\n", node->start + node->busy_length);

node->free_length = 0;
Expand Down
Loading

0 comments on commit 0d69991

Please sign in to comment.