diff options
-rw-r--r-- | sbe/image/Makefile | 34 | ||||
-rw-r--r-- | sbe/image/base_loader.c | 23 | ||||
-rw-r--r-- | sbe/image/base_ppe_header.S | 33 | ||||
-rw-r--r-- | sbe/image/img_defs.mk | 1 | ||||
-rw-r--r-- | sbe/image/linkloader.cmd | 72 | ||||
-rw-r--r-- | sbe/image/linksbe.cmd | 1 | ||||
-rw-r--r-- | sbe/image/linkseeprom.cmd | 8 | ||||
-rw-r--r-- | sbe/image/sbe_loader.c | 22 | ||||
-rw-r--r-- | sbe/image/sbe_xip_image.c | 156 | ||||
-rw-r--r-- | sbe/image/sbe_xip_image.h | 130 | ||||
-rw-r--r-- | sbe/image/topfiles.mk | 2 | ||||
-rw-r--r-- | tools/image/p9_image_help_base.H | 2 | ||||
-rw-r--r-- | tools/image/sbe_xip_tool.c | 876 |
13 files changed, 663 insertions, 697 deletions
diff --git a/sbe/image/Makefile b/sbe/image/Makefile index 6fcea4af..80efb5eb 100644 --- a/sbe/image/Makefile +++ b/sbe/image/Makefile @@ -85,6 +85,7 @@ LINK_OBJS += $(OBJS) $(GCCLIBS) LINK_SCRIPT_SEEPROM = $(addprefix $(OBJDIR)/, linkscriptseeprom) LINK_SCRIPT_SBE = $(addprefix $(OBJDIR)/, linkscriptsbe) +LINK_SCRIPT_LOADER = $(addprefix $(OBJDIR)/, linkscriptloader) #default target is to make a binary application image @@ -117,7 +118,25 @@ $(OBJDIR)/$(IMAGE_SBE_NAME).out: $(OBJDIR)/base_sbe_fixed.o $(LINK_OBJS) $(LINK_ $(LINK_SCRIPT_SBE): linksbe.cmd $(CPP) -E -x c++ -P $(DEFS) linksbe.cmd -o $(LINK_SCRIPT_SBE) -all: $(OBJDIR)/$(IMAGE_SEEPROM_NAME).bin $(OBJDIR)/$(IMAGE_SBE_NAME).bin $(SBE_TOOLS) normalize defaultset $(OBJDIR)/fixed.bin + + + +$(OBJDIR)/$(IMAGE_LOADER_NAME).bin $(OBJDIR)/$(IMAGE_LOADER_NAME).dis: $(OBJDIR)/$(IMAGE_LOADER_NAME).out + $(OBJCOPY) -O binary $< $(OBJDIR)/$(IMAGE_LOADER_NAME).bin --pad-to 0x`/usr/bin/nm $(OBJDIR)/$(IMAGE_LOADER_NAME).out | grep "A _loader_end" | cut -d " " -f 1` + $(OBJDUMP) -S $< > $(OBJDIR)/$(IMAGE_LOADER_NAME).dis + +#create a linked ELF executable +$(OBJDIR)/$(IMAGE_LOADER_NAME).out: $(OBJDIR)/base_loader.o $(LINK_OBJS) $(LINK_SCRIPT_LOADER) + $(LD) -e base_loader -T$(LINK_SCRIPT_LOADER) -Map $(OBJDIR)/$(IMAGE_LOADER_NAME).map -Bstatic -o $(OBJDIR)/$(IMAGE_LOADER_NAME).out $(LIB_DIRS) $(OBJDIR)/base_loader.o --start-group $(SBEFWLIB) $(LLIBS) --end-group + +#pass the link command file through the C preprocessor to evaluate macros and remove comments +$(LINK_SCRIPT_LOADER): linkloader.cmd + $(CPP) -E -x c++ -P $(DEFS) linkloader.cmd -o $(LINK_SCRIPT_LOADER) + + + + +all: $(OBJDIR)/$(IMAGE_SEEPROM_NAME).bin $(OBJDIR)/$(IMAGE_SBE_NAME).bin $(OBJDIR)/$(IMAGE_LOADER_NAME).bin $(SBE_TOOLS) normalize defaultset $(OBJDIR)/fixed.bin appendbase appendloader #Create an obj directory if needed $(LINK_OBJS) $(OBJS) $(OBJS:.o=.d) $(OBJDIR)/base_sbe_fixed.o $(OBJDIR)/base_sbe_fixed.d: | $(OBJDIR) @@ -210,6 +229,15 @@ defaultset: $(SBE_TOOLS) $(OBJDIR)/$(IMAGE_SEEPROM_NAME).bin normalize $(OBJDIR)/fixed.bin: $(OBJDIR)/$(IMAGE_SEEPROM_NAME).bin $(TOOLS_IMAGE_DIR)/sbe_xip_tool $(OBJDIR)/$(IMAGE_SEEPROM_NAME).bin extract .fixed $(BASE_OBJDIR)/fixed.bin + +appendbase: $(OBJDIR)/$(IMAGE_SEEPROM_NAME).bin $(OBJDIR)/$(IMAGE_SBE_NAME).bin + $(TOOLS_IMAGE_DIR)/sbe_xip_tool $(OBJDIR)/$(IMAGE_SEEPROM_NAME).bin append .base $(OBJDIR)/$(IMAGE_SBE_NAME).bin + + + +appendloader: $(OBJDIR)/$(IMAGE_SEEPROM_NAME).bin $(OBJDIR)/$(IMAGE_LOADER_NAME).bin + $(TOOLS_IMAGE_DIR)/sbe_xip_tool $(OBJDIR)/$(IMAGE_SEEPROM_NAME).bin append .baseloader $(OBJDIR)/$(IMAGE_LOADER_NAME).bin + #/afs/bb/proj/cte/tools/ppetools/prod/powerpc-eabi/bin/objcopy -O binary --only-section=.fixed $(OBJDIR)/$(IMAGE_SEEPROM_NAME).out $(OBJDIR)/fixed.bin # collect all of the trace hash files for this image into a single trexStringFile @@ -221,9 +249,9 @@ tracehash: #clean the kernel directory first, then the application level clean clean: rm -fr $(OBJDIR) - rm $(TOP-FIXED-HEADERS) + rm -f $(TOP-FIXED-HEADERS) rm -fr $(TOOLS_IMAGE_DIR)/bin/* - rm *.dump + rm -f *.dump dump: diff --git a/sbe/image/base_loader.c b/sbe/image/base_loader.c new file mode 100644 index 00000000..c9717bcd --- /dev/null +++ b/sbe/image/base_loader.c @@ -0,0 +1,23 @@ +#include "sbe_xip_image.h" +#include "sbetrace.H" + +int32_t base_loader(); + + +int32_t base_loader() { + + int32_t rc = 0; + + SbeXipHeader *hdr = 0;//getXipHdr(); + uint32_t idx; + + + for(idx = 0; idx < SBE_XIP_SECTIONS; idx++) { + + SBE_TRACE("Section Idx:%u Size:0x%08X", idx, hdr->iv_section[idx].iv_size); + + } + + return rc; +} + diff --git a/sbe/image/base_ppe_header.S b/sbe/image/base_ppe_header.S index 0d0d3a0d..28614b08 100644 --- a/sbe/image/base_ppe_header.S +++ b/sbe/image/base_ppe_header.S @@ -13,12 +13,12 @@ #include "proc_sbe_fixed.H" -#define PORE_SPACE_UNDEFINED 0xffff -#define PORE_SPACE_OCI 0x8000 -#define PORE_SPACE_PNOR 0x800b -#define PORE_SPACE_OTPROM 0x0001 -#define PORE_SPACE_SEEPROM 0x800c -#define PORE_SPACE_PIBMEM 0x0008 +#define IMAGE_SPACE_UNDEFINED 0xffff +#define IMAGE_SPACE_OCI 0x8000 +#define IMAGE_SPACE_PNOR 0x800b +#define IMAGE_SPACE_OTPROM 0x0001 +#define IMAGE_SPACE_SEEPROM 0x800c +#define IMAGE_SPACE_BASE 0x0008 @@ -49,7 +49,7 @@ .endm .macro ..check_default_space - .if (_PGAS_DEFAULT_SPACE == PORE_SPACE_UNDEFINED) + .if (_PGAS_DEFAULT_SPACE == IMAGE_SPACE_UNDEFINED) .error "The PGAS default address space has not been defined" .endif .endm @@ -108,19 +108,16 @@ __header_64_reserved: SbeXipSection header SbeXipSection fixed, 8 SbeXipSection fixed_toc, 8 - SbeXipSection ipl_text, 4 - SbeXipSection ipl_data, 8 + SbeXipSection loader_text, 4 + SbeXipSection loader_data, 8 SbeXipSection text, 4 SbeXipSection data, 8 SbeXipSection toc, 4 SbeXipSection strings - SbeXipSection halt, 4, empty=1 - SbeXipSection pibmem0, 8, empty=1 - SbeXipSection dcrings, 8, empty=1 + SbeXipSection base, 4, empty=1 + SbeXipSection baseloader, 8, empty=1 + SbeXipSection overlay, 8, empty=1 SbeXipSection rings, 8, empty=1 - SbeXipSection slw, 128, empty=1 - SbeXipSection fit, empty=1 - SbeXipSection ffdc, 8, empty=1 ////////////////////////////////////////////////////////////////////// @@ -179,13 +176,13 @@ __header_string_reserved: .section .fixed, "a", @progbits .section .fixed_toc, "a", @progbits - .section .ipl_data, "a", @progbits - .section .ipl_text, "a", @progbits + .section .loader_data, "a", @progbits + .section .loader_text, "a", @progbits .section .toc, "a", @progbits .section .strings, "aS", @progbits - ..set_default_space PORE_SPACE_SEEPROM + ..set_default_space IMAGE_SPACE_SEEPROM SbeXipHeader SBE_SEEPROM_MAGIC, 0xFFF00000, 0xFFF00C78, _seeprom_size // Create the .fixed section diff --git a/sbe/image/img_defs.mk b/sbe/image/img_defs.mk index abf3bcf6..3be16a72 100644 --- a/sbe/image/img_defs.mk +++ b/sbe/image/img_defs.mk @@ -34,6 +34,7 @@ IMAGE_SEEPROM_NAME := seeprom_main IMAGE_SBE_NAME := sbe_main +IMAGE_LOADER_NAME := loader_main PPE_TYPE := std diff --git a/sbe/image/linkloader.cmd b/sbe/image/linkloader.cmd new file mode 100644 index 00000000..b89748bc --- /dev/null +++ b/sbe/image/linkloader.cmd @@ -0,0 +1,72 @@ + +// Need to do this so that elf32-powerpc is not modified! +#undef powerpc + +#ifndef INITIAL_STACK_SIZE +#define INITIAL_STACK_SIZE 256 +#endif + +OUTPUT_FORMAT(elf32-powerpc); + +MEMORY +{ + sram : ORIGIN = 0xffff2000, LENGTH = 0x10000 +} + +SECTIONS +{ + . = 0xffff2000; + + //////////////////////////////// + // Read-only Data + //////////////////////////////// + + . = ALIGN(8); + _RODATA_SECTION_BASE = .; + + .text . : { *(.text) } > sram + .data . : { *(.data) } > sram + + // SDA2 constant sections .sdata2 and .sbss2 must be adjacent to each + // other. Our SDATA sections are small so we'll use strictly positive + // offsets. + + _SDA2_BASE_ = .; + .sdata2 . : { *(.sdata2) } > sram + .sbss2 . : { *(.sbss2) } > sram + + // Other read-only data. + + .rodata . : { *(.rodata*) *(.got2) } > sram + + _RODATA_SECTION_SIZE = . - _RODATA_SECTION_BASE; + + //////////////////////////////// + // Read-write Data + //////////////////////////////// + + . = ALIGN(8); + _DATA_SECTION_BASE = .; + + // SDA sections .sdata and .sbss must be adjacent to each + // other. Our SDATA sections are small so we'll use strictly positive + // offsets. + + _SDA_BASE_ = .; + .sdata . : { *(.sdata) } > sram + .sbss . : { *(.sbss) } > sram + + // Other read-write data + // It's not clear why boot.S is generating empty .glink,.iplt + + .rela . : { *(.rela*) } > sram + .rwdata . : { *(.data) *(.bss) } > sram + + _PK_INITIAL_STACK_LIMIT = .; + . = . + INITIAL_STACK_SIZE; + _PK_INITIAL_STACK = . - 1; + + . = ALIGN(8); + _loader_end = . - 0; + +} diff --git a/sbe/image/linksbe.cmd b/sbe/image/linksbe.cmd index 95cbaa49..0f7435db 100644 --- a/sbe/image/linksbe.cmd +++ b/sbe/image/linksbe.cmd @@ -62,7 +62,6 @@ SECTIONS .rela . : { *(.rela*) } > sram .rwdata . : { *(.data) *(.bss) } > sram -// .iplt . : { *(.iplt) } > sram _PK_INITIAL_STACK_LIMIT = .; . = . + INITIAL_STACK_SIZE; diff --git a/sbe/image/linkseeprom.cmd b/sbe/image/linkseeprom.cmd index f127ea8a..42ee99e2 100644 --- a/sbe/image/linkseeprom.cmd +++ b/sbe/image/linkseeprom.cmd @@ -27,14 +27,14 @@ SECTIONS . = ALIGN(8); _fixed_toc_origin = .; _fixed_toc_offset = . - _seeprom_origin; .fixed_toc . : { *(.fixed_toc) } _fixed_toc_size = . - _fixed_toc_origin; //////////////////////////////// - // IPL_TEXT + // LOADER_TEXT //////////////////////////////// - . = ALIGN(4); _ipl_text_origin = .; _ipl_text_offset = . - _seeprom_origin; .ipl_text . : { *(.ipl_text) } _ipl_text_size = . - _ipl_text_origin; + . = ALIGN(4); _loader_text_origin = .; _loader_text_offset = . - _seeprom_origin; .loader_text . : { *(.loader_text) } _loader_text_size = . - _loader_text_origin; //////////////////////////////// - // IPL_DATA + // LOADER_DATA //////////////////////////////// - . = ALIGN(8); _ipl_data_origin = .; _ipl_data_offset = . - _seeprom_origin; .ipl_data . : { *(.ipl_data) } _ipl_data_size = . - _ipl_data_origin; + . = ALIGN(8); _loader_data_origin = .; _loader_data_offset = . - _seeprom_origin; .loader_data . : { *(.loader_data) } _loader_data_size = . - _loader_data_origin; //////////////////////////////// // TEXT diff --git a/sbe/image/sbe_loader.c b/sbe/image/sbe_loader.c new file mode 100644 index 00000000..30fbda59 --- /dev/null +++ b/sbe/image/sbe_loader.c @@ -0,0 +1,22 @@ +#include "sbe_xip_image.h" +#include "sbetrace.H" + +int32_t sbe_loader() __attribute__ ((section (".loader_text"))); + + +int32_t sbe_loader() { + + int32_t rc = 0; + + SbeXipHeader *hdr = 0;//getXipHdr(); + uint32_t idx; + + + for(idx = 0; idx < SBE_XIP_SECTIONS; idx++) { + + SBE_TRACE("Section Idx:%u Size:0x%08X", idx, hdr->iv_section[idx].iv_size); + + } + + return rc; +} diff --git a/sbe/image/sbe_xip_image.c b/sbe/image/sbe_xip_image.c index 91576d50..270b450d 100644 --- a/sbe/image/sbe_xip_image.c +++ b/sbe/image/sbe_xip_image.c @@ -1,5 +1,3 @@ -// $Id: sbe_xip_image.c,v 1.28 2013/12/11 00:12:41 bcbrock Exp $ - /// \file sbe_xip_image.c /// \brief APIs for validating, normalizing, searching and manipulating /// SBE-XIP images. @@ -1735,115 +1733,6 @@ sbe_xip_find(void* i_image, } -int -sbe_xip_map_halt(void* io_image, - int (*i_fn)(void* io_image, - const uint64_t i_imageAddress, - const char* i_rcString, - void* io_arg), - void* io_arg) -{ - int rc; - SbeXipSection haltSection; - SbeXipHalt *halt; - uint32_t size; - uint32_t actualSize; - - do { - rc = xipQuickCheck(io_image, 0); - if (rc) break; - - rc = sbe_xip_get_section(io_image, SBE_XIP_SECTION_HALT, &haltSection); - if (rc) break; - - halt = (SbeXipHalt*)((unsigned long)io_image + haltSection.iv_offset); - size = haltSection.iv_size; - - while (size) { - - rc = i_fn(io_image, - xipRevLe64(halt->iv_address), - halt->iv_string, - io_arg); - if (rc) break; - - // The SbeXipHalt structure claims a 4-character string. The - // computation below computes the actual record size based on the - // actual length of the string, including the 0-byte termination. - - actualSize = 8 + (((strlen(halt->iv_string) + 4) / 4) * 4); - - if (size < actualSize) { - rc = TRACE_ERRORX(SBE_XIP_IMAGE_ERROR, - "The .halt section is improperly formed\n"); - break; - } - - size -= actualSize; - halt = (SbeXipHalt*)((unsigned long)halt + actualSize); - }; - - if (rc) break; - - } while (0); - - return rc; -} - - -typedef struct { - uint64_t iv_address; - const char* iv_string; -} GetHaltStruct; - - -XIP_STATIC int -xipGetHaltMap(void* io_image, - const uint64_t i_imageAddress, - const char* i_rcString, - void* io_arg) -{ - int rc; - - GetHaltStruct* s = (GetHaltStruct*)io_arg; - - if (i_imageAddress == s->iv_address) { - s->iv_string = i_rcString; - rc = -1; - } else { - rc = 0; - } - - return rc; -} - - -int -sbe_xip_get_halt(void* io_image, - const uint64_t i_imageAddress, - const char** o_rcString) -{ - int rc; - GetHaltStruct s; - - s.iv_address = i_imageAddress; - do { - rc = xipQuickCheck(io_image, 0); - if (rc) break; - - rc = sbe_xip_map_halt(io_image, xipGetHaltMap, &s); - if (rc == 0) { - rc = TRACE_ERRORX(SBE_XIP_ITEM_NOT_FOUND, - "sbe_xip_get_halt: No HALT code is associated " - "with address " F0x012llx "\n", i_imageAddress); - } else if (rc < 0) { - *o_rcString = s.iv_string; - rc = 0; - } - } while (0); - - return rc; -} int @@ -1858,12 +1747,27 @@ sbe_xip_get_scalar(void *i_image, const char* i_id, uint64_t* o_data) case SBE_XIP_UINT8: *o_data = *((uint8_t*)(item.iv_imageData)); break; + case SBE_XIP_UINT16: + *o_data = xipRevLe16(*((uint16_t*)(item.iv_imageData))); + break; case SBE_XIP_UINT32: *o_data = xipRevLe32(*((uint32_t*)(item.iv_imageData))); break; case SBE_XIP_UINT64: *o_data = xipRevLe64(*((uint64_t*)(item.iv_imageData))); break; + case SBE_XIP_INT8: + *o_data = *((int8_t*)(item.iv_imageData)); + break; + case SBE_XIP_INT16: + *o_data = xipRevLe16(*((int16_t*)(item.iv_imageData))); + break; + case SBE_XIP_INT32: + *o_data = xipRevLe32(*((int32_t*)(item.iv_imageData))); + break; + case SBE_XIP_INT64: + *o_data = xipRevLe64(*((int64_t*)(item.iv_imageData))); + break; case SBE_XIP_ADDRESS: *o_data = item.iv_address; break; @@ -1898,12 +1802,27 @@ sbe_xip_get_element(void *i_image, case SBE_XIP_UINT8: *o_data = ((uint8_t*)(item.iv_imageData))[i_index]; break; + case SBE_XIP_UINT16: + *o_data = xipRevLe16(((uint16_t*)(item.iv_imageData))[i_index]); + break; case SBE_XIP_UINT32: *o_data = xipRevLe32(((uint32_t*)(item.iv_imageData))[i_index]); break; case SBE_XIP_UINT64: *o_data = xipRevLe64(((uint64_t*)(item.iv_imageData))[i_index]); break; + case SBE_XIP_INT8: + *o_data = ((int8_t*)(item.iv_imageData))[i_index]; + break; + case SBE_XIP_INT16: + *o_data = xipRevLe16(((int16_t*)(item.iv_imageData))[i_index]); + break; + case SBE_XIP_INT32: + *o_data = xipRevLe32(((int32_t*)(item.iv_imageData))[i_index]); + break; + case SBE_XIP_INT64: + *o_data = xipRevLe64(((int64_t*)(item.iv_imageData))[i_index]); + break; default: rc = TRACE_ERROR(SBE_XIP_TYPE_ERROR); break; @@ -1976,12 +1895,27 @@ sbe_xip_set_scalar(void* io_image, const char* i_id, const uint64_t i_data) case SBE_XIP_UINT8: *((uint8_t*)(item.iv_imageData)) = (uint8_t)i_data; break; + case SBE_XIP_UINT16: + *((uint16_t*)(item.iv_imageData)) = xipRevLe16((uint16_t)i_data); + break; case SBE_XIP_UINT32: *((uint32_t*)(item.iv_imageData)) = xipRevLe32((uint32_t)i_data); break; case SBE_XIP_UINT64: *((uint64_t*)(item.iv_imageData)) = xipRevLe64((uint64_t)i_data); break; + case SBE_XIP_INT8: + *((int8_t*)(item.iv_imageData)) = (int8_t)i_data; + break; + case SBE_XIP_INT16: + *((int16_t*)(item.iv_imageData)) = xipRevLe16((int16_t)i_data); + break; + case SBE_XIP_INT32: + *((int32_t*)(item.iv_imageData)) = xipRevLe32((int32_t)i_data); + break; + case SBE_XIP_INT64: + *((int64_t*)(item.iv_imageData)) = xipRevLe64((int64_t)i_data); + break; default: rc = TRACE_ERROR(SBE_XIP_TYPE_ERROR); break; diff --git a/sbe/image/sbe_xip_image.h b/sbe/image/sbe_xip_image.h index 696f5a63..fc1bf47c 100644 --- a/sbe/image/sbe_xip_image.h +++ b/sbe/image/sbe_xip_image.h @@ -56,21 +56,18 @@ #define SBE_XIP_SECTION_HEADER 0 #define SBE_XIP_SECTION_FIXED 1 #define SBE_XIP_SECTION_FIXED_TOC 2 -#define SBE_XIP_SECTION_IPL_TEXT 3 -#define SBE_XIP_SECTION_IPL_DATA 4 +#define SBE_XIP_SECTION_LOADER_TEXT 3 +#define SBE_XIP_SECTION_LOADER_DATA 4 #define SBE_XIP_SECTION_TEXT 5 #define SBE_XIP_SECTION_DATA 6 #define SBE_XIP_SECTION_TOC 7 #define SBE_XIP_SECTION_STRINGS 8 -#define SBE_XIP_SECTION_HALT 9 -#define SBE_XIP_SECTION_PIBMEM0 10 -#define SBE_XIP_SECTION_DCRINGS 11 +#define SBE_XIP_SECTION_BASE 9 +#define SBE_XIP_SECTION_BASELOADER 10 +#define SBE_XIP_SECTION_OVERLAYS 11 #define SBE_XIP_SECTION_RINGS 12 -#define SBE_XIP_SECTION_SLW 13 -#define SBE_XIP_SECTION_FIT 14 -#define SBE_XIP_SECTION_FFDC 15 -#define SBE_XIP_SECTIONS 16 +#define SBE_XIP_SECTIONS 13 /// @} @@ -99,19 +96,16 @@ ".header", \ ".fixed", \ ".fixed_toc", \ - ".ipl_text", \ - ".ipl_data", \ + ".loader_text", \ + ".loader_data", \ ".text", \ ".data", \ ".toc", \ ".strings", \ - ".halt", \ - ".pibmem0", \ - ".dcrings", \ + ".base", \ + ".baseloader", \ + ".overlays", \ ".rings", \ - ".slw", \ - ".fit", \ - ".ffdc", \ } /// Applications can use this macro to safely index the array of section @@ -578,41 +572,6 @@ typedef struct { } SbeXipItem; -/// Prototype entry in the .halt section -/// -/// The .halt section is generated by the 'reqhalt' macro. This structure -/// associates the address of each halt with the string form of the FAPI -/// return code associated with the halt. The string form is used because the -/// FAPI error return code is not constant. The .halt section is 4-byte -/// aligned, and each address/string entry is always padded to a multiple of 4 -/// bytes. -/// -/// In the .halt section the \a iv_string may be any length, thus the size of -/// each actual record is variable (although guaranteed to always be a -/// multiple of 4 bytes). Although the C compiler might natuarlly align -/// instances of this structure on a 64-bit boundary, the APIs that allow -/// access to the .halt section assume that the underlying machine can do -/// non-aligned loads from a pointer to this structure. - -typedef struct { - - /// The 64-bit relocatable address of the halt - /// - /// This is the address found in the PC (Status Register bits 16:63) when - /// the image halts. The full 64-bit form is used rather than the simple - /// 32-bit offset to support merging SEEPROM and PIBMEM .halt sections in - /// the SEEPROM IPL images. - uint64_t iv_address; - - /// A C-prototype for a variable-length 0-terminated ASCII string - /// - /// This is a prototype only to simplify C programming. The actual string - /// may be any length. - char iv_string[4]; - -} SbeXipHalt; - - /// Validate an SBE-XIP image /// /// \param[in] i_image A pointer to an SBE-XIP image in host memory. @@ -1024,73 +983,6 @@ sbe_xip_find(void* i_image, SbeXipItem* o_item); -/// Map over an SBE-XIP image .halt section -/// -/// \param[in,out] io_image A pointer to an SBE-XIP image in host memory. The -/// image is assumed to be consistent with the information contained in the -/// header regarding the presence of and sizes of all sections. -/// -/// \param[in] i_fn A pointer to a function to call on each entry in .halt. -/// The function has the prototype: -/// -/// \code -/// int (*i_fn)(void* io_image, -/// const uint64_t i_imageAddress, -/// const char* i_rcString, -/// void* io_arg) -/// -/// \endcode -/// -/// \param[in,out] io_arg The private argument of \a i_fn. -/// -/// This API iterates over each entry of the .halt section, calling \a i_fn -/// with each HALT address, the string form of the return code associated with -/// that HALT address, and a private argument. The iteration terminates either -/// when all .halt entries have been mapped, or \a i_fn returns a non-zero -/// code. The \a i_imageAddddress passed to \a i_fn is the full 48-bit -/// relocatable IMAGE address. -/// -/// \retval 0 Success, including the case that the image has no .halt section. -/// -/// \retval non-0 May be either one of the SBE-XIP image error codes (see \ref -/// sbe_xip_image_errors), or any non-zero code from \a i_fn. Since the -/// standard SBE_XIP return codes are \> 0, application-defined codes should -/// be \< 0. -int -sbe_xip_map_halt(void* io_image, - int (*i_fn)(void* io_image, - const uint64_t i_imageAddress, - const char* i_rcString, - void* io_arg), - void* io_arg); - - -/// Get the string from of a HALT code from an SBE-XIP image .halt section -/// -/// \param[in,out] io_image A pointer to an SBE-XIP image in host memory. The -/// image is assumed to be consistent with the information contained in the -/// header regarding the presence of and sizes of all sections. -/// -/// \param[in] i_imageAddress This is the 48-bit address found in the PC when -/// the IMAGE halts. This address is actually 4 bytes beyond the actual HALT -/// instruction, however for simplicity this is the address used to index the -/// HALT. -/// -/// \param[out] o_rcString The caller provides the address of a string-pointer -/// variable which is updated with a pointer to the string form of the halt -/// code associated with \a i_imageAddress (assuming a successful completion). -/// -/// \retval 0 Success -/// -/// \revtal SBE_XIP_ITEM_NOT_FOUND The \a i_imageAddress is not associated -/// with a halt code in .halt. -/// -/// \revtal Other See \ref sbe_xip_image_errors -int -sbe_xip_get_halt(void* io_image, - const uint64_t i_imageAddress, - const char** o_rcString); - /// Delete a section from an SBE-XIP image in host memory /// diff --git a/sbe/image/topfiles.mk b/sbe/image/topfiles.mk index 4e378d4f..88c11bee 100644 --- a/sbe/image/topfiles.mk +++ b/sbe/image/topfiles.mk @@ -1,4 +1,4 @@ -TOP-C-SOURCES = base_ppe_demo.c +TOP-C-SOURCES = base_ppe_demo.c sbe_loader.c TOP-CPP-SOURCES = TOP-S-SOURCES = base_ppe_header.S diff --git a/tools/image/p9_image_help_base.H b/tools/image/p9_image_help_base.H index 9d13b2f4..ff5ce70b 100644 --- a/tools/image/p9_image_help_base.H +++ b/tools/image/p9_image_help_base.H @@ -28,7 +28,7 @@ const uint64_t MAX_UINT64_T = (uint64_t)0xFFFFFFFF<<32 | (uint64_t)0 const uint8_t RING_SECTION_ID[] = { SBE_XIP_SECTION_RINGS, - SBE_XIP_SECTION_DCRINGS, + SBE_XIP_SECTION_OVERLAYS, }; const uint8_t RING_SECTION_ID_SIZE = sizeof(RING_SECTION_ID) / sizeof(RING_SECTION_ID[0]); diff --git a/tools/image/sbe_xip_tool.c b/tools/image/sbe_xip_tool.c index 195a29ef..75448a25 100644 --- a/tools/image/sbe_xip_tool.c +++ b/tools/image/sbe_xip_tool.c @@ -77,13 +77,9 @@ // // The 'report' command prints a report including a dump of the header and // section table, a listing of the types and values of all items that appear -// in the TOC, and a dump of the .halt section. The TOC listing includes the +// in the TOC. The TOC listing includes the // sequence number of the entry in the TOC, the item name, the item type and -// the item value. The .halt listing displays a map of HALT PC values to the -// string form of the halt code associated with the HALT address. The optional -// <regex> expression, if present, is a POSIX Basic Regular Expression. If -// <regex> is specified, then no header, section table or .halt dumps are -// provided, and only the TOC entries matching <regex> will be listed. +// the item value. // // The 'append' command either creates or extends the section named by the // section argument, by appending the contents of the named file verbatim. @@ -158,13 +154,9 @@ const char* g_usage = "\n" "The 'report' command prints a report including a dump of the header and\n" "section table, a listing of the types and values of all items that appear\n" -"in the TOC, and a dump of the .halt section. The TOC listing includes the\n" +"in the TOC. The TOC listing includes the\n" "sequence number of the entry in the TOC, the item name, the item type and\n" -"the item value. The .halt listing displays a map of HALT PC values to the\n" -"string form of the halt code associated with the HALT address. The optional\n" -"<regex> expression, if present, is a POSIX Basic Regular Expression. If\n" -"<regex> is specified, then no header, section table or .halt dumps are\n" -"provided, and only the TOC entries matching <regex> will be listed.\n" +"the item value.\n" "\n" "The 'append' command either creates or extends the section named by the\n" "section argument, by appending the contents of the named file verbatim.\n" @@ -332,16 +324,41 @@ tocListing(void* io_image, if (rc) break; printf("0x%02x", (uint8_t)data); break; + case SBE_XIP_INT8: + rc = sbe_xip_get_scalar(io_image, i_item->iv_id, &data); + if (rc) break; + printf("%d", (int8_t)data); + break; + case SBE_XIP_UINT16: + rc = sbe_xip_get_scalar(io_image, i_item->iv_id, &data); + if (rc) break; + printf("0x%08x", (uint16_t)data); + break; + case SBE_XIP_INT16: + rc = sbe_xip_get_scalar(io_image, i_item->iv_id, &data); + if (rc) break; + printf("%d", (int16_t)data); + break; case SBE_XIP_UINT32: rc = sbe_xip_get_scalar(io_image, i_item->iv_id, &data); if (rc) break; printf("0x%08x", (uint32_t)data); break; + case SBE_XIP_INT32: + rc = sbe_xip_get_scalar(io_image, i_item->iv_id, &data); + if (rc) break; + printf("%d", (int32_t)data); + break; case SBE_XIP_UINT64: rc = sbe_xip_get_scalar(io_image, i_item->iv_id, &data); if (rc) break; printf("0x%016llx", data); break; + case SBE_XIP_INT64: + rc = sbe_xip_get_scalar(io_image, i_item->iv_id, &data); + if (rc) break; + printf("%d", (int64_t)data); + break; case SBE_XIP_STRING: rc = sbe_xip_get_string(io_image, i_item->iv_id, &s); if (rc) break; @@ -355,6 +372,7 @@ tocListing(void* io_image, (uint32_t)(data & 0xffffffff)); break; default: + printf("unknown type\n"); rc = SBE_XIP_BUG; break; } @@ -421,19 +439,6 @@ dumpHeader(void* i_image) } -// Dump an entry from .halt - -int -haltListing(void* io_image, - const uint64_t i_homerAddress, - const char* i_rcString, - void* io_arg) -{ - printf("%016llx : %s\n", i_homerAddress, i_rcString); - return 0; -} - - // Print a report int @@ -475,17 +480,6 @@ report(void* io_image, const int i_argc, const char** i_argv) rc = sbe_xip_map_toc(io_image, tocListing, (void*)(&control)); if (rc) break; - // Dump the .halt section - - if (i_argc == 0) { - printf("\nHALT report\n\n"); - rc = sbe_xip_map_halt(io_image, haltListing, 0); - if (rc == SBE_XIP_ITEM_NOT_FOUND) { - rc = 0; - } - if (rc) break; - } - } while (0); return rc; @@ -550,6 +544,7 @@ set(void* io_image, const int i_argc, const char** i_argv, int i_setv) switch (item.iv_type) { case SBE_XIP_UINT8: + case SBE_XIP_UINT16: case SBE_XIP_UINT32: case SBE_XIP_UINT64: @@ -586,6 +581,15 @@ set(void* io_image, const int i_argc, const char** i_argv, int i_setv) } break; + case SBE_XIP_UINT16: + if ((uint16_t)newValue != newValue) { + fprintf(stderr, + "Value 0x%016llx too large for 16-bit type\n", + newValue); + exit(1); + } + break; + case SBE_XIP_UINT32: if ((uint32_t)newValue != newValue) { fprintf(stderr, @@ -616,7 +620,18 @@ set(void* io_image, const int i_argc, const char** i_argv, int i_setv) rc = sbe_xip_set_string(io_image, key, (char*)value); if (rc) rc = SBE_XIP_BUG; break; - + case SBE_XIP_INT8: + case SBE_XIP_INT16: + case SBE_XIP_INT32: + case SBE_XIP_INT64: + fprintf(stderr, + "Item %s has int type %s, " + "which is not supported for '%s'.\n", + i_argv[arg], + SBE_XIP_TYPE_STRING(g_typeStrings, item.iv_type), + (i_setv ? "setv" : "set")); + exit(1); + break; default: fprintf(stderr, "Item %s has type %s, " @@ -713,6 +728,7 @@ get(void* i_image, const int i_argc, const char** i_argv, int i_getv) switch (item.iv_type) { case SBE_XIP_UINT8: + case SBE_XIP_UINT16: case SBE_XIP_UINT32: case SBE_XIP_UINT64: rc = sbe_xip_get_element(i_image, key, index_val, &data); @@ -724,6 +740,9 @@ get(void* i_image, const int i_argc, const char** i_argv, int i_getv) case SBE_XIP_UINT8: printf("0x%02x\n", (uint8_t)data); break; + case SBE_XIP_UINT16: + printf("0x%04x\n", (uint16_t)data); + break; case SBE_XIP_UINT32: printf("0x%08x\n", (uint32_t)data); break; @@ -762,7 +781,14 @@ get(void* i_image, const int i_argc, const char** i_argv, int i_getv) } printf("%s\n", s); break; - + case SBE_XIP_INT8: + case SBE_XIP_INT16: + case SBE_XIP_INT32: + case SBE_XIP_INT64: + fprintf(stderr, "%s%d : Bug, int types not implemented %d\n", + __FILE__, __LINE__, item.iv_type); + exit(1); + break; default: fprintf(stderr, "%s%d : Bug, unexpected type %d\n", __FILE__, __LINE__, item.iv_type); @@ -1332,18 +1358,6 @@ TEST(void* io_image, const int i_argc, const char** i_argv) BOMB_IF(sbe_xip_find(io_image, "proc_sbe_ex_dpll_initf", 0) != 0); } - // Run the embedded delete and append tests. This assumes that the - // test image does not contain the .fit and .ffdc sections. We just - // append zeros here, we're mostly interested in whether we can handle - // errors and return the image back to its original state. - - BOMB_IF((deleteAppendImage = malloc(imageSize + 2000)) == 0); - memcpy(deleteAppendImage, io_image, imageSize); - - BOMB_IF(sbe_xip_append(deleteAppendImage, SBE_XIP_SECTION_FIT, - 0, 973, imageSize + 2000, 0) != 0); - BOMB_IF(sbe_xip_append(deleteAppendImage, SBE_XIP_SECTION_FFDC, - 0, 973, imageSize + 2000, 0) != 0); #ifdef DEBUG_SBE_XIP_IMAGE printf("\nYou will see an expected warning below " @@ -1351,14 +1365,6 @@ TEST(void* io_image, const int i_argc, const char** i_argv) "It means the TEST is working (not failing)\n\n"); #endif - BOMB_IF(sbe_xip_append(deleteAppendImage, SBE_XIP_SECTION_FFDC, - 0, 973, imageSize + 2000, 0) == 0); - - BOMB_IF(sbe_xip_delete_section(deleteAppendImage, SBE_XIP_SECTION_FFDC) != 0); - BOMB_IF(sbe_xip_delete_section(deleteAppendImage, SBE_XIP_SECTION_FIT) != 0); - - memcpy(io_image, deleteAppendImage, imageSize); - // Finally compare against the original BOMB_IF(memcmp(io_image, originalImage, imageSize)); @@ -1473,440 +1479,432 @@ int disassembleSection(void *i_image, int i_argc, const char **i_argv) { - int rc=0, rcSet=0; - uint32_t rcCount=0; - char *disList=NULL; - uint32_t sizeSection=0, nextLinkOffsetBlock=0; - uint32_t sizeBlock=0, sizeData=0, sizeCode=0, sizeData2=0; - uint32_t sizeDisLine=0, sizeList=0, sizeListMax=0; - uint32_t offsetCode=0; - uint8_t typeRingsSection=0; // 0: RS4 1: Wiggle-Flip - uint8_t bSummary=0, bFoundInToc=0; - uint32_t sectionId; - uint64_t backPtr=0, fwdPtr=0; - PairingInfo pairingInfo; - const char *sectionName; + int rc=0, rcSet=0; + uint32_t rcCount=0; + char *disList=NULL; + uint32_t sizeSection=0, nextLinkOffsetBlock=0; + uint32_t sizeBlock=0, sizeData=0, sizeCode=0, sizeData2=0; + uint32_t sizeDisLine=0, sizeList=0, sizeListMax=0; + uint32_t offsetCode=0; + uint8_t typeRingsSection=0; // 0: RS4 1: Wiggle-Flip + uint8_t bSummary=0, bFoundInToc=0; + uint32_t sectionId; + uint64_t backPtr=0, fwdPtr=0; + PairingInfo pairingInfo; + const char *sectionName; char *ringName; uint32_t ringSeqNo=0; // Ring sequence location counter. uint8_t vectorPos,overRidable; - void *nextBlock, *nextSection; - SbeXipHeader hostHeader; - SbeXipSection hostSection; - ImageInlineContext ctx; - ImageInlineDisassembly dis; - char lineDis[LISTING_STRING_SIZE]; - void *hostRs4Container; - uint32_t compressedBits=0, ringLength=0; - double compressionPct=0; - - if (i_argc != 1) { - fprintf(stderr, g_usage); - exit(1); - } - sectionName = i_argv[0]; - - // Determine SBE-XIP section ID from the section name, e.g. - // .ipl_text => SBE_XIP_SECTION_IPL_TEXT - // .text => SBE_XIP_SECTION_TEXT - // .rings => SBE_XIP_SECTION_RINGS - if (strcmp(sectionName, ".header")==0) - sectionId = SBE_XIP_SECTION_HEADER; - else - if (strcmp(sectionName, ".fixed")==0) - sectionId = SBE_XIP_SECTION_FIXED; - else - if (strcmp(sectionName, ".fixed_toc")==0) - sectionId = SBE_XIP_SECTION_FIXED_TOC; - else - if (strcmp(sectionName, ".ipl_text")==0) - sectionId = SBE_XIP_SECTION_IPL_TEXT; - else - if (strcmp(sectionName, ".ipl_data")==0) - sectionId = SBE_XIP_SECTION_IPL_DATA; - else - if (strcmp(sectionName, ".text")==0) - sectionId = SBE_XIP_SECTION_TEXT; - else - if (strcmp(sectionName, ".data")==0) - sectionId = SBE_XIP_SECTION_DATA; - else - if (strcmp(sectionName, ".toc")==0) - sectionId = SBE_XIP_SECTION_TOC; - else - if (strcmp(sectionName, ".strings")==0) - sectionId = SBE_XIP_SECTION_STRINGS; - else - if (strcmp(sectionName, ".pibmem0")==0) - sectionId = SBE_XIP_SECTION_PIBMEM0; - else - if (strcmp(sectionName, ".rings")==0) - sectionId = SBE_XIP_SECTION_RINGS; - else - if (strcmp(sectionName, ".rings_summary")==0) { - sectionId = SBE_XIP_SECTION_RINGS; - bSummary = 1; - } - else - if (strcmp(sectionName, ".dcrings")==0) - sectionId = SBE_XIP_SECTION_DCRINGS; - else - if (strcmp(sectionName, ".halt")==0) - sectionId = SBE_XIP_SECTION_HALT; - else - if (strcmp(sectionName, ".slw")==0) - sectionId = SBE_XIP_SECTION_SLW; - else - if (strcmp(sectionName, ".ffdc")==0) - sectionId = SBE_XIP_SECTION_FFDC; - else { - fprintf(stderr,"ERROR : %s is an invalid section name.\n",sectionName); - fprintf(stderr,"Valid <section> names for the 'dis' function are:\n"); - fprintf(stderr,"\t.header\n"); - fprintf(stderr,"\t.fixed\n"); - fprintf(stderr,"\t.fixed_toc\n"); - fprintf(stderr,"\t.ipl_text\n"); - fprintf(stderr,"\t.ipl_data\n"); - fprintf(stderr,"\t.text\n"); - fprintf(stderr,"\t.data\n"); - fprintf(stderr,"\t.toc\n"); - fprintf(stderr,"\t.strings\n"); - fprintf(stderr,"\t.pibmem0\n"); - fprintf(stderr,"\t.rings\n"); - fprintf(stderr,"\t.rings_summary\n"); - fprintf(stderr,"\t.dcrings\n"); - fprintf(stderr,"\t.halt\n"); - fprintf(stderr,"\t.slw\n"); - fprintf(stderr,"\t.ffdc\n"); - exit(1); - } - - // Get host header and section pointer. - // - sbe_xip_translate_header( &hostHeader, (SbeXipHeader*)i_image); - rc = sbe_xip_get_section( i_image, sectionId, &hostSection); - if (rc) { - fprintf( stderr, "sbe_xip_get_section() failed : %s\n", SBE_XIP_ERROR_STRING(g_errorStrings, rc)); - return SBE_XIP_DISASSEMBLER_ERROR; - } - sizeSection = hostSection.iv_size; - nextBlock = (void*)(hostSection.iv_offset + (uintptr_t)i_image); - nextSection = (void*)((uint64_t)nextBlock + (uint64_t)sizeSection); + void *nextBlock, *nextSection; + SbeXipHeader hostHeader; + SbeXipSection hostSection; + ImageInlineContext ctx; + ImageInlineDisassembly dis; + char lineDis[LISTING_STRING_SIZE]; + void *hostRs4Container; + uint32_t compressedBits=0, ringLength=0; + double compressionPct=0; + + if (i_argc != 1) { + fprintf(stderr, g_usage); + exit(1); + } + sectionName = i_argv[0]; + + // Determine SBE-XIP section ID from the section name, e.g. + // .loader_text => SBE_XIP_SECTION_LOADER_TEXT + // .text => SBE_XIP_SECTION_TEXT + // .rings => SBE_XIP_SECTION_RINGS + if (strcmp(sectionName, ".header")==0) + sectionId = SBE_XIP_SECTION_HEADER; + else + if (strcmp(sectionName, ".fixed")==0) + sectionId = SBE_XIP_SECTION_FIXED; + else + if (strcmp(sectionName, ".fixed_toc")==0) + sectionId = SBE_XIP_SECTION_FIXED_TOC; + else + if (strcmp(sectionName, ".loader_text")==0) + sectionId = SBE_XIP_SECTION_LOADER_TEXT; + else + if (strcmp(sectionName, ".loader_data")==0) + sectionId = SBE_XIP_SECTION_LOADER_DATA; + else + if (strcmp(sectionName, ".text")==0) + sectionId = SBE_XIP_SECTION_TEXT; + else + if (strcmp(sectionName, ".data")==0) + sectionId = SBE_XIP_SECTION_DATA; + else + if (strcmp(sectionName, ".toc")==0) + sectionId = SBE_XIP_SECTION_TOC; + else + if (strcmp(sectionName, ".strings")==0) + sectionId = SBE_XIP_SECTION_STRINGS; + else + if (strcmp(sectionName, ".base")==0) + sectionId = SBE_XIP_SECTION_BASE; + else + if (strcmp(sectionName, ".baseloader")==0) + sectionId = SBE_XIP_SECTION_BASELOADER; + else + if (strcmp(sectionName, ".rings")==0) + sectionId = SBE_XIP_SECTION_RINGS; + else + if (strcmp(sectionName, ".rings_summary")==0) { + sectionId = SBE_XIP_SECTION_RINGS; + bSummary = 1; + } + else + if (strcmp(sectionName, ".overlays")==0) + sectionId = SBE_XIP_SECTION_OVERLAYS; + else { + fprintf(stderr,"ERROR : %s is an invalid section name.\n",sectionName); + fprintf(stderr,"Valid <section> names for the 'dis' function are:\n"); + fprintf(stderr,"\t.header\n"); + fprintf(stderr,"\t.fixed\n"); + fprintf(stderr,"\t.fixed_toc\n"); + fprintf(stderr,"\t.loader_text\n"); + fprintf(stderr,"\t.loader_data\n"); + fprintf(stderr,"\t.text\n"); + fprintf(stderr,"\t.data\n"); + fprintf(stderr,"\t.toc\n"); + fprintf(stderr,"\t.strings\n"); + fprintf(stderr,"\t.base\n"); + fprintf(stderr,"\t.baseloader\n"); + fprintf(stderr,"\t.overlays\n"); + fprintf(stderr,"\t.rings\n"); + fprintf(stderr,"\t.rings_summary\n"); + exit(1); + } + + // Get host header and section pointer. + // + sbe_xip_translate_header( &hostHeader, (SbeXipHeader*)i_image); + rc = sbe_xip_get_section( i_image, sectionId, &hostSection); + if (rc) { + fprintf( stderr, "sbe_xip_get_section() failed : %s\n", SBE_XIP_ERROR_STRING(g_errorStrings, rc)); + return SBE_XIP_DISASSEMBLER_ERROR; + } + sizeSection = hostSection.iv_size; + nextBlock = (void*)(hostSection.iv_offset + (uintptr_t)i_image); + nextSection = (void*)((uint64_t)nextBlock + (uint64_t)sizeSection); - // Relocatable offset of section at hand. - nextLinkOffsetBlock = (uint32_t)hostHeader.iv_linkAddress + hostSection.iv_offset; - - // Allocate buffer to hold disassembled listing. (Start out with minimum 10k buffer size.) - // - if (sizeSection>10000) - sizeListMax = sizeSection; // Just to use something as an initial guess. - else - sizeListMax = 10000; - disList = (char*)malloc(sizeListMax); - if (disList==NULL) { - fprintf( stderr, "ERROR : malloc() failed.\n"); - fprintf( stderr, "\tMore info: %s\n", DIS_ERROR_STRING(g_errorStringsDis, DIS_MEMORY_ERROR)); - return SBE_XIP_DISASSEMBLER_ERROR; - } - *disList = '\0'; // Make sure the buffer is NULL terminated (though probably not needed.) - sizeList = 0; - - // Create context and point it to image section. - // - rc = image_inline_context_create( &ctx, - nextBlock, - sizeSection, - nextLinkOffsetBlock, - 0); - if (rc) { - fprintf( stderr, "ERROR : %s (rc=%i)\n",image_inline_error_strings[rc],rc); - fprintf( stderr, "\tMore info: %s\n", DIS_ERROR_STRING(g_errorStringsDis, DIS_DISASM_ERROR)); - return SBE_XIP_DISASSEMBLER_ERROR; - } + // Relocatable offset of section at hand. + nextLinkOffsetBlock = (uint32_t)hostHeader.iv_linkAddress + hostSection.iv_offset; - while ((uint64_t)nextBlock<(uint64_t)nextSection) { + // Allocate buffer to hold disassembled listing. (Start out with minimum 10k buffer size.) + // + if (sizeSection>10000) + sizeListMax = sizeSection; // Just to use something as an initial guess. + else + sizeListMax = 10000; + disList = (char*)malloc(sizeListMax); + if (disList==NULL) { + fprintf( stderr, "ERROR : malloc() failed.\n"); + fprintf( stderr, "\tMore info: %s\n", DIS_ERROR_STRING(g_errorStringsDis, DIS_MEMORY_ERROR)); + return SBE_XIP_DISASSEMBLER_ERROR; + } + *disList = '\0'; // Make sure the buffer is NULL terminated (though probably not needed.) + sizeList = 0; - // Disassemble sections based on their types and intents. + // Create context and point it to image section. // - if (sectionId==SBE_XIP_SECTION_RINGS || sectionId==SBE_XIP_SECTION_DCRINGS) { - // Ring section (with a mix of data and code.) - // ...use BaseRingLayout structure to decode each ring block. - offsetCode = (uint32_t)myRev64(((BaseRingLayout*)nextBlock)->entryOffset); - sizeBlock = myRev32(((BaseRingLayout*)nextBlock)->sizeOfThis); - // ...determine ring type, either RS4 or Wiggle-flip. - if (offsetCode-(myRev32(((BaseRingLayout*)nextBlock)->sizeOfMeta)+3)/4*4>28) { - typeRingsSection = 0; // RS4 w/32-byte header. - sizeData2 = sizeBlock - offsetCode - ASM_RS4_LAUNCH_BUF_SIZE; - } - else - typeRingsSection = 1; // Wiggle-flip w/24-byte header. - // ...get the backPtr and fwdPtr and put at top of disasm listing. - backPtr = myRev64(((BaseRingLayout*)nextBlock)->backItemPtr); - sbe_xip_read_uint64(i_image, - backPtr, - &fwdPtr); + rc = image_inline_context_create( &ctx, + nextBlock, + sizeSection, + nextLinkOffsetBlock, + 0); + if (rc) { + fprintf( stderr, "ERROR : %s (rc=%i)\n",image_inline_error_strings[rc],rc); + fprintf( stderr, "\tMore info: %s\n", DIS_ERROR_STRING(g_errorStringsDis, DIS_DISASM_ERROR)); + return SBE_XIP_DISASSEMBLER_ERROR; + } + + while ((uint64_t)nextBlock<(uint64_t)nextSection) { + + // Disassemble sections based on their types and intents. + // + if (sectionId==SBE_XIP_SECTION_RINGS || sectionId==SBE_XIP_SECTION_OVERLAYS) { + // Ring section (with a mix of data and code.) + // ...use BaseRingLayout structure to decode each ring block. + offsetCode = (uint32_t)myRev64(((BaseRingLayout*)nextBlock)->entryOffset); + sizeBlock = myRev32(((BaseRingLayout*)nextBlock)->sizeOfThis); + // ...determine ring type, either RS4 or Wiggle-flip. + if (offsetCode-(myRev32(((BaseRingLayout*)nextBlock)->sizeOfMeta)+3)/4*4>28) { + typeRingsSection = 0; // RS4 w/32-byte header. + sizeData2 = sizeBlock - offsetCode - ASM_RS4_LAUNCH_BUF_SIZE; + } + else + typeRingsSection = 1; // Wiggle-flip w/24-byte header. + // ...get the backPtr and fwdPtr and put at top of disasm listing. + backPtr = myRev64(((BaseRingLayout*)nextBlock)->backItemPtr); + sbe_xip_read_uint64(i_image, + backPtr, + &fwdPtr); - // Calculate RS4 compression efficiency if RS4 rings. - if (typeRingsSection==0) { - hostRs4Container = (void*)( (uintptr_t)nextBlock + - offsetCode + ASM_RS4_LAUNCH_BUF_SIZE ); - compressedBits = myRev32(((CompressedScanData*)hostRs4Container)->iv_algorithmReserved) * 4; - ringLength = myRev32(((CompressedScanData*)hostRs4Container)->iv_length); - compressionPct = (double)compressedBits / (double)ringLength * 100.0; + // Calculate RS4 compression efficiency if RS4 rings. + if (typeRingsSection==0) { + hostRs4Container = (void*)( (uintptr_t)nextBlock + + offsetCode + ASM_RS4_LAUNCH_BUF_SIZE ); + compressedBits = myRev32(((CompressedScanData*)hostRs4Container)->iv_algorithmReserved) * 4; + ringLength = myRev32(((CompressedScanData*)hostRs4Container)->iv_length); + compressionPct = (double)compressedBits / (double)ringLength * 100.0; } - // + // // Map over TOC or do a targeted search of FIXED_TOC to pair backPtr addr // with ring name and override and/or vector position (i.e. multi-chiplet). // - sbe_xip_get_section( i_image, SBE_XIP_SECTION_TOC, &hostSection); + sbe_xip_get_section( i_image, SBE_XIP_SECTION_TOC, &hostSection); if (hostSection.iv_offset) { - // TOC exists. - pairingInfo.address = backPtr; + // TOC exists. + pairingInfo.address = backPtr; // Search for pairing. First exhaust base position (pos=0), then next, then next, ... for (pairingInfo.vectorpos=0;pairingInfo.vectorpos<32;pairingInfo.vectorpos++) { - rc = sbe_xip_map_toc( i_image, pairRingNameAndAddr, (void*)(&pairingInfo)); + rc = sbe_xip_map_toc( i_image, pairRingNameAndAddr, (void*)(&pairingInfo)); if (rc) break; } - if (rc==DIS_RING_NAME_ADDR_MATCH_FAILURE) { - fprintf( stderr,"ERROR : Error associated with sbe_xip_map_toc().\n"); - fprintf( stderr, "\tMore info: %s\n", DIS_ERROR_STRING(g_errorStringsDis, DIS_RING_NAME_ADDR_MATCH_FAILURE)); - return SBE_XIP_DISASSEMBLER_ERROR; - } - ringSeqNo++; + if (rc==DIS_RING_NAME_ADDR_MATCH_FAILURE) { + fprintf( stderr,"ERROR : Error associated with sbe_xip_map_toc().\n"); + fprintf( stderr, "\tMore info: %s\n", DIS_ERROR_STRING(g_errorStringsDis, DIS_RING_NAME_ADDR_MATCH_FAILURE)); + return SBE_XIP_DISASSEMBLER_ERROR; + } + ringSeqNo++; if (rc==DIS_RING_NAME_ADDR_MATCH_SUCCESS) { bFoundInToc = 1; - ringName = pairingInfo.name; // The ring name matched in pairRingNameAndAddr() + ringName = pairingInfo.name; // The ring name matched in pairRingNameAndAddr() vectorPos = pairingInfo.vectorpos; // The vector position matched in pairRingNameAndAddr() overRidable = pairingInfo.overridable; // Whether the ring supports on override ring. - if (pairingInfo.override) { - sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, - "# ------------------------------\n# %i.\n# ringName = %s (override)\n# vectorPos = %i\n# overRidable = %i\n# backPtr = 0x%08x\n# fwdPtr = 0x%08x\n# Compressed Bits = %u\n# Ring Length Bits = %u\n# Compression = %0.2f%%\n", - ringSeqNo, ringName,vectorPos,overRidable,(uint32_t)backPtr,(uint32_t)fwdPtr,compressedBits,ringLength,compressionPct); - } - else { - sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, - "# ------------------------------\n# %i.\n# ringName = %s (base)\n# vectorPos = %i\n# overRidable = %i\n# backPtr = 0x%08x\n# fwdPtr = 0x%08x\n# Compressed Bits = %u\n# Ring Length Bits = %u\n# Compression = %0.2f%%\n", - ringSeqNo,ringName,vectorPos,overRidable,(uint32_t)backPtr,(uint32_t)fwdPtr,compressedBits,ringLength,compressionPct); - } + if (pairingInfo.override) { + sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, + "# ------------------------------\n# %i.\n# ringName = %s (override)\n# vectorPos = %i\n# overRidable = %i\n# backPtr = 0x%08x\n# fwdPtr = 0x%08x\n# Compressed Bits = %u\n# Ring Length Bits = %u\n# Compression = %0.2f%%\n", + ringSeqNo, ringName,vectorPos,overRidable,(uint32_t)backPtr,(uint32_t)fwdPtr,compressedBits,ringLength,compressionPct); + } + else { + sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, + "# ------------------------------\n# %i.\n# ringName = %s (base)\n# vectorPos = %i\n# overRidable = %i\n# backPtr = 0x%08x\n# fwdPtr = 0x%08x\n# Compressed Bits = %u\n# Ring Length Bits = %u\n# Compression = %0.2f%%\n", + ringSeqNo,ringName,vectorPos,overRidable,(uint32_t)backPtr,(uint32_t)fwdPtr,compressedBits,ringLength,compressionPct); + } } - else { - sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, - "# ------------------------------\n# %i.\n# ringName = Not found (but TOC's available)\n# backPtr = 0x%08x\n# fwdPtr = 0x%08x\n", - ringSeqNo,(uint32_t)backPtr,(uint32_t)fwdPtr); + else { + sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, + "# ------------------------------\n# %i.\n# ringName = Not found (but TOC's available)\n# backPtr = 0x%08x\n# fwdPtr = 0x%08x\n", + ringSeqNo,(uint32_t)backPtr,(uint32_t)fwdPtr); } - } + } else { - // TOC doesn't exist. First try targeted search of MVPD ring names in FIXED_TOC. - bFoundInToc = 0; // If we find in fixed_toc, then change to 1. + // TOC doesn't exist. First try targeted search of MVPD ring names in FIXED_TOC. + bFoundInToc = 0; // If we find in fixed_toc, then change to 1. // 2012-11-13: CMO TBD. Try using pairRingNameAndAddr by enabling a sequential - // traversing of each of the MVPD lists inside that function. You'll - // need to call pairRing manually from right here (or from a - // sbe_xip_search_fixed_toc()-like function). Maybe you can add a + // traversing of each of the MVPD lists inside that function. You'll + // need to call pairRing manually from right here (or from a + // sbe_xip_search_fixed_toc()-like function). Maybe you can add a // 4th arg to pairRing that is zero by default, meaning it is to be // used by xip_map_toc(). But if non-zero, it is to be used in a // traversing manner. Or you could add another member to the - // PairingInfo struct to indirectly pass this info to the function. + // PairingInfo struct to indirectly pass this info to the function. // You'd also need to pass two more arguments to get_vpd_ring_list_ - // entry() to indicate sequence number and the MVPD keyword. - // rc = pairRingNameAndAddr(); + // entry() to indicate sequence number and the MVPD keyword. + // rc = pairRingNameAndAddr(); // if (rc==DIS_RING_NAME_ADDR_MATCH_SUCCESS) { - // bFoundInToc = 1; - // // Do same as in TOC section above. - // break; - // } - // // OK, so ring name wasn't in TOC nor in FIXED_TOC. That happens if the ring - // // is a non-Mvpd ring and the TOC has been removed, such as in an IPL or - // // Seeprom image. - ringSeqNo++; - if (typeRingsSection==0) { - // RS4 header, which has override info - if (((Rs4RingLayout*)nextBlock)->override==0) { - sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, - "# ------------------------------\n# %i.\n# ringName = Not available (base)\n# backPtr = 0x%08x\n# fwdPtr = 0x%08x\n# Compressed Bits = %u\n# Ring Length Bits = %u\n# Compression = %0.2f%%\n", - ringSeqNo,(uint32_t)backPtr,(uint32_t)fwdPtr,compressedBits,ringLength,compressionPct); - } + // bFoundInToc = 1; + // // Do same as in TOC section above. + // break; + // } + // // OK, so ring name wasn't in TOC nor in FIXED_TOC. That happens if the ring + // // is a non-Mvpd ring and the TOC has been removed, such as in an IPL or + // // Seeprom image. + ringSeqNo++; + if (typeRingsSection==0) { + // RS4 header, which has override info + if (((Rs4RingLayout*)nextBlock)->override==0) { + sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, + "# ------------------------------\n# %i.\n# ringName = Not available (base)\n# backPtr = 0x%08x\n# fwdPtr = 0x%08x\n# Compressed Bits = %u\n# Ring Length Bits = %u\n# Compression = %0.2f%%\n", + ringSeqNo,(uint32_t)backPtr,(uint32_t)fwdPtr,compressedBits,ringLength,compressionPct); + } else { - sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, - "# ------------------------------\n# %i.\n# ringName = Not available (override)\n# backPtr = 0x%08x\n# fwdPtr = 0x%08x\n# Compressed Bits = %u\n# Ring Length Bits = %u\n# Compression = %0.2f%%\n", - ringSeqNo,(uint32_t)backPtr,(uint32_t)fwdPtr,compressedBits,ringLength,compressionPct); + sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, + "# ------------------------------\n# %i.\n# ringName = Not available (override)\n# backPtr = 0x%08x\n# fwdPtr = 0x%08x\n# Compressed Bits = %u\n# Ring Length Bits = %u\n# Compression = %0.2f%%\n", + ringSeqNo,(uint32_t)backPtr,(uint32_t)fwdPtr,compressedBits,ringLength,compressionPct); } - } + } else { - // WF header, which doesn't have override info - sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, - "# ------------------------------\n# %i.\n# ringName and override = Not available\n# backPtr = 0x%08x\n# fwdPtr = 0x%08x\n", - ringSeqNo,(uint32_t)backPtr,(uint32_t)fwdPtr); + // WF header, which doesn't have override info + sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, + "# ------------------------------\n# %i.\n# ringName and override = Not available\n# backPtr = 0x%08x\n# fwdPtr = 0x%08x\n", + ringSeqNo,(uint32_t)backPtr,(uint32_t)fwdPtr); } - } - sizeList = sizeList + sizeDisLine; - disList = strcat(disList,lineDis); + } + sizeList = sizeList + sizeDisLine; + disList = strcat(disList,lineDis); } - else if ( sectionId==SBE_XIP_SECTION_IPL_TEXT || - sectionId==SBE_XIP_SECTION_TEXT) { - // Sections that have only code. - offsetCode = 0; - sizeBlock = sizeSection; - } - else { - // Sections that have only data. - offsetCode = sizeSection; - sizeBlock = sizeSection; - } - sizeData = offsetCode; - sizeCode = sizeBlock - offsetCode - sizeData2; - - if (sectionId==SBE_XIP_SECTION_RINGS && bSummary) { - // - // Summarize rings section. - - if (typeRingsSection==0) { // RS4 header. - sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, - "# ddLevel = 0x%02x\n# override= %i\n# sysPhase= %i\n# Block size= %i\n", - myRev32(((Rs4RingLayout*)nextBlock)->ddLevel), - ((Rs4RingLayout*)nextBlock)->override, - ((Rs4RingLayout*)nextBlock)->sysPhase, - sizeBlock); - } - else { // WF header. + else if ( sectionId==SBE_XIP_SECTION_LOADER_TEXT || + sectionId==SBE_XIP_SECTION_TEXT) { + // Sections that have only code. + offsetCode = 0; + sizeBlock = sizeSection; + } + else { + // Sections that have only data. + offsetCode = sizeSection; + sizeBlock = sizeSection; + } + sizeData = offsetCode; + sizeCode = sizeBlock - offsetCode - sizeData2; + + if (sectionId==SBE_XIP_SECTION_RINGS && bSummary) { + // + // Summarize rings section. + + if (typeRingsSection==0) { // RS4 header. + sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, + "# ddLevel = 0x%02x\n# override= %i\n# sysPhase= %i\n# Block size= %i\n", + myRev32(((Rs4RingLayout*)nextBlock)->ddLevel), + ((Rs4RingLayout*)nextBlock)->override, + ((Rs4RingLayout*)nextBlock)->sysPhase, + sizeBlock); + } + else { // WF header. if (bFoundInToc) { - sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, - "# override= %i\n# Block size= %i\n", - pairingInfo.override, sizeBlock); + sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, + "# override= %i\n# Block size= %i\n", + pairingInfo.override, sizeBlock); } else { - sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, - "# override= Not available\n# Block size= %i\n", - sizeBlock); + sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, + "# override= Not available\n# Block size= %i\n", + sizeBlock); } - } - sizeList = sizeList + sizeDisLine; - disList = strcat(disList,lineDis); - // Readjust list buffer size, if needed. - if (sizeList > sizeListMax-1000) { - sizeListMax = 2*sizeListMax; - disList = (char*)realloc( (void*)(disList), sizeListMax); - } - - } - else { - // - // Do disassembly. - - // ...data disassembly - if (sizeData>0) { - ctx.options = IMAGE_INLINE_LISTING_MODE | IMAGE_INLINE_DISASSEMBLE_DATA; - do { - rc = image_inline_disassemble( &ctx, &dis); - sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE,"%s\n",dis.s); - sizeList = sizeList + sizeDisLine; - disList = strcat(disList,lineDis); - if (rc) { - rcSet = rcSet | 0x1; - sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, - "WARNING: %s (rc=%i) -> Stopping disasm. Check code and sectionID=%i.\n", - image_inline_error_strings[rc],rc,sectionId); + } sizeList = sizeList + sizeDisLine; disList = strcat(disList,lineDis); - } - // Readjust list buffer size, if needed. - if (sizeList > sizeListMax-1000) { - sizeListMax = 2*sizeListMax; - disList = (char*)realloc( (void*)(disList), sizeListMax); - } - } while (rc==0 && ctx.lc<nextLinkOffsetBlock+sizeData); - } - if (rcSet) - rc = 0; - - // ...code disassembly - if (sizeCode>0) { - ctx.options = IMAGE_INLINE_LISTING_MODE; - do { - rc = image_inline_disassemble( &ctx, &dis); - ctx.options = IMAGE_INLINE_LISTING_MODE; - sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE,"%s\n",dis.s); - sizeList = sizeList + sizeDisLine; - disList = strcat(disList,lineDis); - if (rc && rcCount<100) { - rcSet = rcSet | 0x2; - rcCount++; - if (sectionId==SBE_XIP_SECTION_RINGS) { - sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, - "WARNING: %s (rc=%i) -> Trying data disasm mode. Check code, xyzRingLayout structures and image section.\n", - image_inline_error_strings[rc],rc); + // Readjust list buffer size, if needed. + if (sizeList > sizeListMax-1000) { + sizeListMax = 2*sizeListMax; + disList = (char*)realloc( (void*)(disList), sizeListMax); } - else { - sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, - "WARNING: %s (rc=%i) -> Trying data disasm mode.\n", - image_inline_error_strings[rc],rc); + + } + else { + // + // Do disassembly. + + // ...data disassembly + if (sizeData>0) { + ctx.options = IMAGE_INLINE_LISTING_MODE | IMAGE_INLINE_DISASSEMBLE_DATA; + do { + rc = image_inline_disassemble( &ctx, &dis); + sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE,"%s\n",dis.s); + sizeList = sizeList + sizeDisLine; + disList = strcat(disList,lineDis); + if (rc) { + rcSet = rcSet | 0x1; + sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, + "WARNING: %s (rc=%i) -> Stopping disasm. Check code and sectionID=%i.\n", + image_inline_error_strings[rc],rc,sectionId); + sizeList = sizeList + sizeDisLine; + disList = strcat(disList,lineDis); + } + // Readjust list buffer size, if needed. + if (sizeList > sizeListMax-1000) { + sizeListMax = 2*sizeListMax; + disList = (char*)realloc( (void*)(disList), sizeListMax); + } + } while (rc==0 && ctx.lc<nextLinkOffsetBlock+sizeData); } - sizeList = sizeList + sizeDisLine; - disList = strcat(disList,lineDis); - ctx.options = IMAGE_INLINE_LISTING_MODE | IMAGE_INLINE_DISASSEMBLE_DATA; - rc = 0; - } - else { - if (rc && rcCount>=1000) { - fprintf(stderr, "Too many disasm warnings. Check output listing.\n"); - fprintf( stderr, "\tMore info: %s\n", DIS_ERROR_STRING(g_errorStringsDis, DIS_TOO_MANY_DISASM_WARNINGS)); - return SBE_XIP_DISASSEMBLER_ERROR; + if (rcSet) + rc = 0; + + // ...code disassembly + if (sizeCode>0) { + ctx.options = IMAGE_INLINE_LISTING_MODE; + do { + rc = image_inline_disassemble( &ctx, &dis); + ctx.options = IMAGE_INLINE_LISTING_MODE; + sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE,"%s\n",dis.s); + sizeList = sizeList + sizeDisLine; + disList = strcat(disList,lineDis); + if (rc && rcCount<100) { + rcSet = rcSet | 0x2; + rcCount++; + if (sectionId==SBE_XIP_SECTION_RINGS) { + sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, + "WARNING: %s (rc=%i) -> Trying data disasm mode. Check code, xyzRingLayout structures and image section.\n", + image_inline_error_strings[rc],rc); + } + else { + sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, + "WARNING: %s (rc=%i) -> Trying data disasm mode.\n", + image_inline_error_strings[rc],rc); + } + sizeList = sizeList + sizeDisLine; + disList = strcat(disList,lineDis); + ctx.options = IMAGE_INLINE_LISTING_MODE | IMAGE_INLINE_DISASSEMBLE_DATA; + rc = 0; + } + else { + if (rc && rcCount>=1000) { + fprintf(stderr, "Too many disasm warnings. Check output listing.\n"); + fprintf( stderr, "\tMore info: %s\n", DIS_ERROR_STRING(g_errorStringsDis, DIS_TOO_MANY_DISASM_WARNINGS)); + return SBE_XIP_DISASSEMBLER_ERROR; + } + } + // Readjust list buffer size, if needed. + if (sizeList > sizeListMax-1000) { + sizeListMax = 2*sizeListMax; + disList = (char*)realloc( (void*)(disList), sizeListMax); + } + } while (rc==0 && ctx.lc<nextLinkOffsetBlock+sizeData+sizeCode); } - } - // Readjust list buffer size, if needed. - if (sizeList > sizeListMax-1000) { - sizeListMax = 2*sizeListMax; - disList = (char*)realloc( (void*)(disList), sizeListMax); - } - } while (rc==0 && ctx.lc<nextLinkOffsetBlock+sizeData+sizeCode); - } - if (rcSet) - rc = 0; + if (rcSet) + rc = 0; - // ...data2 disassembly (only done for rings section if RS4 type.) - if (sizeData2>0) { - ctx.options = IMAGE_INLINE_LISTING_MODE | IMAGE_INLINE_DISASSEMBLE_DATA; - do { - rc = image_inline_disassemble( &ctx, &dis); - sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE,"%s\n",dis.s); - sizeList = sizeList + sizeDisLine; - disList = strcat(disList,lineDis); - if (rc) { - rcSet = rcSet | 0x4; - sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, - "WARNING: %s (rc=%i) -> Stopping disasm. Check code and sectionID=%i.\n", - image_inline_error_strings[rc],rc,sectionId); - sizeList = sizeList + sizeDisLine; - disList = strcat(disList,lineDis); - } - // Readjust list buffer size, if needed. - if (sizeList > sizeListMax-1000) { - sizeListMax = 2*sizeListMax; - disList = (char*)realloc( (void*)(disList), sizeListMax); - } - } while (rc==0 && ctx.lc<nextLinkOffsetBlock+sizeBlock); - } - if (rcSet) - rc = 0; + // ...data2 disassembly (only done for rings section if RS4 type.) + if (sizeData2>0) { + ctx.options = IMAGE_INLINE_LISTING_MODE | IMAGE_INLINE_DISASSEMBLE_DATA; + do { + rc = image_inline_disassemble( &ctx, &dis); + sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE,"%s\n",dis.s); + sizeList = sizeList + sizeDisLine; + disList = strcat(disList,lineDis); + if (rc) { + rcSet = rcSet | 0x4; + sizeDisLine = snprintf(lineDis,LISTING_STRING_SIZE, + "WARNING: %s (rc=%i) -> Stopping disasm. Check code and sectionID=%i.\n", + image_inline_error_strings[rc],rc,sectionId); + sizeList = sizeList + sizeDisLine; + disList = strcat(disList,lineDis); + } + // Readjust list buffer size, if needed. + if (sizeList > sizeListMax-1000) { + sizeListMax = 2*sizeListMax; + disList = (char*)realloc( (void*)(disList), sizeListMax); + } + } while (rc==0 && ctx.lc<nextLinkOffsetBlock+sizeBlock); + } + if (rcSet) + rc = 0; - } // End of if (bSummary) condition. + } // End of if (bSummary) condition. - nextBlock = (void*)((uint64_t)nextBlock + (uint64_t)sizeBlock); - nextLinkOffsetBlock = nextLinkOffsetBlock + sizeBlock; + nextBlock = (void*)((uint64_t)nextBlock + (uint64_t)sizeBlock); + nextLinkOffsetBlock = nextLinkOffsetBlock + sizeBlock; - } // End of while(nextBlock...) loop. + } // End of while(nextBlock...) loop. - // Adjust final buffer size, add 1 for NULL char and print it. - if (disList) { - disList = (char*)realloc( (void*)(disList), sizeList+1); - fprintf(stdout,"%s\n",disList); - free(disList); - } + // Adjust final buffer size, add 1 for NULL char and print it. + if (disList) { + disList = (char*)realloc( (void*)(disList), sizeList+1); + fprintf(stdout,"%s\n",disList); + free(disList); + } - if (rcSet) - fprintf( stderr, "INFO : There were some hickups: %s\n", DIS_ERROR_STRING(g_errorStringsDis, DIS_DISASM_TROUBLES)); + if (rcSet) + fprintf( stderr, "INFO : There were some hickups: %s\n", DIS_ERROR_STRING(g_errorStringsDis, DIS_DISASM_TROUBLES)); - return 0; + return 0; } #endif |