summaryrefslogtreecommitdiffstats
path: root/fluent-bit/lib/wasm-micro-runtime-WAMR-1.2.2/core/iwasm/common/arch/invokeNative_mips.s
blob: 645f4f2ec4232f77321cb3bd4789fa951fbca7f5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 * Copyright (C) 2019 Intel Corporation.  All rights reserved.
 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
 */

    .text
    .align 2
    .globl invokeNative
    .ent invokeNative
    .type invokeNative, @function

/**
 * On function entry parameters:
 * $4 = func_ptr
 * $5 = args
 * $6 = arg_num
 */

invokeNative:
    .frame $fp, 8, $0
    .mask 0x00000000, 0
    .fmask 0x00000000, 0

    /* Fixed part of frame */
    subu $sp, 8

    /* save registers */
    sw $31, 4($sp)
    sw $fp, 0($sp)

    /* set frame pointer to bottom of fixed frame */
    move $fp, $sp

    /* allocate enough stack space */
    sll $11, $6, 2  /* $11 == arg_num * 4 */
    subu $sp, $11

    /* make 8-byte aligned */
    and $sp, ~7

    move $9, $sp
    move $25, $4    /* $25 = func_ptr */

push_args:
    beq $6, 0, done /* arg_num == 0 ? */
    lw $8, 0($5)    /* $8 = *args */
    sw $8, 0($9)    /* store $8 to stack */
    addu $5, 4      /* args++ */
    addu $9, 4      /* sp++ */
    subu $6, 1      /* arg_num-- */
    j push_args

done:
    lw $4, 0($sp)   /* Load $4..$7 from stack */
    lw $5, 4($sp)
    lw $6, 8($sp)
    lw $7, 12($sp)
    ldc1 $f12, 0($sp) /* Load $f12, $f13, $f14, $f15 */
    ldc1 $f14, 8($sp)

    jalr $25       /* call function */

    nop

    /* restore saved registers */
    move $sp, $fp
    lw $31, 4($sp)
    lw $fp, 0($sp)

    /* pop frame */
    addu $sp, $sp, 8

    j $31
    .end invokeNative