Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ QEMU_BASEOPTS= \
-device qemu-xhci,bus=pcie.1,id=xhci \
-device usb-mouse,bus=xhci.0 \
-device usb-kbd,bus=xhci.0 \
-chardev null,id=usbterm \
-device usb-storage,bus=xhci.0,drive=stick \
-device ahci,id=ahci \
-device ide-hd,drive=drive0,bus=ahci.0 \
Expand Down
13 changes: 9 additions & 4 deletions servers/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,17 @@ MKRAMFS_BIN?=$(MKRAMFS_DIR)/$(MKRAMFS)

.PHONY: all clean

all: test_server/test_server.elf devman/devman.elf pcidrv/pcidrv.elf ahcidrv/ahcidrv.elf fat32drv/fat32drv.elf kterminal
all: test_server/test_server.elf devman/devman.elf pcidrv/pcidrv.elf ahcidrv/ahcidrv.elf xhcidrv/xhcidrv.elf fat32drv/fat32drv.elf kterminal/kterminal.elf

clean:
$(MAKE) -C test_server clean
$(MAKE) -C devman clean
$(MAKE) -C pcidrv clean
$(MAKE) -C ahcidrv clean
$(MAKE) -C xhcidrv clean
$(MAKE) -C fat32drv clean
$(MAKE) -C kterminal clean
$(MAKE) -C common/usb clean
$(RM) system.ramfs

$(MKRAMFS_BIN): $(MKRAMFS_DIR)
Expand All @@ -33,16 +35,19 @@ pcidrv/pcidrv.elf: server_common.mk pcidrv/Makefile Makefile pcidrv/main.c
ahcidrv/ahcidrv.elf: server_common.mk ahcidrv/Makefile Makefile ahcidrv/main.c
$(MAKE) -C ahcidrv ahcidrv.elf

xhcidrv/xhcidrv.elf: server_common.mk xhcidrv/Makefile Makefile xhcidrv/main.c
$(MAKE) -C xhcidrv xhcidrv.elf

fat32drv/fat32drv.elf: server_common.mk fat32drv/Makefile Makefile fat32drv/main.c
$(MAKE) -C fat32drv fat32drv.elf

kterminal/kterminal.elf: server_common.mk kterminal/Makefile Makefile
$(MAKE) -C kterminal kterminal.elf

ifeq ($(ARCH),x86_64)
system_ramfs: $(MKRAMFS_BIN) test_server/test_server.elf devman/devman.elf pcidrv/pcidrv.elf ahcidrv/ahcidrv.elf fat32drv/fat32drv.elf kterminal/kterminal.elf
$(MKRAMFS_BIN) system.ramfs test_server/test_server.elf devman/devman.elf pcidrv/pcidrv.elf ahcidrv/ahcidrv.elf fat32drv/fat32drv.elf kterminal/kterminal.elf ../system/sysconf.json
system_ramfs: $(MKRAMFS_BIN) test_server/test_server.elf devman/devman.elf pcidrv/pcidrv.elf ahcidrv/ahcidrv.elf fat32drv/fat32drv.elf kterminal/kterminal.elf xhcidrv/xhcidrv.elf ../system/sysconf.json
$(MKRAMFS_BIN) system.ramfs test_server/test_server.elf devman/devman.elf pcidrv/pcidrv.elf ahcidrv/ahcidrv.elf fat32drv/fat32drv.elf kterminal/kterminal.elf xhcidrv/xhcidrv.elf ../system/sysconf.json
else
system_ramfs: $(MKRAMFS_BIN) test_server/test_server.elf kterminal/kterminal.elf devman/devman.elf
system_ramfs: $(MKRAMFS_BIN) test_server/test_server.elf kterminal/kterminal.elf devman/devman.elf ../system/sysconf.json
$(MKRAMFS_BIN) system.ramfs test_server/test_server.elf kterminal/kterminal.elf devman/devman.elf ../system/sysconf.json
endif
27 changes: 26 additions & 1 deletion servers/common/device_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ typedef enum {
DEVICE_TYPE_PCI = 1,
DEVICE_TYPE_STORAGE = 2,
DEVICE_TYPE_NETWORK = 3,
DEVICE_TYPE_DISPLAY = 4
DEVICE_TYPE_DISPLAY = 4,
DEVICE_TYPE_USB = 5
} DeviceType;

// Hardware types for storage devices
Expand All @@ -36,6 +37,15 @@ typedef enum {
STORAGE_HW_USB = 4
} StorageHardwareType;

// Hardware types for USB devices
typedef enum {
USB_HW_UNKNOWN = 0,
USB_HW_XHCI = 1,
USB_HW_EHCI = 2,
USB_HW_UHCI = 3,
USB_HW_OHCI = 4
} UsbHardwareType;

// Query types
typedef enum { QUERY_BY_TYPE = 1, QUERY_BY_ID = 2, QUERY_ALL = 3, QUERY_CHILDREN = 4 } DeviceQueryType;

Expand Down Expand Up @@ -81,6 +91,21 @@ typedef struct {
uint64_t config_base; // PCI config space base address
} PciDeviceInfo;

// USB-specific device information
typedef struct {
DeviceInfo base;
uint16_t vendor_id;
uint16_t product_id;
uint8_t device_class;
uint8_t device_subclass;
uint8_t device_protocol;
uint8_t port_number;
uint8_t device_speed;
char manufacturer[64];
char product[64];
char serial_number[32];
} UsbDeviceInfo;

// Device registration message
typedef struct {
DeviceMessageType msg_type;
Expand Down
64 changes: 64 additions & 0 deletions servers/common/usb/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
ARCH?=x86_64
TARGET_TRIPLE?=$(ARCH)-elf-anos

ASM?=nasm
XLD?=$(TARGET_TRIPLE)-ld
XOBJCOPY?=$(TARGET_TRIPLE)-objcopy
XOBJDUMP?=$(TARGET_TRIPLE)-objdump
STRIP?=$(TARGET_TRIPLE)-strip
XCC?=$(TARGET_TRIPLE)-gcc
XAR?=$(TARGET_TRIPLE)-ar
ASFLAGS=-f elf64 -F dwarf -g
CFLAGS=-Wall -Werror -Wpedantic -std=c23 \
-fno-asynchronous-unwind-tables \
-g \
-O$(OPTIMIZE)

SERVERS_ROOT_DIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
ROOT_DIR=$(abspath $(SERVERS_ROOT_DIR)/..)
THIS_DIR=$(SERVERS_ROOT_DIR)/$(SERVER_NAME)

USB_COMMON_NAME=usbcore
LIBRARY=$(USB_COMMON_NAME)
LIBRARY_OBJS=usb_core.o

LIBRARY_NAME=$(BINARY).a
LIBRARY_UC=$(shell echo '$(BINARY)' | tr '[:lower:]' '[:upper:]')
ALL_TARGETS=$(LIBRARY_NAME)
CLEAN_ARTIFACTS=$(THIS_DIR)/*.dis $(THIS_DIR)/*.elf $(THIS_DIR)/*.o $(THIS_DIR)/$(LIBRARY_NAME)
SHORT_HASH?=`git rev-parse --short HEAD`

CDEFS+=-D$(LIBRARY_UC)_BUILD

ifeq ($(CONSERVATIVE_BUILD),true)
CFLAGS+=-DCONSERVATIVE_BUILD
ifeq ($(CONSERVATIVE_UBSAN),true)
CFLAGS+=-fsanitize=undefined
LIBRARY_OBJS+=../common/ubsan.o
endif
endif

# USB core library build
CDEFS=

.PHONY: all build clean test

all: build

build: $(ALL_TARGETS)

%.o: %.asm
$(ASM) \
-DVERSTR=$(SHORT_HASH) \
$(ASFLAGS) \
-o $@ $<

%.o: %.c
$(XCC) -DVERSTR=$(SHORT_HASH) $(CDEFS) $(CFLAGS) -c -o $@ $< \
-I$(THIS_DIR)/include

$(LIBRARY_NAME): $(LIBRARY_OBJS)
$(XAR) rcs lib$(USB_COMMON_NAME).a $(LIBRARY_OBJS)

clean:
rm -f *.o *.a
Loading
Loading