Skip to content

Commit 195e910

Browse files
committed
added sse_hvc_main_handler
1 parent 59dd690 commit 195e910

File tree

2 files changed

+138
-1
lines changed

2 files changed

+138
-1
lines changed

include/sse/sse.h

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,23 @@
11
#ifndef __SSE_H__
22
#define __SSE_H__
3+
4+
#include <stddef.h>
5+
#include <stdint.h>
6+
7+
#define SSE_FOPEN_HVC_NR 0
8+
#define SSE_FREAD_HVC_NR 1
9+
#define SSE_FWRITE_HVC_NR 2
10+
#define SSE_FSEEK_HVC_NR 3
11+
#define SSE_REWIND_HVC_NR 4
12+
#define SSE_FCLOSE_HVC_NR 5
13+
14+
void sse_hvc_main_handler(uint16_t hvc_number);
15+
16+
int sse_hvc_fopen_handler(const char* filename, const char* mode);
17+
int sse_hvc_fread_handler(char* buf, size_t size, size_t nmemb, int fd);
18+
int sse_hvc_fwrite_handler(char* buf, size_t size, size_t nmemb, int fd);
19+
int sse_hvc_fseek_handler(int fd, uint64_t offset, int pos);
20+
int sse_hvc_rewind_handler(int fd);
21+
int sse_hvc_fclose_handler(int fd);
22+
323
#endif

sse/sse.c

Lines changed: 118 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,118 @@
1-
#include "sse/sse.h"
1+
#include "sse/sse.h"
2+
#include "core/vm.h"
3+
#include "mm/paging.h"
4+
5+
/*
6+
7+
+ So, basically when the guestOS calls the hypervisor, some args are placed in the general purpose registers. (x0-x7)
8+
9+
+ But when the context switches, these registers are put into VM structure's pt_regs.
10+
11+
+ So now, we need to access those args from pt_regs.
12+
13+
+ Also, the pointers passed from guest are in its IPA. Hence we need to find the page in physical memory as well.
14+
15+
+ Return value from the hypervisor is placed in 'x0' in pt_regs, so when context switch happens back to guest, it can view the return value as though nothing happened.
16+
17+
*/
18+
19+
extern struct vm* current;
20+
21+
void sse_hvc_main_handler(uint16_t hvc_number){
22+
23+
struct pt_regs* vm_regs = (struct pt_regs*) get_vm_pt_regs(current); // This is VM's state before context switch occured.
24+
25+
uint64_t x0 = vm_regs->regs[0];
26+
uint64_t x1 = vm_regs->regs[1];
27+
uint64_t x2 = vm_regs->regs[2];
28+
uint64_t x3 = vm_regs->regs[3];
29+
30+
31+
// temporary variables used inside switch statement.
32+
int return_val = -1;
33+
char* filename_virt;
34+
char* filename_phys;
35+
char* mode_virt;
36+
char* mode_phys;
37+
char* buf_virt;
38+
char* buf_phys;
39+
size_t size, nmemb;
40+
int fd;
41+
int pos;
42+
uint64_t offset;
43+
44+
switch(hvc_number){
45+
case SSE_FOPEN_HVC_NR:
46+
47+
filename_virt = (char*)x0;
48+
mode_virt = (char*)x1;
49+
50+
filename_phys = (char*)ipa_to_phys(current, (uint64_t)filename_virt);
51+
mode_phys = (char*)ipa_to_phys(current, (uint64_t)mode_virt);
52+
53+
return_val = sse_hvc_fopen_handler(filename_phys, mode_phys);
54+
break;
55+
case SSE_FREAD_HVC_NR:
56+
57+
buf_virt = (char*)x0;
58+
size = (size_t)x1;
59+
nmemb = (size_t)x2;
60+
fd = (int)x3;
61+
62+
buf_phys = (char*)ipa_to_phys(current, (uint64_t)buf_virt);
63+
64+
return_val = sse_hvc_fread_handler(buf_phys, size, nmemb, fd);
65+
break;
66+
case SSE_FWRITE_HVC_NR:
67+
68+
buf_virt = (char*)x0;
69+
size = (size_t)x1;
70+
nmemb = (size_t)x2;
71+
fd = (int)x3;
72+
73+
buf_phys = (char*)ipa_to_phys(current, (uint64_t)buf_virt);
74+
75+
return_val = sse_hvc_fwrite_handler(buf_phys, size, nmemb, fd);
76+
break;
77+
case SSE_FSEEK_HVC_NR:
78+
fd = (int)x0;
79+
offset = (uint64_t)x1;
80+
pos = (int)x2;
81+
return_val = sse_hvc_fseek_handler(fd, offset, pos);
82+
break;
83+
case SSE_REWIND_HVC_NR:
84+
85+
fd = (int)x0;
86+
return_val = sse_hvc_rewind_handler(fd);
87+
break;
88+
case SSE_FCLOSE_HVC_NR:
89+
fd = (int)x0;
90+
return_val = sse_hvc_fclose_handler(x0);
91+
break;
92+
}
93+
94+
// now we place 'return_val' into VM's pt_regs so it can see it.
95+
vm_regs->regs[0] = return_val;
96+
97+
}
98+
99+
int sse_hvc_fopen_handler(const char* filename, const char* mode){
100+
101+
printf("file: %s Mode: %s\n", filename, mode);
102+
103+
}
104+
int sse_hvc_fread_handler(char* buf, size_t size, size_t nmemb, int fd){
105+
106+
}
107+
int sse_hvc_fwrite_handler(char* buf, size_t size, size_t nmemb, int fd){
108+
109+
}
110+
int sse_hvc_fseek_handler(int fd, uint64_t offset, int pos){
111+
112+
}
113+
int sse_hvc_rewind_handler(int fd){
114+
115+
}
116+
int sse_hvc_fclose_handler(int fd){
117+
118+
}

0 commit comments

Comments
 (0)