Commit 68b4255a authored by Russ Cox's avatar Russ Cox

runtime: ,s/[a-zA-Z0-9_]+/runtime·&/g, almost

Prefix all external symbols in runtime by runtime·,
to avoid conflicts with possible symbols of the same
name in linked-in C libraries.  The obvious conflicts
are printf, malloc, and free, but hide everything to
avoid future pain.

The symbols left alone are:

	** known to cgo **
	_cgo_free
	_cgo_malloc
	libcgo_thread_start
	initcgo
	ncgocall

	** known to linker **
	_rt0_$GOARCH
	_rt0_$GOARCH_$GOOS
	text
	etext
	data
	end
	pclntab
	epclntab
	symtab
	esymtab

	** known to C compiler **
	_divv
	_modv
	_div64by32
	etc (arch specific)

Tested on darwin/386, darwin/amd64, linux/386, linux/amd64.

Built (but not tested) for freebsd/386, freebsd/amd64, linux/arm, windows/386.

R=r, PeterGo
CC=golang-dev
https://golang.org/cl/2899041
parent 3b6ddd9b
...@@ -174,7 +174,7 @@ func (p *Package) writeDefsFunc(fc, fgo2 *os.File, n *Name, soprefix, sopath str ...@@ -174,7 +174,7 @@ func (p *Package) writeDefsFunc(fc, fgo2 *os.File, n *Name, soprefix, sopath str
fmt.Fprintf(fc, "void\n") fmt.Fprintf(fc, "void\n")
fmt.Fprintf(fc, "·%s(struct{uint8 x[%d];}p)\n", n.Mangle, argSize) fmt.Fprintf(fc, "·%s(struct{uint8 x[%d];}p)\n", n.Mangle, argSize)
fmt.Fprintf(fc, "{\n") fmt.Fprintf(fc, "{\n")
fmt.Fprintf(fc, "\tcgocall(_cgo%s, &p);\n", n.Mangle) fmt.Fprintf(fc, "\truntime·cgocall(_cgo%s, &p);\n", n.Mangle)
if n.AddError { if n.AddError {
// gcc leaves errno in first word of interface at end of p. // gcc leaves errno in first word of interface at end of p.
// check whether it is zero; if so, turn interface into nil. // check whether it is zero; if so, turn interface into nil.
...@@ -416,7 +416,7 @@ func (p *Package) writeExports(fgo2, fc *os.File) { ...@@ -416,7 +416,7 @@ func (p *Package) writeExports(fgo2, fc *os.File) {
fmt.Fprintf(fc, "\nvoid\n") fmt.Fprintf(fc, "\nvoid\n")
fmt.Fprintf(fc, "_cgoexp_%s(void *a, int32 n)\n", exp.ExpName) fmt.Fprintf(fc, "_cgoexp_%s(void *a, int32 n)\n", exp.ExpName)
fmt.Fprintf(fc, "{\n") fmt.Fprintf(fc, "{\n")
fmt.Fprintf(fc, "\tcgocallback(·%s, a, n);\n", goname) fmt.Fprintf(fc, "\truntime·cgocallback(·%s, a, n);\n", goname)
fmt.Fprintf(fc, "}\n") fmt.Fprintf(fc, "}\n")
// Calling a function with a receiver from C requires // Calling a function with a receiver from C requires
...@@ -603,22 +603,22 @@ void ·_Cerrno(void*, int32); ...@@ -603,22 +603,22 @@ void ·_Cerrno(void*, int32);
void void
·_Cfunc_GoString(int8 *p, String s) ·_Cfunc_GoString(int8 *p, String s)
{ {
s = gostring((byte*)p); s = runtime·gostring((byte*)p);
FLUSH(&s); FLUSH(&s);
} }
void void
·_Cfunc_GoStringN(int8 *p, int32 l, String s) ·_Cfunc_GoStringN(int8 *p, int32 l, String s)
{ {
s = gostringn((byte*)p, l); s = runtime·gostringn((byte*)p, l);
FLUSH(&s); FLUSH(&s);
} }
void void
·_Cfunc_CString(String s, int8 *p) ·_Cfunc_CString(String s, int8 *p)
{ {
p = cmalloc(s.len+1); p = runtime·cmalloc(s.len+1);
mcpy((byte*)p, s.str, s.len); runtime·mcpy((byte*)p, s.str, s.len);
p[s.len] = 0; p[s.len] = 0;
FLUSH(&p); FLUSH(&p);
} }
......
char *runtimeimport = char *runtimeimport =
"package runtime\n" "package runtime\n"
"func \"\".mal (? int32) *any\n" "func \"\".new (? int32) *any\n"
"func \"\".panicindex ()\n" "func \"\".panicindex ()\n"
"func \"\".panicslice ()\n" "func \"\".panicslice ()\n"
"func \"\".throwreturn ()\n" "func \"\".throwreturn ()\n"
...@@ -19,7 +19,7 @@ char *runtimeimport = ...@@ -19,7 +19,7 @@ char *runtimeimport =
"func \"\".printslice (? any)\n" "func \"\".printslice (? any)\n"
"func \"\".printnl ()\n" "func \"\".printnl ()\n"
"func \"\".printsp ()\n" "func \"\".printsp ()\n"
"func \"\".printf ()\n" "func \"\".goprintf ()\n"
"func \"\".concatstring ()\n" "func \"\".concatstring ()\n"
"func \"\".append ()\n" "func \"\".append ()\n"
"func \"\".appendslice (typ *uint8, x any, y []any) any\n" "func \"\".appendslice (typ *uint8, x any, y []any) any\n"
......
...@@ -10,7 +10,7 @@ package PACKAGE ...@@ -10,7 +10,7 @@ package PACKAGE
// emitted by compiler, not referred to by go programs // emitted by compiler, not referred to by go programs
func mal(int32) *any func new(int32) *any
func panicindex() func panicindex()
func panicslice() func panicslice()
func throwreturn() func throwreturn()
...@@ -31,7 +31,7 @@ func printeface(any) ...@@ -31,7 +31,7 @@ func printeface(any)
func printslice(any) func printslice(any)
func printnl() func printnl()
func printsp() func printsp()
func printf() func goprintf()
// filled in by compiler: int n, string, string, ... // filled in by compiler: int n, string, string, ...
func concatstring() func concatstring()
......
...@@ -1862,7 +1862,7 @@ walkprint(Node *nn, NodeList **init, int defer) ...@@ -1862,7 +1862,7 @@ walkprint(Node *nn, NodeList **init, int defer)
if(defer) { if(defer) {
if(op == OPRINTN) if(op == OPRINTN)
fmtprint(&fmt, "\n"); fmtprint(&fmt, "\n");
on = syslook("printf", 1); on = syslook("goprintf", 1);
on->type = functype(nil, intypes, nil); on->type = functype(nil, intypes, nil);
args->n = nod(OLITERAL, N, N); args->n = nod(OLITERAL, N, N);
args->n->val.ctype = CTSTR; args->n->val.ctype = CTSTR;
...@@ -1891,7 +1891,7 @@ callnew(Type *t) ...@@ -1891,7 +1891,7 @@ callnew(Type *t)
Node *fn; Node *fn;
dowidth(t); dowidth(t);
fn = syslook("mal", 1); fn = syslook("new", 1);
argtype(fn, t); argtype(fn, t);
return mkcall1(fn, ptrto(t), nil, nodintconst(t->width)); return mkcall1(fn, ptrto(t), nil, nodintconst(t->width));
} }
......
...@@ -23,23 +23,23 @@ TEXT _rt0_386(SB),7,$0 ...@@ -23,23 +23,23 @@ TEXT _rt0_386(SB),7,$0
JMP ok JMP ok
// set up %gs // set up %gs
CALL ldt0setup(SB) CALL runtime·ldt0setup(SB)
// store through it, to make sure it works // store through it, to make sure it works
CMPL isplan9(SB), $1 CMPL runtime·isplan9(SB), $1
JEQ ok JEQ ok
get_tls(BX) get_tls(BX)
MOVL $0x123, g(BX) MOVL $0x123, g(BX)
MOVL tls0(SB), AX MOVL runtime·tls0(SB), AX
CMPL AX, $0x123 CMPL AX, $0x123
JEQ ok JEQ ok
MOVL AX, 0 // abort MOVL AX, 0 // abort
ok: ok:
// set up m and g "registers" // set up m and g "registers"
get_tls(BX) get_tls(BX)
LEAL g0(SB), CX LEAL runtime·g0(SB), CX
MOVL CX, g(BX) MOVL CX, g(BX)
LEAL m0(SB), AX LEAL runtime·m0(SB), AX
MOVL AX, m(BX) MOVL AX, m(BX)
// save m->g0 = g0 // save m->g0 = g0
...@@ -49,46 +49,46 @@ ok: ...@@ -49,46 +49,46 @@ ok:
LEAL (-8192+104)(SP), AX // TODO: 104? LEAL (-8192+104)(SP), AX // TODO: 104?
MOVL AX, g_stackguard(CX) MOVL AX, g_stackguard(CX)
MOVL SP, g_stackbase(CX) MOVL SP, g_stackbase(CX)
CALL emptyfunc(SB) // fault if stack check is wrong CALL runtime·emptyfunc(SB) // fault if stack check is wrong
// convention is D is always cleared // convention is D is always cleared
CLD CLD
CALL check(SB) CALL runtime·check(SB)
// saved argc, argv // saved argc, argv
MOVL 120(SP), AX MOVL 120(SP), AX
MOVL AX, 0(SP) MOVL AX, 0(SP)
MOVL 124(SP), AX MOVL 124(SP), AX
MOVL AX, 4(SP) MOVL AX, 4(SP)
CALL args(SB) CALL runtime·args(SB)
CALL osinit(SB) CALL runtime·osinit(SB)
CALL schedinit(SB) CALL runtime·schedinit(SB)
// create a new goroutine to start program // create a new goroutine to start program
PUSHL $mainstart(SB) // entry PUSHL $runtime·mainstart(SB) // entry
PUSHL $0 // arg size PUSHL $0 // arg size
CALL ·newproc(SB) CALL runtime·newproc(SB)
POPL AX POPL AX
POPL AX POPL AX
// start this M // start this M
CALL mstart(SB) CALL runtime·mstart(SB)
INT $3 INT $3
RET RET
TEXT mainstart(SB),7,$0 TEXT runtime·mainstart(SB),7,$0
CALL main·init(SB) CALL main·init(SB)
CALL initdone(SB) CALL runtime·initdone(SB)
CALL main·main(SB) CALL main·main(SB)
PUSHL $0 PUSHL $0
CALL exit(SB) CALL runtime·exit(SB)
POPL AX POPL AX
INT $3 INT $3
RET RET
TEXT breakpoint(SB),7,$0 TEXT runtime·breakpoint(SB),7,$0
INT $3 INT $3
RET RET
...@@ -98,7 +98,7 @@ TEXT breakpoint(SB),7,$0 ...@@ -98,7 +98,7 @@ TEXT breakpoint(SB),7,$0
// uintptr gosave(Gobuf*) // uintptr gosave(Gobuf*)
// save state in Gobuf; setjmp // save state in Gobuf; setjmp
TEXT gosave(SB), 7, $0 TEXT runtime·gosave(SB), 7, $0
MOVL 4(SP), AX // gobuf MOVL 4(SP), AX // gobuf
LEAL 4(SP), BX // caller's SP LEAL 4(SP), BX // caller's SP
MOVL BX, gobuf_sp(AX) MOVL BX, gobuf_sp(AX)
...@@ -112,7 +112,7 @@ TEXT gosave(SB), 7, $0 ...@@ -112,7 +112,7 @@ TEXT gosave(SB), 7, $0
// void gogo(Gobuf*, uintptr) // void gogo(Gobuf*, uintptr)
// restore state from Gobuf; longjmp // restore state from Gobuf; longjmp
TEXT gogo(SB), 7, $0 TEXT runtime·gogo(SB), 7, $0
MOVL 8(SP), AX // return 2nd arg MOVL 8(SP), AX // return 2nd arg
MOVL 4(SP), BX // gobuf MOVL 4(SP), BX // gobuf
MOVL gobuf_g(BX), DX MOVL gobuf_g(BX), DX
...@@ -126,7 +126,7 @@ TEXT gogo(SB), 7, $0 ...@@ -126,7 +126,7 @@ TEXT gogo(SB), 7, $0
// void gogocall(Gobuf*, void (*fn)(void)) // void gogocall(Gobuf*, void (*fn)(void))
// restore state from Gobuf but then call fn. // restore state from Gobuf but then call fn.
// (call fn, returning to state in Gobuf) // (call fn, returning to state in Gobuf)
TEXT gogocall(SB), 7, $0 TEXT runtime·gogocall(SB), 7, $0
MOVL 8(SP), AX // fn MOVL 8(SP), AX // fn
MOVL 4(SP), BX // gobuf MOVL 4(SP), BX // gobuf
MOVL gobuf_g(BX), DX MOVL gobuf_g(BX), DX
...@@ -144,7 +144,7 @@ TEXT gogocall(SB), 7, $0 ...@@ -144,7 +144,7 @@ TEXT gogocall(SB), 7, $0
*/ */
// Called during function prolog when more stack is needed. // Called during function prolog when more stack is needed.
TEXT ·morestack(SB),7,$0 TEXT runtime·morestack(SB),7,$0
// Cannot grow scheduler stack (m->g0). // Cannot grow scheduler stack (m->g0).
get_tls(CX) get_tls(CX)
MOVL m(CX), BX MOVL m(CX), BX
...@@ -178,7 +178,7 @@ TEXT ·morestack(SB),7,$0 ...@@ -178,7 +178,7 @@ TEXT ·morestack(SB),7,$0
MOVL m_g0(BX), BP MOVL m_g0(BX), BP
MOVL BP, g(CX) MOVL BP, g(CX)
MOVL (m_sched+gobuf_sp)(BX), SP MOVL (m_sched+gobuf_sp)(BX), SP
CALL newstack(SB) CALL runtime·newstack(SB)
MOVL $0, 0x1003 // crash if newstack returns MOVL $0, 0x1003 // crash if newstack returns
RET RET
...@@ -220,13 +220,13 @@ TEXT reflect·call(SB), 7, $0 ...@@ -220,13 +220,13 @@ TEXT reflect·call(SB), 7, $0
get_tls(CX) get_tls(CX)
MOVL BP, g(CX) MOVL BP, g(CX)
MOVL (m_sched+gobuf_sp)(BX), SP MOVL (m_sched+gobuf_sp)(BX), SP
CALL newstack(SB) CALL runtime·newstack(SB)
MOVL $0, 0x1103 // crash if newstack returns MOVL $0, 0x1103 // crash if newstack returns
RET RET
// Return point when leaving stack. // Return point when leaving stack.
TEXT ·lessstack(SB), 7, $0 TEXT runtime·lessstack(SB), 7, $0
// Save return value in m->cret // Save return value in m->cret
get_tls(CX) get_tls(CX)
MOVL m(CX), BX MOVL m(CX), BX
...@@ -236,7 +236,7 @@ TEXT ·lessstack(SB), 7, $0 ...@@ -236,7 +236,7 @@ TEXT ·lessstack(SB), 7, $0
MOVL m_g0(BX), DX MOVL m_g0(BX), DX
MOVL DX, g(CX) MOVL DX, g(CX)
MOVL (m_sched+gobuf_sp)(BX), SP MOVL (m_sched+gobuf_sp)(BX), SP
CALL oldstack(SB) CALL runtime·oldstack(SB)
MOVL $0, 0x1004 // crash if oldstack returns MOVL $0, 0x1004 // crash if oldstack returns
RET RET
...@@ -248,7 +248,7 @@ TEXT ·lessstack(SB), 7, $0 ...@@ -248,7 +248,7 @@ TEXT ·lessstack(SB), 7, $0
// return 1; // return 1;
// }else // }else
// return 0; // return 0;
TEXT cas(SB), 7, $0 TEXT runtime·cas(SB), 7, $0
MOVL 4(SP), BX MOVL 4(SP), BX
MOVL 8(SP), AX MOVL 8(SP), AX
MOVL 12(SP), CX MOVL 12(SP), CX
...@@ -267,7 +267,7 @@ TEXT cas(SB), 7, $0 ...@@ -267,7 +267,7 @@ TEXT cas(SB), 7, $0
// return 1; // return 1;
// }else // }else
// return 0; // return 0;
TEXT casp(SB), 7, $0 TEXT runtime·casp(SB), 7, $0
MOVL 4(SP), BX MOVL 4(SP), BX
MOVL 8(SP), AX MOVL 8(SP), AX
MOVL 12(SP), CX MOVL 12(SP), CX
...@@ -284,14 +284,14 @@ TEXT casp(SB), 7, $0 ...@@ -284,14 +284,14 @@ TEXT casp(SB), 7, $0
// 1. pop the caller // 1. pop the caller
// 2. sub 5 bytes from the callers return // 2. sub 5 bytes from the callers return
// 3. jmp to the argument // 3. jmp to the argument
TEXT jmpdefer(SB), 7, $0 TEXT runtime·jmpdefer(SB), 7, $0
MOVL 4(SP), AX // fn MOVL 4(SP), AX // fn
MOVL 8(SP), BX // caller sp MOVL 8(SP), BX // caller sp
LEAL -4(BX), SP // caller sp after CALL LEAL -4(BX), SP // caller sp after CALL
SUBL $5, (SP) // return to CALL again SUBL $5, (SP) // return to CALL again
JMP AX // but first run the deferred function JMP AX // but first run the deferred function
TEXT ·memclr(SB),7,$0 TEXT runtime·memclr(SB),7,$0
MOVL 4(SP), DI // arg 1 addr MOVL 4(SP), DI // arg 1 addr
MOVL 8(SP), CX // arg 2 count MOVL 8(SP), CX // arg 2 count
ADDL $3, CX ADDL $3, CX
...@@ -302,42 +302,42 @@ TEXT ·memclr(SB),7,$0 ...@@ -302,42 +302,42 @@ TEXT ·memclr(SB),7,$0
STOSL STOSL
RET RET
TEXT ·getcallerpc+0(SB),7,$0 TEXT runtime·getcallerpc(SB),7,$0
MOVL x+0(FP),AX // addr of first arg MOVL x+0(FP),AX // addr of first arg
MOVL -4(AX),AX // get calling pc MOVL -4(AX),AX // get calling pc
RET RET
TEXT ·setcallerpc+0(SB),7,$0 TEXT runtime·setcallerpc(SB),7,$0
MOVL x+0(FP),AX // addr of first arg MOVL x+0(FP),AX // addr of first arg
MOVL x+4(FP), BX MOVL x+4(FP), BX
MOVL BX, -4(AX) // set calling pc MOVL BX, -4(AX) // set calling pc
RET RET
TEXT getcallersp(SB), 7, $0 TEXT runtime·getcallersp(SB), 7, $0
MOVL sp+0(FP), AX MOVL sp+0(FP), AX
RET RET
TEXT ldt0setup(SB),7,$16 TEXT runtime·ldt0setup(SB),7,$16
// set up ldt 7 to point at tls0 // set up ldt 7 to point at tls0
// ldt 1 would be fine on Linux, but on OS X, 7 is as low as we can go. // ldt 1 would be fine on Linux, but on OS X, 7 is as low as we can go.
// the entry number is just a hint. setldt will set up GS with what it used. // the entry number is just a hint. setldt will set up GS with what it used.
MOVL $7, 0(SP) MOVL $7, 0(SP)
LEAL tls0(SB), AX LEAL runtime·tls0(SB), AX
MOVL AX, 4(SP) MOVL AX, 4(SP)
MOVL $32, 8(SP) // sizeof(tls array) MOVL $32, 8(SP) // sizeof(tls array)
CALL setldt(SB) CALL runtime·setldt(SB)
RET RET
TEXT emptyfunc(SB),0,$0 TEXT runtime·emptyfunc(SB),0,$0
RET RET
TEXT abort(SB),7,$0 TEXT runtime·abort(SB),7,$0
INT $0x3 INT $0x3
// runcgo(void(*fn)(void*), void *arg) // runcgo(void(*fn)(void*), void *arg)
// Call fn(arg) on the scheduler stack, // Call fn(arg) on the scheduler stack,
// aligned appropriately for the gcc ABI. // aligned appropriately for the gcc ABI.
TEXT runcgo(SB),7,$16 TEXT runtime·runcgo(SB),7,$16
MOVL fn+0(FP), AX MOVL fn+0(FP), AX
MOVL arg+4(FP), BX MOVL arg+4(FP), BX
MOVL SP, CX MOVL SP, CX
...@@ -372,7 +372,7 @@ TEXT runcgo(SB),7,$16 ...@@ -372,7 +372,7 @@ TEXT runcgo(SB),7,$16
// runcgocallback(G *g1, void* sp, void (*fn)(void)) // runcgocallback(G *g1, void* sp, void (*fn)(void))
// Switch to g1 and sp, call fn, switch back. fn's arguments are on // Switch to g1 and sp, call fn, switch back. fn's arguments are on
// the new stack. // the new stack.
TEXT runcgocallback(SB),7,$32 TEXT runtime·runcgocallback(SB),7,$32
MOVL g1+0(FP), DX MOVL g1+0(FP), DX
MOVL sp+4(FP), AX MOVL sp+4(FP), AX
MOVL fn+8(FP), BX MOVL fn+8(FP), BX
...@@ -401,7 +401,7 @@ TEXT runcgocallback(SB),7,$32 ...@@ -401,7 +401,7 @@ TEXT runcgocallback(SB),7,$32
RET RET
// check that SP is in range [g->stackbase, g->stackguard) // check that SP is in range [g->stackbase, g->stackguard)
TEXT stackcheck(SB), 7, $0 TEXT runtime·stackcheck(SB), 7, $0
get_tls(CX) get_tls(CX)
MOVL g(CX), AX MOVL g(CX), AX
CMPL g_stackbase(AX), SP CMPL g_stackbase(AX), SP
...@@ -412,7 +412,4 @@ TEXT stackcheck(SB), 7, $0 ...@@ -412,7 +412,4 @@ TEXT stackcheck(SB), 7, $0
INT $3 INT $3
RET RET
GLOBL m0(SB), $1024 GLOBL runtime·tls0(SB), $32
GLOBL g0(SB), $1024
GLOBL tls0(SB), $32
GLOBL initcgo(SB), $4
...@@ -9,23 +9,23 @@ ...@@ -9,23 +9,23 @@
// fn func(arg0, arg1, arg2 *ptr, callerpc uintptr, xxx) yyy, // fn func(arg0, arg1, arg2 *ptr, callerpc uintptr, xxx) yyy,
// arg0, arg1, arg2 *ptr) (func(xxx) yyy) // arg0, arg1, arg2 *ptr) (func(xxx) yyy)
void void
·closure(int32 siz, byte *fn, byte *arg0) runtime·closure(int32 siz, byte *fn, byte *arg0)
{ {
byte *p, *q, **ret; byte *p, *q, **ret;
int32 i, n; int32 i, n;
int32 pcrel; int32 pcrel;
if(goos != nil && strcmp((uint8*)goos, (uint8*)"nacl") == 0) if(runtime·goos != nil && runtime·strcmp((uint8*)runtime·goos, (uint8*)"nacl") == 0)
throw("no closures in native client yet"); runtime·throw("no closures in native client yet");
if(siz < 0 || siz%4 != 0) if(siz < 0 || siz%4 != 0)
throw("bad closure size"); runtime·throw("bad closure size");
ret = (byte**)((byte*)&arg0 + siz); ret = (byte**)((byte*)&arg0 + siz);
if(siz > 100) { if(siz > 100) {
// TODO(rsc): implement stack growth preamble? // TODO(rsc): implement stack growth preamble?
throw("closure too big"); runtime·throw("closure too big");
} }
// compute size of new fn. // compute size of new fn.
...@@ -43,12 +43,12 @@ void ...@@ -43,12 +43,12 @@ void
if(n%4) if(n%4)
n += 4 - n%4; n += 4 - n%4;
p = mal(n); p = runtime·mal(n);
*ret = p; *ret = p;
q = p + n - siz; q = p + n - siz;
if(siz > 0) { if(siz > 0) {
mcpy(q, (byte*)&arg0, siz); runtime·mcpy(q, (byte*)&arg0, siz);
// SUBL $siz, SP // SUBL $siz, SP
*p++ = 0x81; *p++ = 0x81;
...@@ -104,7 +104,5 @@ void ...@@ -104,7 +104,5 @@ void
*p++ = 0xc3; *p++ = 0xc3;
if(p > q) if(p > q)
throw("bad math in sys.closure"); runtime·throw("bad math in sys.closure");
} }
...@@ -23,8 +23,7 @@ ...@@ -23,8 +23,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
TEXT memmove(SB), 7, $0 TEXT runtime·memmove(SB), 7, $0
MOVL to+0(FP), DI MOVL to+0(FP), DI
MOVL fr+4(FP), SI MOVL fr+4(FP), SI
MOVL n+8(FP), BX MOVL n+8(FP), BX
......
...@@ -27,7 +27,7 @@ ...@@ -27,7 +27,7 @@
* C runtime for 64-bit divide. * C runtime for 64-bit divide.
*/ */
TEXT _mul64by32(SB), 7, $0 TEXT _mul64by32(SB), 7, $0
MOVL r+0(FP), CX MOVL r+0(FP), CX
MOVL a+4(FP), AX MOVL a+4(FP), AX
MULL b+12(FP) MULL b+12(FP)
...@@ -39,7 +39,7 @@ TEXT _mul64by32(SB), 7, $0 ...@@ -39,7 +39,7 @@ TEXT _mul64by32(SB), 7, $0
MOVL BX, 4(CX) MOVL BX, 4(CX)
RET RET
TEXT _div64by32(SB), 7, $0 TEXT _div64by32(SB), 7, $0
MOVL r+12(FP), CX MOVL r+12(FP), CX
MOVL a+0(FP), AX MOVL a+0(FP), AX
MOVL a+4(FP), DX MOVL a+4(FP), DX
......
...@@ -59,7 +59,7 @@ struct Vlong ...@@ -59,7 +59,7 @@ struct Vlong
}; };
}; };
void abort(void); void runtime·abort(void);
void void
_d2v(Vlong *y, double d) _d2v(Vlong *y, double d)
...@@ -270,7 +270,7 @@ _divvu(Vlong *q, Vlong n, Vlong d) ...@@ -270,7 +270,7 @@ _divvu(Vlong *q, Vlong n, Vlong d)
} }
void void
·uint64div(Vlong n, Vlong d, Vlong q) runtime·uint64div(Vlong n, Vlong d, Vlong q)
{ {
_divvu(&q, n, d); _divvu(&q, n, d);
} }
...@@ -288,7 +288,7 @@ _modvu(Vlong *r, Vlong n, Vlong d) ...@@ -288,7 +288,7 @@ _modvu(Vlong *r, Vlong n, Vlong d)
} }
void void
·uint64mod(Vlong n, Vlong d, Vlong q) runtime·uint64mod(Vlong n, Vlong d, Vlong q)
{ {
_modvu(&q, n, d); _modvu(&q, n, d);
} }
...@@ -334,7 +334,7 @@ _divv(Vlong *q, Vlong n, Vlong d) ...@@ -334,7 +334,7 @@ _divv(Vlong *q, Vlong n, Vlong d)
} }
void void
·int64div(Vlong n, Vlong d, Vlong q) runtime·int64div(Vlong n, Vlong d, Vlong q)
{ {
_divv(&q, n, d); _divv(&q, n, d);
} }
...@@ -368,7 +368,7 @@ _modv(Vlong *r, Vlong n, Vlong d) ...@@ -368,7 +368,7 @@ _modv(Vlong *r, Vlong n, Vlong d)
} }
void void
·int64mod(Vlong n, Vlong d, Vlong q) runtime·int64mod(Vlong n, Vlong d, Vlong q)
{ {
_modv(&q, n, d); _modv(&q, n, d);
} }
...@@ -522,7 +522,7 @@ _vasop(Vlong *ret, void *lv, void fn(Vlong*, Vlong, Vlong), int type, Vlong rv) ...@@ -522,7 +522,7 @@ _vasop(Vlong *ret, void *lv, void fn(Vlong*, Vlong, Vlong), int type, Vlong rv)
u.hi = 0; u.hi = 0;
switch(type) { switch(type) {
default: default:
abort(); runtime·abort();
break; break;
case 1: /* schar */ case 1: /* schar */
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
#include "amd64/asm.h" #include "amd64/asm.h"
TEXT _rt0_amd64(SB),7,$-8 TEXT _rt0_amd64(SB),7,$-8
// copy arguments forward on an even stack // copy arguments forward on an even stack
MOVQ 0(DI), AX // argc MOVQ 0(DI), AX // argc
LEAQ 8(DI), BX // argv LEAQ 8(DI), BX // argv
...@@ -21,22 +21,22 @@ TEXT _rt0_amd64(SB),7,$-8 ...@@ -21,22 +21,22 @@ TEXT _rt0_amd64(SB),7,$-8
JMP ok JMP ok
needtls: needtls:
LEAQ tls0(SB), DI LEAQ runtime·tls0(SB), DI
CALL settls(SB) CALL runtime·settls(SB)
// store through it, to make sure it works // store through it, to make sure it works
get_tls(BX) get_tls(BX)
MOVQ $0x123, g(BX) MOVQ $0x123, g(BX)
MOVQ tls0(SB), AX MOVQ runtime·tls0(SB), AX
CMPQ AX, $0x123 CMPQ AX, $0x123
JEQ 2(PC) JEQ 2(PC)
MOVL AX, 0 // abort MOVL AX, 0 // abort
ok: ok:
// set the per-goroutine and per-mach "registers" // set the per-goroutine and per-mach "registers"
get_tls(BX) get_tls(BX)
LEAQ g0(SB), CX LEAQ runtime·g0(SB), CX
MOVQ CX, g(BX) MOVQ CX, g(BX)
LEAQ m0(SB), AX LEAQ runtime·m0(SB), AX
MOVQ AX, m(BX) MOVQ AX, m(BX)
// save m->g0 = g0 // save m->g0 = g0
...@@ -48,40 +48,40 @@ ok: ...@@ -48,40 +48,40 @@ ok:
MOVQ SP, g_stackbase(CX) MOVQ SP, g_stackbase(CX)
CLD // convention is D is always left cleared CLD // convention is D is always left cleared
CALL check(SB) CALL runtime·check(SB)
MOVL 16(SP), AX // copy argc MOVL 16(SP), AX // copy argc
MOVL AX, 0(SP) MOVL AX, 0(SP)
MOVQ 24(SP), AX // copy argv MOVQ 24(SP), AX // copy argv
MOVQ AX, 8(SP) MOVQ AX, 8(SP)
CALL args(SB) CALL runtime·args(SB)
CALL osinit(SB) CALL runtime·osinit(SB)
CALL schedinit(SB) CALL runtime·schedinit(SB)
// create a new goroutine to start program // create a new goroutine to start program
PUSHQ $mainstart(SB) // entry PUSHQ $runtime·mainstart(SB) // entry
PUSHQ $0 // arg size PUSHQ $0 // arg size
CALL ·newproc(SB) CALL runtime·newproc(SB)
POPQ AX POPQ AX
POPQ AX POPQ AX
// start this M // start this M
CALL mstart(SB) CALL runtime·mstart(SB)
CALL notok(SB) // never returns CALL runtime·notok(SB) // never returns
RET RET
TEXT mainstart(SB),7,$0 TEXT runtime·mainstart(SB),7,$0
CALL main·init(SB) CALL main·init(SB)
CALL initdone(SB) CALL runtime·initdone(SB)
CALL main·main(SB) CALL main·main(SB)
PUSHQ $0 PUSHQ $0
CALL exit(SB) CALL runtime·exit(SB)
POPQ AX POPQ AX
CALL notok(SB) CALL runtime·notok(SB)
RET RET
TEXT breakpoint(SB),7,$0 TEXT runtime·breakpoint(SB),7,$0
BYTE $0xcc BYTE $0xcc
RET RET
...@@ -91,7 +91,7 @@ TEXT breakpoint(SB),7,$0 ...@@ -91,7 +91,7 @@ TEXT breakpoint(SB),7,$0
// uintptr gosave(Gobuf*) // uintptr gosave(Gobuf*)
// save state in Gobuf; setjmp // save state in Gobuf; setjmp
TEXT gosave(SB), 7, $0 TEXT runtime·gosave(SB), 7, $0
MOVQ 8(SP), AX // gobuf MOVQ 8(SP), AX // gobuf
LEAQ 8(SP), BX // caller's SP LEAQ 8(SP), BX // caller's SP
MOVQ BX, gobuf_sp(AX) MOVQ BX, gobuf_sp(AX)
...@@ -105,7 +105,7 @@ TEXT gosave(SB), 7, $0 ...@@ -105,7 +105,7 @@ TEXT gosave(SB), 7, $0
// void gogo(Gobuf*, uintptr) // void gogo(Gobuf*, uintptr)
// restore state from Gobuf; longjmp // restore state from Gobuf; longjmp
TEXT gogo(SB), 7, $0 TEXT runtime·gogo(SB), 7, $0
MOVQ 16(SP), AX // return 2nd arg MOVQ 16(SP), AX // return 2nd arg
MOVQ 8(SP), BX // gobuf MOVQ 8(SP), BX // gobuf
MOVQ gobuf_g(BX), DX MOVQ gobuf_g(BX), DX
...@@ -119,7 +119,7 @@ TEXT gogo(SB), 7, $0 ...@@ -119,7 +119,7 @@ TEXT gogo(SB), 7, $0
// void gogocall(Gobuf*, void (*fn)(void)) // void gogocall(Gobuf*, void (*fn)(void))
// restore state from Gobuf but then call fn. // restore state from Gobuf but then call fn.
// (call fn, returning to state in Gobuf) // (call fn, returning to state in Gobuf)
TEXT gogocall(SB), 7, $0 TEXT runtime·gogocall(SB), 7, $0
MOVQ 16(SP), AX // fn MOVQ 16(SP), AX // fn
MOVQ 8(SP), BX // gobuf MOVQ 8(SP), BX // gobuf
MOVQ gobuf_g(BX), DX MOVQ gobuf_g(BX), DX
...@@ -138,7 +138,7 @@ TEXT gogocall(SB), 7, $0 ...@@ -138,7 +138,7 @@ TEXT gogocall(SB), 7, $0
// Called during function prolog when more stack is needed. // Called during function prolog when more stack is needed.
// Caller has already done get_tls(CX); MOVQ m(CX), BX. // Caller has already done get_tls(CX); MOVQ m(CX), BX.
TEXT morestack(SB),7,$0 TEXT runtime·morestack(SB),7,$0
// Cannot grow scheduler stack (m->g0). // Cannot grow scheduler stack (m->g0).
MOVQ m_g0(BX), SI MOVQ m_g0(BX), SI
CMPQ g(CX), SI CMPQ g(CX), SI
...@@ -164,7 +164,7 @@ TEXT morestack(SB),7,$0 ...@@ -164,7 +164,7 @@ TEXT morestack(SB),7,$0
MOVQ m_g0(BX), BP MOVQ m_g0(BX), BP
MOVQ BP, g(CX) MOVQ BP, g(CX)
MOVQ (m_sched+gobuf_sp)(BX), SP MOVQ (m_sched+gobuf_sp)(BX), SP
CALL newstack(SB) CALL runtime·newstack(SB)
MOVQ $0, 0x1003 // crash if newstack returns MOVQ $0, 0x1003 // crash if newstack returns
RET RET
...@@ -206,12 +206,12 @@ TEXT reflect·call(SB), 7, $0 ...@@ -206,12 +206,12 @@ TEXT reflect·call(SB), 7, $0
get_tls(CX) get_tls(CX)
MOVQ BP, g(CX) MOVQ BP, g(CX)
MOVQ (m_sched+gobuf_sp)(BX), SP MOVQ (m_sched+gobuf_sp)(BX), SP
CALL newstack(SB) CALL runtime·newstack(SB)
MOVQ $0, 0x1103 // crash if newstack returns MOVQ $0, 0x1103 // crash if newstack returns
RET RET
// Return point when leaving stack. // Return point when leaving stack.
TEXT ·lessstack(SB), 7, $0 TEXT runtime·lessstack(SB), 7, $0
// Save return value in m->cret // Save return value in m->cret
get_tls(CX) get_tls(CX)
MOVQ m(CX), BX MOVQ m(CX), BX
...@@ -221,81 +221,81 @@ TEXT ·lessstack(SB), 7, $0 ...@@ -221,81 +221,81 @@ TEXT ·lessstack(SB), 7, $0
MOVQ m_g0(BX), DX MOVQ m_g0(BX), DX
MOVQ DX, g(CX) MOVQ DX, g(CX)
MOVQ (m_sched+gobuf_sp)(BX), SP MOVQ (m_sched+gobuf_sp)(BX), SP
CALL oldstack(SB) CALL runtime·oldstack(SB)
MOVQ $0, 0x1004 // crash if oldstack returns MOVQ $0, 0x1004 // crash if oldstack returns
RET RET
// morestack trampolines // morestack trampolines
TEXT ·morestack00+0(SB),7,$0 TEXT runtime·morestack00(SB),7,$0
get_tls(CX) get_tls(CX)
MOVQ m(CX), BX MOVQ m(CX), BX
MOVQ $0, AX MOVQ $0, AX
MOVQ AX, m_moreframe(BX) MOVQ AX, m_moreframe(BX)
MOVQ $morestack+0(SB), AX MOVQ $runtime·morestack(SB), AX
JMP AX JMP AX
TEXT ·morestack01+0(SB),7,$0 TEXT runtime·morestack01(SB),7,$0
get_tls(CX) get_tls(CX)
MOVQ m(CX), BX MOVQ m(CX), BX
SHLQ $32, AX SHLQ $32, AX
MOVQ AX, m_moreframe(BX) MOVQ AX, m_moreframe(BX)
MOVQ $morestack+0(SB), AX MOVQ $runtime·morestack(SB), AX
JMP AX JMP AX
TEXT ·morestack10+0(SB),7,$0 TEXT runtime·morestack10(SB),7,$0
get_tls(CX) get_tls(CX)
MOVQ m(CX), BX MOVQ m(CX), BX
MOVLQZX AX, AX MOVLQZX AX, AX
MOVQ AX, m_moreframe(BX) MOVQ AX, m_moreframe(BX)
MOVQ $morestack+0(SB), AX MOVQ $runtime·morestack(SB), AX
JMP AX JMP AX
TEXT ·morestack11+0(SB),7,$0 TEXT runtime·morestack11(SB),7,$0
get_tls(CX) get_tls(CX)
MOVQ m(CX), BX MOVQ m(CX), BX
MOVQ AX, m_moreframe(BX) MOVQ AX, m_moreframe(BX)
MOVQ $morestack+0(SB), AX MOVQ $runtime·morestack(SB), AX
JMP AX JMP AX
// subcases of morestack01 // subcases of morestack01
// with const of 8,16,...48 // with const of 8,16,...48
TEXT ·morestack8(SB),7,$0 TEXT runtime·morestack8(SB),7,$0
PUSHQ $1 PUSHQ $1
MOVQ $·morestackx(SB), AX MOVQ $morestack<>(SB), AX
JMP AX JMP AX
TEXT ·morestack16(SB),7,$0 TEXT runtime·morestack16(SB),7,$0
PUSHQ $2 PUSHQ $2
MOVQ $·morestackx(SB), AX MOVQ $morestack<>(SB), AX
JMP AX JMP AX
TEXT ·morestack24(SB),7,$0 TEXT runtime·morestack24(SB),7,$0
PUSHQ $3 PUSHQ $3
MOVQ $·morestackx(SB), AX MOVQ $morestack<>(SB), AX
JMP AX JMP AX
TEXT ·morestack32(SB),7,$0 TEXT runtime·morestack32(SB),7,$0
PUSHQ $4 PUSHQ $4
MOVQ $·morestackx(SB), AX MOVQ $morestack<>(SB), AX
JMP AX JMP AX
TEXT ·morestack40(SB),7,$0 TEXT runtime·morestack40(SB),7,$0
PUSHQ $5 PUSHQ $5
MOVQ $·morestackx(SB), AX MOVQ $morestack<>(SB), AX
JMP AX JMP AX
TEXT ·morestack48(SB),7,$0 TEXT runtime·morestack48(SB),7,$0
PUSHQ $6 PUSHQ $6
MOVQ $·morestackx(SB), AX MOVQ $morestack<>(SB), AX
JMP AX JMP AX
TEXT ·morestackx(SB),7,$0 TEXT morestack<>(SB),7,$0
get_tls(CX) get_tls(CX)
MOVQ m(CX), BX MOVQ m(CX), BX
POPQ AX POPQ AX
SHLQ $35, AX SHLQ $35, AX
MOVQ AX, m_moreframe(BX) MOVQ AX, m_moreframe(BX)
MOVQ $morestack(SB), AX MOVQ $runtime·morestack(SB), AX
JMP AX JMP AX
// bool cas(int32 *val, int32 old, int32 new) // bool cas(int32 *val, int32 old, int32 new)
...@@ -305,7 +305,7 @@ TEXT ·morestackx(SB),7,$0 ...@@ -305,7 +305,7 @@ TEXT ·morestackx(SB),7,$0
// return 1; // return 1;
// } else // } else
// return 0; // return 0;
TEXT cas(SB), 7, $0 TEXT runtime·cas(SB), 7, $0
MOVQ 8(SP), BX MOVQ 8(SP), BX
MOVL 16(SP), AX MOVL 16(SP), AX
MOVL 20(SP), CX MOVL 20(SP), CX
...@@ -322,7 +322,7 @@ TEXT cas(SB), 7, $0 ...@@ -322,7 +322,7 @@ TEXT cas(SB), 7, $0
// 1. pop the caller // 1. pop the caller
// 2. sub 5 bytes from the callers return // 2. sub 5 bytes from the callers return
// 3. jmp to the argument // 3. jmp to the argument
TEXT jmpdefer(SB), 7, $0 TEXT runtime·jmpdefer(SB), 7, $0
MOVQ 8(SP), AX // fn MOVQ 8(SP), AX // fn
MOVQ 16(SP), BX // caller sp MOVQ 16(SP), BX // caller sp
LEAQ -8(BX), SP // caller sp after CALL LEAQ -8(BX), SP // caller sp after CALL
...@@ -332,7 +332,7 @@ TEXT jmpdefer(SB), 7, $0 ...@@ -332,7 +332,7 @@ TEXT jmpdefer(SB), 7, $0
// runcgo(void(*fn)(void*), void *arg) // runcgo(void(*fn)(void*), void *arg)
// Call fn(arg) on the scheduler stack, // Call fn(arg) on the scheduler stack,
// aligned appropriately for the gcc ABI. // aligned appropriately for the gcc ABI.
TEXT runcgo(SB),7,$32 TEXT runtime·runcgo(SB),7,$32
MOVQ fn+0(FP), R12 MOVQ fn+0(FP), R12
MOVQ arg+8(FP), R13 MOVQ arg+8(FP), R13
MOVQ SP, CX MOVQ SP, CX
...@@ -365,7 +365,7 @@ TEXT runcgo(SB),7,$32 ...@@ -365,7 +365,7 @@ TEXT runcgo(SB),7,$32
// runcgocallback(G *g1, void* sp, void (*fn)(void)) // runcgocallback(G *g1, void* sp, void (*fn)(void))
// Switch to g1 and sp, call fn, switch back. fn's arguments are on // Switch to g1 and sp, call fn, switch back. fn's arguments are on
// the new stack. // the new stack.
TEXT runcgocallback(SB),7,$48 TEXT runtime·runcgocallback(SB),7,$48
MOVQ g1+0(FP), DX MOVQ g1+0(FP), DX
MOVQ sp+8(FP), AX MOVQ sp+8(FP), AX
MOVQ fp+16(FP), BX MOVQ fp+16(FP), BX
...@@ -394,7 +394,7 @@ TEXT runcgocallback(SB),7,$48 ...@@ -394,7 +394,7 @@ TEXT runcgocallback(SB),7,$48
RET RET
// check that SP is in range [g->stackbase, g->stackguard) // check that SP is in range [g->stackbase, g->stackguard)
TEXT stackcheck(SB), 7, $0 TEXT runtime·stackcheck(SB), 7, $0
get_tls(CX) get_tls(CX)
MOVQ g(CX), AX MOVQ g(CX), AX
CMPQ g_stackbase(AX), SP CMPQ g_stackbase(AX), SP
...@@ -405,7 +405,7 @@ TEXT stackcheck(SB), 7, $0 ...@@ -405,7 +405,7 @@ TEXT stackcheck(SB), 7, $0
INT $3 INT $3
RET RET
TEXT ·memclr(SB),7,$0 TEXT runtime·memclr(SB),7,$0
MOVQ 8(SP), DI // arg 1 addr MOVQ 8(SP), DI // arg 1 addr
MOVL 16(SP), CX // arg 2 count MOVL 16(SP), CX // arg 2 count
ADDL $7, CX ADDL $7, CX
...@@ -416,20 +416,19 @@ TEXT ·memclr(SB),7,$0 ...@@ -416,20 +416,19 @@ TEXT ·memclr(SB),7,$0
STOSQ STOSQ
RET RET
TEXT ·getcallerpc+0(SB),7,$0 TEXT runtime·getcallerpc(SB),7,$0
MOVQ x+0(FP),AX // addr of first arg MOVQ x+0(FP),AX // addr of first arg
MOVQ -8(AX),AX // get calling pc MOVQ -8(AX),AX // get calling pc
RET RET
TEXT ·setcallerpc+0(SB),7,$0 TEXT runtime·setcallerpc(SB),7,$0
MOVQ x+0(FP),AX // addr of first arg MOVQ x+0(FP),AX // addr of first arg
MOVQ x+8(FP), BX MOVQ x+8(FP), BX
MOVQ BX, -8(AX) // set calling pc MOVQ BX, -8(AX) // set calling pc
RET RET
TEXT getcallersp(SB),7,$0 TEXT runtime·getcallersp(SB),7,$0
MOVQ sp+0(FP), AX MOVQ sp+0(FP), AX
RET RET
GLOBL initcgo(SB), $8 GLOBL runtime·tls0(SB), $64
GLOBL tls0(SB), $64
...@@ -9,20 +9,20 @@ ...@@ -9,20 +9,20 @@
// fn func(arg0, arg1, arg2 *ptr, callerpc uintptr, xxx) yyy, // fn func(arg0, arg1, arg2 *ptr, callerpc uintptr, xxx) yyy,
// arg0, arg1, arg2 *ptr) (func(xxx) yyy) // arg0, arg1, arg2 *ptr) (func(xxx) yyy)
void void
·closure(int32 siz, byte *fn, byte *arg0) runtime·closure(int32 siz, byte *fn, byte *arg0)
{ {
byte *p, *q, **ret; byte *p, *q, **ret;
int32 i, n; int32 i, n;
int64 pcrel; int64 pcrel;
if(siz < 0 || siz%8 != 0) if(siz < 0 || siz%8 != 0)
throw("bad closure size"); runtime·throw("bad closure size");
ret = (byte**)((byte*)&arg0 + siz); ret = (byte**)((byte*)&arg0 + siz);
if(siz > 100) { if(siz > 100) {
// TODO(rsc): implement stack growth preamble? // TODO(rsc): implement stack growth preamble?
throw("closure too big"); runtime·throw("closure too big");
} }
// compute size of new fn. // compute size of new fn.
...@@ -40,12 +40,12 @@ void ...@@ -40,12 +40,12 @@ void
if(n%8) if(n%8)
n += 8 - n%8; n += 8 - n%8;
p = mal(n); p = runtime·mal(n);
*ret = p; *ret = p;
q = p + n - siz; q = p + n - siz;
if(siz > 0) { if(siz > 0) {
mcpy(q, (byte*)&arg0, siz); runtime·mcpy(q, (byte*)&arg0, siz);
// SUBQ $siz, SP // SUBQ $siz, SP
*p++ = 0x48; *p++ = 0x48;
...@@ -117,7 +117,7 @@ void ...@@ -117,7 +117,7 @@ void
*p++ = 0xc3; *p++ = 0xc3;
if(p > q) if(p > q)
throw("bad math in sys.closure"); runtime·throw("bad math in sys.closure");
} }
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE. // THE SOFTWARE.
TEXT memmove(SB), 7, $0 TEXT runtime·memmove(SB), 7, $0
MOVQ to+0(FP), DI MOVQ to+0(FP), DI
MOVQ fr+8(FP), SI MOVQ fr+8(FP), SI
......
...@@ -6,8 +6,8 @@ ...@@ -6,8 +6,8 @@
#include "malloc.h" #include "malloc.h"
static uintptr isclosureentry(uintptr); static uintptr isclosureentry(uintptr);
void ·deferproc(void); void runtime·deferproc(void);
void ·newproc(void); void runtime·newproc(void);
// This code is also used for the 386 tracebacks. // This code is also used for the 386 tracebacks.
// Use uintptr for an appropriate word-sized integer. // Use uintptr for an appropriate word-sized integer.
...@@ -35,7 +35,7 @@ gentraceback(byte *pc0, byte *sp, G *g, int32 skip, uintptr *pcbuf, int32 m) ...@@ -35,7 +35,7 @@ gentraceback(byte *pc0, byte *sp, G *g, int32 skip, uintptr *pcbuf, int32 m)
} }
nascent = 0; nascent = 0;
if(pc0 == g->sched.pc && sp == g->sched.sp && pc0 == (byte*)goexit) { if(pc0 == g->sched.pc && sp == g->sched.sp && pc0 == (byte*)runtime·goexit) {
// Hasn't started yet. g->sched is set up for goexit // Hasn't started yet. g->sched is set up for goexit
// but goroutine will start at g->entry. // but goroutine will start at g->entry.
nascent = 1; nascent = 1;
...@@ -45,7 +45,7 @@ gentraceback(byte *pc0, byte *sp, G *g, int32 skip, uintptr *pcbuf, int32 m) ...@@ -45,7 +45,7 @@ gentraceback(byte *pc0, byte *sp, G *g, int32 skip, uintptr *pcbuf, int32 m)
n = 0; n = 0;
stk = (Stktop*)g->stackbase; stk = (Stktop*)g->stackbase;
for(iter = 0; iter < 100 && n < m; iter++) { // iter avoids looping forever for(iter = 0; iter < 100 && n < m; iter++) { // iter avoids looping forever
if(pc == (uintptr)·lessstack) { if(pc == (uintptr)runtime·lessstack) {
// Hit top of stack segment. Unwind to next segment. // Hit top of stack segment. Unwind to next segment.
pc = (uintptr)stk->gobuf.pc; pc = (uintptr)stk->gobuf.pc;
sp = stk->gobuf.sp; sp = stk->gobuf.sp;
...@@ -53,14 +53,14 @@ gentraceback(byte *pc0, byte *sp, G *g, int32 skip, uintptr *pcbuf, int32 m) ...@@ -53,14 +53,14 @@ gentraceback(byte *pc0, byte *sp, G *g, int32 skip, uintptr *pcbuf, int32 m)
continue; continue;
} }
if(pc <= 0x1000 || (f = findfunc(pc)) == nil) { if(pc <= 0x1000 || (f = runtime·findfunc(pc)) == nil) {
// Dangerous, but worthwhile: see if this is a closure: // Dangerous, but worthwhile: see if this is a closure:
// ADDQ $wwxxyyzz, SP; RET // ADDQ $wwxxyyzz, SP; RET
// [48] 81 c4 zz yy xx ww c3 // [48] 81 c4 zz yy xx ww c3
// The 0x48 byte is only on amd64. // The 0x48 byte is only on amd64.
p = (byte*)pc; p = (byte*)pc;
// We check p < p+8 to avoid wrapping and faulting if we lose track. // We check p < p+8 to avoid wrapping and faulting if we lose track.
if(mheap.min < p && p < p+8 && p+8 < mheap.max && // pointer in allocated memory if(runtime·mheap.min < p && p < p+8 && p+8 < runtime·mheap.max && // pointer in allocated memory
(sizeof(uintptr) != 8 || *p++ == 0x48) && // skip 0x48 byte on amd64 (sizeof(uintptr) != 8 || *p++ == 0x48) && // skip 0x48 byte on amd64
p[0] == 0x81 && p[1] == 0xc4 && p[6] == 0xc3) { p[0] == 0x81 && p[1] == 0xc4 && p[6] == 0xc3) {
sp += *(uint32*)(p+2); sp += *(uint32*)(p+2);
...@@ -85,14 +85,14 @@ gentraceback(byte *pc0, byte *sp, G *g, int32 skip, uintptr *pcbuf, int32 m) ...@@ -85,14 +85,14 @@ gentraceback(byte *pc0, byte *sp, G *g, int32 skip, uintptr *pcbuf, int32 m)
// Print during crash. // Print during crash.
// main+0xf /home/rsc/go/src/runtime/x.go:23 // main+0xf /home/rsc/go/src/runtime/x.go:23
// main(0x1, 0x2, 0x3) // main(0x1, 0x2, 0x3)
printf("%S", f->name); runtime·printf("%S", f->name);
if(pc > f->entry) if(pc > f->entry)
printf("+%p", (uintptr)(pc - f->entry)); runtime·printf("+%p", (uintptr)(pc - f->entry));
tracepc = pc; // back up to CALL instruction for funcline. tracepc = pc; // back up to CALL instruction for funcline.
if(n > 0 && pc > f->entry) if(n > 0 && pc > f->entry)
tracepc--; tracepc--;
printf(" %S:%d\n", f->src, funcline(f, tracepc)); runtime·printf(" %S:%d\n", f->src, runtime·funcline(f, tracepc));
printf("\t%S(", f->name); runtime·printf("\t%S(", f->name);
fp = (uintptr*)sp; fp = (uintptr*)sp;
if(f->frame < sizeof(uintptr)) if(f->frame < sizeof(uintptr))
fp++; fp++;
...@@ -100,14 +100,14 @@ gentraceback(byte *pc0, byte *sp, G *g, int32 skip, uintptr *pcbuf, int32 m) ...@@ -100,14 +100,14 @@ gentraceback(byte *pc0, byte *sp, G *g, int32 skip, uintptr *pcbuf, int32 m)
fp += f->frame/sizeof(uintptr); fp += f->frame/sizeof(uintptr);
for(i = 0; i < f->args; i++) { for(i = 0; i < f->args; i++) {
if(i != 0) if(i != 0)
prints(", "); runtime·prints(", ");
·printhex(fp[i]); runtime·printhex(fp[i]);
if(i >= 4) { if(i >= 4) {
prints(", ..."); runtime·prints(", ...");
break; break;
} }
} }
prints(")\n"); runtime·prints(")\n");
n++; n++;
} }
...@@ -123,26 +123,26 @@ gentraceback(byte *pc0, byte *sp, G *g, int32 skip, uintptr *pcbuf, int32 m) ...@@ -123,26 +123,26 @@ gentraceback(byte *pc0, byte *sp, G *g, int32 skip, uintptr *pcbuf, int32 m)
else else
sp += f->frame; sp += f->frame;
pc = *((uintptr*)sp - 1); pc = *((uintptr*)sp - 1);
if(f->entry == (uintptr)·deferproc || f->entry == (uintptr)·newproc) if(f->entry == (uintptr)runtime·deferproc || f->entry == (uintptr)runtime·newproc)
sp += 2*sizeof(uintptr); sp += 2*sizeof(uintptr);
} }
return n; return n;
} }
void void
traceback(byte *pc0, byte *sp, byte*, G *g) runtime·traceback(byte *pc0, byte *sp, byte*, G *g)
{ {
gentraceback(pc0, sp, g, 0, nil, 100); gentraceback(pc0, sp, g, 0, nil, 100);
} }
int32 int32
callers(int32 skip, uintptr *pcbuf, int32 m) runtime·callers(int32 skip, uintptr *pcbuf, int32 m)
{ {
byte *pc, *sp; byte *pc, *sp;
// our caller's pc, sp. // our caller's pc, sp.
sp = (byte*)&skip; sp = (byte*)&skip;
pc = ·getcallerpc(&skip); pc = runtime·getcallerpc(&skip);
return gentraceback(pc, sp, g, skip, pcbuf, m); return gentraceback(pc, sp, g, skip, pcbuf, m);
} }
...@@ -154,7 +154,7 @@ isclosureentry(uintptr pc) ...@@ -154,7 +154,7 @@ isclosureentry(uintptr pc)
int32 i, siz; int32 i, siz;
p = (byte*)pc; p = (byte*)pc;
if(p < mheap.min || p+32 > mheap.max) if(p < runtime·mheap.min || p+32 > runtime·mheap.max)
return 0; return 0;
// SUBQ $siz, SP // SUBQ $siz, SP
......
...@@ -19,8 +19,8 @@ TEXT _rt0_arm(SB),7,$-4 ...@@ -19,8 +19,8 @@ TEXT _rt0_arm(SB),7,$-4
// set up m and g registers // set up m and g registers
// g is R10, m is R9 // g is R10, m is R9
MOVW $g0(SB), g MOVW $runtime·g0(SB), g
MOVW $m0(SB), m MOVW $runtime·m0(SB), m
// save m->g0 = g0 // save m->g0 = g0
MOVW g, m_g0(m) MOVW g, m_g0(m)
...@@ -29,47 +29,47 @@ TEXT _rt0_arm(SB),7,$-4 ...@@ -29,47 +29,47 @@ TEXT _rt0_arm(SB),7,$-4
MOVW $(-8192+104)(R13), R0 MOVW $(-8192+104)(R13), R0
MOVW R0, g_stackguard(g) // (w 104b guard) MOVW R0, g_stackguard(g) // (w 104b guard)
MOVW R13, g_stackbase(g) MOVW R13, g_stackbase(g)
BL emptyfunc(SB) // fault if stack check is wrong BL runtime·emptyfunc(SB) // fault if stack check is wrong
BL check(SB) BL runtime·check(SB)
// saved argc, argv // saved argc, argv
MOVW 120(R13), R0 MOVW 120(R13), R0
MOVW R0, 4(R13) MOVW R0, 4(R13)
MOVW 124(R13), R1 MOVW 124(R13), R1
MOVW R1, 8(R13) MOVW R1, 8(R13)
BL args(SB) BL runtime·args(SB)
BL osinit(SB) BL runtime·osinit(SB)
BL schedinit(SB) BL runtime·schedinit(SB)
// create a new goroutine to start program // create a new goroutine to start program
MOVW $mainstart(SB), R0 MOVW $runtime·mainstart(SB), R0
MOVW.W R0, -4(R13) MOVW.W R0, -4(R13)
MOVW $8, R0 MOVW $8, R0
MOVW.W R0, -4(R13) MOVW.W R0, -4(R13)
MOVW $0, R0 MOVW $0, R0
MOVW.W R0, -4(R13) // push $0 as guard MOVW.W R0, -4(R13) // push $0 as guard
BL ·newproc(SB) BL runtime·newproc(SB)
MOVW $12(R13), R13 // pop args and LR MOVW $12(R13), R13 // pop args and LR
// start this M // start this M
BL mstart(SB) BL runtime·mstart(SB)
MOVW $1234, R0 MOVW $1234, R0
MOVW $1000, R1 MOVW $1000, R1
MOVW R0, (R1) // fail hard MOVW R0, (R1) // fail hard
B _dep_dummy(SB) // Never reached B runtime·_dep_dummy(SB) // Never reached
TEXT mainstart(SB),7,$4 TEXT runtime·mainstart(SB),7,$4
BL main·init(SB) BL main·init(SB)
BL initdone(SB) BL runtime·initdone(SB)
EOR R0, R0 EOR R0, R0
MOVW R0, 0(R13) MOVW R0, 0(R13)
BL main·main(SB) BL main·main(SB)
MOVW $0, R0 MOVW $0, R0
MOVW R0, 4(SP) MOVW R0, 4(SP)
BL exit(SB) BL runtime·exit(SB)
MOVW $1234, R0 MOVW $1234, R0
MOVW $1001, R1 MOVW $1001, R1
MOVW R0, (R1) // fail hard MOVW R0, (R1) // fail hard
...@@ -77,7 +77,7 @@ TEXT mainstart(SB),7,$4 ...@@ -77,7 +77,7 @@ TEXT mainstart(SB),7,$4
// TODO(kaib): remove these once i actually understand how the linker removes symbols // TODO(kaib): remove these once i actually understand how the linker removes symbols
// pull in dummy dependencies // pull in dummy dependencies
TEXT _dep_dummy(SB),7,$0 TEXT runtime·_dep_dummy(SB),7,$0
BL _div(SB) BL _div(SB)
BL _divu(SB) BL _divu(SB)
BL _mod(SB) BL _mod(SB)
...@@ -85,7 +85,7 @@ TEXT _dep_dummy(SB),7,$0 ...@@ -85,7 +85,7 @@ TEXT _dep_dummy(SB),7,$0
BL _modu(SB) BL _modu(SB)
BL _sfloat(SB) BL _sfloat(SB)
TEXT breakpoint(SB),7,$0 TEXT runtime·breakpoint(SB),7,$0
// no breakpoint yet; let program exit // no breakpoint yet; let program exit
RET RET
...@@ -95,7 +95,7 @@ TEXT breakpoint(SB),7,$0 ...@@ -95,7 +95,7 @@ TEXT breakpoint(SB),7,$0
// uintptr gosave(Gobuf*) // uintptr gosave(Gobuf*)
// save state in Gobuf; setjmp // save state in Gobuf; setjmp
TEXT gosave(SB), 7, $-4 TEXT runtime·gosave(SB), 7, $-4
MOVW 0(FP), R0 // gobuf MOVW 0(FP), R0 // gobuf
MOVW SP, gobuf_sp(R0) MOVW SP, gobuf_sp(R0)
MOVW LR, gobuf_pc(R0) MOVW LR, gobuf_pc(R0)
...@@ -105,7 +105,7 @@ TEXT gosave(SB), 7, $-4 ...@@ -105,7 +105,7 @@ TEXT gosave(SB), 7, $-4
// void gogo(Gobuf*, uintptr) // void gogo(Gobuf*, uintptr)
// restore state from Gobuf; longjmp // restore state from Gobuf; longjmp
TEXT gogo(SB), 7, $-4 TEXT runtime·gogo(SB), 7, $-4
MOVW 0(FP), R1 // gobuf MOVW 0(FP), R1 // gobuf
MOVW 4(FP), R0 // return 2nd arg MOVW 4(FP), R0 // return 2nd arg
MOVW gobuf_g(R1), g MOVW gobuf_g(R1), g
...@@ -117,7 +117,7 @@ TEXT gogo(SB), 7, $-4 ...@@ -117,7 +117,7 @@ TEXT gogo(SB), 7, $-4
// restore state from Gobuf but then call fn. // restore state from Gobuf but then call fn.
// (call fn, returning to state in Gobuf) // (call fn, returning to state in Gobuf)
// using frame size $-4 means do not save LR on stack. // using frame size $-4 means do not save LR on stack.
TEXT gogocall(SB), 7, $-4 TEXT runtime·gogocall(SB), 7, $-4
MOVW 0(FP), R0 // gobuf MOVW 0(FP), R0 // gobuf
MOVW 4(FP), R1 // fn MOVW 4(FP), R1 // fn
MOVW 8(FP), R2 // fp offset MOVW 8(FP), R2 // fp offset
...@@ -138,11 +138,11 @@ TEXT gogocall(SB), 7, $-4 ...@@ -138,11 +138,11 @@ TEXT gogocall(SB), 7, $-4
// NB. we do not save R0 because we've forced 5c to pass all arguments // NB. we do not save R0 because we've forced 5c to pass all arguments
// on the stack. // on the stack.
// using frame size $-4 means do not save LR on stack. // using frame size $-4 means do not save LR on stack.
TEXT ·morestack(SB),7,$-4 TEXT runtime·morestack(SB),7,$-4
// Cannot grow scheduler stack (m->g0). // Cannot grow scheduler stack (m->g0).
MOVW m_g0(m), R4 MOVW m_g0(m), R4
CMP g, R4 CMP g, R4
BL.EQ abort(SB) BL.EQ runtime·abort(SB)
// Save in m. // Save in m.
MOVW R1, m_moreframe(m) MOVW R1, m_moreframe(m)
...@@ -161,7 +161,7 @@ TEXT ·morestack(SB),7,$-4 ...@@ -161,7 +161,7 @@ TEXT ·morestack(SB),7,$-4
// Call newstack on m's scheduling stack. // Call newstack on m's scheduling stack.
MOVW m_g0(m), g MOVW m_g0(m), g
MOVW (m_sched+gobuf_sp)(m), SP MOVW (m_sched+gobuf_sp)(m), SP
B newstack(SB) B runtime·newstack(SB)
// Called from reflection library. Mimics morestack, // Called from reflection library. Mimics morestack,
// reuses stack growth code to create a frame // reuses stack growth code to create a frame
...@@ -197,32 +197,32 @@ TEXT reflect·call(SB), 7, $-4 ...@@ -197,32 +197,32 @@ TEXT reflect·call(SB), 7, $-4
// Call newstack on m's scheduling stack. // Call newstack on m's scheduling stack.
MOVW m_g0(m), g MOVW m_g0(m), g
MOVW (m_sched+gobuf_sp)(m), SP MOVW (m_sched+gobuf_sp)(m), SP
B newstack(SB) B runtime·newstack(SB)
// Return point when leaving stack. // Return point when leaving stack.
// using frame size $-4 means do not save LR on stack. // using frame size $-4 means do not save LR on stack.
TEXT ·lessstack(SB), 7, $-4 TEXT runtime·lessstack(SB), 7, $-4
// Save return value in m->cret // Save return value in m->cret
MOVW R0, m_cret(m) MOVW R0, m_cret(m)
// Call oldstack on m's scheduling stack. // Call oldstack on m's scheduling stack.
MOVW m_g0(m), g MOVW m_g0(m), g
MOVW (m_sched+gobuf_sp)(m), SP MOVW (m_sched+gobuf_sp)(m), SP
B oldstack(SB) B runtime·oldstack(SB)
// void jmpdefer(fn, sp); // void jmpdefer(fn, sp);
// called from deferreturn. // called from deferreturn.
// 1. grab stored LR for caller // 1. grab stored LR for caller
// 2. sub 4 bytes to get back to BL deferreturn // 2. sub 4 bytes to get back to BL deferreturn
// 3. B to fn // 3. B to fn
TEXT jmpdefer(SB), 7, $0 TEXT runtime·jmpdefer(SB), 7, $0
MOVW 0(SP), LR MOVW 0(SP), LR
MOVW $-4(LR), LR // BL deferreturn MOVW $-4(LR), LR // BL deferreturn
MOVW 4(SP), R0 // fn MOVW 4(SP), R0 // fn
MOVW 8(SP), SP MOVW 8(SP), SP
B (R0) B (R0)
TEXT ·memclr(SB),7,$20 TEXT runtime·memclr(SB),7,$20
MOVW 0(FP), R0 MOVW 0(FP), R0
MOVW $0, R1 // c = 0 MOVW $0, R1 // c = 0
MOVW R1, -16(SP) MOVW R1, -16(SP)
...@@ -230,21 +230,21 @@ TEXT ·memclr(SB),7,$20 ...@@ -230,21 +230,21 @@ TEXT ·memclr(SB),7,$20
MOVW R1, -12(SP) MOVW R1, -12(SP)
MOVW m, -8(SP) // Save m and g MOVW m, -8(SP) // Save m and g
MOVW g, -4(SP) MOVW g, -4(SP)
BL memset(SB) BL runtime·memset(SB)
MOVW -8(SP), m // Restore m and g, memset clobbers them MOVW -8(SP), m // Restore m and g, memset clobbers them
MOVW -4(SP), g MOVW -4(SP), g
RET RET
TEXT ·getcallerpc+0(SB),7,$-4 TEXT runtime·getcallerpc(SB),7,$-4
MOVW 0(SP), R0 MOVW 0(SP), R0
RET RET
TEXT ·setcallerpc+0(SB),7,$-4 TEXT runtime·setcallerpc(SB),7,$-4
MOVW x+4(FP), R0 MOVW x+4(FP), R0
MOVW R0, 0(SP) MOVW R0, 0(SP)
RET RET
TEXT getcallersp(SB),7,$-4 TEXT runtime·getcallersp(SB),7,$-4
MOVW 0(FP), R0 MOVW 0(FP), R0
MOVW $-4(R0), R0 MOVW $-4(R0), R0
RET RET
...@@ -253,8 +253,8 @@ TEXT getcallersp(SB),7,$-4 ...@@ -253,8 +253,8 @@ TEXT getcallersp(SB),7,$-4
// Just call fn(arg), but first align the stack // Just call fn(arg), but first align the stack
// appropriately for the gcc ABI. // appropriately for the gcc ABI.
// TODO(kaib): figure out the arm-gcc ABI // TODO(kaib): figure out the arm-gcc ABI
TEXT runcgo(SB),7,$16 TEXT runtime·runcgo(SB),7,$16
BL abort(SB) BL runtime·abort(SB)
// MOVL fn+0(FP), AX // MOVL fn+0(FP), AX
// MOVL arg+4(FP), BX // MOVL arg+4(FP), BX
// MOVL SP, CX // MOVL SP, CX
...@@ -265,13 +265,13 @@ TEXT runcgo(SB),7,$16 ...@@ -265,13 +265,13 @@ TEXT runcgo(SB),7,$16
// MOVL 4(SP), SP // MOVL 4(SP), SP
// RET // RET
TEXT emptyfunc(SB),0,$0 TEXT runtime·emptyfunc(SB),0,$0
RET RET
TEXT abort(SB),7,$-4 TEXT runtime·abort(SB),7,$-4
MOVW $0, R0 MOVW $0, R0
MOVW (R0), R1 MOVW (R0), R1
TEXT runcgocallback(SB),7,$0 TEXT runtime·runcgocallback(SB),7,$0
MOVW $0, R0 MOVW $0, R0
MOVW (R0), R1 MOVW (R0), R1
...@@ -14,12 +14,12 @@ ...@@ -14,12 +14,12 @@
// }else // }else
// return 0; // return 0;
TEXT cas(SB),7,$0 TEXT runtime·cas(SB),7,$0
MOVW 0(FP), R0 // *val MOVW 0(FP), R0 // *val
MOVW 4(FP), R1 // old MOVW 4(FP), R1 // old
MOVW 8(FP), R2 // new MOVW 8(FP), R2 // new
MOVW $1, R3 MOVW $1, R3
MOVW $cas_mutex(SB), R4 MOVW $runtime·cas_mutex(SB), R4
l: l:
SWPW (R4), R3 // acquire mutex SWPW (R4), R3 // acquire mutex
CMP $0, R3 CMP $0, R3
...@@ -39,5 +39,5 @@ fail0: ...@@ -39,5 +39,5 @@ fail0:
MOVW $0, R0 MOVW $0, R0
RET RET
DATA cas_mutex(SB)/4, $0 DATA runtime·cas_mutex(SB)/4, $0
GLOBL cas_mutex(SB), $4 GLOBL runtime·cas_mutex(SB), $4
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
// }else // }else
// return 0; // return 0;
TEXT cas(SB),7,$0 TEXT cas(SB),7,$0
MOVW 0(FP), R1 // *val MOVW 0(FP), R1 // *val
MOVW 4(FP), R2 // old MOVW 4(FP), R2 // old
MOVW 8(FP), R3 // new MOVW 8(FP), R3 // new
......
...@@ -47,20 +47,20 @@ extern void cacheflush(byte* start, byte* end); ...@@ -47,20 +47,20 @@ extern void cacheflush(byte* start, byte* end);
#pragma textflag 7 #pragma textflag 7
void void
·closure(int32 siz, byte *fn, byte *arg0) runtime·closure(int32 siz, byte *fn, byte *arg0)
{ {
byte *p, *q, **ret; byte *p, *q, **ret;
uint32 *pc; uint32 *pc;
int32 n; int32 n;
if(siz < 0 || siz%4 != 0) if(siz < 0 || siz%4 != 0)
throw("bad closure size"); runtime·throw("bad closure size");
ret = (byte**)((byte*)&arg0 + siz); ret = (byte**)((byte*)&arg0 + siz);
if(siz > 100) { if(siz > 100) {
// TODO(kaib): implement stack growth preamble? // TODO(kaib): implement stack growth preamble?
throw("closure too big"); runtime·throw("closure too big");
} }
// size of new fn. // size of new fn.
...@@ -73,7 +73,7 @@ void ...@@ -73,7 +73,7 @@ void
// store args aligned after code, so gc can find them. // store args aligned after code, so gc can find them.
n += siz; n += siz;
p = mal(n); p = runtime·mal(n);
*ret = p; *ret = p;
q = p + n - siz; q = p + n - siz;
...@@ -83,7 +83,7 @@ void ...@@ -83,7 +83,7 @@ void
*pc++ = 0xe52de000 | (siz + 4); *pc++ = 0xe52de000 | (siz + 4);
if(siz > 0) { if(siz > 0) {
mcpy(q, (byte*)&arg0, siz); runtime·mcpy(q, (byte*)&arg0, siz);
// MOVW $vars(PC), R0 // MOVW $vars(PC), R0
*pc = 0xe28f0000 | (int32)(q - (byte*)pc - 8); *pc = 0xe28f0000 | (int32)(q - (byte*)pc - 8);
...@@ -122,8 +122,8 @@ void ...@@ -122,8 +122,8 @@ void
p = (byte*)pc; p = (byte*)pc;
if(p > q) if(p > q)
throw("bad math in sys.closure"); runtime·throw("bad math in sys.closure");
cacheflush(*ret, q+siz); runtime·cacheflush(*ret, q+siz);
} }
...@@ -31,7 +31,7 @@ TMP = 3 /* N and TMP don't overlap */ ...@@ -31,7 +31,7 @@ TMP = 3 /* N and TMP don't overlap */
TMP1 = 4 TMP1 = 4
// TODO(kaib): This can be done with the existing registers of LR is re-used. Same for memset. // TODO(kaib): This can be done with the existing registers of LR is re-used. Same for memset.
TEXT memmove(SB), 7, $8 TEXT runtime·memmove(SB), 7, $8
// save g and m // save g and m
MOVW R9, 4(R13) MOVW R9, 4(R13)
MOVW R10, 8(R13) MOVW R10, 8(R13)
......
...@@ -31,7 +31,7 @@ TMP = 3 /* N and TMP don't overlap */ ...@@ -31,7 +31,7 @@ TMP = 3 /* N and TMP don't overlap */
// TODO(kaib): memset clobbers R9 and R10 (m and g). This makes the // TODO(kaib): memset clobbers R9 and R10 (m and g). This makes the
// registers unpredictable if (when) memset SIGSEGV's. Fix it by // registers unpredictable if (when) memset SIGSEGV's. Fix it by
// moving the R4-R11 register bank. // moving the R4-R11 register bank.
TEXT memset(SB), $0 TEXT runtime·memset(SB), $0
MOVW R0, R(TO) MOVW R0, R(TO)
MOVW data+4(FP), R(4) MOVW data+4(FP), R(4)
MOVW n+8(FP), R(N) MOVW n+8(FP), R(N)
......
...@@ -14,8 +14,8 @@ static void ...@@ -14,8 +14,8 @@ static void
fabort(void) fabort(void)
{ {
if (1) { if (1) {
printf("Unsupported floating point instruction\n"); runtime·printf("Unsupported floating point instruction\n");
abort(); runtime·abort();
} }
} }
...@@ -88,7 +88,7 @@ precision(uint32 i) ...@@ -88,7 +88,7 @@ precision(uint32 i)
case 0x80: case 0x80:
return 1; return 1;
default: default:
fabort(); runtime·fabort();
} }
return 0; return 0;
} }
...@@ -108,7 +108,7 @@ fprint(void) ...@@ -108,7 +108,7 @@ fprint(void)
{ {
uint32 i; uint32 i;
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
printf("\tf%d:\t%X\n", i, m->freg[i]); runtime·printf("\tf%d:\t%X\n", i, m->freg[i]);
} }
} }
...@@ -117,7 +117,7 @@ d2s(uint64 d) ...@@ -117,7 +117,7 @@ d2s(uint64 d)
{ {
uint32 x; uint32 x;
·f64to32c(d, &x); runtime·f64to32c(d, &x);
return x; return x;
} }
...@@ -126,7 +126,7 @@ s2d(uint32 s) ...@@ -126,7 +126,7 @@ s2d(uint32 s)
{ {
uint64 x; uint64 x;
·f32to64c(s, &x); runtime·f32to64c(s, &x);
return x; return x;
} }
...@@ -147,16 +147,16 @@ dataprocess(uint32* pc) ...@@ -147,16 +147,16 @@ dataprocess(uint32* pc)
lhs = i>>16 & 7; lhs = i>>16 & 7;
rhs = i & 15; rhs = i & 15;
prec = precision(i); prec = runtime·precision(i);
// if (prec != 1) // if (prec != 1)
// goto undef; // goto undef;
if (unary) { if (unary) {
switch (opcode) { switch (opcode) {
case 0: // mvf case 0: // mvf
fd = frhs(rhs); fd = runtime·frhs(rhs);
if(prec == 0) if(prec == 0)
fd = s2d(d2s(fd)); fd = runtime·s2d(d2s(fd));
m->freg[dest] = fd; m->freg[dest] = fd;
goto ret; goto ret;
default: default:
...@@ -164,21 +164,21 @@ dataprocess(uint32* pc) ...@@ -164,21 +164,21 @@ dataprocess(uint32* pc)
} }
} else { } else {
l = m->freg[lhs]; l = m->freg[lhs];
r = frhs(rhs); r = runtime·frhs(rhs);
switch (opcode) { switch (opcode) {
default: default:
goto undef; goto undef;
case 0: case 0:
·fadd64c(l, r, &m->freg[dest]); runtime·fadd64c(l, r, &m->freg[dest]);
break; break;
case 1: case 1:
·fmul64c(l, r, &m->freg[dest]); runtime·fmul64c(l, r, &m->freg[dest]);
break; break;
case 2: case 2:
·fsub64c(l, r, &m->freg[dest]); runtime·fsub64c(l, r, &m->freg[dest]);
break; break;
case 4: case 4:
·fdiv64c(l, r, &m->freg[dest]); runtime·fdiv64c(l, r, &m->freg[dest]);
break; break;
} }
goto ret; goto ret;
...@@ -190,18 +190,18 @@ undef: ...@@ -190,18 +190,18 @@ undef:
ret: ret:
if (trace || doabort) { if (trace || doabort) {
printf(" %p %x\t%s%s\tf%d, ", pc, *pc, opnames[opcode | unary<<4], runtime·printf(" %p %x\t%s%s\tf%d, ", pc, *pc, opnames[opcode | unary<<4],
fpprec[prec], dest); fpprec[prec], dest);
if (!unary) if (!unary)
printf("f%d, ", lhs); runtime·printf("f%d, ", lhs);
if (rhs & 0x8) if (rhs & 0x8)
printf("#%s\n", fpconst[rhs&0x7]); runtime·printf("#%s\n", fpconst[rhs&0x7]);
else else
printf("f%d\n", rhs&0x7); runtime·printf("f%d\n", rhs&0x7);
fprint(); runtime·fprint();
} }
if (doabort) if (doabort)
fabort(); runtime·fabort();
} }
#define CPSR 14 #define CPSR 14
...@@ -225,8 +225,8 @@ compare(uint32 *pc, uint32 *regs) ...@@ -225,8 +225,8 @@ compare(uint32 *pc, uint32 *regs)
rhs = i & 0xf; rhs = i & 0xf;
l = m->freg[lhs]; l = m->freg[lhs];
r = frhs(rhs); r = runtime·frhs(rhs);
·fcmp64c(l, r, &cmp, &nan); runtime·fcmp64c(l, r, &cmp, &nan);
if (nan) if (nan)
flags = FLAGS_C | FLAGS_V; flags = FLAGS_C | FLAGS_V;
else if (cmp == 0) else if (cmp == 0)
...@@ -237,11 +237,11 @@ compare(uint32 *pc, uint32 *regs) ...@@ -237,11 +237,11 @@ compare(uint32 *pc, uint32 *regs)
flags = FLAGS_C; flags = FLAGS_C;
if (trace) { if (trace) {
printf(" %p %x\tcmf\tf%d, ", pc, *pc, lhs); runtime·printf(" %p %x\tcmf\tf%d, ", pc, *pc, lhs);
if (rhs & 0x8) if (rhs & 0x8)
printf("#%s\n", fpconst[rhs&0x7]); runtime·printf("#%s\n", fpconst[rhs&0x7]);
else else
printf("f%d\n", rhs&0x7); runtime·printf("f%d\n", rhs&0x7);
} }
regs[CPSR] = regs[CPSR] & 0x0fffffff | flags; regs[CPSR] = regs[CPSR] & 0x0fffffff | flags;
} }
...@@ -278,12 +278,12 @@ loadstore(uint32 *pc, uint32 *regs) ...@@ -278,12 +278,12 @@ loadstore(uint32 *pc, uint32 *regs)
if (tlen) if (tlen)
m->freg[freg] = *((uint64*)addr); m->freg[freg] = *((uint64*)addr);
else else
m->freg[freg] = s2d(*((uint32*)addr)); m->freg[freg] = runtime·s2d(*((uint32*)addr));
else else
if (tlen) if (tlen)
*((uint64*)addr) = m->freg[freg]; *((uint64*)addr) = m->freg[freg];
else else
*((uint32*)addr) = d2s(m->freg[freg]); *((uint32*)addr) = runtime·d2s(m->freg[freg]);
goto ret; goto ret;
undef: undef:
...@@ -292,18 +292,18 @@ undef: ...@@ -292,18 +292,18 @@ undef:
ret: ret:
if (trace || doabort) { if (trace || doabort) {
if (isload) if (isload)
printf(" %p %x\tldf", pc, *pc); runtime·printf(" %p %x\tldf", pc, *pc);
else else
printf(" %p %x\tstf", pc, *pc); runtime·printf(" %p %x\tstf", pc, *pc);
printf("%s\t\tf%d, %s%d(r%d)", fpprec[tlen], freg, ud ? "" : "-", offset, reg); runtime·printf("%s\t\tf%d, %s%d(r%d)", fpprec[tlen], freg, ud ? "" : "-", offset, reg);
printf("\t\t// %p", regs[reg] + (ud ? offset : -offset)); runtime·printf("\t\t// %p", regs[reg] + (ud ? offset : -offset));
if (coproc != 1 || p != 1 || wb != 0) if (coproc != 1 || p != 1 || wb != 0)
printf(" coproc: %d pre: %d wb %d", coproc, p, wb); runtime·printf(" coproc: %d pre: %d wb %d", coproc, p, wb);
printf("\n"); runtime·printf("\n");
fprint(); runtime·fprint();
} }
if (doabort) if (doabort)
fabort(); runtime·fabort();
} }
static void static void
...@@ -318,16 +318,16 @@ fltfix(uint32 *pc, uint32 *regs) ...@@ -318,16 +318,16 @@ fltfix(uint32 *pc, uint32 *regs)
toarm = i>>20 & 0x1; toarm = i>>20 & 0x1;
freg = i>>16 & 0x7; freg = i>>16 & 0x7;
reg = i>>12 & 0xf; reg = i>>12 & 0xf;
prec = precision(i); prec = runtime·precision(i);
if (toarm) { // fix if (toarm) { // fix
f0 = m->freg[freg]; f0 = m->freg[freg];
·f64tointc(f0, &val, &ok); runtime·f64tointc(f0, &val, &ok);
if (!ok || (int32)val != val) if (!ok || (int32)val != val)
val = 0; val = 0;
regs[reg] = val; regs[reg] = val;
} else { // flt } else { // flt
·fintto64c((int32)regs[reg], &f0); runtime·fintto64c((int32)regs[reg], &f0);
m->freg[freg] = f0; m->freg[freg] = f0;
} }
goto ret; goto ret;
...@@ -335,13 +335,13 @@ fltfix(uint32 *pc, uint32 *regs) ...@@ -335,13 +335,13 @@ fltfix(uint32 *pc, uint32 *regs)
ret: ret:
if (trace || doabort) { if (trace || doabort) {
if (toarm) if (toarm)
printf(" %p %x\tfix%s\t\tr%d, f%d\n", pc, *pc, fpprec[prec], reg, freg); runtime·printf(" %p %x\tfix%s\t\tr%d, f%d\n", pc, *pc, fpprec[prec], reg, freg);
else else
printf(" %p %x\tflt%s\t\tf%d, r%d\n", pc, *pc, fpprec[prec], freg, reg); runtime·printf(" %p %x\tflt%s\t\tf%d, r%d\n", pc, *pc, fpprec[prec], freg, reg);
fprint(); runtime·fprint();
} }
if (doabort) if (doabort)
fabort(); runtime·fabort();
} }
// returns number of words that the fp instruction is occupying, 0 if next instruction isn't float. // returns number of words that the fp instruction is occupying, 0 if next instruction isn't float.
...@@ -367,7 +367,7 @@ stepflt(uint32 *pc, uint32 *regs) ...@@ -367,7 +367,7 @@ stepflt(uint32 *pc, uint32 *regs)
c = i >> 25 & 7; c = i >> 25 & 7;
switch(c) { switch(c) {
case 6: // 110 case 6: // 110
loadstore(pc, regs); runtime·loadstore(pc, regs);
return 1; return 1;
case 7: // 111 case 7: // 111
if (i>>24 & 1) if (i>>24 & 1)
...@@ -375,15 +375,15 @@ stepflt(uint32 *pc, uint32 *regs) ...@@ -375,15 +375,15 @@ stepflt(uint32 *pc, uint32 *regs)
if (i>>4 & 1) { //data transfer if (i>>4 & 1) { //data transfer
if ((i&0x00f0ff00) == 0x0090f100) { if ((i&0x00f0ff00) == 0x0090f100) {
compare(pc, regs); runtime·compare(pc, regs);
} else if ((i&0x00e00f10) == 0x00000110) { } else if ((i&0x00e00f10) == 0x00000110) {
fltfix(pc, regs); runtime·fltfix(pc, regs);
} else { } else {
printf(" %p %x\t// case 7 fail\n", pc, i); runtime·printf(" %p %x\t// case 7 fail\n", pc, i);
fabort(); runtime·fabort();
} }
} else { } else {
dataprocess(pc); runtime·dataprocess(pc);
} }
return 1; return 1;
} }
...@@ -410,11 +410,11 @@ stepflt(uint32 *pc, uint32 *regs) ...@@ -410,11 +410,11 @@ stepflt(uint32 *pc, uint32 *regs)
#pragma textflag 7 #pragma textflag 7
uint32* uint32*
_sfloat2(uint32 *lr, uint32 r0) runtime·_sfloat2(uint32 *lr, uint32 r0)
{ {
uint32 skip; uint32 skip;
while(skip = stepflt(lr, &r0)) while(skip = runtime·stepflt(lr, &r0))
lr += skip; lr += skip;
return lr; return lr;
} }
......
...@@ -16,9 +16,9 @@ gentraceback(byte *pc0, byte *sp, byte *lr0, G *g, int32 skip, uintptr *pcbuf, i ...@@ -16,9 +16,9 @@ gentraceback(byte *pc0, byte *sp, byte *lr0, G *g, int32 skip, uintptr *pcbuf, i
lr = (uintptr)lr0; lr = (uintptr)lr0;
// If the PC is goexit, it hasn't started yet. // If the PC is goexit, it hasn't started yet.
if(pc == (uintptr)goexit) { if(pc == (uintptr)runtime·goexit) {
pc = (uintptr)g->entry; pc = (uintptr)g->entry;
lr = (uintptr)goexit; lr = (uintptr)runtime·goexit;
} }
// If the PC is zero, it's likely a nil function call. // If the PC is zero, it's likely a nil function call.
...@@ -31,7 +31,7 @@ gentraceback(byte *pc0, byte *sp, byte *lr0, G *g, int32 skip, uintptr *pcbuf, i ...@@ -31,7 +31,7 @@ gentraceback(byte *pc0, byte *sp, byte *lr0, G *g, int32 skip, uintptr *pcbuf, i
n = 0; n = 0;
stk = (Stktop*)g->stackbase; stk = (Stktop*)g->stackbase;
for(iter = 0; iter < 100 && n < m; iter++) { // iter avoids looping forever for(iter = 0; iter < 100 && n < m; iter++) { // iter avoids looping forever
if(pc == (uintptr)·lessstack) { if(pc == (uintptr)runtime·lessstack) {
// Hit top of stack segment. Unwind to next segment. // Hit top of stack segment. Unwind to next segment.
pc = (uintptr)stk->gobuf.pc; pc = (uintptr)stk->gobuf.pc;
sp = stk->gobuf.sp; sp = stk->gobuf.sp;
...@@ -39,7 +39,7 @@ gentraceback(byte *pc0, byte *sp, byte *lr0, G *g, int32 skip, uintptr *pcbuf, i ...@@ -39,7 +39,7 @@ gentraceback(byte *pc0, byte *sp, byte *lr0, G *g, int32 skip, uintptr *pcbuf, i
stk = (Stktop*)stk->stackbase; stk = (Stktop*)stk->stackbase;
continue; continue;
} }
if(pc <= 0x1000 || (f = findfunc(pc-4)) == nil) { if(pc <= 0x1000 || (f = runtime·findfunc(pc-4)) == nil) {
// TODO: Check for closure. // TODO: Check for closure.
break; break;
} }
...@@ -53,24 +53,24 @@ gentraceback(byte *pc0, byte *sp, byte *lr0, G *g, int32 skip, uintptr *pcbuf, i ...@@ -53,24 +53,24 @@ gentraceback(byte *pc0, byte *sp, byte *lr0, G *g, int32 skip, uintptr *pcbuf, i
// Print during crash. // Print during crash.
// main+0xf /home/rsc/go/src/runtime/x.go:23 // main+0xf /home/rsc/go/src/runtime/x.go:23
// main(0x1, 0x2, 0x3) // main(0x1, 0x2, 0x3)
printf("%S", f->name); runtime·printf("%S", f->name);
if(pc > f->entry) if(pc > f->entry)
printf("+%p", (uintptr)(pc - f->entry)); runtime·printf("+%p", (uintptr)(pc - f->entry));
tracepc = pc; // back up to CALL instruction for funcline. tracepc = pc; // back up to CALL instruction for funcline.
if(n > 0 && pc > f->entry) if(n > 0 && pc > f->entry)
tracepc -= sizeof(uintptr); tracepc -= sizeof(uintptr);
printf(" %S:%d\n", f->src, funcline(f, tracepc)); runtime·printf(" %S:%d\n", f->src, runtime·funcline(f, tracepc));
printf("\t%S(", f->name); runtime·printf("\t%S(", f->name);
for(i = 0; i < f->args; i++) { for(i = 0; i < f->args; i++) {
if(i != 0) if(i != 0)
prints(", "); runtime·prints(", ");
·printhex(((uintptr*)sp)[1+i]); runtime·printhex(((uintptr*)sp)[1+i]);
if(i >= 4) { if(i >= 4) {
prints(", ..."); runtime·prints(", ...");
break; break;
} }
} }
prints(")\n"); runtime·prints(")\n");
n++; n++;
} }
...@@ -85,19 +85,19 @@ gentraceback(byte *pc0, byte *sp, byte *lr0, G *g, int32 skip, uintptr *pcbuf, i ...@@ -85,19 +85,19 @@ gentraceback(byte *pc0, byte *sp, byte *lr0, G *g, int32 skip, uintptr *pcbuf, i
} }
void void
traceback(byte *pc0, byte *sp, byte *lr, G *g) runtime·traceback(byte *pc0, byte *sp, byte *lr, G *g)
{ {
gentraceback(pc0, sp, lr, g, 0, nil, 100); gentraceback(pc0, sp, lr, g, 0, nil, 100);
} }
// func caller(n int) (pc uintptr, file string, line int, ok bool) // func caller(n int) (pc uintptr, file string, line int, ok bool)
int32 int32
callers(int32 skip, uintptr *pcbuf, int32 m) runtime·callers(int32 skip, uintptr *pcbuf, int32 m)
{ {
byte *pc, *sp; byte *pc, *sp;
sp = getcallersp(&skip); sp = runtime·getcallersp(&skip);
pc = ·getcallerpc(&skip); pc = runtime·getcallerpc(&skip);
return gentraceback(pc, sp, 0, g, skip, pcbuf, m); return gentraceback(pc, sp, 0, g, skip, pcbuf, m);
} }
...@@ -30,7 +30,7 @@ arg=0 ...@@ -30,7 +30,7 @@ arg=0
/* replaced use of R10 by R11 because the former can be the data segment base register */ /* replaced use of R10 by R11 because the former can be the data segment base register */
TEXT _mulv(SB), $0 TEXT _mulv(SB), $0
MOVW 0(FP), R0 MOVW 0(FP), R0
MOVW 4(FP), R2 /* l0 */ MOVW 4(FP), R2 /* l0 */
MOVW 8(FP), R11 /* h0 */ MOVW 8(FP), R11 /* h0 */
...@@ -52,7 +52,7 @@ D = 2 ...@@ -52,7 +52,7 @@ D = 2
CC = 3 CC = 3
TMP = 11 TMP = 11
TEXT save<>(SB), 7, $0 TEXT save<>(SB), 7, $0
MOVW R(Q), 0(FP) MOVW R(Q), 0(FP)
MOVW R(N), 4(FP) MOVW R(N), 4(FP)
MOVW R(D), 8(FP) MOVW R(D), 8(FP)
...@@ -66,7 +66,7 @@ TEXT save<>(SB), 7, $0 ...@@ -66,7 +66,7 @@ TEXT save<>(SB), 7, $0
/* MOVW -1(R(D)), R(TMP) /* divide by zero fault */ /* MOVW -1(R(D)), R(TMP) /* divide by zero fault */
s1: RET s1: RET
TEXT rest<>(SB), 7, $0 TEXT rest<>(SB), 7, $0
MOVW 0(FP), R(Q) MOVW 0(FP), R(Q)
MOVW 4(FP), R(N) MOVW 4(FP), R(N)
MOVW 8(FP), R(D) MOVW 8(FP), R(D)
...@@ -79,7 +79,7 @@ TEXT rest<>(SB), 7, $0 ...@@ -79,7 +79,7 @@ TEXT rest<>(SB), 7, $0
ADD $20, R13 ADD $20, R13
B (R14) B (R14)
TEXT div<>(SB), 7, $0 TEXT div<>(SB), 7, $0
MOVW $32, R(CC) MOVW $32, R(CC)
/* /*
* skip zeros 8-at-a-time * skip zeros 8-at-a-time
...@@ -114,7 +114,7 @@ loop: ...@@ -114,7 +114,7 @@ loop:
BNE loop BNE loop
RET RET
TEXT _div(SB), 7, $16 TEXT _div(SB), 7, $16
BL save<>(SB) BL save<>(SB)
CMP $0, R(Q) CMP $0, R(Q)
BGE d1 BGE d1
...@@ -135,7 +135,7 @@ d2: ...@@ -135,7 +135,7 @@ d2:
RSB $0, R(Q), R(TMP) RSB $0, R(Q), R(TMP)
B out B out
TEXT _mod(SB), 7, $16 TEXT _mod(SB), 7, $16
BL save<>(SB) BL save<>(SB)
CMP $0, R(D) CMP $0, R(D)
RSB.LT $0, R(D), R(D) RSB.LT $0, R(D), R(D)
...@@ -150,13 +150,13 @@ m1: ...@@ -150,13 +150,13 @@ m1:
MOVW R(N), R(TMP) MOVW R(N), R(TMP)
B out B out
TEXT _divu(SB), 7, $16 TEXT _divu(SB), 7, $16
BL save<>(SB) BL save<>(SB)
BL div<>(SB) BL div<>(SB)
MOVW R(Q), R(TMP) MOVW R(Q), R(TMP)
B out B out
TEXT _modu(SB), 7, $16 TEXT _modu(SB), 7, $16
BL save<>(SB) BL save<>(SB)
BL div<>(SB) BL div<>(SB)
MOVW R(N), R(TMP) MOVW R(N), R(TMP)
...@@ -169,7 +169,7 @@ out: ...@@ -169,7 +169,7 @@ out:
// trampoline for _sfloat2. passes LR as arg0 and // trampoline for _sfloat2. passes LR as arg0 and
// saves registers R0-R13 and CPSR on the stack. R0-R12 and CPSR flags can // saves registers R0-R13 and CPSR on the stack. R0-R12 and CPSR flags can
// be changed by _sfloat2. // be changed by _sfloat2.
TEXT _sfloat(SB), 7, $64 // 4 arg + 14*4 saved regs + cpsr TEXT _sfloat(SB), 7, $64 // 4 arg + 14*4 saved regs + cpsr
MOVW R14, 4(R13) MOVW R14, 4(R13)
MOVW R0, 8(R13) MOVW R0, 8(R13)
MOVW $12(R13), R0 MOVW $12(R13), R0
......
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
// THE SOFTWARE. // THE SOFTWARE.
// declared here to avoid include of runtime.h // declared here to avoid include of runtime.h
void panicstring(char*); void runtime·panicstring(char*);
typedef unsigned long ulong; typedef unsigned long ulong;
typedef unsigned int uint; typedef unsigned int uint;
...@@ -35,9 +35,9 @@ typedef signed char schar; ...@@ -35,9 +35,9 @@ typedef signed char schar;
#define SIGN(n) (1UL<<(n-1)) #define SIGN(n) (1UL<<(n-1))
void void
panicdivide(void) runtime·panicdivide(void)
{ {
panicstring("integer divide by zero"); runtime·panicstring("integer divide by zero");
} }
typedef struct Vlong Vlong; typedef struct Vlong Vlong;
...@@ -60,7 +60,7 @@ struct Vlong ...@@ -60,7 +60,7 @@ struct Vlong
}; };
}; };
void abort(void); void runtime·abort(void);
void void
_addv(Vlong *r, Vlong a, Vlong b) _addv(Vlong *r, Vlong a, Vlong b)
...@@ -152,7 +152,7 @@ _f2v(Vlong *y, float f) ...@@ -152,7 +152,7 @@ _f2v(Vlong *y, float f)
} }
void void
·float64toint64(double d, Vlong y) runtime·float64toint64(double d, Vlong y)
{ {
_d2v(&y, d); _d2v(&y, d);
} }
...@@ -178,7 +178,7 @@ _v2f(Vlong x) ...@@ -178,7 +178,7 @@ _v2f(Vlong x)
} }
void void
·int64tofloat64(Vlong y, double d) runtime·int64tofloat64(Vlong y, double d)
{ {
d = _v2d(y); d = _v2d(y);
} }
...@@ -199,7 +199,7 @@ dodiv(Vlong num, Vlong den, Vlong *q, Vlong *r) ...@@ -199,7 +199,7 @@ dodiv(Vlong num, Vlong den, Vlong *q, Vlong *r)
* get a divide by zero * get a divide by zero
*/ */
if(denlo==0 && denhi==0) { if(denlo==0 && denhi==0) {
panicdivide(); runtime·panicdivide();
} }
/* /*
...@@ -259,7 +259,7 @@ _divvu(Vlong *q, Vlong n, Vlong d) ...@@ -259,7 +259,7 @@ _divvu(Vlong *q, Vlong n, Vlong d)
} }
void void
·uint64div(Vlong n, Vlong d, Vlong q) runtime·uint64div(Vlong n, Vlong d, Vlong q)
{ {
_divvu(&q, n, d); _divvu(&q, n, d);
} }
...@@ -277,7 +277,7 @@ _modvu(Vlong *r, Vlong n, Vlong d) ...@@ -277,7 +277,7 @@ _modvu(Vlong *r, Vlong n, Vlong d)
} }
void void
·uint64mod(Vlong n, Vlong d, Vlong q) runtime·uint64mod(Vlong n, Vlong d, Vlong q)
{ {
_modvu(&q, n, d); _modvu(&q, n, d);
} }
...@@ -322,7 +322,7 @@ _divv(Vlong *q, Vlong n, Vlong d) ...@@ -322,7 +322,7 @@ _divv(Vlong *q, Vlong n, Vlong d)
} }
void void
·int64div(Vlong n, Vlong d, Vlong q) runtime·int64div(Vlong n, Vlong d, Vlong q)
{ {
_divv(&q, n, d); _divv(&q, n, d);
} }
...@@ -349,7 +349,7 @@ _modv(Vlong *r, Vlong n, Vlong d) ...@@ -349,7 +349,7 @@ _modv(Vlong *r, Vlong n, Vlong d)
} }
void void
·int64mod(Vlong n, Vlong d, Vlong q) runtime·int64mod(Vlong n, Vlong d, Vlong q)
{ {
_modv(&q, n, d); _modv(&q, n, d);
} }
...@@ -502,7 +502,7 @@ _vasop(Vlong *ret, void *lv, void fn(Vlong*, Vlong, Vlong), int type, Vlong rv) ...@@ -502,7 +502,7 @@ _vasop(Vlong *ret, void *lv, void fn(Vlong*, Vlong, Vlong), int type, Vlong rv)
u = *ret; u = *ret;
switch(type) { switch(type) {
default: default:
abort(); runtime·abort();
break; break;
case 1: /* schar */ case 1: /* schar */
......
...@@ -7,16 +7,16 @@ ...@@ -7,16 +7,16 @@
void *initcgo; /* filled in by dynamic linker when Cgo is available */ void *initcgo; /* filled in by dynamic linker when Cgo is available */
int64 ncgocall; int64 ncgocall;
void ·entersyscall(void); void runtime·entersyscall(void);
void ·exitsyscall(void); void runtime·exitsyscall(void);
void void
cgocall(void (*fn)(void*), void *arg) runtime·cgocall(void (*fn)(void*), void *arg)
{ {
G *oldlock; G *oldlock;
if(initcgo == nil) if(initcgo == nil)
throw("cgocall unavailable"); runtime·throw("cgocall unavailable");
ncgocall++; ncgocall++;
...@@ -34,9 +34,9 @@ cgocall(void (*fn)(void*), void *arg) ...@@ -34,9 +34,9 @@ cgocall(void (*fn)(void*), void *arg)
* M to run goroutines while we are in the * M to run goroutines while we are in the
* foreign code. * foreign code.
*/ */
·entersyscall(); runtime·entersyscall();
runcgo(fn, arg); runtime·runcgo(fn, arg);
·exitsyscall(); runtime·exitsyscall();
m->lockedg = oldlock; m->lockedg = oldlock;
if(oldlock == nil) if(oldlock == nil)
...@@ -51,38 +51,38 @@ cgocall(void (*fn)(void*), void *arg) ...@@ -51,38 +51,38 @@ cgocall(void (*fn)(void*), void *arg)
// arguments back where they came from, and finally returns to the old // arguments back where they came from, and finally returns to the old
// stack. // stack.
void void
cgocallback(void (*fn)(void), void *arg, int32 argsize) runtime·cgocallback(void (*fn)(void), void *arg, int32 argsize)
{ {
Gobuf oldsched, oldg1sched; Gobuf oldsched, oldg1sched;
G *g1; G *g1;
void *sp; void *sp;
if(g != m->g0) if(g != m->g0)
throw("bad g in cgocallback"); runtime·throw("bad g in cgocallback");
g1 = m->curg; g1 = m->curg;
oldsched = m->sched; oldsched = m->sched;
oldg1sched = g1->sched; oldg1sched = g1->sched;
startcgocallback(g1); runtime·startcgocallback(g1);
sp = g1->sched.sp - argsize; sp = g1->sched.sp - argsize;
if(sp < g1->stackguard) if(sp < g1->stackguard)
throw("g stack overflow in cgocallback"); runtime·throw("g stack overflow in cgocallback");
mcpy(sp, arg, argsize); runtime·mcpy(sp, arg, argsize);
runcgocallback(g1, sp, fn); runtime·runcgocallback(g1, sp, fn);
mcpy(arg, sp, argsize); runtime·mcpy(arg, sp, argsize);
endcgocallback(g1); runtime·endcgocallback(g1);
m->sched = oldsched; m->sched = oldsched;
g1->sched = oldg1sched; g1->sched = oldg1sched;
} }
void void
·Cgocalls(int64 ret) runtime·Cgocalls(int64 ret)
{ {
ret = ncgocall; ret = ncgocall;
FLUSH(&ret); FLUSH(&ret);
...@@ -92,7 +92,7 @@ void (*_cgo_malloc)(void*); ...@@ -92,7 +92,7 @@ void (*_cgo_malloc)(void*);
void (*_cgo_free)(void*); void (*_cgo_free)(void*);
void* void*
cmalloc(uintptr n) runtime·cmalloc(uintptr n)
{ {
struct a { struct a {
uint64 n; uint64 n;
...@@ -101,13 +101,13 @@ cmalloc(uintptr n) ...@@ -101,13 +101,13 @@ cmalloc(uintptr n)
a.n = n; a.n = n;
a.ret = nil; a.ret = nil;
cgocall(_cgo_malloc, &a); runtime·cgocall(_cgo_malloc, &a);
return a.ret; return a.ret;
} }
void void
cfree(void *p) runtime·cfree(void *p)
{ {
cgocall(_cgo_free, p); runtime·cgocall(_cgo_free, p);
} }
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* Cgo interface. * Cgo interface.
*/ */
void cgocall(void (*fn)(void*), void*); void runtime·cgocall(void (*fn)(void*), void*);
void cgocallback(void (*fn)(void), void*, int32); void runtime·cgocallback(void (*fn)(void), void*, int32);
void *cmalloc(uintptr); void *runtime·cmalloc(uintptr);
void cfree(void*); void runtime·cfree(void*);
This diff is collapsed.
...@@ -7,34 +7,34 @@ ...@@ -7,34 +7,34 @@
typedef struct Complex128 Complex128; typedef struct Complex128 Complex128;
void void
·complex128div(Complex128 n, Complex128 d, Complex128 q) runtime·complex128div(Complex128 n, Complex128 d, Complex128 q)
{ {
int32 ninf, dinf, nnan, dnan; int32 ninf, dinf, nnan, dnan;
float64 a, b, ratio, denom; float64 a, b, ratio, denom;
// Special cases as in C99. // Special cases as in C99.
ninf = isInf(n.real, 0) || isInf(n.imag, 0); ninf = runtime·isInf(n.real, 0) || runtime·isInf(n.imag, 0);
dinf = isInf(d.real, 0) || isInf(d.imag, 0); dinf = runtime·isInf(d.real, 0) || runtime·isInf(d.imag, 0);
nnan = !ninf && (isNaN(n.real) || isNaN(n.imag)); nnan = !ninf && (runtime·isNaN(n.real) || runtime·isNaN(n.imag));
dnan = !dinf && (isNaN(d.real) || isNaN(d.imag)); dnan = !dinf && (runtime·isNaN(d.real) || runtime·isNaN(d.imag));
if(nnan || dnan) { if(nnan || dnan) {
q.real = NaN(); q.real = runtime·NaN();
q.imag = NaN(); q.imag = runtime·NaN();
} else if(ninf && !dinf && !dnan) { } else if(ninf && !dinf && !dnan) {
q.real = Inf(0); q.real = runtime·Inf(0);
q.imag = Inf(0); q.imag = runtime·Inf(0);
} else if(!ninf && !nnan && dinf) { } else if(!ninf && !nnan && dinf) {
q.real = 0; q.real = 0;
q.imag = 0; q.imag = 0;
} else if(d.real == 0 && d.imag == 0) { } else if(d.real == 0 && d.imag == 0) {
if(n.real == 0 && n.imag == 0) { if(n.real == 0 && n.imag == 0) {
q.real = NaN(); q.real = runtime·NaN();
q.imag = NaN(); q.imag = runtime·NaN();
} else { } else {
q.real = Inf(0); q.real = runtime·Inf(0);
q.imag = Inf(0); q.imag = runtime·Inf(0);
} }
} else { } else {
// Standard complex arithmetic, factored to avoid unnecessary overflow. // Standard complex arithmetic, factored to avoid unnecessary overflow.
......
...@@ -4,5 +4,5 @@ ...@@ -4,5 +4,5 @@
// Darwin and Linux use the same linkage to main // Darwin and Linux use the same linkage to main
TEXT _rt0_386_darwin(SB),7,$0 TEXT _rt0_386_darwin(SB),7,$0
JMP _rt0_386(SB) JMP _rt0_386(SB)
...@@ -8,39 +8,38 @@ ...@@ -8,39 +8,38 @@
#include "signals.h" #include "signals.h"
void void
dumpregs(Regs *r) runtime·dumpregs(Regs *r)
{ {
printf("eax %x\n", r->eax); runtime·printf("eax %x\n", r->eax);
printf("ebx %x\n", r->ebx); runtime·printf("ebx %x\n", r->ebx);
printf("ecx %x\n", r->ecx); runtime·printf("ecx %x\n", r->ecx);
printf("edx %x\n", r->edx); runtime·printf("edx %x\n", r->edx);
printf("edi %x\n", r->edi); runtime·printf("edi %x\n", r->edi);
printf("esi %x\n", r->esi); runtime·printf("esi %x\n", r->esi);
printf("ebp %x\n", r->ebp); runtime·printf("ebp %x\n", r->ebp);
printf("esp %x\n", r->esp); runtime·printf("esp %x\n", r->esp);
printf("eip %x\n", r->eip); runtime·printf("eip %x\n", r->eip);
printf("eflags %x\n", r->eflags); runtime·printf("eflags %x\n", r->eflags);
printf("cs %x\n", r->cs); runtime·printf("cs %x\n", r->cs);
printf("fs %x\n", r->fs); runtime·printf("fs %x\n", r->fs);
printf("gs %x\n", r->gs); runtime·printf("gs %x\n", r->gs);
} }
String String
signame(int32 sig) runtime·signame(int32 sig)
{ {
if(sig < 0 || sig >= NSIG) if(sig < 0 || sig >= NSIG)
return emptystring; return runtime·emptystring;
return gostringnocopy((byte*)sigtab[sig].name); return runtime·gostringnocopy((byte*)runtime·sigtab[sig].name);
} }
void void
sighandler(int32 sig, Siginfo *info, void *context) runtime·sighandler(int32 sig, Siginfo *info, void *context)
{ {
Ucontext *uc; Ucontext *uc;
Mcontext *mc; Mcontext *mc;
Regs *r; Regs *r;
uintptr *sp; uintptr *sp;
void (*fn)(void);
G *gp; G *gp;
byte *pc; byte *pc;
...@@ -48,7 +47,7 @@ sighandler(int32 sig, Siginfo *info, void *context) ...@@ -48,7 +47,7 @@ sighandler(int32 sig, Siginfo *info, void *context)
mc = uc->uc_mcontext; mc = uc->uc_mcontext;
r = &mc->ss; r = &mc->ss;
if((gp = m->curg) != nil && (sigtab[sig].flags & SigPanic)) { if((gp = m->curg) != nil && (runtime·sigtab[sig].flags & SigPanic)) {
// Work around Leopard bug that doesn't set FPE_INTDIV. // Work around Leopard bug that doesn't set FPE_INTDIV.
// Look at instruction to see if it is a divide. // Look at instruction to see if it is a divide.
// Not necessary in Snow Leopard (si_code will be != 0). // Not necessary in Snow Leopard (si_code will be != 0).
...@@ -68,91 +67,91 @@ sighandler(int32 sig, Siginfo *info, void *context) ...@@ -68,91 +67,91 @@ sighandler(int32 sig, Siginfo *info, void *context)
gp->sigcode0 = info->si_code; gp->sigcode0 = info->si_code;
gp->sigcode1 = (uintptr)info->si_addr; gp->sigcode1 = (uintptr)info->si_addr;
// Only push sigpanic if r->eip != 0. // Only push runtime·sigpanic if r->eip != 0.
// If r->eip == 0, probably panicked because of a // If r->eip == 0, probably panicked because of a
// call to a nil func. Not pushing that onto sp will // call to a nil func. Not pushing that onto sp will
// make the trace look like a call to sigpanic instead. // make the trace look like a call to runtime·sigpanic instead.
// (Otherwise the trace will end at sigpanic and we // (Otherwise the trace will end at runtime·sigpanic and we
// won't get to see who faulted.) // won't get to see who faulted.)
if(r->eip != 0) { if(r->eip != 0) {
sp = (uintptr*)r->esp; sp = (uintptr*)r->esp;
*--sp = r->eip; *--sp = r->eip;
r->esp = (uintptr)sp; r->esp = (uintptr)sp;
} }
r->eip = (uintptr)sigpanic; r->eip = (uintptr)runtime·sigpanic;
return; return;
} }
if(sigtab[sig].flags & SigQueue) { if(runtime·sigtab[sig].flags & SigQueue) {
if(sigsend(sig) || (sigtab[sig].flags & SigIgnore)) if(runtime·sigsend(sig) || (runtime·sigtab[sig].flags & SigIgnore))
return; return;
exit(2); // SIGINT, SIGTERM, etc runtime·exit(2); // SIGINT, SIGTERM, etc
} }
if(panicking) // traceback already printed if(runtime·panicking) // traceback already printed
exit(2); runtime·exit(2);
panicking = 1; runtime·panicking = 1;
if(sig < 0 || sig >= NSIG){ if(sig < 0 || sig >= NSIG){
printf("Signal %d\n", sig); runtime·printf("Signal %d\n", sig);
}else{ }else{
printf("%s\n", sigtab[sig].name); runtime·printf("%s\n", runtime·sigtab[sig].name);
} }
printf("pc: %x\n", r->eip); runtime·printf("pc: %x\n", r->eip);
printf("\n"); runtime·printf("\n");
if(gotraceback()){ if(runtime·gotraceback()){
traceback((void*)r->eip, (void*)r->esp, 0, m->curg); runtime·traceback((void*)r->eip, (void*)r->esp, 0, m->curg);
tracebackothers(m->curg); runtime·tracebackothers(m->curg);
dumpregs(r); runtime·dumpregs(r);
} }
breakpoint(); runtime·breakpoint();
exit(2); runtime·exit(2);
} }
void void
sigignore(int32, Siginfo*, void*) runtime·sigignore(int32, Siginfo*, void*)
{ {
} }
void void
signalstack(byte *p, int32 n) runtime·signalstack(byte *p, int32 n)
{ {
StackT st; StackT st;
st.ss_sp = p; st.ss_sp = p;
st.ss_size = n; st.ss_size = n;
st.ss_flags = 0; st.ss_flags = 0;
sigaltstack(&st, nil); runtime·sigaltstack(&st, nil);
} }
void void
initsig(int32 queue) runtime·initsig(int32 queue)
{ {
int32 i; int32 i;
static Sigaction sa; static Sigaction sa;
siginit(); runtime·siginit();
sa.sa_flags |= SA_SIGINFO|SA_ONSTACK; sa.sa_flags |= SA_SIGINFO|SA_ONSTACK;
sa.sa_mask = 0xFFFFFFFFU; sa.sa_mask = 0xFFFFFFFFU;
sa.sa_tramp = sigtramp; // sigtramp's job is to call into real handler sa.sa_tramp = runtime·sigtramp; // runtime·sigtramp's job is to call into real handler
for(i = 0; i<NSIG; i++) { for(i = 0; i<NSIG; i++) {
if(sigtab[i].flags) { if(runtime·sigtab[i].flags) {
if((sigtab[i].flags & SigQueue) != queue) if((runtime·sigtab[i].flags & SigQueue) != queue)
continue; continue;
if(sigtab[i].flags & (SigCatch | SigQueue)) { if(runtime·sigtab[i].flags & (SigCatch | SigQueue)) {
sa.__sigaction_u.__sa_sigaction = sighandler; sa.__sigaction_u.__sa_sigaction = runtime·sighandler;
} else { } else {
sa.__sigaction_u.__sa_sigaction = sigignore; sa.__sigaction_u.__sa_sigaction = runtime·sigignore;
} }
if(sigtab[i].flags & SigRestart) if(runtime·sigtab[i].flags & SigRestart)
sa.sa_flags |= SA_RESTART; sa.sa_flags |= SA_RESTART;
else else
sa.sa_flags &= ~SA_RESTART; sa.sa_flags &= ~SA_RESTART;
sigaction(i, &sa, nil); runtime·sigaction(i, &sa, nil);
} }
} }
} }
...@@ -8,47 +8,47 @@ ...@@ -8,47 +8,47 @@
#include "386/asm.h" #include "386/asm.h"
TEXT notok(SB),7,$0 TEXT runtime·notok(SB),7,$0
MOVL $0xf1, 0xf1 MOVL $0xf1, 0xf1
RET RET
// Exit the entire program (like C exit) // Exit the entire program (like C exit)
TEXT exit(SB),7,$0 TEXT runtime·exit(SB),7,$0
MOVL $1, AX MOVL $1, AX
INT $0x80 INT $0x80
CALL notok(SB) CALL runtime·notok(SB)
RET RET
// Exit this OS thread (like pthread_exit, which eventually // Exit this OS thread (like pthread_exit, which eventually
// calls __bsdthread_terminate). // calls __bsdthread_terminate).
TEXT exit1(SB),7,$0 TEXT runtime·exit1(SB),7,$0
MOVL $361, AX MOVL $361, AX
INT $0x80 INT $0x80
JAE 2(PC) JAE 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
TEXT write(SB),7,$0 TEXT runtime·write(SB),7,$0
MOVL $4, AX MOVL $4, AX
INT $0x80 INT $0x80
JAE 2(PC) JAE 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
TEXT ·mmap(SB),7,$0 TEXT runtime·mmap(SB),7,$0
MOVL $197, AX MOVL $197, AX
INT $0x80 INT $0x80
RET RET
TEXT ·munmap(SB),7,$0 TEXT runtime·munmap(SB),7,$0
MOVL $73, AX MOVL $73, AX
INT $0x80 INT $0x80
JAE 2(PC) JAE 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
// void gettime(int64 *sec, int32 *usec) // void gettime(int64 *sec, int32 *usec)
TEXT gettime(SB), 7, $32 TEXT runtime·gettime(SB), 7, $32
LEAL 12(SP), AX // must be non-nil, unused LEAL 12(SP), AX // must be non-nil, unused
MOVL AX, 4(SP) MOVL AX, 4(SP)
MOVL $0, 8(SP) // time zone pointer MOVL $0, 8(SP) // time zone pointer
...@@ -63,11 +63,11 @@ TEXT gettime(SB), 7, $32 ...@@ -63,11 +63,11 @@ TEXT gettime(SB), 7, $32
MOVL DX, (DI) MOVL DX, (DI)
RET RET
TEXT sigaction(SB),7,$0 TEXT runtime·sigaction(SB),7,$0
MOVL $46, AX MOVL $46, AX
INT $0x80 INT $0x80
JAE 2(PC) JAE 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
// Sigtramp's job is to call the actual signal handler. // Sigtramp's job is to call the actual signal handler.
...@@ -78,7 +78,7 @@ TEXT sigaction(SB),7,$0 ...@@ -78,7 +78,7 @@ TEXT sigaction(SB),7,$0
// 12(FP) signal number // 12(FP) signal number
// 16(FP) siginfo // 16(FP) siginfo
// 20(FP) context // 20(FP) context
TEXT sigtramp(SB),7,$40 TEXT runtime·sigtramp(SB),7,$40
get_tls(CX) get_tls(CX)
// save g // save g
...@@ -114,19 +114,19 @@ TEXT sigtramp(SB),7,$40 ...@@ -114,19 +114,19 @@ TEXT sigtramp(SB),7,$40
MOVL BX, 8(SP) MOVL BX, 8(SP)
MOVL $184, AX // sigreturn(ucontext, infostyle) MOVL $184, AX // sigreturn(ucontext, infostyle)
INT $0x80 INT $0x80
CALL notok(SB) CALL runtime·notok(SB)
RET RET
TEXT sigaltstack(SB),7,$0 TEXT runtime·sigaltstack(SB),7,$0
MOVL $53, AX MOVL $53, AX
INT $0x80 INT $0x80
JAE 2(PC) JAE 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
// void bsdthread_create(void *stk, M *m, G *g, void (*fn)(void)) // void bsdthread_create(void *stk, M *m, G *g, void (*fn)(void))
// System call args are: func arg stack pthread flags. // System call args are: func arg stack pthread flags.
TEXT bsdthread_create(SB),7,$32 TEXT runtime·bsdthread_create(SB),7,$32
MOVL $360, AX MOVL $360, AX
// 0(SP) is where the caller PC would be; kernel skips it // 0(SP) is where the caller PC would be; kernel skips it
MOVL func+12(FP), BX MOVL func+12(FP), BX
...@@ -155,7 +155,7 @@ TEXT bsdthread_create(SB),7,$32 ...@@ -155,7 +155,7 @@ TEXT bsdthread_create(SB),7,$32
// DI = stack top // DI = stack top
// SI = flags (= 0x1000000) // SI = flags (= 0x1000000)
// SP = stack - C_32_STK_ALIGN // SP = stack - C_32_STK_ALIGN
TEXT bsdthread_start(SB),7,$0 TEXT runtime·bsdthread_start(SB),7,$0
// set up ldt 7+id to point at m->tls. // set up ldt 7+id to point at m->tls.
// m->tls is at m+40. newosproc left // m->tls is at m+40. newosproc left
// the m->id in tls[0]. // the m->id in tls[0].
...@@ -167,7 +167,7 @@ TEXT bsdthread_start(SB),7,$0 ...@@ -167,7 +167,7 @@ TEXT bsdthread_start(SB),7,$0
PUSHL $32 // sizeof tls PUSHL $32 // sizeof tls
PUSHL BP // &tls PUSHL BP // &tls
PUSHL DI // tls # PUSHL DI // tls #
CALL setldt(SB) CALL runtime·setldt(SB)
POPL AX POPL AX
POPL AX POPL AX
POPL AX POPL AX
...@@ -178,18 +178,18 @@ TEXT bsdthread_start(SB),7,$0 ...@@ -178,18 +178,18 @@ TEXT bsdthread_start(SB),7,$0
MOVL AX, g(BP) MOVL AX, g(BP)
MOVL DX, m(BP) MOVL DX, m(BP)
MOVL BX, m_procid(DX) // m->procid = thread port (for debuggers) MOVL BX, m_procid(DX) // m->procid = thread port (for debuggers)
CALL stackcheck(SB) // smashes AX CALL runtime·stackcheck(SB) // smashes AX
CALL CX // fn() CALL CX // fn()
CALL exit1(SB) CALL runtime·exit1(SB)
RET RET
// void bsdthread_register(void) // void bsdthread_register(void)
// registers callbacks for threadstart (see bsdthread_create above // registers callbacks for threadstart (see bsdthread_create above
// and wqthread and pthsize (not used). returns 0 on success. // and wqthread and pthsize (not used). returns 0 on success.
TEXT bsdthread_register(SB),7,$40 TEXT runtime·bsdthread_register(SB),7,$40
MOVL $366, AX MOVL $366, AX
// 0(SP) is where kernel expects caller PC; ignored // 0(SP) is where kernel expects caller PC; ignored
MOVL $bsdthread_start(SB), 4(SP) // threadstart MOVL $runtime·bsdthread_start(SB), 4(SP) // threadstart
MOVL $0, 8(SP) // wqthread, not used by us MOVL $0, 8(SP) // wqthread, not used by us
MOVL $0, 12(SP) // pthsize, not used by us MOVL $0, 12(SP) // pthsize, not used by us
MOVL $0, 16(SP) // dummy_value [sic] MOVL $0, 16(SP) // dummy_value [sic]
...@@ -197,7 +197,7 @@ TEXT bsdthread_register(SB),7,$40 ...@@ -197,7 +197,7 @@ TEXT bsdthread_register(SB),7,$40
MOVL $0, 24(SP) // dispatchqueue_offset MOVL $0, 24(SP) // dispatchqueue_offset
INT $0x80 INT $0x80
JAE 2(PC) JAE 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
// Invoke Mach system call. // Invoke Mach system call.
...@@ -211,57 +211,57 @@ TEXT bsdthread_register(SB),7,$40 ...@@ -211,57 +211,57 @@ TEXT bsdthread_register(SB),7,$40
// in the high 16 bits that seems to be the // in the high 16 bits that seems to be the
// argument count in bytes but is not always. // argument count in bytes but is not always.
// INT $0x80 works fine for those. // INT $0x80 works fine for those.
TEXT sysenter(SB),7,$0 TEXT runtime·sysenter(SB),7,$0
POPL DX POPL DX
MOVL SP, CX MOVL SP, CX
BYTE $0x0F; BYTE $0x34; // SYSENTER BYTE $0x0F; BYTE $0x34; // SYSENTER
// returns to DX with SP set to CX // returns to DX with SP set to CX
TEXT mach_msg_trap(SB),7,$0 TEXT runtime·mach_msg_trap(SB),7,$0
MOVL $-31, AX MOVL $-31, AX
CALL sysenter(SB) CALL runtime·sysenter(SB)
RET RET
TEXT mach_reply_port(SB),7,$0 TEXT runtime·mach_reply_port(SB),7,$0
MOVL $-26, AX MOVL $-26, AX
CALL sysenter(SB) CALL runtime·sysenter(SB)
RET RET
TEXT mach_task_self(SB),7,$0 TEXT runtime·mach_task_self(SB),7,$0
MOVL $-28, AX MOVL $-28, AX
CALL sysenter(SB) CALL runtime·sysenter(SB)
RET RET
// Mach provides trap versions of the semaphore ops, // Mach provides trap versions of the semaphore ops,
// instead of requiring the use of RPC. // instead of requiring the use of RPC.
// uint32 mach_semaphore_wait(uint32) // uint32 mach_semaphore_wait(uint32)
TEXT mach_semaphore_wait(SB),7,$0 TEXT runtime·mach_semaphore_wait(SB),7,$0
MOVL $-36, AX MOVL $-36, AX
CALL sysenter(SB) CALL runtime·sysenter(SB)
RET RET
// uint32 mach_semaphore_timedwait(uint32, uint32, uint32) // uint32 mach_semaphore_timedwait(uint32, uint32, uint32)
TEXT mach_semaphore_timedwait(SB),7,$0 TEXT runtime·mach_semaphore_timedwait(SB),7,$0
MOVL $-38, AX MOVL $-38, AX
CALL sysenter(SB) CALL runtime·sysenter(SB)
RET RET
// uint32 mach_semaphore_signal(uint32) // uint32 mach_semaphore_signal(uint32)
TEXT mach_semaphore_signal(SB),7,$0 TEXT runtime·mach_semaphore_signal(SB),7,$0
MOVL $-33, AX MOVL $-33, AX
CALL sysenter(SB) CALL runtime·sysenter(SB)
RET RET
// uint32 mach_semaphore_signal_all(uint32) // uint32 mach_semaphore_signal_all(uint32)
TEXT mach_semaphore_signal_all(SB),7,$0 TEXT runtime·mach_semaphore_signal_all(SB),7,$0
MOVL $-34, AX MOVL $-34, AX
CALL sysenter(SB) CALL runtime·sysenter(SB)
RET RET
// setldt(int entry, int address, int limit) // setldt(int entry, int address, int limit)
// entry and limit are ignored. // entry and limit are ignored.
TEXT setldt(SB),7,$32 TEXT runtime·setldt(SB),7,$32
MOVL address+4(FP), BX // aka base MOVL address+4(FP), BX // aka base
/* /*
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// Darwin and Linux use the same linkage to main // Darwin and Linux use the same linkage to main
TEXT _rt0_amd64_darwin(SB),7,$-8 TEXT _rt0_amd64_darwin(SB),7,$-8
MOVQ $_rt0_amd64(SB), AX MOVQ $_rt0_amd64(SB), AX
MOVQ SP, DI MOVQ SP, DI
JMP AX JMP AX
...@@ -8,41 +8,41 @@ ...@@ -8,41 +8,41 @@
#include "signals.h" #include "signals.h"
void void
dumpregs(Regs *r) runtime·dumpregs(Regs *r)
{ {
printf("rax %X\n", r->rax); runtime·printf("rax %X\n", r->rax);
printf("rbx %X\n", r->rbx); runtime·printf("rbx %X\n", r->rbx);
printf("rcx %X\n", r->rcx); runtime·printf("rcx %X\n", r->rcx);
printf("rdx %X\n", r->rdx); runtime·printf("rdx %X\n", r->rdx);
printf("rdi %X\n", r->rdi); runtime·printf("rdi %X\n", r->rdi);
printf("rsi %X\n", r->rsi); runtime·printf("rsi %X\n", r->rsi);
printf("rbp %X\n", r->rbp); runtime·printf("rbp %X\n", r->rbp);
printf("rsp %X\n", r->rsp); runtime·printf("rsp %X\n", r->rsp);
printf("r8 %X\n", r->r8 ); runtime·printf("r8 %X\n", r->r8 );
printf("r9 %X\n", r->r9 ); runtime·printf("r9 %X\n", r->r9 );
printf("r10 %X\n", r->r10); runtime·printf("r10 %X\n", r->r10);
printf("r11 %X\n", r->r11); runtime·printf("r11 %X\n", r->r11);
printf("r12 %X\n", r->r12); runtime·printf("r12 %X\n", r->r12);
printf("r13 %X\n", r->r13); runtime·printf("r13 %X\n", r->r13);
printf("r14 %X\n", r->r14); runtime·printf("r14 %X\n", r->r14);
printf("r15 %X\n", r->r15); runtime·printf("r15 %X\n", r->r15);
printf("rip %X\n", r->rip); runtime·printf("rip %X\n", r->rip);
printf("rflags %X\n", r->rflags); runtime·printf("rflags %X\n", r->rflags);
printf("cs %X\n", r->cs); runtime·printf("cs %X\n", r->cs);
printf("fs %X\n", r->fs); runtime·printf("fs %X\n", r->fs);
printf("gs %X\n", r->gs); runtime·printf("gs %X\n", r->gs);
} }
String String
signame(int32 sig) runtime·signame(int32 sig)
{ {
if(sig < 0 || sig >= NSIG) if(sig < 0 || sig >= NSIG)
return emptystring; return runtime·emptystring;
return gostringnocopy((byte*)sigtab[sig].name); return runtime·gostringnocopy((byte*)runtime·sigtab[sig].name);
} }
void void
sighandler(int32 sig, Siginfo *info, void *context) runtime·sighandler(int32 sig, Siginfo *info, void *context)
{ {
Ucontext *uc; Ucontext *uc;
Mcontext *mc; Mcontext *mc;
...@@ -55,7 +55,7 @@ sighandler(int32 sig, Siginfo *info, void *context) ...@@ -55,7 +55,7 @@ sighandler(int32 sig, Siginfo *info, void *context)
mc = uc->uc_mcontext; mc = uc->uc_mcontext;
r = &mc->ss; r = &mc->ss;
if((gp = m->curg) != nil && (sigtab[sig].flags & SigPanic)) { if((gp = m->curg) != nil && (runtime·sigtab[sig].flags & SigPanic)) {
// Work around Leopard bug that doesn't set FPE_INTDIV. // Work around Leopard bug that doesn't set FPE_INTDIV.
// Look at instruction to see if it is a divide. // Look at instruction to see if it is a divide.
// Not necessary in Snow Leopard (si_code will be != 0). // Not necessary in Snow Leopard (si_code will be != 0).
...@@ -77,91 +77,91 @@ sighandler(int32 sig, Siginfo *info, void *context) ...@@ -77,91 +77,91 @@ sighandler(int32 sig, Siginfo *info, void *context)
gp->sigcode0 = info->si_code; gp->sigcode0 = info->si_code;
gp->sigcode1 = (uintptr)info->si_addr; gp->sigcode1 = (uintptr)info->si_addr;
// Only push sigpanic if r->rip != 0. // Only push runtime·sigpanic if r->rip != 0.
// If r->rip == 0, probably panicked because of a // If r->rip == 0, probably panicked because of a
// call to a nil func. Not pushing that onto sp will // call to a nil func. Not pushing that onto sp will
// make the trace look like a call to sigpanic instead. // make the trace look like a call to runtime·sigpanic instead.
// (Otherwise the trace will end at sigpanic and we // (Otherwise the trace will end at runtime·sigpanic and we
// won't get to see who faulted.) // won't get to see who faulted.)
if(r->rip != 0) { if(r->rip != 0) {
sp = (uintptr*)r->rsp; sp = (uintptr*)r->rsp;
*--sp = r->rip; *--sp = r->rip;
r->rsp = (uintptr)sp; r->rsp = (uintptr)sp;
} }
r->rip = (uintptr)sigpanic; r->rip = (uintptr)runtime·sigpanic;
return; return;
} }
if(sigtab[sig].flags & SigQueue) { if(runtime·sigtab[sig].flags & SigQueue) {
if(sigsend(sig) || (sigtab[sig].flags & SigIgnore)) if(runtime·sigsend(sig) || (runtime·sigtab[sig].flags & SigIgnore))
return; return;
exit(2); // SIGINT, SIGTERM, etc runtime·exit(2); // SIGINT, SIGTERM, etc
} }
if(panicking) // traceback already printed if(runtime·panicking) // traceback already printed
exit(2); runtime·exit(2);
panicking = 1; runtime·panicking = 1;
if(sig < 0 || sig >= NSIG){ if(sig < 0 || sig >= NSIG){
printf("Signal %d\n", sig); runtime·printf("Signal %d\n", sig);
}else{ }else{
printf("%s\n", sigtab[sig].name); runtime·printf("%s\n", runtime·sigtab[sig].name);
} }
printf("pc: %X\n", r->rip); runtime·printf("pc: %X\n", r->rip);
printf("\n"); runtime·printf("\n");
if(gotraceback()){ if(runtime·gotraceback()){
traceback((void*)r->rip, (void*)r->rsp, 0, g); runtime·traceback((void*)r->rip, (void*)r->rsp, 0, g);
tracebackothers(g); runtime·tracebackothers(g);
dumpregs(r); runtime·dumpregs(r);
} }
breakpoint(); runtime·breakpoint();
exit(2); runtime·exit(2);
} }
void void
sigignore(int32, Siginfo*, void*) runtime·sigignore(int32, Siginfo*, void*)
{ {
} }
void void
signalstack(byte *p, int32 n) runtime·signalstack(byte *p, int32 n)
{ {
StackT st; StackT st;
st.ss_sp = p; st.ss_sp = p;
st.ss_size = n; st.ss_size = n;
st.ss_flags = 0; st.ss_flags = 0;
sigaltstack(&st, nil); runtime·sigaltstack(&st, nil);
} }
void void
initsig(int32 queue) runtime·initsig(int32 queue)
{ {
int32 i; int32 i;
static Sigaction sa; static Sigaction sa;
siginit(); runtime·siginit();
sa.sa_flags |= SA_SIGINFO|SA_ONSTACK; sa.sa_flags |= SA_SIGINFO|SA_ONSTACK;
sa.sa_mask = 0xFFFFFFFFU; sa.sa_mask = 0xFFFFFFFFU;
sa.sa_tramp = sigtramp; // sigtramp's job is to call into real handler sa.sa_tramp = runtime·sigtramp; // runtime·sigtramp's job is to call into real handler
for(i = 0; i<NSIG; i++) { for(i = 0; i<NSIG; i++) {
if(sigtab[i].flags) { if(runtime·sigtab[i].flags) {
if((sigtab[i].flags & SigQueue) != queue) if((runtime·sigtab[i].flags & SigQueue) != queue)
continue; continue;
if(sigtab[i].flags & (SigCatch | SigQueue)) { if(runtime·sigtab[i].flags & (SigCatch | SigQueue)) {
sa.__sigaction_u.__sa_sigaction = sighandler; sa.__sigaction_u.__sa_sigaction = runtime·sighandler;
} else { } else {
sa.__sigaction_u.__sa_sigaction = sigignore; sa.__sigaction_u.__sa_sigaction = runtime·sigignore;
} }
if(sigtab[i].flags & SigRestart) if(runtime·sigtab[i].flags & SigRestart)
sa.sa_flags |= SA_RESTART; sa.sa_flags |= SA_RESTART;
else else
sa.sa_flags &= ~SA_RESTART; sa.sa_flags &= ~SA_RESTART;
sigaction(i, &sa, nil); runtime·sigaction(i, &sa, nil);
} }
} }
} }
...@@ -14,34 +14,34 @@ ...@@ -14,34 +14,34 @@
#include "amd64/asm.h" #include "amd64/asm.h"
// Exit the entire program (like C exit) // Exit the entire program (like C exit)
TEXT exit(SB),7,$0 TEXT runtime·exit(SB),7,$0
MOVL 8(SP), DI // arg 1 exit status MOVL 8(SP), DI // arg 1 exit status
MOVL $(0x2000000+1), AX // syscall entry MOVL $(0x2000000+1), AX // syscall entry
SYSCALL SYSCALL
CALL notok(SB) CALL runtime·notok(SB)
RET RET
// Exit this OS thread (like pthread_exit, which eventually // Exit this OS thread (like pthread_exit, which eventually
// calls __bsdthread_terminate). // calls __bsdthread_terminate).
TEXT exit1(SB),7,$0 TEXT runtime·exit1(SB),7,$0
MOVL 8(SP), DI // arg 1 exit status MOVL 8(SP), DI // arg 1 exit status
MOVL $(0x2000000+361), AX // syscall entry MOVL $(0x2000000+361), AX // syscall entry
SYSCALL SYSCALL
CALL notok(SB) CALL runtime·notok(SB)
RET RET
TEXT write(SB),7,$0 TEXT runtime·write(SB),7,$0
MOVL 8(SP), DI // arg 1 fd MOVL 8(SP), DI // arg 1 fd
MOVQ 16(SP), SI // arg 2 buf MOVQ 16(SP), SI // arg 2 buf
MOVL 24(SP), DX // arg 3 count MOVL 24(SP), DX // arg 3 count
MOVL $(0x2000000+4), AX // syscall entry MOVL $(0x2000000+4), AX // syscall entry
SYSCALL SYSCALL
JCC 2(PC) JCC 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
// void gettime(int64 *sec, int32 *usec) // void gettime(int64 *sec, int32 *usec)
TEXT gettime(SB), 7, $32 TEXT runtime·gettime(SB), 7, $32
MOVQ SP, DI // must be non-nil, unused MOVQ SP, DI // must be non-nil, unused
MOVQ $0, SI MOVQ $0, SI
MOVQ $(0x2000000+116), AX MOVQ $(0x2000000+116), AX
...@@ -52,7 +52,7 @@ TEXT gettime(SB), 7, $32 ...@@ -52,7 +52,7 @@ TEXT gettime(SB), 7, $32
MOVL DX, (DI) MOVL DX, (DI)
RET RET
TEXT sigaction(SB),7,$0 TEXT runtime·sigaction(SB),7,$0
MOVL 8(SP), DI // arg 1 sig MOVL 8(SP), DI // arg 1 sig
MOVQ 16(SP), SI // arg 2 act MOVQ 16(SP), SI // arg 2 act
MOVQ 24(SP), DX // arg 3 oact MOVQ 24(SP), DX // arg 3 oact
...@@ -61,10 +61,10 @@ TEXT sigaction(SB),7,$0 ...@@ -61,10 +61,10 @@ TEXT sigaction(SB),7,$0
MOVL $(0x2000000+46), AX // syscall entry MOVL $(0x2000000+46), AX // syscall entry
SYSCALL SYSCALL
JCC 2(PC) JCC 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
TEXT sigtramp(SB),7,$64 TEXT runtime·sigtramp(SB),7,$64
get_tls(BX) get_tls(BX)
// save g // save g
...@@ -94,7 +94,7 @@ TEXT sigtramp(SB),7,$64 ...@@ -94,7 +94,7 @@ TEXT sigtramp(SB),7,$64
SYSCALL SYSCALL
INT $3 // not reached INT $3 // not reached
TEXT ·mmap(SB),7,$0 TEXT runtime·mmap(SB),7,$0
MOVQ 8(SP), DI // arg 1 addr MOVQ 8(SP), DI // arg 1 addr
MOVQ 16(SP), SI // arg 2 len MOVQ 16(SP), SI // arg 2 len
MOVL 24(SP), DX // arg 3 prot MOVL 24(SP), DX // arg 3 prot
...@@ -105,31 +105,31 @@ TEXT ·mmap(SB),7,$0 ...@@ -105,31 +105,31 @@ TEXT ·mmap(SB),7,$0
SYSCALL SYSCALL
RET RET
TEXT ·munmap(SB),7,$0 TEXT runtime·munmap(SB),7,$0
MOVQ 8(SP), DI // arg 1 addr MOVQ 8(SP), DI // arg 1 addr
MOVQ 16(SP), SI // arg 2 len MOVQ 16(SP), SI // arg 2 len
MOVL $(0x2000000+73), AX // syscall entry MOVL $(0x2000000+73), AX // syscall entry
SYSCALL SYSCALL
JCC 2(PC) JCC 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
TEXT notok(SB),7,$0 TEXT runtime·notok(SB),7,$0
MOVL $0xf1, BP MOVL $0xf1, BP
MOVQ BP, (BP) MOVQ BP, (BP)
RET RET
TEXT sigaltstack(SB),7,$0 TEXT runtime·sigaltstack(SB),7,$0
MOVQ new+8(SP), DI MOVQ new+8(SP), DI
MOVQ old+16(SP), SI MOVQ old+16(SP), SI
MOVQ $(0x2000000+53), AX MOVQ $(0x2000000+53), AX
SYSCALL SYSCALL
JCC 2(PC) JCC 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
// void bsdthread_create(void *stk, M *m, G *g, void (*fn)(void)) // void bsdthread_create(void *stk, M *m, G *g, void (*fn)(void))
TEXT bsdthread_create(SB),7,$0 TEXT runtime·bsdthread_create(SB),7,$0
// Set up arguments to bsdthread_create system call. // Set up arguments to bsdthread_create system call.
// The ones in quotes pass through to the thread callback // The ones in quotes pass through to the thread callback
// uninterpreted, so we can put whatever we want there. // uninterpreted, so we can put whatever we want there.
...@@ -158,7 +158,7 @@ TEXT bsdthread_create(SB),7,$0 ...@@ -158,7 +158,7 @@ TEXT bsdthread_create(SB),7,$0
// R8 = stack // R8 = stack
// R9 = flags (= 0) // R9 = flags (= 0)
// SP = stack - C_64_REDZONE_LEN (= stack - 128) // SP = stack - C_64_REDZONE_LEN (= stack - 128)
TEXT bsdthread_start(SB),7,$0 TEXT runtime·bsdthread_start(SB),7,$0
MOVQ R8, SP // empirically, SP is very wrong but R8 is right MOVQ R8, SP // empirically, SP is very wrong but R8 is right
PUSHQ DX PUSHQ DX
...@@ -167,7 +167,7 @@ TEXT bsdthread_start(SB),7,$0 ...@@ -167,7 +167,7 @@ TEXT bsdthread_start(SB),7,$0
// set up thread local storage pointing at m->tls. // set up thread local storage pointing at m->tls.
LEAQ m_tls(CX), DI LEAQ m_tls(CX), DI
CALL settls(SB) CALL runtime·settls(SB)
POPQ SI POPQ SI
POPQ CX POPQ CX
...@@ -178,16 +178,16 @@ TEXT bsdthread_start(SB),7,$0 ...@@ -178,16 +178,16 @@ TEXT bsdthread_start(SB),7,$0
MOVQ SI, m_procid(CX) // thread port is m->procid MOVQ SI, m_procid(CX) // thread port is m->procid
MOVQ m_g0(CX), AX MOVQ m_g0(CX), AX
MOVQ AX, g(BX) MOVQ AX, g(BX)
CALL stackcheck(SB) // smashes AX, CX CALL runtime·stackcheck(SB) // smashes AX, CX
CALL DX // fn CALL DX // fn
CALL exit1(SB) CALL runtime·exit1(SB)
RET RET
// void bsdthread_register(void) // void bsdthread_register(void)
// registers callbacks for threadstart (see bsdthread_create above // registers callbacks for threadstart (see bsdthread_create above
// and wqthread and pthsize (not used). returns 0 on success. // and wqthread and pthsize (not used). returns 0 on success.
TEXT bsdthread_register(SB),7,$0 TEXT runtime·bsdthread_register(SB),7,$0
MOVQ $bsdthread_start(SB), DI // threadstart MOVQ $runtime·bsdthread_start(SB), DI // threadstart
MOVQ $0, SI // wqthread, not used by us MOVQ $0, SI // wqthread, not used by us
MOVQ $0, DX // pthsize, not used by us MOVQ $0, DX // pthsize, not used by us
MOVQ $0, R10 // dummy_value [sic] MOVQ $0, R10 // dummy_value [sic]
...@@ -196,13 +196,13 @@ TEXT bsdthread_register(SB),7,$0 ...@@ -196,13 +196,13 @@ TEXT bsdthread_register(SB),7,$0
MOVQ $(0x2000000+366), AX // bsdthread_register MOVQ $(0x2000000+366), AX // bsdthread_register
SYSCALL SYSCALL
JCC 2(PC) JCC 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
// Mach system calls use 0x1000000 instead of the BSD's 0x2000000. // Mach system calls use 0x1000000 instead of the BSD's 0x2000000.
// uint32 mach_msg_trap(void*, uint32, uint32, uint32, uint32, uint32, uint32) // uint32 mach_msg_trap(void*, uint32, uint32, uint32, uint32, uint32, uint32)
TEXT mach_msg_trap(SB),7,$0 TEXT runtime·mach_msg_trap(SB),7,$0
MOVQ 8(SP), DI MOVQ 8(SP), DI
MOVL 16(SP), SI MOVL 16(SP), SI
MOVL 20(SP), DX MOVL 20(SP), DX
...@@ -216,17 +216,17 @@ TEXT mach_msg_trap(SB),7,$0 ...@@ -216,17 +216,17 @@ TEXT mach_msg_trap(SB),7,$0
POPQ R11 POPQ R11
RET RET
TEXT mach_task_self(SB),7,$0 TEXT runtime·mach_task_self(SB),7,$0
MOVL $(0x1000000+28), AX // task_self_trap MOVL $(0x1000000+28), AX // task_self_trap
SYSCALL SYSCALL
RET RET
TEXT mach_thread_self(SB),7,$0 TEXT runtime·mach_thread_self(SB),7,$0
MOVL $(0x1000000+27), AX // thread_self_trap MOVL $(0x1000000+27), AX // thread_self_trap
SYSCALL SYSCALL
RET RET
TEXT mach_reply_port(SB),7,$0 TEXT runtime·mach_reply_port(SB),7,$0
MOVL $(0x1000000+26), AX // mach_reply_port MOVL $(0x1000000+26), AX // mach_reply_port
SYSCALL SYSCALL
RET RET
...@@ -235,14 +235,14 @@ TEXT mach_reply_port(SB),7,$0 ...@@ -235,14 +235,14 @@ TEXT mach_reply_port(SB),7,$0
// instead of requiring the use of RPC. // instead of requiring the use of RPC.
// uint32 mach_semaphore_wait(uint32) // uint32 mach_semaphore_wait(uint32)
TEXT mach_semaphore_wait(SB),7,$0 TEXT runtime·mach_semaphore_wait(SB),7,$0
MOVL 8(SP), DI MOVL 8(SP), DI
MOVL $(0x1000000+36), AX // semaphore_wait_trap MOVL $(0x1000000+36), AX // semaphore_wait_trap
SYSCALL SYSCALL
RET RET
// uint32 mach_semaphore_timedwait(uint32, uint32, uint32) // uint32 mach_semaphore_timedwait(uint32, uint32, uint32)
TEXT mach_semaphore_timedwait(SB),7,$0 TEXT runtime·mach_semaphore_timedwait(SB),7,$0
MOVL 8(SP), DI MOVL 8(SP), DI
MOVL 12(SP), SI MOVL 12(SP), SI
MOVL 16(SP), DX MOVL 16(SP), DX
...@@ -251,21 +251,21 @@ TEXT mach_semaphore_timedwait(SB),7,$0 ...@@ -251,21 +251,21 @@ TEXT mach_semaphore_timedwait(SB),7,$0
RET RET
// uint32 mach_semaphore_signal(uint32) // uint32 mach_semaphore_signal(uint32)
TEXT mach_semaphore_signal(SB),7,$0 TEXT runtime·mach_semaphore_signal(SB),7,$0
MOVL 8(SP), DI MOVL 8(SP), DI
MOVL $(0x1000000+33), AX // semaphore_signal_trap MOVL $(0x1000000+33), AX // semaphore_signal_trap
SYSCALL SYSCALL
RET RET
// uint32 mach_semaphore_signal_all(uint32) // uint32 mach_semaphore_signal_all(uint32)
TEXT mach_semaphore_signal_all(SB),7,$0 TEXT runtime·mach_semaphore_signal_all(SB),7,$0
MOVL 8(SP), DI MOVL 8(SP), DI
MOVL $(0x1000000+34), AX // semaphore_signal_all_trap MOVL $(0x1000000+34), AX // semaphore_signal_all_trap
SYSCALL SYSCALL
RET RET
// set tls base to DI // set tls base to DI
TEXT settls(SB),7,$32 TEXT runtime·settls(SB),7,$32
/* /*
* Same as in ../386/sys.s:/ugliness, different constant. * Same as in ../386/sys.s:/ugliness, different constant.
* See ../../../../libcgo/darwin_amd64.c for the derivation * See ../../../../libcgo/darwin_amd64.c for the derivation
......
...@@ -4,21 +4,21 @@ ...@@ -4,21 +4,21 @@
#include "malloc.h" #include "malloc.h"
void* void*
SysAlloc(uintptr n) runtime·SysAlloc(uintptr n)
{ {
void *v; void *v;
mstats.sys += n; mstats.sys += n;
v = runtime_mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0); v = runtime·mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
if(v < (void*)4096) { if(v < (void*)4096) {
printf("mmap: errno=%p\n", v); runtime·printf("mmap: errno=%p\n", v);
throw("mmap"); runtime·throw("mmap");
} }
return v; return v;
} }
void void
SysUnused(void *v, uintptr n) runtime·SysUnused(void *v, uintptr n)
{ {
USED(v); USED(v);
USED(n); USED(n);
...@@ -26,15 +26,15 @@ SysUnused(void *v, uintptr n) ...@@ -26,15 +26,15 @@ SysUnused(void *v, uintptr n)
} }
void void
SysFree(void *v, uintptr n) runtime·SysFree(void *v, uintptr n)
{ {
mstats.sys -= n; mstats.sys -= n;
runtime_munmap(v, n); runtime·munmap(v, n);
} }
void void
SysMemInit(void) runtime·SysMemInit(void)
{ {
// Code generators assume that references to addresses // Code generators assume that references to addresses
// on the first page will fault. Map the page explicitly with // on the first page will fault. Map the page explicitly with
...@@ -42,5 +42,5 @@ SysMemInit(void) ...@@ -42,5 +42,5 @@ SysMemInit(void)
// allocating that page as the virtual address space fills. // allocating that page as the virtual address space fills.
// Ignore any error, since other systems might be smart // Ignore any error, since other systems might be smart
// enough to never allow anything there. // enough to never allow anything there.
// runtime_mmap(nil, 4096, PROT_NONE, MAP_FIXED|MAP_ANON|MAP_PRIVATE, -1, 0); // mmap(nil, 4096, PROT_NONE, MAP_FIXED|MAP_ANON|MAP_PRIVATE, -1, 0);
} }
...@@ -2,24 +2,24 @@ ...@@ -2,24 +2,24 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
int32 bsdthread_create(void*, M*, G*, void(*)(void)); int32 runtime·bsdthread_create(void*, M*, G*, void(*)(void));
void bsdthread_register(void); void runtime·bsdthread_register(void);
int32 mach_msg_trap(MachHeader*, int32, uint32, uint32, uint32, uint32, uint32); int32 runtime·mach_msg_trap(MachHeader*, int32, uint32, uint32, uint32, uint32, uint32);
uint32 mach_reply_port(void); uint32 runtime·mach_reply_port(void);
void mach_semacquire(uint32); void runtime·mach_semacquire(uint32);
uint32 mach_semcreate(void); uint32 runtime·mach_semcreate(void);
void mach_semdestroy(uint32); void runtime·mach_semdestroy(uint32);
void mach_semrelease(uint32); void runtime·mach_semrelease(uint32);
void mach_semreset(uint32); void runtime·mach_semreset(uint32);
uint32 mach_task_self(void); uint32 runtime·mach_task_self(void);
uint32 mach_task_self(void); uint32 runtime·mach_task_self(void);
uint32 mach_thread_self(void); uint32 runtime·mach_thread_self(void);
uint32 mach_thread_self(void); uint32 runtime·mach_thread_self(void);
struct Sigaction; struct Sigaction;
void sigaction(uintptr, struct Sigaction*, struct Sigaction*); void runtime·sigaction(uintptr, struct Sigaction*, struct Sigaction*);
struct StackT; struct StackT;
void sigaltstack(struct StackT*, struct StackT*); void runtime·sigaltstack(struct StackT*, struct StackT*);
void sigtramp(void); void runtime·sigtramp(void);
void sigpanic(void); void runtime·sigpanic(void);
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#define Q SigQueue #define Q SigQueue
#define P SigPanic #define P SigPanic
SigTab sigtab[] = { SigTab runtime·sigtab[] = {
/* 0 */ 0, "SIGNONE: no trap", /* 0 */ 0, "SIGNONE: no trap",
/* 1 */ Q+R, "SIGHUP: terminal line hangup", /* 1 */ Q+R, "SIGHUP: terminal line hangup",
/* 2 */ Q+R, "SIGINT: interrupt", /* 2 */ Q+R, "SIGINT: interrupt",
......
This diff is collapsed.
...@@ -9,7 +9,7 @@ static uint64 uvinf = 0x7FF0000000000000ULL; ...@@ -9,7 +9,7 @@ static uint64 uvinf = 0x7FF0000000000000ULL;
static uint64 uvneginf = 0xFFF0000000000000ULL; static uint64 uvneginf = 0xFFF0000000000000ULL;
uint32 uint32
float32tobits(float32 f) runtime·float32tobits(float32 f)
{ {
// The obvious cast-and-pointer code is technically // The obvious cast-and-pointer code is technically
// not valid, and gcc miscompiles it. Use a union instead. // not valid, and gcc miscompiles it. Use a union instead.
...@@ -22,7 +22,7 @@ float32tobits(float32 f) ...@@ -22,7 +22,7 @@ float32tobits(float32 f)
} }
uint64 uint64
float64tobits(float64 f) runtime·float64tobits(float64 f)
{ {
// The obvious cast-and-pointer code is technically // The obvious cast-and-pointer code is technically
// not valid, and gcc miscompiles it. Use a union instead. // not valid, and gcc miscompiles it. Use a union instead.
...@@ -35,7 +35,7 @@ float64tobits(float64 f) ...@@ -35,7 +35,7 @@ float64tobits(float64 f)
} }
float64 float64
float64frombits(uint64 i) runtime·float64frombits(uint64 i)
{ {
// The obvious cast-and-pointer code is technically // The obvious cast-and-pointer code is technically
// not valid, and gcc miscompiles it. Use a union instead. // not valid, and gcc miscompiles it. Use a union instead.
...@@ -48,7 +48,7 @@ float64frombits(uint64 i) ...@@ -48,7 +48,7 @@ float64frombits(uint64 i)
} }
float32 float32
float32frombits(uint32 i) runtime·float32frombits(uint32 i)
{ {
// The obvious cast-and-pointer code is technically // The obvious cast-and-pointer code is technically
// not valid, and gcc miscompiles it. Use a union instead. // not valid, and gcc miscompiles it. Use a union instead.
...@@ -61,11 +61,11 @@ float32frombits(uint32 i) ...@@ -61,11 +61,11 @@ float32frombits(uint32 i)
} }
bool bool
isInf(float64 f, int32 sign) runtime·isInf(float64 f, int32 sign)
{ {
uint64 x; uint64 x;
x = float64tobits(f); x = runtime·float64tobits(f);
if(sign == 0) if(sign == 0)
return x == uvinf || x == uvneginf; return x == uvinf || x == uvneginf;
if(sign > 0) if(sign > 0)
...@@ -74,27 +74,27 @@ isInf(float64 f, int32 sign) ...@@ -74,27 +74,27 @@ isInf(float64 f, int32 sign)
} }
float64 float64
NaN(void) runtime·NaN(void)
{ {
return float64frombits(uvnan); return runtime·float64frombits(uvnan);
} }
bool bool
isNaN(float64 f) runtime·isNaN(float64 f)
{ {
uint64 x; uint64 x;
x = float64tobits(f); x = runtime·float64tobits(f);
return ((uint32)(x>>52) & 0x7FF) == 0x7FF && !isInf(f, 0); return ((uint32)(x>>52) & 0x7FF) == 0x7FF && !runtime·isInf(f, 0);
} }
float64 float64
Inf(int32 sign) runtime·Inf(int32 sign)
{ {
if(sign >= 0) if(sign >= 0)
return float64frombits(uvinf); return runtime·float64frombits(uvinf);
else else
return float64frombits(uvneginf); return runtime·float64frombits(uvneginf);
} }
enum enum
...@@ -105,7 +105,7 @@ enum ...@@ -105,7 +105,7 @@ enum
}; };
float64 float64
frexp(float64 d, int32 *ep) runtime·frexp(float64 d, int32 *ep)
{ {
uint64 x; uint64 x;
...@@ -113,36 +113,36 @@ frexp(float64 d, int32 *ep) ...@@ -113,36 +113,36 @@ frexp(float64 d, int32 *ep)
*ep = 0; *ep = 0;
return 0; return 0;
} }
x = float64tobits(d); x = runtime·float64tobits(d);
*ep = (int32)((x >> SHIFT) & MASK) - BIAS; *ep = (int32)((x >> SHIFT) & MASK) - BIAS;
x &= ~((uint64)MASK << SHIFT); x &= ~((uint64)MASK << SHIFT);
x |= (uint64)BIAS << SHIFT; x |= (uint64)BIAS << SHIFT;
return float64frombits(x); return runtime·float64frombits(x);
} }
float64 float64
ldexp(float64 d, int32 e) runtime·ldexp(float64 d, int32 e)
{ {
uint64 x; uint64 x;
if(d == 0) if(d == 0)
return 0; return 0;
x = float64tobits(d); x = runtime·float64tobits(d);
e += (int32)(x >> SHIFT) & MASK; e += (int32)(x >> SHIFT) & MASK;
if(e <= 0) if(e <= 0)
return 0; /* underflow */ return 0; /* underflow */
if(e >= MASK){ /* overflow */ if(e >= MASK){ /* overflow */
if(d < 0) if(d < 0)
return Inf(-1); return runtime·Inf(-1);
return Inf(1); return runtime·Inf(1);
} }
x &= ~((uint64)MASK << SHIFT); x &= ~((uint64)MASK << SHIFT);
x |= (uint64)e << SHIFT; x |= (uint64)e << SHIFT;
return float64frombits(x); return runtime·float64frombits(x);
} }
float64 float64
modf(float64 d, float64 *ip) runtime·modf(float64 d, float64 *ip)
{ {
float64 dd; float64 dd;
uint64 x; uint64 x;
...@@ -150,7 +150,7 @@ modf(float64 d, float64 *ip) ...@@ -150,7 +150,7 @@ modf(float64 d, float64 *ip)
if(d < 1) { if(d < 1) {
if(d < 0) { if(d < 0) {
d = modf(-d, ip); d = runtime·modf(-d, ip);
*ip = -*ip; *ip = -*ip;
return -d; return -d;
} }
...@@ -158,7 +158,7 @@ modf(float64 d, float64 *ip) ...@@ -158,7 +158,7 @@ modf(float64 d, float64 *ip)
return d; return d;
} }
x = float64tobits(d); x = runtime·float64tobits(d);
e = (int32)((x >> SHIFT) & MASK) - BIAS; e = (int32)((x >> SHIFT) & MASK) - BIAS;
/* /*
...@@ -166,7 +166,7 @@ modf(float64 d, float64 *ip) ...@@ -166,7 +166,7 @@ modf(float64 d, float64 *ip)
*/ */
if(e <= 64-11) if(e <= 64-11)
x &= ~(((uint64)1 << (64LL-11LL-e))-1); x &= ~(((uint64)1 << (64LL-11LL-e))-1);
dd = float64frombits(x); dd = runtime·float64frombits(x);
*ip = dd; *ip = dd;
return d - dd; return d - dd;
} }
......
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
// Darwin and Linux use the same linkage to main // Darwin and Linux use the same linkage to main
TEXT _rt0_386_freebsd(SB),7,$0 TEXT _rt0_386_freebsd(SB),7,$0
JMP _rt0_386(SB) JMP _rt0_386(SB)
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "signals.h" #include "signals.h"
#include "os.h" #include "os.h"
extern void sigtramp(void); extern void runtime·sigtramp(void);
typedef struct sigaction { typedef struct sigaction {
union { union {
...@@ -19,33 +19,33 @@ typedef struct sigaction { ...@@ -19,33 +19,33 @@ typedef struct sigaction {
} Sigaction; } Sigaction;
void void
dumpregs(Mcontext *r) runtime·dumpregs(Mcontext *r)
{ {
printf("eax %x\n", r->mc_eax); runtime·printf("eax %x\n", r->mc_eax);
printf("ebx %x\n", r->mc_ebx); runtime·printf("ebx %x\n", r->mc_ebx);
printf("ecx %x\n", r->mc_ecx); runtime·printf("ecx %x\n", r->mc_ecx);
printf("edx %x\n", r->mc_edx); runtime·printf("edx %x\n", r->mc_edx);
printf("edi %x\n", r->mc_edi); runtime·printf("edi %x\n", r->mc_edi);
printf("esi %x\n", r->mc_esi); runtime·printf("esi %x\n", r->mc_esi);
printf("ebp %x\n", r->mc_ebp); runtime·printf("ebp %x\n", r->mc_ebp);
printf("esp %x\n", r->mc_esp); runtime·printf("esp %x\n", r->mc_esp);
printf("eip %x\n", r->mc_eip); runtime·printf("eip %x\n", r->mc_eip);
printf("eflags %x\n", r->mc_eflags); runtime·printf("eflags %x\n", r->mc_eflags);
printf("cs %x\n", r->mc_cs); runtime·printf("cs %x\n", r->mc_cs);
printf("fs %x\n", r->mc_fs); runtime·printf("fs %x\n", r->mc_fs);
printf("gs %x\n", r->mc_gs); runtime·printf("gs %x\n", r->mc_gs);
} }
String String
signame(int32 sig) runtime·signame(int32 sig)
{ {
if(sig < 0 || sig >= NSIG) if(sig < 0 || sig >= NSIG)
return emptystring; return runtime·emptystring;
return gostringnocopy((byte*)sigtab[sig].name); return runtime·gostringnocopy((byte*)runtime·sigtab[sig].name);
} }
void void
sighandler(int32 sig, Siginfo* info, void* context) runtime·sighandler(int32 sig, Siginfo* info, void* context)
{ {
Ucontext *uc; Ucontext *uc;
Mcontext *r; Mcontext *r;
...@@ -55,7 +55,7 @@ sighandler(int32 sig, Siginfo* info, void* context) ...@@ -55,7 +55,7 @@ sighandler(int32 sig, Siginfo* info, void* context)
uc = context; uc = context;
r = &uc->uc_mcontext; r = &uc->uc_mcontext;
if((gp = m->curg) != nil && (sigtab[sig].flags & SigPanic)) { if((gp = m->curg) != nil && (runtime·sigtab[sig].flags & SigPanic)) {
// Make it look like a call to the signal func. // Make it look like a call to the signal func.
// Have to pass arguments out of band since // Have to pass arguments out of band since
// augmenting the stack frame would break // augmenting the stack frame would break
...@@ -64,91 +64,91 @@ sighandler(int32 sig, Siginfo* info, void* context) ...@@ -64,91 +64,91 @@ sighandler(int32 sig, Siginfo* info, void* context)
gp->sigcode0 = info->si_code; gp->sigcode0 = info->si_code;
gp->sigcode1 = (uintptr)info->si_addr; gp->sigcode1 = (uintptr)info->si_addr;
// Only push sigpanic if r->mc_eip != 0. // Only push runtime·sigpanic if r->mc_eip != 0.
// If r->mc_eip == 0, probably panicked because of a // If r->mc_eip == 0, probably panicked because of a
// call to a nil func. Not pushing that onto sp will // call to a nil func. Not pushing that onto sp will
// make the trace look like a call to sigpanic instead. // make the trace look like a call to runtime·sigpanic instead.
// (Otherwise the trace will end at sigpanic and we // (Otherwise the trace will end at runtime·sigpanic and we
// won't get to see who faulted.) // won't get to see who faulted.)
if(r->mc_eip != 0) { if(r->mc_eip != 0) {
sp = (uintptr*)r->mc_esp; sp = (uintptr*)r->mc_esp;
*--sp = r->mc_eip; *--sp = r->mc_eip;
r->mc_esp = (uintptr)sp; r->mc_esp = (uintptr)sp;
} }
r->mc_eip = (uintptr)sigpanic; r->mc_eip = (uintptr)runtime·sigpanic;
return; return;
} }
if(sigtab[sig].flags & SigQueue) { if(runtime·sigtab[sig].flags & SigQueue) {
if(sigsend(sig) || (sigtab[sig].flags & SigIgnore)) if(runtime·sigsend(sig) || (runtime·sigtab[sig].flags & SigIgnore))
return; return;
exit(2); // SIGINT, SIGTERM, etc runtime·exit(2); // SIGINT, SIGTERM, etc
} }
if(panicking) // traceback already printed if(runtime·panicking) // traceback already printed
exit(2); runtime·exit(2);
panicking = 1; runtime·panicking = 1;
if(sig < 0 || sig >= NSIG) if(sig < 0 || sig >= NSIG)
printf("Signal %d\n", sig); runtime·printf("Signal %d\n", sig);
else else
printf("%s\n", sigtab[sig].name); runtime·printf("%s\n", runtime·sigtab[sig].name);
printf("PC=%X\n", r->mc_eip); runtime·printf("PC=%X\n", r->mc_eip);
printf("\n"); runtime·printf("\n");
if(gotraceback()){ if(runtime·gotraceback()){
traceback((void*)r->mc_eip, (void*)r->mc_esp, 0, m->curg); runtime·traceback((void*)r->mc_eip, (void*)r->mc_esp, 0, m->curg);
tracebackothers(m->curg); runtime·tracebackothers(m->curg);
dumpregs(r); runtime·dumpregs(r);
} }
breakpoint(); runtime·breakpoint();
exit(2); runtime·exit(2);
} }
void void
sigignore(void) runtime·sigignore(void)
{ {
} }
void void
signalstack(byte *p, int32 n) runtime·signalstack(byte *p, int32 n)
{ {
Sigaltstack st; Sigaltstack st;
st.ss_sp = (int8*)p; st.ss_sp = (int8*)p;
st.ss_size = n; st.ss_size = n;
st.ss_flags = 0; st.ss_flags = 0;
sigaltstack(&st, nil); runtime·sigaltstack(&st, nil);
} }
void void
initsig(int32 queue) runtime·initsig(int32 queue)
{ {
static Sigaction sa; static Sigaction sa;
siginit(); runtime·siginit();
int32 i; int32 i;
sa.sa_flags |= SA_ONSTACK | SA_SIGINFO; sa.sa_flags |= SA_ONSTACK | SA_SIGINFO;
sa.sa_mask = ~0x0ull; sa.sa_mask = ~0x0ull;
for(i = 0; i < NSIG; i++) { for(i = 0; i < NSIG; i++) {
if(sigtab[i].flags) { if(runtime·sigtab[i].flags) {
if((sigtab[i].flags & SigQueue) != queue) if((runtime·sigtab[i].flags & SigQueue) != queue)
continue; continue;
if(sigtab[i].flags & (SigCatch | SigQueue)) if(runtime·sigtab[i].flags & (SigCatch | SigQueue))
sa.__sigaction_u.__sa_sigaction = (void*) sigtramp; sa.__sigaction_u.__sa_sigaction = (void*) runtime·sigtramp;
else else
sa.__sigaction_u.__sa_sigaction = (void*) sigignore; sa.__sigaction_u.__sa_sigaction = (void*) runtime·sigignore;
if(sigtab[i].flags & SigRestart) if(runtime·sigtab[i].flags & SigRestart)
sa.sa_flags |= SA_RESTART; sa.sa_flags |= SA_RESTART;
else else
sa.sa_flags &= ~SA_RESTART; sa.sa_flags &= ~SA_RESTART;
sigaction(i, &sa, nil); runtime·sigaction(i, &sa, nil);
} }
} }
} }
...@@ -8,17 +8,17 @@ ...@@ -8,17 +8,17 @@
#include "386/asm.h" #include "386/asm.h"
TEXT sys_umtx_op(SB),7,$-4 TEXT runtime·sys_umtx_op(SB),7,$-4
MOVL $454, AX MOVL $454, AX
INT $0x80 INT $0x80
RET RET
TEXT thr_new(SB),7,$-4 TEXT runtime·thr_new(SB),7,$-4
MOVL $455, AX MOVL $455, AX
INT $0x80 INT $0x80
RET RET
TEXT thr_start(SB),7,$0 TEXT runtime·thr_start(SB),7,$0
MOVL mm+0(FP), AX MOVL mm+0(FP), AX
MOVL m_g0(AX), BX MOVL m_g0(AX), BX
LEAL m_tls(AX), BP LEAL m_tls(AX), BP
...@@ -28,7 +28,7 @@ TEXT thr_start(SB),7,$0 ...@@ -28,7 +28,7 @@ TEXT thr_start(SB),7,$0
PUSHL $32 PUSHL $32
PUSHL BP PUSHL BP
PUSHL DI PUSHL DI
CALL setldt(SB) CALL runtime·setldt(SB)
POPL AX POPL AX
POPL AX POPL AX
POPL AX POPL AX
...@@ -37,36 +37,36 @@ TEXT thr_start(SB),7,$0 ...@@ -37,36 +37,36 @@ TEXT thr_start(SB),7,$0
MOVL BX, g(CX) MOVL BX, g(CX)
MOVL AX, m(CX) MOVL AX, m(CX)
CALL stackcheck(SB) // smashes AX CALL runtime·stackcheck(SB) // smashes AX
CALL mstart(SB) CALL runtime·mstart(SB)
MOVL 0, AX // crash (not reached) MOVL 0, AX // crash (not reached)
// Exit the entire program (like C exit) // Exit the entire program (like C exit)
TEXT exit(SB),7,$-4 TEXT runtime·exit(SB),7,$-4
MOVL $1, AX MOVL $1, AX
INT $0x80 INT $0x80
CALL notok(SB) CALL runtime·notok(SB)
RET RET
TEXT exit1(SB),7,$-4 TEXT runtime·exit1(SB),7,$-4
MOVL $431, AX MOVL $431, AX
INT $0x80 INT $0x80
JAE 2(PC) JAE 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
TEXT write(SB),7,$-4 TEXT runtime·write(SB),7,$-4
MOVL $4, AX MOVL $4, AX
INT $0x80 INT $0x80
JAE 2(PC) JAE 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
TEXT notok(SB),7,$0 TEXT runtime·notok(SB),7,$0
MOVL $0xf1, 0xf1 MOVL $0xf1, 0xf1
RET RET
TEXT ·mmap(SB),7,$32 TEXT runtime·mmap(SB),7,$32
LEAL arg0+0(FP), SI LEAL arg0+0(FP), SI
LEAL 4(SP), DI LEAL 4(SP), DI
CLD CLD
...@@ -82,14 +82,14 @@ TEXT ·mmap(SB),7,$32 ...@@ -82,14 +82,14 @@ TEXT ·mmap(SB),7,$32
INT $0x80 INT $0x80
RET RET
TEXT ·munmap(SB),7,$-4 TEXT runtime·munmap(SB),7,$-4
MOVL $73, AX MOVL $73, AX
INT $0x80 INT $0x80
JAE 2(PC) JAE 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
TEXT gettime(SB), 7, $32 TEXT runtime·gettime(SB), 7, $32
MOVL $116, AX MOVL $116, AX
LEAL 12(SP), BX LEAL 12(SP), BX
MOVL BX, 4(SP) MOVL BX, 4(SP)
...@@ -106,14 +106,14 @@ TEXT gettime(SB), 7, $32 ...@@ -106,14 +106,14 @@ TEXT gettime(SB), 7, $32
MOVL BX, (DI) MOVL BX, (DI)
RET RET
TEXT sigaction(SB),7,$-4 TEXT runtime·sigaction(SB),7,$-4
MOVL $416, AX MOVL $416, AX
INT $0x80 INT $0x80
JAE 2(PC) JAE 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
TEXT sigtramp(SB),7,$40 TEXT runtime·sigtramp(SB),7,$40
// g = m->gsignal // g = m->gsignal
get_tls(DX) get_tls(DX)
MOVL m(DX), BP MOVL m(DX), BP
...@@ -127,7 +127,7 @@ TEXT sigtramp(SB),7,$40 ...@@ -127,7 +127,7 @@ TEXT sigtramp(SB),7,$40
MOVL AX, 0(SP) MOVL AX, 0(SP)
MOVL BX, 4(SP) MOVL BX, 4(SP)
MOVL CX, 8(SP) MOVL CX, 8(SP)
CALL sighandler(SB) CALL runtime·sighandler(SB)
// g = m->curg // g = m->curg
get_tls(DX) get_tls(DX)
...@@ -141,14 +141,14 @@ TEXT sigtramp(SB),7,$40 ...@@ -141,14 +141,14 @@ TEXT sigtramp(SB),7,$40
MOVL AX, 4(SP) MOVL AX, 4(SP)
MOVL $417, AX // sigreturn(ucontext) MOVL $417, AX // sigreturn(ucontext)
INT $0x80 INT $0x80
CALL notok(SB) CALL runtime·notok(SB)
RET RET
TEXT sigaltstack(SB),7,$0 TEXT runtime·sigaltstack(SB),7,$0
MOVL $53, AX MOVL $53, AX
INT $0x80 INT $0x80
JAE 2(PC) JAE 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
/* /*
...@@ -168,7 +168,7 @@ int i386_set_ldt(int, const union ldt_entry *, int); ...@@ -168,7 +168,7 @@ int i386_set_ldt(int, const union ldt_entry *, int);
*/ */
// setldt(int entry, int address, int limit) // setldt(int entry, int address, int limit)
TEXT setldt(SB),7,$32 TEXT runtime·setldt(SB),7,$32
MOVL address+4(FP), BX // aka base MOVL address+4(FP), BX // aka base
// see comment in linux/386/sys.s; freebsd is similar // see comment in linux/386/sys.s; freebsd is similar
ADDL $0x8, BX ADDL $0x8, BX
...@@ -193,7 +193,7 @@ TEXT setldt(SB),7,$32 ...@@ -193,7 +193,7 @@ TEXT setldt(SB),7,$32
MOVL $0xffffffff, 0(SP) // auto-allocate entry and return in AX MOVL $0xffffffff, 0(SP) // auto-allocate entry and return in AX
MOVL AX, 4(SP) MOVL AX, 4(SP)
MOVL $1, 8(SP) MOVL $1, 8(SP)
CALL i386_set_ldt(SB) CALL runtime·i386_set_ldt(SB)
// compute segment selector - (entry*8+7) // compute segment selector - (entry*8+7)
SHLL $3, AX SHLL $3, AX
...@@ -201,7 +201,7 @@ TEXT setldt(SB),7,$32 ...@@ -201,7 +201,7 @@ TEXT setldt(SB),7,$32
MOVW AX, GS MOVW AX, GS
RET RET
TEXT i386_set_ldt(SB),7,$16 TEXT runtime·i386_set_ldt(SB),7,$16
LEAL args+0(FP), AX // 0(FP) == 4(SP) before SP got moved LEAL args+0(FP), AX // 0(FP) == 4(SP) before SP got moved
MOVL $0, 0(SP) // syscall gap MOVL $0, 0(SP) // syscall gap
MOVL $1, 4(SP) MOVL $1, 4(SP)
...@@ -213,4 +213,4 @@ TEXT i386_set_ldt(SB),7,$16 ...@@ -213,4 +213,4 @@ TEXT i386_set_ldt(SB),7,$16
INT $3 INT $3
RET RET
GLOBL tlsoffset(SB),$4 GLOBL runtime·tlsoffset(SB),$4
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
// Darwin and Linux use the same linkage to main // Darwin and Linux use the same linkage to main
TEXT _rt0_amd64_freebsd(SB),7,$-8 TEXT _rt0_amd64_freebsd(SB),7,$-8
MOVQ $_rt0_amd64(SB), DX MOVQ $_rt0_amd64(SB), DX
JMP DX JMP DX
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "signals.h" #include "signals.h"
#include "os.h" #include "os.h"
extern void sigtramp(void); extern void runtime·sigtramp(void);
typedef struct sigaction { typedef struct sigaction {
union { union {
...@@ -19,41 +19,41 @@ typedef struct sigaction { ...@@ -19,41 +19,41 @@ typedef struct sigaction {
} Sigaction; } Sigaction;
void void
dumpregs(Mcontext *r) runtime·dumpregs(Mcontext *r)
{ {
printf("rax %X\n", r->mc_rax); runtime·printf("rax %X\n", r->mc_rax);
printf("rbx %X\n", r->mc_rbx); runtime·printf("rbx %X\n", r->mc_rbx);
printf("rcx %X\n", r->mc_rcx); runtime·printf("rcx %X\n", r->mc_rcx);
printf("rdx %X\n", r->mc_rdx); runtime·printf("rdx %X\n", r->mc_rdx);
printf("rdi %X\n", r->mc_rdi); runtime·printf("rdi %X\n", r->mc_rdi);
printf("rsi %X\n", r->mc_rsi); runtime·printf("rsi %X\n", r->mc_rsi);
printf("rbp %X\n", r->mc_rbp); runtime·printf("rbp %X\n", r->mc_rbp);
printf("rsp %X\n", r->mc_rsp); runtime·printf("rsp %X\n", r->mc_rsp);
printf("r8 %X\n", r->mc_r8 ); runtime·printf("r8 %X\n", r->mc_r8 );
printf("r9 %X\n", r->mc_r9 ); runtime·printf("r9 %X\n", r->mc_r9 );
printf("r10 %X\n", r->mc_r10); runtime·printf("r10 %X\n", r->mc_r10);
printf("r11 %X\n", r->mc_r11); runtime·printf("r11 %X\n", r->mc_r11);
printf("r12 %X\n", r->mc_r12); runtime·printf("r12 %X\n", r->mc_r12);
printf("r13 %X\n", r->mc_r13); runtime·printf("r13 %X\n", r->mc_r13);
printf("r14 %X\n", r->mc_r14); runtime·printf("r14 %X\n", r->mc_r14);
printf("r15 %X\n", r->mc_r15); runtime·printf("r15 %X\n", r->mc_r15);
printf("rip %X\n", r->mc_rip); runtime·printf("rip %X\n", r->mc_rip);
printf("rflags %X\n", r->mc_flags); runtime·printf("rflags %X\n", r->mc_flags);
printf("cs %X\n", r->mc_cs); runtime·printf("cs %X\n", r->mc_cs);
printf("fs %X\n", r->mc_fs); runtime·printf("fs %X\n", r->mc_fs);
printf("gs %X\n", r->mc_gs); runtime·printf("gs %X\n", r->mc_gs);
} }
String String
signame(int32 sig) runtime·signame(int32 sig)
{ {
if(sig < 0 || sig >= NSIG) if(sig < 0 || sig >= NSIG)
return emptystring; return runtime·emptystring;
return gostringnocopy((byte*)sigtab[sig].name); return runtime·gostringnocopy((byte*)runtime·sigtab[sig].name);
} }
void void
sighandler(int32 sig, Siginfo* info, void* context) runtime·sighandler(int32 sig, Siginfo* info, void* context)
{ {
Ucontext *uc; Ucontext *uc;
Mcontext *r; Mcontext *r;
...@@ -63,7 +63,7 @@ sighandler(int32 sig, Siginfo* info, void* context) ...@@ -63,7 +63,7 @@ sighandler(int32 sig, Siginfo* info, void* context)
uc = context; uc = context;
r = &uc->uc_mcontext; r = &uc->uc_mcontext;
if((gp = m->curg) != nil && (sigtab[sig].flags & SigPanic)) { if((gp = m->curg) != nil && (runtime·sigtab[sig].flags & SigPanic)) {
// Make it look like a call to the signal func. // Make it look like a call to the signal func.
// Have to pass arguments out of band since // Have to pass arguments out of band since
// augmenting the stack frame would break // augmenting the stack frame would break
...@@ -72,91 +72,91 @@ sighandler(int32 sig, Siginfo* info, void* context) ...@@ -72,91 +72,91 @@ sighandler(int32 sig, Siginfo* info, void* context)
gp->sigcode0 = info->si_code; gp->sigcode0 = info->si_code;
gp->sigcode1 = (uintptr)info->si_addr; gp->sigcode1 = (uintptr)info->si_addr;
// Only push sigpanic if r->mc_rip != 0. // Only push runtime·sigpanic if r->mc_rip != 0.
// If r->mc_rip == 0, probably panicked because of a // If r->mc_rip == 0, probably panicked because of a
// call to a nil func. Not pushing that onto sp will // call to a nil func. Not pushing that onto sp will
// make the trace look like a call to sigpanic instead. // make the trace look like a call to runtime·sigpanic instead.
// (Otherwise the trace will end at sigpanic and we // (Otherwise the trace will end at runtime·sigpanic and we
// won't get to see who faulted.) // won't get to see who faulted.)
if(r->mc_rip != 0) { if(r->mc_rip != 0) {
sp = (uintptr*)r->mc_rsp; sp = (uintptr*)r->mc_rsp;
*--sp = r->mc_rip; *--sp = r->mc_rip;
r->mc_rsp = (uintptr)sp; r->mc_rsp = (uintptr)sp;
} }
r->mc_rip = (uintptr)sigpanic; r->mc_rip = (uintptr)runtime·sigpanic;
return; return;
} }
if(sigtab[sig].flags & SigQueue) { if(runtime·sigtab[sig].flags & SigQueue) {
if(sigsend(sig) || (sigtab[sig].flags & SigIgnore)) if(runtime·sigsend(sig) || (runtime·sigtab[sig].flags & SigIgnore))
return; return;
exit(2); // SIGINT, SIGTERM, etc runtime·exit(2); // SIGINT, SIGTERM, etc
} }
if(panicking) // traceback already printed if(runtime·panicking) // traceback already printed
exit(2); runtime·exit(2);
panicking = 1; runtime·panicking = 1;
if(sig < 0 || sig >= NSIG) if(sig < 0 || sig >= NSIG)
printf("Signal %d\n", sig); runtime·printf("Signal %d\n", sig);
else else
printf("%s\n", sigtab[sig].name); runtime·printf("%s\n", runtime·sigtab[sig].name);
printf("PC=%X\n", r->mc_rip); runtime·printf("PC=%X\n", r->mc_rip);
printf("\n"); runtime·printf("\n");
if(gotraceback()){ if(runtime·gotraceback()){
traceback((void*)r->mc_rip, (void*)r->mc_rsp, 0, g); runtime·traceback((void*)r->mc_rip, (void*)r->mc_rsp, 0, g);
tracebackothers(g); runtime·tracebackothers(g);
dumpregs(r); runtime·dumpregs(r);
} }
breakpoint(); runtime·breakpoint();
exit(2); runtime·exit(2);
} }
void void
sigignore(void) runtime·sigignore(void)
{ {
} }
void void
signalstack(byte *p, int32 n) runtime·signalstack(byte *p, int32 n)
{ {
Sigaltstack st; Sigaltstack st;
st.ss_sp = (int8*)p; st.ss_sp = (int8*)p;
st.ss_size = n; st.ss_size = n;
st.ss_flags = 0; st.ss_flags = 0;
sigaltstack(&st, nil); runtime·sigaltstack(&st, nil);
} }
void void
initsig(int32 queue) runtime·initsig(int32 queue)
{ {
static Sigaction sa; static Sigaction sa;
siginit(); runtime·siginit();
int32 i; int32 i;
sa.sa_flags |= SA_ONSTACK | SA_SIGINFO; sa.sa_flags |= SA_ONSTACK | SA_SIGINFO;
sa.sa_mask = ~0x0ull; sa.sa_mask = ~0x0ull;
for(i = 0; i < NSIG; i++) { for(i = 0; i < NSIG; i++) {
if(sigtab[i].flags) { if(runtime·sigtab[i].flags) {
if((sigtab[i].flags & SigQueue) != queue) if((runtime·sigtab[i].flags & SigQueue) != queue)
continue; continue;
if(sigtab[i].flags & (SigCatch | SigQueue)) if(runtime·sigtab[i].flags & (SigCatch | SigQueue))
sa.__sigaction_u.__sa_sigaction = (void*) sigtramp; sa.__sigaction_u.__sa_sigaction = (void*) runtime·sigtramp;
else else
sa.__sigaction_u.__sa_sigaction = (void*) sigignore; sa.__sigaction_u.__sa_sigaction = (void*) runtime·sigignore;
if(sigtab[i].flags & SigRestart) if(runtime·sigtab[i].flags & SigRestart)
sa.sa_flags |= SA_RESTART; sa.sa_flags |= SA_RESTART;
else else
sa.sa_flags &= ~SA_RESTART; sa.sa_flags &= ~SA_RESTART;
sigaction(i, &sa, nil); runtime·sigaction(i, &sa, nil);
} }
} }
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#include "amd64/asm.h" #include "amd64/asm.h"
TEXT sys_umtx_op(SB),7,$0 TEXT runtime·sys_umtx_op(SB),7,$0
MOVQ 8(SP), DI MOVQ 8(SP), DI
MOVL 16(SP), SI MOVL 16(SP), SI
MOVL 20(SP), DX MOVL 20(SP), DX
...@@ -18,19 +18,19 @@ TEXT sys_umtx_op(SB),7,$0 ...@@ -18,19 +18,19 @@ TEXT sys_umtx_op(SB),7,$0
SYSCALL SYSCALL
RET RET
TEXT thr_new(SB),7,$0 TEXT runtime·thr_new(SB),7,$0
MOVQ 8(SP), DI MOVQ 8(SP), DI
MOVQ 16(SP), SI MOVQ 16(SP), SI
MOVL $455, AX MOVL $455, AX
SYSCALL SYSCALL
RET RET
TEXT thr_start(SB),7,$0 TEXT runtime·thr_start(SB),7,$0
MOVQ DI, R13 // m MOVQ DI, R13 // m
// set up FS to point at m->tls // set up FS to point at m->tls
LEAQ m_tls(R13), DI LEAQ m_tls(R13), DI
CALL settls(SB) // smashes DI CALL runtime·settls(SB) // smashes DI
// set up m, g // set up m, g
get_tls(CX) get_tls(CX)
...@@ -38,36 +38,36 @@ TEXT thr_start(SB),7,$0 ...@@ -38,36 +38,36 @@ TEXT thr_start(SB),7,$0
MOVQ m_g0(R13), DI MOVQ m_g0(R13), DI
MOVQ DI, g(CX) MOVQ DI, g(CX)
CALL stackcheck(SB) CALL runtime·stackcheck(SB)
CALL mstart(SB) CALL runtime·mstart(SB)
MOVQ 0, AX // crash (not reached) MOVQ 0, AX // crash (not reached)
// Exit the entire program (like C exit) // Exit the entire program (like C exit)
TEXT exit(SB),7,$-8 TEXT runtime·exit(SB),7,$-8
MOVL 8(SP), DI // arg 1 exit status MOVL 8(SP), DI // arg 1 exit status
MOVL $1, AX MOVL $1, AX
SYSCALL SYSCALL
CALL notok(SB) CALL runtime·notok(SB)
RET RET
TEXT exit1(SB),7,$-8 TEXT runtime·exit1(SB),7,$-8
MOVQ 8(SP), DI // arg 1 exit status MOVQ 8(SP), DI // arg 1 exit status
MOVL $431, AX MOVL $431, AX
SYSCALL SYSCALL
CALL notok(SB) CALL runtime·notok(SB)
RET RET
TEXT write(SB),7,$-8 TEXT runtime·write(SB),7,$-8
MOVL 8(SP), DI // arg 1 fd MOVL 8(SP), DI // arg 1 fd
MOVQ 16(SP), SI // arg 2 buf MOVQ 16(SP), SI // arg 2 buf
MOVL 24(SP), DX // arg 3 count MOVL 24(SP), DX // arg 3 count
MOVL $4, AX MOVL $4, AX
SYSCALL SYSCALL
JCC 2(PC) JCC 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
TEXT gettime(SB), 7, $32 TEXT runtime·gettime(SB), 7, $32
MOVL $116, AX MOVL $116, AX
LEAQ 8(SP), DI LEAQ 8(SP), DI
MOVQ $0, SI MOVQ $0, SI
...@@ -82,17 +82,17 @@ TEXT gettime(SB), 7, $32 ...@@ -82,17 +82,17 @@ TEXT gettime(SB), 7, $32
MOVL BX, (DI) MOVL BX, (DI)
RET RET
TEXT sigaction(SB),7,$-8 TEXT runtime·sigaction(SB),7,$-8
MOVL 8(SP), DI // arg 1 sig MOVL 8(SP), DI // arg 1 sig
MOVQ 16(SP), SI // arg 2 act MOVQ 16(SP), SI // arg 2 act
MOVQ 24(SP), DX // arg 3 oact MOVQ 24(SP), DX // arg 3 oact
MOVL $416, AX MOVL $416, AX
SYSCALL SYSCALL
JCC 2(PC) JCC 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
TEXT sigtramp(SB),7,$24-16 TEXT runtime·sigtramp(SB),7,$24-16
get_tls(CX) get_tls(CX)
MOVQ m(CX), AX MOVQ m(CX), AX
MOVQ m_gsignal(AX), AX MOVQ m_gsignal(AX), AX
...@@ -100,10 +100,10 @@ TEXT sigtramp(SB),7,$24-16 ...@@ -100,10 +100,10 @@ TEXT sigtramp(SB),7,$24-16
MOVQ DI, 0(SP) MOVQ DI, 0(SP)
MOVQ SI, 8(SP) MOVQ SI, 8(SP)
MOVQ DX, 16(SP) MOVQ DX, 16(SP)
CALL sighandler(SB) CALL runtime·sighandler(SB)
RET RET
TEXT ·mmap(SB),7,$0 TEXT runtime·mmap(SB),7,$0
MOVQ 8(SP), DI // arg 1 addr MOVQ 8(SP), DI // arg 1 addr
MOVQ 16(SP), SI // arg 2 len MOVQ 16(SP), SI // arg 2 len
MOVL 24(SP), DX // arg 3 prot MOVL 24(SP), DX // arg 3 prot
...@@ -114,31 +114,31 @@ TEXT ·mmap(SB),7,$0 ...@@ -114,31 +114,31 @@ TEXT ·mmap(SB),7,$0
SYSCALL SYSCALL
RET RET
TEXT ·munmap(SB),7,$0 TEXT runtime·munmap(SB),7,$0
MOVQ 8(SP), DI // arg 1 addr MOVQ 8(SP), DI // arg 1 addr
MOVQ 16(SP), SI // arg 2 len MOVQ 16(SP), SI // arg 2 len
MOVL $73, AX MOVL $73, AX
SYSCALL SYSCALL
JCC 2(PC) JCC 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
TEXT notok(SB),7,$-8 TEXT runtime·notok(SB),7,$-8
MOVL $0xf1, BP MOVL $0xf1, BP
MOVQ BP, (BP) MOVQ BP, (BP)
RET RET
TEXT sigaltstack(SB),7,$-8 TEXT runtime·sigaltstack(SB),7,$-8
MOVQ new+8(SP), DI MOVQ new+8(SP), DI
MOVQ old+16(SP), SI MOVQ old+16(SP), SI
MOVQ $53, AX MOVQ $53, AX
SYSCALL SYSCALL
JCC 2(PC) JCC 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
// set tls base to DI // set tls base to DI
TEXT settls(SB),7,$8 TEXT runtime·settls(SB),7,$8
ADDQ $16, DI // adjust for ELF: wants to use -16(FS) and -8(FS) for g and m ADDQ $16, DI // adjust for ELF: wants to use -16(FS) and -8(FS) for g and m
MOVQ DI, 0(SP) MOVQ DI, 0(SP)
MOVQ SP, SI MOVQ SP, SI
...@@ -146,5 +146,5 @@ TEXT settls(SB),7,$8 ...@@ -146,5 +146,5 @@ TEXT settls(SB),7,$8
MOVQ $165, AX // sysarch MOVQ $165, AX // sysarch
SYSCALL SYSCALL
JCC 2(PC) JCC 2(PC)
CALL notok(SB) CALL runtime·notok(SB)
RET RET
...@@ -4,21 +4,21 @@ ...@@ -4,21 +4,21 @@
#include "malloc.h" #include "malloc.h"
void* void*
SysAlloc(uintptr n) runtime·SysAlloc(uintptr n)
{ {
void *v; void *v;
mstats.sys += n; mstats.sys += n;
v = runtime_mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0); v = runtime·mmap(nil, n, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_ANON|MAP_PRIVATE, -1, 0);
if(v < (void*)4096) { if(v < (void*)4096) {
printf("mmap: errno=%p\n", v); runtime·printf("mmap: errno=%p\n", v);
throw("mmap"); runtime·throw("mmap");
} }
return v; return v;
} }
void void
SysUnused(void *v, uintptr n) runtime·SysUnused(void *v, uintptr n)
{ {
USED(v); USED(v);
USED(n); USED(n);
...@@ -26,15 +26,15 @@ SysUnused(void *v, uintptr n) ...@@ -26,15 +26,15 @@ SysUnused(void *v, uintptr n)
} }
void void
SysFree(void *v, uintptr n) runtime·SysFree(void *v, uintptr n)
{ {
mstats.sys -= n; mstats.sys -= n;
runtime_munmap(v, n); runtime·munmap(v, n);
} }
void void
SysMemInit(void) runtime·SysMemInit(void)
{ {
// Code generators assume that references to addresses // Code generators assume that references to addresses
// on the first page will fault. Map the page explicitly with // on the first page will fault. Map the page explicitly with
...@@ -42,5 +42,5 @@ SysMemInit(void) ...@@ -42,5 +42,5 @@ SysMemInit(void)
// allocating that page as the virtual address space fills. // allocating that page as the virtual address space fills.
// Ignore any error, since other systems might be smart // Ignore any error, since other systems might be smart
// enough to never allow anything there. // enough to never allow anything there.
runtime_mmap(nil, 4096, PROT_NONE, MAP_FIXED|MAP_ANON|MAP_PRIVATE, -1, 0); runtime·mmap(nil, 4096, PROT_NONE, MAP_FIXED|MAP_ANON|MAP_PRIVATE, -1, 0);
} }
int32 thr_new(ThrParam*, int32); int32 runtime·thr_new(ThrParam*, int32);
void sigpanic(void); void runtime·sigpanic(void);
void sigaltstack(Sigaltstack*, Sigaltstack*); void runtime·sigaltstack(Sigaltstack*, Sigaltstack*);
struct sigaction; struct sigaction;
void sigaction(int32, struct sigaction*, struct sigaction*); void runtime·sigaction(int32, struct sigaction*, struct sigaction*);
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
#define Q SigQueue #define Q SigQueue
#define P SigPanic #define P SigPanic
SigTab sigtab[] = { SigTab runtime·sigtab[] = {
/* 0 */ 0, "SIGNONE: no trap", /* 0 */ 0, "SIGNONE: no trap",
/* 1 */ Q+R, "SIGHUP: terminal line hangup", /* 1 */ Q+R, "SIGHUP: terminal line hangup",
/* 2 */ Q+R, "SIGINT: interrupt", /* 2 */ Q+R, "SIGINT: interrupt",
......
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
...@@ -4,6 +4,6 @@ ...@@ -4,6 +4,6 @@
// Darwin and Linux use the same linkage to main // Darwin and Linux use the same linkage to main
TEXT _rt0_386_linux(SB),7,$0 TEXT _rt0_386_linux(SB),7,$0
JMP _rt0_386(SB) JMP _rt0_386(SB)
This diff is collapsed.
This diff is collapsed.
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
// Darwin and Linux use the same linkage to main // Darwin and Linux use the same linkage to main
TEXT _rt0_amd64_linux(SB),7,$-8 TEXT _rt0_amd64_linux(SB),7,$-8
MOVQ $_rt0_amd64(SB), AX MOVQ $_rt0_amd64(SB), AX
MOVQ SP, DI MOVQ SP, DI
JMP AX JMP AX
This diff is collapsed.
This diff is collapsed.
...@@ -2,5 +2,5 @@ ...@@ -2,5 +2,5 @@
// Use of this source code is governed by a BSD-style // Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file. // license that can be found in the LICENSE file.
TEXT _rt0_arm_linux(SB),7,$0 TEXT _rt0_arm_linux(SB),7,$0
B _rt0_arm(SB) B _rt0_arm(SB)
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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