diff --git a/src/include/hlib.h b/src/include/hlib.h index bcd6966..22fd9be 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -76,6 +76,7 @@ extern bool listRemoveValue(ListElement **list, void *value); extern void *getPhysicalAddress(void *address); extern void sleep(uint32_t millis); +extern uint32_t fork(void (f)(), void *, void *, void *); extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); #define listAdd(list, data) _listAdd(malloc, list, data) diff --git a/src/include/hlib.h b/src/include/hlib.h index bcd6966..22fd9be 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -76,6 +76,7 @@ extern bool listRemoveValue(ListElement **list, void *value); extern void *getPhysicalAddress(void *address); extern void sleep(uint32_t millis); +extern uint32_t fork(void (f)(), void *, void *, void *); extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); #define listAdd(list, data) _listAdd(malloc, list, data) diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index b3a7456..8591e94 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -110,3 +110,13 @@ } call->returnValue = 0; } + +void handleForkSyscall(Syscall *call) { + Service *service = call->service; + ServiceFunction function = { + .service = service, + .address = call->parameters[0], + .name = "fork function", + }; + scheduleFunction(&function, NULL, call->parameters[1], call->parameters[2], call->parameters[3]); +} diff --git a/src/include/hlib.h b/src/include/hlib.h index bcd6966..22fd9be 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -76,6 +76,7 @@ extern bool listRemoveValue(ListElement **list, void *value); extern void *getPhysicalAddress(void *address); extern void sleep(uint32_t millis); +extern uint32_t fork(void (f)(), void *, void *, void *); extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); #define listAdd(list, data) _listAdd(malloc, list, data) diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index b3a7456..8591e94 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -110,3 +110,13 @@ } call->returnValue = 0; } + +void handleForkSyscall(Syscall *call) { + Service *service = call->service; + ServiceFunction function = { + .service = service, + .address = call->parameters[0], + .name = "fork function", + }; + scheduleFunction(&function, NULL, call->parameters[1], call->parameters[2], call->parameters[3]); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 61ab6d8..7a86b12 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -79,6 +79,7 @@ extern uintptr_t handleStackContainsSyscall; extern uintptr_t handleAwaitSyscall; extern uintptr_t handleGetPhysicalSyscall; +extern uintptr_t handleForkSyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -104,6 +105,7 @@ (void *)&handleStackContainsSyscall, (void *)&handleAwaitSyscall, (void *)&handleGetPhysicalSyscall, + (void *)&handleForkSyscall, }; void processSyscall(Syscall *call) { diff --git a/src/include/hlib.h b/src/include/hlib.h index bcd6966..22fd9be 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -76,6 +76,7 @@ extern bool listRemoveValue(ListElement **list, void *value); extern void *getPhysicalAddress(void *address); extern void sleep(uint32_t millis); +extern uint32_t fork(void (f)(), void *, void *, void *); extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); #define listAdd(list, data) _listAdd(malloc, list, data) diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index b3a7456..8591e94 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -110,3 +110,13 @@ } call->returnValue = 0; } + +void handleForkSyscall(Syscall *call) { + Service *service = call->service; + ServiceFunction function = { + .service = service, + .address = call->parameters[0], + .name = "fork function", + }; + scheduleFunction(&function, NULL, call->parameters[1], call->parameters[2], call->parameters[3]); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 61ab6d8..7a86b12 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -79,6 +79,7 @@ extern uintptr_t handleStackContainsSyscall; extern uintptr_t handleAwaitSyscall; extern uintptr_t handleGetPhysicalSyscall; +extern uintptr_t handleForkSyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -104,6 +105,7 @@ (void *)&handleStackContainsSyscall, (void *)&handleAwaitSyscall, (void *)&handleGetPhysicalSyscall, + (void *)&handleForkSyscall, }; void processSyscall(Syscall *call) { diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index 88343b8..2025b24 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -28,6 +28,7 @@ SYS_STACK_CONTAINS = 20, SYS_AWAIT = 21, SYS_GET_PHYSICAL = 22, + SYS_FORK = 23, } SyscallIds; extern uint32_t getFunction(uint32_t module, char *name); diff --git a/src/include/hlib.h b/src/include/hlib.h index bcd6966..22fd9be 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -76,6 +76,7 @@ extern bool listRemoveValue(ListElement **list, void *value); extern void *getPhysicalAddress(void *address); extern void sleep(uint32_t millis); +extern uint32_t fork(void (f)(), void *, void *, void *); extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); #define listAdd(list, data) _listAdd(malloc, list, data) diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index b3a7456..8591e94 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -110,3 +110,13 @@ } call->returnValue = 0; } + +void handleForkSyscall(Syscall *call) { + Service *service = call->service; + ServiceFunction function = { + .service = service, + .address = call->parameters[0], + .name = "fork function", + }; + scheduleFunction(&function, NULL, call->parameters[1], call->parameters[2], call->parameters[3]); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 61ab6d8..7a86b12 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -79,6 +79,7 @@ extern uintptr_t handleStackContainsSyscall; extern uintptr_t handleAwaitSyscall; extern uintptr_t handleGetPhysicalSyscall; +extern uintptr_t handleForkSyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -104,6 +105,7 @@ (void *)&handleStackContainsSyscall, (void *)&handleAwaitSyscall, (void *)&handleGetPhysicalSyscall, + (void *)&handleForkSyscall, }; void processSyscall(Syscall *call) { diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index 88343b8..2025b24 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -28,6 +28,7 @@ SYS_STACK_CONTAINS = 20, SYS_AWAIT = 21, SYS_GET_PHYSICAL = 22, + SYS_FORK = 23, } 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 e31be53..1669154 100644 --- a/src/userland/hlib/service/service.c +++ b/src/userland/hlib/service/service.c @@ -32,3 +32,8 @@ return PTR(syscall(SYS_GET_PHYSICAL, U32(source) & ~0xFFF, 0, 0, 0) | (U32(source) & 0xFFF)); } + +uint32_t fork(void (f)(), void *a, void *b, void *c) { + return syscall(SYS_FORK, U32(f), U32(a), U32(b), U32(c)); +} + diff --git a/src/include/hlib.h b/src/include/hlib.h index bcd6966..22fd9be 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -76,6 +76,7 @@ extern bool listRemoveValue(ListElement **list, void *value); extern void *getPhysicalAddress(void *address); extern void sleep(uint32_t millis); +extern uint32_t fork(void (f)(), void *, void *, void *); extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); #define listAdd(list, data) _listAdd(malloc, list, data) diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index b3a7456..8591e94 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -110,3 +110,13 @@ } call->returnValue = 0; } + +void handleForkSyscall(Syscall *call) { + Service *service = call->service; + ServiceFunction function = { + .service = service, + .address = call->parameters[0], + .name = "fork function", + }; + scheduleFunction(&function, NULL, call->parameters[1], call->parameters[2], call->parameters[3]); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 61ab6d8..7a86b12 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -79,6 +79,7 @@ extern uintptr_t handleStackContainsSyscall; extern uintptr_t handleAwaitSyscall; extern uintptr_t handleGetPhysicalSyscall; +extern uintptr_t handleForkSyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -104,6 +105,7 @@ (void *)&handleStackContainsSyscall, (void *)&handleAwaitSyscall, (void *)&handleGetPhysicalSyscall, + (void *)&handleForkSyscall, }; void processSyscall(Syscall *call) { diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index 88343b8..2025b24 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -28,6 +28,7 @@ SYS_STACK_CONTAINS = 20, SYS_AWAIT = 21, SYS_GET_PHYSICAL = 22, + SYS_FORK = 23, } 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 e31be53..1669154 100644 --- a/src/userland/hlib/service/service.c +++ b/src/userland/hlib/service/service.c @@ -32,3 +32,8 @@ return PTR(syscall(SYS_GET_PHYSICAL, U32(source) & ~0xFFF, 0, 0, 0) | (U32(source) & 0xFFF)); } + +uint32_t fork(void (f)(), void *a, void *b, void *c) { + return syscall(SYS_FORK, U32(f), U32(a), U32(b), U32(c)); +} + diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 1b1e3c1..5a31845 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -63,7 +63,7 @@ uint8_t endpointIndex = (endpointNumber)*2 - 1 + direction; void *buffer = requestMemory(1, 0, 0); void *bufferPhysical = getPhysicalAddress(buffer); - slot->interface->setupHID(slot->data, endpointIndex, buffer); + fork(slot->interface->setupHID, slot->data, endpointIndex, buffer); }) // clear list } diff --git a/src/include/hlib.h b/src/include/hlib.h index bcd6966..22fd9be 100644 --- a/src/include/hlib.h +++ b/src/include/hlib.h @@ -76,6 +76,7 @@ extern bool listRemoveValue(ListElement **list, void *value); extern void *getPhysicalAddress(void *address); extern void sleep(uint32_t millis); +extern uint32_t fork(void (f)(), void *, void *, void *); extern void _listAdd(void *(malloc)(uint32_t), ListElement **list, void *data); #define listAdd(list, data) _listAdd(malloc, list, data) diff --git a/src/kernel/service/serviceSyscalls.c b/src/kernel/service/serviceSyscalls.c index b3a7456..8591e94 100644 --- a/src/kernel/service/serviceSyscalls.c +++ b/src/kernel/service/serviceSyscalls.c @@ -110,3 +110,13 @@ } call->returnValue = 0; } + +void handleForkSyscall(Syscall *call) { + Service *service = call->service; + ServiceFunction function = { + .service = service, + .address = call->parameters[0], + .name = "fork function", + }; + scheduleFunction(&function, NULL, call->parameters[1], call->parameters[2], call->parameters[3]); +} diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 61ab6d8..7a86b12 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -79,6 +79,7 @@ extern uintptr_t handleStackContainsSyscall; extern uintptr_t handleAwaitSyscall; extern uintptr_t handleGetPhysicalSyscall; +extern uintptr_t handleForkSyscall; void (*syscallHandlers[])(Syscall *) = { 0, @@ -104,6 +105,7 @@ (void *)&handleStackContainsSyscall, (void *)&handleAwaitSyscall, (void *)&handleGetPhysicalSyscall, + (void *)&handleForkSyscall, }; void processSyscall(Syscall *call) { diff --git a/src/userland/hlib/include/syscalls.h b/src/userland/hlib/include/syscalls.h index 88343b8..2025b24 100644 --- a/src/userland/hlib/include/syscalls.h +++ b/src/userland/hlib/include/syscalls.h @@ -28,6 +28,7 @@ SYS_STACK_CONTAINS = 20, SYS_AWAIT = 21, SYS_GET_PHYSICAL = 22, + SYS_FORK = 23, } 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 e31be53..1669154 100644 --- a/src/userland/hlib/service/service.c +++ b/src/userland/hlib/service/service.c @@ -32,3 +32,8 @@ return PTR(syscall(SYS_GET_PHYSICAL, U32(source) & ~0xFFF, 0, 0, 0) | (U32(source) & 0xFFF)); } + +uint32_t fork(void (f)(), void *a, void *b, void *c) { + return syscall(SYS_FORK, U32(f), U32(a), U32(b), U32(c)); +} + diff --git a/src/userland/usb/main.c b/src/userland/usb/main.c index 1b1e3c1..5a31845 100644 --- a/src/userland/usb/main.c +++ b/src/userland/usb/main.c @@ -63,7 +63,7 @@ uint8_t endpointIndex = (endpointNumber)*2 - 1 + direction; void *buffer = requestMemory(1, 0, 0); void *bufferPhysical = getPhysicalAddress(buffer); - slot->interface->setupHID(slot->data, endpointIndex, buffer); + fork(slot->interface->setupHID, slot->data, endpointIndex, buffer); }) // clear list } diff --git a/src/userland/usb/xhci/xhci.c b/src/userland/usb/xhci/xhci.c index f5b89fc..8457f25 100644 --- a/src/userland/usb/xhci/xhci.c +++ b/src/userland/usb/xhci/xhci.c @@ -215,6 +215,7 @@ } } + UsbHostControllerInterface xhci = { .initialize = init, .getDeviceDescriptor = (void *)usbGetDeviceDescriptor,