Subversion Repositories HelenOS

Rev

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

Rev 2961 Rev 2962
Line 39... Line 39...
39
#include <fcntl.h>
39
#include <fcntl.h>
40
#include <sys/types.h>
40
#include <sys/types.h>
41
#include <as.h>
41
#include <as.h>
42
 
42
 
43
#include "elf.h"
43
#include "elf.h"
44
#include "pcb.h"
44
#include "elf_load.h"
45
 
-
 
46
unsigned int elf_load(int fd, elf_header_t *header);
-
 
47
 
-
 
48
typedef void (*entry_point_t)(void);
-
 
49
 
-
 
50
static int elf_load_file(char *file_name, elf_header_t *header)
-
 
51
{
-
 
52
    int fd;
-
 
53
    int rc;
-
 
54
 
-
 
55
    printf("open and read '%s'...\n", file_name);
-
 
56
 
-
 
57
    fd = open(file_name, 0);
-
 
58
    if (fd < 0) {
-
 
59
        printf("failed opening file\n");
-
 
60
        return -1;
-
 
61
    }
-
 
62
 
-
 
63
    rc = elf_load(fd, header);
-
 
64
    printf("elf_load() -> %d\n", rc);
-
 
65
 
-
 
66
    close(fd);
-
 
67
 
-
 
68
    return rc;
-
 
69
}
-
 
70
 
-
 
71
static void elf_run(elf_header_t *header)
-
 
72
{
-
 
73
    entry_point_t entry_point;
-
 
74
 
-
 
75
    entry_point = (entry_point_t)header->e_entry;
-
 
76
    (*entry_point)();
-
 
77
 
-
 
78
    /* not reached */
-
 
79
}
-
 
80
 
-
 
81
static int elf_create_pcb(elf_header_t *header)
-
 
82
{
-
 
83
    pcb_t *pcb;
-
 
84
    void *a;
-
 
85
 
-
 
86
    pcb = (pcb_t *)PCB_ADDRESS;
-
 
87
 
-
 
88
    a = as_area_create(pcb, sizeof(pcb_t), AS_AREA_READ | AS_AREA_WRITE);
-
 
89
    if (a == (void *)(-1)) {
-
 
90
        printf("elf_create_pcb: memory mapping failed\n");
-
 
91
        return EE_MEMORY;
-
 
92
    }
-
 
93
 
-
 
94
    pcb->entry = (entry_point_t)header->e_entry;
-
 
95
 
-
 
96
    return 0;
-
 
97
}
-
 
98
 
45
 
99
int main(int argc, char *argv[])
46
int main(int argc, char *argv[])
100
{
47
{
101
    elf_header_t prog_header;
48
    elf_header_t prog_header;
102
    elf_header_t interp_header;
49
    elf_header_t interp_header;