diff --git a/src/kernel/interrupts/interruptDescriptors.asm b/src/kernel/interrupts/interruptDescriptors.asm index 342cf25..1b80dc9 100644 --- a/src/kernel/interrupts/interruptDescriptors.asm +++ b/src/kernel/interrupts/interruptDescriptors.asm @@ -3,6 +3,7 @@ extern onInterrupt extern temporaryESP extern handleSyscallEnd +extern onException global interruptStack interruptStack: resb 1024 @@ -20,6 +21,7 @@ je $ mov ecx, 0x500000 mov cr3, ecx + call onException mov eax, [temporaryESP] mov esp, eax pop ebp diff --git a/src/kernel/interrupts/interruptDescriptors.asm b/src/kernel/interrupts/interruptDescriptors.asm index 342cf25..1b80dc9 100644 --- a/src/kernel/interrupts/interruptDescriptors.asm +++ b/src/kernel/interrupts/interruptDescriptors.asm @@ -3,6 +3,7 @@ extern onInterrupt extern temporaryESP extern handleSyscallEnd +extern onException global interruptStack interruptStack: resb 1024 @@ -20,6 +21,7 @@ je $ mov ecx, 0x500000 mov cr3, ecx + call onException mov eax, [temporaryESP] mov esp, eax pop ebp diff --git a/src/kernel/interrupts/interrupts.c b/src/kernel/interrupts/interrupts.c index c8bded8..8ce4e9c 100644 --- a/src/kernel/interrupts/interrupts.c +++ b/src/kernel/interrupts/interrupts.c @@ -20,6 +20,8 @@ __attribute__((section(".sharedFunctions"))) __attribute__((aligned(0x10))) IdtEntry idtEntries[256] = {}; +ListElement *exceptionSubscriptions; + void onInterrupt(void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, uint32_t intNo) { foreach (interruptSubscriptions[intNo], ServiceFunction *, provider, @@ -27,6 +29,14 @@ ; } +void onException(void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, + uint32_t intNo) { + foreach (interruptSubscriptions[0], ServiceFunction *, provider, { + scheduleFunction(provider, intNo, 0, + ((Service *)currentSyscall->service)->nameHash, NULL); + }) +} + extern void *interruptStack; void setupPic(); diff --git a/src/kernel/interrupts/interruptDescriptors.asm b/src/kernel/interrupts/interruptDescriptors.asm index 342cf25..1b80dc9 100644 --- a/src/kernel/interrupts/interruptDescriptors.asm +++ b/src/kernel/interrupts/interruptDescriptors.asm @@ -3,6 +3,7 @@ extern onInterrupt extern temporaryESP extern handleSyscallEnd +extern onException global interruptStack interruptStack: resb 1024 @@ -20,6 +21,7 @@ je $ mov ecx, 0x500000 mov cr3, ecx + call onException mov eax, [temporaryESP] mov esp, eax pop ebp diff --git a/src/kernel/interrupts/interrupts.c b/src/kernel/interrupts/interrupts.c index c8bded8..8ce4e9c 100644 --- a/src/kernel/interrupts/interrupts.c +++ b/src/kernel/interrupts/interrupts.c @@ -20,6 +20,8 @@ __attribute__((section(".sharedFunctions"))) __attribute__((aligned(0x10))) IdtEntry idtEntries[256] = {}; +ListElement *exceptionSubscriptions; + void onInterrupt(void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, uint32_t intNo) { foreach (interruptSubscriptions[intNo], ServiceFunction *, provider, @@ -27,6 +29,14 @@ ; } +void onException(void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, + uint32_t intNo) { + foreach (interruptSubscriptions[0], ServiceFunction *, provider, { + scheduleFunction(provider, intNo, 0, + ((Service *)currentSyscall->service)->nameHash, NULL); + }) +} + extern void *interruptStack; void setupPic(); diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 10c23b9..ae7b506 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -4,7 +4,7 @@ #include int32_t main() { - printf("doing a crash test now . . . "); + printf("trying to divide by zero now . . . "); printf("0/0 = %i", 0 / 0); return 0; } diff --git a/src/kernel/interrupts/interruptDescriptors.asm b/src/kernel/interrupts/interruptDescriptors.asm index 342cf25..1b80dc9 100644 --- a/src/kernel/interrupts/interruptDescriptors.asm +++ b/src/kernel/interrupts/interruptDescriptors.asm @@ -3,6 +3,7 @@ extern onInterrupt extern temporaryESP extern handleSyscallEnd +extern onException global interruptStack interruptStack: resb 1024 @@ -20,6 +21,7 @@ je $ mov ecx, 0x500000 mov cr3, ecx + call onException mov eax, [temporaryESP] mov esp, eax pop ebp diff --git a/src/kernel/interrupts/interrupts.c b/src/kernel/interrupts/interrupts.c index c8bded8..8ce4e9c 100644 --- a/src/kernel/interrupts/interrupts.c +++ b/src/kernel/interrupts/interrupts.c @@ -20,6 +20,8 @@ __attribute__((section(".sharedFunctions"))) __attribute__((aligned(0x10))) IdtEntry idtEntries[256] = {}; +ListElement *exceptionSubscriptions; + void onInterrupt(void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, uint32_t intNo) { foreach (interruptSubscriptions[intNo], ServiceFunction *, provider, @@ -27,6 +29,14 @@ ; } +void onException(void *cr3, uint32_t d, uint32_t c, uint32_t b, uint32_t a, + uint32_t intNo) { + foreach (interruptSubscriptions[0], ServiceFunction *, provider, { + scheduleFunction(provider, intNo, 0, + ((Service *)currentSyscall->service)->nameHash, NULL); + }) +} + extern void *interruptStack; void setupPic(); diff --git a/src/userland/crashTest/main.c b/src/userland/crashTest/main.c index 10c23b9..ae7b506 100644 --- a/src/userland/crashTest/main.c +++ b/src/userland/crashTest/main.c @@ -4,7 +4,7 @@ #include int32_t main() { - printf("doing a crash test now . . . "); + printf("trying to divide by zero now . . . "); printf("0/0 = %i", 0 / 0); return 0; } diff --git a/src/userland/log/main.c b/src/userland/log/main.c index 2ac85e1..eb92e52 100644 --- a/src/userland/log/main.c +++ b/src/userland/log/main.c @@ -5,6 +5,22 @@ uint32_t services[10], functions[10], outputCount; +char *EXCEPTION_NAMES[] = {"DIVISION ERROR", + "DEBUG EXCEPTION", + "NON-MASKABLE-INTERRUPT", + "BREAKPOINT EXCEPTION", + "OVERFLOW EXCEPTION", + "BOUND RANGE EXCEEDED EXCEPTION", + "INVALID OPCODE EXCEPTION", + "DEVICE NOT AVAILABLE EXCEPTION", + "DOUBLE FAULT", + "COPROCESSOR EXCEPTION", + "INVALID TSS EXCEPTION", + "SEGMENT NOT PRESENT EXCEPTION", + "STACK-SEGMENT-FAULT", + "GENERAL PROTECTION FAULT", + "PAGE FAULT"}; + void writeChar(uint8_t data) { for (uint8_t i = 0; i < outputCount; i++) { request(services[i], functions[i], data, 0); @@ -50,10 +66,16 @@ printf("loading '%s' from initrd", buffer); } +void onException(uint32_t intNo, uint32_t unused, uint32_t serviceName) { + readString(serviceName, buffer); + printf("service \"%s\" commited a %s", buffer, EXCEPTION_NAMES[intNo]); +} + int32_t main() { createFunction("log", (void *)handleLog); createFunction("registerOut", (void *)registerOut); uint32_t eventId = getEvent(0, "loadInitrd"); subscribeEvent(0, eventId, (void *)onInitrdLoad); + subscribeInterrupt(0, (void *)onException); return 0; }