mirror of
https://github.com/drasko/codezero.git
synced 2026-03-02 18:43:16 +01:00
Incorporated means to specify shared memory, task address space and utcb regions to posix container
This commit is contained in:
@@ -20,24 +20,48 @@ def create_symlinks(arch):
|
||||
os.system("rm %s" % (arch_path2))
|
||||
os.system("ln -s %s %s" % ("arch-" + arch, arch_path2))
|
||||
|
||||
def generate_lma_lds(target, source, env):
|
||||
def generate_container_h(target, source, env):
|
||||
base_value_dict = {}
|
||||
with open(source[0].path, 'r') as ch_in:
|
||||
with open(target[0].path, 'w+') as ch_out:
|
||||
container_h = ch_in.read()
|
||||
assert container.pager_task_region_start != 0
|
||||
assert container.pager_task_region_end != 0
|
||||
assert container.pager_shm_region_start != 0
|
||||
assert container.pager_shm_region_end != 0
|
||||
assert container.pager_utcb_region_start != 0
|
||||
assert container.pager_utcb_region_end != 0
|
||||
|
||||
base_value_dict = { 'task_start' : conv_hex(container.pager_task_region_start), \
|
||||
'task_end' : conv_hex(container.pager_task_region_end), \
|
||||
'shmem_start' : conv_hex(container.pager_shm_region_start), \
|
||||
'shmem_end' : conv_hex(container.pager_shm_region_end), \
|
||||
'utcb_start' : conv_hex(container.pager_utcb_region_start), \
|
||||
'utcb_end' : conv_hex(container.pager_utcb_region_end) }
|
||||
ch_out.write(container_h % base_value_dict)
|
||||
|
||||
def generate_vma_lma_lds(target, source, env):
|
||||
with open(source[0].path, 'r') as lds_in:
|
||||
with open(target[0].path, 'w+') as lds_out:
|
||||
linker_script = lds_in.read()
|
||||
assert container.pager_lma != 0
|
||||
lds_out.write(linker_script % conv_hex(container.pager_lma))
|
||||
assert container.pager_vma != 0
|
||||
lds_out.write(linker_script % (conv_hex(container.pager_vma), \
|
||||
conv_hex(container.pager_lma)))
|
||||
|
||||
lma_lds = Command('include/linker.lds', 'include/linker.lds.in', generate_lma_lds)
|
||||
lma_lds = Command('include/linker.lds', 'include/linker.lds.in', generate_vma_lma_lds)
|
||||
|
||||
container_h = Command('include/container.h', 'include/container.h.in', generate_container_h)
|
||||
src = [Glob('*.c') + Glob('mm/*.c') + Glob('lib/*.c') + Glob('fs/*.c') + Glob('fs/memfs/*.c') + Glob('lib/elf/*.c') + Glob('mm/arch/*.c')]
|
||||
|
||||
e = env.Clone()
|
||||
|
||||
e.Append(LINKFLAGS = ['-T' + lma_lds[0].path, '-u_start'])
|
||||
e.Append(LIBS = 'posix')
|
||||
e.Append(CPPFLAGS = ' -include ' + container_h[0].path)
|
||||
objs = e.Object(src)
|
||||
mm0 = e.Program('mm0.elf', objs)
|
||||
|
||||
Depends(objs, container_h)
|
||||
Depends(mm0, lma_lds)
|
||||
Return('mm0')
|
||||
|
||||
|
||||
14
conts/posix/mm0/include/container.h.in
Normal file
14
conts/posix/mm0/include/container.h.in
Normal file
@@ -0,0 +1,14 @@
|
||||
#ifndef __MM0_CONTAINER_H__
|
||||
#define __MM0_CONTAINER_H__
|
||||
|
||||
#define SHMEM_REGION_START %(shmem_start)s
|
||||
#define SHMEM_REGION_END %(shmem_end)s
|
||||
|
||||
#define TASK_REGION_START %(task_start)s
|
||||
#define TASK_REGION_END %(task_end)s
|
||||
|
||||
#define UTCB_REGION_START %(utcb_start)s
|
||||
#define UTCB_REGION_END %(utcb_end)s
|
||||
|
||||
|
||||
#endif /* __MM0_CONTAINER_H__ */
|
||||
@@ -18,8 +18,6 @@
|
||||
#include <capability.h>
|
||||
|
||||
struct initdata {
|
||||
struct capability *bootcaps;
|
||||
struct capability *physmem;
|
||||
struct bootdesc *bootdesc;
|
||||
struct page_bitmap *page_map;
|
||||
unsigned long pager_utcb_virt;
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
/*
|
||||
* Linker script-defined memory markers.
|
||||
*/
|
||||
|
||||
extern unsigned long virtual_base[];
|
||||
extern unsigned long __start_text[];
|
||||
extern unsigned long __end_text[];
|
||||
extern unsigned long __start_data[];
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2007 - 2009 Bahadir Balban
|
||||
*/
|
||||
|
||||
virtual_base = 0xE0000000;
|
||||
virtual_base = %s;
|
||||
physical_base = %s;
|
||||
|
||||
pager_offset = virtual_base - physical_base;
|
||||
|
||||
@@ -228,7 +228,8 @@ int do_execve(struct tcb *sender, char *filename,
|
||||
return 0;
|
||||
}
|
||||
|
||||
int sys_execve(struct tcb *sender, char *pathname, char *argv[], char *envp[])
|
||||
int sys_execve(struct tcb *sender, char *pathname,
|
||||
char *argv[], char *envp[])
|
||||
{
|
||||
int ret;
|
||||
char *path;
|
||||
@@ -242,17 +243,19 @@ int sys_execve(struct tcb *sender, char *pathname, char *argv[], char *envp[])
|
||||
memset(&env, 0, sizeof(env));
|
||||
|
||||
/* Copy the executable path string */
|
||||
if ((ret = copy_user_string(sender, path, pathname, PATH_MAX)) < 0)
|
||||
if ((ret = copy_user_string(sender, path,
|
||||
pathname, PATH_MAX)) < 0)
|
||||
return ret;
|
||||
// printf("%s: Copied pathname: %s\n", __FUNCTION__, path);
|
||||
|
||||
/* Copy the args */
|
||||
if (argv && ((ret = copy_user_args(sender, &args, argv, ARGS_MAX)) < 0))
|
||||
if (argv && ((ret = copy_user_args(sender, &args,
|
||||
argv, ARGS_MAX)) < 0))
|
||||
goto out1;
|
||||
|
||||
/* Copy the env */
|
||||
if (envp && ((ret = copy_user_args(sender, &env, envp,
|
||||
ARGS_MAX - args.size)) < 0))
|
||||
ARGS_MAX - args.size))
|
||||
< 0))
|
||||
goto out2;
|
||||
|
||||
ret = do_execve(sender, path, &args, &env);
|
||||
|
||||
@@ -43,6 +43,13 @@ struct memdesc physmem; /* Initial, primitive memory descriptor */
|
||||
struct membank membank[1]; /* The memory bank */
|
||||
struct page *page_array; /* The physical page array based on mem bank */
|
||||
|
||||
struct container_memory_regions {
|
||||
struct capability *shmem;
|
||||
struct capability *utcb;
|
||||
struct capability *task;
|
||||
struct capability *pager;
|
||||
struct capability *physmem;
|
||||
} cont_mem_regions;
|
||||
|
||||
/* Capability descriptor list */
|
||||
struct cap_list capability_list;
|
||||
@@ -50,7 +57,6 @@ struct cap_list capability_list;
|
||||
__initdata static struct capability *caparray;
|
||||
__initdata static int total_caps = 0;
|
||||
|
||||
|
||||
void print_pfn_range(int pfn, int size)
|
||||
{
|
||||
unsigned int addr = pfn << PAGE_BITS;
|
||||
@@ -153,10 +159,11 @@ int pager_setup_task(void)
|
||||
}
|
||||
|
||||
/* Copy all init-memory allocated capabilities */
|
||||
void copy_boot_capabilities()
|
||||
void copy_boot_capabilities(int ncaps)
|
||||
{
|
||||
struct capability *cap;
|
||||
|
||||
link_init(&capability_list.caps);
|
||||
for (int i = 0; i < total_caps; i++) {
|
||||
cap = kzalloc(sizeof(struct capability));
|
||||
|
||||
@@ -167,14 +174,16 @@ void copy_boot_capabilities()
|
||||
link_init(&cap->list);
|
||||
|
||||
/* Add capability to global cap list */
|
||||
list_insert(&capability_list.caps, &cap->list);
|
||||
list_insert(&cap->list, &capability_list.caps);
|
||||
}
|
||||
capability_list.ncaps = ncaps;
|
||||
}
|
||||
|
||||
int read_pager_capabilities()
|
||||
{
|
||||
int ncaps;
|
||||
int err;
|
||||
struct capability *cap;
|
||||
|
||||
/* Read number of capabilities */
|
||||
if ((err = l4_capability_control(CAP_CONTROL_NCAPS,
|
||||
@@ -182,7 +191,9 @@ int read_pager_capabilities()
|
||||
printf("l4_capability_control() reading # of"
|
||||
" capabilities failed.\n Could not "
|
||||
"complete CAP_CONTROL_NCAPS request.\n");
|
||||
goto error;
|
||||
BUG();
|
||||
} else {
|
||||
printf("There are %d capabilities defined.\n", ncaps);
|
||||
}
|
||||
total_caps = ncaps;
|
||||
|
||||
@@ -195,33 +206,88 @@ int read_pager_capabilities()
|
||||
printf("l4_capability_control() reading of "
|
||||
"capabilities failed.\n Could not "
|
||||
"complete CAP_CONTROL_READ_CAPS request.\n");
|
||||
goto error;
|
||||
BUG();
|
||||
}
|
||||
|
||||
/* Set up initdata pointer to important capabilities */
|
||||
initdata.bootcaps = caparray;
|
||||
for (int i = 0; i < ncaps; i++) {
|
||||
/*
|
||||
* TODO: There may be multiple physmem caps!
|
||||
* This really needs to be considered as multiple
|
||||
* membanks!!!
|
||||
*/
|
||||
if ((caparray[i].type & CAP_RTYPE_MASK)
|
||||
== CAP_RTYPE_PHYSMEM) {
|
||||
initdata.physmem = &caparray[i];
|
||||
return 0;
|
||||
/* Copy them to real allocated structures */
|
||||
copy_boot_capabilities(ncaps);
|
||||
|
||||
memset(&cont_mem_regions, 0, sizeof(cont_mem_regions));
|
||||
|
||||
/* Set up pointers to important capabilities */
|
||||
list_foreach_struct(cap, &capability_list.caps, list) {
|
||||
/* Physical memory bank */
|
||||
if ((cap->type & CAP_RTYPE_MASK)
|
||||
== CAP_RTYPE_PHYSMEM)
|
||||
cont_mem_regions.physmem = cap;
|
||||
|
||||
/* Virtual regions */
|
||||
if ((cap->type & CAP_RTYPE_MASK)
|
||||
== CAP_RTYPE_VIRTMEM) {
|
||||
|
||||
printf("Capability range 0x%lx - 0x%lx\n",
|
||||
__pfn_to_addr(cap->start), __pfn_to_addr(cap->end));
|
||||
/* Pager address region (get from linker-defined) */
|
||||
if (__pfn_to_addr(cap->start)
|
||||
== (unsigned long)virtual_base)
|
||||
cont_mem_regions.pager = cap;
|
||||
|
||||
/* UTCB address region */
|
||||
else if (UTCB_REGION_START == __pfn_to_addr(cap->start)) {
|
||||
if (UTCB_REGION_END != __pfn_to_addr(cap->end)) {
|
||||
printf("FATAL: Region designated "
|
||||
"for UTCB allocation does not "
|
||||
"match on start/end marks");
|
||||
BUG();
|
||||
}
|
||||
|
||||
if (!(cap->access & CAP_MAP_UTCB_BIT)) {
|
||||
printf("FATAL: Region designated "
|
||||
"for UTCB allocation does not "
|
||||
"have UTCB map permissions");
|
||||
BUG();
|
||||
}
|
||||
cont_mem_regions.utcb = cap;
|
||||
}
|
||||
|
||||
/* Shared memory disjoint region */
|
||||
else if (SHMEM_REGION_START == __pfn_to_addr(cap->start)) {
|
||||
if (SHMEM_REGION_END != __pfn_to_addr(cap->end)) {
|
||||
printf("FATAL: Region designated "
|
||||
"for SHM allocation does not "
|
||||
"match on start/end marks");
|
||||
BUG();
|
||||
}
|
||||
|
||||
cont_mem_regions.shmem = cap;
|
||||
}
|
||||
|
||||
/* Task memory region */
|
||||
else if (TASK_REGION_START == __pfn_to_addr(cap->start)) {
|
||||
if (TASK_REGION_END != __pfn_to_addr(cap->end)) {
|
||||
printf("FATAL: Region designated "
|
||||
"for Task address space does not "
|
||||
"match on start/end marks");
|
||||
BUG();
|
||||
}
|
||||
cont_mem_regions.task = cap;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
printf("%s: Error, pager has no physmem "
|
||||
"capability defined.\n", __TASKNAME__);
|
||||
|
||||
goto error;
|
||||
if (!cont_mem_regions.task ||
|
||||
!cont_mem_regions.shmem ||
|
||||
!cont_mem_regions.utcb ||
|
||||
!cont_mem_regions.physmem ||
|
||||
!cont_mem_regions.pager) {
|
||||
printf("%s: Error, pager does not have one of the required"
|
||||
"mem capabilities defined. (TASK, SHM, PHYSMEM, UTCB)\n",
|
||||
__TASKNAME__);
|
||||
printf("%p, %p, %p, %p, %p\n", cont_mem_regions.task, cont_mem_regions.shmem, cont_mem_regions.utcb, cont_mem_regions.physmem, cont_mem_regions.pager);
|
||||
BUG();
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
error:
|
||||
BUG();
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -230,12 +296,6 @@ error:
|
||||
*/
|
||||
void release_initdata()
|
||||
{
|
||||
/*
|
||||
* Copy boot capabilities to a list of
|
||||
* real capabilities
|
||||
*/
|
||||
copy_boot_capabilities();
|
||||
|
||||
/* Free and unmap init memory:
|
||||
*
|
||||
* FIXME: We can and do safely unmap the boot
|
||||
@@ -397,14 +457,14 @@ void init_physmem_primary()
|
||||
/* Allocate page map structure */
|
||||
initdata.page_map =
|
||||
alloc_bootmem(sizeof(struct page_bitmap) +
|
||||
((initdata.physmem->end -
|
||||
initdata.physmem->start)
|
||||
((cont_mem_regions.physmem->end -
|
||||
cont_mem_regions.physmem->start)
|
||||
>> 5) + 1, 0);
|
||||
|
||||
/* Initialise page map from physmem capability */
|
||||
init_page_map(initdata.page_map,
|
||||
initdata.physmem->start,
|
||||
initdata.physmem->end);
|
||||
cont_mem_regions.physmem->start,
|
||||
cont_mem_regions.physmem->end);
|
||||
|
||||
/* Mark pager and other boot task areas as used */
|
||||
for (int i = 0; i < bootdesc->total_images; i++) {
|
||||
@@ -419,8 +479,8 @@ void init_physmem_primary()
|
||||
pfn_end - pfn_start, 1);
|
||||
}
|
||||
|
||||
physmem.start = initdata.physmem->start;
|
||||
physmem.end = initdata.physmem->end;
|
||||
physmem.start = cont_mem_regions.physmem->start;
|
||||
physmem.end = cont_mem_regions.physmem->end;
|
||||
|
||||
physmem.free_cur = pfn_images_end;
|
||||
physmem.free_end = physmem.end;
|
||||
|
||||
@@ -11,6 +11,8 @@ from tools.pyelf.lmanext import *
|
||||
|
||||
src = [Glob('*.c') + Glob('test_exec.S') + Glob('src/*.[Sc]') + Glob('src/arch/arm/*.c')]
|
||||
|
||||
container = next((c for c in config.containers if int(c.id) == int(contid)), None)
|
||||
|
||||
asm_string = \
|
||||
'''
|
||||
.align 4
|
||||
@@ -26,7 +28,7 @@ def generate_lma_lds(target, source, env):
|
||||
with open(source[1].path, 'r') as lds_in:
|
||||
with open(target[0].path, 'w+') as lds_out:
|
||||
linker_script = lds_in.read()
|
||||
lds_out.write(linker_script % next_available_lma(source[0].path))
|
||||
lds_out.write(linker_script % (container.pager_task_region_start, next_available_lma(source[0].path)))
|
||||
|
||||
lma_lds = Command('include/linker.lds', [previmage, 'include/linker.lds.in'], generate_lma_lds)
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
* Copyright (C) 2007 - 2009 Bahadir Balban
|
||||
*/
|
||||
|
||||
virtual_base = 0x10000000;
|
||||
virtual_base = %s;
|
||||
physical_base = %s;
|
||||
|
||||
__stack = (0x20000000 - 0x1000 - 8); /* First page before the env/args */
|
||||
|
||||
Reference in New Issue
Block a user