about summary refs log tree commit diff stats
path: root/src/dynarec/rv64/rv64_next.S
blob: 5d4daa0abc546d6a6a95298a6e7e2bbf716be30c (plain) (blame)
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
#define ASM_MAPPING 1
#include "rv64_mapping.h"
#undef ASM_MAPPING

.text
.align 4

.extern LinkNext

.global rv64_next

    // NULL pointer before rv64_next, for getDB
    .8byte  0

// rv64(void)
rv64_next:

    // 16 bytes aligned
    addi    sp,  sp,  -(8 * 10)

    // push regs we care that might be destoryed
    sd      RDI, (0*8)(sp)
    sd      RSI, (1*8)(sp)
    sd      RDX, (2*8)(sp)
    sd      RCX, (3*8)(sp)
    sd      R8,  (4*8)(sp)
    sd      R9,  (5*8)(sp)
    sd      RAX, (6*8)(sp)
    sd      RIP, (8*8)(sp)

    mv      a0, Emu
    mv      a1, RIP
#ifdef HAVE_TRACE
    mv      a2, ra          // "from" is in ra, so put in a2
#endif
    addi    a3, sp, 8*8     // a3 is address to change rip

    // call the function
1:
    auipc   t4, %pcrel_hi(LinkNext)
    jalr    t4, %pcrel_lo(1b)

    // reserve return value
    mv      t3, a0

    // pop regs
    ld      RDI, (0*8)(sp)
    ld      RSI, (1*8)(sp)
    ld      RDX, (2*8)(sp)
    ld      RCX, (3*8)(sp)
    ld      R8,  (4*8)(sp)
    ld      R9,  (5*8)(sp)
    ld      RAX, (6*8)(sp)
    ld      RIP, (8*8)(sp)

    addi    sp,  sp,  (8 * 10)

    // return offset is jump address
    jr      t3