100
105
"#define m(r) 4(r)\n"
108
"// Plan 9 does not have per-process segment descriptors with\n"
109
"// which to do thread-local storage. Instead, we will use a\n"
110
"// fixed offset from the per-process TOS struct address for\n"
111
"// the local storage. Since the process ID is contained in the\n"
112
"// TOS struct, we specify an offset for that here as well.\n"
103
113
"#define get_tls(r) MOVL _tos(SB), r \n"
104
114
"#define g(r) -8(r)\n"
105
115
"#define m(r) -4(r)\n"
116
"#define procid(r) 48(r)\n"
108
119
"// On Linux systems, what we call 0(GS) and 4(GS) for g and m\n"
122
133
"// which is where these macros come into play.\n"
123
134
"// get_tls sets up the temporary and then g and r use it.\n"
125
"// The final wrinkle is that get_tls needs to read from %gs:0,\n"
136
"// Another wrinkle is that get_tls needs to read from %gs:0,\n"
126
137
"// but in 8l input it's called 8(GS), because 8l is going to\n"
127
138
"// subtract 8 from all the offsets, as described above.\n"
140
"// The final wrinkle is that when generating an ELF .o file for\n"
141
"// external linking mode, we need to be able to relocate the\n"
142
"// -8(r) and -4(r) instructions. Tag them with an extra (GS*1)\n"
143
"// that is ignored by the linker except for that identification.\n"
128
144
"#define get_tls(r) MOVL 8(GS), r\n"
129
"#define g(r) -8(r)\n"
130
"#define m(r) -4(r)\n"
145
"#define g(r) -8(r)(GS*1)\n"
146
"#define m(r) -4(r)(GS*1)\n"
133
149
"#define get_tls(r)\n"
188
210
fatal("unknown $GOOS/$GOARCH in mkzasm");
191
// Run 6c -DGOOS_goos -DGOARCH_goarch -Iworkdir -a proc.c
213
// Run 6c -D GOOS_goos -D GOARCH_goarch -I workdir -a -n -o workdir/proc.acid proc.c
192
214
// to get acid [sic] output.
194
216
vadd(&argv, bpathf(&b, "%s/%sc", tooldir, gochar));
195
vadd(&argv, bprintf(&b, "-DGOOS_%s", goos));
196
vadd(&argv, bprintf(&b, "-DGOARCH_%s", goarch));
197
vadd(&argv, bprintf(&b, "-I%s", workdir));
218
vadd(&argv, bprintf(&b, "GOOS_%s", goos));
220
vadd(&argv, bprintf(&b, "GOARCH_%s", goarch));
222
vadd(&argv, bprintf(&b, "%s", workdir));
198
223
vadd(&argv, "-a");
226
vadd(&argv, bpathf(&b, "%s/proc.acid", workdir));
199
227
vadd(&argv, "proc.c");
200
runv(&in, dir, CheckExit, &argv);
228
runv(nil, dir, CheckExit, &argv);
229
readfile(&in, bpathf(&b, "%s/proc.acid", workdir));
202
231
// Convert input like
223
252
else if(streq(fields.p[1], "WinCall"))
224
253
aggr = "wincall";
254
else if(streq(fields.p[1], "SEH"))
226
257
if(hasprefix(lines.p[i], "}"))
288
// Run 6c -DGOOS_goos -DGOARCH_goarch -Iworkdir -q
321
// Run 6c -D GOOS_goos -D GOARCH_goarch -I workdir -q -n -o workdir/runtimedefs
289
322
// on each of the runtimedefs C files.
290
323
vadd(&argv, bpathf(&b, "%s/%sc", tooldir, gochar));
291
vadd(&argv, bprintf(&b, "-DGOOS_%s", goos));
292
vadd(&argv, bprintf(&b, "-DGOARCH_%s", goarch));
293
vadd(&argv, bprintf(&b, "-I%s", workdir));
325
vadd(&argv, bprintf(&b, "GOOS_%s", goos));
327
vadd(&argv, bprintf(&b, "GOARCH_%s", goarch));
329
vadd(&argv, bprintf(&b, "%s", workdir));
294
330
vadd(&argv, "-q");
333
vadd(&argv, bpathf(&b, "%s/runtimedefs", workdir));
296
335
p = argv.p[argv.len-1];
297
336
for(i=0; i<nelem(runtimedefs); i++) {
298
337
argv.p[argv.len-1] = runtimedefs[i];
299
runv(&b, dir, CheckExit, &argv);
338
runv(nil, dir, CheckExit, &argv);
339
readfile(&b, bpathf(&b1, "%s/runtimedefs", workdir));
300
340
bwriteb(&in, &b);
302
342
argv.p[argv.len-1] = p;