From: Robert Pengelly Date: Wed, 6 Nov 2024 23:54:07 +0000 (+0000) Subject: Changed a.out-ia16 to elks-ia16 and create i386 elks executables X-Git-Url: https://git.candlhat.org/?a=commitdiff_plain;h=f6a389bca54c4f483e1f0a020a7872ca72a23f97;p=slink.git Changed a.out-ia16 to elks-ia16 and create i386 elks executables --- diff --git a/elks.c b/elks.c index 8dfc9f8..fbac57e 100644 --- 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 51d93c0..cdb7af5 100644 --- 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 852066b..6f5e289 100644 --- 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 7861b2e..eb87b24 100644 --- 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; }