2012-08-31 11:21:13 -06:00
|
|
|
// Copyright 2010 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 "zasm_GOOS_GOARCH.h"
|
2013-08-07 13:20:05 -06:00
|
|
|
#include "../../cmd/ld/textflag.h"
|
2012-08-31 11:21:13 -06:00
|
|
|
|
|
|
|
// setldt(int entry, int address, int limit)
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·setldt(SB),NOSPLIT,$0
|
2012-08-31 11:21:13 -06:00
|
|
|
RET
|
|
|
|
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·open(SB),NOSPLIT,$0
|
2012-08-31 11:21:13 -06:00
|
|
|
MOVQ $0x8000, AX
|
|
|
|
MOVQ $14, BP
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·pread(SB),NOSPLIT,$0
|
2012-08-31 11:21:13 -06:00
|
|
|
MOVQ $0x8000, AX
|
|
|
|
MOVQ $50, BP
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·pwrite(SB),NOSPLIT,$0
|
2012-08-31 11:21:13 -06:00
|
|
|
MOVQ $0x8000, AX
|
|
|
|
MOVQ $51, BP
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2012-12-17 09:07:40 -07:00
|
|
|
// int32 _seek(int64*, int32, int64, int32)
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT _seek<>(SB),NOSPLIT,$0
|
2012-12-17 09:07:40 -07:00
|
|
|
MOVQ $0x8000, AX
|
|
|
|
MOVQ $39, BP
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
|
|
|
// int64 seek(int32, int64, int32)
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·seek(SB),NOSPLIT,$56
|
2012-12-17 09:07:40 -07:00
|
|
|
LEAQ new+48(SP), CX
|
|
|
|
MOVQ CX, 0(SP)
|
|
|
|
MOVQ fd+0(FP), CX
|
|
|
|
MOVQ CX, 8(SP)
|
|
|
|
MOVQ off+8(FP), CX
|
|
|
|
MOVQ CX, 16(SP)
|
|
|
|
MOVQ whence+16(FP), CX
|
|
|
|
MOVQ CX, 24(SP)
|
|
|
|
CALL _seek<>(SB)
|
|
|
|
CMPL AX, $0
|
|
|
|
JGE 2(PC)
|
|
|
|
MOVQ $-1, new+48(SP)
|
|
|
|
MOVQ new+48(SP), AX
|
|
|
|
RET
|
|
|
|
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·close(SB),NOSPLIT,$0
|
2012-08-31 11:21:13 -06:00
|
|
|
MOVQ $0x8000, AX
|
|
|
|
MOVQ $4, BP
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·exits(SB),NOSPLIT,$0
|
2012-08-31 11:21:13 -06:00
|
|
|
MOVQ $0x8000, AX
|
|
|
|
MOVQ $8, BP
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·brk_(SB),NOSPLIT,$0
|
2012-08-31 11:21:13 -06:00
|
|
|
MOVQ $0x8000, AX
|
|
|
|
MOVQ $24, BP
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·sleep(SB),NOSPLIT,$0
|
2012-08-31 11:21:13 -06:00
|
|
|
MOVQ $0x8000, AX
|
|
|
|
MOVQ $17, BP
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·plan9_semacquire(SB),NOSPLIT,$0
|
2012-08-31 11:21:13 -06:00
|
|
|
MOVQ $0x8000, AX
|
|
|
|
MOVQ $37, BP
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·plan9_tsemacquire(SB),NOSPLIT,$0
|
2012-08-31 11:21:13 -06:00
|
|
|
MOVQ $0x8000, AX
|
|
|
|
MOVQ $52, BP
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·notify(SB),NOSPLIT,$0
|
2012-08-31 11:21:13 -06:00
|
|
|
MOVQ $0x8000, AX
|
|
|
|
MOVQ $28, BP
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·noted(SB),NOSPLIT,$0
|
2012-08-31 11:21:13 -06:00
|
|
|
MOVQ $0x8000, AX
|
|
|
|
MOVQ $29, BP
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·plan9_semrelease(SB),NOSPLIT,$0
|
2012-08-31 11:21:13 -06:00
|
|
|
MOVQ $0x8000, AX
|
|
|
|
MOVQ $38, BP
|
|
|
|
SYSCALL
|
|
|
|
RET
|
2013-01-30 03:53:56 -07:00
|
|
|
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·nanotime(SB),NOSPLIT,$0
|
2013-02-25 17:56:08 -07:00
|
|
|
MOVQ $0x8000, AX
|
|
|
|
MOVQ $60, BP
|
|
|
|
SYSCALL
|
|
|
|
RET
|
|
|
|
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·rfork(SB),NOSPLIT,$0
|
2012-08-31 11:21:13 -06:00
|
|
|
MOVQ $0x8000, AX
|
|
|
|
MOVQ $19, BP // rfork
|
|
|
|
SYSCALL
|
|
|
|
|
|
|
|
// In parent, return.
|
|
|
|
CMPQ AX, $0
|
|
|
|
JEQ 2(PC)
|
|
|
|
RET
|
|
|
|
|
|
|
|
// In child on forked stack.
|
|
|
|
MOVQ mm+24(SP), BX // m
|
|
|
|
MOVQ gg+32(SP), DX // g
|
|
|
|
MOVQ fn+40(SP), SI // fn
|
|
|
|
|
|
|
|
// set SP to be on the new child stack
|
|
|
|
MOVQ stack+16(SP), CX
|
|
|
|
MOVQ CX, SP
|
|
|
|
|
|
|
|
// Initialize m, g.
|
|
|
|
get_tls(AX)
|
|
|
|
MOVQ DX, g(AX)
|
all: remove 'extern register M *m' from runtime
The runtime has historically held two dedicated values g (current goroutine)
and m (current thread) in 'extern register' slots (TLS on x86, real registers
backed by TLS on ARM).
This CL removes the extern register m; code now uses g->m.
On ARM, this frees up the register that formerly held m (R9).
This is important for NaCl, because NaCl ARM code cannot use R9 at all.
The Go 1 macrobenchmarks (those with per-op times >= 10 µs) are unaffected:
BenchmarkBinaryTree17 5491374955 5471024381 -0.37%
BenchmarkFannkuch11 4357101311 4275174828 -1.88%
BenchmarkGobDecode 11029957 11364184 +3.03%
BenchmarkGobEncode 6852205 6784822 -0.98%
BenchmarkGzip 650795967 650152275 -0.10%
BenchmarkGunzip 140962363 141041670 +0.06%
BenchmarkHTTPClientServer 71581 73081 +2.10%
BenchmarkJSONEncode 31928079 31913356 -0.05%
BenchmarkJSONDecode 117470065 113689916 -3.22%
BenchmarkMandelbrot200 6008923 5998712 -0.17%
BenchmarkGoParse 6310917 6327487 +0.26%
BenchmarkRegexpMatchMedium_1K 114568 114763 +0.17%
BenchmarkRegexpMatchHard_1K 168977 169244 +0.16%
BenchmarkRevcomp 935294971 914060918 -2.27%
BenchmarkTemplate 145917123 148186096 +1.55%
Minux previous reported larger variations, but these were caused by
run-to-run noise, not repeatable slowdowns.
Actual code changes by Minux.
I only did the docs and the benchmarking.
LGTM=dvyukov, iant, minux
R=minux, josharian, iant, dave, bradfitz, dvyukov
CC=golang-codereviews
https://golang.org/cl/109050043
2014-06-26 09:54:39 -06:00
|
|
|
MOVQ BX, g_m(DX)
|
2012-08-31 11:21:13 -06:00
|
|
|
|
2012-09-24 10:24:45 -06:00
|
|
|
// Initialize AX from pid in TLS.
|
liblink: introduce TLS register on 386 and amd64
When I did the original 386 ports on Linux and OS X, I chose to
define GS-relative expressions like 4(GS) as relative to the actual
thread-local storage base, which was usually GS but might not be
(it might be FS, or it might be a different constant offset from GS or FS).
The original scope was limited but since then the rewrites have
gotten out of control. Sometimes GS is rewritten, sometimes FS.
Some ports do other rewrites to enable shared libraries and
other linking. At no point in the code is it clear whether you are
looking at the real GS/FS or some synthesized thing that will be
rewritten. The code manipulating all these is duplicated in many
places.
The first step to fixing issue 7719 is to make the code intelligible
again.
This CL adds an explicit TLS pseudo-register to the 386 and amd64.
As a register, TLS refers to the thread-local storage base, and it
can only be loaded into another register:
MOVQ TLS, AX
An offset from the thread-local storage base is written off(reg)(TLS*1).
Semantically it is off(reg), but the (TLS*1) annotation marks this as
indexing from the loaded TLS base. This emits a relocation so that
if the linker needs to adjust the offset, it can. For example:
MOVQ TLS, AX
MOVQ 8(AX)(TLS*1), CX // load m into CX
On systems that support direct access to the TLS memory, this
pair of instructions can be reduced to a direct TLS memory reference:
MOVQ 8(TLS), CX // load m into CX
The 2-instruction and 1-instruction forms correspond roughly to
ELF TLS initial exec mode and ELF TLS local exec mode, respectively.
Liblink applies this rewrite on systems that support the 1-instruction form.
The decision is made using only the operating system (and probably
the -shared flag, eventually), not the link mode. If some link modes
on a particular operating system require the 2-instruction form,
then all builds for that operating system will use the 2-instruction
form, so that the link mode decision can be delayed to link time.
Obviously it is late to be making changes like this, but I despair
of correcting issue 7719 and issue 7164 without it. To make sure
I am not changing existing behavior, I built a "hello world" program
for every GOOS/GOARCH combination we have and then worked
to make sure that the rewrite generates exactly the same binaries,
byte for byte. There are a handful of TODOs in the code marking
kludges to get the byte-for-byte property, but at least now I can
explain exactly how each binary is handled.
The targets I tested this way are:
darwin-386
darwin-amd64
dragonfly-386
dragonfly-amd64
freebsd-386
freebsd-amd64
freebsd-arm
linux-386
linux-amd64
linux-arm
nacl-386
nacl-amd64p32
netbsd-386
netbsd-amd64
openbsd-386
openbsd-amd64
plan9-386
plan9-amd64
solaris-amd64
windows-386
windows-amd64
There were four exceptions to the byte-for-byte goal:
windows-386 and windows-amd64 have a time stamp
at bytes 137 and 138 of the header.
darwin-386 and plan9-386 have five or six modified
bytes in the middle of the Go symbol table, caused by
editing comments in runtime/sys_{darwin,plan9}_386.s.
Fixes #7164.
LGTM=iant
R=iant, aram, minux.ma, dave
CC=golang-codereviews
https://golang.org/cl/87920043
2014-04-15 11:45:39 -06:00
|
|
|
MOVQ 0(FS), AX
|
2012-08-31 11:21:13 -06:00
|
|
|
MOVQ AX, m_procid(BX) // save pid as m->procid
|
|
|
|
|
|
|
|
CALL runtime·stackcheck(SB) // smashes AX, CX
|
|
|
|
|
|
|
|
MOVQ 0(DX), DX // paranoia; check they are not nil
|
|
|
|
MOVQ 0(BX), BX
|
|
|
|
|
|
|
|
CALL SI // fn()
|
|
|
|
CALL runtime·exit(SB)
|
|
|
|
RET
|
|
|
|
|
|
|
|
// This is needed by asm_amd64.s
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·settls(SB),NOSPLIT,$0
|
2012-08-31 11:21:13 -06:00
|
|
|
RET
|
2012-10-05 14:23:30 -06:00
|
|
|
|
2013-01-30 03:53:56 -07:00
|
|
|
// void sigtramp(void *ureg, int8 *note)
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·sigtramp(SB),NOSPLIT,$0
|
2013-01-30 03:53:56 -07:00
|
|
|
get_tls(AX)
|
|
|
|
|
all: remove 'extern register M *m' from runtime
The runtime has historically held two dedicated values g (current goroutine)
and m (current thread) in 'extern register' slots (TLS on x86, real registers
backed by TLS on ARM).
This CL removes the extern register m; code now uses g->m.
On ARM, this frees up the register that formerly held m (R9).
This is important for NaCl, because NaCl ARM code cannot use R9 at all.
The Go 1 macrobenchmarks (those with per-op times >= 10 µs) are unaffected:
BenchmarkBinaryTree17 5491374955 5471024381 -0.37%
BenchmarkFannkuch11 4357101311 4275174828 -1.88%
BenchmarkGobDecode 11029957 11364184 +3.03%
BenchmarkGobEncode 6852205 6784822 -0.98%
BenchmarkGzip 650795967 650152275 -0.10%
BenchmarkGunzip 140962363 141041670 +0.06%
BenchmarkHTTPClientServer 71581 73081 +2.10%
BenchmarkJSONEncode 31928079 31913356 -0.05%
BenchmarkJSONDecode 117470065 113689916 -3.22%
BenchmarkMandelbrot200 6008923 5998712 -0.17%
BenchmarkGoParse 6310917 6327487 +0.26%
BenchmarkRegexpMatchMedium_1K 114568 114763 +0.17%
BenchmarkRegexpMatchHard_1K 168977 169244 +0.16%
BenchmarkRevcomp 935294971 914060918 -2.27%
BenchmarkTemplate 145917123 148186096 +1.55%
Minux previous reported larger variations, but these were caused by
run-to-run noise, not repeatable slowdowns.
Actual code changes by Minux.
I only did the docs and the benchmarking.
LGTM=dvyukov, iant, minux
R=minux, josharian, iant, dave, bradfitz, dvyukov
CC=golang-codereviews
https://golang.org/cl/109050043
2014-06-26 09:54:39 -06:00
|
|
|
// check that g exists
|
|
|
|
MOVQ g(AX), BX
|
2013-01-30 03:53:56 -07:00
|
|
|
CMPQ BX, $0
|
|
|
|
JNE 3(PC)
|
2013-07-11 14:39:39 -06:00
|
|
|
CALL runtime·badsignal2(SB) // will exit
|
2013-01-30 03:53:56 -07:00
|
|
|
RET
|
|
|
|
|
|
|
|
// save args
|
|
|
|
MOVQ ureg+8(SP), CX
|
|
|
|
MOVQ note+16(SP), DX
|
|
|
|
|
|
|
|
// change stack
|
all: remove 'extern register M *m' from runtime
The runtime has historically held two dedicated values g (current goroutine)
and m (current thread) in 'extern register' slots (TLS on x86, real registers
backed by TLS on ARM).
This CL removes the extern register m; code now uses g->m.
On ARM, this frees up the register that formerly held m (R9).
This is important for NaCl, because NaCl ARM code cannot use R9 at all.
The Go 1 macrobenchmarks (those with per-op times >= 10 µs) are unaffected:
BenchmarkBinaryTree17 5491374955 5471024381 -0.37%
BenchmarkFannkuch11 4357101311 4275174828 -1.88%
BenchmarkGobDecode 11029957 11364184 +3.03%
BenchmarkGobEncode 6852205 6784822 -0.98%
BenchmarkGzip 650795967 650152275 -0.10%
BenchmarkGunzip 140962363 141041670 +0.06%
BenchmarkHTTPClientServer 71581 73081 +2.10%
BenchmarkJSONEncode 31928079 31913356 -0.05%
BenchmarkJSONDecode 117470065 113689916 -3.22%
BenchmarkMandelbrot200 6008923 5998712 -0.17%
BenchmarkGoParse 6310917 6327487 +0.26%
BenchmarkRegexpMatchMedium_1K 114568 114763 +0.17%
BenchmarkRegexpMatchHard_1K 168977 169244 +0.16%
BenchmarkRevcomp 935294971 914060918 -2.27%
BenchmarkTemplate 145917123 148186096 +1.55%
Minux previous reported larger variations, but these were caused by
run-to-run noise, not repeatable slowdowns.
Actual code changes by Minux.
I only did the docs and the benchmarking.
LGTM=dvyukov, iant, minux
R=minux, josharian, iant, dave, bradfitz, dvyukov
CC=golang-codereviews
https://golang.org/cl/109050043
2014-06-26 09:54:39 -06:00
|
|
|
MOVQ g_m(BX), BX
|
2013-01-30 03:53:56 -07:00
|
|
|
MOVQ m_gsignal(BX), R10
|
|
|
|
MOVQ g_stackbase(R10), BP
|
|
|
|
MOVQ BP, SP
|
|
|
|
|
|
|
|
// make room for args and g
|
|
|
|
SUBQ $32, SP
|
|
|
|
|
|
|
|
// save g
|
|
|
|
MOVQ g(AX), BP
|
|
|
|
MOVQ BP, 24(SP)
|
|
|
|
|
|
|
|
// g = m->gsignal
|
|
|
|
MOVQ R10, g(AX)
|
|
|
|
|
|
|
|
// load args and call sighandler
|
|
|
|
MOVQ CX, 0(SP)
|
|
|
|
MOVQ DX, 8(SP)
|
|
|
|
MOVQ BP, 16(SP)
|
|
|
|
|
|
|
|
CALL runtime·sighandler(SB)
|
|
|
|
|
|
|
|
// restore g
|
|
|
|
get_tls(BX)
|
|
|
|
MOVQ 24(SP), R10
|
|
|
|
MOVQ R10, g(BX)
|
|
|
|
|
|
|
|
// call noted(AX)
|
|
|
|
MOVQ AX, 0(SP)
|
|
|
|
CALL runtime·noted(SB)
|
|
|
|
RET
|
|
|
|
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·setfpmasks(SB),NOSPLIT,$8
|
2012-10-05 14:23:30 -06:00
|
|
|
STMXCSR 0(SP)
|
|
|
|
MOVL 0(SP), AX
|
|
|
|
ANDL $~0x3F, AX
|
|
|
|
ORL $(0x3F<<7), AX
|
|
|
|
MOVL AX, 0(SP)
|
|
|
|
LDMXCSR 0(SP)
|
|
|
|
RET
|
2013-03-07 16:54:44 -07:00
|
|
|
|
|
|
|
#define ERRMAX 128 /* from os_plan9.h */
|
|
|
|
|
|
|
|
// func errstr() String
|
|
|
|
// Only used by package syscall.
|
|
|
|
// Grab error string due to a syscall made
|
|
|
|
// in entersyscall mode, without going
|
|
|
|
// through the allocator (issue 4994).
|
|
|
|
// See ../syscall/asm_plan9_386.s:/·Syscall/
|
2013-08-07 13:20:05 -06:00
|
|
|
TEXT runtime·errstr(SB),NOSPLIT,$0
|
2013-03-07 16:54:44 -07:00
|
|
|
get_tls(AX)
|
all: remove 'extern register M *m' from runtime
The runtime has historically held two dedicated values g (current goroutine)
and m (current thread) in 'extern register' slots (TLS on x86, real registers
backed by TLS on ARM).
This CL removes the extern register m; code now uses g->m.
On ARM, this frees up the register that formerly held m (R9).
This is important for NaCl, because NaCl ARM code cannot use R9 at all.
The Go 1 macrobenchmarks (those with per-op times >= 10 µs) are unaffected:
BenchmarkBinaryTree17 5491374955 5471024381 -0.37%
BenchmarkFannkuch11 4357101311 4275174828 -1.88%
BenchmarkGobDecode 11029957 11364184 +3.03%
BenchmarkGobEncode 6852205 6784822 -0.98%
BenchmarkGzip 650795967 650152275 -0.10%
BenchmarkGunzip 140962363 141041670 +0.06%
BenchmarkHTTPClientServer 71581 73081 +2.10%
BenchmarkJSONEncode 31928079 31913356 -0.05%
BenchmarkJSONDecode 117470065 113689916 -3.22%
BenchmarkMandelbrot200 6008923 5998712 -0.17%
BenchmarkGoParse 6310917 6327487 +0.26%
BenchmarkRegexpMatchMedium_1K 114568 114763 +0.17%
BenchmarkRegexpMatchHard_1K 168977 169244 +0.16%
BenchmarkRevcomp 935294971 914060918 -2.27%
BenchmarkTemplate 145917123 148186096 +1.55%
Minux previous reported larger variations, but these were caused by
run-to-run noise, not repeatable slowdowns.
Actual code changes by Minux.
I only did the docs and the benchmarking.
LGTM=dvyukov, iant, minux
R=minux, josharian, iant, dave, bradfitz, dvyukov
CC=golang-codereviews
https://golang.org/cl/109050043
2014-06-26 09:54:39 -06:00
|
|
|
MOVQ g(AX), BX
|
|
|
|
MOVQ g_m(BX), BX
|
2013-03-07 16:54:44 -07:00
|
|
|
MOVQ m_errstr(BX), CX
|
|
|
|
MOVQ CX, 8(SP)
|
|
|
|
MOVQ $ERRMAX, 16(SP)
|
|
|
|
MOVQ $0x8000, AX
|
|
|
|
MOVQ $41, BP
|
|
|
|
SYSCALL
|
2013-03-08 21:39:15 -07:00
|
|
|
|
|
|
|
// syscall requires caller-save
|
|
|
|
MOVQ 8(SP), CX
|
|
|
|
|
|
|
|
// push the argument
|
|
|
|
PUSHQ CX
|
2013-03-07 16:54:44 -07:00
|
|
|
CALL runtime·findnull(SB)
|
2013-03-08 21:39:15 -07:00
|
|
|
POPQ CX
|
2013-03-07 16:54:44 -07:00
|
|
|
MOVQ AX, 16(SP)
|
|
|
|
RET
|