diff --git a/src/kernel/service/eventSyscalls.c b/src/kernel/service/eventSyscalls.c index e4bfa39..c47f3ce 100644 --- a/src/kernel/service/eventSyscalls.c +++ b/src/kernel/service/eventSyscalls.c @@ -7,7 +7,7 @@ if (!name) { return; } - Event *event = malloc(sizeof(ServiceFunction)); + Event *event = malloc(sizeof(Event)); Service *service = call->service; event->subscriptions = NULL; event->name = name; diff --git a/src/kernel/service/eventSyscalls.c b/src/kernel/service/eventSyscalls.c index e4bfa39..c47f3ce 100644 --- a/src/kernel/service/eventSyscalls.c +++ b/src/kernel/service/eventSyscalls.c @@ -7,7 +7,7 @@ if (!name) { return; } - Event *event = malloc(sizeof(ServiceFunction)); + Event *event = malloc(sizeof(Event)); Service *service = call->service; event->subscriptions = NULL; event->name = name; diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index df2a093..f0452fb 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -28,6 +28,10 @@ lock = false; } +bool checkFocus() { + return stackContains(focusService); +} + void handleLog(uint32_t stringId, uint32_t unused, uint32_t caller, uint32_t callerId) { if (stackContains(focusService)) { @@ -119,6 +123,7 @@ ioManager = getServiceId(); logFunction = createFunction("", (void *)handleLog); keyCallback = createFunction("", (void *)handleKey); + createFunction("checkFocus", (void *)checkFocus); mainService = loadFromInitrd("vga"); mainOut = getFunction(mainService, "writeChar"); globalService = loadFromInitrd("parallel"); diff --git a/src/kernel/service/eventSyscalls.c b/src/kernel/service/eventSyscalls.c index e4bfa39..c47f3ce 100644 --- a/src/kernel/service/eventSyscalls.c +++ b/src/kernel/service/eventSyscalls.c @@ -7,7 +7,7 @@ if (!name) { return; } - Event *event = malloc(sizeof(ServiceFunction)); + Event *event = malloc(sizeof(Event)); Service *service = call->service; event->subscriptions = NULL; event->name = name; diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index df2a093..f0452fb 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -28,6 +28,10 @@ lock = false; } +bool checkFocus() { + return stackContains(focusService); +} + void handleLog(uint32_t stringId, uint32_t unused, uint32_t caller, uint32_t callerId) { if (stackContains(focusService)) { @@ -119,6 +123,7 @@ ioManager = getServiceId(); logFunction = createFunction("", (void *)handleLog); keyCallback = createFunction("", (void *)handleKey); + createFunction("checkFocus", (void *)checkFocus); mainService = loadFromInitrd("vga"); mainOut = getFunction(mainService, "writeChar"); globalService = loadFromInitrd("parallel"); diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 5f264fb..0f56bed 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -9,6 +9,8 @@ printf("finished loading all the essential modules\n"); loadFromInitrd("lspci"); loadFromInitrd("pit"); + loadFromInitrd("mouse"); + loadFromInitrd("usb"); uint32_t id = loadFromInitrdUninitialized("shell"); requestName("ioManager", "setForeground", id, 0); request(id, 0, 0, 0); diff --git a/src/kernel/service/eventSyscalls.c b/src/kernel/service/eventSyscalls.c index e4bfa39..c47f3ce 100644 --- a/src/kernel/service/eventSyscalls.c +++ b/src/kernel/service/eventSyscalls.c @@ -7,7 +7,7 @@ if (!name) { return; } - Event *event = malloc(sizeof(ServiceFunction)); + Event *event = malloc(sizeof(Event)); Service *service = call->service; event->subscriptions = NULL; event->name = name; diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index df2a093..f0452fb 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -28,6 +28,10 @@ lock = false; } +bool checkFocus() { + return stackContains(focusService); +} + void handleLog(uint32_t stringId, uint32_t unused, uint32_t caller, uint32_t callerId) { if (stackContains(focusService)) { @@ -119,6 +123,7 @@ ioManager = getServiceId(); logFunction = createFunction("", (void *)handleLog); keyCallback = createFunction("", (void *)handleKey); + createFunction("checkFocus", (void *)checkFocus); mainService = loadFromInitrd("vga"); mainOut = getFunction(mainService, "writeChar"); globalService = loadFromInitrd("parallel"); diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 5f264fb..0f56bed 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -9,6 +9,8 @@ printf("finished loading all the essential modules\n"); loadFromInitrd("lspci"); loadFromInitrd("pit"); + loadFromInitrd("mouse"); + loadFromInitrd("usb"); uint32_t id = loadFromInitrdUninitialized("shell"); requestName("ioManager", "setForeground", id, 0); request(id, 0, 0, 0); diff --git a/src/userland/mouse/Makefile b/src/userland/mouse/Makefile new file mode 100644 index 0000000..4dd1acb --- /dev/null +++ b/src/userland/mouse/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 = mouse + +../../../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/kernel/service/eventSyscalls.c b/src/kernel/service/eventSyscalls.c index e4bfa39..c47f3ce 100644 --- a/src/kernel/service/eventSyscalls.c +++ b/src/kernel/service/eventSyscalls.c @@ -7,7 +7,7 @@ if (!name) { return; } - Event *event = malloc(sizeof(ServiceFunction)); + Event *event = malloc(sizeof(Event)); Service *service = call->service; event->subscriptions = NULL; event->name = name; diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index df2a093..f0452fb 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -28,6 +28,10 @@ lock = false; } +bool checkFocus() { + return stackContains(focusService); +} + void handleLog(uint32_t stringId, uint32_t unused, uint32_t caller, uint32_t callerId) { if (stackContains(focusService)) { @@ -119,6 +123,7 @@ ioManager = getServiceId(); logFunction = createFunction("", (void *)handleLog); keyCallback = createFunction("", (void *)handleKey); + createFunction("checkFocus", (void *)checkFocus); mainService = loadFromInitrd("vga"); mainOut = getFunction(mainService, "writeChar"); globalService = loadFromInitrd("parallel"); diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 5f264fb..0f56bed 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -9,6 +9,8 @@ printf("finished loading all the essential modules\n"); loadFromInitrd("lspci"); loadFromInitrd("pit"); + loadFromInitrd("mouse"); + loadFromInitrd("usb"); uint32_t id = loadFromInitrdUninitialized("shell"); requestName("ioManager", "setForeground", id, 0); request(id, 0, 0, 0); diff --git a/src/userland/mouse/Makefile b/src/userland/mouse/Makefile new file mode 100644 index 0000000..4dd1acb --- /dev/null +++ b/src/userland/mouse/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 = mouse + +../../../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/mouse/main.c b/src/userland/mouse/main.c new file mode 100644 index 0000000..0776699 --- /dev/null +++ b/src/userland/mouse/main.c @@ -0,0 +1,46 @@ +#define ALLOC_MAIN +#include + +volatile int32_t x = 0, y = 0; +volatile bool initialized = false; +volatile uint32_t updateEvent, buttons; + +REQUEST(checkFocus, "ioManager", "checkFocus"); + +void moveAbsolute(int32_t newX, int32_t newY) { + x = newX; + y = newY; + fireEvent(updateEvent, 0); +} + +void moveRelative(int32_t dX, int32_t dY) { + x += dX; + y += dY; + fireEvent(updateEvent, 0); +} + +void updateButtons(uint8_t newButtons) { + buttons = newButtons; + fireEvent(updateEvent, 0); +} + +void initialize() { + initialized = true; + createFunction("moveAbsolute", (void *)moveAbsolute); + createFunction("moveRelative", (void *)moveRelative); + createFunction("updateButtons", (void *)updateButtons); + updateEvent = createEvent("update"); +} + +int32_t main() { + if (!initialized) { initialize(); } + if (!checkFocus(0, 0)) { + return; + } + uint32_t serviceId = getServiceId(); + printf("service: %i, event: %i\n", serviceId, updateEvent); + while (1) { + await(serviceId, updateEvent); + printf("mouse info: buttons: %i, x: %i, y: %i \r", buttons, x, y); + } +} diff --git a/src/kernel/service/eventSyscalls.c b/src/kernel/service/eventSyscalls.c index e4bfa39..c47f3ce 100644 --- a/src/kernel/service/eventSyscalls.c +++ b/src/kernel/service/eventSyscalls.c @@ -7,7 +7,7 @@ if (!name) { return; } - Event *event = malloc(sizeof(ServiceFunction)); + Event *event = malloc(sizeof(Event)); Service *service = call->service; event->subscriptions = NULL; event->name = name; diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index df2a093..f0452fb 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -28,6 +28,10 @@ lock = false; } +bool checkFocus() { + return stackContains(focusService); +} + void handleLog(uint32_t stringId, uint32_t unused, uint32_t caller, uint32_t callerId) { if (stackContains(focusService)) { @@ -119,6 +123,7 @@ ioManager = getServiceId(); logFunction = createFunction("", (void *)handleLog); keyCallback = createFunction("", (void *)handleKey); + createFunction("checkFocus", (void *)checkFocus); mainService = loadFromInitrd("vga"); mainOut = getFunction(mainService, "writeChar"); globalService = loadFromInitrd("parallel"); diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 5f264fb..0f56bed 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -9,6 +9,8 @@ printf("finished loading all the essential modules\n"); loadFromInitrd("lspci"); loadFromInitrd("pit"); + loadFromInitrd("mouse"); + loadFromInitrd("usb"); uint32_t id = loadFromInitrdUninitialized("shell"); requestName("ioManager", "setForeground", id, 0); request(id, 0, 0, 0); diff --git a/src/userland/mouse/Makefile b/src/userland/mouse/Makefile new file mode 100644 index 0000000..4dd1acb --- /dev/null +++ b/src/userland/mouse/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 = mouse + +../../../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/mouse/main.c b/src/userland/mouse/main.c new file mode 100644 index 0000000..0776699 --- /dev/null +++ b/src/userland/mouse/main.c @@ -0,0 +1,46 @@ +#define ALLOC_MAIN +#include + +volatile int32_t x = 0, y = 0; +volatile bool initialized = false; +volatile uint32_t updateEvent, buttons; + +REQUEST(checkFocus, "ioManager", "checkFocus"); + +void moveAbsolute(int32_t newX, int32_t newY) { + x = newX; + y = newY; + fireEvent(updateEvent, 0); +} + +void moveRelative(int32_t dX, int32_t dY) { + x += dX; + y += dY; + fireEvent(updateEvent, 0); +} + +void updateButtons(uint8_t newButtons) { + buttons = newButtons; + fireEvent(updateEvent, 0); +} + +void initialize() { + initialized = true; + createFunction("moveAbsolute", (void *)moveAbsolute); + createFunction("moveRelative", (void *)moveRelative); + createFunction("updateButtons", (void *)updateButtons); + updateEvent = createEvent("update"); +} + +int32_t main() { + if (!initialized) { initialize(); } + if (!checkFocus(0, 0)) { + return; + } + uint32_t serviceId = getServiceId(); + printf("service: %i, event: %i\n", serviceId, updateEvent); + while (1) { + await(serviceId, updateEvent); + printf("mouse info: buttons: %i, x: %i, y: %i \r", buttons, x, y); + } +} diff --git a/src/userland/usb/xhci/controller.c b/src/userland/usb/xhci/controller.c index 85ac9f5..14c9a0a 100644 --- a/src/userland/usb/xhci/controller.c +++ b/src/userland/usb/xhci/controller.c @@ -142,10 +142,10 @@ U32(&globalController->events .physical[globalController->events.dequeue]) | (1 << 3); - printf("event %i [%x %x %x %x]: %i\n", - globalController->events.dequeue, trb->dataLow, - trb->dataHigh, trb->status, trb->control, - trb->control >> 10 & 0x3F); + // printf("event %i [%x %x %x %x]: %i\n", + // globalController->events.dequeue, trb->dataLow, + // trb->dataHigh, trb->status, trb->control, + // trb->control >> 10 & 0x3F); fireEventCode(xhciEvent, U32(trb), trb->dataLow); } } diff --git a/src/kernel/service/eventSyscalls.c b/src/kernel/service/eventSyscalls.c index e4bfa39..c47f3ce 100644 --- a/src/kernel/service/eventSyscalls.c +++ b/src/kernel/service/eventSyscalls.c @@ -7,7 +7,7 @@ if (!name) { return; } - Event *event = malloc(sizeof(ServiceFunction)); + Event *event = malloc(sizeof(Event)); Service *service = call->service; event->subscriptions = NULL; event->name = name; diff --git a/src/userland/ioManager/main.c b/src/userland/ioManager/main.c index df2a093..f0452fb 100644 --- a/src/userland/ioManager/main.c +++ b/src/userland/ioManager/main.c @@ -28,6 +28,10 @@ lock = false; } +bool checkFocus() { + return stackContains(focusService); +} + void handleLog(uint32_t stringId, uint32_t unused, uint32_t caller, uint32_t callerId) { if (stackContains(focusService)) { @@ -119,6 +123,7 @@ ioManager = getServiceId(); logFunction = createFunction("", (void *)handleLog); keyCallback = createFunction("", (void *)handleKey); + createFunction("checkFocus", (void *)checkFocus); mainService = loadFromInitrd("vga"); mainOut = getFunction(mainService, "writeChar"); globalService = loadFromInitrd("parallel"); diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 5f264fb..0f56bed 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -9,6 +9,8 @@ printf("finished loading all the essential modules\n"); loadFromInitrd("lspci"); loadFromInitrd("pit"); + loadFromInitrd("mouse"); + loadFromInitrd("usb"); uint32_t id = loadFromInitrdUninitialized("shell"); requestName("ioManager", "setForeground", id, 0); request(id, 0, 0, 0); diff --git a/src/userland/mouse/Makefile b/src/userland/mouse/Makefile new file mode 100644 index 0000000..4dd1acb --- /dev/null +++ b/src/userland/mouse/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 = mouse + +../../../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/mouse/main.c b/src/userland/mouse/main.c new file mode 100644 index 0000000..0776699 --- /dev/null +++ b/src/userland/mouse/main.c @@ -0,0 +1,46 @@ +#define ALLOC_MAIN +#include + +volatile int32_t x = 0, y = 0; +volatile bool initialized = false; +volatile uint32_t updateEvent, buttons; + +REQUEST(checkFocus, "ioManager", "checkFocus"); + +void moveAbsolute(int32_t newX, int32_t newY) { + x = newX; + y = newY; + fireEvent(updateEvent, 0); +} + +void moveRelative(int32_t dX, int32_t dY) { + x += dX; + y += dY; + fireEvent(updateEvent, 0); +} + +void updateButtons(uint8_t newButtons) { + buttons = newButtons; + fireEvent(updateEvent, 0); +} + +void initialize() { + initialized = true; + createFunction("moveAbsolute", (void *)moveAbsolute); + createFunction("moveRelative", (void *)moveRelative); + createFunction("updateButtons", (void *)updateButtons); + updateEvent = createEvent("update"); +} + +int32_t main() { + if (!initialized) { initialize(); } + if (!checkFocus(0, 0)) { + return; + } + uint32_t serviceId = getServiceId(); + printf("service: %i, event: %i\n", serviceId, updateEvent); + while (1) { + await(serviceId, updateEvent); + printf("mouse info: buttons: %i, x: %i, y: %i \r", buttons, x, y); + } +} diff --git a/src/userland/usb/xhci/controller.c b/src/userland/usb/xhci/controller.c index 85ac9f5..14c9a0a 100644 --- a/src/userland/usb/xhci/controller.c +++ b/src/userland/usb/xhci/controller.c @@ -142,10 +142,10 @@ U32(&globalController->events .physical[globalController->events.dequeue]) | (1 << 3); - printf("event %i [%x %x %x %x]: %i\n", - globalController->events.dequeue, trb->dataLow, - trb->dataHigh, trb->status, trb->control, - trb->control >> 10 & 0x3F); + // printf("event %i [%x %x %x %x]: %i\n", + // globalController->events.dequeue, trb->dataLow, + // trb->dataHigh, trb->status, trb->control, + // trb->control >> 10 & 0x3F); fireEventCode(xhciEvent, U32(trb), trb->dataLow); } } diff --git a/src/userland/usb/xhci/xhci.c b/src/userland/usb/xhci/xhci.c index 8457f25..d3f7486 100644 --- a/src/userland/usb/xhci/xhci.c +++ b/src/userland/usb/xhci/xhci.c @@ -185,6 +185,9 @@ awaitCode(serviceId, xhciEvent, commandAddress); } +REQUEST(moveRelative, "mouse", "moveRelative"); +REQUEST(updateButtons, "mouse", "updateButtons"); + void setupHID(SlotXHCI *slot, uint32_t endpointIndex, void *buffer) { setProtocol(slot); setIdle(slot); @@ -198,17 +201,14 @@ normal.dataBuffer[0] = U32(getPhysicalAddress(buffer)); normal.transferSize = 4; - int32_t x = 0, y = 0; - while (1) { uint32_t commandAddress = U32(enqueueCommand( slot->endpointRings[endpointIndex], (void *)&normal)); slot->controller->doorbells[slot->slotIndex] = endpointIndex + 1; awaitCode(serviceId, xhciEvent, commandAddress); MouseReport *report = buffer; - x += report->x; - y += report->y; - printf("event: buttons: %i, x: %i, y: %i \r", report->buttons, x, y); + moveRelative((int32_t) report->x, (int32_t)report->y); + updateButtons(report->buttons, 0); // todo: sleep for at least endpoint->interval? // todo: start this loop in a fork? sleep(10);