Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 3399 → Rev 3400

/branches/dynload/uspace/lib/rtld/include/arch.h
File deleted
/branches/dynload/uspace/lib/rtld/include/rtld_arch.h
0,0 → 1,48
/*
* 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 RTLD_ARCH_H_
#define RTLD_ARCH_H_
 
#include <rtld.h>
 
void module_process_pre_arch(module_t *m);
 
void rel_table_process(module_t *m, elf_rel_t *rt, size_t rt_size);
void rela_table_process(module_t *m, elf_rela_t *rt, size_t rt_size);
 
#endif
 
/** @}
*/
/branches/dynload/uspace/lib/rtld/elf_load.c
1,0 → 0,0
link ../../app/iloader/elf_load.c
link ../../srv/loader/elf_load.c
/branches/dynload/uspace/lib/rtld/module.c
39,12 → 39,12
#include <unistd.h>
#include <fcntl.h>
#include <libadt/list.h>
#include <loader/pcb.h>
 
#include <rtld.h>
#include <dynamic.h>
#include <pcb.h>
#include <elf_load.h>
#include <arch.h>
#include <rtld_arch.h>
#include <module.h>
 
/** (Eagerly) process all relocation tables in a module.
126,9 → 126,10
exit(1);
}
 
/* Prepend soname with slash */
/* Prepend soname with '/lib/' */
name_buf[0] = '/';
strcpy(name_buf + 1, name);
strcpy(name_buf, "/lib/");
strcpy(name_buf + 5, name);
 
/* FIXME: need to vary bias / allocate address space */
m->bias = 0x20000;
136,7 → 137,7
 
rc = elf_load_file(name_buf, m->bias, &info);
if (rc < 0) {
printf("Failed to load '%s'\n");
printf("Failed to load '%s'\n", name_buf);
exit(1);
}
 
/branches/dynload/uspace/lib/rtld/rtld.c
37,19 → 37,20
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <loader/pcb.h>
 
#include <rtld.h>
#include <dynamic.h>
#include <pcb.h>
#include <elf_load.h>
#include <module.h>
#include <arch.h>
#include <rtld_arch.h>
 
runtime_env_t runtime_env;
 
void program_run(void *entry, pcb_t *pcb);
 
void _rtld_main(void)
{
pcb_t *pcb;
static module_t prog;
module_t *rtld;
 
66,9 → 67,8
printf("Parse rtld .dynamic section at 0x%x\n", runtime_env.rtld_dynamic);
dynamic_parse(runtime_env.rtld_dynamic, rtld->bias, &rtld->dyn);
 
pcb = __pcb_get();
printf("Parse program .dynamic section at 0x%x\n", pcb->dynamic);
dynamic_parse(pcb->dynamic, 0, &prog.dyn);
printf("Parse program .dynamic section at 0x%x\n", __pcb->dynamic);
dynamic_parse(__pcb->dynamic, 0, &prog.dyn);
prog.bias = 0;
prog.dyn.soname = "[program]";
 
98,9 → 98,29
/*
* Finally, run the main program.
*/
printf("Run program.. (at 0x%x)\n", (uintptr_t)pcb->entry);
pcb->entry();
printf("Run program.. (at 0x%x)\n", (uintptr_t)__pcb->entry);
//__pcb->entry();
program_run(__pcb->entry, __pcb);
}
 
/** Fake main to satisfy dependency from libc */
int main(int argc, char *argv[])
{
return 0;
}
 
typedef void (*ep2)(void *);
 
void program_run(void *entry, pcb_t *pcb)
{
asm (
// "xorl %%ebx, %%ebx\n"
// "movl 0(%%ebx), %%ecx\n"
"mov %%eax, %%ebx\n"
"jmp *%0\n"
:: "m" (entry), "a" (pcb)
);
}
 
/** @}
*/
/branches/dynload/uspace/lib/rtld/Makefile
37,7 → 37,7
include $(LIBC_PREFIX)/Makefile.toolchain
include arch/$(ARCH)/Makefile.inc
 
CFLAGS += -I../../srv/loader/include -Iinclude -fPIC -O0 -ggdb
CFLAGS += -Iinclude -I../../srv/loader/include -fPIC -O0 -ggdb
LFLAGS += -shared --no-undefined -soname rtld.so
 
LIBS = $(LIBC_PREFIX)/libc.pic.a $(SOFTINT_PREFIX)/libsoftint.pic.a
/branches/dynload/uspace/lib/rtld/arch/ia32/Makefile.inc
27,10 → 27,10
#
 
CFLAGS += -D__32_BITS__
LFLAGS += -e __bootstrap
LFLAGS += -e __entry
 
ARCH_SOURCES := \
arch/$(ARCH)/src/entry.s \
arch/$(ARCH)/src/bootstrap.c \
arch/$(ARCH)/src/runtime.c \
arch/$(ARCH)/src/reloc.c
 
/branches/dynload/uspace/lib/rtld/arch/ia32/src/entry.s
28,15 → 28,15
 
.section .text
 
.globl __bootstrap
.globl __entry
.hidden __bootstrap
 
.type __entry, @function
 
## Rtld entry point
#
# %ebx contains the PCB pointer
#
__entry:
mov %ss, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
 
# Pass the PCB pointer to __bootstrap as the first argument
pushl %ebx
call __bootstrap
/branches/dynload/uspace/lib/rtld/arch/ia32/src/runtime.c
40,14 → 40,14
 
static void kputint(unsigned i)
{
unsigned dummy;
asm volatile (
"movl $31, %%eax;"
"int $0x30"
: "=d" (dummy) /* output - %edx clobbered */
: "d" (i) /* input */
: "%eax","%ecx" /* all scratch registers clobbered */
);
// unsigned dummy;
// asm volatile (
// "movl $31, %%eax;"
// "int $0x30"
// : "=d" (dummy) /* output - %edx clobbered */
// : "d" (i) /* input */
// : "%eax","%ecx" /* all scratch registers clobbered */
// );
}
 
typedef struct {
/branches/dynload/uspace/lib/rtld/arch/ia32/src/bootstrap.c
34,12 → 34,12
* @file
*/
 
#include <loader/pcb.h>
#include <elf_dyn.h>
#include <rtld.h>
#include <pcb.h>
 
void __main(void);
void __io_init(void);
void __main(pcb_t *pcb);
//void __io_init(void);
void __exit(void);
 
static void kputint(unsigned i)
46,15 → 46,15
{
unsigned dummy;
asm volatile (
"movl $31, %%eax;"
"movl $32, %%eax;"
"int $0x30"
: "=d" (dummy) /* output - %edx clobbered */
: "d" (i) /* input */
: "%eax","%ecx" /* all scratch registers clobbered */
);
);
}
 
void __bootstrap(void)
void __bootstrap(pcb_t *pcb)
{
unsigned bias;
unsigned *got;
74,11 → 74,8
elf_rel_t *rel_table;
elf_rel_t *jmp_rel_table;
size_t jmp_rel_entries;
pcb_t *pcb;
pcb = __pcb_get();
 
/* The program loader (iloader) kindly provided us with these */
/* The program loader kindly provided us with these */
dynamic = pcb->rtld_dynamic;
bias = pcb->rtld_bias;
/*
97,6 → 94,7
: "=r" (bias), "=r" (dynamic)
);
*/
kputint(pcb);
kputint(bias);
kputint((unsigned)dynamic);
 
128,13 → 126,13
++i;
}
kputint(1);
kputint((unsigned)sym_table);
kputint((unsigned)rel_table);
kputint((unsigned)rel_entries);
// kputint(1);
// kputint((unsigned)sym_table);
// kputint((unsigned)rel_table);
// kputint((unsigned)rel_entries);
 
/* Now relocate all our dynsyms */
kputint(-1);
// kputint(-1);
for (i=0; i<rel_entries; i++) {
kputint(i);
221,16 → 219,22
}
 
kputint(-1);
kputint(0x42);
 
/* This will come in handy */
__pcb = pcb;
runtime_env.rtld_dynamic = dynamic;
runtime_env.rtld.bias = bias;
 
kputint(0x43);
/* Init libc and run rtld main */
__main();
__main(pcb);
 
kputint(33);
__io_init();
kputint(0x44);
 
// kputint(33);
// __io_init();
kputint(34);
_rtld_main();
kputint(35);