Subversion Repositories HelenOS

Rev

Rev 2996 | 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>
2952 svoboda 40
 
2965 svoboda 41
#include <rtld.h>
2968 svoboda 42
#include <dynamic.h>
2969 svoboda 43
#include <pcb.h>
44
#include <elf_load.h>
2999 svoboda 45
#include <module.h>
2973 svoboda 46
#include <arch.h>
2959 svoboda 47
 
2980 svoboda 48
runtime_env_t runtime_env;
49
 
2933 svoboda 50
void _rtld_main(void)
51
{
2959 svoboda 52
    pcb_t *pcb;
2969 svoboda 53
    elf_info_t lib_info;
2973 svoboda 54
    static module_t prog;
2978 svoboda 55
    static module_t lib;
2981 svoboda 56
    module_t *rtld;
2969 svoboda 57
    int rc;
2933 svoboda 58
 
2959 svoboda 59
    printf("Hello, world! (from rtld)\n");
2933 svoboda 60
 
2999 svoboda 61
    /*
62
     * First we need to process dynamic sections of the two modules
63
     * that have been already loaded, that is, of ourselves and of
64
     * the executable program.
65
     */
66
 
2981 svoboda 67
    /* rtld_dynamic and rtld->bias were filled out by the bootstrap code */
68
    rtld = &runtime_env.rtld;
2996 svoboda 69
    printf("Parse rtld .dynamic section at 0x%x\n", runtime_env.rtld_dynamic);
2981 svoboda 70
    dynamic_parse(runtime_env.rtld_dynamic, rtld->bias, &rtld->dyn);
71
 
2990 svoboda 72
    pcb = __pcb_get();
2996 svoboda 73
    printf("Parse program .dynamic section at 0x%x\n", pcb->dynamic);
2973 svoboda 74
    dynamic_parse(pcb->dynamic, 0, &prog.dyn);
2978 svoboda 75
    prog.bias = 0;
2980 svoboda 76
    prog.dyn.soname = "[program]";
2969 svoboda 77
 
2999 svoboda 78
    /* Initialize list of loaded modules */
79
    list_initialize(&runtime_env.modules_head);
80
    list_append(&prog.modules_link, &runtime_env.modules_head);
81
    list_append(&rtld->modules_link, &runtime_env.modules_head);
2969 svoboda 82
 
2999 svoboda 83
    /* Pointer to program module. Used as root of the dependency graph */
2980 svoboda 84
    runtime_env.program = &prog;
85
 
2999 svoboda 86
    /*
87
     * Now we can continue with loading all other modules.
88
     */
2973 svoboda 89
 
2999 svoboda 90
    printf("Load all program dependencies\n");
91
    module_load_deps(&prog);
2981 svoboda 92
 
2999 svoboda 93
    /*
94
     * Now relocate/link all modules together.
95
     */
2980 svoboda 96
 
2999 svoboda 97
    /* Process relocations in all modules */
98
    printf("Relocate all modules\n");
99
    modules_process_relocs();
100
 
101
    /*
102
     * Finally, run the main program.
103
     */
2996 svoboda 104
    printf("Run program.. (at 0x%x)\n", (uintptr_t)pcb->entry);
2959 svoboda 105
    pcb->entry();
2933 svoboda 106
}
107
 
108
/** @}
109
 */