diff --git a/src/include/hlib.h b/src/include/hlib.h index 2a68800..8bb4ac8 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -67,5 +67,6 @@ extern void *listPopFirst(ListElement **list); extern uint32_t listCount(ListElement *list); extern void *listGet(ListElement *list, uint32_t position); +extern void *getPhysicalAddress(void *address); #endif diff --git a/src/include/hlib.h b/src/include/hlib.h index 2a68800..8bb4ac8 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -67,5 +67,6 @@ extern void *listPopFirst(ListElement **list); extern uint32_t listCount(ListElement *list); extern void *listGet(ListElement *list, uint32_t position); +extern void *getPhysicalAddress(void *address); #endif diff --git a/src/kernel/service/memorySyscalls.c b/src/kernel/service/memorySyscalls.c index ef93d5f..631b97b 100644 --- a/src/kernel/service/memorySyscalls.c +++ b/src/kernel/service/memorySyscalls.c @@ -32,3 +32,9 @@ } call->returnValue = U32(ADDRESS(virtualStart)) + (U32(physical) & 0xFFF); } + +void handleGetPhysicalSyscall(Syscall *call) { + Service *service = call->service; + call->returnValue = U32(getPhysicalAddress( + service->pagingInfo.pageDirectory, PTR(call->parameters[0]))); +} diff --git a/src/include/hlib.h b/src/include/hlib.h index 2a68800..8bb4ac8 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -67,5 +67,6 @@ extern void *listPopFirst(ListElement **list); extern uint32_t listCount(ListElement *list); extern void *listGet(ListElement *list, uint32_t position); +extern void *getPhysicalAddress(void *address); #endif diff --git a/src/kernel/service/memorySyscalls.c b/src/kernel/service/memorySyscalls.c index ef93d5f..631b97b 100644 --- a/src/kernel/service/memorySyscalls.c +++ b/src/kernel/service/memorySyscalls.c @@ -32,3 +32,9 @@ } call->returnValue = U32(ADDRESS(virtualStart)) + (U32(physical) & 0xFFF); } + +void handleGetPhysicalSyscall(Syscall *call) { + Service *service = call->service; + call->returnValue = U32(getPhysicalAddress( + service->pagingInfo.pageDirectory, PTR(call->parameters[0]))); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index d855560..a0acca3 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -70,7 +70,7 @@ extern uintptr_t handleSubscribeInterruptSyscall; extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall, handleReadStringSyscall, handleDiscardStringSyscall; -extern uintptr_t handleRequestMemorySyscall; +extern uintptr_t handleRequestMemorySyscall, handleGetPhysicalSyscall; extern uintptr_t handleLookupSymbolSyscall; extern uintptr_t handleStackContainsSyscall; extern uintptr_t handleAwaitSyscall; @@ -98,6 +98,7 @@ (void *)&handleLookupSymbolSyscall, (void *)&handleStackContainsSyscall, (void *)&handleAwaitSyscall, + (void *)&handleGetPhysicalSyscall, 0, 0, 0, diff --git a/src/include/hlib.h b/src/include/hlib.h index 2a68800..8bb4ac8 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -67,5 +67,6 @@ extern void *listPopFirst(ListElement **list); extern uint32_t listCount(ListElement *list); extern void *listGet(ListElement *list, uint32_t position); +extern void *getPhysicalAddress(void *address); #endif diff --git a/src/kernel/service/memorySyscalls.c b/src/kernel/service/memorySyscalls.c index ef93d5f..631b97b 100644 --- a/src/kernel/service/memorySyscalls.c +++ b/src/kernel/service/memorySyscalls.c @@ -32,3 +32,9 @@ } call->returnValue = U32(ADDRESS(virtualStart)) + (U32(physical) & 0xFFF); } + +void handleGetPhysicalSyscall(Syscall *call) { + Service *service = call->service; + call->returnValue = U32(getPhysicalAddress( + service->pagingInfo.pageDirectory, PTR(call->parameters[0]))); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index d855560..a0acca3 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -70,7 +70,7 @@ extern uintptr_t handleSubscribeInterruptSyscall; extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall, handleReadStringSyscall, handleDiscardStringSyscall; -extern uintptr_t handleRequestMemorySyscall; +extern uintptr_t handleRequestMemorySyscall, handleGetPhysicalSyscall; extern uintptr_t handleLookupSymbolSyscall; extern uintptr_t handleStackContainsSyscall; extern uintptr_t handleAwaitSyscall; @@ -98,6 +98,7 @@ (void *)&handleLookupSymbolSyscall, (void *)&handleStackContainsSyscall, (void *)&handleAwaitSyscall, + (void *)&handleGetPhysicalSyscall, 0, 0, 0, diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index c872d37..88343b8 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -27,6 +27,7 @@ SYS_LOOKUP_SYMBOL = 19, SYS_STACK_CONTAINS = 20, SYS_AWAIT = 21, + SYS_GET_PHYSICAL = 22, } SyscallIds; extern uint32_t getFunction(uint32_t module, char *name); diff --git a/src/include/hlib.h b/src/include/hlib.h index 2a68800..8bb4ac8 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -67,5 +67,6 @@ extern void *listPopFirst(ListElement **list); extern uint32_t listCount(ListElement *list); extern void *listGet(ListElement *list, uint32_t position); +extern void *getPhysicalAddress(void *address); #endif diff --git a/src/kernel/service/memorySyscalls.c b/src/kernel/service/memorySyscalls.c index ef93d5f..631b97b 100644 --- a/src/kernel/service/memorySyscalls.c +++ b/src/kernel/service/memorySyscalls.c @@ -32,3 +32,9 @@ } call->returnValue = U32(ADDRESS(virtualStart)) + (U32(physical) & 0xFFF); } + +void handleGetPhysicalSyscall(Syscall *call) { + Service *service = call->service; + call->returnValue = U32(getPhysicalAddress( + service->pagingInfo.pageDirectory, PTR(call->parameters[0]))); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index d855560..a0acca3 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -70,7 +70,7 @@ extern uintptr_t handleSubscribeInterruptSyscall; extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall, handleReadStringSyscall, handleDiscardStringSyscall; -extern uintptr_t handleRequestMemorySyscall; +extern uintptr_t handleRequestMemorySyscall, handleGetPhysicalSyscall; extern uintptr_t handleLookupSymbolSyscall; extern uintptr_t handleStackContainsSyscall; extern uintptr_t handleAwaitSyscall; @@ -98,6 +98,7 @@ (void *)&handleLookupSymbolSyscall, (void *)&handleStackContainsSyscall, (void *)&handleAwaitSyscall, + (void *)&handleGetPhysicalSyscall, 0, 0, 0, diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index c872d37..88343b8 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -27,6 +27,7 @@ SYS_LOOKUP_SYMBOL = 19, SYS_STACK_CONTAINS = 20, SYS_AWAIT = 21, + SYS_GET_PHYSICAL = 22, } SyscallIds; extern uint32_t getFunction(uint32_t module, char *name); diff --git a/src/userland/hlib/service/service.c b/src/userland/hlib/service/service.c index 0a7b20f..50a4f94 100644 --- a/src/userland/hlib/service/service.c +++ b/src/userland/hlib/service/service.c @@ -27,3 +27,7 @@ uint32_t lookupSymbol(uint32_t serviceId, uint32_t address) { return syscall(SYS_LOOKUP_SYMBOL, serviceId, address, 0, 0); } + +void *getPhysicalAddress(void *source) { + return PTR(syscall(SYS_GET_PHYSICAL, U32(source), 0, 0, 0)); +} diff --git a/src/include/hlib.h b/src/include/hlib.h index 2a68800..8bb4ac8 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -67,5 +67,6 @@ extern void *listPopFirst(ListElement **list); extern uint32_t listCount(ListElement *list); extern void *listGet(ListElement *list, uint32_t position); +extern void *getPhysicalAddress(void *address); #endif diff --git a/src/kernel/service/memorySyscalls.c b/src/kernel/service/memorySyscalls.c index ef93d5f..631b97b 100644 --- a/src/kernel/service/memorySyscalls.c +++ b/src/kernel/service/memorySyscalls.c @@ -32,3 +32,9 @@ } call->returnValue = U32(ADDRESS(virtualStart)) + (U32(physical) & 0xFFF); } + +void handleGetPhysicalSyscall(Syscall *call) { + Service *service = call->service; + call->returnValue = U32(getPhysicalAddress( + service->pagingInfo.pageDirectory, PTR(call->parameters[0]))); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index d855560..a0acca3 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -70,7 +70,7 @@ extern uintptr_t handleSubscribeInterruptSyscall; extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall, handleReadStringSyscall, handleDiscardStringSyscall; -extern uintptr_t handleRequestMemorySyscall; +extern uintptr_t handleRequestMemorySyscall, handleGetPhysicalSyscall; extern uintptr_t handleLookupSymbolSyscall; extern uintptr_t handleStackContainsSyscall; extern uintptr_t handleAwaitSyscall; @@ -98,6 +98,7 @@ (void *)&handleLookupSymbolSyscall, (void *)&handleStackContainsSyscall, (void *)&handleAwaitSyscall, + (void *)&handleGetPhysicalSyscall, 0, 0, 0, diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index c872d37..88343b8 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -27,6 +27,7 @@ SYS_LOOKUP_SYMBOL = 19, SYS_STACK_CONTAINS = 20, SYS_AWAIT = 21, + SYS_GET_PHYSICAL = 22, } SyscallIds; extern uint32_t getFunction(uint32_t module, char *name); diff --git a/src/userland/hlib/service/service.c b/src/userland/hlib/service/service.c index 0a7b20f..50a4f94 100644 --- a/src/userland/hlib/service/service.c +++ b/src/userland/hlib/service/service.c @@ -27,3 +27,7 @@ uint32_t lookupSymbol(uint32_t serviceId, uint32_t address) { return syscall(SYS_LOOKUP_SYMBOL, serviceId, address, 0, 0); } + +void *getPhysicalAddress(void *source) { + return PTR(syscall(SYS_GET_PHYSICAL, U32(source), 0, 0, 0)); +} diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 8fe12a1..7633554 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -97,6 +97,12 @@ if (!(operational->usbStatus & 1)) { printf("controller is not halted, aborting...\n"); } + operational->deviceNotificationControl = 2; + operational->configure |= 16; + DeviceContext *context = malloc(sizeof(DeviceContext)); + operational->deviceContextArray = + (uint64_t)U32(getPhysicalAddress(context)); + XHCIPortRegister *ports = OFFSET(operational, 0x400); for (uint32_t i = 0; i < 16; i++) { resetRootPort(&ports[i]); diff --git a/src/include/hlib.h b/src/include/hlib.h index 2a68800..8bb4ac8 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -67,5 +67,6 @@ extern void *listPopFirst(ListElement **list); extern uint32_t listCount(ListElement *list); extern void *listGet(ListElement *list, uint32_t position); +extern void *getPhysicalAddress(void *address); #endif diff --git a/src/kernel/service/memorySyscalls.c b/src/kernel/service/memorySyscalls.c index ef93d5f..631b97b 100644 --- a/src/kernel/service/memorySyscalls.c +++ b/src/kernel/service/memorySyscalls.c @@ -32,3 +32,9 @@ } call->returnValue = U32(ADDRESS(virtualStart)) + (U32(physical) & 0xFFF); } + +void handleGetPhysicalSyscall(Syscall *call) { + Service *service = call->service; + call->returnValue = U32(getPhysicalAddress( + service->pagingInfo.pageDirectory, PTR(call->parameters[0]))); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index d855560..a0acca3 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -70,7 +70,7 @@ extern uintptr_t handleSubscribeInterruptSyscall; extern uintptr_t handleInsertStringSyscall, handleReadStringLengthSyscall, handleReadStringSyscall, handleDiscardStringSyscall; -extern uintptr_t handleRequestMemorySyscall; +extern uintptr_t handleRequestMemorySyscall, handleGetPhysicalSyscall; extern uintptr_t handleLookupSymbolSyscall; extern uintptr_t handleStackContainsSyscall; extern uintptr_t handleAwaitSyscall; @@ -98,6 +98,7 @@ (void *)&handleLookupSymbolSyscall, (void *)&handleStackContainsSyscall, (void *)&handleAwaitSyscall, + (void *)&handleGetPhysicalSyscall, 0, 0, 0, diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index c872d37..88343b8 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -27,6 +27,7 @@ SYS_LOOKUP_SYMBOL = 19, SYS_STACK_CONTAINS = 20, SYS_AWAIT = 21, + SYS_GET_PHYSICAL = 22, } SyscallIds; extern uint32_t getFunction(uint32_t module, char *name); diff --git a/src/userland/hlib/service/service.c b/src/userland/hlib/service/service.c index 0a7b20f..50a4f94 100644 --- a/src/userland/hlib/service/service.c +++ b/src/userland/hlib/service/service.c @@ -27,3 +27,7 @@ uint32_t lookupSymbol(uint32_t serviceId, uint32_t address) { return syscall(SYS_LOOKUP_SYMBOL, serviceId, address, 0, 0); } + +void *getPhysicalAddress(void *source) { + return PTR(syscall(SYS_GET_PHYSICAL, U32(source), 0, 0, 0)); +} diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 8fe12a1..7633554 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -97,6 +97,12 @@ if (!(operational->usbStatus & 1)) { printf("controller is not halted, aborting...\n"); } + operational->deviceNotificationControl = 2; + operational->configure |= 16; + DeviceContext *context = malloc(sizeof(DeviceContext)); + operational->deviceContextArray = + (uint64_t)U32(getPhysicalAddress(context)); + XHCIPortRegister *ports = OFFSET(operational, 0x400); for (uint32_t i = 0; i < 16; i++) { resetRootPort(&ports[i]); diff --git a/src/userland/usb/usb.h b/src/userland/usb/usb.h index 82a8b3f..3dcea62 100644 --- a/src/userland/usb/usb.h +++ b/src/userland/usb/usb.h @@ -20,11 +20,69 @@ uint32_t usbCommand, usbStatus; uint64_t pageSize; uint32_t deviceNotificationControl, commandRingControl; - uint64_t deviceContextArrayOffset; + uint64_t deviceContextArray; uint32_t configure; } XHCIOperationalRegisters; typedef struct { + uint32_t routeString : 20; + uint32_t speed : 4; + uint32_t reserved : 1; + uint32_t multiTT : 1; + uint32_t isHub : 1; + uint32_t contextEntries : 5; + + uint32_t maxExitLatency : 16; + uint32_t rootHubPortNumber : 8; + uint32_t portCount : 8; // only if this is a hub + + uint32_t parentHubSlot : 8; + uint32_t parentPortNumber : 8; + uint32_t TTThinkTime : 2; + uint32_t reserved1 : 4; + uint32_t interrupterTarget : 10; + + uint32_t deviceAddress : 8; + uint32_t reserved2 : 20; + uint32_t slotState : 4; + + uint32_t reserved3[4]; +} SlotContext; + +typedef struct { + uint32_t endpointState : 3; + uint32_t reserved : 5; + uint32_t maximumBurstCount : 2; + uint32_t maxPrimaryStreams : 5; + uint32_t linearStreamArray : 1; + uint32_t interval : 8; + uint32_t maxEndpointServiceTime : 8; + + uint32_t reserved1 : 1; + uint32_t errorCont : 2; + uint32_t endpointType : 3; + uint32_t reserved2 : 1; + uint32_t hostInitiateDisable : 1; + uint32_t maxBurstSize : 8; + uint32_t maxPacketSize : 16; + + uint32_t dequeueCycleState : 1; + uint32_t reserved3 : 3; + uint32_t TRDequePointerLow : 28; + uint32_t TRDequePointerHigh; + + uint32_t everageTRBLength : 16; + uint32_t maxServiceTimeIntervalPayloadLow : 16; + + uint32_t reserved4[3]; +} EndpointContext; + +typedef struct { + SlotContext slotContext; + EndpointContext endpoints[31]; +} DeviceContext; + +typedef struct { uint32_t statusControl, powerManagement, linkInfo, reserved; } XHCIPortRegister;