From fcd76f7dc9482d7c1e89731e07712f05b2dc4cfa Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 24 Mar 2009 11:49:22 -0700 Subject: [PATCH] move amd64-specific (but os-independent) pieces of runtime into amd64/ directory. split rt2_amd64.c into closure.c and traceback.c. TBR=r OCL=26678 CL=26678 --- src/runtime/Makefile | 20 +-- src/runtime/{rt0_amd64.s => amd64/asm.s} | 0 src/runtime/amd64/closure.c | 121 ++++++++++++++++++ .../{rt2_amd64.c => amd64/traceback.c} | 118 ----------------- 4 files changed, 133 insertions(+), 126 deletions(-) rename src/runtime/{rt0_amd64.s => amd64/asm.s} (100%) create mode 100644 src/runtime/amd64/closure.c rename src/runtime/{rt2_amd64.c => amd64/traceback.c} (60%) diff --git a/src/runtime/Makefile b/src/runtime/Makefile index 468a5eb325..9b852d46ef 100644 --- a/src/runtime/Makefile +++ b/src/runtime/Makefile @@ -13,12 +13,12 @@ RT0OFILES=\ rt0_$(GOARCH)_$(GOOS).$O\ LIBOFILES=\ - rt0_$(GOARCH).$O\ rt1_$(GOARCH)_$(GOOS).$O\ - rt2_$(GOARCH).$O\ sys_$(GOARCH)_$(GOOS).$O\ array.$O\ + asm.$O\ chan.$O\ + closure.$O\ float.$O\ float_go.$O\ hashmap.$O\ @@ -40,6 +40,7 @@ LIBOFILES=\ sema_go.$O\ string.$O\ symtab.$O\ + traceback.$O\ OFILES=$(RT0OFILES) $(LIBOFILES) OS_H=$(GOARCH)_$(GOOS).h @@ -64,10 +65,16 @@ clean: rm -f *.$(O) *.a runtime.acid cgo2c %.$O: %.c - $(CC) -wF $< + $(CC) $(CFLAGS) -wF $< -sys_file.$O: sys_file.c sys_types.h $(OS_H) - $(CC) -wF -D$(GOARCH)_$(GOOS) $< +%.$O: $(GOARCH)/%.c + $(CC) $(CFLAGS) -wF $< + +%.$O: %.s + $(AS) $< + +%.$O: $(GOARCH)/%.s + $(AS) $< cgo2c: cgo2c.c quietgcc -o $@ $< @@ -76,9 +83,6 @@ cgo2c: cgo2c.c ./cgo2c $< > $@.tmp mv -f $@.tmp $@ -%.$O: %.s - $(AS) $< - runtime.acid: runtime.h proc.c $(CC) -a proc.c >runtime.acid diff --git a/src/runtime/rt0_amd64.s b/src/runtime/amd64/asm.s similarity index 100% rename from src/runtime/rt0_amd64.s rename to src/runtime/amd64/asm.s diff --git a/src/runtime/amd64/closure.c b/src/runtime/amd64/closure.c new file mode 100644 index 0000000000..5717d3c5e8 --- /dev/null +++ b/src/runtime/amd64/closure.c @@ -0,0 +1,121 @@ +// Copyright 2009 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +#include "runtime.h" + +#pragma textflag 7 +// func closure(siz int32, +// fn func(arg0, arg1, arg2 *ptr, callerpc uintptr, xxx) yyy, +// arg0, arg1, arg2 *ptr) (func(xxx) yyy) +void +sys·closure(int32 siz, byte *fn, byte *arg0) +{ + byte *p, *q, **ret; + int32 i, n; + int64 pcrel; + + if(siz < 0 || siz%8 != 0) + throw("bad closure size"); + + ret = (byte**)((byte*)&arg0 + siz); + + if(siz > 100) { + // TODO(rsc): implement stack growth preamble? + throw("closure too big"); + } + + // compute size of new fn. + // must match code laid out below. + n = 7+10+3; // SUBQ MOVQ MOVQ + if(siz <= 4*8) + n += 2*siz/8; // MOVSQ MOVSQ... + else + n += 7+3; // MOVQ REP MOVSQ + n += 12; // CALL worst case; sometimes only 5 + n += 7+1; // ADDQ RET + + // store args aligned after code, so gc can find them. + n += siz; + if(n%8) + n += 8 - n%8; + + p = mal(n); + *ret = p; + q = p + n - siz; + mcpy(q, (byte*)&arg0, siz); + + // SUBQ $siz, SP + *p++ = 0x48; + *p++ = 0x81; + *p++ = 0xec; + *(uint32*)p = siz; + p += 4; + + // MOVQ $q, SI + *p++ = 0x48; + *p++ = 0xbe; + *(byte**)p = q; + p += 8; + + // MOVQ SP, DI + *p++ = 0x48; + *p++ = 0x89; + *p++ = 0xe7; + + if(siz <= 4*8) { + for(i=0; i q) + throw("bad math in sys.closure"); +} + + diff --git a/src/runtime/rt2_amd64.c b/src/runtime/amd64/traceback.c similarity index 60% rename from src/runtime/rt2_amd64.c rename to src/runtime/amd64/traceback.c index 84ae0b1ba8..bc2724b765 100644 --- a/src/runtime/rt2_amd64.c +++ b/src/runtime/amd64/traceback.c @@ -4,10 +4,6 @@ #include "runtime.h" -extern int32 debug; - -extern uint8 end; - void traceback(byte *pc0, byte *sp, G *g) { @@ -147,118 +143,4 @@ sys·Caller(int32 n, uint64 retpc, string retfile, int32 retline, bool retbool) FLUSH(&retbool); } -#pragma textflag 7 -// func closure(siz int32, -// fn func(arg0, arg1, arg2 *ptr, callerpc uintptr, xxx) yyy, -// arg0, arg1, arg2 *ptr) (func(xxx) yyy) -void -sys·closure(int32 siz, byte *fn, byte *arg0) -{ - byte *p, *q, **ret; - int32 i, n; - int64 pcrel; - - if(siz < 0 || siz%8 != 0) - throw("bad closure size"); - - ret = (byte**)((byte*)&arg0 + siz); - - if(siz > 100) { - // TODO(rsc): implement stack growth preamble? - throw("closure too big"); - } - - // compute size of new fn. - // must match code laid out below. - n = 7+10+3; // SUBQ MOVQ MOVQ - if(siz <= 4*8) - n += 2*siz/8; // MOVSQ MOVSQ... - else - n += 7+3; // MOVQ REP MOVSQ - n += 12; // CALL worst case; sometimes only 5 - n += 7+1; // ADDQ RET - - // store args aligned after code, so gc can find them. - n += siz; - if(n%8) - n += 8 - n%8; - - p = mal(n); - *ret = p; - q = p + n - siz; - mcpy(q, (byte*)&arg0, siz); - - // SUBQ $siz, SP - *p++ = 0x48; - *p++ = 0x81; - *p++ = 0xec; - *(uint32*)p = siz; - p += 4; - - // MOVQ $q, SI - *p++ = 0x48; - *p++ = 0xbe; - *(byte**)p = q; - p += 8; - - // MOVQ SP, DI - *p++ = 0x48; - *p++ = 0x89; - *p++ = 0xe7; - - if(siz <= 4*8) { - for(i=0; i q) - throw("bad math in sys.closure"); -} - -- 2.48.1