runtime.mcall source code

141 views
Skip to first unread message

yao shucai

unread,
Oct 1, 2015, 4:15:48 PM10/1/15
to golang-nuts
Hi there,

I am reading the source code of the golang recently. I understand the functionality of the mcall except one line code(asm_amd64.s : 184):
183:    PUSHQ AX
184: MOVQ DI, DX
MOVQ 0(DI), DI
CALL DI
POPQ AX

I can't figure out why do we need to move DI to DX? Is there any special purpose of this instruction? 

Thanks!
Shucai

Ian Lance Taylor

unread,
Oct 1, 2015, 4:33:14 PM10/1/15
to yao shucai, golang-nuts
In Go a function pointer points to a block of memory whose first word
contains a pointer to the actual code and whose subsequent words
contain the function closure (see https://golang.org/s/go11func).
When calling the function, a pointer to that block of memory is always
passed in a special register, so that the function can access its
closure if necessary. On amd64, the closure pointer is passed in the
DX register.

Ian

yao shucai

unread,
Oct 1, 2015, 4:43:20 PM10/1/15
to golang-nuts, yao20...@gmail.com

Get it. Thank you very much!

Shucai
Reply all
Reply to author
Forward
0 new messages