]> Shamusworld >> Repos - rmac/blobdiff - object.c
Fix for bug #78: Thanks to ggn for reporting and supplying the patch.
[rmac] / object.c
index cef73eea72babb0f8cf001c82008527addbea5f0..4614c38d66ed373eed028d7f0ed9a849f1282017 100644 (file)
--- a/object.c
+++ b/object.c
@@ -228,9 +228,16 @@ int WriteObject(int fd)
        }
 
        // Write requested object file...
-       switch (obj_format)
-       {
-       case BSD:
+       if ((obj_format == BSD) || ((obj_format == ALCYON) && (prg_flag == 0)))
+    {
+               // Force BSD format from here onwards
+               obj_format = BSD;
+
+               if (verb_flag)
+               {
+                       printf("Total       : %d bytes\n", sect[TEXT].sloc + sect[DATA].sloc + sect[BSS].sloc);
+               }
+
                ssize = ((LONG)sy_assign(NULL, NULL));          // Assign index numbers to the symbols
                tds = sect[TEXT].sloc + sect[DATA].sloc;        // Get size of TEXT and DATA segment
                buf = malloc(0x600000);                                         // Allocate 6mb object file image memory
@@ -308,9 +315,21 @@ int WriteObject(int fd)
                if (buf)
                        free(buf);                                      // Free allocated memory
 
-               break;
-
-       case ALCYON:
+    }
+    else if (obj_format==ALCYON)
+    {
+               if (verb_flag)
+               {
+                       if (prg_flag)
+                       {
+                               printf("TOS header  : 28 bytes\n");
+                               printf("Total       : %d bytes\n", 28 + sect[TEXT].sloc + sect[DATA].sloc + sect[BSS].sloc);
+                       }
+                       else
+                       {
+                               printf("Total       : %d bytes\n", sect[TEXT].sloc + sect[DATA].sloc + sect[BSS].sloc);
+                       }
+               }
                /*
                 *  Compute size of symbol table;
                 *   assign numbers to the symbols...
@@ -329,24 +348,24 @@ int WriteObject(int fd)
                if (t < ssize)
                        t = ssize;
 
-               buf = malloc(t + HDRSIZE) + HDRSIZE;
+               buf = (char *)((int)malloc(t + HDRSIZE) + HDRSIZE);
 
                /*
                 *  Build object file header
                 *   just before the text+data image
                 */
                chptr = buf - HDRSIZE;  /* -> base of header */
-               D_word(0x601a);                 /* magic number */
-               t = sect[TEXT].sloc;    /* TEXT size */
+               D_word(0x601a);                 /* 00 - magic number */
+               t = sect[TEXT].sloc;    /* 02 - TEXT size */
                D_long(t);
-               t = sect[DATA].sloc;    /* DATA size */
+               t = sect[DATA].sloc;    /* 06 - DATA size */
                D_long(t);
-               t = sect[BSS].sloc;             /* BSS size */
+               t = sect[BSS].sloc;             /* 0a - BSS size */
                D_long(t);
-               D_long(ssize);                  /* symbol table size */
-               D_long(0);                              /* stack size (unused) */
-               D_long(0);                              /* entry point (unused) */
-               D_word(0);                              /* relocation information exists */
+               D_long(ssize);                  /* 0e - symbol table size */
+               D_long(0);                              /* 12 - stack size (unused) */
+               D_long(PRGFLAGS);               /* 16 - PRGFLAGS */
+               D_word(0);                              /* 1a - relocation information exists */
 
                /*
                 *  Construct text and data segments;
@@ -384,7 +403,6 @@ int WriteObject(int fd)
                 */
                tds = markimg(buf, tds, sect[TEXT].sloc, 1);
                write(fd, buf, tds);
-               break;
        }
 
        return 0;