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.
|
|
|
|
|
2011-12-19 13:51:13 -07:00
|
|
|
#include "zasm_GOOS_GOARCH.h"
|
2010-01-06 18:58:55 -07:00
|
|
|
|
2011-08-27 07:17:00 -06:00
|
|
|
// void runtime·asmstdcall(void *c);
|
|
|
|
TEXT runtime·asmstdcall(SB),7,$0
|
2011-09-14 00:19:45 -06:00
|
|
|
MOVL c+0(FP), BX
|
2010-01-06 18:58:55 -07:00
|
|
|
|
2011-08-27 07:17:00 -06:00
|
|
|
// SetLastError(0).
|
|
|
|
MOVL $0, 0x34(FS)
|
2010-09-11 19:45:16 -06:00
|
|
|
|
2011-08-27 07:17:00 -06:00
|
|
|
// Copy args to the stack.
|
2011-08-29 22:43:54 -06:00
|
|
|
MOVL SP, BP
|
2011-09-14 00:19:45 -06:00
|
|
|
MOVL wincall_n(BX), CX // words
|
|
|
|
MOVL CX, AX
|
|
|
|
SALL $2, AX
|
|
|
|
SUBL AX, SP // room for args
|
2010-09-11 19:45:16 -06:00
|
|
|
MOVL SP, DI
|
2011-09-14 00:19:45 -06:00
|
|
|
MOVL wincall_args(BX), SI
|
2010-06-11 02:38:12 -06:00
|
|
|
CLD
|
2010-09-11 19:45:16 -06:00
|
|
|
REP; MOVSL
|
|
|
|
|
2011-08-29 22:43:54 -06:00
|
|
|
// Call stdcall or cdecl function.
|
|
|
|
// DI SI BP BX are preserved, SP is not
|
2011-09-14 00:19:45 -06:00
|
|
|
CALL wincall_fn(BX)
|
2011-08-29 22:43:54 -06:00
|
|
|
MOVL BP, SP
|
2010-09-11 19:45:16 -06:00
|
|
|
|
2011-08-27 07:17:00 -06:00
|
|
|
// Return result.
|
2011-09-14 00:19:45 -06:00
|
|
|
MOVL c+0(FP), BX
|
|
|
|
MOVL AX, wincall_r1(BX)
|
|
|
|
MOVL DX, wincall_r2(BX)
|
2010-01-06 18:58:55 -07:00
|
|
|
|
2011-08-27 07:17:00 -06:00
|
|
|
// GetLastError().
|
2011-09-14 00:19:45 -06:00
|
|
|
MOVL 0x34(FS), AX
|
|
|
|
MOVL AX, wincall_err(BX)
|
2010-09-11 19:45:16 -06:00
|
|
|
|
2011-01-20 07:21:04 -07:00
|
|
|
RET
|
2010-09-11 19:45:16 -06:00
|
|
|
|
2012-03-08 13:53:11 -07:00
|
|
|
TEXT runtime·badcallback(SB),7,$24
|
2012-03-08 22:10:34 -07:00
|
|
|
// stderr
|
2012-03-08 13:53:11 -07:00
|
|
|
MOVL $-12, 0(SP)
|
|
|
|
MOVL SP, BP
|
|
|
|
CALL *runtime·GetStdHandle(SB)
|
|
|
|
MOVL BP, SP
|
2012-03-08 22:10:34 -07:00
|
|
|
|
2012-03-08 13:53:11 -07:00
|
|
|
MOVL AX, 0(SP) // handle
|
|
|
|
MOVL $runtime·badcallbackmsg(SB), DX // pointer
|
|
|
|
MOVL DX, 4(SP)
|
|
|
|
MOVL runtime·badcallbacklen(SB), DX // count
|
|
|
|
MOVL DX, 8(SP)
|
|
|
|
LEAL 20(SP), DX // written count
|
|
|
|
MOVL $0, 0(DX)
|
|
|
|
MOVL DX, 12(SP)
|
|
|
|
MOVL $0, 16(SP) // overlapped
|
|
|
|
CALL *runtime·WriteFile(SB)
|
|
|
|
MOVL BP, SI
|
|
|
|
RET
|
|
|
|
|
2012-03-12 13:55:18 -06:00
|
|
|
TEXT runtime·badsignal(SB),7,$24
|
|
|
|
// stderr
|
|
|
|
MOVL $-12, 0(SP)
|
|
|
|
MOVL SP, BP
|
|
|
|
CALL *runtime·GetStdHandle(SB)
|
|
|
|
MOVL BP, SP
|
|
|
|
|
|
|
|
MOVL AX, 0(SP) // handle
|
|
|
|
MOVL $runtime·badsignalmsg(SB), DX // pointer
|
|
|
|
MOVL DX, 4(SP)
|
|
|
|
MOVL runtime·badsignallen(SB), DX // count
|
|
|
|
MOVL DX, 8(SP)
|
|
|
|
LEAL 20(SP), DX // written count
|
|
|
|
MOVL $0, 0(DX)
|
|
|
|
MOVL DX, 12(SP)
|
|
|
|
MOVL $0, 16(SP) // overlapped
|
|
|
|
CALL *runtime·WriteFile(SB)
|
|
|
|
MOVL BP, SI
|
|
|
|
RET
|
|
|
|
|
2011-02-01 09:49:24 -07:00
|
|
|
// faster get/set last error
|
|
|
|
TEXT runtime·getlasterror(SB),7,$0
|
|
|
|
MOVL 0x34(FS), AX
|
|
|
|
RET
|
|
|
|
|
|
|
|
TEXT runtime·setlasterror(SB),7,$0
|
|
|
|
MOVL err+0(FP), AX
|
|
|
|
MOVL AX, 0x34(FS)
|
|
|
|
RET
|
|
|
|
|
2011-11-06 17:00:14 -07:00
|
|
|
TEXT runtime·sigtramp(SB),7,$28
|
2011-01-19 13:10:15 -07:00
|
|
|
// unwinding?
|
2011-11-06 17:00:14 -07:00
|
|
|
MOVL info+0(FP), CX
|
|
|
|
TESTL $6, 4(CX) // exception flags
|
2011-01-19 13:10:15 -07:00
|
|
|
MOVL $1, AX
|
2011-01-20 07:21:04 -07:00
|
|
|
JNZ sigdone
|
2011-01-19 13:10:15 -07:00
|
|
|
|
|
|
|
// copy arguments for call to sighandler
|
2011-11-06 17:00:14 -07:00
|
|
|
MOVL CX, 0(SP)
|
|
|
|
MOVL context+8(FP), CX
|
2011-01-19 13:10:15 -07:00
|
|
|
MOVL CX, 4(SP)
|
2012-03-12 13:55:18 -06:00
|
|
|
|
2011-11-06 17:00:14 -07:00
|
|
|
get_tls(CX)
|
2012-03-12 13:55:18 -06:00
|
|
|
|
|
|
|
// check that m exists
|
|
|
|
MOVL m(CX), AX
|
|
|
|
CMPL AX, $0
|
|
|
|
JNE 2(PC)
|
|
|
|
CALL runtime·badsignal(SB)
|
|
|
|
|
2011-11-06 17:00:14 -07:00
|
|
|
MOVL g(CX), CX
|
|
|
|
MOVL CX, 8(SP)
|
|
|
|
|
2011-01-19 13:10:15 -07:00
|
|
|
MOVL BX, 12(SP)
|
2011-11-06 17:00:14 -07:00
|
|
|
MOVL BP, 16(SP)
|
|
|
|
MOVL SI, 20(SP)
|
|
|
|
MOVL DI, 24(SP)
|
2011-01-19 13:10:15 -07:00
|
|
|
|
|
|
|
CALL runtime·sighandler(SB)
|
2011-11-06 17:00:14 -07:00
|
|
|
// AX is set to report result back to Windows
|
2011-01-19 13:10:15 -07:00
|
|
|
|
2011-11-06 17:00:14 -07:00
|
|
|
MOVL 24(SP), DI
|
|
|
|
MOVL 20(SP), SI
|
|
|
|
MOVL 16(SP), BP
|
|
|
|
MOVL 12(SP), BX
|
2011-01-19 13:10:15 -07:00
|
|
|
sigdone:
|
|
|
|
RET
|
|
|
|
|
2011-02-14 10:15:13 -07:00
|
|
|
TEXT runtime·ctrlhandler(SB),7,$0
|
2011-09-17 01:57:59 -06:00
|
|
|
PUSHL $runtime·ctrlhandler1(SB)
|
|
|
|
CALL runtime·externalthreadhandler(SB)
|
|
|
|
MOVL 4(SP), CX
|
|
|
|
ADDL $12, SP
|
|
|
|
JMP CX
|
|
|
|
|
|
|
|
TEXT runtime·profileloop(SB),7,$0
|
|
|
|
PUSHL $runtime·profileloop1(SB)
|
|
|
|
CALL runtime·externalthreadhandler(SB)
|
|
|
|
MOVL 4(SP), CX
|
|
|
|
ADDL $12, SP
|
|
|
|
JMP CX
|
|
|
|
|
|
|
|
TEXT runtime·externalthreadhandler(SB),7,$0
|
2011-02-14 10:15:13 -07:00
|
|
|
PUSHL BP
|
|
|
|
MOVL SP, BP
|
|
|
|
PUSHL BX
|
|
|
|
PUSHL SI
|
|
|
|
PUSHL DI
|
2012-01-08 17:23:07 -07:00
|
|
|
PUSHL 0x14(FS)
|
2011-09-17 01:57:59 -06:00
|
|
|
MOVL SP, DX
|
2011-02-14 10:15:13 -07:00
|
|
|
|
|
|
|
// setup dummy m, g
|
2011-09-17 01:57:59 -06:00
|
|
|
SUBL $m_end, SP // space for M
|
|
|
|
MOVL SP, 0(SP)
|
|
|
|
MOVL $m_end, 4(SP)
|
|
|
|
CALL runtime·memclr(SB) // smashes AX,BX,CX
|
|
|
|
|
2011-02-14 10:15:13 -07:00
|
|
|
LEAL m_tls(SP), CX
|
2012-01-08 17:23:07 -07:00
|
|
|
MOVL CX, 0x14(FS)
|
2011-02-14 10:15:13 -07:00
|
|
|
MOVL SP, m(CX)
|
2011-09-17 01:57:59 -06:00
|
|
|
MOVL SP, BX
|
|
|
|
SUBL $g_end, SP // space for G
|
2011-02-14 10:15:13 -07:00
|
|
|
MOVL SP, g(CX)
|
2011-09-17 01:57:59 -06:00
|
|
|
MOVL SP, m_g0(BX)
|
|
|
|
|
|
|
|
MOVL SP, 0(SP)
|
|
|
|
MOVL $g_end, 4(SP)
|
|
|
|
CALL runtime·memclr(SB) // smashes AX,BX,CX
|
2011-02-14 10:15:13 -07:00
|
|
|
LEAL -4096(SP), CX
|
|
|
|
MOVL CX, g_stackguard(SP)
|
2011-09-17 01:57:59 -06:00
|
|
|
MOVL DX, g_stackbase(SP)
|
2011-02-14 10:15:13 -07:00
|
|
|
|
2011-09-17 01:57:59 -06:00
|
|
|
PUSHL 16(BP) // arg for handler
|
|
|
|
CALL 8(BP)
|
2011-02-14 10:15:13 -07:00
|
|
|
POPL CX
|
|
|
|
|
|
|
|
get_tls(CX)
|
|
|
|
MOVL g(CX), CX
|
|
|
|
MOVL g_stackbase(CX), SP
|
2012-01-08 17:23:07 -07:00
|
|
|
POPL 0x14(FS)
|
2011-02-14 10:15:13 -07:00
|
|
|
POPL DI
|
|
|
|
POPL SI
|
|
|
|
POPL BX
|
|
|
|
POPL BP
|
2011-09-17 01:57:59 -06:00
|
|
|
RET
|
2011-02-14 10:15:13 -07:00
|
|
|
|
2011-01-21 19:55:53 -07:00
|
|
|
// Called from dynamic function created by ../thread.c compilecallback,
|
|
|
|
// running on Windows stack (not Go stack).
|
2011-02-01 09:49:24 -07:00
|
|
|
// BX, BP, SI, DI registers and DF flag are preserved
|
2011-01-21 19:55:53 -07:00
|
|
|
// as required by windows callback convention.
|
2011-02-01 09:49:24 -07:00
|
|
|
// AX = address of go func we need to call
|
|
|
|
// DX = total size of arguments
|
2011-01-21 19:55:53 -07:00
|
|
|
//
|
|
|
|
TEXT runtime·callbackasm+0(SB),7,$0
|
2011-02-10 05:02:27 -07:00
|
|
|
// preserve whatever's at the memory location that
|
|
|
|
// the callback will use to store the return value
|
2011-02-01 09:49:24 -07:00
|
|
|
LEAL 8(SP), CX
|
2011-02-10 05:02:27 -07:00
|
|
|
PUSHL 0(CX)(DX*1)
|
|
|
|
ADDL $4, DX // extend argsize by size of return value
|
2011-01-21 19:55:53 -07:00
|
|
|
|
2011-02-01 09:49:24 -07:00
|
|
|
// save registers as required for windows callback
|
|
|
|
PUSHL DI
|
|
|
|
PUSHL SI
|
|
|
|
PUSHL BP
|
|
|
|
PUSHL BX
|
2011-08-10 01:17:28 -06:00
|
|
|
|
|
|
|
// set up SEH frame again
|
|
|
|
PUSHL $runtime·sigtramp(SB)
|
|
|
|
PUSHL 0(FS)
|
|
|
|
MOVL SP, 0(FS)
|
|
|
|
|
|
|
|
// callback parameters
|
2011-02-01 09:49:24 -07:00
|
|
|
PUSHL DX
|
|
|
|
PUSHL CX
|
|
|
|
PUSHL AX
|
|
|
|
|
2011-01-21 19:55:53 -07:00
|
|
|
CLD
|
|
|
|
|
2013-02-22 14:08:56 -07:00
|
|
|
CALL runtime·cgocallback_gofunc(SB)
|
2011-01-21 19:55:53 -07:00
|
|
|
|
2011-02-10 05:02:27 -07:00
|
|
|
POPL AX
|
2011-02-01 09:49:24 -07:00
|
|
|
POPL CX
|
|
|
|
POPL DX
|
2011-08-10 01:17:28 -06:00
|
|
|
|
|
|
|
// pop SEH frame
|
|
|
|
POPL 0(FS)
|
|
|
|
POPL BX
|
|
|
|
|
|
|
|
// restore registers as required for windows callback
|
2011-02-01 09:49:24 -07:00
|
|
|
POPL BX
|
|
|
|
POPL BP
|
|
|
|
POPL SI
|
|
|
|
POPL DI
|
2011-08-10 01:17:28 -06:00
|
|
|
|
2011-01-21 19:55:53 -07:00
|
|
|
CLD
|
|
|
|
|
2011-02-10 05:02:27 -07:00
|
|
|
MOVL -4(CX)(DX*1), AX
|
|
|
|
POPL -4(CX)(DX*1)
|
2011-02-01 09:49:24 -07:00
|
|
|
RET
|
2011-01-21 19:55:53 -07:00
|
|
|
|
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
|
|
|
|
2010-09-11 19:45:16 -06:00
|
|
|
// Layout new m scheduler stack on os stack.
|
|
|
|
MOVL SP, AX
|
|
|
|
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
|
2012-01-08 17:23:07 -07:00
|
|
|
MOVL SI, 0x14(FS)
|
2010-01-06 18:58:55 -07:00
|
|
|
MOVL CX, m(SI)
|
|
|
|
MOVL DX, g(SI)
|
|
|
|
|
2010-09-11 19:45:16 -06:00
|
|
|
// 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
|
|
|
|
|
|
|
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
|
2012-01-08 17:23:07 -07:00
|
|
|
MOVL CX, 0x14(FS)
|
2010-01-06 18:58:55 -07:00
|
|
|
RET
|
2012-05-29 23:10:54 -06:00
|
|
|
|
|
|
|
// void install_exception_handler()
|
|
|
|
TEXT runtime·install_exception_handler(SB),7,$0
|
|
|
|
get_tls(CX)
|
|
|
|
MOVL m(CX), CX // m
|
|
|
|
|
|
|
|
// Set up SEH frame
|
|
|
|
MOVL m_seh(CX), DX
|
|
|
|
MOVL $runtime·sigtramp(SB), AX
|
|
|
|
MOVL AX, seh_handler(DX)
|
|
|
|
MOVL 0(FS), AX
|
|
|
|
MOVL AX, seh_prev(DX)
|
|
|
|
|
|
|
|
// Install it
|
|
|
|
MOVL DX, 0(FS)
|
|
|
|
|
|
|
|
RET
|
2013-02-20 15:48:23 -07:00
|
|
|
|
|
|
|
// void remove_exception_handler()
|
|
|
|
TEXT runtime·remove_exception_handler(SB),7,$0
|
|
|
|
get_tls(CX)
|
|
|
|
MOVL m(CX), CX // m
|
|
|
|
|
|
|
|
// Remove SEH frame
|
|
|
|
MOVL m_seh(CX), DX
|
|
|
|
MOVL seh_prev(DX), AX
|
|
|
|
MOVL AX, 0(FS)
|
|
|
|
|
|
|
|
RET
|