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 #ifndef BERBERIS_LITE_TRANSLATOR_LITE_TRANSLATE_REGION_H_
18 #define BERBERIS_LITE_TRANSLATOR_LITE_TRANSLATE_REGION_H_
19 
20 #include <tuple>
21 
22 #include "berberis/assembler/machine_code.h"
23 #include "berberis/base/config.h"
24 #include "berberis/guest_state/guest_addr.h"
25 #include "berberis/runtime_primitives/host_code.h"
26 #include "berberis/runtime_primitives/runtime_library.h"
27 
28 namespace berberis {
29 
30 struct LiteTranslateParams {
31   bool allow_dispatch = true;
32   bool enable_reg_mapping = true;
33   bool enable_self_profiling = false;
34   uint32_t* counter_location = nullptr;
35   uint32_t counter_threshold = config::kGearSwitchThreshold;
36   HostCode counter_threshold_callback =
37       AsHostCode(berberis::berberis_entry_HandleLightCounterThresholdReached);
38 };
39 
40 bool LiteTranslateRange(GuestAddr start_pc,
41                         GuestAddr end_pc,
42                         MachineCode* machine_code,
43                         LiteTranslateParams params);
44 std::tuple<bool, GuestAddr> TryLiteTranslateRegion(GuestAddr start_pc,
45                                                    MachineCode* machine_code,
46                                                    LiteTranslateParams params);
47 
48 }  // namespace berberis
49 
50 #endif  // BERBERIS_LITE_TRANSLATOR_LITE_TRANSLATE_REGION_H_
51