Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3771 → Rev 3772

/branches/dynload/uspace/app/dload/dload.c
80,7 → 80,7
runtime_env->program = &prog;
 
/* Work around non-existent memory space allocation. */
runtime_env->next_bias = 0x100000;
runtime_env->next_bias = 0x1000000;
 
/*
* Now we can continue with loading all other modules.
/branches/dynload/uspace/app/dload/arch/mips32/_link.ld.in
0,0 → 1,59
STARTUP(LIBC_PREFIX/arch/ARCH/src/entry.o)
ENTRY(__entry)
 
PHDRS {
text PT_LOAD FLAGS(5);
data PT_LOAD FLAGS(6);
}
 
SECTIONS {
. = 0x60004000 + SIZEOF_HEADERS;
.init : {
*(.init);
} :text
.text : {
*(.text);
*(.rodata*);
} :text
 
. = . + 0x4000;
 
.data : {
*(.data);
*(.data.rel*);
} :data
 
.got : {
_gp = .;
*(.got);
} :data
 
.tdata : {
_tdata_start = .;
*(.tdata);
_tdata_end = .;
} :data
.tbss : {
_tbss_start = .;
*(.tbss);
_tbss_end = .;
} :data
_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
 
.sbss : {
*(.scommon);
*(.sbss);
}
.bss : {
*(.bss);
*(COMMON);
} :data
 
. = ALIGN(0x4000);
_heap = .;
 
/DISCARD/ : {
*(*);
}
}
/branches/dynload/uspace/app/dload/arch/mips32/Makefile.inc
0,0 → 1,32
#
# Copyright (c) 2008 Jiri Svoboda
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# - The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
 
CFLAGS += -D__32_BITS__
 
ARCH_SOURCES := \
arch/$(ARCH)/mips32.s
/branches/dynload/uspace/app/dload/arch/mips32/mips32.s
0,0 → 1,49
#
# Copyright (c) 2008 Jiri Svoboda
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# - The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
 
.text
.section .text
.global program_run
.set noreorder
 
## void program_run(void *entry_point, void *pcb);
#
# $a0 (=$4) contains entry_point
# $a1 (=$5) contains pcb
#
# Jump to a program entry point
.ent program_run
program_run:
# tmp := entry_point
move $25, $a0
 
# Pass pcb to the entry point in $a0
move $a0, $a1
jr $25
nop
.end
/branches/dynload/uspace/lib/rtld/include/dynamic.h
37,6 → 37,7
 
#include <bool.h>
#include <elf_dyn.h>
#include <arch/dynamic.h>
 
/**
* Holds the data extracted from an ELF Dynamic section.
45,7 → 46,7
* to their final run-time values by adding the load bias
* and indices into the symbol table are converted to pointers.
*/
typedef struct {
typedef struct dyn_info {
/** Type of relocations used for the PLT, either DT_REL or DT_RELA */
int plt_rel;
 
92,9 → 93,13
 
/** Pointer to the module's dynamic section */
elf_dyn_t *dynamic;
 
/** Architecture-specific info. */
dyn_info_arch_t arch;
} dyn_info_t;
 
void dynamic_parse(elf_dyn_t *dyn_ptr, size_t bias, dyn_info_t *info);
void dyn_parse_arch(elf_dyn_t *dp, size_t bias, dyn_info_t *info);
 
#endif
 
/branches/dynload/uspace/lib/rtld/dynamic.c
87,7 → 87,10
case DT_JMPREL: info->jmp_rel = d_ptr; break;
case DT_BIND_NOW: info->bind_now = true; break;
 
default: break;
default:
if (dp->d_tag >= DT_LOPROC && dp->d_tag <= DT_HIPROC)
dyn_parse_arch(dp, bias, info);
break;
}
 
++dp;
/branches/dynload/uspace/lib/rtld/symbol.c
212,8 → 212,15
}
}
 
/* Otherwise start in the executable program */
return symbol_bfs_find(name, runtime_env->program, mod);
/* Not DT_SYMBOLIC or no match. Now try other locations. */
 
if (runtime_env->program) {
/* Program is dynamic -- start with program as root. */
return symbol_bfs_find(name, runtime_env->program, mod);
} else {
/* Program is static -- start with @a origin as root. */
return symbol_bfs_find(name, origin, mod);
}
}
 
uintptr_t symbol_get_addr(elf_symbol_t *sym, module_t *m)
/branches/dynload/uspace/lib/rtld/arch/ppc32/include/dynamic.h
0,0 → 1,47
/*
* Copyright (c) 2008 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup generic
* @{
*/
/** @file
*/
 
#ifndef ppc32_DYNAMIC_H_
#define ppc32_DYNAMIC_H_
 
#include <sys/types.h>
 
typedef struct {
/* Empty. */
} dyn_info_arch_t;
 
#endif
 
/** @}
*/
/branches/dynload/uspace/lib/rtld/arch/ppc32/Makefile.inc
29,4 → 29,5
CFLAGS += -D__32_BITS__
 
ARCH_SOURCES := \
arch/$(ARCH)/src/dynamic.c \
arch/$(ARCH)/src/reloc.c
/branches/dynload/uspace/lib/rtld/arch/ppc32/src/reloc.c
85,6 → 85,9
{
uint32_t *plt;
uint32_t *_plt_ent;
/* No lazy linking -- no pre-processing yet. */
return;
 
plt = m->dyn.plt_got;
if (!plt) {
/branches/dynload/uspace/lib/rtld/arch/ppc32/src/dynamic.c
0,0 → 1,51
/*
* Copyright (c) 2008 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup rtld rtld
* @brief
* @{
*/
/**
* @file
*/
 
#include <stdio.h>
#include <stdlib.h>
 
#include <elf_dyn.h>
#include <dynamic.h>
 
void dyn_parse_arch(elf_dyn_t *dp, size_t bias, dyn_info_t *info)
{
(void) dp;
(void) bias;
(void) info;
}
 
/** @}
*/
/branches/dynload/uspace/lib/rtld/arch/mips32/include/elf_dyn.h
0,0 → 1,57
/*
* Copyright (c) 2008 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup generic
* @{
*/
/** @file
*/
 
#ifndef mips32_ELF_DYN_H_
#define mips32_ELF_DYN_H_
 
/*
* mips32 program header types
*/
#define DT_MIPS_BASE_ADDRESS 0x70000006
#define DT_MIPS_SYMTABNO 0x70000011
#define DT_MIPS_GOTSYM 0x70000013
 
/*
* mips32 relocation types
*/
 
#define R_MIPS_NONE 0
#define R_MIPS_REL32 3
 
#define R_MIPS_TLS_DTPMOD32 333 /* fixme */
 
#endif
 
/** @}
*/
/branches/dynload/uspace/lib/rtld/arch/mips32/include/dynamic.h
0,0 → 1,52
/*
* Copyright (c) 2008 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup generic
* @{
*/
/** @file
*/
 
#ifndef mips32_DYNAMIC_H_
#define mips32_DYNAMIC_H_
 
#include <sys/types.h>
 
typedef struct {
/** Number of local entries in GOT. */
uint32_t gotsym;
/** Number of entries in dynamic symbol table. */
uint32_t sym_no;
/** ???. */
uint32_t base;
} dyn_info_arch_t;
 
#endif
 
/** @}
*/
/branches/dynload/uspace/lib/rtld/arch/mips32/Makefile.inc
0,0 → 1,33
#
# Copyright (c) 2008 Jiri Svoboda
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# - Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# - Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# - The name of the author may not be used to endorse or promote products
# derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
 
CFLAGS += -D__32_BITS__
 
ARCH_SOURCES := \
arch/$(ARCH)/src/dynamic.c \
arch/$(ARCH)/src/reloc.c
/branches/dynload/uspace/lib/rtld/arch/mips32/src/dynamic.c
0,0 → 1,60
/*
* Copyright (c) 2008 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup rtld rtld
* @brief
* @{
*/
/**
* @file
*/
 
#include <stdio.h>
#include <stdlib.h>
 
#include <elf_dyn.h>
#include <dynamic.h>
 
void dyn_parse_arch(elf_dyn_t *dp, size_t bias, dyn_info_t *info)
{
// void *d_ptr;
elf_word d_val;
 
// d_ptr = (void *)((uint8_t *)dp->d_un.d_ptr + bias);
d_val = dp->d_un.d_val;
 
switch (dp->d_tag) {
case DT_MIPS_BASE_ADDRESS: info->arch.base = d_val; break;
case DT_MIPS_SYMTABNO: info->arch.sym_no = d_val; break;
case DT_MIPS_GOTSYM: info->arch.gotsym = d_val; break;
default: break;
}
}
 
/** @}
*/
/branches/dynload/uspace/lib/rtld/arch/mips32/src/reloc.c
0,0 → 1,251
/*
* Copyright (c) 2008 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup rtld rtld
* @brief
* @{
*/
/**
* @file
*/
 
#include <stdio.h>
#include <stdlib.h>
 
#include <arch.h>
#include <elf_dyn.h>
#include <symbol.h>
#include <rtld.h>
 
void module_process_pre_arch(module_t *m)
{
elf_symbol_t *sym_table;
elf_symbol_t *sym_def;
elf_symbol_t *sym;
uint32_t gotsym;
uint32_t *got;
char *str_tab;
int i;
 
uint32_t sym_addr;
module_t *dest;
 
got = (uint32_t *) m->dyn.plt_got;
sym_table = m->dyn.sym_tab;
str_tab = m->dyn.str_tab;
gotsym = m->dyn.arch.gotsym;
 
DPRINTF("** Relocate GOT entries **\n");
DPRINTF("MIPS base = 0x%x\n", m->dyn.arch.base);
 
/*
* Local entries.
*/
for (i = 0; i < gotsym; i++) {
/* FIXME: really subtract MIPS base? */
got[i] += m->bias - m->dyn.arch.base;
}
 
DPRINTF("sym_ent = %d, gotsym = %d\n", m->dyn.arch.sym_no, gotsym);
 
/*
* Global entries.
*/
for (i = gotsym; i < m->dyn.arch.sym_no; i++) {
DPRINTF("relocate GOT entry %d\n", i);
// getchar();
 
sym = &sym_table[i];
if (ELF32_R_TYPE(sym->st_info) == STT_FUNC) {
if (sym->st_shndx == SHN_UNDEF) {
if (sym->st_value == 0) {
/* 1 */
} else {
if (got[i] == sym->st_value) {
/* 2 */
DPRINTF("(2)\n");
got[i] += m->bias - m->dyn.arch.base;
continue;
} else {
/* 3 */
DPRINTF("(3)\n");
got[i] = sym->st_value + m->bias - m->dyn.arch.base;
continue;
}
}
} else {
/* 2 */
DPRINTF("(2)\n");
got[i] += m->bias - m->dyn.arch.base;
continue;
}
} else {
if (sym->st_shndx == SHN_UNDEF ||
sym->st_shndx == SHN_COMMON) {
/* 1 */
} else {
/* 1 */
}
}
DPRINTF("(1) symbol name='%s'\n", str_tab + sym->st_name);
sym_def = symbol_def_find(str_tab + sym->st_name, m, &dest);
if (sym_def) {
sym_addr = symbol_get_addr(sym_def, dest);
DPRINTF("symbol definition found, addr=0x%x\n", sym_addr);
} else {
DPRINTF("symbol definition not found\n");
continue;
}
DPRINTF("write 0x%x at 0x%x\n", sym_addr, (uint32_t) &got[i]);
// getchar();
got[i] = sym_addr;
}
 
DPRINTF("** Done **\n");
}
 
/**
* Process (fixup) all relocations in a relocation table.
*/
void rel_table_process(module_t *m, elf_rel_t *rt, size_t rt_size)
{
int i;
 
size_t rt_entries;
size_t r_offset;
elf_word r_info;
unsigned rel_type;
elf_word sym_idx;
uintptr_t sym_addr;
elf_symbol_t *sym_table;
elf_symbol_t *sym;
uint32_t *r_ptr;
uint16_t *r_ptr16;
char *str_tab;
elf_symbol_t *sym_def;
module_t *dest;
 
uint32_t *got;
uint32_t gotsym;
uint32_t ea;
 
DPRINTF("parse relocation table\n");
 
sym_table = m->dyn.sym_tab;
rt_entries = rt_size / sizeof(elf_rela_t);
str_tab = m->dyn.str_tab;
got = (uint32_t *) m->dyn.plt_got;
gotsym = m->dyn.arch.gotsym;
 
DPRINTF("got=0x%lx, gotsym=%d\n", (uintptr_t) got, gotsym);
 
DPRINTF("address: 0x%x, entries: %d\n", (uintptr_t)rt, rt_entries);
for (i = 0; i < rt_entries; ++i) {
DPRINTF("symbol %d: ", i);
r_offset = rt[i].r_offset;
r_info = rt[i].r_info;
 
sym_idx = ELF32_R_SYM(r_info);
sym = &sym_table[sym_idx];
 
DPRINTF("name '%s', value 0x%x, size 0x%x\n",
str_tab + sym->st_name,
sym->st_value,
sym->st_size);
 
rel_type = ELF32_R_TYPE(r_info);
r_ptr = (uint32_t *)(r_offset + m->bias);
r_ptr16 = (uint16_t *)(r_offset + m->bias);
 
if (sym->st_name != 0) {
DPRINTF("rel_type: %x, rel_offset: 0x%x\n", rel_type, r_offset);
DPRINTF("dest name: '%s'\n", dest->dyn.soname);
DPRINTF("dest bias: 0x%x\n", dest->bias);
if (sym_def) {
sym_addr = symbol_get_addr(sym_def, dest);
DPRINTF("symbol definition found, addr=0x%x\n", sym_addr);
} else {
DPRINTF("symbol definition not found\n");
continue;
}
}
 
DPRINTF("switch(%u)\n", rel_type);
 
switch (rel_type) {
case R_MIPS_NONE:
DPRINTF("Ignoring R_MIPS_NONE\n");
break;
 
case R_MIPS_REL32:
DPRINTF("fixup R_MIPS_REL32 (r - ea + s)\n");
if (sym_idx < gotsym)
ea = sym_addr;
else
ea = got[sym_idx];
 
*r_ptr += sym_addr - ea;
DPRINTF("p = 0x%x, val := 0x%x\n", (uint32_t) r_ptr,
*r_ptr);
// getchar();
break;
 
/* No other non-TLS relocation types should appear. */
 
case R_MIPS_TLS_DTPMOD32:
/*
* We can ignore this as long as the only module
* with TLS variables is libc.so.
*/
DPRINTF("Ignoring R_MIPS_DTPMOD32\n");
break;
 
default:
printf("Error: Unknown relocation type %d.\n",
rel_type);
exit(1);
break;
}
}
 
 
printf("relocation done\n");
}
 
void rela_table_process(module_t *m, elf_rela_t *rt, size_t rt_size)
{
/* Unused */
(void)m; (void)rt; (void)rt_size;
}
 
/** @}
*/
/branches/dynload/uspace/lib/rtld/arch/ia32/include/dynamic.h
0,0 → 1,47
/*
* Copyright (c) 2008 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup generic
* @{
*/
/** @file
*/
 
#ifndef ia32_DYNAMIC_H_
#define ia32_DYNAMIC_H_
 
#include <sys/types.h>
 
typedef struct {
/* Empty. */
} dyn_info_arch_t;
 
#endif
 
/** @}
*/
/branches/dynload/uspace/lib/rtld/arch/ia32/Makefile.inc
29,4 → 29,5
CFLAGS += -D__32_BITS__
 
ARCH_SOURCES := \
arch/$(ARCH)/src/dynamic.c \
arch/$(ARCH)/src/reloc.c
/branches/dynload/uspace/lib/rtld/arch/ia32/src/dynamic.c
0,0 → 1,51
/*
* Copyright (c) 2008 Jiri Svoboda
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
 
/** @addtogroup rtld rtld
* @brief
* @{
*/
/**
* @file
*/
 
#include <stdio.h>
#include <stdlib.h>
 
#include <elf_dyn.h>
#include <dynamic.h>
 
void dyn_parse_arch(elf_dyn_t *dp, size_t bias, dyn_info_t *info)
{
(void) dp;
(void) bias;
(void) info;
}
 
/** @}
*/
/branches/dynload/uspace/lib/libtest/arch/mips32/_link.ld.in
0,0 → 1,91
ENTRY(__entry)
 
PHDRS {
text PT_LOAD FLAGS(5);
data PT_LOAD FLAGS(6);
dynamic PT_DYNAMIC;
}
 
SECTIONS {
. = 0x4000 + SIZEOF_HEADERS;
.init : {
*(.init);
} :text
.text : {
*(.text);
*(.rodata*);
*(.MIPS.stubs);
} :text
 
.rel.plt : {
*(.rel.plt);
}
/*
*.rel.dyn MUST FOLLOW IMMEDIATELY after .rel.plt
* without alignment gap or DT_REL will be broken
*/
.rel.dyn : {
*(.rel.*);
} :text
 
.plt : {
*(.plt);
} :text
 
.hash : {
*(.hash);
} :text
 
.dynsym : {
*(.dynsym);
} :text
 
.dynstr : {
*(.dynstr);
} :text
 
.dynamic : {
*(.dynamic);
} :text :dynamic
 
. = . + 0x4000;
 
.data : {
*(.data);
*(.data.rel*);
} :data
 
.got : {
_gp = .;
*(.got);
} :data
/*
.tdata : {
_tdata_start = .;
*(.tdata);
_tdata_end = .;
} :data
.tbss : {
_tbss_start = .;
*(.tbss);
_tbss_end = .;
} :data
_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
*/
.sbss : {
*(.scommon);
*(.sbss);
}
.bss : {
*(.bss);
*(COMMON);
} :data
 
. = ALIGN(0x4000);
_heap = .;
 
/DISCARD/ : {
*(*);
}
}
/branches/dynload/uspace/lib/libc/shared/arch/mips32/_link.ld.in
0,0 → 1,104
STARTUP(LIBC_PREFIX/arch/ARCH/src/entry.o)
ENTRY(__entry)
 
PHDRS {
interp PT_INTERP;
text PT_LOAD FLAGS(5);
data PT_LOAD FLAGS(6);
dynamic PT_DYNAMIC;
}
 
SECTIONS {
. = 0x4000 + SIZEOF_HEADERS;
 
.interp : {
*(.interp);
} :text :interp
 
/* Align on word boundary -- instructions will follow. */
. = ALIGN(4);
.init : {
*(.init);
} :text
.text : {
*(.text);
*(.rodata*);
*(.MIPS.stubs);
} :text
 
.hash : {
*(.hash);
} : text
 
.reginfo : {
*(.reginfo);
} : text
 
.rel.plt : {
*(.rel.plt);
} : text
/*
*.rel.dyn MUST FOLLOW IMMEDIATELY after .rel.plt
* without alignment gap or DT_REL will be broken
*/
.rel.dyn : {
*(.rel.*);
} :text
 
.plt : {
*(.plt);
} : text
 
.dynsym : {
*(.dynsym);
} : text
 
.dynstr : {
*(.dynstr);
} : text
 
. = . + 0x4000;
 
.dynamic : {
*(.dynamic);
} :data :dynamic
 
.data : {
*(.data);
*(.data.rel*);
} :data
 
.got : {
_gp = .;
*(.got);
} :data
/*
.tdata : {
_tdata_start = .;
*(.tdata);
_tdata_end = .;
} :data
.tbss : {
_tbss_start = .;
*(.tbss);
_tbss_end = .;
} :data
_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
*/
.sbss : {
*(.scommon);
*(.sbss);
}
.bss : {
*(.bss);
*(COMMON);
} :data
 
. = ALIGN(0x4000);
_heap = .;
 
/* /DISCARD/ : {
*(*);
}*/
}
/branches/dynload/uspace/lib/libc/shared/arch/mips32/_lib.ld.in
0,0 → 1,95
ENTRY(__entry)
 
PHDRS {
text PT_LOAD FLAGS(5);
data PT_LOAD FLAGS(6);
dynamic PT_DYNAMIC;
}
 
SECTIONS {
. = 0x4000 + SIZEOF_HEADERS;
.init : {
*(.init);
} :text
.text : {
*(.text);
*(.rodata*);
*(.MIPS.stubs);
} :text
 
.hash : {
*(.hash);
} : text
 
.reginfo : {
*(.reginfo);
} : text
 
.rel.plt : {
*(.rel.plt);
} : text
/*
*.rel.dyn MUST FOLLOW IMMEDIATELY after .rel.plt
* without alignment gap or DT_REL will be broken
*/
.rel.dyn : {
*(.rel.*);
} :text
 
.plt : {
*(.plt);
} : text
 
.dynsym : {
*(.dynsym);
} : text
 
.dynstr : {
*(.dynstr);
} : text
 
. = . + 0x4000;
 
.dynamic : {
*(.dynamic);
} :data :dynamic
 
.data : {
*(.data);
*(.data.rel*);
} :data
 
.got : {
_gp = .;
*(.got);
} :data
 
.tdata : {
_tdata_start = .;
*(.tdata);
_tdata_end = .;
} :data
.tbss : {
_tbss_start = .;
*(.tbss);
_tbss_end = .;
} :data
_tls_alignment = MAX(ALIGNOF(.tdata), ALIGNOF(.tbss));
 
.sbss : {
*(.scommon);
*(.sbss);
}
.bss : {
*(.bss);
*(COMMON);
} :data
 
. = ALIGN(0x4000);
_heap = .;
 
/* /DISCARD/ : {
*(*);
}*/
}
/branches/dynload/uspace/lib/libc/Makefile
119,7 → 119,7
-makedepend $(DEFS) $(PIC_CFLAGS) -o.pio -f - $(ARCH_SOURCES) $(GENERIC_SOURCES) >> Makefile.depend 2> /dev/null
 
libc.a: depend $(OBJECTS)
$(AR) rc $@ $(LIBS) $(OBJECTS) $(RTLD_PREFIX)/librtld.a
$(AR) rc $@ $(LIBS) $(OBJECTS)
 
libc.pic.a: depend $(PIC_OBJECTS)
$(AR) rc $@ $(LIBS) $(PIC_OBJECTS)
/branches/dynload/uspace/lib/libc/arch/mips32/src/tls.c
46,5 → 46,25
tls_free_variant_1(tcb, size);
}
 
typedef struct {
unsigned long ti_module;
unsigned long ti_offset;
} tls_index;
 
void *__tls_get_addr(tls_index *ti);
 
/* mips32 uses TLS variant 1 */
void *__tls_get_addr(tls_index *ti)
{
uint8_t *tls;
uint32_t v;
 
tls = (uint8_t *)__tcb_get() + sizeof(tcb_t);
 
/* Hopefully this is right. No docs found. */
v = (uint32_t) (tls + ti->ti_offset + 0x8000);
return (void *) v;
}
 
/** @}
*/
/branches/dynload/uspace/srv/loader/main.c
225,6 → 225,8
{
int rc;
 
printf("Load program '%s'\n", pathname);
 
rc = elf_load_file(pathname, 0, 0, &prog_info);
if (rc < 0) {
printf("Failed to load executable '%s'.\n", pathname);
232,11 → 234,17
return 1;
}
 
printf("Create PCB\n");
 
elf_create_pcb(&prog_info, &pcb);
 
printf("Fill args\n");
 
pcb.argc = argc;
pcb.argv = argv;
 
printf("Check interp\n");
 
if (prog_info.interp == NULL) {
/* Statically linked program */
is_dyn_linked = false;
282,6 → 290,7
program_run(interp_info.entry, &pcb);
 
} else {
printf("Run static program\n");
/* Statically linked program */
close_console();
ipc_answer_0(rid, EOK);
/branches/dynload/uspace/srv/loader/elf_load.c
306,10 → 306,13
printf("dynamic section found at 0x%x\n",
(uintptr_t)elf->info->dynamic);
break;
case 0x70000000:
/* FIXME: MIPS reginfo */
break;
case PT_SHLIB:
case PT_NOTE:
case PT_LOPROC:
case PT_HIPROC:
// case PT_LOPROC:
// case PT_HIPROC:
default:
printf("segment p_type %d unknown\n", entry->p_type);
return EE_UNSUPPORTED;
374,7 → 377,8
a = as_area_create((uint8_t *)base + bias, mem_sz,
AS_AREA_READ | AS_AREA_WRITE | AS_AREA_CACHEABLE);
if (a == (void *)(-1)) {
printf("memory mapping failed\n");
printf("memory mapping failed (0x%x, %d)\n",
base+bias, mem_sz);
return EE_MEMORY;
}
 
/branches/dynload/boot/arch/mips32/loader/Makefile
106,10 → 106,16
RD_APPS = \
$(USPACEDIR)/app/tetris/tetris \
$(USPACEDIR)/app/tester/tester \
$(USPACEDIR)/app/dload/dload \
$(USPACEDIR)/app/dltest/dltest \
$(USPACEDIR)/app/trace/trace \
$(USPACEDIR)/app/bdsh/bdsh \
$(USPACEDIR)/app/klog/klog
 
RD_LIBS = \
$(USPACEDIR)/lib/libc/shared/libc.so.0 \
$(USPACEDIR)/lib/libtest/libtest.so.0
 
OBJECTS := $(addsuffix .o,$(basename $(SOURCES)))
COMPONENT_OBJECTS := $(addsuffix .o,$(basename $(notdir $(COMPONENTS))))
 
134,10 → 140,13
done
-rm -f _components.h _components.c _link.ld _link.ld.in $(COMPONENT_OBJECTS) initrd.o $(OBJECTS) initrd.img image.boot Makefile.depend
 
_components.h _components.c _link.ld $(COMPONENT_OBJECTS) initrd.o: $(COMPONENTS) $(RD_SRVS) $(RD_APPS) _link.ld.in
_components.h _components.c _link.ld $(COMPONENT_OBJECTS) initrd.o: $(COMPONENTS) $(RD_SRVS) $(RD_LIBS) $(RD_APPS) _link.ld.in
for file in $(RD_SRVS) ; do \
cp $$file $(USPACEDIR)/dist/srv/ ; \
done
for lib in $(RD_LIBS) ; do \
cp $$lib $(USPACEDIR)/dist/lib/ ; \
done
for file in $(RD_APPS) ; do \
cp $$file $(USPACEDIR)/dist/app/ ; \
done