Inial population of repository.
This commit is contained in:
35
simulator/ovl_split/Makefile
Normal file
35
simulator/ovl_split/Makefile
Normal file
@@ -0,0 +1,35 @@
|
||||
#################################################################################
|
||||
### MODE: determines what compiler flags to use
|
||||
### SYSTEM: determines the intermediate and final file directory names (for now)
|
||||
### DEFINES: list of predefined macros to pass to the compiler
|
||||
### INC_DIRS: list of include paths to pass to the compiler
|
||||
### DEP_INC_DIRS: list of include paths to search for dependencies in
|
||||
### LIB_DIRS: list of library paths to pass to the linker
|
||||
### TARGET_TYPE: determines whether to build executables or libraries
|
||||
### SOURCES: list of source (c++) files
|
||||
### SRC_DIRS: list of source paths. Needed to generate implicit rules
|
||||
### SOURCE_LIBS: list of locally built libs (they are included as a dependency)
|
||||
### LINK_LIBS: list of libraries to link againsg on top of SOURCE_LIBS
|
||||
### TARGETS: list of target final targets (library names or executable files)
|
||||
|
||||
ifndef MODE
|
||||
MODE=release
|
||||
#MODE=debug
|
||||
endif
|
||||
|
||||
include ../common.mak
|
||||
|
||||
TARGET_TYPE = EXECUTABLE
|
||||
|
||||
SOURCES =
|
||||
SOURCES += ovl_split.cpp
|
||||
|
||||
SOURCE_LIBS =
|
||||
|
||||
LINK_LIBS =
|
||||
LINK_LIBS += $(COMMON_LIBS)
|
||||
|
||||
TARGETS =
|
||||
TARGETS += ovl_split
|
||||
|
||||
include ../engine.mak
|
||||
176
simulator/ovl_split/ovl_split.cpp
Normal file
176
simulator/ovl_split/ovl_split.cpp
Normal file
@@ -0,0 +1,176 @@
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
// cray_ios_disasm.cpp : Defines the entry point for the console application.
|
||||
//
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include "utils.h"
|
||||
#include <map>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
bool IsUpperCaseOrNum(char aC) {
|
||||
if (aC >= 'A' && aC <= 'Z') return true;
|
||||
if (aC >= '0' && aC <= '9') return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
struct ProcessedFileHeader_s {
|
||||
uint16_t FileSize;
|
||||
uint16_t Flags;
|
||||
uint16_t Flags1;
|
||||
uint16_t Flags2;
|
||||
char FileName[9];
|
||||
};
|
||||
|
||||
const size_t cFileHeaderSize = 16;
|
||||
|
||||
ProcessedFileHeader_s DecodeHeader(uint8_t *aContent, size_t aMaxOffset, size_t aOffset) {
|
||||
ProcessedFileHeader_s RetVal;
|
||||
RetVal.FileSize = SwapBytes(*(uint16_t*)(aContent+aOffset)) * 2;
|
||||
aOffset += 2;
|
||||
RetVal.FileSize -= cFileHeaderSize;
|
||||
|
||||
RetVal.Flags = SwapBytes(*(uint16_t*)(aContent+aOffset));
|
||||
aOffset += 2;
|
||||
|
||||
memcpy(RetVal.FileName,aContent+aOffset,8);
|
||||
RetVal.FileName[8] = 0;
|
||||
aOffset += 8;
|
||||
|
||||
RetVal.Flags1 = SwapBytes(*(uint16_t*)(aContent+aOffset));
|
||||
aOffset += 2;
|
||||
|
||||
RetVal.Flags2 = SwapBytes(*(uint16_t*)(aContent+aOffset));
|
||||
aOffset += 2;
|
||||
|
||||
return RetVal;
|
||||
}
|
||||
|
||||
bool IsValidHeader(ProcessedFileHeader_s &aHeader, size_t aMaxOffset, size_t aOffset) {
|
||||
if (aHeader.FileSize > aMaxOffset - aOffset) return false;
|
||||
// if (aHeader.FileSize > 65536) return false;
|
||||
// if (aHeader.FileSize == -(int16_t)cFileHeaderSize) return false;
|
||||
if (aHeader.Flags != 0) return false;
|
||||
if (aHeader.Flags1 == 0) return false;
|
||||
if ((aHeader.Flags1 & 0xf000) != 0x0000 && (aHeader.Flags1 & 0xf000) != 0x8000) return false;
|
||||
|
||||
if (!IsUpperCaseOrNum(aHeader.FileName[0])) return false;
|
||||
|
||||
bool InStr = true;
|
||||
for(int i=1;i<8;++i) {
|
||||
if (InStr) {
|
||||
if (aHeader.FileName[i] == 0) {
|
||||
InStr = false;
|
||||
} else {
|
||||
if (!IsUpperCaseOrNum(aHeader.FileName[i])) return false;
|
||||
}
|
||||
} else {
|
||||
if (aHeader.FileName[i] != 0) return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsValidHeader(uint8_t *aContent, size_t aMaxOffset, size_t aOffset) {
|
||||
ProcessedFileHeader_s Header = DecodeHeader(aContent,aMaxOffset,aOffset);
|
||||
return IsValidHeader(Header, aMaxOffset, aOffset);
|
||||
}
|
||||
|
||||
bool FindNextHeader(uint8_t *aContent, size_t aMaxOffset, size_t &aOffset) {
|
||||
while (aOffset < aMaxOffset-16) {
|
||||
if (IsValidHeader(aContent, aMaxOffset, aOffset)) return true;
|
||||
++aOffset;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
typedef std::map<size_t, std::string> FileDirectory_t;
|
||||
|
||||
void ParseOvlNum(FileDirectory_t &aFileNames, std::vector<uint8_t> &aFile, size_t aFileCnt) {
|
||||
char Desc[255];
|
||||
for(size_t FileIdx=0;FileIdx<aFileCnt;++FileIdx) {
|
||||
uint16_t StartOffs = SwapBytes(*(uint16_t*)&aFile[FileIdx*8+4]) * 8 - 12;
|
||||
uint16_t Size = SwapBytes(*(uint16_t*)&aFile[FileIdx*8+6]);
|
||||
if (Size >= 255) break;
|
||||
memcpy(Desc,&aFile[StartOffs],Size);
|
||||
Desc[Size] = 0;
|
||||
std::cout << aFileNames[FileIdx] << ": " << Desc << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
if (argc != 2) {
|
||||
printf("Usage: %s <image file>\n",argv[0]);
|
||||
return 1;
|
||||
}
|
||||
const char *InFileName = argv[1];
|
||||
FILE *Input = fopen(InFileName,"rb");
|
||||
if (Input == nullptr) {
|
||||
printf("Can't open input file: %s\n", InFileName);
|
||||
return 1;
|
||||
}
|
||||
uint64_t TotalFileSize = boost::filesystem::file_size(InFileName);
|
||||
const size_t MaxFileSize = 256*1024*1024;
|
||||
if (TotalFileSize > MaxFileSize) {
|
||||
printf("Can't use files larger than %uMB\n",unsigned(MaxFileSize/1024/1024));
|
||||
fclose(Input);
|
||||
return 1;
|
||||
}
|
||||
uint8_t *File = new uint8_t[(size_t)TotalFileSize+1];
|
||||
if (File == nullptr) {
|
||||
printf("Not enough memory to allocate buffer for image\n");
|
||||
fclose(Input);
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t Read = fread(File,1,(size_t)TotalFileSize,Input);
|
||||
fclose(Input);
|
||||
if (Read != TotalFileSize) {
|
||||
printf("Can't read file.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
{
|
||||
size_t FileCnt = SwapBytes(*((uint16_t *)(File)));
|
||||
size_t Offset = 4;
|
||||
size_t FileIdx = 0;
|
||||
FileDirectory_t FileNames;
|
||||
std::vector<uint8_t> OvlNum;
|
||||
size_t MaxFileId = 0;
|
||||
while (FileIdx < FileCnt) {
|
||||
ProcessedFileHeader_s Header = DecodeHeader(File,(size_t)TotalFileSize,Offset);
|
||||
if (!IsValidHeader(Header,(size_t)TotalFileSize,Offset)) {
|
||||
printf("Lost track at offset 0x%08x\n",unsigned(Offset));
|
||||
break;
|
||||
}
|
||||
Offset += cFileHeaderSize;
|
||||
printf("0x%08x-0x%08x flags:0x%04x 0x%04x size:%8d %s\n",unsigned(Offset-cFileHeaderSize) , unsigned(Offset+Header.FileSize) ,Header.Flags1, Header.Flags2, Header.FileSize, Header.FileName);
|
||||
char OutFileName[255];
|
||||
size_t FileId = Header.Flags1 & 0x7fff;
|
||||
if (FileId > MaxFileId) MaxFileId = FileId;
|
||||
FileNames[FileId] = Header.FileName;
|
||||
if (strcmp(Header.FileName, "OVLNUM") == 0) {
|
||||
OvlNum.resize(Header.FileSize);
|
||||
memcpy(&OvlNum[0],File+Offset,Header.FileSize);
|
||||
}
|
||||
sprintf(OutFileName,"%04u_%s.%s",unsigned(FileIdx),Header.FileName,((Header.Flags1 & 0x8000) == 0) ? "cod":"dat");
|
||||
FILE *OutFile = fopen(OutFileName,"wb");
|
||||
if (OutFile != nullptr) {
|
||||
fwrite(File+Offset,1,Header.FileSize,OutFile);
|
||||
fclose(OutFile);
|
||||
}
|
||||
Offset += Header.FileSize;
|
||||
++FileIdx;
|
||||
}
|
||||
if (OvlNum.size() > 0) {
|
||||
std::cout << "Overlay file explanations" << std::endl;
|
||||
std::cout << "========================================" << std::endl;
|
||||
ParseOvlNum(FileNames,OvlNum,MaxFileId+1);
|
||||
}
|
||||
}
|
||||
delete[] File;
|
||||
return 0;
|
||||
}
|
||||
|
||||
20
simulator/ovl_split/ovl_split.sln
Normal file
20
simulator/ovl_split/ovl_split.sln
Normal file
@@ -0,0 +1,20 @@
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 2012
|
||||
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "ovl_split", "ovl_split.vcxproj", "{71288978-E247-4B15-8ED2-E244785B0329}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Win32 = Debug|Win32
|
||||
Release|Win32 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{71288978-E247-4B15-8ED2-E244785B0329}.Debug|Win32.ActiveCfg = Debug|Win32
|
||||
{71288978-E247-4B15-8ED2-E244785B0329}.Debug|Win32.Build.0 = Debug|Win32
|
||||
{71288978-E247-4B15-8ED2-E244785B0329}.Release|Win32.ActiveCfg = Release|Win32
|
||||
{71288978-E247-4B15-8ED2-E244785B0329}.Release|Win32.Build.0 = Release|Win32
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
85
simulator/ovl_split/ovl_split.vcxproj
Normal file
85
simulator/ovl_split/ovl_split.vcxproj
Normal file
@@ -0,0 +1,85 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<ItemGroup Label="ProjectConfigurations">
|
||||
<ProjectConfiguration Include="Debug|Win32">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Debug|x64">
|
||||
<Configuration>Debug</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release_PGO_Inst|Win32">
|
||||
<Configuration>Release_PGO_Inst</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release_PGO_Inst|x64">
|
||||
<Configuration>Release_PGO_Inst</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|Win32">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>Win32</Platform>
|
||||
</ProjectConfiguration>
|
||||
<ProjectConfiguration Include="Release|x64">
|
||||
<Configuration>Release</Configuration>
|
||||
<Platform>x64</Platform>
|
||||
</ProjectConfiguration>
|
||||
</ItemGroup>
|
||||
<PropertyGroup Label="Globals">
|
||||
<ProjectGuid>{DE4FBBFE-7479-4AFF-846D-69DC799F5ADF}</ProjectGuid>
|
||||
<RootNamespace>ovl_split</RootNamespace>
|
||||
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration">
|
||||
<ConfigurationType>Application</ConfigurationType>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_PGO_Inst|Win32'" Label="Configuration">
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release_PGO_Inst|x64'" Label="Configuration">
|
||||
<PlatformToolset>v141_xp</PlatformToolset>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<Import Project="..\common.props" />
|
||||
<ImportGroup Label="PropertySheets">
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
</ImportGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<Link>
|
||||
<Profile>true</Profile>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release_PGO_Inst|Win32'">
|
||||
<Link>
|
||||
<Profile>true</Profile>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<Link>
|
||||
<Profile>true</Profile>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release_PGO_Inst|x64'">
|
||||
<Link>
|
||||
<Profile>true</Profile>
|
||||
</Link>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="ovl_split.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
</Project>
|
||||
Reference in New Issue
Block a user