diff --git a/Makefile b/Makefile index 766deab..d163a1c 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int +EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int -device qemu-xhci BUILD_FOLDER = build diff --git a/Makefile b/Makefile index 766deab..d163a1c 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int +EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int -device qemu-xhci BUILD_FOLDER = build diff --git a/src/userland/lspci/main.c b/src/userland/lspci/main.c index 29ec790..33ac1cd 100644 --- a/src/userland/lspci/main.c +++ b/src/userland/lspci/main.c @@ -31,8 +31,7 @@ uint32_t deviceCount = 0; ListElement *pciDevices = NULL; - -ListElement **getPciDevices() { return &pciDevices; } +bool initialized = false; uint8_t pciConfigReadByte(uint32_t bus, uint32_t device, uint32_t function, uint8_t offset) { @@ -132,18 +131,36 @@ } } -bool initialized = false; +int32_t getDeviceClass(uint32_t deviceId); + +void initializePci() { + createFunction("getDeviceClass", (void *)getDeviceClass); + if (!(getHeaderType(0, 0, 0) & 0x80)) { + checkBus(0); + } else { + for (uint8_t bus = 0; bus < 8; bus++) { + checkBus(bus); + } + } + deviceCount = listCount(pciDevices); + initialized = true; +} + +int32_t getDeviceClass(uint32_t deviceId) { + if (!initialized) { + initializePci(); + } + if (deviceId >= deviceCount) { + return 0; + } + PciDevice *device = listGet(pciDevices, deviceId); + return device->class << 16 | device->subclass << 8 | + device->programmingInterface; +} int32_t main() { if (!initialized) { - if (!(getHeaderType(0, 0, 0) & 0x80)) { - checkBus(0); - } else { - for (uint8_t bus = 0; bus < 8; bus++) { - checkBus(bus); - } - } - initialized = true; + initializePci(); return 0; } foreach (pciDevices, PciDevice *, device, { diff --git a/Makefile b/Makefile index 766deab..d163a1c 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int +EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int -device qemu-xhci BUILD_FOLDER = build diff --git a/src/userland/lspci/main.c b/src/userland/lspci/main.c index 29ec790..33ac1cd 100644 --- a/src/userland/lspci/main.c +++ b/src/userland/lspci/main.c @@ -31,8 +31,7 @@ uint32_t deviceCount = 0; ListElement *pciDevices = NULL; - -ListElement **getPciDevices() { return &pciDevices; } +bool initialized = false; uint8_t pciConfigReadByte(uint32_t bus, uint32_t device, uint32_t function, uint8_t offset) { @@ -132,18 +131,36 @@ } } -bool initialized = false; +int32_t getDeviceClass(uint32_t deviceId); + +void initializePci() { + createFunction("getDeviceClass", (void *)getDeviceClass); + if (!(getHeaderType(0, 0, 0) & 0x80)) { + checkBus(0); + } else { + for (uint8_t bus = 0; bus < 8; bus++) { + checkBus(bus); + } + } + deviceCount = listCount(pciDevices); + initialized = true; +} + +int32_t getDeviceClass(uint32_t deviceId) { + if (!initialized) { + initializePci(); + } + if (deviceId >= deviceCount) { + return 0; + } + PciDevice *device = listGet(pciDevices, deviceId); + return device->class << 16 | device->subclass << 8 | + device->programmingInterface; +} int32_t main() { if (!initialized) { - if (!(getHeaderType(0, 0, 0) & 0x80)) { - checkBus(0); - } else { - for (uint8_t bus = 0; bus < 8; bus++) { - checkBus(bus); - } - } - initialized = true; + initializePci(); return 0; } foreach (pciDevices, PciDevice *, device, { diff --git a/src/userland/usb/Makefile b/src/userland/usb/Makefile new file mode 100644 index 0000000..f3ac86a --- /dev/null +++ b/src/userland/usb/Makefile @@ -0,0 +1,31 @@ +CC = i686-elf-gcc +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I ../../include -I include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0 +LD = i686-elf-ld +LD_FLAGS = -z max-page-size=0x1000 -T ../link.ld +AS = nasm +ASFlAGS = -felf32 + +BUILD_FOLDER = build + +SOURCE_FILES := $(shell find . -name *.c -or -name *.asm -or -name *.s) +OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) + +NAME = usb + +../../../initrd/$(NAME): $(OBJS) ../../../build/hlib.o + @echo "linking user program $(NAME)" + @$(LD) $(LD_FLAGS) -o ../../../initrd/$(NAME) $(OBJS) + +$(BUILD_FOLDER)/%.asm.o: %.asm + @echo "asembling $<" + @mkdir -p $(dir $@) + @$(AS) $(ASFlAGS) $< -o $@ + +$(BUILD_FOLDER)/%.c.o: %.c + @echo "compiling $<" + @mkdir -p $(dir $@) + @$(CC) $(CCFLAGS) -r $< -o $@ + +clean: + @echo "clearing build folder" + @rm -r $(BUILD_FOLDER) diff --git a/Makefile b/Makefile index 766deab..d163a1c 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int +EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int -device qemu-xhci BUILD_FOLDER = build diff --git a/src/userland/lspci/main.c b/src/userland/lspci/main.c index 29ec790..33ac1cd 100644 --- a/src/userland/lspci/main.c +++ b/src/userland/lspci/main.c @@ -31,8 +31,7 @@ uint32_t deviceCount = 0; ListElement *pciDevices = NULL; - -ListElement **getPciDevices() { return &pciDevices; } +bool initialized = false; uint8_t pciConfigReadByte(uint32_t bus, uint32_t device, uint32_t function, uint8_t offset) { @@ -132,18 +131,36 @@ } } -bool initialized = false; +int32_t getDeviceClass(uint32_t deviceId); + +void initializePci() { + createFunction("getDeviceClass", (void *)getDeviceClass); + if (!(getHeaderType(0, 0, 0) & 0x80)) { + checkBus(0); + } else { + for (uint8_t bus = 0; bus < 8; bus++) { + checkBus(bus); + } + } + deviceCount = listCount(pciDevices); + initialized = true; +} + +int32_t getDeviceClass(uint32_t deviceId) { + if (!initialized) { + initializePci(); + } + if (deviceId >= deviceCount) { + return 0; + } + PciDevice *device = listGet(pciDevices, deviceId); + return device->class << 16 | device->subclass << 8 | + device->programmingInterface; +} int32_t main() { if (!initialized) { - if (!(getHeaderType(0, 0, 0) & 0x80)) { - checkBus(0); - } else { - for (uint8_t bus = 0; bus < 8; bus++) { - checkBus(bus); - } - } - initialized = true; + initializePci(); return 0; } foreach (pciDevices, PciDevice *, device, { diff --git a/src/userland/usb/Makefile b/src/userland/usb/Makefile new file mode 100644 index 0000000..f3ac86a --- /dev/null +++ b/src/userland/usb/Makefile @@ -0,0 +1,31 @@ +CC = i686-elf-gcc +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I ../../include -I include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0 +LD = i686-elf-ld +LD_FLAGS = -z max-page-size=0x1000 -T ../link.ld +AS = nasm +ASFlAGS = -felf32 + +BUILD_FOLDER = build + +SOURCE_FILES := $(shell find . -name *.c -or -name *.asm -or -name *.s) +OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) + +NAME = usb + +../../../initrd/$(NAME): $(OBJS) ../../../build/hlib.o + @echo "linking user program $(NAME)" + @$(LD) $(LD_FLAGS) -o ../../../initrd/$(NAME) $(OBJS) + +$(BUILD_FOLDER)/%.asm.o: %.asm + @echo "asembling $<" + @mkdir -p $(dir $@) + @$(AS) $(ASFlAGS) $< -o $@ + +$(BUILD_FOLDER)/%.c.o: %.c + @echo "compiling $<" + @mkdir -p $(dir $@) + @$(CC) $(CCFLAGS) -r $< -o $@ + +clean: + @echo "clearing build folder" + @rm -r $(BUILD_FOLDER) diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c new file mode 100644 index 0000000..a6457bd --- /dev/null +++ b/src/userland/usb/main.c @@ -0,0 +1,14 @@ +#define ALLOC_MAIN +#include + +#include "usb.h" + +int32_t main() { + uint32_t pciService = getService("lspci"); + uint32_t function = getFunction(pciService, "getDeviceClass"); + uint32_t i = 0, class = 0; + while ((class = request(pciService, function, i, 0))) { + printf("device %i has class 0x%x\n", i, class); + i++; + } +} diff --git a/Makefile b/Makefile index 766deab..d163a1c 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int +EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int -device qemu-xhci BUILD_FOLDER = build diff --git a/src/userland/lspci/main.c b/src/userland/lspci/main.c index 29ec790..33ac1cd 100644 --- a/src/userland/lspci/main.c +++ b/src/userland/lspci/main.c @@ -31,8 +31,7 @@ uint32_t deviceCount = 0; ListElement *pciDevices = NULL; - -ListElement **getPciDevices() { return &pciDevices; } +bool initialized = false; uint8_t pciConfigReadByte(uint32_t bus, uint32_t device, uint32_t function, uint8_t offset) { @@ -132,18 +131,36 @@ } } -bool initialized = false; +int32_t getDeviceClass(uint32_t deviceId); + +void initializePci() { + createFunction("getDeviceClass", (void *)getDeviceClass); + if (!(getHeaderType(0, 0, 0) & 0x80)) { + checkBus(0); + } else { + for (uint8_t bus = 0; bus < 8; bus++) { + checkBus(bus); + } + } + deviceCount = listCount(pciDevices); + initialized = true; +} + +int32_t getDeviceClass(uint32_t deviceId) { + if (!initialized) { + initializePci(); + } + if (deviceId >= deviceCount) { + return 0; + } + PciDevice *device = listGet(pciDevices, deviceId); + return device->class << 16 | device->subclass << 8 | + device->programmingInterface; +} int32_t main() { if (!initialized) { - if (!(getHeaderType(0, 0, 0) & 0x80)) { - checkBus(0); - } else { - for (uint8_t bus = 0; bus < 8; bus++) { - checkBus(bus); - } - } - initialized = true; + initializePci(); return 0; } foreach (pciDevices, PciDevice *, device, { diff --git a/src/userland/usb/Makefile b/src/userland/usb/Makefile new file mode 100644 index 0000000..f3ac86a --- /dev/null +++ b/src/userland/usb/Makefile @@ -0,0 +1,31 @@ +CC = i686-elf-gcc +CCFLAGS = -m32 -mtune=generic -ffreestanding -nostdlib -c -I ../../include -I include -Wno-discarded-qualifiers -fms-extensions -Wno-shift-count-overflow -O0 +LD = i686-elf-ld +LD_FLAGS = -z max-page-size=0x1000 -T ../link.ld +AS = nasm +ASFlAGS = -felf32 + +BUILD_FOLDER = build + +SOURCE_FILES := $(shell find . -name *.c -or -name *.asm -or -name *.s) +OBJS := $(SOURCE_FILES:%=$(BUILD_FOLDER)/%.o) + +NAME = usb + +../../../initrd/$(NAME): $(OBJS) ../../../build/hlib.o + @echo "linking user program $(NAME)" + @$(LD) $(LD_FLAGS) -o ../../../initrd/$(NAME) $(OBJS) + +$(BUILD_FOLDER)/%.asm.o: %.asm + @echo "asembling $<" + @mkdir -p $(dir $@) + @$(AS) $(ASFlAGS) $< -o $@ + +$(BUILD_FOLDER)/%.c.o: %.c + @echo "compiling $<" + @mkdir -p $(dir $@) + @$(CC) $(CCFLAGS) -r $< -o $@ + +clean: + @echo "clearing build folder" + @rm -r $(BUILD_FOLDER) diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c new file mode 100644 index 0000000..a6457bd --- /dev/null +++ b/src/userland/usb/main.c @@ -0,0 +1,14 @@ +#define ALLOC_MAIN +#include + +#include "usb.h" + +int32_t main() { + uint32_t pciService = getService("lspci"); + uint32_t function = getFunction(pciService, "getDeviceClass"); + uint32_t i = 0, class = 0; + while ((class = request(pciService, function, i, 0))) { + printf("device %i has class 0x%x\n", i, class); + i++; + } +} diff --git a/src/userland/usb/usb.h b/src/userland/usb/usb.h new file mode 100644 index 0000000..947aa51 --- /dev/null +++ b/src/userland/usb/usb.h @@ -0,0 +1,6 @@ +#ifndef USB_H +#define USB_H + +#include + +#endif