From 8a55a80c236dbc5cd62087798b884ed62faed404 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Tue, 6 Oct 2009 21:12:45 +0300 Subject: [PATCH] Fixed lots of issues with mm0 initialization, final one was an oversized do_munmap. test0 now successfully runs its beginning. test0 SConscript has a dependency problem. Issues to be investigated: - vm_file and vnodes need to be merged fully in all functions. - libposix shared page references need to be removed. - Any references to VFS_TID, PAGER_TID need to be removed. --- conts/posix/libposix/init.c | 23 ---------- conts/posix/mm0/include/memfs/memfs.h | 2 +- conts/posix/mm0/mm/init.c | 8 ++-- conts/posix/mm0/mm/memory.c | 1 + conts/posix/mm0/mm/pagers.c | 4 +- conts/posix/mm0/mm/task.c | 31 +++++++------ conts/posix/test0/SConscript | 9 ++-- conts/posix/test0/container.c | 3 -- conts/posix/test0/include/linker.lds.in | 48 +++++++++++---------- conts/posix/test0/src/test_exec/container.c | 3 -- src/arch/arm/exception.c | 2 +- 11 files changed, 56 insertions(+), 78 deletions(-) delete mode 100644 conts/posix/libposix/init.c diff --git a/conts/posix/libposix/init.c b/conts/posix/libposix/init.c deleted file mode 100644 index d9c0a35..0000000 --- a/conts/posix/libposix/init.c +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Main entry point for posix services and applications. - * - * Copyright (C) 2007-2009 Bahadir Balban - */ -#include -#include -#include - -void posix_service_init(void) -{ - /* Non-pager tasks initialise their shared communication page */ - BUG_ON(self_tid() != VFS_TID); - shared_page_init(); -} - -void libposix_init(void) -{ - /* Shall only be run by posix applications */ - BUG_ON(self_tid() == PAGER_TID || self_tid() == VFS_TID); - shared_page_init(); -} - diff --git a/conts/posix/mm0/include/memfs/memfs.h b/conts/posix/mm0/include/memfs/memfs.h index aeaef86..ea1fbec 100644 --- a/conts/posix/mm0/include/memfs/memfs.h +++ b/conts/posix/mm0/include/memfs/memfs.h @@ -42,7 +42,7 @@ #define MEMFS_TOTAL_SIZE SZ_4MB #define MEMFS_TOTAL_INODES 128 #define MEMFS_TOTAL_BLOCKS 2000 -#define MEMFS_FMAX_BLOCKS 60 +#define MEMFS_FMAX_BLOCKS 120 #define MEMFS_BLOCK_SIZE PAGE_SIZE #define MEMFS_MAGIC 0xB #define MEMFS_NAME "memfs" diff --git a/conts/posix/mm0/mm/init.c b/conts/posix/mm0/mm/init.c index dc60e79..51942dc 100644 --- a/conts/posix/mm0/mm/init.c +++ b/conts/posix/mm0/mm/init.c @@ -467,10 +467,12 @@ void copy_init_process(void) /* * Map an anonymous region and prefault it. + * Its got to be from __end, because we haven't + * unmapped .init section yet (where map_start normally lies). */ if (IS_ERR(mapped = - do_mmap(0, 0, self, 0, - VMA_ANONYMOUS | VM_READ | + do_mmap(0, 0, self, page_align_up(__end), + VMA_ANONYMOUS | VM_READ | VMA_FIXED | VM_WRITE | VM_EXEC | VMA_PRIVATE, __pfn(img_size)))) { printf("FATAL: do_mmap: failed with %d.\n", @@ -496,7 +498,7 @@ void copy_init_process(void) sys_close(find_task(self_tid()), fd); /* Unmap anon region */ - do_munmap(self, (unsigned long)mapped, img_size); + do_munmap(self, (unsigned long)mapped, __pfn(img_size)); /* Unmap raw virtual range for image memory */ l4_unmap_helper(init_img_start,__pfn(img_size)); diff --git a/conts/posix/mm0/mm/memory.c b/conts/posix/mm0/mm/memory.c index 661367b..b45e17e 100644 --- a/conts/posix/mm0/mm/memory.c +++ b/conts/posix/mm0/mm/memory.c @@ -157,6 +157,7 @@ void *pager_map_file_range(struct vm_file *f, unsigned long byte_offset, return (void *)((unsigned long)page | (PAGE_MASK & byte_offset)); } +/* FIXME: PAGE_COLOR!!! */ void *pager_validate_map_user_range2(struct tcb *user, void *userptr, unsigned long size, unsigned int vm_flags) { diff --git a/conts/posix/mm0/mm/pagers.c b/conts/posix/mm0/mm/pagers.c index 8c11430..af11cdd 100644 --- a/conts/posix/mm0/mm/pagers.c +++ b/conts/posix/mm0/mm/pagers.c @@ -97,8 +97,8 @@ int file_page_out(struct vm_object *vm_obj, unsigned long page_offset) /* Map the page to self */ l4_map(paddr, vaddr, 1, MAP_USR_RW_FLAGS, self_tid()); - printf("%s/%s: Writing to vnode %lu, at pgoff 0x%lu, %d pages, buf at %p\n", - __TASKNAME__, __FUNCTION__, vm_file_to_vnum(f), page_offset, 1, vaddr); + //printf("%s/%s: Writing to vnode %lu, at pgoff 0x%lu, %d pages, buf at %p\n", + // __TASKNAME__, __FUNCTION__, vm_file_to_vnum(f), page_offset, 1, vaddr); /* Syscall to vfs to write page back to file. */ if ((err = vfs_write(vm_file_to_vnum(f), page_offset, 1, vaddr)) < 0) diff --git a/conts/posix/mm0/mm/task.c b/conts/posix/mm0/mm/task.c index 050cb32..620af59 100644 --- a/conts/posix/mm0/mm/task.c +++ b/conts/posix/mm0/mm/task.c @@ -491,21 +491,24 @@ int task_map_stack(struct vm_file *f, struct exec_file_desc *efd, struct tcb *ta return (int)mapped; } - /* Map the stack's part that will contain args and environment */ - if (IS_ERR(args_on_stack = - pager_validate_map_user_range2(task, - (void *)task->args_start, - stack_used, - VM_READ | VM_WRITE))) { - return (int)args_on_stack; + /* If args or env use any bytes */ + if (stack_used) { + /* Map the stack's part that will contain args and environment */ + if (IS_ERR(args_on_stack = + pager_validate_map_user_range2(task, + (void *)task->args_start, + stack_used, + VM_READ | VM_WRITE))) { + return (int)args_on_stack; + } + + /* Copy arguments and env */ + task_args_to_user(args_on_stack, args, env); + + /* Unmap task's those stack pages from pager */ + pager_unmap_pages(args_on_stack, arg_pages); } - /* Copy arguments and env */ - task_args_to_user(args_on_stack, args, env); - - /* Unmap task's those stack pages from pager */ - pager_unmap_pages(args_on_stack, arg_pages); - return 0; } @@ -536,7 +539,7 @@ int task_map_bss(struct vm_file *f, struct exec_file_desc *efd, struct tcb *task /* Get the page */ last_data_page = task_virt_to_page(task, task->data_end); - /* Map the page */ + /* Map the page. FIXME: PAGE COLOR!!! */ pagebuf = l4_map_helper((void *)page_to_phys(last_data_page), 1); /* Find the bss offset */ diff --git a/conts/posix/test0/SConscript b/conts/posix/test0/SConscript index 6603dc9..070694c 100644 --- a/conts/posix/test0/SConscript +++ b/conts/posix/test0/SConscript @@ -9,7 +9,7 @@ sys.path.append('../../../../') from config.lib import * from tools.pyelf.lmanext import * -src = [Glob('*.[c]') + Glob('test_exec.S') + Glob('src/*.c') + Glob('src/arch/arm/*.c')] +src = [Glob('*.c') + Glob('test_exec.S') + Glob('src/*.c') + Glob('src/arch/arm/*.c')] asm_string = \ ''' @@ -41,6 +41,7 @@ test_exec_src = Glob('src/test_exec/*.[cS]') test_exec_objs = test_exec_env.Object(test_exec_src) test_exec = test_exec_env.Program('src/test_exec/test_exec', test_exec_objs) test_exec_asm = Command('test_exec.S', test_exec, generate_incbin_asm) +Depends(test_exec, test_exec_objs) env.Append(LIBS = ['posix', 'c-userspace']) env.Append(LINKFLAGS = ['-T' + lma_lds[0].path, '-u_start']) @@ -49,7 +50,6 @@ env.Replace(PROGSUFFIX = '') objs = env.Object(src + test_exec_asm) test0 = env.Program('test0', objs) - elf_wrap_string = \ ''' .align 4 @@ -75,11 +75,8 @@ elf_wrap_env.Append(LINKFLAGS = '-T' + elf_wrapped_lds[0].path) elf_wrap_objs = elf_wrap_env.Object(elf_wrapped_asm) test0_elf_elf = elf_wrap_env.Program('test0_elf.elf', elf_wrap_objs) -Depends(test0, objs) Depends(test0, lma_lds) -Depends(lma_lds, previmage) Depends(test0, test_exec) -Depends(test0_elf_elf, elf_wrap_objs) -Depends(test0_elf_elf, test0) +Depends(lma_lds, previmage) Depends(test0_elf_elf, elf_wrapped_lds) Return('test0_elf_elf') diff --git a/conts/posix/test0/container.c b/conts/posix/test0/container.c index 2e145e3..e6ab94b 100644 --- a/conts/posix/test0/container.c +++ b/conts/posix/test0/container.c @@ -16,9 +16,6 @@ void __container_init(void) /* Generic L4 thread initialisation */ __l4_init(); - /* Initialise posix library for application */ - libposix_init(); - /* Entry to main */ main(); } diff --git a/conts/posix/test0/include/linker.lds.in b/conts/posix/test0/include/linker.lds.in index 8ee4e7b..6bc06ae 100644 --- a/conts/posix/test0/include/linker.lds.in +++ b/conts/posix/test0/include/linker.lds.in @@ -1,24 +1,14 @@ /* - * Simple linker script for userspace or svc tasks. + * Userspace linker script * - * Copyright (C) 2007 Bahadir Balban + * Copyright (C) 2007 - 2009 Bahadir Balban */ -/* - * The only catch with this linker script is that everything - * is linked starting at virtual_base, and loaded starting - * at physical_base. virtual_base is the predefined region - * of virtual memory for userland applications. physical_base - * is determined at build-time, it is one of the subsequent pages - * that come after the kernel image's load area. - */ -/* USER_AREA_START, see memlayout.h */ virtual_base = 0x10000000; physical_base = %s; -__stack = (0x20000000 - 0x1000 - 8); /* First page before the env/args */ -/* INCLUDE "include/physical_base.lds" */ -/* physical_base = 0x228000; */ +__stack = (0x20000000 - 0x1000 - 8); /* First page before the env/args */ + offset = virtual_base - physical_base; ENTRY(_start) @@ -27,18 +17,32 @@ SECTIONS { . = virtual_base; _start_text = .; - .text : AT (ADDR(.text) - offset) { *(.text.head) *(.text) } - /* rodata is needed else your strings will link at physical! */ - .rodata : AT (ADDR(.rodata) - offset) { *(.rodata) } - .rodata1 : AT (ADDR(.rodata1) - offset) { *(.rodata1) } - .data : AT (ADDR(.data) - offset) - { - . = ALIGN(4K); + .text : AT (ADDR(.text) - offset) { + *(.text.head) + *(.text) + } + .rodata : AT (ADDR(.rodata) - offset) { + *(.rodata) + } + .rodata1 : AT (ADDR(.rodata1) - offset) { + *(.rodata1) + } + + . = ALIGN(4K); + .data : AT (ADDR(.data) - offset) { _start_test_exec = .; *(.testexec) _end_test_exec = .; *(.data) } - .bss : AT (ADDR(.bss) - offset) { *(.bss) } + .got : AT (ADDR(.got) - offset) { + *(.got) + } + .got.plt : AT (ADDR(.got.plt) - offset) { + *(.got.plt) + } + .bss : AT (ADDR(.bss) - offset) { + *(.bss) + } _end = .; } diff --git a/conts/posix/test0/src/test_exec/container.c b/conts/posix/test0/src/test_exec/container.c index 2e145e3..e6ab94b 100644 --- a/conts/posix/test0/src/test_exec/container.c +++ b/conts/posix/test0/src/test_exec/container.c @@ -16,9 +16,6 @@ void __container_init(void) /* Generic L4 thread initialisation */ __l4_init(); - /* Initialise posix library for application */ - libposix_init(); - /* Entry to main */ main(); } diff --git a/src/arch/arm/exception.c b/src/arch/arm/exception.c index ad1a463..700bcc4 100644 --- a/src/arch/arm/exception.c +++ b/src/arch/arm/exception.c @@ -19,7 +19,7 @@ #include INC_SUBARCH(mm.h) /* Abort debugging conditions */ - #define DEBUG_ABORTS +// #define DEBUG_ABORTS #if defined (DEBUG_ABORTS) #define dbg_abort(...) dprintk(__VA_ARGS__) #else