More changes for cleaner initialization and support for containers.

This commit is contained in:
Bahadir Balban
2009-07-25 17:44:29 +03:00
parent ba1cc0c6bc
commit f7b768ee16
17 changed files with 247 additions and 149 deletions

View File

@@ -4,7 +4,7 @@
Import('env')
# The set of source files associated with this SConscript file.
src_local = ['physmem.c', 'irq.c', 'scheduler.c', 'time.c', 'tcb.c', 'pgalloc.c', 'kmalloc.c', 'space.c']
src_local = ['physmem.c', 'irq.c', 'scheduler.c', 'time.c', 'tcb.c', 'pgalloc.c', 'kmalloc.c', 'space.c', 'bootm.c']
obj = env.Object(src_local)
Return('obj')

52
src/generic/bootm.c Normal file
View File

@@ -0,0 +1,52 @@
/*
* Boot memory allocator
*
* Copyright (C) 2009 Bahadir Balban
*/
#include INC_ARCH(linker.h)
#include INC_GLUE(memory.h)
#include <l4/lib/printk.h>
/* All memory allocated here is discarded after boot */
#define BOOTMEM_SIZE SZ_32K
SECTION(".init.pgd") pgd_table_t init_pgd;
SECTION(".init.bootmem") char bootmem[BOOTMEM_SIZE];
static unsigned long cursor = (unsigned long)&bootmem;
void *alloc_bootmem(int size, int alignment)
{
void *ptr;
/* If alignment is required */
if (alignment) {
/* And cursor is not aligned */
if (!is_aligned(cursor, alignment))
/* Align the cursor to alignment */
cursor = align_up(cursor, alignment);
}
/* Allocate from cursor */
ptr = (void *)cursor;
/* Update cursor */
cursor += size;
/* Check if cursor is passed bootmem area */
if (cursor >= (unsigned long)&bootmem[BOOTMEM_SIZE]) {
printk("Fatal: Insufficient boot memory.\n");
BUG();
}
return ptr;
}
pmd_table_t *alloc_boot_pmd(void)
{
return alloc_bootmem(sizeof(pmd_table_t), sizeof(pmd_table_t));
}

56
src/generic/kresource.c Normal file
View File

@@ -0,0 +1,56 @@
/*
* Initialize system resource management.
*
* Copyright (C) 2009 Bahadir Balban
*/
/*
* Here are the steps used to initialize system resources:
*
* Check total physical memory
* Check container memory capabilities
* Find biggest unused physical memory region
* Calculate how much memory is used by all containers
* Initialize a slab-like allocator for all resources.
* Copy boot allocations to real allocations accounted to containers and kernel.
* E.g. initial page table may become page table of a container pager.
* First few pmds used belong to kernel usage, etc.
* Delete all boot memory and add it to physical memory pool.
*/
#define MEM_FLAGS_VIRTUAL (1 << 0)
#define MEM_AREA_CACHED (1 << 1)
struct mem_area {
struct link list;
l4id_t mid;
unsigned long start;
unsigned long end;
unsigned long npages;
unsigned long flags;
};
void init_system_resources()
{
struct mem_area *physmem = alloc_bootmem(sizeof(physmem), 4);
struct mem_area *kernel_used = alloc_bootmem(sizeof(physmem), 4);
/* Initialize the first memory descriptor for total physical memory */
physmem.start = PHYS_MEM_START;
physmem.end = PHYS_MEM_END;
physmem.mid = 0;
physmem.npages = (physmem.end - physmem.start) >> PAGE_BITS;
/* Figure out current kernel usage */
kernel_used.start = virt_to_phys(_kernel_start);
kernel_used.end = virt_to_phys(_kernel_end);
/* Figure out each container's physical memory usage */
for (int i = 0; i < containers->total; i++) {
}
}

View File

@@ -152,12 +152,7 @@ void *alloc_page(void)
void *alloc_pmd(void)
{
pmd_table_t *pmd;
if (!(pmd = alloc_boot_pmd()))
pmd = pgalloc_from_cache(PGALLOC_PMD_CACHE);
return pmd;
return pgalloc_from_cache(PGALLOC_PMD_CACHE);
}
void *alloc_pgd(void)