Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
V
virtual_game_machine
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
adrian.spycher
virtual_game_machine
Commits
084c5f96
Commit
084c5f96
authored
6 months ago
by
adrian.spycher
Browse files
Options
Downloads
Patches
Plain Diff
feat!: handle gfx init
parent
bffb454c
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
vmm/handler.c
+23
-5
23 additions, 5 deletions
vmm/handler.c
vmm/handler.h
+5
-4
5 additions, 4 deletions
vmm/handler.h
vmm/operation.c
+5
-2
5 additions, 2 deletions
vmm/operation.c
vmm/operation.h
+6
-0
6 additions, 0 deletions
vmm/operation.h
vmm/vmm_main.c
+53
-14
53 additions, 14 deletions
vmm/vmm_main.c
with
92 additions
and
25 deletions
vmm/handler.c
+
23
−
5
View file @
084c5f96
...
...
@@ -3,6 +3,7 @@
#include
<err.h>
#include
<stdio.h>
#include
<stdint.h>
#include
<stdarg.h>
#include
<unistd.h>
#include
<stdbool.h>
...
...
@@ -165,12 +166,26 @@ static void wrapper_op_gfx_init(uint8_t *shared_buf) {
// - VMM EXIT REASON HANDLER -
void
handle_halt
(
struct
kvm_run
*
run
,
uint8_t
*
shared_buf
,
uint8_t
*
mem
)
{
void
handle_halt
(
struct
kvm_run
*
run
,
...
)
{
// printf("KVM_EXIT_HLT\n");
va_list
args
;
va_start
(
args
,
run
);
va_arg
(
args
,
uint8_t
*
);
va_arg
(
args
,
uint8_t
*
);
// skip two first args
bool
*
done
=
va_arg
(
args
,
bool
*
);
printf
(
"guest halted
\n
"
);
*
done
=
true
;
va_end
(
args
);
}
void
handle_pmio
(
struct
kvm_run
*
run
,
uint8_t
*
shared_buf
,
uint8_t
*
mem
)
{
// waiting for : uint8_t *shared_buf, uint8_t *mem
void
handle_pmio
(
struct
kvm_run
*
run
,
...)
{
va_list
args
;
va_start
(
args
,
run
);
uint8_t
*
shared_buf
=
va_arg
(
args
,
uint8_t
*
);
uint8_t
*
mem
=
va_arg
(
args
,
uint8_t
*
);
if
(
run
->
io
.
direction
==
KVM_EXIT_IO_OUT
)
{
...
...
@@ -189,9 +204,12 @@ void handle_pmio(struct kvm_run *run, uint8_t *shared_buf, uint8_t *mem) {
state_compute
(
current_state
,
value
);
}
}
va_end
(
args
);
}
void
handle_mmio
(
struct
kvm_run
*
run
,
uint8_t
*
shared_buf
,
uint8_t
*
mem
)
{
// waiting for : uint8_t *shared_buf, uint8_t *mem
void
handle_mmio
(
struct
kvm_run
*
run
,
...)
{
if
(
run
->
mmio
.
is_write
)
{
...
...
@@ -219,7 +237,7 @@ void handle_hypercall(uint32_t code, uint8_t *shared_buf, uint8_t *mem) {
wrapper_op_timer
(
shared_buf
);
break
;
case
HYPERCALL_CODE_GFX_INIT
:
case
HYPERCALL_CODE_GFX_INIT
:
wrapper_op_gfx_init
(
shared_buf
);
break
;
...
...
This diff is collapsed.
Click to expand it.
vmm/handler.h
+
5
−
4
View file @
084c5f96
...
...
@@ -2,11 +2,12 @@
#define _STATES_H_
#include
<stdint.h>
#include
<stdbool.h>
#include
<linux/kvm.h>
// --- DEFINE ---
typedef
void
(
*
state_handler_t
)(
struct
kvm_run
*
run
,
uint8_t
*
shared_buf
,
uint8_t
*
mem
);
typedef
void
(
*
state_handler_t
)(
struct
kvm_run
*
run
,
...
);
extern
state_handler_t
const
STATE_HANDLERS
[];
...
...
@@ -19,7 +20,7 @@ extern state_handler_t const STATE_HANDLERS[];
* @param shared_buf Buffer shared between the host and guest.
* @param mem Pointer to the VM's memory.
*/
void
handle_halt
(
struct
kvm_run
*
run
,
uint8_t
*
shared_buf
,
uint8_t
*
mem
);
void
handle_halt
(
struct
kvm_run
*
run
,
...
);
/**
* @brief Handles the I/O port access (PMIO) exit from the virtual machine.
...
...
@@ -30,7 +31,7 @@ void handle_halt(struct kvm_run *run, uint8_t *shared_buf, uint8_t *mem);
* @param shared_buf Buffer shared between the host and guest.
* @param mem Pointer to the VM's memory.
*/
void
handle_pmio
(
struct
kvm_run
*
run
,
uint8_t
*
shared_buf
,
uint8_t
*
mem
);
void
handle_pmio
(
struct
kvm_run
*
run
,
...
);
/**
* @brief Handles the memory-mapped I/O (MMIO) exit from the virtual machine.
...
...
@@ -41,7 +42,7 @@ void handle_pmio(struct kvm_run *run, uint8_t *shared_buf, uint8_t *mem);
* @param shared_buf Buffer shared between the host and guest.
* @param mem Pointer to the VM's memory.
*/
void
handle_mmio
(
struct
kvm_run
*
run
,
uint8_t
*
shared_buf
,
uint8_t
*
mem
);
void
handle_mmio
(
struct
kvm_run
*
run
,
...
);
/**
* @brief Handles hypercalls issued by the virtual machine.
...
...
This diff is collapsed.
Click to expand it.
vmm/operation.c
+
5
−
2
View file @
084c5f96
...
...
@@ -3,6 +3,7 @@
#include
<stdio.h>
#include
<stdint.h>
#include
<unistd.h>
#include
<semaphore.h>
#include
"shared/hypercall_params.h"
...
...
@@ -57,7 +58,7 @@ void op_callback_timer_conclude(void *addr) {
hyper_timer_sleep_params_t
*
p_timer
=
(
addr
==
NULL
)
?
&
param_timer
:
(
hyper_timer_sleep_params_t
*
)
addr
;
printf
(
"hypercall : setting up a %dus timer...
\n
"
,
p_timer
->
us
);
sleep
(
p_timer
->
us
/
1e6
);
u
sleep
(
p_timer
->
us
);
}
void
op_callback_gfx_init_store_w
(
void
*
addr
)
{
...
...
@@ -75,5 +76,7 @@ void op_callback_gfx_init_conclude(void *addr) {
hyper_init_gfx_params_t
*
p_gfx_init
=
(
addr
==
NULL
)
?
&
param_gfx_init
:
(
hyper_init_gfx_params_t
*
)
addr
;
printf
(
"hypercall : initializing gfx %dx%d...
\n
"
,
p_gfx_init
->
width
,
p_gfx_init
->
height
);
// TODO:
width_gfx
=
p_gfx_init
->
width
;
height_gfx
=
p_gfx_init
->
height
;
sem_post
(
&
sem_gfx
);
}
This diff is collapsed.
Click to expand it.
vmm/operation.h
+
6
−
0
View file @
084c5f96
...
...
@@ -3,6 +3,8 @@
#include
<stdint.h>
#include
<unistd.h>
#include
<pthread.h>
#include
<semaphore.h>
// --- DEFINE ---
...
...
@@ -26,6 +28,10 @@ typedef struct {
void
(
*
callback
)(
void
*
addr
);
// custom function that would be executed at the end of the state
}
state_t
;
extern
sem_t
sem_gfx
;
extern
uint32_t
width_gfx
;
extern
uint32_t
height_gfx
;
extern
state_t
*
STATE_ALL_STARTERS
[];
extern
state_t
STATE_TIMER
[];
...
...
This diff is collapsed.
Click to expand it.
vmm/vmm_main.c
+
53
−
14
View file @
084c5f96
...
...
@@ -11,8 +11,12 @@
#include
<sys/mman.h>
#include
<sys/stat.h>
#include
<sys/types.h>
#include
<pthread.h>
#include
<semaphore.h>
#include
"gfx.h"
#include
"handler.h"
#include
"operation.h"
#include
"shared/hypercall_params.h"
// -- DEFINE --
...
...
@@ -20,15 +24,47 @@
#define KVM_API_VERSION 12
#define RAM_SIZE (512 * 1024)
#define SEM_THREAD 0
sem_t
sem_gfx
;
uint32_t
width_gfx
;
uint32_t
height_gfx
;
static
uint8_t
*
mem
,
*
shared_buf
;
static
struct
kvm_run
*
run
;
static
int
vcpufd
;
// -- THREAD --
static
void
*
thread_hypercall
()
{
bool
done
=
false
;
while
(
!
done
)
{
if
(
ioctl
(
vcpufd
,
KVM_RUN
,
NULL
)
==
-
1
)
err
(
1
,
"KVM_RUN"
);
state_handler_t
handler
=
STATE_HANDLERS
[
run
->
exit_reason
];
if
(
handler
)
{
handler
(
run
,
shared_buf
,
mem
,
&
done
);
}
else
{
errx
(
1
,
"exit_reason = 0x%x"
,
run
->
exit_reason
);
}
}
return
NULL
;
}
// -- MAIN --
int
main
(
int
argc
,
char
*
argv
[])
{
int
kvmfd
,
vmfd
,
vcpufd
;
int
kvmfd
,
vmfd
;
struct
kvm_sregs
sregs
;
struct
kvm_run
*
run
;
int32_t
mmap_size
;
uint8_t
*
mem
,
*
shared_buf
;
// -- 0. Handle Args --
if
(
argc
!=
2
)
err
(
1
,
"Number of args invalide"
);
...
...
@@ -139,20 +175,23 @@ int main(int argc, char* argv[])
// -- 7. Run the vCPU --
bool
done
=
false
;
while
(
!
done
)
{
sem_init
(
&
sem_gfx
,
SEM_THREAD
,
0
);
if
(
ioctl
(
vcpufd
,
KVM_RUN
,
NULL
)
==
-
1
)
err
(
1
,
"KVM_RUN"
);
pthread_t
t_hypercall
;
pthread_create
(
&
t_hypercall
,
NULL
,
thread_hypercall
,
NULL
);
s
tate_handler_t
handler
=
STATE_HANDLERS
[
run
->
exit_reason
]
;
s
em_wait
(
&
sem_gfx
)
;
if
(
handler
)
{
// -- 8. Manage gfx --
handler
(
run
,
shared_buf
,
mem
);
}
else
{
gfx_context_t
*
ctxt
=
gfx_create
(
"Basic Example"
,
width_gfx
,
height_gfx
);
if
(
!
ctxt
)
err
(
1
,
"KVM_SET_REGS"
);
errx
(
1
,
"exit_reason = 0x%x"
,
run
->
exit_reason
);
}
}
// -- X. Finalize --
pthread_join
(
t_hypercall
,
NULL
);
gfx_destroy
(
ctxt
);
sem_destroy
(
&
sem_gfx
);
return
0
;
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment