Changed a.out-ia16 to elks-ia16 and create i386 elks executables
authorRobert Pengelly <robertapengelly@hotmail.com>
Wed, 6 Nov 2024 23:54:07 +0000 (23:54 +0000)
committerRobert Pengelly <robertapengelly@hotmail.com>
Wed, 6 Nov 2024 23:54:07 +0000 (23:54 +0000)
elks.c
ld.c
ld.h
lib.c

diff --git a/elks.c b/elks.c
index 8dfc9f8426aedf191cf65833141b0f8c87cc590d..fbac57e9d2d30ff3aa5c4af059c9420416de3fce 100644 (file)
--- a/elks.c
+++ b/elks.c
@@ -373,7 +373,7 @@ static int relocate (struct elks_object *object, struct elks_relocation_info *r,
             r_symbolnum = GET_UINT32 (r->r_symbolnum) & (3L << 29);
             r_address = GET_INT32 (r->r_address);
             
-            if (state->format == LD_FORMAT_IA16_AOUT || state->format == LD_FORMAT_I386_AOUT || ((r_symbolnum >> 28) & 0xff) != N_ABS) {
+            if (state->format == LD_FORMAT_IA16_ELKS || state->format == LD_FORMAT_I386_ELKS || state->format == LD_FORMAT_I386_AOUT || ((r_symbolnum >> 28) & 0xff) != N_ABS) {
             
                 if (state->format == LD_FORMAT_BIN || state->format == LD_FORMAT_COM) {
                 
@@ -481,7 +481,7 @@ static int init_elks_object (void) {
 
     if (state->format == LD_FORMAT_I386_AOUT) {
         header_size = sizeof (struct aout_exec);
-    } else if (state->format == LD_FORMAT_IA16_AOUT) {
+    } else if (state->format == LD_FORMAT_IA16_ELKS || state->format == LD_FORMAT_I386_ELKS) {
         header_size = sizeof (struct elks_exec);
     }
     
@@ -518,7 +518,7 @@ static int write_elks_object (unsigned long a_entry) {
         write741_to_byte_array (header->a_trsize, tgr.relocations_count * sizeof (struct relocation_info));
         write741_to_byte_array (header->a_drsize, dgr.relocations_count * sizeof (struct relocation_info));
     
-    } else if (state->format == LD_FORMAT_IA16_AOUT) {
+    } else if (state->format == LD_FORMAT_IA16_ELKS || state->format == LD_FORMAT_I386_ELKS) {
     
         struct elks_exec *header = output;
         
@@ -526,7 +526,7 @@ static int write_elks_object (unsigned long a_entry) {
         header->a_magic[1] = ELKS_MAGIC & 0xff;
         
         header->a_flags = 0x10;
-        header->a_cpu = 0x04;
+        header->a_cpu = (state->format == LD_FORMAT_I386_ELKS) ? 0x10 : 0x04;
         header->a_hdrlen = sizeof (*header);
         
         write741_to_byte_array (header->a_text, state->text_size);
@@ -571,7 +571,7 @@ static int write_elks_object (unsigned long a_entry) {
         
         }
     
-    } else if (state->format == LD_FORMAT_IA16_AOUT) {
+    } else if (state->format == LD_FORMAT_IA16_ELKS || state->format == LD_FORMAT_I386_ELKS) {
     
         if (tgr.relocations_count > 0) {
         
@@ -623,7 +623,7 @@ int create_executable_from_elks_objects (void) {
         text = (void *) (char *) output;
         data = (void *) ((char *) text + state->text_size);
     
-    } else if (state->format == LD_FORMAT_IA16_AOUT || state->format == LD_FORMAT_I386_AOUT) {
+    } else if (state->format == LD_FORMAT_IA16_ELKS || state->format == LD_FORMAT_I386_ELKS || state->format == LD_FORMAT_I386_AOUT) {
     
         if (init_elks_object ()) {
         
@@ -662,7 +662,7 @@ int create_executable_from_elks_objects (void) {
         return EXIT_FAILURE;
     }
     
-    if (state->format == LD_FORMAT_IA16_AOUT || state->format == LD_FORMAT_I386_AOUT) {
+    if (state->format == LD_FORMAT_IA16_ELKS || state->format == LD_FORMAT_I386_ELKS || state->format == LD_FORMAT_I386_AOUT) {
         entry = get_entry ();
     }
     
@@ -708,7 +708,7 @@ int create_executable_from_elks_objects (void) {
         
         }
     
-    } else if (state->format == LD_FORMAT_IA16_AOUT || state->format == LD_FORMAT_I386_AOUT) {
+    } else if (state->format == LD_FORMAT_IA16_ELKS || state->format == LD_FORMAT_I386_ELKS || state->format == LD_FORMAT_I386_AOUT) {
     
         if (write_elks_object (entry)) {
         
diff --git a/ld.c b/ld.c
index 51d93c02b1aa4a58f1247f5f6390b5f80e54cc26..cdb7af52a6e86bfc3b18ac305a20605f32e23194 100644 (file)
--- a/ld.c
+++ b/ld.c
@@ -659,7 +659,7 @@ int main (int argc, char **argv) {
         state->ofile = xstrdup ("a.out");
     }
     
-    if (state->format == LD_FORMAT_BIN || state->format == LD_FORMAT_COM) {
+    if (state->format == LD_FORMAT_BIN || state->format == LD_FORMAT_COM || state->format == LD_FORMAT_IA16_ELKS || state->format == LD_FORMAT_I386_ELKS) {
     
         if (state->format == LD_FORMAT_COM) {
             state->psp = 0x100;
@@ -677,6 +677,17 @@ int main (int argc, char **argv) {
     
     }
     
+    if (state->format == LD_FORMAT_IA16_ELKS) {
+    
+        if (state->text_size > 65536L || state->data_size > 65536L || (state->text_size + state->data_size) > 65536L) {
+        
+            report_at (program_name, 0, REPORT_ERROR, "binary to large for elks-ia16");
+            return EXIT_FAILURE;
+        
+        }
+    
+    }
+    
     if (state->nb_elks_objs > 0) {
     
         if (create_executable_from_elks_objects ()) {
diff --git a/ld.h b/ld.h
index 852066bf9259d602299342e5c2cf4e2174ad3a94..6f5e28924f540b2336e59c84e7b1547cc38c5543 100644 (file)
--- a/ld.h
+++ b/ld.h
@@ -51,8 +51,10 @@ struct ld_state {
 #define     LD_FORMAT_COM               0x00
 #define     LD_FORMAT_BIN               0x01
 
-#define     LD_FORMAT_IA16_AOUT         0x02
-#define     LD_FORMAT_I386_AOUT         0x04
+#define     LD_FORMAT_IA16_ELKS         0x02
+#define     LD_FORMAT_I386_ELKS         0x04
+
+#define     LD_FORMAT_I386_AOUT         0x08
 
 extern struct ld_state *state;
 extern const char *program_name;
diff --git a/lib.c b/lib.c
index 7861b2e2e3aaae4ea0d7d01885806bf950db115a..eb87b241cfab23b636cfbab1caa5c1bda587623a 100644 (file)
--- a/lib.c
+++ b/lib.c
@@ -65,7 +65,8 @@ static void print_usage (void) {
         
         fprintf (stderr, "    --oformat FORMAT      Specify the format of output file (default msdos)\n");
         fprintf (stderr, "                              Supported formats are:\n");
-        fprintf (stderr, "                                  a.out-i386, binary, msdos\n");
+        fprintf (stderr, "                                  a.out-i386, elks-ia16, elks-i386,\n");
+        fprintf (stderr, "                                  binary, msdos\n");
         
         fprintf (stderr, "    -e ADDRESS            Set start address.\n");
         fprintf (stderr, "    -s                    Ignored.\n");
@@ -254,9 +255,16 @@ void parse_args (int argc, char **argv, int optind) {
                 
                 }
                 
-                if (xstrcasecmp (optarg, "a.out-ia16") == 0) {
+                if (xstrcasecmp (optarg, "elks-ia16") == 0) {
                 
-                    state->format = LD_FORMAT_IA16_AOUT;
+                    state->format = LD_FORMAT_IA16_ELKS;
+                    break;
+                
+                }
+                
+                if (xstrcasecmp (optarg, "elks-i386") == 0) {
+                
+                    state->format = LD_FORMAT_I386_ELKS;
                     break;
                 
                 }