From e5cde20ca97ca8c66343f5e8a69961624a9afdd7 Mon Sep 17 00:00:00 2001 From: Bahadir Balban Date: Thu, 1 Oct 2009 13:13:27 +0300 Subject: [PATCH] Fixed a fault with posix tasks not getting their LMA correctly --- config/configuration.py | 19 +++++++++++-------- conts/posix/mm0/SConscript | 1 + conts/posix/test0/SConscript | 3 ++- loader/libs/elf/src/elf.c | 24 +++++++++++++++++------- loader/main.c | 4 ++-- tools/pyelf/lmanext.py | 3 ++- 6 files changed, 35 insertions(+), 19 deletions(-) diff --git a/config/configuration.py b/config/configuration.py index 1e47441..f083c74 100644 --- a/config/configuration.py +++ b/config/configuration.py @@ -2,6 +2,7 @@ # -*- mode: python; coding: utf-8; -*- import os, sys, shelve, shutil, re from projpaths import * +from lib import * class Container: def __init__(self, id): @@ -152,17 +153,19 @@ class configuration: # Make sure elements in order for indexed accessing self.containers.sort(self.compare_containers) + def container_print(self, c): + print '\nContainer %d' % c.id + print 'Container type: %s' % c.type + print 'Container Name: %s' % c.name + print 'Container Pager lma: %s' % conv_hex(c.pager_lma) + print 'Container Pager vma: %s' % conv_hex(c.pager_vma) + print 'Container Pager size: %s' % conv_hex(c.pager_size) + print 'Container Virtual regions: %s' % c.virt_regions + print 'Container Physical regions: %s' % c.phys_regions def containers_print(self, containers): for c in containers: - print '\nContainer %d' % c.id - print 'Container type: %s' % c.type - print 'Container Name: %s' % c.name - print 'Container Pager lma: %s' % hex(c.pager_lma) - print 'Container Pager vma: %s' % hex(c.pager_vma) - print 'Container Pager size: %s' % hex(c.pager_size) - print 'Container Virtual regions: %s' % c.virt_regions - print 'Container Physical regions: %s' % c.phys_regions + self.container_print(self, c) def config_print(self): print 'Configuration\n' diff --git a/conts/posix/mm0/SConscript b/conts/posix/mm0/SConscript index 369e6f1..b8c3fc2 100644 --- a/conts/posix/mm0/SConscript +++ b/conts/posix/mm0/SConscript @@ -24,6 +24,7 @@ def generate_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)) lma_lds = Command('include/linker.lds', 'include/linker.lds.in', generate_lma_lds) diff --git a/conts/posix/test0/SConscript b/conts/posix/test0/SConscript index 955d041..a18d827 100644 --- a/conts/posix/test0/SConscript +++ b/conts/posix/test0/SConscript @@ -48,8 +48,9 @@ env.Append(LINKFLAGS = ['-T' + lma_lds[0].path, '-u_start']) env.Append(CPPFLAGS = ' -D__USERSPACE__') objs = env.Object(src + test_exec_asm) test0 = env.Program('test0.elf', objs) - +Depends(test0, objs) Depends(test0, lma_lds) +Depends(lma_lds, previmage) env.Depends(test0, test_exec) Return('test0') diff --git a/loader/libs/elf/src/elf.c b/loader/libs/elf/src/elf.c index e10a3a6..3e421a9 100644 --- a/loader/libs/elf/src/elf.c +++ b/loader/libs/elf/src/elf.c @@ -350,6 +350,11 @@ elf_loadFile(void *elfFile, bool phys) //printf("Number of program headers: %d\n", num_pheaders); //printf("Program header offset of first header from file beginning: 0x%p\n",pheader_offset); + /* + * FIXME: + * This should have a linked list of mapped ranges so that it can check + * at run-time whether any images are overlapping in their LMA and refuse to load. + */ for(i=0; i < num_pheaders; i++) { /* Load that section */ uint64_t dest, src; @@ -357,11 +362,11 @@ elf_loadFile(void *elfFile, bool phys) size_t len; if (phys) { dest = elf_getProgramHeaderPaddr(elfFile, i); - // printf("Elf file pheader physical: %p\n", dest); - // printf("Elf file pheader virtual: %p\n", - // elf_getProgramHeaderVaddr(elfFile,i)); + // printf("Elf file pheader physical: 0x%x\n", (unsigned int)dest); + // printf("Elf file pheader virtual: 0x%x\n", + // (unsigned int)elf_getProgramHeaderVaddr(elfFile,i)); } else { - // printf("Elf file pheader virtual: %p\n", dest); + // printf("Elf file pheader virtual: 0x%x\n", (unsigned int)dest); dest = elf_getProgramHeaderVaddr(elfFile, i); } len = elf_getProgramHeaderFileSize(elfFile, i); @@ -370,14 +375,19 @@ elf_loadFile(void *elfFile, bool phys) // printf("Elf program header offset: %p\n", src); pheader_type = elf_getProgramHeaderType(elfFile, i); // printf("Elf program header type: %p\n", pheader_type); - // printf("Copying from %x to %x of size: %p\n", (unsigned int)src, (unsigned int)dest, len); + +/* Enable this one + printf("Copying to range from 0x%x to 0x%x of size: 0x%x\n", (unsigned int)dest, (unsigned int)dest + (unsigned int)len, (unsigned int)len); + */ memcpy((void*) (uintptr_t) dest, (void*) (uintptr_t) src, len); dest += len; clrsize = elf_getProgramHeaderMemorySize(elfFile, i) - len; - // printf("Clearing memory... starting from %x, size: %x\n", (unsigned int)dest, clrsize); +// printf("Clearing memory... starting from %x, size: %x\n", (unsigned int)dest, (unsigned int)clrsize); memset((void*) (uintptr_t) dest, 0, clrsize); - // printf("Memory cleared.\n"); +// printf("Memory cleared.\n"); } +// And this one +// printf("\n"); return true; } diff --git a/loader/main.c b/loader/main.c index ae4067c..da0a296 100644 --- a/loader/main.c +++ b/loader/main.c @@ -121,9 +121,9 @@ int main(void) printf("elf-loader:\tkernel entry point is %lx\n", *kernel_entry); arch_start_kernel(kernel_entry); - printf("elf-loader:\tKernel start failed!\n"); + printf("elf-loader:\tKernel start failed! Looping endless.\n"); while (1) - printf("Endless loop.\n"); + ; return -1; } diff --git a/tools/pyelf/lmanext.py b/tools/pyelf/lmanext.py index 2dcf009..7f442c8 100644 --- a/tools/pyelf/lmanext.py +++ b/tools/pyelf/lmanext.py @@ -28,8 +28,9 @@ def next_available_lma(srcfile): p_align = x.p_align if paddr > paddr_max: paddr_max = paddr - paddr_aligned = paddr_max & ~(p_align.value - 1) + #print "paddr_max %s " % hex(paddr_max) + #print "paddr_aligned %s " % hex(paddr_aligned) if paddr_max & (p_align.value - 1): paddr_aligned += p_align.value return conv_hex(paddr_aligned)