diff options
author | Russ Cox <rsc@golang.org> | 2009-03-24 11:49:22 -0700 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2009-03-24 11:49:22 -0700 |
commit | 87efb27f42c7230b89097f296935058492f40b52 (patch) | |
tree | 80d7ab5845634b7f1a43a4f98857b77d5589e413 | |
parent | 362494a9f69b24358c6a50e962648929ac3118fd (diff) | |
download | golang-87efb27f42c7230b89097f296935058492f40b52.tar.gz |
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
-rw-r--r-- | src/runtime/Makefile | 20 | ||||
-rw-r--r-- | src/runtime/amd64/asm.s (renamed from src/runtime/rt0_amd64.s) | 0 | ||||
-rw-r--r-- | src/runtime/amd64/closure.c | 121 | ||||
-rw-r--r-- | src/runtime/amd64/traceback.c (renamed from src/runtime/rt2_amd64.c) | 118 |
4 files changed, 133 insertions, 126 deletions
diff --git a/src/runtime/Makefile b/src/runtime/Makefile index 468a5eb32..9b852d46e 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 index f8d4a381b..f8d4a381b 100644 --- a/src/runtime/rt0_amd64.s +++ b/src/runtime/amd64/asm.s diff --git a/src/runtime/amd64/closure.c b/src/runtime/amd64/closure.c new file mode 100644 index 000000000..5717d3c5e --- /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<siz; i+=8) { + // MOVSQ + *p++ = 0x48; + *p++ = 0xa5; + } + } else { + // MOVQ $(siz/8), CX [32-bit immediate siz/8] + *p++ = 0x48; + *p++ = 0xc7; + *p++ = 0xc1; + *(uint32*)p = siz/8; + p += 4; + + // REP; MOVSQ + *p++ = 0xf3; + *p++ = 0x48; + *p++ = 0xa5; + } + + + // call fn + pcrel = fn - (p+5); + if((int32)pcrel == pcrel) { + // can use direct call with pc-relative offset + // CALL fn + *p++ = 0xe8; + *(int32*)p = pcrel; + p += 4; + } else { + // MOVQ $fn, CX [64-bit immediate fn] + *p++ = 0x48; + *p++ = 0xb9; + *(byte**)p = fn; + p += 8; + + // CALL *CX + *p++ = 0xff; + *p++ = 0xd1; + } + + // ADDQ $siz, SP + *p++ = 0x48; + *p++ = 0x81; + *p++ = 0xc4; + *(uint32*)p = siz; + p += 4; + + // RET + *p++ = 0xc3; + + if(p > q) + throw("bad math in sys.closure"); +} + + diff --git a/src/runtime/rt2_amd64.c b/src/runtime/amd64/traceback.c index 84ae0b1ba..bc2724b76 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<siz; i+=8) { - // MOVSQ - *p++ = 0x48; - *p++ = 0xa5; - } - } else { - // MOVQ $(siz/8), CX [32-bit immediate siz/8] - *p++ = 0x48; - *p++ = 0xc7; - *p++ = 0xc1; - *(uint32*)p = siz/8; - p += 4; - - // REP; MOVSQ - *p++ = 0xf3; - *p++ = 0x48; - *p++ = 0xa5; - } - - - // call fn - pcrel = fn - (p+5); - if((int32)pcrel == pcrel) { - // can use direct call with pc-relative offset - // CALL fn - *p++ = 0xe8; - *(int32*)p = pcrel; - p += 4; - } else { - // MOVQ $fn, CX [64-bit immediate fn] - *p++ = 0x48; - *p++ = 0xb9; - *(byte**)p = fn; - p += 8; - - // CALL *CX - *p++ = 0xff; - *p++ = 0xd1; - } - - // ADDQ $siz, SP - *p++ = 0x48; - *p++ = 0x81; - *p++ = 0xc4; - *(uint32*)p = siz; - p += 4; - - // RET - *p++ = 0xc3; - - if(p > q) - throw("bad math in sys.closure"); -} - |