forked from Locietta/xanmod-kernel-WSL2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrvvm.patch
6536 lines (6514 loc) · 210 KB
/
rvvm.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
patch file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index db82e07..03a5e10 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,13 +1,25 @@
# CMake configuration file for those who don't like Make (like I do)
# Prev-maintainer: cerg2010cerg2010
-cmake_minimum_required(VERSION 3.9)
+cmake_minimum_required(VERSION 3.12)
set(RVVM_VERSION 0.7)
-project(RVVM VERSION ${RVVM_VERSION}
+
+project(
+ RVVM VERSION ${RVVM_VERSION}
DESCRIPTION "RISC-V Virtual Machine"
HOMEPAGE_URL "https://github.com/LekKit/RVVM"
- LANGUAGES C CXX)
+ LANGUAGES C CXX
+)
+
+if (NOT RVVM__ROOTFS)
+ message(STATUS "STATUS: RVVM__ROOTFS must be set")
+ message(FATAL_ERROR "FATAL: RVVM__ROOTFS must be set")
+ # the default root path ('/') for finding virtio dependencies
+ set(RVVM__ROOTFS "/")
+else()
+ message(STATUS "STATUS: RVVM__ROOTFS was set")
+endif()
option(RVVM_USE_RV64 "Use RV64 CPU" ON)
option(RVVM_USE_FPU "Use floating-point instructions" ON)
@@ -18,6 +30,7 @@ option(RVVM_USE_NET "Use networking" ON)
option(RVVM_USE_TAP_LINUX "Use Linux TAP (deprecated)" OFF)
option(RVVM_USE_FDT "Use Flattened Device Tree generation" ON)
option(RVVM_USE_PCI "Use ATA over PCI, PIO mode is used otherwise" ON)
+option(RVVM_USE_VIRTIO "Use Virtio" ON)
option(RVVM_USE_SPINLOCK_DEBUG "Use spinlock debugging" ON)
option(RVVM_USE_PRECISE_FS "Use precise FPU status tracking" OFF)
option(RVVM_USE_LIB "Build shared librvvm library" ON)
@@ -52,11 +65,12 @@ set(RVVM_SRC_DIR "${RVVM_SOURCE_DIR}/src")
# Get commit id
find_package(Git)
execute_process(COMMAND
- "${GIT_EXECUTABLE}" describe --match=NeVeRmAtCh_TaG --always --dirty
- WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
- RESULT_VARIABLE RESULT
- OUTPUT_VARIABLE RVVM_COMMIT
- ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE)
+ "${GIT_EXECUTABLE}" describe --match=NeVeRmAtCh_TaG --always --dirty
+ WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
+ RESULT_VARIABLE RESULT
+ OUTPUT_VARIABLE RVVM_COMMIT
+ ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE
+)
if (RESULT)
message(WARNING "Couldn't determine upstream git commit!")
set(RVVM_COMMIT "unknown")
@@ -114,28 +128,48 @@ if (CMAKE_C_COMPILER_ID MATCHES "GNU|Clang")
endif()
if (UNIX)
- find_package(Threads REQUIRED)
- target_link_libraries(rvvm_common INTERFACE Threads::Threads)
- # Link librt, libatomic if we have them
- find_library(RVVM_RT_LIB rt)
- if (RVVM_RT_LIB)
- target_link_libraries(rvvm_common INTERFACE rt)
- endif()
- find_library(RVVM_ATOMIC_LIB atomic)
- if (RVVM_ATOMIC_LIB)
- target_link_libraries(rvvm_common INTERFACE ${RVVM_ATOMIC_LIB})
+ if (ANDROID)
+ #
+ # android bionic c has built-in support for pthread HOWEVER it is not full posix
+ #
+ # - android pthread is a more limited version of posix pthread
+ # - see https://stackoverflow.com/a/64432754
+ #
+ #
+ # android ndk does not contain librt
+ #
+ # android ndk has libatomic
+ #
+ target_link_libraries(rvvm_common INTERFACE atomic)
+ else()
+ find_package(Threads REQUIRED)
+ target_link_libraries(rvvm_common INTERFACE Threads::Threads)
+ # Link librt, libatomic if we have them
+ find_library(RVVM_RT_LIB rt)
+ if (RVVM_RT_LIB)
+ target_link_libraries(rvvm_common INTERFACE rt)
+ endif()
+ find_library(RVVM_ATOMIC_LIB atomic)
+ if (RVVM_ATOMIC_LIB)
+ target_link_libraries(rvvm_common INTERFACE ${RVVM_ATOMIC_LIB})
+ endif()
endif()
endif()
# General sources
file(GLOB RVVM_SRC LIST_DIRECTORIES FALSE CONFIGURE_DEPENDS
- "${RVVM_SRC_DIR}/*.h"
"${RVVM_SRC_DIR}/*.c"
"${RVVM_SRC_DIR}/cpu/riscv_*.c"
)
+file(GLOB RVVM_SRC_H LIST_DIRECTORIES FALSE CONFIGURE_DEPENDS
+ "${RVVM_SRC_DIR}/*.h"
+ "${RVVM_SRC_DIR}/cpu/*.h"
+)
set(RVVM_MAIN_SRC "${RVVM_SRC_DIR}/main.c")
set(RVVM_NETWORKING_SRC "${RVVM_SRC_DIR}/networking.c")
+set(RVVM_NETWORKING_SRC_H "${RVVM_SRC_DIR}/networking.h")
list(REMOVE_ITEM RVVM_SRC ${RVVM_MAIN_SRC} ${RVVM_NETWORKING_SRC})
+list(REMOVE_ITEM RVVM_SRC_H ${RVVM_NETWORKING_SRC_H})
if (RVVM_USE_RV64)
file(GLOB RVVM_RV64_SRC LIST_DIRECTORIES FALSE CONFIGURE_DEPENDS
@@ -171,18 +205,29 @@ endif()
# RVJIT sources
if (RVVM_USE_JIT)
file(GLOB RVVM_RVJIT_SRC LIST_DIRECTORIES FALSE CONFIGURE_DEPENDS
- "${RVVM_SRC_DIR}/rvjit/*.h"
"${RVVM_SRC_DIR}/rvjit/*.c"
)
+ file(GLOB RVVM_RVJIT_SRC_H LIST_DIRECTORIES FALSE CONFIGURE_DEPENDS
+ "${RVVM_SRC_DIR}/rvjit/*.h"
+ )
list(APPEND RVVM_SRC ${RVVM_RVJIT_SRC})
+ list(APPEND RVVM_SRC_H ${RVVM_RVJIT_SRC_H})
target_compile_definitions(rvvm_common INTERFACE USE_JIT)
endif()
# Device sources
file(GLOB RVVM_DEVICES_SRC LIST_DIRECTORIES FALSE CONFIGURE_DEPENDS
- "${RVVM_SRC_DIR}/devices/*.h"
"${RVVM_SRC_DIR}/devices/*.c"
)
+file(GLOB RVVM_DEVICES_SRC_H LIST_DIRECTORIES FALSE CONFIGURE_DEPENDS
+ "${RVVM_SRC_DIR}/devices/*.h"
+)
+file(GLOB RVVM_DEVICES_VIRTIO_SRC LIST_DIRECTORIES FALSE CONFIGURE_DEPENDS
+ "${RVVM_SRC_DIR}/devices/virtio*.c"
+)
+file(GLOB RVVM_DEVICES_VIRTIO_SRC_H LIST_DIRECTORIES FALSE CONFIGURE_DEPENDS
+ "${RVVM_SRC_DIR}/devices/virtio*.h"
+)
set(RVVM_XCB_SRC "${RVVM_SRC_DIR}/devices/x11window_xcb.c")
set(RVVM_XLIB_SRC "${RVVM_SRC_DIR}/devices/x11window_xlib.c")
set(RVVM_WIN32_SRC "${RVVM_SRC_DIR}/devices/win32window.c")
@@ -190,13 +235,26 @@ set(RVVM_HAIKU_SRC "${RVVM_SRC_DIR}/devices/haiku_window.cpp")
set(RVVM_SDL_SRC "${RVVM_SRC_DIR}/devices/sdl_window.c")
set(RVVM_TAP_LINUX_SRC "${RVVM_SRC_DIR}/devices/tap_linux.c")
set(RVVM_TAP_USER_SRC "${RVVM_SRC_DIR}/devices/tap_user.c")
+set(RVVM_VIRTIO_WINDOW_SRC "${RVVM_SRC_DIR}/devices/virtio_window.c")
list(REMOVE_ITEM RVVM_DEVICES_SRC
${RVVM_XLIB_SRC}
${RVVM_WIN32_SRC}
${RVVM_HAIKU_SRC}
${RVVM_SDL_SRC}
${RVVM_TAP_LINUX_SRC}
- ${RVVM_TAP_USER_SRC})
+ ${RVVM_TAP_USER_SRC}
+ ${RVVM_VIRTIO_WINDOW_SRC}
+)
+
+if (NOT RVVM_USE_VIRTIO)
+ list(REMOVE_ITEM RVVM_DEVICES_SRC ${RVVM_DEVICES_VIRTIO_SRC})
+ list(REMOVE_ITEM RVVM_DEVICES_SRC_H ${RVVM_DEVICES_VIRTIO_SRC_H})
+else()
+ target_compile_definitions(rvvm_common INTERFACE USE_VIRTIO=1)
+ set( CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake/packages" )
+ find_package(VIRGLRENDERER REQUIRED)
+ target_link_libraries(rvvm_common INTERFACE virglrenderer)
+endif()
if (RVVM_USE_GUI AND (NOT BUILD_LIBRETRO))
target_compile_definitions(rvvm_common INTERFACE USE_GUI)
@@ -313,10 +371,37 @@ else()
set_target_properties(rvvm_libretro PROPERTIES SUFFIX "${LIBRETRO_SUFFIX}.bc")
elseif (LIBRETRO_STATIC)
set_target_properties(rvvm_libretro PROPERTIES SUFFIX "${LIBRETRO_SUFFIX}.a")
- endif ()
+ endif()
endif()
# Restore IPO setting
if (RVVM_LTO)
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ${RVVM_OLD_IPO})
endif()
+
+set(INSTALL_BIN_DIR "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Installation directory for executables")
+set(INSTALL_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Installation directory for libraries")
+set(INSTALL_INC_DIR "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Installation directory for headers")
+
+if (BUILD_LIBRETRO)
+ install(
+ TARGETS rvvm_static rvvm_libretro
+ RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
+ ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
+ LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
+ )
+elseif (RVVM_USE_LIB)
+ install(
+ TARGETS rvvm_static rvvm rvvm_cli
+ RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
+ ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
+ LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
+ )
+else()
+ install(
+ TARGETS rvvm_static rvvm_cli
+ RUNTIME DESTINATION "${INSTALL_BIN_DIR}"
+ ARCHIVE DESTINATION "${INSTALL_LIB_DIR}"
+ LIBRARY DESTINATION "${INSTALL_LIB_DIR}"
+ )
+endif()
diff --git a/Makefile b/Makefile
index 2366413..e514d84 100644
--- a/Makefile
+++ b/Makefile
@@ -289,7 +289,9 @@ override CFLAGS := -I$(SRCDIR) -DRVVM_VERSION=\"$(VERSION)\" $(CFLAGS)
# Conditionally compiled sources, do not build by default
SRC_cond := $(SRCDIR)/devices/x11window_xlib.c $(SRCDIR)/devices/win32window.c \
$(SRCDIR)/devices/sdl_window.c $(SRCDIR)/devices/haiku_window.cpp \
- $(SRCDIR)/devices/tap_linux.c $(SRCDIR)/devices/tap_user.c $(SRCDIR)/networking.c
+ $(SRCDIR)/devices/tap_linux.c $(SRCDIR)/devices/tap_user.c $(SRCDIR)/networking.c $(SRCDIR)/devices/virtio-blk.c $(SRCDIR)/devices/virtio-gpu.c $(SRCDIR)/devices/virtio-input.c $(SRCDIR)/devices/virtio-net.c $(SRCDIR)/devices/virtio_window.c
+
+# $(SRCDIR)/devices/virtio_window.c reference only
# Output directories / files
BUILDDIR ?= $(BUILD_TYPE).$(OS).$(ARCH)
@@ -318,6 +320,7 @@ USE_TAP_LINUX ?= 0
USE_FDT ?= 1
USE_PCI ?= 1
USE_VFIO ?= 1
+USE_VIRTIO ?= 1
USE_SPINLOCK_DEBUG ?= 1
USE_JNI ?= 1
USE_ISOLATION ?= 1
@@ -449,6 +452,16 @@ ifeq ($(USE_VFIO),1)
override CFLAGS += -DUSE_VFIO
endif
+ifeq ($(USE_VIRTIO),1)
+SRC += $(SRCDIR)/devices/virtio-blk.c
+SRC += $(SRCDIR)/devices/virtio-gpu.c
+SRC += $(SRCDIR)/devices/virtio-input.c
+ifeq ($(USE_NET),1)
+SRC += $(SRCDIR)/devices/virtio-net.c
+endif
+override CFLAGS += -DUSE_VIRTIO
+endif
+
ifeq ($(USE_SPINLOCK_DEBUG),1)
override CFLAGS += -DUSE_SPINLOCK_DEBUG
endif
diff --git a/cmake/packages/FindEPOXY.cmake b/cmake/packages/FindEPOXY.cmake
new file mode 100644
index 0000000..bd1be91
--- /dev/null
+++ b/cmake/packages/FindEPOXY.cmake
@@ -0,0 +1,73 @@
+# Try to find the EPOXY library
+#
+# If successful, the following variables will be defined:
+# EPOXY_INCLUDE_DIR
+# EPOXY_LIBRARIES
+# EPOXY_FOUND
+#
+# additionally exposes the following target:
+# epoxy
+
+find_package(PkgConfig QUIET)
+pkg_check_modules(PC_GLOB QUIET epoxy)
+
+set(CMAKE_FIND_DEBUG_MODE FALSE)
+
+find_path(EPOXY_INCLUDE_DIRS NAMES epoxy/gl.h epoxy/egl.h
+ PATHS ${RVVM__ROOTFS}include ${RVVM__ROOTFS}usr/include
+ NO_DEFAULT_PATH
+ NO_PACKAGE_ROOT_PATH
+ NO_CMAKE_PATH
+ NO_CMAKE_ENVIRONMENT_PATH
+ NO_SYSTEM_ENVIRONMENT_PATH
+ NO_CMAKE_SYSTEM_PATH
+ NO_CMAKE_FIND_ROOT_PATH
+)
+find_library(EPOXY_LIBRARIES NAMES libepoxy.so
+ PATHS ${RVVM__ROOTFS}lib ${RVVM__ROOTFS}usr/lib
+ NO_DEFAULT_PATH
+ NO_PACKAGE_ROOT_PATH
+ NO_CMAKE_PATH
+ NO_CMAKE_ENVIRONMENT_PATH
+ NO_SYSTEM_ENVIRONMENT_PATH
+ NO_CMAKE_SYSTEM_PATH
+ NO_CMAKE_FIND_ROOT_PATH
+)
+
+set(CMAKE_FIND_DEBUG_MODE FALSE)
+
+if(EPOXY_INCLUDE_DIRS AND (EXISTS "${EPOXY_INCLUDE_DIRS}/epoxy/gl.h" OR EXISTS "${EPOXY_INCLUDE_DIRS}/epoxy/egl.h"))
+ set(EPOXY_VERSION_STRING "1.0")
+else()
+ set(EPOXY_INCLUDE_DIRS "")
+ set(EPOXY_LIBRARIES "")
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(EPOXY
+ FOUND_VAR
+ EPOXY_FOUND
+ REQUIRED_VARS
+ EPOXY_INCLUDE_DIRS
+ EPOXY_LIBRARIES
+ VERSION_VAR
+ EPOXY_VERSION_STRING)
+mark_as_advanced(EPOXY_INCLUDE_DIRS EPOXY_LIBRARIES)
+
+message(STATUS "EPOXY: found : ${EPOXY_FOUND}")
+message(STATUS "EPOXY: include_dirs : ${EPOXY_INCLUDE_DIRS}")
+message(STATUS "EPOXY: lib : ${EPOXY_LIBRARIES}")
+message(STATUS "EPOXY: version : ${EPOXY_VERSION_STRING}")
+
+if (EPOXY_FOUND AND NOT TARGET epoxy)
+ add_library(epoxy UNKNOWN IMPORTED)
+ set_target_properties(epoxy PROPERTIES IMPORTED_LOCATION ${EPOXY_LIBRARIES})
+ target_include_directories(epoxy INTERFACE ${EPOXY_INCLUDE_DIRS})
+ if (EXISTS "${EPOXY_INCLUDE_DIRS}/epoxy/gl.h")
+ target_compile_definitions(epoxy INTERFACE HAVE_EPOXY_GL_H)
+ endif()
+ if (EXISTS "${EPOXY_INCLUDE_DIRS}/epoxy/egl.h")
+ target_compile_definitions(epoxy INTERFACE HAVE_EPOXY_EGL_H)
+ endif()
+ set(EPOXY_TARGET epoxy)
+endif()
diff --git a/cmake/packages/FindVIRGLRENDERER.cmake b/cmake/packages/FindVIRGLRENDERER.cmake
new file mode 100644
index 0000000..9ced2aa
--- /dev/null
+++ b/cmake/packages/FindVIRGLRENDERER.cmake
@@ -0,0 +1,80 @@
+# Try to find the VIRGLRENDERER library
+#
+# If successful, the following variables will be defined:
+# VIRGLRENDERER_INCLUDE_DIR
+# VIRGLRENDERER_LIBRARIES
+# VIRGLRENDERER_FOUND
+#
+# additionally exposes the following target:
+# virglrenderer
+
+find_package(EPOXY REQUIRED)
+
+find_package(PkgConfig QUIET)
+pkg_check_modules(PC_GLOB QUIET VIRGLRENDERER)
+
+set(CMAKE_FIND_DEBUG_MODE FALSE)
+
+find_path(VIRGLRENDERER_INCLUDE_DIRS NAMES virgl/virgl-version.h
+ PATHS ${RVVM__ROOTFS}include ${RVVM__ROOTFS}usr/include
+ NO_DEFAULT_PATH
+ NO_PACKAGE_ROOT_PATH
+ NO_CMAKE_PATH
+ NO_CMAKE_ENVIRONMENT_PATH
+ NO_SYSTEM_ENVIRONMENT_PATH
+ NO_CMAKE_SYSTEM_PATH
+ NO_CMAKE_FIND_ROOT_PATH
+)
+find_library(VIRGLRENDERER_LIBRARIES NAMES libvirglrenderer.so
+ PATHS ${RVVM__ROOTFS}lib ${RVVM__ROOTFS}usr/lib
+ NO_DEFAULT_PATH
+ NO_PACKAGE_ROOT_PATH
+ NO_CMAKE_PATH
+ NO_CMAKE_ENVIRONMENT_PATH
+ NO_SYSTEM_ENVIRONMENT_PATH
+ NO_CMAKE_SYSTEM_PATH
+ NO_CMAKE_FIND_ROOT_PATH
+)
+
+set(CMAKE_FIND_DEBUG_MODE FALSE)
+
+if(VIRGLRENDERER_INCLUDE_DIRS AND EXISTS "${VIRGLRENDERER_INCLUDE_DIRS}/virgl/virgl-version.h" AND EXISTS "${VIRGLRENDERER_INCLUDE_DIRS}/virgl/virglrenderer.h")
+ FILE(STRINGS "${VIRGLRENDERER_INCLUDE_DIRS}/virgl/virgl-version.h" VIRGLRENDERER_version_major_str REGEX "^#define[ \t]+VIRGL_MAJOR_VERSION[ \t]+\(.+\)")
+ FILE(STRINGS "${VIRGLRENDERER_INCLUDE_DIRS}/virgl/virgl-version.h" VIRGLRENDERER_version_minor_str REGEX "^#define[ \t]+VIRGL_MINOR_VERSION[ \t]+\(.+\)")
+ FILE(STRINGS "${VIRGLRENDERER_INCLUDE_DIRS}/virgl/virgl-version.h" VIRGLRENDERER_version_micro_str REGEX "^#define[ \t]+VIRGL_MICRO_VERSION[ \t]+\(.+\)")
+
+ STRING(REGEX REPLACE "^#define[ \t]+VIRGL_MAJOR_VERSION[ \t]+\\\(([^\)]+)\\\).*" "\\1" VIRGL_MAJOR_VERSION "${VIRGLRENDERER_version_major_str}")
+ STRING(REGEX REPLACE "^#define[ \t]+VIRGL_MINOR_VERSION[ \t]+\\\(([^\)]+)\\\).*" "\\1" VIRGL_MINOR_VERSION "${VIRGLRENDERER_version_minor_str}")
+ STRING(REGEX REPLACE "^#define[ \t]+VIRGL_MICRO_VERSION[ \t]+\\\(([^\)]+)\\\).*" "\\1" VIRGL_MICRO_VERSION "${VIRGLRENDERER_version_micro_str}")
+
+ STRING(CONCAT VIRGLRENDERER_VERSION_STRING ${VIRGL_MAJOR_VERSION} "." ${VIRGL_MINOR_VERSION} "." ${VIRGL_MICRO_VERSION})
+else()
+ set(VIRGLRENDERER_INCLUDE_DIRS "")
+ set(VIRGLRENDERER_LIBRARIES "")
+endif()
+
+include(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(VIRGLRENDERER
+ FOUND_VAR
+ VIRGLRENDERER_FOUND
+ REQUIRED_VARS
+ VIRGLRENDERER_INCLUDE_DIRS
+ VIRGLRENDERER_LIBRARIES
+ VERSION_VAR
+ VIRGLRENDERER_VERSION_STRING)
+mark_as_advanced(VIRGLRENDERER_INCLUDE_DIRS VIRGLRENDERER_LIBRARIES)
+
+message(STATUS "VIRGLRENDERER: found : ${VIRGLRENDERER_FOUND}")
+message(STATUS "VIRGLRENDERER: include_dirs : ${VIRGLRENDERER_INCLUDE_DIRS}")
+message(STATUS "VIRGLRENDERER: lib : ${VIRGLRENDERER_LIBRARIES}")
+message(STATUS "VIRGLRENDERER: version : ${VIRGLRENDERER_VERSION_STRING}")
+
+if (VIRGLRENDERER_FOUND AND NOT TARGET virglrenderer)
+ add_library(virglrenderer UNKNOWN IMPORTED)
+ set_target_properties(virglrenderer PROPERTIES IMPORTED_LOCATION ${VIRGLRENDERER_LIBRARIES})
+ target_include_directories(virglrenderer INTERFACE ${VIRGLRENDERER_INCLUDE_DIRS})
+ target_compile_definitions(virglrenderer INTERFACE HAVE_VIRGL_VERSION_H)
+ target_compile_definitions(virglrenderer INTERFACE HAVE_VIRGLRENDERER_H)
+ target_link_libraries(virglrenderer INTERFACE epoxy)
+ set(VIRGLRENDERER_TARGET virglrenderer)
+endif()
diff --git a/empty.c b/empty.c
new file mode 100644
index 0000000..e69de29
diff --git a/src/devices/rvvm_virtio_ids.h b/src/devices/rvvm_virtio_ids.h
new file mode 100644
index 0000000..46ba2a9
--- /dev/null
+++ b/src/devices/rvvm_virtio_ids.h
@@ -0,0 +1,111 @@
+#ifndef _LINUX_VIRTIO_IDS_H
+#define _LINUX_VIRTIO_IDS_H
+
+#include <inttypes.h>
+
+#ifndef __bitwise
+#define __bitwise
+
+typedef int8_t __s8;
+typedef uint8_t __u8;
+typedef int16_t __s16;
+typedef uint16_t __u16;
+typedef int32_t __s32;
+typedef uint32_t __u32;
+typedef int64_t __s64;
+typedef uint64_t __u64;
+
+typedef __u16 __bitwise __le16;
+typedef __u16 __bitwise __be16;
+typedef __u32 __bitwise __le32;
+typedef __u32 __bitwise __be32;
+typedef __u64 __bitwise __le64;
+typedef __u64 __bitwise __be64;
+
+typedef __u16 __bitwise __sum16;
+typedef __u32 __bitwise __wsum;
+
+#endif
+
+/*
+ * Virtio IDs
+ *
+ * This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE. */
+
+#define VIRTIO_ID_NET 1 /* virtio net */
+#define VIRTIO_ID_BLOCK 2 /* virtio block */
+#define VIRTIO_ID_CONSOLE 3 /* virtio console */
+#define VIRTIO_ID_RNG 4 /* virtio rng */
+#define VIRTIO_ID_BALLOON 5 /* virtio balloon */
+#define VIRTIO_ID_IOMEM 6 /* virtio ioMemory */
+#define VIRTIO_ID_RPMSG 7 /* virtio remote processor messaging */
+#define VIRTIO_ID_SCSI 8 /* virtio scsi */
+#define VIRTIO_ID_9P 9 /* 9p virtio console */
+#define VIRTIO_ID_MAC80211_WLAN 10 /* virtio WLAN MAC */
+#define VIRTIO_ID_RPROC_SERIAL 11 /* virtio remoteproc serial link */
+#define VIRTIO_ID_CAIF 12 /* Virtio caif */
+#define VIRTIO_ID_MEMORY_BALLOON 13 /* virtio memory balloon */
+#define VIRTIO_ID_GPU 16 /* virtio GPU */
+#define VIRTIO_ID_CLOCK 17 /* virtio clock/timer */
+#define VIRTIO_ID_INPUT 18 /* virtio input */
+#define VIRTIO_ID_VSOCK 19 /* virtio vsock transport */
+#define VIRTIO_ID_CRYPTO 20 /* virtio crypto */
+#define VIRTIO_ID_SIGNAL_DIST 21 /* virtio signal distribution device */
+#define VIRTIO_ID_PSTORE 22 /* virtio pstore device */
+#define VIRTIO_ID_IOMMU 23 /* virtio IOMMU */
+#define VIRTIO_ID_MEM 24 /* virtio mem */
+#define VIRTIO_ID_SOUND 25 /* virtio sound */
+#define VIRTIO_ID_FS 26 /* virtio filesystem */
+#define VIRTIO_ID_PMEM 27 /* virtio pmem */
+#define VIRTIO_ID_RPMB 28 /* virtio rpmb */
+#define VIRTIO_ID_MAC80211_HWSIM 29 /* virtio mac80211-hwsim */
+#define VIRTIO_ID_VIDEO_ENCODER 30 /* virtio video encoder */
+#define VIRTIO_ID_VIDEO_DECODER 31 /* virtio video decoder */
+#define VIRTIO_ID_SCMI 32 /* virtio SCMI */
+#define VIRTIO_ID_NITRO_SEC_MOD 33 /* virtio nitro secure module*/
+#define VIRTIO_ID_I2C_ADAPTER 34 /* virtio i2c adapter */
+#define VIRTIO_ID_WATCHDOG 35 /* virtio watchdog */
+#define VIRTIO_ID_CAN 36 /* virtio can */
+#define VIRTIO_ID_DMABUF 37 /* virtio dmabuf */
+#define VIRTIO_ID_PARAM_SERV 38 /* virtio parameter server */
+#define VIRTIO_ID_AUDIO_POLICY 39 /* virtio audio policy */
+#define VIRTIO_ID_BT 40 /* virtio bluetooth */
+#define VIRTIO_ID_GPIO 41 /* virtio gpio */
+
+/*
+ * Virtio Transitional IDs
+ */
+
+#define VIRTIO_TRANS_ID_NET 0x1000 /* transitional virtio net */
+#define VIRTIO_TRANS_ID_BLOCK 0x1001 /* transitional virtio block */
+#define VIRTIO_TRANS_ID_BALLOON 0x1002 /* transitional virtio balloon */
+#define VIRTIO_TRANS_ID_CONSOLE 0x1003 /* transitional virtio console */
+#define VIRTIO_TRANS_ID_SCSI 0x1004 /* transitional virtio SCSI */
+#define VIRTIO_TRANS_ID_RNG 0x1005 /* transitional virtio rng */
+#define VIRTIO_TRANS_ID_9P 0x1009 /* transitional virtio 9p console */
+
+#endif /* _LINUX_VIRTIO_IDS_H */
diff --git a/src/devices/rvvm_virtio_pci.h b/src/devices/rvvm_virtio_pci.h
new file mode 100644
index 0000000..42ec84f
--- /dev/null
+++ b/src/devices/rvvm_virtio_pci.h
@@ -0,0 +1,287 @@
+/*
+ * Virtio PCI driver
+ *
+ * This module allows virtio devices to be used over a virtual PCI device.
+ * This can be used with QEMU based VMMs like KVM or Xen.
+ *
+ * Copyright IBM Corp. 2007
+ *
+ * Authors:
+ * Anthony Liguori <[email protected]>
+ *
+ * This header is BSD licensed so anyone can use the definitions to implement
+ * compatible drivers/servers.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of IBM nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL IBM OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+#ifndef _LINUX_VIRTIO_PCI_H
+#define _LINUX_VIRTIO_PCI_H
+
+#ifndef VIRTIO_PCI_NO_LEGACY
+
+/* A 32-bit r/o bitmask of the features supported by the host */
+#define VIRTIO_PCI_HOST_FEATURES 0
+
+/* A 32-bit r/w bitmask of features activated by the guest */
+#define VIRTIO_PCI_GUEST_FEATURES 4
+
+/* A 32-bit r/w PFN for the currently selected queue */
+#define VIRTIO_PCI_QUEUE_PFN 8
+
+/* A 16-bit r/o queue size for the currently selected queue */
+#define VIRTIO_PCI_QUEUE_NUM 12
+
+/* A 16-bit r/w queue selector */
+#define VIRTIO_PCI_QUEUE_SEL 14
+
+/* A 16-bit r/w queue notifier */
+#define VIRTIO_PCI_QUEUE_NOTIFY 16
+
+/* An 8-bit device status register. */
+#define VIRTIO_PCI_STATUS 18
+
+/* An 8-bit r/o interrupt status register. Reading the value will return the
+ * current contents of the ISR and will also clear it. This is effectively
+ * a read-and-acknowledge. */
+#define VIRTIO_PCI_ISR 19
+
+/* MSI-X registers: only enabled if MSI-X is enabled. */
+/* A 16-bit vector for configuration changes. */
+#define VIRTIO_MSI_CONFIG_VECTOR 20
+/* A 16-bit vector for selected queue notifications. */
+#define VIRTIO_MSI_QUEUE_VECTOR 22
+
+/* The remaining space is defined by each driver as the per-driver
+ * configuration space */
+#define VIRTIO_PCI_CONFIG_OFF(msix_enabled) ((msix_enabled) ? 24 : 20)
+/* Deprecated: please use VIRTIO_PCI_CONFIG_OFF instead */
+#define VIRTIO_PCI_CONFIG(dev) VIRTIO_PCI_CONFIG_OFF((dev)->msix_enabled)
+
+/* Virtio ABI version, this must match exactly */
+#define VIRTIO_PCI_ABI_VERSION 0
+
+/* How many bits to shift physical queue address written to QUEUE_PFN.
+ * 12 is historical, and due to x86 page size. */
+#define VIRTIO_PCI_QUEUE_ADDR_SHIFT 12
+
+/* The alignment to use between consumer and producer parts of vring.
+ * x86 pagesize again. */
+#define VIRTIO_PCI_VRING_ALIGN 4096
+
+#endif /* VIRTIO_PCI_NO_LEGACY */
+
+/* The bit of the ISR which indicates a device configuration change. */
+#define VIRTIO_PCI_ISR_CONFIG 0x2
+/* Vector value used to disable MSI for queue */
+#define VIRTIO_MSI_NO_VECTOR 0xffff
+
+#ifndef VIRTIO_PCI_NO_MODERN
+
+/* IDs for different capabilities. Must all exist. */
+
+/* Common configuration */
+#define VIRTIO_PCI_CAP_COMMON_CFG 1
+/* Notifications */
+#define VIRTIO_PCI_CAP_NOTIFY_CFG 2
+/* ISR access */
+#define VIRTIO_PCI_CAP_ISR_CFG 3
+/* Device specific configuration */
+#define VIRTIO_PCI_CAP_DEVICE_CFG 4
+/* PCI configuration access */
+#define VIRTIO_PCI_CAP_PCI_CFG 5
+/* Additional shared memory capability */
+#define VIRTIO_PCI_CAP_SHARED_MEMORY_CFG 8
+
+/* This is the PCI capability header: */
+struct virtio_pci_cap {
+ __u8 cap_vndr; /* Generic PCI field: PCI_CAP_ID_VNDR */
+ __u8 cap_next; /* Generic PCI field: next ptr. */
+ __u8 cap_len; /* Generic PCI field: capability length */
+ __u8 cfg_type; /* Identifies the structure. */
+ __u8 bar; /* Where to find it. */
+ __u8 id; /* Multiple capabilities of the same type */
+ __u8 padding[2]; /* Pad to full dword. */
+ __le32 offset; /* Offset within bar. */
+ __le32 length; /* Length of the structure, in bytes. */
+};
+
+struct virtio_pci_cap64 {
+ struct virtio_pci_cap cap;
+ __le32 offset_hi; /* Most sig 32 bits of offset */
+ __le32 length_hi; /* Most sig 32 bits of length */
+};
+
+struct virtio_pci_notify_cap {
+ struct virtio_pci_cap cap;
+ __le32 notify_off_multiplier; /* Multiplier for queue_notify_off. */
+};
+
+/* Fields in VIRTIO_PCI_CAP_COMMON_CFG: */
+struct virtio_pci_common_cfg {
+ /* About the whole device. */
+ __le32 device_feature_select; /* read-write */
+ __le32 device_feature; /* read-only */
+ __le32 guest_feature_select; /* read-write */
+ __le32 guest_feature; /* read-write */
+ __le16 msix_config; /* read-write */
+ __le16 num_queues; /* read-only */
+ __u8 device_status; /* read-write */
+ __u8 config_generation; /* read-only */
+
+ /* About a specific virtqueue. */
+ __le16 queue_select; /* read-write */
+ __le16 queue_size; /* read-write, power of 2. */
+ __le16 queue_msix_vector; /* read-write */
+ __le16 queue_enable; /* read-write */
+ __le16 queue_notify_off; /* read-only */
+ __le32 queue_desc_lo; /* read-write */
+ __le32 queue_desc_hi; /* read-write */
+ __le32 queue_avail_lo; /* read-write */
+ __le32 queue_avail_hi; /* read-write */
+ __le32 queue_used_lo; /* read-write */
+ __le32 queue_used_hi; /* read-write */
+};
+
+/*
+ * Warning: do not use sizeof on this: use offsetofend for
+ * specific fields you need.
+ */
+struct virtio_pci_modern_common_cfg {
+ struct virtio_pci_common_cfg cfg;
+
+ __le16 queue_notify_data; /* read-write */
+ __le16 queue_reset; /* read-write */
+
+ __le16 admin_queue_index; /* read-only */
+ __le16 admin_queue_num; /* read-only */
+};
+
+/* Fields in VIRTIO_PCI_CAP_PCI_CFG: */
+struct virtio_pci_cfg_cap {
+ struct virtio_pci_cap cap;
+ __u8 pci_cfg_data[4]; /* Data for BAR access. */
+};
+
+/* Macro versions of offsets for the Old Timers! */
+#define VIRTIO_PCI_CAP_VNDR 0
+#define VIRTIO_PCI_CAP_NEXT 1
+#define VIRTIO_PCI_CAP_LEN 2
+#define VIRTIO_PCI_CAP_CFG_TYPE 3
+#define VIRTIO_PCI_CAP_BAR 4
+#define VIRTIO_PCI_CAP_OFFSET 8
+#define VIRTIO_PCI_CAP_LENGTH 12
+
+#define VIRTIO_PCI_NOTIFY_CAP_MULT 16
+
+#define VIRTIO_PCI_COMMON_DFSELECT 0
+#define VIRTIO_PCI_COMMON_DF 4
+#define VIRTIO_PCI_COMMON_GFSELECT 8
+#define VIRTIO_PCI_COMMON_GF 12
+#define VIRTIO_PCI_COMMON_MSIX 16
+#define VIRTIO_PCI_COMMON_NUMQ 18
+#define VIRTIO_PCI_COMMON_STATUS 20
+#define VIRTIO_PCI_COMMON_CFGGENERATION 21
+#define VIRTIO_PCI_COMMON_Q_SELECT 22
+#define VIRTIO_PCI_COMMON_Q_SIZE 24
+#define VIRTIO_PCI_COMMON_Q_MSIX 26
+#define VIRTIO_PCI_COMMON_Q_ENABLE 28
+#define VIRTIO_PCI_COMMON_Q_NOFF 30
+#define VIRTIO_PCI_COMMON_Q_DESCLO 32
+#define VIRTIO_PCI_COMMON_Q_DESCHI 36
+#define VIRTIO_PCI_COMMON_Q_AVAILLO 40
+#define VIRTIO_PCI_COMMON_Q_AVAILHI 44
+#define VIRTIO_PCI_COMMON_Q_USEDLO 48
+#define VIRTIO_PCI_COMMON_Q_USEDHI 52
+#define VIRTIO_PCI_COMMON_Q_NDATA 56
+#define VIRTIO_PCI_COMMON_Q_RESET 58
+#define VIRTIO_PCI_COMMON_ADM_Q_IDX 60
+#define VIRTIO_PCI_COMMON_ADM_Q_NUM 62
+
+#endif /* VIRTIO_PCI_NO_MODERN */
+
+/* Admin command status. */
+#define VIRTIO_ADMIN_STATUS_OK 0
+
+/* Admin command opcode. */
+#define VIRTIO_ADMIN_CMD_LIST_QUERY 0x0
+#define VIRTIO_ADMIN_CMD_LIST_USE 0x1
+
+/* Admin command group type. */
+#define VIRTIO_ADMIN_GROUP_TYPE_SRIOV 0x1
+
+/* Transitional device admin command. */
+#define VIRTIO_ADMIN_CMD_LEGACY_COMMON_CFG_WRITE 0x2
+#define VIRTIO_ADMIN_CMD_LEGACY_COMMON_CFG_READ 0x3
+#define VIRTIO_ADMIN_CMD_LEGACY_DEV_CFG_WRITE 0x4
+#define VIRTIO_ADMIN_CMD_LEGACY_DEV_CFG_READ 0x5
+#define VIRTIO_ADMIN_CMD_LEGACY_NOTIFY_INFO 0x6
+
+struct virtio_admin_cmd_hdr {
+ __le16 opcode;
+ /*
+ * 1 - SR-IOV
+ * 2-65535 - reserved
+ */
+ __le16 group_type;
+ /* Unused, reserved for future extensions. */
+ __u8 reserved1[12];
+ __le64 group_member_id;
+};
+
+struct virtio_admin_cmd_status {
+ __le16 status;
+ __le16 status_qualifier;
+ /* Unused, reserved for future extensions. */
+ __u8 reserved2[4];
+};
+
+struct virtio_admin_cmd_legacy_wr_data {
+ __u8 offset; /* Starting offset of the register(s) to write. */
+ __u8 reserved[7];
+ __u8 registers[];
+};
+
+struct virtio_admin_cmd_legacy_rd_data {
+ __u8 offset; /* Starting offset of the register(s) to read. */
+};
+
+#define VIRTIO_ADMIN_CMD_NOTIFY_INFO_FLAGS_END 0
+#define VIRTIO_ADMIN_CMD_NOTIFY_INFO_FLAGS_OWNER_DEV 0x1
+#define VIRTIO_ADMIN_CMD_NOTIFY_INFO_FLAGS_OWNER_MEM 0x2
+
+#define VIRTIO_ADMIN_CMD_MAX_NOTIFY_INFO 4
+
+struct virtio_admin_cmd_notify_info_data {
+ __u8 flags; /* 0 = end of list, 1 = owner device, 2 = member device */
+ __u8 bar; /* BAR of the member or the owner device */
+ __u8 padding[6];
+ __le64 offset; /* Offset within bar. */
+};
+
+struct virtio_admin_cmd_notify_info_result {
+ struct virtio_admin_cmd_notify_info_data entries[VIRTIO_ADMIN_CMD_MAX_NOTIFY_INFO];
+};
+
+#endif
diff --git a/src/devices/shm.c b/src/devices/shm.c
new file mode 100644
index 0000000..9bf1be1
--- /dev/null
+++ b/src/devices/shm.c
@@ -0,0 +1,297 @@
+/*
+shm.c - Memory-Mapped Shared Memory
+Copyright (C) 2024 ZLangJIT <github.com/ZLangJIT>
+
+This program is free software: you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program. If not, see <https://www.gnu.org/licenses/>.
+*/
+
+#include "shm.h"
+
+#include "rvvm.h"
+
+#include "utils.h"
+
+#ifdef USE_FDT
+#include "fdtlib.h"
+#endif
+
+#if _WIN32
+
+#include <fileapi.h> // CreateFile
+#include <memoryapi.h> // MapViewOfFile, UnmapViewOfFile
+
+#else
+
+#include <fcntl.h> // open
+#include <unistd.h> // close
+#include <sys/stat.h> // stat
+#include <sys/mman.h> // mmap
+
+#endif
+
+PUBLIC rvvm_mmio_dev_t* shm_init_(rvvm_machine_t* machine, rvvm_mmio_dev_t* shm_region, const char * dev_name);
+
+static void shm_remove_file(rvvm_mmio_dev_t* device)
+{
+ shm_ctx_t* shm_ctx = (shm_ctx_t*)device->data;
+#if _WIN32
+ rvvm_info("unmapping path '%s' via UnmapViewOfFile", shm_ctx->source);
+ UnmapViewOfFile(shm_ctx->buffer);
+#else
+ rvvm_info("unmapping path '%s' via munmmap", shm_ctx->source);
+ munmap(shm_ctx->buffer, shm_ctx->size);
+#endif
+ free(shm_ctx);
+}
+
+static rvvm_mmio_type_t shm_data_dev_type = {
+ .name = "rvvm_shm_data_file",
+ .remove = shm_remove_file,
+};
+
+static rvvm_mmio_type_t shm_exe_dev_type = {
+ .name = "rvvm_shm_exe_file",
+ .remove = shm_remove_file,
+};
+
+PUBLIC rvvm_mmio_dev_t* shm_init_named(rvvm_machine_t* machine, const char * global_name, const char * dev_name)
+{
+ UNUSED(machine);
+ UNUSED(global_name);
+ UNUSED(dev_name);
+ return NULL;
+}
+
+PUBLIC rvvm_mmio_dev_t* shm_init_data(rvvm_machine_t* machine, const char * path, const char * dev_name)
+{
+ shm_ctx_t* shm_ctx = safe_new_obj(shm_ctx_t);
+ shm_ctx->source = path;
+#if _WIN32
+ rvvm_info("mapping path '%s' via MapViewOfFile", path);
+ HANDLE file_handle = CreateFileA(path,
+ GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
+ );
+ if (GetLastError() == ERROR_FILE_NOT_FOUND || file_handle == INVALID_HANDLE_VALUE) {
+ free(shm_file);
+ free(shm_ctx);
+ return NULL;
+ }
+ shm_ctx->size = GetFileSize(file_handle, NULL);
+ HANDLE file_mapping = CreateFileMapping(file_handle, NULL, PAGE_READ, 0, shm_ctx->size, NULL);
+ CloseHandle(file_handle);
+ shm_ctx->buffer = MapViewOfFile(file_mapping, FILE_MAP_READ, 0, 0, shm_ctx->size);
+ CloseHandle(file_mapping);
+#else
+ rvvm_info("mapping path '%s' via mmap", path);
+ int file_handle = open(path, O_RDONLY);
+ if (file_handle == -1) {
+ free(shm_ctx);
+ rvvm_error("Failed to map file %s (open() failed)", path);
+ return NULL;
+ }
+ struct stat file_info;
+ if (fstat(file_handle, &file_info) == -1) {
+ close(file_handle);
+ free(shm_ctx);
+ rvvm_error("Failed to map file %s (fstat() failed)", path);
+ return NULL;
+ }
+ shm_ctx->size = file_info.st_size;
+ shm_ctx->buffer = mmap(NULL, shm_ctx->size, PROT_READ, MAP_PRIVATE, file_handle, 0);
+ close(file_handle);
+ if (shm_ctx->buffer == MAP_FAILED) {
+ free(shm_ctx);
+ rvvm_error("Failed to map file %s (MAP_FAILED)", path);
+ return NULL;
+ }
+#endif
+ // Map the buffer into physical memory
+ rvvm_info("mapped path '%s' at address %p with size %zu", path, shm_ctx->buffer, shm_ctx->size);
+ rvvm_mmio_dev_t shm_region = {
+ .mapping = shm_ctx->buffer,
+ .addr = rvvm_mmio_zone_auto(machine, 0, shm_ctx->size),
+ .size = shm_ctx->size,
+ .data = shm_ctx,
+ .type = &shm_data_dev_type,
+ };
+ UNUSED(dev_name);
+ rvvm_mmio_dev_t* mmio = rvvm_attach_mmio(machine, &shm_region);
+ if (mmio == NULL) return mmio;
+ return mmio;
+}
+
+PUBLIC rvvm_mmio_dev_t* shm_init_exe(rvvm_machine_t* machine, const char * path, const char * dev_name)
+{
+ shm_ctx_t* shm_ctx = safe_new_obj(shm_ctx_t);
+ shm_ctx->source = path;
+#if _WIN32
+ rvvm_info("mapping path '%s' via MapViewOfFile", path);
+ HANDLE file_handle = CreateFileA(path,
+ GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL
+ );
+ if (GetLastError() == ERROR_FILE_NOT_FOUND || file_handle == INVALID_HANDLE_VALUE) {
+ free(shm_ctx);
+ return NULL;
+ }
+ shm_ctx->size = GetFileSize(file_handle, NULL);
+ HANDLE file_mapping = CreateFileMapping(file_handle, NULL, PAGE_EXECUTE_READ, 0, shm_ctx->size, NULL);
+ CloseHandle(file_handle);
+ shm_ctx->buffer = MapViewOfFile(file_mapping, FILE_MAP_READ | FILE_MAP_EXECUTE, 0, 0, shm_ctx->size);
+ CloseHandle(file_mapping);
+#else
+ rvvm_info("mapping path '%s' via mmap", path);
+ int file_handle = open(path, O_RDONLY);
+ if (file_handle == -1) {
+ free(shm_ctx);
+ rvvm_error("Failed to map file %s (open() failed)", path);