Commit fcd76f7d authored by Russ Cox's avatar Russ Cox

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
parent 13584f4a
......@@ -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
// 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");
}
......@@ -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");
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment