diff --git a/Makefile b/Makefile index 7ee17e3..766deab 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s +EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int BUILD_FOLDER = build diff --git a/Makefile b/Makefile index 7ee17e3..766deab 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s +EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int BUILD_FOLDER = build diff --git a/src/kernel/include/syscall.h b/src/kernel/include/syscall.h index 46ac97c..30df090 100644 --- a/src/kernel/include/syscall.h +++ b/src/kernel/include/syscall.h @@ -19,4 +19,7 @@ extern void setupSyscalls(); extern void processSyscall(Syscall *call); +extern void handleSyscall(void *esp, uint32_t function, uint32_t parameter0, + uint32_t parameter1, uint32_t parameter2, + uint32_t parameter3); #endif diff --git a/Makefile b/Makefile index 7ee17e3..766deab 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s +EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int BUILD_FOLDER = build diff --git a/src/kernel/include/syscall.h b/src/kernel/include/syscall.h index 46ac97c..30df090 100644 --- a/src/kernel/include/syscall.h +++ b/src/kernel/include/syscall.h @@ -19,4 +19,7 @@ extern void setupSyscalls(); extern void processSyscall(Syscall *call); +extern void handleSyscall(void *esp, uint32_t function, uint32_t parameter0, + uint32_t parameter1, uint32_t parameter2, + uint32_t parameter3); #endif diff --git a/src/kernel/interrupts/interruptDescriptors.asm b/src/kernel/interrupts/interruptDescriptors.asm index 094e43d..f003f4d 100644 --- a/src/kernel/interrupts/interruptDescriptors.asm +++ b/src/kernel/interrupts/interruptDescriptors.asm @@ -14,9 +14,8 @@ ret exceptionAbort: - mov eax, cr3 - cmp eax, 0x500000 - je $ + mov ebx, [esp+24] + jmp $ mov eax, 0x500000 mov cr3, eax mov eax, [temporaryESP] @@ -36,40 +35,18 @@ mov eax, [esp+20] cmp eax, 31 jng exceptionAbort -.normalInterrupt: - push eax -.checkUsermode: - mov eax, cr3 - cmp eax, 0x500000 - je .kernelPages -.saveRegistersToOldStack: - mov eax, [esp+44] ; eax = old esp - mov ebx, [esp+32] ; ebx = old eip - mov [eax], ebx ; virtual push - add eax, 4 -.pushRegisters: - mov ebx, [esp+4] ; ebx = old edx - mov [eax], ebx ; virtual push ebx - add eax, 4 - mov ebx, [esp+8] ; ebx = old ecx - mov [eax], ebx ; virtual push ebx - add eax, 4 - mov ebx, [esp+12] ; ebx = old ebx - mov [eax], ebx ; virtual push ebx - add eax, 4 - mov ebx, [esp+16] ; ebx = old edx - mov [eax], ebx ; virtual push ebx - add eax, 4 -.kernelPages: - push eax +.goToKernelPages: mov eax, 0x500000 mov cr3, eax -.callHandler: - push interruptReturn call onInterrupt -.iretNow: - add esp, 40 - iret + pop eax + mov cr3, eax + pop edx + pop ecx + pop ebx + pop eax + add esp, 8 + iretd %macro interruptHandler 1 ALIGN 4 diff --git a/Makefile b/Makefile index 7ee17e3..766deab 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s +EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int BUILD_FOLDER = build diff --git a/src/kernel/include/syscall.h b/src/kernel/include/syscall.h index 46ac97c..30df090 100644 --- a/src/kernel/include/syscall.h +++ b/src/kernel/include/syscall.h @@ -19,4 +19,7 @@ extern void setupSyscalls(); extern void processSyscall(Syscall *call); +extern void handleSyscall(void *esp, uint32_t function, uint32_t parameter0, + uint32_t parameter1, uint32_t parameter2, + uint32_t parameter3); #endif diff --git a/src/kernel/interrupts/interruptDescriptors.asm b/src/kernel/interrupts/interruptDescriptors.asm index 094e43d..f003f4d 100644 --- a/src/kernel/interrupts/interruptDescriptors.asm +++ b/src/kernel/interrupts/interruptDescriptors.asm @@ -14,9 +14,8 @@ ret exceptionAbort: - mov eax, cr3 - cmp eax, 0x500000 - je $ + mov ebx, [esp+24] + jmp $ mov eax, 0x500000 mov cr3, eax mov eax, [temporaryESP] @@ -36,40 +35,18 @@ mov eax, [esp+20] cmp eax, 31 jng exceptionAbort -.normalInterrupt: - push eax -.checkUsermode: - mov eax, cr3 - cmp eax, 0x500000 - je .kernelPages -.saveRegistersToOldStack: - mov eax, [esp+44] ; eax = old esp - mov ebx, [esp+32] ; ebx = old eip - mov [eax], ebx ; virtual push - add eax, 4 -.pushRegisters: - mov ebx, [esp+4] ; ebx = old edx - mov [eax], ebx ; virtual push ebx - add eax, 4 - mov ebx, [esp+8] ; ebx = old ecx - mov [eax], ebx ; virtual push ebx - add eax, 4 - mov ebx, [esp+12] ; ebx = old ebx - mov [eax], ebx ; virtual push ebx - add eax, 4 - mov ebx, [esp+16] ; ebx = old edx - mov [eax], ebx ; virtual push ebx - add eax, 4 -.kernelPages: - push eax +.goToKernelPages: mov eax, 0x500000 mov cr3, eax -.callHandler: - push interruptReturn call onInterrupt -.iretNow: - add esp, 40 - iret + pop eax + mov cr3, eax + pop edx + pop ecx + pop ebx + pop eax + add esp, 8 + iretd %macro interruptHandler 1 ALIGN 4 diff --git a/src/kernel/interrupts/interrupts.c b/src/kernel/interrupts/interrupts.c index c40ecee..c8bded8 100644 --- a/src/kernel/interrupts/interrupts.c +++ b/src/kernel/interrupts/interrupts.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #define IDT_ENTRY(i) \ @@ -19,23 +20,11 @@ __attribute__((section(".sharedFunctions"))) __attribute__((aligned(0x10))) IdtEntry idtEntries[256] = {}; -void onInterrupt(void *eip, void *esp, uint32_t intNo, void *cr3) { - // an external interrupt was triggered +void onInterrupt(void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, + uint32_t intNo) { foreach (interruptSubscriptions[intNo], ServiceFunction *, provider, { scheduleFunction(provider, intNo, 0, 0, NULL); }) ; - if (cr3 == PTR(0x500000)) { - // interrupt was triggered while the kernel was doing stuff - return; - } - Syscall *call = malloc(sizeof(Syscall)); - call->service = currentSyscall->service; - call->esp = esp; - call->respondingTo = currentSyscall->respondingTo; - call->cr3 = cr3; - call->resume = true; - listAdd(&callsToProcess, call); - asm("jmp handleSyscallEnd"); } extern void *interruptStack; @@ -51,13 +40,15 @@ currentGdt[5].baseHigh = U32(&tss) >> 24; currentGdt[5].access = 0xE9; currentGdt[5].granularity = 0; + currentGdt[3].access = 0xFD; + currentGdt[4].access = 0xF2; tss.ss0 = tss.ss = 0x10; tss.esp0 = tss.esp = U32(&interruptStack) + 1024; asm("mov $40, %%ax" ::); asm("ltr %%ax" ::); for (uint16_t i = 0; i < 256; i++) { idtEntries[i].reserved = 0; - idtEntries[i].type = 0x8E; + idtEntries[i].type = 0xEE; idtEntries[i].segment = 0x8; } TIMES(IDT_ENTRY); diff --git a/Makefile b/Makefile index 7ee17e3..766deab 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s +EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int BUILD_FOLDER = build diff --git a/src/kernel/include/syscall.h b/src/kernel/include/syscall.h index 46ac97c..30df090 100644 --- a/src/kernel/include/syscall.h +++ b/src/kernel/include/syscall.h @@ -19,4 +19,7 @@ extern void setupSyscalls(); extern void processSyscall(Syscall *call); +extern void handleSyscall(void *esp, uint32_t function, uint32_t parameter0, + uint32_t parameter1, uint32_t parameter2, + uint32_t parameter3); #endif diff --git a/src/kernel/interrupts/interruptDescriptors.asm b/src/kernel/interrupts/interruptDescriptors.asm index 094e43d..f003f4d 100644 --- a/src/kernel/interrupts/interruptDescriptors.asm +++ b/src/kernel/interrupts/interruptDescriptors.asm @@ -14,9 +14,8 @@ ret exceptionAbort: - mov eax, cr3 - cmp eax, 0x500000 - je $ + mov ebx, [esp+24] + jmp $ mov eax, 0x500000 mov cr3, eax mov eax, [temporaryESP] @@ -36,40 +35,18 @@ mov eax, [esp+20] cmp eax, 31 jng exceptionAbort -.normalInterrupt: - push eax -.checkUsermode: - mov eax, cr3 - cmp eax, 0x500000 - je .kernelPages -.saveRegistersToOldStack: - mov eax, [esp+44] ; eax = old esp - mov ebx, [esp+32] ; ebx = old eip - mov [eax], ebx ; virtual push - add eax, 4 -.pushRegisters: - mov ebx, [esp+4] ; ebx = old edx - mov [eax], ebx ; virtual push ebx - add eax, 4 - mov ebx, [esp+8] ; ebx = old ecx - mov [eax], ebx ; virtual push ebx - add eax, 4 - mov ebx, [esp+12] ; ebx = old ebx - mov [eax], ebx ; virtual push ebx - add eax, 4 - mov ebx, [esp+16] ; ebx = old edx - mov [eax], ebx ; virtual push ebx - add eax, 4 -.kernelPages: - push eax +.goToKernelPages: mov eax, 0x500000 mov cr3, eax -.callHandler: - push interruptReturn call onInterrupt -.iretNow: - add esp, 40 - iret + pop eax + mov cr3, eax + pop edx + pop ecx + pop ebx + pop eax + add esp, 8 + iretd %macro interruptHandler 1 ALIGN 4 diff --git a/src/kernel/interrupts/interrupts.c b/src/kernel/interrupts/interrupts.c index c40ecee..c8bded8 100644 --- a/src/kernel/interrupts/interrupts.c +++ b/src/kernel/interrupts/interrupts.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #define IDT_ENTRY(i) \ @@ -19,23 +20,11 @@ __attribute__((section(".sharedFunctions"))) __attribute__((aligned(0x10))) IdtEntry idtEntries[256] = {}; -void onInterrupt(void *eip, void *esp, uint32_t intNo, void *cr3) { - // an external interrupt was triggered +void onInterrupt(void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, + uint32_t intNo) { foreach (interruptSubscriptions[intNo], ServiceFunction *, provider, { scheduleFunction(provider, intNo, 0, 0, NULL); }) ; - if (cr3 == PTR(0x500000)) { - // interrupt was triggered while the kernel was doing stuff - return; - } - Syscall *call = malloc(sizeof(Syscall)); - call->service = currentSyscall->service; - call->esp = esp; - call->respondingTo = currentSyscall->respondingTo; - call->cr3 = cr3; - call->resume = true; - listAdd(&callsToProcess, call); - asm("jmp handleSyscallEnd"); } extern void *interruptStack; @@ -51,13 +40,15 @@ currentGdt[5].baseHigh = U32(&tss) >> 24; currentGdt[5].access = 0xE9; currentGdt[5].granularity = 0; + currentGdt[3].access = 0xFD; + currentGdt[4].access = 0xF2; tss.ss0 = tss.ss = 0x10; tss.esp0 = tss.esp = U32(&interruptStack) + 1024; asm("mov $40, %%ax" ::); asm("ltr %%ax" ::); for (uint16_t i = 0; i < 256; i++) { idtEntries[i].reserved = 0; - idtEntries[i].type = 0x8E; + idtEntries[i].type = 0xEE; idtEntries[i].segment = 0x8; } TIMES(IDT_ENTRY); diff --git a/src/kernel/stringmap/stringmapSyscalls.c b/src/kernel/stringmap/stringmapSyscalls.c index 665c765..2e1ff3d 100644 --- a/src/kernel/stringmap/stringmapSyscalls.c +++ b/src/kernel/stringmap/stringmapSyscalls.c @@ -28,7 +28,9 @@ void *buffer = kernelMapPhysical(getPhysicalAddress( callService->pagingInfo.pageDirectory, PTR(call->parameters[1]))); char *string = retrieveString(stringId); - memcpy(string, buffer, strlen(string) + 1); + if (string) { + memcpy(string, buffer, strlen(string) + 1); + } unmapPage(buffer); } diff --git a/Makefile b/Makefile index 7ee17e3..766deab 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s +EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int BUILD_FOLDER = build diff --git a/src/kernel/include/syscall.h b/src/kernel/include/syscall.h index 46ac97c..30df090 100644 --- a/src/kernel/include/syscall.h +++ b/src/kernel/include/syscall.h @@ -19,4 +19,7 @@ extern void setupSyscalls(); extern void processSyscall(Syscall *call); +extern void handleSyscall(void *esp, uint32_t function, uint32_t parameter0, + uint32_t parameter1, uint32_t parameter2, + uint32_t parameter3); #endif diff --git a/src/kernel/interrupts/interruptDescriptors.asm b/src/kernel/interrupts/interruptDescriptors.asm index 094e43d..f003f4d 100644 --- a/src/kernel/interrupts/interruptDescriptors.asm +++ b/src/kernel/interrupts/interruptDescriptors.asm @@ -14,9 +14,8 @@ ret exceptionAbort: - mov eax, cr3 - cmp eax, 0x500000 - je $ + mov ebx, [esp+24] + jmp $ mov eax, 0x500000 mov cr3, eax mov eax, [temporaryESP] @@ -36,40 +35,18 @@ mov eax, [esp+20] cmp eax, 31 jng exceptionAbort -.normalInterrupt: - push eax -.checkUsermode: - mov eax, cr3 - cmp eax, 0x500000 - je .kernelPages -.saveRegistersToOldStack: - mov eax, [esp+44] ; eax = old esp - mov ebx, [esp+32] ; ebx = old eip - mov [eax], ebx ; virtual push - add eax, 4 -.pushRegisters: - mov ebx, [esp+4] ; ebx = old edx - mov [eax], ebx ; virtual push ebx - add eax, 4 - mov ebx, [esp+8] ; ebx = old ecx - mov [eax], ebx ; virtual push ebx - add eax, 4 - mov ebx, [esp+12] ; ebx = old ebx - mov [eax], ebx ; virtual push ebx - add eax, 4 - mov ebx, [esp+16] ; ebx = old edx - mov [eax], ebx ; virtual push ebx - add eax, 4 -.kernelPages: - push eax +.goToKernelPages: mov eax, 0x500000 mov cr3, eax -.callHandler: - push interruptReturn call onInterrupt -.iretNow: - add esp, 40 - iret + pop eax + mov cr3, eax + pop edx + pop ecx + pop ebx + pop eax + add esp, 8 + iretd %macro interruptHandler 1 ALIGN 4 diff --git a/src/kernel/interrupts/interrupts.c b/src/kernel/interrupts/interrupts.c index c40ecee..c8bded8 100644 --- a/src/kernel/interrupts/interrupts.c +++ b/src/kernel/interrupts/interrupts.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #define IDT_ENTRY(i) \ @@ -19,23 +20,11 @@ __attribute__((section(".sharedFunctions"))) __attribute__((aligned(0x10))) IdtEntry idtEntries[256] = {}; -void onInterrupt(void *eip, void *esp, uint32_t intNo, void *cr3) { - // an external interrupt was triggered +void onInterrupt(void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, + uint32_t intNo) { foreach (interruptSubscriptions[intNo], ServiceFunction *, provider, { scheduleFunction(provider, intNo, 0, 0, NULL); }) ; - if (cr3 == PTR(0x500000)) { - // interrupt was triggered while the kernel was doing stuff - return; - } - Syscall *call = malloc(sizeof(Syscall)); - call->service = currentSyscall->service; - call->esp = esp; - call->respondingTo = currentSyscall->respondingTo; - call->cr3 = cr3; - call->resume = true; - listAdd(&callsToProcess, call); - asm("jmp handleSyscallEnd"); } extern void *interruptStack; @@ -51,13 +40,15 @@ currentGdt[5].baseHigh = U32(&tss) >> 24; currentGdt[5].access = 0xE9; currentGdt[5].granularity = 0; + currentGdt[3].access = 0xFD; + currentGdt[4].access = 0xF2; tss.ss0 = tss.ss = 0x10; tss.esp0 = tss.esp = U32(&interruptStack) + 1024; asm("mov $40, %%ax" ::); asm("ltr %%ax" ::); for (uint16_t i = 0; i < 256; i++) { idtEntries[i].reserved = 0; - idtEntries[i].type = 0x8E; + idtEntries[i].type = 0xEE; idtEntries[i].segment = 0x8; } TIMES(IDT_ENTRY); diff --git a/src/kernel/stringmap/stringmapSyscalls.c b/src/kernel/stringmap/stringmapSyscalls.c index 665c765..2e1ff3d 100644 --- a/src/kernel/stringmap/stringmapSyscalls.c +++ b/src/kernel/stringmap/stringmapSyscalls.c @@ -28,7 +28,9 @@ void *buffer = kernelMapPhysical(getPhysicalAddress( callService->pagingInfo.pageDirectory, PTR(call->parameters[1]))); char *string = retrieveString(stringId); - memcpy(string, buffer, strlen(string) + 1); + if (string) { + memcpy(string, buffer, strlen(string) + 1); + } unmapPage(buffer); } diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 9b7d63f..e93c99c 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -43,6 +43,10 @@ Service *currentService = currentSyscall->service; call->cr3 = getPhysicalAddressKernel(currentService->pagingInfo.pageDirectory); + if (function == -1) { + call->resume = true; + call->function = 0; + } listAdd(&callsToProcess, call); } diff --git a/Makefile b/Makefile index 7ee17e3..766deab 100644 --- a/Makefile +++ b/Makefile @@ -7,7 +7,7 @@ AS = nasm ASFlAGS = -felf32 EMU = qemu-system-x86_64 -EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s +EMUFLAGS = -m 1G -drive format=raw,file=$(IMAGE_FILE) -no-reboot -no-shutdown -monitor stdio -d int -D crashlog.log -s -d int BUILD_FOLDER = build diff --git a/src/kernel/include/syscall.h b/src/kernel/include/syscall.h index 46ac97c..30df090 100644 --- a/src/kernel/include/syscall.h +++ b/src/kernel/include/syscall.h @@ -19,4 +19,7 @@ extern void setupSyscalls(); extern void processSyscall(Syscall *call); +extern void handleSyscall(void *esp, uint32_t function, uint32_t parameter0, + uint32_t parameter1, uint32_t parameter2, + uint32_t parameter3); #endif diff --git a/src/kernel/interrupts/interruptDescriptors.asm b/src/kernel/interrupts/interruptDescriptors.asm index 094e43d..f003f4d 100644 --- a/src/kernel/interrupts/interruptDescriptors.asm +++ b/src/kernel/interrupts/interruptDescriptors.asm @@ -14,9 +14,8 @@ ret exceptionAbort: - mov eax, cr3 - cmp eax, 0x500000 - je $ + mov ebx, [esp+24] + jmp $ mov eax, 0x500000 mov cr3, eax mov eax, [temporaryESP] @@ -36,40 +35,18 @@ mov eax, [esp+20] cmp eax, 31 jng exceptionAbort -.normalInterrupt: - push eax -.checkUsermode: - mov eax, cr3 - cmp eax, 0x500000 - je .kernelPages -.saveRegistersToOldStack: - mov eax, [esp+44] ; eax = old esp - mov ebx, [esp+32] ; ebx = old eip - mov [eax], ebx ; virtual push - add eax, 4 -.pushRegisters: - mov ebx, [esp+4] ; ebx = old edx - mov [eax], ebx ; virtual push ebx - add eax, 4 - mov ebx, [esp+8] ; ebx = old ecx - mov [eax], ebx ; virtual push ebx - add eax, 4 - mov ebx, [esp+12] ; ebx = old ebx - mov [eax], ebx ; virtual push ebx - add eax, 4 - mov ebx, [esp+16] ; ebx = old edx - mov [eax], ebx ; virtual push ebx - add eax, 4 -.kernelPages: - push eax +.goToKernelPages: mov eax, 0x500000 mov cr3, eax -.callHandler: - push interruptReturn call onInterrupt -.iretNow: - add esp, 40 - iret + pop eax + mov cr3, eax + pop edx + pop ecx + pop ebx + pop eax + add esp, 8 + iretd %macro interruptHandler 1 ALIGN 4 diff --git a/src/kernel/interrupts/interrupts.c b/src/kernel/interrupts/interrupts.c index c40ecee..c8bded8 100644 --- a/src/kernel/interrupts/interrupts.c +++ b/src/kernel/interrupts/interrupts.c @@ -2,6 +2,7 @@ #include #include #include +#include #include #define IDT_ENTRY(i) \ @@ -19,23 +20,11 @@ __attribute__((section(".sharedFunctions"))) __attribute__((aligned(0x10))) IdtEntry idtEntries[256] = {}; -void onInterrupt(void *eip, void *esp, uint32_t intNo, void *cr3) { - // an external interrupt was triggered +void onInterrupt(void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, + uint32_t intNo) { foreach (interruptSubscriptions[intNo], ServiceFunction *, provider, { scheduleFunction(provider, intNo, 0, 0, NULL); }) ; - if (cr3 == PTR(0x500000)) { - // interrupt was triggered while the kernel was doing stuff - return; - } - Syscall *call = malloc(sizeof(Syscall)); - call->service = currentSyscall->service; - call->esp = esp; - call->respondingTo = currentSyscall->respondingTo; - call->cr3 = cr3; - call->resume = true; - listAdd(&callsToProcess, call); - asm("jmp handleSyscallEnd"); } extern void *interruptStack; @@ -51,13 +40,15 @@ currentGdt[5].baseHigh = U32(&tss) >> 24; currentGdt[5].access = 0xE9; currentGdt[5].granularity = 0; + currentGdt[3].access = 0xFD; + currentGdt[4].access = 0xF2; tss.ss0 = tss.ss = 0x10; tss.esp0 = tss.esp = U32(&interruptStack) + 1024; asm("mov $40, %%ax" ::); asm("ltr %%ax" ::); for (uint16_t i = 0; i < 256; i++) { idtEntries[i].reserved = 0; - idtEntries[i].type = 0x8E; + idtEntries[i].type = 0xEE; idtEntries[i].segment = 0x8; } TIMES(IDT_ENTRY); diff --git a/src/kernel/stringmap/stringmapSyscalls.c b/src/kernel/stringmap/stringmapSyscalls.c index 665c765..2e1ff3d 100644 --- a/src/kernel/stringmap/stringmapSyscalls.c +++ b/src/kernel/stringmap/stringmapSyscalls.c @@ -28,7 +28,9 @@ void *buffer = kernelMapPhysical(getPhysicalAddress( callService->pagingInfo.pageDirectory, PTR(call->parameters[1]))); char *string = retrieveString(stringId); - memcpy(string, buffer, strlen(string) + 1); + if (string) { + memcpy(string, buffer, strlen(string) + 1); + } unmapPage(buffer); } diff --git a/src/kernel/syscalls/syscall.c b/src/kernel/syscalls/syscall.c index 9b7d63f..e93c99c 100644 --- a/src/kernel/syscalls/syscall.c +++ b/src/kernel/syscalls/syscall.c @@ -43,6 +43,10 @@ Service *currentService = currentSyscall->service; call->cr3 = getPhysicalAddressKernel(currentService->pagingInfo.pageDirectory); + if (function == -1) { + call->resume = true; + call->function = 0; + } listAdd(&callsToProcess, call); } diff --git a/src/userland/log/main.c b/src/userland/log/main.c index 6e5f629..2ac85e1 100644 --- a/src/userland/log/main.c +++ b/src/userland/log/main.c @@ -22,7 +22,7 @@ void handleLog(uint32_t stringId, uint32_t unused, uint32_t caller) { while (lock) { - ioIn(1, 1); + syscall(-1, 0, 0, 0, 0); } lock = true; writeString("[ ");