Subversion Repositories HelenOS

Rev

Rev 3673 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2933 svoboda 1
/*
2
 * Copyright (c) 2008 Jiri Svoboda
3
 * All rights reserved.
4
 *
5
 * Redistribution and use in source and binary forms, with or without
6
 * modification, are permitted provided that the following conditions
7
 * are met:
8
 *
9
 * - Redistributions of source code must retain the above copyright
10
 *   notice, this list of conditions and the following disclaimer.
11
 * - Redistributions in binary form must reproduce the above copyright
12
 *   notice, this list of conditions and the following disclaimer in the
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
15
 *   derived from this software without specific prior written permission.
16
 *
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
19
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
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
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
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
 */
28
 
29
/** @addtogroup rtld rtld
30
 * @brief
31
 * @{
32
 */
33
/**
34
 * @file
35
 */
36
 
2952 svoboda 37
#include <stdio.h>
2954 svoboda 38
#include <unistd.h>
39
#include <fcntl.h>
3400 svoboda 40
#include <loader/pcb.h>
2952 svoboda 41
 
2965 svoboda 42
#include <rtld.h>
2968 svoboda 43
#include <dynamic.h>
2969 svoboda 44
#include <elf_load.h>
2999 svoboda 45
#include <module.h>
3400 svoboda 46
#include <rtld_arch.h>
2959 svoboda 47
 
2980 svoboda 48
runtime_env_t runtime_env;
49
 
3400 svoboda 50
void program_run(void *entry, pcb_t *pcb);
51
 
3673 svoboda 52
static void rtld_main(void)
2933 svoboda 53
{
2973 svoboda 54
    static module_t prog;
2933 svoboda 55
 
3562 svoboda 56
    DPRINTF("Hello, world! (from rtld)\n");
2933 svoboda 57
 
2999 svoboda 58
    /*
3677 svoboda 59
     * First we need to process dynamic sections of the executable
60
     * program and insert it into the module graph.
2999 svoboda 61
     */
62
 
3562 svoboda 63
    DPRINTF("Parse program .dynamic section at 0x%x\n", __pcb->dynamic);
3400 svoboda 64
    dynamic_parse(__pcb->dynamic, 0, &prog.dyn);
2978 svoboda 65
    prog.bias = 0;
2980 svoboda 66
    prog.dyn.soname = "[program]";
2969 svoboda 67
 
2999 svoboda 68
    /* Initialize list of loaded modules */
69
    list_initialize(&runtime_env.modules_head);
70
    list_append(&prog.modules_link, &runtime_env.modules_head);
2969 svoboda 71
 
3677 svoboda 72
    /* Pointer to program module. Used as root of the module graph. */
2980 svoboda 73
    runtime_env.program = &prog;
74
 
2999 svoboda 75
    /*
76
     * Now we can continue with loading all other modules.
77
     */
2973 svoboda 78
 
3562 svoboda 79
    DPRINTF("Load all program dependencies\n");
2999 svoboda 80
    module_load_deps(&prog);
2981 svoboda 81
 
2999 svoboda 82
    /*
83
     * Now relocate/link all modules together.
84
     */
2980 svoboda 85
 
2999 svoboda 86
    /* Process relocations in all modules */
3562 svoboda 87
    DPRINTF("Relocate all modules\n");
2999 svoboda 88
    modules_process_relocs();
89
 
90
    /*
91
     * Finally, run the main program.
92
     */
3673 svoboda 93
    DPRINTF("Run program.. (at 0x%lx)\n", (uintptr_t)__pcb->entry);
3562 svoboda 94
 
95
#ifndef RTLD_DEBUG
96
    close_console();
97
#endif
3400 svoboda 98
    program_run(__pcb->entry, __pcb);
2933 svoboda 99
}
100
 
3400 svoboda 101
int main(int argc, char *argv[])
102
{
3673 svoboda 103
    rtld_main();
3400 svoboda 104
    return 0;
105
}
106
 
2933 svoboda 107
/** @}
108
 */