1 /*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17 #include "gtest/gtest.h"
18
19 #include <cstdint>
20 #include <initializer_list>
21 #include <tuple>
22
23 #include "berberis/assembler/machine_code.h"
24 #include "berberis/guest_state/guest_addr.h"
25 #include "berberis/guest_state/guest_state.h"
26 #include "berberis/lite_translator/lite_translate_region.h"
27 #include "berberis/runtime_primitives/memory_region_reservation.h"
28 #include "berberis/test_utils/scoped_exec_region.h"
29 #include "berberis/test_utils/testing_run_generated_code.h"
30
31 #include "riscv64_to_x86_64/lite_translator.h"
32
33 namespace berberis {
34
35 namespace {
36
37 template <uint8_t kInsnSize = 4>
RunOneInstruction(ThreadState * state,GuestAddr stop_pc)38 bool RunOneInstruction(ThreadState* state, GuestAddr stop_pc) {
39 MachineCode machine_code;
40 bool success = LiteTranslateRange(state->cpu.insn_addr,
41 state->cpu.insn_addr + kInsnSize,
42 &machine_code,
43 LiteTranslateParams{.allow_dispatch = false});
44
45 if (!success) {
46 return false;
47 }
48
49 ScopedExecRegion exec(&machine_code);
50
51 TestingRunGeneratedCode(state, exec.get(), stop_pc);
52 return true;
53 }
54
55 #define TESTSUITE Riscv64LiteTranslateInsnTest
56 #define TESTING_LITE_TRANSLATOR
57
58 #include "berberis/test_utils/insn_tests_riscv64-inl.h"
59
60 #undef TESTING_LITE_TRANSLATOR
61 #undef TESTSUITE
62
63 } // namespace
64
65 } // namespace berberis
66