summaryrefslogtreecommitdiff
path: root/deps/v8/src/heap/base/asm/riscv/save_registers_asm.cc
blob: d46d8d7062a3e8c0a12409f14fb8cd76f362089f (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
// Copyright 2020 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <src/heap/base/stack.h>

// Save all callee-saved registers in the specified buffer.
// extern "C" void SaveCalleeSavedRegisters(intptr_t* buffer);

// See asm/x64/save_registers_asm.cc for why the function is not generated
// using clang.
//
// Calling convention source:
// https://riscv.org/wp-content/uploads/2015/01/riscv-calling.pdf Table 18.2

#if V8_HOST_ARCH_RISCV64
// 12 64-bit registers = 12 intprt_t
static_assert(heap::base::Stack::NumberOfCalleeSavedRegisters == 12,
              "Mismatch in the number of callee-saved registers");
static_assert(sizeof(intptr_t) == 8, "Mismatch in word size");

asm(".global SaveCalleeSavedRegisters             \n"
    ".type SaveCalleeSavedRegisters, %function    \n"
    ".hidden SaveCalleeSavedRegisters             \n"
    "SaveCalleeSavedRegisters:                    \n"
    // a0: [ intptr_t* buffer ]
    // Save the callee-saved registers: s0-s11.
    "  sd s11, 88(a0)                             \n"
    "  sd s10, 80(a0)                             \n"
    "  sd s9, 72(a0)                              \n"
    "  sd s8, 64(a0)                              \n"
    "  sd s7, 56(a0)                              \n"
    "  sd s6, 48(a0)                              \n"
    "  sd s5, 40(a0)                              \n"
    "  sd s4, 32(a0)                              \n"
    "  sd s3, 24(a0)                              \n"
    "  sd s2, 16(a0)                              \n"
    "  sd s1,  8(a0)                              \n"
    "  sd s0,  0(a0)                              \n"
    // Return.
    "  jr ra                                      \n");
#elif V8_HOST_ARCH_RISCV32
// 12 32-bit registers = 12 intprt_t
static_assert(heap::base::Stack::NumberOfCalleeSavedRegisters == 12,
              "Mismatch in the number of callee-saved registers");
static_assert(sizeof(intptr_t) == 4, "Mismatch in word size");

asm(".global SaveCalleeSavedRegisters             \n"
    ".type SaveCalleeSavedRegisters, %function    \n"
    ".hidden SaveCalleeSavedRegisters             \n"
    "SaveCalleeSavedRegisters:                    \n"
    // a0: [ intptr_t* buffer ]
    // Save the callee-saved registers: s0-s11.
    "  sw s11, 44(a0)                             \n"
    "  sw s10, 40(a0)                             \n"
    "  sw s9, 36(a0)                              \n"
    "  sw s8, 32(a0)                              \n"
    "  sw s7, 28(a0)                              \n"
    "  sw s6, 24(a0)                              \n"
    "  sw s5, 20(a0)                              \n"
    "  sw s4, 16(a0)                              \n"
    "  sw s3, 12(a0)                              \n"
    "  sw s2,  8(a0)                              \n"
    "  sw s1,  4(a0)                              \n"
    "  sw s0,  0(a0)                              \n"
    // Return.
    "  jr ra                                      \n");
#endif