StupidOS/bin/ld/main.c

94 lines
1.4 KiB
C
Raw Normal View History

2024-03-20 15:51:27 +00:00
#include <stdlib.h>
#include <stdio.h>
#include <coff.h>
2024-06-14 03:32:46 +00:00
# define BASE_ADDRESS = 0x100000
2024-03-20 15:51:27 +00:00
static char *prg_name;
static char *outfile = "a.out";
2024-06-10 08:05:10 +00:00
typedef struct {
2024-06-14 03:32:46 +00:00
size_t size;
uint8_t *raw;
2024-03-21 12:18:23 +00:00
} Section;
2024-06-14 03:32:46 +00:00
typedef struct object {
size_t section_count;
Section *sections;
2024-06-10 08:05:10 +00:00
2024-06-14 03:32:46 +00:00
struct object *next;
2024-06-10 08:05:10 +00:00
} Object;
2024-03-21 12:18:23 +00:00
2024-06-14 03:32:46 +00:00
typedef struct {
} Symtab;
2024-03-20 15:51:27 +00:00
static void
usage(int retcode)
{
if (retcode == EXIT_FAILURE)
{
fprintf(stderr, "Try '%s -h' form more information.\n", prg_name);
}
else
{
printf("Usage: %s [-hV] [-o outfile] [OBJS...]\n", prg_name);
printf("\t-h\tdisplay this help and exit\n");
printf("\t-V\toutput version information\n");
printf("\t-o outfile\tout file (default: %s)\n", outfile);
printf("\nReport bugs to <%s>\n", MK_BUGREPORT);
}
exit(retcode);
}
static void
version(void)
{
2024-06-14 03:32:46 +00:00
printf("%s (%s) %s", prg_name, MK_PACKAGE, MK_COMMIT);
2024-03-20 15:51:27 +00:00
exit(EXIT_SUCCESS);
}
int
main(int argc, char **argv)
{
FILE *fp;
FILHDR fhdr;
SCNHDR shdr;
2024-03-21 12:18:23 +00:00
uint8_t *buffer;
2024-06-10 08:05:10 +00:00
SYMENT entry;
2024-04-02 10:03:47 +00:00
RELOC reloc;
2024-03-21 12:18:23 +00:00
int idx;
2024-03-20 15:51:27 +00:00
prg_name = argv[0];
while ((argc > 1) && (argv[1][0] == '-'))
{
switch (argv[1][1])
{
case 'h':
usage(EXIT_SUCCESS);
break;
case 'V':
version();
break;
case 'o':
argv++;
argc--;
if (argc <= 1) usage(EXIT_FAILURE);
outfile = argv[1];
break;
}
argv++;
argc--;
}
if (argc <= 1) usage(EXIT_FAILURE);
2024-06-14 03:32:46 +00:00
2024-03-20 15:51:27 +00:00
return (EXIT_SUCCESS);
}