]> Shamusworld >> Repos - rln/blobdiff - rln.c
Patch to properly handle WORD sized symbol relocations by SainT.
[rln] / rln.c
diff --git a/rln.c b/rln.c
index 5b3323255551eccfde37216b5e8ce06998fbf5fc..1cbf9545efc88fbb39ad2d7f2fe6041fea454f59 100644 (file)
--- a/rln.c
+++ b/rln.c
@@ -1,6 +1,6 @@
 //
 // RLN - Reboot's Linker for the Atari Jaguar console system
-// Copyright (C) 199x, Allan K. Pratt, 2014-2015 Reboot & Friends
+// Copyright (C) 199x, Allan K. Pratt, 2014-2017 Reboot & Friends
 //
 
 #include "rln.h"
@@ -22,7 +22,7 @@ unsigned sflag = 0;                                   // Output only global symbols
 unsigned vflag = 0;                                    // Verbose flag
 unsigned wflag = 0;                                    // Show warnings flag
 unsigned zflag = 0;                                    // Suppress banner flag
-unsigned pflag = 0, uflag = 0;         // Unimplemented flags
+unsigned pflag = 0, uflag = 0;         // Unimplemented flags (partial link, don't abort on unresolved symbols)
 unsigned hd = 0;                                       // Index of next file handle to fill
 unsigned secalign = 7;                         // Section Alignment (8=phrase)
 unsigned tbase = 0;                                    // TEXT base address
@@ -585,6 +585,7 @@ int RelocateSegment(struct OFILE * ofile, int flag)
        unsigned glblreloc;             // Global relocation flag
        unsigned absreloc;              // Absolute relocation flag
        unsigned relreloc;              // Relative relocation flag
+       unsigned wordreloc;             // Relocate word only flag
        unsigned swcond;                // Switch statement condition
        unsigned relocsize;             // Relocation record size
 
@@ -664,8 +665,9 @@ int RelocateSegment(struct OFILE * ofile, int flag)
                addr = GetLong(rptr);
                rflg = GetLong(rptr + 4);
                glblreloc = (rflg & 0x00000010 ? 1 : 0);// Set global relocation flag
-               absreloc = (rflg & 0x00000040 ? 1 : 0); // Set absolute relocation flag
-               relreloc = (rflg & 0x000000A0 ? 1 : 0); // Set relative relocation flag
+               absreloc  = (rflg & 0x00000040 ? 1 : 0); // Set absolute relocation flag
+               relreloc  = (rflg & 0x000000A0 ? 1 : 0); // Set relative relocation flag
+               wordreloc = (rflg & 0x00000002 ? 1 : 0); // Set word relocation flag
 
                // Additional processing required for global relocations
                if (glblreloc)
@@ -682,9 +684,10 @@ int RelocateSegment(struct OFILE * ofile, int flag)
                        newdata = GetLong(ost + ((ssidx - 1) * 12) + 8);
                }
 
-               // Obtain the existing long word segment data and flip words if the
-               // relocation flags indicate it relates to a RISC MOVEI instruction
-               olddata = GetLong(sptr + addr);
+               // Obtain the existing long word (or word) segment data and flip words
+               // if the relocation flags indicate it relates to a RISC MOVEI
+               // instruction
+               olddata = (wordreloc ? GetWord(sptr + addr) : GetLong(sptr + addr));
 
                if (rflg & 0x01)
                        olddata = _SWAPWORD(olddata);
@@ -734,7 +737,10 @@ int RelocateSegment(struct OFILE * ofile, int flag)
                        if (rflg & 0x01)
                                newdata = _SWAPWORD(newdata);
 
-                       PutLong(sptr + addr, newdata);
+                       if (wordreloc)
+                               PutWord(sptr + addr, newdata);
+                       else
+                               PutLong(sptr + addr, newdata);
                }
                else if (relreloc)
                {
@@ -1050,11 +1056,11 @@ int WriteOutputFile(struct OHEADER * header)
        if (strchr(ofile, '.') == NULL)
        {
                if (aflag && cflag)
-                       strcat(ofile, ".cof");          // COF files
+                       strcat(ofile, ".cof");          // COF files (a type of abs)
                else if (aflag && !cflag)
                        strcat(ofile, ".abs");          // ABS files
                else
-                       strcat(ofile, ".o");            // Object files (partial linking etc)
+                       strcat(ofile, ".o");            // Object files (partial linking, etc)
        }
 
        FILE * fd = fopen(ofile, "wb");         // Attempt to open output file
@@ -1157,18 +1163,20 @@ int WriteOutputFile(struct OHEADER * header)
        }
 
        // Write the header, but not if noheaderflag
-       // Absolute (ABS) header
-       if (!cflag)
+       if (!noheaderflag)
        {
-               if (!noheaderflag)
+               // Absolute (ABS) header
+               if (!cflag)
+               {
                        if (fwrite(himage, 36, 1, fd) != 1)
                                goto werror;
-       }
-       // Absolute (COF) header
-       else
-       {
-               if (fwrite(himage, 168, 1, fd) != 1)
-                       goto werror;
+               }
+               // Absolute (COF) header
+               else
+               {
+                       if (fwrite(himage, 168, 1, fd) != 1)
+                               goto werror;
+               }
        }
 
        // Write the TEXT segment of each object file
@@ -1215,7 +1223,12 @@ int WriteOutputFile(struct OHEADER * header)
                }
        }
 
-       if (!noheaderflag)
+//wha? if (!noheaderflag)
+       // This isn't quite right, but it's closer...
+       // (the l and s flags tell the linker to output local & global symbols
+       //  in the symbol table, so it seems there's some other thing that's a
+       // default set somewhere. Not 100% sure. Setting -s kills -l, BTW...)
+       if (lflag || sflag)
        {
                // Write the symbols table and string table
                // Absolute (COF) symbol/string table
@@ -2983,7 +2996,7 @@ void ShowVersion(void)
                "| |  | | | | |\n"
                "|_|  |_|_| |_|\n"
                "\nReboot's Linker for Atari Jaguar\n"
-               "Copyright (c) 199x Allan K. Pratt, 2014-2015 Reboot\n"
+               "Copyright (c) 199x Allan K. Pratt, 2014-2017 Reboot\n"
                "V%i.%i.%i %s (%s)\n\n", MAJOR, MINOR, PATCH, __DATE__, PLATFORM);
        }
 }
@@ -3008,10 +3021,11 @@ void ShowHelp(void)
        printf("   -d                      wait for key after link\n");
        printf("   -e                      output COF absolute file\n");
        printf("   -g                      output source-level debugging\n");
-       printf("   -i <fname> <label>      incbin <fname> and set <label>\n");
+       printf("   -i <fname> <label>      incbin <fname> and set <label> (trunc to 8 chars)\n");
+       printf("   -ii <fname> <label>     incbin <fname> and set <label> (no truncation)\n");
        printf("   -l                      add local symbols\n");
        printf("   -m                      produce load symbols map\n");
-       printf("   -n                      output no file header to .abs file\n");
+       printf("   -n                      output no file header to absolute file\n");
        printf("   -o <fname>              set output name\n");
        printf("   -r<size>                section alignment size\n");
        printf("                           w: word (2 bytes)\n");
@@ -3019,7 +3033,7 @@ void ShowHelp(void)
        printf("                           p: phrase (8 bytes, default alignment)\n");
        printf("                           d: double phrase (16 bytes)\n");
        printf("                           q: quad phrase (32 bytes)\n");
-       printf("   -s                      output only global symbols\n");
+       printf("   -s                      output only global symbols (supresses -l)\n");
        printf("   -u                      allow unresolved symbols (experimental)\n");
        printf("   -v                      set verbose mode\n");
        printf("   -w                      show linker warnings\n");