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 PRIV (x ) ((emu_state_t *) x->priv)
1618
@@ -72,6 +74,18 @@ static void emu_update_vblk_interrupts(vm_t *vm)
7274}
7375#endif
7476
77+ #if SEMU_HAS (VIRTIOGPU )
78+ static void emu_update_vgpu_interrupts (vm_t * vm )
79+ {
80+ emu_state_t * data = (emu_state_t * ) vm -> priv ;
81+ if (data -> vgpu .InterruptStatus )
82+ data -> plic .active |= IRQ_VGPU_BIT ;
83+ else
84+ data -> plic .active &= ~IRQ_VGPU_BIT ;
85+ plic_update_interrupts (vm , & data -> plic );
86+ }
87+ #endif
88+
7589static void mem_load (vm_t * vm , uint32_t addr , uint8_t width , uint32_t * value )
7690{
7791 emu_state_t * data = PRIV (vm );
@@ -104,6 +118,12 @@ static void mem_load(vm_t *vm, uint32_t addr, uint8_t width, uint32_t *value)
104118 virtio_blk_read (vm , & data -> vblk , addr & 0xFFFFF , width , value );
105119 emu_update_vblk_interrupts (vm );
106120 return ;
121+ #endif
122+ #if SEMU_HAS (VIRTIOGPU )
123+ case 0x43 : /* virtio-gpu */
124+ virtio_gpu_read (vm , & data -> vgpu , addr & 0xFFFFF , width , value );
125+ emu_update_vgpu_interrupts (vm );
126+ return ;
107127#endif
108128 }
109129 }
@@ -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 }
@@ -423,6 +449,12 @@ static int semu_start(int argc, char **argv)
423449 emu .vblk .ram = emu .ram ;
424450 emu .disk = virtio_blk_init (& (emu .vblk ), disk_file );
425451#endif
452+ #if SEMU_HAS (VIRTIOGPU )
453+ emu .vgpu .ram = emu .ram ;
454+ virtio_gpu_init (& (emu .vgpu ));
455+ virtio_gpu_add_scanout (& (emu .vgpu ), 1024 , 768 );
456+ display_window_init ();
457+ #endif
426458
427459 /* Emulate */
428460 uint32_t peripheral_update_ctr = 0 ;
@@ -444,6 +476,11 @@ static int semu_start(int argc, char **argv)
444476 if (emu .vblk .InterruptStatus )
445477 emu_update_vblk_interrupts (& vm );
446478#endif
479+
480+ #if SEMU_HAS (VIRTIOGPU )
481+ if (emu .vgpu .InterruptStatus )
482+ emu_update_vgpu_interrupts (& vm );
483+ #endif
447484 }
448485
449486 if (vm .insn_count > emu .timer )
0 commit comments