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"
|
|
|
|
|
|
|
|
TEXT get_kernel_module(SB),7,$0
|
|
|
|
MOVL 0x30(FS), AX // get PEB
|
|
|
|
MOVL 0x0c(AX), AX // get PEB_LDR_DATA
|
|
|
|
MOVL 0x1c(AX), AX // get init order module list
|
|
|
|
MOVL (AX), AX // get next entry (kernel module)
|
|
|
|
MOVL 0x08(AX), AX // get base of module
|
|
|
|
RET
|
|
|
|
|
2010-09-11 19:45:16 -06:00
|
|
|
// void *stdcall_raw(void *fn, int32 count, uintptr *args)
|
|
|
|
TEXT stdcall_raw(SB),7,$4
|
|
|
|
// 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
|
|
|
|
|
|
|
|
RET
|
|
|
|
|
|
|
|
// void tstart(M *newm);
|
|
|
|
TEXT tstart(SB),7,$0
|
|
|
|
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
|
|
|
MOVL SP, DI // remember stack
|
|
|
|
|
|
|
|
// 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
|
|
|
|
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
|
|
|
|
2010-09-11 19:45:16 -06:00
|
|
|
PUSHL DI // original stack
|
2010-01-06 18:58:55 -07:00
|
|
|
|
|
|
|
CALL stackcheck(SB) // clobbers AX,CX
|
2010-09-11 19:45:16 -06:00
|
|
|
|
|
|
|
CALL mstart(SB)
|
|
|
|
|
|
|
|
POPL DI // original stack
|
|
|
|
MOVL DI, SP
|
|
|
|
|
|
|
|
RET
|
|
|
|
|
|
|
|
// uint32 tstart_stdcall(M *newm);
|
|
|
|
TEXT tstart_stdcall(SB),7,$0
|
|
|
|
MOVL newm+4(SP), BX
|
|
|
|
|
|
|
|
PUSHL BX
|
|
|
|
CALL tstart+0(SB)
|
|
|
|
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)
|
|
|
|
TEXT setldt(SB),7,$0
|
|
|
|
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.
|
|
|
|
TEXT 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
|