Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement VirtIO GPU and input devices #34

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
Draft
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
run: |
brew install make dtc expect e2fsprogs
- name: default build
run: make
run: make ENABLE_SDL=0
shell: bash
- name: automated test
run: .ci/autorun.sh
Expand Down
56 changes: 56 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ include mk/common.mk
CC ?= gcc
CFLAGS := -O2 -g -Wall -Wextra
CFLAGS += -include common.h
LDFLAGS :=

# clock frequency
CLOCK_FREQ ?= 65000000
Expand All @@ -13,6 +14,8 @@ OBJS_EXTRA :=
# command line option
OPTS :=

LDFLAGS += -lpthread

# virtio-blk
ENABLE_VIRTIOBLK ?= 1
$(call set-feature, VIRTIOBLK)
Expand All @@ -31,6 +34,13 @@ ifeq ($(call has, VIRTIOBLK), 1)
endif
endif

# virtio-rng
ENABLE_VIRTIORNG ?= 1
$(call set-feature, VIRTIORNG)
ifeq ($(call has, VIRTIORNG), 1)
OBJS_EXTRA += virtio-rng.o
endif

NETDEV ?= tap
# virtio-net
ENABLE_VIRTIONET ?= 1
Expand All @@ -43,6 +53,52 @@ ifeq ($(call has, VIRTIONET), 1)
OBJS_EXTRA += netdev.o
endif

# virtio-input
ENABLE_VIRTIOINPUT ?= 1
ifneq ($(UNAME_S),Linux)
ENABLE_VIRTIOINPUT := 0
endif
$(call set-feature, VIRTIOINPUT)
ifeq ($(call has, VIRTIOINPUT), 1)
OBJS_EXTRA += virtio-input.o
endif

# virtio-gpu
ENABLE_VIRTIOGPU ?= 1
ifneq ($(UNAME_S),Linux)
ENABLE_VIRTIOGPU := 0
endif

# VirGL
ENABLE_VIRGL ?= 1
ifneq (ENABLE_VIRTIOGPU,0)
CFLAGS += $(shell pkg-config virglrenderer --cflags)
LDFLAGS += $(shell pkg-config virglrenderer --libs)
endif

$(call set-feature, VIRGL)

# SDL2
ENABLE_SDL ?= 1
jserv marked this conversation as resolved.
Show resolved Hide resolved
ifeq (, $(shell which sdl2-config))
$(warning No sdl2-config in $$PATH. Check SDL2 installation in advance)
override ENABLE_SDL := 0
endif

ifeq ($(ENABLE_SDL),1)
CFLAGS += $(shell sdl2-config --cflags)
LDFLAGS += $(shell sdl2-config --libs)
else
override ENABLE_VIRTIOGPU := 0
endif

ifeq ($(ENABLE_VIRTIOGPU),1)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you check ENABLE_SDL here?

OBJS_EXTRA += window.o
OBJS_EXTRA += virtio-gpu.o
endif

$(call set-feature, VIRTIOGPU)

BIN = semu
all: $(BIN) minimal.dtb

Expand Down
13 changes: 13 additions & 0 deletions common.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

#include "feature.h"

#define BITS_PER_CHAR 8
#define BITS_PER_LONG (BITS_PER_CHAR * sizeof(long))

#define unlikely(x) __builtin_expect((x), 0)
#define likely(x) __builtin_expect((x), 1)

Expand All @@ -17,6 +20,16 @@ static inline int ilog2(int x)
return 31 - __builtin_clz(x | 1);
}

static inline void set_bit(unsigned long bit, unsigned long *word)
{
*word |= (1 << bit);
}

static inline void bitmap_set_bit(unsigned long *map, unsigned long bit)
{
set_bit(bit % BITS_PER_LONG, &map[bit / BITS_PER_LONG]);
}

/* Range check
* For any variable range checking:
* if (x >= minx && x <= maxx) ...
Expand Down
Loading
Loading