Search
lxdream.org :: lxdream :: r105:1faa0745f200
lxdream 0.9.1
released Jun 29
Download Now
changeset105:1faa0745f200
parent104:94b2d9962b59
child106:9048bac046c3
authornkeynes
dateTue Mar 14 11:44:29 2006 +0000 (18 years ago)
Add elf loader suppt
src/loader.c
src/main.c
1.1 --- a/src/loader.c Tue Mar 14 11:44:04 2006 +0000
1.2 +++ b/src/loader.c Tue Mar 14 11:44:29 2006 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: loader.c,v 1.10 2006-02-05 04:04:25 nkeynes Exp $
1.6 + * $Id: loader.c,v 1.11 2006-03-14 11:44:29 nkeynes Exp $
1.7 *
1.8 * File loading routines, mostly for loading demos without going through the
1.9 * whole procedure of making a CD image for them.
1.10 @@ -22,6 +22,7 @@
1.11 #include <sys/stat.h>
1.12 #include <errno.h>
1.13 #include <stdint.h>
1.14 +#include <elf.h>
1.15 #include "gui/gui.h"
1.16 #include "mem.h"
1.17 #include "sh4core.h"
1.18 @@ -93,9 +94,11 @@
1.19 } else if( memcmp( buf, "PK\x03\x04", 4 ) == 0 ) {
1.20 /* ZIP file, aka SBI file */
1.21 WARN( "SBI files not supported yet" );
1.22 - } else if( memcpy( buf, "\x7fELF", 4 ) == 0 ) {
1.23 + } else if( buf[0] == 0x7F && buf[1] == 'E' &&
1.24 + buf[2] == 'L' && buf[3] == 'F' ) {
1.25 /* ELF binary */
1.26 - WARN( "ELF files not supported yet" );
1.27 + lseek( fd, 0, SEEK_SET );
1.28 + file_load_elf_fd( fd );
1.29 } else {
1.30 /* Assume raw binary */
1.31 file_load_binary( filename );
1.32 @@ -119,3 +122,42 @@
1.33 bios_install();
1.34 gtk_gui_update();
1.35 }
1.36 +
1.37 +int file_load_elf_fd( int fd )
1.38 +{
1.39 + Elf32_Ehdr head;
1.40 + Elf32_Phdr phdr;
1.41 + int i;
1.42 +
1.43 + if( read( fd, &head, sizeof(head) ) != sizeof(head) )
1.44 + return -1;
1.45 + if( head.e_ident[EI_CLASS] != ELFCLASS32 ||
1.46 + head.e_ident[EI_DATA] != ELFDATA2LSB ||
1.47 + head.e_ident[EI_VERSION] != 1 ||
1.48 + head.e_type != ET_EXEC ||
1.49 + head.e_machine != EM_SH ||
1.50 + head.e_version != 1 ) {
1.51 + ERROR( "File is not an SH4 ELF executable file" );
1.52 + return -1;
1.53 + }
1.54 +
1.55 + /* Program headers */
1.56 + for( i=0; i<head.e_phnum; i++ ) {
1.57 + lseek( fd, head.e_phoff + i*head.e_phentsize, SEEK_SET );
1.58 + read( fd, &phdr, sizeof(phdr) );
1.59 + if( phdr.p_type == PT_LOAD ) {
1.60 + lseek( fd, phdr.p_offset, SEEK_SET );
1.61 + char *target = mem_get_region( phdr.p_vaddr );
1.62 + read( fd, target, phdr.p_filesz );
1.63 + if( phdr.p_memsz > phdr.p_filesz ) {
1.64 + memset( target + phdr.p_filesz, 0, phdr.p_memsz - phdr.p_filesz );
1.65 + }
1.66 + INFO( "Loaded %d bytes to %08X", phdr.p_filesz, phdr.p_vaddr );
1.67 + }
1.68 + }
1.69 +
1.70 + sh4_set_pc( head.e_entry );
1.71 + bios_install();
1.72 + dcload_install();
1.73 + gtk_gui_update();
1.74 +}
2.1 --- a/src/main.c Tue Mar 14 11:44:04 2006 +0000
2.2 +++ b/src/main.c Tue Mar 14 11:44:29 2006 +0000
2.3 @@ -1,5 +1,5 @@
2.4 /**
2.5 - * $Id: main.c,v 1.13 2006-02-05 04:05:27 nkeynes Exp $
2.6 + * $Id: main.c,v 1.14 2006-03-14 11:44:29 nkeynes Exp $
2.7 *
2.8 * Main program, initializes dreamcast and gui, then passes control off to
2.9 * the gtk main loop (currently).
2.10 @@ -27,7 +27,7 @@
2.11 #include <gnome.h>
2.12 #include "gui/gui.h"
2.13 #include "dream.h"
2.14 -#include "bios.h"
2.15 +#include "syscall.h"
2.16 #include "dreamcast.h"
2.17
2.18 #define S3M_PLAYER "s3mplay.bin"
2.19 @@ -81,6 +81,7 @@
2.20 } else {
2.21 dreamcast_init();
2.22 }
2.23 +
2.24 } else {
2.25 dreamcast_configure_aica_only();
2.26 mem_load_block( aica_program, 0x00800000, 2048*1024 );
2.27 @@ -96,6 +97,7 @@
2.28
2.29 if( without_bios ) {
2.30 bios_install();
2.31 + dcload_install();
2.32 }
2.33 INFO( "DreamOn! ready..." );
2.34 if( optind < argc ) {
.