Skip to content

Commit

Permalink
Add support for upcoming ELF format
Browse files Browse the repository at this point in the history
Written by Vincent Rivière, with some additions by Thorsten Otto
  • Loading branch information
vinriviere authored and th-otto committed Aug 19, 2023
1 parent 038abe3 commit 3fee749
Show file tree
Hide file tree
Showing 8 changed files with 240 additions and 210 deletions.
245 changes: 123 additions & 122 deletions po/cat-id-tbl.c

Large diffs are not rendered by default.

172 changes: 88 additions & 84 deletions po/mintbin.pot

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/csize.c
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ invalid argument to `--format'"));
continue;
}
if (target->format != oldstyle_prg_target
&& target->format != prg_target)
&& target->format != prg_target
&& target->format != prgelf_target)
{
status = EXIT_FAILURE;
error (EXIT_SUCCESS, 0, _("%s: not a MiNT executable file"),
Expand Down
3 changes: 2 additions & 1 deletion src/flags.c
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,8 @@ warning: changing the bestfit flag is dangerous"));
continue;
}
if (target->format != prg_target
&& target->format != oldstyle_prg_target)
&& target->format != oldstyle_prg_target
&& target->format != prgelf_target)
{
status = EXIT_FAILURE;
error (EXIT_SUCCESS, 0, _("%s: not a MiNT executable"),
Expand Down
3 changes: 3 additions & 0 deletions src/mintbin.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ MiNT demand-paged executable with traditional symbol table.\n"),
case oldstyle_prg_target:
fputs (_("Old-style GEMDOS executable.\n"), stdout);
break;
case prgelf_target:
fputs (_("PRG/ELF executable.\n"), stdout);
break;
default:
fputs (_("Unrecognized file format.\n"), stdout);
break;
Expand Down
3 changes: 2 additions & 1 deletion src/stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,8 @@ print_stack (filename)

if (target->format != prg_target
&& target->format != oldstyle_prg_target
&& target->format != aout_target) {
&& target->format != aout_target
&& target->format != prgelf_target) {
error (EXIT_SUCCESS, 0, _("%s: file format not recognized"),
target->filename);
return -1;
Expand Down
15 changes: 15 additions & 0 deletions src/targets.c
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ swap_prg_header_in (target)
{
int is_601a = 1;
int is_extended_mint = 0;
int elfheader_offset = 0;
unsigned char* crs = target->header;

target->format = invalid_target;
Expand Down Expand Up @@ -217,6 +218,11 @@ swap_prg_header_in (target)
{
is_extended_mint = 1;
}
else if (crs[0] == 'E' && crs[1] == 'L'
&& crs[2] == 'F' && crs[3] >= 0x28)
{
elfheader_offset = crs[3];
}
crs += 4;
target->execp.g_flags = get32 (crs);
crs += 4;
Expand All @@ -229,6 +235,15 @@ swap_prg_header_in (target)
+ target->execp.g_text + target->execp.a_data
+ target->execp.g_syms;
target->execp.g_symbol_format = 1;

if (elfheader_offset != 0) {
target->format = prgelf_target;
target->execp.g_symbol_format = 2;
target->execp.g_stkpos = get32 (target->header + 0x24); /* PRGELF_HEADER.g_stkpos */
target->stksize_looked_up = 1;
target->execp.a_entry = get32 (target->header + elfheader_offset + 0x18); /* ehdr.e_entry */
}

return 0;
}

Expand Down
6 changes: 5 additions & 1 deletion src/targets.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ enum mintbin_targets_enum {
/* Old-style prg executables or other 0x601a files that are
not recognized. */
#define oldstyle_prg_target oldstyle_prg_target
oldstyle_prg_target
oldstyle_prg_target,

/* PRG/ELF executables. */
#define prgelf_target prgelf_target
prgelf_target
};

struct mintbin_target {
Expand Down

1 comment on commit 3fee749

@vinriviere
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forgot that I added PRG/ELF support to mintbin on a separate mintelf branch. This was before knowing if that effort would be welcomed or not. Fortunately it was. For memories, my initial patch: a6028f9

@th-otto Thanks for having pushed that support to the master branch. This had to be done, at some point. But instead of changing my patch and keeping my name as author, I would have preferred that you push my commit as-is, then add your changes on top of it in a separate commit. That way the history would have been more accurate.

Anyway, that doesn't matter much. Result is the same. I'm going to delete the mintelf branch right now, as it has been merged to master.

Please sign in to comment.