summaryrefslogtreecommitdiff
path: root/src/cmd/dist/buildruntime.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/cmd/dist/buildruntime.c')
-rw-r--r--src/cmd/dist/buildruntime.c115
1 files changed, 101 insertions, 14 deletions
diff --git a/src/cmd/dist/buildruntime.c b/src/cmd/dist/buildruntime.c
index ee867566f..e6e309d92 100644
--- a/src/cmd/dist/buildruntime.c
+++ b/src/cmd/dist/buildruntime.c
@@ -38,6 +38,34 @@ mkzversion(char *dir, char *file)
bfree(&out);
}
+// mkzexperiment writes zaexperiment.h (sic):
+//
+// #define GOEXPERIMENT "experiment string"
+//
+void
+mkzexperiment(char *dir, char *file)
+{
+ Buf b, out, exp;
+
+ USED(dir);
+
+ binit(&b);
+ binit(&out);
+ binit(&exp);
+
+ xgetenv(&exp, "GOEXPERIMENT");
+ bwritestr(&out, bprintf(&b,
+ "// auto generated by go tool dist\n"
+ "\n"
+ "#define GOEXPERIMENT \"%s\"\n", bstr(&exp)));
+
+ writefile(&out, file, 0);
+
+ bfree(&b);
+ bfree(&out);
+ bfree(&exp);
+}
+
// mkzgoarch writes zgoarch_$GOARCH.go:
//
// package runtime
@@ -162,24 +190,27 @@ static struct {
"#define m(r) 8(GS)\n"
"#define procid(r) 16(GS)\n"
},
- {"amd64", "",
- "// The offsets 0 and 8 are known to:\n"
- "// ../../cmd/6l/pass.c:/D_GS\n"
- "// cgo/gcc_linux_amd64.c:/^threadentry\n"
- "// cgo/gcc_darwin_amd64.c:/^threadentry\n"
- "//\n"
- "#define get_tls(r)\n"
- "#define g(r) 0(GS)\n"
- "#define m(r) 8(GS)\n"
+ // The TLS accessors here are defined here to use initial exec model.
+ // If the linker is not outputting a shared library, it will reduce
+ // the TLS accessors to the local exec model, effectively removing
+ // get_tls().
+ {"amd64", "linux",
+ "#define get_tls(r) MOVQ runtime·tlsgm(SB), r\n"
+ "#define g(r) 0(r)(GS*1)\n"
+ "#define m(r) 8(r)(GS*1)\n"
},
-
+ {"amd64", "",
+ "#define get_tls(r)\n"
+ "#define g(r) 0(GS)\n"
+ "#define m(r) 8(GS)\n"
+ },
{"arm", "",
- "#define g R10\n"
- "#define m R9\n"
"#define LR R14\n"
},
};
+#define MAXWINCB 2000 /* maximum number of windows callbacks allowed */
+
// mkzasm writes zasm_$GOOS_$GOARCH.h,
// which contains struct offsets for use by
// assembly files. It also writes a copy to the work space
@@ -190,12 +221,13 @@ mkzasm(char *dir, char *file)
{
int i, n;
char *aggr, *p;
- Buf in, b, out;
+ Buf in, b, out, exp;
Vec argv, lines, fields;
binit(&in);
binit(&b);
binit(&out);
+ binit(&exp);
vinit(&argv);
vinit(&lines);
vinit(&fields);
@@ -234,10 +266,11 @@ ok:
// Gobuf 24 sched;
// 'Y' 48 stack0;
// }
+ // StackMin = 128;
// into output like
// #define g_sched 24
// #define g_stack0 48
- //
+ // #define const_StackMin 128
aggr = nil;
splitlines(&lines, bstr(&in));
for(i=0; i<lines.len; i++) {
@@ -247,10 +280,14 @@ ok:
aggr = "g";
else if(streq(fields.p[1], "M"))
aggr = "m";
+ else if(streq(fields.p[1], "P"))
+ aggr = "p";
else if(streq(fields.p[1], "Gobuf"))
aggr = "gobuf";
else if(streq(fields.p[1], "WinCall"))
aggr = "wincall";
+ else if(streq(fields.p[1], "WinCallbackContext"))
+ aggr = "cbctxt";
else if(streq(fields.p[1], "SEH"))
aggr = "seh";
}
@@ -263,8 +300,22 @@ ok:
p[xstrlen(p)-1] = '\0';
bwritestr(&out, bprintf(&b, "#define %s_%s %s\n", aggr, fields.p[n-1], fields.p[n-2]));
}
+ if(fields.len == 3 && streq(fields.p[1], "=")) { // generated from enumerated constants
+ p = fields.p[2];
+ if(p[xstrlen(p)-1] == ';')
+ p[xstrlen(p)-1] = '\0';
+ bwritestr(&out, bprintf(&b, "#define const_%s %s\n", fields.p[0], p));
+ }
+ }
+
+ // Some #defines that are used for .c files.
+ if(streq(goos, "windows")) {
+ bwritestr(&out, bprintf(&b, "#define cb_max %d\n", MAXWINCB));
}
+ xgetenv(&exp, "GOEXPERIMENT");
+ bwritestr(&out, bprintf(&b, "#define GOEXPERIMENT \"%s\"\n", bstr(&exp)));
+
// Write both to file and to workdir/zasm_GOOS_GOARCH.h.
writefile(&out, file, 0);
writefile(&out, bprintf(&b, "%s/zasm_GOOS_GOARCH.h", workdir), 0);
@@ -272,11 +323,47 @@ ok:
bfree(&in);
bfree(&b);
bfree(&out);
+ bfree(&exp);
vfree(&argv);
vfree(&lines);
vfree(&fields);
}
+// mkzsys writes zsys_$GOOS_$GOARCH.h,
+// which contains arch or os specific asm code.
+//
+void
+mkzsys(char *dir, char *file)
+{
+ int i;
+ Buf out;
+
+ USED(dir);
+
+ binit(&out);
+
+ bwritestr(&out, "// auto generated by go tool dist\n\n");
+ if(streq(goos, "windows")) {
+ bwritef(&out,
+ "// runtime·callbackasm is called by external code to\n"
+ "// execute Go implemented callback function. It is not\n"
+ "// called from the start, instead runtime·compilecallback\n"
+ "// always returns address into runtime·callbackasm offset\n"
+ "// appropriately so different callbacks start with different\n"
+ "// CALL instruction in runtime·callbackasm. This determines\n"
+ "// which Go callback function is executed later on.\n"
+ "TEXT runtime·callbackasm(SB),7,$0\n");
+ for(i=0; i<MAXWINCB; i++) {
+ bwritef(&out, "\tCALL\truntime·callbackasm1(SB)\n");
+ }
+ bwritef(&out, "\tRET\n");
+ }
+
+ writefile(&out, file, 0);
+
+ bfree(&out);
+}
+
static char *runtimedefs[] = {
"proc.c",
"iface.c",