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

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [examples/] [elf2raw64/] [src/] [elfreader.h] - Blame information for rev 5

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 5 sergeykhbr
#pragma once
2
 
3
#include <inttypes.h>
4
#include <vector>
5
#include "elftypes.h"
6
 
7
class SrcElement {
8
 public:
9
    //uint32 adr;
10
    uint32_t val;
11
    uint8_t *pDataName;    // 0=no name
12
    uint8_t *pFuncName;
13
    uint8_t *pSectionName;
14
    uint8_t *pFileName;
15
    bool  bInit;
16
    char disas[128];
17
};
18
 
19
class SrcImage {
20
 public:
21
    uint32_t entry;
22
    uint32_t iSizeWords;
23
    SrcElement *arr;
24
};
25
 
26
class ElfReader {
27
 public:
28
    ElfReader(const char *file_name);
29
    ~ElfReader();
30
 
31
    bool isOpened() { return iElfFileSize != 0; }
32
    void writeRawImage(const char *file_name, uint32_t fixed_size = 0);
33
    void writeRomHexArray(const char *file_name, uint64_t base_addr,
34
                          uint32_t bytes_per_line, uint32_t fixed_size = 0);
35
 
36
 private:
37
    int iElfFileSize;
38
    uint8_t *elf_img;
39
 
40
    ElfHeaderType *Elf32_Ehdr;
41
    std::vector<SectionHeaderType> section;
42
    std::vector<SymbolTableType> debug_symbols;
43
    std::vector<ProgramHeaderType> program;
44
 
45
    char *pSectionNames;  // .shstrtab
46
    char *pSymbolName;    // .strtab
47
    uint32_t uiRawImageBytes;
48
    SrcImage src_img;
49
 
50
 
51
    void readElfHeader();
52
    void readSections();
53
    void createRawImage();
54
    void attachSymbolsToRawImage();
55
    void readProgramHeader(); // doesn't used information
56
 
57
    void SwapBytes(Elf32_Half &);
58
    void SwapBytes(Elf32_Word &);
59
    void SwapBytes(uint64_t &);
60
    uint32_t read32(uint32_t off);
61
};

powered by: WebSVN 2.1.0

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