/branches/dynload/uspace/app/iramfs/Makefile |
---|
87,6 → 87,5 |
%.o: %.c |
$(CC) $(DEFS) $(CFLAGS) -c $< -o $@ |
data.c: ../../lib/rtld/rtld.so ../tetris/tetris |
../../../tools/bin2c.py ../../lib/rtld/rtld.so rtld.so rtld >$@ |
../../../tools/bin2c.py ../tetris/tetris tetris tetris >>$@ |
data.c: ../../lib/rtld/rtld.so |
../../../tools/bin2c.py $< >$@ |
/branches/dynload/uspace/app/iramfs/data.h |
---|
37,14 → 37,10 |
#include <sys/types.h> |
extern const uint8_t rtld[]; |
extern const size_t rtld_size; |
extern const char rtld_filename[]; |
extern const uint8_t data[]; |
extern const size_t data_size; |
extern const char data_filename[]; |
extern const uint8_t tetris[]; |
extern const size_t tetris_size; |
extern const char tetris_filename[]; |
#endif |
/** @} |
/branches/dynload/uspace/app/iramfs/main.c |
---|
42,25 → 42,33 |
#include "data.h" |
#define min(a,b) ((a)>(b) ? (b) : (a)) |
int write_file(const uint8_t *data, size_t length, const char *file_name) |
int main(int argc, char *argv[]) |
{ |
int fd; |
int cnt; |
int rc; |
int nbytes; |
uint8_t *dp; |
int written; |
int fd; |
int cnt; |
printf("Create %s\n", file_name); |
printf("This is iramfs\n"); |
do { |
rc = mount("tmpfs", "/", "nulldev0"); |
printf("mount tmpfs on / -> %d\n", rc); |
if (rc == 0) break; |
fd = open(file_name, O_CREAT); |
if (fd < 0) { printf("open failed\n"); return -1; } |
usleep(1000 * 1000); |
} while (1); |
printf("write %d bytes...\n", length); |
nbytes = length; dp = data; written = 0; |
fd = open(data_filename, O_CREAT); |
if (fd < 0) { printf("open failed\n"); return 1; } |
printf("write %d bytes...\n", data_size); |
nbytes = data_size; dp = data; written = 0; |
while (nbytes > 0) { |
cnt = write(fd, dp, min(4096, nbytes)); |
if (cnt < 0) { printf("write failed\n"); return -1; } |
if (cnt < 0) { printf("write failed\n"); return 1; } |
dp += cnt; |
written += cnt; |
nbytes -= cnt; |
70,25 → 78,6 |
printf("\n\nwritten %d bytes\n", written); |
close(fd); |
return 0; |
} |
int main(int argc, char *argv[]) |
{ |
int rc; |
printf("This is iramfs\n"); |
do { |
rc = mount("tmpfs", "/", "nulldev0"); |
printf("mount tmpfs on / -> %d\n", rc); |
if (rc == 0) break; |
usleep(1000 * 1000); |
} while (1); |
if (write_file(rtld, rtld_size, rtld_filename) < 0) return 1; |
if (write_file(tetris, tetris_size, tetris_filename) < 0) return 1; |
printf("done\n"); |
getchar(); |
return 0; |
/branches/dynload/uspace/app/iloader/main.c |
---|
38,10 → 38,8 |
#include <unistd.h> |
#include <fcntl.h> |
#include <sys/types.h> |
#include <as.h> |
#include "elf.h" |
#include "pcb.h" |
unsigned int elf_load(int fd, elf_header_t *header); |
78,26 → 76,9 |
/* not reached */ |
} |
void elf_create_pcb(elf_header_t *header) |
{ |
pcb_t *pcb; |
void *a; |
pcb = (pcb_t *)PCB_ADDRESS; |
a = as_area_create(pcb, sizeof(pcb_t), AS_AREA_READ | AS_AREA_WRITE); |
if (a == (void *)(-1)) { |
printf("elf_create_pcb: memory mapping failed\n"); |
return EE_MEMORY; |
} |
pcb->entry = (entry_point_t)header->e_entry; |
} |
int main(int argc, char *argv[]) |
{ |
elf_header_t prog_header; |
elf_header_t interp_header; |
elf_header_t header; |
char *file_name; |
int rc; |
104,29 → 85,18 |
printf("This is loader\n"); |
getchar(); |
printf("Load program\n"); |
file_name = "/test"; |
rc = elf_load_file(file_name, &header); |
printf("open and read '%s'...\n", file_name); |
rc = elf_load_file("/tetris", &prog_header); |
if (rc < 0) { |
printf("failed to load program\n"); |
return 1; |
} |
printf("Create PCB\n"); |
elf_create_pcb(&prog_header); |
printf("run program\n"); |
elf_run(&header); |
printf("Load dynamic linker\n"); |
file_name = "/rtld.so"; |
printf("open and read '%s'...\n", file_name); |
rc = elf_load_file(file_name, &interp_header); |
if (rc < 0) { |
printf("failed to load dynamic linker\n"); |
return 1; |
} |
printf("run dynamic linker\n"); |
elf_run(&interp_header); |
/* not reached */ |
return 0; |
} |
/branches/dynload/uspace/app/iloader/arch/ia32/_link.ld.in |
---|
7,7 → 7,7 |
} |
SECTIONS { |
. = 0x70001000; |
. = 0x40001000; |
.init ALIGN(0x1000) : SUBALIGN(0x1000) { |
*(.init); |