1
1
#include <assert.h>
2
2
#include <fcntl.h>
3
3
#include <getopt.h>
4
+ #include <signal.h>
4
5
#include <stdio.h>
5
6
#include <stdlib.h>
6
7
#include <string.h>
11
12
#include "device.h"
12
13
#include "riscv.h"
13
14
#include "riscv_private.h"
15
+ #include "window.h"
14
16
15
17
/* Define fetch separately since it is simpler (fixed width, already checked
16
18
* alignment, only main RAM is executable).
@@ -70,6 +72,18 @@ static void emu_update_vblk_interrupts(vm_t *vm)
70
72
}
71
73
#endif
72
74
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
+
73
87
static void mem_load (vm_t * vm , uint32_t addr , uint8_t width , uint32_t * value )
74
88
{
75
89
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)
103
117
virtio_blk_read (vm , & data -> vblk , addr & 0xFFFFF , width , value );
104
118
emu_update_vblk_interrupts (vm );
105
119
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 ;
106
126
#endif
107
127
}
108
128
}
@@ -142,6 +162,12 @@ static void mem_store(vm_t *vm, uint32_t addr, uint8_t width, uint32_t value)
142
162
virtio_blk_write (vm , & data -> vblk , addr & 0xFFFFF , width , value );
143
163
emu_update_vblk_interrupts (vm );
144
164
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 ;
145
171
#endif
146
172
}
147
173
}
@@ -422,6 +448,12 @@ static int semu_start(int argc, char **argv)
422
448
emu .vblk .ram = emu .ram ;
423
449
emu .disk = virtio_blk_init (& (emu .vblk ), disk_file );
424
450
#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
425
457
426
458
/* Emulate */
427
459
uint32_t peripheral_update_ctr = 0 ;
@@ -443,6 +475,11 @@ static int semu_start(int argc, char **argv)
443
475
if (emu .vblk .InterruptStatus )
444
476
emu_update_vblk_interrupts (& vm );
445
477
#endif
478
+
479
+ #if SEMU_HAS (VIRTIOGPU )
480
+ if (emu .vgpu .InterruptStatus )
481
+ emu_update_vgpu_interrupts (& vm );
482
+ #endif
446
483
}
447
484
448
485
if (vm .insn_count_hi > emu .timer_hi ||
0 commit comments