Interrupt working (Except that I need to remap PIC).
1. Fix a stupid mistake in idt dispatch table (IDT_ENTRY_NUM instead of IDT_ENTRY_SIZE)! 2. Figured out that before enabling APIC, the PIC is not completely disabled/remapped. Took hours to debug why immediately after enabling interrupt, a double fault happens when executing "mov eax, 0". Turned out that PIC maps timer interrupt to int vet 8, which is double fault in the vector table. The double fault normally pushes an error code 0, the ISR is expecting the error code but the timer interrupt does not push an error code thereby screwing up the interrupt stack completely. The kernel runs normally after "sti" after changing the int 8 vector to just "iretq". (Remapping the PIC: http://wiki.osdev.org/I_Cant_Get_Interrupts_Working#I.27m_receiving_EXC9_instead_of_IRQ1_when_striking_a_key_.3F.21). Oh FML, hours wasted..
This commit is contained in:
parent
bc49a854dd
commit
b2254e207d
@ -84,7 +84,7 @@
|
||||
#display_library: macintosh
|
||||
#display_library: nogui
|
||||
#display_library: rfb
|
||||
display_library: sdl
|
||||
display_library: sdl, options="gui_debug"
|
||||
#display_library: sdl2
|
||||
#display_library: term
|
||||
#display_library: vncsrv
|
||||
|
45764
x64/kernel.dasm
45764
x64/kernel.dasm
File diff suppressed because it is too large
Load Diff
@ -24,14 +24,13 @@ pop rax
|
||||
push rax ; eflags
|
||||
|
||||
push rsi ; cs
|
||||
push qword .reload ;eip
|
||||
push qword .reload ;rip
|
||||
iretq
|
||||
.reload:
|
||||
mov es,dx
|
||||
mov fs,dx
|
||||
mov gs,dx
|
||||
mov ds,dx
|
||||
mov rsp,rbp
|
||||
pop rbp
|
||||
ret
|
||||
|
||||
@ -49,6 +48,12 @@ hal_flush_idt:
|
||||
lidt [rdi]
|
||||
ret
|
||||
|
||||
;======================
|
||||
global hal_read_idt
|
||||
hal_read_idt:
|
||||
sidt [rdi]
|
||||
ret
|
||||
|
||||
;======================
|
||||
global hal_read_cr3
|
||||
hal_read_cr3:
|
||||
|
@ -27,7 +27,6 @@ static void KAPI _hal_obtain_cpu_info(k_hal_info_t *hal_info)
|
||||
|
||||
static void KAPI _hal_init_gdt()
|
||||
{
|
||||
text_pos = get_pos(0, 0);
|
||||
|
||||
// get gdt ready
|
||||
hal_write_segment_descriptor((void *) &g_gdt[0], 0, 0, 0);
|
||||
@ -62,12 +61,14 @@ k_hal_info_t *KAPI hal_init(char *m_info)
|
||||
if (m_info == NULL || (uint64_t) m_info & bit_field_mask_64(0, 2))
|
||||
return NULL;
|
||||
|
||||
// set up kernel heap;
|
||||
hal_alloc_init();
|
||||
text_pos = get_pos(0, 0);
|
||||
|
||||
// set up GDT
|
||||
_hal_init_gdt();
|
||||
|
||||
// set up kernel heap;
|
||||
hal_alloc_init();
|
||||
|
||||
// init interrupt
|
||||
if(hal_interrupt_init() != 0)
|
||||
{
|
||||
|
@ -3,6 +3,7 @@
|
||||
* See COPYING under root for details
|
||||
*/
|
||||
|
||||
#include <hal_arch.h>
|
||||
#include "bit_ops.h"
|
||||
#include "hal_arch.h"
|
||||
#include "hal_intr.h"
|
||||
@ -120,7 +121,6 @@ static void KAPI _hal_populate_idt()
|
||||
hal_set_interrupt_handler(37, hal_interrupt_handler_37);
|
||||
hal_set_interrupt_handler(38, hal_interrupt_handler_38);
|
||||
hal_set_interrupt_handler(39, hal_interrupt_handler_39);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@ -178,7 +178,6 @@ int32_t KAPI hal_interrupt_init(void)
|
||||
// hal_printf("IDT%d: %d,%d,%d,%d",i, (uint64_t)g_idt);
|
||||
// }
|
||||
hal_trigger_interrupt(33);
|
||||
hal_halt_cpu();
|
||||
hal_enable_interrupt();
|
||||
|
||||
return 0;
|
||||
|
@ -6,9 +6,9 @@
|
||||
#include "hal_intr.h"
|
||||
#include "hal_var.h"
|
||||
|
||||
uint8_t g_gdt[8*9];
|
||||
uint8_t g_gdt[GDT_ENTRY_NUM*GDT_ENTRY_SIZE];
|
||||
uint8_t g_idt[IDT_ENTRY_NUM*IDT_ENTRY_SIZE];
|
||||
void (*g_intr_handler_table[IDT_ENTRY_SIZE])(uint64_t pc, uint64_t sp, uint64_t error);
|
||||
void (*g_intr_handler_table[IDT_ENTRY_NUM])(uint64_t pc, uint64_t sp, uint64_t error);
|
||||
hal_gdt_ptr_t g_gdt_ptr;
|
||||
hal_idt_ptr_t g_idt_ptr;
|
||||
uint64_t text_pos;
|
@ -3,17 +3,17 @@
|
||||
|
||||
#include "k_def.h"
|
||||
|
||||
typedef struct __attribute__ ((packed))
|
||||
typedef struct
|
||||
{
|
||||
uint16_t limit;
|
||||
uint64_t base;
|
||||
} hal_gdt_ptr_t;
|
||||
} __attribute__ ((packed)) hal_gdt_ptr_t;
|
||||
|
||||
typedef struct __attribute__ ((packed))
|
||||
typedef struct
|
||||
{
|
||||
uint16_t limit;
|
||||
uint64_t base;
|
||||
} hal_idt_ptr_t;
|
||||
} __attribute__ ((packed)) hal_idt_ptr_t;
|
||||
|
||||
extern uint64_t KAPI hal_interlocked_exchange(uint64_t *dst, uint64_t val);
|
||||
|
||||
@ -46,6 +46,8 @@ extern void KAPI hal_flush_tlb();
|
||||
|
||||
extern void KAPI hal_flush_idt(hal_idt_ptr_t *idt_ptr);
|
||||
|
||||
extern void KAPI hal_read_idt(hal_idt_ptr_t **idt_ptr);
|
||||
|
||||
extern void KAPI hal_write_cr3(uint64_t base);
|
||||
|
||||
extern uint64_t KAPI hal_read_cr3();
|
||||
|
@ -11,9 +11,9 @@
|
||||
#include "hal_arch.h"
|
||||
#include "hal_intr.h"
|
||||
|
||||
extern uint8_t g_gdt[];
|
||||
extern uint8_t g_idt[];
|
||||
extern void (*g_intr_handler_table[IDT_ENTRY_SIZE])(uint64_t pc, uint64_t sp, uint64_t error);
|
||||
extern uint8_t g_gdt[GDT_ENTRY_NUM*GDT_ENTRY_SIZE];
|
||||
extern uint8_t g_idt[IDT_ENTRY_NUM*IDT_ENTRY_SIZE];
|
||||
extern void (*g_intr_handler_table[IDT_ENTRY_NUM])(uint64_t pc, uint64_t sp, uint64_t error);
|
||||
extern hal_gdt_ptr_t g_gdt_ptr;
|
||||
extern hal_idt_ptr_t g_idt_ptr;
|
||||
extern uint64_t text_pos;
|
||||
|
@ -9,21 +9,21 @@
|
||||
|
||||
#include "k_def.h"
|
||||
|
||||
typedef struct __attribute__((packed))
|
||||
typedef struct
|
||||
{
|
||||
uint64_t rax;
|
||||
uint64_t rbx;
|
||||
uint64_t rcx;
|
||||
uint64_t rdx;
|
||||
} process_context_t;
|
||||
} __attribute__((packed)) process_context_t;
|
||||
|
||||
typedef struct __attribute__((packed))
|
||||
typedef struct
|
||||
{
|
||||
uint32_t process_id;
|
||||
uint32_t priority;
|
||||
process_context_t context;
|
||||
|
||||
} process_control_block_t;
|
||||
} __attribute__((packed)) process_control_block_t;
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user