Revert "flush data and code cache after patching syscall"
[common.git] / source / lv1_hvcall.c
blobab9e73ad4c9ad5eb1456b08e0a4eecce7d770883
2 /*
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; version 2 of the License.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 #include <stdint.h>
19 #define LV1_HVCALL(name, in, out, num) extern int64_t _lv1_##name(LV1_##in##_IN_##out##_OUT_ARG_DECL);
21 #include <unistd.h>
23 #include <lv1_hvcall.h>
24 #include <lv2_syscall.h>
27 * lv2 syscall 615 (3.41)
29 #define _LV2_SYSCALL_HVCALL_ADDR 0x8000000000295f24ull
31 #define _LV2_SYSCALL_HVCALL_PATCH(num) \
32 uint64_t old_code[4]; \
34 old_code[0] = lv2_peek(_LV2_SYSCALL_HVCALL_ADDR); \
35 old_code[1] = lv2_peek(_LV2_SYSCALL_HVCALL_ADDR + 8); \
36 old_code[2] = lv2_peek(_LV2_SYSCALL_HVCALL_ADDR + 16); \
37 old_code[3] = lv2_peek(_LV2_SYSCALL_HVCALL_ADDR + 24); \
39 lv2_poke(_LV2_SYSCALL_HVCALL_ADDR, 0x7c0802a6f8010010ull); \
40 lv2_poke(_LV2_SYSCALL_HVCALL_ADDR + 8, 0x3960000044000022ull | ((uint64_t) num << 32)); \
41 lv2_poke(_LV2_SYSCALL_HVCALL_ADDR + 16, 0xe80100107c0803a6ull); \
42 lv2_poke(_LV2_SYSCALL_HVCALL_ADDR + 24, 0x4e80002060000000ull); \
44 #define _LV2_SYSCALL_HVCALL_RESTORE \
45 lv2_poke(_LV2_SYSCALL_HVCALL_ADDR, old_code[0]); \
46 lv2_poke(_LV2_SYSCALL_HVCALL_ADDR + 8, old_code[1]); \
47 lv2_poke(_LV2_SYSCALL_HVCALL_ADDR + 16, old_code[2]); \
48 lv2_poke(_LV2_SYSCALL_HVCALL_ADDR + 24, old_code[3]);
50 #define LV1_1_IN_0_OUT(name, num) \
51 int64_t lv1_##name(LV1_1_IN_0_OUT_ARG_DECL) \
52 { \
53 int64_t ret; \
55 _LV2_SYSCALL_HVCALL_PATCH(num); \
57 ret = _lv1_##name(LV1_1_IN_0_OUT_ARGS); \
59 _LV2_SYSCALL_HVCALL_RESTORE; \
61 usleep(1000); \
63 return ret; \
66 #define LV1_3_IN_1_OUT(name, num) \
67 int64_t lv1_##name(LV1_3_IN_1_OUT_ARG_DECL) \
68 { \
69 int64_t ret; \
71 _LV2_SYSCALL_HVCALL_PATCH(num); \
73 ret = _lv1_##name(LV1_3_IN_1_OUT_ARGS); \
75 _LV2_SYSCALL_HVCALL_RESTORE; \
77 usleep(1000); \
79 return ret; \
82 #define LV1_6_IN_3_OUT(name, num) \
83 int64_t lv1_##name(LV1_6_IN_3_OUT_ARG_DECL) \
84 { \
85 int64_t ret; \
87 _LV2_SYSCALL_HVCALL_PATCH(num); \
89 ret = _lv1_##name(LV1_6_IN_3_OUT_ARGS); \
91 _LV2_SYSCALL_HVCALL_RESTORE; \
93 usleep(1000); \
95 return ret; \
98 #undef LV1_HVCALL
99 #define LV1_HVCALL(name, in, out, num) LV1_##in##_IN_##out##_OUT(name, num)
101 #include <lv1_hvcall.h>