Skip to content

Commit eb4d558

Browse files
committed
feat(inc/hypercall): add generic hypercall get/set argument methods
This commit introduces two methods for setting and retrieving hypercall arguments, allowing each hypercall implementation to flexibly manage its specific arguments as needed. Signed-off-by: João Peixoto <[email protected]>
1 parent cdf3494 commit eb4d558

File tree

4 files changed

+17
-13
lines changed

4 files changed

+17
-13
lines changed

src/core/hypercall.c

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,14 @@
44
*/
55

66
#include <hypercall.h>
7-
#include <cpu.h>
8-
#include <vm.h>
9-
#include <ipc.h>
107

118
long int hypercall(unsigned long id)
129
{
1310
long int ret = -HC_E_INVAL_ID;
1411

15-
unsigned long arg0 = vcpu_readreg(cpu()->vcpu, HYPCALL_IN_ARG_REG(0));
16-
unsigned long arg1 = vcpu_readreg(cpu()->vcpu, HYPCALL_IN_ARG_REG(1));
17-
unsigned long arg2 = vcpu_readreg(cpu()->vcpu, HYPCALL_IN_ARG_REG(2));
18-
1912
switch (id) {
2013
case HC_IPC:
21-
ret = ipc_hypercall(arg0, arg1, arg2);
14+
ret = ipc_hypercall();
2215
break;
2316
default:
2417
WARNING("Unknown hypercall id %d", id);

src/core/inc/hypercall.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,24 @@
88

99
#include <bao.h>
1010
#include <arch/hypercall.h>
11+
#include <vm.h>
1112

1213
enum { HC_INVAL = 0, HC_IPC = 1 };
1314

1415
enum { HC_E_SUCCESS = 0, HC_E_FAILURE = 1, HC_E_INVAL_ID = 2, HC_E_INVAL_ARGS = 3 };
1516

16-
typedef unsigned long (*hypercall_handler)(unsigned long arg0, unsigned long arg1,
17-
unsigned long arg2);
17+
typedef unsigned long (*hypercall_handler)(void);
1818

1919
long int hypercall(unsigned long id);
2020

21+
static inline unsigned long hypercall_get_arg(struct vcpu* vcpu, size_t arg_index)
22+
{
23+
return vcpu_readreg(vcpu, HYPCALL_IN_ARG_REG(arg_index));
24+
}
25+
26+
static inline void hypercall_set_ret(struct vcpu* vcpu, size_t arg_index, unsigned long arg_val)
27+
{
28+
vcpu_writereg(vcpu, HYPCALL_OUT_ARG_REG(arg_index), arg_val);
29+
}
30+
2131
#endif /* HYPERCALL_H */

src/core/inc/ipc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ struct ipc {
1919

2020
struct vm_config;
2121

22-
long int ipc_hypercall(unsigned long arg0, unsigned long arg1, unsigned long arg2);
22+
long int ipc_hypercall(void);
2323
void ipc_init(void);
2424

2525
#endif /* IPC_H */

src/core/ipc.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ static void ipc_handler(uint32_t event, uint64_t data)
5858
}
5959
CPU_MSG_HANDLER(ipc_handler, IPC_CPUMSG_ID)
6060

61-
long int ipc_hypercall(unsigned long ipc_id, unsigned long ipc_event, unsigned long arg2)
61+
long int ipc_hypercall(void)
6262
{
63-
UNUSED_ARG(arg2);
63+
unsigned long ipc_id = hypercall_get_arg(cpu()->vcpu, 0);
64+
unsigned long ipc_event = hypercall_get_arg(cpu()->vcpu, 1);
6465

6566
long int ret = -HC_E_SUCCESS;
6667

0 commit comments

Comments
 (0)