Skip to content

Commit d7a7710

Browse files
committed
add: srxfixup tool implementation
1 parent e2f9e9f commit d7a7710

File tree

15 files changed

+9663
-0
lines changed

15 files changed

+9663
-0
lines changed

tools/srxfixup/.clang-format

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
---
2+
Language: Cpp
3+
AccessModifierOffset: -4
4+
AlignAfterOpenBracket: AlwaysBreak
5+
AlignConsecutiveAssignments: false
6+
AlignConsecutiveDeclarations: false
7+
AlignOperands: AlignAfterOperator
8+
AlignTrailingComments: true
9+
AllowAllParametersOfDeclarationOnNextLine: true
10+
AllowShortBlocksOnASingleLine: Never
11+
AllowShortCaseLabelsOnASingleLine: false
12+
AllowShortFunctionsOnASingleLine: Inline
13+
AllowShortIfStatementsOnASingleLine: Never
14+
AllowShortLoopsOnASingleLine: false
15+
AlwaysBreakAfterDefinitionReturnType: None
16+
AlwaysBreakAfterReturnType: None
17+
AlwaysBreakBeforeMultilineStrings: false
18+
AlwaysBreakTemplateDeclarations: Yes
19+
BinPackArguments: false
20+
BinPackParameters: false
21+
BreakBeforeBinaryOperators: NonAssignment
22+
BreakBeforeBraces: Allman
23+
BreakBeforeTernaryOperators: false
24+
BreakConstructorInitializersBeforeComma: false
25+
ColumnLimit: 120
26+
CommentPragmas: '^ (IWYU pragma:|NOLINT)'
27+
ConstructorInitializerAllOnOneLineOrOnePerLine: false
28+
ConstructorInitializerIndentWidth: 2
29+
ContinuationIndentWidth: 2
30+
DerivePointerAlignment: false
31+
DisableFormat: false
32+
ForEachMacros: []
33+
IndentCaseLabels: true
34+
IndentWidth: 2
35+
IndentWrappedFunctionNames: false
36+
KeepEmptyLinesAtTheStartOfBlocks: false
37+
MaxEmptyLinesToKeep: 1
38+
NamespaceIndentation: None
39+
PenaltyBreakBeforeFirstCallParameter: 19
40+
PenaltyBreakComment: 300
41+
PenaltyBreakFirstLessLess: 120
42+
PenaltyBreakString: 1000
43+
PenaltyExcessCharacter: 1000000
44+
PenaltyReturnTypeOnItsOwnLine: 60
45+
PointerAlignment: Right
46+
ReflowComments: true
47+
SortIncludes: true
48+
SpaceAfterCStyleCast: false
49+
SpaceBeforeAssignmentOperators: true
50+
SpaceBeforeParens: ControlStatements
51+
SpaceInEmptyParentheses: false
52+
SpacesBeforeTrailingComments: 2
53+
SpacesInAngles: false
54+
SpacesInContainerLiterals: true
55+
SpacesInCStyleCastParentheses: false
56+
SpacesInSquareBrackets: false
57+
Standard: c++11
58+
TabWidth: 2
59+
UseTab: ForContinuationAndIndentation
60+
SpacesInParens: Custom
61+
SpacesInParensOptions:
62+
InConditionalStatements: true

tools/srxfixup/Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# _____ ___ ____ ___ ____
2+
# ____| | ____| | | |____|
3+
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
4+
#-----------------------------------------------------------------------
5+
# Copyright 2001-2022, ps2dev - http://www.ps2dev.org
6+
# Licenced under Academic Free License version 2.0
7+
# Review ps2sdk README & LICENSE files for further details.
8+
9+
TOOLS_BIN_ALTNAMES ?= eefixup erx-strip iopfixup irx-strip
10+
11+
TOOLS_OBJS = \
12+
srxfixup.o \
13+
anaarg.o \
14+
ring.o \
15+
swapmem.o \
16+
elflib.o \
17+
elfdump.o \
18+
mipsdis.o \
19+
srxgen.o \
20+
readconf.o \
21+
iopfixconf.o \
22+
eefixconf.o
23+
24+
include $(PS2SDKSRC)/Defs.make
25+
include $(PS2SDKSRC)/tools/Rules.bin.make
26+
include $(PS2SDKSRC)/tools/Rules.make
27+
include $(PS2SDKSRC)/tools/Rules.release

tools/srxfixup/README.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# srxfixup
2+
3+
This tool mainly handles generation of IRX and ERX files, mainly used as
4+
relocatable executables or libraries.
5+
This tool performs the following tasks on relocatable ELF files in order to
6+
ensure that loadcore can load it as a relocatable file:
7+
8+
* Sets the ELF header `e_type` to `0xFF80`, `0xFF81`, or `0xFF91`, depending
9+
on the features and architecture used
10+
11+
* Creates the `.iopmod` or `.eemod` section and first program header,
12+
containing metadata about the file, such as name, version, and section sizes/offsets
13+
14+
* Rebuilds relocations
15+
16+
## Aliases
17+
18+
This tool provides the following:
19+
20+
* `iopfixup`
21+
* `irx-strip`
22+
* `eefixup`
23+
* `erx-strip`
24+
25+
## Usage
26+
27+
To see usage and possible command line arguments that can be used with the
28+
program, run it without arguments.

tools/srxfixup/src/anaarg.c

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
/*
2+
# _____ ___ ____ ___ ____
3+
# ____| | ____| | | |____|
4+
# | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5+
#-----------------------------------------------------------------------
6+
# Copyright ps2dev - http://www.ps2dev.org
7+
# Licenced under Academic Free License version 2.0
8+
# Review ps2sdk README & LICENSE files for further details.
9+
*/
10+
11+
#include "srxfixup_internal.h"
12+
#include <stdint.h>
13+
#include <stdio.h>
14+
#include <stdlib.h>
15+
#include <string.h>
16+
17+
int analize_arguments(const Opttable *dopttable, int argc, char **argv)
18+
{
19+
Opt_strings *optstr;
20+
const char *opt;
21+
Opttable *otp;
22+
Opttable *igadd;
23+
Opttable *opttable;
24+
char *cp;
25+
char **argvp;
26+
char **nargv;
27+
int nargc;
28+
int i;
29+
int argca;
30+
char **argva;
31+
32+
for ( i = 0; dopttable[i].option; i += 1 )
33+
{
34+
;
35+
}
36+
opttable = (Opttable *)__builtin_alloca((argc + i) * sizeof(Opttable));
37+
memset(opttable, 0, (argc + i) * sizeof(Opttable));
38+
memcpy(opttable, dopttable, i * sizeof(Opttable));
39+
igadd = &opttable[i];
40+
nargv = (char **)__builtin_alloca((argc + 1) * sizeof(char *));
41+
memset(nargv, 0, (argc + 1) * sizeof(char *));
42+
argvp = argv;
43+
*nargv = *argv;
44+
nargc = 1;
45+
for ( argca = argc - 1, argva = argv + 1;; argca -= 1, argva += 1 )
46+
{
47+
if ( argca <= 0 )
48+
{
49+
for ( i = 0; i < nargc + 1; i += 1 )
50+
{
51+
argvp[i] = nargv[i];
52+
}
53+
for ( i = 0; opttable[i].option; i += 1 )
54+
{
55+
if ( opttable[i].vartype == 'l' )
56+
{
57+
*(SLink **)opttable[i].var = ring_to_liner(*(SLink **)opttable[i].var);
58+
}
59+
}
60+
return nargc;
61+
}
62+
if ( **argva == '-' )
63+
{
64+
opt = 0;
65+
for ( i = 0; opttable[i].option; i += 1 )
66+
{
67+
if ( opttable[i].havearg == ARG_HAVEARG_UNK3 )
68+
{
69+
if ( !strcmp(opttable[i].option, *argva) )
70+
{
71+
break;
72+
}
73+
}
74+
else
75+
{
76+
if ( !strncmp(opttable[i].option, *argva, strlen(opttable[i].option)) )
77+
{
78+
break;
79+
}
80+
}
81+
}
82+
if ( !opttable[i].option )
83+
{
84+
return -1;
85+
}
86+
if ( opttable[i].havearg != ARG_HAVEARG_NONE && opttable[i].havearg != ARG_HAVEARG_UNK3 )
87+
{
88+
if ( opttable[i].havearg == ARG_HAVEARG_UNK4 || (*argva)[strlen(opttable[i].option)] )
89+
{
90+
opt = &(*argva)[strlen(opttable[i].option)];
91+
}
92+
else if ( argca > 1 )
93+
{
94+
opt = argva[1];
95+
argva += 1;
96+
argca -= 1;
97+
}
98+
}
99+
if ( opttable[i].havearg != ARG_HAVEARG_REQUIRED || opt )
100+
{
101+
switch ( opttable[i].vartype )
102+
{
103+
case 'F':
104+
case 'f':
105+
if ( (*argva)[strlen(opttable[i].option)] )
106+
{
107+
*(uint32_t *)opttable[i].var = strtoul(&(*argva)[strlen(opttable[i].option)], NULL, 16);
108+
}
109+
else
110+
{
111+
*(uint32_t *)opttable[i].var = (opttable[i].vartype == 'f') ? 1 : 0;
112+
}
113+
break;
114+
case 'h':
115+
if ( opt != NULL )
116+
{
117+
*(uint32_t *)opttable[i].var = strtoul(opt, 0, 16);
118+
}
119+
break;
120+
case 'i':
121+
if ( opt != NULL )
122+
{
123+
for ( otp = igadd; opttable < otp; otp -= 1 )
124+
{
125+
*otp = otp[-1];
126+
}
127+
igadd += 1;
128+
opttable->option = opt;
129+
opttable->vartype = 'n';
130+
opttable->havearg = ARG_HAVEARG_UNK3;
131+
cp = strchr(opttable->option, ':');
132+
if ( cp )
133+
{
134+
*cp = 0;
135+
switch ( cp[1] )
136+
{
137+
case 'c':
138+
opttable->havearg = ARG_HAVEARG_UNK4;
139+
break;
140+
case 'n':
141+
opttable->havearg = ARG_HAVEARG_REQUIRED;
142+
break;
143+
case 'o':
144+
opttable->havearg = ARG_HAVEARG_UNK1;
145+
break;
146+
default:
147+
break;
148+
}
149+
}
150+
}
151+
break;
152+
case 'l':
153+
optstr = (Opt_strings *)calloc(1, sizeof(Opt_strings));
154+
optstr->string = opt;
155+
*(SLink **)opttable[i].var = add_ring_tail(*(SLink **)opttable[i].var, (SLink *)optstr);
156+
break;
157+
case 'n':
158+
break;
159+
case 's':
160+
*(const char **)opttable[i].var = opt;
161+
break;
162+
default:
163+
fprintf(stderr, "internal error\n");
164+
return -1;
165+
}
166+
}
167+
else
168+
{
169+
return -1;
170+
}
171+
}
172+
else
173+
{
174+
nargv[nargc] = *argva;
175+
nargc += 1;
176+
}
177+
}
178+
}

0 commit comments

Comments
 (0)