11#include <assert.h>
22#include <fcntl.h>
33#include <getopt.h>
4+ #include <signal.h>
45#include <stdio.h>
56#include <stdlib.h>
67#include <string.h>
1112#include "device.h"
1213#include "riscv.h"
1314#include "riscv_private.h"
15+ #include "window.h"
1416
1517/* Define fetch separately since it is simpler (fixed width, already checked
1618 * alignment, only main RAM is executable).
@@ -70,6 +72,18 @@ static void emu_update_vblk_interrupts(vm_t *vm)
7072}
7173#endif
7274
75+ #if SEMU_HAS (VIRTIOGPU )
76+ static void emu_update_vgpu_interrupts (vm_t * vm )
77+ {
78+ emu_state_t * data = (emu_state_t * ) vm -> priv ;
79+ if (data -> vgpu .InterruptStatus )
80+ data -> plic .active |= IRQ_VGPU_BIT ;
81+ else
82+ data -> plic .active &= ~IRQ_VGPU_BIT ;
83+ plic_update_interrupts (vm , & data -> plic );
84+ }
85+ #endif
86+
7387static void mem_load (vm_t * vm , uint32_t addr , uint8_t width , uint32_t * value )
7488{
7589 emu_state_t * data = (emu_state_t * ) vm -> priv ;
@@ -103,6 +117,12 @@ static void mem_load(vm_t *vm, uint32_t addr, uint8_t width, uint32_t *value)
103117 virtio_blk_read (vm , & data -> vblk , addr & 0xFFFFF , width , value );
104118 emu_update_vblk_interrupts (vm );
105119 return ;
120+ #endif
121+ #if SEMU_HAS (VIRTIOGPU )
122+ case 0x43 : /* virtio-gpu */
123+ virtio_gpu_read (vm , & data -> vgpu , addr & 0xFFFFF , width , value );
124+ emu_update_vgpu_interrupts (vm );
125+ return ;
106126#endif
107127 }
108128 }
@@ -142,6 +162,12 @@ static void mem_store(vm_t *vm, uint32_t addr, uint8_t width, uint32_t value)
142162 virtio_blk_write (vm , & data -> vblk , addr & 0xFFFFF , width , value );
143163 emu_update_vblk_interrupts (vm );
144164 return ;
165+ #endif
166+ #if SEMU_HAS (VIRTIOGPU )
167+ case 0x43 : /* virtio-gpu */
168+ virtio_gpu_write (vm , & data -> vgpu , addr & 0xFFFFF , width , value );
169+ emu_update_vgpu_interrupts (vm );
170+ return ;
145171#endif
146172 }
147173 }
@@ -422,6 +448,12 @@ static int semu_start(int argc, char **argv)
422448 emu .vblk .ram = emu .ram ;
423449 emu .disk = virtio_blk_init (& (emu .vblk ), disk_file );
424450#endif
451+ #if SEMU_HAS (VIRTIOGPU )
452+ emu .vgpu .ram = emu .ram ;
453+ virtio_gpu_init (& (emu .vgpu ));
454+ virtio_gpu_add_scanout (& (emu .vgpu ), 1024 , 768 );
455+ display_window_init ();
456+ #endif
425457
426458 /* Emulate */
427459 uint32_t peripheral_update_ctr = 0 ;
@@ -443,6 +475,11 @@ static int semu_start(int argc, char **argv)
443475 if (emu .vblk .InterruptStatus )
444476 emu_update_vblk_interrupts (& vm );
445477#endif
478+
479+ #if SEMU_HAS (VIRTIOGPU )
480+ if (emu .vgpu .InterruptStatus )
481+ emu_update_vgpu_interrupts (& vm );
482+ #endif
446483 }
447484
448485 if (vm .insn_count_hi > emu .timer_hi ||
0 commit comments