Subversion Repositories HelenOS

Rev

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

Rev 2961 Rev 2962
Line 40... Line 40...
40
#include <stdio.h>
40
#include <stdio.h>
41
#include <sys/types.h>
41
#include <sys/types.h>
42
#include <align.h>
42
#include <align.h>
43
#include <assert.h>
43
#include <assert.h>
44
#include <as.h>
44
#include <as.h>
-
 
45
#include <unistd.h>
-
 
46
#include <fcntl.h>
-
 
47
 
45
#include "elf.h"
48
#include "elf.h"
-
 
49
#include "pcb.h"
-
 
50
#include "elf_load.h"
46
 
51
 
47
#define RTLD_BIAS 0x80000
52
#define RTLD_BIAS 0x80000
48
//#define RTLD_BIAS 0
53
//#define RTLD_BIAS 0
49
 
54
 
50
static char *error_codes[] = {
55
static char *error_codes[] = {
Line 54... Line 59...
54
    "incompatible image",
59
    "incompatible image",
55
    "unsupported image type",
60
    "unsupported image type",
56
    "irrecoverable error"
61
    "irrecoverable error"
57
};
62
};
58
 
63
 
-
 
64
static unsigned int elf_load(int fd, elf_header_t *header);
59
static int segment_header(int fd, elf_header_t *elf);
65
static int segment_header(int fd, elf_header_t *elf);
60
static int section_header(int fd, elf_header_t *elf);
66
static int section_header(int fd, elf_header_t *elf);
61
static int load_segment(int fd, elf_segment_header_t *entry, elf_header_t *elf);
67
static int load_segment(int fd, elf_segment_header_t *entry, elf_header_t *elf);
62
 
68
 
63
typedef void (*epoint_t)(void);
69
typedef void (*entry_point_t)(void);
-
 
70
 
-
 
71
int elf_load_file(char *file_name, elf_header_t *header)
-
 
72
{
-
 
73
    int fd;
-
 
74
    int rc;
-
 
75
 
-
 
76
    printf("open and read '%s'...\n", file_name);
-
 
77
 
-
 
78
    fd = open(file_name, 0);
-
 
79
    if (fd < 0) {
-
 
80
        printf("failed opening file\n");
-
 
81
        return -1;
-
 
82
    }
-
 
83
 
-
 
84
    rc = elf_load(fd, header);
-
 
85
    printf("elf_load() -> %d\n", rc);
-
 
86
 
-
 
87
    close(fd);
-
 
88
 
-
 
89
    return rc;
-
 
90
}
-
 
91
 
-
 
92
void elf_run(elf_header_t *header)
-
 
93
{
-
 
94
    entry_point_t entry_point;
-
 
95
 
-
 
96
    entry_point = (entry_point_t)header->e_entry;
-
 
97
    (*entry_point)();
-
 
98
 
-
 
99
    /* not reached */
-
 
100
}
-
 
101
 
-
 
102
int elf_create_pcb(elf_header_t *header)
-
 
103
{
-
 
104
    pcb_t *pcb;
-
 
105
    void *a;
-
 
106
 
-
 
107
    pcb = (pcb_t *)PCB_ADDRESS;
-
 
108
 
-
 
109
    a = as_area_create(pcb, sizeof(pcb_t), AS_AREA_READ | AS_AREA_WRITE);
-
 
110
    if (a == (void *)(-1)) {
-
 
111
        printf("elf_create_pcb: memory mapping failed\n");
-
 
112
        return EE_MEMORY;
-
 
113
    }
-
 
114
 
-
 
115
    pcb->entry = (entry_point_t)header->e_entry;
-
 
116
 
-
 
117
    return 0;
-
 
118
}
-
 
119
 
64
 
120
 
65
/** ELF loader
121
/** ELF loader
66
 *
122
 *
67
 * @param header Pointer to ELF header in memory
123
 * @param header Pointer to ELF header in memory
68
 * @return EE_OK on success
124
 * @return EE_OK on success
69
 */
125
 */
70
unsigned int elf_load(int fd, elf_header_t *header)
126
static unsigned int elf_load(int fd, elf_header_t *header)
71
{
127
{
72
    int i, rc;
128
    int i, rc;
73
 
129
 
74
    rc = read(fd, header, sizeof(elf_header_t));
130
    rc = read(fd, header, sizeof(elf_header_t));
75
    if (rc < 0) {
131
    if (rc < 0) {