diff --git a/src/include/syscalls.h b/src/include/syscalls.h index bfedf35..5e5c46b 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -5,8 +5,8 @@ #include typedef enum { - SYS_REGISTER_FUNCTION, - SYS_REQUEST, + SYS_REGISTER_FUNCTION = 1, + SYS_REQUEST = 2, } SyscallIds; typedef struct { @@ -14,6 +14,8 @@ void *returnAddress; void *returnEsp; uint32_t cr3; + void *respondingTo; + void *pageDirectory; bool resume; } Syscall; diff --git a/src/include/syscalls.h b/src/include/syscalls.h index bfedf35..5e5c46b 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -5,8 +5,8 @@ #include typedef enum { - SYS_REGISTER_FUNCTION, - SYS_REQUEST, + SYS_REGISTER_FUNCTION = 1, + SYS_REQUEST = 2, } SyscallIds; typedef struct { @@ -14,6 +14,8 @@ void *returnAddress; void *returnEsp; uint32_t cr3; + void *respondingTo; + void *pageDirectory; bool resume; } Syscall; diff --git a/src/kernel/main.c b/src/kernel/main.c index 350adc8..844c779 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -21,7 +21,8 @@ Service *findServiceByCR3(uint32_t cr3) { foreach (services, Service *, service, { - if (service->pagingInfo.pageDirectory == PTR(cr3)) { + if (getPhysicalAddressKernel(service->pagingInfo.pageDirectory) == + PTR(cr3)) { return service; } }) @@ -43,6 +44,45 @@ run(provider->service, provider->address); } +void handleInstallSyscall(Syscall *call, Service *service) { + Provider *provider = malloc(sizeof(Provider)); + RegisterServiceProviderSyscall *registerCall = (void *)call; + char *providerName = kernelMapPhysical( + getPhysicalAddress(registerCall->pageDirectory, registerCall->name)); + provider->name = providerName; + provider->address = registerCall->handler; + provider->service = service; + listAdd(&service->providers, provider); + call->resume = true; + listAdd(&callsToProcess, call); +} + +extern void *runEnd; + +void handleRequestSyscall(Syscall *call, Service *service) { + RequestSyscall *request = (void *)call; + char *serviceName = kernelMapPhysical( + getPhysicalAddress(request->pageDirectory, request->service)); + Service *providerService = findService(serviceName); + char *providerName = kernelMapPhysical( + getPhysicalAddress(request->pageDirectory, request->request)); + Provider *callProvider = findProvider(providerService, providerName); + Syscall *runCall = malloc(sizeof(Syscall)); + runCall->id = 0; + runCall->resume = true; + runCall->respondingTo = call; + runCall->pageDirectory = providerService->pagingInfo.pageDirectory; + runCall->cr3 = U32(getPhysicalAddressKernel(runCall->pageDirectory)); + runCall->returnEsp = malloc(0x1000); + runCall->returnAddress = callProvider->address; + runCall->resume = true; + sharePage(&providerService->pagingInfo, runCall->returnEsp, + runCall->returnEsp); + runCall->returnEsp += 0xFFC; + *(void **)runCall->returnEsp = runEnd; + listAdd(&callsToProcess, runCall); +} + void kernelMain(void *multibootInfo) { setupMemory(); void *address = kernelMapMultiplePhysicalPages(multibootInfo, 4); @@ -66,15 +106,12 @@ continue; } switch (call->id) { - case SYS_REGISTER_FUNCTION:; - Provider *provider = malloc(sizeof(Provider)); - RegisterServiceProviderSyscall *registerCall = (void *)call; - provider->name = registerCall->name; - provider->address = registerCall->handler; - provider->service = service; - listAdd(&service->providers, provider); + case SYS_REGISTER_FUNCTION: + handleInstallSyscall(call, service); + break; + case SYS_REQUEST: + handleRequestSyscall(call, service); + break; } - call->resume = true; - listAdd(&callsToProcess, call); } } diff --git a/src/include/syscalls.h b/src/include/syscalls.h index bfedf35..5e5c46b 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -5,8 +5,8 @@ #include typedef enum { - SYS_REGISTER_FUNCTION, - SYS_REQUEST, + SYS_REGISTER_FUNCTION = 1, + SYS_REQUEST = 2, } SyscallIds; typedef struct { @@ -14,6 +14,8 @@ void *returnAddress; void *returnEsp; uint32_t cr3; + void *respondingTo; + void *pageDirectory; bool resume; } Syscall; diff --git a/src/kernel/main.c b/src/kernel/main.c index 350adc8..844c779 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -21,7 +21,8 @@ Service *findServiceByCR3(uint32_t cr3) { foreach (services, Service *, service, { - if (service->pagingInfo.pageDirectory == PTR(cr3)) { + if (getPhysicalAddressKernel(service->pagingInfo.pageDirectory) == + PTR(cr3)) { return service; } }) @@ -43,6 +44,45 @@ run(provider->service, provider->address); } +void handleInstallSyscall(Syscall *call, Service *service) { + Provider *provider = malloc(sizeof(Provider)); + RegisterServiceProviderSyscall *registerCall = (void *)call; + char *providerName = kernelMapPhysical( + getPhysicalAddress(registerCall->pageDirectory, registerCall->name)); + provider->name = providerName; + provider->address = registerCall->handler; + provider->service = service; + listAdd(&service->providers, provider); + call->resume = true; + listAdd(&callsToProcess, call); +} + +extern void *runEnd; + +void handleRequestSyscall(Syscall *call, Service *service) { + RequestSyscall *request = (void *)call; + char *serviceName = kernelMapPhysical( + getPhysicalAddress(request->pageDirectory, request->service)); + Service *providerService = findService(serviceName); + char *providerName = kernelMapPhysical( + getPhysicalAddress(request->pageDirectory, request->request)); + Provider *callProvider = findProvider(providerService, providerName); + Syscall *runCall = malloc(sizeof(Syscall)); + runCall->id = 0; + runCall->resume = true; + runCall->respondingTo = call; + runCall->pageDirectory = providerService->pagingInfo.pageDirectory; + runCall->cr3 = U32(getPhysicalAddressKernel(runCall->pageDirectory)); + runCall->returnEsp = malloc(0x1000); + runCall->returnAddress = callProvider->address; + runCall->resume = true; + sharePage(&providerService->pagingInfo, runCall->returnEsp, + runCall->returnEsp); + runCall->returnEsp += 0xFFC; + *(void **)runCall->returnEsp = runEnd; + listAdd(&callsToProcess, runCall); +} + void kernelMain(void *multibootInfo) { setupMemory(); void *address = kernelMapMultiplePhysicalPages(multibootInfo, 4); @@ -66,15 +106,12 @@ continue; } switch (call->id) { - case SYS_REGISTER_FUNCTION:; - Provider *provider = malloc(sizeof(Provider)); - RegisterServiceProviderSyscall *registerCall = (void *)call; - provider->name = registerCall->name; - provider->address = registerCall->handler; - provider->service = service; - listAdd(&service->providers, provider); + case SYS_REGISTER_FUNCTION: + handleInstallSyscall(call, service); + break; + case SYS_REQUEST: + handleRequestSyscall(call, service); + break; } - call->resume = true; - listAdd(&callsToProcess, call); } } diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 93006dc..3a1bf1e 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -20,8 +20,8 @@ if (!callData) { asm("jmp runEndSyscall"); } - void *pageDirectory = mapTemporary(cr3); - void *dataPhysical = getPhysicalAddress(pageDirectory, callData); + callData->pageDirectory = kernelMapPhysical(cr3); + void *dataPhysical = getPhysicalAddress(callData->pageDirectory, callData); Syscall *data = kernelMapPhysical(dataPhysical); data->cr3 = U32(cr3); listAdd(&callsToProcess, data); diff --git a/src/include/syscalls.h b/src/include/syscalls.h index bfedf35..5e5c46b 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -5,8 +5,8 @@ #include typedef enum { - SYS_REGISTER_FUNCTION, - SYS_REQUEST, + SYS_REGISTER_FUNCTION = 1, + SYS_REQUEST = 2, } SyscallIds; typedef struct { @@ -14,6 +14,8 @@ void *returnAddress; void *returnEsp; uint32_t cr3; + void *respondingTo; + void *pageDirectory; bool resume; } Syscall; diff --git a/src/kernel/main.c b/src/kernel/main.c index 350adc8..844c779 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -21,7 +21,8 @@ Service *findServiceByCR3(uint32_t cr3) { foreach (services, Service *, service, { - if (service->pagingInfo.pageDirectory == PTR(cr3)) { + if (getPhysicalAddressKernel(service->pagingInfo.pageDirectory) == + PTR(cr3)) { return service; } }) @@ -43,6 +44,45 @@ run(provider->service, provider->address); } +void handleInstallSyscall(Syscall *call, Service *service) { + Provider *provider = malloc(sizeof(Provider)); + RegisterServiceProviderSyscall *registerCall = (void *)call; + char *providerName = kernelMapPhysical( + getPhysicalAddress(registerCall->pageDirectory, registerCall->name)); + provider->name = providerName; + provider->address = registerCall->handler; + provider->service = service; + listAdd(&service->providers, provider); + call->resume = true; + listAdd(&callsToProcess, call); +} + +extern void *runEnd; + +void handleRequestSyscall(Syscall *call, Service *service) { + RequestSyscall *request = (void *)call; + char *serviceName = kernelMapPhysical( + getPhysicalAddress(request->pageDirectory, request->service)); + Service *providerService = findService(serviceName); + char *providerName = kernelMapPhysical( + getPhysicalAddress(request->pageDirectory, request->request)); + Provider *callProvider = findProvider(providerService, providerName); + Syscall *runCall = malloc(sizeof(Syscall)); + runCall->id = 0; + runCall->resume = true; + runCall->respondingTo = call; + runCall->pageDirectory = providerService->pagingInfo.pageDirectory; + runCall->cr3 = U32(getPhysicalAddressKernel(runCall->pageDirectory)); + runCall->returnEsp = malloc(0x1000); + runCall->returnAddress = callProvider->address; + runCall->resume = true; + sharePage(&providerService->pagingInfo, runCall->returnEsp, + runCall->returnEsp); + runCall->returnEsp += 0xFFC; + *(void **)runCall->returnEsp = runEnd; + listAdd(&callsToProcess, runCall); +} + void kernelMain(void *multibootInfo) { setupMemory(); void *address = kernelMapMultiplePhysicalPages(multibootInfo, 4); @@ -66,15 +106,12 @@ continue; } switch (call->id) { - case SYS_REGISTER_FUNCTION:; - Provider *provider = malloc(sizeof(Provider)); - RegisterServiceProviderSyscall *registerCall = (void *)call; - provider->name = registerCall->name; - provider->address = registerCall->handler; - provider->service = service; - listAdd(&service->providers, provider); + case SYS_REGISTER_FUNCTION: + handleInstallSyscall(call, service); + break; + case SYS_REQUEST: + handleRequestSyscall(call, service); + break; } - call->resume = true; - listAdd(&callsToProcess, call); } } diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 93006dc..3a1bf1e 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -20,8 +20,8 @@ if (!callData) { asm("jmp runEndSyscall"); } - void *pageDirectory = mapTemporary(cr3); - void *dataPhysical = getPhysicalAddress(pageDirectory, callData); + callData->pageDirectory = kernelMapPhysical(cr3); + void *dataPhysical = getPhysicalAddress(callData->pageDirectory, callData); Syscall *data = kernelMapPhysical(dataPhysical); data->cr3 = U32(cr3); listAdd(&callsToProcess, data); diff --git a/src/kernel/util/list.c b/src/kernel/util/list.c index 4fbc79e..aa04956 100644 --- a/src/kernel/util/list.c +++ b/src/kernel/util/list.c @@ -2,19 +2,10 @@ #include void listAdd(ListElement **list, void *data) { - ListElement *element = *list; - if (!element) { - *list = malloc(sizeof(ListElement)); - element = *list; - } else { - while (element->next) { - element = element->next; - } - element->next = malloc(sizeof(ListElement)); - element = element->next; - } - element->next = NULL; + ListElement *element = malloc(sizeof(ListElement)); + element->next = *list; element->data = data; + *list = element; } void *listPopFirst(ListElement **list) { diff --git a/src/include/syscalls.h b/src/include/syscalls.h index bfedf35..5e5c46b 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -5,8 +5,8 @@ #include typedef enum { - SYS_REGISTER_FUNCTION, - SYS_REQUEST, + SYS_REGISTER_FUNCTION = 1, + SYS_REQUEST = 2, } SyscallIds; typedef struct { @@ -14,6 +14,8 @@ void *returnAddress; void *returnEsp; uint32_t cr3; + void *respondingTo; + void *pageDirectory; bool resume; } Syscall; diff --git a/src/kernel/main.c b/src/kernel/main.c index 350adc8..844c779 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -21,7 +21,8 @@ Service *findServiceByCR3(uint32_t cr3) { foreach (services, Service *, service, { - if (service->pagingInfo.pageDirectory == PTR(cr3)) { + if (getPhysicalAddressKernel(service->pagingInfo.pageDirectory) == + PTR(cr3)) { return service; } }) @@ -43,6 +44,45 @@ run(provider->service, provider->address); } +void handleInstallSyscall(Syscall *call, Service *service) { + Provider *provider = malloc(sizeof(Provider)); + RegisterServiceProviderSyscall *registerCall = (void *)call; + char *providerName = kernelMapPhysical( + getPhysicalAddress(registerCall->pageDirectory, registerCall->name)); + provider->name = providerName; + provider->address = registerCall->handler; + provider->service = service; + listAdd(&service->providers, provider); + call->resume = true; + listAdd(&callsToProcess, call); +} + +extern void *runEnd; + +void handleRequestSyscall(Syscall *call, Service *service) { + RequestSyscall *request = (void *)call; + char *serviceName = kernelMapPhysical( + getPhysicalAddress(request->pageDirectory, request->service)); + Service *providerService = findService(serviceName); + char *providerName = kernelMapPhysical( + getPhysicalAddress(request->pageDirectory, request->request)); + Provider *callProvider = findProvider(providerService, providerName); + Syscall *runCall = malloc(sizeof(Syscall)); + runCall->id = 0; + runCall->resume = true; + runCall->respondingTo = call; + runCall->pageDirectory = providerService->pagingInfo.pageDirectory; + runCall->cr3 = U32(getPhysicalAddressKernel(runCall->pageDirectory)); + runCall->returnEsp = malloc(0x1000); + runCall->returnAddress = callProvider->address; + runCall->resume = true; + sharePage(&providerService->pagingInfo, runCall->returnEsp, + runCall->returnEsp); + runCall->returnEsp += 0xFFC; + *(void **)runCall->returnEsp = runEnd; + listAdd(&callsToProcess, runCall); +} + void kernelMain(void *multibootInfo) { setupMemory(); void *address = kernelMapMultiplePhysicalPages(multibootInfo, 4); @@ -66,15 +106,12 @@ continue; } switch (call->id) { - case SYS_REGISTER_FUNCTION:; - Provider *provider = malloc(sizeof(Provider)); - RegisterServiceProviderSyscall *registerCall = (void *)call; - provider->name = registerCall->name; - provider->address = registerCall->handler; - provider->service = service; - listAdd(&service->providers, provider); + case SYS_REGISTER_FUNCTION: + handleInstallSyscall(call, service); + break; + case SYS_REQUEST: + handleRequestSyscall(call, service); + break; } - call->resume = true; - listAdd(&callsToProcess, call); } } diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 93006dc..3a1bf1e 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -20,8 +20,8 @@ if (!callData) { asm("jmp runEndSyscall"); } - void *pageDirectory = mapTemporary(cr3); - void *dataPhysical = getPhysicalAddress(pageDirectory, callData); + callData->pageDirectory = kernelMapPhysical(cr3); + void *dataPhysical = getPhysicalAddress(callData->pageDirectory, callData); Syscall *data = kernelMapPhysical(dataPhysical); data->cr3 = U32(cr3); listAdd(&callsToProcess, data); diff --git a/src/kernel/util/list.c b/src/kernel/util/list.c index 4fbc79e..aa04956 100644 --- a/src/kernel/util/list.c +++ b/src/kernel/util/list.c @@ -2,19 +2,10 @@ #include void listAdd(ListElement **list, void *data) { - ListElement *element = *list; - if (!element) { - *list = malloc(sizeof(ListElement)); - element = *list; - } else { - while (element->next) { - element = element->next; - } - element->next = malloc(sizeof(ListElement)); - element = element->next; - } - element->next = NULL; + ListElement *element = malloc(sizeof(ListElement)); + element->next = *list; element->data = data; + *list = element; } void *listPopFirst(ListElement **list) { diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 8d8fec5..957fb57 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -26,10 +26,13 @@ } void testProvider(void *requestData) { - writeParallel('t'); - writeParallel('e'); - writeParallel('s'); - writeParallel('t'); + // writeParallel('t'); + // writeParallel('e'); + // writeParallel('s'); + // writeParallel('t'); + asm("mov %%eax, %0" ::"r"(0xB105F00D)); + while (1) + ; } void bufferFunction() {} @@ -58,7 +61,7 @@ void installServiceProvider(char *name, void(provider)(void *)) { RegisterServiceProviderSyscall call = { - .id = SYS_REQUEST, + .id = SYS_REGISTER_FUNCTION, .name = name, .handler = provider, }; @@ -71,7 +74,7 @@ // writeParallel('I'); // install installServiceProvider("test", testProvider); // writeParallel('C'); // call - // test(); + test(); // writeParallel('E'); // end return 0; }