-
Notifications
You must be signed in to change notification settings - Fork 0
/
ld.java
178 lines (151 loc) · 5.07 KB
/
ld.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* Main.java
*
* Created on December 21, 2005, 4:06 PM
*
* OMF linker
*/
import java.util.*;
//import omf.*;
import java.io.*;
/**
*
* @author Kelvin W Sherlock
*/
public class ld {
/** Creates a new instance of Main */
public ld() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
int flags = Linker.FLAG_EXPRESS;
int org = 0;
boolean trace = false;
String outf = "a.out";
ArrayList<String> libs = new ArrayList<String>();
ArrayList<String> libDirs = new ArrayList<String>();
GetOpt go = new GetOpt(args, "hMrtvVxB:l:L:o:T:");
int c;
while ((c = go.Next()) != -1)
{
switch(c)
{
case 'B':
{
String s = go.Argument();
if (s.compareToIgnoreCase("rtl") == 0)
flags |= Linker.FLAG_RTL;
else if (s.compareToIgnoreCase("bin") == 0)
flags |= Linker.FLAG_BIN;
}
break;
case 'l':
libs.add(go.Argument());
break;
case 'L':
libDirs.add(go.Argument());
break;
case 'M':
flags |= Linker.FLAG_MAP;
break;
case 'o':
outf = go.Argument();
break;
case 'r':
flags |= Linker.FLAG_RELOAD;
break;
case 't':
trace = true;
break;
case 'T':
org = ParseNumber(go.Argument());
break;
case 'v':
flags |= Linker.FLAG_VERBOSE;
break;
case 'x':
flags &= (~Linker.FLAG_EXPRESS);
break;
case 'h':
case '?':
usage();
break;
}
}
args = go.CommandLine();
go = null;
if (args.length == 0)
{
System.out.println("No input files.");
return;
}
Linker linker = new Linker(flags, org);
for (int i = 0; i < args.length; i++)
{
File f = new File(args[i]);
if (trace) System.out.println(f.getPath());
linker.ProcessFile(f);
}
// now add in any libraries...
// consider having a default of ./ perhaps.
for (Iterator<String> libIter = libs.iterator(); libIter.hasNext(); )
{
String lib = libIter.next();
boolean found = false;
for (Iterator<String> dirIter = libDirs.iterator(); dirIter.hasNext();)
{
String dir = dirIter.next();
File f = new File(dir, lib);
if (!f.exists()) continue;
if (trace) System.out.println(f.getPath());
linker.ProcessLibrary(f);
found = true;
break;
}
if (!found)
{
System.out.println("Library " + lib + " not found.");
}
}
linker.Save(new File(outf));
// now save
}
private static int ParseNumber(String str)
{
int c;
if (str == null) return 0;
c = str.charAt(0);
if (c == '$')
{
return Integer.parseInt(str.substring(1), 16);
}
if (c == '0' && str.charAt(1) == 'x')
{
return Integer.parseInt(str.substring(2), 16);
}
return Integer.parseInt(str);
}
private static void usage()
{
System.out.println("linkiigs v 0.1");
System.out.println("usage: linkiigs [options] files");
System.out.println("options:");
System.out.println("\t-B bin create binary file");
System.out.println("\t-B rtl create run time library file");
System.out.println("\t-B omf create omf file (default)");
System.out.println("\t-h show help");
System.out.println("\t-l lib library file to use");
System.out.println("\t-L libpath library path to use");
System.out.println("\t-M print link map");
System.out.println("\t-o file save output to file");
//System.out.println("\t-p pathname Pathname Table Segment path");
System.out.println("\t-r set reload bit in ~globals and ~arrays");
System.out.println("\t-v be verbose");
System.out.println("\t-V show version information");
System.out.println("\t-T xxxx absolute load segment address");
System.out.println("\t-t print the names of files as processed");
System.out.println("\t-x do NOT create ExpressLoad file");
}
}