fix bug in the calculation of esp0
This commit is contained in:
parent
09ec6dcc3a
commit
89c792cc03
5 changed files with 15 additions and 51 deletions
|
@ -32,15 +32,19 @@
|
||||||
//#define START_KERNEL_JACOBI
|
//#define START_KERNEL_JACOBI
|
||||||
#define START_MMNIF_TEST
|
#define START_MMNIF_TEST
|
||||||
#endif
|
#endif
|
||||||
|
#ifdef CONFIG_LWIP
|
||||||
#define START_ECHO
|
#define START_ECHO
|
||||||
|
#ifndef CONFIG_TICKLESS
|
||||||
//#define START_NETIO
|
//#define START_NETIO
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
//#define START_CONSUMER_PRODUCER
|
//#define START_CONSUMER_PRODUCER
|
||||||
#define START_FOO
|
#define START_FOO
|
||||||
//#define START_JOIN_TEST
|
//#define START_JOIN_TEST
|
||||||
//#define START_PI
|
//#define START_PI
|
||||||
//#define START_MEASURE_CTX_SWITCH
|
//#define START_MEASURE_CTX_SWITCH
|
||||||
#define START_HELLO
|
//#define START_HELLO
|
||||||
//#define START_TESTS
|
#define START_TESTS
|
||||||
//#define START_JACOBI
|
//#define START_JACOBI
|
||||||
|
|
||||||
// does our demos require GFX support?
|
// does our demos require GFX support?
|
||||||
|
|
|
@ -753,8 +753,6 @@ apic_svr:
|
||||||
extern irq_handler
|
extern irq_handler
|
||||||
extern get_current_stack
|
extern get_current_stack
|
||||||
extern finish_task_switch
|
extern finish_task_switch
|
||||||
extern apic_cpu_id
|
|
||||||
extern task_state_segments
|
|
||||||
|
|
||||||
global switch_context
|
global switch_context
|
||||||
ALIGN 4
|
ALIGN 4
|
||||||
|
@ -792,24 +790,6 @@ common_switch:
|
||||||
call get_current_stack ; get new esp
|
call get_current_stack ; get new esp
|
||||||
xchg eax, esp
|
xchg eax, esp
|
||||||
|
|
||||||
; determine TSS
|
|
||||||
%if MAX_CORES > 1
|
|
||||||
call apic_cpu_id
|
|
||||||
mov ecx, DWORD 0x68
|
|
||||||
mul ecx
|
|
||||||
%else
|
|
||||||
xor eax, eax
|
|
||||||
%endif
|
|
||||||
add eax, task_state_segments
|
|
||||||
|
|
||||||
; determine and set esp0 in TSS
|
|
||||||
mov ebx, esp
|
|
||||||
mov ecx, KERNEL_STACK_SIZE-1
|
|
||||||
not ecx
|
|
||||||
and ebx, ecx
|
|
||||||
add ebx, KERNEL_STACK_SIZE-16
|
|
||||||
mov [eax+4], ebx
|
|
||||||
|
|
||||||
; set task switched flag
|
; set task switched flag
|
||||||
mov eax, cr0
|
mov eax, cr0
|
||||||
or eax, 8
|
or eax, 8
|
||||||
|
|
|
@ -1066,8 +1066,6 @@ apic_svr:
|
||||||
extern irq_handler
|
extern irq_handler
|
||||||
extern get_current_stack
|
extern get_current_stack
|
||||||
extern finish_task_switch
|
extern finish_task_switch
|
||||||
extern apic_cpu_id
|
|
||||||
extern task_state_segments
|
|
||||||
|
|
||||||
global switch_context
|
global switch_context
|
||||||
ALIGN 8
|
ALIGN 8
|
||||||
|
@ -1137,24 +1135,6 @@ common_switch:
|
||||||
call get_current_stack ; get new rsp
|
call get_current_stack ; get new rsp
|
||||||
xchg rax, rsp
|
xchg rax, rsp
|
||||||
|
|
||||||
; determine TSS
|
|
||||||
%if MAX_CORES > 1
|
|
||||||
call apic_cpu_id
|
|
||||||
mov rcx, QWORD 0x68
|
|
||||||
mul rcx
|
|
||||||
%else
|
|
||||||
xor rax, rax
|
|
||||||
%endif
|
|
||||||
add rax, task_state_segments
|
|
||||||
|
|
||||||
; determine and set esp0 in TSS
|
|
||||||
mov rbx, rsp
|
|
||||||
mov rcx, KERNEL_STACK_SIZE-1
|
|
||||||
not rcx
|
|
||||||
and rbx, rcx
|
|
||||||
add rbx, KERNEL_STACK_SIZE-16
|
|
||||||
mov [rax+4], rbx
|
|
||||||
|
|
||||||
; set task switched flag
|
; set task switched flag
|
||||||
mov rax, cr0
|
mov rax, cr0
|
||||||
or eax, 8
|
or eax, 8
|
||||||
|
|
|
@ -28,8 +28,8 @@
|
||||||
#include <asm/page.h>
|
#include <asm/page.h>
|
||||||
|
|
||||||
gdt_ptr_t gp;
|
gdt_ptr_t gp;
|
||||||
tss_t task_state_segments[MAX_CORES] __attribute__ ((aligned (PAGE_SIZE)));
|
static tss_t task_state_segments[MAX_CORES] __attribute__ ((aligned (PAGE_SIZE)));
|
||||||
static unsigned char kstacks[MAX_TASKS][KERNEL_STACK_SIZE] __attribute__ ((aligned (PAGE_SIZE))) = {[0 ... MAX_TASKS-1][0 ... KERNEL_STACK_SIZE-1] = 0xCD};
|
static unsigned char kstacks[MAX_TASKS][KERNEL_STACK_SIZE] __attribute__ ((aligned (PAGE_SIZE))) = {[0][0 ... KERNEL_STACK_SIZE-1] = 0xCD};
|
||||||
size_t default_stack_pointer = (size_t) kstacks[0] + KERNEL_STACK_SIZE - 16; // => stack is 16byte aligned
|
size_t default_stack_pointer = (size_t) kstacks[0] + KERNEL_STACK_SIZE - 16; // => stack is 16byte aligned
|
||||||
// currently, our kernel has full access to the ioports
|
// currently, our kernel has full access to the ioports
|
||||||
static gdt_entry_t gdt[GDT_ENTRIES] = {[0 ... GDT_ENTRIES-1] = {0, 0, 0, 0, 0, 0}};
|
static gdt_entry_t gdt[GDT_ENTRIES] = {[0 ... GDT_ENTRIES-1] = {0, 0, 0, 0, 0, 0}};
|
||||||
|
@ -44,6 +44,10 @@ size_t* get_current_stack(void)
|
||||||
{
|
{
|
||||||
task_t* curr_task = per_core(current_task);
|
task_t* curr_task = per_core(current_task);
|
||||||
|
|
||||||
|
// determine and set esp0
|
||||||
|
task_state_segments[CORE_ID].esp0 = (size_t) kstacks[curr_task->id] + KERNEL_STACK_SIZE - 16; // => stack is 16byte aligned
|
||||||
|
|
||||||
|
// use new page table
|
||||||
write_cr3(virt_to_phys((size_t)curr_task->pgd));
|
write_cr3(virt_to_phys((size_t)curr_task->pgd));
|
||||||
|
|
||||||
return curr_task->stack;
|
return curr_task->stack;
|
||||||
|
@ -58,7 +62,6 @@ size_t get_stack(uint32_t id)
|
||||||
|
|
||||||
int arch_fork(task_t* task)
|
int arch_fork(task_t* task)
|
||||||
{
|
{
|
||||||
uint16_t cs = 0x08;
|
|
||||||
uint32_t id;
|
uint32_t id;
|
||||||
struct state* state;
|
struct state* state;
|
||||||
task_t* curr_task = per_core(current_task);
|
task_t* curr_task = per_core(current_task);
|
||||||
|
@ -84,7 +87,7 @@ int arch_fork(task_t* task)
|
||||||
esp += (size_t) kstacks[id];
|
esp += (size_t) kstacks[id];
|
||||||
|
|
||||||
state = (struct state*) (esp - state_size);
|
state = (struct state*) (esp - state_size);
|
||||||
memset(state, 0x00, state_size);
|
//memset(state, 0x00, state_size);
|
||||||
|
|
||||||
asm volatile ("pusha; pop %0" : "=m"(state->edi));
|
asm volatile ("pusha; pop %0" : "=m"(state->edi));
|
||||||
asm volatile ("pop %0" : "=m"(state->esi));
|
asm volatile ("pop %0" : "=m"(state->esi));
|
||||||
|
@ -99,7 +102,7 @@ int arch_fork(task_t* task)
|
||||||
task->stack = (size_t*) state;
|
task->stack = (size_t*) state;
|
||||||
state->int_no = 0xB16B00B5;
|
state->int_no = 0xB16B00B5;
|
||||||
state->error = 0xC03DB4B3;
|
state->error = 0xC03DB4B3;
|
||||||
state->cs = cs;
|
state->cs = 0x08;
|
||||||
// store the current EFLAGS
|
// store the current EFLAGS
|
||||||
asm volatile ("pushf; pop %0" : "=m"(state->eflags));
|
asm volatile ("pushf; pop %0" : "=m"(state->eflags));
|
||||||
// enable interrupts
|
// enable interrupts
|
||||||
|
|
|
@ -102,13 +102,10 @@ int cpu_detection(void)
|
||||||
cr4 |= 0x400; // set the OSXMMEXCPT bit
|
cr4 |= 0x400; // set the OSXMMEXCPT bit
|
||||||
write_cr4(cr4);
|
write_cr4(cr4);
|
||||||
|
|
||||||
if (has_sse()) {
|
if (has_sse())
|
||||||
kprintf("Enable the usage of sfence\n");
|
|
||||||
wmb = sfence;
|
wmb = sfence;
|
||||||
}
|
|
||||||
|
|
||||||
if (has_sse2()) {
|
if (has_sse2()) {
|
||||||
kprintf("Enable the usage of lfence and mfence\n");
|
|
||||||
rmb = lfence;
|
rmb = lfence;
|
||||||
mb = mfence;
|
mb = mfence;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue