Added ELF section types check and new error messages
[clinton/Virtual-Jaguar-Rx.git] / src / file.cpp
index a296bd0..73d255e 100644 (file)
@@ -16,6 +16,7 @@
 // JPM   June/2016  Visual Studio support, ELF format support and Soft debugger support\r
 // JPM  07/15/2016  DWARF format support\r
 // JPM  04/06/2019  Added ELF sections check\r
+// JPM  03/12/2020  Added ELF section types check and new error messages\r
 //\r
 \r
 #include "file.h"\r
@@ -232,10 +233,10 @@ WriteLog("FILE: Cartridge run address is reported as $%X...\n", jaguarRunAddress
                                                                {\r
                                                                        switch (PtrGElfShdr->sh_type)\r
                                                                        {\r
-                                                                       case    SHT_NULL:\r
+                                                                       case SHT_NULL:\r
                                                                                break;\r
 \r
-                                                                       case    SHT_PROGBITS:\r
+                                                                       case SHT_PROGBITS:\r
                                                                                if ((PtrGElfShdr->sh_flags & (SHF_ALLOC | SHF_WRITE | SHF_EXECINSTR)))\r
                                                                                {\r
                                                                                        if (PtrGElfShdr->sh_addr >= 0x800000)\r
@@ -252,14 +253,19 @@ WriteLog("FILE: Cartridge run address is reported as $%X...\n", jaguarRunAddress
                                                                                {\r
                                                                                        switch (ElfSectionNameType)\r
                                                                                        {\r
+                                                                                       case ELF_debug_TYPE:\r
+                                                                                       case ELF_debug_abbrev_TYPE:\r
                                                                                        case ELF_debug_aranges_TYPE:\r
+                                                                                       case ELF_debug_frame_TYPE:\r
                                                                                        case ELF_debug_info_TYPE:\r
-                                                                                       case ELF_debug_abbrev_TYPE:\r
                                                                                        case ELF_debug_line_TYPE:\r
-                                                                                       case ELF_debug_frame_TYPE:\r
+                                                                                       case ELF_debug_loc_TYPE:\r
+                                                                                       case ELF_debug_macinfo_TYPE:\r
+                                                                                       case ELF_debug_pubnames_TYPE:\r
+                                                                                       case ELF_debug_pubtypes_TYPE:\r
                                                                                        case ELF_debug_ranges_TYPE:\r
                                                                                        case ELF_debug_str_TYPE:\r
-                                                                                       case ELF_debug_loc_TYPE:\r
+                                                                                       case ELF_debug_types_TYPE:                                              \r
                                                                                                break;\r
 \r
                                                                                        case ELF_heap_TYPE:\r
@@ -269,27 +275,30 @@ WriteLog("FILE: Cartridge run address is reported as $%X...\n", jaguarRunAddress
                                                                                                break;\r
 \r
                                                                                        default:\r
+                                                                                               WriteLog("FILE: ELF section %s is not recognized\n", NameSection);\r
                                                                                                error = true;\r
                                                                                                break;\r
                                                                                        }\r
                                                                                }\r
                                                                                break;\r
 \r
-                                                                       case    SHT_NOBITS:\r
+                                                                       case SHT_NOBITS:\r
                                                                                break;\r
 \r
-                                                                       case    SHT_STRTAB:\r
-                                                                       case    SHT_SYMTAB:\r
+                                                                       case SHT_STRTAB:\r
+                                                                       case SHT_SYMTAB:\r
                                                                                while ((error == false) && ((PtrElfData = elf_getdata(PtrElfScn, PtrElfData)) != NULL))\r
                                                                                {\r
                                                                                        if (!ELFManager_AddTab(PtrElfData, ElfSectionNameType))\r
                                                                                        {\r
+                                                                                               WriteLog("FILE: ELF tab cannot be allocated\n");\r
                                                                                                error = true;\r
                                                                                        }\r
                                                                                }\r
                                                                                break;\r
 \r
                                                                        default:\r
+                                                                               WriteLog("FILE: ELF SHT type %i not recognized\n", PtrGElfShdr->sh_type);\r
                                                                                error = true;\r
                                                                                break;\r
                                                                        }\r
@@ -297,6 +306,7 @@ WriteLog("FILE: Cartridge run address is reported as $%X...\n", jaguarRunAddress
                                                        }\r
                                                }\r
 \r
+                                               // Set the executable address\r
                                                jaguarRunAddress = (uint32_t)PtrGElfEhdr->e_entry;\r
                                                WriteLog("FILE: Setting up ELF 32bits... Run address: %08X\n", jaguarRunAddress);\r
                                        }\r
@@ -307,6 +317,7 @@ WriteLog("FILE: Cartridge run address is reported as $%X...\n", jaguarRunAddress
                                }\r
                                else\r
                                {\r
+                                       WriteLog("FILE: Cannot get the number of the ELF sections\n");\r
                                        error = true;\r
                                }\r
                        }\r