diff options
Diffstat (limited to 'src/pkg/runtime/windows/386/sys.s')
-rw-r--r-- | src/pkg/runtime/windows/386/sys.s | 145 |
1 files changed, 114 insertions, 31 deletions
diff --git a/src/pkg/runtime/windows/386/sys.s b/src/pkg/runtime/windows/386/sys.s index 7f99b34de..d1a8a49a9 100644 --- a/src/pkg/runtime/windows/386/sys.s +++ b/src/pkg/runtime/windows/386/sys.s @@ -5,7 +5,7 @@ #include "386/asm.h" // void *stdcall_raw(void *fn, int32 count, uintptr *args) -TEXT runtime·stdcall_raw(SB),7,$4 +TEXT runtime·stdcall_raw(SB),7,$0 // Copy arguments from stack. MOVL fn+0(FP), AX MOVL count+4(FP), CX // words @@ -14,17 +14,18 @@ TEXT runtime·stdcall_raw(SB),7,$4 // Switch to m->g0 if needed. get_tls(DI) MOVL m(DI), DX - MOVL g(DI), SI - MOVL SI, 0(SP) // save g - MOVL SP, m_gostack(DX) // save SP + MOVL 0(FS), SI + MOVL SI, m_sehframe(DX) MOVL m_g0(DX), SI CMPL g(DI), SI - JEQ 3(PC) + MOVL SP, BX + JEQ 2(PC) MOVL (m_sched+gobuf_sp)(DX), SP + PUSHL BX + PUSHL g(DI) MOVL SI, g(DI) // Copy args to new stack. - SUBL $(10*4), SP // padding MOVL CX, BX SALL $2, BX SUBL BX, SP // room for args @@ -38,28 +39,122 @@ TEXT runtime·stdcall_raw(SB),7,$4 // Restore original SP, g. get_tls(DI) - MOVL m(DI), DX - MOVL m_gostack(DX), SP // restore SP - MOVL 0(SP), SI // restore g - MOVL SI, g(DI) + POPL g(DI) + POPL SP // Someday the convention will be D is always cleared. CLD - RET + RET + +// 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 + +TEXT runtime·sigtramp(SB),7,$0 + PUSHL BP // cdecl + 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 + MOVL 4(BX), CX // exception flags + ANDL $6, CX + MOVL $1, AX + JNZ sigdone + + // 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 + JZ sigdone + + // call windows default handler early + MOVL 4(SP), BX // our SEH frame + MOVL 0(BX), BX // SEH frame of default handler + MOVL BX, 4(SP) // set establisher frame + CALL 4(BX) + +sigdone: + RET + +// Called from dynamic function created by ../thread.c compilecallback, +// running on Windows stack (not Go stack). +// BX, BP, SI, DI registers and DF flag are preserved +// as required by windows callback convention. +// AX = address of go func we need to call +// DX = total size of arguments +// +TEXT runtime·callbackasm+0(SB),7,$0 + LEAL 8(SP), CX + + // save registers as required for windows callback + PUSHL 0(FS) + PUSHL DI + PUSHL SI + PUSHL BP + PUSHL BX + PUSHL DX + PUSHL CX + PUSHL AX + + // reinstall our SEH handler + get_tls(CX) + MOVL m(CX), CX + MOVL m_sehframe(CX), CX + MOVL CX, 0(FS) + CLD + + CALL runtime·cgocallback(SB) + + // restore registers as required for windows callback + POPL CX + POPL CX + POPL DX + POPL BX + POPL BP + POPL SI + POPL DI + POPL 0(FS) + CLD + + RET // void tstart(M *newm); TEXT runtime·tstart(SB),7,$0 MOVL newm+4(SP), CX // m MOVL m_g0(CX), DX // g - MOVL SP, DI // remember stack + // Set up SEH frame + PUSHL $runtime·sigtramp(SB) + PUSHL 0(FS) + MOVL SP, 0(FS) // Layout new m scheduler stack on os stack. MOVL SP, AX - SUBL $256, AX // just some space for ourselves MOVL AX, g_stackbase(DX) - SUBL $8192, AX // stack size + SUBL $(64*1024), AX // stack size MOVL AX, g_stackguard(DX) // Set up tls. @@ -68,20 +163,17 @@ TEXT runtime·tstart(SB),7,$0 MOVL CX, m(SI) MOVL DX, g(SI) - // Use scheduler stack now. - MOVL g_stackbase(DX), SP - // Someday the convention will be D is always cleared. CLD - PUSHL DI // original stack - - CALL runtime·stackcheck(SB) // clobbers AX,CX + CALL runtime·stackcheck(SB) // clobbers AX,CX CALL runtime·mstart(SB) - POPL DI // original stack - MOVL DI, SP + // Pop SEH frame + MOVL 0(FS), SP + POPL 0(FS) + POPL CX RET @@ -107,12 +199,3 @@ TEXT runtime·setldt(SB),7,$0 MOVL address+4(FP), CX MOVL CX, 0x2c(FS) RET - -// for now, return 0,0. only used for internal performance monitoring. -TEXT runtime·gettime(SB),7,$0 - MOVL sec+0(FP), DI - MOVL $0, (DI) - MOVL $0, 4(DI) // zero extend 32 -> 64 bits - MOVL usec+4(FP), DI - MOVL $0, (DI) - RET |