[Cbe-oss-dev] [PATCH 10/10] MARS: remove separate elf implementation

Kazunori Asayama asayama at sm.sony.co.jp
Thu Aug 28 16:39:52 EST 2008


Yuji Mano wrote:
> This removes the mars_elf.h/.c. Since the handling of elf image can be specific
> to the workload model (in the current case this is the task model), move the
> task specific elf handling code into mars_task.c.
> 
> Signed-off-by: Yuji Mano <yuji.mano at am.sony.com>

Acked-by: Kazunori Asayama <asayama at sm.sony.co.jp>

> 
> ---
>  include/Makefile.am                   |    1 
>  include/common/mars/mars_task_types.h |    6 ++
>  include/host/mars/mars_elf.h          |   56 ---------------------------
>  src/host/lib/Makefile.am              |    1 
>  src/host/lib/mars_elf.c               |   70 ----------------------------------
>  src/host/lib/mars_task.c              |   20 ++++++---
>  6 files changed, 20 insertions(+), 134 deletions(-)
> 
> --- a/include/Makefile.am
> +++ b/include/Makefile.am
> @@ -79,7 +79,6 @@ EXTRA_DIST = \
>  	common/mars/mars_debug.h \
>  	common/mars/mars_kernel_types.h \
>  	common/mars/mars_workload_types.h \
> -	host/mars/mars_elf.h \
>  	host/mars/mars_timer.h \
>  	host/mars/mars_workload_queue.h \
>  	mpu/mars/mars_dma.h \
> --- a/include/common/mars/mars_task_types.h
> +++ b/include/common/mars/mars_task_types.h
> @@ -107,6 +107,12 @@ extern "C" {
>  
>  /**
>   * \ingroup group_mars_task
> + * \brief Virtual Address of task elf
> + */
> +#define MARS_TASK_ELF_VADDR			0x10000
> +
> +/**
> + * \ingroup group_mars_task
>   * \brief MARS task argument structure
>   *
>   * This structure is initialized by the user and within the
> --- a/include/host/mars/mars_elf.h
> +++ /dev/null
> @@ -1,56 +0,0 @@
> -/*
> - * Copyright 2008 Sony Corporation of America
> - *
> - *
> - * Permission is hereby granted, free of charge, to any person obtaining
> - * a copy of this Library and associated documentation files (the
> - * "Library"), to deal in the Library without restriction, including
> - * without limitation the rights to use, copy, modify, merge, publish,
> - * distribute, sublicense, and/or sell copies of the Library, and to
> - * permit persons to whom the Library is furnished to do so, subject to
> - * the following conditions:
> - *
> - *  The above copyright notice and this permission notice shall be
> - *  included in all copies or substantial portions of the Library.
> - *
> - *  If you modify the Library, you may copy and distribute your modified
> - *  version of the Library in object code or as an executable provided
> - *  that you also do one of the following:
> - *
> - *   Accompany the modified version of the Library with the complete
> - *   corresponding machine-readable source code for the modified version
> - *   of the Library; or,
> - *
> - *   Accompany the modified version of the Library with a written offer
> - *   for a complete machine-readable copy of the corresponding source
> - *   code of the modified version of the Library.
> - *
> - *
> - * THE LIBRARY IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
> - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
> - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
> - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
> - * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
> - */
> -
> -#ifndef MARS_ELF_H
> -#define MARS_ELF_H
> -
> -#if defined(__cplusplus)
> -extern "C" {
> -#endif
> -
> -#include <stdint.h>
> -
> -#define MARS_ELF_VADDR		0x10000
> -
> -int mars_elf_parse(const void *elf_image, uint64_t *exec, uint32_t *exec_size,
> -			uint32_t *bss_size, uint32_t *vaddr, uint32_t *entry);
> -
> -#if defined(__cplusplus)
> -}
> -#endif
> -
> -#endif
> --- a/src/host/lib/Makefile.am
> +++ b/src/host/lib/Makefile.am
> @@ -70,7 +70,6 @@ libmars_la_LDFLAGS = \
>  
>  libmars_la_SOURCES = \
>  	mars.c \
> -	mars_elf.c \
>  	mars_mutex.c \
>  	mars_workload_queue.c \
>  	mars_task.c \
> --- a/src/host/lib/mars_elf.c
> +++ /dev/null
> @@ -1,70 +0,0 @@
> -/*
> - * Copyright 2008 Sony Corporation of America
> - *
> - *
> - * Permission is hereby granted, free of charge, to any person obtaining
> - * a copy of this Library and associated documentation files (the
> - * "Library"), to deal in the Library without restriction, including
> - * without limitation the rights to use, copy, modify, merge, publish,
> - * distribute, sublicense, and/or sell copies of the Library, and to
> - * permit persons to whom the Library is furnished to do so, subject to
> - * the following conditions:
> - *
> - *  The above copyright notice and this permission notice shall be
> - *  included in all copies or substantial portions of the Library.
> - *
> - *  If you modify the Library, you may copy and distribute your modified
> - *  version of the Library in object code or as an executable provided
> - *  that you also do one of the following:
> - *
> - *   Accompany the modified version of the Library with the complete
> - *   corresponding machine-readable source code for the modified version
> - *   of the Library; or,
> - *
> - *   Accompany the modified version of the Library with a written offer
> - *   for a complete machine-readable copy of the corresponding source
> - *   code of the modified version of the Library.
> - *
> - *
> - * THE LIBRARY IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> - * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> - * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
> - * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
> - * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
> - * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
> - * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
> - */
> -
> -#include <elf.h>
> -
> -#include "mars/mars_elf.h"
> -#include "mars/mars_error.h"
> -#include "mars/mars_debug.h"
> -
> -int mars_elf_parse(const void *elf_image, uint64_t *exec, uint32_t *exec_size,
> -			uint32_t *bss_size, uint32_t *vaddr, uint32_t *entry)
> -{
> -	MARS_CHECK_RET(elf_image, MARS_ERROR_NULL);
> -	MARS_CHECK_RET(exec, MARS_ERROR_NULL);
> -	MARS_CHECK_RET(exec_size, MARS_ERROR_NULL);
> -	MARS_CHECK_RET(bss_size, MARS_ERROR_NULL);
> -	MARS_CHECK_RET(vaddr, MARS_ERROR_NULL);
> -	MARS_CHECK_RET(entry, MARS_ERROR_NULL);
> -
> -	Elf32_Ehdr *ehdr = (Elf32_Ehdr *)elf_image;
> -	Elf32_Phdr *phdr = (Elf32_Phdr *)((void *)ehdr + ehdr->e_phoff);
> -
> -	//MARS_CHECK_RET(ehdr->e_phnum == 1, MARS_ERROR_FORMAT);
> -	MARS_CHECK_RET(phdr->p_type == PT_LOAD, MARS_ERROR_FORMAT);
> -	MARS_CHECK_RET(phdr->p_vaddr == MARS_ELF_VADDR,
> -			MARS_ERROR_FORMAT);
> -
> -	/* set the context exec size and entry */
> -	*exec = (uint64_t)(uintptr_t)((void *)ehdr + phdr->p_offset);
> -	*exec_size = phdr->p_filesz;
> -	*bss_size = phdr->p_memsz - phdr->p_filesz;
> -	*vaddr = phdr->p_vaddr;
> -	*entry = ehdr->e_entry;
> -
> -	return MARS_SUCCESS;
> -}
> --- a/src/host/lib/mars_task.c
> +++ b/src/host/lib/mars_task.c
> @@ -35,13 +35,13 @@
>   * LIBRARY OR THE USE OR OTHER DEALINGS IN THE LIBRARY.
>   */
>  
> +#include <elf.h>
>  #include <string.h>
>  #include <malloc.h>
>  
>  #include "mars/mars_task.h"
>  #include "mars/mars_workload_queue.h"
>  #include "mars/mars.h"
> -#include "mars/mars_elf.h"
>  #include "mars/mars_error.h"
>  #include "mars/mars_debug.h"
>  
> @@ -52,17 +52,25 @@ int mars_task_initialize(struct mars_con
>  	MARS_CHECK_RET(mars, MARS_ERROR_NULL);
>  	MARS_CHECK_RET(id, MARS_ERROR_NULL);
>  	MARS_CHECK_RET(params, MARS_ERROR_NULL);
> +	MARS_CHECK_RET(params->elf_image, MARS_ERROR_PARAMS);
>  
>  	int ret;
>  	struct mars_task_context task;
> +	Elf32_Ehdr *ehdr = (Elf32_Ehdr *)params->elf_image;
> +	Elf32_Phdr *phdr = (Elf32_Phdr *)((void *)ehdr + ehdr->e_phoff);
> +
> +	//MARS_CHECK_RET(ehdr->e_phnum == 1, MARS_ERROR_FORMAT);
> +	MARS_CHECK_RET(phdr->p_type == PT_LOAD, MARS_ERROR_FORMAT);
> +	MARS_CHECK_RET(phdr->p_vaddr == MARS_TASK_ELF_VADDR,
> +			MARS_ERROR_FORMAT);
>  
>  	/* initialize task context */
>  	task.id.mars_context_ea = (uint64_t)(uintptr_t)mars;
> -
> -	/* parse the elf parameter */
> -	ret = mars_elf_parse(params->elf_image, &task.exec, &task.exec_size,
> -				&task.bss_size, &task.vaddr, &task.entry);
> -	MARS_CHECK_RET(ret == MARS_SUCCESS, ret);
> +	task.exec = (uint64_t)(uintptr_t)((void *)ehdr + phdr->p_offset);
> +	task.exec_size = phdr->p_filesz;
> +	task.bss_size = phdr->p_memsz - phdr->p_filesz;
> +	task.vaddr = phdr->p_vaddr;
> +	task.entry = ehdr->e_entry;
>  
>  	/* copy the task name into task id */
>  	if (params->name) {
> 
> 

-- 
(ASAYAMA Kazunori
  (asayama at sm.sony.co.jp))
t



More information about the cbe-oss-dev mailing list