Subversion Repositories HelenOS

Rev

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

Rev 3561 Rev 3677
Line 57... Line 57...
57
#include <as.h>
57
#include <as.h>
58
 
58
 
59
#include <elf.h>
59
#include <elf.h>
60
#include <elf_load.h>
60
#include <elf_load.h>
61
 
61
 
62
/**
-
 
63
 * Bias used for loading the dynamic linker. This will be soon replaced
-
 
64
 * by automatic placement.
-
 
65
 */
-
 
66
#define RTLD_BIAS 0x80000
-
 
67
 
-
 
68
/** Pathname of the file that will be loaded */
62
/** Pathname of the file that will be loaded */
69
static char *pathname = NULL;
63
static char *pathname = NULL;
70
 
64
 
71
/** The Program control block */
65
/** The Program control block */
72
static pcb_t pcb;
66
static pcb_t pcb;
Line 227... Line 221...
227
 */
221
 */
228
static int loader_load(ipc_callid_t rid, ipc_call_t *request)
222
static int loader_load(ipc_callid_t rid, ipc_call_t *request)
229
{
223
{
230
    int rc;
224
    int rc;
231
 
225
 
232
//  printf("Load program '%s'\n", pathname);
-
 
233
 
-
 
234
    rc = elf_load_file(pathname, 0, 0, &prog_info);
226
    rc = elf_load_file(pathname, 0, 0, &prog_info);
235
    if (rc < 0) {
227
    if (rc < 0) {
236
        printf("failed to load program\n");
228
        printf("Failed to load executable '%s'.\n", pathname);
237
        ipc_answer_0(rid, EINVAL);
229
        ipc_answer_0(rid, EINVAL);
238
        return 1;
230
        return 1;
239
    }
231
    }
240
 
232
 
241
//  printf("Create PCB\n");
-
 
242
    elf_create_pcb(&prog_info, &pcb);
233
    elf_create_pcb(&prog_info, &pcb);
243
 
234
 
244
    pcb.argc = argc;
235
    pcb.argc = argc;
245
    pcb.argv = argv;
236
    pcb.argv = argv;
246
 
237
 
247
    if (prog_info.interp == NULL) {
238
    if (prog_info.interp == NULL) {
248
        /* Statically linked program */
239
        /* Statically linked program */
249
//      printf("Run statically linked program\n");
-
 
250
//      printf("entry point: 0x%lx\n", prog_info.entry);
-
 
251
        is_dyn_linked = false;
240
        is_dyn_linked = false;
252
        ipc_answer_0(rid, EOK);
241
        ipc_answer_0(rid, EOK);
253
        return 0;
242
        return 0;
254
    }
243
    }
255
 
244
 
256
    printf("Load dynamic linker '%s'\n", prog_info.interp);
245
    printf("Load ELF interpreter '%s'\n", prog_info.interp);
257
    rc = elf_load_file(prog_info.interp, RTLD_BIAS, 0, &interp_info);
246
    rc = elf_load_file(prog_info.interp, 0, 0, &interp_info);
258
    if (rc < 0) {
247
    if (rc < 0) {
259
        printf("failed to load dynamic linker\n");
248
        printf("Failed to load interpreter '%s.'\n", prog_info.interp);
260
        ipc_answer_0(rid, EINVAL);
249
        ipc_answer_0(rid, EINVAL);
261
        return 1;
250
        return 1;
262
    }
251
    }
263
 
252
 
264
    /*
-
 
265
     * Provide dynamic linker with some useful data
-
 
266
     */
-
 
267
    pcb.rtld_dynamic = interp_info.dynamic;
-
 
268
    pcb.rtld_bias = RTLD_BIAS;
-
 
269
 
-
 
270
    printf("run dynamic linker\n");
253
    printf("Run interpreter.\n");
271
    printf("rtld_dynamic = 0x%lx\n", pcb.rtld_dynamic);
-
 
272
    printf("entry point: 0x%lx\n", interp_info.entry);
254
    printf("entry point: 0x%lx\n", interp_info.entry);
273
    printf("pcb address: 0x%lx\n", &pcb);
255
    printf("pcb address: 0x%lx\n", &pcb);
274
 
256
 
275
    is_dyn_linked = true;
257
    is_dyn_linked = true;
276
    ipc_answer_0(rid, EOK);
258
    ipc_answer_0(rid, EOK);