2010-01-06 18:58:55 -07:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "386/asm.h"
|
|
|
|
|
2010-09-11 19:45:16 -06:00
|
|
|
// void *stdcall_raw(void *fn, int32 count, uintptr *args)
|
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
2010-11-04 12:00:19 -06:00
|
|
|
TEXT runtime·stdcall_raw(SB),7,$4
|
2010-09-11 19:45:16 -06:00
|
|
|
// Copy arguments from stack.
|
|
|
|
MOVL fn+0(FP), AX
|
|
|
|
MOVL count+4(FP), CX // words
|
|
|
|
MOVL args+8(FP), BP
|
2010-01-06 18:58:55 -07:00
|
|
|
|
2010-09-11 19:45:16 -06:00
|
|
|
// Switch to m->g0 if needed.
|
2010-06-11 02:38:12 -06:00
|
|
|
get_tls(DI)
|
|
|
|
MOVL m(DI), DX
|
2010-09-11 19:45:16 -06:00
|
|
|
MOVL g(DI), SI
|
|
|
|
MOVL SI, 0(SP) // save g
|
|
|
|
MOVL SP, m_gostack(DX) // save SP
|
2010-06-11 02:38:12 -06:00
|
|
|
MOVL m_g0(DX), SI
|
|
|
|
CMPL g(DI), SI
|
2010-09-11 19:45:16 -06:00
|
|
|
JEQ 3(PC)
|
2010-06-11 02:38:12 -06:00
|
|
|
MOVL (m_sched+gobuf_sp)(DX), SP
|
|
|
|
MOVL SI, g(DI)
|
2010-09-11 19:45:16 -06:00
|
|
|
|
|
|
|
// Copy args to new stack.
|
|
|
|
SUBL $(10*4), SP // padding
|
|
|
|
MOVL CX, BX
|
|
|
|
SALL $2, BX
|
|
|
|
SUBL BX, SP // room for args
|
|
|
|
MOVL SP, DI
|
|
|
|
MOVL BP, SI
|
2010-06-11 02:38:12 -06:00
|
|
|
CLD
|
2010-09-11 19:45:16 -06:00
|
|
|
REP; MOVSL
|
|
|
|
|
|
|
|
// Call stdcall function.
|
|
|
|
CALL AX
|
|
|
|
|
|
|
|
// Restore original SP, g.
|
2010-06-11 02:38:12 -06:00
|
|
|
get_tls(DI)
|
2010-09-11 19:45:16 -06:00
|
|
|
MOVL m(DI), DX
|
|
|
|
MOVL m_gostack(DX), SP // restore SP
|
|
|
|
MOVL 0(SP), SI // restore g
|
2010-06-11 02:38:12 -06:00
|
|
|
MOVL SI, g(DI)
|
2010-01-06 18:58:55 -07:00
|
|
|
|
2010-09-11 19:45:16 -06:00
|
|
|
// Someday the convention will be D is always cleared.
|
|
|
|
CLD
|
|
|
|
|
2011-01-20 07:21:04 -07:00
|
|
|
RET
|
2010-09-11 19:45:16 -06:00
|
|
|
|
2011-01-19 13:10:15 -07:00
|
|
|
TEXT runtime·sigtramp(SB),7,$0
|
2011-01-20 07:21:04 -07:00
|
|
|
PUSHL BP // cdecl
|
2011-01-19 13:10:15 -07:00
|
|
|
PUSHL 0(FS)
|
|
|
|
CALL runtime·sigtramp1(SB)
|
|
|
|
POPL 0(FS)
|
|
|
|
POPL BP
|
|
|
|
RET
|
|
|
|
|
|
|
|
TEXT runtime·sigtramp1(SB),0,$16-28
|
|
|
|
// unwinding?
|
|
|
|
MOVL info+12(FP), BX
|
2011-01-20 07:21:04 -07:00
|
|
|
MOVL 4(BX), CX // exception flags
|
2011-01-19 13:10:15 -07:00
|
|
|
ANDL $6, CX
|
|
|
|
MOVL $1, AX
|
2011-01-20 07:21:04 -07:00
|
|
|
JNZ sigdone
|
2011-01-19 13:10:15 -07:00
|
|
|
|
|
|
|
// place ourselves at the top of the SEH chain to
|
|
|
|
// ensure SEH frames lie within thread stack bounds
|
|
|
|
MOVL frame+16(FP), CX // our SEH frame
|
|
|
|
MOVL CX, 0(FS)
|
|
|
|
|
|
|
|
// copy arguments for call to sighandler
|
|
|
|
MOVL BX, 0(SP)
|
|
|
|
MOVL CX, 4(SP)
|
|
|
|
MOVL context+20(FP), BX
|
|
|
|
MOVL BX, 8(SP)
|
|
|
|
MOVL dispatcher+24(FP), BX
|
|
|
|
MOVL BX, 12(SP)
|
|
|
|
|
|
|
|
CALL runtime·sighandler(SB)
|
|
|
|
TESTL AX, AX
|
2011-01-20 07:21:04 -07:00
|
|
|
JZ sigdone
|
2011-01-19 13:10:15 -07:00
|
|
|
|
|
|
|
// call windows default handler early
|
2011-01-20 07:21:04 -07:00
|
|
|
MOVL 4(SP), BX // our SEH frame
|
|
|
|
MOVL 0(BX), BX // SEH frame of default handler
|
|
|
|
MOVL BX, 4(SP) // set establisher frame
|
2011-01-24 23:56:33 -07:00
|
|
|
CALL 4(BX)
|
2011-01-19 13:10:15 -07:00
|
|
|
|
|
|
|
sigdone:
|
|
|
|
RET
|
|
|
|
|
2011-01-21 19:55:53 -07:00
|
|
|
// Called from dynamic function created by ../thread.c compilecallback,
|
|
|
|
// running on Windows stack (not Go stack).
|
|
|
|
// Returns straight to DLL.
|
2011-01-24 23:56:33 -07:00
|
|
|
// EBX, EBP, ESI, EDI registers and DF flag are preserved
|
2011-01-21 19:55:53 -07:00
|
|
|
// as required by windows callback convention.
|
|
|
|
// On entry to the function the stack looks like:
|
|
|
|
//
|
|
|
|
// 0(SP) - return address to callback
|
|
|
|
// 4(SP) - address of go func we need to call
|
|
|
|
// 8(SP) - total size of arguments
|
|
|
|
// 12(SP) - room to save BX register
|
2011-01-24 23:56:33 -07:00
|
|
|
// 16(SP) - room to save BP
|
|
|
|
// 20(SP) - room to save SI
|
|
|
|
// 24(SP) - room to save DI
|
|
|
|
// 28(SP) - return address to DLL
|
|
|
|
// 32(SP) - beginning of arguments
|
2011-01-21 19:55:53 -07:00
|
|
|
//
|
|
|
|
TEXT runtime·callbackasm+0(SB),7,$0
|
|
|
|
MOVL BX, 12(SP) // save registers as required for windows callback
|
2011-01-24 23:56:33 -07:00
|
|
|
MOVL BP, 16(SP)
|
|
|
|
MOVL SI, 20(SP)
|
|
|
|
MOVL DI, 24(SP)
|
2011-01-21 19:55:53 -07:00
|
|
|
|
2011-01-24 23:56:33 -07:00
|
|
|
LEAL args+32(SP), AX
|
2011-01-21 19:55:53 -07:00
|
|
|
MOVL AX, 0(SP)
|
|
|
|
|
|
|
|
CLD
|
|
|
|
|
|
|
|
CALL runtime·callback(SB)
|
|
|
|
|
|
|
|
MOVL 12(SP), BX // restore registers as required for windows callback
|
2011-01-24 23:56:33 -07:00
|
|
|
MOVL 16(SP), BP
|
|
|
|
MOVL 20(SP), SI
|
|
|
|
MOVL 24(SP), DI
|
2011-01-21 19:55:53 -07:00
|
|
|
CLD
|
|
|
|
|
2011-01-24 23:56:33 -07:00
|
|
|
MOVL ret+28(SP), CX
|
2011-01-21 19:55:53 -07:00
|
|
|
MOVL size+8(SP), DX
|
2011-01-24 23:56:33 -07:00
|
|
|
ADDL $32, DX
|
2011-01-21 19:55:53 -07:00
|
|
|
ADDL DX, SP
|
|
|
|
JMP CX
|
|
|
|
|
2010-09-11 19:45:16 -06:00
|
|
|
// void tstart(M *newm);
|
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
2010-11-04 12:00:19 -06:00
|
|
|
TEXT runtime·tstart(SB),7,$0
|
2010-09-11 19:45:16 -06:00
|
|
|
MOVL newm+4(SP), CX // m
|
|
|
|
MOVL m_g0(CX), DX // g
|
2010-01-06 18:58:55 -07:00
|
|
|
|
2011-01-19 13:10:15 -07:00
|
|
|
// Set up SEH frame
|
|
|
|
PUSHL $runtime·sigtramp(SB)
|
|
|
|
PUSHL 0(FS)
|
|
|
|
MOVL SP, 0(FS)
|
2010-09-11 19:45:16 -06:00
|
|
|
|
|
|
|
// Layout new m scheduler stack on os stack.
|
|
|
|
MOVL SP, AX
|
|
|
|
SUBL $256, AX // just some space for ourselves
|
|
|
|
MOVL AX, g_stackbase(DX)
|
2011-01-24 23:56:33 -07:00
|
|
|
SUBL $(64*1024), AX // stack size
|
2010-09-11 19:45:16 -06:00
|
|
|
MOVL AX, g_stackguard(DX)
|
|
|
|
|
|
|
|
// Set up tls.
|
2010-01-06 18:58:55 -07:00
|
|
|
LEAL m_tls(CX), SI
|
|
|
|
MOVL SI, 0x2c(FS)
|
|
|
|
MOVL CX, m(SI)
|
|
|
|
MOVL DX, g(SI)
|
|
|
|
|
2010-09-11 19:45:16 -06:00
|
|
|
// Use scheduler stack now.
|
|
|
|
MOVL g_stackbase(DX), SP
|
|
|
|
|
|
|
|
// Someday the convention will be D is always cleared.
|
|
|
|
CLD
|
2010-01-06 18:58:55 -07:00
|
|
|
|
2011-01-20 07:21:04 -07:00
|
|
|
CALL runtime·stackcheck(SB) // clobbers AX,CX
|
2010-09-11 19:45:16 -06:00
|
|
|
|
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
2010-11-04 12:00:19 -06:00
|
|
|
CALL runtime·mstart(SB)
|
2010-09-11 19:45:16 -06:00
|
|
|
|
2011-01-19 13:10:15 -07:00
|
|
|
// Pop SEH frame
|
|
|
|
MOVL 0(FS), SP
|
|
|
|
POPL 0(FS)
|
|
|
|
POPL CX
|
2010-09-11 19:45:16 -06:00
|
|
|
|
|
|
|
RET
|
|
|
|
|
|
|
|
// uint32 tstart_stdcall(M *newm);
|
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
2010-11-04 12:00:19 -06:00
|
|
|
TEXT runtime·tstart_stdcall(SB),7,$0
|
2010-09-11 19:45:16 -06:00
|
|
|
MOVL newm+4(SP), BX
|
|
|
|
|
|
|
|
PUSHL BX
|
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
2010-11-04 12:00:19 -06:00
|
|
|
CALL runtime·tstart(SB)
|
2010-09-11 19:45:16 -06:00
|
|
|
POPL BX
|
|
|
|
|
|
|
|
// Adjust stack for stdcall to return properly.
|
|
|
|
MOVL (SP), AX // save return address
|
|
|
|
ADDL $4, SP // remove single parameter
|
|
|
|
MOVL AX, (SP) // restore return address
|
|
|
|
|
|
|
|
XORL AX, AX // return 0 == success
|
|
|
|
|
2010-01-06 18:58:55 -07:00
|
|
|
RET
|
|
|
|
|
|
|
|
// setldt(int entry, int address, int limit)
|
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
2010-11-04 12:00:19 -06:00
|
|
|
TEXT runtime·setldt(SB),7,$0
|
2010-01-06 18:58:55 -07:00
|
|
|
MOVL address+4(FP), CX
|
|
|
|
MOVL CX, 0x2c(FS)
|
|
|
|
RET
|
2010-02-12 13:49:16 -07:00
|
|
|
|
|
|
|
// for now, return 0,0. only used for internal performance monitoring.
|
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
2010-11-04 12:00:19 -06:00
|
|
|
TEXT runtime·gettime(SB),7,$0
|
2010-02-12 13:49:16 -07:00
|
|
|
MOVL sec+0(FP), DI
|
|
|
|
MOVL $0, (DI)
|
2011-01-20 07:21:04 -07:00
|
|
|
MOVL $0, 4(DI) // zero extend 32 -> 64 bits
|
2010-02-12 13:49:16 -07:00
|
|
|
MOVL usec+4(FP), DI
|
|
|
|
MOVL $0, (DI)
|
|
|
|
RET
|