diff --git a/src/include/syscalls.h b/src/include/syscalls.h index 2a35dd8..dd3cc12 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -15,16 +15,4 @@ SYS_GET_PROVIDER = 7, } SyscallIds; -typedef struct Syscall { - uint32_t function; - uint32_t parameters[4]; - uint32_t returnValue; - void *esp; - void *cr3; - struct Syscall *respondingTo; - void *service; - bool resume; - bool avoidReschedule; -} Syscall; - #endif diff --git a/src/include/syscalls.h b/src/include/syscalls.h index 2a35dd8..dd3cc12 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -15,16 +15,4 @@ SYS_GET_PROVIDER = 7, } SyscallIds; -typedef struct Syscall { - uint32_t function; - uint32_t parameters[4]; - uint32_t returnValue; - void *esp; - void *cr3; - struct Syscall *respondingTo; - void *service; - bool resume; - bool avoidReschedule; -} Syscall; - #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index f0af9ac..62206d2 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -2,7 +2,7 @@ #define SERVICE_H #include -#include +#include #include typedef struct { diff --git a/src/include/syscalls.h b/src/include/syscalls.h index 2a35dd8..dd3cc12 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -15,16 +15,4 @@ SYS_GET_PROVIDER = 7, } SyscallIds; -typedef struct Syscall { - uint32_t function; - uint32_t parameters[4]; - uint32_t returnValue; - void *esp; - void *cr3; - struct Syscall *respondingTo; - void *service; - bool resume; - bool avoidReschedule; -} Syscall; - #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index f0af9ac..62206d2 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -2,7 +2,7 @@ #define SERVICE_H #include -#include +#include #include typedef struct { diff --git a/src/kernel/include/syscall.h b/src/kernel/include/syscall.h index b5576a4..e7ced85 100644 --- a/src/kernel/include/syscall.h +++ b/src/kernel/include/syscall.h @@ -3,8 +3,19 @@ #include -extern void setupSyscalls(); +typedef struct Syscall { + uint32_t function; + uint32_t parameters[4]; + uint32_t returnValue; + void *esp; + void *cr3; + struct Syscall *respondingTo; + void *service; + bool resume; + bool avoidReschedule; +} Syscall; +extern void setupSyscalls(); extern void (*syscallHandlers[])(Syscall *); #endif diff --git a/src/include/syscalls.h b/src/include/syscalls.h index 2a35dd8..dd3cc12 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -15,16 +15,4 @@ SYS_GET_PROVIDER = 7, } SyscallIds; -typedef struct Syscall { - uint32_t function; - uint32_t parameters[4]; - uint32_t returnValue; - void *esp; - void *cr3; - struct Syscall *respondingTo; - void *service; - bool resume; - bool avoidReschedule; -} Syscall; - #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index f0af9ac..62206d2 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -2,7 +2,7 @@ #define SERVICE_H #include -#include +#include #include typedef struct { diff --git a/src/kernel/include/syscall.h b/src/kernel/include/syscall.h index b5576a4..e7ced85 100644 --- a/src/kernel/include/syscall.h +++ b/src/kernel/include/syscall.h @@ -3,8 +3,19 @@ #include -extern void setupSyscalls(); +typedef struct Syscall { + uint32_t function; + uint32_t parameters[4]; + uint32_t returnValue; + void *esp; + void *cr3; + struct Syscall *respondingTo; + void *service; + bool resume; + bool avoidReschedule; +} Syscall; +extern void setupSyscalls(); extern void (*syscallHandlers[])(Syscall *); #endif diff --git a/src/kernel/main.c b/src/kernel/main.c index a70cf75..33b9b77 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -56,6 +56,7 @@ } if (call->resume) { resume(call); + free(call); continue; } void (*handler)(Syscall *) = syscallHandlers[call->function]; diff --git a/src/include/syscalls.h b/src/include/syscalls.h index 2a35dd8..dd3cc12 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -15,16 +15,4 @@ SYS_GET_PROVIDER = 7, } SyscallIds; -typedef struct Syscall { - uint32_t function; - uint32_t parameters[4]; - uint32_t returnValue; - void *esp; - void *cr3; - struct Syscall *respondingTo; - void *service; - bool resume; - bool avoidReschedule; -} Syscall; - #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index f0af9ac..62206d2 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -2,7 +2,7 @@ #define SERVICE_H #include -#include +#include #include typedef struct { diff --git a/src/kernel/include/syscall.h b/src/kernel/include/syscall.h index b5576a4..e7ced85 100644 --- a/src/kernel/include/syscall.h +++ b/src/kernel/include/syscall.h @@ -3,8 +3,19 @@ #include -extern void setupSyscalls(); +typedef struct Syscall { + uint32_t function; + uint32_t parameters[4]; + uint32_t returnValue; + void *esp; + void *cr3; + struct Syscall *respondingTo; + void *service; + bool resume; + bool avoidReschedule; +} Syscall; +extern void setupSyscalls(); extern void (*syscallHandlers[])(Syscall *); #endif diff --git a/src/kernel/main.c b/src/kernel/main.c index a70cf75..33b9b77 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -56,6 +56,7 @@ } if (call->resume) { resume(call); + free(call); continue; } void (*handler)(Syscall *) = syscallHandlers[call->function]; diff --git a/src/kernel/service/service.asm b/src/kernel/service/service.asm index 9c47365..1d8ad27 100644 --- a/src/kernel/service/service.asm +++ b/src/kernel/service/service.asm @@ -14,7 +14,6 @@ mov [temporaryESP], eax mov ebx, [currentSyscall] mov ecx, [ebx + 24] - mov ebp, ecx mov edx, returnPoint mov eax, [ebx + 28] mov ebx, [ebx + 20] diff --git a/src/include/syscalls.h b/src/include/syscalls.h index 2a35dd8..dd3cc12 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -15,16 +15,4 @@ SYS_GET_PROVIDER = 7, } SyscallIds; -typedef struct Syscall { - uint32_t function; - uint32_t parameters[4]; - uint32_t returnValue; - void *esp; - void *cr3; - struct Syscall *respondingTo; - void *service; - bool resume; - bool avoidReschedule; -} Syscall; - #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index f0af9ac..62206d2 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -2,7 +2,7 @@ #define SERVICE_H #include -#include +#include #include typedef struct { diff --git a/src/kernel/include/syscall.h b/src/kernel/include/syscall.h index b5576a4..e7ced85 100644 --- a/src/kernel/include/syscall.h +++ b/src/kernel/include/syscall.h @@ -3,8 +3,19 @@ #include -extern void setupSyscalls(); +typedef struct Syscall { + uint32_t function; + uint32_t parameters[4]; + uint32_t returnValue; + void *esp; + void *cr3; + struct Syscall *respondingTo; + void *service; + bool resume; + bool avoidReschedule; +} Syscall; +extern void setupSyscalls(); extern void (*syscallHandlers[])(Syscall *); #endif diff --git a/src/kernel/main.c b/src/kernel/main.c index a70cf75..33b9b77 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -56,6 +56,7 @@ } if (call->resume) { resume(call); + free(call); continue; } void (*handler)(Syscall *) = syscallHandlers[call->function]; diff --git a/src/kernel/service/service.asm b/src/kernel/service/service.asm index 9c47365..1d8ad27 100644 --- a/src/kernel/service/service.asm +++ b/src/kernel/service/service.asm @@ -14,7 +14,6 @@ mov [temporaryESP], eax mov ebx, [currentSyscall] mov ecx, [ebx + 24] - mov ebp, ecx mov edx, returnPoint mov eax, [ebx + 28] mov ebx, [ebx + 20] diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 541cea0..76d1d07 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -18,10 +18,18 @@ 0); // when transitioning to 64 bit: U32(value) >> 32); } +uint32_t n = 0; + void handleSyscall(void *esp, uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3) { if (!function) { + if (n++ == 5) { + asm("nop" ::"a"(function), "b"(currentSyscall), + "c"(currentSyscall->respondingTo)); + while (1) + ; + } if (currentSyscall->respondingTo) { listAdd(&callsToProcess, currentSyscall->respondingTo); } @@ -35,8 +43,12 @@ call->parameters[3] = parameter3; call->service = currentSyscall->service; call->esp = esp; - if (!call->respondingTo) { - call->respondingTo = currentSyscall->respondingTo; + call->respondingTo = currentSyscall->respondingTo; + if (call->respondingTo->service == currentSyscall->service) { + asm("nop" ::"a"(currentSyscall), "b"(call), + "c"(currentSyscall->respondingTo), "d"(0xB105F00D)); + while (1) + ; } Service *currentService = currentSyscall->service; call->cr3 = @@ -77,18 +89,23 @@ Service *providerService = listGet(services, call->parameters[0]); Provider *provider = listGet(providerService->providers, call->parameters[1]); + void *data = kernelMapPhysical(getPhysicalAddress( + service->pagingInfo.pageDirectory, PTR(call->parameters[2]))); + sharePage(&providerService->pagingInfo, data, data); Syscall *runCall = malloc(sizeof(Syscall)); runCall->function = SYS_RUN; runCall->esp = malloc(0x1000); - runCall->respondingTo = (void *)call; + runCall->respondingTo = call; runCall->cr3 = getPhysicalAddressKernel(providerService->pagingInfo.pageDirectory); runCall->service = providerService; runCall->resume = true; sharePage(&providerService->pagingInfo, runCall->esp, runCall->esp); - runCall->esp += 0xFF8; + runCall->esp += 0xFF0; *(void **)runCall->esp = provider->address; - *(void **)(runCall->esp + 4) = &runEnd; + *(void **)(runCall->esp + 0x4) = &runEnd; + *(void **)(runCall->esp + 0x8) = data; + *(uint32_t *)(runCall->esp + 0xC) = call->parameters[3]; listAdd(&callsToProcess, runCall); call->avoidReschedule = true; } diff --git a/src/include/syscalls.h b/src/include/syscalls.h index 2a35dd8..dd3cc12 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -15,16 +15,4 @@ SYS_GET_PROVIDER = 7, } SyscallIds; -typedef struct Syscall { - uint32_t function; - uint32_t parameters[4]; - uint32_t returnValue; - void *esp; - void *cr3; - struct Syscall *respondingTo; - void *service; - bool resume; - bool avoidReschedule; -} Syscall; - #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index f0af9ac..62206d2 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -2,7 +2,7 @@ #define SERVICE_H #include -#include +#include #include typedef struct { diff --git a/src/kernel/include/syscall.h b/src/kernel/include/syscall.h index b5576a4..e7ced85 100644 --- a/src/kernel/include/syscall.h +++ b/src/kernel/include/syscall.h @@ -3,8 +3,19 @@ #include -extern void setupSyscalls(); +typedef struct Syscall { + uint32_t function; + uint32_t parameters[4]; + uint32_t returnValue; + void *esp; + void *cr3; + struct Syscall *respondingTo; + void *service; + bool resume; + bool avoidReschedule; +} Syscall; +extern void setupSyscalls(); extern void (*syscallHandlers[])(Syscall *); #endif diff --git a/src/kernel/main.c b/src/kernel/main.c index a70cf75..33b9b77 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -56,6 +56,7 @@ } if (call->resume) { resume(call); + free(call); continue; } void (*handler)(Syscall *) = syscallHandlers[call->function]; diff --git a/src/kernel/service/service.asm b/src/kernel/service/service.asm index 9c47365..1d8ad27 100644 --- a/src/kernel/service/service.asm +++ b/src/kernel/service/service.asm @@ -14,7 +14,6 @@ mov [temporaryESP], eax mov ebx, [currentSyscall] mov ecx, [ebx + 24] - mov ebp, ecx mov edx, returnPoint mov eax, [ebx + 28] mov ebx, [ebx + 20] diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 541cea0..76d1d07 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -18,10 +18,18 @@ 0); // when transitioning to 64 bit: U32(value) >> 32); } +uint32_t n = 0; + void handleSyscall(void *esp, uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3) { if (!function) { + if (n++ == 5) { + asm("nop" ::"a"(function), "b"(currentSyscall), + "c"(currentSyscall->respondingTo)); + while (1) + ; + } if (currentSyscall->respondingTo) { listAdd(&callsToProcess, currentSyscall->respondingTo); } @@ -35,8 +43,12 @@ call->parameters[3] = parameter3; call->service = currentSyscall->service; call->esp = esp; - if (!call->respondingTo) { - call->respondingTo = currentSyscall->respondingTo; + call->respondingTo = currentSyscall->respondingTo; + if (call->respondingTo->service == currentSyscall->service) { + asm("nop" ::"a"(currentSyscall), "b"(call), + "c"(currentSyscall->respondingTo), "d"(0xB105F00D)); + while (1) + ; } Service *currentService = currentSyscall->service; call->cr3 = @@ -77,18 +89,23 @@ Service *providerService = listGet(services, call->parameters[0]); Provider *provider = listGet(providerService->providers, call->parameters[1]); + void *data = kernelMapPhysical(getPhysicalAddress( + service->pagingInfo.pageDirectory, PTR(call->parameters[2]))); + sharePage(&providerService->pagingInfo, data, data); Syscall *runCall = malloc(sizeof(Syscall)); runCall->function = SYS_RUN; runCall->esp = malloc(0x1000); - runCall->respondingTo = (void *)call; + runCall->respondingTo = call; runCall->cr3 = getPhysicalAddressKernel(providerService->pagingInfo.pageDirectory); runCall->service = providerService; runCall->resume = true; sharePage(&providerService->pagingInfo, runCall->esp, runCall->esp); - runCall->esp += 0xFF8; + runCall->esp += 0xFF0; *(void **)runCall->esp = provider->address; - *(void **)(runCall->esp + 4) = &runEnd; + *(void **)(runCall->esp + 0x4) = &runEnd; + *(void **)(runCall->esp + 0x8) = data; + *(uint32_t *)(runCall->esp + 0xC) = call->parameters[3]; listAdd(&callsToProcess, runCall); call->avoidReschedule = true; } diff --git a/src/kernel/util/list.c b/src/kernel/util/list.c index a5f39fb..fca8497 100644 --- a/src/kernel/util/list.c +++ b/src/kernel/util/list.c @@ -20,7 +20,9 @@ if (!*list) { return NULL; } - void *result = (*list)->data; + ListElement *resultElement = *list; + void *result = resultElement->data; *list = (*list)->next; + free(resultElement); return result; } diff --git a/src/include/syscalls.h b/src/include/syscalls.h index 2a35dd8..dd3cc12 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -15,16 +15,4 @@ SYS_GET_PROVIDER = 7, } SyscallIds; -typedef struct Syscall { - uint32_t function; - uint32_t parameters[4]; - uint32_t returnValue; - void *esp; - void *cr3; - struct Syscall *respondingTo; - void *service; - bool resume; - bool avoidReschedule; -} Syscall; - #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index f0af9ac..62206d2 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -2,7 +2,7 @@ #define SERVICE_H #include -#include +#include #include typedef struct { diff --git a/src/kernel/include/syscall.h b/src/kernel/include/syscall.h index b5576a4..e7ced85 100644 --- a/src/kernel/include/syscall.h +++ b/src/kernel/include/syscall.h @@ -3,8 +3,19 @@ #include -extern void setupSyscalls(); +typedef struct Syscall { + uint32_t function; + uint32_t parameters[4]; + uint32_t returnValue; + void *esp; + void *cr3; + struct Syscall *respondingTo; + void *service; + bool resume; + bool avoidReschedule; +} Syscall; +extern void setupSyscalls(); extern void (*syscallHandlers[])(Syscall *); #endif diff --git a/src/kernel/main.c b/src/kernel/main.c index a70cf75..33b9b77 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -56,6 +56,7 @@ } if (call->resume) { resume(call); + free(call); continue; } void (*handler)(Syscall *) = syscallHandlers[call->function]; diff --git a/src/kernel/service/service.asm b/src/kernel/service/service.asm index 9c47365..1d8ad27 100644 --- a/src/kernel/service/service.asm +++ b/src/kernel/service/service.asm @@ -14,7 +14,6 @@ mov [temporaryESP], eax mov ebx, [currentSyscall] mov ecx, [ebx + 24] - mov ebp, ecx mov edx, returnPoint mov eax, [ebx + 28] mov ebx, [ebx + 20] diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 541cea0..76d1d07 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -18,10 +18,18 @@ 0); // when transitioning to 64 bit: U32(value) >> 32); } +uint32_t n = 0; + void handleSyscall(void *esp, uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3) { if (!function) { + if (n++ == 5) { + asm("nop" ::"a"(function), "b"(currentSyscall), + "c"(currentSyscall->respondingTo)); + while (1) + ; + } if (currentSyscall->respondingTo) { listAdd(&callsToProcess, currentSyscall->respondingTo); } @@ -35,8 +43,12 @@ call->parameters[3] = parameter3; call->service = currentSyscall->service; call->esp = esp; - if (!call->respondingTo) { - call->respondingTo = currentSyscall->respondingTo; + call->respondingTo = currentSyscall->respondingTo; + if (call->respondingTo->service == currentSyscall->service) { + asm("nop" ::"a"(currentSyscall), "b"(call), + "c"(currentSyscall->respondingTo), "d"(0xB105F00D)); + while (1) + ; } Service *currentService = currentSyscall->service; call->cr3 = @@ -77,18 +89,23 @@ Service *providerService = listGet(services, call->parameters[0]); Provider *provider = listGet(providerService->providers, call->parameters[1]); + void *data = kernelMapPhysical(getPhysicalAddress( + service->pagingInfo.pageDirectory, PTR(call->parameters[2]))); + sharePage(&providerService->pagingInfo, data, data); Syscall *runCall = malloc(sizeof(Syscall)); runCall->function = SYS_RUN; runCall->esp = malloc(0x1000); - runCall->respondingTo = (void *)call; + runCall->respondingTo = call; runCall->cr3 = getPhysicalAddressKernel(providerService->pagingInfo.pageDirectory); runCall->service = providerService; runCall->resume = true; sharePage(&providerService->pagingInfo, runCall->esp, runCall->esp); - runCall->esp += 0xFF8; + runCall->esp += 0xFF0; *(void **)runCall->esp = provider->address; - *(void **)(runCall->esp + 4) = &runEnd; + *(void **)(runCall->esp + 0x4) = &runEnd; + *(void **)(runCall->esp + 0x8) = data; + *(uint32_t *)(runCall->esp + 0xC) = call->parameters[3]; listAdd(&callsToProcess, runCall); call->avoidReschedule = true; } diff --git a/src/kernel/util/list.c b/src/kernel/util/list.c index a5f39fb..fca8497 100644 --- a/src/kernel/util/list.c +++ b/src/kernel/util/list.c @@ -20,7 +20,9 @@ if (!*list) { return NULL; } - void *result = (*list)->data; + ListElement *resultElement = *list; + void *result = resultElement->data; *list = (*list)->next; + free(resultElement); return result; } diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 271647b..45d48ef 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -6,17 +6,22 @@ uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3) { - uint32_t esp, result; + uint32_t esp; asm("push %%eax" ::"a"(&&end)); asm("mov %%esp, %%eax" : "=a"(esp)); asm("sysenter\n" : : "a"(function), "b"(parameter0), "c"(parameter1), "d"(parameter2), "S"(parameter3), "D"(esp)); +// eax is set by the kernel as the return value end: - // eax is set by the kernel as the return value - asm("nop" : "=a"(result)); - return result; + // the 0x1C comes from the number of parameters / local variables do handle + // this function with care or it will break everything + asm("add $0x1C, %%esp\n" + "pop %%ebp\n" + "ret" ::); + // don't go here! ret returns with the correct value + return 0; } void request(uint32_t module, uint32_t function, void *data, uint32_t size) { @@ -57,5 +62,6 @@ int32_t main() { loadFromInitrd("log"); log("hello world"); + log("honey os is alive :)"); return 0; } diff --git a/src/include/syscalls.h b/src/include/syscalls.h index 2a35dd8..dd3cc12 100644 --- a/src/include/syscalls.h +++ b/src/include/syscalls.h @@ -15,16 +15,4 @@ SYS_GET_PROVIDER = 7, } SyscallIds; -typedef struct Syscall { - uint32_t function; - uint32_t parameters[4]; - uint32_t returnValue; - void *esp; - void *cr3; - struct Syscall *respondingTo; - void *service; - bool resume; - bool avoidReschedule; -} Syscall; - #endif diff --git a/src/kernel/include/service.h b/src/kernel/include/service.h index f0af9ac..62206d2 100644 --- a/src/kernel/include/service.h +++ b/src/kernel/include/service.h @@ -2,7 +2,7 @@ #define SERVICE_H #include -#include +#include #include typedef struct { diff --git a/src/kernel/include/syscall.h b/src/kernel/include/syscall.h index b5576a4..e7ced85 100644 --- a/src/kernel/include/syscall.h +++ b/src/kernel/include/syscall.h @@ -3,8 +3,19 @@ #include -extern void setupSyscalls(); +typedef struct Syscall { + uint32_t function; + uint32_t parameters[4]; + uint32_t returnValue; + void *esp; + void *cr3; + struct Syscall *respondingTo; + void *service; + bool resume; + bool avoidReschedule; +} Syscall; +extern void setupSyscalls(); extern void (*syscallHandlers[])(Syscall *); #endif diff --git a/src/kernel/main.c b/src/kernel/main.c index a70cf75..33b9b77 100644 --- a/src/kernel/main.c +++ b/src/kernel/main.c @@ -56,6 +56,7 @@ } if (call->resume) { resume(call); + free(call); continue; } void (*handler)(Syscall *) = syscallHandlers[call->function]; diff --git a/src/kernel/service/service.asm b/src/kernel/service/service.asm index 9c47365..1d8ad27 100644 --- a/src/kernel/service/service.asm +++ b/src/kernel/service/service.asm @@ -14,7 +14,6 @@ mov [temporaryESP], eax mov ebx, [currentSyscall] mov ecx, [ebx + 24] - mov ebp, ecx mov edx, returnPoint mov eax, [ebx + 28] mov ebx, [ebx + 20] diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 541cea0..76d1d07 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -18,10 +18,18 @@ 0); // when transitioning to 64 bit: U32(value) >> 32); } +uint32_t n = 0; + void handleSyscall(void *esp, uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3) { if (!function) { + if (n++ == 5) { + asm("nop" ::"a"(function), "b"(currentSyscall), + "c"(currentSyscall->respondingTo)); + while (1) + ; + } if (currentSyscall->respondingTo) { listAdd(&callsToProcess, currentSyscall->respondingTo); } @@ -35,8 +43,12 @@ call->parameters[3] = parameter3; call->service = currentSyscall->service; call->esp = esp; - if (!call->respondingTo) { - call->respondingTo = currentSyscall->respondingTo; + call->respondingTo = currentSyscall->respondingTo; + if (call->respondingTo->service == currentSyscall->service) { + asm("nop" ::"a"(currentSyscall), "b"(call), + "c"(currentSyscall->respondingTo), "d"(0xB105F00D)); + while (1) + ; } Service *currentService = currentSyscall->service; call->cr3 = @@ -77,18 +89,23 @@ Service *providerService = listGet(services, call->parameters[0]); Provider *provider = listGet(providerService->providers, call->parameters[1]); + void *data = kernelMapPhysical(getPhysicalAddress( + service->pagingInfo.pageDirectory, PTR(call->parameters[2]))); + sharePage(&providerService->pagingInfo, data, data); Syscall *runCall = malloc(sizeof(Syscall)); runCall->function = SYS_RUN; runCall->esp = malloc(0x1000); - runCall->respondingTo = (void *)call; + runCall->respondingTo = call; runCall->cr3 = getPhysicalAddressKernel(providerService->pagingInfo.pageDirectory); runCall->service = providerService; runCall->resume = true; sharePage(&providerService->pagingInfo, runCall->esp, runCall->esp); - runCall->esp += 0xFF8; + runCall->esp += 0xFF0; *(void **)runCall->esp = provider->address; - *(void **)(runCall->esp + 4) = &runEnd; + *(void **)(runCall->esp + 0x4) = &runEnd; + *(void **)(runCall->esp + 0x8) = data; + *(uint32_t *)(runCall->esp + 0xC) = call->parameters[3]; listAdd(&callsToProcess, runCall); call->avoidReschedule = true; } diff --git a/src/kernel/util/list.c b/src/kernel/util/list.c index a5f39fb..fca8497 100644 --- a/src/kernel/util/list.c +++ b/src/kernel/util/list.c @@ -20,7 +20,9 @@ if (!*list) { return NULL; } - void *result = (*list)->data; + ListElement *resultElement = *list; + void *result = resultElement->data; *list = (*list)->next; + free(resultElement); return result; } diff --git a/src/userland/loader/main.c b/src/userland/loader/main.c index 271647b..45d48ef 100644 --- a/src/userland/loader/main.c +++ b/src/userland/loader/main.c @@ -6,17 +6,22 @@ uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3) { - uint32_t esp, result; + uint32_t esp; asm("push %%eax" ::"a"(&&end)); asm("mov %%esp, %%eax" : "=a"(esp)); asm("sysenter\n" : : "a"(function), "b"(parameter0), "c"(parameter1), "d"(parameter2), "S"(parameter3), "D"(esp)); +// eax is set by the kernel as the return value end: - // eax is set by the kernel as the return value - asm("nop" : "=a"(result)); - return result; + // the 0x1C comes from the number of parameters / local variables do handle + // this function with care or it will break everything + asm("add $0x1C, %%esp\n" + "pop %%ebp\n" + "ret" ::); + // don't go here! ret returns with the correct value + return 0; } void request(uint32_t module, uint32_t function, void *data, uint32_t size) { @@ -57,5 +62,6 @@ int32_t main() { loadFromInitrd("log"); log("hello world"); + log("honey os is alive :)"); return 0; } diff --git a/src/userland/log/main.c b/src/userland/log/main.c index e2a95b1..054223a 100644 --- a/src/userland/log/main.c +++ b/src/userland/log/main.c @@ -6,7 +6,7 @@ uint32_t syscall(uint32_t function, uint32_t parameter0, uint32_t parameter1, uint32_t parameter2, uint32_t parameter3) { - uint32_t esp, result; + uint32_t esp; asm("push %%eax" ::"a"(&&end)); asm("mov %%esp, %%eax" : "=a"(esp)); asm("sysenter\n" @@ -15,11 +15,16 @@ "S"(parameter3), "D"(esp)); // eax is set by the kernel as the return value end: - asm("nop" : "=a"(result)); - return result; + // the 0x1C comes from the number of parameters / local variables do handle + // this function with care or it will break everything + asm("add $0x1C, %%esp\n" + "pop %%ebp\n" + "ret" ::); + // don't go here! ret returns with the correct value + return 0; } -void installServiceProvider(char *name, void(provider)(void *)) { +void installServiceProvider(char *name, void(provider)(void *, uint32_t)) { syscall(SYS_REGISTER_FUNCTION, U32(name), U32(provider), 0, 0); } @@ -53,10 +58,13 @@ } } -void log(void *requestData) { - writeParallel('l'); - writeParallel('o'); - writeParallel('g'); +void log(void *data, uint32_t dataLength) { + char *string = data, dump; + for (uint32_t i = 0; i < dataLength; i++) { + writeParallel(string[i]); + } + writeParallel('\r'); + writeParallel('\n'); } int32_t main() {