mirror of
https://github.com/autc04/Retro68.git
synced 2024-09-29 10:55:00 +00:00
Elf2Mac now generates CODE resources itself; --mac-flat for the old functionality
This commit is contained in:
parent
6a3e6863c5
commit
284126e13c
@ -48,13 +48,8 @@ using std::shared_ptr;
|
|||||||
using std::make_shared;
|
using std::make_shared;
|
||||||
using std::unique_ptr;
|
using std::unique_ptr;
|
||||||
|
|
||||||
unordered_map<string, Elf_Scn*> codeSections;
|
|
||||||
unordered_map<string, Elf_Scn*> relaSections;
|
|
||||||
Elf_Scn* dataSection;
|
|
||||||
Elf_Scn* bssSection;
|
|
||||||
Elf_Scn *symtabSection;
|
|
||||||
size_t sectionHeaderStringTableIdx;
|
size_t sectionHeaderStringTableIdx;
|
||||||
size_t mainStringTableIdx;
|
size_t mainStringTableIdx = (size_t)-1;
|
||||||
|
|
||||||
class Symtab;
|
class Symtab;
|
||||||
|
|
||||||
@ -175,7 +170,7 @@ void GrokELF(string input)
|
|||||||
GElf_Ehdr ehdr;
|
GElf_Ehdr ehdr;
|
||||||
gelf_getehdr(elf, &ehdr);
|
gelf_getehdr(elf, &ehdr);
|
||||||
|
|
||||||
unordered_map<string, Elf_Scn*> progbits;
|
Elf_Scn* bssSection = NULL;
|
||||||
|
|
||||||
int idx = 0;
|
int idx = 0;
|
||||||
for(Elf_Scn *scn = NULL; (scn = elf_nextscn(elf, scn)) != NULL;idx++)
|
for(Elf_Scn *scn = NULL; (scn = elf_nextscn(elf, scn)) != NULL;idx++)
|
||||||
@ -201,7 +196,6 @@ void GrokELF(string input)
|
|||||||
if(boost::algorithm::starts_with(name,".rela."))
|
if(boost::algorithm::starts_with(name,".rela."))
|
||||||
{
|
{
|
||||||
string progbitsName = name.substr(5);
|
string progbitsName = name.substr(5);
|
||||||
relaSections[progbitsName] = scn;
|
|
||||||
assert(sections.find(progbitsName) != sections.end());
|
assert(sections.find(progbitsName) != sections.end());
|
||||||
sections[progbitsName]->SetRela(scn);
|
sections[progbitsName]->SetRela(scn);
|
||||||
}
|
}
|
||||||
@ -209,27 +203,24 @@ void GrokELF(string input)
|
|||||||
if(shdr.sh_type == SHT_PROGBITS
|
if(shdr.sh_type == SHT_PROGBITS
|
||||||
&& !bssSection) // ignore everything after bss, that's just debug info
|
&& !bssSection) // ignore everything after bss, that's just debug info
|
||||||
{
|
{
|
||||||
codeSections[name] = scn;
|
|
||||||
sections.emplace(name, make_shared<Section>(idx, scn));
|
sections.emplace(name, make_shared<Section>(idx, scn));
|
||||||
}
|
}
|
||||||
if(shdr.sh_type == SHT_NOBITS)
|
if(shdr.sh_type == SHT_NOBITS)
|
||||||
{
|
{
|
||||||
bssSection = scn;
|
bssSection = scn;
|
||||||
|
// Currently, the bss section is only used here
|
||||||
|
// to know when to start skipping debug info sections.
|
||||||
|
// (What's the official way to distinguish a debug info section from a "real" section?)
|
||||||
|
|
||||||
|
// We don't even need to remember the size of address of the bss segment,
|
||||||
|
// the initialization code in libretro/relocate.c knows this from
|
||||||
|
// the _sbss and _ebss symbols defined in the linker script.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ElfToFlt(string input, string output)
|
void FlatCode(std::ostream& out)
|
||||||
{
|
{
|
||||||
GrokELF(input);
|
|
||||||
|
|
||||||
GElf_Shdr text_shdr, data_shdr, bss_shdr;
|
|
||||||
gelf_getshdr(codeSections[".text"], &text_shdr);
|
|
||||||
gelf_getshdr(codeSections[".data"], &data_shdr);
|
|
||||||
gelf_getshdr(bssSection, &bss_shdr);
|
|
||||||
|
|
||||||
ofstream out(output);
|
|
||||||
|
|
||||||
out << sections[".text"]->GetData();
|
out << sections[".text"]->GetData();
|
||||||
out << sections[".data"]->GetData();
|
out << sections[".data"]->GetData();
|
||||||
|
|
||||||
@ -238,6 +229,74 @@ void ElfToFlt(string input, string output)
|
|||||||
longword(out, -1);
|
longword(out, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FlatCode(string fn)
|
||||||
|
{
|
||||||
|
ofstream out(fn);
|
||||||
|
FlatCode(out);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string fromhex(std::string hex)
|
||||||
|
{
|
||||||
|
std::string bin;
|
||||||
|
int nibble;
|
||||||
|
bool haveNibble = false;
|
||||||
|
for(std::string::iterator p = hex.begin(); p != hex.end(); ++p)
|
||||||
|
{
|
||||||
|
if(std::isspace(*p))
|
||||||
|
continue;
|
||||||
|
assert(isdigit(*p) || (tolower(*p) >= 'a' && tolower(*p) <= 'f'));
|
||||||
|
int digit;
|
||||||
|
if(isdigit(*p))
|
||||||
|
digit = *p - '0';
|
||||||
|
else
|
||||||
|
digit = tolower(*p) - 'a' + 0xA;
|
||||||
|
|
||||||
|
if(haveNibble)
|
||||||
|
{
|
||||||
|
bin += (char) ((nibble << 4) | digit);
|
||||||
|
haveNibble = false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
nibble = digit;
|
||||||
|
haveNibble = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return bin;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SingleSegmentApp(string output)
|
||||||
|
{
|
||||||
|
ResourceFile file(output);
|
||||||
|
Resources& rsrc = file.resources;
|
||||||
|
|
||||||
|
rsrc.addResource(Resource(ResType("CODE"), 0,
|
||||||
|
fromhex(
|
||||||
|
"00000028 00000000 00000008 00000020"
|
||||||
|
"0000 3F3C 0001 A9F0"
|
||||||
|
)
|
||||||
|
));
|
||||||
|
|
||||||
|
|
||||||
|
{
|
||||||
|
std::ostringstream code1;
|
||||||
|
word(code1, 0);
|
||||||
|
word(code1, 1);
|
||||||
|
FlatCode(code1);
|
||||||
|
|
||||||
|
rsrc.addResource(Resource(ResType("CODE"), 1,
|
||||||
|
code1.str()));
|
||||||
|
}
|
||||||
|
|
||||||
|
file.creator = ResType("????");
|
||||||
|
file.type = ResType("APPL");
|
||||||
|
|
||||||
|
file.write();
|
||||||
|
}
|
||||||
|
|
||||||
string argvZero;
|
string argvZero;
|
||||||
|
|
||||||
void RealLD(vector<string> args)
|
void RealLD(vector<string> args)
|
||||||
@ -293,6 +352,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
string outputFile = "a.out";
|
string outputFile = "a.out";
|
||||||
bool elf2mac = false;
|
bool elf2mac = false;
|
||||||
|
bool flatoutput = false;
|
||||||
|
|
||||||
vector<string> args2;
|
vector<string> args2;
|
||||||
for(auto p = args.begin(), e = args.end(); p != e; ++p)
|
for(auto p = args.begin(), e = args.end(); p != e; ++p)
|
||||||
@ -312,6 +372,11 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
elf2mac = true;
|
elf2mac = true;
|
||||||
}
|
}
|
||||||
|
else if(*p == "--mac-flat")
|
||||||
|
{
|
||||||
|
elf2mac = true;
|
||||||
|
flatoutput = true;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
args2.push_back(*p);
|
args2.push_back(*p);
|
||||||
@ -334,7 +399,11 @@ int main(int argc, char *argv[])
|
|||||||
args2.push_back(tmpfile);
|
args2.push_back(tmpfile);
|
||||||
RealLD(args2);
|
RealLD(args2);
|
||||||
unlink(tmpfile);
|
unlink(tmpfile);
|
||||||
ElfToFlt(outputFile + ".gdb", outputFile);
|
GrokELF(outputFile + ".gdb");
|
||||||
|
if(flatoutput)
|
||||||
|
FlatCode(outputFile);
|
||||||
|
else
|
||||||
|
SingleSegmentApp(outputFile);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -346,7 +415,8 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
if(argc != 2)
|
if(argc != 2)
|
||||||
errx(EXIT_FAILURE, "usage : %s file-name ", argv[0]);
|
errx(EXIT_FAILURE, "usage : %s file-name ", argv[0]);
|
||||||
ElfToFlt(argv[1], "out.flt");
|
GrokELF(argv[1]);
|
||||||
|
FlatCode("out.flt");
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1,26 +1,53 @@
|
|||||||
|
# Copyright 2017 Wolfgang Thaller.
|
||||||
|
#
|
||||||
|
# This file is part of Retro68.
|
||||||
|
#
|
||||||
|
# Retro68 is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# Retro68 is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with Retro68. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
# Here's how to build a system extension, a.k.a. an INIT.
|
||||||
|
# The same applies to various other kinds of code resources.
|
||||||
|
|
||||||
|
# PowerPC is not currently supported here.
|
||||||
|
# As for Carbon, there are no code resources anyway.
|
||||||
|
|
||||||
|
# Step 1:
|
||||||
|
# Build the code resource as a regular executable
|
||||||
|
# (not using the add_application macro)
|
||||||
add_executable(SystemExtension
|
add_executable(SystemExtension
|
||||||
SystemExtension.c
|
SystemExtension.c
|
||||||
SystemExtension.r
|
|
||||||
ShowInitIcon.c
|
ShowInitIcon.c
|
||||||
|
SystemExtension.r
|
||||||
ShowInitIcon.h)
|
ShowInitIcon.h)
|
||||||
|
|
||||||
set_target_properties(SystemExtension PROPERTIES OUTPUT_NAME SystemExtension.flt)
|
set_target_properties(SystemExtension PROPERTIES
|
||||||
|
OUTPUT_NAME SystemExtension.flt
|
||||||
|
|
||||||
|
# set a linker flag that says we want a flat piece
|
||||||
|
# of code in a data file
|
||||||
|
LINK_FLAGS -Wl,--mac-flat)
|
||||||
|
|
||||||
|
# Use Rez to put it together
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT SystemExtension.bin SystemExtension.dsk
|
OUTPUT SystemExtension.bin SystemExtension.dsk
|
||||||
COMMAND ${REZ} -I ${REZ_INCLUDE_PATH}
|
COMMAND ${REZ} -I ${REZ_INCLUDE_PATH}
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/SystemExtension.r
|
${CMAKE_CURRENT_SOURCE_DIR}/SystemExtension.r
|
||||||
--copy ${CMAKE_CURRENT_SOURCE_DIR}/Icons.rsrc.bin
|
--copy ${CMAKE_CURRENT_SOURCE_DIR}/Icons.rsrc.bin
|
||||||
-o SystemExtension.bin
|
-o SystemExtension.bin
|
||||||
-t INIT
|
--cc SystemExtension.dsk
|
||||||
COMMAND ${REZ} --copy SystemExtension.bin
|
--cc SystemExtension
|
||||||
-o SystemExtension.dsk
|
|
||||||
-t INIT
|
|
||||||
COMMAND ${REZ} --copy SystemExtension.bin
|
|
||||||
-o SystemExtension
|
|
||||||
-t INIT
|
-t INIT
|
||||||
DEPENDS SystemExtension SystemExtension.r Icons.rsrc.bin)
|
DEPENDS SystemExtension SystemExtension.r Icons.rsrc.bin)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
add_custom_target(SystemExtension_INIT ALL DEPENDS SystemExtension.dsk)
|
add_custom_target(SystemExtension_INIT ALL DEPENDS SystemExtension.dsk)
|
||||||
|
@ -70,16 +70,16 @@ function(add_application name)
|
|||||||
|
|
||||||
if(CMAKE_SYSTEM_NAME MATCHES Retro68)
|
if(CMAKE_SYSTEM_NAME MATCHES Retro68)
|
||||||
|
|
||||||
set_target_properties(${name} PROPERTIES OUTPUT_NAME ${name}.flt)
|
set_target_properties(${name} PROPERTIES OUTPUT_NAME ${name}.code.bin)
|
||||||
|
|
||||||
add_custom_command(
|
add_custom_command(
|
||||||
OUTPUT ${name}.bin ${name}.APPL ${name}.dsk ${name}.ad "%${name}.ad"
|
OUTPUT ${name}.bin ${name}.APPL ${name}.dsk ${name}.ad "%${name}.ad"
|
||||||
COMMAND ${REZ} ${REZ_FLAGS}
|
COMMAND ${REZ} ${REZ_FLAGS}
|
||||||
${REZ_TEMPLATES_PATH}/Retro68APPL.r
|
${REZ_TEMPLATES_PATH}/Retro68APPL.r
|
||||||
-I${REZ_INCLUDE_PATH}
|
-I${REZ_INCLUDE_PATH}
|
||||||
-DFLT_FILE_NAME="\\"${name}.flt\\""
|
--copy "${name}.code.bin"
|
||||||
-o "${name}.bin" --cc "${name}.dsk" --cc "${name}.APPL"
|
-o "${name}.bin"
|
||||||
--cc "%${name}.ad"
|
--cc "${name}.dsk" --cc "${name}.APPL" --cc "%${name}.ad"
|
||||||
-t ${ARGS_TYPE} -c ${ARGS_CREATOR}
|
-t ${ARGS_TYPE} -c ${ARGS_CREATOR}
|
||||||
${ARGS_MAKEAPPL_ARGS}
|
${ARGS_MAKEAPPL_ARGS}
|
||||||
DEPENDS ${name} ${rsrc_files})
|
DEPENDS ${name} ${rsrc_files})
|
||||||
|
@ -1,6 +1,13 @@
|
|||||||
#include "Processes.r"
|
#include "Processes.r"
|
||||||
#include "Retro68.r"
|
#include "Retro68.r"
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
/*
|
||||||
|
* By default, Application CODE resources are no longer
|
||||||
|
* created by Rez, but rather by Elf2Mac.
|
||||||
|
* It is still possible to create a single-segment
|
||||||
|
* application this way, though.
|
||||||
|
*/
|
||||||
resource 'CODE' (0) RETRO68_JUMP_TABLE;
|
resource 'CODE' (0) RETRO68_JUMP_TABLE;
|
||||||
|
|
||||||
resource 'CODE' (1) {
|
resource 'CODE' (1) {
|
||||||
@ -11,6 +18,7 @@ resource 'CODE' (1) {
|
|||||||
#endif
|
#endif
|
||||||
$$read(FLT_FILE_NAME);
|
$$read(FLT_FILE_NAME);
|
||||||
};
|
};
|
||||||
|
#endif
|
||||||
|
|
||||||
resource 'SIZE' (-1) {
|
resource 'SIZE' (-1) {
|
||||||
dontSaveScreen,
|
dontSaveScreen,
|
||||||
|
Loading…
Reference in New Issue
Block a user