Container/Pager/Capability initialization that works.

Need to safely free boot memory and jump to first task's stack.
Need to test scheduler and all syscall entries.
This commit is contained in:
Bahadir Balban
2009-08-04 13:56:11 +03:00
parent 7e8845abf8
commit 519bfba8c7
12 changed files with 150 additions and 126 deletions

View File

@@ -8,6 +8,7 @@
#include INC_ARCH(linker.h)
#include INC_GLUE(memory.h)
#include <l4/lib/printk.h>
#include <l4/generic/space.h>
/* All memory allocated here is discarded after boot */
@@ -15,6 +16,7 @@
SECTION(".init.pgd") pgd_table_t init_pgd;
SECTION(".init.bootmem") char bootmem[BOOTMEM_SIZE];
SECTION(".init.data") struct address_space init_space;
static unsigned long cursor = (unsigned long)&bootmem;

View File

@@ -144,6 +144,10 @@ int container_init(struct container *c)
init_ktcb_list(&c->ktcb_list);
init_mutex_queue_head(&c->mutex_queue_head);
/* Ini pager structs */
for (int i = 0; i < CONFIG_MAX_PAGERS_USED; i++) {
cap_list_init(&c->pager[i].cap_list);
}
/* Init scheduler */
sched_init(&c->scheduler);
@@ -166,6 +170,11 @@ void kcont_insert_container(struct container *c,
kcont->containers.ncont++;
}
/*
* This searches pager capabilities and if it has a virtual memory area
* defined as a UTCB, uses the first entry as its utcb. If not, it is
* not an error, perhaps another pager will map its utcb.
*/
void task_setup_utcb(struct ktcb *task, struct pager *pager)
{
struct capability *cap;
@@ -177,10 +186,30 @@ void task_setup_utcb(struct ktcb *task, struct pager *pager)
(cap->access & CAP_MAP_UTCB)) {
/* Use first address slot as pager's utcb */
task->utcb_address = __pfn_to_addr(cap->start);
return;
}
}
}
#if 0
void switch_stack(struct ktcb *task)
{
register u32 stack asm("sp");
register u32 fp asm("fp");
register u32 newstack = align((unsigned long)task + PAGE_SIZE, sizeof(short));
signed long long offset = newstack - __bootstack;
fp += offset;
sp += offset;
/* Copy stack contents to new stack */
memcpy(&newstack, __bootstack, stack - __bootstack);
/* Switch to new stack */
}
#endif
/*
* TODO:
*

View File

@@ -85,18 +85,6 @@ void free_user_mutex(void *addr)
BUG_ON(mem_cache_free(kernel_container.mutex_cache, addr) < 0);
}
void cap_list_init(struct cap_list *clist)
{
clist->ncaps = 0;
link_init(&clist->caps);
}
void cap_list_insert(struct capability *cap, struct cap_list *clist)
{
list_insert(&cap->list, &clist->caps);
clist->ncaps++;
}
/*
* This splits a capability, splitter region must be in
* the *middle* of original capability
@@ -252,6 +240,9 @@ void init_kernel_container(struct kernel_container *kcont)
kcont->mutex_ids.nwords = SYSTEM_IDS_MAX;
kcont->capability_ids.nwords = SYSTEM_IDS_MAX;
/* Initialize container head */
container_head_init(&kcont->containers);
/* Get first container id for itself */
kcont->cid = id_new(&kcont->container_ids);
@@ -305,9 +296,9 @@ int copy_pager_info(struct pager *pager, struct pager_info *pinfo)
struct capability *cap;
struct cap_info *cap_info;
pager->start_lma = pinfo->pager_lma;
pager->start_vma = pinfo->pager_vma;
pager->memsize = pinfo->pager_size;
pager->start_lma = __pfn_to_addr(pinfo->pager_lma);
pager->start_vma = __pfn_to_addr(pinfo->pager_vma);
pager->memsize = __pfn_to_addr(pinfo->pager_size);
/* Copy all cinfo structures into real capabilities */
for (int i = 0; i < pinfo->ncaps; i++) {
@@ -353,6 +344,10 @@ void setup_containers(struct boot_resources *bootres,
/*
* Move to real page tables, accounted by
* pgds and pmds provided from the caches
*
* We do not want to delay this too much,
* since we want to avoid allocating an uncertain
* amount of memory from the boot allocators.
*/
current_pgd = realloc_page_tables();
@@ -372,10 +367,51 @@ void setup_containers(struct boot_resources *bootres,
container_init_pagers(kcont, current_pgd);
}
void setup_capabilities(struct boot_resources *bootres,
struct kernel_container *kcont)
/*
* Copy boot-time allocated kernel capabilities to ones that
* are allocated from the capability memcache
*/
void copy_boot_capabilities(struct cap_list *caplist)
{
struct capability *bootcap, *n, *realcap;
/* For every bootmem-allocated capability */
list_foreach_removable_struct(bootcap, n,
&caplist->caps,
list) {
/* Create new one from capability cache */
realcap = capability_create();
/* Copy all fields except id to real */
realcap->owner = bootcap->owner;
realcap->resid = bootcap->resid;
realcap->type = bootcap->type;
realcap->access = bootcap->access;
realcap->start = bootcap->start;
realcap->end = bootcap->end;
/* Unlink boot one */
list_remove(&bootcap->list);
/* Add real one to head */
list_insert(&realcap->list,
&caplist->caps);
}
}
/*
* Creates capabilities allocated with a real id, and from the
* capability cache, in place of ones allocated at boot-time.
*/
void kcont_setup_capabilities(struct boot_resources *bootres,
struct kernel_container *kcont)
{
copy_boot_capabilities(&kcont->physmem_used);
copy_boot_capabilities(&kcont->physmem_free);
copy_boot_capabilities(&kcont->virtmem_used);
copy_boot_capabilities(&kcont->virtmem_free);
copy_boot_capabilities(&kcont->devmem_used);
copy_boot_capabilities(&kcont->devmem_free);
}
/*
@@ -412,9 +448,9 @@ struct mem_cache *init_resource_cache(int nstruct, int struct_size,
page_align_up(bufsize),
MAP_SVC_RW_FLAGS);
} else {
add_mapping(__pfn_to_addr(cap->start),
virtual, page_align_up(bufsize),
MAP_SVC_RW_FLAGS);
add_mapping_pgd(__pfn_to_addr(cap->start),
virtual, page_align_up(bufsize),
MAP_SVC_RW_FLAGS, &init_pgd);
}
/* Unmap area from memcap */
memcap_unmap_range(cap, &kcont->physmem_free,
@@ -425,7 +461,7 @@ struct mem_cache *init_resource_cache(int nstruct, int struct_size,
/* Initialize the cache */
return mem_cache_init((void *)virtual, bufsize,
struct_size, 1);
struct_size, aligned);
}
}
return 0;
@@ -602,6 +638,7 @@ int setup_boot_resources(struct boot_resources *bootres,
return 0;
}
/*
* FIXME: Add error handling
*
@@ -612,6 +649,7 @@ int setup_boot_resources(struct boot_resources *bootres,
*/
int init_system_resources(struct kernel_container *kcont)
{
/* FIXME: Count kernel resources */
struct boot_resources bootres;
memset(&bootres, 0, sizeof(bootres));
@@ -623,8 +661,8 @@ int init_system_resources(struct kernel_container *kcont)
/* Create system containers */
setup_containers(&bootres, kcont);
/* Create capabilities */
setup_capabilities(&bootres, kcont);
/* Create real capabilities */
kcont_setup_capabilities(&bootres, kcont);
return 0;
}

View File

@@ -209,7 +209,7 @@ void sched_resume_sync(struct ktcb *task)
BUG_ON(task == current);
task->state = TASK_RUNNABLE;
sched_rq_add_task(task,
curcont->scheduler.rq_runnable,
task->container->scheduler.rq_runnable,
RQ_ADD_FRONT);
schedule();
}
@@ -223,7 +223,9 @@ void sched_resume_sync(struct ktcb *task)
void sched_resume_async(struct ktcb *task)
{
task->state = TASK_RUNNABLE;
sched_rq_add_task(task, curcont->scheduler.rq_runnable, RQ_ADD_FRONT);
sched_rq_add_task(task,
task->container->scheduler.rq_runnable,
RQ_ADD_FRONT);
}
/*

View File

@@ -130,11 +130,13 @@ struct ktcb *tcb_find(l4id_t tid)
void tcb_add(struct ktcb *new)
{
spin_lock(&curcont->ktcb_list.list_lock);
struct container *c = new->container;
spin_lock(&c->ktcb_list.list_lock);
BUG_ON(!list_empty(&new->task_list));
BUG_ON(!++curcont->ktcb_list.count);
list_insert(&new->task_list, &curcont->ktcb_list.list);
spin_unlock(&curcont->ktcb_list.list_lock);
BUG_ON(!++c->ktcb_list.count);
list_insert(&new->task_list, &c->ktcb_list.list);
spin_unlock(&c->ktcb_list.list_lock);
}
void tcb_remove(struct ktcb *new)