enhancing IDT

This commit is contained in:
Adrien Bourmault 2019-04-26 20:11:08 +02:00
parent ed534340ae
commit 74593f7f71
6 changed files with 92 additions and 47 deletions

View File

@ -9,6 +9,7 @@ typedef struct IdtDescriptor_t IdtDescriptor_t;
typedef struct IdtEntry_t IdtEntry_t; typedef struct IdtEntry_t IdtEntry_t;
typedef struct IdtPtr_t IdtPtr_t; typedef struct IdtPtr_t IdtPtr_t;
typedef struct IRQList_t IRQList_t; typedef struct IRQList_t IRQList_t;
typedef struct ISRFrame_t ISRFrame_t;
// -------------------------------------------------------------------------- // // -------------------------------------------------------------------------- //
@ -49,6 +50,27 @@ struct IRQList_t
} entry[224]; } entry[224];
}; };
struct ISRFrame_t {
/* the register file */
uint64_t regs[15];
/* the error code and interrupt id */
uint64_t id;
uint64_t error;
/* these are pushed automatically by the CPU */
uint64_t rip;
uint64_t cs;
uint64_t rflags;
uint64_t rsp;
uint64_t ss;
} __attribute__((__packed__));
typedef struct
{
} __attribute__((__packed__)) cpu_state_t;
static char *IsrExceptions[32] = { static char *IsrExceptions[32] = {
"Divide Error Fault", "Divide Error Fault",
"Debug Exception Trap", "Debug Exception Trap",
@ -59,7 +81,7 @@ static char *IsrExceptions[32] = {
"Invalid Opcode Fault", "Invalid Opcode Fault",
"Device Not Available or No Math Coprocessor Fault", "Device Not Available or No Math Coprocessor Fault",
"Double Fault Abort", "Double Fault Abort",
"Coprocessor Segment Overrun Fault", "Coprocessor Segment Overrun Fault (Legacy)",
"Invalid TSS Fault", "Invalid TSS Fault",
"Segment Not Present Fault", "Segment Not Present Fault",
"Stack Segment fault", "Stack Segment fault",
@ -80,7 +102,7 @@ static char *IsrExceptions[32] = {
"Intel Reserved", "Intel Reserved",
"Intel Reserved", "Intel Reserved",
"Intel Reserved", "Intel Reserved",
"Intel Reserved", "Security Exception",
"Intel Reserved" "Intel Reserved"
}; };

View File

@ -53,26 +53,41 @@ divideByZero:
;; ISR handler ;; ISR handler
;; ;;
isrPreHandler: isrPreHandler:
mov ax, ds pushAll
push rax
mov ax, 0x0 ; Check if we are switching from user mode to supervisor mode
mov ds, ax mov rax, [rsp + 152]
mov es, ax and rax, 0x3000
mov fs, ax jz .SEnter
mov gs, ax
swapgs ; XXX need TSS
.SEnter:
; Increment mask count as we configure all interrupts to mask IF
; automatically in the IDT
inc qword [gs:8]
; Call the C routine for dispatching an interrupt
cld ; DF must be cleared by the caller
mov rdi, rsp ; First argument points to the processor state
mov rbp, 0 ; Terminate stack traces here
call IdtHandler call IdtHandler
pop rbx ; decrement mask count
mov ds, bx dec qword [gs:8]
mov es, bx
mov fs, bx
mov gs, bx
; check if we are switching from supervisor to user mode
mov rax, [rsp + 152]
and rax, 0x3000
jz .SExit
swapgs
.SExit:
popAll popAll
add rsp, 8 ; pop the error code and interrupt id
sti add rsp, 16
iretq iretq
;; Divide Error Fault ;; Divide Error Fault

View File

@ -25,33 +25,47 @@
[BITS 64] [BITS 64]
%macro pushAll 0 %macro pushAll 0
push rax push r15
push rcx push r14
push rdx push r13
push rbx push r12
push r11
push r10
push r9
push r8
push rbp push rbp
push rsi
push rdi push rdi
push rsi
push rdx
push rcx
push rbx
push rax
%endmacro %endmacro
%macro popAll 0 %macro popAll 0
pop rdi
pop rsi
pop rbp
pop rbx
pop rdx
pop rcx
pop rax pop rax
pop rbx
pop rcx
pop rdx
pop rsi
pop rdi
pop rbp
pop r8
pop r9
pop r10
pop r11
pop r12
pop r13
pop r14
pop r15
%endmacro %endmacro
%macro IsrWithoutErrCode 1 %macro IsrWithoutErrCode 1
global isr%1 global isr%1
isr%1: isr%1:
cli cli
push byte 0 push 0
pushAll push %1
xor rdi, rdi
mov rdi, %1
jmp isrPreHandler jmp isrPreHandler
%endmacro %endmacro
@ -59,8 +73,6 @@ isr%1:
global isr%1 global isr%1
isr%1: isr%1:
cli cli
pushAll push %1
xor rdi, rdi
mov rdi, %1
jmp isrPreHandler jmp isrPreHandler
%endmacro %endmacro

View File

@ -94,14 +94,12 @@ noreturn void BtStartKern(multiboot_info_t *mbInfo, uint mbMagic, void *codeSeg)
IoPrintRtcTime(); IoPrintRtcTime();
/* KernLog("There was %d ticks\n", IoGetRtcTicks()); */ KernLog("There was %d ticks\n", IoGetRtcTicks());
/* for (uint i = 1; i < 2 ; i++) { */ for (uint i = 1; i < 20000 ; i++) {
/* while (IoGetRtcTicks() < i * 10000) { */ while (IoGetRtcTicks() < i * 10000) {
/* } */ }
/* IoPrintRtcTime(); */ IoPrintRtcTime();
/* } */ }
int* var = 7*GB;
*var = 2;
KernLog("Goodbye after %d ticks\n", IoGetRtcTicks()); KernLog("Goodbye after %d ticks\n", IoGetRtcTicks());
// End this machine's suffering // End this machine's suffering

View File

@ -65,5 +65,4 @@ KeybIsr:
mov ds, ax mov ds, ax
popAll popAll
sti
iretq iretq

View File

@ -65,5 +65,4 @@ RtcIsr:
mov ds, ax mov ds, ax
popAll popAll
sti
iretq iretq