Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2964 → Rev 2965

/branches/dynload/uspace/lib/rtld/arch/ia32/bootstrap.c
File deleted
/branches/dynload/uspace/lib/rtld/arch/ia32/runtime.c
File deleted
/branches/dynload/uspace/lib/rtld/arch/ia32/entry.s
File deleted
/branches/dynload/uspace/lib/rtld/arch/ia32/include/elf_dyn.h
0,0 → 1,50
/*
* 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_ELF_DYN_H_
#define ia32_ELF_DYN_H_
 
/*
* ia32 dynamic relocation types
*/
 
#define R_386_32 1
#define R_386_GLOB_DAT 6
#define R_386_JUMP_SLOT 7
#define R_386_RELATIVE 8
 
#endif
 
/** @}
*/
/branches/dynload/uspace/lib/rtld/arch/ia32/Makefile.inc
26,8 → 26,10
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
 
CFLAGS += -D__32_BITS__
 
ARCH_SOURCES := \
arch/$(ARCH)/entry.s \
arch/$(ARCH)/bootstrap.c \
arch/$(ARCH)/runtime.c
arch/$(ARCH)/src/entry.s \
arch/$(ARCH)/src/bootstrap.c \
arch/$(ARCH)/src/runtime.c
 
/branches/dynload/uspace/lib/rtld/arch/ia32/src/entry.s
0,0 → 1,42
#
# Copyright (c) 2005 Martin Decky
# 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.
#
 
.section .text
 
.globl __bootstrap
.hidden __bootstrap
 
.type __entry, @function
 
__entry:
mov %ss, %ax
mov %ax, %ds
mov %ax, %es
mov %ax, %fs
 
call __bootstrap
/branches/dynload/uspace/lib/rtld/arch/ia32/src/runtime.c
0,0 → 1,98
/*
* 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 <sys/types.h>
#include <align.h>
#include <tls.h>
 
void _putint(int i);
/* FIXME */
void __udivdi3(void);
void __umoddi3(void);
 
static void kputint(unsigned i)
{
unsigned dummy;
asm volatile (
"movl $30, %%eax;"
"int $0x30"
: "=d" (dummy) /* output - %edx clobbered */
: "d" (i) /* input */
: "%eax","%ecx" /* all scratch registers clobbered */
);
}
 
typedef struct {
unsigned long int ti_module;
unsigned long int ti_offset;
} tls_index;
 
void __attribute__ ((__regparm__ (1)))
*___tls_get_addr(tls_index *ti);
 
void __attribute__ ((__regparm__ (1)))
*___tls_get_addr(tls_index *ti)
{
size_t tls_size;
uint8_t *tls;
 
/* Calculate size of TLS block */
tls_size = ALIGN_UP(&_tbss_end - &_tdata_start, &_tls_alignment);
 
/* The TLS block is just before TCB */
tls = (uint8_t *)__tcb_get() - tls_size;
 
return tls + ti->ti_offset;
}
 
void __umoddi3(void)
{
kputint(0x101);
*(int *)0 = 0; /* cause a page fault */
}
 
void __udivdi3(void)
{
kputint(0x102);
*(int *)0 = 0; /* cause a page fault */
}
 
void _putint(int i)
{
}
 
/** @}
*/
/branches/dynload/uspace/lib/rtld/arch/ia32/src/bootstrap.c
0,0 → 1,239
/*
* 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 <elf_dyn.h>
#include <rtld.h>
 
void __main(void);
void __io_init(void);
void __exit(void);
 
static void kputint(unsigned i)
{
unsigned dummy;
asm volatile (
"movl $30, %%eax;"
"int $0x30"
: "=d" (dummy) /* output - %edx clobbered */
: "d" (i) /* input */
: "%eax","%ecx" /* all scratch registers clobbered */
);
}
 
void __bootstrap(void)
{
unsigned bias;
unsigned *got;
elf_dyn_t *dynamic;
void *dptr;
unsigned dval;
int i;
 
size_t rel_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_rel_t *rel_table;
elf_rel_t *jmp_rel_table;
size_t jmp_rel_entries;
 
asm volatile (
/* Calculate the bias into %0 */
/* Generates "fake" R_386_RELATIVE run-time relocation */
" call .L0;"
".L0: pop %0;"
" subl $.L0, %0;"
 
/* Calculate run-time address of _DYNAMIC into %1 */
/* Generates "fake" R_386_RELATIVE run-time relocation */
" movl $_DYNAMIC, %1;" /* Again, at link time 0-based VMA gets in */
" addl %0, %1;" /* Add bias to compute run-time address */
 
: "=r" (bias), "=r" (dynamic)
);
 
kputint(bias);
kputint((unsigned)dynamic);
 
/* parse DYNAMIC */
got = 0;
sym_table = 0;
rel_table = 0;
rel_entries = 0;
jmp_rel_table = 0;
jmp_rel_entries = 0;
 
i = 0;
while (dynamic[i].d_tag != 0) {
dptr = (void *)(dynamic[i].d_un.d_val + bias);
dval = dynamic[i].d_un.d_val;
 
switch (dynamic[i].d_tag) {
case 2/* DT_PLTRELSZ */: jmp_rel_entries = dval/8; break;
case 23/* DT_JMPREL */: jmp_rel_table = dptr; break;
case 3 /* DT_PLTGOT */:
/* GOT address */
got = dptr; break;
case 6 /* DT_SYMTAB */ : sym_table = dptr; break;
case 17 /* DT_REL */ : rel_table = dptr; break;
case 18 /* DT_RELSZ */ : rel_entries = dval / 8; break;
default: break;
}
 
++i;
}
kputint(1);
kputint((unsigned)sym_table);
kputint((unsigned)rel_table);
kputint((unsigned)rel_entries);
 
/* Now relocate all our dynsyms */
kputint(-1);
for (i=0; i<rel_entries; i++) {
kputint(i);
r_offset = rel_table[i].r_offset;
r_info = rel_table[i].r_info;
 
rel_type = ELF32_R_TYPE(r_info);
 
kputint(rel_type);
kputint(r_offset);
 
switch (rel_type) {
case 6: /* R_386_GLOB_DAT */
case 7: /* R_386_JUMP_SLOT */
kputint(16);
sym_idx = ELF32_R_SYM(r_info);
 
sym_addr = sym_table[sym_idx].st_value + bias;
kputint(sym_idx);
kputint(sym_addr);
 
*(unsigned *)(r_offset+bias) = sym_addr;
break;
 
case 1: /* R_386_32 */
kputint(16);
sym_idx = ELF32_R_SYM(r_info);
 
sym_addr = sym_table[sym_idx].st_value + bias;
kputint(sym_idx);
kputint(sym_addr);
 
*(unsigned *)(r_offset+bias) += sym_addr;
break;
case 8: /* R_386_RELATIVE */
kputint(16);
*(unsigned *)(r_offset+bias) += bias;
break;
}
}
 
kputint(-1);
for (i=0; i<jmp_rel_entries; i++) {
kputint(i);
r_offset = jmp_rel_table[i].r_offset;
r_info = jmp_rel_table[i].r_info;
 
rel_type = ELF32_R_TYPE(r_info);
 
kputint(rel_type);
kputint(r_offset);
 
switch (rel_type) {
case 6: /* R_386_GLOB_DAT */
case 7: /* R_386_JUMP_SLOT */
kputint(16);
sym_idx = ELF32_R_SYM(r_info);
 
sym_addr = sym_table[sym_idx].st_value + bias;
kputint(sym_idx);
kputint(sym_addr);
 
*(unsigned *)(r_offset+bias) = sym_addr;
break;
 
case 1: /* R_386_32 */
kputint(16);
sym_idx = ELF32_R_SYM(r_info);
 
sym_addr = sym_table[sym_idx].st_value + bias;
kputint(sym_idx);
kputint(sym_addr);
 
*(unsigned *)(r_offset+bias) += sym_addr;
break;
case 8: /* R_386_RELATIVE */
kputint(16);
*(unsigned *)(r_offset+bias) += bias;
break;
}
}
 
kputint(-1);
/* Init libc and run rtld main */
__main();
 
kputint(33);
__io_init();
kputint(34);
_rtld_main();
kputint(35);
__exit();
 
kputint(36);
 
asm (
"movl $250, %%eax;"
"int $0x30"
: /* output */
: /* input */
: "%eax","%ecx","%edx" /* all scratch registers clobbered */
);
}
 
/** @}
*/