1 /* This is a cheap hack. The xa51 has a couple of ways to scramble
2 relocation info into it's opcode that the standard linker can't
5 The relocatable format looks like the known one, BUT ISN'T.
7 The only things that are handled now are:
9 "SDCCXA rel, version %f" must be the first line
10 "H %d areas %d global symbols" defines the # of areas and globals
11 "S <symbol> [Ref000 | DefXXXX]" Def's are supposed to be defined in
12 their own area/segment
13 "A <seg> size %d flags %d" switch to another segment. this can happen
14 multiple times and should be equal. flags is ignored
15 "T xx xx bb bb ..." where x is the address within the current segment
17 "R xx <how> <symbol>" the relocation tag. xx is the offset within the
18 previous "T .." line. <how> could be something like REL_FF, REL_FFFF,
19 ABS_F0FF. and symbol is the previous defined symbol it refers to
28 #include "xa_version.h"
30 static char outFileName[PATH_MAX];
32 void baseName(char *name, char*base) {
35 // find the last path seperator in name
36 for (first=strlen(name)-1;
37 (name[first]!='/' && name[first]!='\\') && first;
39 if (name[first]=='/' || name[first]=='\\') {
43 // find the last ext seperator in name
44 for (last=strlen(name)-1;
45 (name[last]!='.' && last);
51 printf ("baseName: %s %d %d\n", name, first, last);
52 // fill the base with the baseName
53 for (i=first; i<last; i++) {
54 base[i-first]=name[i];
59 void readModule(char *module) {
64 if ((relModule=fopen(module, "r"))==NULL) {
68 printf ("ReadModule: %s\n", module);
69 // first we need to check if this is a valid file
70 if (sscanf(line, "SDCCXA rel, version %lf", &thisVersion)!=1) {
71 fprintf (stderr, "%s is not a valid input file\n", module);
74 if (thisVersion!=version) {
75 fprintf (stderr, "version conflict; we: %f != module: %f\n",
76 version, thisVersion);
82 void writeModule(char *module) {
83 if (!outFileName[0]) {
84 sprintf (outFileName, "%s.bin", module);
86 printf ("WriteModule: %s\n", outFileName);
89 void usage (char * progName, int errNo) {
90 fprintf (stderr, "usage: %s f.rel [f1.rel [f2.rel [...]]]\n", progName);
96 int main(int argc, char **argv) {
97 char outputName[PATH_MAX];
104 baseName(argv[1], outputName);
105 printf ("using baseName: %s\n", outputName);
106 for (i=1; i<argc; i++) {
109 writeModule (outputName);