Task contexts now load segment registers correctly

Interrupt enable bit set in saved EFLAGS register
This commit is contained in:
2021-04-18 02:10:03 -05:00
parent 1171aa2ca3
commit c39cbb79cd
3 changed files with 32 additions and 7 deletions

View File

@@ -5,4 +5,4 @@
void *initialize_context(void *task_entry, struct page_stack_t *page_stack); void *initialize_context(void *task_entry, struct page_stack_t *page_stack);
void load_context(struct process_state_t *context) __attribute__((noreturn)); void load_context(struct process_state_t *context) __attribute__((naked));

View File

@@ -35,7 +35,7 @@ void *initialize_context(void *task_entry, struct page_stack_t *page_stack)
memset(stack, 0, sizeof(*stack)); memset(stack, 0, sizeof(*stack));
stack->eip = (uint32_t)task_entry; stack->eip = (uint32_t)task_entry;
stack->cs = 27; stack->cs = 27;
stack->flags = flags; stack->flags = flags | 0x200;
stack->esp = 0xFF7FE000; stack->esp = 0xFF7FE000;
stack->ss = 35; stack->ss = 35;
stack->esp_temp = &stack->eax; stack->esp_temp = &stack->eax;
@@ -44,8 +44,13 @@ void *initialize_context(void *task_entry, struct page_stack_t *page_stack)
void load_context(struct process_state_t *context) void load_context(struct process_state_t *context)
{ {
asm("mov %0, %%esp; " asm("mov $0x10, %%ax; "
"mov %%ax, %%ds; "
"mov %%ax, %%es; "
"mov %%ax, %%fs; "
"mov %%ax, %%gs; "
::: "ax");
asm("mov 4(%esp), %esp; "
"popal; " "popal; "
"iret; " "iret; ");
:: "r"(context));
} }

View File

@@ -16,6 +16,12 @@ void isr_division_by_zero(void* frame)
void isr_gp_fault(void* frame, unsigned int error) void isr_gp_fault(void* frame, unsigned int error)
{ {
asm("cli"); asm("cli");
asm("mov $0x10, %%ax; "
"mov %%ax, %%ds; "
"mov %%ax, %%es; "
"mov %%ax, %%fs; "
"mov %%ax, %%gs; "
::: "ax");
printf("Exception: GP fault, code %08x\n", error); printf("Exception: GP fault, code %08x\n", error);
asm("hlt"); asm("hlt");
} }
@@ -25,6 +31,12 @@ void isr_page_fault(void* frame, unsigned int error)
size_t addr; size_t addr;
asm("mov %%cr2, %0" asm("mov %%cr2, %0"
: "=r"(addr)); : "=r"(addr));
asm("mov $0x10, %%ax; "
"mov %%ax, %%ds; "
"mov %%ax, %%es; "
"mov %%ax, %%fs; "
"mov %%ax, %%gs; "
::: "ax");
printf("Exception: Page fault, code %08x, linear address %08x\n", error, addr); printf("Exception: Page fault, code %08x, linear address %08x\n", error, addr);
asm("hlt"); asm("hlt");
} }
@@ -46,10 +58,18 @@ void isr_timer(void* frame)
void isr_preempt(void* frame) void isr_preempt(void* frame)
{ {
asm("pushal; " asm("pushal; "
"mov %esp, %ebp"); "mov %esp, %ebp; ");
asm("mov $0x10, %%ax; "
"mov %%ax, %%ds; "
"mov %%ax, %%es; "
"mov %%ax, %%fs; "
"mov %%ax, %%gs; "
::: "ax");
struct process_state_t *process_state; struct process_state_t *process_state;
asm("mov %%ebp, %0" asm("mov %%ebp, %0"
: "=r"(process_state)); : "=r"(process_state));
printf("Preempted process %08x.\n", kernel_state.active_process);
apic_eoi();
next_process(&kernel_state, process_state); next_process(&kernel_state, process_state);
} }