2000-05-28 13:40:48 +00:00
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* */
|
|
|
|
|
/* main.c */
|
|
|
|
|
/* */
|
|
|
|
|
/* Main program for the ld65 linker */
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/* */
|
2003-02-16 14:32:13 +00:00
|
|
|
|
/* (C) 1998-2003 Ullrich von Bassewitz */
|
|
|
|
|
/* R<>merstrasse 52 */
|
|
|
|
|
/* D-70794 Filderstadt */
|
|
|
|
|
/* EMail: uz@cc65.org */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* */
|
|
|
|
|
/* */
|
|
|
|
|
/* This software is provided 'as-is', without any expressed or implied */
|
|
|
|
|
/* warranty. In no event will the authors be held liable for any damages */
|
|
|
|
|
/* arising from the use of this software. */
|
|
|
|
|
/* */
|
|
|
|
|
/* Permission is granted to anyone to use this software for any purpose, */
|
|
|
|
|
/* including commercial applications, and to alter it and redistribute it */
|
|
|
|
|
/* freely, subject to the following restrictions: */
|
|
|
|
|
/* */
|
|
|
|
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
|
|
|
/* claim that you wrote the original software. If you use this software */
|
|
|
|
|
/* in a product, an acknowledgment in the product documentation would be */
|
|
|
|
|
/* appreciated but is not required. */
|
|
|
|
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
|
|
|
/* be misrepresented as being the original software. */
|
|
|
|
|
/* 3. This notice may not be removed or altered from any source */
|
|
|
|
|
/* distribution. */
|
|
|
|
|
/* */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
2000-08-23 14:13:24 +00:00
|
|
|
|
/* common */
|
|
|
|
|
#include "cmdline.h"
|
2003-06-02 13:37:05 +00:00
|
|
|
|
#include "filetype.h"
|
2000-08-23 14:13:24 +00:00
|
|
|
|
#include "libdefs.h"
|
|
|
|
|
#include "objdefs.h"
|
2001-03-10 10:21:03 +00:00
|
|
|
|
#include "print.h"
|
2000-08-23 14:13:24 +00:00
|
|
|
|
#include "target.h"
|
|
|
|
|
#include "version.h"
|
|
|
|
|
#include "xmalloc.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2000-08-23 14:13:24 +00:00
|
|
|
|
/* ld65 */
|
2003-06-06 12:45:19 +00:00
|
|
|
|
#include "asserts.h"
|
2000-08-23 14:13:24 +00:00
|
|
|
|
#include "binfmt.h"
|
2000-11-20 15:22:57 +00:00
|
|
|
|
#include "condes.h"
|
2000-08-23 14:13:24 +00:00
|
|
|
|
#include "config.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
#include "error.h"
|
2000-08-23 14:13:24 +00:00
|
|
|
|
#include "exports.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
#include "fileio.h"
|
2003-05-29 09:35:11 +00:00
|
|
|
|
#include "filepath.h"
|
2000-08-23 14:13:24 +00:00
|
|
|
|
#include "global.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
#include "library.h"
|
|
|
|
|
#include "mapfile.h"
|
2000-08-23 14:13:24 +00:00
|
|
|
|
#include "objfile.h"
|
|
|
|
|
#include "scanner.h"
|
|
|
|
|
#include "segments.h"
|
2003-06-04 12:40:14 +00:00
|
|
|
|
#include "spool.h"
|
2000-08-23 14:13:24 +00:00
|
|
|
|
#include "tgtcfg.h"
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Data */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned ObjFiles = 0; /* Count of object files linked */
|
|
|
|
|
static unsigned LibFiles = 0; /* Count of library files linked */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
/* Code */
|
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void Usage (void)
|
|
|
|
|
/* Print usage information and exit */
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr,
|
|
|
|
|
"Usage: %s [options] module ...\n"
|
2000-06-14 09:57:42 +00:00
|
|
|
|
"Short options:\n"
|
2001-10-02 19:01:00 +00:00
|
|
|
|
" -C name\t\tUse linker config file\n"
|
2003-05-29 09:35:11 +00:00
|
|
|
|
" -L path\t\tSpecify a library search path\n"
|
2001-10-02 19:01:00 +00:00
|
|
|
|
" -Ln name\t\tCreate a VICE label file\n"
|
|
|
|
|
" -S addr\t\tSet the default start address\n"
|
|
|
|
|
" -V\t\t\tPrint the linker version\n"
|
2000-06-14 09:57:42 +00:00
|
|
|
|
" -h\t\t\tHelp (this text)\n"
|
|
|
|
|
" -m name\t\tCreate a map file\n"
|
|
|
|
|
" -o name\t\tName the default output file\n"
|
2000-08-23 14:13:24 +00:00
|
|
|
|
" -t sys\t\tSet the target system\n"
|
2000-06-14 09:57:42 +00:00
|
|
|
|
" -v\t\t\tVerbose mode\n"
|
|
|
|
|
" -vm\t\t\tVerbose map file\n"
|
|
|
|
|
"\n"
|
|
|
|
|
"Long options:\n"
|
2003-05-29 09:35:11 +00:00
|
|
|
|
" --cfg-path path\tSpecify a config file search path\n"
|
2002-12-13 00:29:40 +00:00
|
|
|
|
" --config name\t\tUse linker config file\n"
|
2003-08-15 10:59:22 +00:00
|
|
|
|
" --dbgfile name\tGenerate debug information\n"
|
2003-02-16 14:32:13 +00:00
|
|
|
|
" --dump-config name\tDump a builtin configuration\n"
|
2000-06-14 09:57:42 +00:00
|
|
|
|
" --help\t\tHelp (this text)\n"
|
2003-06-02 13:37:05 +00:00
|
|
|
|
" --lib file\t\tLink this library\n"
|
2003-05-29 09:35:11 +00:00
|
|
|
|
" --lib-path path\tSpecify a library search path\n"
|
2000-08-23 14:13:24 +00:00
|
|
|
|
" --mapfile name\tCreate a map file\n"
|
2002-04-25 18:11:05 +00:00
|
|
|
|
" --module-id id\tSpecify a module id\n"
|
2003-06-02 13:37:05 +00:00
|
|
|
|
" --obj file\t\tLink this object file\n"
|
2003-05-29 09:35:11 +00:00
|
|
|
|
" --obj-path path\tSpecify an object file search path\n"
|
2000-08-24 06:41:55 +00:00
|
|
|
|
" --start-addr addr\tSet the default start address\n"
|
2000-08-23 14:13:24 +00:00
|
|
|
|
" --target sys\t\tSet the target system\n"
|
2000-06-14 09:57:42 +00:00
|
|
|
|
" --version\t\tPrint the linker version\n",
|
2000-05-28 13:40:48 +00:00
|
|
|
|
ProgName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static unsigned long CvtNumber (const char* Arg, const char* Number)
|
|
|
|
|
/* Convert a number from a string. Allow '$' and '0x' prefixes for hex
|
|
|
|
|
* numbers.
|
|
|
|
|
*/
|
|
|
|
|
{
|
|
|
|
|
unsigned long Val;
|
2000-06-14 09:57:42 +00:00
|
|
|
|
int Converted;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
/* Convert */
|
|
|
|
|
if (*Number == '$') {
|
|
|
|
|
++Number;
|
2000-06-14 09:57:42 +00:00
|
|
|
|
Converted = sscanf (Number, "%lx", &Val);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
} else {
|
2000-06-14 09:57:42 +00:00
|
|
|
|
Converted = sscanf (Number, "%li", (long*)&Val);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-14 09:57:42 +00:00
|
|
|
|
/* Check if we do really have a number */
|
|
|
|
|
if (Converted != 1) {
|
2000-08-24 06:41:55 +00:00
|
|
|
|
Error ("Invalid number given in argument: %s\n", Arg);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
2000-06-14 09:57:42 +00:00
|
|
|
|
/* Return the result */
|
|
|
|
|
return Val;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 13:37:05 +00:00
|
|
|
|
static void LinkFile (const char* Name, FILETYPE Type)
|
|
|
|
|
/* Handle one file */
|
2000-05-28 13:40:48 +00:00
|
|
|
|
{
|
2003-06-02 13:37:05 +00:00
|
|
|
|
char* PathName;
|
|
|
|
|
FILE* F;
|
|
|
|
|
unsigned long Magic;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
|
2003-06-02 13:37:05 +00:00
|
|
|
|
/* If we don't know the file type, determine it from the extension */
|
|
|
|
|
if (Type == FILETYPE_UNKNOWN) {
|
|
|
|
|
Type = GetFileType (Name);
|
|
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2003-06-02 13:37:05 +00:00
|
|
|
|
/* For known file types, search the file in the directory list */
|
|
|
|
|
switch (Type) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2003-06-02 13:37:05 +00:00
|
|
|
|
case FILETYPE_LIB:
|
|
|
|
|
PathName = SearchFile (Name, SEARCH_LIB);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case FILETYPE_OBJ:
|
|
|
|
|
PathName = SearchFile (Name, SEARCH_OBJ);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
PathName = xstrdup (Name); /* Use the name as is */
|
|
|
|
|
break;
|
|
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2003-06-02 13:37:05 +00:00
|
|
|
|
/* We must have a valid name now */
|
|
|
|
|
if (PathName == 0) {
|
|
|
|
|
Error ("Input file `%s' not found", Name);
|
|
|
|
|
}
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2003-06-02 13:37:05 +00:00
|
|
|
|
/* Try to open the file */
|
|
|
|
|
F = fopen (PathName, "rb");
|
|
|
|
|
if (F == 0) {
|
|
|
|
|
Error ("Cannot open `%s': %s", PathName, strerror (errno));
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Read the magic word */
|
|
|
|
|
Magic = Read32 (F);
|
|
|
|
|
|
2003-06-02 13:37:05 +00:00
|
|
|
|
/* Check the magic for known file types. The handling is somewhat weird
|
|
|
|
|
* since we may have given a file with a ".lib" extension, which was
|
|
|
|
|
* searched and found in a directory for library files, but we now find
|
|
|
|
|
* out (by looking at the magic) that it's indeed an object file. We just
|
|
|
|
|
* ignore the problem and hope no one will notice...
|
|
|
|
|
*/
|
2000-05-28 13:40:48 +00:00
|
|
|
|
switch (Magic) {
|
|
|
|
|
|
2003-06-02 13:37:05 +00:00
|
|
|
|
case OBJ_MAGIC:
|
|
|
|
|
ObjAdd (F, PathName);
|
|
|
|
|
++ObjFiles;
|
|
|
|
|
break;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2003-06-02 13:37:05 +00:00
|
|
|
|
case LIB_MAGIC:
|
|
|
|
|
LibAdd (F, PathName);
|
|
|
|
|
++LibFiles;
|
|
|
|
|
break;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2003-06-02 13:37:05 +00:00
|
|
|
|
default:
|
2000-05-28 13:40:48 +00:00
|
|
|
|
fclose (F);
|
2003-06-02 13:37:05 +00:00
|
|
|
|
Error ("File `%s' has unknown type", PathName);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
2003-06-02 13:37:05 +00:00
|
|
|
|
/* Free allocated memory. */
|
|
|
|
|
xfree (PathName);
|
2000-06-14 09:57:42 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-05-29 09:35:11 +00:00
|
|
|
|
static void OptCfgPath (const char* Opt attribute ((unused)), const char* Arg)
|
|
|
|
|
/* Specify a config file search path */
|
|
|
|
|
{
|
|
|
|
|
AddSearchPath (Arg, SEARCH_CFG);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 22:04:19 +00:00
|
|
|
|
static void OptConfig (const char* Opt attribute ((unused)), const char* Arg)
|
2000-08-23 14:13:24 +00:00
|
|
|
|
/* Define the config file */
|
|
|
|
|
{
|
2003-06-02 13:37:05 +00:00
|
|
|
|
char* PathName;
|
|
|
|
|
|
2000-08-23 14:13:24 +00:00
|
|
|
|
if (CfgAvail ()) {
|
|
|
|
|
Error ("Cannot use -C/-t twice");
|
|
|
|
|
}
|
2003-06-02 13:37:05 +00:00
|
|
|
|
/* Search for the file */
|
|
|
|
|
PathName = SearchFile (Arg, SEARCH_CFG);
|
|
|
|
|
if (PathName == 0) {
|
|
|
|
|
Error ("Cannot find config file `%s'", Arg);
|
|
|
|
|
} else {
|
|
|
|
|
CfgSetName (PathName);
|
|
|
|
|
}
|
2000-08-23 14:13:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 22:04:19 +00:00
|
|
|
|
static void OptDbgFile (const char* Opt attribute ((unused)), const char* Arg)
|
2001-05-29 07:39:46 +00:00
|
|
|
|
/* Give the name of the debug file */
|
|
|
|
|
{
|
|
|
|
|
DbgFileName = Arg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-02-16 14:32:13 +00:00
|
|
|
|
static void OptDumpConfig (const char* Opt attribute ((unused)), const char* Arg)
|
|
|
|
|
/* Dump a builtin linker configuration */
|
|
|
|
|
{
|
|
|
|
|
/* Map the given target name to its id */
|
|
|
|
|
target_t T = FindTarget (Arg);
|
|
|
|
|
if (T == TGT_UNKNOWN) {
|
|
|
|
|
Error ("Target system `%s' is unknown", Arg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Dump the builtin configuration */
|
|
|
|
|
DumpBuiltinConfig (stdout, T);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-10-02 19:01:00 +00:00
|
|
|
|
static void OptHelp (const char* Opt attribute ((unused)),
|
2001-09-30 22:04:19 +00:00
|
|
|
|
const char* Arg attribute ((unused)))
|
2000-06-14 09:57:42 +00:00
|
|
|
|
/* Print usage information and exit */
|
|
|
|
|
{
|
|
|
|
|
Usage ();
|
|
|
|
|
exit (EXIT_SUCCESS);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 13:37:05 +00:00
|
|
|
|
static void OptLib (const char* Opt attribute ((unused)), const char* Arg)
|
|
|
|
|
/* Link a library */
|
|
|
|
|
{
|
|
|
|
|
LinkFile (Arg, FILETYPE_LIB);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-05-29 09:35:11 +00:00
|
|
|
|
static void OptLibPath (const char* Opt attribute ((unused)), const char* Arg)
|
|
|
|
|
/* Specify a library file search path */
|
|
|
|
|
{
|
|
|
|
|
AddSearchPath (Arg, SEARCH_LIB);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 22:04:19 +00:00
|
|
|
|
static void OptMapFile (const char* Opt attribute ((unused)), const char* Arg)
|
2000-08-23 14:13:24 +00:00
|
|
|
|
/* Give the name of the map file */
|
|
|
|
|
{
|
|
|
|
|
MapFileName = Arg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-04-25 18:11:05 +00:00
|
|
|
|
static void OptModuleId (const char* Opt, const char* Arg)
|
|
|
|
|
/* Specify a module id */
|
|
|
|
|
{
|
|
|
|
|
unsigned long Id = CvtNumber (Opt, Arg);
|
|
|
|
|
if (Id > 0xFFFFUL) {
|
|
|
|
|
Error ("Range error in module id");
|
|
|
|
|
}
|
|
|
|
|
ModuleId = (unsigned) Id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 13:37:05 +00:00
|
|
|
|
static void OptObj (const char* Opt attribute ((unused)), const char* Arg)
|
|
|
|
|
/* Link an object file */
|
|
|
|
|
{
|
|
|
|
|
LinkFile (Arg, FILETYPE_OBJ);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-05-29 09:35:11 +00:00
|
|
|
|
static void OptObjPath (const char* Opt attribute ((unused)), const char* Arg)
|
|
|
|
|
/* Specify an object file search path */
|
|
|
|
|
{
|
|
|
|
|
AddSearchPath (Arg, SEARCH_OBJ);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-08-24 06:41:55 +00:00
|
|
|
|
static void OptStartAddr (const char* Opt, const char* Arg)
|
|
|
|
|
/* Set the default start address */
|
|
|
|
|
{
|
|
|
|
|
StartAddr = CvtNumber (Opt, Arg);
|
2002-12-03 22:32:38 +00:00
|
|
|
|
HaveStartAddr = 1;
|
2000-08-24 06:41:55 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-09-30 22:04:19 +00:00
|
|
|
|
static void OptTarget (const char* Opt attribute ((unused)), const char* Arg)
|
2000-08-23 14:13:24 +00:00
|
|
|
|
/* Set the target system */
|
|
|
|
|
{
|
|
|
|
|
const TargetDesc* D;
|
|
|
|
|
|
|
|
|
|
/* Map the target name to a target id */
|
|
|
|
|
Target = FindTarget (Arg);
|
|
|
|
|
if (Target == TGT_UNKNOWN) {
|
|
|
|
|
Error ("Invalid target name: `%s'", Arg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Get the target description record */
|
|
|
|
|
D = &Targets[Target];
|
|
|
|
|
|
|
|
|
|
/* Set the target data */
|
|
|
|
|
DefaultBinFmt = D->BinFmt;
|
|
|
|
|
CfgSetBuf (D->Cfg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-10-02 19:01:00 +00:00
|
|
|
|
static void OptVersion (const char* Opt attribute ((unused)),
|
2001-09-30 22:04:19 +00:00
|
|
|
|
const char* Arg attribute ((unused)))
|
2000-06-14 09:57:42 +00:00
|
|
|
|
/* Print the assembler version */
|
|
|
|
|
{
|
|
|
|
|
fprintf (stderr,
|
2002-11-25 17:33:58 +00:00
|
|
|
|
"ld65 V%u.%u.%u - (C) Copyright 1998-2002 Ullrich von Bassewitz\n",
|
2000-06-14 09:57:42 +00:00
|
|
|
|
VER_MAJOR, VER_MINOR, VER_PATCH);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main (int argc, char* argv [])
|
|
|
|
|
/* Assembler main program */
|
|
|
|
|
{
|
2000-06-14 09:57:42 +00:00
|
|
|
|
/* Program long options */
|
|
|
|
|
static const LongOpt OptTab[] = {
|
2003-05-29 09:35:11 +00:00
|
|
|
|
{ "--cfg-path", 1, OptCfgPath },
|
2001-09-30 22:04:19 +00:00
|
|
|
|
{ "--config", 1, OptConfig },
|
2002-04-25 18:11:05 +00:00
|
|
|
|
{ "--dbgfile", 1, OptDbgFile },
|
2003-02-16 14:32:13 +00:00
|
|
|
|
{ "--dump-config", 1, OptDumpConfig },
|
2002-04-25 18:11:05 +00:00
|
|
|
|
{ "--help", 0, OptHelp },
|
2003-06-02 13:37:05 +00:00
|
|
|
|
{ "--lib", 1, OptLib },
|
2003-05-29 09:35:11 +00:00
|
|
|
|
{ "--lib-path", 1, OptLibPath },
|
2002-04-25 18:11:05 +00:00
|
|
|
|
{ "--mapfile", 1, OptMapFile },
|
|
|
|
|
{ "--module-id", 1, OptModuleId },
|
2003-06-02 13:37:05 +00:00
|
|
|
|
{ "--obj", 1, OptObj },
|
2003-05-29 09:35:11 +00:00
|
|
|
|
{ "--obj-path", 1, OptObjPath },
|
2001-09-30 22:04:19 +00:00
|
|
|
|
{ "--start-addr", 1, OptStartAddr },
|
|
|
|
|
{ "--target", 1, OptTarget },
|
|
|
|
|
{ "--version", 0, OptVersion },
|
2000-06-14 09:57:42 +00:00
|
|
|
|
};
|
|
|
|
|
|
2001-09-15 13:36:59 +00:00
|
|
|
|
unsigned I;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2001-10-02 19:01:00 +00:00
|
|
|
|
/* Initialize the cmdline module */
|
2001-03-09 21:59:23 +00:00
|
|
|
|
InitCmdLine (&argc, &argv, "ld65");
|
2000-06-14 09:57:42 +00:00
|
|
|
|
|
2003-06-02 13:37:05 +00:00
|
|
|
|
/* Initialize the input file search paths */
|
|
|
|
|
InitSearchPaths ();
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
2003-06-04 12:40:14 +00:00
|
|
|
|
/* Initialize the string pool */
|
|
|
|
|
InitStrPool ();
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* Check the parameters */
|
|
|
|
|
I = 1;
|
2001-03-09 21:59:23 +00:00
|
|
|
|
while (I < ArgCount) {
|
2000-08-23 14:13:24 +00:00
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* Get the argument */
|
2001-03-09 21:59:23 +00:00
|
|
|
|
const char* Arg = ArgVec[I];
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
/* Check for an option */
|
|
|
|
|
if (Arg [0] == '-') {
|
|
|
|
|
|
|
|
|
|
/* An option */
|
|
|
|
|
switch (Arg [1]) {
|
|
|
|
|
|
|
|
|
|
case '-':
|
2000-08-23 14:13:24 +00:00
|
|
|
|
LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
|
|
|
|
|
break;
|
|
|
|
|
|
2000-10-18 07:29:40 +00:00
|
|
|
|
case 'h':
|
|
|
|
|
case '?':
|
|
|
|
|
OptHelp (Arg, 0);
|
|
|
|
|
break;
|
|
|
|
|
|
2000-08-23 14:13:24 +00:00
|
|
|
|
case 'm':
|
|
|
|
|
OptMapFile (Arg, GetArg (&I, 2));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'o':
|
|
|
|
|
OutputName = GetArg (&I, 2);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 't':
|
|
|
|
|
if (CfgAvail ()) {
|
|
|
|
|
Error ("Cannot use -C/-t twice");
|
|
|
|
|
}
|
|
|
|
|
OptTarget (Arg, GetArg (&I, 2));
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'v':
|
|
|
|
|
switch (Arg [2]) {
|
2000-08-24 06:41:55 +00:00
|
|
|
|
case 'm': VerboseMap = 1; break;
|
2001-03-10 10:21:03 +00:00
|
|
|
|
case '\0': ++Verbosity; break;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
default: UnknownOption (Arg);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'C':
|
2000-08-23 14:13:24 +00:00
|
|
|
|
OptConfig (Arg, GetArg (&I, 2));
|
2000-05-28 13:40:48 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'L':
|
|
|
|
|
switch (Arg [2]) {
|
2003-08-15 09:19:57 +00:00
|
|
|
|
/* ## The first one is obsolete and will go */
|
2003-05-29 09:35:11 +00:00
|
|
|
|
case 'n': LabelFileName = GetArg (&I, 3); break;
|
|
|
|
|
default: OptLibPath (Arg, GetArg (&I, 2)); break;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'S':
|
2000-08-24 06:41:55 +00:00
|
|
|
|
OptStartAddr (Arg, GetArg (&I, 2));
|
2000-05-28 13:40:48 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case 'V':
|
2000-06-14 09:57:42 +00:00
|
|
|
|
OptVersion (Arg, 0);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
break;
|
|
|
|
|
|
2000-08-23 14:13:24 +00:00
|
|
|
|
default:
|
|
|
|
|
UnknownOption (Arg);
|
|
|
|
|
break;
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
|
|
/* A filename */
|
2003-06-02 13:37:05 +00:00
|
|
|
|
LinkFile (Arg, FILETYPE_UNKNOWN);
|
2000-05-28 13:40:48 +00:00
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Next argument */
|
|
|
|
|
++I;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check if we had any object files */
|
|
|
|
|
if (ObjFiles == 0) {
|
2000-08-23 14:13:24 +00:00
|
|
|
|
Error ("No object files to link");
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Check if we have a valid configuration */
|
|
|
|
|
if (!CfgAvail ()) {
|
2000-08-23 14:13:24 +00:00
|
|
|
|
Error ("Memory configuration missing");
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Read the config file */
|
|
|
|
|
CfgRead ();
|
|
|
|
|
|
2000-11-20 15:22:57 +00:00
|
|
|
|
/* Create the condes tables if requested */
|
|
|
|
|
ConDesCreate ();
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* Assign start addresses for the segments, define linker symbols */
|
|
|
|
|
CfgAssignSegments ();
|
|
|
|
|
|
2003-06-06 12:45:19 +00:00
|
|
|
|
/* Check module assertions */
|
|
|
|
|
CheckAssertions ();
|
|
|
|
|
|
2000-05-28 13:40:48 +00:00
|
|
|
|
/* Create the output file */
|
|
|
|
|
CfgWriteTarget ();
|
|
|
|
|
|
|
|
|
|
/* Check for segments not written to the output file */
|
|
|
|
|
CheckSegments ();
|
|
|
|
|
|
|
|
|
|
/* If requested, create a map file and a label file for VICE */
|
|
|
|
|
if (MapFileName) {
|
|
|
|
|
CreateMapFile ();
|
|
|
|
|
}
|
|
|
|
|
if (LabelFileName) {
|
|
|
|
|
CreateLabelFile ();
|
2001-09-15 13:36:59 +00:00
|
|
|
|
}
|
2001-05-29 07:39:46 +00:00
|
|
|
|
if (DbgFileName) {
|
|
|
|
|
CreateDbgFile ();
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Dump the data for debugging */
|
2001-03-10 10:21:03 +00:00
|
|
|
|
if (Verbosity > 1) {
|
2000-05-28 13:40:48 +00:00
|
|
|
|
SegDump ();
|
2000-11-20 15:22:57 +00:00
|
|
|
|
ConDesDump ();
|
2000-05-28 13:40:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Return an apropriate exit code */
|
|
|
|
|
return EXIT_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-06-14 09:57:42 +00:00
|
|
|
|
|