OpenCores
URL https://opencores.org/ocsvn/s6soc/s6soc/trunk

Subversion Repositories s6soc

[/] [s6soc/] [trunk/] [sw/] [host/] [zipelf.cpp] - Diff between revs 48 and 52

Show entire file | Details | Blame | View Log

Rev 48 Rev 52
Line 117... Line 117...
                fprintf(stderr, "This is a 64-bit ELF file, ZipCPU ELF files are all 32-bit\n");
                fprintf(stderr, "This is a 64-bit ELF file, ZipCPU ELF files are all 32-bit\n");
                exit(EXIT_FAILURE);
                exit(EXIT_FAILURE);
        }
        }
 
 
        if (dbg) {
        if (dbg) {
        printf("    %-20s 0x%jx\n", "e_type", (uintmax_t)ehdr.e_type);
        fprintf(stderr,"    %-20s 0x%jx\n","e_type", (uintmax_t)ehdr.e_type);
        printf("    %-20s 0x%jx\n", "e_machine", (uintmax_t)ehdr.e_machine);
        fprintf(stderr,"    %-20s 0x%jx\n","e_machine", (uintmax_t)ehdr.e_machine);
        printf("    %-20s 0x%jx\n", "e_version", (uintmax_t)ehdr.e_version);
        fprintf(stderr,"    %-20s 0x%jx\n","e_version", (uintmax_t)ehdr.e_version);
        printf("    %-20s 0x%jx\n", "e_entry", (uintmax_t)ehdr.e_entry);
        fprintf(stderr,"    %-20s 0x%jx\n","e_entry",(uintmax_t)ehdr.e_entry);
        printf("    %-20s 0x%jx\n", "e_phoff", (uintmax_t)ehdr.e_phoff);
        fprintf(stderr,"    %-20s 0x%jx\n","e_phoff",(uintmax_t)ehdr.e_phoff);
        printf("    %-20s 0x%jx\n", "e_shoff", (uintmax_t)ehdr.e_shoff);
        fprintf(stderr,"    %-20s 0x%jx\n","e_shoff",(uintmax_t)ehdr.e_shoff);
        printf("    %-20s 0x%jx\n", "e_flags", (uintmax_t)ehdr.e_flags);
        fprintf(stderr,"    %-20s 0x%jx\n","e_flags",(uintmax_t)ehdr.e_flags);
        printf("    %-20s 0x%jx\n", "e_ehsize", (uintmax_t)ehdr.e_ehsize);
        fprintf(stderr,"    %-20s 0x%jx\n","e_ehsize",(uintmax_t)ehdr.e_ehsize);
        printf("    %-20s 0x%jx\n", "e_phentsize", (uintmax_t)ehdr.e_phentsize);
        fprintf(stderr,"    %-20s 0x%jx\n","e_phentsize", (uintmax_t)ehdr.e_phentsize);
        printf("    %-20s 0x%jx\n", "e_shentsize", (uintmax_t)ehdr.e_shentsize);
        fprintf(stderr,"    %-20s 0x%jx\n","e_shentsize", (uintmax_t)ehdr.e_shentsize);
        printf("\n");
        fprintf(stderr,"\n");
        }
        }
 
 
 
 
        // Check whether or not this is an ELF file for the ZipCPU ...
        // Check whether or not this is an ELF file for the ZipCPU ...
        if (ehdr.e_machine != 0x0dad1) {
        if (ehdr.e_machine != 0x0dad1) {
Line 159... Line 159...
                        fprintf(stderr, "getphdr() failed: %s\n", elf_errmsg(-1));
                        fprintf(stderr, "getphdr() failed: %s\n", elf_errmsg(-1));
                        exit(EXIT_FAILURE);
                        exit(EXIT_FAILURE);
                }
                }
 
 
                if (dbg) {
                if (dbg) {
                printf("    %-20s 0x%x\n", "p_type",   phdr.p_type);
                fprintf(stderr, "    %-20s 0x%x\n", "p_type",   phdr.p_type);
                printf("    %-20s 0x%jx\n", "p_offset", phdr.p_offset);
                fprintf(stderr, "    %-20s 0x%jx\n", "p_offset", phdr.p_offset);
                printf("    %-20s 0x%jx\n", "p_vaddr",  phdr.p_vaddr);
                fprintf(stderr, "    %-20s 0x%jx\n", "p_vaddr",  phdr.p_vaddr);
                printf("    %-20s 0x%jx\n", "p_paddr",  phdr.p_paddr);
                fprintf(stderr, "    %-20s 0x%jx\n", "p_paddr",  phdr.p_paddr);
                printf("    %-20s 0x%jx\n", "p_filesz", phdr.p_filesz);
                fprintf(stderr, "    %-20s 0x%jx\n", "p_filesz", phdr.p_filesz);
                printf("    %-20s 0x%jx\n", "p_memsz",  phdr.p_memsz);
                fprintf(stderr, "    %-20s 0x%jx\n", "p_memsz",  phdr.p_memsz);
                printf("    %-20s 0x%x [", "p_flags",  phdr.p_flags);
                fprintf(stderr, "    %-20s 0x%x [", "p_flags",  phdr.p_flags);
 
 
                if (phdr.p_flags & PF_X)        printf(" Execute");
                if (phdr.p_flags & PF_X)        fprintf(stderr, " Execute");
                if (phdr.p_flags & PF_R)        printf(" Read");
                if (phdr.p_flags & PF_R)        fprintf(stderr, " Read");
                if (phdr.p_flags & PF_W)        printf(" Write");
                if (phdr.p_flags & PF_W)        fprintf(stderr, " Write");
                printf("]\n");
                fprintf(stderr, "]\n");
                printf("    %-20s 0x%jx\n", "p_align", phdr.p_align);
                fprintf(stderr, "    %-20s 0x%jx\n", "p_align", phdr.p_align);
                }
                }
 
 
                total_octets += phdr.p_memsz;
                total_octets += phdr.p_filesz;
        }
        }
 
 
        char    *d = (char *)malloc(total_octets + sizeof(ELFSECTION)+sizeof(ELFSECTION *));
        char    *d = (char *)malloc(total_octets + sizeof(ELFSECTION)+sizeof(ELFSECTION *));
        memset(d, 0, total_octets);
        memset(d, 0, total_octets);
 
 
        ELFSECTION **r = sections = (ELFSECTION **)d;
        ELFSECTION **r = sections = (ELFSECTION **)d;
        current_offset = (n+1)*sizeof(ELFSECTION *);
        current_offset = (n+1)*sizeof(ELFSECTION *);
        current_section = 0;
        current_section = 0;
 
 
        for(i=0; i<(int)n; i++) {
        for(i=0; i<(int)n; i++) {
 
                if (dbg) fprintf(stderr, "Working with &d[%d]\n", current_offset);
                r[i] = (ELFSECTION *)(&d[current_offset]);
                r[i] = (ELFSECTION *)(&d[current_offset]);
 
 
                if (gelf_getphdr(e, i, &phdr) != &phdr) {
                if (gelf_getphdr(e, i, &phdr) != &phdr) {
                        fprintf(stderr, "getphdr() failed: %s\n", elf_errmsg(-1));
                        fprintf(stderr, "getphdr() failed: %s\n", elf_errmsg(-1));
                        exit(EXIT_FAILURE);
                        exit(EXIT_FAILURE);
                }
                }
 
 
                if (dbg) {
                if (dbg) {
                printf("    %-20s 0x%jx\n", "p_offset", phdr.p_offset);
                fprintf(stderr, "    %-20s 0x%jx\n", "p_offset", phdr.p_offset);
                printf("    %-20s 0x%jx\n", "p_vaddr",  phdr.p_vaddr);
                fprintf(stderr, "    %-20s 0x%jx\n", "p_vaddr",  phdr.p_vaddr);
                printf("    %-20s 0x%jx\n", "p_paddr",  phdr.p_paddr);
                fprintf(stderr, "    %-20s 0x%jx\n", "p_paddr",  phdr.p_paddr);
                printf("    %-20s 0x%jx\n", "p_filesz", phdr.p_filesz);
                fprintf(stderr, "    %-20s 0x%jx\n", "p_filesz", phdr.p_filesz);
                printf("    %-20s 0x%jx\n", "p_memsz",  phdr.p_memsz);
                fprintf(stderr, "    %-20s 0x%jx\n", "p_memsz",  phdr.p_memsz);
                printf("    %-20s 0x%x [", "p_flags",  phdr.p_flags);
                fprintf(stderr, "    %-20s 0x%x [", "p_flags",  phdr.p_flags);
 
 
                if (phdr.p_flags & PF_X)        printf(" Execute");
                if (phdr.p_flags & PF_X)        fprintf(stderr, " Execute");
                if (phdr.p_flags & PF_R)        printf(" Read");
                if (phdr.p_flags & PF_R)        fprintf(stderr, " Read");
                if (phdr.p_flags & PF_W)        printf(" Write");
                if (phdr.p_flags & PF_W)        fprintf(stderr, " Write");
                printf("]\n");
                fprintf(stderr, "]\n");
 
 
                printf("    %-20s 0x%jx\n", "p_align", phdr.p_align);
                fprintf(stderr, "    %-20s 0x%jx\n", "p_align", phdr.p_align);
                }
                }
 
 
                current_section++;
                current_section++;
 
 
                r[i]->m_start = phdr.p_paddr;
                r[i]->m_start = phdr.p_paddr;
                r[i]->m_len   = phdr.p_filesz;
                r[i]->m_len   = phdr.p_filesz;
 
 
                current_offset += phdr.p_memsz + sizeof(ELFSECTION);
                current_offset += phdr.p_filesz + sizeof(ELFSECTION);
 
 
                // Now, let's read in our section ...
                // Now, let's read in our section ...
                if (lseek(fd, phdr.p_offset, SEEK_SET) < 0) {
                if (lseek(fd, phdr.p_offset, SEEK_SET) < 0) {
                        fprintf(stderr, "Could not seek to file position %08lx\n", phdr.p_offset);
                        fprintf(stderr, "Could not seek to file position %08lx\n", phdr.p_offset);
                        perror("O/S Err:");
                        perror("O/S Err:");

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.