Subversion Repositories HelenOS

Rev

Rev 3552 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3552 Rev 3562
1
/*
1
/*
2
 * Copyright (c) 2008 Jiri Svoboda
2
 * Copyright (c) 2008 Jiri Svoboda
3
 * All rights reserved.
3
 * All rights reserved.
4
 *
4
 *
5
 * Redistribution and use in source and binary forms, with or without
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
6
 * modification, are permitted provided that the following conditions
7
 * are met:
7
 * are met:
8
 *
8
 *
9
 * - Redistributions of source code must retain the above copyright
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
12
 *   notice, this list of conditions and the following disclaimer in the
13
 *   documentation and/or other materials provided with the distribution.
13
 *   documentation and/or other materials provided with the distribution.
14
 * - The name of the author may not be used to endorse or promote products
14
 * - The name of the author may not be used to endorse or promote products
15
 *   derived from this software without specific prior written permission.
15
 *   derived from this software without specific prior written permission.
16
 *
16
 *
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
27
 */
28
 
28
 
29
/** @addtogroup rtld rtld
29
/** @addtogroup rtld rtld
30
 * @brief
30
 * @brief
31
 * @{
31
 * @{
32
 */
32
 */
33
/**
33
/**
34
 * @file
34
 * @file
35
 */
35
 */
36
 
36
 
37
#include <stdio.h>
37
#include <stdio.h>
38
#include <unistd.h>
38
#include <unistd.h>
39
#include <fcntl.h>
39
#include <fcntl.h>
40
#include <loader/pcb.h>
40
#include <loader/pcb.h>
41
 
41
 
42
#include <rtld.h>
42
#include <rtld.h>
43
#include <dynamic.h>
43
#include <dynamic.h>
44
#include <elf_load.h>
44
#include <elf_load.h>
45
#include <module.h>
45
#include <module.h>
46
#include <rtld_arch.h>
46
#include <rtld_arch.h>
47
 
47
 
48
runtime_env_t runtime_env;
48
runtime_env_t runtime_env;
49
 
49
 
50
void program_run(void *entry, pcb_t *pcb);
50
void program_run(void *entry, pcb_t *pcb);
51
 
51
 
52
void _rtld_main(void)
52
void _rtld_main(void)
53
{
53
{
54
    static module_t prog;
54
    static module_t prog;
55
//  module_t *rtld;
55
//  module_t *rtld;
56
 
56
 
57
    printf("Hello, world! (from rtld)\n");
57
    DPRINTF("Hello, world! (from rtld)\n");
58
 
58
 
59
    /*
59
    /*
60
     * First we need to process dynamic sections of the two modules
60
     * First we need to process dynamic sections of the two modules
61
     * that have been already loaded, that is, of ourselves and of
61
     * that have been already loaded, that is, of ourselves and of
62
     * the executable program.
62
     * the executable program.
63
     */
63
     */
64
 
64
 
65
    /* rtld_dynamic and rtld->bias were filled out by the bootstrap code */
65
    /* rtld_dynamic and rtld->bias were filled out by the bootstrap code */
66
//  rtld = &runtime_env.rtld;
66
//  rtld = &runtime_env.rtld;
67
//  printf("Parse rtld .dynamic section at 0x%x\n", runtime_env.rtld_dynamic);
67
//  DPRINTF("Parse rtld .dynamic section at 0x%x\n", runtime_env.rtld_dynamic);
68
//  dynamic_parse(runtime_env.rtld_dynamic, rtld->bias, &rtld->dyn);
68
//  dynamic_parse(runtime_env.rtld_dynamic, rtld->bias, &rtld->dyn);
69
 
69
 
70
    printf("Parse program .dynamic section at 0x%x\n", __pcb->dynamic);
70
    DPRINTF("Parse program .dynamic section at 0x%x\n", __pcb->dynamic);
71
    dynamic_parse(__pcb->dynamic, 0, &prog.dyn);
71
    dynamic_parse(__pcb->dynamic, 0, &prog.dyn);
72
    prog.bias = 0;
72
    prog.bias = 0;
73
    prog.dyn.soname = "[program]";
73
    prog.dyn.soname = "[program]";
74
 
74
 
75
    /* Initialize list of loaded modules */
75
    /* Initialize list of loaded modules */
76
    list_initialize(&runtime_env.modules_head);
76
    list_initialize(&runtime_env.modules_head);
77
    list_append(&prog.modules_link, &runtime_env.modules_head);
77
    list_append(&prog.modules_link, &runtime_env.modules_head);
78
//  list_append(&rtld->modules_link, &runtime_env.modules_head);
78
//  list_append(&rtld->modules_link, &runtime_env.modules_head);
79
 
79
 
80
    /* Pointer to program module. Used as root of the dependency graph */
80
    /* Pointer to program module. Used as root of the dependency graph */
81
    runtime_env.program = &prog;
81
    runtime_env.program = &prog;
82
 
82
 
83
    /*
83
    /*
84
     * Now we can continue with loading all other modules.
84
     * Now we can continue with loading all other modules.
85
     */
85
     */
86
 
86
 
87
    printf("Load all program dependencies\n");
87
    DPRINTF("Load all program dependencies\n");
88
    module_load_deps(&prog);
88
    module_load_deps(&prog);
89
 
89
 
90
    /*
90
    /*
91
     * Now relocate/link all modules together.
91
     * Now relocate/link all modules together.
92
     */
92
     */
93
 
93
 
94
    /* Process relocations in all modules */
94
    /* Process relocations in all modules */
95
    printf("Relocate all modules\n");
95
    DPRINTF("Relocate all modules\n");
96
    modules_process_relocs();
96
    modules_process_relocs();
97
 
97
 
98
    /*
98
    /*
99
     * Finally, run the main program.
99
     * Finally, run the main program.
100
     */
100
     */
101
    printf("Run program.. (at 0x%x)\n", (uintptr_t)__pcb->entry);
101
    DPRINTF("Run program.. (at 0x%x)\n", (uintptr_t)__pcb->entry);
-
 
102
 
-
 
103
#ifndef RTLD_DEBUG
-
 
104
    close_console();
-
 
105
#endif
102
    //__pcb->entry();
106
    //__pcb->entry();
103
    program_run(__pcb->entry, __pcb);
107
    program_run(__pcb->entry, __pcb);
104
}
108
}
105
 
109
 
106
/** Fake main to satisfy dependency from libc */
110
/** Fake main to satisfy dependency from libc */
107
int main(int argc, char *argv[])
111
int main(int argc, char *argv[])
108
{
112
{
109
    return 0;
113
    return 0;
110
}
114
}
111
/*
115
/*
112
typedef void (*ep2)(void *);
116
typedef void (*ep2)(void *);
113
 
117
 
114
void program_run(void *entry, pcb_t *pcb)
118
void program_run(void *entry, pcb_t *pcb)
115
{
119
{
116
    asm (
120
    asm (
117
//      "xorl %%ebx, %%ebx\n"
121
//      "xorl %%ebx, %%ebx\n"
118
//      "movl 0(%%ebx), %%ecx\n"
122
//      "movl 0(%%ebx), %%ecx\n"
119
        "mov %%eax, %%ebx\n"
123
        "mov %%eax, %%ebx\n"
120
        "jmp *%0\n"
124
        "jmp *%0\n"
121
        :: "m" (entry), "a" (pcb)
125
        :: "m" (entry), "a" (pcb)
122
    );
126
    );
123
}*/
127
}*/
124
 
128
 
125
/** @}
129
/** @}
126
 */
130
 */
127
 
131