mirror of
https://github.com/drasko/codezero.git
synced 2026-02-28 17:53:13 +01:00
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.
This commit is contained in:
@@ -1,23 +0,0 @@
|
|||||||
/*
|
|
||||||
* Main entry point for posix services and applications.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2007-2009 Bahadir Balban
|
|
||||||
*/
|
|
||||||
#include <shpage.h>
|
|
||||||
#include <posix_init.h>
|
|
||||||
#include <libposix.h>
|
|
||||||
|
|
||||||
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();
|
|
||||||
}
|
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@
|
|||||||
#define MEMFS_TOTAL_SIZE SZ_4MB
|
#define MEMFS_TOTAL_SIZE SZ_4MB
|
||||||
#define MEMFS_TOTAL_INODES 128
|
#define MEMFS_TOTAL_INODES 128
|
||||||
#define MEMFS_TOTAL_BLOCKS 2000
|
#define MEMFS_TOTAL_BLOCKS 2000
|
||||||
#define MEMFS_FMAX_BLOCKS 60
|
#define MEMFS_FMAX_BLOCKS 120
|
||||||
#define MEMFS_BLOCK_SIZE PAGE_SIZE
|
#define MEMFS_BLOCK_SIZE PAGE_SIZE
|
||||||
#define MEMFS_MAGIC 0xB
|
#define MEMFS_MAGIC 0xB
|
||||||
#define MEMFS_NAME "memfs"
|
#define MEMFS_NAME "memfs"
|
||||||
|
|||||||
@@ -467,10 +467,12 @@ void copy_init_process(void)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Map an anonymous region and prefault it.
|
* 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 =
|
if (IS_ERR(mapped =
|
||||||
do_mmap(0, 0, self, 0,
|
do_mmap(0, 0, self, page_align_up(__end),
|
||||||
VMA_ANONYMOUS | VM_READ |
|
VMA_ANONYMOUS | VM_READ | VMA_FIXED |
|
||||||
VM_WRITE | VM_EXEC | VMA_PRIVATE,
|
VM_WRITE | VM_EXEC | VMA_PRIVATE,
|
||||||
__pfn(img_size)))) {
|
__pfn(img_size)))) {
|
||||||
printf("FATAL: do_mmap: failed with %d.\n",
|
printf("FATAL: do_mmap: failed with %d.\n",
|
||||||
@@ -496,7 +498,7 @@ void copy_init_process(void)
|
|||||||
sys_close(find_task(self_tid()), fd);
|
sys_close(find_task(self_tid()), fd);
|
||||||
|
|
||||||
/* Unmap anon region */
|
/* 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 */
|
/* Unmap raw virtual range for image memory */
|
||||||
l4_unmap_helper(init_img_start,__pfn(img_size));
|
l4_unmap_helper(init_img_start,__pfn(img_size));
|
||||||
|
|||||||
@@ -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));
|
return (void *)((unsigned long)page | (PAGE_MASK & byte_offset));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* FIXME: PAGE_COLOR!!! */
|
||||||
void *pager_validate_map_user_range2(struct tcb *user, void *userptr,
|
void *pager_validate_map_user_range2(struct tcb *user, void *userptr,
|
||||||
unsigned long size, unsigned int vm_flags)
|
unsigned long size, unsigned int vm_flags)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -97,8 +97,8 @@ int file_page_out(struct vm_object *vm_obj, unsigned long page_offset)
|
|||||||
/* Map the page to self */
|
/* Map the page to self */
|
||||||
l4_map(paddr, vaddr, 1, MAP_USR_RW_FLAGS, self_tid());
|
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",
|
//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);
|
// __TASKNAME__, __FUNCTION__, vm_file_to_vnum(f), page_offset, 1, vaddr);
|
||||||
|
|
||||||
/* Syscall to vfs to write page back to file. */
|
/* Syscall to vfs to write page back to file. */
|
||||||
if ((err = vfs_write(vm_file_to_vnum(f), page_offset, 1, vaddr)) < 0)
|
if ((err = vfs_write(vm_file_to_vnum(f), page_offset, 1, vaddr)) < 0)
|
||||||
|
|||||||
@@ -491,21 +491,24 @@ int task_map_stack(struct vm_file *f, struct exec_file_desc *efd, struct tcb *ta
|
|||||||
return (int)mapped;
|
return (int)mapped;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Map the stack's part that will contain args and environment */
|
/* If args or env use any bytes */
|
||||||
if (IS_ERR(args_on_stack =
|
if (stack_used) {
|
||||||
pager_validate_map_user_range2(task,
|
/* Map the stack's part that will contain args and environment */
|
||||||
(void *)task->args_start,
|
if (IS_ERR(args_on_stack =
|
||||||
stack_used,
|
pager_validate_map_user_range2(task,
|
||||||
VM_READ | VM_WRITE))) {
|
(void *)task->args_start,
|
||||||
return (int)args_on_stack;
|
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;
|
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 */
|
/* Get the page */
|
||||||
last_data_page = task_virt_to_page(task, task->data_end);
|
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);
|
pagebuf = l4_map_helper((void *)page_to_phys(last_data_page), 1);
|
||||||
|
|
||||||
/* Find the bss offset */
|
/* Find the bss offset */
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ sys.path.append('../../../../')
|
|||||||
from config.lib import *
|
from config.lib import *
|
||||||
from tools.pyelf.lmanext 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 = \
|
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_objs = test_exec_env.Object(test_exec_src)
|
||||||
test_exec = test_exec_env.Program('src/test_exec/test_exec', test_exec_objs)
|
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)
|
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(LIBS = ['posix', 'c-userspace'])
|
||||||
env.Append(LINKFLAGS = ['-T' + lma_lds[0].path, '-u_start'])
|
env.Append(LINKFLAGS = ['-T' + lma_lds[0].path, '-u_start'])
|
||||||
@@ -49,7 +50,6 @@ env.Replace(PROGSUFFIX = '')
|
|||||||
objs = env.Object(src + test_exec_asm)
|
objs = env.Object(src + test_exec_asm)
|
||||||
test0 = env.Program('test0', objs)
|
test0 = env.Program('test0', objs)
|
||||||
|
|
||||||
|
|
||||||
elf_wrap_string = \
|
elf_wrap_string = \
|
||||||
'''
|
'''
|
||||||
.align 4
|
.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)
|
elf_wrap_objs = elf_wrap_env.Object(elf_wrapped_asm)
|
||||||
test0_elf_elf = elf_wrap_env.Program('test0_elf.elf', elf_wrap_objs)
|
test0_elf_elf = elf_wrap_env.Program('test0_elf.elf', elf_wrap_objs)
|
||||||
|
|
||||||
Depends(test0, objs)
|
|
||||||
Depends(test0, lma_lds)
|
Depends(test0, lma_lds)
|
||||||
Depends(lma_lds, previmage)
|
|
||||||
Depends(test0, test_exec)
|
Depends(test0, test_exec)
|
||||||
Depends(test0_elf_elf, elf_wrap_objs)
|
Depends(lma_lds, previmage)
|
||||||
Depends(test0_elf_elf, test0)
|
|
||||||
Depends(test0_elf_elf, elf_wrapped_lds)
|
Depends(test0_elf_elf, elf_wrapped_lds)
|
||||||
Return('test0_elf_elf')
|
Return('test0_elf_elf')
|
||||||
|
|||||||
@@ -16,9 +16,6 @@ void __container_init(void)
|
|||||||
/* Generic L4 thread initialisation */
|
/* Generic L4 thread initialisation */
|
||||||
__l4_init();
|
__l4_init();
|
||||||
|
|
||||||
/* Initialise posix library for application */
|
|
||||||
libposix_init();
|
|
||||||
|
|
||||||
/* Entry to main */
|
/* Entry to main */
|
||||||
main();
|
main();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
virtual_base = 0x10000000;
|
||||||
physical_base = %s;
|
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;
|
offset = virtual_base - physical_base;
|
||||||
|
|
||||||
ENTRY(_start)
|
ENTRY(_start)
|
||||||
@@ -27,18 +17,32 @@ SECTIONS
|
|||||||
{
|
{
|
||||||
. = virtual_base;
|
. = virtual_base;
|
||||||
_start_text = .;
|
_start_text = .;
|
||||||
.text : AT (ADDR(.text) - offset) { *(.text.head) *(.text) }
|
.text : AT (ADDR(.text) - offset) {
|
||||||
/* rodata is needed else your strings will link at physical! */
|
*(.text.head)
|
||||||
.rodata : AT (ADDR(.rodata) - offset) { *(.rodata) }
|
*(.text)
|
||||||
.rodata1 : AT (ADDR(.rodata1) - offset) { *(.rodata1) }
|
}
|
||||||
.data : AT (ADDR(.data) - offset)
|
.rodata : AT (ADDR(.rodata) - offset) {
|
||||||
{
|
*(.rodata)
|
||||||
. = ALIGN(4K);
|
}
|
||||||
|
.rodata1 : AT (ADDR(.rodata1) - offset) {
|
||||||
|
*(.rodata1)
|
||||||
|
}
|
||||||
|
|
||||||
|
. = ALIGN(4K);
|
||||||
|
.data : AT (ADDR(.data) - offset) {
|
||||||
_start_test_exec = .;
|
_start_test_exec = .;
|
||||||
*(.testexec)
|
*(.testexec)
|
||||||
_end_test_exec = .;
|
_end_test_exec = .;
|
||||||
*(.data)
|
*(.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 = .;
|
_end = .;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,9 +16,6 @@ void __container_init(void)
|
|||||||
/* Generic L4 thread initialisation */
|
/* Generic L4 thread initialisation */
|
||||||
__l4_init();
|
__l4_init();
|
||||||
|
|
||||||
/* Initialise posix library for application */
|
|
||||||
libposix_init();
|
|
||||||
|
|
||||||
/* Entry to main */
|
/* Entry to main */
|
||||||
main();
|
main();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,7 +19,7 @@
|
|||||||
#include INC_SUBARCH(mm.h)
|
#include INC_SUBARCH(mm.h)
|
||||||
|
|
||||||
/* Abort debugging conditions */
|
/* Abort debugging conditions */
|
||||||
#define DEBUG_ABORTS
|
// #define DEBUG_ABORTS
|
||||||
#if defined (DEBUG_ABORTS)
|
#if defined (DEBUG_ABORTS)
|
||||||
#define dbg_abort(...) dprintk(__VA_ARGS__)
|
#define dbg_abort(...) dprintk(__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
|
|||||||
Reference in New Issue
Block a user