increased usleep pause after HV call
[common.git] / source / lv1_hvcall.c
blob91cf3669e3fa8cb5ad8ab728bf858778a3fbb21f
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 USLEEP_PAUSE 10000
52 #define LV1_1_IN_0_OUT(name, num) \
53 int64_t lv1_##name(LV1_1_IN_0_OUT_ARG_DECL) \
54 { \
55 int64_t ret; \
57 _LV2_SYSCALL_HVCALL_PATCH(num); \
59 ret = _lv1_##name(LV1_1_IN_0_OUT_ARGS); \
61 _LV2_SYSCALL_HVCALL_RESTORE; \
63 usleep(USLEEP_PAUSE); \
65 return ret; \
68 #define LV1_3_IN_1_OUT(name, num) \
69 int64_t lv1_##name(LV1_3_IN_1_OUT_ARG_DECL) \
70 { \
71 int64_t ret; \
73 _LV2_SYSCALL_HVCALL_PATCH(num); \
75 ret = _lv1_##name(LV1_3_IN_1_OUT_ARGS); \
77 _LV2_SYSCALL_HVCALL_RESTORE; \
79 usleep(USLEEP_PAUSE); \
81 return ret; \
84 #define LV1_6_IN_3_OUT(name, num) \
85 int64_t lv1_##name(LV1_6_IN_3_OUT_ARG_DECL) \
86 { \
87 int64_t ret; \
89 _LV2_SYSCALL_HVCALL_PATCH(num); \
91 ret = _lv1_##name(LV1_6_IN_3_OUT_ARGS); \
93 _LV2_SYSCALL_HVCALL_RESTORE; \
95 usleep(USLEEP_PAUSE); \
97 return ret; \
100 #undef LV1_HVCALL
101 #define LV1_HVCALL(name, in, out, num) LV1_##in##_IN_##out##_OUT(name, num)
103 #include <lv1_hvcall.h>