diff --git a/doc/asm.html b/doc/asm.html index cc8598aeff8042..7173d9bd514fb2 100644 --- a/doc/asm.html +++ b/doc/asm.html @@ -464,6 +464,57 @@
+If a package has any .s files, then go build
will direct
+the compiler to emit a special header called go_asm.h
,
+which the .s files can then #include
.
+The file contains symbolic #define
constants for the
+offsets of Go struct fields, the sizes of Go struct types, and most
+Go const
declarations defined in the current package.
+Go assembly should avoid making assumptions about the layout of Go
+types and instead use these constants.
+This improves the readability of assembly code, and keeps it robust to
+changes in data layout either in the Go type definitions or in the
+layout rules used by the Go compiler.
+
+Constants are of the form const_name
.
+For example, given the Go declaration const bufSize =
+1024
, assembly code can refer to the value of this constant
+as const_bufSize
.
+
+Field offsets are of the form type_field
.
+Struct sizes are of the form type__size
.
+For example, consider the following Go definition:
+
+type reader struct { + buf [bufSize]byte + r int +} ++ +
+Assembly can refer to the size of this struct
+as reader__size
and the offsets of the two fields
+as reader_buf
and reader_r
.
+Hence, if register R1
contains a pointer to
+a reader
, assembly can reference the r
field
+as reader_r(R1)
.
+
+If any of these #define
names are ambiguous (for example,
+a struct with a _size
field), #include
+"go_asm.h"
will fail with a "redefinition of macro" error.
+
@@ -615,21 +666,15 @@
The runtime pointer to the g
structure is maintained
through the value of an otherwise unused (as far as Go is concerned) register in the MMU.
-An OS-dependent macro get_tls
is defined for the assembler if the source is
-in the runtime
package and includes a special header, go_tls.h
:
+In the runtime package, assembly code can include go_tls.h
, which defines
+an OS- and architecture-dependent macro get_tls
for accessing this register.
+The get_tls
macro takes one argument, which is the register to load the
+g
pointer into.
-#include "go_tls.h" --
-Within the runtime, the get_tls
macro loads its argument register
-with a pointer to the g
pointer, and the g
struct
-contains the m
pointer.
-There's another special header containing the offsets for each
-element of g
, called go_asm.h
.
-The sequence to load g
and m
using CX
looks like this:
+For example, the sequence to load g
and m
+using CX
looks like this:
@@ -642,8 +687,7 @@32-bit Intel 386
-Note: The code above works only in the runtime
package, while go_tls.h
also
-applies to arm, amd64 and amd64p32, and go_asm.h
applies to all architectures.
+The get_tls
macro is also defined on amd64.