]> Cypherpunks repositories - gostls13.git/commitdiff
move amd64-specific (but os-independent) pieces of runtime
authorRuss Cox <rsc@golang.org>
Tue, 24 Mar 2009 18:49:22 +0000 (11:49 -0700)
committerRuss Cox <rsc@golang.org>
Tue, 24 Mar 2009 18:49:22 +0000 (11:49 -0700)
into amd64/ directory.

split rt2_amd64.c into closure.c and traceback.c.

TBR=r
OCL=26678
CL=26678

src/runtime/Makefile
src/runtime/amd64/asm.s [moved from src/runtime/rt0_amd64.s with 100% similarity]
src/runtime/amd64/closure.c [new file with mode: 0644]
src/runtime/amd64/traceback.c [moved from src/runtime/rt2_amd64.c with 60% similarity]

index 468a5eb325bc0a39eed8860d7492283100ed4884..9b852d46eff6072c109a36074b117dd8c0c28271 100644 (file)
@@ -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/amd64/closure.c b/src/runtime/amd64/closure.c
new file mode 100644 (file)
index 0000000..5717d3c
--- /dev/null
@@ -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");
+}
+
+
similarity index 60%
rename from src/runtime/rt2_amd64.c
rename to src/runtime/amd64/traceback.c
index 84ae0b1ba81a70e4bfd9bbf5971412259f544b1d..bc2724b765af8b245437e78e8306635c592be93a 100644 (file)
@@ -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");
-}
-