Subversion Repositories HelenOS

Rev

Rev 2952 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 2952 Rev 2965
Line 32... Line 32...
32
 */
32
 */
33
/**
33
/**
34
 * @file
34
 * @file
35
 */
35
 */
36
 
36
 
-
 
37
#include <elf_dyn.h>
-
 
38
#include <rtld.h>
-
 
39
 
37
void __main(void);
40
void __main(void);
38
void __io_init(void);
41
void __io_init(void);
39
void __exit(void);
42
void __exit(void);
40
 
43
 
41
void _rtld_main(void);
-
 
42
 
-
 
43
#define ELF32_R_SYM(i) ((i)>>8)
-
 
44
#define ELF32_R_TYPE(i) ((unsigned char)(i))
-
 
45
 
-
 
46
typedef struct {
-
 
47
    int d_tag;
-
 
48
    union {
-
 
49
        unsigned d_val;
-
 
50
        unsigned *d_ptr;
-
 
51
    } d_un;
-
 
52
} elf32_dyn;
-
 
53
 
-
 
54
typedef struct {
-
 
55
    unsigned r_offset;
-
 
56
    unsigned r_info;
-
 
57
} elf32_rel;
-
 
58
 
-
 
59
typedef struct {
-
 
60
    unsigned st_name;
-
 
61
    unsigned st_value;
-
 
62
    unsigned st_size;
-
 
63
    unsigned char st_info;
-
 
64
    unsigned char st_other;
-
 
65
    unsigned short st_shndx;
-
 
66
} elf32_sym;
-
 
67
 
-
 
68
static void kputint(unsigned i)
44
static void kputint(unsigned i)
69
{
45
{
70
    unsigned dummy;
46
    unsigned dummy;
71
    asm volatile (
47
    asm volatile (
72
        "movl $30, %%eax;"
48
        "movl $30, %%eax;"
Line 79... Line 55...
79
 
55
 
80
void __bootstrap(void)
56
void __bootstrap(void)
81
{
57
{
82
    unsigned bias;
58
    unsigned bias;
83
    unsigned *got;
59
    unsigned *got;
84
    elf32_dyn *dynamic;
60
    elf_dyn_t *dynamic;
85
    unsigned *dptr;
61
    void *dptr;
86
    unsigned dval;
62
    unsigned dval;
87
    int i;
63
    int i;
88
 
64
 
89
    unsigned rel_entries;
65
    size_t rel_entries;
90
    unsigned r_offset;
66
    size_t r_offset;
91
    unsigned r_info;
67
    elf_word r_info;
92
    unsigned rel_type;
68
    unsigned rel_type;
93
    unsigned sym_idx;
69
    elf_word sym_idx;
94
    unsigned sym_addr;
70
    uintptr_t sym_addr;
95
   
71
   
96
    elf32_sym *sym_table;
72
    elf_symbol_t *sym_table;
97
    elf32_rel *rel_table;
73
    elf_rel_t *rel_table;
98
    elf32_rel *jmp_rel_table;
74
    elf_rel_t *jmp_rel_table;
99
    elf32_rel *jmp_rel_entries;
75
    size_t jmp_rel_entries;
100
 
-
 
101
    asm volatile (
-
 
102
    "movl $30, %eax;"
-
 
103
    "int $0x30"
-
 
104
    );
-
 
105
 
-
 
106
    /* Copied from libc/arch/ia32/entry.s */
-
 
107
/*asm volatile (
-
 
108
    "mov %ss, %ax;"
-
 
109
    "mov %ax, %ds;"
-
 
110
    "mov %ax, %es;"
-
 
111
    "mov %ax, %fs;"
-
 
112
);*/
-
 
113
 
-
 
114
 
76
 
115
asm volatile (
77
asm volatile (
116
    /* Calculate the bias into %0 */
78
    /* Calculate the bias into %0 */
117
    /* Generates "fake" R_386_RELATIVE run-time relocation */
79
    /* Generates "fake" R_386_RELATIVE run-time relocation */
118
"   call .L0;"
80
"   call .L0;"
Line 138... Line 100...
138
    jmp_rel_table = 0;
100
    jmp_rel_table = 0;
139
    jmp_rel_entries = 0;
101
    jmp_rel_entries = 0;
140
 
102
 
141
    i = 0;
103
    i = 0;
142
    while (dynamic[i].d_tag != 0) {
104
    while (dynamic[i].d_tag != 0) {
143
        dptr = (unsigned *)(dynamic[i].d_un.d_val + bias);
105
        dptr = (void *)(dynamic[i].d_un.d_val + bias);
144
        dval = dynamic[i].d_un.d_val;
106
        dval = dynamic[i].d_un.d_val;
145
 
107
 
146
        switch (dynamic[i].d_tag) {
108
        switch (dynamic[i].d_tag) {
147
        case 2/* DT_PLTRELSZ */: jmp_rel_entries = dval/8; break;
109
        case 2/* DT_PLTRELSZ */: jmp_rel_entries = dval/8; break;
148
        case 23/* DT_JMPREL */: jmp_rel_table = dptr; break;
110
        case 23/* DT_JMPREL */: jmp_rel_table = dptr; break;