From 1213055aff45b811cf8073c3904bb7c3f08dfff5 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Sat, 18 May 2019 00:03:35 +0200 Subject: [PATCH] Pushing more registers --- include/kernel.h | 2 +- kaleid/kernel/ke/cpuf.asm | 9 +++++++++ kaleid/kernel/ke/idt.c | 19 +++++++++++++------ kaleid/kernel/ke/isr.asm | 20 +++++++++++++------- 4 files changed, 36 insertions(+), 14 deletions(-) diff --git a/include/kernel.h b/include/kernel.h index 8e5c271..50fbddc 100644 --- a/include/kernel.h +++ b/include/kernel.h @@ -111,7 +111,7 @@ struct CpuInfo_t struct ISRFrame_t { /* The register file */ - ulong regs[15]; + ulong regs[20]; /* The error code and interrupt id */ ulong intNo; diff --git a/kaleid/kernel/ke/cpuf.asm b/kaleid/kernel/ke/cpuf.asm index fd0295c..50d396f 100644 --- a/kaleid/kernel/ke/cpuf.asm +++ b/kaleid/kernel/ke/cpuf.asm @@ -24,5 +24,14 @@ [BITS 64] +global divideByZero + %include "kaleid/kernel/ke/cpuf.inc" +;; +;; Bug test +;; +divideByZero: + ret + + diff --git a/kaleid/kernel/ke/idt.c b/kaleid/kernel/ke/idt.c index 32899a7..a5d2e03 100644 --- a/kaleid/kernel/ke/idt.c +++ b/kaleid/kernel/ke/idt.c @@ -283,7 +283,9 @@ static void EarlyExceptionHandler(ISRFrame_t *regs) " RDI: %#016lx RBP: %#016lx R8: %#016lx\n" " R9: %#016lx R10: %#016lx R11: %#016lx\n" " R12: %#016lx R13: %#016lx R14: %#016lx\n" - " R15: %#016lx RFLAGS: %#022b (%#06x)", + " R15: %#016lx CR0: %#016lx CR2: %#016lx\n" + " CR3: %#016lx CR4: %#016lx CR8: %#016lx\n" + " RFLAGS: %#022b (%#06x)", regs->intNo, ExceptionsChar[regs->intNo], regs->ErrorCode, @@ -292,11 +294,6 @@ static void EarlyExceptionHandler(ISRFrame_t *regs) regs->cs, regs->rsp, regs->ss, - regs->regs[0], - regs->regs[1], - regs->regs[2], - regs->regs[3], - regs->regs[4], regs->regs[5], regs->regs[6], regs->regs[7], @@ -307,6 +304,16 @@ static void EarlyExceptionHandler(ISRFrame_t *regs) regs->regs[12], regs->regs[13], regs->regs[14], + regs->regs[15], + regs->regs[16], + regs->regs[17], + regs->regs[18], + regs->regs[19], + regs->regs[0], + regs->regs[1], + regs->regs[2], + regs->regs[3], + regs->regs[4], regs->rflags, regs->rflags ); diff --git a/kaleid/kernel/ke/isr.asm b/kaleid/kernel/ke/isr.asm index 11905da..9365fb3 100644 --- a/kaleid/kernel/ke/isr.asm +++ b/kaleid/kernel/ke/isr.asm @@ -27,7 +27,6 @@ %include "kaleid/kernel/ke/cpuf.inc" global KeLoadIDT -global divideByZero extern _KeIdtPtr extern _KeHandleISR @@ -39,17 +38,21 @@ KeLoadIDT: lidt [_KeIdtPtr] ret -;; -;; Bug test -;; -divideByZero: - ret - ;; ;; ISR Exception pre-handler ;; isrPreHandler: pushAll + mov rax, cr8 + push rax + mov rax, cr4 + push rax + mov rax, cr3 + push rax + mov rax, cr2 + push rax + mov rax, cr0 + push rax ; Check if we are switching from user mode to supervisor mode mov rax, [rsp + 152] @@ -80,7 +83,10 @@ isrPreHandler: swapgs ; XXX need TSS .SExit: + ; pop the control registers + add rsp, 40 popAll + ; pop the error code and interrupt id add rsp, 16