github.com/razvanm/vanadium-go-1.3@v0.0.0-20160721203343-4a65068e5915/src/runtime/ppapi/ppapi_nacl_386.st (about)

     1  // -*- mode: asm -*-
     2  // Copyright 2014 The Go Authors. All rights reserved.
     3  // Use of this source code is governed by a BSD-style
     4  // license that can be found in the LICENSE file.
     5  
     6  // TODO(jyh): Figure out why GOOS/GOARCH don't work.
     7  // #include "../zasm_GOOS_GOARCH.h"
     8  #include "../zasm_nacl_386.h"
     9  #include "../../cmd/ld/textflag.h"
    10  #include "../funcdata.h"
    11  #include "../irt_nacl.h"
    12  #include "ppapi_GOOS.h"
    13  
    14  // Architectural parameters.
    15  //
    16  //sizeof int64 8 4
    17  //sizeof float64 8 4
    18  
    19  // doreturn(ty) expands to the instruction sequence for saving the return
    20  // value into the caller's stack frame.
    21  {% macro doreturn(resultType, off) -%}
    22  	{% set kind = resultType.kind -%}
    23  	{% if kind == 'int32' or kind == '*' -%}
    24  	MOVL	AX, {{off}}(BP)
    25  	{%- elif kind == 'int64' -%}
    26  	MOVL	AX, {{off}}(BP)
    27  	MOVL	DX, ({{off}}+4)(BP)
    28  	{%- elif kind == 'float32' -%}
    29  	FMOVLP	F0, {{off}}(BP)
    30  	{%- elif kind == 'float64' -%}
    31  	FMOVDP	F0, {{off}}(BP)
    32  	{%- else -%}
    33  	// No return value.
    34  	{%- endif %}
    35  {%- endmacro %}
    36  
    37  // Callbacks are invoked through cgocallback.
    38  {% for func in callbacks -%}
    39  {% set fsize = framesize(func) -%}
    40  TEXT ppapi·{{func.name}}(SB),NOSPLIT,${{fsize+32}}
    41  	MOVL	BP, {{fsize+16}}(SP)
    42  	MOVL	BX, {{fsize+20}}(SP)
    43  	MOVL	SI, {{fsize+24}}(SP)
    44  	MOVL	DI, {{fsize+28}}(SP)
    45  	{% for aoff in range(0, fsize, 4) -%}
    46  	MOVL	arg{{aoff}}+{{aoff}}(FP), AX
    47  	MOVL	AX, {{aoff+12}}(SP)
    48  	{% endfor -%}
    49  	MOVL	$·{{func.name}}(SB), AX
    50  	MOVL	AX, 0(SP)
    51  	LEAL	12(SP), AX
    52  	MOVL	AX, 4(SP)
    53  	MOVL	${{fsize+4}}, 8(SP)
    54  	MOVL	$0, {{fsize+12}}(SP)
    55  	CALL	runtime·cgocallback(SB)
    56  	MOVL	{{fsize+12}}(SP), AX
    57  	MOVL	{{fsize+16}}(SP), BP
    58  	MOVL	{{fsize+20}}(SP), BX
    59  	MOVL	{{fsize+24}}(SP), SI
    60  	MOVL	{{fsize+28}}(SP), DI
    61  	RET
    62  
    63  {% endfor %}
    64  
    65  // PPAPI calls are invoked using cgocall.
    66  {% for func in functions -%}
    67  {% set fsize = framesize(func) -%}
    68  TEXT ·{{func.name}}(SB),NOSPLIT,$8
    69  	MOVL	$ppapi·{{func.name}}(SB), 0(SP)
    70  	LEAL	arg0+0(FP), AX
    71  	MOVL	AX, 4(SP)
    72  	CALL	runtime·cgocall(SB)
    73  	RET
    74  
    75  TEXT ppapi·{{func.name}}(SB),NOSPLIT,${{fsize}}
    76  	MOVL	args+0(FP), BP
    77  	{% for aoff in range(0, fsize, 4) -%}
    78  	MOVL	{{aoff}}(BP), AX
    79  	MOVL	AX, {{aoff}}(SP)
    80  	{% endfor -%}
    81  	MOVL	ppapi·ppb_interfaces+({{func.interface}}*8+4)(SB), AX
    82  	MOVL	({{func.index}}*4)(AX), AX
    83  	CALL	AX
    84  	{% if func.structReturn -%}
    85  	SUBL	$4, SP	// Adjust SP due to struct return.
    86  	{% endif -%}
    87  	{{ doreturn(func.result, fsize) }}
    88  	RET
    89  
    90  {% endfor %}
    91  
    92  // ppapi·ppp_initialize_module_handler is called once at initialization
    93  // initialization time.  Called from the C stack.
    94  TEXT ppapi·ppp_initialize_module_handler(SB),NOSPLIT,$12
    95  	MOVL	SI, 4(SP)
    96  	MOVL	DI, 8(SP)
    97  	MOVL	module_id+0(FP), AX
    98  	MOVL	AX, ppapi·module_id(SB)
    99  	MOVL	get_browser_interface+4(FP), DI
   100  	LEAL	ppapi·ppb_interfaces(SB), SI
   101  initialize_module_loop:
   102  	MOVL	0(SI), AX  // name
   103  	TESTL	AX, AX
   104  	JZ	initialize_module_done
   105  	MOVL	AX, 0(SP)
   106  	CALL	DI
   107  	MOVL	AX, 4(SI)  // ppb
   108  	ADDL	$8, SI
   109  	JMP	initialize_module_loop
   110  initialize_module_done:
   111  	MOVL	4(SP), SI
   112  	MOVL	8(SP), DI
   113  	XORL	AX, AX
   114  	RET
   115  
   116  // ppapi·ppp_shutdown_module_handler my or may not be called when the
   117  // module is closed.  Ignore the callback.  Called from the C stack.
   118  TEXT ppapi·ppp_shutdown_module_handler(SB),NOSPLIT,$0
   119  	RET
   120  
   121  // ppapi·ppp_get_interface_handler is called by the browser to get
   122  // callback functions.  Called from the C stack.
   123  TEXT ppapi·ppp_get_interface_handler(SB),NOSPLIT,$24
   124  	MOVL	BP, 8(SP)
   125  	MOVL	BX, 12(SP)
   126  	MOVL	SI, 16(SP)
   127  	MOVL	DI, 20(SP)
   128  	MOVL	interface_name+0(FP), AX
   129  	MOVL	AX, 0(SP)
   130  	CALL	ppapi·ppp_get_interface(SB)
   131  	MOVL	8(SP), BP
   132  	MOVL	12(SP), BX
   133  	MOVL	16(SP), SI
   134  	MOVL	20(SP), DI
   135  	RET
   136  
   137  // ppapi·start is called to start PPAPI.  Never returns.
   138  TEXT ppapi·start(SB),NOSPLIT,$4
   139  	LEAL	ppapi·pp_start_functions(SB), DI
   140  	MOVL	DI, 0(SP)
   141  	MOVL	runtime·nacl_irt_ppapihook_v0_1+IRT_PPAPI_START(SB), AX
   142  	CALL	AX
   143  	RET
   144  
   145  TEXT syscall·runtime_ppapi_InitPPAPI(SB),NOSPLIT,$8-0
   146  	NO_LOCAL_POINTERS
   147  	LEAL	ppapi·start(SB), AX
   148  	MOVL	AX, 0(SP)
   149  	MOVL	$0, 4(SP)
   150  	CALL	runtime·cgocall(SB)
   151  	// Not reached
   152  	INT	$3
   153  	RET
   154  
   155  // Tunnel some functions from runtime.
   156  TEXT ·gostring(SB),NOSPLIT,$0
   157  	JMP	runtime·gostring(SB)
   158  
   159  TEXT ·gostringn(SB),NOSPLIT,$0
   160  	JMP	runtime·gostringn(SB)
   161  
   162  TEXT ·free(SB),NOSPLIT,$0
   163  	JMP	runtime·cfree(SB)