// 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 "go_asm.h"
#include "go_tls.h"
#include "funcdata.h"
#include "textflag.h"
// _rt0_386 is common startup code for most 386 systems when using
// internal linking. This is the entry point for the program from the
// kernel for an ordinary -buildmode=exe program. The stack holds the
// number of arguments and the C-style argv.
TEXT _rt0_386(SB),NOSPLIT,$8
MOVL 8(SP), AX // argc
LEAL 12(SP), BX // argv
MOVL AX, 0(SP)
MOVL BX, 4(SP)
JMP runtime·rt0_go(SB)
// _rt0_386_lib is common startup code for most 386 systems when
// using -buildmode=c-archive or -buildmode=c-shared. The linker will
// arrange to invoke this function as a global constructor (for
// c-archive) or when the shared library is loaded (for c-shared).
// We expect argc and argv to be passed on the stack following the
// usual C ABI.
TEXT _rt0_386_lib(SB),NOSPLIT,$0
PUSHL BP
MOVL SP, BP
PUSHL BX
PUSHL SI
PUSHL DI
MOVL 8(BP), AX
MOVL AX, _rt0_386_lib_argc<>(SB)
MOVL 12(BP), AX
MOVL AX, _rt0_386_lib_argv<>(SB)
// Synchronous initialization.
CALL runtime·libpreinit(SB)
SUBL $8, SP
// Create a new thread to do the runtime initialization.
MOVL _cgo_sys_thread_create(SB), AX
TESTL AX, AX
JZ nocgo
// Align stack to call C function.
// We moved SP to BP above, but BP was clobbered by the libpreinit call.
MOVL SP, BP
ANDL $~15, SP
MOVL $_rt0_386_lib_go(SB), BX
MOVL BX, 0(SP)
MOVL $0, 4(SP)
CALL AX
MOVL BP, SP
JMP restore
nocgo:
MOVL $0x800000, 0(SP) // stacksize = 8192KB
MOVL $_rt0_386_lib_go(SB), AX
MOVL AX, 4(SP) // fn
CALL runtime·newosproc0(SB)
restore:
ADDL $8, SP
POPL DI
POPL SI
POPL BX
POPL BP
RET
// _rt0_386_lib_go initializes the Go runtime.
// This is started in a separate thread by _rt0_386_lib.
TEXT _rt0_386_lib_go(SB),NOSPLIT,$8
MOVL _rt0_386_lib_argc<>(SB), AX
MOVL AX, 0(SP)
MOVL _rt0_386_lib_argv<>(SB), AX
MOVL AX, 4(SP)
JMP runtime·rt0_go(SB)
DATA _rt0_386_lib_argc<>(SB)/4, $0
GLOBL _rt0_386_lib_argc<>(SB),NOPTR, $4
DATA _rt0_386_lib_argv<>(SB)/4, $0
GLOBL _rt0_386_lib_argv<>(SB),NOPTR, $4
TEXT runtime·rt0_go(SB),NOSPLIT|NOFRAME,$0
// Copy arguments forward on an even stack.
// Users of this function jump to it, they don't call it.
MOVL 0(SP), AX
MOVL 4(SP), BX
SUBL $128, SP // plenty of scratch
ANDL $~15, SP
MOVL AX, 120(SP) // save argc, argv away
MOVL BX, 124(SP)
// set default stack bounds.
// _cgo_init may update stackguard.
MOVL $runtime·g0(SB), BP
LEAL (-64*1024+104)(SP), BX
MOVL BX, g_stackguard0(BP)
MOVL BX, g_stackguard1(BP)
MOVL BX, (g_stack+stack_lo)(BP)
MOVL SP, (g_stack+stack_hi)(BP)
// find out information about the processor we're on
// first see if CPUID instruction is supported.
PUSHFL
PUSHFL
XORL $(1<<21), 0(SP) // flip ID bit
POPFL
PUSHFL
POPL AX
XORL 0(SP), AX
POPFL // restore EFLAGS
TESTL $(1<<21), AX
JNE has_cpuid
bad_proc: // show that the program requires MMX.
MOVL $2, 0(SP)
MOVL $bad_proc
|